2015-04-06 11:20:51 -05:00
|
|
|
// 6 april 2015
|
2015-04-06 23:26:27 -05:00
|
|
|
#include "uipriv_unix.h"
|
2015-04-06 11:20:51 -05:00
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window {
|
|
|
|
uiWindow w;
|
2015-04-06 11:20:51 -05:00
|
|
|
GtkWidget *widget;
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParent *content;
|
2015-04-06 11:20:51 -05:00
|
|
|
int (*onClosing)(uiWindow *, void *);
|
|
|
|
void *onClosingData;
|
2015-04-13 11:05:14 -05:00
|
|
|
int margined;
|
2015-04-06 11:20:51 -05:00
|
|
|
};
|
|
|
|
|
2015-04-10 20:48:50 -05:00
|
|
|
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
|
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) data;
|
2015-04-10 20:48:50 -05:00
|
|
|
|
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
static void onDestroy(GtkWidget *widget, gpointer data)
|
2015-04-07 21:46:15 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) data;
|
2015-04-07 21:46:15 -05:00
|
|
|
|
|
|
|
uiFree(w);
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void windowDestroy(uiWindow *ww)
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
2015-04-06 11:20:51 -05:00
|
|
|
|
|
|
|
gtk_widget_destroy(w->widget);
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static uintptr_t handle(uiWindow *ww)
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-06 11:20:51 -05:00
|
|
|
return (uintptr_t) (w->widget);
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static char *title(uiWindow *ww)
|
2015-04-09 01:56:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-09 01:56:51 -05:00
|
|
|
return g_strdup(gtk_window_get_title(GTK_WINDOW(w->widget)));
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void setTitle(uiWindow *ww, const char *title)
|
2015-04-09 01:56:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-09 01:56:51 -05:00
|
|
|
gtk_window_set_title(GTK_WINDOW(w->widget), title);
|
|
|
|
}
|
2015-04-06 11:20:51 -05:00
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void show(uiWindow *ww)
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-11 23:59:32 -05:00
|
|
|
// don't use gtk_widget_show_all(); that will override user hidden settings
|
|
|
|
gtk_widget_show(w->widget);
|
2015-04-06 11:20:51 -05:00
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void hide(uiWindow *ww)
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
2015-04-06 11:20:51 -05:00
|
|
|
gtk_widget_hide(w->widget);
|
|
|
|
}
|
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void setOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
|
2015-04-06 11:20:51 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-06 11:20:51 -05:00
|
|
|
w->onClosing = f;
|
|
|
|
w->onClosingData = data;
|
|
|
|
}
|
2015-04-07 12:22:46 -05:00
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void setChild(uiWindow *ww, uiControl *c)
|
2015-04-07 12:22:46 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-13 11:05:14 -05:00
|
|
|
uiParentSetChild(w->content, c);
|
|
|
|
uiParentUpdate(w->content);
|
2015-04-07 12:22:46 -05:00
|
|
|
}
|
2015-04-09 14:18:18 -05:00
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static int margined(uiWindow *ww)
|
2015-04-09 20:11:56 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-13 11:05:14 -05:00
|
|
|
return w->margined;
|
2015-04-09 20:11:56 -05:00
|
|
|
}
|
2015-04-09 14:18:18 -05:00
|
|
|
|
2015-04-15 21:26:27 -05:00
|
|
|
static void setMargined(uiWindow *ww, int margined)
|
2015-04-09 14:18:18 -05:00
|
|
|
{
|
2015-04-15 21:26:27 -05:00
|
|
|
struct window *w = (struct window *) ww;
|
|
|
|
|
2015-04-13 11:05:14 -05:00
|
|
|
w->margined = margined;
|
|
|
|
if (w->margined)
|
|
|
|
uiParentSetMargins(w->content, gtkXMargin, gtkYMargin, gtkXMargin, gtkYMargin);
|
|
|
|
else
|
|
|
|
uiParentSetMargins(w->content, 0, 0, 0, 0);
|
|
|
|
uiParentUpdate(w->content);
|
2015-04-09 14:18:18 -05:00
|
|
|
}
|
2015-04-15 21:26:27 -05:00
|
|
|
|
|
|
|
uiWindow *uiNewWindow(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 = title;
|
|
|
|
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);
|
|
|
|
}
|