From 96172d9b044e84172f3c3315bb378a032a618531 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 30 Jun 2015 10:52:38 -0400 Subject: [PATCH] Finished the implementation of GTK+ uiButton and implemented a few fixes and added some TODOs. --- redo/control.c | 3 ++- redo/unix/box.c | 3 +++ redo/unix/button.c | 12 ++++++++++-- unix/button.c | 45 --------------------------------------------- 4 files changed, 15 insertions(+), 48 deletions(-) diff --git a/redo/control.c b/redo/control.c index 18575787..23a0dc0d 100644 --- a/redo/control.c +++ b/redo/control.c @@ -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); } diff --git a/redo/unix/box.c b/redo/unix/box.c index 44472616..949c1ef0 100644 --- a/redo/unix/box.c +++ b/redo/unix/box.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; diff --git a/redo/unix/button.c b/redo/unix/button.c index 588297c8..df356ed5 100644 --- a/redo/unix/button.c +++ b/redo/unix/button.c @@ -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; diff --git a/unix/button.c b/unix/button.c index e3081866..8e64d046 100644 --- a/unix/button.c +++ b/unix/button.c @@ -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); -}