2015-06-11 18:07:06 -05:00
|
|
|
// 11 june 2015
|
|
|
|
#include "uipriv_unix.h"
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
struct uiWindow {
|
|
|
|
uiUnixControl c;
|
2015-06-13 11:59:13 -05:00
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
GtkWidget *widget;
|
2015-06-13 11:59:13 -05:00
|
|
|
GtkContainer *container;
|
|
|
|
GtkWindow *window;
|
|
|
|
|
|
|
|
GtkWidget *vboxWidget;
|
|
|
|
GtkContainer *vboxContainer;
|
|
|
|
GtkBox *vbox;
|
|
|
|
|
|
|
|
GtkWidget *menubar;
|
|
|
|
|
2015-08-28 16:16:02 -05:00
|
|
|
struct child *child;
|
2015-08-28 09:30:42 -05:00
|
|
|
int margined;
|
2015-06-29 10:48:27 -05:00
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
int (*onClosing)(uiWindow *, void *);
|
|
|
|
void *onClosingData;
|
|
|
|
};
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
static void onDestroy(uiWindow *);
|
|
|
|
|
|
|
|
uiUnixDefineControlWithOnDestroy(
|
|
|
|
uiWindow, // type name
|
|
|
|
uiWindowType, // type function
|
|
|
|
onDestroy(this); // on destroy
|
|
|
|
)
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-13 11:59:13 -05:00
|
|
|
static gboolean onClosing(GtkWidget *win, GdkEvent *e, gpointer data)
|
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
uiWindow *w = uiWindow(data);
|
2015-06-13 11:59:13 -05:00
|
|
|
|
|
|
|
// manually destroy the window ourselves; don't let the delete-event handler do it
|
2015-08-28 08:56:41 -05:00
|
|
|
if ((*(w->onClosing))(w, w->onClosingData))
|
2015-06-13 11:59:13 -05:00
|
|
|
uiControlDestroy(uiControl(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 0;
|
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
static void onDestroy(uiWindow *w)
|
2015-06-13 11:59:13 -05:00
|
|
|
{
|
|
|
|
// first hide ourselves
|
|
|
|
gtk_widget_hide(w->widget);
|
2015-06-30 00:16:35 -05:00
|
|
|
// now destroy the child
|
2015-08-28 16:16:02 -05:00
|
|
|
if (w->child != NULL)
|
|
|
|
childDestroy(w->child);
|
2015-06-13 11:59:13 -05:00
|
|
|
// now destroy the menus, if any
|
|
|
|
if (w->menubar != NULL)
|
|
|
|
freeMenubar(w->menubar);
|
2015-08-28 08:56:41 -05:00
|
|
|
gtk_widget_destroy(w->vboxWidget);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-06-13 11:59:13 -05:00
|
|
|
static void windowCommitShow(uiControl *c)
|
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
uiWindow *w = uiWindow(c);
|
2015-06-13 11:59:13 -05:00
|
|
|
|
|
|
|
// don't use gtk_widget_show_all() as that will show all children, regardless of user settings
|
|
|
|
// don't use gtk_widget_show(); that doesn't bring to front or give keyboard focus
|
|
|
|
// (gtk_window_present() does call gtk_widget_show() though)
|
|
|
|
gtk_window_present(w->window);
|
|
|
|
}
|
|
|
|
|
2015-06-11 18:07:06 -05:00
|
|
|
static void windowContainerUpdateState(uiControl *c)
|
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
uiWindow *w = uiWindow(c);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
|
|
|
if (w->child != NULL)
|
2015-08-28 16:16:02 -05:00
|
|
|
childUpdateState(w->child);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
char *uiWindowTitle(uiWindow *w)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-06-13 11:59:13 -05:00
|
|
|
return uiUnixStrdupText(gtk_window_get_title(w->window));
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiWindowSetTitle(uiWindow *w, const char *title)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-06-13 11:59:13 -05:00
|
|
|
gtk_window_set_title(w->window, title);
|
2015-06-11 18:07:06 -05:00
|
|
|
// don't queue resize; the caption isn't part of what affects layout and sizing of the client area (it'll be ellipsized if too long)
|
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
|
|
|
w->onClosing = f;
|
|
|
|
w->onClosingData = data;
|
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiWindowSetChild(uiWindow *w, uiControl *child)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-28 16:16:02 -05:00
|
|
|
if (w->child != NULL)
|
2015-12-12 14:30:56 -06:00
|
|
|
childRemove(w->child);
|
2015-08-28 16:16:02 -05:00
|
|
|
w->child = newChildWithBox(child, uiControl(w), w->vboxContainer, w->margined);
|
2015-08-28 08:56:41 -05:00
|
|
|
if (w->child != NULL) {
|
2015-08-28 16:16:02 -05:00
|
|
|
gtk_widget_set_hexpand(childBox(w->child), TRUE);
|
|
|
|
gtk_widget_set_halign(childBox(w->child), GTK_ALIGN_FILL);
|
|
|
|
gtk_widget_set_vexpand(childBox(w->child), TRUE);
|
|
|
|
gtk_widget_set_valign(childBox(w->child), GTK_ALIGN_FILL);
|
2015-08-28 08:56:41 -05:00
|
|
|
}
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
int uiWindowMargined(uiWindow *w)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
return w->margined;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
void uiWindowSetMargined(uiWindow *w, int margined)
|
2015-06-11 18:07:06 -05:00
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
w->margined = margined;
|
2015-08-28 16:16:02 -05:00
|
|
|
if (w->child != NULL)
|
|
|
|
childSetMargined(w->child, w->margined);
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
|
|
|
{
|
2015-08-28 08:56:41 -05:00
|
|
|
uiWindow *w;
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-28 09:10:52 -05:00
|
|
|
w = (uiWindow *) uiNewControl(uiWindowType());
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-06-13 11:59:13 -05:00
|
|
|
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);
|
|
|
|
gtk_window_resize(w->window, width, height);
|
|
|
|
|
|
|
|
w->vboxWidget = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
|
|
|
w->vboxContainer = GTK_CONTAINER(w->vboxWidget);
|
|
|
|
w->vbox = GTK_BOX(w->vboxWidget);
|
|
|
|
|
|
|
|
// set the vbox as the GtkWindow child
|
|
|
|
gtk_container_add(w->container, w->vboxWidget);
|
|
|
|
|
|
|
|
if (hasMenubar) {
|
|
|
|
w->menubar = makeMenubar(uiWindow(w));
|
|
|
|
gtk_container_add(w->vboxContainer, w->menubar);
|
|
|
|
}
|
|
|
|
|
|
|
|
// show everything in the vbox, but not the GtkWindow itself
|
|
|
|
gtk_widget_show_all(w->vboxWidget);
|
|
|
|
|
|
|
|
// and connect our OnClosing() event
|
|
|
|
g_signal_connect(w->widget, "delete-event", G_CALLBACK(onClosing), w);
|
2015-08-28 08:56:41 -05:00
|
|
|
uiWindowOnClosing(w, defaultOnClosing, NULL);
|
2015-06-11 18:07:06 -05:00
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
uiUnixFinishNewControl(w, uiWindow);
|
2015-06-13 11:59:13 -05:00
|
|
|
uiControl(w)->CommitShow = windowCommitShow;
|
2015-06-11 18:07:06 -05:00
|
|
|
uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
|
|
|
|
|
2015-08-28 08:56:41 -05:00
|
|
|
return w;
|
2015-06-11 18:07:06 -05:00
|
|
|
}
|