Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/dlls/comdlg32/colordlg.c
8875 views
1
/*
2
* COMMDLG - Color Dialog
3
*
4
* Copyright 1994 Martin Ayotte
5
* Copyright 1996 Albrecht Kleine
6
* Copyright 2019 Vijay Kiran Kamuju
7
*
8
* This library is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Lesser General Public
10
* License as published by the Free Software Foundation; either
11
* version 2.1 of the License, or (at your option) any later version.
12
*
13
* This library is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* Lesser General Public License for more details.
17
*
18
* You should have received a copy of the GNU Lesser General Public
19
* License along with this library; if not, write to the Free Software
20
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21
*/
22
23
/* BUGS : still seems to not refresh correctly
24
sometimes, especially when 2 instances of the
25
dialog are loaded at the same time */
26
27
#include <stdarg.h>
28
#include <stdio.h>
29
#include "windef.h"
30
#include "winbase.h"
31
#include "wingdi.h"
32
#include "winuser.h"
33
#include "colordlg.h"
34
#include "commdlg.h"
35
#include "dlgs.h"
36
#include "cderr.h"
37
#include "cdlg.h"
38
39
#include "wine/debug.h"
40
41
WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
42
43
static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
44
45
#define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
46
47
static const COLORREF predefcolors[6][8]=
48
{
49
{ 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
50
0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
51
{ 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
52
0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
53
54
{ 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
55
0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
56
{ 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
57
0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
58
59
{ 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
60
0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
61
{ 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
62
0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
63
};
64
65
/* Chose Color PRIVATE Structure:
66
*
67
* This structure is duplicated in the 16 bit code with
68
* an extra member
69
*/
70
71
typedef struct CCPRIVATE
72
{
73
LPCHOOSECOLORW lpcc; /* points to public known data structure */
74
HWND hwndSelf; /* dialog window */
75
int nextuserdef; /* next free place in user defined color array */
76
HDC hdcMem; /* color graph used for BitBlt() */
77
HBITMAP hbmMem; /* color graph bitmap */
78
RECT fullsize; /* original dialog window size */
79
UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
80
RECT old3angle; /* last position of l-marker */
81
BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
82
int h;
83
int s;
84
int l; /* for temporary storing of hue,sat,lum */
85
int capturedGraph; /* control mouse captured */
86
RECT focusRect; /* rectangle last focused item */
87
HWND hwndFocus; /* handle last focused item */
88
} CCPRIV;
89
90
static int hsl_to_x(int hue, int sat, int lum)
91
{
92
int res = 0, maxrgb;
93
94
/* l below 120 */
95
maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
96
if (hue < 80)
97
res = 0;
98
else
99
if (hue < 120)
100
{
101
res = (hue - 80) * maxrgb; /* 0...10240 */
102
res /= 40; /* 0...256 */
103
}
104
else
105
if (hue < 200)
106
res = maxrgb;
107
else
108
{
109
res= (240 - hue) * maxrgb;
110
res /= 40;
111
}
112
res = res - maxrgb / 2; /* -128...128 */
113
114
/* saturation */
115
res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
116
117
/* lum above 120 */
118
if (lum > 120 && res < 256)
119
res += ((lum - 120) * (256 - res)) / 120;
120
121
return min(res, 255);
122
}
123
124
/***********************************************************************
125
* CC_HSLtoRGB [internal]
126
*/
127
static COLORREF CC_HSLtoRGB(int hue, int sat, int lum)
128
{
129
int h, r, g, b;
130
131
/* r */
132
h = hue > 80 ? hue-80 : hue+160;
133
r = hsl_to_x(h, sat, lum);
134
/* g */
135
h = hue > 160 ? hue-160 : hue+80;
136
g = hsl_to_x(h, sat, lum);
137
/* b */
138
b = hsl_to_x(hue, sat, lum);
139
140
return RGB(r, g, b);
141
}
142
143
/***********************************************************************
144
* CC_RGBtoHSL [internal]
145
*/
146
static int CC_RGBtoHSL(char c, COLORREF rgb)
147
{
148
WORD maxi, mini, mmsum, mmdif, result = 0;
149
int iresult = 0, r, g, b;
150
151
r = GetRValue(rgb);
152
g = GetGValue(rgb);
153
b = GetBValue(rgb);
154
155
maxi = max(r, b);
156
maxi = max(maxi, g);
157
mini = min(r, b);
158
mini = min(mini, g);
159
160
mmsum = maxi + mini;
161
mmdif = maxi - mini;
162
163
switch(c)
164
{
165
/* lum */
166
case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
167
result = mmsum / 255; /* 0...240 */
168
break;
169
/* saturation */
170
case 'S': if (!mmsum)
171
result = 0;
172
else
173
if (!mini || maxi == 255)
174
result = 240;
175
else
176
{
177
result = mmdif * 240; /* 0...61200=255*240 */
178
result /= (mmsum > 255 ? 510 - mmsum : mmsum); /* 0..255 */
179
}
180
break;
181
/* hue */
182
case 'H': if (!mmdif)
183
result = 160;
184
else
185
{
186
if (maxi == r)
187
{
188
iresult = 40 * (g - b); /* -10200 ... 10200 */
189
iresult /= (int) mmdif; /* -40 .. 40 */
190
if (iresult < 0)
191
iresult += 240; /* 0..40 and 200..240 */
192
}
193
else
194
if (maxi == g)
195
{
196
iresult = 40 * (b - r);
197
iresult /= (int) mmdif;
198
iresult += 80; /* 40 .. 120 */
199
}
200
else
201
if (maxi == b)
202
{
203
iresult = 40 * (r - g);
204
iresult /= (int) mmdif;
205
iresult += 160; /* 120 .. 200 */
206
}
207
result = iresult;
208
}
209
break;
210
}
211
return result; /* is this integer arithmetic precise enough ? */
212
}
213
214
215
/***********************************************************************
216
* CC_DrawCurrentFocusRect [internal]
217
*/
218
static void CC_DrawCurrentFocusRect( const CCPRIV *lpp )
219
{
220
if (lpp->hwndFocus)
221
{
222
HDC hdc = GetDC(lpp->hwndFocus);
223
DrawFocusRect(hdc, &lpp->focusRect);
224
ReleaseDC(lpp->hwndFocus, hdc);
225
}
226
}
227
228
/***********************************************************************
229
* CC_DrawFocusRect [internal]
230
*/
231
static void CC_DrawFocusRect(CCPRIV *lpp, HWND hwnd, int x, int y, int rows, int cols)
232
{
233
RECT rect;
234
int dx, dy;
235
HDC hdc;
236
237
CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
238
/* calculate new rect */
239
GetClientRect(hwnd, &rect);
240
dx = (rect.right - rect.left) / cols;
241
dy = (rect.bottom - rect.top) / rows;
242
rect.left += (x * dx) - 2;
243
rect.top += (y * dy) - 2;
244
rect.right = rect.left + dx;
245
rect.bottom = rect.top + dy;
246
/* draw it */
247
hdc = GetDC(hwnd);
248
DrawFocusRect(hdc, &rect);
249
lpp->focusRect = rect;
250
lpp->hwndFocus = hwnd;
251
ReleaseDC(hwnd, hdc);
252
}
253
254
#define DISTANCE 4
255
256
/***********************************************************************
257
* CC_MouseCheckPredefColorArray [internal]
258
* returns TRUE if one of the predefined colors is clicked
259
*/
260
static BOOL CC_MouseCheckPredefColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
261
{
262
HWND hwnd;
263
POINT point;
264
RECT rect;
265
int dx, dy, x, y;
266
267
CONV_LPARAMTOPOINT(lParam, &point);
268
ClientToScreen(lpp->hwndSelf, &point);
269
hwnd = GetDlgItem(lpp->hwndSelf, COLOR_BOX1);
270
GetWindowRect(hwnd, &rect);
271
if (PtInRect(&rect, point))
272
{
273
dx = (rect.right - rect.left) / cols;
274
dy = (rect.bottom - rect.top) / rows;
275
ScreenToClient(hwnd, &point);
276
277
if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
278
{
279
x = point.x / dx;
280
y = point.y / dy;
281
lpp->lpcc->rgbResult = predefcolors[y][x];
282
CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
283
return TRUE;
284
}
285
}
286
return FALSE;
287
}
288
289
/***********************************************************************
290
* CC_MouseCheckUserColorArray [internal]
291
* return TRUE if the user clicked a color
292
*/
293
static BOOL CC_MouseCheckUserColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
294
{
295
HWND hwnd;
296
POINT point;
297
RECT rect;
298
int dx, dy, x, y;
299
COLORREF *crarr = lpp->lpcc->lpCustColors;
300
301
CONV_LPARAMTOPOINT(lParam, &point);
302
ClientToScreen(lpp->hwndSelf, &point);
303
hwnd = GetDlgItem(lpp->hwndSelf, COLOR_CUSTOM1);
304
GetWindowRect(hwnd, &rect);
305
if (PtInRect(&rect, point))
306
{
307
dx = (rect.right - rect.left) / cols;
308
dy = (rect.bottom - rect.top) / rows;
309
ScreenToClient(hwnd, &point);
310
311
if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
312
{
313
x = point.x / dx;
314
y = point.y / dy;
315
lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
316
CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
317
return TRUE;
318
}
319
}
320
return FALSE;
321
}
322
323
#define MAXVERT 240
324
#define MAXHORI 239
325
326
/* 240 ^...... ^^ 240
327
| . ||
328
SAT | . || LUM
329
| . ||
330
+-----> 239 ----
331
HUE
332
*/
333
/***********************************************************************
334
* CC_MouseCheckColorGraph [internal]
335
*/
336
static BOOL CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
337
{
338
HWND hwnd;
339
POINT point;
340
RECT rect;
341
int x,y;
342
343
CONV_LPARAMTOPOINT(lParam, &point);
344
ClientToScreen(hDlg, &point);
345
hwnd = GetDlgItem( hDlg, dlgitem );
346
GetWindowRect(hwnd, &rect);
347
348
if (!PtInRect(&rect, point))
349
return FALSE;
350
351
GetClientRect(hwnd, &rect);
352
ScreenToClient(hwnd, &point);
353
354
x = (point.x * MAXHORI) / rect.right;
355
y = ((rect.bottom - point.y) * MAXVERT) / rect.bottom;
356
357
if (x < 0) x = 0;
358
if (y < 0) y = 0;
359
if (x > MAXHORI) x = MAXHORI;
360
if (y > MAXVERT) y = MAXVERT;
361
362
if (hori)
363
*hori = x;
364
if (vert)
365
*vert = y;
366
367
return TRUE;
368
}
369
/***********************************************************************
370
* CC_MouseCheckResultWindow [internal]
371
* test if double click one of the result colors
372
*/
373
static BOOL CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
374
{
375
HWND hwnd;
376
POINT point;
377
RECT rect;
378
379
CONV_LPARAMTOPOINT(lParam, &point);
380
ClientToScreen(hDlg, &point);
381
hwnd = GetDlgItem(hDlg, COLOR_CURRENT);
382
GetWindowRect(hwnd, &rect);
383
if (PtInRect(&rect, point))
384
{
385
PostMessageA(hDlg, WM_COMMAND, COLOR_SOLID, 0);
386
return TRUE;
387
}
388
return FALSE;
389
}
390
391
/***********************************************************************
392
* CC_CheckDigitsInEdit [internal]
393
*/
394
static int CC_CheckDigitsInEdit( CCPRIV *infoPtr, HWND hwnd, int maxval )
395
{
396
int i, k, m, result, value;
397
char buffer[30];
398
399
GetWindowTextA(hwnd, buffer, ARRAY_SIZE(buffer));
400
m = strlen(buffer);
401
result = 0;
402
403
for (i = 0 ; i < m ; i++)
404
if (buffer[i] < '0' || buffer[i] > '9')
405
{
406
for (k = i + 1; k <= m; k++) /* delete bad character */
407
{
408
buffer[i] = buffer[k];
409
m--;
410
}
411
buffer[m] = 0;
412
result = 1;
413
}
414
415
value = atoi(buffer);
416
if (value > maxval) /* build a new string */
417
{
418
value = maxval;
419
sprintf(buffer, "%d", maxval);
420
result = 2;
421
}
422
if (result)
423
{
424
LRESULT editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
425
infoPtr->updating = TRUE;
426
SetWindowTextA(hwnd, buffer );
427
SendMessageA(hwnd, EM_SETSEL, 0, editpos);
428
infoPtr->updating = FALSE;
429
}
430
return value;
431
}
432
433
434
435
/***********************************************************************
436
* CC_PaintSelectedColor [internal]
437
*/
438
static void CC_PaintSelectedColor(const CCPRIV *infoPtr)
439
{
440
if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
441
{
442
RECT rect;
443
HDC hdc;
444
HBRUSH hBrush;
445
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT);
446
447
hdc = GetDC(hwnd);
448
GetClientRect(hwnd, &rect) ;
449
hBrush = CreateSolidBrush(infoPtr->lpcc->rgbResult);
450
if (hBrush)
451
{
452
FillRect(hdc, &rect, hBrush);
453
DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
454
DeleteObject(hBrush);
455
}
456
ReleaseDC(hwnd, hdc);
457
}
458
}
459
460
/***********************************************************************
461
* CC_PaintTriangle [internal]
462
*/
463
static void CC_PaintTriangle(CCPRIV *infoPtr)
464
{
465
HDC hDC;
466
int temp;
467
int w = LOWORD(GetDialogBaseUnits()) / 2;
468
POINT points[3];
469
int height;
470
int oben;
471
RECT rect;
472
HBRUSH hbr;
473
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
474
475
if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW))) /* if full size */
476
{
477
GetClientRect(hwnd, &rect);
478
height = rect.bottom;
479
hDC = GetDC(infoPtr->hwndSelf);
480
points[0].y = rect.top;
481
points[0].x = rect.right; /* | /| */
482
ClientToScreen(hwnd, points); /* | / | */
483
ScreenToClient(infoPtr->hwndSelf, points); /* |< | */
484
oben = points[0].y; /* | \ | */
485
/* | \| */
486
temp = height * infoPtr->l;
487
points[0].x += 1;
488
points[0].y = oben + height - temp / MAXVERT;
489
points[1].y = points[0].y + w;
490
points[2].y = points[0].y - w;
491
points[2].x = points[1].x = points[0].x + w;
492
493
hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
494
if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
495
FillRect(hDC, &infoPtr->old3angle, hbr);
496
infoPtr->old3angle.left = points[0].x;
497
infoPtr->old3angle.right = points[1].x + 1;
498
infoPtr->old3angle.top = points[2].y - 1;
499
infoPtr->old3angle.bottom= points[1].y + 1;
500
501
hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
502
Polygon(hDC, points, 3);
503
SelectObject(hDC, hbr);
504
505
ReleaseDC(infoPtr->hwndSelf, hDC);
506
}
507
}
508
509
510
/***********************************************************************
511
* CC_PaintCross [internal]
512
*/
513
static void CC_PaintCross(CCPRIV *infoPtr)
514
{
515
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
516
517
if (IsWindowVisible(hwnd)) /* if full size */
518
{
519
int w, wc, width;
520
HDC hDC;
521
RECT rect;
522
POINT point;
523
HRGN region;
524
525
rect.left = 6;
526
rect.right = 2;
527
rect.top = 1;
528
rect.bottom = 0;
529
MapDialogRect(infoPtr->hwndSelf, &rect);
530
w = rect.left;
531
wc = rect.right;
532
width = rect.top;
533
534
GetClientRect(hwnd, &rect);
535
hDC = GetDC(hwnd);
536
region = CreateRectRgnIndirect(&rect);
537
SelectClipRgn(hDC, region);
538
DeleteObject(region);
539
540
point.x = (rect.right * infoPtr->h) / MAXHORI;
541
point.y = rect.bottom - (rect.bottom * infoPtr->s) / MAXVERT;
542
543
rect.left = point.x - w;
544
rect.right = point.x - wc;
545
rect.top = point.y - width;
546
rect.bottom = point.y + width;
547
FillRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
548
549
rect.left = point.x + wc;
550
rect.right = point.x + w;
551
FillRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
552
553
rect.left = point.x - width;
554
rect.right = point.x + width;
555
rect.top = point.y - w;
556
rect.bottom = point.y - wc;
557
FillRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
558
559
rect.top = point.y + wc;
560
rect.bottom = point.y + w;
561
FillRect(hDC, &rect, GetStockObject(BLACK_BRUSH));
562
563
ReleaseDC(hwnd, hDC);
564
}
565
}
566
567
568
#define XSTEPS 48
569
#define YSTEPS 24
570
571
572
/***********************************************************************
573
* CC_PrepareColorGraph [internal]
574
*/
575
static void CC_PrepareColorGraph(CCPRIV *infoPtr)
576
{
577
int sdif, hdif, xdif, ydif, hue, sat;
578
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
579
HBRUSH hbrush;
580
HDC hdc ;
581
RECT rect, client;
582
HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
583
584
GetClientRect(hwnd, &client);
585
hdc = GetDC(hwnd);
586
infoPtr->hdcMem = CreateCompatibleDC(hdc);
587
infoPtr->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
588
SelectObject(infoPtr->hdcMem, infoPtr->hbmMem);
589
590
xdif = client.right / XSTEPS;
591
ydif = client.bottom / YSTEPS+1;
592
hdif = 239 / XSTEPS;
593
sdif = 240 / YSTEPS;
594
for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
595
{
596
rect.right = rect.left + xdif;
597
rect.bottom = client.bottom;
598
for(sat = 0; sat < 240 + sdif; sat += sdif)
599
{
600
rect.top = rect.bottom - ydif;
601
hbrush = CreateSolidBrush(CC_HSLtoRGB(hue, sat, 120));
602
FillRect(infoPtr->hdcMem, &rect, hbrush);
603
DeleteObject(hbrush);
604
rect.bottom = rect.top;
605
}
606
rect.left = rect.right;
607
}
608
ReleaseDC(hwnd, hdc);
609
SetCursor(hcursor);
610
}
611
612
/***********************************************************************
613
* CC_PaintColorGraph [internal]
614
*/
615
static void CC_PaintColorGraph(CCPRIV *infoPtr)
616
{
617
HWND hwnd = GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW );
618
HDC hDC;
619
RECT rect;
620
621
if (IsWindowVisible(hwnd)) /* if full size */
622
{
623
if (!infoPtr->hdcMem)
624
CC_PrepareColorGraph(infoPtr); /* should not be necessary */
625
626
hDC = GetDC(hwnd);
627
GetClientRect(hwnd, &rect);
628
if (infoPtr->hdcMem)
629
BitBlt(hDC, 0, 0, rect.right, rect.bottom, infoPtr->hdcMem, 0, 0, SRCCOPY);
630
else
631
WARN("choose color: hdcMem is not defined\n");
632
ReleaseDC(hwnd, hDC);
633
}
634
}
635
636
/***********************************************************************
637
* CC_PaintLumBar [internal]
638
*/
639
static void CC_PaintLumBar(const CCPRIV *infoPtr)
640
{
641
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
642
RECT rect, client;
643
int lum, ldif, ydif;
644
HBRUSH hbrush;
645
HDC hDC;
646
647
if (IsWindowVisible(hwnd))
648
{
649
hDC = GetDC(hwnd);
650
GetClientRect(hwnd, &client);
651
rect = client;
652
653
ldif = 240 / YSTEPS;
654
ydif = client.bottom / YSTEPS+1;
655
for (lum = 0; lum < 240 + ldif; lum += ldif)
656
{
657
rect.top = max(0, rect.bottom - ydif);
658
hbrush = CreateSolidBrush(CC_HSLtoRGB(infoPtr->h, infoPtr->s, lum));
659
FillRect(hDC, &rect, hbrush);
660
DeleteObject(hbrush);
661
rect.bottom = rect.top;
662
}
663
GetClientRect(hwnd, &rect);
664
DrawEdge(hDC, &rect, BDR_SUNKENOUTER, BF_RECT);
665
ReleaseDC(hwnd, hDC);
666
}
667
}
668
669
/***********************************************************************
670
* CC_EditSetRGB [internal]
671
*/
672
static void CC_EditSetRGB( CCPRIV *infoPtr )
673
{
674
if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
675
{
676
COLORREF cr = infoPtr->lpcc->rgbResult;
677
int r = GetRValue(cr);
678
int g = GetGValue(cr);
679
int b = GetBValue(cr);
680
681
infoPtr->updating = TRUE;
682
SetDlgItemInt(infoPtr->hwndSelf, COLOR_RED, r, TRUE);
683
SetDlgItemInt(infoPtr->hwndSelf, COLOR_GREEN, g, TRUE);
684
SetDlgItemInt(infoPtr->hwndSelf, COLOR_BLUE, b, TRUE);
685
infoPtr->updating = FALSE;
686
}
687
}
688
689
/***********************************************************************
690
* CC_EditSetHSL [internal]
691
*/
692
static void CC_EditSetHSL( CCPRIV *infoPtr )
693
{
694
if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
695
{
696
infoPtr->updating = TRUE;
697
SetDlgItemInt(infoPtr->hwndSelf, COLOR_HUE, infoPtr->h, TRUE);
698
SetDlgItemInt(infoPtr->hwndSelf, COLOR_SAT, infoPtr->s, TRUE);
699
SetDlgItemInt(infoPtr->hwndSelf, COLOR_LUM, infoPtr->l, TRUE);
700
infoPtr->updating = FALSE;
701
}
702
CC_PaintLumBar(infoPtr);
703
}
704
705
/***********************************************************************
706
* CC_SwitchToFullSize [internal]
707
*/
708
static void CC_SwitchToFullSize( CCPRIV *infoPtr, const RECT *lprect )
709
{
710
int i;
711
712
EnableWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_MIX), FALSE);
713
CC_PrepareColorGraph(infoPtr);
714
for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
715
ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
716
for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
717
ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
718
ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_SOLID), SW_SHOW);
719
ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_ADD), SW_SHOW);
720
ShowWindow( GetDlgItem(infoPtr->hwndSelf, 1090), SW_SHOW);
721
722
if (lprect)
723
SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, lprect->right-lprect->left,
724
lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
725
726
ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL), SW_SHOW);
727
ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT), SW_SHOW);
728
729
CC_EditSetRGB(infoPtr);
730
CC_EditSetHSL(infoPtr);
731
ShowWindow( GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW), SW_SHOW);
732
UpdateWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) );
733
}
734
735
/***********************************************************************
736
* CC_PaintPredefColorArray [internal]
737
* Paints the default standard 48 colors
738
*/
739
static void CC_PaintPredefColorArray(const CCPRIV *infoPtr, int rows, int cols)
740
{
741
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_BOX1);
742
RECT rect, blockrect;
743
HDC hdc;
744
HBRUSH hBrush;
745
int dx, dy, i, j, k;
746
747
GetClientRect(hwnd, &rect);
748
dx = rect.right / cols;
749
dy = rect.bottom / rows;
750
k = rect.left;
751
752
hdc = GetDC(hwnd);
753
GetClientRect(hwnd, &rect);
754
hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
755
if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
756
FillRect(hdc, &rect, hBrush);
757
for ( j = 0; j < rows; j++ )
758
{
759
for ( i = 0; i < cols; i++ )
760
{
761
hBrush = CreateSolidBrush(predefcolors[j][i]);
762
if (hBrush)
763
{
764
blockrect.left = rect.left;
765
blockrect.top = rect.top;
766
blockrect.right = rect.left + dx - DISTANCE;
767
blockrect.bottom = rect.top + dy - DISTANCE;
768
FillRect(hdc, &blockrect, hBrush);
769
DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
770
DeleteObject(hBrush);
771
}
772
rect.left += dx;
773
}
774
rect.top += dy;
775
rect.left = k;
776
}
777
ReleaseDC(hwnd, hdc);
778
if (infoPtr->hwndFocus == hwnd)
779
CC_DrawCurrentFocusRect(infoPtr);
780
}
781
/***********************************************************************
782
* CC_PaintUserColorArray [internal]
783
* Paint the 16 user-selected colors
784
*/
785
static void CC_PaintUserColorArray(const CCPRIV *infoPtr, int rows, int cols)
786
{
787
HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CUSTOM1);
788
RECT rect, blockrect;
789
HDC hdc;
790
HBRUSH hBrush;
791
int dx, dy, i, j, k;
792
793
GetClientRect(hwnd, &rect);
794
795
dx = rect.right / cols;
796
dy = rect.bottom / rows;
797
k = rect.left;
798
799
hdc = GetDC(hwnd);
800
if (hdc)
801
{
802
hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
803
if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
804
FillRect( hdc, &rect, hBrush );
805
for (j = 0; j < rows; j++)
806
{
807
for (i = 0; i < cols; i++)
808
{
809
hBrush = CreateSolidBrush(infoPtr->lpcc->lpCustColors[i+j*cols]);
810
if (hBrush)
811
{
812
blockrect.left = rect.left;
813
blockrect.top = rect.top;
814
blockrect.right = rect.left + dx - DISTANCE;
815
blockrect.bottom = rect.top + dy - DISTANCE;
816
FillRect(hdc, &blockrect, hBrush);
817
DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
818
DeleteObject(hBrush);
819
}
820
rect.left += dx;
821
}
822
rect.top += dy;
823
rect.left = k;
824
}
825
ReleaseDC(hwnd, hdc);
826
}
827
if (infoPtr->hwndFocus == hwnd)
828
CC_DrawCurrentFocusRect(infoPtr);
829
}
830
831
832
/***********************************************************************
833
* CC_HookCallChk [internal]
834
*/
835
static BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
836
{
837
if (lpcc)
838
if(lpcc->Flags & CC_ENABLEHOOK)
839
if (lpcc->lpfnHook)
840
return TRUE;
841
return FALSE;
842
}
843
844
/***********************************************************************
845
* CC_WMInitDialog [internal]
846
*/
847
static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
848
{
849
CHOOSECOLORW *cc = (CHOOSECOLORW*)lParam;
850
int i;
851
LRESULT res;
852
int r, g, b;
853
HWND hwnd;
854
RECT rect;
855
POINT point;
856
CCPRIV *lpp;
857
858
TRACE("WM_INITDIALOG lParam=%08IX\n", lParam);
859
860
if (cc->lStructSize != sizeof(CHOOSECOLORW))
861
{
862
EndDialog(hDlg, 0);
863
return FALSE;
864
}
865
866
lpp = calloc(1, sizeof(*lpp));
867
lpp->lpcc = cc;
868
lpp->hwndSelf = hDlg;
869
870
SetPropW( hDlg, L"colourdialogprop", lpp );
871
872
if (!(lpp->lpcc->Flags & CC_SHOWHELP))
873
ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
874
lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
875
876
#if 0
877
cpos = MAKELONG(5,7); /* init */
878
if (lpp->lpcc->Flags & CC_RGBINIT)
879
{
880
for (i = 0; i < 6; i++)
881
for (j = 0; j < 8; j++)
882
if (predefcolors[i][j] == lpp->lpcc->rgbResult)
883
{
884
cpos = MAKELONG(i,j);
885
goto found;
886
}
887
}
888
found:
889
/* FIXME: Draw_a_focus_rect & set_init_values */
890
#endif
891
892
GetWindowRect(hDlg, &lpp->fullsize);
893
if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
894
{
895
hwnd = GetDlgItem(hDlg, COLOR_MIX);
896
EnableWindow(hwnd, FALSE);
897
}
898
if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
899
{
900
rect = lpp->fullsize;
901
res = rect.bottom - rect.top;
902
hwnd = GetDlgItem(hDlg, COLOR_RAINBOW); /* cut at left border */
903
point.x = point.y = 0;
904
ClientToScreen(hwnd, &point);
905
ScreenToClient(hDlg,&point);
906
GetClientRect(hDlg, &rect);
907
point.x += GetSystemMetrics(SM_CXDLGFRAME);
908
SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
909
910
for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
911
ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
912
for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
913
ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
914
ShowWindow( GetDlgItem(hDlg, COLOR_SOLID), SW_HIDE);
915
ShowWindow( GetDlgItem(hDlg, COLOR_ADD), SW_HIDE);
916
ShowWindow( GetDlgItem(hDlg, COLOR_RAINBOW), SW_HIDE);
917
ShowWindow( GetDlgItem(hDlg, COLOR_CURRENT), SW_HIDE);
918
ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
919
}
920
else
921
CC_SwitchToFullSize(lpp, NULL);
922
res = TRUE;
923
for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
924
SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
925
if (CC_HookCallChk(lpp->lpcc))
926
{
927
res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
928
}
929
930
/* Set the initial values of the color chooser dialog */
931
r = GetRValue(lpp->lpcc->rgbResult);
932
g = GetGValue(lpp->lpcc->rgbResult);
933
b = GetBValue(lpp->lpcc->rgbResult);
934
935
CC_PaintSelectedColor(lpp);
936
lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
937
lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
938
lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
939
940
/* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
941
SetDlgItemInt(hDlg, COLOR_HUE, lpp->h, TRUE);
942
SetDlgItemInt(hDlg, COLOR_SAT, lpp->s, TRUE);
943
SetDlgItemInt(hDlg, COLOR_LUM, lpp->l, TRUE);
944
SetDlgItemInt(hDlg, COLOR_RED, r, TRUE);
945
SetDlgItemInt(hDlg, COLOR_GREEN, g, TRUE);
946
SetDlgItemInt(hDlg, COLOR_BLUE, b, TRUE);
947
948
CC_PaintCross(lpp);
949
CC_PaintTriangle(lpp);
950
951
return res;
952
}
953
954
955
/***********************************************************************
956
* CC_WMCommand [internal]
957
*/
958
static LRESULT CC_WMCommand(CCPRIV *lpp, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl)
959
{
960
int r, g, b, i, xx;
961
UINT cokmsg;
962
HDC hdc;
963
COLORREF *cr;
964
965
TRACE("CC_WMCommand wParam=%Ix lParam=%Ix\n", wParam, lParam);
966
switch (LOWORD(wParam))
967
{
968
case COLOR_RED: /* edit notify RGB */
969
case COLOR_GREEN:
970
case COLOR_BLUE:
971
if (notifyCode == EN_UPDATE && !lpp->updating)
972
{
973
i = CC_CheckDigitsInEdit(lpp, hwndCtl, 255);
974
r = GetRValue(lpp->lpcc->rgbResult);
975
g = GetGValue(lpp->lpcc->rgbResult);
976
b = GetBValue(lpp->lpcc->rgbResult);
977
xx = 0;
978
switch (LOWORD(wParam))
979
{
980
case COLOR_RED: if ((xx = (i != r))) r = i; break;
981
case COLOR_GREEN: if ((xx = (i != g))) g = i; break;
982
case COLOR_BLUE: if ((xx = (i != b))) b = i; break;
983
}
984
if (xx) /* something has changed */
985
{
986
lpp->lpcc->rgbResult = RGB(r, g, b);
987
CC_PaintSelectedColor(lpp);
988
lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
989
lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
990
lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
991
CC_EditSetHSL(lpp);
992
CC_PaintCross(lpp);
993
CC_PaintTriangle(lpp);
994
}
995
}
996
break;
997
998
case COLOR_HUE: /* edit notify HSL */
999
case COLOR_SAT:
1000
case COLOR_LUM:
1001
if (notifyCode == EN_UPDATE && !lpp->updating)
1002
{
1003
i = CC_CheckDigitsInEdit(lpp, hwndCtl, LOWORD(wParam) == COLOR_HUE ? 239 : 240);
1004
xx = 0;
1005
switch (LOWORD(wParam))
1006
{
1007
case COLOR_HUE: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1008
case COLOR_SAT: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1009
case COLOR_LUM: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1010
}
1011
if (xx) /* something has changed */
1012
{
1013
lpp->lpcc->rgbResult = CC_HSLtoRGB(lpp->h, lpp->s, lpp->l);
1014
CC_PaintSelectedColor(lpp);
1015
CC_EditSetRGB(lpp);
1016
CC_PaintCross(lpp);
1017
CC_PaintTriangle(lpp);
1018
CC_PaintLumBar(lpp);
1019
}
1020
}
1021
break;
1022
1023
case COLOR_MIX:
1024
CC_SwitchToFullSize(lpp, &lpp->fullsize);
1025
SetFocus( GetDlgItem(lpp->hwndSelf, COLOR_HUE));
1026
break;
1027
1028
case COLOR_ADD: /* add colors ... column by column */
1029
cr = lpp->lpcc->lpCustColors;
1030
cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1031
if (++lpp->nextuserdef == 16)
1032
lpp->nextuserdef = 0;
1033
CC_PaintUserColorArray(lpp, 2, 8);
1034
break;
1035
1036
case COLOR_SOLID: /* resulting color */
1037
hdc = GetDC(lpp->hwndSelf);
1038
lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1039
ReleaseDC(lpp->hwndSelf, hdc);
1040
CC_EditSetRGB(lpp);
1041
CC_PaintSelectedColor(lpp);
1042
lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
1043
lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
1044
lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
1045
CC_EditSetHSL(lpp);
1046
CC_PaintCross(lpp);
1047
CC_PaintTriangle(lpp);
1048
break;
1049
1050
case pshHelp: /* Help! */ /* The Beatles, 1965 ;-) */
1051
i = RegisterWindowMessageA(HELPMSGSTRINGA);
1052
if (lpp->lpcc->hwndOwner)
1053
SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1054
if ( CC_HookCallChk(lpp->lpcc))
1055
CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, lpp->hwndSelf,
1056
WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1057
break;
1058
1059
case IDOK :
1060
cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1061
if (lpp->lpcc->hwndOwner)
1062
if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1063
break; /* do NOT close */
1064
EndDialog(lpp->hwndSelf, 1) ;
1065
return TRUE ;
1066
1067
case IDCANCEL :
1068
EndDialog(lpp->hwndSelf, 0) ;
1069
return TRUE ;
1070
1071
}
1072
return FALSE;
1073
}
1074
1075
/***********************************************************************
1076
* CC_WMPaint [internal]
1077
*/
1078
static LRESULT CC_WMPaint( CCPRIV *lpp )
1079
{
1080
PAINTSTRUCT ps;
1081
1082
BeginPaint(lpp->hwndSelf, &ps);
1083
/* we have to paint dialog children except text and buttons */
1084
CC_PaintPredefColorArray(lpp, 6, 8);
1085
CC_PaintUserColorArray(lpp, 2, 8);
1086
CC_PaintLumBar(lpp);
1087
CC_PaintTriangle(lpp);
1088
CC_PaintSelectedColor(lpp);
1089
CC_PaintColorGraph(lpp);
1090
CC_PaintCross(lpp);
1091
EndPaint(lpp->hwndSelf, &ps);
1092
1093
return TRUE;
1094
}
1095
1096
/***********************************************************************
1097
* CC_WMLButtonUp [internal]
1098
*/
1099
static LRESULT CC_WMLButtonUp( CCPRIV *infoPtr )
1100
{
1101
if (infoPtr->capturedGraph)
1102
{
1103
infoPtr->capturedGraph = 0;
1104
ReleaseCapture();
1105
CC_PaintColorGraph(infoPtr);
1106
CC_PaintCross(infoPtr);
1107
return 1;
1108
}
1109
return 0;
1110
}
1111
1112
/***********************************************************************
1113
* CC_WMMouseMove [internal]
1114
*/
1115
static LRESULT CC_WMMouseMove( CCPRIV *infoPtr, LPARAM lParam )
1116
{
1117
if (infoPtr->capturedGraph)
1118
{
1119
int *ptrh = NULL, *ptrs = &infoPtr->l;
1120
if (infoPtr->capturedGraph == COLOR_RAINBOW)
1121
{
1122
ptrh = &infoPtr->h;
1123
ptrs = &infoPtr->s;
1124
}
1125
if (CC_MouseCheckColorGraph( infoPtr->hwndSelf, infoPtr->capturedGraph, ptrh, ptrs, lParam))
1126
{
1127
infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1128
CC_EditSetRGB(infoPtr);
1129
CC_EditSetHSL(infoPtr);
1130
CC_PaintColorGraph(infoPtr);
1131
CC_PaintCross(infoPtr);
1132
CC_PaintTriangle(infoPtr);
1133
CC_PaintSelectedColor(infoPtr);
1134
}
1135
else
1136
{
1137
ReleaseCapture();
1138
infoPtr->capturedGraph = 0;
1139
}
1140
return 1;
1141
}
1142
return 0;
1143
}
1144
1145
/***********************************************************************
1146
* CC_WMLButtonDown [internal]
1147
*/
1148
static LRESULT CC_WMLButtonDown( CCPRIV *infoPtr, LPARAM lParam )
1149
{
1150
int i = 0;
1151
1152
if (CC_MouseCheckPredefColorArray(infoPtr, 6, 8, lParam))
1153
i = 1;
1154
else
1155
if (CC_MouseCheckUserColorArray(infoPtr, 2, 8, lParam))
1156
i = 1;
1157
else
1158
if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_RAINBOW, &infoPtr->h, &infoPtr->s, lParam))
1159
{
1160
i = 2;
1161
infoPtr->capturedGraph = COLOR_RAINBOW;
1162
}
1163
else
1164
if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_LUMSCROLL, NULL, &infoPtr->l, lParam))
1165
{
1166
i = 2;
1167
infoPtr->capturedGraph = COLOR_LUMSCROLL;
1168
}
1169
if ( i == 2 )
1170
{
1171
SetCapture(infoPtr->hwndSelf);
1172
infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1173
}
1174
if ( i == 1 )
1175
{
1176
infoPtr->h = CC_RGBtoHSL('H', infoPtr->lpcc->rgbResult);
1177
infoPtr->s = CC_RGBtoHSL('S', infoPtr->lpcc->rgbResult);
1178
infoPtr->l = CC_RGBtoHSL('L', infoPtr->lpcc->rgbResult);
1179
}
1180
if (i)
1181
{
1182
CC_EditSetRGB(infoPtr);
1183
CC_EditSetHSL(infoPtr);
1184
CC_PaintColorGraph(infoPtr);
1185
CC_PaintCross(infoPtr);
1186
CC_PaintTriangle(infoPtr);
1187
CC_PaintSelectedColor(infoPtr);
1188
return TRUE;
1189
}
1190
return FALSE;
1191
}
1192
1193
/***********************************************************************
1194
* ColorDlgProc32 [internal]
1195
*
1196
*/
1197
static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1198
WPARAM wParam, LPARAM lParam )
1199
{
1200
1201
INT_PTR res;
1202
CCPRIV *lpp = GetPropW( hDlg, L"colourdialogprop" );
1203
1204
if (message != WM_INITDIALOG)
1205
{
1206
if (!lpp)
1207
return FALSE;
1208
res = 0;
1209
if (CC_HookCallChk(lpp->lpcc))
1210
res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1211
if ( res )
1212
return res;
1213
}
1214
1215
/* FIXME: SetRGB message
1216
if (message && message == msetrgb)
1217
return HandleSetRGB(hDlg, lParam);
1218
*/
1219
1220
switch (message)
1221
{
1222
case WM_INITDIALOG:
1223
return CC_WMInitDialog(hDlg, wParam, lParam);
1224
case WM_NCDESTROY:
1225
DeleteDC(lpp->hdcMem);
1226
DeleteObject(lpp->hbmMem);
1227
free(lpp);
1228
RemovePropW( hDlg, L"colourdialogprop" );
1229
break;
1230
case WM_COMMAND:
1231
if (CC_WMCommand(lpp, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1232
return TRUE;
1233
break;
1234
case WM_PAINT:
1235
if (CC_WMPaint(lpp))
1236
return TRUE;
1237
break;
1238
case WM_LBUTTONDBLCLK:
1239
if (CC_MouseCheckResultWindow(hDlg, lParam))
1240
return TRUE;
1241
break;
1242
case WM_MOUSEMOVE:
1243
if (CC_WMMouseMove(lpp, lParam))
1244
return TRUE;
1245
break;
1246
case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1247
if (CC_WMLButtonUp(lpp))
1248
return TRUE;
1249
break;
1250
case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1251
if (CC_WMLButtonDown(lpp, lParam))
1252
return TRUE;
1253
break;
1254
}
1255
return FALSE ;
1256
}
1257
1258
/***********************************************************************
1259
* ChooseColorW (COMDLG32.@)
1260
*
1261
* Create a color dialog box.
1262
*
1263
* PARAMS
1264
* lpChCol [I/O] in: information to initialize the dialog box.
1265
* out: User's color selection
1266
*
1267
* RETURNS
1268
* TRUE: Ok button clicked.
1269
* FALSE: Cancel button clicked, or error.
1270
*/
1271
BOOL WINAPI ChooseColorW( CHOOSECOLORW *lpChCol )
1272
{
1273
HANDLE hDlgTmpl = 0;
1274
const void *template;
1275
1276
TRACE("(%p)\n", lpChCol);
1277
1278
if (!lpChCol) return FALSE;
1279
1280
if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1281
{
1282
if (!(template = LockResource(lpChCol->hInstance)))
1283
{
1284
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1285
return FALSE;
1286
}
1287
}
1288
else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1289
{
1290
HRSRC hResInfo;
1291
if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1292
lpChCol->lpTemplateName,
1293
(LPWSTR)RT_DIALOG)))
1294
{
1295
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1296
return FALSE;
1297
}
1298
if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1299
!(template = LockResource(hDlgTmpl)))
1300
{
1301
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1302
return FALSE;
1303
}
1304
}
1305
else
1306
{
1307
HRSRC hResInfo;
1308
HGLOBAL hDlgTmpl;
1309
if (!(hResInfo = FindResourceW(COMDLG32_hInstance, L"CHOOSE_COLOR", (LPWSTR)RT_DIALOG)))
1310
{
1311
COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1312
return FALSE;
1313
}
1314
if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1315
!(template = LockResource(hDlgTmpl)))
1316
{
1317
COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1318
return FALSE;
1319
}
1320
}
1321
1322
return DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1323
ColorDlgProc, (LPARAM)lpChCol);
1324
}
1325
1326
/***********************************************************************
1327
* ChooseColorA (COMDLG32.@)
1328
*
1329
* See ChooseColorW.
1330
*/
1331
BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1332
1333
{
1334
LPWSTR template_name = NULL;
1335
BOOL ret;
1336
1337
CHOOSECOLORW *lpcc = calloc(1, sizeof(*lpcc));
1338
lpcc->lStructSize = sizeof(*lpcc);
1339
lpcc->hwndOwner = lpChCol->hwndOwner;
1340
lpcc->hInstance = lpChCol->hInstance;
1341
lpcc->rgbResult = lpChCol->rgbResult;
1342
lpcc->lpCustColors = lpChCol->lpCustColors;
1343
lpcc->Flags = lpChCol->Flags;
1344
lpcc->lCustData = lpChCol->lCustData;
1345
lpcc->lpfnHook = lpChCol->lpfnHook;
1346
if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1347
if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
1348
INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1349
template_name = malloc( len * sizeof(WCHAR) );
1350
MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1351
lpcc->lpTemplateName = template_name;
1352
} else {
1353
lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1354
}
1355
}
1356
1357
ret = ChooseColorW(lpcc);
1358
1359
if (ret)
1360
lpChCol->rgbResult = lpcc->rgbResult;
1361
1362
free(template_name);
1363
free(lpcc);
1364
return ret;
1365
}
1366
1367