Revision: 7336
Author:   deton.kih
Date:     Sat Oct 22 20:07:42 2011
Log:      * Add previous and next page buttons to gtk candidate window.
* gtk2/candwin/gtk.c
* gtk2/candwin/horizontal-gtk.c
* gtk2/candwin/tbl-gtk.c
  - (_UIMCandidateWindow): Add prev/next page buttons.
  - (pagebutton_clicked): New.
  - (candidate_window_init):
    Add initialization of prev/next page buttons.
  - (candwin_activate):
    Add reset of need_page_update.
    Set sensitiveness of prev/next page buttons
    according to number of candidates.
  - (candwin_set_nr_candidates): Ditto.
  - (uim_cand_win_gtk_set_index):
    Update page when prev/next page button is clicked.
  - (uim_cand_win_gtk_set_page):
    Add check whether page data is received
    because candwin may not have page data when
    prev/next page button is clicked.
  - (uim_cand_win_gtk_show):
    Change num_label to hbox which contains prev/next page buttons.
* gtk2/immodule/uim-cand-win-gtk.c
  - (pagebutton_clicked): New.
  - (uim_cand_win_gtk_init):
    Add initialization of prev/next page buttons.
  - (uim_cand_win_gtk_set_nr_candidates):
    Set sensitiveness of prev/next page buttons
    according to number of candidates.
  - (uim_cand_win_gtk_set_candidates): Ditto.
* gtk2/immodule/uim-cand-win-gtk.h
  - (_UIMCandWinGtk): Add prev/next page buttons.
* gtk2/immodule/gtk-im-uim.c
  - (index_changed_cb):
    Get page candidates from IM when prev/next page button is clicked.
* gtk2/immodule/uim-cand-win-horizontal-gtk.c
  - (uim_cand_win_horizontal_gtk_set_index):
    Add check whether page data is received
    because candwin may not have page data when
    prev/next page button is clicked.
  - (update_table_button): Ditto.
* gtk2/immodule/uim-cand-win-tbl-gtk.c
  - (uim_cand_win_tbl_gtk_set_page): Ditto.
* scm/tutcode.scm
  - (tutcode-set-candidate-index-handler):
    If index is in shown page on candidate window then commit
    the index, else only update selected index because
    prev/next page button is pressed.
* scm/prime.scm
  - (prime-set-candidate-index-handler): Ditto.

http://code.google.com/p/uim/source/detail?r=7336

Modified:
 /trunk/gtk2/candwin/gtk.c
 /trunk/gtk2/candwin/horizontal-gtk.c
 /trunk/gtk2/candwin/tbl-gtk.c
 /trunk/gtk2/immodule/gtk-im-uim.c
 /trunk/gtk2/immodule/uim-cand-win-gtk.c
 /trunk/gtk2/immodule/uim-cand-win-gtk.h
 /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c
 /trunk/gtk2/immodule/uim-cand-win-tbl-gtk.c
 /trunk/scm/prime.scm
 /trunk/scm/tutcode.scm

=======================================
--- /trunk/gtk2/candwin/gtk.c   Sun Jun 19 18:58:39 2011
+++ /trunk/gtk2/candwin/gtk.c   Sat Oct 22 20:07:42 2011
@@ -64,6 +64,8 @@

   GtkWidget *view;
   GtkWidget *num_label;
+  GtkWidget *prev_page_button;
+  GtkWidget *next_page_button;

   GPtrArray *stores;

@@ -81,6 +83,7 @@

   gboolean is_active;
   gboolean need_hilite;
+  gboolean need_page_update;

   /* sub window */
   struct sub_window {
@@ -339,6 +342,44 @@
   return retval;
 }
 #endif
+
+static void
+pagebutton_clicked(GtkButton *button, gpointer data)
+{
+  UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data);
+
+  if (cwin->candidate_index < 0) {
+    /* if candidate_index < 0, "index-changed" signal is not emitted
+     * and candidates for new page is not set.
+     */
+    cwin->candidate_index = cwin->page_index * cwin->display_limit;
+  }
+  if (button == GTK_BUTTON(cwin->prev_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index - 1);
+  } else if (button == GTK_BUTTON(cwin->next_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index + 1);
+  } else {
+    return;
+  }
+  if (cwin->candidate_index >= 0) {
+    g_signal_emit(G_OBJECT(cwin),
+                  cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
+  }
+  if (!cwin->stores->pdata[cwin->page_index]) {
+    /*       candwin                         uim-xim
+     * pagebutton_clicked()
+     *            ---------"index"------------>
+ * InputContext::candidate_select()
+     *            <---"set_page_candidates"----
+     *                                        Canddisp::select()
+     *            <--------"select"------------
+     * candwin_update()
+     *   uim_cand_win_gtk_set_index()
+     *     uim_cand_win_gtk_set_page()
+     */
+    cwin->need_page_update = TRUE;
+  }
+}

 static void
 cb_tree_view_destroy(GtkWidget *widget, GPtrArray *stores)
