Converted unix/button.c.
This commit is contained in:
parent
c19a90cfca
commit
ff6a3ed543
|
@ -2,19 +2,19 @@
|
||||||
#include "uipriv_unix.h"
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
struct button {
|
struct button {
|
||||||
|
uiButton b;
|
||||||
void (*onClicked)(uiControl *, void *);
|
void (*onClicked)(uiControl *, void *);
|
||||||
void *onClickedData;
|
void *onClickedData;
|
||||||
};
|
};
|
||||||
|
|
||||||
static void onClicked(GtkButton *button, gpointer data)
|
static void onClicked(GtkButton *button, gpointer data)
|
||||||
{
|
{
|
||||||
uiControl *c = uiControl(data);
|
struct button *b = (struct button *) data;
|
||||||
struct button *b = (struct button *) (c->data);
|
|
||||||
|
|
||||||
(*(b->onClicked))(c, b->onClickedData);
|
(*(b->onClicked))(uiButton(b), b->onClickedData);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void defaultOnClicked(uiControl *c, void *data)
|
static void defaultOnClicked(uiButton *b, void *data)
|
||||||
{
|
{
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
|
@ -26,19 +26,21 @@ static void onDestroy(GtkWidget *widget, gpointer data)
|
||||||
uiFree(b);
|
uiFree(b);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BUTTON(b) GTK_BUTTON(uiControlHandle(uiControl(b)))
|
||||||
|
|
||||||
static char *getText(uiButton *b)
|
static char *getText(uiButton *b)
|
||||||
{
|
{
|
||||||
return g_strdup(gtk_button_get_label(GTK_BUTTON(uiControlHandle(b.base))));
|
return g_strdup(gtk_button_get_label(BUTTON(b)));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setText(uiButton *b, const char *text)
|
static void setText(uiButton *b, const char *text)
|
||||||
{
|
{
|
||||||
gtk_button_set_label(GTK_BUTTON(uiControlHandle(b.base)), text);
|
gtk_button_set_label(BUTTON(b), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setOnClicked(uiButton *b, void (*f)(uiControl *, void *), void *data)
|
static void setOnClicked(uiButton *b, void (*f)(uiControl *, void *), void *data)
|
||||||
{
|
{
|
||||||
struct button *b = (struct button *) (b->base.data);
|
struct button *b = (struct button *) b;
|
||||||
|
|
||||||
b->onClicked = f;
|
b->onClicked = f;
|
||||||
b->onClickedData = data;
|
b->onClickedData = data;
|
||||||
|
@ -46,28 +48,24 @@ static void setOnClicked(uiButton *b, void (*f)(uiControl *, void *), void *data
|
||||||
|
|
||||||
uiControl *uiNewButton(const char *text)
|
uiControl *uiNewButton(const char *text)
|
||||||
{
|
{
|
||||||
uiButton *b;
|
struct button *b;
|
||||||
struct button *bb;
|
|
||||||
GtkWidget *widget;
|
GtkWidget *widget;
|
||||||
|
|
||||||
b = uiNew(uiButton);
|
b = uiNew(b);
|
||||||
|
|
||||||
uiUnixNewControl(&(b.base), GTK_TYPE_BUTTON,
|
uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON,
|
||||||
FALSE, FALSE,
|
FALSE, FALSE,
|
||||||
"label", text,
|
"label", text,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
widget = GTK_WIDGET(uiControlHandle(&(b.base)));
|
widget = GTK_WIDGET(BUTTON(b));
|
||||||
g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);
|
g_signal_connect(widget, "clicked", G_CALLBACK(onClicked), b);
|
||||||
|
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), b);
|
||||||
|
b->onClicked = defaultOnClicked;
|
||||||
|
|
||||||
bb = uiNew(struct button);
|
uiButton(b)->Text = getText;
|
||||||
g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), bb);
|
uiButton(b)->SetText = setText;
|
||||||
bb->onClicked = defaultOnClicked;
|
uiButton(b)->OnClicked = setOnClicked;
|
||||||
b->priv.data = bb;
|
|
||||||
|
|
||||||
b->Text = getText;
|
|
||||||
b->SetText = setText;
|
|
||||||
b->OnClicked = setOnClicked;
|
|
||||||
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue