[SHELL32]
[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 CopyRect(&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 char buffer[10];
665
666 infoPtr->updating = TRUE;
667 sprintf(buffer, "%d", r);
668 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_R), buffer);
669 sprintf(buffer, "%d", g);
670 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_G), buffer);
671 sprintf( buffer, "%d", b );
672 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_B), buffer);
673 infoPtr->updating = FALSE;
674 }
675 }
676
677 /***********************************************************************
678 * CC_EditSetHSL [internal]
679 */
680 static void CC_EditSetHSL( CCPRIV *infoPtr )
681 {
682 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_GRAPH) )) /* if full size */
683 {
684 char buffer[10];
685
686 infoPtr->updating = TRUE;
687 sprintf(buffer, "%d", infoPtr->h);
688 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_H), buffer);
689 sprintf(buffer, "%d", infoPtr->s);
690 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_S), buffer);
691 sprintf(buffer, "%d", infoPtr->l);
692 SetWindowTextA( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_EDIT_L), buffer);
693 infoPtr->updating = FALSE;
694 }
695 CC_PaintLumBar(infoPtr);
696 }
697
698 /***********************************************************************
699 * CC_SwitchToFullSize [internal]
700 */
701 static void CC_SwitchToFullSize( CCPRIV *infoPtr, const RECT *lprect )
702 {
703 int i;
704
705 EnableWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_DEFINE), FALSE);
706 CC_PrepareColorGraph(infoPtr);
707 for (i = IDC_COLOR_EDIT_H; i <= IDC_COLOR_EDIT_B; i++)
708 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
709 for (i = IDC_COLOR_HL; i <= IDC_COLOR_BL; i++)
710 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
711 ShowWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_RES), SW_SHOW);
712 ShowWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_ADD), SW_SHOW);
713 ShowWindow( GetDlgItem(infoPtr->hwndSelf, 1090), SW_SHOW);
714
715 if (lprect)
716 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, lprect->right-lprect->left,
717 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
718
719 ShowWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_LUMBAR), SW_SHOW);
720 ShowWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_RESULT), SW_SHOW);
721
722 CC_EditSetRGB(infoPtr);
723 CC_EditSetHSL(infoPtr);
724 ShowWindow( GetDlgItem( infoPtr->hwndSelf, IDC_COLOR_GRAPH), SW_SHOW);
725 UpdateWindow( GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_GRAPH) );
726 }
727
728 /***********************************************************************
729 * CC_PaintPredefColorArray [internal]
730 * Paints the default standard 48 colors
731 */
732 static void CC_PaintPredefColorArray(const CCPRIV *infoPtr, int rows, int cols)
733 {
734 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_PREDEF);
735 RECT rect, blockrect;
736 HDC hdc;
737 HBRUSH hBrush;
738 int dx, dy, i, j, k;
739
740 GetClientRect(hwnd, &rect);
741 dx = rect.right / cols;
742 dy = rect.bottom / rows;
743 k = rect.left;
744
745 hdc = GetDC(hwnd);
746 GetClientRect(hwnd, &rect);
747 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
748 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
749 FillRect(hdc, &rect, hBrush);
750 for ( j = 0; j < rows; j++ )
751 {
752 for ( i = 0; i < cols; i++ )
753 {
754 hBrush = CreateSolidBrush(predefcolors[j][i]);
755 if (hBrush)
756 {
757 blockrect.left = rect.left;
758 blockrect.top = rect.top;
759 blockrect.right = rect.left + dx - DISTANCE;
760 blockrect.bottom = rect.top + dy - DISTANCE;
761 FillRect(hdc, &blockrect, hBrush);
762 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
763 DeleteObject(hBrush);
764 }
765 rect.left += dx;
766 }
767 rect.top += dy;
768 rect.left = k;
769 }
770 ReleaseDC(hwnd, hdc);
771 if (infoPtr->hwndFocus == hwnd)
772 CC_DrawCurrentFocusRect(infoPtr);
773 }
774 /***********************************************************************
775 * CC_PaintUserColorArray [internal]
776 * Paint the 16 user-selected colors
777 */
778 static void CC_PaintUserColorArray(const CCPRIV *infoPtr, int rows, int cols)
779 {
780 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, IDC_COLOR_USRDEF);
781 RECT rect, blockrect;
782 HDC hdc;
783 HBRUSH hBrush;
784 int dx, dy, i, j, k;
785
786 GetClientRect(hwnd, &rect);
787
788 dx = rect.right / cols;
789 dy = rect.bottom / rows;
790 k = rect.left;
791
792 hdc = GetDC(hwnd);
793 if (hdc)
794 {
795 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
796 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
797 FillRect( hdc, &rect, hBrush );
798 for (j = 0; j < rows; j++)
799 {
800 for (i = 0; i < cols; i++)
801 {
802 hBrush = CreateSolidBrush(infoPtr->lpcc->lpCustColors[i+j*cols]);
803 if (hBrush)
804 {
805 blockrect.left = rect.left;
806 blockrect.top = rect.top;
807 blockrect.right = rect.left + dx - DISTANCE;
808 blockrect.bottom = rect.top + dy - DISTANCE;
809 FillRect(hdc, &blockrect, hBrush);
810 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
811 DeleteObject(hBrush);
812 }
813 rect.left += dx;
814 }
815 rect.top += dy;
816 rect.left = k;
817 }
818 ReleaseDC(hwnd, hdc);
819 }
820 if (infoPtr->hwndFocus == hwnd)
821 CC_DrawCurrentFocusRect(infoPtr);
822 }
823
824
825 /***********************************************************************
826 * CC_HookCallChk [internal]
827 */
828 static BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
829 {
830 if (lpcc)
831 if(lpcc->Flags & CC_ENABLEHOOK)
832 if (lpcc->lpfnHook)
833 return TRUE;
834 return FALSE;
835 }
836
837 /***********************************************************************
838 * CC_WMInitDialog [internal]
839 */
840 static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
841 {
842 CHOOSECOLORW *cc = (CHOOSECOLORW*)lParam;
843 int i, res;
844 int r, g, b;
845 HWND hwnd;
846 RECT rect;
847 POINT point;
848 CCPRIV *lpp;
849
850 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
851
852 if (cc->lStructSize != sizeof(CHOOSECOLORW))
853 {
854 EndDialog(hDlg, 0);
855 return FALSE;
856 }
857
858 lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
859 lpp->lpcc = cc;
860 lpp->hwndSelf = hDlg;
861
862 SetPropW( hDlg, szColourDialogProp, lpp );
863
864 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
865 ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
866 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
867
868 #if 0
869 cpos = MAKELONG(5,7); /* init */
870 if (lpp->lpcc->Flags & CC_RGBINIT)
871 {
872 for (i = 0; i < 6; i++)
873 for (j = 0; j < 8; j++)
874 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
875 {
876 cpos = MAKELONG(i,j);
877 goto found;
878 }
879 }
880 found:
881 /* FIXME: Draw_a_focus_rect & set_init_values */
882 #endif
883
884 GetWindowRect(hDlg, &lpp->fullsize);
885 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
886 {
887 hwnd = GetDlgItem(hDlg, IDC_COLOR_DEFINE);
888 EnableWindow(hwnd, FALSE);
889 }
890 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
891 {
892 rect = lpp->fullsize;
893 res = rect.bottom - rect.top;
894 hwnd = GetDlgItem(hDlg, IDC_COLOR_GRAPH); /* cut at left border */
895 point.x = point.y = 0;
896 ClientToScreen(hwnd, &point);
897 ScreenToClient(hDlg,&point);
898 GetClientRect(hDlg, &rect);
899 point.x += GetSystemMetrics(SM_CXDLGFRAME);
900 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
901
902 for (i = IDC_COLOR_EDIT_H; i <= IDC_COLOR_EDIT_B; i++)
903 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
904 for (i = IDC_COLOR_HL; i <= IDC_COLOR_BL; i++)
905 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
906 ShowWindow( GetDlgItem(hDlg, IDC_COLOR_RES), SW_HIDE);
907 ShowWindow( GetDlgItem(hDlg, IDC_COLOR_ADD), SW_HIDE);
908 ShowWindow( GetDlgItem(hDlg, IDC_COLOR_GRAPH), SW_HIDE);
909 ShowWindow( GetDlgItem(hDlg, IDC_COLOR_RESULT), SW_HIDE);
910 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
911 }
912 else
913 CC_SwitchToFullSize(lpp, NULL);
914 res = TRUE;
915 for (i = IDC_COLOR_EDIT_H; i <= IDC_COLOR_EDIT_B; i++)
916 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
917 if (CC_HookCallChk(lpp->lpcc))
918 {
919 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
920 }
921
922 /* Set the initial values of the color chooser dialog */
923 r = GetRValue(lpp->lpcc->rgbResult);
924 g = GetGValue(lpp->lpcc->rgbResult);
925 b = GetBValue(lpp->lpcc->rgbResult);
926
927 CC_PaintSelectedColor(lpp);
928 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
929 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
930 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
931
932 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
933 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_H, lpp->h, TRUE);
934 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_S, lpp->s, TRUE);
935 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_L, lpp->l, TRUE);
936 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_R, r, TRUE);
937 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_G, g, TRUE);
938 SetDlgItemInt(hDlg, IDC_COLOR_EDIT_B, b, TRUE);
939
940 CC_PaintCross(lpp);
941 CC_PaintTriangle(lpp);
942
943 return res;
944 }
945
946
947 /***********************************************************************
948 * CC_WMCommand [internal]
949 */
950 static LRESULT CC_WMCommand(CCPRIV *lpp, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl)
951 {
952 int r, g, b, i, xx;
953 UINT cokmsg;
954 HDC hdc;
955 COLORREF *cr;
956
957 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam, lParam);
958 switch (LOWORD(wParam))
959 {
960 case IDC_COLOR_EDIT_R: /* edit notify RGB */
961 case IDC_COLOR_EDIT_G:
962 case IDC_COLOR_EDIT_B:
963 if (notifyCode == EN_UPDATE && !lpp->updating)
964 {
965 i = CC_CheckDigitsInEdit(hwndCtl, 255);
966 r = GetRValue(lpp->lpcc->rgbResult);
967 g = GetGValue(lpp->lpcc->rgbResult);
968 b= GetBValue(lpp->lpcc->rgbResult);
969 xx = 0;
970 switch (LOWORD(wParam))
971 {
972 case IDC_COLOR_EDIT_R: if ((xx = (i != r))) r = i; break;
973 case IDC_COLOR_EDIT_G: if ((xx = (i != g))) g = i; break;
974 case IDC_COLOR_EDIT_B: if ((xx = (i != b))) b = i; break;
975 }
976 if (xx) /* something has changed */
977 {
978 lpp->lpcc->rgbResult = RGB(r, g, b);
979 CC_PaintSelectedColor(lpp);
980 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
981 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
982 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
983 CC_EditSetHSL(lpp);
984 CC_PaintCross(lpp);
985 CC_PaintTriangle(lpp);
986 }
987 }
988 break;
989
990 case IDC_COLOR_EDIT_H: /* edit notify HSL */
991 case IDC_COLOR_EDIT_S:
992 case IDC_COLOR_EDIT_L:
993 if (notifyCode == EN_UPDATE && !lpp->updating)
994 {
995 i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == IDC_COLOR_EDIT_H ? 239 : 240);
996 xx = 0;
997 switch (LOWORD(wParam))
998 {
999 case IDC_COLOR_EDIT_H: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1000 case IDC_COLOR_EDIT_S: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1001 case IDC_COLOR_EDIT_L: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1002 }
1003 if (xx) /* something has changed */
1004 {
1005 lpp->lpcc->rgbResult = CC_HSLtoRGB(lpp->h, lpp->s, lpp->l);
1006 CC_PaintSelectedColor(lpp);
1007 CC_EditSetRGB(lpp);
1008 CC_PaintCross(lpp);
1009 CC_PaintTriangle(lpp);
1010 }
1011 }
1012 break;
1013
1014 case IDC_COLOR_DEFINE:
1015 CC_SwitchToFullSize(lpp, &lpp->fullsize);
1016 SetFocus( GetDlgItem(lpp->hwndSelf, IDC_COLOR_EDIT_H));
1017 break;
1018
1019 case IDC_COLOR_ADD: /* add colors ... column by column */
1020 cr = lpp->lpcc->lpCustColors;
1021 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1022 if (++lpp->nextuserdef == 16)
1023 lpp->nextuserdef = 0;
1024 CC_PaintUserColorArray(lpp, 2, 8);
1025 break;
1026
1027 case IDC_COLOR_RES: /* resulting color */
1028 hdc = GetDC(lpp->hwndSelf);
1029 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1030 ReleaseDC(lpp->hwndSelf, hdc);
1031 CC_EditSetRGB(lpp);
1032 CC_PaintSelectedColor(lpp);
1033 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
1034 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
1035 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
1036 CC_EditSetHSL(lpp);
1037 CC_PaintCross(lpp);
1038 CC_PaintTriangle(lpp);
1039 break;
1040
1041 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1042 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1043 if (lpp->lpcc->hwndOwner)
1044 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1045 if ( CC_HookCallChk(lpp->lpcc))
1046 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, lpp->hwndSelf,
1047 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1048 break;
1049
1050 case IDOK :
1051 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1052 if (lpp->lpcc->hwndOwner)
1053 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1054 break; /* do NOT close */
1055 EndDialog(lpp->hwndSelf, 1) ;
1056 return TRUE ;
1057
1058 case IDCANCEL :
1059 EndDialog(lpp->hwndSelf, 0) ;
1060 return TRUE ;
1061
1062 }
1063 return FALSE;
1064 }
1065
1066 /***********************************************************************
1067 * CC_WMPaint [internal]
1068 */
1069 static LRESULT CC_WMPaint( CCPRIV *lpp )
1070 {
1071 PAINTSTRUCT ps;
1072
1073 BeginPaint(lpp->hwndSelf, &ps);
1074 /* we have to paint dialog children except text and buttons */
1075 CC_PaintPredefColorArray(lpp, 6, 8);
1076 CC_PaintUserColorArray(lpp, 2, 8);
1077 CC_PaintLumBar(lpp);
1078 CC_PaintTriangle(lpp);
1079 CC_PaintSelectedColor(lpp);
1080 CC_PaintColorGraph(lpp);
1081 CC_PaintCross(lpp);
1082 EndPaint(lpp->hwndSelf, &ps);
1083
1084 return TRUE;
1085 }
1086
1087 /***********************************************************************
1088 * CC_WMLButtonUp [internal]
1089 */
1090 static LRESULT CC_WMLButtonUp( CCPRIV *infoPtr )
1091 {
1092 if (infoPtr->capturedGraph)
1093 {
1094 infoPtr->capturedGraph = 0;
1095 ReleaseCapture();
1096 CC_PaintCross(infoPtr);
1097 return 1;
1098 }
1099 return 0;
1100 }
1101
1102 /***********************************************************************
1103 * CC_WMMouseMove [internal]
1104 */
1105 static LRESULT CC_WMMouseMove( CCPRIV *infoPtr, LPARAM lParam )
1106 {
1107 if (infoPtr->capturedGraph)
1108 {
1109 int *ptrh = NULL, *ptrs = &infoPtr->l;
1110 if (infoPtr->capturedGraph == IDC_COLOR_GRAPH)
1111 {
1112 ptrh = &infoPtr->h;
1113 ptrs = &infoPtr->s;
1114 }
1115 if (CC_MouseCheckColorGraph( infoPtr->hwndSelf, infoPtr->capturedGraph, ptrh, ptrs, lParam))
1116 {
1117 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1118 CC_EditSetRGB(infoPtr);
1119 CC_EditSetHSL(infoPtr);
1120 CC_PaintCross(infoPtr);
1121 CC_PaintTriangle(infoPtr);
1122 CC_PaintSelectedColor(infoPtr);
1123 }
1124 else
1125 {
1126 ReleaseCapture();
1127 infoPtr->capturedGraph = 0;
1128 }
1129 return 1;
1130 }
1131 return 0;
1132 }
1133
1134 /***********************************************************************
1135 * CC_WMLButtonDown [internal]
1136 */
1137 static LRESULT CC_WMLButtonDown( CCPRIV *infoPtr, LPARAM lParam )
1138 {
1139 int i = 0;
1140
1141 if (CC_MouseCheckPredefColorArray(infoPtr, 6, 8, lParam))
1142 i = 1;
1143 else
1144 if (CC_MouseCheckUserColorArray(infoPtr, 2, 8, lParam))
1145 i = 1;
1146 else
1147 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, IDC_COLOR_GRAPH, &infoPtr->h, &infoPtr->s, lParam))
1148 {
1149 i = 2;
1150 infoPtr->capturedGraph = IDC_COLOR_GRAPH;
1151 }
1152 else
1153 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, IDC_COLOR_LUMBAR, NULL, &infoPtr->l, lParam))
1154 {
1155 i = 2;
1156 infoPtr->capturedGraph = IDC_COLOR_LUMBAR;
1157 }
1158 if ( i == 2 )
1159 {
1160 SetCapture(infoPtr->hwndSelf);
1161 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1162 }
1163 if ( i == 1 )
1164 {
1165 infoPtr->h = CC_RGBtoHSL('H', infoPtr->lpcc->rgbResult);
1166 infoPtr->s = CC_RGBtoHSL('S', infoPtr->lpcc->rgbResult);
1167 infoPtr->l = CC_RGBtoHSL('L', infoPtr->lpcc->rgbResult);
1168 }
1169 if (i)
1170 {
1171 CC_EditSetRGB(infoPtr);
1172 CC_EditSetHSL(infoPtr);
1173 CC_PaintCross(infoPtr);
1174 CC_PaintTriangle(infoPtr);
1175 CC_PaintSelectedColor(infoPtr);
1176 return TRUE;
1177 }
1178 return FALSE;
1179 }
1180
1181 /***********************************************************************
1182 * ColorDlgProc32 [internal]
1183 *
1184 */
1185 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1186 WPARAM wParam, LPARAM lParam )
1187 {
1188
1189 int res;
1190 CCPRIV *lpp = GetPropW( hDlg, szColourDialogProp );
1191
1192 if (message != WM_INITDIALOG)
1193 {
1194 if (!lpp)
1195 return FALSE;
1196 res = 0;
1197 if (CC_HookCallChk(lpp->lpcc))
1198 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1199 if ( res )
1200 return res;
1201 }
1202
1203 /* FIXME: SetRGB message
1204 if (message && message == msetrgb)
1205 return HandleSetRGB(hDlg, lParam);
1206 */
1207
1208 switch (message)
1209 {
1210 case WM_INITDIALOG:
1211 return CC_WMInitDialog(hDlg, wParam, lParam);
1212 case WM_NCDESTROY:
1213 DeleteDC(lpp->hdcMem);
1214 DeleteObject(lpp->hbmMem);
1215 HeapFree(GetProcessHeap(), 0, lpp);
1216 RemovePropW( hDlg, szColourDialogProp );
1217 break;
1218 case WM_COMMAND:
1219 if (CC_WMCommand(lpp, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1220 return TRUE;
1221 break;
1222 case WM_PAINT:
1223 if (CC_WMPaint(lpp))
1224 return TRUE;
1225 break;
1226 case WM_LBUTTONDBLCLK:
1227 if (CC_MouseCheckResultWindow(hDlg, lParam))
1228 return TRUE;
1229 break;
1230 case WM_MOUSEMOVE:
1231 if (CC_WMMouseMove(lpp, lParam))
1232 return TRUE;
1233 break;
1234 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1235 if (CC_WMLButtonUp(lpp))
1236 return TRUE;
1237 break;
1238 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1239 if (CC_WMLButtonDown(lpp, lParam))
1240 return TRUE;
1241 break;
1242 }
1243 return FALSE ;
1244 }
1245
1246 /***********************************************************************
1247 * ChooseColorW (COMDLG32.@)
1248 *
1249 * Create a color dialog box.
1250 *
1251 * PARAMS
1252 * lpChCol [I/O] in: information to initialize the dialog box.
1253 * out: User's color selection
1254 *
1255 * RETURNS
1256 * TRUE: Ok button clicked.
1257 * FALSE: Cancel button clicked, or error.
1258 */
1259 BOOL WINAPI ChooseColorW( CHOOSECOLORW *lpChCol )
1260 {
1261 HANDLE hDlgTmpl = 0;
1262 const void *template;
1263
1264 TRACE("(%p)\n", lpChCol);
1265
1266 if (!lpChCol) return FALSE;
1267
1268 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1269 {
1270 if (!(template = LockResource(lpChCol->hInstance)))
1271 {
1272 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1273 return FALSE;
1274 }
1275 }
1276 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1277 {
1278 HRSRC hResInfo;
1279 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1280 lpChCol->lpTemplateName,
1281 (LPWSTR)RT_DIALOG)))
1282 {
1283 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1284 return FALSE;
1285 }
1286 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1287 !(template = LockResource(hDlgTmpl)))
1288 {
1289 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1290 return FALSE;
1291 }
1292 }
1293 else
1294 {
1295 HRSRC hResInfo;
1296 HGLOBAL hDlgTmpl;
1297 static const WCHAR wszCHOOSE_COLOR[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1298 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, wszCHOOSE_COLOR, (LPWSTR)RT_DIALOG)))
1299 {
1300 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1301 return FALSE;
1302 }
1303 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1304 !(template = LockResource(hDlgTmpl)))
1305 {
1306 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1307 return FALSE;
1308 }
1309 }
1310
1311 return DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1312 ColorDlgProc, (LPARAM)lpChCol);
1313 }
1314
1315 /***********************************************************************
1316 * ChooseColorA (COMDLG32.@)
1317 *
1318 * See ChooseColorW.
1319 */
1320 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1321
1322 {
1323 LPWSTR template_name = NULL;
1324 BOOL ret;
1325
1326 LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
1327 lpcc->lStructSize = sizeof(*lpcc);
1328 lpcc->hwndOwner = lpChCol->hwndOwner;
1329 lpcc->hInstance = lpChCol->hInstance;
1330 lpcc->rgbResult = lpChCol->rgbResult;
1331 lpcc->lpCustColors = lpChCol->lpCustColors;
1332 lpcc->Flags = lpChCol->Flags;
1333 lpcc->lCustData = lpChCol->lCustData;
1334 lpcc->lpfnHook = lpChCol->lpfnHook;
1335 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1336 if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
1337 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1338 template_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1339 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1340 lpcc->lpTemplateName = template_name;
1341 } else {
1342 lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1343 }
1344 }
1345
1346 ret = ChooseColorW(lpcc);
1347
1348 if (ret)
1349 lpChCol->rgbResult = lpcc->rgbResult;
1350 HeapFree(GetProcessHeap(), 0, template_name);
1351 HeapFree(GetProcessHeap(), 0, lpcc);
1352 return ret;
1353 }