Add the gtk header file path
[framework/uifw/ise-engine-hangul.git] / src / scim_hangul_imengine.h
1 /** @file scim_hangul_imengine.h
2  */
3
4 /* 
5  * Smart Common Input Method
6  * 
7  * Copyright (C) 2004-2006 Choe Hwanjin
8  * Copyright (c) 2004-2006 James Su <suzhe@tsinghua.org.cn>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23  *
24  * $Id: scim_hangul_imengine.h,v 1.17 2007/05/27 13:08:07 hwanjin Exp $
25  */
26
27 #if !defined (__SCIM_HANGUL_IMENGINE_H)
28 #define __SCIM_HANGUL_IMENGINE_H
29
30 #include <hangul.h>
31
32 using namespace scim;
33
34 enum HangulInputMode
35 {
36     INPUT_MODE_DIRECT,
37     INPUT_MODE_HANGUL,
38     INPUT_MODE_HANJA
39 };
40
41 enum HangulOutputMode
42 {
43     OUTPUT_MODE_SYLLABLE = 0,
44     OUTPUT_MODE_JAMO     = 1 << 1,
45     OUTPUT_MODE_JAMO_EXT = 1 << 2
46 };
47
48 class HangulFactory : public IMEngineFactoryBase
49 {
50     String                   m_uuid;
51     String                   m_name;
52
53     ConfigPointer            m_config;
54
55     String                   m_keyboard_layout;
56
57     bool                     m_always_use_jamo;
58
59     bool                     m_show_candidate_comment;
60     bool                     m_lookup_table_vertical;
61     bool                     m_use_ascii_mode;
62     bool                     m_commit_by_word;
63     bool                     m_hanja_mode;
64
65     KeyEventList             m_hangul_keys;
66     KeyEventList             m_hanja_keys;
67     KeyEventList             m_hanja_mode_keys;
68
69     Connection               m_reload_signal_connection;
70
71     HanjaTable*              m_hanja_table;
72     HanjaTable*              m_symbol_table;
73
74     friend class HangulInstance;
75
76 public:
77     HangulFactory (const ConfigPointer &config);
78
79     virtual ~HangulFactory ();
80
81     virtual WideString  get_name () const;
82     virtual WideString  get_authors () const;
83     virtual WideString  get_credits () const;
84     virtual WideString  get_help () const;
85     virtual String      get_uuid () const;
86     virtual String      get_icon_file () const;
87
88     virtual IMEngineInstancePointer create_instance (const String& encoding, int id = -1);
89
90 private:
91     void reload_config (const ConfigPointer &config);
92 };
93
94 class HangulInstance : public IMEngineInstanceBase
95 {
96     HangulFactory       *m_factory;
97
98     CommonLookupTable    m_lookup_table;
99     std::vector<String>  m_candidate_comments;
100     WideString           m_preedit;
101     WideString           m_surrounding_text;
102
103     KeyEvent             m_prev_key;
104
105     HangulInputContext  *m_hic;
106
107     bool                 m_hangul_mode;
108     int                  m_output_mode;
109
110 public:
111     HangulInstance (HangulFactory *factory,
112                     const String  &encoding,
113                     int            id = -1);
114
115     virtual ~HangulInstance ();
116
117     virtual bool process_key_event (const KeyEvent& key);
118     virtual void move_preedit_caret (unsigned int pos);
119     virtual void select_candidate (unsigned int item);
120     virtual void update_lookup_table_page_size (unsigned int page_size);
121     virtual void lookup_table_page_up ();
122     virtual void lookup_table_page_down ();
123     virtual void reset ();
124     virtual void flush ();
125     virtual void focus_in ();
126     virtual void focus_out ();
127     virtual void trigger_property (const String &property);
128
129 private:
130     bool is_backspace_key (const KeyEvent &key) const {
131         return (key.code == SCIM_KEY_BackSpace);
132     }
133
134     bool is_hangul_key (const KeyEvent &key) const {
135         return match_key_event (m_factory->m_hangul_keys, key);
136     }
137
138     bool is_hanja_key (const KeyEvent &key) const {
139         return match_key_event (m_factory->m_hanja_keys, key);
140     }
141
142     bool is_hanja_mode_key (const KeyEvent &key) const {
143         return match_key_event (m_factory->m_hanja_mode_keys, key);
144     }
145
146     /* preedit string */
147     WideString get_preedit_string () {
148         WideString wstr = m_preedit;
149         const ucschar *str = hangul_ic_get_preedit_string(m_hic);
150         while (*str != 0)
151             wstr.push_back (*str++);
152         return wstr;
153     }
154
155     WideString get_commit_string () {
156         WideString wstr;
157         const ucschar *str = hangul_ic_get_commit_string(m_hic);
158         while (*str != L'\0')
159             wstr.push_back (*str++);
160         return wstr;
161     }
162
163     void hangul_update_preedit_string ();
164
165     bool   use_ascii_mode() {
166         return m_factory->m_use_ascii_mode;
167     }
168
169     bool   is_hangul_mode() {
170         return m_hangul_mode;
171     }
172
173     bool   is_hanja_mode() {
174         return m_factory->m_hanja_mode;
175     }
176
177     void   toggle_hangul_mode();
178     void   toggle_hanja_mode();
179     void   change_keyboard_layout(const String &layout);
180
181     /* property handling */
182     void   register_all_properties();
183
184     /* aux string */
185     void hangul_update_aux_string ();
186
187     /* candidate functions */
188     String get_candidate_string();
189     void   update_candidates ();
190     void   delete_candidates ();
191
192     /* candidate keys */
193     bool   candidate_key_event (const KeyEvent &key);
194
195     /* match key event */
196     bool   match_key_event (const KeyEventList &keys, const KeyEvent &key) const;
197 };
198 #endif
199
200 /*
201 vi:ts=4:nowrap:ai:expandtab
202 */