|
Packit |
3ff832 |
/* -*- mode: C; c-basic-offset: 4; indent-tabs-mode: nil; -*- */
|
|
Packit |
3ff832 |
/* vim:set et sts=4: */
|
|
Packit |
3ff832 |
/* IBus - The Input Bus
|
|
Packit |
3ff832 |
* Copyright (C) 2008-2010 Peng Huang <shawn.p.huang@gmail.com>
|
|
Packit |
3ff832 |
* Copyright (C) 2008-2010 Red Hat, Inc.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
3ff832 |
* modify it under the terms of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License as published by the Free Software Foundation; either
|
|
Packit |
3ff832 |
* version 2.1 of the License, or (at your option) any later version.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
3ff832 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
3ff832 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
3ff832 |
* Lesser General Public License for more details.
|
|
Packit |
3ff832 |
*
|
|
Packit |
3ff832 |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
3ff832 |
* License along with this library; if not, write to the Free Software
|
|
Packit |
3ff832 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
|
|
Packit |
3ff832 |
* USA
|
|
Packit |
3ff832 |
*/
|
|
Packit |
3ff832 |
#include "ibuslookuptable.h"
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* functions prototype */
|
|
Packit |
3ff832 |
static void ibus_lookup_table_destroy (IBusLookupTable *table);
|
|
Packit |
3ff832 |
static gboolean ibus_lookup_table_serialize (IBusLookupTable *table,
|
|
Packit |
3ff832 |
GVariantBuilder *builder);
|
|
Packit |
3ff832 |
static gint ibus_lookup_table_deserialize (IBusLookupTable *table,
|
|
Packit |
3ff832 |
GVariant *variant);
|
|
Packit |
3ff832 |
static gboolean ibus_lookup_table_copy (IBusLookupTable *dest,
|
|
Packit |
3ff832 |
IBusLookupTable *src);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
G_DEFINE_TYPE (IBusLookupTable, ibus_lookup_table, IBUS_TYPE_SERIALIZABLE)
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_lookup_table_class_init (IBusLookupTableClass *class)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
IBusObjectClass *object_class = IBUS_OBJECT_CLASS (class);
|
|
Packit |
3ff832 |
IBusSerializableClass *serializable_class = IBUS_SERIALIZABLE_CLASS (class);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
object_class->destroy = (IBusObjectDestroyFunc) ibus_lookup_table_destroy;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
serializable_class->serialize = (IBusSerializableSerializeFunc) ibus_lookup_table_serialize;
|
|
Packit |
3ff832 |
serializable_class->deserialize = (IBusSerializableDeserializeFunc) ibus_lookup_table_deserialize;
|
|
Packit |
3ff832 |
serializable_class->copy = (IBusSerializableCopyFunc) ibus_lookup_table_copy;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_lookup_table_init (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
table->candidates = g_array_new (TRUE, TRUE, sizeof (IBusText *));
|
|
Packit |
3ff832 |
table->labels = g_array_new (TRUE, TRUE, sizeof (IBusText *));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static void
|
|
Packit |
3ff832 |
ibus_lookup_table_destroy (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
IBusText **p;
|
|
Packit |
3ff832 |
gint i;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->candidates != NULL) {
|
|
Packit |
3ff832 |
p = (IBusText **) g_array_free (table->candidates, FALSE);
|
|
Packit |
3ff832 |
table->candidates = NULL;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
for (i = 0; p[i] != NULL; i++) {
|
|
Packit |
3ff832 |
g_object_unref (p[i]);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_free (p);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->labels != NULL) {
|
|
Packit |
3ff832 |
p = (IBusText **) g_array_free (table->labels, FALSE);
|
|
Packit |
3ff832 |
table->labels = NULL;
|
|
Packit |
3ff832 |
for (i = 0; p[i] != NULL; i++) {
|
|
Packit |
3ff832 |
g_object_unref (p[i]);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_free (p);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBUS_OBJECT_CLASS (ibus_lookup_table_parent_class)->destroy ((IBusObject *) table);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_serialize (IBusLookupTable *table,
|
|
Packit |
3ff832 |
GVariantBuilder *builder)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
gboolean retval;
|
|
Packit |
3ff832 |
guint i;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->serialize ((IBusSerializable *)table, builder);
|
|
Packit |
3ff832 |
g_return_val_if_fail (retval, 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "u", table->page_size);
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "u", table->cursor_pos);
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "b", table->cursor_visible);
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "b", table->round);
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "i", table->orientation);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GVariantBuilder array;
|
|
Packit |
3ff832 |
/* append candidates */
|
|
Packit |
3ff832 |
g_variant_builder_init (&array, G_VARIANT_TYPE ("av"));
|
|
Packit |
3ff832 |
for (i = 0;; i++) {
|
|
Packit |
3ff832 |
IBusText *text = ibus_lookup_table_get_candidate (table, i);
|
|
Packit |
3ff832 |
if (text == NULL)
|
|
Packit |
3ff832 |
break;
|
|
Packit |
3ff832 |
g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)text));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "av", &array);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* append labels */
|
|
Packit |
3ff832 |
g_variant_builder_init (&array, G_VARIANT_TYPE ("av"));
|
|
Packit |
3ff832 |
for (i = 0;; i++) {
|
|
Packit |
3ff832 |
IBusText *text = ibus_lookup_table_get_label (table, i);
|
|
Packit |
3ff832 |
if (text == NULL)
|
|
Packit |
3ff832 |
break;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_variant_builder_add (&array, "v", ibus_serializable_serialize ((IBusSerializable *)text));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_variant_builder_add (builder, "av", &array);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static gint
|
|
Packit |
3ff832 |
ibus_lookup_table_deserialize (IBusLookupTable *table,
|
|
Packit |
3ff832 |
GVariant *variant)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
gint retval;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->deserialize ((IBusSerializable *)table, variant);
|
|
Packit |
3ff832 |
g_return_val_if_fail (retval, 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (table), 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "u", &table->page_size);
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "u", &table->cursor_pos);
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "b", &table->cursor_visible);
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "b", &table->round);
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "i", &table->orientation);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
GVariant *var;
|
|
Packit |
3ff832 |
// deserialize candidates
|
|
Packit |
3ff832 |
GVariantIter *iter = NULL;
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "av", &iter);
|
|
Packit |
3ff832 |
while (g_variant_iter_loop (iter, "v", &var)) {
|
|
Packit |
3ff832 |
ibus_lookup_table_append_candidate (table, IBUS_TEXT (ibus_serializable_deserialize (var)));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_variant_iter_free (iter);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
// deserialize labels
|
|
Packit |
3ff832 |
iter = NULL;
|
|
Packit |
3ff832 |
g_variant_get_child (variant, retval++, "av", &iter);
|
|
Packit |
3ff832 |
while (g_variant_iter_loop (iter, "v", &var)) {
|
|
Packit |
3ff832 |
ibus_lookup_table_append_label (table, IBUS_TEXT (ibus_serializable_deserialize (var)));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
g_variant_iter_free (iter);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return retval;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
static gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_copy (IBusLookupTable *dest,
|
|
Packit |
3ff832 |
IBusLookupTable *src)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
gboolean retval;
|
|
Packit |
3ff832 |
guint i;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
retval = IBUS_SERIALIZABLE_CLASS (ibus_lookup_table_parent_class)->copy ((IBusSerializable *)dest, (IBusSerializable *)src);
|
|
Packit |
3ff832 |
g_return_val_if_fail (retval, FALSE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (dest), FALSE);
|
|
Packit |
3ff832 |
g_return_val_if_fail (IBUS_IS_LOOKUP_TABLE (src), FALSE);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
// copy candidates
|
|
Packit |
3ff832 |
for (i = 0;; i++) {
|
|
Packit |
3ff832 |
IBusText *text;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
text = ibus_lookup_table_get_candidate (src, i);
|
|
Packit |
3ff832 |
if (text == NULL)
|
|
Packit |
3ff832 |
break;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
text = (IBusText *) ibus_serializable_copy ((IBusSerializable *) text);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
ibus_lookup_table_append_candidate (dest, text);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
// copy labels
|
|
Packit |
3ff832 |
for (i = 0;; i++) {
|
|
Packit |
3ff832 |
IBusText *text;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
text = ibus_lookup_table_get_label (src, i);
|
|
Packit |
3ff832 |
if (text == NULL)
|
|
Packit |
3ff832 |
break;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
text = (IBusText *) ibus_serializable_copy ((IBusSerializable *) text);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
ibus_lookup_table_append_label (dest, text);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusLookupTable *
|
|
Packit |
3ff832 |
ibus_lookup_table_new (guint page_size,
|
|
Packit |
3ff832 |
guint cursor_pos,
|
|
Packit |
3ff832 |
gboolean cursor_visible,
|
|
Packit |
3ff832 |
gboolean round)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (page_size > 0);
|
|
Packit |
3ff832 |
g_assert (page_size <= 16);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusLookupTable *table;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table= g_object_new (IBUS_TYPE_LOOKUP_TABLE, NULL);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->page_size = page_size;
|
|
Packit |
3ff832 |
table->cursor_pos = cursor_pos;
|
|
Packit |
3ff832 |
table->cursor_visible = cursor_visible;
|
|
Packit |
3ff832 |
table->round = round;
|
|
Packit |
3ff832 |
table->orientation = IBUS_ORIENTATION_SYSTEM;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
guint
|
|
Packit |
3ff832 |
ibus_lookup_table_get_number_of_candidates (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->candidates->len;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_append_candidate (IBusLookupTable *table,
|
|
Packit |
3ff832 |
IBusText *text)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_TEXT (text));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_object_ref_sink (text);
|
|
Packit |
3ff832 |
g_array_append_val (table->candidates, text);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusText *
|
|
Packit |
3ff832 |
ibus_lookup_table_get_candidate (IBusLookupTable *table,
|
|
Packit |
3ff832 |
guint index)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (index >= table->candidates->len)
|
|
Packit |
3ff832 |
return NULL;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return g_array_index (table->candidates, IBusText *, index);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_append_label (IBusLookupTable *table,
|
|
Packit |
3ff832 |
IBusText *text)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_TEXT (text));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_object_ref_sink (text);
|
|
Packit |
3ff832 |
g_array_append_val (table->labels, text);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_label (IBusLookupTable *table,
|
|
Packit |
3ff832 |
guint index,
|
|
Packit |
3ff832 |
IBusText *text)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_TEXT (text));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->labels->len <= index) {
|
|
Packit |
3ff832 |
g_array_set_size (table->labels, index + 1);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusText *old = ibus_lookup_table_get_label (table, index);
|
|
Packit |
3ff832 |
if (old != NULL) {
|
|
Packit |
3ff832 |
g_object_unref (old);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_object_ref_sink (text);
|
|
Packit |
3ff832 |
g_array_index (table->labels, IBusText *, index) = text;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
IBusText *
|
|
Packit |
3ff832 |
ibus_lookup_table_get_label (IBusLookupTable *table,
|
|
Packit |
3ff832 |
guint index)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (index >= table->labels->len)
|
|
Packit |
3ff832 |
return NULL;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return g_array_index (table->labels, IBusText *, index);
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_clear (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gint index;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
for (index = 0; index < table->candidates->len; index ++) {
|
|
Packit |
3ff832 |
g_object_unref (g_array_index (table->candidates, IBusText *, index));
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
g_array_set_size (table->candidates, 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = 0;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_cursor_pos (IBusLookupTable *table,
|
|
Packit |
3ff832 |
guint cursor_pos)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (cursor_pos < table->candidates->len);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = cursor_pos;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
guint
|
|
Packit |
3ff832 |
ibus_lookup_table_get_cursor_pos (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->cursor_pos;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
guint
|
|
Packit |
3ff832 |
ibus_lookup_table_get_cursor_in_page (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->cursor_pos % table->page_size;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_cursor_visible (IBusLookupTable *table,
|
|
Packit |
3ff832 |
gboolean visible)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_visible = visible;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_is_cursor_visible (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->cursor_visible;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_page_size (IBusLookupTable *table,
|
|
Packit |
3ff832 |
guint page_size)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (page_size > 0);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->page_size = page_size;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
guint
|
|
Packit |
3ff832 |
ibus_lookup_table_get_page_size (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->page_size;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_round (IBusLookupTable *table,
|
|
Packit |
3ff832 |
gboolean round)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->round = round ? TRUE: FALSE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_is_round (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->round;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
void
|
|
Packit |
3ff832 |
ibus_lookup_table_set_orientation (IBusLookupTable *table,
|
|
Packit |
3ff832 |
gint orientation)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
g_assert (orientation == IBUS_ORIENTATION_HORIZONTAL ||
|
|
Packit |
3ff832 |
orientation == IBUS_ORIENTATION_VERTICAL ||
|
|
Packit |
3ff832 |
orientation == IBUS_ORIENTATION_SYSTEM);
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->orientation = orientation;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gint
|
|
Packit |
3ff832 |
ibus_lookup_table_get_orientation (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return table->orientation;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_page_up (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->cursor_pos < table->page_size) {
|
|
Packit |
3ff832 |
gint i;
|
|
Packit |
3ff832 |
gint page_nr;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (!table->round) {
|
|
Packit |
3ff832 |
return FALSE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* cursor index in page */
|
|
Packit |
3ff832 |
i = table->cursor_pos % table->page_size;
|
|
Packit |
3ff832 |
page_nr = (table->candidates->len + table->page_size - 1) / table->page_size;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = page_nr * table->page_size + i;
|
|
Packit |
3ff832 |
if (table->cursor_pos >= table->candidates->len) {
|
|
Packit |
3ff832 |
table->cursor_pos = table->candidates->len - 1;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos -= table->page_size;
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_page_down (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gint i;
|
|
Packit |
3ff832 |
gint page;
|
|
Packit |
3ff832 |
gint page_nr;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
/* cursor index in page */
|
|
Packit |
3ff832 |
i = table->cursor_pos % table->page_size;
|
|
Packit |
3ff832 |
page = table->cursor_pos / table->page_size;
|
|
Packit |
3ff832 |
page_nr = (table->candidates->len + table->page_size - 1) / table->page_size;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (page == page_nr - 1) {
|
|
Packit |
3ff832 |
if (!table->round)
|
|
Packit |
3ff832 |
return FALSE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = i;
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos += table->page_size;
|
|
Packit |
3ff832 |
if (table->cursor_pos > table->candidates->len - 1) {
|
|
Packit |
3ff832 |
table->cursor_pos = table->candidates->len - 1;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_cursor_up (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->cursor_pos == 0) {
|
|
Packit |
3ff832 |
if (!table->round)
|
|
Packit |
3ff832 |
return FALSE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = table->candidates->len - 1;
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos --;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
gboolean
|
|
Packit |
3ff832 |
ibus_lookup_table_cursor_down (IBusLookupTable *table)
|
|
Packit |
3ff832 |
{
|
|
Packit |
3ff832 |
g_assert (IBUS_IS_LOOKUP_TABLE (table));
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
if (table->cursor_pos == table->candidates->len - 1) {
|
|
Packit |
3ff832 |
if (!table->round)
|
|
Packit |
3ff832 |
return FALSE;
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos = 0;
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|
|
Packit |
3ff832 |
|
|
Packit |
3ff832 |
table->cursor_pos ++;
|
|
Packit |
3ff832 |
return TRUE;
|
|
Packit |
3ff832 |
}
|