diff --git a/eek/eek-clutter-section.c b/eek/eek-clutter-section.c index cc4a4585..579315cb 100644 --- a/eek/eek-clutter-section.c +++ b/eek/eek-clutter-section.c @@ -98,6 +98,27 @@ eek_clutter_section_real_get_columns (EekSection *self, 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 eek_clutter_section_real_set_angle (EekSection *self, gint angle) @@ -219,6 +240,8 @@ eek_section_iface_init (EekSectionIface *iface) iface->get_rows = eek_clutter_section_real_get_rows; iface->set_columns = eek_clutter_section_real_set_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->get_angle = eek_clutter_section_real_get_angle; iface->set_bounds = eek_clutter_section_real_set_bounds; diff --git a/eek/eek-section.c b/eek/eek-section.c index e394ecbe..11c02d76 100644 --- a/eek/eek-section.c +++ b/eek/eek-section.c @@ -157,17 +157,17 @@ eek_section_get_rows (EekSection *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); } /** * eek_section_set_columns: * @section: an #EekSection - * @row: the row index in @section + * @row: row index in @section * @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 eek_section_set_columns (EekSection *section, @@ -183,9 +183,9 @@ eek_section_set_columns (EekSection *section, /** * eek_section_get_columns: * @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 eek_section_get_columns (EekSection *section, @@ -197,6 +197,43 @@ eek_section_get_columns (EekSection *section, 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: * @section: an #EekSection diff --git a/eek/eek-section.h b/eek/eek-section.h index 7b754d0d..ffd563fe 100644 --- a/eek/eek-section.h +++ b/eek/eek-section.h @@ -38,72 +38,82 @@ struct _EekSectionIface GTypeInterface g_iface; /*< public >*/ - void (* set_rows) (EekSection *self, - gint rows); - gint (* get_rows) (EekSection *self); - void (* set_columns) (EekSection *self, - gint row, - gint columns); - gint (* get_columns) (EekSection *self, - gint row); + void (* set_rows) (EekSection *self, + gint rows); + gint (* get_rows) (EekSection *self); + void (* set_columns) (EekSection *self, + gint row, + gint columns); + gint (* get_columns) (EekSection *self, + gint row); + void (* set_orientation) (EekSection *self, + gint row, + EekOrientation orientation); + EekOrientation (* get_orientation) (EekSection *self, + gint row); - void (* set_angle) (EekSection *self, - gint angle); - gint (* get_angle) (EekSection *self); + void (* set_angle) (EekSection *self, + gint angle); + gint (* get_angle) (EekSection *self); - void (* set_bounds) (EekSection *self, - EekBounds *bounds); - void (* get_bounds) (EekSection *self, - EekBounds *bounds); + void (* set_bounds) (EekSection *self, + EekBounds *bounds); + void (* get_bounds) (EekSection *self, + EekBounds *bounds); - EekKey *(* create_key) (EekSection *self, - const gchar *name, - guint *keysyms, - gint num_groups, - gint num_levels, - gint column, - gint row, - EekOutline *outline, - EekBounds *bounds); + EekKey *(* create_key) (EekSection *self, + const gchar *name, + guint *keysyms, + gint num_groups, + gint num_levels, + gint column, + gint row, + EekOutline *outline, + EekBounds *bounds); - void (* foreach_key) (EekSection *self, - GFunc func, - gpointer user_data); + void (* foreach_key) (EekSection *self, + GFunc func, + 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, - gint rows); -gint eek_section_get_rows (EekSection *section); -void eek_section_set_columns (EekSection *section, - gint row, - gint columns); -gint eek_section_get_columns (EekSection *section, - gint row); +void eek_section_set_rows (EekSection *section, + gint rows); +gint eek_section_get_rows (EekSection *section); +void eek_section_set_columns (EekSection *section, + gint row, + gint columns); +gint eek_section_get_columns (EekSection *section, + 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, - gint angle); -gint eek_section_get_angle (EekSection *section); +void eek_section_set_angle (EekSection *section, + gint angle); +gint eek_section_get_angle (EekSection *section); -void eek_section_set_bounds (EekSection *section, - EekBounds *bounds); -void eek_section_get_bounds (EekSection *section, - EekBounds *bounds); +void eek_section_set_bounds (EekSection *section, + EekBounds *bounds); +void eek_section_get_bounds (EekSection *section, + EekBounds *bounds); -EekKey *eek_section_create_key (EekSection *section, - const gchar *name, - guint *keysyms, - gint num_groups, - gint num_levels, - gint column, - gint row, - EekOutline *outline, - EekBounds *bounds); +EekKey *eek_section_create_key (EekSection *section, + const gchar *name, + guint *keysyms, + gint num_groups, + gint num_levels, + gint column, + gint row, + EekOutline *outline, + EekBounds *bounds); -void eek_section_foreach_key (EekSection *section, - GFunc func, - gpointer user_data); +void eek_section_foreach_key (EekSection *section, + GFunc func, + gpointer user_data); G_END_DECLS #endif /* EEK_SECTION_H */ diff --git a/eek/eek-simple-section.c b/eek/eek-simple-section.c index 78d0c06a..88bd8179 100644 --- a/eek/eek-simple-section.c +++ b/eek/eek-simple-section.c @@ -48,6 +48,7 @@ struct _EekSimpleSectionPrivate gchar *name; gint num_rows; gint *num_columns; + EekOrientation *orientations; gint angle; EekBounds bounds; GSList *keys; @@ -65,6 +66,9 @@ eek_simple_section_real_set_rows (EekSection *self, if (rows > 0) { g_free (priv->num_columns); 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]; } +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 eek_simple_section_real_set_angle (EekSection *self, gint angle) @@ -193,6 +220,8 @@ eek_section_iface_init (EekSectionIface *iface) iface->get_rows = eek_simple_section_real_get_rows; iface->set_columns = eek_simple_section_real_set_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->get_angle = eek_simple_section_real_get_angle; iface->set_bounds = eek_simple_section_real_set_bounds; @@ -221,6 +250,7 @@ eek_simple_section_finalize (GObject *object) g_free (priv->name); g_slist_free (priv->keys); g_slice_free (gint, priv->num_columns); + g_slice_free (EekOrientation, priv->orientations); G_OBJECT_CLASS (eek_simple_section_parent_class)->finalize (object); } @@ -316,4 +346,5 @@ eek_simple_section_init (EekSimpleSection *self) priv->keys = NULL; priv->num_rows = 0; priv->num_columns = NULL; + priv->orientations = NULL; } diff --git a/eek/eek-types.h b/eek/eek-types.h index 90ae1e61..c0f213af 100644 --- a/eek/eek-types.h +++ b/eek/eek-types.h @@ -24,6 +24,12 @@ G_BEGIN_DECLS +typedef enum { + EEK_ORIENTATION_VERTICAL, + EEK_ORIENTATION_HORIZONTAL, + EEK_ORIENTATION_INVALID = -1 +} EekOrientation; + typedef struct _EekKeyboard EekKeyboard; /** diff --git a/eek/eek-xkb-layout.c b/eek/eek-xkb-layout.c index 9bba9aec..182d9806 100644 --- a/eek/eek-xkb-layout.c +++ b/eek/eek-xkb-layout.c @@ -242,6 +242,11 @@ create_section (EekXkbLayout *layout, left = xkbrow->left; top = xkbrow->top; 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++) { XkbKeyRec *xkbkey; XkbBoundsRec *xkbbounds;