@@ -373,6 +414,7 @@
   GtkTreeViewColumn *column;
   GtkWidget *scrolled_window;
   GtkWidget *vbox;
+  GtkWidget *hbox;
   GtkWidget *frame;
   GtkTreeSelection *selection;
   GdkRectangle cursor_location;
@@ -436,7 +478,20 @@

   cwin->num_label = gtk_label_new("");

-  gtk_box_pack_start(GTK_BOX(vbox), cwin->num_label, FALSE, FALSE, 0);
+  /* hbox with prev and next page button: [[<] num_label [>]] */
+  hbox = gtk_hbox_new(FALSE, 0);
+  cwin->prev_page_button = gtk_button_new_with_label("<");
+  cwin->next_page_button = gtk_button_new_with_label(">");
+  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(cwin->prev_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), cwin->num_label, FALSE, FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(cwin->next_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+  g_signal_connect(cwin->prev_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);
+  g_signal_connect(cwin->next_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);

 #if 0
   g_signal_connect(G_OBJECT(cwin->view), "button-press-event",
@@ -447,6 +502,7 @@
   cwin->pos_y = 0;
   cwin->is_active = FALSE;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->caret_state_indicator = caret_state_indicator_new();

   cursor_location.x = 0;
@@ -515,6 +571,7 @@
   cwin->nr_candidates = j - 1;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;

   if (candidates == NULL)
     return;
@@ -557,6 +614,14 @@
   }
   g_slist_free(candidates);

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   uim_cand_win_gtk_set_page(cwin, 0);
   update_label(cwin);

@@ -640,8 +705,17 @@
   cwin->nr_candidates = nr;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->is_active = TRUE;

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   if (cwin->stores == NULL)
     cwin->stores = g_ptr_array_new();

@@ -848,7 +922,7 @@
   else
     new_page = cwin->page_index;

-  if (cwin->page_index != new_page)
+  if (cwin->page_index != new_page || cwin->need_page_update)
     uim_cand_win_gtk_set_page(cwin, new_page);

   if (cwin->candidate_index >= 0 && cwin->need_hilite) {
@@ -892,8 +966,10 @@
   else
     new_page = page;

-  gtk_tree_view_set_model(GTK_TREE_VIEW(cwin->view),
-                         GTK_TREE_MODEL(cwin->stores->pdata[new_page]));
+  if (cwin->stores->pdata[new_page]) {
+    gtk_tree_view_set_model(GTK_TREE_VIEW(cwin->view),
+                            GTK_TREE_MODEL(cwin->stores->pdata[new_page]));
+  }

   cwin->page_index = new_page;

@@ -913,6 +989,7 @@
  /* shrink the window */
   gtk_window_resize(GTK_WINDOW(cwin), CANDWIN_DEFAULT_WIDTH, 1);

+ cwin->need_page_update = FALSE; /* avoid infinite loop with set_index() */
   uim_cand_win_gtk_set_index(cwin, new_index);
 }

=======================================
--- /trunk/gtk2/candwin/horizontal-gtk.c        Tue Oct 18 03:57:44 2011
+++ /trunk/gtk2/candwin/horizontal-gtk.c        Sat Oct 22 20:07:42 2011
@@ -70,6 +70,9 @@
   GtkWidget *viewport;
   GtkWidget *vbox;
   GtkWidget *frame;
+  GtkWidget *hbox;
+  GtkWidget *prev_page_button;
+  GtkWidget *next_page_button;

   GPtrArray *stores;
   GPtrArray *buttons;
@@ -89,6 +92,7 @@

   gboolean is_active;
   gboolean need_hilite;
+  gboolean need_page_update;

   /* sub window */
   struct sub_window {
@@ -375,6 +379,44 @@
   }
   g_signal_emit_by_name(G_OBJECT(cwin), "index-changed");
 }
