forked from OpenSalamander/salamander
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiconlist.cpp
2145 lines (1876 loc) · 68.2 KB
/
iconlist.cpp
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
// SPDX-FileCopyrightText: 2023 Open Salamander Authors
// SPDX-License-Identifier: GPL-2.0-or-later
#include "precomp.h"
#include "dep\pnglite\\pnglite.h"
//******************************************************************************
//
// CIconList
//
// udava pocet polozek v jedne radce; po vzoru W2K davame 4;
// asi pro vetsi rychlost provadenych operaci?
const int IL_ITEMS_IN_ROW = 4;
#define IL_TYPE_NORMAL 0 // bezna ikona, kterou lze vykreslit pres BitBlt
#define IL_TYPE_XOR 1 // ikona obsahujici oblasti, ktere je treba XORovat
#define IL_TYPE_ALPHA 2 // ikona obsahujici alfa kanal
HDC CIconList::HMemDC = NULL;
HBITMAP CIconList::HOldBitmap = NULL;
HBITMAP CIconList::HTmpImage = NULL;
DWORD* CIconList::TmpImageRaw = NULL;
int CIconList::TmpImageWidth = 0;
int CIconList::TmpImageHeight = 0;
int CIconList::MemDCLocks = 0;
CRITICAL_SECTION CIconList::CriticalSection;
int CIconList::CriticalSectionLocks = 0;
CIconList::CIconList()
{
if (CriticalSectionLocks == 0)
HANDLES(InitializeCriticalSection(&CriticalSection));
CriticalSectionLocks++;
ImageWidth = 0;
ImageHeight = 0;
ImageCount = 0;
BitmapWidth = 0;
BitmapHeight = 0;
HImage = NULL;
ImageRaw = NULL;
ImageFlags = NULL;
BkColor = RGB(255, 255, 255);
// Dump = FALSE;
}
CIconList::~CIconList()
{
HANDLES(EnterCriticalSection(&CriticalSection));
MemDCLocks--;
HBITMAP hCurrentBmp = GetCurrentBitmap();
if (hCurrentBmp != NULL && (hCurrentBmp == HImage || hCurrentBmp == HTmpImage))
SelectObject(HMemDC, HOldBitmap);
if (MemDCLocks == 0)
{
if (HOldBitmap != NULL)
SelectObject(HMemDC, HOldBitmap);
HANDLES(DeleteDC(HMemDC));
HMemDC = NULL;
HOldBitmap = NULL;
if (HTmpImage != NULL)
{
HANDLES(DeleteObject(HTmpImage));
HTmpImage = NULL;
TmpImageRaw = NULL;
}
}
if (HImage != NULL)
{
ImageRaw = NULL;
HANDLES(DeleteObject(HImage));
HImage = NULL;
}
if (ImageFlags != NULL)
{
free(ImageFlags);
ImageFlags = NULL;
}
HANDLES(LeaveCriticalSection(&CriticalSection));
CriticalSectionLocks--;
if (CriticalSectionLocks == 0)
HANDLES(DeleteCriticalSection(&CriticalSection));
}
HBITMAP
CIconList::GetCurrentBitmap()
{
if (HMemDC == NULL)
return NULL;
return (HBITMAP)GetCurrentObject(HMemDC, OBJ_BITMAP);
}
BOOL CIconList::CreateOrEnlargeTmpImage(int width, int height)
{
if (HTmpImage == NULL || TmpImageWidth < width || TmpImageHeight < height)
{
// !!! Pozor, pri pouzivani BITMAPV4HEADER u Petra padal Salamander v ICM32.DLL,
// stary BITMAPINFOHEADER zjevne staci
BITMAPINFOHEADER bmhdr;
memset(&bmhdr, 0, sizeof(bmhdr));
bmhdr.biSize = sizeof(bmhdr);
bmhdr.biWidth = width;
bmhdr.biHeight = -height; // top-down
bmhdr.biPlanes = 1;
bmhdr.biBitCount = 32;
bmhdr.biCompression = BI_RGB;
void* lpBits = NULL;
HBITMAP hBmp = HANDLES(CreateDIBSection(NULL, (CONST BITMAPINFO*)&bmhdr,
DIB_RGB_COLORS, &lpBits, NULL, 0));
if (hBmp == NULL)
{
TRACE_E("CreateDIBSection() failed!");
return FALSE;
}
if (HTmpImage != NULL)
HANDLES(DeleteObject(HTmpImage)); // pokud existuje stara bitmapa, zrusime ji
HTmpImage = hBmp;
TmpImageRaw = (DWORD*)lpBits;
TmpImageWidth = width;
TmpImageHeight = height;
}
return TRUE;
}
BOOL CIconList::Create(int imageWidth, int imageHeight, int imageCount)
{
if (HImage != NULL)
{
TRACE_E("CIconList::Create: Image already exists!");
return FALSE;
}
if (imageWidth < 1 || imageHeight < 1 || imageCount < 1)
{
TRACE_E("CIconList::Create: Incorrect parameters!");
return FALSE;
}
HANDLES(EnterCriticalSection(&CriticalSection));
ImageFlags = (BYTE*)malloc(sizeof(BYTE) * imageCount);
if (ImageFlags == NULL)
{
TRACE_E(LOW_MEMORY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return FALSE;
}
ZeroMemory(ImageFlags, sizeof(BYTE) * imageCount); // bez alfa kanalu
int bmpWidth = imageWidth * min(imageCount, IL_ITEMS_IN_ROW);
int bmpHeight = imageHeight * ((imageCount + IL_ITEMS_IN_ROW - 1) / IL_ITEMS_IN_ROW);
// pomocne DC, abychom mohli vytvorit kompatibilni bitmapu
HDC hDC = HANDLES(GetDC(NULL));
if (hDC == NULL)
{
TRACE_E("Error creating DC!");
free(ImageFlags);
ImageFlags = NULL;
HANDLES(LeaveCriticalSection(&CriticalSection));
return FALSE;
}
if (HMemDC == NULL)
{
HMemDC = HANDLES(CreateCompatibleDC(hDC));
if (HMemDC == NULL)
{
TRACE_E("Error creating memory DC!");
HANDLES(ReleaseDC(NULL, hDC));
free(ImageFlags);
ImageFlags = NULL;
HANDLES(LeaveCriticalSection(&CriticalSection));
return FALSE;
}
HOldBitmap = (HBITMAP)GetCurrentObject(HMemDC, OBJ_BITMAP);
}
MemDCLocks++;
// pokud jeste neexistuje cache/mask bitmapa nebo je mala, vytvorime ji
if (!CreateOrEnlargeTmpImage(imageWidth, imageHeight))
{
HANDLES(ReleaseDC(NULL, hDC));
free(ImageFlags);
ImageFlags = NULL;
return FALSE;
}
// !!! Pozor, pri pouzivani BITMAPV4HEADER u Petra padal Salamander v ICM32.DLL,
// stary BITMAPINFOHEADER zjevne staci
BITMAPINFOHEADER bmhdr;
memset(&bmhdr, 0, sizeof(bmhdr));
bmhdr.biSize = sizeof(bmhdr);
bmhdr.biWidth = bmpWidth;
bmhdr.biHeight = -bmpHeight; // top-down
bmhdr.biPlanes = 1;
bmhdr.biBitCount = 32;
bmhdr.biCompression = BI_RGB;
void* lpBits = NULL;
HImage = HANDLES(CreateDIBSection(hDC, (CONST BITMAPINFO*)&bmhdr, DIB_RGB_COLORS, &lpBits, NULL, 0));
ImageRaw = (DWORD*)lpBits;
HANDLES(ReleaseDC(NULL, hDC));
if (HImage == NULL)
{
TRACE_E("Error creating image bitmap!");
free(ImageFlags);
ImageFlags = NULL;
HANDLES(LeaveCriticalSection(&CriticalSection));
return FALSE;
}
ImageWidth = imageWidth;
ImageHeight = imageHeight;
ImageCount = imageCount;
BitmapWidth = bmpWidth;
BitmapHeight = bmpHeight;
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::CreateFromImageList(HIMAGELIST hIL, int requiredImageSize)
{
if (hIL == NULL)
{
TRACE_E("CIconList::CreateFromImageList() hIL==NULL");
return FALSE;
}
// vytahneme geometrii image listu
int count = ImageList_GetImageCount(hIL);
if (count == 0)
{
TRACE_E("CIconList::CreateFromImageList() hIL is empty");
return FALSE;
}
int cx, cy;
if (requiredImageSize == -1)
{
if (!ImageList_GetIconSize(hIL, &cx, &cy))
{
TRACE_E("ImageList_GetIconSize() failed");
return FALSE;
}
}
else
{
cx = requiredImageSize;
cy = requiredImageSize;
}
if (!Create(cx, cy, count))
return FALSE;
// j.r. tady by se dalo optimalizovat: misto predavani po ikonach predat pres ImageList_Draw
if (count > 20)
{
TRACE_E("CIconList::CreateFromImageList(): Let me know that you need so many icons, it would deserve some optimizations here. Jan.");
}
int i;
for (i = 0; i < count; i++)
{
HICON hIcon = ImageList_GetIcon(hIL, i, ILD_NORMAL);
if (hIcon == NULL)
{
TRACE_E("ImageList_GetIcon() failed");
return FALSE;
}
if (!ReplaceIcon(i, hIcon))
return FALSE;
DestroyIcon(hIcon);
}
return TRUE;
}
// Pokud mam pod W2K desktop 32bpp, dostavam XP ikonky s alfa kanalem neorezane,
// tedy vcetne alfa kanalu. Pokud prepnu desktop na 16bpp, je alfa kanal orezany (nulovany).
// Pokud tedy ApplyMaskToImage dostane ikonku vcetne alfa kanalu, vrati typ
// IL_TYPE_ALPHA a Salamander bude korektne zobrazovat tyto ikony i pod OS < XP
BYTE CIconList::ApplyMaskToImage(int index, BYTE forceXOR)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// prohledneme celou ikonku a urcime o jaky typ se jedna (NORMAL, XOR, ALPHA)
BYTE type = IL_TYPE_NORMAL;
if (forceXOR)
type = IL_TYPE_XOR;
else
{
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* ptr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* maskPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
if (((*ptr) & 0xFF000000) != 0)
{
type = IL_TYPE_ALPHA;
goto SKIP;
}
if ((*maskPtr != 0) && (*ptr != 0))
{
type = IL_TYPE_XOR;
// to ze je ikonka kandidat na XOR jeste neznamena,
// ze nebude ALPHA, takze nemuzeme vypadnout
}
ptr++;
maskPtr++;
}
}
}
// if (isXOR)
// DumpToTrace(index);
SKIP:
if (type == IL_TYPE_NORMAL)
{
// pripravime si barvu pozadi ve spravnem formatu
DWORD bkClr = GetRValue(BkColor) << 16 | GetGValue(BkColor) << 8 | GetBValue(BkColor);
// pruhledne oblasti masky preneseme do alfa kanalu
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* ptr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* maskPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
if (*maskPtr != 0)
{
// zcela pruhledna oblast
// alfa kanal je v nejvyssim bytu, nastavime na 00, zbytek bude barva pozadi
*ptr = bkClr;
}
else
{
*ptr |= 0xFF000000; // oblast nastavime jako nepruhlednou
}
ptr++;
maskPtr++;
}
}
}
if (type == IL_TYPE_XOR)
{
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* ptr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* maskPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
if (*maskPtr == 0)
*ptr |= 0xFF000000; // nepruhledna oblast
ptr++;
maskPtr++;
}
}
}
HANDLES(LeaveCriticalSection(&CriticalSection));
return type;
}
/*
void
CIconList::DumpToTrace(int index, BOOL dumpMask)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
TRACE_E("COLOR BITMAP");
int row;
for (row = 0; row < ImageHeight; row++)
{
char buff[1000];
buff[0] = 0;
DWORD *ptr = ImageRaw + iX + (iY + row) * BitmapWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
sprintf(buff + strlen(buff), "%.8X ", *ptr);
ptr++;
}
TRACE_I(buff);
}
if (dumpMask)
{
TRACE_E("MASK BITMAP");
for (row = 0; row < ImageHeight; row++)
{
char buff[1000];
buff[0] = 0;
DWORD *maskPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
sprintf(buff + strlen(buff), "%.8X ", *maskPtr);
maskPtr++;
}
TRACE_I(buff);
}
}
char buff[100];
sprintf(buff, "%d", ImageFlags[index]);
TRACE_I("ImageFlags["<<index<<"]="<<buff);
HANDLES(LeaveCriticalSection(&CriticalSection));
}
*/
//int counter = 0;
void CIconList::StoreMonoIcon(int index, WORD* mask)
{
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
}
BOOL CIconList::ReplaceIcon(int index, HICON hIcon)
{
CALL_STACK_MESSAGE2("CIconList::ReplaceIcon(%d, )", index);
HICON hIconOrig = hIcon;
BOOL ret = TRUE;
ICONINFO ii;
ZeroMemory(&ii, sizeof(ii));
HDC hSrcDC;
HBITMAP hOldSrcBmp;
HANDLES(EnterCriticalSection(&CriticalSection));
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// kontrola parametru
if (index < 0 || index >= ImageCount)
{
TRACE_E("CIconList::ReplaceIcon(): Index is out of range! index=" << index);
goto BAIL;
}
// pokud je treba, provedeme resize ikonky
// Honza: pod W10 mi zacalo volani CopyImage padat v debug x64 verzi, pokud byl povolen LR_COPYFROMRESOURCE flag
// FIXME: provest audit, zda je tento downscale jeste potreba, kdyz SalLoadIcon() nove vola LoadIconWithScaleDown()
hIcon = (HICON)CopyImage(hIconOrig, IMAGE_ICON, ImageWidth, ImageHeight, /*LR_COPYFROMRESOURCE | */ LR_COPYRETURNORG);
// vytahneme z handlu ikony jeji MASK a COLOR bitmapy
if (!GetIconInfo(hIcon, &ii))
{
TRACE_E("GetIconInfo() failed!");
DWORD err = GetLastError();
goto BAIL;
}
BITMAP bm;
if (!GetObject(ii.hbmMask, sizeof(bm), &bm))
{
TRACE_E("GetObject() failed!");
goto BAIL;
}
// pokud se jedna o b&w ikonu, mela by mit sudou vysku
if (ii.hbmColor == NULL && (bm.bmHeight & 1) == 1)
{
TRACE_E("CIconList::ReplaceIcon() Icon has wrong MASK height");
goto BAIL;
}
// ikonka by mela mit stejne rozmery, jako ma nase polozka
if (bm.bmWidth != ImageWidth ||
(ii.hbmColor == NULL && bm.bmHeight != ImageHeight * 2) ||
(ii.hbmColor != NULL && bm.bmHeight != ImageHeight))
TRACE_E("CIconList::ReplaceIcon() Icon has wrong size: bmWidth=" << bm.bmWidth << " bmHeight=" << bm.bmHeight);
// potrebujeme dostatecny prostor pro masku
if (!CreateOrEnlargeTmpImage(bm.bmWidth, bm.bmHeight))
goto BAIL;
hSrcDC = HANDLES(CreateCompatibleDC(NULL)); // pomocne dc pro bitblt
hOldSrcBmp = (HBITMAP)SelectObject(hSrcDC, ii.hbmMask);
// ii.hbmMask -> HTmpImage
SelectObject(HMemDC, HTmpImage);
BitBlt(HMemDC, 0, 0, ImageWidth, ImageHeight, hSrcDC, 0, 0, SRCCOPY);
// ii.hbmColor -> HImage (pokud je hbmColor==NULL, lezi XOR cast ve spodni polovine hbmMask
if (ii.hbmColor != NULL)
SelectObject(hSrcDC, ii.hbmColor);
SelectObject(HMemDC, HImage);
BitBlt(HMemDC, iX, iY, ImageWidth, ImageHeight, hSrcDC, 0, (ii.hbmColor != NULL) ? 0 : ImageHeight, SRCCOPY);
GdiFlush(); // podle MSDN je treba zavolat nez zacneme pristupovat na raw data
// TRACE_I("counter: "<<counter);
// if (++counter == 19)
// DumpToTrace(index);
ImageFlags[index] = ApplyMaskToImage(index, ii.hbmColor == NULL);
SelectObject(hSrcDC, hOldSrcBmp);
HANDLES(DeleteDC(hSrcDC));
BAIL:
HANDLES(LeaveCriticalSection(&CriticalSection));
if (ii.hbmMask != NULL)
DeleteObject(ii.hbmMask);
if (ii.hbmColor != NULL)
DeleteObject(ii.hbmColor);
// pokud jsme menili velikost, musime sestrelit docasnou ikonku
if (hIcon != hIconOrig)
DestroyIcon(hIcon);
// if (Dump)
// {
// TRACE_E("ReplaceIcon()");
// DumpToTrace(index, FALSE);
// }
return ret;
}
#define ROP_DSna 0x00220326
HICON
CIconList::GetIcon(int index, BOOL useHandles)
{
HICON icon = GetIcon(index);
if (useHandles)
HANDLES_ADD_EX(__otMessages, icon != NULL, __htIcon, __hoCreateIconIndirect, icon, GetLastError(), TRUE);
return icon;
}
HICON
CIconList::GetIcon(int index)
{
// kontrola parametru
if (index < 0 || index >= ImageCount)
{
TRACE_E("CIconList::GetIcon: index is out of range!");
return NULL;
}
// vytvorime B&W masku + barevnou bitmapu dle obrazovky
HDC hDC = HANDLES(GetDC(NULL));
HBITMAP hMask = HANDLES(CreateBitmap(ImageWidth, ImageHeight, 1, 1, NULL));
HBITMAP hColor = HANDLES(CreateCompatibleBitmap(hDC, ImageWidth, ImageHeight));
HANDLES(ReleaseDC(NULL, hDC));
HANDLES(EnterCriticalSection(&CriticalSection));
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
BYTE type = ImageFlags[index];
// do HTmpImage pripravime COLOR cast ikonky
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
if (type == IL_TYPE_ALPHA) // az na XP a novejsich systemech vracime ikony s alphou
{
*tmpPtr = argb;
}
else
{
// v pruhledne oblasti je barva pozadi image listu, ale my tam
// musime dodat cernou barvu, aby fungoval XOR mechanismus kresleni
if (alpha != 0)
*tmpPtr = argb;
else
*tmpPtr = 0x00000000;
}
imagePtr++;
tmpPtr++;
}
}
// preneseme HTmpImage do hColor
SelectObject(HMemDC, HTmpImage);
hDC = HANDLES(CreateCompatibleDC(NULL));
HBITMAP hOldBmp = (HBITMAP)SelectObject(hDC, hColor);
BitBlt(hDC, 0, 0, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
SelectObject(hDC, hMask);
// do HTmpImage pripravime MASK cast ikonky
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
*tmpPtr = (alpha != 0) ? RGB(0, 0, 0) : RGB(255, 255, 255);
imagePtr++;
tmpPtr++;
}
}
// preneseme HTmpImage do hMask
BitBlt(hDC, 0, 0, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
// if (Dump)
// {
// TRACE_E("GetIcon()");
// DumpToTrace(index, TRUE);
// }
// zameteme
SelectObject(hDC, hOldBmp);
HANDLES(DeleteDC(hDC));
HANDLES(LeaveCriticalSection(&CriticalSection));
// z hColor + hMask vytvorime ikonku
ICONINFO ii;
ii.fIcon = TRUE;
ii.xHotspot = 0;
ii.yHotspot = 0;
ii.hbmColor = hColor;
ii.hbmMask = hMask;
HICON hIcon;
hIcon = CreateIconIndirect(&ii); // nesmi byt v handles, vyvazi ikonku ven ze Salamandera
HANDLES(DeleteObject(hColor));
HANDLES(DeleteObject(hMask));
return hIcon;
}
BOOL CIconList::Draw(int index, HDC hDC, int x, int y, COLORREF blendClr, DWORD flags)
{
// kontrola parametru
if (index < 0 || index >= ImageCount)
{
TRACE_E("CIconList::Draw() Index is out of range! index=" << index << " ImageCount=" << ImageCount);
return FALSE;
}
if (flags & IL_DRAW_MASK) // maska se pouziva pri drag&dropu, napriklad u shared adesaru, viz StateImageList_Draw()
return DrawMask(hDC, x, y, index, RGB(0, 0, 0), RGB(255, 255, 255));
if (flags & IL_DRAW_BLEND)
return AlphaBlend(hDC, x, y, index, BkColor, blendClr);
if (flags & IL_DRAW_ASALPHA)
return DrawAsAlphaLeaveBackground(hDC, x, y, index, blendClr);
if (ImageFlags[index] == IL_TYPE_ALPHA)
{
if (flags & IL_DRAW_TRANSPARENT)
return DrawALPHALeaveBackground(hDC, x, y, index);
else
return DrawALPHA(hDC, x, y, index, BkColor);
}
if (ImageFlags[index] == IL_TYPE_XOR)
return DrawXOR(hDC, x, y, index, BkColor);
HANDLES(EnterCriticalSection(&CriticalSection));
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
SelectObject(HMemDC, HImage);
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, iX, iY, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::DrawMask(HDC hDC, int x, int y, int index, COLORREF fgColor, COLORREF bkColor)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
//DumpToTrace(index);
// sosneme data z obrazovky do HTmpImage
// nase DrawMask pouze nastavuje cerne body v miste masky, abychom mohli snadno mergovat s overlayem
// pri volani z StateImageList_Draw(); pokud bude casem treba zobrazovat dalsi overlay, bude to chtit
// udelat v StateImageList_Draw() merger na zaklade boolovskych bitblt operaci a tato metoda by pak
// mohla nastavovat take fgColor; odpadla by podminka *** dole
SelectObject(HMemDC, HTmpImage);
BitBlt(HMemDC, 0, 0, ImageWidth, ImageHeight, hDC, x, y, SRCCOPY);
// budeme kreslit do HTmpImage
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
DWORD clr = (alpha == 0) ? bkColor : fgColor;
if (alpha != 0) // *** viz komentar nahore
*tmpPtr = clr;
imagePtr++;
tmpPtr++;
}
}
// vykreslime HTmpImage do obrazovky
// SelectObject(HMemDC, HTmpImage);
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::DrawXOR(HDC hDC, int x, int y, int index, COLORREF bkColor)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// budeme kreslit do HTmpImage
BYTE bkR = GetRValue(bkColor);
BYTE bkG = GetGValue(bkColor);
BYTE bkB = GetBValue(bkColor);
DWORD bkClr = GetRValue(bkColor) << 16 | GetGValue(bkColor) << 8 | GetBValue(bkColor);
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
DWORD clr = (alpha == 0) ? bkClr : 0;
clr ^= (argb & 0x00FFFFFF);
*tmpPtr = clr;
imagePtr++;
tmpPtr++;
}
}
// vykreslime HTmpImage do obrazovky
SelectObject(HMemDC, HTmpImage);
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::DrawALPHA(HDC hDC, int x, int y, int index, COLORREF bkColor)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// v prvni fazi preneseme data do HMask
SelectObject(HMemDC, HTmpImage);
BYTE bkR = GetRValue(bkColor);
BYTE bkG = GetGValue(bkColor);
BYTE bkB = GetBValue(bkColor);
DWORD bkClr = GetRValue(bkColor) << 16 | GetGValue(bkColor) << 8 | GetBValue(bkColor);
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
if (alpha == 0)
*tmpPtr = bkClr;
else if (alpha == 255)
*tmpPtr = argb;
else
{
BYTE r = (BYTE)((argb & 0x00FF0000) >> 16);
BYTE g = (BYTE)((argb & 0x0000FF00) >> 8);
BYTE b = (BYTE)((argb & 0x000000FF));
BYTE newR = (BYTE)((DWORD)r * alpha / 255 + (DWORD)bkR * (255 - alpha) / 255);
BYTE newG = (BYTE)((DWORD)g * alpha / 255 + (DWORD)bkG * (255 - alpha) / 255);
BYTE newB = (BYTE)((DWORD)b * alpha / 255 + (DWORD)bkB * (255 - alpha) / 255);
*tmpPtr = (DWORD)newR << 16 | (DWORD)newG << 8 | (DWORD)newB;
}
imagePtr++;
tmpPtr++;
}
}
// vykreslime HTmpImage do obrazovky
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::DrawALPHALeaveBackground(HDC hDC, int x, int y, int index)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// v prvni fazi preneseme z ciloveho DC data do HMask
SelectObject(HMemDC, HTmpImage);
BitBlt(HMemDC, 0, 0, ImageWidth, ImageHeight, hDC, x, y, SRCCOPY);
GdiFlush(); // podle MSDN je treba zavolat nez zacneme pristupovat na raw data
/*
BYTE bkR = GetRValue(bkColor);
BYTE bkG = GetGValue(bkColor);
BYTE bkB = GetBValue(bkColor);
DWORD bkClr = GetRValue(bkColor) << 16 | GetGValue(bkColor) << 8 | GetBValue(bkColor);
*/
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
if (alpha != 0)
{
if (alpha == 255)
*tmpPtr = argb;
else
{
BYTE bkR = GetRValue(*tmpPtr);
BYTE bkG = GetGValue(*tmpPtr);
BYTE bkB = GetBValue(*tmpPtr);
BYTE r = (BYTE)((argb & 0x00FF0000) >> 16);
BYTE g = (BYTE)((argb & 0x0000FF00) >> 8);
BYTE b = (BYTE)((argb & 0x000000FF));
BYTE newR = (BYTE)((DWORD)r * alpha / 255 + (DWORD)bkR * (255 - alpha) / 255);
BYTE newG = (BYTE)((DWORD)g * alpha / 255 + (DWORD)bkG * (255 - alpha) / 255);
BYTE newB = (BYTE)((DWORD)b * alpha / 255 + (DWORD)bkB * (255 - alpha) / 255);
*tmpPtr = (DWORD)newR << 16 | (DWORD)newG << 8 | (DWORD)newB;
}
}
imagePtr++;
tmpPtr++;
}
}
// vykreslime HTmpImage do obrazovky
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::DrawAsAlphaLeaveBackground(HDC hDC, int x, int y, int index, COLORREF fgColor)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// v prvni fazi preneseme z ciloveho DC data do HMask
SelectObject(HMemDC, HTmpImage);
BitBlt(HMemDC, 0, 0, ImageWidth, ImageHeight, hDC, x, y, SRCCOPY);
GdiFlush(); // podle MSDN je treba zavolat nez zacneme pristupovat na raw data
BYTE fgR = GetRValue(fgColor);
BYTE fgG = GetGValue(fgColor);
BYTE fgB = GetBValue(fgColor);
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = 255 - (BYTE)(argb & 0x000000FF); // vsechny kanaly nesou stejnou hodnotu, kterou mame povazovat za alpha kanal
if (alpha != 0)
{
BYTE bkR = (BYTE)((*tmpPtr & 0x00FF0000) >> 16);
BYTE bkG = (BYTE)((*tmpPtr & 0x0000FF00) >> 8);
BYTE bkB = (BYTE)((*tmpPtr & 0x000000FF));
BYTE newR = (BYTE)((DWORD)fgR * alpha / 255 + (DWORD)bkR * (255 - alpha) / 255);
BYTE newG = (BYTE)((DWORD)fgG * alpha / 255 + (DWORD)bkG * (255 - alpha) / 255);
BYTE newB = (BYTE)((DWORD)fgB * alpha / 255 + (DWORD)bkB * (255 - alpha) / 255);
*tmpPtr = (DWORD)newR << 16 | (DWORD)newG << 8 | (DWORD)newB;
}
imagePtr++;
tmpPtr++;
}
}
// vykreslime HTmpImage do obrazovky
BitBlt(hDC, x, y, ImageWidth, ImageHeight, HMemDC, 0, 0, SRCCOPY);
HANDLES(LeaveCriticalSection(&CriticalSection));
return TRUE;
}
BOOL CIconList::AlphaBlend(HDC hDC, int x, int y, int index, COLORREF bkColor, COLORREF fgColor)
{
HANDLES(EnterCriticalSection(&CriticalSection));
// souradnice v bodech v HImage
int iX = ImageWidth * (index % IL_ITEMS_IN_ROW);
int iY = ImageHeight * (index / IL_ITEMS_IN_ROW);
// jde o variantu, kde je treba XORovat?
BOOL xorType = ImageFlags[index] == IL_TYPE_XOR;
// v prvni pripravime raw data pro HTmpImage
int bitsPerPixel = GetCurrentBPP(hDC);
if (bitsPerPixel <= 8)
{
// 256 barev nebo mene: misto blendeni prekryvame sachovnici
DWORD bkClrOpaque = GetRValue(bkColor) << 16 | GetGValue(bkColor) << 8 | GetBValue(bkColor);
DWORD bkClr;
if (fgColor != CLR_NONE)
bkClr = GetRValue(fgColor) << 16 | GetGValue(fgColor) << 8 | GetBValue(fgColor);
else
bkClr = GetRValue(bkColor) << 16 | GetGValue(bkColor) << 8 | GetBValue(bkColor);
int row;
for (row = 0; row < ImageHeight; row++)
{
DWORD* imagePtr = ImageRaw + iX + (iY + row) * BitmapWidth;
DWORD* tmpPtr = TmpImageRaw + row * TmpImageWidth;
int col;
for (col = 0; col < ImageWidth; col++)
{
DWORD argb = *imagePtr;
BYTE alpha = (BYTE)((argb & 0xFF000000) >> 24);
if (xorType && alpha == 0)