Commit b2657c06 authored by Daiki Ueno's avatar Daiki Ueno

Move symbol-index property per-element instead of per-keyboard.

parent fccf9e88
......@@ -34,15 +34,25 @@
#include "eek-element.h"
#include "eek-container.h"
#include "eek-marshalers.h"
#include "eek-serializable.h"
enum {
PROP_0,
PROP_NAME,
PROP_BOUNDS,
PROP_GROUP,
PROP_LEVEL,
PROP_LAST
};
enum {
SYMBOL_INDEX_CHANGED,
LAST_SIGNAL
};
static guint signals[LAST_SIGNAL] = { 0, };
static void eek_serializable_iface_init (EekSerializableIface *iface);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (EekElement, eek_element, G_TYPE_OBJECT,
......@@ -58,6 +68,8 @@ struct _EekElementPrivate
gchar *name;
EekBounds bounds;
EekElement *parent;
gint group;
gint level;
};
static GVariant *
......@@ -182,6 +194,41 @@ eek_element_real_get_bounds (EekElement *self,
g_object_notify (G_OBJECT(self), "bounds");
}
static void
eek_element_real_set_symbol_index (EekElement *self,
gint group,
gint level)
{
EekElementPrivate *priv = EEK_ELEMENT_GET_PRIVATE(self);
if (priv->group != group || priv->level != level) {
priv->group = group;
priv->level = level;
g_signal_emit_by_name (self, "symbol-index-changed", group, level);
}
}
static void
eek_element_real_get_symbol_index (EekElement *self,
gint *group,
gint *level)
{
EekElementPrivate *priv = EEK_ELEMENT_GET_PRIVATE(self);
if (group)
*group = priv->group;
if (level)
*level = priv->level;
}
static void
eek_element_real_symbol_index_changed (EekElement *self,
gint group,
gint level)
{
// g_debug ("symbol-index-changed");
}
static void
eek_element_finalize (GObject *object)
{
......@@ -206,6 +253,13 @@ eek_element_set_property (GObject *object,
eek_element_set_bounds (EEK_ELEMENT(object),
g_value_get_boxed (value));
break;
case PROP_GROUP:
eek_element_set_group (EEK_ELEMENT(object),
g_value_get_int (value));
break;
case PROP_LEVEL:
eek_element_set_level (EEK_ELEMENT(object),
g_value_get_int (value));
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -228,6 +282,12 @@ eek_element_get_property (GObject *object,
eek_element_get_bounds (EEK_ELEMENT(object), &bounds);
g_value_set_boxed (value, &bounds);
break;
case PROP_GROUP:
g_value_set_int (value, eek_element_get_group (EEK_ELEMENT(object)));
break;
case PROP_LEVEL:
g_value_set_int (value, eek_element_get_level (EEK_ELEMENT(object)));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
......@@ -249,6 +309,11 @@ eek_element_class_init (EekElementClass *klass)
klass->get_name = eek_element_real_get_name;
klass->set_bounds = eek_element_real_set_bounds;
klass->get_bounds = eek_element_real_get_bounds;
klass->set_symbol_index = eek_element_real_set_symbol_index;
klass->get_symbol_index = eek_element_real_get_symbol_index;
/* signals */
klass->symbol_index_changed = eek_element_real_symbol_index_changed;
gobject_class->set_property = eek_element_set_property;
gobject_class->get_property = eek_element_get_property;
......@@ -281,6 +346,56 @@ eek_element_class_init (EekElementClass *klass)
g_object_class_install_property (gobject_class,
PROP_BOUNDS,
pspec);
/**
* EekElement:group:
*
* The group value of the symbol index of #EekElement.
*/
pspec = g_param_spec_int ("group",
"Group",
"Group value of the symbol index",
-1, G_MAXINT, -1,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_GROUP,
pspec);
/**
* EekElement:level:
*
* The level value of the symbol index of #EekElement.
*/
pspec = g_param_spec_int ("level",
"Level",
"Level value of the symbol index",
-1, G_MAXINT, -1,
G_PARAM_READWRITE);
g_object_class_install_property (gobject_class,
PROP_LEVEL,
pspec);
/**
* EekElement::symbol-index-changed:
* @element: an #EekElement
* @group: row index of the symbol matrix of keys on @element
* @level: column index of the symbol matrix of keys on @element
*
* The ::symbol-index-changed signal is emitted each time the
* global configuration of group/level index changes.
*/
signals[SYMBOL_INDEX_CHANGED] =
g_signal_new (I_("symbol-index-changed"),
G_TYPE_FROM_CLASS(gobject_class),
G_SIGNAL_RUN_LAST,
G_STRUCT_OFFSET(EekElementClass, symbol_index_changed),
NULL,
NULL,
_eek_marshal_VOID__INT_INT,
G_TYPE_NONE,
2,
G_TYPE_INT,
G_TYPE_INT);
}
static void
......@@ -291,6 +406,8 @@ eek_element_init (EekElement *self)
priv = self->priv = EEK_ELEMENT_GET_PRIVATE(self);
priv->name = NULL;
memset (&priv->bounds, 0, sizeof priv->bounds);
priv->group = -1;
priv->level = -1;
}
/**
......@@ -452,3 +569,117 @@ eek_element_set_size (EekElement *element,
bounds.height = height;
eek_element_set_bounds (element, &bounds);
}
/**
* eek_element_set_symbol_index:
* @element: an #EekElement
* @group: row index of the symbol matrix
* @level: column index of the symbol matrix
*
* Set the default index of the symbol matrices of @element. The
* setting affects the child, if child does not have the index set, as
* well as this element. To unset, pass -1 as group/level.
*/
void
eek_element_set_symbol_index (EekElement *element,
gint group,
gint level)
{
g_return_if_fail (EEK_IS_ELEMENT(element));
EEK_ELEMENT_GET_CLASS(element)->set_symbol_index (element, group, level);
}
/**
* eek_element_get_symbol_index:
* @element: an #EekElement
* @group: a pointer where the group value of the symbol index will be stored
* @level: a pointer where the level value of the symbol index will be stored
*
* Get the default index of the symbol matrices of @element.
* If the index is not set, -1 will be returned.
*/
void
eek_element_get_symbol_index (EekElement *element,
gint *group,
gint *level)
{
g_return_if_fail (EEK_IS_ELEMENT(element));
g_return_if_fail (group || level);
EEK_ELEMENT_GET_CLASS(element)->get_symbol_index (element, group, level);
}
/**
* eek_element_set_group:
* @element: an #EekElement
* @group: group index of @element
*
* Set the group value of the default symbol index of @element. To
* unset, pass -1 as @group.
*
* See also: eek_element_set_symbol_index()
*/
void
eek_element_set_group (EekElement *element,
gint group)
{
gint level;
level = eek_element_get_level (element);
eek_element_set_symbol_index (element, group, level);
}
/**
* eek_element_set_level:
* @element: an #EekElement
* @level: level index of @element
*
* Set the level value of the default symbol index of @element. To
* unset, pass -1 as @level.
*
* See also: eek_element_set_symbol_index()
*/
void
eek_element_set_level (EekElement *element,
gint level)
{
gint group;
group = eek_element_get_group (element);
eek_element_set_symbol_index (element, group, level);
}
/**
* eek_element_get_group:
* @element: an #EekElement
*
* Return the group value of the default symbol index of @element.
* If the value is not set, -1 will be returned.
*
* See also: eek_element_get_symbol_index()
*/
gint
eek_element_get_group (EekElement *element)
{
gint group;
eek_element_get_symbol_index (element, &group, NULL);
return group;
}
/**
* eek_element_get_level:
* @element: an #EekElement
*
* Return the level value of the default symbol index of @element.
* If the value is not set, -1 will be returned.
*
* See also: eek_element_get_symbol_index()
*/
gint
eek_element_get_level (EekElement *element)
{
gint level;
eek_element_get_symbol_index (element, NULL, &level);
return level;
}
......@@ -46,23 +46,35 @@ struct _EekElementClass
{
/*< private >*/
GObjectClass parent_class;
void (* set_parent) (EekElement *self,
EekElement *parent);
EekElement *(* get_parent) (EekElement *self);
void (* set_name) (EekElement *self,
const gchar *name);
void (* set_parent) (EekElement *self,
EekElement *parent);
EekElement *(* get_parent) (EekElement *self);
void (* set_name) (EekElement *self,
const gchar *name);
G_CONST_RETURN gchar *(* get_name) (EekElement *self);
G_CONST_RETURN gchar *(* get_name) (EekElement *self);
void (* set_bounds) (EekElement *self,
EekBounds *bounds);
void (* set_bounds) (EekElement *self,
EekBounds *bounds);
void (* get_bounds) (EekElement *self,
EekBounds *bounds);
void (* get_bounds) (EekElement *self,
EekBounds *bounds);
void (* set_symbol_index) (EekElement *self,
gint group,
gint level);
void (* get_symbol_index) (EekElement *self,
gint *group,
gint *level);
/* signals */
void (* symbol_index_changed) (EekElement *self,
gint group,
gint level);
/*< private >*/
/* padding */
gpointer pdummy[24];
gpointer pdummy[21];
};
GType eek_element_get_type (void) G_GNUC_CONST;
......@@ -92,5 +104,18 @@ void eek_element_get_absolute_position (EekElement *element,
gdouble *x,
gdouble *y);
void eek_element_set_symbol_index (EekElement *element,
gint group,
gint level);
void eek_element_get_symbol_index (EekElement *element,
gint *group,
gint *level);
void eek_element_set_group (EekElement *element,
gint group);
void eek_element_set_level (EekElement *element,
gint level);
gint eek_element_get_group (EekElement *element);
gint eek_element_get_level (EekElement *element);
G_END_DECLS
#endif /* EEK_ELEMENT_H */
......@@ -550,20 +550,6 @@ eek_key_get_symbol_matrix (EekKey *key)
return EEK_KEY_GET_CLASS(key)->get_symbol_matrix (key);
}
static EekKeyboard *
get_keyboard (EekKey *key)
{
EekElement *parent;
parent = eek_element_get_parent (EEK_ELEMENT(key));
g_return_val_if_fail (EEK_IS_SECTION(parent), NULL);
parent = eek_element_get_parent (parent);
g_return_val_if_fail (EEK_IS_KEYBOARD(parent), NULL);
return EEK_KEYBOARD(parent);
}
/**
* eek_key_get_symbol:
* @key: an #EekKey
......@@ -592,14 +578,38 @@ eek_key_get_symbol_with_fallback (EekKey *key,
gint fallback_level)
{
gint group, level;
EekKeyboard *keyboard;
g_return_val_if_fail (EEK_IS_KEY (key), NULL);
g_return_val_if_fail (fallback_group >= 0, NULL);
g_return_val_if_fail (fallback_level >= 0, NULL);
eek_element_get_symbol_index (EEK_ELEMENT(key), &group, &level);
if (group < 0 || level < 0) {
EekElement *section;
section = eek_element_get_parent (EEK_ELEMENT(key));
g_return_val_if_fail (EEK_IS_SECTION (section), NULL);
keyboard = get_keyboard (key);
g_return_val_if_fail (keyboard, NULL);
if (group < 0)
group = eek_element_get_group (section);
if (level < 0)
level = eek_element_get_level (section);
if (group < 0 || level < 0) {
EekElement *keyboard;
keyboard = eek_element_get_parent (section);
g_return_val_if_fail (EEK_IS_KEYBOARD (keyboard), NULL);
if (group < 0)
group = eek_element_get_group (keyboard);
if (level < 0)
level = eek_element_get_level (keyboard);
}
}
eek_keyboard_get_symbol_index (keyboard, &group, &level);
return eek_key_get_symbol_at_index (key,
group,
level,
......@@ -628,8 +638,13 @@ eek_key_get_symbol_at_index (EekKey *key,
EekKeyPrivate *priv = EEK_KEY_GET_PRIVATE(key);
gint num_symbols;
g_return_val_if_fail (group >= 0, NULL);
g_return_val_if_fail (level >= 0, NULL);
g_return_val_if_fail (fallback_group >= 0, NULL);
g_return_val_if_fail (fallback_level >= 0, NULL);
if (group < 0)
group = fallback_group;
if (level < 0)
level = fallback_level;
if (!priv->symbol_matrix)
return NULL;
......
This diff is collapsed.
......@@ -53,30 +53,22 @@ struct _EekKeyboard
/**
* EekKeyboardClass:
* @set_symbol_index: virtual function for setting group and level of
* the entire keyboard
* @get_symbol_index: virtual function for getting group and level of
* the entire keyboard
* @create_section: virtual function for creating a section
* @find_key_by_keycode: virtual function for finding a key in the
* keyboard by keycode
* @key_pressed: class handler for #EekKeyboard::key-pressed signal
* @key_released: class handler for #EekKeyboard::key-released signal
* @symbol_index_changed: class handler for #EekKeyboard::symbol-index-changed signal
*/
struct _EekKeyboardClass
{
/*< private >*/
EekContainerClass parent_class;
/*< public >*/
void (* set_symbol_index) (EekKeyboard *self,
gint group,
gint level);
void (* get_symbol_index) (EekKeyboard *self,
gint *group,
gint *level);
/* obsolete members moved to EekElement */
gpointer set_symbol_index;
gpointer get_symbol_index;
/*< public >*/
EekSection *(* create_section) (EekKeyboard *self);
EekKey *(* find_key_by_keycode) (EekKeyboard *self,
......@@ -87,11 +79,11 @@ struct _EekKeyboardClass
EekKey *key);
void (* key_released) (EekKeyboard *self,
EekKey *key);
void (* symbol_index_changed) (EekKeyboard *self,
gint group,
gint level);
/*< private >*/
/* obsolete members moved to EekElement */
gpointer symbol_index_changed;
/* padding */
gpointer pdummy[24];
};
......
......@@ -501,9 +501,8 @@ eekboard_context_set_group (EekboardContext *context,
priv = EEKBOARD_CONTEXT_GET_PRIVATE (context);
g_return_if_fail (priv->keyboard);
g_return_if_fail (group >= 0);
eek_keyboard_set_group (priv->keyboard, group);
eek_element_set_group (EEK_ELEMENT(priv->keyboard), group);
g_dbus_proxy_call (G_DBUS_PROXY(context),
"SetGroup",
g_variant_new ("(i)", group),
......
......@@ -504,7 +504,7 @@ on_xkl_state_changed (XklEngine *xklengine,
EekboardDesktopClient *client = user_data;
if (type == GROUP_CHANGED && client->keyboard) {
gint group = eek_keyboard_get_group (client->keyboard);
gint group = eek_element_get_group (EEK_ELEMENT(client->keyboard));
if (group != value) {
eekboard_context_set_group (client->context, value, NULL);
}
......
......@@ -574,7 +574,7 @@ handle_method_call (GDBusConnection *connection,
}
g_variant_get (parameters, "(i)", &group);
eek_keyboard_set_group (context->keyboard, group);
eek_element_set_group (EEK_ELEMENT(context->keyboard), group);
if (context->window) {
gboolean was_visible = gtk_widget_get_visible (context->window);
......
......@@ -113,7 +113,7 @@ main (int argc, char **argv)
keyboard = eek_keyboard_new (layout, 640, 480);
g_object_unref (layout);
eek_keyboard_set_group (keyboard, opt_group);
eek_element_set_group (EEK_ELEMENT(keyboard), opt_group);
widget = eek_gtk_keyboard_new (keyboard);
g_object_unref (keyboard);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment