Finished the implementation of GTK+ uiButton and implemented a few fixes and added some TODOs.
This commit is contained in:
parent
a2fee7aeb7
commit
96172d9b04
|
@ -45,8 +45,9 @@ static void controlBaseSetParent(uiControl *c, uiControl *parent)
|
|||
complain("attempt to reparent uiControl %p (has parent %p, attempt to give parent %p)", c, cb->parent, parent);
|
||||
if (parent == NULL && cb->parent == NULL)
|
||||
complain("attempt to double unparent uiControl %p", c);
|
||||
cb->parent = parent;
|
||||
// this must come first; GTK+ CommitSetParent() needs the old parent
|
||||
uiControlCommitSetParent(c, parent);
|
||||
cb->parent = parent;
|
||||
// for situations such as where the old parent was disabled but the new one is not, etc.
|
||||
uiControlUpdateState(c);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
// 7 april 2015
|
||||
#include "uipriv_unix.h"
|
||||
|
||||
// TODO
|
||||
// - the move the label box on GTK+ is not sized halfway, or the label below it is not; one of the two
|
||||
|
||||
struct box {
|
||||
uiBox b;
|
||||
GtkWidget *widget;
|
||||
|
|
|
@ -11,6 +11,13 @@ struct button {
|
|||
|
||||
uiDefineControlType(uiButton, uiTypeButton, struct button)
|
||||
|
||||
static void onClicked(GtkButton *button, gpointer data)
|
||||
{
|
||||
struct button *b = (struct button *) data;
|
||||
|
||||
(*(b->onClicked))(uiButton(b), b->onClickedData);
|
||||
}
|
||||
|
||||
static uintptr_t buttonHandle(uiControl *c)
|
||||
{
|
||||
struct button *b = (struct button *) c;
|
||||
|
@ -27,14 +34,14 @@ static char *buttonText(uiButton *bb)
|
|||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
return PUT_CODE_HERE;
|
||||
return uiUnixStrdupText(gtk_button_get_label(b->button));
|
||||
}
|
||||
|
||||
static void buttonSetText(uiButton *bb, const char *text)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
PUT_CODE_HERE;
|
||||
gtk_button_set_label(b->button, text);
|
||||
// changing the text might necessitate a change in the button's size
|
||||
uiControlQueueResize(uiControl(b));
|
||||
}
|
||||
|
@ -57,6 +64,7 @@ uiButton *uiNewButton(const char *text)
|
|||
b->button = GTK_BUTTON(b->widget);
|
||||
uiUnixMakeSingleWidgetControl(uiControl(b), b->widget);
|
||||
|
||||
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
||||
b->onClicked = defaultOnClicked;
|
||||
|
||||
uiControl(b)->Handle = buttonHandle;
|
||||
|
|
|
@ -16,52 +16,7 @@ static void onClicked(GtkButton *button, gpointer data)
|
|||
(*(b->onClicked))(uiButton(b), b->onClickedData);
|
||||
}
|
||||
|
||||
static void defaultOnClicked(uiButton *b, void *data)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
|
||||
static void onDestroy(void *data)
|
||||
{
|
||||
struct button *b = (struct button *) data;
|
||||
|
||||
uiFree(b);
|
||||
}
|
||||
|
||||
static char *buttonText(uiButton *bb)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
return uiUnixStrdupText(gtk_button_get_label(b->button));
|
||||
}
|
||||
|
||||
static void buttonSetText(uiButton *bb, const char *text)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
gtk_button_set_label(b->button, text);
|
||||
}
|
||||
|
||||
static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)
|
||||
{
|
||||
struct button *b = (struct button *) bb;
|
||||
|
||||
b->onClicked = f;
|
||||
b->onClickedData = data;
|
||||
}
|
||||
|
||||
uiButton *uiNewButton(const char *text)
|
||||
{
|
||||
struct button *b;
|
||||
|
||||
b = uiNew(struct button);
|
||||
|
||||
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
|
||||
b->onClicked = defaultOnClicked;
|
||||
|
||||
uiButton(b)->Text = buttonText;
|
||||
uiButton(b)->SetText = buttonSetText;
|
||||
uiButton(b)->OnClicked = buttonOnClicked;
|
||||
|
||||
return uiButton(b);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue