gdiplus: Use wide-char string literals.
[wine.git] / dlls / comdlg32 / colordlg.c
blob510e0723f261bee96ebc9ae7ae53242116ce8c74
1 /*
2 * COMMDLG - Color Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 2019 Vijay Kiran Kamuju
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.
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.
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
23 /* BUGS : still seems to not refresh correctly
24 sometimes, especially when 2 instances of the
25 dialog are loaded at the same time */
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"
39 #include "wine/debug.h"
40 #include "wine/heap.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
44 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
46 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
48 static const COLORREF predefcolors[6][8]=
50 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
51 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
52 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
53 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
55 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
56 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
57 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
58 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
60 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
61 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
62 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
63 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
66 static const WCHAR szColourDialogProp[] = {
67 'c','o','l','o','u','r','d','i','a','l','o','g','p','r','o','p',0 };
69 /* Chose Color PRIVATE Structure:
71 * This structure is duplicated in the 16 bit code with
72 * an extra member
75 typedef struct CCPRIVATE
77 LPCHOOSECOLORW lpcc; /* points to public known data structure */
78 HWND hwndSelf; /* dialog window */
79 int nextuserdef; /* next free place in user defined color array */
80 HDC hdcMem; /* color graph used for BitBlt() */
81 HBITMAP hbmMem; /* color graph bitmap */
82 RECT fullsize; /* original dialog window size */
83 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
84 RECT old3angle; /* last position of l-marker */
85 RECT oldcross; /* last position of color/saturation marker */
86 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
87 int h;
88 int s;
89 int l; /* for temporary storing of hue,sat,lum */
90 int capturedGraph; /* control mouse captured */
91 RECT focusRect; /* rectangle last focused item */
92 HWND hwndFocus; /* handle last focused item */
93 } CCPRIV;
95 static int hsl_to_x(int hue, int sat, int lum)
97 int res = 0, maxrgb;
99 /* l below 120 */
100 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
101 if (hue < 80)
102 res = 0;
103 else
104 if (hue < 120)
106 res = (hue - 80) * maxrgb; /* 0...10240 */
107 res /= 40; /* 0...256 */
109 else
110 if (hue < 200)
111 res = maxrgb;
112 else
114 res= (240 - hue) * maxrgb;
115 res /= 40;
117 res = res - maxrgb / 2; /* -128...128 */
119 /* saturation */
120 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
122 /* lum above 120 */
123 if (lum > 120 && res < 256)
124 res += ((lum - 120) * (256 - res)) / 120;
126 return min(res, 255);
129 /***********************************************************************
130 * CC_HSLtoRGB [internal]
132 static COLORREF CC_HSLtoRGB(int hue, int sat, int lum)
134 int h, r, g, b;
136 /* r */
137 h = hue > 80 ? hue-80 : hue+160;
138 r = hsl_to_x(h, sat, lum);
139 /* g */
140 h = hue > 160 ? hue-160 : hue+80;
141 g = hsl_to_x(h, sat, lum);
142 /* b */
143 b = hsl_to_x(hue, sat, lum);
145 return RGB(r, g, b);
148 /***********************************************************************
149 * CC_RGBtoHSL [internal]
151 static int CC_RGBtoHSL(char c, COLORREF rgb)
153 WORD maxi, mini, mmsum, mmdif, result = 0;
154 int iresult = 0, r, g, b;
156 r = GetRValue(rgb);
157 g = GetGValue(rgb);
158 b = GetBValue(rgb);
160 maxi = max(r, b);
161 maxi = max(maxi, g);
162 mini = min(r, b);
163 mini = min(mini, g);
165 mmsum = maxi + mini;
166 mmdif = maxi - mini;
168 switch(c)
170 /* lum */
171 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
172 result = mmsum / 255; /* 0...240 */
173 break;
174 /* saturation */
175 case 'S': if (!mmsum)
176 result = 0;
177 else
178 if (!mini || maxi == 255)
179 result = 240;
180 else
182 result = mmdif * 240; /* 0...61200=255*240 */
183 result /= (mmsum > 255 ? 510 - mmsum : mmsum); /* 0..255 */
185 break;
186 /* hue */
187 case 'H': if (!mmdif)
188 result = 160;
189 else
191 if (maxi == r)
193 iresult = 40 * (g - b); /* -10200 ... 10200 */
194 iresult /= (int) mmdif; /* -40 .. 40 */
195 if (iresult < 0)
196 iresult += 240; /* 0..40 and 200..240 */
198 else
199 if (maxi == g)
201 iresult = 40 * (b - r);
202 iresult /= (int) mmdif;
203 iresult += 80; /* 40 .. 120 */
205 else
206 if (maxi == b)
208 iresult = 40 * (r - g);
209 iresult /= (int) mmdif;
210 iresult += 160; /* 120 .. 200 */
212 result = iresult;
214 break;
216 return result; /* is this integer arithmetic precise enough ? */
220 /***********************************************************************
221 * CC_DrawCurrentFocusRect [internal]
223 static void CC_DrawCurrentFocusRect( const CCPRIV *lpp )
225 if (lpp->hwndFocus)
227 HDC hdc = GetDC(lpp->hwndFocus);
228 DrawFocusRect(hdc, &lpp->focusRect);
229 ReleaseDC(lpp->hwndFocus, hdc);
233 /***********************************************************************
234 * CC_DrawFocusRect [internal]
236 static void CC_DrawFocusRect(CCPRIV *lpp, HWND hwnd, int x, int y, int rows, int cols)
238 RECT rect;
239 int dx, dy;
240 HDC hdc;
242 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
243 /* calculate new rect */
244 GetClientRect(hwnd, &rect);
245 dx = (rect.right - rect.left) / cols;
246 dy = (rect.bottom - rect.top) / rows;
247 rect.left += (x * dx) - 2;
248 rect.top += (y * dy) - 2;
249 rect.right = rect.left + dx;
250 rect.bottom = rect.top + dy;
251 /* draw it */
252 hdc = GetDC(hwnd);
253 DrawFocusRect(hdc, &rect);
254 lpp->focusRect = rect;
255 lpp->hwndFocus = hwnd;
256 ReleaseDC(hwnd, hdc);
259 #define DISTANCE 4
261 /***********************************************************************
262 * CC_MouseCheckPredefColorArray [internal]
263 * returns TRUE if one of the predefined colors is clicked
265 static BOOL CC_MouseCheckPredefColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
267 HWND hwnd;
268 POINT point;
269 RECT rect;
270 int dx, dy, x, y;
272 CONV_LPARAMTOPOINT(lParam, &point);
273 ClientToScreen(lpp->hwndSelf, &point);
274 hwnd = GetDlgItem(lpp->hwndSelf, COLOR_BOX1);
275 GetWindowRect(hwnd, &rect);
276 if (PtInRect(&rect, point))
278 dx = (rect.right - rect.left) / cols;
279 dy = (rect.bottom - rect.top) / rows;
280 ScreenToClient(hwnd, &point);
282 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
284 x = point.x / dx;
285 y = point.y / dy;
286 lpp->lpcc->rgbResult = predefcolors[y][x];
287 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
288 return TRUE;
291 return FALSE;
294 /***********************************************************************
295 * CC_MouseCheckUserColorArray [internal]
296 * return TRUE if the user clicked a color
298 static BOOL CC_MouseCheckUserColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
300 HWND hwnd;
301 POINT point;
302 RECT rect;
303 int dx, dy, x, y;
304 COLORREF *crarr = lpp->lpcc->lpCustColors;
306 CONV_LPARAMTOPOINT(lParam, &point);
307 ClientToScreen(lpp->hwndSelf, &point);
308 hwnd = GetDlgItem(lpp->hwndSelf, COLOR_CUSTOM1);
309 GetWindowRect(hwnd, &rect);
310 if (PtInRect(&rect, point))
312 dx = (rect.right - rect.left) / cols;
313 dy = (rect.bottom - rect.top) / rows;
314 ScreenToClient(hwnd, &point);
316 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
318 x = point.x / dx;
319 y = point.y / dy;
320 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
321 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
322 return TRUE;
325 return FALSE;
328 #define MAXVERT 240
329 #define MAXHORI 239
331 /* 240 ^...... ^^ 240
332 | . ||
333 SAT | . || LUM
334 | . ||
335 +-----> 239 ----
338 /***********************************************************************
339 * CC_MouseCheckColorGraph [internal]
341 static BOOL CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
343 HWND hwnd;
344 POINT point;
345 RECT rect;
346 long x,y;
348 CONV_LPARAMTOPOINT(lParam, &point);
349 ClientToScreen(hDlg, &point);
350 hwnd = GetDlgItem( hDlg, dlgitem );
351 GetWindowRect(hwnd, &rect);
353 if (!PtInRect(&rect, point))
354 return FALSE;
356 GetClientRect(hwnd, &rect);
357 ScreenToClient(hwnd, &point);
359 x = (long) point.x * MAXHORI;
360 x /= rect.right;
361 y = (long) (rect.bottom - point.y) * MAXVERT;
362 y /= rect.bottom;
364 if (x < 0) x = 0;
365 if (y < 0) y = 0;
366 if (x > MAXHORI) x = MAXHORI;
367 if (y > MAXVERT) y = MAXVERT;
369 if (hori)
370 *hori = x;
371 if (vert)
372 *vert = y;
374 return TRUE;
376 /***********************************************************************
377 * CC_MouseCheckResultWindow [internal]
378 * test if double click one of the result colors
380 static BOOL CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
382 HWND hwnd;
383 POINT point;
384 RECT rect;
386 CONV_LPARAMTOPOINT(lParam, &point);
387 ClientToScreen(hDlg, &point);
388 hwnd = GetDlgItem(hDlg, COLOR_CURRENT);
389 GetWindowRect(hwnd, &rect);
390 if (PtInRect(&rect, point))
392 PostMessageA(hDlg, WM_COMMAND, COLOR_SOLID, 0);
393 return TRUE;
395 return FALSE;
398 /***********************************************************************
399 * CC_CheckDigitsInEdit [internal]
401 static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
403 int i, k, m, result, value;
404 long editpos;
405 char buffer[30];
407 GetWindowTextA(hwnd, buffer, ARRAY_SIZE(buffer));
408 m = strlen(buffer);
409 result = 0;
411 for (i = 0 ; i < m ; i++)
412 if (buffer[i] < '0' || buffer[i] > '9')
414 for (k = i + 1; k <= m; k++) /* delete bad character */
416 buffer[i] = buffer[k];
417 m--;
419 buffer[m] = 0;
420 result = 1;
423 value = atoi(buffer);
424 if (value > maxval) /* build a new string */
426 sprintf(buffer, "%d", maxval);
427 result = 2;
429 if (result)
431 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
432 SetWindowTextA(hwnd, buffer );
433 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
435 return value;
440 /***********************************************************************
441 * CC_PaintSelectedColor [internal]
443 static void CC_PaintSelectedColor(const CCPRIV *infoPtr)
445 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
447 RECT rect;
448 HDC hdc;
449 HBRUSH hBrush;
450 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT);
452 hdc = GetDC(hwnd);
453 GetClientRect(hwnd, &rect) ;
454 hBrush = CreateSolidBrush(infoPtr->lpcc->rgbResult);
455 if (hBrush)
457 FillRect(hdc, &rect, hBrush);
458 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
459 DeleteObject(hBrush);
461 ReleaseDC(hwnd, hdc);
465 /***********************************************************************
466 * CC_PaintTriangle [internal]
468 static void CC_PaintTriangle(CCPRIV *infoPtr)
470 HDC hDC;
471 long temp;
472 int w = LOWORD(GetDialogBaseUnits()) / 2;
473 POINT points[3];
474 int height;
475 int oben;
476 RECT rect;
477 HBRUSH hbr;
478 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
480 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW))) /* if full size */
482 GetClientRect(hwnd, &rect);
483 height = rect.bottom;
484 hDC = GetDC(infoPtr->hwndSelf);
485 points[0].y = rect.top;
486 points[0].x = rect.right; /* | /| */
487 ClientToScreen(hwnd, points); /* | / | */
488 ScreenToClient(infoPtr->hwndSelf, points); /* |< | */
489 oben = points[0].y; /* | \ | */
490 /* | \| */
491 temp = (long)height * (long)infoPtr->l;
492 points[0].x += 1;
493 points[0].y = oben + height - temp / (long)MAXVERT;
494 points[1].y = points[0].y + w;
495 points[2].y = points[0].y - w;
496 points[2].x = points[1].x = points[0].x + w;
498 hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
499 if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
500 FillRect(hDC, &infoPtr->old3angle, hbr);
501 infoPtr->old3angle.left = points[0].x;
502 infoPtr->old3angle.right = points[1].x + 1;
503 infoPtr->old3angle.top = points[2].y - 1;
504 infoPtr->old3angle.bottom= points[1].y + 1;
506 hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
507 Polygon(hDC, points, 3);
508 SelectObject(hDC, hbr);
510 ReleaseDC(infoPtr->hwndSelf, hDC);
515 /***********************************************************************
516 * CC_PaintCross [internal]
518 static void CC_PaintCross(CCPRIV *infoPtr)
520 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
522 if (IsWindowVisible(hwnd)) /* if full size */
524 HDC hDC;
525 int w = GetDialogBaseUnits() - 1;
526 int wc = GetDialogBaseUnits() * 3 / 4;
527 RECT rect;
528 POINT point, p;
529 HPEN hPen;
530 int x, y;
532 x = infoPtr->h;
533 y = infoPtr->s;
535 GetClientRect(hwnd, &rect);
536 hDC = GetDC(hwnd);
537 SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
539 point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
540 point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
541 if ( infoPtr->oldcross.left != infoPtr->oldcross.right )
542 BitBlt(hDC, infoPtr->oldcross.left, infoPtr->oldcross.top,
543 infoPtr->oldcross.right - infoPtr->oldcross.left,
544 infoPtr->oldcross.bottom - infoPtr->oldcross.top,
545 infoPtr->hdcMem, infoPtr->oldcross.left, infoPtr->oldcross.top, SRCCOPY);
546 infoPtr->oldcross.left = point.x - w - 1;
547 infoPtr->oldcross.right = point.x + w + 1;
548 infoPtr->oldcross.top = point.y - w - 1;
549 infoPtr->oldcross.bottom = point.y + w + 1;
551 hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0)); /* -black- color */
552 hPen = SelectObject(hDC, hPen);
553 MoveToEx(hDC, point.x - w, point.y, &p);
554 LineTo(hDC, point.x - wc, point.y);
555 MoveToEx(hDC, point.x + wc, point.y, &p);
556 LineTo(hDC, point.x + w, point.y);
557 MoveToEx(hDC, point.x, point.y - w, &p);
558 LineTo(hDC, point.x, point.y - wc);
559 MoveToEx(hDC, point.x, point.y + wc, &p);
560 LineTo(hDC, point.x, point.y + w);
561 DeleteObject( SelectObject(hDC, hPen));
563 ReleaseDC(hwnd, hDC);
568 #define XSTEPS 48
569 #define YSTEPS 24
572 /***********************************************************************
573 * CC_PrepareColorGraph [internal]
575 static void CC_PrepareColorGraph(CCPRIV *infoPtr)
577 int sdif, hdif, xdif, ydif, hue, sat;
578 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
579 HBRUSH hbrush;
580 HDC hdc ;
581 RECT rect, client;
582 HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
584 GetClientRect(hwnd, &client);
585 hdc = GetDC(hwnd);
586 infoPtr->hdcMem = CreateCompatibleDC(hdc);
587 infoPtr->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
588 SelectObject(infoPtr->hdcMem, infoPtr->hbmMem);
590 xdif = client.right / XSTEPS;
591 ydif = client.bottom / YSTEPS+1;
592 hdif = 239 / XSTEPS;
593 sdif = 240 / YSTEPS;
594 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
596 rect.right = rect.left + xdif;
597 rect.bottom = client.bottom;
598 for(sat = 0; sat < 240 + sdif; sat += sdif)
600 rect.top = rect.bottom - ydif;
601 hbrush = CreateSolidBrush(CC_HSLtoRGB(hue, sat, 120));
602 FillRect(infoPtr->hdcMem, &rect, hbrush);
603 DeleteObject(hbrush);
604 rect.bottom = rect.top;
606 rect.left = rect.right;
608 ReleaseDC(hwnd, hdc);
609 SetCursor(hcursor);
612 /***********************************************************************
613 * CC_PaintColorGraph [internal]
615 static void CC_PaintColorGraph(CCPRIV *infoPtr)
617 HWND hwnd = GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW );
618 HDC hDC;
619 RECT rect;
621 if (IsWindowVisible(hwnd)) /* if full size */
623 if (!infoPtr->hdcMem)
624 CC_PrepareColorGraph(infoPtr); /* should not be necessary */
626 hDC = GetDC(hwnd);
627 GetClientRect(hwnd, &rect);
628 if (infoPtr->hdcMem)
629 BitBlt(hDC, 0, 0, rect.right, rect.bottom, infoPtr->hdcMem, 0, 0, SRCCOPY);
630 else
631 WARN("choose color: hdcMem is not defined\n");
632 ReleaseDC(hwnd, hDC);
636 /***********************************************************************
637 * CC_PaintLumBar [internal]
639 static void CC_PaintLumBar(const CCPRIV *infoPtr)
641 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
642 RECT rect, client;
643 int lum, ldif, ydif;
644 HBRUSH hbrush;
645 HDC hDC;
647 if (IsWindowVisible(hwnd))
649 hDC = GetDC(hwnd);
650 GetClientRect(hwnd, &client);
651 rect = client;
653 ldif = 240 / YSTEPS;
654 ydif = client.bottom / YSTEPS+1;
655 for (lum = 0; lum < 240 + ldif; lum += ldif)
657 rect.top = max(0, rect.bottom - ydif);
658 hbrush = CreateSolidBrush(CC_HSLtoRGB(infoPtr->h, infoPtr->s, lum));
659 FillRect(hDC, &rect, hbrush);
660 DeleteObject(hbrush);
661 rect.bottom = rect.top;
663 GetClientRect(hwnd, &rect);
664 DrawEdge(hDC, &rect, BDR_SUNKENOUTER, BF_RECT);
665 ReleaseDC(hwnd, hDC);
669 /***********************************************************************
670 * CC_EditSetRGB [internal]
672 static void CC_EditSetRGB( CCPRIV *infoPtr )
674 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
676 COLORREF cr = infoPtr->lpcc->rgbResult;
677 int r = GetRValue(cr);
678 int g = GetGValue(cr);
679 int b = GetBValue(cr);
681 infoPtr->updating = TRUE;
682 SetDlgItemInt(infoPtr->hwndSelf, COLOR_RED, r, TRUE);
683 SetDlgItemInt(infoPtr->hwndSelf, COLOR_GREEN, g, TRUE);
684 SetDlgItemInt(infoPtr->hwndSelf, COLOR_BLUE, b, TRUE);
685 infoPtr->updating = FALSE;
689 /***********************************************************************
690 * CC_EditSetHSL [internal]
692 static void CC_EditSetHSL( CCPRIV *infoPtr )
694 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
696 infoPtr->updating = TRUE;
697 SetDlgItemInt(infoPtr->hwndSelf, COLOR_HUE, infoPtr->h, TRUE);
698 SetDlgItemInt(infoPtr->hwndSelf, COLOR_SAT, infoPtr->s, TRUE);
699 SetDlgItemInt(infoPtr->hwndSelf, COLOR_LUM, infoPtr->l, TRUE);
700 infoPtr->updating = FALSE;
702 CC_PaintLumBar(infoPtr);
705 /***********************************************************************
706 * CC_SwitchToFullSize [internal]
708 static void CC_SwitchToFullSize( CCPRIV *infoPtr, const RECT *lprect )
710 int i;
712 EnableWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_MIX), FALSE);
713 CC_PrepareColorGraph(infoPtr);
714 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
715 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
716 for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
717 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
718 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_SOLID), SW_SHOW);
719 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_ADD), SW_SHOW);
720 ShowWindow( GetDlgItem(infoPtr->hwndSelf, 1090), SW_SHOW);
722 if (lprect)
723 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, lprect->right-lprect->left,
724 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
726 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL), SW_SHOW);
727 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT), SW_SHOW);
729 CC_EditSetRGB(infoPtr);
730 CC_EditSetHSL(infoPtr);
731 ShowWindow( GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW), SW_SHOW);
732 UpdateWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) );
735 /***********************************************************************
736 * CC_PaintPredefColorArray [internal]
737 * Paints the default standard 48 colors
739 static void CC_PaintPredefColorArray(const CCPRIV *infoPtr, int rows, int cols)
741 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_BOX1);
742 RECT rect, blockrect;
743 HDC hdc;
744 HBRUSH hBrush;
745 int dx, dy, i, j, k;
747 GetClientRect(hwnd, &rect);
748 dx = rect.right / cols;
749 dy = rect.bottom / rows;
750 k = rect.left;
752 hdc = GetDC(hwnd);
753 GetClientRect(hwnd, &rect);
754 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
755 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
756 FillRect(hdc, &rect, hBrush);
757 for ( j = 0; j < rows; j++ )
759 for ( i = 0; i < cols; i++ )
761 hBrush = CreateSolidBrush(predefcolors[j][i]);
762 if (hBrush)
764 blockrect.left = rect.left;
765 blockrect.top = rect.top;
766 blockrect.right = rect.left + dx - DISTANCE;
767 blockrect.bottom = rect.top + dy - DISTANCE;
768 FillRect(hdc, &blockrect, hBrush);
769 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
770 DeleteObject(hBrush);
772 rect.left += dx;
774 rect.top += dy;
775 rect.left = k;
777 ReleaseDC(hwnd, hdc);
778 if (infoPtr->hwndFocus == hwnd)
779 CC_DrawCurrentFocusRect(infoPtr);
781 /***********************************************************************
782 * CC_PaintUserColorArray [internal]
783 * Paint the 16 user-selected colors
785 static void CC_PaintUserColorArray(const CCPRIV *infoPtr, int rows, int cols)
787 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CUSTOM1);
788 RECT rect, blockrect;
789 HDC hdc;
790 HBRUSH hBrush;
791 int dx, dy, i, j, k;
793 GetClientRect(hwnd, &rect);
795 dx = rect.right / cols;
796 dy = rect.bottom / rows;
797 k = rect.left;
799 hdc = GetDC(hwnd);
800 if (hdc)
802 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
803 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
804 FillRect( hdc, &rect, hBrush );
805 for (j = 0; j < rows; j++)
807 for (i = 0; i < cols; i++)
809 hBrush = CreateSolidBrush(infoPtr->lpcc->lpCustColors[i+j*cols]);
810 if (hBrush)
812 blockrect.left = rect.left;
813 blockrect.top = rect.top;
814 blockrect.right = rect.left + dx - DISTANCE;
815 blockrect.bottom = rect.top + dy - DISTANCE;
816 FillRect(hdc, &blockrect, hBrush);
817 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
818 DeleteObject(hBrush);
820 rect.left += dx;
822 rect.top += dy;
823 rect.left = k;
825 ReleaseDC(hwnd, hdc);
827 if (infoPtr->hwndFocus == hwnd)
828 CC_DrawCurrentFocusRect(infoPtr);
832 /***********************************************************************
833 * CC_HookCallChk [internal]
835 static BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
837 if (lpcc)
838 if(lpcc->Flags & CC_ENABLEHOOK)
839 if (lpcc->lpfnHook)
840 return TRUE;
841 return FALSE;
844 /***********************************************************************
845 * CC_WMInitDialog [internal]
847 static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
849 CHOOSECOLORW *cc = (CHOOSECOLORW*)lParam;
850 int i, res;
851 int r, g, b;
852 HWND hwnd;
853 RECT rect;
854 POINT point;
855 CCPRIV *lpp;
857 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
859 if (cc->lStructSize != sizeof(CHOOSECOLORW))
861 EndDialog(hDlg, 0);
862 return FALSE;
865 lpp = heap_alloc_zero(sizeof(*lpp));
866 lpp->lpcc = cc;
867 lpp->hwndSelf = hDlg;
869 SetPropW( hDlg, szColourDialogProp, lpp );
871 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
872 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
873 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
875 #if 0
876 cpos = MAKELONG(5,7); /* init */
877 if (lpp->lpcc->Flags & CC_RGBINIT)
879 for (i = 0; i < 6; i++)
880 for (j = 0; j < 8; j++)
881 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
883 cpos = MAKELONG(i,j);
884 goto found;
887 found:
888 /* FIXME: Draw_a_focus_rect & set_init_values */
889 #endif
891 GetWindowRect(hDlg, &lpp->fullsize);
892 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
894 hwnd = GetDlgItem(hDlg, COLOR_MIX);
895 EnableWindow(hwnd, FALSE);
897 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
899 rect = lpp->fullsize;
900 res = rect.bottom - rect.top;
901 hwnd = GetDlgItem(hDlg, COLOR_RAINBOW); /* cut at left border */
902 point.x = point.y = 0;
903 ClientToScreen(hwnd, &point);
904 ScreenToClient(hDlg,&point);
905 GetClientRect(hDlg, &rect);
906 point.x += GetSystemMetrics(SM_CXDLGFRAME);
907 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
909 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
910 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
911 for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
912 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
913 ShowWindow( GetDlgItem(hDlg, COLOR_SOLID), SW_HIDE);
914 ShowWindow( GetDlgItem(hDlg, COLOR_ADD), SW_HIDE);
915 ShowWindow( GetDlgItem(hDlg, COLOR_RAINBOW), SW_HIDE);
916 ShowWindow( GetDlgItem(hDlg, COLOR_CURRENT), SW_HIDE);
917 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
919 else
920 CC_SwitchToFullSize(lpp, NULL);
921 res = TRUE;
922 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
923 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
924 if (CC_HookCallChk(lpp->lpcc))
926 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
929 /* Set the initial values of the color chooser dialog */
930 r = GetRValue(lpp->lpcc->rgbResult);
931 g = GetGValue(lpp->lpcc->rgbResult);
932 b = GetBValue(lpp->lpcc->rgbResult);
934 CC_PaintSelectedColor(lpp);
935 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
936 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
937 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
939 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
940 SetDlgItemInt(hDlg, COLOR_HUE, lpp->h, TRUE);
941 SetDlgItemInt(hDlg, COLOR_SAT, lpp->s, TRUE);
942 SetDlgItemInt(hDlg, COLOR_LUM, lpp->l, TRUE);
943 SetDlgItemInt(hDlg, COLOR_RED, r, TRUE);
944 SetDlgItemInt(hDlg, COLOR_GREEN, g, TRUE);
945 SetDlgItemInt(hDlg, COLOR_BLUE, b, TRUE);
947 CC_PaintCross(lpp);
948 CC_PaintTriangle(lpp);
950 return res;
954 /***********************************************************************
955 * CC_WMCommand [internal]
957 static LRESULT CC_WMCommand(CCPRIV *lpp, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl)
959 int r, g, b, i, xx;
960 UINT cokmsg;
961 HDC hdc;
962 COLORREF *cr;
964 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam, lParam);
965 switch (LOWORD(wParam))
967 case COLOR_RED: /* edit notify RGB */
968 case COLOR_GREEN:
969 case COLOR_BLUE:
970 if (notifyCode == EN_UPDATE && !lpp->updating)
972 i = CC_CheckDigitsInEdit(hwndCtl, 255);
973 r = GetRValue(lpp->lpcc->rgbResult);
974 g = GetGValue(lpp->lpcc->rgbResult);
975 b= GetBValue(lpp->lpcc->rgbResult);
976 xx = 0;
977 switch (LOWORD(wParam))
979 case COLOR_RED: if ((xx = (i != r))) r = i; break;
980 case COLOR_GREEN: if ((xx = (i != g))) g = i; break;
981 case COLOR_BLUE: if ((xx = (i != b))) b = i; break;
983 if (xx) /* something has changed */
985 lpp->lpcc->rgbResult = RGB(r, g, b);
986 CC_PaintSelectedColor(lpp);
987 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
988 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
989 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
990 CC_EditSetHSL(lpp);
991 CC_PaintCross(lpp);
992 CC_PaintTriangle(lpp);
995 break;
997 case COLOR_HUE: /* edit notify HSL */
998 case COLOR_SAT:
999 case COLOR_LUM:
1000 if (notifyCode == EN_UPDATE && !lpp->updating)
1002 i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == COLOR_HUE ? 239 : 240);
1003 xx = 0;
1004 switch (LOWORD(wParam))
1006 case COLOR_HUE: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1007 case COLOR_SAT: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1008 case COLOR_LUM: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1010 if (xx) /* something has changed */
1012 lpp->lpcc->rgbResult = CC_HSLtoRGB(lpp->h, lpp->s, lpp->l);
1013 CC_PaintSelectedColor(lpp);
1014 CC_EditSetRGB(lpp);
1015 CC_PaintCross(lpp);
1016 CC_PaintTriangle(lpp);
1019 break;
1021 case COLOR_MIX:
1022 CC_SwitchToFullSize(lpp, &lpp->fullsize);
1023 SetFocus( GetDlgItem(lpp->hwndSelf, COLOR_HUE));
1024 break;
1026 case COLOR_ADD: /* add colors ... column by column */
1027 cr = lpp->lpcc->lpCustColors;
1028 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1029 if (++lpp->nextuserdef == 16)
1030 lpp->nextuserdef = 0;
1031 CC_PaintUserColorArray(lpp, 2, 8);
1032 break;
1034 case COLOR_SOLID: /* resulting color */
1035 hdc = GetDC(lpp->hwndSelf);
1036 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1037 ReleaseDC(lpp->hwndSelf, hdc);
1038 CC_EditSetRGB(lpp);
1039 CC_PaintSelectedColor(lpp);
1040 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
1041 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
1042 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
1043 CC_EditSetHSL(lpp);
1044 CC_PaintCross(lpp);
1045 CC_PaintTriangle(lpp);
1046 break;
1048 case pshHelp: /* Help! */ /* The Beatles, 1965 ;-) */
1049 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1050 if (lpp->lpcc->hwndOwner)
1051 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1052 if ( CC_HookCallChk(lpp->lpcc))
1053 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, lpp->hwndSelf,
1054 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1055 break;
1057 case IDOK :
1058 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1059 if (lpp->lpcc->hwndOwner)
1060 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1061 break; /* do NOT close */
1062 EndDialog(lpp->hwndSelf, 1) ;
1063 return TRUE ;
1065 case IDCANCEL :
1066 EndDialog(lpp->hwndSelf, 0) ;
1067 return TRUE ;
1070 return FALSE;
1073 /***********************************************************************
1074 * CC_WMPaint [internal]
1076 static LRESULT CC_WMPaint( CCPRIV *lpp )
1078 PAINTSTRUCT ps;
1080 BeginPaint(lpp->hwndSelf, &ps);
1081 /* we have to paint dialog children except text and buttons */
1082 CC_PaintPredefColorArray(lpp, 6, 8);
1083 CC_PaintUserColorArray(lpp, 2, 8);
1084 CC_PaintLumBar(lpp);
1085 CC_PaintTriangle(lpp);
1086 CC_PaintSelectedColor(lpp);
1087 CC_PaintColorGraph(lpp);
1088 CC_PaintCross(lpp);
1089 EndPaint(lpp->hwndSelf, &ps);
1091 return TRUE;
1094 /***********************************************************************
1095 * CC_WMLButtonUp [internal]
1097 static LRESULT CC_WMLButtonUp( CCPRIV *infoPtr )
1099 if (infoPtr->capturedGraph)
1101 infoPtr->capturedGraph = 0;
1102 ReleaseCapture();
1103 CC_PaintCross(infoPtr);
1104 return 1;
1106 return 0;
1109 /***********************************************************************
1110 * CC_WMMouseMove [internal]
1112 static LRESULT CC_WMMouseMove( CCPRIV *infoPtr, LPARAM lParam )
1114 if (infoPtr->capturedGraph)
1116 int *ptrh = NULL, *ptrs = &infoPtr->l;
1117 if (infoPtr->capturedGraph == COLOR_RAINBOW)
1119 ptrh = &infoPtr->h;
1120 ptrs = &infoPtr->s;
1122 if (CC_MouseCheckColorGraph( infoPtr->hwndSelf, infoPtr->capturedGraph, ptrh, ptrs, lParam))
1124 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1125 CC_EditSetRGB(infoPtr);
1126 CC_EditSetHSL(infoPtr);
1127 CC_PaintCross(infoPtr);
1128 CC_PaintTriangle(infoPtr);
1129 CC_PaintSelectedColor(infoPtr);
1131 else
1133 ReleaseCapture();
1134 infoPtr->capturedGraph = 0;
1136 return 1;
1138 return 0;
1141 /***********************************************************************
1142 * CC_WMLButtonDown [internal]
1144 static LRESULT CC_WMLButtonDown( CCPRIV *infoPtr, LPARAM lParam )
1146 int i = 0;
1148 if (CC_MouseCheckPredefColorArray(infoPtr, 6, 8, lParam))
1149 i = 1;
1150 else
1151 if (CC_MouseCheckUserColorArray(infoPtr, 2, 8, lParam))
1152 i = 1;
1153 else
1154 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_RAINBOW, &infoPtr->h, &infoPtr->s, lParam))
1156 i = 2;
1157 infoPtr->capturedGraph = COLOR_RAINBOW;
1159 else
1160 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_LUMSCROLL, NULL, &infoPtr->l, lParam))
1162 i = 2;
1163 infoPtr->capturedGraph = COLOR_LUMSCROLL;
1165 if ( i == 2 )
1167 SetCapture(infoPtr->hwndSelf);
1168 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1170 if ( i == 1 )
1172 infoPtr->h = CC_RGBtoHSL('H', infoPtr->lpcc->rgbResult);
1173 infoPtr->s = CC_RGBtoHSL('S', infoPtr->lpcc->rgbResult);
1174 infoPtr->l = CC_RGBtoHSL('L', infoPtr->lpcc->rgbResult);
1176 if (i)
1178 CC_EditSetRGB(infoPtr);
1179 CC_EditSetHSL(infoPtr);
1180 CC_PaintCross(infoPtr);
1181 CC_PaintTriangle(infoPtr);
1182 CC_PaintSelectedColor(infoPtr);
1183 return TRUE;
1185 return FALSE;
1188 /***********************************************************************
1189 * ColorDlgProc32 [internal]
1192 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1193 WPARAM wParam, LPARAM lParam )
1196 int res;
1197 CCPRIV *lpp = GetPropW( hDlg, szColourDialogProp );
1199 if (message != WM_INITDIALOG)
1201 if (!lpp)
1202 return FALSE;
1203 res = 0;
1204 if (CC_HookCallChk(lpp->lpcc))
1205 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1206 if ( res )
1207 return res;
1210 /* FIXME: SetRGB message
1211 if (message && message == msetrgb)
1212 return HandleSetRGB(hDlg, lParam);
1215 switch (message)
1217 case WM_INITDIALOG:
1218 return CC_WMInitDialog(hDlg, wParam, lParam);
1219 case WM_NCDESTROY:
1220 DeleteDC(lpp->hdcMem);
1221 DeleteObject(lpp->hbmMem);
1222 heap_free(lpp);
1223 RemovePropW( hDlg, szColourDialogProp );
1224 break;
1225 case WM_COMMAND:
1226 if (CC_WMCommand(lpp, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1227 return TRUE;
1228 break;
1229 case WM_PAINT:
1230 if (CC_WMPaint(lpp))
1231 return TRUE;
1232 break;
1233 case WM_LBUTTONDBLCLK:
1234 if (CC_MouseCheckResultWindow(hDlg, lParam))
1235 return TRUE;
1236 break;
1237 case WM_MOUSEMOVE:
1238 if (CC_WMMouseMove(lpp, lParam))
1239 return TRUE;
1240 break;
1241 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1242 if (CC_WMLButtonUp(lpp))
1243 return TRUE;
1244 break;
1245 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1246 if (CC_WMLButtonDown(lpp, lParam))
1247 return TRUE;
1248 break;
1250 return FALSE ;
1253 /***********************************************************************
1254 * ChooseColorW (COMDLG32.@)
1256 * Create a color dialog box.
1258 * PARAMS
1259 * lpChCol [I/O] in: information to initialize the dialog box.
1260 * out: User's color selection
1262 * RETURNS
1263 * TRUE: Ok button clicked.
1264 * FALSE: Cancel button clicked, or error.
1266 BOOL WINAPI ChooseColorW( CHOOSECOLORW *lpChCol )
1268 HANDLE hDlgTmpl = 0;
1269 const void *template;
1271 TRACE("(%p)\n", lpChCol);
1273 if (!lpChCol) return FALSE;
1275 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1277 if (!(template = LockResource(lpChCol->hInstance)))
1279 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1280 return FALSE;
1283 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1285 HRSRC hResInfo;
1286 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1287 lpChCol->lpTemplateName,
1288 (LPWSTR)RT_DIALOG)))
1290 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1291 return FALSE;
1293 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1294 !(template = LockResource(hDlgTmpl)))
1296 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1297 return FALSE;
1300 else
1302 HRSRC hResInfo;
1303 HGLOBAL hDlgTmpl;
1304 static const WCHAR wszCHOOSE_COLOR[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1305 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, wszCHOOSE_COLOR, (LPWSTR)RT_DIALOG)))
1307 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1308 return FALSE;
1310 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1311 !(template = LockResource(hDlgTmpl)))
1313 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1314 return FALSE;
1318 return DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1319 ColorDlgProc, (LPARAM)lpChCol);
1322 /***********************************************************************
1323 * ChooseColorA (COMDLG32.@)
1325 * See ChooseColorW.
1327 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1330 LPWSTR template_name = NULL;
1331 BOOL ret;
1333 CHOOSECOLORW *lpcc = heap_alloc_zero(sizeof(*lpcc));
1334 lpcc->lStructSize = sizeof(*lpcc);
1335 lpcc->hwndOwner = lpChCol->hwndOwner;
1336 lpcc->hInstance = lpChCol->hInstance;
1337 lpcc->rgbResult = lpChCol->rgbResult;
1338 lpcc->lpCustColors = lpChCol->lpCustColors;
1339 lpcc->Flags = lpChCol->Flags;
1340 lpcc->lCustData = lpChCol->lCustData;
1341 lpcc->lpfnHook = lpChCol->lpfnHook;
1342 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1343 if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
1344 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1345 template_name = heap_alloc( len * sizeof(WCHAR) );
1346 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1347 lpcc->lpTemplateName = template_name;
1348 } else {
1349 lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1353 ret = ChooseColorW(lpcc);
1355 if (ret)
1356 lpChCol->rgbResult = lpcc->rgbResult;
1358 heap_free(template_name);
1359 heap_free(lpcc);
1360 return ret;