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

View File

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

View File

@ -46,6 +46,11 @@ struct _EekSectionIface
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);
@ -81,6 +86,11 @@ void eek_section_set_columns (EekSection *section,
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);

View File

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

View File

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

View File

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