More GTK+ uiWindow work. Readded the backend's text.c; finally replaced its g_strdup().
This commit is contained in:
parent
f90c15fef1
commit
6a90d8c5c6
|
@ -4,6 +4,7 @@ osCFILES = \
|
||||||
unix/alloc.c \
|
unix/alloc.c \
|
||||||
unix/main.c \
|
unix/main.c \
|
||||||
unix/oscontainer.c \
|
unix/oscontainer.c \
|
||||||
|
unix/text.c \
|
||||||
unix/util.c \
|
unix/util.c \
|
||||||
unix/window.c
|
unix/window.c
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
// 9 april 2015
|
||||||
|
#include "uipriv_unix.h"
|
||||||
|
|
||||||
|
char *strdupText(const char *t)
|
||||||
|
{
|
||||||
|
return g_strdup(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
void uiFreeText(char *t)
|
||||||
|
{
|
||||||
|
g_free(t);
|
||||||
|
}
|
|
@ -10,3 +10,6 @@
|
||||||
|
|
||||||
#define gtkXMargin 12
|
#define gtkXMargin 12
|
||||||
#define gtkYMargin 12
|
#define gtkYMargin 12
|
||||||
|
|
||||||
|
// text.c
|
||||||
|
extern char *strdupText(const char *);
|
||||||
|
|
|
@ -20,6 +20,112 @@ struct window {
|
||||||
int margined;
|
int margined;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) data;
|
||||||
|
|
||||||
|
// manually destroy the window ourselves; don't let the delete-event handler do it
|
||||||
|
if ((*(w->onClosing))(uiWindow(w), w->onClosingData))
|
||||||
|
uiWindowDestroy(uiWindow(w));
|
||||||
|
// don't continue to the default delete-event handler; we destroyed the window by now
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int defaultOnClosing(uiWindow *w, void *data)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowDestroy(uiWindow *ww)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
// first, hide the window to avoid flicker
|
||||||
|
gtk_widget_hide(w->widget);
|
||||||
|
// next, remove the uiOSContainer from the vbox
|
||||||
|
gtk_container_remove(w->vboxcontainer, GTK_WIDGET(uiOSContainerHandle(w->content)));
|
||||||
|
// next, destroy the uiOSContainer, which will destroy its child widget
|
||||||
|
uiOSContainerDestroy(w->content);
|
||||||
|
// TODO menus
|
||||||
|
// next, destroy the GtkWindow itself, which will destroy the vbox, menus, etc.
|
||||||
|
gtk_widget_destroy(w->widget);
|
||||||
|
// finally, free ourselves
|
||||||
|
uiFree(w);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uintptr_t windowHandle(uiWindow *ww)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
return (uintptr_t) (w->widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static char *windowTitle(uiWindow *ww)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
return strdupText(gtk_window_get_title(w->window));
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowSetTitle(uiWindow *ww, const char *title)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
gtk_window_set_title(w->window, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowShow(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 windowHide(uiWindow *ww)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
gtk_widget_hide(w->widget);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
w->onClosing = f;
|
||||||
|
w->onClosingData = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowSetChild(uiWindow *ww, uiControl *c)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
// TODO make the update implicit
|
||||||
|
uiOSContainerSetMainControl(w->content, c);
|
||||||
|
uiOSContainerUpdate(w->content);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int windowMargined(uiWindow *ww)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
return w->margined;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void windowSetMargined(uiWindow *ww, int margined)
|
||||||
|
{
|
||||||
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
|
// TODO make the update implicit
|
||||||
|
w->margined = margined;
|
||||||
|
if (w->margined)
|
||||||
|
uiOSContainerSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
|
||||||
|
else
|
||||||
|
uiOSContainerSetMargins(w->content, 0, 0, 0, 0);
|
||||||
|
uiOSContainerUpdate(w->content);
|
||||||
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubars)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubars)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
@ -44,13 +150,14 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubars)
|
||||||
gtk_widget_set_hexpand(GTK_WIDGET(w->content), TRUE);
|
gtk_widget_set_hexpand(GTK_WIDGET(w->content), TRUE);
|
||||||
gtk_widget_set_halign(GTK_WIDGET(w->content), GTK_ALIGN_FILL);
|
gtk_widget_set_halign(GTK_WIDGET(w->content), GTK_ALIGN_FILL);
|
||||||
gtk_widget_set_vexpand(GTK_WIDGET(w->content), TRUE);
|
gtk_widget_set_vexpand(GTK_WIDGET(w->content), TRUE);
|
||||||
gtk_widget_set_valign(GTK_WIDGET(w->content), GTK_ALL_FILL);
|
gtk_widget_set_valign(GTK_WIDGET(w->content), GTK_ALIGN_FILL);
|
||||||
|
|
||||||
// show everything in the vbox, but not the GtkWindow itself
|
// show everything in the vbox, but not the GtkWindow itself
|
||||||
gtk_widget_show_all(w->vboxwidget);
|
gtk_widget_show_all(w->vboxwidget);
|
||||||
|
|
||||||
// and connect our OnClosing() event
|
// and connect our OnClosing() event
|
||||||
g_signal_connect(w->TODO
|
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
||||||
|
w->onClosing = defaultOnClosing;
|
||||||
|
|
||||||
uiWindow(w)->Destroy = windowDestroy;
|
uiWindow(w)->Destroy = windowDestroy;
|
||||||
uiWindow(w)->Handle = windowHandle;
|
uiWindow(w)->Handle = windowHandle;
|
||||||
|
|
|
@ -1,170 +0,0 @@
|
||||||
// 6 april 2015
|
|
||||||
#include "uipriv_unix.h"
|
|
||||||
|
|
||||||
struct window {
|
|
||||||
uiWindow w;
|
|
||||||
GtkWidget *widget;
|
|
||||||
GtkContainer *container;
|
|
||||||
GtkWindow *window;
|
|
||||||
uiOSContainer *content;
|
|
||||||
int (*onClosing)(uiWindow *, void *);
|
|
||||||
void *onClosingData;
|
|
||||||
int margined;
|
|
||||||
gulong destroyBlocker;
|
|
||||||
};
|
|
||||||
|
|
||||||
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) data;
|
|
||||||
|
|
||||||
// manually destroy the window ourselves; don't let the delete-event handler do it
|
|
||||||
if ((*(w->onClosing))(uiWindow(w), w->onClosingData))
|
|
||||||
uiWindowDestroy(uiWindow(w));
|
|
||||||
return TRUE; // don't continue to the default delete-event handler; we destroyed the window by now
|
|
||||||
}
|
|
||||||
|
|
||||||
static int defaultOnClosing(uiWindow *w, void *data)
|
|
||||||
{
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO should we change the GtkWindow's child first?
|
|
||||||
static void windowDestroy(uiWindow *ww)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
// first, hide the window to prevent our cleanup from being noticed
|
|
||||||
gtk_widget_hide(w->widget);
|
|
||||||
// next, remove the uiOSContainer from the GtkWindow so the GtkWindow can release its reference on the uiOSContainer
|
|
||||||
gtk_container_remove(w->container, GTK_WIDGET(uiOSContainerHandle(w->content)));
|
|
||||||
// next, destroy the content uiOSContainer
|
|
||||||
// this will destroy any children
|
|
||||||
uiOSContainerDestroy(w->content);
|
|
||||||
// now that we cleaned up properly, we can mark our window as ready to be destroyed
|
|
||||||
//TODO g_signal_handler_disconnect(w->widget, w->destroyBlocker);
|
|
||||||
// finally, destroy the window
|
|
||||||
gtk_widget_destroy(w->widget);
|
|
||||||
// and free ourselves
|
|
||||||
uiFree(w);
|
|
||||||
}
|
|
||||||
|
|
||||||
static uintptr_t windowHandle(uiWindow *ww)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
return (uintptr_t) (w->widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *windowTitle(uiWindow *ww)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
return g_strdup(gtk_window_get_title(w->window));
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowSetTitle(uiWindow *ww, const char *title)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
gtk_window_set_title(w->window, title);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowShow(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 windowHide(uiWindow *ww)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
gtk_widget_hide(w->widget);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
w->onClosing = f;
|
|
||||||
w->onClosingData = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowSetChild(uiWindow *ww, uiControl *c)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
uiOSContainerSetMainControl(w->content, c);
|
|
||||||
uiOSContainerUpdate(w->content);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int windowMargined(uiWindow *ww)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
return w->margined;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowSetMargined(uiWindow *ww, int margined)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) ww;
|
|
||||||
|
|
||||||
w->margined = margined;
|
|
||||||
if (w->margined)
|
|
||||||
uiOSContainerSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
|
|
||||||
else
|
|
||||||
uiOSContainerSetMargins(w->content, 0, 0, 0, 0);
|
|
||||||
uiOSContainerUpdate(w->content);
|
|
||||||
}
|
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
|
||||||
{
|
|
||||||
struct window *w;
|
|
||||||
GtkWidget *vbox;
|
|
||||||
GtkWidget *contentWidget;
|
|
||||||
|
|
||||||
w = uiNew(struct window);
|
|
||||||
|
|
||||||
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
||||||
w->container = GTK_CONTAINER(w->widget);
|
|
||||||
w->window = GTK_WINDOW(w->widget);
|
|
||||||
|
|
||||||
gtk_window_set_title(w->window, title);
|
|
||||||
// TODO this does not take menus or CSD into account
|
|
||||||
gtk_window_resize(w->window, width, height);
|
|
||||||
|
|
||||||
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
|
||||||
//TODO w->destroyBlocker = g_signal_connect(w->widget, "destroy", G_CALLBACK(destroyBlocker), w);
|
|
||||||
|
|
||||||
if (hasMenubar) {
|
|
||||||
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
||||||
gtk_widget_show_all(vbox);
|
|
||||||
gtk_container_add(w->container, vbox);
|
|
||||||
|
|
||||||
//TODO gtk_container_add(GTK_CONTAINER(vbox), makeMenubar());
|
|
||||||
|
|
||||||
w->content = uiNewOSContainer((uintptr_t) GTK_CONTAINER(vbox));
|
|
||||||
contentWidget = GTK_WIDGET(uiOSContainerHandle(w->content));
|
|
||||||
gtk_widget_set_hexpand(contentWidget, TRUE);
|
|
||||||
gtk_widget_set_halign(contentWidget, GTK_ALIGN_FILL);
|
|
||||||
gtk_widget_set_vexpand(contentWidget, TRUE);
|
|
||||||
gtk_widget_set_valign(contentWidget, GTK_ALIGN_FILL);
|
|
||||||
} else
|
|
||||||
w->content = uiNewOSContainer((uintptr_t) (w->container));
|
|
||||||
|
|
||||||
w->onClosing = defaultOnClosing;
|
|
||||||
|
|
||||||
uiWindow(w)->Destroy = windowDestroy;
|
|
||||||
uiWindow(w)->Handle = windowHandle;
|
|
||||||
uiWindow(w)->Title = windowTitle;
|
|
||||||
uiWindow(w)->SetTitle = windowSetTitle;
|
|
||||||
uiWindow(w)->Show = windowShow;
|
|
||||||
uiWindow(w)->Hide = windowHide;
|
|
||||||
uiWindow(w)->OnClosing = windowOnClosing;
|
|
||||||
uiWindow(w)->SetChild = windowSetChild;
|
|
||||||
uiWindow(w)->Margined = windowMargined;
|
|
||||||
uiWindow(w)->SetMargined = windowSetMargined;
|
|
||||||
|
|
||||||
return uiWindow(w);
|
|
||||||
}
|
|
Loading…
Reference in New Issue