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
|
|
|
|
|
|
|
struct uiWindow {
|
|
|
|
GtkWidget *widget;
|
2015-04-07 12:22:46 -05:00
|
|
|
GtkWidget *container;
|
2015-04-06 11:20:51 -05:00
|
|
|
int (*onClosing)(uiWindow *, void *);
|
|
|
|
void *onClosingData;
|
|
|
|
};
|
|
|
|
|
2015-04-08 00:16:22 -05:00
|
|
|
static void onDestroy(GtkWidget *widget, gpointer data)
|
2015-04-07 21:46:15 -05:00
|
|
|
{
|
|
|
|
uiWindow *w = (uiWindow *) data;
|
|
|
|
|
|
|
|
uiFree(w);
|
|
|
|
}
|
|
|
|
|
2015-04-06 11:20:51 -05:00
|
|
|
uiWindow *uiNewWindow(char *title, int width, int height)
|
|
|
|
{
|
|
|
|
uiWindow *w;
|
|
|
|
|
2015-04-07 18:04:09 -05:00
|
|
|
w = uiNew(uiWindow);
|
2015-04-06 11:20:51 -05:00
|
|
|
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);
|
2015-04-07 21:46:15 -05:00
|
|
|
g_signal_connect(w->widget, "destroy", G_CALLBACK(onDestroy), w);
|
2015-04-07 12:22:46 -05:00
|
|
|
w->container = newContainer();
|
|
|
|
gtk_container_add(GTK_CONTAINER(w->widget), w->container);
|
2015-04-06 11:20:51 -05:00
|
|
|
return w;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowDestroy(uiWindow *w)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(w->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
uintptr_t uiWindowHandle(uiWindow *w)
|
|
|
|
{
|
|
|
|
return (uintptr_t) (w->widget);
|
|
|
|
}
|
|
|
|
|
2015-04-09 01:56:51 -05:00
|
|
|
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);
|
|
|
|
}
|
2015-04-06 11:20:51 -05:00
|
|
|
|
|
|
|
void uiWindowShow(uiWindow *w)
|
|
|
|
{
|
|
|
|
gtk_widget_show_all(w->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowHide(uiWindow *w)
|
|
|
|
{
|
|
|
|
gtk_widget_hide(w->widget);
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
|
|
|
{
|
|
|
|
w->onClosing = f;
|
|
|
|
w->onClosingData = data;
|
|
|
|
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
|
|
|
}
|
2015-04-07 12:22:46 -05:00
|
|
|
|
|
|
|
void uiWindowSetChild(uiWindow *w, uiControl *c)
|
|
|
|
{
|
|
|
|
uiContainer(w->container)->child = c;
|
2015-04-09 18:17:23 -05:00
|
|
|
uiControlSetParent(uiContainer(w->container)->child, (uintptr_t) (w->container));
|
2015-04-07 12:22:46 -05:00
|
|
|
}
|
2015-04-09 14:18:18 -05:00
|
|
|
|
2015-04-09 20:11:56 -05:00
|
|
|
int uiWindowMargined(uiWindow *w)
|
|
|
|
{
|
|
|
|
return uiContainer(w->container)->margined;
|
|
|
|
}
|
2015-04-09 14:18:18 -05:00
|
|
|
|
|
|
|
void uiWindowSetMargined(uiWindow *w, int margined)
|
|
|
|
{
|
|
|
|
uiContainer(w->container)->margined = margined;
|
|
|
|
updateParent((uintptr_t) (w->container));
|
|
|
|
}
|