ui/motif/window.c

changeset 931
6ca1ef6c8107
parent 930
4ce8df2311f0
child 933
70e14fa98ab4
equal deleted inserted replaced
930:4ce8df2311f0 931:6ca1ef6c8107
85 int window_height = window_default_height; 85 int window_height = window_default_height;
86 if(!simple) { 86 if(!simple) {
87 ui_get_window_default_width(&window_width, &window_height); 87 ui_get_window_default_width(&window_width, &window_height);
88 } 88 }
89 89
90 UiMotifAppWindow *appwindow = cxZalloc(a, sizeof(UiMotifAppWindow));
91 // Because we store appwindow as userdata in the widget, we use this
92 // magic field to check, if the pointer is actually the correct type.
93 // This is a dubious technique, but this is only the last defense
94 // mechanism against someone using the API wrong.
95 appwindow->magic = UI_MOTIF_APP_WINDOW;
96
90 Arg args[16]; 97 Arg args[16];
91 int n = 0; 98 int n = 0;
92 XtSetArg(args[n], XmNtitle, title); n++; 99 XtSetArg(args[n], XmNtitle, title); n++;
93 XtSetArg(args[n], XmNminWidth, 100); n++; 100 XtSetArg(args[n], XmNminWidth, 100); n++;
94 XtSetArg(args[n], XmNminHeight, 50); n++; 101 XtSetArg(args[n], XmNminHeight, 50); n++;
95 XtSetArg(args[n], XmNwidth, window_width); n++; 102 XtSetArg(args[n], XmNwidth, window_width); n++;
96 XtSetArg(args[n], XmNheight, window_height); n++; 103 XtSetArg(args[n], XmNheight, window_height); n++;
104 XtSetArg(args[n], XmNuserData, appwindow); n++;
97 105
98 Widget toplevel = XtAppCreateShell( 106 Widget toplevel = XtAppCreateShell(
99 ui_appname(), 107 ui_appname(),
100 "mainwindow", 108 "mainwindow",
101 //applicationShellWidgetClass, 109 //applicationShellWidgetClass,
121 toplevel, 129 toplevel,
122 NULL); 130 NULL);
123 131
124 // menu 132 // menu
125 if(!simple) { 133 if(!simple) {
126 ui_create_menubar(obj, window); 134 appwindow->menubar = ui_create_menubar(obj, window);
127 } 135 }
128 136
129 // content frame 137 // content frame
130 n = 0; 138 n = 0;
131 Widget frame = XmCreateFrame(window, "window_frame", args, n); 139 Widget frame = XmCreateFrame(window, "window_frame", args, n);
164 window_default_width = width; 172 window_default_width = width;
165 window_default_height = height; 173 window_default_height = height;
166 } 174 }
167 175
168 void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) { 176 void ui_window_menubar_set_visible(UiObject *obj, UiBool visible) {
169 177 UiMotifAppWindow *window = NULL;
178 XtVaGetValues(obj->widget, XmNuserData, &window, NULL);
179 if(window) {
180 if(window->magic != UI_MOTIF_APP_WINDOW) {
181 fprintf(stderr, "Error: obj is not an app window\n");
182 return;
183 }
184 if(window->menubar) {
185 ui_set_visible(window->menubar, visible);
186 }
187 }
170 } 188 }
171 189
172 static void filedialog_event(UiEventData *event, int result, UiFileList flist) { 190 static void filedialog_event(UiEventData *event, int result, UiFileList flist) {
173 UiEvent evt; 191 UiEvent evt;
174 evt.obj = event->obj; 192 evt.obj = event->obj;

mercurial