From 85ee2e93dd58663939530772841aeb97aa25e213 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 25 Apr 2016 19:45:05 -0400 Subject: [PATCH] More ui_unix.h and unix/control.c work. NOW we're ready to migrate the controls. --- ui_unix.h | 78 +++++++++++++++++++++++++------------------------- unix/control.c | 28 ++---------------- 2 files changed, 41 insertions(+), 65 deletions(-) diff --git a/ui_unix.h b/ui_unix.h index 28cbbf86..6ea475a6 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -22,95 +22,95 @@ struct uiUnixControl { // TODO document _UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gboolean); -#define uiUnixControlDefaultDestroy(type, handlefield) \ +#define uiUnixControlDefaultDestroy(type) \ static void type ## Destroy(uiControl *c) \ { \ uiControlVerifyDestroy(c); \ /* TODO is this safe on floating refs? */ \ - g_object_unref(type(c)->handlefield); \ + g_object_unref(type(c)->widget); \ uiFreeControl(c); \ } -#define uiUnixControlDefaultHandle(type, handlefield) \ +#define uiUnixControlDefaultHandle(type) \ static uintptr_t type ## Handle(uiControl *c) \ { \ - return (uintptr_t) (type(c)->handlefield); \ + return (uintptr_t) (type(c)->widget); \ } -#define uiUnixControlDefaultParent(type, handlefield) \ +#define uiUnixControlDefaultParent(type) \ static uiControl *type ## Parent(uiControl *c) \ { \ return uiUnixControl(c)->parent; \ } -#define uiUnixControlDefaultSetParent(type, handlefield) \ +#define uiUnixControlDefaultSetParent(type) \ static void type ## SetParent(uiControl *c, uiControl *parent) \ { \ uiControlVerifySetParent(c, parent); \ uiUnixControl(c)->parent = parent; \ } -#define uiUnixControlDefaultToplevel(type, handlefield) \ +#define uiUnixControlDefaultToplevel(type) \ static int type ## Toplevel(uiControl *c) \ { \ return 0; \ } -#define uiUnixControlDefaultVisible(type, handlefield) \ +#define uiUnixControlDefaultVisible(type) \ static int type ## Visible(uiControl *c) \ { \ - return gtk_widget_get_visible(type(c)->handlefield); \ + return gtk_widget_get_visible(type(c)->widget); \ } -#define uiUnixControlDefaultShow(type, handlefield) \ +#define uiUnixControlDefaultShow(type) \ static void type ## Show(uiControl *c) \ { \ - gtk_widget_show(type(c)->handlefield); \ + gtk_widget_show(type(c)->widget); \ } -#define uiUnixControlDefaultHide(type, handlefield) \ +#define uiUnixControlDefaultHide(type) \ static void type ## Hide(uiControl *c) \ { \ - gtk_widget_hide(type(c)->handlefield); \ + gtk_widget_hide(type(c)->widget); \ } -#define uiUnixControlDefaultEnabled(type, handlefield) \ +#define uiUnixControlDefaultEnabled(type) \ static int type ## Enabled(uiControl *c) \ { \ - return gtk_widget_get_sensitive(type(c)->handlefield); \ + return gtk_widget_get_sensitive(type(c)->widget); \ } -#define uiUnixControlDefaultEnable(type, handlefield) \ +#define uiUnixControlDefaultEnable(type) \ static void type ## Enable(uiControl *c) \ { \ - gtk_widget_set_sensitive(type(c)->handlefield, TRUE); \ + gtk_widget_set_sensitive(type(c)->widget, TRUE); \ } -#define uiUnixControlDefaultDisable(type, handlefield) \ +#define uiUnixControlDefaultDisable(type) \ static void type ## Disable(uiControl *c) \ { \ - gtk_widget_set_sensitive(type(c)->handlefield, FALSE); \ + gtk_widget_set_sensitive(type(c)->widget, FALSE); \ } -#define uiUnixControlDefaultSetContainer(type, handlefield) \ +#define uiUnixControlDefaultSetContainer(type) \ static void type ## SetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) \ { \ if (!uiUnixControl(c)->addedBefore) { \ - g_object_ref_sink(type(c)->handlefield); /* our own reference, which we release in Destroy() */ \ - gtk_widget_show(type(c)->handlefield); \ + g_object_ref_sink(type(c)->widget); /* our own reference, which we release in Destroy() */ \ + gtk_widget_show(type(c)->widget); \ uiUnixControl(c)->addedBefore = TRUE; \ } \ if (remove) \ - gtk_container_remove(container, type(c)->handlefield); \ + gtk_container_remove(container, type(c)->widget); \ else \ - gtk_container_add(container, type(c)->handlefield); \ + gtk_container_add(container, type(c)->widget); \ } -#define uiUnixControlAllDefaultsExceptDestroy(type, handlefield) \ - uiUnixControlDefaultHandle(type, handlefield) \ - uiUnixControlDefaultParent(type, handlefield) \ - uiUnixControlDefaultSetParent(type, handlefield) \ - uiUnixControlDefaultToplevel(type, handlefield) \ - uiUnixControlDefaultVisible(type, handlefield) \ - uiUnixControlDefaultShow(type, handlefield) \ - uiUnixControlDefaultHide(type, handlefield) \ - uiUnixControlDefaultEnabled(type, handlefield) \ - uiUnixControlDefaultEnable(type, handlefield) \ - uiUnixControlDefaultDisable(type, handlefield) \ - uiUnixControlDefaultSetContainer(type, handlefield) +#define uiUnixControlAllDefaultsExceptDestroy(type) \ + uiUnixControlDefaultHandle(type) \ + uiUnixControlDefaultParent(type) \ + uiUnixControlDefaultSetParent(type) \ + uiUnixControlDefaultToplevel(type) \ + uiUnixControlDefaultVisible(type) \ + uiUnixControlDefaultShow(type) \ + uiUnixControlDefaultHide(type) \ + uiUnixControlDefaultEnabled(type) \ + uiUnixControlDefaultEnable(type) \ + uiUnixControlDefaultDisable(type) \ + uiUnixControlDefaultSetContainer(type) -#define uiUnixControlAllDefaults(type, handlefield) \ - uiUnixControlDefaultDestroy(type, handlefield) \ - uiUnixControlAllDefaultsExceptDestroy(type, handlefield) +#define uiUnixControlAllDefaults(type) \ + uiUnixControlDefaultDestroy(type) \ + uiUnixControlAllDefaultsExceptDestroy(type) // TODO document #define uiUnixNewControl(type, var) \ diff --git a/unix/control.c b/unix/control.c index 3906c04b..652b42c2 100644 --- a/unix/control.c +++ b/unix/control.c @@ -1,33 +1,9 @@ // 16 august 2015 #include "uipriv_unix.h" -static void defaultCommitShow(uiControl *c) +void uiUnixControlSetContainer(uiUnixControl *c, GtkContainer *container, gboolean remove) { - gtk_widget_show(GTK_WIDGET(uiControlHandle(c))); -} - -static void defaultCommitHide(uiControl *c) -{ - gtk_widget_hide(GTK_WIDGET(uiControlHandle(c))); -} - -void osCommitEnable(uiControl *c) -{ - gtk_widget_set_sensitive(GTK_WIDGET(uiControlHandle(c)), TRUE); -} - -void osCommitDisable(uiControl *c) -{ - gtk_widget_set_sensitive(GTK_WIDGET(uiControlHandle(c)), FALSE); -} - -void uiUnixFinishControl(uiControl *c) -{ - g_object_ref_sink(GTK_WIDGET(uiControlHandle(c))); - if (!isToplevel(c)) - gtk_widget_show(GTK_WIDGET(uiControlHandle(c))); - c->CommitShow = defaultCommitShow; - c->CommitHide = defaultCommitHide; + (*(c->SetContainer))(c, container, remove); } #define uiUnixControlSignature 0x556E6978