/
iupwin_dialog.c
1522 lines (1298 loc) · 44.7 KB
/
iupwin_dialog.c
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
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** \file
* \brief IupDialog class
*
* See Copyright Notice in "iup.h"
*/
#include <windows.h>
#include <commdlg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#include <stdarg.h>
#include "iup.h"
#include "iupcbs.h"
#include "iup_object.h"
#include "iup_layout.h"
#include "iup_dlglist.h"
#include "iup_attrib.h"
#include "iup_drv.h"
#include "iup_drvinfo.h"
#include "iup_drvfont.h"
#include "iup_focus.h"
#include "iup_str.h"
#define _IUPDLG_PRIVATE
#include "iup_dialog.h"
#include "iup_image.h"
#include "iupwin_drv.h"
#include "iupwin_handle.h"
#include "iupwin_brush.h"
#include "iupwin_info.h"
#define IUPWIN_TRAY_NOTIFICATION 102
static int WM_HELPMSG;
static int winDialogSetBgColorAttrib(Ihandle* ih, const char* value);
static int winDialogSetTrayAttrib(Ihandle *ih, const char *value);
/****************************************************************
Utilities
****************************************************************/
int iupdrvDialogIsVisible(Ihandle* ih)
{
return iupdrvIsVisible(ih);
}
void iupdrvDialogGetSize(Ihandle* ih, InativeHandle* handle, int *w, int *h)
{
RECT rect;
if (!handle)
handle = ih->handle;
GetWindowRect(handle, &rect);
if (w) *w = rect.right-rect.left;
if (h) *h = rect.bottom-rect.top;
}
void iupdrvDialogSetVisible(Ihandle* ih, int visible)
{
ShowWindow(ih->handle, visible? ih->data->cmd_show: SW_HIDE);
}
void iupdrvDialogGetPosition(Ihandle *ih, InativeHandle* handle, int *x, int *y)
{
RECT rect;
if (!handle)
handle = ih->handle;
GetWindowRect(handle, &rect);
if (x) *x = rect.left;
if (y) *y = rect.top;
}
void iupdrvDialogSetPosition(Ihandle *ih, int x, int y)
{
/* Only moves the window and places it at the top of the Z order. */
SetWindowPos(ih->handle, HWND_TOP, x, y, 0, 0, SWP_NOSIZE);
}
static void winDialogGetWindowDecor(Ihandle* ih, int *border, int *caption)
{
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
GetWindowInfo(ih->handle, &wi);
*border = wi.cxWindowBorders;
if (wi.rcClient.bottom == wi.rcClient.top)
*caption = wi.rcClient.bottom - wi.cyWindowBorders;
else
{
/* caption = window height - top border - client height */
*caption = (wi.rcWindow.bottom-wi.rcWindow.top) - 2*wi.cyWindowBorders - (wi.rcClient.bottom-wi.rcClient.top);
}
}
void iupdrvDialogGetDecoration(Ihandle* ih, int *border, int *caption, int *menu)
{
if (ih->data->menu)
*menu = iupdrvMenuGetMenuBarSize(ih->data->menu);
else
*menu = 0;
if (ih->handle)
{
winDialogGetWindowDecor(ih, border, caption);
if (*menu)
*caption -= *menu;
}
else
{
int has_titlebar = iupAttribGetBoolean(ih, "MAXBOX") ||
iupAttribGetBoolean(ih, "MINBOX") ||
iupAttribGetBoolean(ih, "MENUBOX") ||
IupGetAttribute(ih, "TITLE"); /* must use IupGetAttribute to check from the native implementation */
*caption = 0;
if (has_titlebar)
{
if (iupAttribGetBoolean(ih, "TOOLBOX") && iupAttribGet(ih, "PARENTDIALOG"))
*caption = GetSystemMetrics(SM_CYSMCAPTION); /* tool window */
else
*caption = GetSystemMetrics(SM_CYCAPTION); /* normal window */
}
*border = 0;
if (iupAttribGetBoolean(ih, "RESIZE"))
{
/* has_border */
*border = GetSystemMetrics(SM_CXFRAME); /* Thickness of the sizing border around the perimeter of a window */
} /* that can be resized, in pixels. */
else if (has_titlebar)
{
/* has_border */
*border = GetSystemMetrics(SM_CXFIXEDFRAME); /* Thickness of the frame around the perimeter of a window */
} /* that has a caption but is not sizable, in pixels. */
else if (iupAttribGetBoolean(ih, "BORDER"))
{
/* has_border */
*border = GetSystemMetrics(SM_CXBORDER);
}
}
}
int iupdrvDialogSetPlacement(Ihandle* ih)
{
char* placement;
ih->data->cmd_show = SW_SHOWNORMAL;
ih->data->show_state = IUP_SHOW;
if (iupAttribGetBoolean(ih, "FULLSCREEN"))
return 1;
placement = iupAttribGet(ih, "PLACEMENT");
if (!placement)
{
if (IsIconic(ih->handle) || IsZoomed(ih->handle))
ih->data->show_state = IUP_RESTORE;
return 0;
}
if (iupStrEqualNoCase(placement, "MAXIMIZED"))
{
ih->data->cmd_show = SW_SHOWMAXIMIZED;
ih->data->show_state = IUP_MAXIMIZE;
}
else if (iupStrEqualNoCase(placement, "MINIMIZED"))
{
ih->data->cmd_show = SW_SHOWMINIMIZED;
ih->data->show_state = IUP_MINIMIZE;
}
else if (iupStrEqualNoCase(placement, "FULL"))
{
int width, height, x, y;
int caption, border, menu;
iupdrvDialogGetDecoration(ih, &border, &caption, &menu);
/* the dialog will cover the task bar */
iupdrvGetFullSize(&width, &height);
/* position the decoration and menu outside the screen */
x = -(border);
y = -(border+caption+menu);
width += 2*border;
height += 2*border + caption + menu;
/* set the new size and position */
/* WM_SIZE will update the layout */
SetWindowPos(ih->handle, HWND_TOP, x, y, width, height, 0);
if (IsIconic(ih->handle) || IsZoomed(ih->handle))
ih->data->show_state = IUP_RESTORE;
}
iupAttribSetStr(ih, "PLACEMENT", NULL); /* reset to NORMAL */
return 1;
}
static void winDialogMDIRefreshMenu(Ihandle* ih)
{
/* We manually update the menu when a MDI child is added or removed. */
Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
PostMessage(client->handle, WM_MDIREFRESHMENU, 0, 0);
}
static int winDialogMDICloseChildren(Ihandle* ih)
{
Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
if (iupObjectCheck(client))
{
HWND hWndChild = (HWND)SendMessage(client->handle, WM_MDIGETACTIVE, 0, 0);
/* As long as the MDI client has a child, close it */
while (hWndChild)
{
Ihandle* child = iupwinHandleGet(hWndChild);
if (iupObjectCheck(child) && iupAttribGetBoolean(child, "MDICHILD"))
{
Icallback cb = IupGetCallback(child, "CLOSE_CB");
if (cb)
{
int ret = cb(child);
if (ret == IUP_IGNORE)
return 0;
if (ret == IUP_CLOSE)
IupExitLoop();
}
IupDestroy(child);
}
hWndChild = (HWND)SendMessage(client->handle, WM_MDIGETACTIVE, 0, 0);
}
}
return 1;
}
/****************************************************************************
WindowProc
****************************************************************************/
static Ihandle* winMinMaxHandle = NULL;
static int winDialogCheckMinMaxInfo(Ihandle* ih, MINMAXINFO* minmax)
{
int min_w = 1, min_h = 1; /* MINSIZE default value */
int max_w = 65535, max_h = 65535; /* MAXSIZE default value */
iupStrToIntInt(iupAttribGet(ih, "MINSIZE"), &min_w, &min_h, 'x');
iupStrToIntInt(iupAttribGet(ih, "MAXSIZE"), &max_w, &max_h, 'x');
minmax->ptMinTrackSize.x = min_w;
minmax->ptMinTrackSize.y = min_h;
minmax->ptMaxTrackSize.x = max_w;
minmax->ptMaxTrackSize.y = max_h;
if (winMinMaxHandle == ih)
winMinMaxHandle = NULL;
return 1;
}
static void winDialogResize(Ihandle* ih, int width, int height)
{
IFnii cb;
iupdrvDialogGetSize(ih, NULL, &(ih->currentwidth), &(ih->currentheight));
cb = (IFnii)IupGetCallback(ih, "RESIZE_CB");
if (!cb || cb(ih, width, height)!=IUP_IGNORE) /* width and height here are for the client area */
{
ih->data->ignore_resize = 1;
IupRefresh(ih);
ih->data->ignore_resize = 0;
}
}
static int winDialogBaseProc(Ihandle* ih, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result)
{
if (iupwinBaseContainerProc(ih, msg, wp, lp, result))
return 1;
iupwinMenuDialogProc(ih, msg, wp, lp);
switch (msg)
{
case WM_GETMINMAXINFO:
{
if (winDialogCheckMinMaxInfo(ih, (MINMAXINFO*)lp))
{
*result = 0;
return 1;
}
break;
}
case WM_MOVE:
{
IFnii cb = (IFnii)IupGetCallback(ih, "MOVE_CB");
int x, y;
/* ignore LPARAM because they are the clientpos */
iupdrvDialogGetPosition(ih, NULL, &x, &y);
if (cb) cb(ih, x, y);
break;
}
case WM_SIZE:
{
if (ih->data->ignore_resize)
break;
switch(wp)
{
case SIZE_MINIMIZED:
{
if (ih->data->show_state != IUP_MINIMIZE)
{
IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
ih->data->show_state = IUP_MINIMIZE;
if (show_cb && show_cb(ih, IUP_MINIMIZE) == IUP_CLOSE)
IupExitLoop();
}
break;
}
case SIZE_MAXIMIZED:
{
if (ih->data->show_state != IUP_MAXIMIZE)
{
IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
ih->data->show_state = IUP_MAXIMIZE;
if (show_cb && show_cb(ih, IUP_MAXIMIZE) == IUP_CLOSE)
IupExitLoop();
}
winDialogResize(ih, LOWORD(lp), HIWORD(lp));
if (iupAttribGetBoolean(ih, "MDICHILD"))
{
/* WORKAROUND: when a child MDI dialog is maximized,
its title is displayed inside the MDI client area.
So we force a MDI client size update */
RECT rect;
Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
GetClientRect(client->handle, &rect);
PostMessage(client->handle, WM_SIZE, (WPARAM)SIZE_RESTORED, MAKELPARAM(rect.right-rect.left, rect.bottom-rect.top));
}
break;
}
case SIZE_RESTORED:
{
if (ih->data->show_state == IUP_MAXIMIZE || ih->data->show_state == IUP_MINIMIZE)
{
IFni show_cb = (IFni)IupGetCallback(ih, "SHOW_CB");
ih->data->show_state = IUP_RESTORE;
if (show_cb && show_cb(ih, IUP_RESTORE) == IUP_CLOSE)
IupExitLoop();
}
winDialogResize(ih, LOWORD(lp), HIWORD(lp));
break;
}
}
if (iupAttribGetBoolean(ih, "MDIFRAME"))
{
/* We are going to manually position the MDI client,
so abort MDI frame processing. */
*result = 0;
return 1;
}
else
break;
}
case WM_USER+IUPWIN_TRAY_NOTIFICATION:
{
int dclick = 0;
int button = 0;
int pressed = 0;
switch (lp)
{
case WM_LBUTTONDOWN:
pressed = 1;
button = 1;
break;
case WM_MBUTTONDOWN:
pressed = 1;
button = 2;
break;
case WM_RBUTTONDOWN:
pressed = 1;
button = 3;
break;
case WM_LBUTTONDBLCLK:
dclick = 1;
button = 1;
break;
case WM_MBUTTONDBLCLK:
dclick = 1;
button = 2;
break;
case WM_RBUTTONDBLCLK:
dclick = 1;
button = 3;
break;
case WM_LBUTTONUP:
button = 1;
break;
case WM_MBUTTONUP:
button = 2;
break;
case WM_RBUTTONUP:
button = 3;
break;
}
if (button != 0)
{
IFniii cb = (IFniii)IupGetCallback(ih, "TRAYCLICK_CB");
if (cb && cb(ih, button, pressed, dclick) == IUP_CLOSE)
IupExitLoop();
}
break;
}
case WM_CLOSE:
{
Icallback cb = IupGetCallback(ih, "CLOSE_CB");
if (cb)
{
int ret = cb(ih);
if (ret == IUP_IGNORE)
{
*result = 0;
return 1;
}
if (ret == IUP_CLOSE)
IupExitLoop();
}
/* child mdi is automatically destroyed */
if (iupAttribGetBoolean(ih, "MDICHILD"))
IupDestroy(ih);
else
{
if (!winDialogMDICloseChildren(ih))
{
*result = 0;
return 1;
}
IupHide(ih); /* IUP default processing */
}
*result = 0;
return 1;
}
case WM_COPYDATA: /* usually from SetGlobal("SINGLEINSTANCE") */
{
COPYDATASTRUCT* cds = (COPYDATASTRUCT*)lp;
IFnsi cb = (IFnsi)IupGetCallback(ih, "COPYDATA_CB");
if (cb) cb(ih, cds->lpData, cds->cbData);
break;
}
case WM_SETCURSOR:
{
if (ih->handle == (HWND)wp && LOWORD(lp)==HTCLIENT)
{
HCURSOR hCur = (HCURSOR)iupAttribGet(ih, "_IUPWIN_HCURSOR");
if (hCur)
{
SetCursor(hCur);
*result = 1;
return 1;
}
else if (iupAttribGet(ih, "CURSOR"))
{
SetCursor(NULL);
*result = 1;
return 1;
}
}
break;
}
case WM_ERASEBKGND:
{
HBITMAP hBitmap = (HBITMAP)iupAttribGet(ih, "_IUPWIN_BACKGROUND_BITMAP");
if (hBitmap)
{
RECT rect;
HDC hdc = (HDC)wp;
HBRUSH hBrush = CreatePatternBrush(hBitmap);
GetClientRect(ih->handle, &rect);
FillRect(hdc, &rect, hBrush);
DeleteObject(hBrush);
/* return non zero value */
*result = 1;
return 1;
}
else
{
unsigned char r, g, b;
char* color = iupAttribGet(ih, "_IUPWIN_BACKGROUND_COLOR");
if (iupStrToRGB(color, &r, &g, &b))
{
RECT rect;
HDC hdc = (HDC)wp;
SetDCBrushColor(hdc, RGB(r,g,b));
GetClientRect(ih->handle, &rect);
FillRect(hdc, &rect, (HBRUSH)GetStockObject(DC_BRUSH));
/* return non zero value */
*result = 1;
return 1;
}
}
break;
}
case WM_DESTROY:
{
/* Since WM_CLOSE changed the Windows default processing */
/* WM_DESTROY is NOT received by IupDialogs */
/* Except when they are children of other IupDialogs and the parent is destroyed. */
/* So we have to destroy the child dialog. */
/* The application is responsable for destroying the children before this happen. */
IupDestroy(ih);
break;
}
}
if (msg == (UINT)WM_HELPMSG)
{
Ihandle* child = NULL;
DWORD* struct_ptr = (DWORD*)lp;
if (*struct_ptr == sizeof(CHOOSECOLOR))
{
CHOOSECOLOR* choosecolor = (CHOOSECOLOR*)lp;
child = (Ihandle*)choosecolor->lCustData;
}
if (*struct_ptr == sizeof(CHOOSEFONT))
{
CHOOSEFONT* choosefont = (CHOOSEFONT*)lp;
child = (Ihandle*)choosefont->lCustData;
}
if (child)
{
Icallback cb = IupGetCallback(child, "HELP_CB");
if (cb && cb(child) == IUP_CLOSE)
EndDialog((HWND)iupAttribGet(child, "HWND"), IDCANCEL);
}
}
return 0;
}
static LRESULT CALLBACK winDialogProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
LRESULT result;
Ihandle *ih = iupwinHandleGet(hwnd);
if (!ih)
{
/* the first time WM_GETMINMAXINFO is called, Ihandle is not associated yet */
if (msg == WM_GETMINMAXINFO && winMinMaxHandle)
{
if (winDialogCheckMinMaxInfo(winMinMaxHandle, (MINMAXINFO*)lp))
return 0;
}
return DefWindowProc(hwnd, msg, wp, lp);
}
if (winDialogBaseProc(ih, msg, wp, lp, &result))
return result;
return DefWindowProc(hwnd, msg, wp, lp);
}
static LRESULT CALLBACK winDialogMDIChildProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
LRESULT result;
Ihandle *ih = iupwinHandleGet(hwnd);
if (!ih)
{
/* the first time WM_GETMINMAXINFO is called, Ihandle is not associated yet */
if (msg == WM_GETMINMAXINFO && winMinMaxHandle)
{
if (winDialogCheckMinMaxInfo(winMinMaxHandle, (MINMAXINFO*)lp))
return 0;
}
return DefMDIChildProc(hwnd, msg, wp, lp);
}
if (msg == WM_MDIACTIVATE)
{
HWND hNewActive = (HWND)lp;
if (hNewActive == ih->handle)
{
Icallback cb = (Icallback)IupGetCallback(ih, "MDIACTIVATE_CB");
if (cb) cb(ih);
}
}
if (winDialogBaseProc(ih, msg, wp, lp, &result))
return result;
return DefMDIChildProc(hwnd, msg, wp, lp);
}
static LRESULT CALLBACK winDialogMDIFrameProc(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)
{
LRESULT result;
HWND hWndClient = NULL;
Ihandle *ih = iupwinHandleGet(hwnd);
if (!ih)
{
/* the first time WM_GETMINMAXINFO is called, Ihandle is not associated yet */
if (msg == WM_GETMINMAXINFO && winMinMaxHandle)
{
if (winDialogCheckMinMaxInfo(winMinMaxHandle, (MINMAXINFO*)lp))
return 0;
}
return DefFrameProc(hwnd, hWndClient, msg, wp, lp);
}
{
Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
if (client) hWndClient = client->handle;
}
if (winDialogBaseProc(ih, msg, wp, lp, &result))
return result;
if (msg == WM_MENUCOMMAND)
{
int menuId = GetMenuItemID((HMENU)lp, (int)wp);
if (menuId >= IUP_MDI_FIRSTCHILD && hWndClient)
{
/* we manually activate the MDI child when its menu item is selected. */
HWND hChild = GetDlgItem(hWndClient, menuId);
if (hChild)
SendMessage(hWndClient, WM_MDIACTIVATE, (WPARAM)hChild, 0);
}
else if (menuId >= SC_SIZE && menuId <= SC_CONTEXTHELP)
{
/* we manually forward the message to the MDI child */
HWND hChild = (HWND)SendMessage(hWndClient, WM_MDIGETACTIVE, 0, 0);
if (hChild)
SendMessage(hChild, WM_SYSCOMMAND, (WPARAM)menuId, 0);
}
}
return DefFrameProc(hwnd, hWndClient, msg, wp, lp);
}
static void winDialogRegisterClass(int mdi)
{
char* name;
WNDCLASS wndclass;
WNDPROC winproc;
ZeroMemory(&wndclass, sizeof(WNDCLASS));
if (mdi == 2)
{
name = "IupDialogMDIChild";
winproc = (WNDPROC)winDialogMDIChildProc;
}
else if (mdi == 1)
{
name = "IupDialogMDIFrame";
winproc = (WNDPROC)winDialogMDIFrameProc;
}
else
{
if (mdi == -1)
name = "IupDialogControl";
else
name = "IupDialog";
winproc = (WNDPROC)winDialogProc;
}
wndclass.hInstance = iupwin_hinstance;
wndclass.lpszClassName = name;
wndclass.lpfnWndProc = (WNDPROC)winproc;
wndclass.hCursor = LoadCursor(NULL, IDC_ARROW);
/* To use a standard system color, must increase the background-color value by one */
if (mdi == 1)
wndclass.hbrBackground = (HBRUSH)(COLOR_APPWORKSPACE+1);
else
wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE+1);
if (mdi == 0)
wndclass.style |= CS_SAVEBITS;
if (mdi == -1)
wndclass.style |= CS_HREDRAW | CS_VREDRAW;
RegisterClass(&wndclass);
}
/****************************************************************
dialog class functions
****************************************************************/
static int winDialogMapMethod(Ihandle* ih)
{
InativeHandle* native_parent;
DWORD dwStyle = WS_CLIPSIBLINGS,
dwExStyle = 0;
int has_titlebar = 0,
has_border = 0;
char* classname = "IupDialog";
char* title = iupAttribGet(ih, "TITLE");
if (title)
has_titlebar = 1;
if (iupAttribGetBoolean(ih, "RESIZE"))
{
dwStyle |= WS_THICKFRAME;
has_border = 1;
}
else
iupAttribSetStr(ih, "MAXBOX", "NO");
if (iupAttribGetBoolean(ih, "MENUBOX"))
{
dwStyle |= WS_SYSMENU;
has_titlebar = 1;
}
if (iupAttribGetBoolean(ih, "MAXBOX"))
{
dwStyle |= WS_MAXIMIZEBOX;
has_titlebar = 1;
}
if (iupAttribGetBoolean(ih, "MINBOX"))
{
dwStyle |= WS_MINIMIZEBOX;
has_titlebar = 1;
}
if (iupAttribGetBoolean(ih, "BORDER") || has_titlebar)
has_border = 1;
if (iupAttribGetBoolean(ih, "MDICHILD"))
{
Ihandle *client;
/* must have a parent dialog (the mdi frame) */
Ihandle* parent = IupGetAttributeHandle(ih, "PARENTDIALOG");
if (!parent || !parent->handle)
return IUP_ERROR;
/* set when the mdi client is mapped */
client = (Ihandle*)iupAttribGet(parent, "MDICLIENT_HANDLE");
if (!client)
return IUP_ERROR;
/* store the mdi client handle in each mdi child also */
iupAttribSetStr(ih, "MDICLIENT_HANDLE", (char*)client);
classname = "IupDialogMDIChild";
/* The actual parent is the mdi client */
native_parent = client->handle;
dwStyle |= WS_CHILD;
if (has_titlebar)
dwStyle |= WS_CAPTION;
else if (has_border)
dwStyle |= WS_BORDER;
if (!IupGetName(ih))
iupAttribSetHandleName(ih);
}
else
{
native_parent = iupDialogGetNativeParent(ih);
if (native_parent)
{
dwStyle |= WS_POPUP;
if (has_titlebar)
dwStyle |= WS_CAPTION;
else if (has_border)
dwStyle |= WS_BORDER;
}
else
{
if (has_titlebar)
{
dwStyle |= WS_OVERLAPPED;
}
else
{
if (has_border)
dwStyle |= WS_POPUP | WS_BORDER;
else
dwStyle |= WS_POPUP;
dwExStyle |= WS_EX_NOACTIVATE; /* this will hide it from the taskbar */
}
}
if (iupAttribGetBoolean(ih, "MDIFRAME"))
{
COLORREF color = GetSysColor(COLOR_BTNFACE);
iupAttribSetStrf(ih, "_IUPWIN_BACKGROUND_COLOR", "%d %d %d", (int)GetRValue(color),
(int)GetGValue(color),
(int)GetBValue(color));
classname = "IupDialogMDIFrame";
}
}
if (iupAttribGetBoolean(ih, "TOOLBOX") && native_parent)
dwExStyle |= WS_EX_TOOLWINDOW | WS_EX_WINDOWEDGE;
if (iupAttribGetBoolean(ih, "DIALOGFRAME") && native_parent)
dwExStyle |= WS_EX_DLGMODALFRAME; /* this will hide the MENUBOX but not the close button */
iupwinGetNativeParentStyle(ih, &dwExStyle, &dwStyle);
if (iupAttribGetBoolean(ih, "HELPBUTTON"))
dwExStyle |= WS_EX_CONTEXTHELP;
if (iupAttribGetBoolean(ih, "CONTROL") && native_parent)
{
/* TODO: this were used by LuaCom to create embeded controls,
don't know if it is still working */
dwStyle = WS_CHILD | WS_TABSTOP | WS_CLIPCHILDREN;
classname = "IupDialogControl";
}
/* CreateWindowEx will send WM_GETMINMAXINFO before Ihandle is associated with HWND */
if (iupAttribGet(ih, "MINSIZE") || iupAttribGet(ih, "MAXSIZE"))
winMinMaxHandle = ih;
/* size will be updated in IupRefresh -> winDialogLayoutUpdate */
/* position will be updated in iupDialogShowXY */
if (iupAttribGetBoolean(ih, "MDICHILD"))
ih->handle = CreateMDIWindow(classname,
title, /* title */
dwStyle, /* style */
0, /* x-position */
0, /* y-position */
100, /* horizontal size - set this to avoid size calculation problems */
100, /* vertical size */
native_parent, /* owner window */
iupwin_hinstance, /* instance of app. */
0); /* no creation parameters */
else
ih->handle = CreateWindowEx(dwExStyle, /* extended styles */
classname, /* class */
title, /* title */
dwStyle, /* style */
0, /* x-position */
0, /* y-position */
100, /* horizontal size - set this to avoid size calculation problems */
100, /* vertical size */
native_parent, /* owner window */
(HMENU)0, /* Menu or child-window identifier */
iupwin_hinstance, /* instance of app. */
NULL); /* no creation parameters */
if (!ih->handle)
return IUP_ERROR;
/* associate HWND with Ihandle*, all Win32 controls must call this. */
iupwinHandleAdd(ih, ih->handle);
if (iupStrEqual(classname, "IupDialogMDIChild")) /* hides the mdi child */
ShowWindow(ih->handle, SW_HIDE);
/* configure for DROP of files */
if (IupGetCallback(ih, "DROPFILES_CB"))
iupAttribSetStr(ih, "DROPFILESTARGET", "YES");
/* Reset attributes handled during creation that */
/* also can be changed later, and can be consulted from the native system. */
iupAttribSetStr(ih, "TITLE", NULL);
/* Ignore VISIBLE before mapping */
iupAttribSetStr(ih, "VISIBLE", NULL);
/* Set the default CmdShow for ShowWindow */
ih->data->cmd_show = SW_SHOWNORMAL;
if (iupAttribGetBoolean(ih, "MDICHILD"))
winDialogMDIRefreshMenu(ih);
return IUP_NOERROR;
}
static void winDialogUnMapMethod(Ihandle* ih)
{
if (ih->data->menu)
{
ih->data->menu->handle = NULL; /* the dialog will destroy the native menu */
IupDestroy(ih->data->menu);
}
if (iupAttribGet(ih, "_IUPDLG_HASTRAY"))
winDialogSetTrayAttrib(ih, NULL);
iupwinTipsDestroy(ih);
iupwinDestroyDragDrop(ih);
/* remove the association before destroying */
iupwinHandleRemove(ih->handle);
/* Destroys the window, so we can destroy the class */
if (iupAttribGetBoolean(ih, "MDICHILD"))
{
/* for MDICHILDs must send WM_MDIDESTROY, instead of calling DestroyWindow */
Ihandle* client = (Ihandle*)iupAttribGet(ih, "MDICLIENT_HANDLE");
SendMessage(client->handle, WM_MDIDESTROY, (WPARAM)ih->handle, 0);
winDialogMDIRefreshMenu(ih);
}
else
DestroyWindow(ih->handle); /* this will destroy the Windows children also. */
/* but IupDestroy already destroyed the IUP children */
/* so it is safe to call DestroyWindow */
}
static void winDialogLayoutUpdateMethod(Ihandle *ih)
{
if (ih->data->ignore_resize)
return;
ih->data->ignore_resize = 1;
/* for dialogs the position is not updated here */
SetWindowPos(ih->handle, 0, 0, 0, ih->currentwidth, ih->currentheight,
SWP_NOMOVE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOSENDCHANGING);
ih->data->ignore_resize = 0;
}
static void winDialogReleaseMethod(Iclass* ic)
{
(void)ic;
if (iupwinClassExist("IupDialog"))
{
UnregisterClass("IupDialog", iupwin_hinstance);
UnregisterClass("IupDialogControl", iupwin_hinstance);
UnregisterClass("IupDialogMDIChild", iupwin_hinstance);
UnregisterClass("IupDialogMDIFrame", iupwin_hinstance);
}
}
/****************************************************************************
Attributes
****************************************************************************/
static char* winDialogGetClientOffsetAttrib(Ihandle *ih)
{
(void)ih;
return "0x0";
}
static char* winDialogGetClientSizeAttrib(Ihandle* ih)
{
char* str = iupStrGetMemory(20);
RECT rect;
GetClientRect(ih->handle, &rect);
sprintf(str, "%dx%d", (int)(rect.right-rect.left), (int)(rect.bottom-rect.top));
return str;
}
static int winDialogSetBgColorAttrib(Ihandle* ih, const char* value)
{
unsigned char r, g, b;
if (iupStrToRGB(value, &r, &g, &b))
{
iupAttribStoreStr(ih, "_IUPWIN_BACKGROUND_COLOR", value);
iupAttribSetStr(ih, "_IUPWIN_BACKGROUND_BITMAP", NULL);
RedrawWindow(ih->handle, NULL, NULL, RDW_INVALIDATE|RDW_ERASE|RDW_ALLCHILDREN); /* post WM_ERASEBKGND and WM_PAINT */
return 1;
}
return 0;
}