2015-04-07 12:58:50 -05:00
|
|
|
// 7 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
|
|
|
struct button {
|
|
|
|
uiControl *c;
|
|
|
|
void (*onClicked)(uiControl *, void *);
|
|
|
|
void *onClickedData;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define B(x) ((struct button *) (x))
|
|
|
|
|
|
|
|
static void onClicked(GtkButton *b, gpointer data)
|
|
|
|
{
|
|
|
|
(*(B(data)->onClicked))(B(data)->c, B(data)->onClickedData);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void defaultOnClicked(uiControl *c, void *data)
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
static void onDestroy(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
|
|
|
struct button *b = (struct button *) data;
|
|
|
|
|
|
|
|
uiFree(b);
|
|
|
|
}
|
|
|
|
|
2015-04-07 12:58:50 -05:00
|
|
|
uiControl *uiNewButton(const char *text)
|
|
|
|
{
|
|
|
|
struct button *b;
|
|
|
|
GtkWidget *widget;
|
|
|
|
|
2015-04-07 18:04:09 -05:00
|
|
|
b = uiNew(struct button);
|
2015-04-07 12:58:50 -05:00
|
|
|
|
|
|
|
b->c = uiUnixNewControl(GTK_TYPE_BUTTON,
|
2015-04-08 15:24:11 -05:00
|
|
|
FALSE, FALSE, b,
|
2015-04-07 18:47:44 -05:00
|
|
|
"label", text,
|
|
|
|
NULL);
|
2015-04-07 12:58:50 -05:00
|
|
|
|
|
|
|
widget = GTK_WIDGET(uiControlHandle(b->c));
|
2015-04-08 00:16:22 -05:00
|
|
|
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), b);
|
2015-04-07 12:58:50 -05:00
|
|
|
g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);
|
|
|
|
|
|
|
|
b->onClicked = defaultOnClicked;
|
|
|
|
|
|
|
|
return b->c;
|
|
|
|
}
|
|
|
|
|
2015-04-09 01:56:51 -05:00
|
|
|
char *uiButtonText(uiControl *c)
|
|
|
|
{
|
|
|
|
return g_strdup(gtk_button_get_label(GTK_BUTTON(uiControlHandle(c))));
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiButtonSetText(uiControl *c, const char *text)
|
|
|
|
{
|
|
|
|
gtk_button_set_label(GTK_BUTTON(uiControlHandle(c)), text);
|
|
|
|
}
|
2015-04-07 12:58:50 -05:00
|
|
|
|
|
|
|
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
|
|
|
|
{
|
|
|
|
struct button *b;
|
|
|
|
|
|
|
|
b = (struct button *) uiUnixControlData(c);
|
|
|
|
b->onClicked = f;
|
|
|
|
b->onClickedData = data;
|
|
|
|
}
|