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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
/** \file
* \brief Motif IupFileDlg pre-defined dialog
*
* See Copyright Notice in "iup.h"
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <Xm/Xm.h>
#include <Xm/MwmUtil.h>
#include <Xm/FileSB.h>
#include <Xm/Protocols.h>
#include <Xm/SelectioB.h>
#include <Xm/MessageB.h>
#include <Xm/DrawingA.h>
#include <Xm/PushB.h>
#include <Xm/Frame.h>
#include <Xm/List.h>
#include "iup.h"
#include "iupcbs.h"
#include "iup_object.h"
#include "iup_attrib.h"
#include "iup_str.h"
#include "iup_drvinfo.h"
#include "iup_dialog.h"
#include "iup_strmessage.h"
#include "iup_drvinfo.h"
#include "iup_array.h"
#include "iupmot_drv.h"
enum {IUP_DIALOGOPEN, IUP_DIALOGSAVE, IUP_DIALOGDIR};
static void motFileDlgAskUserCallback(Widget w, int* ret_code, XmSelectionBoxCallbackStruct* cbs)
{
if (cbs->reason == XmCR_OK)
*ret_code = 1;
else
*ret_code = -1;
XtDestroyWidget(XtParent(w));
}
static int motFileDlgAskUser(Widget parent, const char* message)
{
Widget questionbox;
Arg args[3];
int ret_code = 0;
XmString title;
XtSetArg(args[0], XmNautoUnmanage, False);
XtSetArg(args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
XtSetArg(args[2], XmNnoResize, True);
questionbox = XmCreateQuestionDialog(parent, "filedlg_question", args, 3);
iupmotSetString(questionbox, XmNmessageString, message);
XtVaGetValues(parent, XmNdialogTitle, &title, NULL);
XtVaSetValues(questionbox, XmNdialogTitle, title, NULL);
XtAddCallback(questionbox, XmNokCallback, (XtCallbackProc)motFileDlgAskUserCallback, (XtPointer)&ret_code);
XtAddCallback(questionbox, XmNcancelCallback, (XtCallbackProc)motFileDlgAskUserCallback, (XtPointer)&ret_code);
XtUnmanageChild(XmMessageBoxGetChild(questionbox, XmDIALOG_HELP_BUTTON));
XtManageChild(questionbox);
while (ret_code == 0)
XtAppProcessEvent(iupmot_appcontext, XtIMAll);
XtUnmanageChild(questionbox);
if (ret_code == 1)
return 1;
else
return 0;
}
static int motFileDlgCheckValue(Ihandle* ih, Widget w)
{
char* value = iupAttribGet(ih, "VALUE");
int dialogtype = iupAttribGetInt(ih, "_IUPDLG_DIALOGTYPE");
if (dialogtype == IUP_DIALOGDIR)
{
if (!iupdrvIsDirectory(value)) /* if does not exist or not a directory */
{
iupStrMessageShowError(ih, "IUP_INVALIDDIR");
return 0;
}
}
else if (!iupAttribGetBoolean(ih, "MULTIPLEFILES"))
{
if (iupdrvIsDirectory(value)) /* selected a directory */
{
iupStrMessageShowError(ih, "IUP_INVALIDDIR");
return 0;
}
else if (!iupdrvIsFile(value)) /* not a file == new file */
{
value = iupAttribGet(ih, "ALLOWNEW");
if (!value)
{
if (dialogtype == IUP_DIALOGSAVE)
value = "YES";
else
value = "NO";
}
if (!iupStrBoolean(value))
{
iupStrMessageShowError(ih, "IUP_FILENOTEXIST");
return 0;
}
}
else if (dialogtype == IUP_DIALOGSAVE && !iupAttribGetInt(ih, "NOOVERWRITEPROMPT"))
{
if (!motFileDlgAskUser(w, iupStrMessageGet("IUP_FILEOVERWRITE")))
return 0;
}
}
return 1;
}
static void motFileDlgCBclose(Widget w, XtPointer client_data, XtPointer call_data)
{
Ihandle *ih = (Ihandle*)client_data;
if (!ih) return;
(void)call_data;
(void)w;
iupAttribSetStr(ih, "VALUE", NULL);
iupAttribSetStr(ih, "STATUS", "-1");
iupAttribSetStr(ih, "_IUP_WM_DELETE", "1");
}
static int motFileDlgGetMultipleFiles(Ihandle* ih, const char* dir, Widget wList)
{
int *pos, sel_count, dir_len;
int i, len, cur_len;
char *filename, *all_names;
Iarray* names_array;
XmString* items;
if (!XmListGetSelectedPos(wList, &pos, &sel_count))
return 0;
names_array = iupArrayCreate(1024, 1); /* just set an initial size, but count is 0 */
XtVaGetValues(wList, XmNitems, &items, NULL);
cur_len = strlen(dir);
all_names = iupArrayAdd(names_array, cur_len+1);
memcpy(all_names, dir, cur_len);
all_names[cur_len] = '|';
dir_len = cur_len;
cur_len++; /* skip separator */
for (i = 0; i<sel_count; i++)
{
filename = iupmotConvertString(items[pos[i]-1]); /* XmListGetSelectedPos starts at 1 */
len = strlen(filename)-dir_len;
cur_len = iupArrayCount(names_array);
all_names = iupArrayAdd(names_array, len+1);
memcpy(all_names+cur_len, filename+dir_len, len);
all_names[cur_len+len] = '|';
}
XtFree((char*)pos);
cur_len = iupArrayCount(names_array);
all_names = iupArrayInc(names_array);
all_names[cur_len+1] = 0;
iupAttribStoreStr(ih, "VALUE", all_names);
iupArrayDestroy(names_array);
return 1;
}
static void motFileDlgCallback(Widget w, Ihandle* ih, XmFileSelectionBoxCallbackStruct* call_data)
{
(void)w;
if (call_data->reason == XmCR_OK)
{
int dialogtype = iupAttribGetInt(ih, "_IUPDLG_DIALOGTYPE");
char* filename;
XmStringGetLtoR(call_data->value, XmSTRING_DEFAULT_CHARSET, &filename);
iupAttribStoreStr(ih, "VALUE", filename);
XtFree(filename);
if (!motFileDlgCheckValue(ih, w))
return;
if (dialogtype == IUP_DIALOGDIR)
{
iupAttribSetStr(ih, "STATUS", "0");
iupAttribSetStr(ih, "FILEEXIST", NULL);
}
else if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
{
Widget wList = XmFileSelectionBoxGetChild(w, XmDIALOG_LIST);
/* VALUE obtained above contains exactly the DIRECTORY */
char* dir = iupAttribGet(ih, "VALUE");
int len = strlen(dir);
if (dir[len-1]=='/') dir[len-1] = 0; /* remove last '/' */
iupAttribStoreStr(ih, "DIRECTORY", dir);
if (!motFileDlgGetMultipleFiles(ih, iupAttribGet(ih, "DIRECTORY"), wList))
{
iupStrMessageShowError(ih, "IUP_FILENOTEXIST");
return;
}
iupAttribSetStr(ih, "STATUS", "0");
iupAttribSetStr(ih, "FILEEXIST", "YES");
}
else
{
IFnss file_cb = (IFnss)IupGetCallback(ih, "FILE_CB");
filename = iupAttribGet(ih, "VALUE");
if (file_cb && file_cb(ih, filename, "OK") == IUP_IGNORE)
return;
if (iupdrvIsFile(filename)) /* check if file exists */
{
char* dir = iupStrFileGetPath(filename);
iupAttribStoreStr(ih, "DIRECTORY", dir);
free(dir);
iupAttribSetStr(ih, "FILEEXIST", "YES");
iupAttribSetStr(ih, "STATUS", "0");
}
else
{
iupAttribSetStr(ih, "FILEEXIST", "NO");
iupAttribSetStr(ih, "STATUS", "1");
}
}
if (!iupAttribGetBoolean(ih, "NOCHANGEDIR")) /* do change the current directory */
{
/* XmFileSelection does not change the current directory */
XmString xm_dir;
char* dir;
XtVaGetValues(w, XmNdirectory, &xm_dir, NULL);
XmStringGetLtoR(xm_dir, XmSTRING_DEFAULT_CHARSET, &dir);
iupdrvSetCurrentDirectory(dir);
XtFree(dir);
}
}
else if (call_data->reason == XmCR_CANCEL)
{
iupAttribSetStr(ih, "VALUE", NULL);
iupAttribSetStr(ih, "FILEEXIST", NULL);
iupAttribSetStr(ih, "STATUS", "-1");
}
}
static void motFileDlgHelpCallback(Widget w, Ihandle *ih, XtPointer call_data)
{
Icallback cb = IupGetCallback(ih, "HELP_CB");
if (cb && cb(ih) == IUP_CLOSE)
{
iupAttribSetStr(ih, "VALUE", NULL);
iupAttribSetStr(ih, "FILEEXIST", NULL);
iupAttribSetStr(ih, "STATUS", "-1");
}
(void)call_data;
(void)w;
}
typedef struct _ImotPromt
{
XmString xm_dir;
int ret_code;
} ImotPromt;
static void motFileDlgPromptCallback(Widget w, ImotPromt* prompt, XmSelectionBoxCallbackStruct* cbs)
{
if (cbs->reason == XmCR_OK)
prompt->xm_dir = XmStringCopy(cbs->value);
prompt->ret_code = 1;
XtDestroyWidget(XtParent(w));
}
static XmString motFileDlgPrompt(Widget parent, const char* message)
{
Widget promptbox;
Arg args[2];
ImotPromt prompt;
XmString title;
XtSetArg(args[0], XmNautoUnmanage, False);
XtSetArg(args[1], XmNdialogStyle, XmDIALOG_FULL_APPLICATION_MODAL);
promptbox = XmCreatePromptDialog(parent, "filedlg_prompt", args, 2);
iupmotSetString(promptbox, XmNselectionLabelString, message);
XtVaGetValues(parent, XmNdialogTitle, &title, NULL);
XtVaSetValues(promptbox, XmNdialogTitle, title, NULL);
prompt.ret_code = 0;
prompt.xm_dir = NULL;
XtAddCallback(promptbox, XmNokCallback, (XtCallbackProc)motFileDlgPromptCallback, (XtPointer)&prompt);
XtAddCallback(promptbox, XmNcancelCallback, (XtCallbackProc)motFileDlgPromptCallback, (XtPointer)&prompt);
XtUnmanageChild(XmSelectionBoxGetChild(promptbox, XmDIALOG_HELP_BUTTON));
XtManageChild(promptbox);
while (prompt.ret_code == 0)
XtAppProcessEvent(iupmot_appcontext, XtIMAll);
XtUnmanageChild(promptbox);
return prompt.xm_dir;
}
static void motFileDlgNewFolderCallback(Widget w, Widget filebox, XtPointer call_data)
{
XmString xm_new_dir = motFileDlgPrompt(filebox, iupStrMessageGet("IUP_NAMENEWFOLDER"));
if (xm_new_dir)
{
XmString xm_dir;
XtVaGetValues(filebox, XmNdirectory, &xm_dir, NULL);
xm_dir = XmStringConcat(xm_dir, xm_new_dir);
{
char* dir;
XmStringGetLtoR(xm_dir, XmSTRING_DEFAULT_CHARSET, &dir);
iupdrvMakeDirectory(dir);
XtFree(dir);
}
XtVaSetValues(filebox, XmNdirectory, xm_dir, NULL);
XmStringFree(xm_dir);
XmStringFree(xm_new_dir);
}
(void)call_data;
(void)w;
}
static void motFileDlgPreviewCanvasResizeCallback(Widget w, Ihandle *ih, XtPointer call_data)
{
Dimension width, height;
XtVaGetValues(w, XmNwidth, &width,
XmNheight, &height,
NULL);
iupAttribSetInt(ih, "PREVIEWWIDTH", width);
iupAttribSetInt(ih, "PREVIEWHEIGHT", height);
(void)call_data;
}
static void motFileDlgUpdatePreviewGLCanvas(Ihandle* ih)
{
Ihandle* glcanvas = IupGetAttributeHandle(ih, "PREVIEWGLCANVAS");
if (glcanvas)
{
iupAttribSetStr(glcanvas, "XWINDOW", iupAttribGet(ih, "XWINDOW"));
glcanvas->iclass->Map(glcanvas);
}
}
static void motFileDlgPreviewCanvasInit(Ihandle *ih, Widget w)
{
XSetWindowAttributes attrs;
GC gc = XCreateGC(iupmot_display, XtWindow(w), 0, NULL);
iupAttribSetStr(ih, "PREVIEWDC", (char*)gc);
iupAttribSetStr(ih, "WID", (char*)w);
iupAttribSetStr(ih, "XWINDOW", (char*)XtWindow(w));
iupAttribSetStr(ih, "XDISPLAY", (char*)iupmot_display);
motFileDlgUpdatePreviewGLCanvas(ih);
attrs.bit_gravity = ForgetGravity; /* For the DrawingArea widget gets Expose events when you resize it to be smaller. */
attrs.background_pixmap = None;
XChangeWindowAttributes(iupmot_display, XtWindow(w), CWBitGravity|CWBackPixmap, &attrs);
}
static void motFileDlgPreviewCanvasExposeCallback(Widget w, Ihandle *ih, XtPointer call_data)
{
Widget filebox = (Widget)iupAttribGet(ih, "_IUPDLG_FILEBOX");
char* filename;
XmString xm_file;
IFnss cb;
if (!iupAttribGet(ih, "PREVIEWDC"))
motFileDlgPreviewCanvasInit(ih, w);
XtVaGetValues(filebox, XmNdirSpec, &xm_file, NULL);
XmStringGetLtoR(xm_file, XmSTRING_DEFAULT_CHARSET, &filename);
cb = (IFnss)IupGetCallback(ih, "FILE_CB");
if (iupdrvIsFile(filename))
cb(ih, filename, "PAINT");
else
cb(ih, NULL, "PAINT");
XtFree(filename);
(void)call_data;
(void)w;
}
static void motFileDlgBrowseSelectionCallback(Widget w, Ihandle* ih, XmListCallbackStruct* list_data)
{
char* filename;
IFnss cb;
XmStringGetLtoR(list_data->item, XmSTRING_DEFAULT_CHARSET, &filename);
cb = (IFnss)IupGetCallback(ih, "FILE_CB");
if (iupdrvIsFile(filename))
cb(ih, filename, "SELECT");
else
cb(ih, filename, "OTHER");
XtFree(filename);
(void)w;
}
static int motFileDlgPopup(Ihandle* ih, int x, int y)
{
InativeHandle* parent = iupDialogGetNativeParent(ih);
Widget filebox, dialog;
int dialogtype, style = XmDIALOG_FULL_APPLICATION_MODAL;
IFnss file_cb = NULL;
Widget preview_canvas = NULL;
char* value;
iupAttribSetInt(ih, "_IUPDLG_X", x); /* used in iupDialogUpdatePosition */
iupAttribSetInt(ih, "_IUPDLG_Y", y);
value = iupAttribGetStr(ih, "DIALOGTYPE");
if (iupStrEqualNoCase(value, "SAVE"))
dialogtype = IUP_DIALOGSAVE;
else if (iupStrEqualNoCase(value, "DIR"))
dialogtype = IUP_DIALOGDIR;
else
dialogtype = IUP_DIALOGOPEN;
iupAttribSetInt(ih, "_IUPDLG_DIALOGTYPE", dialogtype);
if (parent)
{
filebox = XmCreateFileSelectionDialog(parent, "filedialog", NULL, 0);
dialog = XtParent(filebox);
}
else
{
dialog = XtAppCreateShell(NULL, "filedialog", topLevelShellWidgetClass, iupmot_display, NULL, 0);
filebox = XmCreateFileSelectionBox(dialog, "filebox", NULL, 0);
style = XmDIALOG_MODELESS;
XtVaSetValues(dialog,
XmNmwmInputMode, MWM_INPUT_FULL_APPLICATION_MODAL,
XmNmappedWhenManaged, False,
XmNsaveUnder, True,
NULL);
}
if (!filebox)
return IUP_NOERROR;
if (!iupAttribGetBoolean(ih, "SHOWHIDDEN"))
XtVaSetValues(filebox, XmNfileFilterStyle, XmFILTER_HIDDEN_FILES, NULL);
value = iupAttribGet(ih, "TITLE");
if (!value)
{
if (dialogtype == IUP_DIALOGSAVE)
value = "IUP_SAVEAS";
else if (dialogtype == IUP_DIALOGOPEN)
value = "IUP_OPEN";
else
value = "IUP_SELECTDIR";
iupAttribSetStr(ih, "TITLE", iupStrMessageGet(value));
}
iupmotSetString(filebox, XmNdialogTitle, value);
XtVaSetValues(filebox,
XmNdialogStyle, style,
XmNautoUnmanage, False,
NULL);
if (dialogtype == IUP_DIALOGDIR)
XtVaSetValues(filebox, XmNfileTypeMask, XmFILE_DIRECTORY, NULL);
if (iupAttribGetBoolean(ih, "MULTIPLEFILES"))
{
Widget wList = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST);
XtVaSetValues(wList, XmNselectionPolicy, XmEXTENDED_SELECT, NULL);
XtAddCallback(wList, XmNextendedSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);
}
/* just check for the path inside FILE */
value = iupAttribGet(ih, "FILE");
if (value && value[0] == '/')
{
char* dir = iupStrFileGetPath(value);
iupAttribStoreStr(ih, "DIRECTORY", dir);
free(dir);
}
/* set XmNdirectory before XmNpattern and before XmNdirSpec */
value = iupAttribGet(ih, "DIRECTORY");
if (value)
iupmotSetString(filebox, XmNdirectory, value);
value = iupAttribGet(ih, "FILTER");
if (value)
{
char *filter = value;
char *p = strchr(value, ';');
if (p)
{
int size = p-value;
filter = (char*)malloc(size+1);
memcpy(filter, value, size);
filter[size] = 0;
}
iupmotSetString(filebox, XmNpattern, filter);
if (filter != value)
free(filter);
}
value = iupAttribGet(ih, "FILE");
if (value)
{
char* file = value;
if (value[0] != '/') /* if does not contains a full path, then add the directory */
{
char* cur_dir = NULL;
char* dir = iupAttribGet(ih, "DIRECTORY");
if (!dir)
{
cur_dir = iupdrvGetCurrentDirectory();
dir = cur_dir;
}
file = iupStrFileMakeFileName(dir, value);
if (cur_dir)
free(cur_dir);
}
/* clear value before setting. Do not know why we have to do this,
but if not cleared it will fail to set the XmNdirSpec value. */
iupmotSetString(filebox, XmNdirSpec, "");
iupmotSetString(filebox, XmNdirSpec, file);
if (file != value)
free(file);
}
if (!IupGetCallback(ih, "HELP_CB"))
XtUnmanageChild(XmFileSelectionBoxGetChild(filebox, XmDIALOG_HELP_BUTTON));
XtAddCallback(filebox, XmNokCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih);
XtAddCallback(filebox, XmNcancelCallback, (XtCallbackProc)motFileDlgCallback, (XtPointer)ih);
XtAddCallback(filebox, XmNhelpCallback, (XtCallbackProc)motFileDlgHelpCallback, (XtPointer)ih);
if (dialogtype == IUP_DIALOGDIR)
{
Widget new_folder = XtVaCreateManagedWidget("new_folder", xmPushButtonWidgetClass, filebox,
XmNlabelType, XmSTRING,
NULL);
iupmotSetString(new_folder, XmNlabelString, iupStrMessageGet("IUP_CREATEFOLDER"));
XtAddCallback(new_folder, XmNactivateCallback, (XtCallbackProc)motFileDlgNewFolderCallback, (XtPointer)filebox);
}
else
{
file_cb = (IFnss)IupGetCallback(ih, "FILE_CB");
if (file_cb)
{
Widget list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_LIST);
XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);
list = XmFileSelectionBoxGetChild(filebox, XmDIALOG_DIR_LIST);
XtAddCallback(list, XmNbrowseSelectionCallback, (XtCallbackProc)motFileDlgBrowseSelectionCallback, (XtPointer)ih);
if (iupAttribGetBoolean(ih, "SHOWPREVIEW"))
{
Widget frame = XtVaCreateManagedWidget("preview_canvas", xmFrameWidgetClass, filebox,
XmNshadowType, XmSHADOW_ETCHED_IN,
NULL);
preview_canvas = XtVaCreateManagedWidget("preview_canvas", xmDrawingAreaWidgetClass, frame,
XmNwidth, 180,
XmNheight, 150,
XmNresizePolicy, XmRESIZE_GROW,
NULL);
XtAddCallback(preview_canvas, XmNexposeCallback, (XtCallbackProc)motFileDlgPreviewCanvasExposeCallback, (XtPointer)ih);
XtAddCallback(preview_canvas, XmNresizeCallback, (XtCallbackProc)motFileDlgPreviewCanvasResizeCallback, (XtPointer)ih);
iupAttribSetStr(ih, "_IUPDLG_FILEBOX", (char*)filebox);
}
}
}
XmAddWMProtocolCallback(dialog, iupmot_wm_deletewindow, motFileDlgCBclose, (XtPointer)ih);
XtManageChild(filebox);
XtRealizeWidget(dialog);
ih->handle = dialog;
iupDialogUpdatePosition(ih);
ih->handle = NULL; /* reset handle */
if (file_cb)
{
if (preview_canvas)
motFileDlgPreviewCanvasInit(ih, preview_canvas);
file_cb(ih, NULL, "INIT");
}
if (style == XmDIALOG_MODELESS)
XtPopup(dialog, XtGrabExclusive);
/* while the user hasn't provided an answer, simulate main loop.
** The answer changes as soon as the user selects one of the
** buttons and the callback routine changes its value. */
iupAttribSetStr(ih, "STATUS", NULL);
while (iupAttribGet(ih, "STATUS") == NULL)
XtAppProcessEvent(iupmot_appcontext, XtIMAll);
if (file_cb)
{
if (preview_canvas)
XFreeGC(iupmot_display, (GC)iupAttribGet(ih, "PREVIEWDC"));
file_cb(ih, NULL, "FINISH");
}
if (!iupAttribGet(ih, "_IUP_WM_DELETE"))
{
XtUnmanageChild(filebox);
if (style == XmDIALOG_MODELESS)
{
XtPopdown(dialog);
XtDestroyWidget(dialog);
}
}
return IUP_NOERROR;
}
void iupdrvFileDlgInitClass(Iclass* ic)
{
ic->DlgPopup = motFileDlgPopup;
iupClassRegisterAttribute(ic, "MULTIPLEFILES", NULL, NULL, NULL, NULL, IUPAF_NO_INHERIT);
}
|