Add eek_section_{set,get}_orientation.

This commit is contained in:
Daiki Ueno
2010-06-06 13:19:36 +09:00
parent 667418c44c
commit 15eb856ed3
6 changed files with 172 additions and 60 deletions

View File

@ -98,6 +98,27 @@ eek_clutter_section_real_get_columns (EekSection *self,
return eek_section_get_columns (EEK_SECTION(priv->simple), row); return eek_section_get_columns (EEK_SECTION(priv->simple), row);
} }
static void
eek_clutter_section_real_set_orientation (EekSection *self,
gint row,
EekOrientation orientation)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
eek_section_set_orientation (EEK_SECTION(priv->simple), row, orientation);
}
static EekOrientation
eek_clutter_section_real_get_orientation (EekSection *self,
gint row)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, EEK_ORIENTATION_INVALID);
return eek_section_get_orientation (EEK_SECTION(priv->simple), row);
}
static void static void
eek_clutter_section_real_set_angle (EekSection *self, eek_clutter_section_real_set_angle (EekSection *self,
gint angle) gint angle)
@ -219,6 +240,8 @@ eek_section_iface_init (EekSectionIface *iface)
iface->get_rows = eek_clutter_section_real_get_rows; iface->get_rows = eek_clutter_section_real_get_rows;
iface->set_columns = eek_clutter_section_real_set_columns; iface->set_columns = eek_clutter_section_real_set_columns;
iface->get_columns = eek_clutter_section_real_get_columns; iface->get_columns = eek_clutter_section_real_get_columns;
iface->set_orientation = eek_clutter_section_real_set_orientation;
iface->get_orientation = eek_clutter_section_real_get_orientation;
iface->set_angle = eek_clutter_section_real_set_angle; iface->set_angle = eek_clutter_section_real_set_angle;
iface->get_angle = eek_clutter_section_real_get_angle; iface->get_angle = eek_clutter_section_real_get_angle;
iface->set_bounds = eek_clutter_section_real_set_bounds; iface->set_bounds = eek_clutter_section_real_set_bounds;

View File

