1 /* 2 * Copyright (c) 2009 Kov Chai <tchaikov (at) gmail.com> 3 * 4 * The contents of this file are subject to the terms of either the GNU Lesser 5 * General Public License Version 2.1 only ("LGPL") or the Common Development and 6 * Distribution License ("CDDL")(collectively, the "License"). You may not use this 7 * file except in compliance with the License. You can obtain a copy of the CDDL at 8 * http://www.opensource.org/licenses/cddl1.php and a copy of the LGPLv2.1 at 9 * http://www.opensource.org/licenses/lgpl-license.php. See the License for the 10 * specific language governing permissions and limitations under the License. When 11 * distributing the software, include this License Header Notice in each file and 12 * include the full text of the License in the License file as well as the 13 * following notice: 14 * 15 * NOTICE PURSUANT TO SECTION 9 OF THE COMMON DEVELOPMENT AND DISTRIBUTION LICENSE 16 * (CDDL) 17 * For Covered Software in this distribution, this License shall be governed by the 18 * laws of the State of California (excluding conflict-of-law provisions). 19 * Any litigation relating to this License shall be subject to the jurisdiction of 20 * the Federal Courts of the Northern District of California and the state courts 21 * of the State of California, with venue lying in Santa Clara County, California. 22 * 23 * Contributor(s): 24 * 25 * If you wish your version of this file to be governed by only the CDDL or only 26 * the LGPL Version 2.1, indicate your decision by adding "[Contributor]" elects to 27 * include this software in this distribution under the [CDDL or LGPL Version 2.1] 28 * license." If you don't indicate a single choice of license, a recipient has the 29 * option to distribute your version of this file under either the CDDL or the LGPL 30 * Version 2.1, or to extend the choice of license to its licensees as provided 31 * above. However, if you add LGPL Version 2.1 code and therefore, elected the LGPL 32 * Version 2 license, then the option applies only if the new code is made subject 33 * to such option by the copyright holder. 34 */ 35 36 #include "sunpinyin_engine_proxy.h" 37 #include "sunpinyin_engine.h" 38 #include "sunpinyin_config.h" 39 #include "engine.h" 40 41 struct IBusSunPinyinEngineClass { 42 IBusEngineClass parent; 43 }; 44 45 typedef SunPinyinEngine IBusSunPinyinEngine; 46 47 /* functions prototype */ 48 extern "C" 49 { 50 static void ibus_sunpinyin_engine_class_init (IBusSunPinyinEngineClass *); 51 static GObject* ibus_sunpinyin_engine_constructor (GType type, 52 guint n_construct_params, 53 GObjectConstructParam *construct_params); 54 } 55 56 static IBusEngineClass *parent_class = NULL; 57 58 GType 59 ibus_sunpinyin_engine_get_type (void) 60 { 61 static GType type = 0; 62 63 static const GTypeInfo type_info = { 64 sizeof (IBusSunPinyinEngineClass), 65 (GBaseInitFunc) NULL, 66 (GBaseFinalizeFunc) NULL, 67 (GClassInitFunc) ibus_sunpinyin_engine_class_init, 68 NULL, 69 NULL, 70 sizeof (IBusSunPinyinEngine), 71 0, 72 (GInstanceInitFunc) ibus_sunpinyin_engine_init, 73 }; 74 75 if (type == 0) { 76 type = g_type_register_static (IBUS_TYPE_ENGINE, 77 "IBusSunPinyinEngine", 78 &type_info, 79 (GTypeFlags) 0); 80 } 81 82 return type; 83 } 84 85 // load sunpinyin configuration 86 void 87 ibus_sunpinyin_init(IBusBus *bus) 88 { 89 IBusConfig *config = ibus_bus_get_config(bus); 90 SunPinyinConfig::set_config(config); 91 } 92 93 void 94 ibus_sunpinyin_exit() 95 {} 96 97 extern "C" 98 { 99 100 // initialize the meta class object 101 void 102 ibus_sunpinyin_engine_class_init (IBusSunPinyinEngineClass *klass) 103 { 104 GObjectClass *object_class = G_OBJECT_CLASS(klass); 105 IBusObjectClass *ibus_object_class = IBUS_OBJECT_CLASS (klass); 106 IBusEngineClass *engine_class = IBUS_ENGINE_CLASS (klass); 107 108 parent_class = (IBusEngineClass *) g_type_class_peek_parent (klass); 109 110 object_class->constructor = ibus_sunpinyin_engine_constructor; 111 ibus_object_class->destroy = (IBusObjectDestroyFunc) ibus_sunpinyin_engine_destroy; 112 113 engine_class->process_key_event = ibus_sunpinyin_engine_process_key_event; 114 engine_class->focus_in = ibus_sunpinyin_engine_focus_in; 115 engine_class->focus_out = ibus_sunpinyin_engine_focus_out; 116 engine_class->reset = ibus_sunpinyin_engine_reset; 117 engine_class->enable = ibus_sunpinyin_engine_enable; 118 engine_class->disable = ibus_sunpinyin_engine_disable; 119 engine_class->focus_in = ibus_sunpinyin_engine_focus_in; 120 engine_class->focus_out = ibus_sunpinyin_engine_focus_out; 121 engine_class->page_up = ibus_sunpinyin_engine_page_up; 122 engine_class->page_down = ibus_sunpinyin_engine_page_down; 123 engine_class->cursor_up = ibus_sunpinyin_engine_cursor_up; 124 engine_class->cursor_down = ibus_sunpinyin_engine_cursor_down; 125 engine_class->property_activate = ibus_sunpinyin_engine_property_activate; 126 engine_class->candidate_clicked = ibus_sunpinyin_engine_candidate_clicked; 127 } 128 129 // allocate a new ibus engine 130 GObject* 131 ibus_sunpinyin_engine_constructor (GType type, 132 guint n_construct_params, 133 GObjectConstructParam *construct_params) 134 { 135 IBusSunPinyinEngine *engine = (IBusSunPinyinEngine *) 136 G_OBJECT_CLASS (parent_class)->constructor (type, 137 n_construct_params, 138 construct_params); 139 engine->set_parent_class(parent_class); 140 141 const gchar *engine_name = ibus_engine_get_name ((IBusEngine *) engine); 142 g_assert (engine_name); 143 // 144 return (GObject *)engine; 145 } 146 } // extern "C" 147 148