section: Removed multiple rows in section, row/column in key

This commit is contained in:
Dorota Czaplejewicz
2019-07-31 14:00:48 +00:00
parent 43df82355a
commit 6c1c979414
6 changed files with 30 additions and 112 deletions

View File

@ -50,7 +50,7 @@ static void
eek_container_real_add_child (EekContainer *self,
EekElement *child)
{
EekContainerPrivate *priv = eek_container_get_instance_private (self);
EekContainerPrivate *priv = (EekContainerPrivate*)eek_container_get_instance_private (self);
g_return_if_fail (EEK_IS_ELEMENT(child));
g_object_ref (child);

View File

@ -54,8 +54,6 @@ typedef struct _EekKeyPrivate
{
guint keycode;
EekSymbolMatrix *symbol_matrix;
gint column;
gint row;
gulong oref; // UI outline reference
gboolean is_pressed;
gboolean is_locked;
@ -432,59 +430,6 @@ eek_key_get_symbol_at_index (EekKey *key,
level];
}
/**
* eek_key_set_index:
* @key: an #EekKey
* @column: column index of @key in #EekSection
* @row: row index of @key in #EekSection
*
* Set the location of @key in #EekSection with @column and @row.
*/
void
eek_key_set_index (EekKey *key,
gint column,
gint row)
{
g_return_if_fail (EEK_IS_KEY(key));
g_return_if_fail (0 <= column);
g_return_if_fail (0 <= row);
EekKeyPrivate *priv = eek_key_get_instance_private (key);
if (priv->column != column) {
priv->column = column;
g_object_notify (G_OBJECT(key), "column");
}
if (priv->row != row) {
priv->row = row;
g_object_notify (G_OBJECT(key), "row");
}
}
/**
* eek_key_get_index:
* @key: an #EekKey
* @column: (allow-none): pointer where the column index of @key in #EekSection will be stored
* @row: (allow-none): pointer where the row index of @key in #EekSection will be stored
*
* Get the location of @key in #EekSection.
*/
void
eek_key_get_index (EekKey *key,
gint *column,
gint *row)
{
g_return_if_fail (EEK_IS_KEY(key));
g_return_if_fail (column != NULL || row != NULL);
EekKeyPrivate *priv = eek_key_get_instance_private (key);
if (column != NULL)
*column = priv->column;
if (row != NULL)
*row = priv->row;
}
/**
* eek_key_set_oref:
* @key: an #EekKey

View File

@ -61,7 +61,7 @@ typedef struct _EekRow EekRow;
typedef struct _EekSectionPrivate
{
gint angle;
GSList *rows;
EekRow row;
EekModifierType modifiers;
} EekSectionPrivate;
@ -70,9 +70,7 @@ G_DEFINE_TYPE_WITH_PRIVATE (EekSection, eek_section, EEK_TYPE_CONTAINER)
static gint
eek_section_real_get_n_rows (EekSection *self)
{
EekSectionPrivate *priv = eek_section_get_instance_private (self);
return g_slist_length (priv->rows);
return 1;
}
static void
@ -80,13 +78,14 @@ eek_section_real_add_row (EekSection *self,
gint num_columns,
EekOrientation orientation)
{
EekSectionPrivate *priv = eek_section_get_instance_private (self);
EekRow *row;
EekSectionPrivate *priv = (EekSectionPrivate*)eek_section_get_instance_private (self);
priv->row.num_columns = num_columns;
priv->row.orientation = orientation;
/*
row = g_slice_new (EekRow);
row->num_columns = num_columns;
row->orientation = orientation;
priv->rows = g_slist_append (priv->rows, row);
priv->rows = g_slist_append (priv->rows, row);*/
}
static void
@ -95,15 +94,14 @@ eek_section_real_get_row (EekSection *self,
gint *num_columns,
EekOrientation *orientation)
{
EekSectionPrivate *priv = eek_section_get_instance_private (self);
EekRow *row;
row = g_slist_nth_data (priv->rows, index);
g_return_if_fail (row);
if (num_columns)
EekSectionPrivate *priv = (EekSectionPrivate*)eek_section_get_instance_private (self);
EekRow *row = &priv->row;
if (num_columns) {
*num_columns = row->num_columns;
if (orientation)
}
if (orientation) {
*orientation = row->orientation;
}
}
static void
@ -123,27 +121,17 @@ on_unlocked (EekKey *key,
static EekKey *
eek_section_real_create_key (EekSection *self,
const gchar *name,
gint keycode,
gint column_index,
gint row_index)
gint keycode)
{
EekKey *key;
gint num_rows;
EekRow *row;
EekSectionPrivate *priv = (EekSectionPrivate*)eek_section_get_instance_private (self);
num_rows = eek_section_get_n_rows (self);
g_return_val_if_fail (0 <= row_index && row_index < num_rows, NULL);
EekRow *row = &priv->row;
row->num_columns++;
EekSectionPrivate *priv = eek_section_get_instance_private (self);
row = g_slist_nth_data (priv->rows, row_index);
if (row->num_columns < column_index + 1)
row->num_columns = column_index + 1;
key = g_object_new (EEK_TYPE_KEY,
"name", name,
"keycode", keycode,
NULL);
EekKey *key = (EekKey*)g_object_new (EEK_TYPE_KEY,
"name", name,
"keycode", keycode,
NULL);
g_return_val_if_fail (key, NULL);
EEK_CONTAINER_GET_CLASS(self)->add_child (EEK_CONTAINER(self),
@ -223,12 +211,7 @@ static void
eek_section_finalize (GObject *object)
{
EekSection *self = EEK_SECTION (object);
EekSectionPrivate *priv = eek_section_get_instance_private (self);
GSList *head;
for (head = priv->rows; head; head = g_slist_next (head))
g_slice_free (EekRow, head->data);
g_slist_free (priv->rows);
EekSectionPrivate *priv = (EekSectionPrivate*)eek_section_get_instance_private (self);
G_OBJECT_CLASS (eek_section_parent_class)->finalize (object);
}
@ -473,16 +456,12 @@ eek_section_get_row (EekSection *section,
EekKey *
eek_section_create_key (EekSection *section,
const gchar *name,
gint keycode,
gint column,
gint row)
gint keycode)
{
g_return_val_if_fail (EEK_IS_SECTION(section), NULL);
return EEK_SECTION_GET_CLASS(section)->create_key (section,
name,
keycode,
column,
row);
keycode);
}
const double keyspacing = 4.0;

View File

@ -63,9 +63,7 @@ struct _EekSectionClass
EekKey *(* create_key) (EekSection *self,
const gchar *name,
gint keycode,
gint row,
gint column);
gint keycode);
/* signals */
void (* key_pressed) (EekSection *self,
@ -101,9 +99,7 @@ void eek_section_get_row (EekSection *section,
EekKey *eek_section_create_key (EekSection *section,
const gchar *name,
gint keycode,
gint column,
gint row);
gint keycode);
EekKey *eek_section_find_key_by_keycode (EekSection *section,
guint keycode);

View File

@ -414,9 +414,7 @@ geometry_start_element_callback (GMarkupParseContext *pcontext,
data->key = eek_section_create_key (data->section,
name,
keycode,
data->num_columns,
data->num_rows - 1);
keycode);
attribute = get_attribute (attribute_names, attribute_values,
"oref");

View File

@ -32,9 +32,9 @@ test_create (void)
section = eek_keyboard_create_section (keyboard);
g_assert (EEK_IS_SECTION(section));
eek_section_add_row (section, 2, EEK_ORIENTATION_HORIZONTAL);
key0 = eek_section_create_key (section, "key0", 1, 0, 0);
key0 = eek_section_create_key (section, "key0", 1);
g_assert (EEK_IS_KEY(key0));
key1 = eek_section_create_key (section, "key1", 2, 1, 0);
key1 = eek_section_create_key (section, "key1", 2);
g_assert (EEK_IS_KEY(key1));
}