Add API: ibus_lookup_table_{page,cursor}_{down,up}.

This commit is contained in:
Huang Peng 2009-02-14 19:41:56 +08:00
Родитель 0e4911f38f
Коммит a871e41e51
2 изменённых файлов: 99 добавлений и 2 удалений

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -80,6 +80,11 @@ void ibus_lookup_table_set_page_size
(IBusLookupTable *table,
guint page_size);
void ibus_lookup_table_clear (IBusLookupTable *table);
gboolean ibus_lookup_table_page_up (IBusLookupTable *table);
gboolean ibus_lookup_table_page_down(IBusLookupTable *table);
gboolean ibus_lookup_table_cursor_up(IBusLookupTable *table);
gboolean ibus_lookup_table_cursor_down
(IBusLookupTable *table);
G_END_DECLS
#endif