Split eek_section_{set,get}_dimensions.

This commit is contained in:
Daiki Ueno
2010-06-06 04:36:49 +09:00
parent 31004846a2
commit 4447dca695
5 changed files with 183 additions and 105 deletions

View File

@ -59,25 +59,43 @@ struct _EekClutterSectionPrivate
};
static void
eek_clutter_section_real_set_dimensions (EekSection *self,
gint columns,
gint rows)
eek_clutter_section_real_set_rows (EekSection *self,
gint rows)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
eek_section_set_dimensions (EEK_SECTION(priv->simple), columns, rows);
eek_section_set_rows (EEK_SECTION(priv->simple), rows);
}
static gint
eek_clutter_section_real_get_rows (EekSection *self)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, -1);
return eek_section_get_rows (EEK_SECTION(priv->simple));
}
static void
eek_clutter_section_real_get_dimensions (EekSection *self,
gint *columns,
gint *rows)
eek_clutter_section_real_set_columns (EekSection *self,
gint row,
gint columns)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
eek_section_get_dimensions (EEK_SECTION(priv->simple), columns, rows);
eek_section_set_columns (EEK_SECTION(priv->simple), row, columns);
}
static gint
eek_clutter_section_real_get_columns (EekSection *self,
gint row)
{
EekClutterSectionPrivate *priv = EEK_CLUTTER_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, -1);
return eek_section_get_columns (EEK_SECTION(priv->simple), row);
}
static void
@ -146,9 +164,10 @@ eek_clutter_section_real_create_key (EekSection *self,
g_return_val_if_fail (priv, NULL);
eek_section_get_dimensions (self, &columns, &rows);
rows = eek_section_get_rows (self);
g_return_val_if_fail (0 <= row && row < rows, NULL);
columns = eek_section_get_columns (self, row);
g_return_val_if_fail (column < columns, NULL);
g_return_val_if_fail (row < rows, NULL);
matrix.data = keysyms;
matrix.num_groups = num_groups;
@ -196,8 +215,10 @@ eek_clutter_section_real_foreach_key (EekSection *self,
static void
eek_section_iface_init (EekSectionIface *iface)
{
iface->set_dimensions = eek_clutter_section_real_set_dimensions;
iface->get_dimensions = eek_clutter_section_real_get_dimensions;
iface->set_rows = eek_clutter_section_real_set_rows;
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_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

@ -130,41 +130,71 @@ eek_section_get_type (void)
}
/**
* eek_section_set_dimensions:
* eek_section_set_rows:
* @section: an #EekSection
* @columns: the number of columns in @section
* @rows: the number of rows in @section
*
* Set dimensions of @section from @columns and @rows.
* Set the number of rows in @section to @rows.
*/
void
eek_section_set_dimensions (EekSection *section,
gint columns,
gint rows)
eek_section_set_rows (EekSection *section,
gint rows)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->set_dimensions);
(*iface->set_dimensions) (section, columns, rows);
g_return_if_fail (iface->set_rows);
(*iface->set_rows) (section, rows);
}
/**
* eek_section_get_dimensions:
* eek_section_get_rows:
* @section: an #EekSection
* @columns: a pointer where the number of columns in @section is stored
* @rows: a pointer where the number of rows in @section is stored
*
* Get the rotation angle of @section.
* Get the number of rows in @section.
*/
void
eek_section_get_dimensions (EekSection *section,
gint *columns,
gint *rows)
gint
eek_section_get_rows (EekSection *section)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->get_dimensions);
return (*iface->get_dimensions) (section, columns, rows);
g_return_if_fail (iface->get_rows);
return (*iface->get_rows) (section);
}
/**
* eek_section_set_columns:
* @section: an #EekSection
* @row: the row index in @section
* @columns: the number of keys on @row
*
* Set the number of keys on @row.
*/
void
eek_section_set_columns (EekSection *section,
gint row,
gint columns)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->set_columns);
(*iface->set_columns) (section, row, columns);
}
/**
* eek_section_get_columns:
* @section: an #EekSection
* @row: the row index in @section
*
* Get the number of keys on @row.
*/
gint
eek_section_get_columns (EekSection *section,
gint row)
{
EekSectionIface *iface = EEK_SECTION_GET_IFACE(section);
g_return_if_fail (iface->get_columns);
return (*iface->get_columns) (section, row);
}
/**

View File

@ -38,66 +38,72 @@ struct _EekSectionIface
GTypeInterface g_iface;
/*< public >*/
void (* set_dimensions) (EekSection *self,
gint columns,
gint rows);
void (* get_dimensions) (EekSection *self,
gint *columns,
gint *rows);
void (* set_angle) (EekSection *self,
gint angle);
gint (* get_angle) (EekSection *self);
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_bounds) (EekSection *self,
EekBounds *bounds);
void (* get_bounds) (EekSection *self,
EekBounds *bounds);
void (* set_angle) (EekSection *self,
gint angle);
gint (* get_angle) (EekSection *self);
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 (* set_bounds) (EekSection *self,
EekBounds *bounds);
void (* get_bounds) (EekSection *self,
EekBounds *bounds);
void (* foreach_key) (EekSection *self,
GFunc func,
gpointer user_data);
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);
};
GType eek_section_get_type (void) G_GNUC_CONST;
GType eek_section_get_type (void) G_GNUC_CONST;
void eek_section_set_dimensions (EekSection *section,
gint columns,
gint rows);
void eek_section_get_dimensions (EekSection *section,
gint *columns,
gint *rows);
void eek_section_set_angle (EekSection *section,
gint angle);
gint eek_section_get_angle (EekSection *section);
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_bounds (EekSection *section,
EekBounds *bounds);
void eek_section_get_bounds (EekSection *section,
EekBounds *bounds);
void eek_section_set_angle (EekSection *section,
gint angle);
gint eek_section_get_angle (EekSection *section);
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_set_bounds (EekSection *section,
EekBounds *bounds);
void eek_section_get_bounds (EekSection *section,
EekBounds *bounds);
void eek_section_foreach_key (EekSection *section,
GFunc func,
gpointer user_data);
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);
G_END_DECLS
#endif /* EEK_SECTION_H */

