-
Notifications
You must be signed in to change notification settings - Fork 5
/
pmgroup.c
2220 lines (1820 loc) · 51.1 KB
/
pmgroup.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
#include <windowsx.h>
#undef HANDLE_WM_CONTEXTMENU
#define HANDLE_WM_CONTEXTMENU(hwnd, wParam, lParam, fn) \
((fn)((hwnd), (HWND)(wParam), GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam)), 0L) // supposed CHEN FIX
#include "progman.h"
#include "ime.h"
#include "pmanfunc.h"
BOOL FAR PASCAL IMEStringWindow(HWND,HANDLE);
int FAR PASCAL IMEWindowGetCnt(LPTSTR,LPTSTR);
#define HK_SHIFT 0x0100
#define HK_CONTROL 0x0200
#define HK_ALT 0x0400
#define HK_EXT 0x0800
#define F_EXT 0x01000000L
#define OBJ_ITEM 1
// GET_WM_* Definitions, pwin32.h
#define GET_WM_COMMAND_ID(wp, lp) LOWORD(wp)
#define GET_WM_VSCROLL_CODE(wp, lp) LOWORD(wp)
#define GET_WM_VSCROLL_POS(wp, lp) HIWORD(wp)
BOOL bNoScrollCalc = FALSE;
RECT rcArrangeRect;
HWND hwndScrolling = NULL;
BOOL APIENTRY InQuotes(LPTSTR sz);
void NEAR PASCAL ViewActiveItem(PGROUP pGroup);
/* Make the first item in a list the last and return a pointer to it.*/
PITEM PASCAL MakeFirstItemLast(PGROUP pGroup)
{
PITEM pItemCur;
/* Just quit if there's no list.*/
if ((pItemCur = pGroup->pItems) == NULL)
return NULL;
/* Find the end of the list.*/
for( ; pItemCur->pNext ; pItemCur = pItemCur->pNext)
;
/* End of the list.*/
/* This works even if there is only one item in the */
/* list, it's a waste of time though.*/
pItemCur->pNext = pGroup->pItems;
pGroup->pItems = pGroup->pItems->pNext;
pItemCur->pNext->pNext = NULL;
return pItemCur->pNext;
}
VOID PASCAL GetItemText(PGROUP pGroup, PITEM pItem, LPTSTR lpT, int index)
{
LPITEMDEF lpid;
LPGROUPDEF lpgd;
lpid = LockItem(pGroup,pItem);
if (!lpid) {
UnlockGroup(pGroup->hwnd);
*lpT = 0;
return;
}
lpgd = (LPGROUPDEF)GlobalLock(pGroup->hGroup);
switch (index) {
case 0:
lstrcpy(lpT, (LPTSTR) PTR(lpgd, lpid->pName));
break;
case 1:
lstrcpy(lpT, (LPTSTR) PTR(lpgd, lpid->pCommand));
break;
case 2:
lstrcpy(lpT, (LPTSTR) PTR(lpgd, lpid->pIconPath));
break;
default:
*lpT = 0;
break;
}
GlobalUnlock(pGroup->hGroup);
UnlockGroup(pGroup->hwnd);
}
ULONG Color16Palette[] = {
0x00000000, 0x00800000, 0x00008000, 0x00808000,
0x00000080, 0x00800080, 0x00008080, 0x00808080,
0x00c0c0c0, 0x00ff0000, 0x0000ff00, 0x00ffff00,
0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
};
ULONG Color256Palette[] = {
0x00000000, 0x00800000, 0x00008000, 0x00808000, 0x00000080, 0x00800080, 0x00008080, 0x00c0c0c0,
0x00c0dcc0, 0x00a6caf0, 0x00cccccc, 0x00580800, 0x00600800, 0x00680800, 0x00700800, 0x00780800,
0x00801000, 0x00881000, 0x00901000, 0x00981000, 0x00a01000, 0x00a81000, 0x00b01000, 0x00b81000,
0x00c01800, 0x00c81800, 0x00d01800, 0x00d81800, 0x00e01800, 0x00e81800, 0x00f01800, 0x00f81800,
0x00002000, 0x00082000, 0x00102000, 0x00182000, 0x00202000, 0x00282000, 0x00302000, 0x00382000,
0x00402800, 0x00482800, 0x00502800, 0x00582800, 0x00602800, 0x00682800, 0x00702800, 0x00782800,
0x00803000, 0x00883000, 0x00903000, 0x00983000, 0x00a03000, 0x00a83000, 0x00b03000, 0x00b83000,
0x00c03800, 0x00c83800, 0x00d03800, 0x00d83800, 0x00e03800, 0x00e83800, 0x00f03800, 0x00f83800,
0x00004010, 0x00084010, 0x00104010, 0x00184010, 0x00204010, 0x00284010, 0x00304010, 0x00384010,
0x00404810, 0x00484810, 0x00504810, 0x00584810, 0x00604810, 0x00684810, 0x00704810, 0x00784810,
0x00805010, 0x00885010, 0x00905010, 0x00985010, 0x00a05010, 0x00a85010, 0x00b05010, 0x00b85010,
0x00c05810, 0x00c85810, 0x00d05810, 0x00d85810, 0x00e05810, 0x00e85810, 0x00f05810, 0x00f85810,
0x00006010, 0x00086010, 0x00106010, 0x00186010, 0x00206010, 0x00286010, 0x00306010, 0x00386010,
0x00406810, 0x00486810, 0x00506810, 0x00586810, 0x00606810, 0x00686810, 0x00706810, 0x00786810,
0x00807010, 0x00887010, 0x00907010, 0x00987010, 0x00a07010, 0x00a87010, 0x00b07010, 0x00b87010,
0x00c07810, 0x00c87810, 0x00d07810, 0x00d87810, 0x00e07810, 0x00e87810, 0x00f07810, 0x00f87810,
0x00008020, 0x00088020, 0x00108020, 0x00188020, 0x00208020, 0x00288020, 0x00308020, 0x00388020,
0x00408820, 0x00488820, 0x00508820, 0x00588820, 0x00608820, 0x00688820, 0x00708820, 0x00788820,
0x00809020, 0x00889020, 0x00909020, 0x00989020, 0x00a09020, 0x00a89020, 0x00b09020, 0x00b89020,
0x00c09820, 0x00c89820, 0x00d09820, 0x00d89820, 0x00e09820, 0x00e89820, 0x00f09820, 0x00f89820,
0x0000a020, 0x0008a020, 0x0010a020, 0x0018a020, 0x0020a020, 0x0028a020, 0x0030a020, 0x0038a020,
0x0040a820, 0x0048a820, 0x0050a820, 0x0058a820, 0x0060a820, 0x0068a820, 0x0070a820, 0x0078a820,
0x0080b020, 0x0088b020, 0x0090b020, 0x0098b020, 0x00a0b020, 0x00a8b020, 0x00b0b020, 0x00b8b020,
0x00c0b820, 0x00b820c8, 0x00b820d0, 0x00b820d8, 0x00b820e0, 0x00b820e8, 0x00b820f0, 0x00b820f8,
0x0000c030, 0x00c03008, 0x00c03010, 0x00c03018, 0x00c03020, 0x00c03028, 0x00c03030, 0x00c03038,
0x0040c830, 0x00c83048, 0x00c83050, 0x00c83058, 0x00c83060, 0x00c83068, 0x00c83070, 0x00c83078,
0x0080d030, 0x00d03088, 0x00d03090, 0x00d03098, 0x00d030a0, 0x00d030a8, 0x00d030b0, 0x00d030b8,
0x00c0d830, 0x00c8d830, 0x00d0d830, 0x00d8d830, 0x00e0d830, 0x00e8d830, 0x00f0d830, 0x00f8d830,
0x0000e030, 0x0008e030, 0x0010e030, 0x0018e030, 0x0020e030, 0x0028e030, 0x0030e030, 0x0038e030,
0x0040e830, 0x0048e830, 0x0050e830, 0x0058e830, 0x0060e830, 0x0068e830, 0x0070e830, 0x0078e830,
0x0080f030, 0x0088f030, 0x0090f030, 0x0098f030, 0x00a0f030, 0x00a8f030, 0x00fffbf0, 0x00a0a0a4,
0x00808080, 0x00ff0000, 0x0000ff00, 0x00ffff00, 0x000000ff, 0x00ff00ff, 0x0000ffff, 0x00ffffff
};
HICON APIENTRY GetItemIcon(HWND hwnd, PITEM pitem)
{
LPGROUPDEF lpgd;
LPITEMDEF lpid;
HICON hIcon = NULL;
DWORD dwVer;
HANDLE h;
LPBYTE p;
INT id = 0;
INT cb;
DWORD colors, size;
PBITMAPINFOHEADER pbih, pbihNew;
LPVOID palette;
lpgd = LockGroup(hwnd);
if (!lpgd)
return DuplicateIcon(hAppInstance, hItemIcon);
//return hItemIcon;
lpid = ITEM(lpgd,pitem->iItem);
if ((SHORT)lpid->cbIconRes > 0) {
if (lpid->wIconVer == 2)
dwVer = 0x00020000;
else
dwVer = 0x00030000;
pbihNew = NULL;
pbih = (PBITMAPINFOHEADER)PTR(lpgd, lpid->pIconRes);
size = lpid->cbIconRes;
if (pbih->biClrUsed == -1) {
colors = (1 << (pbih->biPlanes * pbih->biBitCount));
size += colors * sizeof(RGBQUAD);
if (colors == 16) {
palette = Color16Palette;
} else if (colors == 256) {
palette = Color256Palette;
} else {
palette = NULL;
}
if (palette != NULL)
pbihNew = (PBITMAPINFOHEADER)LocalAlloc(LPTR, size);
if (pbihNew != NULL) {
RtlCopyMemory(pbihNew, pbih, sizeof( *pbih ));
pbihNew->biClrUsed = 0;
RtlCopyMemory((pbihNew+1), palette, colors * sizeof(RGBQUAD));
RtlCopyMemory((PCHAR)(pbihNew+1) + (colors * sizeof(RGBQUAD)),
(pbih+1),
lpid->cbIconRes - sizeof(*pbih)
);
pbih = pbihNew;
}
else {
//
// reset size
//
size = lpid->cbIconRes;
}
}
hIcon = CreateIconFromResource((PBYTE)pbih, size, TRUE, dwVer);
if (pbihNew != NULL)
LocalFree(pbihNew);
}
if (!hIcon) {
if (h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(ITEMICON), RT_GROUP_ICON)) {
h = LoadResource(hAppInstance, h);
p = LockResource(h);
id = LookupIconIdFromDirectory(p, TRUE);
UnlockResource(h);
FreeResource(h);
}
if (h = FindResource(hAppInstance, (LPTSTR) MAKEINTRESOURCE(id), (LPTSTR) MAKEINTRESOURCE(RT_ICON))) {
cb = SizeofResource(hAppInstance, h);
h = LoadResource(hAppInstance, h);
p = LockResource(h);
hIcon = CreateIconFromResource(p, cb, TRUE, 0x00030000);
UnlockResource(h);
FreeResource(h);
}
}
UnlockGroup(hwnd);
return hIcon;
}
COLORREF PASCAL GetTitleTextColor(VOID)
{
COLORREF color;
color = GetSysColor(COLOR_WINDOW);
if (((WORD)LOBYTE(LOWORD(color)) +
(WORD)HIBYTE(LOWORD(color)) +
(WORD)LOBYTE(HIWORD(color))) >= 3*127)
{
return RGB(0,0,0);
}
else
{
return RGB(255,255,255);
}
}
#define REVERSEPAINT
/*-------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------*/
void NEAR PASCAL ReverseGroupList(PGROUP pGroup)
{
PITEM pitem, p1, p2;
for (p1 = pGroup->pItems, p2 = p1->pNext, p1->pNext = NULL; p2; ) {
pitem = p2->pNext;
p2->pNext = p1;
p1 = p2;
p2 = pitem;
}
pGroup->pItems = p1;
}
VOID PASCAL PaintGroup(HWND hwnd)
{
register HDC hdc;
PGROUP pGroup;
PITEM pitem;
PAINTSTRUCT ps;
LPGROUPDEF lpgd;
LPITEMDEF lpid;
int fontheight;
HBRUSH hbrTitle;
HFONT hFontT;
RECT rcWin;
TEXTMETRIC tm;
HDC hdcMem;
HBITMAP hbmTemp = NULL;
HBRUSH hbr, hbrTemp;
INT nMax;
HICON hIcon;
pGroup = (PGROUP)GetWindowLongPtr(hwnd, GWLP_PGROUP);
hdc = BeginPaint(hwnd, &ps);
if (!pGroup->pItems) {
goto Exit;
}
GetClientRect(hwnd, &rcWin);
#ifdef WEIRDBUG
/* DavidPe - 05/15/91
* For some reason RectVisible() will return FALSE in
* situations it shouldn't. Since this is only a
* performance optimization, we can ignore the problem
* for now.
*/
if (!RectVisible(hdc, &rcWin))
goto Exit;
#endif
if (!(lpgd = LockGroup(hwnd)))
goto Exit;
hFontT = SelectObject(hdc, hFontTitle);
GetTextMetrics(hdc, &tm);
// ToddB: This seems like a good point, I don't see why tmExternalLeading should ever
// need to be considered. The result of decreasing the FontHeight is that DrawText
// will be used instead of TextOut in some cases, which should be harmless but might
// effect the apearence of some single line icon titles.
//#ifdef JAPAN
// Why we should think about ExternalLeading though we calculate the
// title rectange by DrawText() without DT_EXTERNALLEADING. -YN
fontheight = tm.tmHeight;
//#else
// fontheight = tm.tmHeight + tm.tmExternalLeading;
//#endif
SetBkMode(hdc, TRANSPARENT);
SetTextColor(hdc, GetTitleTextColor());
hbrTitle = NULL;
hdcMem = CreateCompatibleDC(hdc);
if (!hdcMem)
goto BitmapSetupComplete;
if (pGroup->hbm) {
hbmTemp = SelectObject(hdcMem, pGroup->hbm);
if (hbmTemp)
goto BitmapSetupComplete;
else
DeleteObject(pGroup->hbm);
}
for (nMax = 1, pitem = pGroup->pItems; pitem; pitem = pitem->pNext) {
if (nMax <= pitem->iItem)
nMax = pitem->iItem + 1;
}
pGroup->hbm = CreateDiscardableBitmap(hdc, cxIcon*lpgd->cItems, cyIcon);
if (!pGroup->hbm)
goto NukeMemDC;
hbmTemp = SelectObject(hdcMem, pGroup->hbm);
if (!hbmTemp)
goto NukeBitmap;
hbr = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
if (!hbr)
goto NukeBitmap;
hbrTemp = SelectObject(hdcMem, hbr);
if (!hbrTemp)
goto NukeBrush;
PatBlt(hdcMem, 0, 0, cxIcon * lpgd->cItems, cyIcon, PATCOPY);
SelectObject(hdcMem, hbrTemp);
DeleteObject(hbr);
for (pitem = pGroup->pItems; pitem != NULL; pitem = pitem->pNext) {
if (hIcon = GetItemIcon(hwnd, pitem)) {
DrawIcon(hdcMem, pitem->iItem * cxIcon, 0, hIcon);
DestroyIcon(hIcon);
} else {
goto DeselectAndNukeBitmap;
}
}
goto BitmapSetupComplete;
NukeBrush:
DeleteObject(hbr);
DeselectAndNukeBitmap:
SelectObject(hdcMem, hbmTemp);
NukeBitmap:
DeleteObject(pGroup->hbm);
pGroup->hbm = NULL;
NukeMemDC:
DeleteDC(hdcMem);
hdcMem = NULL;
BitmapSetupComplete:
ReverseGroupList(pGroup); // reverse the icon list
/* Paint the icons */
for (pitem = pGroup->pItems; pitem; pitem = pitem->pNext) {
if (!pitem->pNext
&& pGroup == pCurrentGroup
&& hwndProgman == GetActiveWindow()) {
hbrTitle = (HANDLE)1; // Use it as a flag
}
else
hbrTitle = (HANDLE)0;
lpid = ITEM(lpgd,pitem->iItem);
if (!bMove || !hbrTitle) {
if (hdcMem) {
BitBlt(hdc, pitem->rcIcon.left + cxOffset,
pitem->rcIcon.top + cyOffset,
lpgd->cxIcon, lpgd->cyIcon, hdcMem,
lpgd->cxIcon*pitem->iItem, 0,
SRCCOPY);
}
else {
if (RectVisible(hdc,&pitem->rcIcon)) {
if (hIcon = GetItemIcon(hwnd,pitem)) {
DrawIcon(hdc, pitem->rcIcon.left + cxOffset,
pitem->rcIcon.top + cyOffset, hIcon);
}
else {
PatBlt(hdc,pitem->rcIcon.left + cxOffset,
pitem->rcIcon.top + cyOffset,
cxIcon, cyIcon, BLACKNESS);
}
}
}
}
}
/* Paint the titles. */
for (pitem = pGroup->pItems; pitem; pitem = pitem->pNext) {
/* test for the active icon */
if (!pitem->pNext
&& pGroup == pCurrentGroup
&& hwndProgman == GetActiveWindow()) {
SetTextColor(hdc, GetSysColor(COLOR_CAPTIONTEXT));
hbrTitle = CreateSolidBrush(GetSysColor(COLOR_ACTIVECAPTION));
}
else {
hbrTitle = (HANDLE)0;
}
lpid = ITEM(lpgd,pitem->iItem);
if (!bMove || !hbrTitle) {
if (hbrTitle)
FillRect(hdc, &(pitem->rcTitle), hbrTitle);
/* draw multi line titles like USER does */
if (pitem->rcTitle.bottom - pitem->rcTitle.top < fontheight*2)
TextOut(hdc, pitem->rcTitle.left+cxOffset, pitem->rcTitle.top,
(LPTSTR) PTR(lpgd, lpid->pName), lstrlen((LPTSTR) PTR(lpgd, lpid->pName)));
else {
if (RectVisible(hdc,&pitem->rcTitle)) {
DrawText(hdc,
(LPTSTR)PTR(lpgd, lpid->pName), -1,
&(pitem->rcTitle),
bIconTitleWrap ?
DT_CENTER | DT_WORDBREAK | DT_NOPREFIX :
DT_CENTER | DT_WORDBREAK | DT_NOPREFIX | DT_SINGLELINE);
}
}
}
if (hbrTitle) {
SetTextColor(hdc, GetTitleTextColor());
DeleteObject(hbrTitle);
hbrTitle = NULL;
}
}
ReverseGroupList(pGroup); // re-reverse the icon list
if (hFontT) {
SelectObject(hdc, hFontT);
}
if (hdcMem) {
SelectObject(hdcMem, hbmTemp);
DeleteDC(hdcMem);
}
UnlockGroup(hwnd);
Exit:
SetBkMode(hdc, OPAQUE);
EndPaint(hwnd, &ps);
#ifdef DEBUG
ProfStop();
{
TCHAR buf[80];
wsprintf(buf, TEXT("msec to paint group = %ld\r\n"), GetTickCount() - dwStartTime);
OutputDebugString(buf);
}
#endif
}
/*-------------------------------------------------------------------------*/
/* */
/* Draw the group icon. */
/* */
/*-------------------------------------------------------------------------*/
VOID DrawGroupIcon(HWND hwnd)
{
PAINTSTRUCT ps;
HDC hDC;
PGROUP pGroup;
hDC = BeginPaint(hwnd, &ps);
pGroup = (PGROUP)GetWindowLongPtr(hwnd,GWLP_PGROUP);
if (pGroup->fCommon) {
DrawIcon(hDC, cxOffset, cyOffset, hCommonGrpIcon);
}
else {
DrawIcon(hDC, cxOffset, cyOffset, hGroupIcon);
}
EndPaint(hwnd, &ps);
}
PITEM PASCAL ItemHitTest(
PGROUP pGroup,
POINTS pts)
{
PITEM pItem;
POINT pt;
pt.x = (int)pts.x;
pt.y = (int)pts.y;
for (pItem = pGroup->pItems; pItem; pItem = pItem->pNext) {
if (PtInRect(&pItem->rcIcon, pt) || PtInRect(&pItem->rcTitle, pt)) {
break;
}
}
return pItem;
}
HRGN PASCAL IconExcludedRgn(PGROUP pGroup, PITEM pItem)
{
RECT rc;
PITEM pItemT;
HRGN hrgn, hrgnT;
hrgn = CreateRectRgn(0,0,0,0);
if (!hrgn)
return NULL;
hrgnT = CreateRectRgn(0,0,0,0);
if (!hrgnT)
{
return hrgn;
}
for (pItemT = pGroup->pItems;
pItemT && pItemT != pItem;
pItemT = pItemT->pNext)
{
if (IntersectRect(&rc,&pItem->rcIcon,&pItemT->rcIcon))
{
SetRectRgn(hrgnT,rc.left,rc.top,rc.right,rc.bottom);
CombineRgn(hrgn,hrgn,hrgnT,RGN_OR);
}
if (IntersectRect(&rc,&pItem->rcIcon,&pItemT->rcTitle))
{
SetRectRgn(hrgnT,rc.left,rc.top,rc.right,rc.bottom);
CombineRgn(hrgn,hrgn,hrgnT,RGN_OR);
}
}
DeleteObject(hrgnT);
return hrgn;
}
VOID APIENTRY InvalidateIcon(PGROUP pGroup, PITEM pItem)
{
RECT rc;
if (!pGroup || !pItem)
return;
UnionRect(&rc, &pItem->rcIcon, &pItem->rcTitle);
if (bAutoArranging)
UnionRect(&rcArrangeRect, &rcArrangeRect, &rc);
else
InvalidateRect(pGroup->hwnd,&rc,TRUE);
}
VOID PASCAL BringItemToTop(PGROUP pGroup, PITEM pItem, BOOL fUpdate)
{
PITEM pItemT;
HRGN hrgn;
if (pItem == pGroup->pItems) {
return;
}
if (hrgn = IconExcludedRgn(pGroup, pItem)) {
InvalidateRgn(pGroup->hwnd, hrgn, TRUE);
DeleteObject(hrgn);
}
/*
* At this point we know there is at least two items, and we're not the
* first one...
*/
for (pItemT = pGroup->pItems; pItemT->pNext != pItem; pItemT = pItemT->pNext)
;
pItemT->pNext = pItem->pNext;
pItem->pNext = pGroup->pItems;
pGroup->pItems = pItem;
/*
* Invalidate the whole titles in order to change the color.
*/
if (fUpdate) {
InvalidateRect(pGroup->hwnd, &pItem->rcTitle, TRUE);
InvalidateRect(pGroup->hwnd, &pItem->pNext->rcTitle, TRUE);
}
}
VOID PASCAL ClickOn(HWND hwnd, POINTS pts)
{
PGROUP pGroup;
PITEM pItem;
POINT pt;
pGroup = (PGROUP)GetWindowLongPtr(hwnd, GWLP_PGROUP);
pItem = ItemHitTest(pGroup, pts);
if (!pItem) {
return;
}
BringItemToTop(pGroup, pItem, TRUE);
ViewActiveItem(pGroup);
pt.x = (int)pts.x;
pt.y = (int)pts.y;
*(LPPOINT)&rcDrag.left = pt;
*(LPPOINT)&rcDrag.right = pt;
hwndDrag = hwnd;
InflateRect(&rcDrag, GetSystemMetrics(SM_CXDOUBLECLK) / 2,
GetSystemMetrics(SM_CYDOUBLECLK) / 2);
}
VOID PASCAL DragItem(HWND hwnd)
{
PGROUP pGroup;
PITEM pItem;
HICON hIcon;
pGroup = (PGROUP)GetWindowLongPtr(hwnd,GWLP_PGROUP);
pItem = pGroup->pItems;
if (!pItem || hwndDrag != hwnd)
goto ProcExit;
/* If the control key isn't down, do a Move operation. */
bMove = !(GetKeyState(VK_CONTROL) & 0x8000);
/* Don't allow "moves" from RO groups. */
if (pGroup->fRO && bMove == TRUE)
goto ProcExit;
/*
* Redraw the window minus the item we're moving.
* REVIEW - if you just painted the background colour into the
* pItem->rcIcon area then you could remove the bMove code from
* PaintGroup().
*/
if (bMove) {
InvalidateIcon(pGroup,pItem);
UpdateWindow(hwnd);
}
hIcon = GetItemIcon(hwnd,pItem);
// BUG BUG MAKELONG(pGroup,pItem) doesn't make sense since all
// pointers all LOMG in WIN32. Will need to change the parameters!
// johannec 08-19-91
if (DragObject(hwndMDIClient, hwnd, (UINT)OBJ_ITEM,
MAKELONG(pGroup,pItem), hIcon) == DRAG_COPY) {
if (bMove)
DeleteItem(pGroup,pItem);
}
else {
/* Drag was SWP or drag failed... just show the item. */
if (bMove) {
bMove = FALSE;
InvalidateIcon(pGroup,pItem);
}
}
DestroyIcon(hIcon);
ProcExit:
bMove = FALSE;
}
void PASCAL GetRealClientRect(
HWND hwnd,
DWORD dwStyle,
LPRECT lprcClient)
{
DWORD Style;
Style = GetWindowLongPtr(hwnd, GWL_STYLE);
/*BUG BUG will GWL_STYLE work???*/
SetWindowLongPtr(hwnd,GWL_STYLE,dwStyle);
GetWindowRect(hwnd,lprcClient);
ScreenToClient(hwnd,(LPPOINT)&lprcClient->left);
ScreenToClient(hwnd,(LPPOINT)&lprcClient->right);
SendMessage(hwnd,WM_NCCALCSIZE,0,(LPARAM)lprcClient);
}
VOID APIENTRY CalcGroupScrolls(HWND hwnd)
{
register PGROUP pGroup;
register PITEM pItem;
RECT rcClient;
RECT rcRange;
RECT rcT;
DWORD dwStyle, dwStyleNew, dwStyleT;
int iMinPos, iMaxPos;
if (bNoScrollCalc || IsIconic(hwnd))
return;
// Stop re-entrance of this routine.
bNoScrollCalc = TRUE;
pGroup = (PGROUP)GetWindowLongPtr(hwnd,GWLP_PGROUP);
if (!pGroup->pItems) {
// No items...
SetRectEmpty(&rcRange);
goto ChangeStyle;
}
hwndScrolling = hwnd;
// If the user has selected auto arranging then make
// the next item in the z-order visable.
if (bAutoArrange)
ViewActiveItem(pGroup);
SetRectEmpty(&rcRange);
for (pItem = pGroup->pItems; pItem; pItem = pItem->pNext)
{
UnionRect(&rcRange,&rcRange,&pItem->rcIcon);
rcT.top = pItem->rcTitle.top; // don't include the
rcT.bottom = pItem->rcTitle.bottom; // title overhang part
rcT.left = pItem->rcIcon.left;
rcT.right = pItem->rcIcon.right;
UnionRect(&rcRange,&rcRange,&rcT);
}
if (rcRange.left != rcRange.right)
{
// Add on a bit for the left border here.
rcRange.left -= ((cxArrange-cxIconSpace)/2)+cxOffset;
// Don't add on a right border so we can cram as many icons in as poss.
// rcRange.right += ((cxArrange-cxIconSpace)/2);
// ADJUST THE RECT SO THAT WE DON'T GET SCROLL BARS IF ONLY THE BORDERS
// OF TEXT ARE NOT VISIBLE ~~~
}
ChangeStyle:
dwStyleNew = dwStyle = GetWindowLongPtr(hwnd,GWL_STYLE);
dwStyleNew &= ~(WS_HSCROLL | WS_VSCROLL);
for (;;)
{
dwStyleT = dwStyleNew;
GetRealClientRect(hwnd, dwStyleNew, &rcClient);
if (rcRange.left < rcClient.left || rcRange.right > rcClient.right)
dwStyleNew |= WS_HSCROLL;
if (rcRange.top < rcClient.top || rcRange.bottom > rcClient.bottom)
dwStyleNew |= WS_VSCROLL;
if (dwStyleNew == dwStyleT)
break;
}
if (dwStyleNew == dwStyle && !(dwStyle & (WS_VSCROLL|WS_HSCROLL)))
{
/* none there and don't need to add 'em!
*/
goto ProcExit;
}
UnionRect(&rcRange,&rcClient,&rcRange);
/* union garantees that left==right or top==bottom in case of no
* scrollbar.
*/
rcRange.right -= rcClient.right-rcClient.left;
rcRange.bottom -= rcClient.bottom-rcClient.top;
/* if the style changed, don't redraw in sb code, just redraw the
* frame at the end cause the whole ncarea has to be repainted
* if it hasn't changed, just move the thumb
*/
if (dwStyleNew==dwStyle)
{
if (dwStyleNew & WS_HSCROLL)
{
if (GetScrollPos(hwnd,SB_HORZ)!=0)
goto SetScrollInfo;
GetScrollRange(hwnd,SB_HORZ,&iMinPos,&iMaxPos);
if ((iMinPos != rcRange.left) || (iMaxPos != rcRange.right))
goto SetScrollInfo;
}
if (dwStyleNew & WS_VSCROLL)
{
if (GetScrollPos(hwnd,SB_VERT)!=0)
goto SetScrollInfo;
GetScrollRange(hwnd,SB_VERT,&iMinPos,&iMaxPos);
if ((iMinPos != rcRange.top) || (iMaxPos != rcRange.bottom))
goto SetScrollInfo;
}
goto ProcExit;
}
SetScrollInfo:
SetScrollPos(hwnd,SB_HORZ,0,FALSE);
SetScrollPos(hwnd,SB_VERT,0,FALSE);
SetScrollRange(hwnd,SB_HORZ,rcRange.left,rcRange.right,FALSE);
SetScrollRange(hwnd,SB_VERT,rcRange.top,rcRange.bottom,FALSE);
SetWindowPos(hwnd, NULL, 0, 0, 0, 0, SWP_NOZORDER | SWP_NOSIZE
| SWP_NOMOVE | SWP_NOACTIVATE
| SWP_DRAWFRAME);
ProcExit:
// Allow other scroll calculations.
bNoScrollCalc = FALSE;
}
VOID PASCAL ScrollGroup(PGROUP pGroup, int xMove, int yMove, BOOL fCalc)
{
register PITEM pItem;
for (pItem = pGroup->pItems; pItem; pItem = pItem->pNext)
{
OffsetRect(&pItem->rcIcon,xMove,yMove);
OffsetRect(&pItem->rcTitle,xMove,yMove);
}
ScrollWindow(pGroup->hwnd,xMove,yMove,NULL,NULL);
UpdateWindow(pGroup->hwnd);
if (fCalc)
CalcGroupScrolls(pGroup->hwnd);
}
VOID APIENTRY ViewActiveItem(PGROUP pGroup)
{
RECT rcClient, rc;
int xMove = 0, yMove = 0;
GetClientRect(pGroup->hwnd,&rcClient);
UnionRect(&rc, &pGroup->pItems->rcIcon, &pGroup->pItems->rcTitle);
// Clip width to that of icon i.e. ignore width of text.
rc.left = pGroup->pItems->rcIcon.left;
rc.right = pGroup->pItems->rcIcon.right;
if (rc.left < rcClient.left)
xMove = rcClient.left - rc.left;
else if (rc.right > rcClient.right)
xMove = rcClient.right - rc.right;
if (rc.top < rcClient.top)
yMove = rcClient.top - rc.top;
else if (rc.bottom > rcClient.bottom)
yMove = rcClient.bottom - rc.bottom;
if (xMove || yMove)
ScrollGroup(pGroup, xMove, yMove,TRUE);
}
BOOL FAR PASCAL CheckHotKey(WPARAM wParam, LPARAM lParam)
{
HWND hwndT;
PGROUP pGroup;
PITEM pItem;
switch (wParam)
{
case VK_SHIFT:
case VK_CONTROL:
case VK_MENU:
case VK_RETURN:
return FALSE;
}
if (GetKeyState(VK_SHIFT) < 0) {
// DBG((" + SHIFT"));
wParam |= HK_SHIFT;
}
if (GetKeyState(VK_CONTROL) < 0) {
// DBG((" + CONTROL"));
wParam |= HK_CONTROL;
}
if (GetKeyState(VK_MENU) < 0) {
// DBG((" + ALT"));
wParam |= HK_ALT;
}
if (lParam & F_EXT) {
// DBG((" EXTENDED"));
wParam |= HK_EXT;
}
// DBG(("... Full code %4.4X...\r\n",wParam));
for (hwndT = GetWindow(hwndMDIClient,GW_CHILD);
hwndT;
hwndT = GetWindow(hwndT,GW_HWNDNEXT)) {
if (GetWindow(hwndT,GW_OWNER))
continue;
pGroup = (PGROUP)GetWindowLongPtr(hwndT,GWLP_PGROUP);
for (pItem = pGroup->pItems; pItem; pItem = pItem->pNext) {
// DBG(("Checking (%4.4X,%4.4X)...\r\n",pGroup,pItem));
if (GroupFlag(pGroup,pItem,(WORD)ID_HOTKEY) == (WORD)wParam) {
// DBG(("F*O*U*N*D\r\n"));
ExecItem(pGroup,pItem,FALSE,FALSE);
return TRUE;
}
}
}
return FALSE;
}
VOID APIENTRY KeyWindow(HWND hwnd, WORD wDirection)
{
int wT;
int wNext;
RECT rc;
RECT rcT;
POINT ptA;
POINT ptT;
PGROUP pGroup;
PITEM pItem, pItemNext;
pGroup = (PGROUP)GetWindowLongPtr(hwnd,GWLP_PGROUP);
if (!pGroup->pItems)
return;
wNext = 0x7FFF;
pItemNext = NULL;
CopyRect(&rc,&pGroup->pItems->rcIcon);
for (pItem = pGroup->pItems->pNext; pItem; pItem = pItem->pNext) {
CopyRect(&rcT,&pItem->rcIcon);
ptT.x = rcT.left - rc.left;
ptT.y = rcT.top - rc.top;
ptA.x = (ptT.x < 0) ? -ptT.x : ptT.x;
ptA.y = (ptT.y < 0) ? -ptT.y : ptT.y;
switch (wDirection) {
case VK_LEFT:
if ((ptT.x >= 0) || (ptA.x < ptA.y))
continue;
break;