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)
211
223
idx = *indicies + cwin->display_limit * cwin->page_index;
213
225
if (!path_currently_selected && cwin->candidate_index != idx) {
214
cwin->candidate_index = idx;
215
g_signal_emit(G_OBJECT(cwin),
216
cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
226
if (cwin->candidate_index >= 0) {
227
cwin->candidate_index = idx;
228
g_signal_emit(G_OBJECT(cwin),
229
cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
234
if (cwin->candidate_index < 0)
437
gchar *cand = node->data;
462
gchar *str = node->data;
463
gchar **column = g_strsplit(str, "\t", 2);
438
464
gtk_list_store_append(store, &ti);
439
465
gtk_list_store_set(store, &ti,
440
COLUMN_HEADING, j + 1,
441
COLUMN_CANDIDATE, cand,
466
COLUMN_HEADING, column[0],
467
COLUMN_CANDIDATE, column[1],
445
472
/* No need to set any data for empty row. */
465
494
candwin_move(char **str)
468
int topwin_x, topwin_y;
469
int cw_wi, cw_he, sc_wi, sc_he;
471
sscanf(str[1], "%d", &topwin_x);
472
sscanf(str[2], "%d", &topwin_y);
474
gtk_window_get_size(GTK_WINDOW(cwin), &cw_wi, &cw_he);
476
sc_wi = gdk_screen_get_width(gdk_screen_get_default());
477
sc_he = gdk_screen_get_height(gdk_screen_get_default());
479
if (sc_wi < topwin_x + cw_wi) {
480
x = topwin_x - cw_wi;
485
if (sc_he < topwin_y + cw_he) {
486
/* FIXME : How can I determine the preedit height? */
487
y = topwin_y - cw_he - 20;
492
gtk_window_move(GTK_WINDOW(cwin), x, y);
496
sscanf(str[1], "%d", &cwin->pos_x);
497
sscanf(str[2], "%d", &cwin->pos_y);
499
uim_cand_win_gtk_layout();
506
513
cwin->is_active = FALSE;
517
caret_state_show(gchar **str)
521
sscanf(str[1], "%d", &timeout);
522
caret_state_indicator_update(cwin->caret_state_indicator, cwin->pos_x, cwin->pos_y, str[2]);
524
caret_state_indicator_set_timeout(cwin->caret_state_indicator, timeout * 1000);
525
gtk_widget_show_all(GTK_WIDGET(cwin->caret_state_indicator));
531
caret_state_indicator_update(cwin->caret_state_indicator, cwin->pos_x, cwin->pos_y, NULL);
537
gtk_widget_hide(cwin->caret_state_indicator);
509
540
static void str_parse(gchar *str)
514
545
tmp = g_strsplit(str, "\n", 0);
517
if (strcmp("activate", tmp[i]) == 0) {
549
if (strcmp("activate", command) == 0) {
518
550
candwin_activate(tmp);
519
} else if (strcmp("select", tmp[i]) == 0) {
551
} else if (strcmp("select", command) == 0) {
520
552
candwin_update(tmp);
521
} else if (strcmp("show", tmp[i]) == 0) {
553
} else if (strcmp("show", command) == 0) {
523
} else if (strcmp("hide", tmp[i]) == 0) {
555
} else if (strcmp("hide", command) == 0) {
524
556
gtk_widget_hide_all(GTK_WIDGET(cwin));
525
} else if (strcmp("move", tmp[i]) == 0) {
557
} else if (strcmp("move", command) == 0) {
526
558
candwin_move(tmp);
527
} else if (strcmp("deactivate", tmp[i]) == 0) {
559
} else if (strcmp("deactivate", command) == 0) {
528
560
candwin_deactivate();
561
} else if (strcmp("show_caret_state", command) == 0) {
562
caret_state_show(tmp);
563
} else if (strcmp("update_caret_state", command) == 0) {
564
caret_state_update();
565
} else if (strcmp("hide_caret_state", command) == 0) {
536
read_cb(gpointer p, int fd, GdkInputCondition c)
572
#define CANDIDATE_BUFFER_SIZE 4096
574
read_cb(GIOChannel *channel, GIOCondition c, gpointer p)
576
char buf[CANDIDATE_BUFFER_SIZE];
577
char *read_buf = strdup("");
581
int fd = g_io_channel_unix_get_fd(channel);
543
n = read(fd, buf, 1024 - 1);
583
while (uim_helper_fd_readable(fd) > 0) {
584
n = read(fd, buf, CANDIDATE_BUFFER_SIZE - 1);
592
read_buf = realloc(read_buf, strlen(read_buf) + n + 1);
593
strcat(read_buf, buf);
552
tmp = g_strsplit(buf, "\n\n", 0);
596
tmp = g_strsplit(read_buf, "\n\n", 0);
555
599
str_parse(tmp[i]);
563
608
main(int argc, char *argv[])
565
612
gtk_set_locale();
566
613
gtk_init(&argc, &argv);
568
615
init_candidate_win();
570
read_tag = gdk_input_add(0, (GdkInputCondition)GDK_INPUT_READ,
617
channel = g_io_channel_unix_new(0);
618
read_tag = g_io_add_watch(channel, G_IO_IN | G_IO_HUP | G_IO_ERR,
620
g_io_channel_unref(channel);
587
637
uim_cand_win_gtk_set_index(UIMCandidateWindow *cwin, gint index)
591
641
g_return_if_fail(UIM_IS_CANDIDATE_WINDOW(cwin));
594
cwin->candidate_index = cwin->nr_candidates - 1;
595
else if ((guint) index >= cwin->nr_candidates)
643
if (index >= (gint) cwin->nr_candidates)
596
644
cwin->candidate_index = 0;
598
646
cwin->candidate_index = index;
600
if (cwin->display_limit)
648
if (cwin->candidate_index >= 0 && cwin->display_limit)
601
649
new_page = cwin->candidate_index / cwin->display_limit;
651
new_page = cwin->page_index;
603
653
if (cwin->page_index != new_page)
604
654
uim_cand_win_gtk_set_page(cwin, new_page);
659
709
= (new_page * cwin->display_limit) + (cwin->candidate_index % cwin->display_limit);
661
new_index = new_page * cwin->display_limit;
663
713
new_index = cwin->candidate_index;
666
if (new_index >= cwin->nr_candidates)
716
if (new_index >= (gint) cwin->nr_candidates)
667
717
new_index = cwin->nr_candidates - 1;
719
/* shrink the window */
720
gtk_window_resize(GTK_WINDOW(cwin), CANDWIN_DEFAULT_WIDTH, 1);
669
722
uim_cand_win_gtk_set_index(cwin, new_index);
726
uim_cand_win_gtk_layout()
729
int screen_width, screen_height;
731
screen_width = gdk_screen_get_width(gdk_screen_get_default());
732
screen_height = gdk_screen_get_height(gdk_screen_get_default());
734
if (screen_width < cwin->pos_x + cwin->width)
735
x = cwin->pos_x - cwin->width;
739
if (screen_height < cwin->pos_y + cwin->height)
740
y = cwin->pos_y - cwin->height - 20; /* FIXME: Preedit height is needed to
741
be sent by uim-xim */
745
gtk_window_move(GTK_WINDOW(cwin), x, y);
749
configure_event_cb(GtkWidget *widget, GdkEventConfigure *event, gpointer data)
751
cwin->width = event->width;
752
cwin->height = event->height;
754
uim_cand_win_gtk_layout();