| 43 static int nwindows = 0; |
43 static int nwindows = 0; |
| 44 |
44 |
| 45 static int window_default_width = 600; |
45 static int window_default_width = 600; |
| 46 static int window_default_height = 500; |
46 static int window_default_height = 500; |
| 47 |
47 |
| 48 static void window_close_handler(Widget window, void *udata, void *cdata) { |
48 void ui_window_widget_destroy(UiObject *obj) { |
| 49 UiObject *obj = udata; |
49 XtDestroyWidget(obj->widget); |
| 50 uic_object_destroy(obj); |
50 uic_object_destroy(obj); |
| 51 |
|
| 52 nwindows--; |
51 nwindows--; |
| 53 if(nwindows == 0) { |
52 if(nwindows == 0) { |
| 54 ui_exit_mainloop(); |
53 ui_exit_mainloop(); |
| |
54 } |
| |
55 } |
| |
56 |
| |
57 static void window_close_handler(Widget window, void *udata, void *cdata) { |
| |
58 UiObject *obj = udata; |
| |
59 |
| |
60 uic_context_prepare_close(obj->ctx); |
| |
61 obj->ref--; |
| |
62 if(obj->ref > 0) { |
| |
63 XtUnmapWidget(obj->widget); |
| |
64 } else { |
| |
65 ui_window_widget_destroy(obj); |
| 55 } |
66 } |
| 56 } |
67 } |
| 57 |
68 |
| 58 |
69 |
| 59 static UiObject* create_window(const char *title, void *window_data, Boolean simple) { |
70 static UiObject* create_window(const char *title, void *window_data, Boolean simple) { |
| 60 CxMempool *mp = cxMempoolCreateSimple(256); |
71 CxMempool *mp = cxMempoolCreateSimple(256); |
| 61 const CxAllocator *a = mp->allocator; |
72 const CxAllocator *a = mp->allocator; |
| 62 UiObject *obj = cxCalloc(a, 1, sizeof(UiObject)); |
73 UiObject *obj = cxCalloc(a, 1, sizeof(UiObject)); |
| 63 obj->ctx = uic_context(obj, mp); |
74 obj->ctx = uic_context(obj, mp); |
| 64 obj->window = window_data; |
75 obj->window = window_data; |
| |
76 obj->destroy = ui_window_widget_destroy; |
| 65 |
77 |
| 66 Arg args[16]; |
78 Arg args[16]; |
| 67 int n = 0; |
79 int n = 0; |
| 68 XtSetArg(args[n], XmNtitle, title); n++; |
80 XtSetArg(args[n], XmNtitle, title); n++; |
| 69 XtSetArg(args[n], XmNminWidth, 100); n++; |
81 XtSetArg(args[n], XmNminWidth, 100); n++; |