1 /*************************************************************************** 2 * Copyright (C) 2010~2012 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 #ifndef _FCITX_CONTEXT_H_ 27 #define _FCITX_CONTEXT_H_ 28 29 #include <fcitx/instance.h> 30 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /** context callback function prototype */ 36 typedef void (*FcitxContextCallback)(void* arg, const void* value); 37 38 /** fcitx context type */ 39 typedef struct _FcitxContext FcitxContext; 40 41 /** fcitx context flag */ 42 typedef enum _FcitxContextFlag { 43 FCF_None = 0, 44 FCF_ResetOnInputMethodChange = (1 << 0) 45 } FcitxContextFlag; 46 47 /** fcitx context value type */ 48 typedef enum _FcitxContextType { 49 FCT_Hotkey, 50 FCT_String, 51 FCT_Void, 52 FCT_Boolean 53 } FcitxContextType; 54 55 /** alternative prevpage key, if this input method requires different key for paging */ 56 #define CONTEXT_ALTERNATIVE_PREVPAGE_KEY "CONTEXT_ALTERNATIVE_PREVPAGE_KEY" 57 /** alternative nextpage key, if this input method requires different key for paging */ 58 #define CONTEXT_ALTERNATIVE_NEXTPAGE_KEY "CONTEXT_ALTERNATIVE_NEXTPAGE_KEY" 59 /** current input method language */ 60 #define CONTEXT_IM_LANGUAGE "CONTEXT_IM_LANGUAGE" 61 /** current input method preferred layout, requires fcitx-xkb to really works */ 62 #define CONTEXT_IM_KEYBOARD_LAYOUT "CONTEXT_IM_KEYBOARD_LAYOUT" 63 /** disable built-in autoeng module */ 64 #define CONTEXT_DISABLE_AUTOENG "CONTEXT_DISABLE_AUTOENG" 65 /** disable built-in quichphrase module */ 66 #define CONTEXT_DISABLE_QUICKPHRASE "CONTEXT_DISABLE_QUICKPHRASE" 67 /** show a built-in remind button or not */ 68 #define CONTEXT_SHOW_REMIND_STATUS "CONTEXT_SHOW_REMIND_STATUS" 69 /** disable auto first candidate highlight */ 70 #define CONTEXT_DISABLE_AUTO_FIRST_CANDIDATE_HIGHTLIGHT "CONTEXT_DISABLE_AUTO_FIRST_CANDIDATE_HIGHTLIGHT" 71 /** disable auto first candidate highlight */ 72 #define CONTEXT_DISABLE_FULLWIDTH "CONTEXT_DISABLE_FULLWIDTH" 73 /** disable punc module */ 74 #define CONTEXT_DISABLE_PUNC "CONTEXT_DISABLE_PUNC" 75 76 /** 77 * @brief register a new global context variable 78 * 79 * @param instance fcitx instance 80 * @param key context name 81 * @param type contex value type 82 * @param flag context flag 83 * @return void 84 **/ 85 void FcitxInstanceRegisterWatchableContext(FcitxInstance* instance, const char* key, FcitxContextType type, unsigned int flag ); 86 87 /** 88 * @brief bind a callback function to this context, callback will be called when context value changed. 89 * 90 * @param instance fcitx instance 91 * @param key context name 92 * @param callback callback function 93 * @param arg extra argument to the callback 94 * @return void 95 **/ 96 void FcitxInstanceWatchContext(FcitxInstance* instance, const char* key, FcitxContextCallback callback, void* arg); 97 98 /** 99 * @brief update the value of a context 100 * 101 * @param instance instance 102 * @param key context name 103 * @param value context value 104 * @return void 105 **/ 106 void FcitxInstanceSetContext(FcitxInstance* instance, const char* key, const void* value); 107 /** 108 * @brief get string type context value 109 * 110 * @param instance fcitx instance 111 * @param key contex name 112 * @return const char* 113 **/ 114 const char* FcitxInstanceGetContextString(FcitxInstance* instance, const char* key); 115 /** 116 * @brief get boolean type context value 117 * 118 * @param instance fcitx instance 119 * @param key context name 120 * @return boolean 121 **/ 122 boolean FcitxInstanceGetContextBoolean(FcitxInstance* instance, const char* key); 123 /** 124 * @brief get hotkey type context value 125 * 126 * @param instance fcitx instance 127 * @param key key 128 * @return const FcitxHotkey* 129 **/ 130 const FcitxHotkey* FcitxInstanceGetContextHotkey(FcitxInstance* instance, const char* key); 131 132 static inline const FcitxHotkey* FcitxConfigPrevPageKey(FcitxInstance * instance,FcitxGlobalConfig * fc)133 FcitxConfigPrevPageKey(FcitxInstance *instance, FcitxGlobalConfig *fc) 134 { 135 const FcitxHotkey *prev = FcitxInstanceGetContextHotkey( 136 instance, CONTEXT_ALTERNATIVE_PREVPAGE_KEY); 137 if (!prev) 138 return fc->hkPrevPage; 139 return prev; 140 } 141 142 static inline const FcitxHotkey* FcitxConfigNextPageKey(FcitxInstance * instance,FcitxGlobalConfig * fc)143 FcitxConfigNextPageKey(FcitxInstance *instance, FcitxGlobalConfig *fc) 144 { 145 const FcitxHotkey *next = FcitxInstanceGetContextHotkey( 146 instance, CONTEXT_ALTERNATIVE_NEXTPAGE_KEY); 147 if (!next) 148 return fc->hkNextPage; 149 return next; 150 } 151 152 #ifdef __cplusplus 153 } 154 #endif 155 156 #endif 157 158 /** 159 * @} 160 */ 161