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