Skip to content

Commit

Permalink
Added input_pad_gtk_button_new_with_unicode() and input_pad_window_ne…
Browse files Browse the repository at this point in the history
…w_with_paddir()
  • Loading branch information
fujiwarat committed Jun 14, 2010
1 parent 1d47bd6 commit 61e33f3
Show file tree
Hide file tree
Showing 14 changed files with 157 additions and 56 deletions.
3 changes: 1 addition & 2 deletions data/input-pad.ui
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@
<object class="GtkRadioAction" id="ShowAllChars">
<property name="name">ShowAllChars</property>
<property name="label" translatable="yes">Show _All Characters</property>
<property name="active">True</property>
</object>
</child>
<child>
<object class="GtkRadioAction" id="ShowCustomChars">
<property name="name">ShowCustomChars</property>
<property name="label" translatable="yes">Show _Custom Characters</property>
<property name="group">ShowAllChars</property>
<property name="active">True</property>
</object>
</child>
<child>
Expand Down Expand Up @@ -253,7 +253,6 @@ Bin</property>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<!--property name="position">0</property-->
</packing>
</child>
<child>
Expand Down
39 changes: 39 additions & 0 deletions input-pad/button-gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,45 @@ input_pad_gtk_button_new_with_label (const gchar *label)
return g_object_new (INPUT_PAD_TYPE_GTK_BUTTON, "label", label, NULL);
}

GtkWidget *
input_pad_gtk_button_new_with_unicode (guint code)
{
gchar buff[7];
gchar buff2[35]; /* 7 x 5 e.g. 'a' -> '0x61 ' */
gchar *tooltip;
int i;
GtkWidget *button;

/* The displaying button is too long with '\t'. */
if (code == '\t') {
buff[0] = ' ';
buff[1] = '\0';
sprintf (buff2, "0x%02X ", (unsigned char) code);
} else {
buff[g_unichar_to_utf8 ((gunichar) code, buff)] = '\0';
for (i = 0; buff[i] && i < 7; i++) {
sprintf (buff2 + i * 5, "0x%02X ", (unsigned char) buff[i]);
}
if (buff[0] == '\0') {
buff2[0] = '0'; buff2[0] = 'x'; buff2[1] = '0'; buff2[2] = '0';
buff2[3] = '\0';
}
}

button = input_pad_gtk_button_new_with_label (buff);
if (code == '\t') {
input_pad_gtk_button_set_keysym (INPUT_PAD_GTK_BUTTON (button),
code);
}
tooltip = g_strdup_printf ("U+%04X\nUTF-8 %s", code, buff2);
gtk_widget_set_tooltip_text (GTK_WIDGET (button), tooltip);
g_free (tooltip);
input_pad_gtk_button_set_table_type (INPUT_PAD_GTK_BUTTON (button),
INPUT_PAD_TABLE_TYPE_CHARS);

return button;
}

