summaryrefslogtreecommitdiffstats
path: root/src/ibuslookuptable.c
diff options
context:
space:
mode:
authorHuang Peng <shawn.p.huang@gmail.com>2009-02-14 19:41:56 +0800
committerHuang Peng <shawn.p.huang@gmail.com>2009-02-14 19:41:56 +0800
commita871e41e512c4a977d9b6504e0f166ed08c0f216 (patch)
treec9dcd8e995c36e2a79308c2d1f77e7a316998977 /src/ibuslookuptable.c
parent0e4911f38f34f5580748f6cb4b5fd584d712ef8f (diff)
downloadibus-a871e41e512c4a977d9b6504e0f166ed08c0f216.tar.gz
ibus-a871e41e512c4a977d9b6504e0f166ed08c0f216.tar.xz
ibus-a871e41e512c4a977d9b6504e0f166ed08c0f216.zip
Add API: ibus_lookup_table_{page,cursor}_{down,up}.
Diffstat (limited to 'src/ibuslookuptable.c')
-rw-r--r--src/ibuslookuptable.c96
1 files changed, 94 insertions, 2 deletions
diff --git a/src/ibuslookuptable.c b/src/ibuslookuptable.c
index e2935b8..53ea6d7 100644
--- a/src/ibuslookuptable.c
+++ b/src/ibuslookuptable.c
@@ -121,7 +121,7 @@ ibus_lookup_table_serialize (IBusLookupTable *table,
retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &table->cursor_visible);
g_return_val_if_fail (retval, FALSE);
-
+
retval = ibus_message_iter_append (iter, G_TYPE_BOOLEAN, &table->round);
g_return_val_if_fail (retval, FALSE);
@@ -168,7 +168,7 @@ ibus_lookup_table_deserialize (IBusLookupTable *table,
retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &table->cursor_visible);
g_return_val_if_fail (retval, FALSE);
-
+
retval = ibus_message_iter_get (iter, G_TYPE_BOOLEAN, &table->round);
g_return_val_if_fail (retval, FALSE);
@@ -281,6 +281,7 @@ ibus_lookup_table_set_cursor_pos (IBusLookupTable *table,
table->cursor_pos = cursor_pos;
}
+
void
ibus_lookup_table_set_page_size (IBusLookupTable *table,
guint page_size)
@@ -290,3 +291,94 @@ ibus_lookup_table_set_page_size (IBusLookupTable *table,
table->page_size = page_size;
}
+gboolean
+ibus_lookup_table_page_up (IBusLookupTable *table)
+{
+ g_assert (IBUS_IS_LOOKUP_TABLE (table));
+
+ if (table->cursor_pos < table->page_size) {
+ gint i;
+ gint page_nr;
+
+ if (!table->round) {
+ return FALSE;
+ }
+
+ /* cursor index in page */
+ i = table->cursor_pos % table->page_size;
+ page_nr = (table->candidates->len + table->page_size - 1) / table->page_size;
+
+ table->cursor_pos = page_nr * table->page_size + i;
+ if (table->cursor_pos >= table->candidates->len) {
+ table->cursor_pos = table->candidates->len - 1;
+ }
+ return TRUE;
+ }
+
+ table->cursor_pos -= table->page_size;
+ return TRUE;
+}
+
+gboolean
+ibus_lookup_table_page_down (IBusLookupTable *table)
+{
+ g_assert (IBUS_IS_LOOKUP_TABLE (table));
+
+ gint i;
+ gint page;
+ gint page_nr;
+
+ /* cursor index in page */
+ i = table->cursor_pos % table->page_size;
+ page = table->cursor_pos / table->page_size;
+ page_nr = (table->candidates->len + table->page_size - 1) / table->page_size;
+
+ if (page == page_nr - 1) {
+ if (!table->round)
+ return FALSE;
+
+ table->cursor_pos = i;
+ return TRUE;
+ }
+
+ table->cursor_pos += table->page_size;
+ if (table->cursor_pos > table->candidates->len - 1) {
+ table->cursor_pos = table->candidates->len - 1;
+ }
+ return TRUE;
+}
+
+gboolean
+ibus_lookup_table_cursor_up (IBusLookupTable *table)
+{
+ g_assert (IBUS_IS_LOOKUP_TABLE (table));
+
+ if (table->cursor_pos == 0) {
+ if (!table->round)
+ return FALSE;
+
+ table->cursor_pos = table->candidates->len - 1;
+ return TRUE;
+ }
+
+ table->cursor_pos --;
+
+ return TRUE;
+}
+
+gboolean
+ibus_lookup_table_cursor_down (IBusLookupTable *table)
+{
+ g_assert (IBUS_IS_LOOKUP_TABLE (table));
+
+ if (table->cursor_pos == table->candidates->len - 1) {
+ if (!table->round)
+ return FALSE;
+
+ table->cursor_pos = 0;
+ return TRUE;
+ }
+
+ table->cursor_pos ++;
+ return TRUE;
+}