diff options
Diffstat (limited to 'new/unix')
| -rw-r--r-- | new/unix/GNUmakeinc.mk | 18 | ||||
| -rw-r--r-- | new/unix/alloc.c | 33 | ||||
| -rw-r--r-- | new/unix/button.c | 71 | ||||
| -rw-r--r-- | new/unix/checkbox.c | 95 | ||||
| -rw-r--r-- | new/unix/entry.c | 45 | ||||
| -rw-r--r-- | new/unix/init.c | 23 | ||||
| -rw-r--r-- | new/unix/label.c | 49 | ||||
| -rw-r--r-- | new/unix/main.c | 23 | ||||
| -rw-r--r-- | new/unix/newcontrol.c | 225 | ||||
| -rw-r--r-- | new/unix/parent.c | 183 | ||||
| -rw-r--r-- | new/unix/tab.c | 61 | ||||
| -rw-r--r-- | new/unix/uipriv_unix.h | 14 | ||||
| -rw-r--r-- | new/unix/util.c | 7 | ||||
| -rw-r--r-- | new/unix/window.c | 137 |
14 files changed, 0 insertions, 984 deletions
diff --git a/new/unix/GNUmakeinc.mk b/new/unix/GNUmakeinc.mk deleted file mode 100644 index 4f707b3..0000000 --- a/new/unix/GNUmakeinc.mk +++ /dev/null @@ -1,18 +0,0 @@ -OSCFILES = \ - alloc.c \ - button.c \ - checkbox.c \ - entry.c \ - init.c \ - label.c \ - main.c \ - newcontrol.c \ - parent.c \ - tab.c \ - util.c \ - window.c - -xCFLAGS += `pkg-config --cflags gtk+-3.0` -xLDFLAGS += `pkg-config --libs gtk+-3.0` - -OUT = new diff --git a/new/unix/alloc.c b/new/unix/alloc.c deleted file mode 100644 index 33482b2..0000000 --- a/new/unix/alloc.c +++ /dev/null @@ -1,33 +0,0 @@ -// 7 april 2015 -#include <stdio.h> -#include "uipriv_unix.h" - -void *uiAlloc(size_t size, const char *type) -{ - void *out; - - out = g_malloc0(size); - if (options.debugLogAllocations) - fprintf(stderr, "%p alloc %s\n", out, type); - return out; -} - -void *uiRealloc(void *p, size_t size, const char *type) -{ - void *out; - - if (p == NULL) - return uiAlloc(size, type); - // TODO fill with 0s - out = g_realloc(p, size); - if (options.debugLogAllocations) - fprintf(stderr, "%p realloc %p\n", p, out); - return out; -} - -void uiFree(void *p) -{ - g_free(p); - if (options.debugLogAllocations) - fprintf(stderr, "%p free\n", p); -} diff --git a/new/unix/button.c b/new/unix/button.c deleted file mode 100644 index 404d7a8..0000000 --- a/new/unix/button.c +++ /dev/null @@ -1,71 +0,0 @@ -// 7 april 2015 -#include "uipriv_unix.h" - -struct button { - uiButton b; - void (*onClicked)(uiButton *, void *); - void *onClickedData; -}; - -static void clicked(GtkButton *button, gpointer data) -{ - struct button *b = (struct button *) data; - - (*(b->onClicked))(uiButton(b), b->onClickedData); -} - -static void defaultOnClicked(uiButton *b, void *data) -{ - // do nothing -} - -static void destroy(GtkWidget *widget, gpointer data) -{ - struct button *b = (struct button *) data; - - uiFree(b); -} - -#define BUTTON(b) GTK_BUTTON(widget(b)) - -static char *buttonText(uiButton *bb) -{ - return g_strdup(gtk_button_get_label(BUTTON(bb))); -} - -static void buttonSetText(uiButton *bb, const char *text) -{ - gtk_button_set_label(BUTTON(bb), 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; - GtkWidget *widget; - - b = uiNew(struct button); - - uiUnixNewControl(uiControl(b), GTK_TYPE_BUTTON, - FALSE, FALSE, - "label", text, - NULL); - - widget = WIDGET(b); - g_signal_connect(widget, "clicked", G_CALLBACK(clicked), b); - g_signal_connect(widget, "destroy", G_CALLBACK(destroy), b); - b->onClicked = defaultOnClicked; - - uiButton(b)->Text = buttonText; - uiButton(b)->SetText = buttonSetText; - uiButton(b)->OnClicked = buttonOnClicked; - - return uiButton(b); -} diff --git a/new/unix/checkbox.c b/new/unix/checkbox.c deleted file mode 100644 index f3563a1..0000000 --- a/new/unix/checkbox.c +++ /dev/null @@ -1,95 +0,0 @@ -// 7 april 2015 -#include "uipriv_unix.h" - -struct checkbox { - uiCheckbox c; - void (*onToggled)(uiCheckbox *, void *); - void *onToggledData; - gulong onToggledSignal; -}; - -static void onToggled(GtkToggleButton *b, gpointer data) -{ - struct checkbox *c = (struct checkbox *) data; - - (*(c->onToggled))(uiCheckbox(c), c->onToggledData); -} - -static void defaultOnToggled(uiCheckbox *c, void *data) -{ - // do nothing -} - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - struct checkbox *c = (struct checkbox *) data; - - uiFree(c); -} - -#define CHECKBOX(c) GTK_CHECK_BUTTON(uiControlHandle(uiControl(c))) - -static char *getText(uiCheckbox *c) -{ - return g_strdup(gtk_button_get_label(GTK_BUTTON(CHECKBOX(c)))); -} - -static void setText(uiCheckbox *c, const char *text) -{ - gtk_button_set_label(GTK_BUTTON(CHECKBOX(c)), text); -} - -static void setOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data) -{ - struct checkbox *c = (struct checkbox *) cc; - - c->onToggled = f; - c->onToggledData = data; -} - -static int getChecked(uiCheckbox *c) -{ - return gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(CHECKBOX(c))) != FALSE; -} - -static void setChecked(uiCheckbox *cc, int checked) -{ - struct checkbox *c = (struct checkbox *) cc; - GtkToggleButton *button; - gboolean active; - - active = FALSE; - if (checked) - active = TRUE; - // we need to inhibit sending of ::toggled because this WILL send a ::toggled otherwise - button = GTK_TOGGLE_BUTTON(CHECKBOX(c)); - g_signal_handler_block(button, c->onToggledSignal); - gtk_toggle_button_set_active(button, active); - g_signal_handler_unblock(button, c->onToggledSignal); -} - -uiCheckbox *uiNewCheckbox(const char *text) -{ - struct checkbox *c; - GtkWidget *widget; - - c = uiNew(struct checkbox); - - uiUnixNewControl(uiControl(c), GTK_TYPE_CHECK_BUTTON, - FALSE, FALSE, - "label", text, - NULL); - - widget = GTK_WIDGET(CHECKBOX(c)); - g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), c); - c->onToggledSignal = g_signal_connect(widget, "toggled", G_CALLBACK(onToggled), c); - c->onToggled = defaultOnToggled; - - uiCheckbox(c)->Text = getText; - uiCheckbox(c)->SetText = setText; - uiCheckbox(c)->OnToggled = setOnToggled; - uiCheckbox(c)->Checked = getChecked; - uiCheckbox(c)->SetChecked = setChecked; - - return uiCheckbox(c); -} diff --git a/new/unix/entry.c b/new/unix/entry.c deleted file mode 100644 index 4731f68..0000000 --- a/new/unix/entry.c +++ /dev/null @@ -1,45 +0,0 @@ -// 8 april 2015 -#include "uipriv_unix.h" - -struct entry { - uiEntry e; -}; - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - struct entry *e = (struct entry *) data; - - uiFree(e); -} - -#define ENTRY(e) GTK_ENTRY(uiControlHandle(uiControl(e))) - -static char *getText(uiEntry *e) -{ - return g_strdup(gtk_entry_get_text(ENTRY(e))); -} - -static void setText(uiEntry *e, const char *text) -{ - gtk_entry_set_text(ENTRY(e), text); -} - -uiEntry *uiNewEntry(void) -{ - struct entry *e; - GtkWidget *widget; - - e = uiNew(struct entry); - - uiUnixNewControl(uiControl(e), GTK_TYPE_ENTRY, - FALSE, FALSE, - NULL); - - widget = GTK_WIDGET(ENTRY(e)); - g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), e); - - uiEntry(e)->Text = getText; - uiEntry(e)->SetText = setText; - - return uiEntry(e); -} diff --git a/new/unix/init.c b/new/unix/init.c deleted file mode 100644 index b10c05b..0000000 --- a/new/unix/init.c +++ /dev/null @@ -1,23 +0,0 @@ -// 6 april 2015 -#include "uipriv_unix.h" - -uiInitOptions options; - -const char *uiInit(uiInitOptions *o) -{ - GError *err = NULL; - const char *msg; - - options = *o; - if (gtk_init_with_args(NULL, NULL, NULL, NULL, NULL, &err) == FALSE) { - msg = g_strdup(err->message); - g_error_free(err); - return msg; - } - return NULL; -} - -void uiFreeInitError(const char *err) -{ - g_free((gpointer) err); -} diff --git a/new/unix/label.c b/new/unix/label.c deleted file mode 100644 index 1a7aa28..0000000 --- a/new/unix/label.c +++ /dev/null @@ -1,49 +0,0 @@ -// 11 april 2015 -#include "uipriv_unix.h" - -struct label { - uiLabel l; -}; - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - struct label *l = (struct label *) data; - - uiFree(l); -} - -#define LABEL(l) GTK_LABEL(uiControlHandle(uiControl(l))) - -static char *getText(uiLabel *l) -{ - // TODO change g_strdup() to a wrapper function for export in ui_unix.h - return g_strdup(gtk_label_get_text(LABEL(l))); -} - -static void setText(uiLabel *l, const char *text) -{ - gtk_label_set_text(LABEL(l), text); -} - -uiLabel *uiNewLabel(const char *text) -{ - struct label *l; - GtkWidget *widget; - - l = uiNew(struct label); - - uiUnixNewControl(uiControl(l), GTK_TYPE_LABEL, - FALSE, FALSE, - "label", text, - "xalign", 0.0, // note: must be a float constant, otherwise the ... will turn it into an int and we get segfaults on some platforms (thanks ebassi in irc.gimp.net/#gtk+) - // TODO yalign 0? - NULL); - - widget = GTK_WIDGET(LABEL(l)); - g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), l); - - uiLabel(l)->Text = getText; - uiLabel(l)->SetText = setText; - - return uiLabel(l); -} diff --git a/new/unix/main.c b/new/unix/main.c deleted file mode 100644 index 10af782..0000000 --- a/new/unix/main.c +++ /dev/null @@ -1,23 +0,0 @@ -// 6 april 2015 -#include "uipriv_unix.h" - -// #qo pkg-config: gtk+-3.0 - -void uiMain(void) -{ - gtk_main(); -} - -// gtk_main_quit() may run immediately, or it may wait for other pending events; "it depends" (thanks mclasen in irc.gimp.net/#gtk+) -// PostQuitMessage() on Windows always waits, so we must do so too -// we'll do it by using an idle callback -static gboolean quit(gpointer data) -{ - gtk_main_quit(); - return FALSE; -} - -void uiQuit(void) -{ - gdk_threads_add_idle(quit, NULL); -} diff --git a/new/unix/newcontrol.c b/new/unix/newcontrol.c deleted file mode 100644 index d23e190..0000000 --- a/new/unix/newcontrol.c +++ /dev/null @@ -1,225 +0,0 @@ -// 7 april 2015 -#include "uipriv_unix.h" - -typedef struct singleWidget singleWidget; - -struct singleWidget { - GtkWidget *widget; - GtkWidget *scrolledWindow; - GtkWidget *immediate; // the widget that is added to the parent container; either widget or scrolledWindow - uiParent *parent; - gboolean userHid; - gboolean containerHid; - gboolean userDisabled; - gboolean containerDisabled; -}; - -static void singleDestroy(uiControl *c) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - gtk_widget_destroy(s->immediate); -} - -static uintptr_t singleHandle(uiControl *c) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - return (uintptr_t) (s->widget); -} - -static void singleSetParent(uiControl *c, uiParent *parent) -{ - singleWidget *s = (singleWidget *) (c->Internal); - uiParent *oldparent; - - oldparent = s->parent; - 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); - } -} - -static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) -{ - singleWidget *s = (singleWidget *) (c->Internal); - 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 - gtk_widget_get_preferred_size(s->widget, NULL, &natural); - *width = natural.width; - *height = natural.height; -} - -static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) -{ - singleWidget *s = (singleWidget *) (c->Internal); - GtkAllocation a; - - a.x = x; - a.y = y; - a.width = width; - a.height = height; - gtk_widget_size_allocate(s->immediate, &a); -} - -static int singleVisible(uiControl *c) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - if (s->userHid) - return 0; - return 1; -} - -static void singleShow(uiControl *c) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - s->userHid = FALSE; - if (!s->containerHid) { - gtk_widget_show_all(s->immediate); - if (s->parent != NULL) - uiParentUpdate(s->parent); - } -} - -static void singleHide(uiControl *c) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - s->userHid = TRUE; - gtk_widget_hide(s->immediate); - if (s->parent != NULL) - uiParentUpdate(s->parent); -} - -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) -{ - singleWidget *s = (singleWidget *) (c->Internal); - - s->userDisabled = FALSE; - if (!s->containerDisabled) - gtk_widget_set_sensitive(s->immediate, TRUE); -} - -static void singleDisable(uiControl *c) -{ - 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); -} - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - singleWidget *s = (singleWidget *) data; - - uiFree(s); -} - -void uiUnixNewControl(uiControl *c, GType type, gboolean inScrolledWindow, gboolean scrolledWindowHasBorder, const char *firstProperty, ...) -{ - singleWidget *s; - va_list ap; - - s = uiNew(singleWidget); - - va_start(ap, firstProperty); - s->widget = GTK_WIDGET(g_object_new_valist(type, firstProperty, ap)); - va_end(ap); - s->immediate = s->widget; - - if (inScrolledWindow) { - 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); - else - gtk_container_add(GTK_CONTAINER(s->scrolledWindow), s->widget); - if (scrolledWindowHasBorder) - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(s->scrolledWindow), GTK_SHADOW_IN); - s->immediate = s->scrolledWindow; - } - - // 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) - // this also ensures singleRemoveParent() works properly - g_object_ref_sink(s->immediate); - - // assign s later; we still need it for one more thing - 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; - - // and let's free everything with the immediate widget - // 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); - - // finally, call gtk_widget_show_all() here to set the initial visibility of the widget - gtk_widget_show_all(s->immediate); - - c->Internal = s; -} diff --git a/new/unix/parent.c b/new/unix/parent.c deleted file mode 100644 index 54d5d06..0000000 --- a/new/unix/parent.c +++ /dev/null @@ -1,183 +0,0 @@ -// 13 august 2014 -#include "uipriv_unix.h" - -#define uipParentType (uipParent_get_type()) -#define uipParent(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), uipParentType, uipParent)) -#define uipIsParent(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), uipParentType)) -#define uipParentClass(class) (G_TYPE_CHECK_CLASS_CAST((class), uipParentType, uipParentClass)) -#define uipIsParentClass(class) (G_TYPE_CHECK_CLASS_TYPE((class), uipParent)) -#define uipGetParentClass(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), uipParentType, uipParentClass)) - -typedef struct uipParent uipParent; -typedef struct uipParentClass uipParentClass; - -struct uipParent { - GtkContainer parent_instance; - // this is what triggers the resizing of all the children - uiControl *child; - // these are the actual children widgets of the container as far as GTK+ is concerned - GPtrArray *children; // for forall() - intmax_t marginLeft; - intmax_t marginTop; - intmax_t marginRight; - intmax_t marginBottom; -}; - -struct uipParentClass { - GtkContainerClass parent_class; -}; - -G_DEFINE_TYPE(uipParent, uipParent, GTK_TYPE_CONTAINER) - -static void uipParent_init(uipParent *p) -{ - if (options.debugLogAllocations) - fprintf(stderr, "%p alloc uipParent\n", p); - p->children = g_ptr_array_new(); - gtk_widget_set_has_window(GTK_WIDGET(p), FALSE); -} - -// instead of having GtkContainer itself unref all our controls, we'll run our own uiControlDestroy() functions for child, which will do that and more -// we still chain up because we need to, but by that point there will be no children for GtkContainer to free -static void uipParent_dispose(GObject *obj) -{ - uipParent *p = uipParent(obj); - - if (p->children != NULL) { - g_ptr_array_unref(p->children); - p->children = NULL; - } - if (p->child != NULL) { - uiControlDestroy(p->child); - p->child = NULL; - } - G_OBJECT_CLASS(uipParent_parent_class)->dispose(obj); -} - -static void uipParent_finalize(GObject *obj) -{ - G_OBJECT_CLASS(uipParent_parent_class)->finalize(obj); - if (options.debugLogAllocations) - fprintf(stderr, "%p free\n", obj); -} - -static void uipParent_add(GtkContainer *container, GtkWidget *widget) -{ - uipParent *p = uipParent(container); - - gtk_widget_set_parent(widget, GTK_WIDGET(p)); - if (p->children != NULL) - g_ptr_array_add(p->children, widget); -} - -static void uipParent_remove(GtkContainer *container, GtkWidget *widget) -{ - uipParent *p = uipParent(container); - - gtk_widget_unparent(widget); - if (p->children != NULL) - g_ptr_array_remove(p->children, widget); -} - -#define gtkXPadding 12 -#define gtkYPadding 6 - -static void uipParent_size_allocate(GtkWidget *widget, GtkAllocation *allocation) -{ - uipParent *p = uipParent(widget); - uiSizing d; - intmax_t x, y, width, height; - - gtk_widget_set_allocation(GTK_WIDGET(p), allocation); - if (p->child == NULL) - return; - x = allocation->x + p->marginLeft; - y = allocation->y + p->marginTop; - width = allocation->width - (p->marginLeft + p->marginRight); - height = allocation->height - (p->marginTop + p->marginBottom); - d.xPadding = gtkXPadding; - d.yPadding = gtkYPadding; - uiControlResize(p->child, x, y, width, height, &d); -} - -struct forall { - GtkCallback callback; - gpointer data; -}; - -static void doforall(gpointer obj, gpointer data) -{ - struct forall *s = (struct forall *) data; - - (*(s->callback))(GTK_WIDGET(obj), s->data); -} - -static void uipParent_forall(GtkContainer *container, gboolean includeInternals, GtkCallback callback, gpointer data) -{ - uipParent *p = uipParent(container); - struct forall s; - - s.callback = callback; - s.data = data; - if (p->children != NULL) - g_ptr_array_foreach(p->children, doforall, &s); -} - -static void uipParent_class_init(uipParentClass *class) -{ - G_OBJECT_CLASS(class)->dispose = uipParent_dispose; - G_OBJECT_CLASS(class)->finalize = uipParent_finalize; - GTK_WIDGET_CLASS(class)->size_allocate = uipParent_size_allocate; - GTK_CONTAINER_CLASS(class)->add = uipParent_add; - GTK_CONTAINER_CLASS(class)->remove = uipParent_remove; - GTK_CONTAINER_CLASS(class)->forall = uipParent_forall; -} - -static uintptr_t parentHandle(uiParent *p) -{ - uipParent *pp = uipParent(p->Internal); - - return (uintptr_t) pp; -} - -static void parentSetChild(uiParent *p, uiControl *child) -{ - uipParent *pp = uipParent(p->Internal); - - pp->child = child; - if (pp->child != NULL) - uiControlSetParent(child, p); -} - -static void parentSetMargins(uiParent *p, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom) -{ - uipParent *pp = uipParent(p->Internal); - - pp->marginLeft = left; - pp->marginTop = top; - pp->marginRight = right; - pp->marginBottom = bottom; -} - -static void parentUpdate(uiParent *p) -{ - uipParent *pp = uipParent(p->Internal); - - gtk_widget_queue_resize(GTK_WIDGET(pp)); -} - -uiParent *uiNewParent(uintptr_t osParent) -{ - uiParent *p; - - p = uiNew(uiParent); - p->Internal = g_object_new(uipParentType, NULL); - p->Handle = parentHandle; - p->SetChild = parentSetChild; - p->SetMargins = parentSetMargins; - p->Update = parentUpdate; - gtk_container_add(GTK_CONTAINER(osParent), GTK_WIDGET(p->Internal)); - // and make it visible by default - gtk_widget_show_all(GTK_WIDGET(p->Internal)); - return p; -} diff --git a/new/unix/tab.c b/new/unix/tab.c deleted file mode 100644 index bb168f5..0000000 --- a/new/unix/tab.c +++ /dev/null @@ -1,61 +0,0 @@ -// 12 april 2015 -#include "uipriv_unix.h" - -struct tab { - uiTab t; - uiParent **pages; - uintmax_t len; - uintmax_t cap; -}; - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - struct tab *t = (struct tab *) data; - - uiFree(t->pages); - uiFree(t); -} - -#define TAB(t) GTK_NOTEBOOK(uiControlHandle(uiControl(t))) - -#define tabCapGrow 32 - -static void addPage(uiTab *tt, const char *name, uiControl *child) -{ - struct tab *t = (struct tab *) tt; - GtkWidget *notebook; - uiParent *content; - - if (t->len >= t->cap) { - t->cap += tabCapGrow; - t->pages = (uiParent **) uiRealloc(t->pages, t->cap * sizeof (uiParent *), "uiParent *[]"); - } - - notebook = GTK_WIDGET(TAB(t)); - content = uiNewParent((uintptr_t) notebook); - uiParentSetChild(content, child); - uiParentUpdate(content); - gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(notebook), GTK_WIDGET(uiParentHandle(content)), name); - - t->pages[t->len] = content; - t->len++; -} - -uiTab *uiNewTab(void) -{ - struct tab *t; - GtkWidget *widget; - - t = uiNew(struct tab); - - uiUnixNewControl(uiControl(t), GTK_TYPE_NOTEBOOK, - FALSE, FALSE, - NULL); - - widget = GTK_WIDGET(TAB(t)); - g_signal_connect(widget, "destroy", G_CALLBACK(onDestroy), t); - - uiTab(t)->AddPage = addPage; - - return uiTab(t); -} diff --git a/new/unix/uipriv_unix.h b/new/unix/uipriv_unix.h deleted file mode 100644 index 0f460cb..0000000 --- a/new/unix/uipriv_unix.h +++ /dev/null @@ -1,14 +0,0 @@ -// 6 april 2015 -#define GLIB_VERSION_MIN_REQUIRED GLIB_VERSION_2_32 -#define GLIB_VERSION_MAX_ALLOWED GLIB_VERSION_2_32 -#define GDK_VERSION_MIN_REQUIRED GDK_VERSION_3_4 -#define GDK_VERSION_MAX_ALLOWED GDK_VERSION_3_4 -#include <gtk/gtk.h> -#include "../uipriv.h" -#include "../ui_unix.h" - -#define gtkXMargin 12 -#define gtkYMargin 12 - -#define widget(c) uiControlHandle(uiControl(c)) -#define WIDGET(c) GTK_WIDGET(widget(c)) diff --git a/new/unix/util.c b/new/unix/util.c deleted file mode 100644 index 72b71df..0000000 --- a/new/unix/util.c +++ /dev/null @@ -1,7 +0,0 @@ -// 9 april 2015 -#include "uipriv_unix.h" - -void uiFreeText(char *t) -{ - g_free(t); -} diff --git a/new/unix/window.c b/new/unix/window.c deleted file mode 100644 index 039feb7..0000000 --- a/new/unix/window.c +++ /dev/null @@ -1,137 +0,0 @@ -// 6 april 2015 -#include "uipriv_unix.h" - -struct window { - uiWindow w; - GtkWidget *widget; - uiParent *content; - int (*onClosing)(uiWindow *, void *); - void *onClosingData; - int margined; -}; - -static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data) -{ - struct window *w = (struct window *) data; - - // return exact values just in case - if ((*(w->onClosing))(uiWindow(w), w->onClosingData)) - return FALSE; - return TRUE; -} - -static int defaultOnClosing(uiWindow *w, void *data) -{ - return 1; -} - -static void onDestroy(GtkWidget *widget, gpointer data) -{ - struct window *w = (struct window *) data; - - uiFree(w); -} - -static void windowDestroy(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - gtk_widget_destroy(w->widget); -} - -static uintptr_t handle(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - return (uintptr_t) (w->widget); -} - -static char *getTitle(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - return g_strdup(gtk_window_get_title(GTK_WINDOW(w->widget))); -} - -static void setTitle(uiWindow *ww, const char *title) -{ - struct window *w = (struct window *) ww; - - gtk_window_set_title(GTK_WINDOW(w->widget), title); -} - -static void show(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - // don't use gtk_widget_show_all(); that will override user hidden settings - gtk_widget_show(w->widget); -} - -static void hide(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - gtk_widget_hide(w->widget); -} - -static void setOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data) -{ - struct window *w = (struct window *) ww; - - w->onClosing = f; - w->onClosingData = data; -} - -static void setChild(uiWindow *ww, uiControl *c) -{ - struct window *w = (struct window *) ww; - - uiParentSetChild(w->content, c); - uiParentUpdate(w->content); -} - -static int margined(uiWindow *ww) -{ - struct window *w = (struct window *) ww; - - return w->margined; -} - -static void setMargined(uiWindow *ww, int margined) -{ - struct window *w = (struct window *) ww; - - w->margined = margined; - if (w->margined) - uiParentSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin); - else - uiParentSetMargins(w->content, 0, 0, 0, 0); - uiParentUpdate(w->content); -} - -uiWindow *uiNewWindow(const char *title, int width, int height) -{ - struct window *w; - - w = uiNew(struct window); - w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW(w->widget), title); - gtk_window_resize(GTK_WINDOW(w->widget), width, height); - g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w); - g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w); - w->content = uiNewParent((uintptr_t) (w->widget)); - w->onClosing = defaultOnClosing; - - uiWindow(w)->Destroy = windowDestroy; - uiWindow(w)->Handle = handle; - uiWindow(w)->Title = getTitle; - uiWindow(w)->SetTitle = setTitle; - uiWindow(w)->Show = show; - uiWindow(w)->Hide = hide; - uiWindow(w)->OnClosing = setOnClosing; - uiWindow(w)->SetChild = setChild; - uiWindow(w)->Margined = margined; - uiWindow(w)->SetMargined = setMargined; - - return uiWindow(w); -} |