@ -157,17 +157,17 @@ eek_section_get_rows (EekSection *section)
{ {
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section); EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->get_rows); g_return_val_if_fail (iface->get_rows, -1);
return (*iface->get_rows) (section); return (*iface->get_rows) (section);
} }
/** /**
* eek_section_set_columns: * eek_section_set_columns:
* @section: an #EekSection * @section: an #EekSection
* @row: the row index in @section * @row: row index in @section
* @columns: the number of keys on @row * @columns: the number of keys on @row
* *
* Set the number of keys on @row. * Set the number of keys on the @row-th row in @section.
*/ */
void void
eek_section_set_columns (EekSection *section, eek_section_set_columns (EekSection *section,
@ -183,9 +183,9 @@ eek_section_set_columns (EekSection *section,
/** /**
* eek_section_get_columns: * eek_section_get_columns:
* @section: an #EekSection * @section: an #EekSection
* @row: the row index in @section * @row: row index in @section
* *
* Get the number of keys on @row. * Get the number of keys on the @row-th row in @section.
*/ */
gint gint
eek_section_get_columns (EekSection *section, eek_section_get_columns (EekSection *section,
@ -197,6 +197,43 @@ eek_section_get_columns (EekSection *section,
return (*iface->get_columns) (section, row); return (*iface->get_columns) (section, row);
} }
/**
* eek_section_set_orientation:
* @section: an #EekSection
* @row: row index in @section
* @orientation: either %EEK_ORIENTATION_HORIZONTAL or %EEK_ORIENTATION_VERTICAL
*
* Set the orientation of the @row-th row in @section to @orientation.
*/
void
eek_section_set_orientation (EekSection *section,
gint row,
EekOrientation orientation)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->set_orientation);
(*iface->set_orientation) (section, row, orientation);
}
/**
* eek_section_get_orientation:
* @section: an #EekSection
* @row: row index in @section
*
* Get the orientation of the @row-th row in @section.
* Returns: either %EEK_ORIENTATION_HORIZONTAL or %EEK_ORIENTATION_VERTICAL
*/
EekOrientation
eek_section_get_orientation (EekSection *section,
gint row)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_val_if_fail (iface->get_orientation, EEK_ORIENTATION_INVALID);
return (*iface->get_orientation) (section, row);
}
/** /**
* eek_section_set_angle: * eek_section_set_angle:
* @section: an #EekSection * @section: an #EekSection

View File

@ -38,72 +38,82 @@ struct _EekSectionIface
GTypeInterface g_iface; GTypeInterface g_iface;
/*< public >*/ /*< public >*/
void (* set_rows) (EekSection *self, void (* set_rows) (EekSection *self,
gint rows); gint rows);
gint (* get_rows) (EekSection *self); gint (* get_rows) (EekSection *self);
void (* set_columns) (EekSection *self, void (* set_columns) (EekSection *self,
gint row, gint row,
gint columns); gint columns);
gint (* get_columns) (EekSection *self, gint (* get_columns) (EekSection *self,
gint row); gint row);
void (* set_orientation) (EekSection *self,
gint row,
EekOrientation orientation);
EekOrientation (* get_orientation) (EekSection *self,
gint row);
void (* set_angle) (EekSection *self, void (* set_angle) (EekSection *self,
gint angle); gint angle);
gint (* get_angle) (EekSection *self); gint (* get_angle) (EekSection *self);
void (* set_bounds) (EekSection *self, void (* set_bounds) (EekSection *self,
EekBounds *bounds); EekBounds *bounds);
void (* get_bounds) (EekSection *self, void (* get_bounds) (EekSection *self,
EekBounds *bounds); EekBounds *bounds);
EekKey *(* create_key) (EekSection *self, EekKey *(* create_key) (EekSection *self,
const gchar *name, const gchar *name,
guint *keysyms, guint *keysyms,
gint num_groups, gint num_groups,
gint num_levels, gint num_levels,
gint column, gint column,
gint row, gint row,
EekOutline *outline, EekOutline *outline,
EekBounds *bounds); EekBounds *bounds);
void (* foreach_key) (EekSection *self, void (* foreach_key) (EekSection *self,
GFunc func, GFunc func,
gpointer user_data); gpointer user_data);
}; };
GType eek_section_get_type (void) G_GNUC_CONST; GType eek_section_get_type (void) G_GNUC_CONST;
void eek_section_set_rows (EekSection *section, void eek_section_set_rows (EekSection *section,
gint rows); gint rows);
gint eek_section_get_rows (EekSection *section); gint eek_section_get_rows (EekSection *section);
void eek_section_set_columns (EekSection *section, void eek_section_set_columns (EekSection *section,
gint row, gint row,
gint columns); gint columns);
gint eek_section_get_columns (EekSection *section, gint eek_section_get_columns (EekSection *section,
gint row); gint row);
void eek_section_set_orientation (EekSection *section,
gint row,
EekOrientation orientation);
EekOrientation eek_section_get_orientation (EekSection *section,
gint row);
void eek_section_set_angle (EekSection *section, void eek_section_set_angle (EekSection *section,
gint angle); gint angle);
gint eek_section_get_angle (EekSection *section); gint eek_section_get_angle (EekSection *section);
void eek_section_set_bounds (EekSection *section, void eek_section_set_bounds (EekSection *section,
EekBounds *bounds); EekBounds *bounds);
void eek_section_get_bounds (EekSection *section, void eek_section_get_bounds (EekSection *section,
EekBounds *bounds); EekBounds *bounds);
EekKey *eek_section_create_key (EekSection *section, EekKey *eek_section_create_key (EekSection *section,
const gchar *name, const gchar *name,
guint *keysyms, guint *keysyms,
gint num_groups, gint num_groups,
gint num_levels, gint num_levels,
gint column, gint column,
gint row, gint row,
EekOutline *outline, EekOutline *outline,
EekBounds *bounds); EekBounds *bounds);
void eek_section_foreach_key (EekSection *section, void eek_section_foreach_key (EekSection *section,
GFunc func, GFunc func,
gpointer user_data); gpointer user_data);
G_END_DECLS G_END_DECLS
#endif /* EEK_SECTION_H */ #endif /* EEK_SECTION_H */

View File