View File

@ -46,35 +46,58 @@ G_DEFINE_TYPE_WITH_CODE (EekSimpleSection, eek_simple_section,
struct _EekSimpleSectionPrivate
{
gchar *name;
gint num_columns;
gint num_rows;
gint *num_columns;
gint angle;
EekBounds bounds;
GSList *keys;
};
static void
eek_simple_section_real_set_dimensions (EekSection *self,
gint columns,
gint rows)
eek_simple_section_real_set_rows (EekSection *self,
gint rows)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
priv->num_columns = columns;
g_return_if_fail (rows >= 0);
priv->num_rows = rows;
if (rows > 0) {
g_free (priv->num_columns);
priv->num_columns = g_slice_alloc (sizeof(gint) * priv->num_rows);
}
}
static gint
eek_simple_section_real_get_rows (EekSection *self)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, -1);
return priv->num_rows;
}
static void
eek_simple_section_real_get_dimensions (EekSection *self,
gint *columns,
gint *rows)
eek_simple_section_real_set_columns (EekSection *self,
gint row,
gint columns)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_if_fail (priv);
*columns = priv->num_columns;
*rows = priv->num_rows;
g_return_if_fail (0 <= row && row < priv->num_rows);
priv->num_columns[row] = columns;
}
static gint
eek_simple_section_real_get_columns (EekSection *self,
gint row)
{
EekSimpleSectionPrivate *priv = EEK_SIMPLE_SECTION_GET_PRIVATE(self);
g_return_val_if_fail (priv, -1);
g_return_val_if_fail (0 <= row && row < priv->num_rows, -1);
return priv->num_columns[row];
}
static void
@ -133,8 +156,8 @@ eek_simple_section_real_create_key (EekSection *self,
EekKeysymMatrix matrix;
g_return_val_if_fail (priv, NULL);
g_return_val_if_fail (column < priv->num_columns, NULL);
g_return_val_if_fail (row < priv->num_rows, NULL);
g_return_val_if_fail (0 <= row && row < priv->num_rows, NULL);
g_return_val_if_fail (column < priv->num_columns[row], NULL);
matrix.data = keysyms;
matrix.num_groups = num_groups;
@ -166,8 +189,10 @@ eek_simple_section_real_foreach_key (EekSection *self,
static void
eek_section_iface_init (EekSectionIface *iface)
{
iface->set_dimensions = eek_simple_section_real_set_dimensions;
iface->get_dimensions = eek_simple_section_real_get_dimensions;
iface->set_rows = eek_simple_section_real_set_rows;
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_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;
@ -195,6 +220,7 @@ eek_simple_section_finalize (GObject *object)
g_free (priv->name);
g_slist_free (priv->keys);
g_slice_free (gint, priv->num_columns);
G_OBJECT_CLASS (eek_simple_section_parent_class)->finalize (object);
}
@ -288,4 +314,6 @@ eek_simple_section_init (EekSimpleSection *self)
priv->angle = 0;
memset (&priv->bounds, 0, sizeof priv->bounds);
priv->keys = NULL;
priv->num_rows = 0;
priv->num_columns = NULL;
}

View File

@ -218,7 +218,7 @@ create_section (EekXkbLayout *layout,
EekBounds bounds;
const gchar *name;
gfloat left, top;
gint i, j, columns;
gint i, j;
bounds.x = xkb_to_pixmap_coord(layout, xkbsection->left);
bounds.y = xkb_to_pixmap_coord(layout, xkbsection->top);
@ -234,21 +234,14 @@ create_section (EekXkbLayout *layout,
xkbsection->angle / 10,
&bounds);
for (columns = 0, i = 0; i < xkbsection->num_rows; i++) {
XkbRowRec *xkbrow;
xkbrow = &xkbsection->rows[i];
if (xkbrow->num_keys > columns)
columns = xkbrow->num_keys;
}
eek_section_set_dimensions (section, columns, xkbsection->num_rows);
eek_section_set_rows (section, xkbsection->num_rows);
for (i = 0; i < xkbsection->num_rows; i++) {
XkbRowRec *xkbrow;
xkbrow = &xkbsection->rows[i];
left = xkbrow->left;
top = xkbrow->top;
eek_section_set_columns (section, i, xkbrow->num_keys);
for (j = 0; j < xkbrow->num_keys; j++) {
XkbKeyRec *xkbkey;
XkbBoundsRec *xkbbounds;