50
51
struct _FcitxPuncState;
51
52
typedef struct _WidePunc {
53
char strWidePunc[MAX_PUNC_NO][MAX_PUNC_LENGTH * UTF8_MAX_LENGTH + 1];
54
char strWidePunc[MAX_PUNC_NO][MAX_PUNC_LENGTH * UTF8_MAX_LENGTH + 1];
58
typedef struct _PuncWhich {
58
63
typedef struct _FcitxPunc {
69
74
static void* PuncCreate(FcitxInstance* instance);
70
75
static boolean PuncPreFilter(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal);
71
76
static boolean ProcessPunc(void* arg, FcitxKeySym sym, unsigned int state, INPUT_RETURN_VALUE* retVal);
72
static void* PuncGetPunc(void* a, FcitxModuleFunctionArg arg);
73
static void* PuncGetPunc2(void* a, FcitxModuleFunctionArg arg);
74
77
static void TogglePuncState(void *arg);
75
78
static boolean GetPuncState(void *arg);
76
79
static void ReloadPunc(void *arg);
80
83
static boolean IsHotKeyPunc(FcitxKeySym sym, unsigned int state);
81
84
static void PuncLanguageChanged(void* arg, const void* value);
86
static void* PuncWhichAlloc(void* arg);
87
static void* PuncWhichCopy(void* arg, void* data, void* src);
88
static void PuncWhichFree(void* arg, void* data);
90
DECLARE_ADDFUNCTIONS(Punc)
83
92
typedef struct _FcitxPuncState {
84
93
char cLastIsAutoConvert;
85
94
boolean bLastIsNumber;
86
95
FcitxInstance* owner;
87
96
FcitxPunc* puncSet;
92
FcitxModule module = {
101
FCITX_DEFINE_PLUGIN(fcitx_punc, module, FcitxModule) = {
101
int ABI_VERSION = FCITX_ABI_VERSION;
103
109
void* PuncCreate(FcitxInstance* instance)
105
111
FcitxPuncState* puncState = fcitx_utils_malloc0(sizeof(FcitxPuncState));
106
FcitxAddon* puncaddon = FcitxAddonsGetAddonByName(FcitxInstanceGetAddons(instance), FCITX_PUNC_NAME);
107
112
puncState->owner = instance;
108
113
LoadPuncDict(puncState);
109
114
FcitxKeyFilterHook hk;
135
140
FcitxInstanceRegisterInputUnFocusHook(instance, hook);
137
FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE, PuncLanguageChanged, puncState);
142
FcitxInstanceWatchContext(instance, CONTEXT_IM_LANGUAGE,
143
PuncLanguageChanged, puncState);
139
145
FcitxProfile* profile = FcitxInstanceGetProfile(instance);
140
146
FcitxUIRegisterStatus(instance, puncState, "punc",
141
profile->bUseWidePunc ? _("Full width punct") : _("Latin punct"),
142
_("Toggle Full Width Punctuation"), TogglePuncState, GetPuncState);
144
AddFunction(puncaddon, PuncGetPunc);
145
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);
146
157
return puncState;
160
void* PuncWhichAlloc(void *arg)
162
FcitxPunc *puncState = arg;
163
PuncWhich *which = fcitx_utils_new(PuncWhich);
164
which->lastPunc = puncState->curPunc;
165
which->bitset = fcitx_bitset_new(256);
169
void* PuncWhichCopy(void* arg, void* data, void* src)
172
PuncWhich *which = data;
173
PuncWhich *whichsrc = src;
174
which->lastPunc = whichsrc->lastPunc;
175
memcpy(which->bitset, whichsrc->bitset, fcitx_bitset_size(256));
179
void PuncWhichFree(void* arg, void* data)
182
PuncWhich *which = data;
149
187
void PuncLanguageChanged(void* arg, const void* value)
151
189
FcitxPuncState* puncState = (FcitxPuncState*) arg;
163
201
FcitxUISetStatusVisable (puncState->owner, "punc", puncState->curPunc != NULL) ;
166
void* PuncGetPunc(void* a, FcitxModuleFunctionArg arg)
168
FcitxPuncState* puncState = (FcitxPuncState*) a;
169
int *key = arg.args[0];
170
return GetPunc(puncState, *key);
174
void* PuncGetPunc2(void* a, FcitxModuleFunctionArg arg)
176
FcitxPuncState* puncState = (FcitxPuncState*) a;
177
int *key = arg.args[0];
178
char** p1 = arg.args[1];
179
char** p2 = arg.args[2];
181
WidePunc *curPunc = puncState->curPunc;
205
PuncGetPunc2(FcitxPuncState *puncState, int key, char **p1, char **p2)
208
WidePunc *curPunc = puncState->curPunc;
186
213
while (curPunc[iIndex].ASCII) {
187
if (curPunc[iIndex].ASCII == *key) {
214
if (curPunc[iIndex].ASCII == key) {
189
216
*p1 = curPunc[iIndex].strWidePunc[0];
190
217
if (curPunc[iIndex].iCount > 1 && p2)
217
while (curPunc[iIndex].ASCII) {
218
curPunc[iIndex].iWhich = 0;
240
FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner);
243
PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot);
244
fcitx_bitset_clear(puncWhich->bitset);
223
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)
225
if (!FcitxHotkeyIsHotKeySimple(sym, state))
228
FcitxPuncState* puncState = (FcitxPuncState*) arg;
229
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))
230
254
puncState->bLastIsNumber = false;
245
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))) {
248
288
FcitxKeySym origsym = sym;
249
289
sym = FcitxHotkeyPadToMain(sym);
250
290
if (profile->bUseWidePunc) {
252
291
if (puncState->bLastIsNumber && config->bEngPuncAfterNumber
253
292
&& (FcitxHotkeyIsHotKey(origsym, state, FCITX_PERIOD)
254
293
|| FcitxHotkeyIsHotKey(origsym, state, FCITX_SEMICOLON)
269
308
FcitxInputStateGetOutputString(input)[0] = '\0';
270
309
INPUT_RETURN_VALUE ret = IRV_TO_PROCESS;
271
310
if (!FcitxInputStateGetIsInRemind(input))
272
ret = FcitxCandidateWordChooseByIndex(FcitxInputStateGetCandidateList(input), 0);
311
ret = FcitxCandidateWordChooseByTotalIndex(FcitxInputStateGetCandidateList(input), 0);
274
313
/* if there is nothing to commit */
275
314
if (ret == IRV_TO_PROCESS) {
309
348
puncState->cLastIsAutoConvert = 0;
310
349
*retVal = IRV_DO_NOTHING;
312
} else if (FcitxHotkeyIsHotKeySimple(sym, state)) {
313
if (FcitxHotkeyIsHotKeyDigit(sym, state))
314
puncState->bLastIsNumber = true;
316
puncState->bLastIsNumber = false;
351
} else if (FcitxHotkeyIsHotKeyDigit(sym, state)) {
352
puncState->bLastIsNumber = true;
354
puncState->bLastIsNumber = false;
320
357
puncState->cLastIsAutoConvert = 0;
486
static inline int GetPuncWhich(FcitxPuncState* puncState, WidePunc* punc)
488
FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner);
491
PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot);
492
if (puncWhich->lastPunc != puncState->curPunc) {
493
fcitx_bitset_clear(puncWhich->bitset);
494
puncWhich->lastPunc = puncState->curPunc;
496
int result = fcitx_bitset_isset(puncWhich->bitset, punc->ASCII) ? 1 : 0;
497
if (result >= punc->iCount)
502
static inline void SetPuncWhich(FcitxPuncState* puncState, WidePunc* punc)
504
FcitxInputContext* ic = FcitxInstanceGetCurrentIC(puncState->owner);
507
PuncWhich* puncWhich = FcitxInstanceGetICData(puncState->owner, ic, puncState->slot);
508
FcitxBitSet* bitset = puncWhich->bitset;
509
if (punc->iCount == 1)
510
fcitx_bitset_unset(bitset, punc->ASCII);
512
if (fcitx_bitset_isset(bitset, punc->ASCII))
513
fcitx_bitset_unset(bitset, punc->ASCII);
515
fcitx_bitset_set(bitset, punc->ASCII);
452
521
* 如果该字符不在标点符号集中,则返回NULL
454
char *GetPunc(FcitxPuncState* puncState, int iKey)
524
GetPunc(FcitxPuncState *puncState, int iKey)
458
WidePunc *curPunc = puncState->curPunc;
528
WidePunc *curPunc = puncState->curPunc;
461
return (char *) NULL;
463
533
while (curPunc[iIndex].ASCII) {
464
534
if (curPunc[iIndex].ASCII == iKey) {
465
pPunc = curPunc[iIndex].strWidePunc[curPunc[iIndex].iWhich];
466
curPunc[iIndex].iWhich++;
467
if (curPunc[iIndex].iWhich >= curPunc[iIndex].iCount)
468
curPunc[iIndex].iWhich = 0;
535
pPunc = curPunc[iIndex].strWidePunc[GetPuncWhich(puncState,
537
SetPuncWhich(puncState, &curPunc[iIndex]);
474
return (char *) NULL;
477
546
void TogglePuncState(void* arg)
482
551
profile->bUseWidePunc = !profile->bUseWidePunc;
484
553
FcitxUISetStatusString(puncState->owner, "punc",
485
profile->bUseWidePunc ? _("Full width punct") : _("Latin punct"),
486
_("Toggle Full Width Punctuation"));
554
profile->bUseWidePunc ? _("Full width punct") :
556
_("Toggle Full Width Punctuation"));
487
557
FcitxProfileSave(profile);