#include <stdio.h>
#include <stdlib.h>
#include "toolkit.h"
#include "menu.h"
#include "toolbar.h"
#include "container.h"
#include "../ui/window.h"
#include "../common/context.h"
#include "Grid.h"
#include <cx/mempool.h>
static int nwindows =
0;
static int window_default_width =
600;
static int window_default_height =
500;
static void window_close_handler(Widget window,
void *udata,
void *cdata) {
UiObject *obj = udata;
uic_object_destroy(obj);
nwindows--;
if(nwindows ==
0) {
ui_exit_mainloop();
}
}
static UiObject* create_window(
const char *title,
void *window_data, Boolean simple) {
CxMempool *mp = cxBasicMempoolCreate(
256);
const CxAllocator *a = mp->allocator;
UiObject *obj = cxCalloc(a,
1,
sizeof(UiObject));
obj->ctx = uic_context(obj, mp);
obj->window = window_data;
Arg args[
16];
int n =
0;
XtSetArg(args[n], XmNtitle, title); n++;
XtSetArg(args[n], XmNminWidth,
100); n++;
XtSetArg(args[n], XmNminHeight,
50); n++;
XtSetArg(args[n], XmNwidth, window_default_width); n++;
XtSetArg(args[n], XmNheight, window_default_height); n++;
Widget toplevel = XtAppCreateShell(
ui_appname(),
"mainwindow",
vendorShellWidgetClass,
ui_motif_get_display(),
args,
n);
Atom wm_delete_window;
wm_delete_window = XmInternAtom(
XtDisplay(toplevel),
"WM_DELETE_WINDOW",
0);
XmAddWMProtocolCallback(
toplevel,
wm_delete_window,
window_close_handler,
obj);
Widget window = XtVaCreateManagedWidget(
title,
xmMainWindowWidgetClass,
toplevel,
NULL);
n =
0;
Widget frame = XmCreateFrame(window,
"window_frame", args, n);
XtManageChild(frame);
Widget vbox = XtCreateManagedWidget(
"window_vbox", gridClass, frame,
NULL,
0);
UiContainerX *container = ui_box_container(obj, vbox,
UI_BOX_VERTICAL);
uic_object_push_container(obj, container);
obj->widget = toplevel;
nwindows++;
return obj;
}
UiObject* ui_window(
const char *title,
void *window_data) {
return create_window(title, window_data,
FALSE);
}
UiObject* ui_simple_window(
const char *title,
void *window_data) {
return create_window(title, window_data,
TRUE);
}