+
+static void
+pagebutton_clicked(GtkButton *button, gpointer data)
+{
+  UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data);
+
+  if (cwin->candidate_index < 0) {
+    /* if candidate_index < 0, "index-changed" signal is not emitted
+     * and candidates for new page is not set.
+     */
+    cwin->candidate_index = cwin->page_index * cwin->display_limit;
+  }
+  if (button == GTK_BUTTON(cwin->prev_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index - 1);
+  } else if (button == GTK_BUTTON(cwin->next_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index + 1);
+  } else {
+    return;
+  }
+  if (cwin->candidate_index >= 0) {
+    g_signal_emit(G_OBJECT(cwin),
+                  cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
+  }
+  if (!cwin->stores->pdata[cwin->page_index]) {
+    /*       candwin                         uim-xim
+     * pagebutton_clicked()
+     *            ---------"index"------------>
+ * InputContext::candidate_select()
+     *            <---"set_page_candidates"----
+     *                                        Canddisp::select()
+     *            <--------"select"------------
+     * candwin_update()
+     *   uim_cand_win_gtk_set_index()
+     *     uim_cand_win_gtk_set_page()
+     */
+    cwin->need_page_update = TRUE;
+  }
+}

 static void
 cb_table_view_destroy(GtkWidget *widget, GPtrArray *stores)
@@ -474,12 +516,26 @@

   cwin->num_label = gtk_label_new("");

- gtk_box_pack_start(GTK_BOX(cwin->vbox), cwin->num_label, FALSE, FALSE, 0);
+  /* hbox with prev and next page button: [[<] num_label [>]] */
+  cwin->hbox = gtk_hbox_new(FALSE, 0);
+  cwin->prev_page_button = gtk_button_new_with_label("<");
+  cwin->next_page_button = gtk_button_new_with_label(">");
+ gtk_box_pack_start(GTK_BOX(cwin->hbox), GTK_WIDGET(cwin->prev_page_button),
+      TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(cwin->hbox), cwin->num_label, FALSE, FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(cwin->hbox), GTK_WIDGET(cwin->next_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(cwin->vbox), cwin->hbox, FALSE, FALSE, 0);
+  g_signal_connect(cwin->prev_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);
+  g_signal_connect(cwin->next_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);

   cwin->pos_x = 0;
   cwin->pos_y = 0;
   cwin->is_active = FALSE;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->caret_state_indicator = caret_state_indicator_new();

   cursor_location.x = 0;
@@ -586,6 +642,7 @@
   cwin->nr_candidates = j - 1;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;

   if (candidates == NULL)
     return;
@@ -628,6 +685,14 @@
   }
   g_slist_free(candidates);

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   uim_cand_win_gtk_set_page(cwin, 0);
   update_label(cwin);

@@ -711,8 +776,17 @@
   cwin->nr_candidates = nr;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->is_active = TRUE;

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   if (cwin->stores == NULL)
     cwin->stores = g_ptr_array_new();

@@ -920,7 +994,7 @@
   else
     new_page = cwin->page_index;

-  if (cwin->page_index != new_page)
+  if (cwin->page_index != new_page || cwin->need_page_update)
     uim_cand_win_gtk_set_page(cwin, new_page);

   if (cwin->candidate_index >= 0 && cwin->need_hilite) {
@@ -946,7 +1020,7 @@
     cwin->selected = idxbutton;

     /* show subwin */
-    {
+    if (cwin->stores->pdata[new_page]) {
       char *annotation = NULL;
       GtkTreeModel *model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]);
       GtkTreeIter iter;
@@ -1100,9 +1174,11 @@
   else
     new_page = page;

-  update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
-                      cwin->buttons, cwin->display_limit);
-  show_table(GTK_TABLE(cwin->view), cwin->buttons);
+  if (cwin->stores->pdata[new_page]) {
+    update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
+                        cwin->buttons, cwin->display_limit);
+    show_table(GTK_TABLE(cwin->view), cwin->buttons);
+  }

   cwin->page_index = new_page;

@@ -1122,6 +1198,7 @@
   /* shrink the window */
   gtk_window_resize(GTK_WINDOW(cwin), CANDWIN_DEFAULT_WIDTH, 1);

+ cwin->need_page_update = FALSE; /* avoid infinite loop with set_index() */
   uim_cand_win_gtk_set_index(cwin, new_index);
 }

