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