Modified:
trunk/imbus/src/im_lookup_table.c
trunk/imbus/src/im_lookup_table.h
trunk/imbus/tests/test_byte_stream.c
trunk/imbus/tests/test_text_stream.c
Log:
Remove the usage of bitmasks from IMLookupTable.
Modified: trunk/imbus/src/im_lookup_table.c
==============================================================================
--- trunk/imbus/src/im_lookup_table.c (original)
+++ trunk/imbus/src/im_lookup_table.c Thu Nov 22 02:20:32 2007
@@ -51,14 +51,14 @@
IMObject object;
/* private */
- IMUInt32 uid;
+ IMUInt32 id;
IMUInt32 cols;
IMUInt32 rows;
IMUInt32 cursor;
IMUInt32 num_pages;
IMUInt32 cur_page;
- IMUInt16 flags;
IMUInt16 orientation;
+ IMUInt16 flags;
IMText *title;
@@ -253,17 +253,15 @@
static void
__im_lookup_table_initialize (IMPointer table)
{
- ((IMLookupTable*)table)->uid = 0;
+ ((IMLookupTable*)table)->id = 0;
((IMLookupTable*)table)->cols = 10;
((IMLookupTable*)table)->rows = 1;
((IMLookupTable*)table)->cursor = 0;
((IMLookupTable*)table)->num_pages = 1;
((IMLookupTable*)table)->cur_page = 0;
((IMLookupTable*)table)->title = 0;
- ((IMLookupTable*)table)->flags =
IM_LOOKUP_TABLE_SHOW_CURSOR |
- IM_LOOKUP_TABLE_SHOW_PAGE_FLIP_BUTTONS;
((IMLookupTable*)table)->orientation = IM_LOOKUP_TABLE_LTRTTB;
-
+ ((IMLookupTable*)table)->flags = 0;
((IMLookupTable*)table)->candidates = im_ptr_array_new ();
}
@@ -299,7 +297,7 @@
im_lookup_table_clear (dest);
- dtp->uid = stp->uid;
+ dtp->id = stp->id;
dtp->cols = stp->cols;
dtp->rows = stp->rows;
dtp->cursor = stp->cursor;
@@ -345,7 +343,7 @@
size = tp->cols * tp->rows;
- buf[0] = tp->uid;
+ buf[0] = tp->id;
buf[1] = tp->cols;
buf[2] = tp->rows;
buf[3] = tp->cursor;
@@ -409,7 +407,7 @@
im_lookup_table_clear (tp);
- tp->uid = buf[0];
+ tp->id = buf[0];
tp->cols = buf[1];
tp->rows = buf[2];
tp->cursor = buf[3];
@@ -633,26 +631,28 @@
}
IMLookupTable*
-im_lookup_table_new (IMUInt32 uid)
+im_lookup_table_new (IMUInt32 id)
{
IMLookupTable *t = (IMLookupTable *) im_object_new (IM_TYPE_LOOKUP_TABLE);
_im_assert (t != 0);
- t->uid = uid;
+ t->id = id;
return t;
}
IMLookupTable*
-im_lookup_table_new_full (IMUInt32 uid, IMUInt orientation, IMUInt
flags, IMUInt cols, IMUInt rows)
+im_lookup_table_new_full (IMUInt32 id, IMUInt orientation,
+ IMUInt cols, IMUInt rows,
+ IMLookupTableFlag *flags, IMSize n_flags)
{
+ IMSize i;
IMLookupTable *t = (IMLookupTable *) im_object_new (IM_TYPE_LOOKUP_TABLE);
_im_assert (t != 0);
- t->uid = uid;
- t->flags = flags;
+ t->id = id;
t->orientation = orientation;
if (cols == 0)
@@ -669,6 +669,14 @@
t->rows = rows;
+ if (flags && n_flags) {
+ for (i = 0; i < n_flags; ++i) {
+ /* FIXME: currently only 15 flags are supported. */
+ _im_assert(flags[i] < 16);
+ t->flags |= (1<<flags[i]);
+ }
+ }
+
return t;
}
void
@@ -694,24 +702,24 @@
im_ptr_array_clear (table->candidates);
}
void
-im_lookup_table_set_unique_id (IMLookupTable *table, IMUInt32 uid)
+im_lookup_table_set_id (IMLookupTable *table, IMUInt32 id)
{
_im_return_if_fail (IM_IS_LOOKUP_TABLE(table));
- table->uid = uid;
+ table->id = id;
}
IMUInt32
-im_lookup_table_get_unique_id (const IMLookupTable *table)
+im_lookup_table_get_id (const IMLookupTable *table)
{
_im_return_val_if_fail (IM_IS_LOOKUP_TABLE(table), (IMUInt32)-1);
- return table->uid;
+ return table->id;
}
void
im_lookup_table_set_orientation (IMLookupTable *table, IMUInt orientation)
{
_im_return_if_fail (IM_IS_LOOKUP_TABLE(table));
- table->flags = orientation;
+ table->orientation = orientation;
}
IMUInt
im_lookup_table_get_orientation (const IMLookupTable *table)
@@ -786,25 +794,23 @@
return table->cursor;
}
void
-im_lookup_table_enable_flags (IMLookupTable *table, IMUInt flags)
+im_lookup_table_set_flag (IMLookupTable *table, IMLookupTableFlag flag,
+ IMBool state)
{
_im_return_if_fail (IM_IS_LOOKUP_TABLE(table));
-
- table->flags |= flags;
-}
-void
-im_lookup_table_disable_flags (IMLookupTable *table, IMUInt flags)
-{
- _im_return_if_fail (IM_IS_LOOKUP_TABLE(table));
-
- table->flags &= ~flags;
+ _im_assert(flag < 16);
+ if (state)
+ table->flags |= (1<<flag);
+ else
+ table->flags &= ~(1<<flag);
}
IMBool
-im_lookup_table_check_flags (const IMLookupTable *table, IMUInt flags)
+im_lookup_table_check_flag (const IMLookupTable *table,
IMLookupTableFlag flag)
{
_im_return_val_if_fail (IM_IS_LOOKUP_TABLE(table), FALSE);
+ _im_assert(flag < 16);
- return (table->flags & flags) == flags;
+ return (table->flags & (1<<flag)) != 0;
}
void
im_lookup_table_set_title (IMLookupTable *table, IMText *title)
Modified: trunk/imbus/src/im_lookup_table.h
==============================================================================
--- trunk/imbus/src/im_lookup_table.h (original)
+++ trunk/imbus/src/im_lookup_table.h Thu Nov 22 02:20:32 2007
@@ -19,19 +19,19 @@
* component.
*
* IMCandidate class shall consist the following kinds of data members
of a candidate phrase.
- * - Label \n
- * type: IMText \n
+ * - Label
+ * type: IMText
* A text label to indicate the candidate on lookup table.
- * - Content \n
- * type: IMText \n
+ * - Content
+ * type: IMText
* Content of the candidate on lookup table. If the content is
empty, UIC may
* refuse to render the this item, it depends on the UIC implementation.
- * - Icon \n
- * type: IMString \n
+ * - Icon
+ * type: IMString
* The identifier (usually a path name) of an icon that UIC may display
* along with the candidate content.
- * - Annotation \n
- * type: IMObject \n
+ * - Annotation
+ * type: IMObject
* An object to annotate the candidate.
* If it's an IMText object, then it maybe a description of the candidate.
* If it's an IMLookupTable object, then it's a sub lookup table associated
@@ -141,26 +141,27 @@
/**
* @enum IMLookupTableOrientation
* @brief Layout orientation of a lookup table.
- * - IM_LOOKUP_TABLE_LTRTTB \n
+ * - IM_LOOKUP_TABLE_LTRTTB
* the layout orientation is from left to right, top to bottom.
- * - IM_LOOKUP_TABLE_RTLTTB \n
+ * - IM_LOOKUP_TABLE_RTLTTB
* the layout orientation is from right to left, top to bottom.
- * - IM_LOOKUP_TABLE_TTBLTR \n
+ * - IM_LOOKUP_TABLE_TTBLTR
* the layout orientation is from top to bottom, left to right.
- * - IM_LOOKUP_TABLE_TTBRTL \n
+ * - IM_LOOKUP_TABLE_TTBRTL
* the layout orientation is from top to bottom, right to left.
*/
typedef enum {
- IM_LOOKUP_TABLE_LTRTTB = 0,
- IM_LOOKUP_TABLE_RTLTTB = 1,
- IM_LOOKUP_TABLE_TTBLTR = 2,
- IM_LOOKUP_TABLE_TTBRTL = 3
+ IM_LOOKUP_TABLE_LTRTTB = 0,
+ IM_LOOKUP_TABLE_RTLTTB = 1,
+ IM_LOOKUP_TABLE_TTBLTR = 2,
+ IM_LOOKUP_TABLE_TTBRTL = 3
} IMLookupTableOrientation;
/**
* @enum IMLookupTableFlag
* @brief Flags to control various behaviour of a lookup table.
*
+ * A flag can be set to TRUE or FALSE
* - IM_LOOKUP_TABLE_SHOW_TITLE
* Whether to show title text or not, default not show.
* - IM_LOOKUP_TABLE_SHOW_CURSOR
@@ -182,12 +183,12 @@
* an event will be sent back to IMEngine to indicate it.
*/
typedef enum {
- IM_LOOKUP_TABLE_SHOW_TITLE = 0x01,
- IM_LOOKUP_TABLE_SHOW_CURSOR = 0x02,
- IM_LOOKUP_TABLE_SHOW_SCROLL_BAR = 0x04,
- IM_LOOKUP_TABLE_SHOW_PAGE_FLIP_BUTTONS = 0x08,
- IM_LOOKUP_TABLE_HORIZONTAL_SHRINKABLE = 0x10,
- IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE = 0x20
+ IM_LOOKUP_TABLE_SHOW_TITLE = 0,
+ IM_LOOKUP_TABLE_SHOW_CURSOR,
+ IM_LOOKUP_TABLE_SHOW_SCROLL_BAR,
+ IM_LOOKUP_TABLE_SHOW_PAGE_FLIP_BUTTONS,
+ IM_LOOKUP_TABLE_HORIZONTAL_SHRINKABLE,
+ IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE
} IMLookupTableFlag;
/**
@@ -301,37 +302,38 @@
/**
* @brief Creates a new empty IMLookupTable.
*
- * Each IMLookupTable has an unique ID to identify itself.
+ * Each IMLookupTable has an integer ID to identify itself.
* This allows an IMEngine to use multiple IMLookupTables
* at the same time. It is useful for multi-level lookup table
* case: candidates in a lookup table have other lookup table
* objects as their annotations.
*
- * @param uid a unique ID to identify this IMLookupTable.
+ * @param id an integer ID to identify this IMLookupTable.
*
* @return a new IMLookupTable.
*/
-IMLookupTable* im_lookup_table_new (IMUInt32
uid);
+IMLookupTable* im_lookup_table_new (IMUInt32
id);
/**
* @brief Creates a new empty IMLookupTable.
* @see im_lookup_table_new()
*
- * @param uid a unique ID to identify this IMLookupTable.
- * @param orientation the orientation of the IMLookupTable,
should be
- * either IM_LOOKUP_TABLE_HORIZONTAL or
- * IM_LOOKUP_TABLE_VERTICAL.
- * @param flags the bitmask of IMLookupTableFlag(s)
+ * @param id an integer ID to identify this IMLookupTable.
+ * @param orientation the orientation of the IMLookupTable.
* @param cols number of columns in the lookup table.
* @param rows number of rows in the lookup table.
+ * @param flags An array contains all flags that need to
be set to
+ * TRUE.
+ * @param n_flags Number of flags in flags array.
*
* @return a new IMLookupTable.
*/
-IMLookupTable* im_lookup_table_new_full (IMUInt32
uid,
+IMLookupTable* im_lookup_table_new_full (IMUInt32
id,
IMUInt
orientation,
- IMUInt
flags,
IMUInt
cols,
- IMUInt
rows);
+ IMUInt
rows,
+ IMLookupTableFlag
*flags,
+ IMSize
n_flags);
/**
* @brief Clears the content of an IMLookupTable.
@@ -344,41 +346,40 @@
void im_lookup_table_clear (IMLookupTable
*table);
/**
- * @brief Sets the unique ID of an IMLookupTable.
+ * @brief Sets the ID of an IMLookupTable.
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
+ * @param id A new integer ID to be used.
*/
-void im_lookup_table_set_unique_id (IMLookupTable
*table,
- IMUInt32
uid);
+void im_lookup_table_set_id (IMLookupTable
*table,
+ IMUInt32
id);
/**
- * @brief Gets the unique ID of an IMLookupTable.
+ * @brief Gets the ID of an IMLookupTable.
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
*
- * @return the unique ID.
+ * @return Integer ID of the specified IMLookupTable object.
*/
-IMUInt32 im_lookup_table_get_unique_id (const IMLookupTable
*table);
+IMUInt32 im_lookup_table_get_id (const IMLookupTable
*table);
/**
* @brief Sets the layout orientation of an IMLookupTable.
*
- * @param table an IMLookupTable.
- * @param orientation can be IM_LOOKUP_TABLE_HORIZONTAL or
- * IM_LOOKUP_TABLE_VERTICAL.
+ * @param table Pointer to an IMLookupTable object.
+ * @param orientation One of the values defined in IMLookupTableOrientation.
*/
void im_lookup_table_set_orientation (IMLookupTable
*table,
- IMUInt
orientation);
+
IMLookupTableOrientation orientation);
/**
* @brief Gets the layout orientation of an IMLookupTable.
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
*
- * @return the layout orientation, either IM_LOOKUP_TABLE_HORIZONTAL or
- * IM_LOOKUP_TABLE_VERTICAL.
+ * @return the layout orientation.
*/
-IMUInt im_lookup_table_get_orientation (const IMLookupTable
*table);
+IMLookupTableOrientation im_lookup_table_get_orientation (const
IMLookupTable *table);
/**
* @brief Sets the IMLookupTable's page size
@@ -389,7 +390,7 @@
* Candidates can be indexed by linear numbers from * 0 to (ncols *
nrows - 1).
* The layout orientation of candidates is specified by caller.
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
* @param cols number of columns (X size), must be greater than
* zero and less equal than IM_LOOKUP_TABLE_MAX_N_COLUMNS.
* @param rows number of rows (Y size), must be greater than zero
@@ -401,7 +402,7 @@
/**
* @brief Get lookup table's page size
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
* @param cols number of columns (X size).
* @param rows number of rows (Y size).
*/
@@ -412,7 +413,7 @@
* @brief Set cursor position (the currently focused candidate)
* in current page.
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
* @param cur the cursor index in that table, if beyonds the
last element,
* it will be set to the end (i.e. columns*rows - 1).
*/
@@ -422,36 +423,34 @@
/**
* @brief Get cursor position (the currently focused candidate).
*
- * @param table an IMLookupTable.
+ * @param table Pointer to an IMLookupTable object.
*
* @return the cursor index.
*/
IMUInt im_lookup_table_get_curosr (const IMLookupTable
*table);
/**
- * @brief Enable various flags for a lookup table to adjust its behaviour.
+ * @brief Enable or disable a specified flag for a lookup table to
adjust its
+ * behaviour.
*
- * @param table an IMLookupTable.
- * @param flags the flags (bitmask of IMLookupTableFlag) of lookup table.
+ * @param table Pointer to an IMLookupTable object.
+ * @param flag A flag to be enabled or disabled.
+ * @param state If it's TRUE then the specified flag will be enabled.
*/
-void im_lookup_table_enable_flags (IMLookupTable
*table,
- IMUInt
flags);
+void im_lookup_table_set_flag (IMLookupTable
*table,
+ IMLookupTableFlag
flag,
+ IMBool
state);
/**
- * @brief Disable various flags for a lookup table to adjust its behaviour.
+ * @brief Check the status of a specified flag of an IMLookupTable object.
*
- * @param table an IMLookupTable.
- * @param flags the flags (bitmask of IMLookupTableFlag) of lookup table.
- */
-void im_lookup_table_disable_flags (IMLookupTable
*table,
- IMUInt
flags);
-/**
- * @brief Check whether one or more flags is enabled or not.
+ * @param table Pointer to an IMLookupTable object.
+ * @param flags the flag to be checked.
*
- * @param table an IMLookupTable.
- * @param flags the flags (bitmask of IMLookupTableFlag) of lookup table.
+ * @return Returns TRUE if the specified flag is enabled for the specified
+ * IMLookupTable object.
*/
-IMBool im_lookup_table_check_flags (const IMLookupTable
*table,
- IMUInt
flags);
+IMBool im_lookup_table_check_flag (const IMLookupTable
*table,
+ IMLookupTableFlag
flag);
/**
* @brief Set title of a lookup table.
*
Modified: trunk/imbus/tests/test_byte_stream.c
==============================================================================
--- trunk/imbus/tests/test_byte_stream.c (original)
+++ trunk/imbus/tests/test_byte_stream.c Thu Nov 22 02:20:32 2007
@@ -30,6 +30,13 @@
IMInt32 int32dim [10] = {1,2,3,4,5,6,7,8,9,10};
+ IMSize n_flags = 3;
+ IMLookupTableFlag flags[] = {
+ IM_LOOKUP_TABLE_SHOW_TITLE,
+ IM_LOOKUP_TABLE_SHOW_CURSOR,
+ IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE
+ };
+
channel_out = im_io_channel_new_file (output, "w", NULL);
stream = im_byte_stream_new ();
@@ -127,8 +134,7 @@
table = im_lookup_table_new_full (12345,
IM_LOOKUP_TABLE_TTBLTR,
- IM_LOOKUP_TABLE_SHOW_TITLE|
IM_LOOKUP_TABLE_SHOW_CURSOR|IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE,
- 4, 4);
+ 4, 4, flags, n_flags);
im_lookup_table_set_title (table, im_text_new_from_utf8_string
("It's a Lookup Table.", -1));
im_lookup_table_set_scroll_info (table, 10, 3);
Modified: trunk/imbus/tests/test_text_stream.c
==============================================================================
--- trunk/imbus/tests/test_text_stream.c (original)
+++ trunk/imbus/tests/test_text_stream.c Thu Nov 22 02:20:32 2007
@@ -29,6 +29,13 @@
IMInt32 int32dim [10] = {1,2,3,4,5,6,7,8,9,10};
+ IMSize n_flags = 3;
+ IMLookupTableFlag flags[] = {
+ IM_LOOKUP_TABLE_SHOW_TITLE,
+ IM_LOOKUP_TABLE_SHOW_CURSOR,
+ IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE
+ };
+
channel_out = im_io_channel_unix_new (1);
stream = im_text_stream_new ();
@@ -126,8 +133,7 @@
table = im_lookup_table_new_full (12345,
IM_LOOKUP_TABLE_TTBLTR,
- IM_LOOKUP_TABLE_SHOW_TITLE|
IM_LOOKUP_TABLE_SHOW_CURSOR|IM_LOOKUP_TABLE_VERTICAL_SHRINKABLE,
- 4, 4);
+ 4, 4, flags, n_flags);
im_lookup_table_set_title (table, im_text_new_from_utf8_string
("It's a Lookup Table.", -1));
im_lookup_table_set_scroll_info (table, 10, 3);