@@ -1309,7 +1386,7 @@
 {
   gtk_widget_show(GTK_WIDGET(cwin->viewport));
   gtk_widget_show(GTK_WIDGET(cwin->scrolled_window));
-  gtk_widget_show(GTK_WIDGET(cwin->num_label));
+  gtk_widget_show_all(GTK_WIDGET(cwin->hbox));
   gtk_widget_show(GTK_WIDGET(cwin->vbox));
   gtk_widget_show(GTK_WIDGET(cwin->frame));
   gtk_widget_show(GTK_WIDGET(cwin));
=======================================
--- /trunk/gtk2/candwin/tbl-gtk.c       Sun Jun 19 18:58:39 2011
+++ /trunk/gtk2/candwin/tbl-gtk.c       Sat Oct 22 20:07:42 2011
@@ -66,6 +66,9 @@
   GtkWidget *viewport;
   GtkWidget *vbox;
   GtkWidget *frame;
+  GtkWidget *hbox;
+  GtkWidget *prev_page_button;
+  GtkWidget *next_page_button;

   GPtrArray *stores;
   GPtrArray *buttons;
@@ -85,6 +88,7 @@

   gboolean is_active;
   gboolean need_hilite;
+  gboolean need_page_update;
 };

 struct _UIMCandidateWindowClass {
@@ -294,6 +298,44 @@
   }
   g_signal_emit_by_name(G_OBJECT(cwin), "index-changed");
 }
+
+static void
+pagebutton_clicked(GtkButton *button, gpointer data)
+{
+  UIMCandidateWindow *cwin = UIM_CANDIDATE_WINDOW(data);
+
+  if (cwin->candidate_index < 0) {
+    /* if candidate_index < 0, "index-changed" signal is not emitted
+     * and candidates for new page is not set.
+     */
+    cwin->candidate_index = cwin->page_index * cwin->display_limit;
+  }
+  if (button == GTK_BUTTON(cwin->prev_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index - 1);
+  } else if (button == GTK_BUTTON(cwin->next_page_button)) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index + 1);
+  } else {
+    return;
+  }
+  if (cwin->candidate_index >= 0) {
+    g_signal_emit(G_OBJECT(cwin),
+                  cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
+  }
+  if (!cwin->stores->pdata[cwin->page_index]) {
+    /*       candwin                         uim-xim
+     * pagebutton_clicked()
+     *            ---------"index"------------>
+ * InputContext::candidate_select()
+     *            <---"set_page_candidates"----
+     *                                        Canddisp::select()
+     *            <--------"select"------------
+     * candwin_update()
+     *   uim_cand_win_gtk_set_index()
+     *     uim_cand_win_gtk_set_page()
+     */
+    cwin->need_page_update = TRUE;
+  }
+}

 static void
 cb_table_view_destroy(GtkWidget *widget, GPtrArray *stores)
@@ -400,12 +442,26 @@

   cwin->num_label = gtk_label_new("");

- gtk_box_pack_start(GTK_BOX(cwin->vbox), cwin->num_label, FALSE, FALSE, 0);
+  /* hbox with prev and next page button: [[<] num_label [>]] */
+  cwin->hbox = gtk_hbox_new(FALSE, 0);
+  cwin->prev_page_button = gtk_button_new_with_label("<");
+  cwin->next_page_button = gtk_button_new_with_label(">");
+ gtk_box_pack_start(GTK_BOX(cwin->hbox), GTK_WIDGET(cwin->prev_page_button),
+      TRUE, TRUE, 0);
+ gtk_box_pack_start(GTK_BOX(cwin->hbox), cwin->num_label, FALSE, FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(cwin->hbox), GTK_WIDGET(cwin->next_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(cwin->vbox), cwin->hbox, FALSE, FALSE, 0);
+  g_signal_connect(cwin->prev_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);
+  g_signal_connect(cwin->next_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);

   cwin->pos_x = 0;
   cwin->pos_y = 0;
   cwin->is_active = FALSE;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->caret_state_indicator = caret_state_indicator_new();

   cursor_location.x = 0;
@@ -568,6 +624,7 @@
   cwin->nr_candidates = j - 1;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;

   if (candidates == NULL)
     return;
@@ -610,6 +667,14 @@
   }
   g_slist_free(candidates);

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   uim_cand_win_gtk_set_page(cwin, 0);
   update_label(cwin);

@@ -688,8 +753,17 @@
   cwin->nr_candidates = nr;
   cwin->display_limit = display_limit;
   cwin->need_hilite = FALSE;
+  cwin->need_page_update = FALSE;
   cwin->is_active = TRUE;

+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   if (cwin->stores == NULL)
     cwin->stores = g_ptr_array_new();