guint
input_pad_gtk_button_get_keycode (InputPadGtkButton *button)
{
Expand Down
1 change: 1 addition & 0 deletions input-pad/button-gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ struct _InputPadGtkButtonClass {

GType input_pad_gtk_button_get_type (void);
GtkWidget * input_pad_gtk_button_new_with_label (const gchar *label);
GtkWidget * input_pad_gtk_button_new_with_unicode (guint code);
guint input_pad_gtk_button_get_keycode
(InputPadGtkButton *button);
void input_pad_gtk_button_set_keycode
Expand Down
2 changes: 1 addition & 1 deletion input-pad/input-pad-group.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct _InputPadTable {
InputPadGroup * input_pad_group_append_from_file
(InputPadGroup *group_data,
const char *file);
InputPadGroup * input_pad_group_parse_all_files (void);
InputPadGroup * input_pad_group_parse_all_files (const char *custom_dirname);
void input_pad_group_destroy
(InputPadGroup *group_data);

Expand Down
6 changes: 5 additions & 1 deletion input-pad/input-pad-window-gtk.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,12 @@ struct _InputPadGtkWindowClass {

G_MODULE_EXPORT
GType input_pad_gtk_window_get_type (void);
GtkWidget * input_pad_gtk_window_new (GtkWindowType type,
GtkWidget * input_pad_gtk_window_new (GtkWindowType type,
unsigned int ibus);
GtkWidget * input_pad_gtk_window_new_with_paddir
(GtkWindowType type,
unsigned int ibus,
const gchar *paddir);

G_END_DECLS

Expand Down
2 changes: 2 additions & 0 deletions input-pad/input-pad.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ const char * input_pad_get_version (void);
void input_pad_window_init (int *argc, char ***argv,
InputPadWindowType type);
void * input_pad_window_new (unsigned int ibus);
void * input_pad_window_new_with_paddir (unsigned int ibus,
const char *paddir);
void input_pad_window_show (void *window_data);
void input_pad_window_hide (void *window_data);
unsigned int input_pad_window_get_visible (void *window_data);
Expand Down
6 changes: 5 additions & 1 deletion input-pad/parse-pad.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ input_pad_group_append_from_file (InputPadGroup *group,
}

InputPadGroup *
input_pad_group_parse_all_files (void)
input_pad_group_parse_all_files (const char *custom_dirname)
{
const gchar *dirname = INPUT_PAD_PAD_SYSTEM_DIR;
const gchar *filename;
Expand All @@ -383,6 +383,10 @@ input_pad_group_parse_all_files (void)
GSList *file_list = NULL;
GSList *list;

if (custom_dirname != NULL) {
dirname = (const gchar *) custom_dirname;
}

if (!dirname ||
!g_file_test (dirname, G_FILE_TEST_IS_DIR)) {
g_warning ("Directory Not Found: %s", dirname ? dirname : "(null)");
Expand Down
84 changes: 51 additions & 33 deletions input-pad/window-gtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,11 @@ on_button_pressed (GtkButton *button, gpointer data)
keysyms = input_pad_gtk_button_get_all_keysyms (ibutton);
group = input_pad_gtk_button_get_keysym_group (ibutton);
state = window->priv->keyboard_state;
if (!g_strcmp0 (str, " ") &&
keysym == (guint) '\t' && keycode == 0 && keysyms == NULL) {
str = "\t";
keysym = 0;
}
if (keysyms && (keysym != keysyms[group][0])) {
state |= ShiftMask;
}
Expand Down Expand Up @@ -1293,7 +1298,6 @@ create_char_table (GtkWidget *vbox, InputPadTable *table_data)
GtkWidget *button = NULL;
gchar **char_table;
gchar *str;
gchar buff[6];
const int TABLE_COLUMN = table_data->column;
int i, num, raw, col, len, code;
guint keysym;
Expand Down Expand Up @@ -1364,8 +1368,7 @@ create_char_table (GtkWidget *vbox, InputPadTable *table_data)
len -= 2;
}
code = (int) g_ascii_strtoll (str, NULL, 16);
buff[g_unichar_to_utf8 ((gunichar) code, buff)] = '\0';
button = input_pad_gtk_button_new_with_label (buff);
button = input_pad_gtk_button_new_with_unicode (code);
/* Decided input-pad always sends char but not keysym.
* Now keyboard layout can be used instead. */
#if 0
Expand Down Expand Up @@ -2118,11 +2121,8 @@ append_char_view_table (GtkWidget *viewport,
GtkWidget *window)
{
unsigned int num;
int col, row, i;
int col, row;
const int TABLE_COLUMN = 15;
gchar buff[7];
gchar buff2[35]; /* 7 x 5 e.g. 'a' -> '0x61 ' */
gchar *tooltip;
GtkWidget *table;
GtkWidget *button;

Expand All @@ -2141,26 +2141,7 @@ append_char_view_table (GtkWidget *viewport,
gtk_widget_show (table);

for (num = start; num <= end; num++) {
if (num == '\t') {
buff[0] = ' ';
buff[1] = '\0';
sprintf (buff2, "0x%02X ", (unsigned char) num);
} else {
buff[g_unichar_to_utf8 ((gunichar) num, buff)] = '\0';
for (i = 0; buff[i] && i < 7; i++) {
sprintf (buff2 + i * 5, "0x%02X ", (unsigned char) buff[i]);
}
if (buff[0] == '\0') {
buff2[0] = '0'; buff2[0] = 'x'; buff2[1] = '0'; buff2[2] = '0';
buff2[3] = '\0';
}
}
button = input_pad_gtk_button_new_with_label (buff);
tooltip = g_strdup_printf ("U+%04X\nUTF-8 %s", num, buff2);
gtk_widget_set_tooltip_text (GTK_WIDGET (button), tooltip);
g_free (tooltip);
input_pad_gtk_button_set_table_type (INPUT_PAD_GTK_BUTTON (button),
INPUT_PAD_TABLE_TYPE_CHARS);
button = input_pad_gtk_button_new_with_unicode (num);
row = (num - start) / TABLE_COLUMN;
col = (num - start) % TABLE_COLUMN;
#if 0
Expand Down Expand Up @@ -2285,11 +2266,12 @@ create_keyboard_layout_ui (GtkBuilder *builder, GtkWidget *window)
}

static GtkWidget *
create_ui (void)
create_ui (InputPadGroup *custom_group)
{
const gchar *filename = INPUT_PAD_UI_FILE;
GError *error = NULL;
GtkWidget *window = NULL;
InputPadGtkWindow *input_pad;
GtkAction *close_item;
GtkBuilder *builder = gtk_builder_new ();

Expand All @@ -2309,6 +2291,14 @@ create_ui (void)
}

window = GTK_WIDGET (gtk_builder_get_object (builder, "TopWindow"));
if (custom_group != NULL) {
g_return_val_if_fail (INPUT_PAD_IS_GTK_WINDOW (window), NULL);
input_pad = INPUT_PAD_GTK_WINDOW (window);
g_return_val_if_fail (input_pad->priv != NULL, NULL);
g_return_val_if_fail (input_pad->priv->group != NULL, NULL);
input_pad_group_destroy (input_pad->priv->group);
input_pad->priv->group = custom_group;
}
gtk_window_set_icon_from_file (GTK_WINDOW (window),
DATAROOTDIR "/pixmaps/input-pad.png",
&error);
Expand Down Expand Up @@ -2465,7 +2455,7 @@ input_pad_gtk_window_set_group (InputPadGtkWindow *window)
{
InputPadGtkWindowPrivate *priv = INPUT_PAD_GTK_WINDOW_GET_PRIVATE (window);
if (priv->group == NULL) {
priv->group = input_pad_group_parse_all_files ();
priv->group = input_pad_group_parse_all_files (NULL);
}
window->priv = priv;
}
Expand Down Expand Up @@ -2600,9 +2590,11 @@ input_pad_gtk_window_class_init (InputPadGtkWindowClass *klass)
GtkWidget *
_input_pad_gtk_window_new_with_gtype (GtkWindowType type,
unsigned int child,
const char *custom_dirname,
gboolean gtype)
{
GtkWidget *window;
InputPadGroup *custom_group = NULL;

g_return_val_if_fail (type >= GTK_WINDOW_TOPLEVEL && type <= GTK_WINDOW_POPUP, NULL);

Expand All @@ -2615,7 +2607,10 @@ _input_pad_gtk_window_new_with_gtype (GtkWindowType type,
INPUT_PAD_TYPE_GTK_WINDOW;
}

window = create_ui ();
if (custom_dirname != NULL) {
custom_group = input_pad_group_parse_all_files (custom_dirname);
}
window = create_ui (custom_group);
INPUT_PAD_GTK_WINDOW (window)->parent.type = type;
INPUT_PAD_GTK_WINDOW (window)->child = child;

Expand All @@ -2625,7 +2620,18 @@ _input_pad_gtk_window_new_with_gtype (GtkWindowType type,
GtkWidget *
input_pad_gtk_window_new (GtkWindowType type, unsigned int child)
{
return _input_pad_gtk_window_new_with_gtype (type, child, FALSE);
return input_pad_gtk_window_new_with_paddir (type, child, NULL);
}

GtkWidget *
input_pad_gtk_window_new_with_paddir (GtkWindowType type,
unsigned int child,
const gchar *paddir)
{
return _input_pad_gtk_window_new_with_gtype (type,
child,
(const char *) paddir,
FALSE);
}

const char*
Expand Down Expand Up @@ -2676,10 +2682,22 @@ input_pad_window_new (unsigned int ibus)
}

void *
_input_pad_window_new_with_gtype (unsigned int ibus, gboolean gtype)
input_pad_window_new_with_paddir (unsigned int ibus, const char *paddir)
{
return input_pad_gtk_window_new_with_paddir (GTK_WINDOW_TOPLEVEL,
ibus,
(const gchar *) paddir);
}

void *
_input_pad_window_new_with_gtype (unsigned int ibus,
const char *paddir,
gboolean gtype)
{
return _input_pad_gtk_window_new_with_gtype (GTK_WINDOW_TOPLEVEL,
ibus, gtype);
ibus,
paddir,
gtype);
}

void
Expand Down
8 changes: 5 additions & 3 deletions pyinput-pad/input_pad.i
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ class InputPadWindow:
import gtk

_input_pad_window_init_wrapper (argv, type)
def new (self, ibus=0):
self.window = _input_pad_window_new_with_gtype (ibus, True)
def new (self, ibus=0, paddir=None):
self.window = _input_pad_window_new_with_gtype (ibus, paddir, True)
def show(self):
input_pad_window_show(self.window)
def hide(self):
Expand All @@ -45,7 +45,9 @@ class InputPadWindow:
%inline %{
/* workaround */
extern void*
_input_pad_window_new_with_gtype (unsigned int ibus, unsigned int gtype);
_input_pad_window_new_with_gtype (unsigned int ibus,
const char *paddir,
unsigned int gtype);

void
_input_pad_window_init_wrapper (PyObject *pyargv, InputPadWindowType type)
Expand Down
5 changes: 5 additions & 0 deletions pyinput-pad/input_pad_group.i
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@

%include input-pad-group.h

%pythoncode
{
def parse_all_files(paddir=None):
return input_pad_group_parse_all_files (paddir)
}
32 changes: 23 additions & 9 deletions pyinput-pad/input_pad_window_gtk.i
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
%{
#include <input-pad-window-gtk-swig.h>
InputPadGtkWindow *
_input_pad_gtk_window_new_wrapper (int pytype, unsigned int ibus);
_input_pad_gtk_window_new_wrapper (int pytype,
unsigned int ibus,
const char *paddir);
unsigned long
_input_pad_gtk_window_connect_wrapper (struct _InputPadGtkWindow *self,
char *signal_id,
Expand All @@ -12,10 +14,19 @@ _input_pad_gtk_window_connect_wrapper (struct _InputPadGtkWindow *self,
%}

%include input-pad-window-gtk-swig.h

%pythoncode
{
class InputPadGtkWindow(_InputPadGtkWindow):
def __init__(self, pytype, ibus=0, paddir=None):
_InputPadGtkWindow.__init__(self, pytype, ibus, paddir)
}

%extend _InputPadGtkWindow {
_InputPadGtkWindow (int pytype,
unsigned int ibus) {
return _input_pad_gtk_window_new_wrapper (pytype, ibus);
_InputPadGtkWindow (int pytype,
unsigned int ibus,
const char *paddir) {
return _input_pad_gtk_window_new_wrapper (pytype, ibus, paddir);
}
void hide () {
gtk_widget_hide (GTK_WIDGET (self));
Expand All @@ -42,17 +53,20 @@ _input_pad_gtk_window_connect_wrapper (struct _InputPadGtkWindow *self,
%inline %{
/* workaround */
extern GtkWidget *
_input_pad_gtk_window_new_with_gtype (GtkWindowType type,
unsigned int child,
gboolean gtype);
_input_pad_gtk_window_new_with_gtype (GtkWindowType type,
unsigned int child,
const char *paddir,
gboolean gtype);

InputPadGtkWindow *
_input_pad_gtk_window_new_wrapper (int pytype, unsigned int ibus)
_input_pad_gtk_window_new_wrapper (int pytype,
unsigned int ibus,
const char *paddir)
{
GtkWindowType type;
type = pytype;
return (InputPadGtkWindow *)
_input_pad_gtk_window_new_with_gtype (type, ibus, TRUE);
_input_pad_gtk_window_new_with_gtype (type, ibus, paddir, TRUE);
}

typedef struct _python_callback_data
Expand Down
Loading

0 comments on commit 61e33f3

Please sign in to comment.