summaryrefslogtreecommitdiff
path: root/new/unix/window.c
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-15 18:49:45 -0400
committerPietro Gagliardi <[email protected]>2015-04-15 18:49:45 -0400
commit518a5ddbf15d50a254c732a80d5907ef8878abe0 (patch)
tree48cf259f98994e4570e65c389fcd9824272884ad /new/unix/window.c
parent50ae3ca045e7f5f5744043df0a4506e2f6930bb1 (diff)
Split all OS backends into their own folders.
Diffstat (limited to 'new/unix/window.c')
-rw-r--r--new/unix/window.c105
1 files changed, 105 insertions, 0 deletions
diff --git a/new/unix/window.c b/new/unix/window.c
new file mode 100644
index 0000000..e3fe6f3
--- /dev/null
+++ b/new/unix/window.c
@@ -0,0 +1,105 @@
+// 6 april 2015
+#include "uipriv_unix.h"
+
+struct uiWindow {
+ GtkWidget *widget;
+ uiParent *content;
+ int (*onClosing)(uiWindow *, void *);
+ void *onClosingData;
+ int margined;
+};
+
+static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
+{
+ uiWindow *w = (uiWindow *) data;
+
+ // return exact values just in case
+ if ((*(w->onClosing))(w, w->onClosingData))
+ return FALSE;
+ return TRUE;
+}
+
+static int defaultOnClosing(uiWindow *w, void *data)
+{
+ return 1;
+}
+
+static void onDestroy(GtkWidget *widget, gpointer data)
+{
+ uiWindow *w = (uiWindow *) data;
+
+ uiFree(w);
+}
+
+uiWindow *uiNewWindow(char *title, int width, int height)
+{
+ uiWindow *w;
+
+ w = uiNew(uiWindow);
+ 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;
+ return w;
+}
+
+void uiWindowDestroy(uiWindow *w)
+{
+ gtk_widget_destroy(w->widget);
+}
+
+uintptr_t uiWindowHandle(uiWindow *w)
+{
+ return (uintptr_t) (w->widget);
+}
+
+char *uiWindowTitle(uiWindow *w)
+{
+ return g_strdup(gtk_window_get_title(GTK_WINDOW(w->widget)));
+}
+
+void uiWindowSetTitle(uiWindow *w, const char *title)
+{
+ gtk_window_set_title(GTK_WINDOW(w->widget), title);
+}
+
+void uiWindowShow(uiWindow *w)
+{
+ // don't use gtk_widget_show_all(); that will override user hidden settings
+ gtk_widget_show(w->widget);
+}
+
+void uiWindowHide(uiWindow *w)
+{
+ gtk_widget_hide(w->widget);
+}
+
+void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
+{
+ w->onClosing = f;
+ w->onClosingData = data;
+}
+
+void uiWindowSetChild(uiWindow *w, uiControl *c)
+{
+ uiParentSetChild(w->content, c);
+ uiParentUpdate(w->content);
+}
+
+int uiWindowMargined(uiWindow *w)
+{
+ return w->margined;
+}
+
+void uiWindowSetMargined(uiWindow *w, int margined)
+{
+ w->margined = margined;
+ if (w->margined)
+ uiParentSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
+ else
+ uiParentSetMargins(w->content, 0, 0, 0, 0);
+ uiParentUpdate(w->content);
+}