@@ -894,7 +968,7 @@
   else
     new_page = cwin->page_index;

-  if (cwin->page_index != new_page)
+  if (cwin->page_index != new_page || cwin->need_page_update)
     uim_cand_win_gtk_set_page(cwin, new_page);

   update_label(cwin);
@@ -987,9 +1061,11 @@
   else
     new_page = page;

-  update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
-                      cwin->buttons, cwin->tbl_cell2label,
-                      cwin->display_limit);
+  if (cwin->stores->pdata[new_page]) {
+    update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
+                        cwin->buttons, cwin->tbl_cell2label,
+                        cwin->display_limit);
+  }

   cwin->page_index = new_page;

@@ -1009,6 +1085,7 @@
  /* shrink the window */
   gtk_window_resize(GTK_WINDOW(cwin), CANDWIN_DEFAULT_WIDTH, 1);

+ cwin->need_page_update = FALSE; /* avoid infinite loop with set_index() */
   uim_cand_win_gtk_set_index(cwin, new_index);
 }

@@ -1182,7 +1259,7 @@
   show_table(GTK_TABLE(cwin->view), cwin->buttons);
   gtk_widget_show(GTK_WIDGET(cwin->viewport));
   gtk_widget_show(GTK_WIDGET(cwin->scrolled_window));
-  gtk_widget_show(GTK_WIDGET(cwin->num_label));
+  gtk_widget_show_all(GTK_WIDGET(cwin->hbox));
   gtk_widget_show(GTK_WIDGET(cwin->vbox));
   gtk_widget_show(GTK_WIDGET(cwin->frame));
   gtk_widget_show(GTK_WIDGET(cwin));
=======================================
--- /trunk/gtk2/immodule/gtk-im-uim.c   Sat Oct 22 19:29:57 2011
+++ /trunk/gtk2/immodule/gtk-im-uim.c   Sat Oct 22 20:07:42 2011
@@ -127,6 +127,10 @@
 #if IM_UIM_USE_DELAY
 static void cand_delay_timer_remove(UIMCandWinGtk *cwin);
 #endif
+#if IM_UIM_USE_NEW_PAGE_HANDLING
+static GSList *get_page_candidates(IMUIMContext *uic, guint page, guint nr, guint display_limit);
+static void free_candidates(GSList *candidates);
+#endif
 static void send_im_list(void);
 static UIMCandWinGtk *im_uim_create_cand_win_gtk(void);

@@ -487,9 +491,30 @@
 static void
 index_changed_cb(UIMCandWinGtk *cwin, IMUIMContext *uic)
 {
+  gint index;
+#if IM_UIM_USE_NEW_PAGE_HANDLING
+  guint new_page;
+#endif
+
   g_return_if_fail(UIM_IS_CAND_WIN_GTK(cwin));

-  uim_set_candidate_index(uic->uc, uim_cand_win_gtk_get_index(cwin));
+  index = uim_cand_win_gtk_get_index(cwin);
+  uim_set_candidate_index(uic->uc, index);
+
+#if IM_UIM_USE_NEW_PAGE_HANDLING
+ new_page = uim_cand_win_gtk_query_new_page_by_cand_select(uic->cwin, index);
+
+  if (!uic->cwin->stores->pdata[new_page]) {
+ /* index_changed signal was triggered by prev/next page button on candwin
+     * (not from uim (cand_select_cb(), cand_shift_page_cb()))
+     */
+    guint nr = uic->cwin->nr_candidates;
+    guint display_limit = uic->cwin->display_limit;
+    GSList *list = get_page_candidates(uic, new_page, nr, display_limit);
+    uim_cand_win_gtk_set_page_candidates(uic->cwin, new_page, list);
+    free_candidates(list);
+  }
+#endif /* IM_UIM_USE_NEW_PAGE_HANDLING */
 }

 static void
=======================================
--- /trunk/gtk2/immodule/uim-cand-win-gtk.c     Sat Oct 22 19:29:57 2011
+++ /trunk/gtk2/immodule/uim-cand-win-gtk.c     Sat Oct 22 20:07:42 2011
@@ -67,6 +67,7 @@
 static void    uim_cand_win_gtk_real_create_sub_window(UIMCandWinGtk *cwin);
 static void    uim_cand_win_gtk_real_layout_sub_window (UIMCandWinGtk *cwin);

