2015-04-07 11:17:05 -05:00
|
|
|
// 7 april 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-04-09 17:17:04 -05:00
|
|
|
typedef struct singleWidget singleWidget;
|
2015-04-07 11:17:05 -05:00
|
|
|
|
2015-04-09 17:17:04 -05:00
|
|
|
struct singleWidget {
|
2015-04-07 11:17:05 -05:00
|
|
|
GtkWidget *widget;
|
|
|
|
GtkWidget *scrolledWindow;
|
|
|
|
GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParent *parent;
|
2015-04-11 13:21:58 -05:00
|
|
|
gboolean userHid;
|
|
|
|
gboolean containerHid;
|
|
|
|
gboolean userDisabled;
|
|
|
|
gboolean containerDisabled;
|
2015-04-07 11:17:05 -05:00
|
|
|
};
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
static void singleDestroy(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-09 17:17:04 -05:00
|
|
|
|
|
|
|
gtk_widget_destroy(s->immediate);
|
2015-04-08 00:16:22 -05:00
|
|
|
}
|
|
|
|
|
2015-04-07 11:17:05 -05:00
|
|
|
static uintptr_t singleHandle(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-09 17:17:04 -05:00
|
|
|
|
|
|
|
return (uintptr_t) (s->widget);
|
2015-04-07 11:17:05 -05:00
|
|
|
}
|
|
|
|
|
2015-04-13 11:05:14 -05:00
|
|
|
static void singleSetParent(uiControl *c, uiParent *parent)
|
2015-04-09 15:21:09 -05:00
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-12 19:08:32 -05:00
|
|
|
uiParent *oldparent;
|
2015-04-09 15:21:09 -05:00
|
|
|
|
|
|
|
oldparent = s->parent;
|
2015-04-14 11:41:25 -05:00
|
|
|
s->parent = parent;
|
|
|
|
if (oldparent != NULL) {
|
|
|
|
gtk_container_remove(GTK_CONTAINER(uiParentHandle(oldparent)), s->immediate);
|
|
|
|
uiParentUpdate(oldparent);
|
|
|
|
}
|
|
|
|
if (s->parent != NULL) {
|
|
|
|
gtk_container_add(GTK_CONTAINER(uiParentHandle(s->parent)), s->immediate);
|
|
|
|
uiParentUpdate(s->parent);
|
|
|
|
}
|
2015-04-09 15:21:09 -05:00
|
|
|
}
|
|
|
|
|
2015-04-09 17:17:04 -05:00
|
|
|
static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
2015-04-07 11:17:05 -05:00
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-07 11:17:05 -05:00
|
|
|
GtkRequisition natural;
|
|
|
|
|
|
|
|
// use the natural size as the minimum size is an *absolute* minimum
|
|
|
|
// for example, if a label has ellipsizing on, it can be the width of the ellipses, not the text
|
|
|
|
// there is a warning about height-for-width sizing, but in my tests this isn't an issue
|
2015-04-09 17:17:04 -05:00
|
|
|
gtk_widget_get_preferred_size(s->widget, NULL, &natural);
|
|
|
|
*width = natural.width;
|
|
|
|
*height = natural.height;
|
2015-04-07 11:17:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-07 11:17:05 -05:00
|
|
|
GtkAllocation a;
|
|
|
|
|
|
|
|
a.x = x;
|
|
|
|
a.y = y;
|
|
|
|
a.width = width;
|
|
|
|
a.height = height;
|
2015-04-09 17:17:04 -05:00
|
|
|
gtk_widget_size_allocate(s->immediate, &a);
|
2015-04-07 11:17:05 -05:00
|
|
|
}
|
|
|
|
|
2015-04-11 13:21:58 -05:00
|
|
|
static int singleVisible(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
if (s->userHid)
|
2015-04-11 13:44:40 -05:00
|
|
|
return 0;
|
|
|
|
return 1;
|
2015-04-11 13:21:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleShow(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->userHid = FALSE;
|
2015-04-11 13:30:07 -05:00
|
|
|
if (!s->containerHid) {
|
2015-04-11 13:21:58 -05:00
|
|
|
gtk_widget_show_all(s->immediate);
|
2015-04-13 11:05:14 -05:00
|
|
|
if (s->parent != NULL)
|
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 13:30:07 -05:00
|
|
|
}
|
2015-04-11 13:21:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleHide(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->userHid = TRUE;
|
|
|
|
gtk_widget_hide(s->immediate);
|
2015-04-13 11:05:14 -05:00
|
|
|
if (s->parent != NULL)
|
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 13:21:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerShow(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->containerHid = FALSE;
|
2015-04-11 13:30:07 -05:00
|
|
|
if (!s->userHid) {
|
2015-04-11 13:21:58 -05:00
|
|
|
gtk_widget_show_all(s->immediate);
|
2015-04-13 11:05:14 -05:00
|
|
|
if (s->parent != NULL)
|
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 13:30:07 -05:00
|
|
|
}
|
2015-04-11 13:21:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerHide(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->containerHid = TRUE;
|
|
|
|
gtk_widget_hide(s->immediate);
|
2015-04-13 11:05:14 -05:00
|
|
|
if (s->parent != NULL)
|
|
|
|
uiParentUpdate(s->parent);
|
2015-04-11 13:21:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
static void singleEnable(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->userDisabled = FALSE;
|
|
|
|
if (!s->containerDisabled)
|
|
|
|
gtk_widget_set_sensitive(s->immediate, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleDisable(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->userDisabled = TRUE;
|
|
|
|
gtk_widget_set_sensitive(s->immediate, FALSE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerEnable(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->containerDisabled = FALSE;
|
|
|
|
if (!s->userDisabled)
|
|
|
|
gtk_widget_set_sensitive(s->immediate, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void singleContainerDisable(uiControl *c)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) (c->Internal);
|
2015-04-11 13:21:58 -05:00
|
|
|
|
|
|
|
s->containerDisabled = TRUE;
|
|
|
|
gtk_widget_set_sensitive(s->immediate, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
static void onDestroy(GtkWidget *widget, gpointer data)
|
|
|
|
{
|
2015-04-15 20:39:50 -05:00
|
|
|
singleWidget *s = (singleWidget *) data;
|
2015-04-08 00:16:22 -05:00
|
|
|
|
2015-04-09 17:17:04 -05:00
|
|
|
uiFree(s);
|
2015-04-08 00:16:22 -05:00
|
|
|
}
|
2015-04-07 11:17:05 -05:00
|
|
|
|
2015-04-15 18:46:24 -05:00
|
|
|
void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, const char *firstProperty, ...)
|
2015-04-07 11:17:05 -05:00
|
|
|
{
|
2015-04-09 17:17:04 -05:00
|
|
|
singleWidget *s;
|
2015-04-07 18:47:44 -05:00
|
|
|
va_list ap;
|
2015-04-07 11:17:05 -05:00
|
|
|
|
2015-04-09 17:17:04 -05:00
|
|
|
s = uiNew(singleWidget);
|
2015-04-07 18:47:44 -05:00
|
|
|
|
|
|
|
va_start(ap, firstProperty);
|
2015-04-09 17:17:04 -05:00
|
|
|
s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap));
|
2015-04-07 18:47:44 -05:00
|
|
|
va_end(ap);
|
2015-04-09 17:17:04 -05:00
|
|
|
s->immediate = s->widget;
|
2015-04-07 11:17:05 -05:00
|
|
|
|
|
|
|
if (inScrolledWindow) {
|
2015-04-09 17:17:04 -05:00
|
|
|
s->scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
|
|
|
|
if (!GTK_IS_SCROLLABLE(s->widget))
|
|
|
|
gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(s->scrolledWindow), s->widget);
|
2015-04-07 11:17:05 -05:00
|
|
|
else
|
2015-04-09 17:17:04 -05:00
|
|
|
gtk_container_add(GTK_CONTAINER(s->scrolledWindow), s->widget);
|
2015-04-07 11:17:05 -05:00
|
|
|
if (scrolledWindowHasBorder)
|
2015-04-09 17:17:04 -05:00
|
|
|
gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(s->scrolledWindow), GTK_SHADOW_IN);
|
|
|
|
s->immediate = s->scrolledWindow;
|
2015-04-07 11:17:05 -05:00
|
|
|
}
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
// we need to keep an extra reference on the immediate widget
|
|
|
|
// this is so uiControlDestroy() can work regardless of when it is called and who calls it
|
|
|
|
// without this:
|
|
|
|
// - end user call works (only one ref)
|
|
|
|
// - call in uiContainer destructor fails (uiContainer ref freed)
|
|
|
|
// with this:
|
|
|
|
// - end user call works (shoudn't be in any container)
|
|
|
|
// - call in uiContainer works (both refs freed)
|
2015-04-09 15:21:09 -05:00
|
|
|
// this also ensures singleRemoveParent() works properly
|
2015-04-09 17:17:04 -05:00
|
|
|
g_object_ref_sink(s->immediate);
|
|
|
|
|
|
|
|
// assign s later; we still need it for one more thing
|
2015-04-15 20:43:20 -05:00
|
|
|
c->Destroy = singleDestroy;
|
|
|
|
c->Handle = singleHandle;
|
|
|
|
c->SetParent = singleSetParent;
|
|
|
|
c->PreferredSize = singlePreferredSize;
|
|
|
|
c->Resize = singleResize;
|
|
|
|
c->Visible = singleVisible;
|
|
|
|
c->Show = singleShow;
|
|
|
|
c->Hide = singleHide;
|
|
|
|
c->ContainerShow = singleContainerShow;
|
|
|
|
c->ContainerHide = singleContainerHide;
|
|
|
|
c->Enable = singleEnable;
|
|
|
|
c->Disable = singleDisable;
|
|
|
|
c->ContainerEnable = singleContainerEnable;
|
|
|
|
c->ContainerDisable = singleContainerDisable;
|
2015-04-09 17:17:04 -05:00
|
|
|
|
|
|
|
// and let's free everything with the immediate widget
|
2015-04-15 20:39:50 -05:00
|
|
|
// we send s as data instead of c just in case c is gone by then
|
|
|
|
g_signal_connect(s->immediate, "destroy", G_CALLBACK(onDestroy), s);
|
2015-04-09 17:17:04 -05:00
|
|
|
|
2015-04-11 23:59:32 -05:00
|
|
|
// finally, call gtk_widget_show_all() here to set the initial visibility of the widget
|
|
|
|
gtk_widget_show_all(s->immediate);
|
|
|
|
|
2015-04-15 20:39:50 -05:00
|
|
|
c->Internal = s;
|
2015-04-07 11:17:05 -05:00
|
|
|
}
|