74
74
static void* PuncCreate(FcitxInstance* instance);
75
75
static boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal);
76
76
static boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal);
77
static void* PuncGetPunc(void* a, FcitxModuleFunctionArg arg);
78
static void* PuncGetPunc2(void* a, FcitxModuleFunctionArg arg);
79
77
static void TogglePuncState(void *arg);
80
78
static boolean GetPuncState(void *arg);
81
79
static void ReloadPunc(void *arg);
89
87
static void* PuncWhichCopy(void* arg, void* data, void* src);
90
88
static void PuncWhichFree(void* arg, void* data);
90
DECLARE_ADDFUNCTIONS(Punc)
93
92
typedef struct _FcitxPuncState {
94
93
char cLastIsAutoConvert;
110
109
void* PuncCreate(FcitxInstance* instance)
112
111
FcitxPuncState* puncState = fcitx_utils_malloc0(sizeof(FcitxPuncState));
113
FcitxAddon* puncaddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_PUNC_NAME);
114
112
puncState->owner = instance;
115
113
LoadPuncDict(puncState);
116
114
FcitxKeyFilterHook hk;
142
140
FcitxInstanceRegisterInputUnFocusHook(instance, hook);
144
FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE, PuncLanguageChanged, puncState);
142
FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE,
143
PuncLanguageChanged, puncState);
146
145
FcitxProfile* profile = FcitxInstanceGetProfile(instance);
147
146
FcitxUIRegisterStatus(instance, puncState, "punc",
148
profile->bUseWidePunc ? _("Full width punct") : _("Latin punct"),
149
_("Toggle Full Width Punctuation"), TogglePuncState, GetPuncState);
151
puncState->slot = FcitxInstanceAllocDataForIC(instance, PuncWhichAlloc, PuncWhichCopy, PuncWhichFree, puncState);
153
AddFunction(puncaddon, PuncGetPunc);
154
AddFunction(puncaddon, PuncGetPunc2);
147
profile->bUseWidePunc ? _("Full width punct") :
149
_("Toggle Full Width Punctuation"), TogglePuncState,
152
puncState->slot = FcitxInstanceAllocDataForIC(instance, PuncWhichAlloc,
153
PuncWhichCopy, PuncWhichFree,
156
FcitxPuncAddFunctions(instance);
155
157
return puncState;
158
void* PuncWhichAlloc(void* arg)
160
void* PuncWhichAlloc(void *arg)
160
FcitxPunc* puncState = arg;
161
PuncWhich* which = fcitx_utils_new(PuncWhich);
162
FcitxPunc *puncState = arg;
163
PuncWhich *which = fcitx_utils_new(PuncWhich);
162
164
which->lastPunc = puncState->curPunc;
163
165
which->bitset = fcitx_bitset_new(256);
167
169
void* PuncWhichCopy(void* arg, void* data, void* src)
169
PuncWhich* which = data;
170
PuncWhich* whichsrc = src;
172
PuncWhich *which = data;
173
PuncWhich *whichsrc = src;
171
174
which->lastPunc = whichsrc->lastPunc;
172
175
memcpy(which->bitset, whichsrc->bitset, fcitx_bitset_size(256));
197
201
FcitxUISetStatusVisable (puncState->owner, "punc", puncState->curPunc != NULL) ;
200
void* PuncGetPunc(void* a, FcitxModuleFunctionArg arg)
202
FcitxPuncState* puncState = (FcitxPuncState*) a;
203
int *key = arg.args[0];
204
return GetPunc(puncState, *key);
208
void* PuncGetPunc2(void* a, FcitxModuleFunctionArg arg)
210
FcitxPuncState* puncState = (FcitxPuncState*) a;
211
int *key = arg.args[0];
212
char** p1 = arg.args[1];
213
char** p2 = arg.args[2];
215
WidePunc *curPunc = puncState->curPunc;
205
PuncGetPunc2(FcitxPuncState *puncState, int key, char **p1, char **p2)
208
WidePunc *curPunc = puncState->curPunc;
220
213
while (curPunc[iIndex].ASCII) {
221
if (curPunc[iIndex].ASCII == *key) {
214
if (curPunc[iIndex].ASCII == key) {
223
216
*p1 = curPunc[iIndex].strWidePunc[0];
224
217
if (curPunc[iIndex].iCount > 1 && p2)
253
244
fcitx_bitset_clear(puncWhich->bitset);
256
boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal)
247
boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state,
248
INPUT_RETURN_VALUE* retVal)
258
if (!FcitxHotkeyIsHotKeySimple(sym, state))
261
FcitxPuncState* puncState = (FcitxPuncState*) arg;
262
if (!FcitxHotkeyIsHotKeyDigit(sym, state) && !IsHotKeyPunc(sym, state))
250
FCITX_UNUSED(retVal);
251
FcitxPuncState *puncState = (FcitxPuncState*)arg;
252
if (FcitxHotkeyIsHotKeySimple(sym, state) &&
253
!FcitxHotkeyIsHotKeyDigit(sym, state) && !IsHotKeyPunc(sym, state))
263
254
puncState->bLastIsNumber = false;
278
268
if (*retVal != IRV_TO_PROCESS)
271
FcitxCandidateWordList *candList = FcitxInputStateGetCandidateList(input);
272
if (FcitxCandidateWordGetListSize(candList) != 0) {
273
if (FcitxCandidateWordGetHasGoneToNextPage(candList) &&
274
FcitxHotkeyIsHotKey(sym, state,
275
FcitxConfigPrevPageKey(instance, config))) {
279
* comparing with upper case, if paging is occupied,
280
* punc will not let next page pass
282
if (FcitxHotkeyIsHotKey(sym, state,
283
FcitxConfigNextPageKey(instance, config))) {
281
288
FcitxKeySym origsym = sym;
282
289
sym = FcitxHotkeyPadToMain(sym);
283
290
if (profile->bUseWidePunc) {
285
291
if (puncState->bLastIsNumber && config->bEngPuncAfterNumber
286
292
&& (FcitxHotkeyIsHotKey(origsym, state, FCITX_PERIOD)
287
293
|| FcitxHotkeyIsHotKey(origsym, state, FCITX_SEMICOLON)
302
308
FcitxInputStateGetOutputString(input)[0] = '\0';
303
309
INPUT_RETURN_VALUE ret = IRV_TO_PROCESS;
304
310
if (!FcitxInputStateGetIsInRemind(input))
305
ret = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
311
ret = FcitxCandidateWordChooseByTotalIndex(FcitxInputStateGetCandidateList(input), 0);
307
313
/* if there is nothing to commit */
308
314
if (ret == IRV_TO_PROCESS) {
342
348
puncState->cLastIsAutoConvert = 0;
343
349
*retVal = IRV_DO_NOTHING;
345
} else if (FcitxHotkeyIsHotKeySimple(sym, state)) {
346
if (FcitxHotkeyIsHotKeyDigit(sym, state))
347
puncState->bLastIsNumber = true;
349
puncState->bLastIsNumber = false;
351
} else if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
352
puncState->bLastIsNumber = true;
354
puncState->bLastIsNumber = false;
353
357
puncState->cLastIsAutoConvert = 0;
517
521
* 如果该字符不在标点符号集中,则返回NULL
519
char *GetPunc(FcitxPuncState* puncState, int iKey)
524
GetPunc(FcitxPuncState *puncState, int iKey)
523
WidePunc *curPunc = puncState->curPunc;
528
WidePunc *curPunc = puncState->curPunc;
526
return (char *) NULL;
528
533
while (curPunc[iIndex].ASCII) {
529
534
if (curPunc[iIndex].ASCII == iKey) {
530
pPunc = curPunc[iIndex].strWidePunc[GetPuncWhich(puncState, &curPunc[iIndex])];
535
pPunc = curPunc[iIndex].strWidePunc[GetPuncWhich(puncState,
531
537
SetPuncWhich(puncState, &curPunc[iIndex]);
537
return (char *) NULL;
540
546
void TogglePuncState(void* arg)
545
551
profile->bUseWidePunc = !profile->bUseWidePunc;
547
553
FcitxUISetStatusString(puncState->owner, "punc",
548
profile->bUseWidePunc ? _("Full width punct") : _("Latin punct"),
549
_("Toggle Full Width Punctuation"));
554
profile->bUseWidePunc ? _("Full width punct") :
556
_("Toggle Full Width Punctuation"));
550
557
FcitxProfileSave(profile);