+static void    pagebutton_clicked(GtkButton *button, gpointer data);

 static GType cand_win_type = 0;
 static GTypeInfo const object_info = {
@@ -152,6 +153,7 @@
 {
   GtkWidget *frame;
   GtkWidget *vbox;
+  GtkWidget *hbox;

   /* init struct */
   cwin->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
@@ -180,7 +182,20 @@
   gtk_box_pack_start(GTK_BOX(vbox), cwin->scrolled_window, TRUE, TRUE, 0);
   uim_cand_win_gtk_set_scrollable(cwin, FALSE);

-  gtk_box_pack_start(GTK_BOX(vbox), cwin->num_label, FALSE, FALSE, 0);
+  /* hbox with prev and next page button: [[<] num_label [>]] */
+  hbox = gtk_hbox_new(FALSE, 0);
+  cwin->prev_page_button = gtk_button_new_with_label("<");
+  cwin->next_page_button = gtk_button_new_with_label(">");
+  gtk_box_pack_start(GTK_BOX(hbox), GTK_WIDGET(cwin->prev_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(hbox), cwin->num_label, FALSE, FALSE, 0);
+  gtk_box_pack_end(GTK_BOX(hbox), GTK_WIDGET(cwin->next_page_button),
+      TRUE, TRUE, 0);
+  gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
+  g_signal_connect(cwin->prev_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);
+  g_signal_connect(cwin->next_page_button, "clicked",
+      G_CALLBACK(pagebutton_clicked), cwin);

   frame = gtk_frame_new(NULL);

@@ -193,7 +208,7 @@

   /* show children */
   gtk_widget_show(cwin->scrolled_window);
-  gtk_widget_show(cwin->num_label);
+  gtk_widget_show_all(hbox);
   gtk_widget_show(vbox);
   gtk_widget_show(frame);

@@ -294,6 +309,14 @@
   cwin->nr_candidates = nr;
   cwin->display_limit = display_limit;

+  if (nr <= display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }
+
   if (cwin->stores == NULL)
     cwin->stores = g_ptr_array_new();

@@ -405,6 +428,14 @@
       }
     }
   }
+
+  if (cwin->nr_candidates <= cwin->display_limit) {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), FALSE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), FALSE);
+  } else {
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->prev_page_button), TRUE);
+    gtk_widget_set_sensitive(GTK_WIDGET(cwin->next_page_button), TRUE);
+  }

   uim_cand_win_gtk_set_page(cwin, 0);

@@ -635,6 +666,38 @@

   return new_page;
 }
+
+static void
+pagebutton_clicked(GtkButton *button, gpointer data)
+{
+  UIMCandWinGtk *cwin = UIM_CAND_WIN_GTK(data);
+  gboolean has_candidates = FALSE;
+
+  if (cwin->candidate_index < 0) {
+    /* if candidate_index < 0, "index-changed" signal is not emitted
+     * and candidates for new page is not set.
+     */
+    cwin->candidate_index = cwin->page_index * cwin->display_limit;
+  }
+  if (button == GTK_BUTTON(cwin->prev_page_button)) {
+    uim_cand_win_gtk_shift_page(cwin, FALSE);
+  } else if (button == GTK_BUTTON(cwin->next_page_button)) {
+    uim_cand_win_gtk_shift_page(cwin, TRUE);
+  } else {
+    return;
+  }
+  if (cwin->stores->pdata[cwin->page_index]) {
+    has_candidates = TRUE;
+  }
+  if (cwin->candidate_index >= 0) {
+    g_signal_emit(G_OBJECT(cwin),
+                  cand_win_gtk_signals[INDEX_CHANGED_SIGNAL], 0);
+  }
+  /* if got candidates, update view */
+  if (!has_candidates && cwin->stores->pdata[cwin->page_index]) {
+    uim_cand_win_gtk_set_page(cwin, cwin->page_index);
+  }
+}

 void
 uim_cand_win_gtk_layout(UIMCandWinGtk *cwin,
=======================================
--- /trunk/gtk2/immodule/uim-cand-win-gtk.h     Thu Jun 16 23:54:38 2011
+++ /trunk/gtk2/immodule/uim-cand-win-gtk.h     Sat Oct 22 20:07:42 2011
@@ -60,6 +60,8 @@
   GtkWidget     *scrolled_window;
   GtkWidget    *view;
   GtkWidget    *num_label;
+  GtkWidget    *prev_page_button;
+  GtkWidget    *next_page_button;

   GPtrArray    *stores;

=======================================
--- /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c Sat Oct 22 19:29:57 2011 +++ /trunk/gtk2/immodule/uim-cand-win-horizontal-gtk.c Sat Oct 22 20:07:42 2011
@@ -441,7 +441,7 @@
     horizontal_cwin->selected = idxbutton;

     /* show subwin */
-    {
+    if (cwin->stores->pdata[new_page]) {
       char *annotation = NULL;
       GtkTreeModel *model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]);
       GtkTreeIter iter;
@@ -530,6 +530,9 @@
   gint display_limit, len, cand_index = 0;

   cwin = UIM_CAND_WIN_GTK(horizontal_cwin);
+  if (!cwin->stores->pdata[new_page]) {
+    return;
+  }
   model = GTK_TREE_MODEL(cwin->stores->pdata[new_page]);
   buttons = horizontal_cwin->buttons;
   display_limit = cwin->display_limit;
=======================================
--- /trunk/gtk2/immodule/uim-cand-win-tbl-gtk.c Sat Oct 22 19:29:57 2011
+++ /trunk/gtk2/immodule/uim-cand-win-tbl-gtk.c Sat Oct 22 20:07:42 2011
@@ -488,10 +488,12 @@
   else
     new_page = page;

-  update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
-                      ctblwin->buttons, ctblwin->tbl_cell2label,
-                      cwin->display_limit);
-  show_table(GTK_TABLE(cwin->view), ctblwin->buttons);
+  if (cwin->stores->pdata[new_page]) {
+    update_table_button(GTK_TREE_MODEL(cwin->stores->pdata[new_page]),
+                        ctblwin->buttons, ctblwin->tbl_cell2label,
+                        cwin->display_limit);
+    show_table(GTK_TABLE(cwin->view), ctblwin->buttons);
+  }

   cwin->page_index = new_page;

