2015-04-07 12:58:50 -05:00
|
|
|
// 7 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct button {
|
2015-04-15 20:57:59 -05:00
|
|
|
uiButton b;
|
2015-04-16 20:01:16 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkButton *button;
|
2015-04-15 22:14:36 -05:00
|
|
|
void (*onClicked)(uiButton *, void *);
|
2015-04-07 12:58:50 -05:00
|
|
|
void *onClickedData;
|
|
|
|
};
|
|
|
|
|
2015-04-16 20:01:16 -05:00
|
|
|
static void onClicked(GtkButton *button, gpointer data)
|
2015-04-07 12:58:50 -05:00
|
|
|
{
|
2015-04-15 20:57:59 -05:00
|
|
|
struct button *b = (struct button *) data;
|
2015-04-09 17:17:04 -05:00
|
|
|
|
2015-04-15 20:57:59 -05:00
|
|
|
(*(b->onClicked))(uiButton(b), b->onClickedData);
|
2015-04-07 12:58:50 -05:00
|
|
|
}
|
|
|
|
|
2015-04-15 20:57:59 -05:00
|
|
|
static void defaultOnClicked(uiButton *b, void *data)
|
2015-04-07 12:58:50 -05:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-04-18 16:14:19 -05:00
|
|
|
static void onDestroy(void *data)
|
2015-04-08 00:16:22 -05:00
|
|
|
{
|
2015-04-18 16:14:19 -05:00
|
|
|
struct button *b = (struct button *) data;
|
2015-04-08 00:16:22 -05:00
|
|
|
|
|
|
|
uiFree(b);
|
|
|
|
}
|
|
|
|
|
2015-04-16 15:38:33 -05:00
|
|
|
static char *buttonText(uiButton *bb)
|
2015-04-07 12:58:50 -05:00
|
|
|
{
|
2015-04-16 20:01:16 -05:00
|
|
|
struct button *b = (struct button *) bb;
|
|
|
|
|
|
|
|
return g_strdup(gtk_button_get_label(b->button));
|
2015-04-07 12:58:50 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 15:38:33 -05:00
|
|
|
static void buttonSetText(uiButton *bb, const char *text)
|
2015-04-09 01:56:51 -05:00
|
|
|
{
|
2015-04-16 20:01:16 -05:00
|
|
|
struct button *b = (struct button *) bb;
|
|
|
|
|
|
|
|
gtk_button_set_label(b->button, text);
|
2015-04-09 01:56:51 -05:00
|
|
|
}
|
|
|
|
|
2015-04-16 15:38:33 -05:00
|
|
|
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
2015-04-09 01:56:51 -05:00
|
|
|
{
|
2015-04-15 22:07:43 -05:00
|
|
|
struct button *b = (struct button *) bb;
|
2015-04-15 18:46:24 -05:00
|
|
|
|
|
|
|
b->onClicked = f;
|
|
|
|
b->onClickedData = data;
|
2015-04-09 01:56:51 -05:00
|
|
|
}
|
2015-04-07 12:58:50 -05:00
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
uiButton *uiNewButton(const char *text)
|
2015-04-07 12:58:50 -05:00
|
|
|
{
|
2015-04-15 20:57:59 -05:00
|
|
|
struct button *b;
|
2015-04-07 12:58:50 -05:00
|
|
|
|
2015-04-15 22:07:43 -05:00
|
|
|
b = uiNew(struct button);
|
2015-04-15 18:46:24 -05:00
|
|
|
|
2015-04-15 20:57:59 -05:00
|
|
|
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON,
|
2015-04-18 16:14:19 -05:00
|
|
|
FALSE, FALSE, onDestroy, b,
|
2015-04-15 18:46:24 -05:00
|
|
|
"label", text,
|
|
|
|
NULL);
|
|
|
|
|
2015-04-16 20:01:16 -05:00
|
|
|
b->widget = WIDGET(b);
|
|
|
|
b->button = GTK_BUTTON(b->widget);
|
|
|
|
|
2015-04-16 21:14:54 -05:00
|
|
|
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
2015-04-15 20:57:59 -05:00
|
|
|
b->onClicked = defaultOnClicked;
|
2015-04-15 18:46:24 -05:00
|
|
|
|
2015-04-16 15:38:33 -05:00
|
|
|
uiButton(b)->Text = buttonText;
|
|
|
|
uiButton(b)->SetText = buttonSetText;
|
|
|
|
uiButton(b)->OnClicked = buttonOnClicked;
|
2015-04-15 18:46:24 -05:00
|
|
|
|
2015-04-15 21:20:25 -05:00
|
|
|
return uiButton(b);
|
2015-04-07 12:58:50 -05:00
|
|
|
}
|