Finished the implementation of GTK+ uiButton and implemented a few fixes and added some TODOs.

This commit is contained in:
Pietro Gagliardi 2015-06-30 10:52:38 -04:00
parent a2fee7aeb7
commit 96172d9b04
4 changed files with 15 additions and 48 deletions

View File

@ -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); complain("attempt to reparent uiControl %p (has parent %p, attempt to give parent %p)", c, cb->parent, parent);
if (parent == NULL && cb->parent == NULL) if (parent == NULL && cb->parent == NULL)
complain("attempt to double unparent uiControl %p", c); complain("attempt to double unparent uiControl %p", c);
cb->parent = parent; // this must come first; GTK+ CommitSetParent() needs the old parent
uiControlCommitSetParent(c, parent); uiControlCommitSetParent(c, parent);
cb->parent = parent;
// for situations such as where the old parent was disabled but the new one is not, etc. // for situations such as where the old parent was disabled but the new one is not, etc.
uiControlUpdateState(c); uiControlUpdateState(c);
} }

View File

@ -1,6 +1,9 @@
// 7 april 2015 // 7 april 2015
#include "uipriv_unix.h" #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 { struct box {
uiBox b; uiBox b;
GtkWidget *widget; GtkWidget *widget;

View File

@ -11,6 +11,13 @@ struct button {
uiDefineControlType(uiButton, uiTypeButton, 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) static uintptr_t buttonHandle(uiControl *c)
{ {
struct button *b = (struct button *) c; struct button *b = (struct button *) c;
@ -27,14 +34,14 @@ static char *buttonText(uiButton *bb)
{ {
struct button *b = (struct button *) 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) static void buttonSetText(uiButton *bb, const char *text)
{ {
struct button *b = (struct button *) bb; 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 // changing the text might necessitate a change in the button's size
uiControlQueueResize(uiControl(b)); uiControlQueueResize(uiControl(b));
} }
@ -57,6 +64,7 @@ uiButton *uiNewButton(const char *text)
b->button = GTK_BUTTON(b->widget); b->button = GTK_BUTTON(b->widget);
uiUnixMakeSingleWidgetControl(uiControl(b), b->widget); uiUnixMakeSingleWidgetControl(uiControl(b), b->widget);
g_signal_connect(b->widget, "clicked", G_CALLBACK(onClicked), b);
b->onClicked = defaultOnClicked; b->onClicked = defaultOnClicked;
uiControl(b)->Handle = buttonHandle; uiControl(b)->Handle = buttonHandle;

View File

@ -16,52 +16,7 @@ static void onClicked(GtkButton *button, gpointer data)
(*(b->onClicked))(uiButton(b), b->onClickedData); (*(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);
}