Migrated unix/newcontrol.c back. Fixed an oversight in unix/container.c.

This commit is contained in:
Pietro Gagliardi 2015-04-28 21:30:38 -04:00
parent 2fdbacfd95
commit 699cd12a19
3 changed files with 39 additions and 84 deletions

View File

@ -6,6 +6,7 @@ osCFILES = \
unix/container.c \ unix/container.c \
unix/main.c \ unix/main.c \
unix/menu.c \ unix/menu.c \
unix/newcontrol.c \
unix/text.c \ unix/text.c \
unix/util.c \ unix/util.c \
unix/window.c unix/window.c

View File

@ -177,6 +177,8 @@ static void containerShow(uiControl *cc)
// don't use gtk_widget_show_all(); that'll show every widget, including ones hidden by the user // don't use gtk_widget_show_all(); that'll show every widget, including ones hidden by the user
gtk_widget_show(GTK_WIDGET(c)); gtk_widget_show(GTK_WIDGET(c));
if (c->parent != NULL)
uiContainerUpdate(c->parent);
c->hidden = 0; c->hidden = 0;
} }
@ -185,6 +187,8 @@ static void containerHide(uiControl *cc)
containerWidget *c = containerWidget(cc->Internal); containerWidget *c = containerWidget(cc->Internal);
gtk_widget_hide(GTK_WIDGET(c)); gtk_widget_hide(GTK_WIDGET(c));
if (c->parent != NULL)
uiContainerUpdate(c->parent);
c->hidden = 1; c->hidden = 1;
} }

View File

