Revision: 6403
Author: ek.kato
Date: Sun May 30 20:47:11 2010
Log: * Merge r6400:6402 from trunk.

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

Modified:
 /branches/1.5/emacs
 /branches/1.5/emacs/callback.c
 /branches/1.5/emacs/candidate.c
 /branches/1.5/emacs/candidate.h
 /branches/1.5/emacs/uim-el-types.h

=======================================
--- /branches/1.5/emacs/callback.c      Sun Apr  4 20:39:49 2010
+++ /branches/1.5/emacs/callback.c      Sun May 30 20:47:11 2010
@@ -106,7 +106,11 @@

   debug_printf(DEBUG_NOTE, "candidate_select_cb (index: %d)\n", index);

+#if !UIM_EL_USE_NEW_PAGE_HANDLING
   ua->cand->index = index;
+#else
+  select_candidate(ua->context, ua->cand, index);
+#endif
 }


=======================================
--- /branches/1.5/emacs/candidate.c     Sun Apr  4 20:39:49 2010
+++ /branches/1.5/emacs/candidate.c     Sun May 30 20:47:11 2010
@@ -46,12 +46,43 @@

   return cand;
 }
+
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+static int
+set_page_candidates(uim_context context, candidate_info *cand)
+{
+  int i, nr_in_page, start;
+
+  start = cand->page_index * cand->disp_limit;
+  if (cand->disp_limit && ((cand->num - start) > cand->disp_limit))
+    nr_in_page = cand->disp_limit;
+  else
+    nr_in_page = cand->num - start;
+
+  for (i = start; i < (start + nr_in_page); i++) {
+    uim_candidate u_cand;
+
+    u_cand = uim_get_candidate(context, i, cand->disp_limit ?
+                                          i % cand->disp_limit :
+                                          i);
+    free(cand->cand_array[i].str);
+    free(cand->cand_array[i].label);
+ cand->cand_array[i].str = uim_strdup(uim_candidate_get_cand_str(u_cand)); + cand->cand_array[i].label = uim_strdup(uim_candidate_get_heading_label(u_cand));
+    uim_candidate_free(u_cand);
+  }
+
+  return 1;
+}
+#endif

 int
new_candidate(uim_context context, candidate_info *cand, int num, int limit)
 {
   int i;
+#if !UIM_EL_USE_NEW_PAGE_HANDLING
   uim_candidate u_cand;
+#endif

   if (cand->valid) clear_candidate(cand);

@@ -60,9 +91,13 @@
   cand->index = -1;
   cand->disp_limit = limit;
   cand->num = num;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+  cand->page_index = 0;
+#endif

   cand->cand_array = (candidate *)malloc(sizeof(candidate) * num);

+#if !UIM_EL_USE_NEW_PAGE_HANDLING
   /* get candidates from context */
   for (i = 0; i < num; i ++) {
        u_cand = uim_get_candidate(context, i, limit ? i % limit : i);
@@ -70,6 +105,13 @@
cand->cand_array[i].label = strdup(uim_candidate_get_heading_label(u_cand));
        uim_candidate_free(u_cand);
   }
+#else
+  for (i = 0; i < num; i++) {
+       cand->cand_array[i].str = NULL;
+       cand->cand_array[i].label = NULL;
+  }
+  set_page_candidates(context, cand);
+#endif

   return 1;
 }
@@ -142,12 +184,32 @@
   }
 }

-
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+void
+select_candidate(uim_context context, candidate_info *cand, int index)
+{
+  int new_page;
+  int index_in_page;
+
+  new_page = cand->disp_limit ? index / cand->disp_limit : 0;
+  index_in_page = cand->disp_limit ? index % cand->disp_limit : index;
+
+  cand->index = index;
+
+  if (new_page != cand->page_index) {
+    cand->page_index = new_page;
+    set_page_candidates(context, cand);
+  }
+}
+#endif

 void
shift_candidate_page(uim_context context, candidate_info *cand, int direction)
 {
   int index;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+  int page, nr_pages;
+#endif
   int is_first = 0, is_last = 0;

   debug_printf(DEBUG_NOTE,
@@ -157,29 +219,54 @@
     return;

   index = cand->index;
-
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+  page = cand->page_index;
+#endif
+
+#if !UIM_EL_USE_NEW_PAGE_HANDLING
   is_first = (index < cand->disp_limit);

   /*
    * ((cand.num - 1) / cand.disp_limit) + 1   : total pages
-   * (index / cand.disp_limit) + 1            : current page number
+   * (index / cand.disp_limit)                : current page number
    */
   is_last = ((((cand->num - 1) / cand->disp_limit) + 1)
                         == ((index / cand->disp_limit) + 1));
-
+#else
+  is_first = (page == 0);
+  nr_pages = ((cand->num - 1) / cand->disp_limit) + 1;
+  is_last = (nr_pages == page);
+#endif
+
   if (direction) { /* forward */

-       if (is_last)
+       if (is_last) {
          index = index % cand->disp_limit;
-       else
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+         cand->page_index = 0;
+#endif
+       }
+       else {
          index += cand->disp_limit;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+         cand->page_index++;
+#endif
+       }

   } else { /* backward */

-       if (is_first)
+       if (is_first) {
          index = (cand->num / cand->disp_limit) * cand->disp_limit + index;
-    else
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+         cand->page_index = nr_pages - 1;
+#endif
+       }
+    else {
          index -= cand->disp_limit;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+         cand->page_index--;
+#endif
+    }
   }

   if (index < 0) index = 0;
@@ -188,5 +275,8 @@

   cand->index = index;

+#if UIM_EL_USE_NEW_PAGE_HANDLING
+  set_page_candidates(context, cand);
+#endif
   uim_set_candidate_index(context, index);
 }
=======================================
--- /branches/1.5/emacs/candidate.h     Sun Apr  4 20:39:49 2010
+++ /branches/1.5/emacs/candidate.h     Sun May 30 20:47:11 2010
@@ -54,6 +54,9 @@
 void clear_candidate(candidate_info *cand);

 int show_candidate(candidate_info *cand);
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+void select_candidate(uim_context context, candidate_info *cand, int index);
+#endif

 void shift_candidate_page(uim_context context, candidate_info *cand,
                                                  int direction);
=======================================
--- /branches/1.5/emacs/uim-el-types.h  Sun Apr  4 20:39:49 2010
+++ /branches/1.5/emacs/uim-el-types.h  Sun May 30 20:47:11 2010
@@ -37,6 +37,8 @@
 #ifndef UIM_EL_TYPES_H
 #define UIM_EL_TYPES_H

+#define UIM_EL_USE_NEW_PAGE_HANDLING   1
+
 typedef struct candidate {
   char *str;
   char *label;
@@ -48,6 +50,9 @@
   int num;
   int disp_limit;
   int index;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+  int page_index;
+#endif
   candidate *cand_array;
 } candidate_info;

Reply via email to