clean up PYConfig.h/cc
[platform/upstream/ibus-libpinyin.git] / src / PYExtEditor.h
1 /* vim:set et ts=4 sts=4:
2  *
3  * ibus-pinyin - The Chinese PinYin engine for IBus
4  *
5  * Copyright (c) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2, or (at your option)
10  * any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 #ifndef __PY_EXT_EDITOR_
22 #define __PY_EXT_EDITOR_
23
24 #include <glib.h>
25
26 typedef struct _IBusEnginePlugin IBusEnginePlugin;
27 typedef struct _lua_command_candidate_t lua_command_candidate_t;
28
29 namespace PY {
30
31
32 class ExtEditor : public Editor {
33 public:
34     ExtEditor (PinyinProperties & props, Config & config);
35
36     virtual gboolean processKeyEvent (guint keyval, guint keycode, guint modifiers);
37     virtual void pageUp (void);
38     virtual void pageDown (void);
39     virtual void cursorUp (void);
40     virtual void cursorDown (void);
41     virtual void update (void);
42     virtual void reset (void);
43     virtual void candidateClicked (guint index, guint button, guint state);
44
45     int loadLuaScript (std::string filename);
46     void resetLuaState (void);
47
48 private:
49     bool updateStateFromInput (void);
50
51     /* Fill lookup table, and update preedit string. */
52     bool fillCommandCandidates (void);
53     bool fillCommandCandidates (std::string prefix);
54     bool fillCommand (std::string command_name, const char * argument);
55
56     bool fillChineseNumber(gint64 num);
57
58     /* Auxiliary functions for lookup table */
59     void clearLookupTable (void);
60     void updateLookupTable (void);
61     gboolean selectCandidateInPage (guint index);
62     gboolean selectCandidate (guint index);
63
64     void updatePreeditText (void);
65     void updateAuxiliaryText (void);
66
67     gboolean processEditKey (guint keyval);
68     gboolean processPageKey (guint keyval);
69     gboolean processLabelKey (guint keyval);
70
71     gboolean processSpace (guint keyval);
72     gboolean processEnter (guint keyval);
73
74     gboolean removeCharBefore (void);
75     gboolean removeCharAfter (void);
76
77     enum LabelMode{
78         LABEL_NONE,
79         LABEL_LIST_NUMBERS,
80         LABEL_LIST_COMMANDS,
81         LABEL_LIST_NONE,
82         LABEL_LIST_DIGIT,
83         LABEL_LIST_ALPHA,
84         LABEL_LIST_SINGLE,
85         LABEL_LAST,
86     };
87     LabelMode m_mode;
88     Pointer<IBusEnginePlugin> m_lua_plugin;
89
90     std::string m_preedit_text;
91     std::string m_auxiliary_text;
92
93     LookupTable m_lookup_table;
94
95     //saved lua extension call results.
96     int m_result_num;
97     const lua_command_candidate_t * m_candidate;
98     GArray * m_candidates;
99
100     const static int m_aux_text_len = 50;
101 };
102
103 };
104 #endif