gwenhywfar 5.14.1
cocoa_gui_dialog.m
Go to the documentation of this file.
1/***************************************************************************
2 begin : August 09 2010
3 copyright : (C) 2010 by Samuel Strupp
4
5 ***************************************************************************
6 * Please see toplevel file COPYING for license details *
7 ***************************************************************************/
8
9#ifdef HAVE_CONFIG_H
10# include <config.h>
11#endif
12
13
14#include "cocoa_gui_dialog_p.h"
15#include <assert.h>
16
17#include <gwenhywfar/inherit.h>
18#include <gwenhywfar/debug.h>
19#include <gwenhywfar/gui_be.h>
20#include <gwenhywfar/i18n.h>
21
22#include <gwenhywfar/text.h>
23#include <gwenhywfar/mdigest.h>
24#include <gwenhywfar/debug.h>
25#include <gwenhywfar/directory.h>
26
27
28
29#define COCOA_DIALOG_WIDGET_REAL 0
30#define COCOA_DIALOG_WIDGET_CONTENT 1
31#define COCOA_DIALOG_WIDGET_DATA 2
32
33#define COCOA_DIALOG_STRING_TITLE 0
34#define COCOA_DIALOG_STRING_VALUE 1
35
36
37
38
39#include "w_dialog.mm"
40#include "w_label.mm"
41#include "w_vlayout.mm"
42#include "w_hlayout.mm"
43#include "w_pushbutton.mm"
44#include "w_lineedit.mm"
45#include "w_textedit.mm"
46#include "w_checkbox.mm"
47#include "w_hline.mm"
48#include "w_vline.mm"
49#include "w_progressbar.mm"
50#include "w_radiobutton.mm"
51#include "w_tabbook.mm"
52#include "w_groupbox.mm"
53#include "w_combobox.mm"
54#include "w_gridlayout.mm"
55#include "w_hspacer.mm"
56#include "w_vspacer.mm"
57#include "w_listbox.mm"
58#include "w_scrollarea.mm"
59#include "w_textbrowser.mm"
60#include "w_stack.mm"
61#include "w_spinbox.mm"
62
63
64
65GWEN_INHERIT(GWEN_DIALOG, COCOA_GUI_DIALOG)
66
67
68
69
71 COCOA_GUI_DIALOG *xdlg;
72
73 GWEN_NEW_OBJECT(COCOA_GUI_DIALOG, xdlg);
74 GWEN_INHERIT_SETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg, xdlg, CocoaGui_Dialog_FreeData);
75
76 // set virtual functions
81
82}
83
84
85
87 COCOA_GUI_DIALOG *xdlg;
88
89 assert(dlg);
90 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
91 assert(xdlg);
92
93 // reset virtual functions
94 GWEN_Dialog_SetSetIntPropertyFn(dlg, xdlg->setIntPropertyFn);
95 GWEN_Dialog_SetGetIntPropertyFn(dlg, xdlg->getIntPropertyFn);
96 GWEN_Dialog_SetSetCharPropertyFn(dlg, xdlg->setCharPropertyFn);
97 GWEN_Dialog_SetGetCharPropertyFn(dlg, xdlg->getCharPropertyFn);
98
99 GWEN_INHERIT_UNLINK(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
100}
101
102
103
105 COCOA_GUI_DIALOG *xdlg;
106
107 xdlg=(COCOA_GUI_DIALOG*) p;
108
109 if (xdlg->mainWindow) {
110 NSWindow *window = (xdlg->mainWindow);
111 [window release];
112 xdlg->mainWindow = nil;
113 }
114
115 GWEN_FREE_OBJECT(xdlg);
116}
117
118
119
121 COCOA_GUI_DIALOG *xdlg;
122
123 assert(dlg);
124 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
125 assert(xdlg);
126
127 return xdlg->mainWindow;
128}
129
130
131
133 GWEN_WIDGET *w,
135 int index,
136 int value,
137 int doSignal) {
138 return GWEN_Widget_SetIntProperty(w, prop, index, value, doSignal);
139}
140
141
142
144 GWEN_WIDGET *w,
146 int index,
147 int defaultValue) {
148 return GWEN_Widget_GetIntProperty(w, prop, index, defaultValue);
149}
150
151
152
154 GWEN_WIDGET *w,
156 int index,
157 const char *value,
158 int doSignal) {
159 return GWEN_Widget_SetCharProperty(w, prop, index, value, doSignal);
160}
161
162
163
165 GWEN_WIDGET *w,
167 int index,
168 const char *defaultValue) {
169 return GWEN_Widget_GetCharProperty(w, prop, index, defaultValue);
170}
171
172
173
174int CocoaGui_Dialog_Setup(GWEN_DIALOG *dlg, NSWindow *parentWindow) {
175 COCOA_GUI_DIALOG *xdlg;
176 GWEN_WIDGET_TREE *wtree;
177 GWEN_WIDGET *w;
178 int rv;
179
180 assert(dlg);
181 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
182 assert(xdlg);
183
184 wtree=GWEN_Dialog_GetWidgets(dlg);
185 if (wtree==NULL) {
186 DBG_ERROR(0, "No widget tree in dialog");
188 }
189 w=GWEN_Widget_Tree_GetFirst(wtree);
190 if (w==NULL) {
191 DBG_ERROR(0, "No widgets in dialog");
193 }
194
196 if (rv<0) {
197 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
198 return rv;
199 }
200
202
203 return 0;
204}
205
206
207
208void CocoaGui_Dialog_Leave(GWEN_DIALOG *dlg, int result) {
209 COCOA_GUI_DIALOG *xdlg;
210 GWEN_DIALOG *parent;
211
212 // get toplevel dialog, the one which actually is the GUI dialog
213 while( (parent=GWEN_Dialog_GetParentDialog(dlg)) )
214 dlg=parent;
215
216 assert(dlg);
217 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
218 assert(xdlg);
219
220 //xdlg->response=result;
221 /*if (g_main_loop_is_running(xdlg->loop))
222 g_main_loop_quit(xdlg->loop);*/
223 if (xdlg->mainWindow) {
224 [NSApp abortModal];
225 [xdlg->mainWindow close];
226 }
227}
228
229
230
231/*static void
232 run_unmap_handler (NSWindow *window, void* data){
233 GWEN_DIALOG *dlg;
234 COCOA_GUI_DIALOG *xdlg;
235
236 dlg=data;
237 assert(dlg);
238 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
239 assert(xdlg);
240
241 DBG_ERROR(0, "here");
242 CocoaGui_Dialog_Leave(dlg, 0);
243 }
244
245
246
247 static int run_delete_handler(NSWindow *window, void* data){
248 GWEN_DIALOG *dlg;
249 COCOA_GUI_DIALOG *xdlg;
250
251 dlg=data;
252 assert(dlg);
253 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
254 assert(xdlg);
255
256 DBG_ERROR(0, "here");
257 CocoaGui_Dialog_Leave(dlg, 0);
258 return TRUE; // Do not destroy
259 }
260
261
262
263 static void
264 run_destroy_handler(NSWindow *window, void* data) {
265 GWEN_DIALOG *dlg;
266 COCOA_GUI_DIALOG *xdlg;
267
268 dlg=data;
269 assert(dlg);
270 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
271 assert(xdlg);
272
273 DBG_ERROR(0, "Destroyed");
274 xdlg->destroyed=1;
275 }*/
276
277
278
279int Cocoa_Gui_Dialog_Run(GWEN_DIALOG *dlg, int untilEnd) {
280 COCOA_GUI_DIALOG *xdlg;
281 CocoaWindow *g;
282
283 assert(dlg);
284 xdlg=GWEN_INHERIT_GETDATA(GWEN_DIALOG, COCOA_GUI_DIALOG, dlg);
285 assert(xdlg);
286
288 if (g==NULL) {
289 DBG_ERROR(GWEN_LOGDOMAIN, "No main widget");
291 return GWEN_ERROR_INVALID;
292 }
293
294 if (untilEnd) {
295 [NSApp runModalForWindow:g];
296 }
297 else {
298 NSModalSession session = [NSApp beginModalSessionForWindow:g];
299 for (;;) {
300 if ([NSApp runModalSession:session] != NSRunContinuesResponse)
301 break;
302 }
303 [NSApp endModalSession:session];
304 }
305
306
307 /* xdlg->unmap_handler =
308 g_signal_connect(g,
309 "unmap",
310 G_CALLBACK (run_unmap_handler),
311 dlg);
312
313 xdlg->delete_handler =
314 g_signal_connect(g,
315 "delete-event",
316 G_CALLBACK (run_delete_handler),
317 dlg);
318
319 xdlg->destroy_handler =
320 g_signal_connect(g,
321 "destroy",
322 G_CALLBACK (run_destroy_handler),
323 dlg);*/
324
325 //xdlg->loop=g_main_loop_new(NULL, FALSE);
326 /*if (untilEnd)
327 g_main_loop_run(xdlg->loop);
328 else {
329 GMainContext *ctx;
330
331 ctx=g_main_loop_get_context(xdlg->loop);
332 while(g_main_context_pending(ctx))
333 g_main_context_iteration(ctx, FALSE);
334 }
335 g_main_loop_unref(xdlg->loop);
336
337 if (!xdlg->destroyed) {
338 g_signal_handler_disconnect(g, xdlg->unmap_handler);
339 g_signal_handler_disconnect(g, xdlg->delete_handler);
340 g_signal_handler_disconnect(g, xdlg->destroy_handler);
341 }
342
343 return xdlg->response;*/
344 return 0;
345}
346
347
348
350 int rv;
351
352 switch(GWEN_Widget_GetType(w)) {
355 break;
358 break;
361 break;
364 break;
367 break;
370 break;
373 break;
376 break;
379 break;
382 break;
385 break;
388 break;
391 break;
393 // just re-use vbox
396 break;
399 break;
402 break;
405 break;
408 break;
411 break;
414 break;
417 break;
420 break;
423 break;
426 break;
427 default:
428 DBG_ERROR(GWEN_LOGDOMAIN, "Unhandled widget type %d", GWEN_Widget_GetType(w));
430 break;
431 }
432
433 if (rv<0) {
434 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
435 return rv;
436 }
437 else {
438 GWEN_WIDGET *wChild;
439
440 // handle children
441 wChild=GWEN_Widget_Tree_GetFirstChild(w);
442 while(wChild) {
443 // recursion
444 rv=CocoaGui_Dialog_SetupTree(wChild);
445 if (rv<0) {
446 DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", rv);
447 return rv;
448 }
449 wChild=GWEN_Widget_Tree_GetNext(wChild);
450 }
451 }
452
453 return 0;
454}
455
456
#define NULL
Definition binreloc.c:300
const char * CocoaGui_Dialog_GetCharProperty(GWEN_DIALOG *dlg, GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
int CocoaGui_Dialog_SetupTree(GWEN_WIDGET *w)
void CocoaGui_Dialog_Extend(GWEN_DIALOG *dlg)
int CocoaGui_Dialog_Setup(GWEN_DIALOG *dlg, NSWindow *parentWindow)
int CocoaGui_Dialog_SetCharProperty(GWEN_DIALOG *dlg, GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
#define COCOA_DIALOG_WIDGET_REAL
void CocoaGui_Dialog_Leave(GWEN_DIALOG *dlg, int result)
void CocoaGui_Dialog_Unextend(GWEN_DIALOG *dlg)
int CocoaGui_Dialog_GetIntProperty(GWEN_DIALOG *dlg, GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
void GWENHYWFAR_CB CocoaGui_Dialog_FreeData(void *bp, void *p)
CocoaWindow * CocoaGui_Dialog_GetMainWidget(const GWEN_DIALOG *dlg)
int Cocoa_Gui_Dialog_Run(GWEN_DIALOG *dlg, int untilEnd)
int CocoaGui_Dialog_SetIntProperty(GWEN_DIALOG *dlg, GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
#define DBG_INFO(dbg_logger, format,...)
Definition debug.h:181
#define DBG_ERROR(dbg_logger, format,...)
Definition debug.h:97
GWEN_WIDGET_TREE * GWEN_Dialog_GetWidgets(const GWEN_DIALOG *dlg)
Definition dialog.c:629
GWEN_DIALOG_GETINTPROPERTY_FN GWEN_Dialog_SetGetIntPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_GETINTPROPERTY_FN fn)
Definition dialog.c:655
GWEN_DIALOG * GWEN_Dialog_GetParentDialog(const GWEN_DIALOG *dlg)
Definition dialog.c:172
GWEN_DIALOG_SETINTPROPERTY_FN GWEN_Dialog_SetSetIntPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_SETINTPROPERTY_FN fn)
Definition dialog.c:640
GWEN_DIALOG_GETCHARPROPERTY_FN GWEN_Dialog_SetGetCharPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_GETCHARPROPERTY_FN fn)
Definition dialog.c:685
GWEN_DIALOG_SETCHARPROPERTY_FN GWEN_Dialog_SetSetCharPropertyFn(GWEN_DIALOG *dlg, GWEN_DIALOG_SETCHARPROPERTY_FN fn)
Definition dialog.c:670
#define GWEN_WIDGET_FLAGS_FILLY
Definition dialog.h:62
#define GWEN_WIDGET_FLAGS_FILLX
Definition dialog.h:61
struct GWEN_DIALOG GWEN_DIALOG
Definition dialog.h:54
GWEN_DIALOG_PROPERTY
Definition dialog.h:260
#define GWEN_ERROR_INVALID
Definition error.h:67
#define GWEN_ERROR_NOT_FOUND
Definition error.h:89
#define GWENHYWFAR_CB
#define GWEN_INHERIT_UNLINK(bt, t, element)
Definition inherit.h:326
#define GWEN_INHERIT_SETDATA(bt, t, element, data, fn)
Definition inherit.h:300
#define GWEN_INHERIT(bt, t)
Definition inherit.h:264
#define GWEN_INHERIT_GETDATA(bt, t, element)
Definition inherit.h:279
#define GWEN_LOGDOMAIN
Definition logger.h:32
#define GWEN_FREE_OBJECT(varname)
Definition memory.h:61
#define GWEN_NEW_OBJECT(typ, varname)
Definition memory.h:55
int CocoaGui_WCheckBox_Setup(GWEN_WIDGET *w)
int CocoaGui_WComboBox_Setup(GWEN_WIDGET *w)
int CocoaGui_WDialog_Setup(GWEN_WIDGET *w)
Definition w_dialog.mm:181
int CocoaGui_WGridLayout_Setup(GWEN_WIDGET *w)
int CocoaGui_WGroupBox_Setup(GWEN_WIDGET *w)
int CocoaGui_WHLayout_Setup(GWEN_WIDGET *w)
Definition w_hlayout.mm:141
int CocoaGui_WHLine_Setup(GWEN_WIDGET *w)
Definition w_hline.mm:77
int CocoaGui_WHSpacer_Setup(GWEN_WIDGET *w)
Definition w_hspacer.mm:73
int CocoaGui_WLabel_Setup(GWEN_WIDGET *w)
Definition w_label.mm:158
int CocoaGui_WLineEdit_Setup(GWEN_WIDGET *w)
int CocoaGui_WListBox_Setup(GWEN_WIDGET *w)
Definition w_listbox.mm:269
int CocoaGui_WProgressBar_Setup(GWEN_WIDGET *w)
int CocoaGui_WPushButton_Setup(GWEN_WIDGET *w)
int CocoaGui_WRadioButton_Setup(GWEN_WIDGET *w)
int CocoaGui_WScrollArea_Setup(GWEN_WIDGET *w)
int CocoaGui_WSpinBox_Setup(GWEN_WIDGET *w)
Definition w_spinbox.mm:201
int CocoaGui_WStack_Setup(GWEN_WIDGET *w)
Definition w_stack.mm:170
int CocoaGui_WTabBook_Setup(GWEN_WIDGET *w)
Definition w_tabbook.mm:153
int CocoaGui_WTextBrowser_Setup(GWEN_WIDGET *w)
int CocoaGui_WTextEdit_Setup(GWEN_WIDGET *w)
int CocoaGui_WVLayout_Setup(GWEN_WIDGET *w)
Definition w_vlayout.mm:143
int CocoaGui_WVLine_Setup(GWEN_WIDGET *w)
Definition w_vline.mm:80
int CocoaGui_WVSpacer_Setup(GWEN_WIDGET *w)
Definition w_vspacer.mm:74
int GWEN_Widget_SetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int value, int doSignal)
Definition widget.c:770
int GWEN_Widget_SetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *value, int doSignal)
Definition widget.c:803
void * GWEN_Widget_GetImplData(const GWEN_WIDGET *w, int index)
Definition widget.c:122
int GWEN_Widget_GetIntProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, int defaultValue)
Definition widget.c:787
void GWEN_Widget_AddFlags(GWEN_WIDGET *w, uint32_t fl)
Definition widget.c:167
const char * GWEN_Widget_GetCharProperty(GWEN_WIDGET *w, GWEN_DIALOG_PROPERTY prop, int index, const char *defaultValue)
Definition widget.c:820
GWEN_WIDGET_TYPE GWEN_Widget_GetType(const GWEN_WIDGET *w)
Definition widget.c:185
struct GWEN_WIDGET GWEN_WIDGET
Definition widget_be.h:34
@ GWEN_Widget_TypeTabBook
Definition widget_be.h:67
@ GWEN_Widget_TypeComboBox
Definition widget_be.h:56
@ GWEN_Widget_TypeTabPage
Definition widget_be.h:68
@ GWEN_Widget_TypeRadioButton
Definition widget_be.h:57
@ GWEN_Widget_TypeHLayout
Definition widget_be.h:62
@ GWEN_Widget_TypeLineEdit
Definition widget_be.h:54
@ GWEN_Widget_TypeWidgetStack
Definition widget_be.h:70
@ GWEN_Widget_TypeScrollArea
Definition widget_be.h:71
@ GWEN_Widget_TypeLabel
Definition widget_be.h:52
@ GWEN_Widget_TypeGroupBox
Definition widget_be.h:59
@ GWEN_Widget_TypeDialog
Definition widget_be.h:66
@ GWEN_Widget_TypePushButton
Definition widget_be.h:53
@ GWEN_Widget_TypeCheckBox
Definition widget_be.h:69
@ GWEN_Widget_TypeTextBrowser
Definition widget_be.h:74
@ GWEN_Widget_TypeHSpacer
Definition widget_be.h:60
@ GWEN_Widget_TypeHLine
Definition widget_be.h:72
@ GWEN_Widget_TypeTextEdit
Definition widget_be.h:55
@ GWEN_Widget_TypeGridLayout
Definition widget_be.h:64
@ GWEN_Widget_TypeVLayout
Definition widget_be.h:63
@ GWEN_Widget_TypeProgressBar
Definition widget_be.h:58
@ GWEN_Widget_TypeSpinBox
Definition widget_be.h:75
@ GWEN_Widget_TypeVSpacer
Definition widget_be.h:61
@ GWEN_Widget_TypeVLine
Definition widget_be.h:73
@ GWEN_Widget_TypeListBox
Definition widget_be.h:65