=======================================
--- /trunk/scm/prime.scm        Thu Jan  6 18:09:56 2011
+++ /trunk/scm/prime.scm        Sat Oct 22 20:07:42 2011
@@ -2309,8 +2309,25 @@
     (if (prime-context-session context)
        (begin
          (if (eq? (prime-context-state context) 'prime-state-segment)
-             (prime-commit-segment-nth context selection-index)
-             (prime-commit-candidate context selection-index))
+              (let*
+                ((prev (prime-context-segment-nth context))
+                 (prev-page (quotient prev prime-nr-candidate-max))
+ (new-page (quotient selection-index prime-nr-candidate-max)))
+                (if (= new-page prev-page)
+                  (prime-commit-segment-nth context selection-index)
+ (prime-context-set-segment-nth! context selection-index)))
+              (let*
+                ((prev (prime-context-nth context))
+                 (page-limit
+ (if (and (eq? (prime-context-history-compare context) 'state) + (eq? (prime-context-state context) 'prime-state-preedit))
+                    3
+                    prime-nr-candidate-max))
+                 (prev-page (quotient prev page-limit))
+                 (new-page (quotient selection-index page-limit)))
+                (if (= new-page prev-page)
+                  (prime-commit-candidate context selection-index)
+                  (prime-context-set-nth! context selection-index))))
          (prime-update context)
          ))))

=======================================
--- /trunk/scm/tutcode.scm      Sat Oct 22 19:03:16 2011
+++ /trunk/scm/tutcode.scm      Sat Oct 22 20:07:42 2011
@@ -4757,7 +4757,9 @@
         (list "" "" "")))))

 ;;; ¸õÊ䥦¥£¥ó¥É¥¦¤¬¸õÊä¤òÁªÂò¤·¤¿¤È¤­¤Ë¸Æ¤Ö´Ø¿ô¡£
-;;; ÁªÂò¤µ¤ì¤¿¸õÊä¤ò³ÎÄꤹ¤ë¡£
+;;; ɽ¼¨Ãæ¤Î¸õÊ䤬ÁªÂò¤µ¤ì¤¿¾ì¹ç¡¢³ºÅö¤¹¤ë¸õÊä¤ò³ÎÄꤹ¤ë¡£
+;;; ɽ¼¨¤µ¤ì¤Æ¤¤¤Ê¤¤¸õÊ䤬ÁªÂò¤µ¤ì¤¿(¸õÊ䥦¥£¥ó¥É¥¦Â¦¤Ç
+;;; ¥Ú¡¼¥¸°ÜưÁàºî¤¬¹Ô¤ï¤ì¤¿)¾ì¹ç¡¢ÆâÉô¤ÎÁªÂò¸õÊäÈÖ¹æ¤ò¹¹¿·¤¹¤ë¤À¤±¡£
 (define (tutcode-set-candidate-index-handler c idx)
   (let* ((pc (tutcode-find-descendant-context c))
          (candwin (tutcode-context-candidate-window pc)))
@@ -4767,30 +4769,47 @@
                             tutcode-candidate-window-history))
           (>= idx 0)
           (< idx (tutcode-context-nr-candidates pc)))