@ -1,34 +1,33 @@
// 7 april 2015 // 7 april 2015
#include "uipriv_unix.h" #include "uipriv_unix.h"
// TODO rename these
// TODO get rid of this
typedef struct singleWidget singleWidget; typedef struct singleWidget singleWidget;
struct singleWidget { struct singleWidget {
GtkWidget *widget; GtkWidget *widget;
GtkWidget *scrolledWindow; GtkWidget *scrolledWindow;
GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow
uiParent *parent; uiContainer *parent;
gboolean userHid; int hidden;
gboolean containerHid;
gboolean userDisabled;
gboolean containerDisabled;
gulong destroyBlocker;
void (*onDestroy)(void *); void (*onDestroy)(void *);
void *onDestroyData; void *onDestroyData;
}; };
// TODO destruction blockers
static void singleDestroy(uiControl *c) static void singleDestroy(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
if (s->parent != NULL) if (s->parent != NULL)
complain("attempt to destroy a uiControl at %p while it still has a parent %p", c, s->parent); complain("attempt to destroy a uiControl at %p while it still has a parent", c);
// first call the widget's own destruction code // first call the widget's own destruction code
(*(s->onDestroy))(s->onDestroyData); (*(s->onDestroy))(s->onDestroyData);
// then mark that we are ready to be destroyed // then actually destroy (TODO sync these comments with the container and window ones)
readyToDestroy(s->immediate, s->destroyBlocker); g_object_unref(s->immediate);
// then actually destroy (TODO sync these comments)
gtk_widget_destroy(s->immediate);
// and free ourselves // and free ourselves
uiFree(s); uiFree(s);
} }
@ -40,21 +39,27 @@ static uintptr_t singleHandle(uiControl *c)
return (uintptr_t) (s->widget); return (uintptr_t) (s->widget);
} }
static void singleSetParent(uiControl *c, uiParent *parent) static void singleSetParent(uiControl *c, uiContainer *parent)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
uiParent *oldparent; uiContainer *oldparent;
GtkContainer *oldcontainer;
GtkContainer *newcontainer;
oldparent = s->parent; oldparent = s->parent;
s->parent = parent; s->parent = parent;
if (oldparent != NULL) { if (oldparent != NULL) {
gtk_container_remove(GTK_CONTAINER(uiParentHandle(oldparent)), s->immediate); oldcontainer = GTK_CONTAINER(uiControlHandle(uiControl(oldparent)));
uiParentUpdate(oldparent); gtk_container_remove(oldcontainer, s->immediate);
} }
if (s->parent != NULL) { if (s->parent != NULL) {
gtk_container_add(GTK_CONTAINER(uiParentHandle(s->parent)), s->immediate); newcontainer = GTK_CONTAINER(uiControlHandle(uiControl(s->parent)));
uiParentUpdate(s->parent); gtk_container_add(newcontainer, s->immediate);
} }
if (oldparent != NULL)
uiContainerUpdate(oldparent);
if (s->parent != NULL)
uiContainerUpdate(s->parent);
} }
static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
@ -86,61 +91,33 @@ static int singleVisible(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
if (s->userHid) return s->hidden;
return 0;
return 1;
} }
static void singleShow(uiControl *c) static void singleShow(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
s->userHid = FALSE;
if (!s->containerHid) {
gtk_widget_show_all(s->immediate); gtk_widget_show_all(s->immediate);
if (s->parent != NULL) if (s->parent != NULL)
uiParentUpdate(s->parent); uiContainerUpdate(s->parent);
} s->hidden = 0;
} }
static void singleHide(uiControl *c) static void singleHide(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
s->userHid = TRUE;
gtk_widget_hide(s->immediate); gtk_widget_hide(s->immediate);
if (s->parent != NULL) if (s->parent != NULL)
uiParentUpdate(s->parent); uiContainerUpdate(s->parent);
} s->hidden = 1;
static void singleContainerShow(uiControl *c)
{
singleWidget *s = (singleWidget *) (c->Internal);
s->containerHid = FALSE;
if (!s->userHid) {
gtk_widget_show_all(s->immediate);
if (s->parent != NULL)
uiParentUpdate(s->parent);
}
}
static void singleContainerHide(uiControl *c)
{
singleWidget *s = (singleWidget *) (c->Internal);
s->containerHid = TRUE;
gtk_widget_hide(s->immediate);
if (s->parent != NULL)
uiParentUpdate(s->parent);
} }
static void singleEnable(uiControl *c) static void singleEnable(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
s->userDisabled = FALSE;
if (!s->containerDisabled)
gtk_widget_set_sensitive(s->immediate, TRUE); gtk_widget_set_sensitive(s->immediate, TRUE);
} }
@ -148,24 +125,6 @@ static void singleDisable(uiControl *c)
{ {
singleWidget *s = (singleWidget *) (c->Internal); singleWidget *s = (singleWidget *) (c->Internal);
s->userDisabled = TRUE;
gtk_widget_set_sensitive(s->immediate, FALSE);
}
static void singleContainerEnable(uiControl *c)
{
singleWidget *s = (singleWidget *) (c->Internal);
s->containerDisabled = FALSE;
if (!s->userDisabled)
gtk_widget_set_sensitive(s->immediate, TRUE);
}
static void singleContainerDisable(uiControl *c)
{
singleWidget *s = (singleWidget *) (c->Internal);
s->containerDisabled = TRUE;
gtk_widget_set_sensitive(s->immediate, FALSE); gtk_widget_set_sensitive(s->immediate, FALSE);
} }
@ -207,7 +166,10 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
s->onDestroy = onDestroy; s->onDestroy = onDestroy;
s->onDestroyData = onDestroyData; s->onDestroyData = onDestroyData;
// assign s later; we still need it for one more thing // finally, call gtk_widget_show_all() here to set the initial visibility of the widget
gtk_widget_show_all(s->immediate);
c->Internal = s;
c->Destroy = singleDestroy; c->Destroy = singleDestroy;
c->Handle = singleHandle; c->Handle = singleHandle;
c->SetParent = singleSetParent; c->SetParent = singleSetParent;
@ -216,18 +178,6 @@ void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gbool
c->Visible = singleVisible; c->Visible = singleVisible;
c->Show = singleShow; c->Show = singleShow;
c->Hide = singleHide; c->Hide = singleHide;
c->ContainerShow = singleContainerShow;
c->ContainerHide = singleContainerHide;
c->Enable = singleEnable; c->Enable = singleEnable;
c->Disable = singleDisable; c->Disable = singleDisable;
c->ContainerEnable = singleContainerEnable;
c->ContainerDisable = singleContainerDisable;
// let's stop premature destruction
s->destroyBlocker = blockDestruction(s->immediate, c);
// finally, call gtk_widget_show_all() here to set the initial visibility of the widget
gtk_widget_show_all(s->immediate);
c->Internal = s;
} }