@ -48,6 +48,7 @@ struct _EekSimpleSectionPrivate
gchar *name; gchar *name;
gint num_rows; gint num_rows;
gint *num_columns; gint *num_columns;
EekOrientation *orientations;
gint angle; gint angle;
EekBounds bounds; EekBounds bounds;
GSList *keys; GSList *keys;
@ -65,6 +66,9 @@ eek_simple_section_real_set_rows (EekSection *self,
if (rows > 0) { if (rows > 0) {
g_free (priv->num_columns); g_free (priv->num_columns);
priv->num_columns = g_slice_alloc (sizeof(gint) * priv->num_rows); priv->num_columns = g_slice_alloc (sizeof(gint) * priv->num_rows);
g_free (priv->orientations);
priv->orientations =
g_slice_alloc (sizeof(EekOrientation) * priv->num_rows);
} }
} }
@ -100,6 +104,29 @@ eek_simple_section_real_get_columns (EekSection *self,
return priv->num_columns[row]; return priv->num_columns[row];
} }
static void
eek_simple_section_real_set_orientation (EekSection *self,
gint row,
EekOrientation orientation)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
g_return_if_fail (0 <= row && row < priv->num_rows);
priv->orientations[row] = orientation;
}
static EekOrientation
eek_simple_section_real_get_orientation (EekSection *self,
gint row)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, EEK_ORIENTATION_INVALID);
g_return_if_fail (0 <= row && row < priv->num_rows);
return priv->orientations[row];
}
static void static void
eek_simple_section_real_set_angle (EekSection *self, eek_simple_section_real_set_angle (EekSection *self,
gint angle) gint angle)
@ -193,6 +220,8 @@ eek_section_iface_init (EekSectionIface *iface)
iface->get_rows = eek_simple_section_real_get_rows; iface->get_rows = eek_simple_section_real_get_rows;
iface->set_columns = eek_simple_section_real_set_columns; iface->set_columns = eek_simple_section_real_set_columns;
iface->get_columns = eek_simple_section_real_get_columns; iface->get_columns = eek_simple_section_real_get_columns;
iface->set_orientation = eek_simple_section_real_set_orientation;
iface->get_orientation = eek_simple_section_real_get_orientation;
iface->set_angle = eek_simple_section_real_set_angle; iface->set_angle = eek_simple_section_real_set_angle;
iface->get_angle = eek_simple_section_real_get_angle; iface->get_angle = eek_simple_section_real_get_angle;
iface->set_bounds = eek_simple_section_real_set_bounds; iface->set_bounds = eek_simple_section_real_set_bounds;
@ -221,6 +250,7 @@ eek_simple_section_finalize (GObject *object)
g_free (priv->name); g_free (priv->name);
g_slist_free (priv->keys); g_slist_free (priv->keys);
g_slice_free (gint, priv->num_columns); g_slice_free (gint, priv->num_columns);
g_slice_free (EekOrientation, priv->orientations);
G_OBJECT_CLASS (eek_simple_section_parent_class)->finalize (object); G_OBJECT_CLASS (eek_simple_section_parent_class)->finalize (object);
} }
@ -316,4 +346,5 @@ eek_simple_section_init (EekSimpleSection *self)
priv->keys = NULL; priv->keys = NULL;
priv->num_rows = 0; priv->num_rows = 0;
priv->num_columns = NULL; priv->num_columns = NULL;
priv->orientations = NULL;
} }

View File

@ -24,6 +24,12 @@
G_BEGIN_DECLS G_BEGIN_DECLS
typedef enum {
EEK_ORIENTATION_VERTICAL,
EEK_ORIENTATION_HORIZONTAL,
EEK_ORIENTATION_INVALID = -1
} EekOrientation;
typedef struct _EekKeyboard EekKeyboard; typedef struct _EekKeyboard EekKeyboard;
/** /**

View File

@ -242,6 +242,11 @@ create_section (EekXkbLayout *layout,
left = xkbrow->left; left = xkbrow->left;
top = xkbrow->top; top = xkbrow->top;
eek_section_set_columns (section, i, xkbrow->num_keys); eek_section_set_columns (section, i, xkbrow->num_keys);
eek_section_set_orientation (section,
i,
xkbrow->vertical ?
EEK_ORIENTATION_VERTICAL :
EEK_ORIENTATION_HORIZONTAL);
for (j = 0; j < xkbrow->num_keys; j++) { for (j = 0; j < xkbrow->num_keys; j++) {
XkbKeyRec *xkbkey; XkbKeyRec *xkbkey;
XkbBoundsRec *xkbbounds; XkbBoundsRec *xkbbounds;