1 /***************************************************************************
2  *   Copyright (C) 2010~2010 by CSSlayer                                   *
3  *   wengxt@gmail.com                                                      *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.              *
19  ***************************************************************************/
20 
21 /**
22  * @addtogroup Fcitx
23  * @{
24  */
25 
26 /**
27  * @file hook.h
28  * Register function to be called automatically.
29  */
30 
31 #ifndef _HOOK_H
32 #define _HOOK_H
33 #include <fcitx-config/fcitx-config.h>
34 #include <fcitx-config/hotkey.h>
35 #include <fcitx/ime.h>
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41     /**
42      * key filter function
43      **/
44     typedef boolean(*FcitxKeyFilter)(void* arg, FcitxKeySym sym,
45                                      unsigned int state,
46                                      INPUT_RETURN_VALUE *retval
47                                     );
48 
49     /**
50      * string filter function
51      **/
52 
53     typedef char* (*FcitxStringFilter)(void* arg, const char* in);
54 
55     /**
56      * ime event hook function
57      **/
58     typedef void (*FcitxIMEventHookFunc)(void* arg);
59 
60     /**
61      * ic event hook function
62      **/
63     typedef void (*FcitxICEventHookFunc)(void* arg, struct _FcitxInputContext* ic);
64 
65     /**
66      * ui status changed hook function
67      **/
68     typedef void (*FcitxUIStatusHookFunc)(void* arg, const char* statusName);
69 
70     /**
71      * Hotkey process struct
72      **/
73     typedef struct _FcitxHotkeyHook {
74         /**
75          * Pointer to fcitx hotkeys, fcitx hotkey is length 2 array.
76          **/
77         FcitxHotkey* hotkey;
78         /**
79          * Function to be called while hotkey is pressed.
80          *
81          * @return INPUT_RETURN_VALUE*
82          **/
83         INPUT_RETURN_VALUE(*hotkeyhandle)(void*);
84         /**
85          * Argument
86          **/
87         void* arg;
88     } FcitxHotkeyHook;
89 
90     /**
91      * Key filter hook
92      **/
93     typedef struct _FcitxKeyFilterHook {
94         /**
95          * Key filter function
96          **/
97         FcitxKeyFilter func;
98         /**
99          * extra argument for filter function
100          **/
101         void *arg;
102     } FcitxKeyFilterHook;
103 
104     /**
105      * Hook for string filter, this hook can change the output string.
106      **/
107     typedef struct _FcitxStringFilterHook {
108         /**
109          * Filter function
110          **/
111         FcitxStringFilter func;
112         /**
113          * Extra argument for the filter function.
114          **/
115         void *arg;
116     } FcitxStringFilterHook;
117 
118     /**
119      * IME Event hook for Reset, Trigger On/Off, Focus/Unfocus
120      **/
121     typedef struct _FcitxIMEventHook {
122         FcitxIMEventHookFunc func; /**< callback function */
123         void *arg; /**< argument for callback */
124     } FcitxIMEventHook;
125 
126     /**
127      * IC Event hook
128      **/
129     typedef struct _FcitxICEventHook {
130         FcitxICEventHookFunc func; /**< callback function */
131         void *arg; /**< argument for callback */
132     } FcitxICEventHook;
133 
134     /**
135      * UI Event hook
136      **/
137     typedef struct _FcitxUIStatusHook {
138         FcitxUIStatusHookFunc func; /**< callback function */
139         void *arg; /**< argument for callback */
140     } FcitxUIStatusHook;
141 
142     /**
143      * register pre input filter
144      *
145      * @param instance fcitx instance
146      * @param hook new hook
147      * @return void
148      **/
149     void FcitxInstanceRegisterPreInputFilter(struct _FcitxInstance* instance, FcitxKeyFilterHook hook) ;
150     /**
151      * register post input filter
152      *
153      * @param instance fcitx instance
154      * @param hook new hook
155      * @return void
156      **/
157     void FcitxInstanceRegisterPostInputFilter(struct _FcitxInstance* instance, FcitxKeyFilterHook hook);
158     /**
159      * register pre release input filter
160      *
161      * @param instance fcitx instance
162      * @param hook new hook
163      * @return void
164      *
165      * @since 4.2.8
166      **/
167     void FcitxInstanceRegisterPreReleaseInputFilter(struct _FcitxInstance* instance, FcitxKeyFilterHook hook) ;
168     /**
169      * register post release input filter
170      *
171      * @param instance fcitx instance
172      * @param hook new hook
173      * @return void
174      *
175      * @since 4.2.8
176      **/
177     void FcitxInstanceRegisterPostReleaseInputFilter(struct _FcitxInstance* instance, FcitxKeyFilterHook hook);
178     /**
179      * register ouput string filter
180      *
181      * @param instance fcitx instance
182      * @param hook new hook
183      * @return void
184      **/
185     void FcitxInstanceRegisterOutputFilter(struct _FcitxInstance* instance, FcitxStringFilterHook hook);
186     /**
187      * register hotkey
188      *
189      * @param instance fcitx instance
190      * @param hook new hook
191      * @return void
192      **/
193     void FcitxInstanceRegisterHotkeyFilter(struct _FcitxInstance* instance, FcitxHotkeyHook hook);
194     /**
195      * register reset input hook
196      *
197      * @param instance fcitx instance
198      * @param hook new hook
199      * @return void
200      **/
201     void FcitxInstanceRegisterResetInputHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
202     /**
203      * register trigger on hook
204      *
205      * @param instance fcitx instance
206      * @param hook new hook
207      * @return void
208      **/
209     void FcitxInstanceRegisterTriggerOnHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
210     /**
211      * register trigger off hook
212      *
213      * @param instance fcitx instance
214      * @param hook new hook
215      * @return void
216      **/
217     void FcitxInstanceRegisterTriggerOffHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
218     /**
219      * register focus in hook
220      *
221      * @param instance fcitx instance
222      * @param hook new hook
223      * @return void
224      **/
225     void FcitxInstanceRegisterInputFocusHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
226     /**
227      * register focus out hook
228      *
229      * @param instance fcitx instance
230      * @param hook new hook
231      * @return void
232      **/
233     void FcitxInstanceRegisterInputUnFocusHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
234     /**
235      * register im changed hook
236      *
237      * @param instance fcitx instance
238      * @param hook new hook
239      * @return void
240      **/
241     void FcitxInstanceRegisterIMChangedHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
242 
243     /**
244      * register update candidate word hook
245      *
246      * @param instance fcitx instance
247      * @param hook new hook
248      * @return void
249      **/
250     void FcitxInstanceRegisterUpdateCandidateWordHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
251 
252     /**
253      * register update input method list hook
254      *
255      * @param instance fcitx instance
256      * @param hook new hook
257      * @return void
258      **/
259     void FcitxInstanceRegisterUpdateIMListHook(struct _FcitxInstance* instance, FcitxIMEventHook hook);
260 
261     /**
262      * process output filter, return string is malloced
263      *
264      * @param instance fcitx instance
265      * @param in input string
266      * @return char*
267      **/
268     char* FcitxInstanceProcessOutputFilter(struct _FcitxInstance* instance, const char *in);
269 
270     /**
271      * process output filter, return string is malloced
272      *
273      * @param instance fcitx instance
274      * @param in input string
275      * @return char*
276      **/
277     char* FcitxInstanceProcessCommitFilter(struct _FcitxInstance* instance, const char *in);
278 
279     /**
280      * register ouput string filter
281      *
282      * @param instance fcitx instance
283      * @param hook new hook
284      * @return void
285      *
286      * @since 4.2.0
287      **/
288     void FcitxInstanceRegisterCommitFilter(struct _FcitxInstance* instance, FcitxStringFilterHook hook);
289 
290     /**
291      * register a hook for watching when ic status changed
292      *
293      * @param instance fcitx instance
294      * @param hook new hook
295      * @return void
296      *
297      * @since 4.2.6
298      **/
299     void FcitxInstanceRegisterICStateChangedHook(struct _FcitxInstance* instance, FcitxICEventHook hook);
300 
301     /**
302      * register a hook for watching when ui status changed
303      *
304      * @param instance fcitx instance
305      * @param hook new hook
306      * @return void
307      *
308      * @since TBD
309      **/
310     void FcitxInstanceRegisterUIStatusChangedHook(struct _FcitxInstance* instance, FcitxUIStatusHook hook);
311 
312     boolean FcitxDummyReleaseInputHook(void* arg, FcitxKeySym sym,
313                                         unsigned int state,
314                                         INPUT_RETURN_VALUE *retval);
315 
316 
317 #ifdef __cplusplus
318 }
319 #endif
320 
321 #endif
322 /**
323  * @}
324  */
325 // kate: indent-mode cstyle; space-indent on; indent-width 0;
326