Commit e999883c authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Generate unique id for <key id="...">.

parent 62584767
......@@ -65,6 +65,7 @@ struct _ParseCallbackData {
EekOrientation orientation;
GSList *points;
GSList *symbols;
guint keyval;
gint groups, levels;
EekOutline outline;
gchar *oref;
......@@ -159,6 +160,7 @@ start_element_callback (GMarkupParseContext *pcontext,
const gchar **names = attribute_names;
const gchar **values = attribute_values;
gint column = -1, row = -1, groups = -1, levels = -1;
guint keyval = EEK_INVALID_KEYSYM;
gchar *name = NULL, *id = NULL, *version = NULL;
validate (element_name, data->element_stack, error);
......@@ -170,10 +172,12 @@ start_element_callback (GMarkupParseContext *pcontext,
column = strtol (*values, NULL, 10);
else if (g_strcmp0 (*names, "row") == 0)
row = strtol (*values, NULL, 10);
else if (g_strcmp0 (*names, "name") == 0)
name = g_strdup (*values);
else if (g_strcmp0 (*names, "id") == 0)
id = g_strdup (*values);
else if (g_strcmp0 (*names, "name") == 0)
name = g_strdup (*values);
else if (g_strcmp0 (*names, "keyval") == 0)
keyval = strtoul (*values, NULL, 10);
else if (g_strcmp0 (*names, "version") == 0)
version = g_strdup (*values);
else if (g_strcmp0 (*names, "groups") == 0)
......@@ -188,24 +192,25 @@ start_element_callback (GMarkupParseContext *pcontext,
data->keyboard = g_object_new (EEK_TYPE_KEYBOARD,
"layout", data->layout,
NULL);
if (name)
eek_element_set_name (EEK_ELEMENT(data->keyboard), name);
if (id)
eek_element_set_name (EEK_ELEMENT(data->keyboard), id);
goto out;
}
if (g_strcmp0 (element_name, "section") == 0) {
data->section = eek_keyboard_create_section (data->keyboard);
if (name)
eek_element_set_name (EEK_ELEMENT(data->section), name);
if (id)
eek_element_set_name (EEK_ELEMENT(data->section), id);
goto out;
}
if (g_strcmp0 (element_name, "key") == 0) {
data->key = eek_section_create_key (data->section, column, row);
if (name)
eek_element_set_name (EEK_ELEMENT(data->key), name);
if (id && g_str_has_prefix (id, "key"))
eek_key_set_keycode (data->key, strtoul (id + 3, NULL, 10));
if (id) {
eek_element_set_name (EEK_ELEMENT(data->key), id);
if (g_str_has_prefix (id, "keycode"))
eek_key_set_keycode (data->key, strtoul (id + 7, NULL, 10));
}
goto out;
}
......@@ -216,6 +221,9 @@ start_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "keysym") == 0)
data->keyval = keyval;
if (g_strcmp0 (element_name, "outline") == 0) {
data->oref = g_strdup (id);
goto out;
......@@ -357,8 +365,8 @@ end_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "columns") == 0) {
data->num_columns = strtol (text, NULL, 10);
if (g_strcmp0 (element_name, "angle") == 0) {
eek_section_set_angle (data->section, strtol (text, NULL, 10));
goto out;
}
......@@ -367,6 +375,11 @@ end_element_callback (GMarkupParseContext *pcontext,
goto out;
}
if (g_strcmp0 (element_name, "columns") == 0) {
data->num_columns = strtol (text, NULL, 10);
goto out;
}
if (g_strcmp0 (element_name, "row") == 0) {
eek_section_add_row (data->section,
data->num_columns,
......@@ -377,10 +390,13 @@ end_element_callback (GMarkupParseContext *pcontext,
}
if (g_strcmp0 (element_name, "keysym") == 0) {
gchar *name = g_strdup (text);
data->symbols = g_slist_prepend (data->symbols,
eek_keysym_new_from_name (name));
g_free (name);
EekKeysym *keysym;
if (data->keyval != EEK_INVALID_KEYSYM)
keysym = eek_keysym_new (data->keyval);
else
keysym = eek_keysym_new_from_name (text);
data->symbols = g_slist_prepend (data->symbols, keysym);
goto out;
}
......@@ -519,7 +535,8 @@ eek_xml_layout_real_create_keyboard (EekLayout *self,
}
eek_element_get_bounds (EEK_ELEMENT(data.keyboard), &bounds);
scale = initial_width < initial_height ? initial_width / bounds.width :
scale = initial_width * bounds.height < initial_height * bounds.width ?
initial_width / bounds.width :
initial_height / bounds.height;
g_hash_table_iter_init (&iter, data.oref_outline_hash);
......
......@@ -55,6 +55,7 @@ struct _OutputCallbackData {
GString *output;
gint indent;
GArray *outline_array;
gint key_serial;
};
typedef struct _OutputCallbackData OutputCallbackData;
......@@ -78,20 +79,34 @@ output_key_callback (EekElement *element, gpointer user_data)
gint i, num_symbols;
EekSymbolMatrix *matrix;
gint column, row;
guint keycode = eek_key_get_keycode (EEK_KEY(element));
guint keycode;
gchar *id;
keycode = eek_key_get_keycode (EEK_KEY(element));
if (keycode == EEK_INVALID_KEYCODE)
id = g_strdup_printf ("key%d", data->key_serial);
else
id = g_strdup_printf ("keycode%d", keycode);
data->key_serial++;
eek_key_get_index (EEK_KEY(element), &column, &row);
g_string_append_indent (data->output, data->indent);
if (eek_element_get_name (element))
g_string_markup_printf (data->output,
"<key id=\"key%u\" column=\"%d\" row=\"%d\" "
"name=\"%s\">\n",
keycode, column, row,
eek_element_get_name (element));
"<key id=\"%s\" name=\"%s\" "
"column=\"%d\" row=\"%d\">\n",
id,
eek_element_get_name (element),
column,
row);
else
g_string_markup_printf (data->output,
"<key id=\"key%d\" column=\"%d\" row=\"%d\">\n",
keycode, column, row);
"<key id=\"%s\" "
"column=\"%d\" row=\"%d\">\n",
id,
column,
row);
g_free (id);
eek_element_get_bounds (element, &bounds);
g_string_append_indent (data->output, data->indent + 1);
......@@ -121,15 +136,27 @@ output_key_callback (EekElement *element, gpointer user_data)
matrix->num_groups, matrix->num_levels);
for (i = 0; i < num_symbols; i++) {
EekSymbol *symbol = matrix->data[i];
g_string_append_indent (data->output, data->indent + 2);
if (EEK_IS_KEYSYM(matrix->data[i]))
g_string_markup_printf (data->output,
"<keysym>%s</keysym>\n",
eek_symbol_get_name (matrix->data[i]));
if (EEK_IS_KEYSYM(symbol)) {
guint xkeysym = eek_keysym_get_xkeysym (EEK_KEYSYM(symbol));
if (xkeysym != EEK_INVALID_KEYSYM)
g_string_markup_printf
(data->output,
"<keysym keyval=\"%u\">%s</keysym>\n",
xkeysym,
eek_symbol_get_name (symbol));
else
g_string_markup_printf (data->output,
"<keysym>%s</keysym>\n",
eek_symbol_get_name (symbol));
}
else
g_string_markup_printf (data->output,
"<symbol>%s</symbol>\n",
eek_symbol_get_name (matrix->data[i]));
eek_symbol_get_name (symbol));
}
g_string_append_indent (data->output, data->indent + 1);
g_string_markup_printf (data->output, "</symbols>\n");
......@@ -202,10 +229,15 @@ eek_keyboard_output (EekKeyboard *keyboard, GString *output, gint indent)
g_assert (EEK_IS_KEYBOARD(keyboard));
g_string_append_indent (output, indent);
g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
"<keyboard version=\""
EEK_XML_SCHEMA_VERSION
"\">\n");
if (eek_element_get_name (EEK_ELEMENT(keyboard)))
g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
"<keyboard version=\"%s\" id=\"%s\">\n",
EEK_XML_SCHEMA_VERSION,
eek_element_get_name (EEK_ELEMENT(keyboard)));
else
g_string_markup_printf (output, "<?xml version=\"1.0\"?>\n"
"<keyboard version=\"%s\">\n",
EEK_XML_SCHEMA_VERSION);
eek_element_get_bounds (EEK_ELEMENT(keyboard), &bounds);
g_string_append_indent (output, indent + 1);
......@@ -214,6 +246,7 @@ eek_keyboard_output (EekKeyboard *keyboard, GString *output, gint indent)
data.output = output;
data.indent = indent;
data.outline_array = g_array_new (FALSE, FALSE, sizeof (gpointer));
data.key_serial = 0;
data.indent++;
eek_container_foreach_child (EEK_CONTAINER(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