17
17
may be used to endorse or promote products derived from this software
18
18
without specific prior written permission.
20
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
21
21
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
22
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE
24
24
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
25
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26
26
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38
38
#include "config.h"
44
44
#include <stdlib.h>
47
47
#include <string.h>
50
50
#include <assert.h>
52
#include <uim/uim-util.h>
52
53
#include "uim-fep.h"
54
55
#include "callbacks.h"
56
57
static uim_context s_context;
57
/* TRUE�ʤ饫��������֤�ȿž���ʤ� */
58
static int s_cursor_no_reverse;
59
/* ���ơ������饤����� */
60
static int s_statusline_width;
58
/* ���ơ������饤��κ����� */
59
static int s_max_width;
62
60
static char *s_commit_str;
63
61
static char *s_statusline_str;
64
62
static char *s_candidate_str;
77
76
static void pushback_cb(void *ptr, int attr, const char *str);
78
77
static void update_cb(void *ptr);
79
78
static void mode_update_cb(void *ptr, int mode);
80
static void property_update_cb(void *ptr, const char *str);
81
static void property_list_update_cb(void *ptr, const char *str);
82
79
static struct preedit_tag *dup_preedit(struct preedit_tag *p);
83
80
static void make_page_strs(void);
84
81
static int numwidth(int n);
125
void init_callbacks(uim_context context, int status_type, int cursor_no_reverse, int statusline_width)
122
void init_callbacks(uim_context context)
127
124
s_context = context;
128
s_cursor_no_reverse = cursor_no_reverse;
129
s_statusline_width = statusline_width;
125
s_max_width = g_win->ws_col;
126
if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
127
s_max_width = g_opt.statusline_width;
130
129
s_commit_str = strdup("");
131
130
s_candidate_str = strdup("");
132
131
s_statusline_str = strdup("");
136
135
s_preedit = create_preedit();
137
136
uim_set_preedit_cb(s_context, clear_cb, pushback_cb, update_cb);
138
137
uim_set_mode_cb(s_context, mode_update_cb);
139
uim_set_prop_label_update_cb(s_context, property_update_cb);
140
uim_set_prop_list_update_cb(s_context, property_list_update_cb);
141
if (status_type != NONE) {
138
if (g_opt.status_type != NONE) {
142
139
uim_set_candidate_selector_cb(s_context, activate_cb, select_cb, shift_page_cb, deactivate_cb);
144
const char *nokori_str = "�Ĥ�";
147
if (uim_iconv->is_convertible(enc = get_enc(), "EUC-JP")) {
148
cd = uim_iconv->create(enc, "EUC-JP");
149
s_nokori_str = uim_iconv->convert(cd, nokori_str);
151
uim_iconv->release(cd);
154
perror("error in iconv_open");
155
puts("-d option is not available");
146
161
int press_key(int key, int key_state)
164
#if defined DEBUG && DEBUG > 2
150
165
if (32 <= key && key <= 127) {
151
166
debug2(("press key = %c key_state = %d\n", key, key_state));
385
407
/* ��ʸ�����̵�� */
387
409
/* ����������֤�ʸ����ȿž�����ʤ� */
388
if (s_cursor_no_reverse && cursor && attr & UPreeditAttr_Reverse && s_preedit->cursor != UNDEFINED) {
410
if (g_opt.cursor_no_reverse && cursor && attr & UPreeditAttr_Reverse && s_preedit->cursor != UNDEFINED) {
389
411
int *rval = width2byte2(str, 1);
390
412
int first_char_byte = rval[0];
391
413
int first_char_width = rval[1];
437
static void property_update_cb(void *ptr, const char *str)
439
debug2(("prop(\"%s\")", str));
441
static void property_list_update_cb(void *ptr, const char *str)
443
debug2(("proplist(\"%s\")", str));
447
460
* �������ץꥨ�ǥ��åȤ��ꡤ�ݥ����֤�
494
507
* s_candidate.page_strs = �ڡ���ʸ���������
495
* ʸ���������max_width��ۤ����Ȥ��ϡ��Ϥ߽Ф�����Υڡ����˰ܤ���
508
* ʸ���������s_max_width��ۤ����Ȥ��ϡ��Ϥ߽Ф�����Υڡ����˰ܤ���
496
509
* 1�Ĥ������䤬�ʤ��ƤϤ߽Ф��Ȥ��ϡ��ܤ��ʤ���
497
* max_width��ü�����������ץ����ǻ��ꤵ�줿��
510
* s_max_width��ü�����������ץ����ǻ��ꤵ�줿��
498
511
* s_candidate.page2index = �ڡ����κǽ�θ����index
499
512
* s_candidate.cand_col = ������
500
513
* s_candidate.nr_pages = �ڡ���������
513
int max_width = g_win->ws_col;
515
if (s_statusline_width != UNDEFINED && s_statusline_width <= max_width) {
516
max_width = s_statusline_width;
519
526
assert(s_candidate.nr != UNDEFINED);
520
527
assert(s_candidate.limit != UNDEFINED);
521
528
assert(s_candidate.cand_col != NULL);
523
530
s_candidate.nr_pages = 0;
525
532
for (index = 0; index < s_candidate.nr; index++) {
533
/* A:�� S:�� D:�� F:�� J:�� K:�� L:�� [�Ĥ� 227] */
526
534
int next = FALSE;
527
535
/* "[10/20]" ���� */
528
int index_width = 3 + numwidth(index + 1) + numwidth(s_candidate.nr);
530
537
uim_candidate cand = uim_get_candidate(s_context, index, index_in_page);
531
538
const char *cand_str_label = uim_candidate_get_heading_label(cand);
532
const char *cand_str_cand = uim_candidate_get_cand_str(cand);
539
char *cand_str_cand = tab2space(uim_candidate_get_cand_str(cand));
533
540
int cand_label_width = strwidth(cand_str_label);
534
int cand_width = cand_label_width + 1 + strwidth(cand_str_cand) + 1;
535
int cand_byte = strlen(cand_str_label) + 1 + strlen(cand_str_cand) + 1;
541
int cand_width = cand_label_width + strlen(":") + strwidth(cand_str_cand) + strlen(" ");
542
int cand_byte = strlen(cand_str_label) + strlen(":") + strlen(cand_str_cand) + strlen(" ");
536
543
char *cand_str = malloc(cand_byte + 1);
546
index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - index - 1);
548
index_width = strlen("[/]") + numwidth(index + 1) + numwidth(s_candidate.nr);
537
551
sprintf(cand_str, "%s:%s ", cand_str_label, cand_str_cand);
538
552
uim_candidate_free(cand);
540
555
if (index_in_page == 0) {
541
556
s_candidate.page2index = realloc(s_candidate.page2index, (s_candidate.nr_pages + 1) * sizeof(int));
543
558
s_candidate.index_col = realloc(s_candidate.index_col, (s_candidate.nr_pages + 1) * sizeof(int));
546
if (page_width + cand_width + index_width > max_width && index_in_page != 0) {
561
if (page_width + cand_width + index_width > s_max_width && index_in_page != 0) {
547
562
/* �Ϥ߽Ф��ΤǼ��Υڡ����˰ܤ� */
549
index_width = 3 + numwidth(index + 1) + numwidth(s_candidate.nr);
565
index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - index - 1);
567
index_width = strlen("[/]") + numwidth(index + 1) + numwidth(s_candidate.nr);
552
if (cand_width + index_width > max_width && index_in_page == 0) {
572
s_candidate.cand_col[index] = page_width + cand_label_width + strlen(":");
574
if (cand_width + index_width > s_max_width && index_in_page == 0) {
575
/* �Ϥ߽Ф��������˰ܤ��ʤ� */
553
576
assert(page_width == 0);
554
/* �Ϥ߽Ф��������˰ܤ��ʤ� */ /* ���ڡ���������1 */
555
cand_width = max_width - index_width - 1;
556
cand_width = strhead(cand_str, cand_width);
557
if (cand_label_width > cand_width) {
558
cand_label_width = cand_width;
579
if (s_max_width >= cand_label_width + strlen(":") + 2 + strlen(" ") + index_width) {
580
/* ���� + ����ǥå��� */
582
cand_width = s_max_width - index_width - strlen(" ");
583
cand_width = strhead(cand_str, cand_width);
584
assert(cand_width > cand_label_width);
585
cand_width += strwidth(" ");
586
cand_byte = strlen(cand_str);
587
cand_str[cand_byte++] = ' ';
588
cand_str[cand_byte] = '\0';
592
index_width = UNDEFINED;
593
if (cand_width > s_max_width) {
594
cand_width = s_max_width;
596
cand_width -= strlen(" ");
597
cand_width = strhead(cand_str, cand_width);
598
if (cand_width <= cand_label_width + strlen(":")) {
600
strcpy(cand_str, " ");
601
s_candidate.cand_col[index] = UNDEFINED;
603
cand_byte = strlen(cand_str);
604
cand_str[cand_byte++] = ' ';
605
cand_str[cand_byte] = '\0';
561
cand_byte = strlen(cand_str);
562
cand_str[cand_byte++] = ' ';
563
cand_str[cand_byte] = '\0';
567
s_candidate.cand_col[index] = page_width + cand_label_width + 1;
568
610
page_width += cand_width;
569
611
page_byte += cand_byte;
570
612
page_str = realloc(page_str, page_byte + 1);
580
int index_byte = index_width;
581
char *index_str = malloc(index_byte + 1);
583
sprintf(index_str, "[%d/%d]", index + 1, s_candidate.nr);
584
for (i = 0; i < numwidth(index + 1); i++) {
585
index_str[1 + i] = ' ';
588
/* ��ۤ�ü�������������ʤ�������Ϥ߽Фʤ� */
589
if (page_width + index_width > max_width) {
590
index_width = max_width - page_width;
591
index_width = strhead(index_str, index_width);
592
index_byte = strlen(index_str);
594
s_candidate.index_col[s_candidate.nr_pages] = page_width + 1;
595
page_byte += index_byte;
596
page_str = realloc(page_str, page_byte + 1);
597
strcat(page_str, index_str);
598
s_candidate.page_strs = realloc(s_candidate.page_strs, (s_candidate.nr_pages + 1)* sizeof(char *));
622
if (index_width == UNDEFINED) {
623
s_candidate.index_col[s_candidate.nr_pages] = UNDEFINED;
625
int index_byte = index_width + 2/* utf-8 */;
626
char *index_str = malloc(index_byte + 1);
629
sprintf(index_str, "[%s %d]", s_nokori_str, s_candidate.nr - index - 1);
631
sprintf(index_str, "[%d/%d]", index + 1, s_candidate.nr);
632
for (i = 0; i < numwidth(index + 1); i++) {
633
index_str[1 + i] = ' ';
637
assert(page_width + index_width <= s_max_width);
638
s_candidate.index_col[s_candidate.nr_pages] = page_width + strlen("[");
639
page_byte += index_byte;
640
page_str = realloc(page_str, page_byte + 1);
641
strcat(page_str, index_str);
644
s_candidate.page_strs = realloc(s_candidate.page_strs, (s_candidate.nr_pages + 1) * sizeof(char *));
599
645
s_candidate.page_strs[s_candidate.nr_pages] = strdup(page_str);
600
646
s_candidate.nr_pages++;
604
650
index_in_page = 0;
607
652
page_str = strdup("");
683
728
/* "[10/20]"���� */
685
int max_width = g_win->ws_col;
686
/* ��ü�θ���Υ���ǥå��� */
687
int right_edge_cand_index = s_candidate.page + 1 == s_candidate.nr_pages ? s_candidate.nr : s_candidate.page2index[s_candidate.page + 1];
688
/* ��ü�θ���Υ���ǥå������� */
689
int right_edge_cand_index_width = numwidth(right_edge_cand_index + 1);
690
/* ���ߤθ���Υ���ǥå������� */
691
int cand_index_width = numwidth(s_candidate.index + 1);
693
s_index_str = malloc(right_edge_cand_index_width + 1);
694
for (i = 0; i < right_edge_cand_index_width - cand_index_width; i++) {
695
s_index_str[i] = ' ';
697
s_index_str[i] = '\0';
698
sprintf(s_index_str, "%s%d", s_index_str, s_candidate.index + 1);
700
if (s_statusline_width != UNDEFINED && s_statusline_width <= max_width) {
701
max_width = s_statusline_width;
731
if (s_candidate.index_col[s_candidate.page] == UNDEFINED) {
732
s_index_str = strdup("");
735
/* ��ü�θ���Υ���ǥå��� */
736
int right_edge_cand_index = s_candidate.page + 1 == s_candidate.nr_pages ? s_candidate.nr - 1 : s_candidate.page2index[s_candidate.page + 1] - 1;
737
/* ��ü�θ���Υ���ǥå������� */
738
int right_edge_cand_index_width = numwidth(right_edge_cand_index + 1);
739
/* ���ߤθ���Υ���ǥå������� */
740
int cand_index_width = numwidth(s_candidate.index + 1);
742
s_index_str = malloc(right_edge_cand_index_width + 1);
743
for (i = 0; i < right_edge_cand_index_width - cand_index_width; i++) {
744
s_index_str[i] = ' ';
746
s_index_str[i] = '\0';
747
sprintf(s_index_str, "%s%d", s_index_str, s_candidate.index + 1);
749
index_width = strlen("[xxxx ]") + numwidth(s_candidate.nr - s_candidate.index - 1);
751
index_width = strlen("[/]") + numwidth(s_candidate.index + 1) + numwidth(s_candidate.nr);
704
756
s_candidate_col = s_candidate.cand_col[s_candidate.index];
757
if (s_candidate_col == UNDEFINED) {
758
s_candidate_str = strdup("");
705
761
cand = uim_get_candidate(s_context, s_candidate.index, 0);
706
762
if (uim_candidate_get_cand_str(cand) == NULL) {
707
763
s_candidate_str = strdup("");
709
765
uim_candidate_free(cand);
712
s_candidate_str = strdup(uim_candidate_get_cand_str(cand));
768
s_candidate_str = tab2space(uim_candidate_get_cand_str(cand));
713
769
cand_width = strwidth(s_candidate_str);
714
index_width = 3 + numwidth(s_candidate.index + 1) + numwidth(s_candidate.nr);
715
/* ��ۤ�ü�������������ʤ�������Ϥ߽Фʤ� */
716
if (s_candidate_col + cand_width + index_width > max_width) {
717
strhead(s_candidate_str, max_width - s_candidate_col - index_width - 1);
770
if (s_candidate_col + cand_width + strlen(" ") + index_width > s_max_width) {
771
strhead(s_candidate_str, s_max_width - s_candidate_col - strlen(" ") - index_width);
719
773
uim_candidate_free(cand);
722
776
void callbacks_winch(void)
778
s_max_width = g_win->ws_col;
779
if (g_opt.statusline_width != UNDEFINED && g_opt.statusline_width <= s_max_width) {
780
s_max_width = g_opt.statusline_width;
724
782
if (s_candidate.nr != UNDEFINED) {
725
783
if (s_candidate.page_strs != NULL) {