1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 #include <stdio.h>
30 #include <stdlib.h>
31
32 #include "toolkit.h"
33 #include "menu.h"
34 #include "toolbar.h"
35 #include "container.h"
36 #include "../ui/window.h"
37 #include "../common/context.h"
38
39 #include "Grid.h"
40
41 #include <cx/mempool.h>
42
43 static int nwindows =
0;
44
45 static int window_default_width =
600;
46 static int window_default_height =
500;
47
48 static void window_close_handler(Widget window,
void *udata,
void *cdata) {
49 UiObject *obj = udata;
50 uic_object_destroy(obj);
51
52 nwindows--;
53 if(nwindows ==
0) {
54 ui_exit_mainloop();
55 }
56 }
57
58
59 static UiObject* create_window(
const char *title,
void *window_data, Boolean simple) {
60 CxMempool *mp = cxBasicMempoolCreate(
256);
61 const CxAllocator *a = mp->allocator;
62 UiObject *obj = cxCalloc(a,
1,
sizeof(UiObject));
63 obj->ctx = uic_context(obj, mp);
64 obj->window = window_data;
65
66 Arg args[
16];
67 int n =
0;
68 XtSetArg(args[n], XmNtitle, title); n++;
69 XtSetArg(args[n], XmNminWidth,
100); n++;
70 XtSetArg(args[n], XmNminHeight,
50); n++;
71 XtSetArg(args[n], XmNwidth, window_default_width); n++;
72 XtSetArg(args[n], XmNheight, window_default_height); n++;
73
74 Widget toplevel = XtAppCreateShell(
75 ui_appname(),
76 "mainwindow",
77
78 vendorShellWidgetClass,
79 ui_motif_get_display(),
80 args,
81 n);
82
83 Atom wm_delete_window;
84 wm_delete_window = XmInternAtom(
85 XtDisplay(toplevel),
86 "WM_DELETE_WINDOW",
87 0);
88 XmAddWMProtocolCallback(
89 toplevel,
90 wm_delete_window,
91 window_close_handler,
92 obj);
93
94 Widget window = XtVaCreateManagedWidget(
95 title,
96 xmMainWindowWidgetClass,
97 toplevel,
98 NULL);
99
100
101 n =
0;
102 Widget frame = XmCreateFrame(window,
"window_frame", args, n);
103 XtManageChild(frame);
104
105 Widget vbox = XtCreateManagedWidget(
"window_vbox", gridClass, frame,
NULL,
0);
106 UiContainerX *container = ui_box_container(obj, vbox,
UI_BOX_VERTICAL);
107 uic_object_push_container(obj, container);
108
109 obj->widget = toplevel;
110 nwindows++;
111 return obj;
112 }
113
114 UiObject* ui_window(
const char *title,
void *window_data) {
115 return create_window(title, window_data,
FALSE);
116 }
117
118 UiObject* ui_simple_window(
const char *title,
void *window_data) {
119 return create_window(title, window_data,
TRUE);
120 }
121