Revision: 6401
Author: ek.kato
Date: Sun May 30 19:44:48 2010
Log: * emacs/uim-types.h
- Define UIM_EL_USE_NEWPAGE_HANDLING.
- (candidate) : Add page_index member.
* emacs/candidate.c
- (set_page_candidates) : New.
- (new_candidate) : Set only the first page.
- (select_candidate) : New.
- (shift_candidate_page) : Set candidates when page is shifted.
* emacs/candidate.h : Add select_candidate().
* emacs/callback.c (candidate_select_cb) : Call select_candidate().
http://code.google.com/p/uim/source/detail?r=6401
Modified:
/trunk/emacs/callback.c
/trunk/emacs/candidate.c
/trunk/emacs/candidate.h
/trunk/emacs/uim-el-types.h
=======================================
--- /trunk/emacs/callback.c Sun Apr 4 20:35:54 2010
+++ /trunk/emacs/callback.c Sun May 30 19:44:48 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
}
=======================================
--- /trunk/emacs/candidate.c Sun Apr 4 20:35:54 2010
+++ /trunk/emacs/candidate.c Sun May 30 19:44:48 2010
@@ -46,12 +46,42 @@
return cand;
}
+
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+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 +90,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 = uim_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 +104,13 @@
cand->cand_array[i].label =
uim_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 +183,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 +218,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 +274,8 @@
cand->index = index;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+ set_page_candidates(context, cand);
+#endif
uim_set_candidate_index(context, index);
}
=======================================
--- /trunk/emacs/candidate.h Sun Apr 4 20:35:54 2010
+++ /trunk/emacs/candidate.h Sun May 30 19:44:48 2010
@@ -56,6 +56,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);
=======================================
--- /trunk/emacs/uim-el-types.h Sun Apr 4 20:35:54 2010
+++ /trunk/emacs/uim-el-types.h Sun May 30 19:44:48 2010
@@ -38,6 +38,7 @@
#define UIM_EMACS_UIM_EL_TYPES_H
#include <config.h>
+#define UIM_EL_USE_NEW_PAGE_HANDLING 1
typedef struct candidate {
char *str;
@@ -50,6 +51,9 @@
int num;
int disp_limit;
int index;
+#if UIM_EL_USE_NEW_PAGE_HANDLING
+ int page_index;
+#endif
candidate *cand_array;
} candidate_info;