-
Notifications
You must be signed in to change notification settings - Fork 3
/
gtab.cpp
1886 lines (1536 loc) · 42.8 KB
/
gtab.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2004-2008 Edward Der-Hua Liu, Hsin-Chu, Taiwan
*/
#include <sys/stat.h>
#include <regex.h>
#include "gcin.h"
#include "gtab.h"
#include "pho.h"
#include "gcin-conf.h"
#include "gcin-endian.h"
#include "gtab-buf.h"
#include "tsin.h"
#include "gst.h"
extern gboolean test_mode;
gboolean gtab_phrase_on();
gboolean gtab_disp_partial_match_on(), gtab_vertical_select_on(), gtab_pre_select_on(), gtab_unique_auto_send_on(), gtab_press_full_auto_send_on();
void init_seltab(char ***p);
extern gint64 key_press_time, key_press_time_ctrl;
extern GtkWidget *gwin_gtab;
void hide_gtab_pre_sel();
void gtab_scan_pre_select(gboolean);
extern GTAB_space_pressed_E _gtab_space_auto_first;
extern char *TableDir;
extern INMD *cur_inmd;
extern char **seltab;
#define gtab_full_space_auto_first (_gtab_space_auto_first & (GTAB_space_auto_first_any|GTAB_space_auto_first_full))
#define AUTO_SELECT_BY_PHRASE (gtab_phrase_on())
gboolean use_tsin_sel_win()
{
return gtab_vertical_select_on() && gtab_phrase_pre_select;
}
static gboolean gtab_pre_select_or_partial_on()
{
return gtab_pre_select_on() || (cur_inmd->flag&FLAG_GTAB_DISP_PARTIAL_MATCH)!=0;
}
gboolean same_query_show_pho_win()
{
return poo.same_pho_query_state != SAME_PHO_QUERY_none;
}
gboolean gcin_edit_display_ap_only();
gboolean gtab_has_input()
{
int i;
for(i=0; i < MAX_TAB_KEY_NUM64_6; i++)
if (ggg.inch[i])
return TRUE;
if (same_query_show_pho_win())
return TRUE;
if (ggg.gtab_buf_select)
return TRUE;
if (ggg.gbufN && !gcin_edit_display_ap_only())
return TRUE;
return FALSE;
}
#define tblch(i) tblch2(cur_inmd, i)
int load_phr_ch(INMD *inm, u_char *ch, char *tt)
{
int phrno =((int)(ch[0])<<16)|((int)ch[1]<<8)|ch[2];
int ofs = inm->phridx[phrno], ofs1 = inm->phridx[phrno+1];
// dbg("load_phr j:%d %d %d %d\n", j, phrno, ofs, ofs1);
int len = ofs1 - ofs;
if (len > MAX_CIN_PHR || len <= 0) {
dbg("phrae error %d\n", len);
strcpy(tt,"err");
return 0;
}
memcpy(tt, inm->phrbuf + ofs, len);
tt[len]=0;
return len;
}
static void load_phr(int j, char *tt)
{
u_char *ch = tblch(j);
load_phr_ch(cur_inmd, ch, tt);
}
static int qcmp_strlen(const void *aa, const void *bb)
{
char *a = *((char **)aa), *b = *((char **)bb);
return strlen(a) - strlen(b);
}
void set_key_codes_label(char *s, int better);
void set_page_label(char *s);
static void clear_page_label()
{
set_page_label("");
}
int gtab_key2name(INMD *tinmd, u_int64_t key, char *t, int *rtlen);
int ch_to_gtab_keys(INMD *tinmd, char *ch, u_int64_t keys[])
{
int n = utf8_str_N(ch);
gboolean phrase = n > 1 || !(ch[0] & 0x80);
int i, keysN=0;
for(i=0; i < tinmd->DefChars; i++) {
char *chi = (char *)tblch2(tinmd, i);
if (phrase) {
if ((chi[0] & 0x80))
continue;
char tstr[512];
load_phr_ch(tinmd, (u_char *)chi, tstr);
if (strcmp(tstr, ch))
continue;
} else {
if (!(chi[0] & 0x80))
continue;
if (!utf8_eq(chi, ch))
continue;
}
u_int64_t key = CONVT2(tinmd, i);
keys[keysN++] = key;
}
return keysN;
}
void lookup_gtabn(char *ch, char *out)
{
char outbuf[512];
char *tbuf[128];
int tbufN=0;
INMD *tinmd = &inmd[default_input_method];
if (!tinmd->DefChars)
tinmd = cur_inmd;
if (!tinmd)
return;
gboolean need_disp = FALSE;
if (!out) {
out = outbuf;
need_disp = TRUE;
}
out[0]=0;
int min_klen = 100;
u_int64_t keys[64];
int keysN = ch_to_gtab_keys(tinmd, ch, keys);
int i;
for(i=0; i < keysN; i++) {
int tlen, klen;
char t[CH_SZ * 10 + 1];
klen = gtab_key2name(tinmd, keys[i], t, &tlen);
if (klen < min_klen)
min_klen = klen;
t[tlen]=0;
tbuf[tbufN] = strdup(t);
tbufN++;
}
qsort(tbuf, tbufN, sizeof(char *), qcmp_strlen);
out[0]=0;
for(i=0; i < tbufN; i++) {
#define MAX_DISP_MATCH 40
if (strlen(out) < MAX_DISP_MATCH) {
strcat(out, tbuf[i]);
if (i < tbufN-1)
strcat(out, " |");
}
free(tbuf[i]);
}
if (!out[0] || !need_disp)
return;
set_key_codes_label(out, ggg.ci > min_klen);
void set_key_codes_label_pho(char *s);
set_key_codes_label_pho(out);
}
void lookup_gtab(char *ch)
{
char tt[CH_SZ+1];
utf8cpy(tt, ch);
lookup_gtabn(tt, NULL);
}
void lookup_gtab_out(char *ch, char *out)
{
char tt[CH_SZ+1];
utf8cpy(tt, ch);
lookup_gtabn(tt, out);
}
void free_gtab()
{
int i;
for(i=0; i < inmdN; i++) {
INMD *inp = &inmd[i];
free(inp->tbl); inp->tbl = NULL;
free(inp->tbl64); inp->tbl64 = NULL;
free(inp->phridx); inp->phridx = NULL;
free(inp->phrbuf); inp->phrbuf = NULL;
free(inp->keyname_lookup); inp->keyname_lookup = NULL;
}
free(inmd);
}
char *b1_cat(char *s, char c)
{
char t[2];
t[0]=c;
t[1]=0;
return strcat(s, t);
}
char *bch_cat(char *s, char *ch)
{
char t[CH_SZ + 1];
int len = u8cpy(t, ch);
t[len]=0;
return strcat(s, t);
}
void minimize_win_gtab();
void disp_gtab_sel(char *s);
void ClrSelArea()
{
disp_gtab_sel("");
minimize_win_gtab();
// hide_gtab_pre_sel();
}
void disp_gtab(char *);
void clear_gtab_input_error_color();
static void clr_seltab()
{
int i;
if (!seltab)
return;
for(i=0; i < MAX_SELKEY; i++)
seltab[i][0]=0;
}
void clear_gtab_in_area(), hide_win_gtab();
void ClrIn()
{
#if WIN32
if (test_mode)
return;
#endif
bzero(ggg.inch,sizeof(ggg.inch));
clr_seltab();
ggg.total_matchN=ggg.pg_idx=ggg.more_pg=ggg.wild_mode=ggg.wild_page=ggg.last_idx=ggg.defselN=ggg.exa_match=
ggg.spc_pressed=ggg.ci=ggg.invalid_spc=0;
ggg.sel1st_i=MAX_SELKEY-1;
clear_gtab_in_area();
ggg.last_idx = 0;
if (gcin_pop_up_win && !gtab_has_input() && !tss.pre_selN)
hide_win_gtab();
clear_gtab_input_error_color();
clear_page_label();
// hide_gtab_pre_sel();
}
void hide_win_pho();
void close_gtab_pho_win()
{
if (test_mode)
return;
if (poo.same_pho_query_state != SAME_PHO_QUERY_none) {
poo.same_pho_query_state = SAME_PHO_QUERY_none;
hide_win_pho();
}
}
void gtab_disp_empty(char *tt, int N);
extern int win_gtab_max_key_press;
static void DispInArea()
{
int i;
#if WIN32
if (test_mode)
return;
#endif
// hide_gtab_pre_sel();
// dbg("sel1st:%d\n", ggg.sel1st_i);
if (gcin_display_on_the_spot_key()) {
if (gwin_gtab && GTK_WIDGET_VISIBLE(gwin_gtab) && poo.same_pho_query_state == SAME_PHO_QUERY_none)
hide_win_gtab();
return;
}
char tt[128];
int ttN=0;
if (win_gtab_max_key_press < ggg.ci)
win_gtab_max_key_press = ggg.ci;
for(i=0;i<ggg.ci;i++) {
char *p=(char *)&cur_inmd->keyname[ggg.inch[i] * CH_SZ];
int len;
if (*p & 0x80)
len=utf8cpy(tt+ttN, p);
else {
len = strlen(p);
strcpy(tt+ttN, p);
}
ttN+=len;
}
tt[ttN]=0;
gtab_disp_empty(tt, win_gtab_max_key_press - i);
disp_gtab(tt);
minimize_win_gtab();
}
int get_DispInArea_str(char *out)
{
int outN=0, i;
for(i=0;i<ggg.ci;i++) {
char *p = (char *)&cur_inmd->keyname[ggg.inch[i] * CH_SZ];
if (*p & 0x80)
outN+=u8cpy(out+outN, p);
else {
int len = strlen(p);
memcpy(out+outN, p, len);
outN+=len;
}
}
#if 0
if (outN) {
hide_gtab_pre_sel();
}
#endif
out[outN]=0;
// dbg("get_DispInArea_str\n", out);
return outN;
}
void set_gtab_input_method_name(char *s);
void case_inverse(KeySym *xkey, int shift_m);
extern unich_t *fullchar[];
void start_gtab_pho_query(char *utf8);
void clear_after_put()
{
ClrIn();
ClrSelArea();
}
void add_to_tsin_buf_str(char *str);
gboolean init_in_method(int in_no);
void hide_win_kbm();
void hide_row2_if_necessary()
{
if (!ggg.wild_mode && gtab_hide_row2 || !gtab_disp_key_codes) {
set_key_codes_label(NULL, 0);
}
}
static void putstr_inp(char *p)
{
#if WIN32
if (test_mode)
return;
#endif
clear_page_label();
// dbg("gtab_hide_row2 %d\n", gtab_hide_row2);
hide_row2_if_necessary();
char_play(p);
int to_tsin = (cur_inmd->flag & FLAG_GTAB_SYM_KBM) && inmd[default_input_method].method_type==method_type_TSIN && tss.c_len;
if (utf8_str_N(p) > 1 || !(p[0]&128)) {
if (gtab_disp_key_codes && !gtab_hide_row2 || ggg.wild_mode)
lookup_gtabn(p, NULL);
#if USE_TSIN
if (to_tsin) {
add_to_tsin_buf_str(p);
}
else
#endif
send_text(p);
}
else {
if (poo.same_pho_query_state == SAME_PHO_QUERY_gtab_input) {
poo.same_pho_query_state = SAME_PHO_QUERY_pho_select;
start_gtab_pho_query(p);
ClrIn();
ClrSelArea();
return;
}
if (gtab_disp_key_codes && !gtab_hide_row2 || ggg.wild_mode)
lookup_gtab(p);
if (to_tsin)
add_to_tsin_buf_str(p);
else
send_utf8_ch(p);
}
clear_after_put();
if ((cur_inmd->flag & FLAG_GTAB_SYM_KBM)) {
extern int win_kbm_inited, b_show_win_kbm;
init_in_method(default_input_method);
if (win_kbm_inited && !b_show_win_kbm)
hide_win_kbm();
}
}
#define swap(a,b) { tt=a; a=b; b=tt; }
static u_int vmask[]=
{ 0,
(0x3f<<24),
(0x3f<<24)|(0x3f<<18),
(0x3f<<24)|(0x3f<<18)|(0x3f<<12),
(0x3f<<24)|(0x3f<<18)|(0x3f<<12)|(0x3f<<6),
(0x3f<<24)|(0x3f<<18)|(0x3f<<12)|(0x3f<<6)|0x3f
};
static u_int vmask_7[]=
{ 0,
(0x7f<<21),
(0x7f<<21)|(0x7f<<14),
(0x7f<<21)|(0x7f<<14)|(0x7f<<7),
(0x7f<<21)|(0x7f<<14)|(0x7f<<7)|0x7f,
};
#define KKK ((u_int64_t)0x3f)
static u_int64_t vmask64[]=
{ 0,
(KKK<<54),
(KKK<<54)|(KKK<<48),
(KKK<<54)|(KKK<<48)|(KKK<<42),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30)|(KKK<<24),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30)|(KKK<<24)|(KKK<<18),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30)|(KKK<<24)|(KKK<<18)|(KKK<<12),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30)|(KKK<<24)|(KKK<<18)|(KKK<<12)|(KKK<<6),
(KKK<<54)|(KKK<<48)|(KKK<<42)|(KKK<<36)|(KKK<<30)|(KKK<<24)|(KKK<<18)|(KKK<<12)|(KKK<<6)|KKK
};
#define KKK7 ((u_int64_t)0x7f)
static u_int64_t vmask64_7[]=
{ 0,
(KKK7<<56),
(KKK7<<56)|(KKK7<<49),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35)|(KKK7<<28),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35)|(KKK7<<28)|(KKK7<<21),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35)|(KKK7<<28)|(KKK7<<21)|(KKK7<<14),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35)|(KKK7<<28)|(KKK7<<21)|(KKK7<<14)|(KKK7<<7),
(KKK7<<56)|(KKK7<<49)|(KKK7<<42)|(KKK7<<35)|(KKK7<<28)|(KKK7<<21)|(KKK7<<14)|(KKK7<<7)|KKK7,
};
#define KEY_N (cur_inmd->max_keyN)
static gboolean tblidx_to_str(int tblidx, char out[])
{
u_char *tbl_ch = tblch(tblidx);
if (tbl_ch[0] < 0x80) {
load_phr(tblidx, out);
return TRUE;
}
int len = u8cpy(out, (char *)tbl_ch);
out[len] = 0;
return FALSE;
}
static gboolean load_seltab(int tblidx, int seltabidx)
{
return tblidx_to_str(tblidx, seltab[seltabidx]);
}
static char* load_tblidx(int tblidx)
{
char tt[MAX_CIN_PHR];
u_char *tbl_ch = tblch(tblidx);
if (tbl_ch[0] < 0x80) {
load_phr(tblidx, tt);
} else {
int len = u8cpy(tt, (char *)tbl_ch);
tt[len] = 0;
}
return strdup(tt);
}
void set_gtab_input_error_color();
static void bell_err()
{
if (test_mode)
return;
bell();
set_gtab_input_error_color();
}
gboolean cmp_inmd_idx(regex_t *reg, int idx)
{
u_int64_t kk=CONVT2(cur_inmd, idx);
char ts[32];
int tsN=0;
ts[tsN++]= ' ';
int i;
for(i=0; i < KEY_N; i++) {
char c = (kk >> (LAST_K_bitN - i*cur_inmd->keybits)) & cur_inmd->kmask;
if (!c)
break;
ts[tsN++] = c + '0';
}
ts[tsN++]= ' ';
ts[tsN]=0;
return regexec(reg, ts, 0, 0, 0);
}
int page_len()
{
return (_gtab_space_auto_first & GTAB_space_auto_first_any) ?
cur_inmd->M_DUP_SEL+1:cur_inmd->M_DUP_SEL;
}
static void page_no_str(char tstr[])
{
if (ggg.wild_mode || ggg.gtab_buf_select) {
int pgN = (ggg.total_matchN + cur_inmd->M_DUP_SEL - 1) / cur_inmd->M_DUP_SEL;
if (pgN < 2)
return;
int pg = ggg.gtab_buf_select ? ggg.pg_idx : ggg.wild_page;
sprintf(tstr, "%d/%d", pg /cur_inmd->M_DUP_SEL + 1, pgN);
} else {
int pgN = (ggg.E1 - ggg.S1 + page_len() - 1) /page_len();
if (pgN < 2)
return;
sprintf(tstr, "%d/%d", (ggg.pg_idx - ggg.S1)/page_len()+1, pgN);
}
}
char *htmlspecialchars(char *s, char out[])
{
char *tstr=g_markup_escape_text(s, -1);
strcpy(out, tstr);
g_free(tstr);
return out;
}
void disp_selection0(gboolean phrase_selected, gboolean force_disp)
{
char pgstr[32];
pgstr[0]=0;
page_no_str(pgstr);
if (!gtab_vertical_select_on()) {
if (ggg.more_pg)
set_page_label(pgstr);
else
clear_page_label();
}
char tt[4096];
tt[0]=0;
char uu[MAX_CIN_PHR];
int ofs;
if (!ggg.wild_mode && ggg.exa_match && (_gtab_space_auto_first & GTAB_space_auto_first_any)) {
strcat(tt, htmlspecialchars(seltab[0], uu));
if (gtab_vertical_select_on())
strcat(tt, "\n");
else
strcat(tt, " ");
ofs = 1;
} else {
ofs = 0;
}
int i,max_i;
for(max_i = cur_inmd->M_DUP_SEL + ofs-1; max_i>=0; max_i--)
if (seltab[max_i][0])
break;
for(i=ofs; i<= max_i; i++) {
if (seltab[i][0]) {
char selback[MAX_CIN_PHR+16];
htmlspecialchars(seltab[i], selback);
utf8cpy(uu, &cur_inmd->selkey[i - ofs]);
char vvv[16];
char www[1024];
sprintf(www, "<span foreground=\"%s\">%s</span>", gcin_sel_key_color, htmlspecialchars(uu, vvv));
strcat(tt, www);
if (gtab_vertical_select_on())
strcat(tt, " ");
if (phrase_selected && i==ggg.sel1st_i) {
strcat(tt, "<span foreground=\"red\">");
strcat(strcat(tt, selback), " ");
strcat(tt, "</span>");
} else {
char uu[MAX_CIN_PHR];
if (gtab_vertical_select_on()) {
utf8cpy_bytes(uu, selback, 120);
strcat(tt, uu);
} else {
strcat(strcat(tt, selback), " ");
}
}
if (gtab_vertical_select_on())
strcat(tt, "\n");
} else {
extern gboolean b_use_full_space;
if (!gtab_vertical_select_on() && gtab_disp_partial_match_on()) {
if (b_use_full_space)
strcat(tt, _(_L(" ")));
else {
strcat(tt, " ");
}
}
}
}
if (gtab_vertical_select_on() && pgstr[0]) {
char tstr2[16];
sprintf(tstr2, "(%s)", pgstr);
strcat(tt, tstr2);
}
int len = strlen(tt);
if (len && tt[len-1] == '\n')
tt[len-1] = 0;
if (gtab_pre_select_or_partial_on() || ggg.wild_mode || ggg.spc_pressed || ggg.last_full || force_disp) {
disp_gtab_sel(tt);
}
}
void disp_selection(gboolean phrase_selected)
{
disp_selection0(phrase_selected, FALSE);
}
void wildcard()
{
int i,t, wild_ofs=0;
int found=0;
regex_t reg;
ClrSelArea();
clr_seltab();
/* printf("wild %d %d %d %d\n", ggg.inch[0], ggg.inch[1], ggg.inch[2], ggg.inch[3]); */
ggg.defselN=0;
char regstr[32];
int regstrN=0;
regstr[regstrN++]=' ';
for(i=0; i < KEY_N; i++) {
if (!ggg.inch[i])
break;
if (ggg.inch[i] == cur_inmd->WILD_STAR) {
regstr[regstrN++]='.';
regstr[regstrN++]='*';
} else
if (ggg.inch[i] == cur_inmd->WILD_QUES) {
regstr[regstrN++]='.';
} else {
char c = ggg.inch[i] + '0'; // start from '0'
if (strchr("*.\\()[]", c))
regstr[regstrN++] = '\\';
regstr[regstrN++]=c;
}
}
regstr[regstrN++]=' ';
regstr[regstrN]=0;
// dbg("regstr %s\n", regstr);
if (regcomp(®, regstr, 0)) {
dbg("regcomp failed\n");
return;
}
for(t=0; t< cur_inmd->DefChars && ggg.defselN < cur_inmd->M_DUP_SEL; t++) {
if (cmp_inmd_idx(®, t))
continue;
if (wild_ofs >= ggg.wild_page) {
load_seltab(t, ggg.defselN);
ggg.defselN++;
} else
wild_ofs++;
found=1;
} /* for t */
if (!found) {
bell_err();
} else
if (!ggg.wild_page) {
ggg.total_matchN = 0;
for(t=0; t< cur_inmd->DefChars; t++)
if (!cmp_inmd_idx(®, t))
ggg.total_matchN++;
}
if (ggg.total_matchN > cur_inmd->M_DUP_SEL)
ggg.more_pg = 1;
regfree(®);
disp_selection(FALSE);
}
static char *ptr_selkey(KeySym key)
{
if (key>= XK_KP_0 && key<= XK_KP_9)
key-= XK_KP_0 - '0';
return strchr(cur_inmd->selkey, key);
}
void init_gtab_pho_query_win();
int feedkey_pho(KeySym xkey, int state);
void set_gtab_target_displayed()
{
close_gtab_pho_win();
}
gboolean is_gtab_query_mode()
{
return poo.same_pho_query_state == SAME_PHO_QUERY_pho_select;
}
void reset_gtab_all()
{
if (!cur_inmd)
return;
ClrIn();
ClrSelArea();
}
static gboolean has_wild_card()
{
int i;
for(i=0; i < cur_inmd->MaxPress; i++)
if (ggg.inch[i]>= cur_inmd->WILD_QUES) {
return TRUE;
}
return FALSE;
}
static void proc_wild_disp()
{
DispInArea();
ggg.wild_page = 0;
wildcard();
disp_selection(0);
}
gboolean full_char_proc(KeySym keysym);
void insert_gbuf_cursor_char(char ch);
gboolean gtab_pre_select_shift(KeySym key, int kbstate);
gboolean shift_char_proc(KeySym key, int kbstate)
{
if (key >= 127)
return FALSE;
#if 0
if (kbstate & LockMask) {
if (key >= 'a' && key <= 'z')
key-=0x20;
} else {
if (key >= 'A' && key <= 'Z')
key+=0x20;
}
#endif
if (gtab_pre_select_shift(key, kbstate))
return TRUE;
if (current_CS->b_half_full_char)
return full_char_proc(key);
if (ggg.gbufN)
insert_gbuf_cursor_char(key);
else
send_ascii(key);
return TRUE;
}
extern GtkWidget *gwin_pho;
gboolean feed_phrase(KeySym ksym, int state);
int gtab_buf_backspace();
gboolean output_gbuf();
int show_buf_select();
void gbuf_next_pg(), gbuf_prev_pg();
void show_win_gtab();
int gbuf_cursor_left();
int gbuf_cursor_right();
int gbuf_cursor_home();
int gbuf_cursor_end();
int gtab_buf_delete();
void set_gbuf_c_sel(int v);
void set_gtab_user_head();
KeySym keypad_proc(KeySym xkey);
void save_gtab_buf_phrase(KeySym key);
gboolean save_gtab_buf_shift_enter();
gboolean win_sym_page_up(), win_sym_page_down();
u_int64_t vmaskci;
gboolean gtab_pre_select_idx(int c);
void save_CS_current_to_temp();
void disp_tray_icon();
gboolean feedkey_gtab(KeySym key, int kbstate)
{
int i,j=0;
int inkey=0;
char *pselkey= NULL;
gboolean phrase_selected = FALSE;
char seltab_phrase[MAX_SELKEY];
gboolean is_keypad = FALSE;
gboolean shift_m = (kbstate & ShiftMask) > 0;
gboolean ctrl_m = (kbstate & ControlMask) > 0;
int caps_eng_tog = tsin_chinese_english_toggle_key == TSIN_CHINESE_ENGLISH_TOGGLE_KEY_CapsLock;
gboolean capslock_on = (kbstate&LockMask);
gboolean is_dayi = !strncmp(cur_inmd->filename, "dayi", 4);
bzero(seltab_phrase, sizeof(seltab_phrase));
// dbg("uuuuu %x %x shift,ctrl:%d,%d\n", key, kbstate, shift_m, ctrl_m);
if (!cur_inmd)
return 0;
#if UNIX
if (key == XK_Caps_Lock)
capslock_on = !capslock_on; // X11 caplock is not on/off immediately
#endif
if (caps_eng_tog) {
gboolean new_tsin_pho_mode =!capslock_on;
if (current_CS->tsin_pho_mode != new_tsin_pho_mode) {
current_CS->tsin_pho_mode = new_tsin_pho_mode;
save_CS_current_to_temp();
disp_tray_icon();
}
}
if (cur_inmd && (cur_inmd->flag & FLAG_GTAB_SYM_KBM))
current_CS->tsin_pho_mode = TRUE;
if ((kbstate & (Mod1Mask|Mod4Mask|Mod5Mask|ControlMask))==ControlMask
&& key>='1' && key<='9' && ggg.gbufN) {
save_gtab_buf_phrase(key);
return 1;
}
if (ggg.gbufN && key==XK_Tab)
return 1;
if ((key==XK_Shift_L||key==XK_Shift_R) && !key_press_time) {
key_press_time = current_time();
key_press_time_ctrl = 0;
} else
if ((key==XK_Control_L||key==XK_Control_R) && !key_press_time_ctrl && tss.pre_selN) {
key_press_time_ctrl = current_time();
return TRUE;
} else {
key_press_time_ctrl = 0;
key_press_time = 0;
}
if (kbstate & (Mod1Mask|Mod4Mask|Mod5Mask|ControlMask)) {
return 0;
}
if (poo.same_pho_query_state == SAME_PHO_QUERY_pho_select)
return feedkey_pho(key, 0);
if (poo.same_pho_query_state == SAME_PHO_QUERY_none && gwin_pho &&
GTK_WIDGET_VISIBLE(gwin_pho))
hide_win_pho();
if (!tsin_pho_mode()) {
if (key < 0x20 || key>=0x7f)
goto shift_proc;
if (capslock_on && gcin_capslock_lower)
case_inverse((KeySym *)&key, shift_m);