-        (tutcode-context-set-nth! pc idx)
-        (case (tutcode-context-state pc)
-          ((tutcode-state-kigou)
- (tutcode-commit pc (tutcode-prepare-commit-string-for-kigou-mode pc)))
-          ((tutcode-state-history)
-            (let ((str (tutcode-prepare-commit-string-for-history pc)))
-              (tutcode-commit pc str)
-              (tutcode-flush pc)
- (tutcode-check-auto-help-window-begin pc (string-to-list str) ())))
-          (else
-            (tutcode-commit-with-auto-help pc)))
-        (tutcode-update-preedit pc))
+        (let*
+          ((prev (tutcode-context-nth pc))
+           (state (tutcode-context-state pc))
+           (page-limit
+            (case state
+ ((tutcode-state-kigou) tutcode-nr-candidate-max-for-kigou-mode) + ((tutcode-state-history) tutcode-nr-candidate-max-for-history)
+              (else tutcode-nr-candidate-max)))
+           (prev-page (quotient prev page-limit))
+           (new-page (quotient idx page-limit)))
+          (tutcode-context-set-nth! pc idx)
+          (if (= new-page prev-page)
+            (case state
+              ((tutcode-state-kigou)
+                (tutcode-commit pc
+                  (tutcode-prepare-commit-string-for-kigou-mode pc)))
+              ((tutcode-state-history)
+                (let ((str (tutcode-prepare-commit-string-for-history pc)))
+                  (tutcode-commit pc str)
+                  (tutcode-flush pc)
+                  (tutcode-check-auto-help-window-begin pc
+                    (string-to-list str) ())))
+              (else
+                (tutcode-commit-with-auto-help pc))))
+          (tutcode-update-preedit pc)))
       ((and (or (eq? candwin 'tutcode-candidate-window-predicting)
                 (eq? candwin 'tutcode-candidate-window-interactive-bushu))
             (>= idx 0))
         (let*
           ((nr-in-page (tutcode-context-prediction-nr-in-page pc))
            (page-limit (tutcode-context-prediction-page-limit pc))
-           (idx-in-page (remainder idx page-limit)))
-          (if (< idx-in-page nr-in-page)
+           (idx-in-page (remainder idx page-limit))
+           (prev (tutcode-context-prediction-index pc))
+           (prev-page (quotient prev page-limit))
+           (new-page (quotient idx page-limit)))
+          (tutcode-context-set-prediction-index! pc idx)
+          (if (and (= new-page prev-page)
+                   (< idx-in-page nr-in-page))
             (let*
               ((nr-predictions (tutcode-lib-get-nr-predictions pc))
-               (pages (quotient idx page-limit))
-               (p-idx (+ idx-in-page (* pages nr-in-page)))
+               (p-idx (+ idx-in-page (* new-page nr-in-page)))
                (i (remainder p-idx nr-predictions))
                (mode (tutcode-context-predicting pc)))
               (if (eq? candwin 'tutcode-candidate-window-interactive-bushu)
@@ -4798,8 +4817,8 @@
                 (if (eq? mode 'tutcode-predicting-bushu)
                   (tutcode-do-commit-prediction-for-bushu pc i)
                   (tutcode-do-commit-prediction pc i
-                    (eq? mode 'tutcode-predicting-completion))))
-              (tutcode-update-preedit pc))))))))
+                    (eq? mode 'tutcode-predicting-completion))))))
+          (tutcode-update-preedit pc))))))

 ;;; ÃÙ±äɽ¼¨¤ËÂбþ¤·¤Æ¤¤¤ë¸õÊ䥦¥£¥ó¥É¥¦¤¬¡¢ÂÔ¤Á»þ´ÖËþλ»þ¤Ë
 ;;; (¸õÊä¿ô¡¢¥Ú¡¼¥¸Æâ¸õÊäɽ¼¨¿ô¡¢ÁªÂò¤µ¤ì¤¿¥¤¥ó¥Ç¥Ã¥¯¥¹ÈÖ¹æ)¤ò

Reply via email to