wow32: Use spec file imports.
[wine.git] / dlls / comdlg32 / colordlg.c
blobe16014c8d193db14964a0f67982ae17672dc68dd
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 /* Chose Color PRIVATE Structure:
68 * This structure is duplicated in the 16 bit code with
69 * an extra member
72 typedef struct CCPRIVATE
74 LPCHOOSECOLORW lpcc; /* points to public known data structure */
75 HWND hwndSelf; /* dialog window */
76 int nextuserdef; /* next free place in user defined color array */
77 HDC hdcMem; /* color graph used for BitBlt() */
78 HBITMAP hbmMem; /* color graph bitmap */
79 RECT fullsize; /* original dialog window size */
80 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
81 RECT old3angle; /* last position of l-marker */
82 RECT oldcross; /* last position of color/saturation marker */
83 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
84 int h;
85 int s;
86 int l; /* for temporary storing of hue,sat,lum */
87 int capturedGraph; /* control mouse captured */
88 RECT focusRect; /* rectangle last focused item */
89 HWND hwndFocus; /* handle last focused item */
90 } CCPRIV;
92 static int hsl_to_x(int hue, int sat, int lum)
94 int res = 0, maxrgb;
96 /* l below 120 */
97 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
98 if (hue < 80)
99 res = 0;
100 else
101 if (hue < 120)
103 res = (hue - 80) * maxrgb; /* 0...10240 */
104 res /= 40; /* 0...256 */
106 else
107 if (hue < 200)
108 res = maxrgb;
109 else
111 res= (240 - hue) * maxrgb;
112 res /= 40;
114 res = res - maxrgb / 2; /* -128...128 */
116 /* saturation */
117 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
119 /* lum above 120 */
120 if (lum > 120 && res < 256)
121 res += ((lum - 120) * (256 - res)) / 120;
123 return min(res, 255);
126 /***********************************************************************
127 * CC_HSLtoRGB [internal]
129 static COLORREF CC_HSLtoRGB(int hue, int sat, int lum)
131 int h, r, g, b;
133 /* r */
134 h = hue > 80 ? hue-80 : hue+160;
135 r = hsl_to_x(h, sat, lum);
136 /* g */
137 h = hue > 160 ? hue-160 : hue+80;
138 g = hsl_to_x(h, sat, lum);
139 /* b */
140 b = hsl_to_x(hue, sat, lum);
142 return RGB(r, g, b);
145 /***********************************************************************
146 * CC_RGBtoHSL [internal]
148 static int CC_RGBtoHSL(char c, COLORREF rgb)
150 WORD maxi, mini, mmsum, mmdif, result = 0;
151 int iresult = 0, r, g, b;
153 r = GetRValue(rgb);
154 g = GetGValue(rgb);
155 b = GetBValue(rgb);
157 maxi = max(r, b);
158 maxi = max(maxi, g);
159 mini = min(r, b);
160 mini = min(mini, g);
162 mmsum = maxi + mini;
163 mmdif = maxi - mini;
165 switch(c)
167 /* lum */
168 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
169 result = mmsum / 255; /* 0...240 */
170 break;
171 /* saturation */
172 case 'S': if (!mmsum)
173 result = 0;
174 else
175 if (!mini || maxi == 255)
176 result = 240;
177 else
179 result = mmdif * 240; /* 0...61200=255*240 */
180 result /= (mmsum > 255 ? 510 - mmsum : mmsum); /* 0..255 */
182 break;
183 /* hue */
184 case 'H': if (!mmdif)
185 result = 160;
186 else
188 if (maxi == r)
190 iresult = 40 * (g - b); /* -10200 ... 10200 */
191 iresult /= (int) mmdif; /* -40 .. 40 */
192 if (iresult < 0)
193 iresult += 240; /* 0..40 and 200..240 */
195 else
196 if (maxi == g)
198 iresult = 40 * (b - r);
199 iresult /= (int) mmdif;
200 iresult += 80; /* 40 .. 120 */
202 else
203 if (maxi == b)
205 iresult = 40 * (r - g);
206 iresult /= (int) mmdif;
207 iresult += 160; /* 120 .. 200 */
209 result = iresult;
211 break;
213 return result; /* is this integer arithmetic precise enough ? */
217 /***********************************************************************
218 * CC_DrawCurrentFocusRect [internal]
220 static void CC_DrawCurrentFocusRect( const CCPRIV *lpp )
222 if (lpp->hwndFocus)
224 HDC hdc = GetDC(lpp->hwndFocus);
225 DrawFocusRect(hdc, &lpp->focusRect);
226 ReleaseDC(lpp->hwndFocus, hdc);
230 /***********************************************************************
231 * CC_DrawFocusRect [internal]
233 static void CC_DrawFocusRect(CCPRIV *lpp, HWND hwnd, int x, int y, int rows, int cols)
235 RECT rect;
236 int dx, dy;
237 HDC hdc;
239 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
240 /* calculate new rect */
241 GetClientRect(hwnd, &rect);
242 dx = (rect.right - rect.left) / cols;
243 dy = (rect.bottom - rect.top) / rows;
244 rect.left += (x * dx) - 2;
245 rect.top += (y * dy) - 2;
246 rect.right = rect.left + dx;
247 rect.bottom = rect.top + dy;
248 /* draw it */
249 hdc = GetDC(hwnd);
250 DrawFocusRect(hdc, &rect);
251 lpp->focusRect = rect;
252 lpp->hwndFocus = hwnd;
253 ReleaseDC(hwnd, hdc);
256 #define DISTANCE 4
258 /***********************************************************************
259 * CC_MouseCheckPredefColorArray [internal]
260 * returns TRUE if one of the predefined colors is clicked
262 static BOOL CC_MouseCheckPredefColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
264 HWND hwnd;
265 POINT point;
266 RECT rect;
267 int dx, dy, x, y;
269 CONV_LPARAMTOPOINT(lParam, &point);
270 ClientToScreen(lpp->hwndSelf, &point);
271 hwnd = GetDlgItem(lpp->hwndSelf, COLOR_BOX1);
272 GetWindowRect(hwnd, &rect);
273 if (PtInRect(&rect, point))
275 dx = (rect.right - rect.left) / cols;
276 dy = (rect.bottom - rect.top) / rows;
277 ScreenToClient(hwnd, &point);
279 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
281 x = point.x / dx;
282 y = point.y / dy;
283 lpp->lpcc->rgbResult = predefcolors[y][x];
284 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
285 return TRUE;
288 return FALSE;
291 /***********************************************************************
292 * CC_MouseCheckUserColorArray [internal]
293 * return TRUE if the user clicked a color
295 static BOOL CC_MouseCheckUserColorArray(CCPRIV *lpp, int rows, int cols, LPARAM lParam)
297 HWND hwnd;
298 POINT point;
299 RECT rect;
300 int dx, dy, x, y;
301 COLORREF *crarr = lpp->lpcc->lpCustColors;
303 CONV_LPARAMTOPOINT(lParam, &point);
304 ClientToScreen(lpp->hwndSelf, &point);
305 hwnd = GetDlgItem(lpp->hwndSelf, COLOR_CUSTOM1);
306 GetWindowRect(hwnd, &rect);
307 if (PtInRect(&rect, point))
309 dx = (rect.right - rect.left) / cols;
310 dy = (rect.bottom - rect.top) / rows;
311 ScreenToClient(hwnd, &point);
313 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
315 x = point.x / dx;
316 y = point.y / dy;
317 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
318 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
319 return TRUE;
322 return FALSE;
325 #define MAXVERT 240
326 #define MAXHORI 239
328 /* 240 ^...... ^^ 240
329 | . ||
330 SAT | . || LUM
331 | . ||
332 +-----> 239 ----
335 /***********************************************************************
336 * CC_MouseCheckColorGraph [internal]
338 static BOOL CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
340 HWND hwnd;
341 POINT point;
342 RECT rect;
343 int x,y;
345 CONV_LPARAMTOPOINT(lParam, &point);
346 ClientToScreen(hDlg, &point);
347 hwnd = GetDlgItem( hDlg, dlgitem );
348 GetWindowRect(hwnd, &rect);
350 if (!PtInRect(&rect, point))
351 return FALSE;
353 GetClientRect(hwnd, &rect);
354 ScreenToClient(hwnd, &point);
356 x = (point.x * MAXHORI) / rect.right;
357 y = ((rect.bottom - point.y) * MAXVERT) / rect.bottom;
359 if (x < 0) x = 0;
360 if (y < 0) y = 0;
361 if (x > MAXHORI) x = MAXHORI;
362 if (y > MAXVERT) y = MAXVERT;
364 if (hori)
365 *hori = x;
366 if (vert)
367 *vert = y;
369 return TRUE;
371 /***********************************************************************
372 * CC_MouseCheckResultWindow [internal]
373 * test if double click one of the result colors
375 static BOOL CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
377 HWND hwnd;
378 POINT point;
379 RECT rect;
381 CONV_LPARAMTOPOINT(lParam, &point);
382 ClientToScreen(hDlg, &point);
383 hwnd = GetDlgItem(hDlg, COLOR_CURRENT);
384 GetWindowRect(hwnd, &rect);
385 if (PtInRect(&rect, point))
387 PostMessageA(hDlg, WM_COMMAND, COLOR_SOLID, 0);
388 return TRUE;
390 return FALSE;
393 /***********************************************************************
394 * CC_CheckDigitsInEdit [internal]
396 static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
398 int i, k, m, result, value;
399 char buffer[30];
401 GetWindowTextA(hwnd, buffer, ARRAY_SIZE(buffer));
402 m = strlen(buffer);
403 result = 0;
405 for (i = 0 ; i < m ; i++)
406 if (buffer[i] < '0' || buffer[i] > '9')
408 for (k = i + 1; k <= m; k++) /* delete bad character */
410 buffer[i] = buffer[k];
411 m--;
413 buffer[m] = 0;
414 result = 1;
417 value = atoi(buffer);
418 if (value > maxval) /* build a new string */
420 sprintf(buffer, "%d", maxval);
421 result = 2;
423 if (result)
425 LRESULT editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
426 SetWindowTextA(hwnd, buffer );
427 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
429 return value;
434 /***********************************************************************
435 * CC_PaintSelectedColor [internal]
437 static void CC_PaintSelectedColor(const CCPRIV *infoPtr)
439 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
441 RECT rect;
442 HDC hdc;
443 HBRUSH hBrush;
444 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT);
446 hdc = GetDC(hwnd);
447 GetClientRect(hwnd, &rect) ;
448 hBrush = CreateSolidBrush(infoPtr->lpcc->rgbResult);
449 if (hBrush)
451 FillRect(hdc, &rect, hBrush);
452 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
453 DeleteObject(hBrush);
455 ReleaseDC(hwnd, hdc);
459 /***********************************************************************
460 * CC_PaintTriangle [internal]
462 static void CC_PaintTriangle(CCPRIV *infoPtr)
464 HDC hDC;
465 int temp;
466 int w = LOWORD(GetDialogBaseUnits()) / 2;
467 POINT points[3];
468 int height;
469 int oben;
470 RECT rect;
471 HBRUSH hbr;
472 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
474 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW))) /* if full size */
476 GetClientRect(hwnd, &rect);
477 height = rect.bottom;
478 hDC = GetDC(infoPtr->hwndSelf);
479 points[0].y = rect.top;
480 points[0].x = rect.right; /* | /| */
481 ClientToScreen(hwnd, points); /* | / | */
482 ScreenToClient(infoPtr->hwndSelf, points); /* |< | */
483 oben = points[0].y; /* | \ | */
484 /* | \| */
485 temp = height * infoPtr->l;
486 points[0].x += 1;
487 points[0].y = oben + height - temp / MAXVERT;
488 points[1].y = points[0].y + w;
489 points[2].y = points[0].y - w;
490 points[2].x = points[1].x = points[0].x + w;
492 hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
493 if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
494 FillRect(hDC, &infoPtr->old3angle, hbr);
495 infoPtr->old3angle.left = points[0].x;
496 infoPtr->old3angle.right = points[1].x + 1;
497 infoPtr->old3angle.top = points[2].y - 1;
498 infoPtr->old3angle.bottom= points[1].y + 1;
500 hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
501 Polygon(hDC, points, 3);
502 SelectObject(hDC, hbr);
504 ReleaseDC(infoPtr->hwndSelf, hDC);
509 /***********************************************************************
510 * CC_PaintCross [internal]
512 static void CC_PaintCross(CCPRIV *infoPtr)
514 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
516 if (IsWindowVisible(hwnd)) /* if full size */
518 HDC hDC;
519 int w = GetDialogBaseUnits() - 1;
520 int wc = GetDialogBaseUnits() * 3 / 4;
521 RECT rect;
522 POINT point, p;
523 HRGN region;
524 HPEN hPen;
525 int x, y;
527 x = infoPtr->h;
528 y = infoPtr->s;
530 GetClientRect(hwnd, &rect);
531 hDC = GetDC(hwnd);
532 region = CreateRectRgnIndirect(&rect);
533 SelectClipRgn(hDC, region);
534 DeleteObject(region);
536 point.x = (rect.right * x) / MAXHORI;
537 point.y = rect.bottom - (rect.bottom * y) / MAXVERT;
538 if ( infoPtr->oldcross.left != infoPtr->oldcross.right )
539 BitBlt(hDC, infoPtr->oldcross.left, infoPtr->oldcross.top,
540 infoPtr->oldcross.right - infoPtr->oldcross.left,
541 infoPtr->oldcross.bottom - infoPtr->oldcross.top,
542 infoPtr->hdcMem, infoPtr->oldcross.left, infoPtr->oldcross.top, SRCCOPY);
543 infoPtr->oldcross.left = point.x - w - 1;
544 infoPtr->oldcross.right = point.x + w + 1;
545 infoPtr->oldcross.top = point.y - w - 1;
546 infoPtr->oldcross.bottom = point.y + w + 1;
548 hPen = CreatePen(PS_SOLID, 3, RGB(0, 0, 0)); /* -black- color */
549 hPen = SelectObject(hDC, hPen);
550 MoveToEx(hDC, point.x - w, point.y, &p);
551 LineTo(hDC, point.x - wc, point.y);
552 MoveToEx(hDC, point.x + wc, point.y, &p);
553 LineTo(hDC, point.x + w, point.y);
554 MoveToEx(hDC, point.x, point.y - w, &p);
555 LineTo(hDC, point.x, point.y - wc);
556 MoveToEx(hDC, point.x, point.y + wc, &p);
557 LineTo(hDC, point.x, point.y + w);
558 DeleteObject( SelectObject(hDC, hPen));
560 ReleaseDC(hwnd, hDC);
565 #define XSTEPS 48
566 #define YSTEPS 24
569 /***********************************************************************
570 * CC_PrepareColorGraph [internal]
572 static void CC_PrepareColorGraph(CCPRIV *infoPtr)
574 int sdif, hdif, xdif, ydif, hue, sat;
575 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
576 HBRUSH hbrush;
577 HDC hdc ;
578 RECT rect, client;
579 HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
581 GetClientRect(hwnd, &client);
582 hdc = GetDC(hwnd);
583 infoPtr->hdcMem = CreateCompatibleDC(hdc);
584 infoPtr->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
585 SelectObject(infoPtr->hdcMem, infoPtr->hbmMem);
587 xdif = client.right / XSTEPS;
588 ydif = client.bottom / YSTEPS+1;
589 hdif = 239 / XSTEPS;
590 sdif = 240 / YSTEPS;
591 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
593 rect.right = rect.left + xdif;
594 rect.bottom = client.bottom;
595 for(sat = 0; sat < 240 + sdif; sat += sdif)
597 rect.top = rect.bottom - ydif;
598 hbrush = CreateSolidBrush(CC_HSLtoRGB(hue, sat, 120));
599 FillRect(infoPtr->hdcMem, &rect, hbrush);
600 DeleteObject(hbrush);
601 rect.bottom = rect.top;
603 rect.left = rect.right;
605 ReleaseDC(hwnd, hdc);
606 SetCursor(hcursor);
609 /***********************************************************************
610 * CC_PaintColorGraph [internal]
612 static void CC_PaintColorGraph(CCPRIV *infoPtr)
614 HWND hwnd = GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW );
615 HDC hDC;
616 RECT rect;
618 if (IsWindowVisible(hwnd)) /* if full size */
620 if (!infoPtr->hdcMem)
621 CC_PrepareColorGraph(infoPtr); /* should not be necessary */
623 hDC = GetDC(hwnd);
624 GetClientRect(hwnd, &rect);
625 if (infoPtr->hdcMem)
626 BitBlt(hDC, 0, 0, rect.right, rect.bottom, infoPtr->hdcMem, 0, 0, SRCCOPY);
627 else
628 WARN("choose color: hdcMem is not defined\n");
629 ReleaseDC(hwnd, hDC);
633 /***********************************************************************
634 * CC_PaintLumBar [internal]
636 static void CC_PaintLumBar(const CCPRIV *infoPtr)
638 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
639 RECT rect, client;
640 int lum, ldif, ydif;
641 HBRUSH hbrush;
642 HDC hDC;
644 if (IsWindowVisible(hwnd))
646 hDC = GetDC(hwnd);
647 GetClientRect(hwnd, &client);
648 rect = client;
650 ldif = 240 / YSTEPS;
651 ydif = client.bottom / YSTEPS+1;
652 for (lum = 0; lum < 240 + ldif; lum += ldif)
654 rect.top = max(0, rect.bottom - ydif);
655 hbrush = CreateSolidBrush(CC_HSLtoRGB(infoPtr->h, infoPtr->s, lum));
656 FillRect(hDC, &rect, hbrush);
657 DeleteObject(hbrush);
658 rect.bottom = rect.top;
660 GetClientRect(hwnd, &rect);
661 DrawEdge(hDC, &rect, BDR_SUNKENOUTER, BF_RECT);
662 ReleaseDC(hwnd, hDC);
666 /***********************************************************************
667 * CC_EditSetRGB [internal]
669 static void CC_EditSetRGB( CCPRIV *infoPtr )
671 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
673 COLORREF cr = infoPtr->lpcc->rgbResult;
674 int r = GetRValue(cr);
675 int g = GetGValue(cr);
676 int b = GetBValue(cr);
678 infoPtr->updating = TRUE;
679 SetDlgItemInt(infoPtr->hwndSelf, COLOR_RED, r, TRUE);
680 SetDlgItemInt(infoPtr->hwndSelf, COLOR_GREEN, g, TRUE);
681 SetDlgItemInt(infoPtr->hwndSelf, COLOR_BLUE, b, TRUE);
682 infoPtr->updating = FALSE;
686 /***********************************************************************
687 * CC_EditSetHSL [internal]
689 static void CC_EditSetHSL( CCPRIV *infoPtr )
691 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
693 infoPtr->updating = TRUE;
694 SetDlgItemInt(infoPtr->hwndSelf, COLOR_HUE, infoPtr->h, TRUE);
695 SetDlgItemInt(infoPtr->hwndSelf, COLOR_SAT, infoPtr->s, TRUE);
696 SetDlgItemInt(infoPtr->hwndSelf, COLOR_LUM, infoPtr->l, TRUE);
697 infoPtr->updating = FALSE;
699 CC_PaintLumBar(infoPtr);
702 /***********************************************************************
703 * CC_SwitchToFullSize [internal]
705 static void CC_SwitchToFullSize( CCPRIV *infoPtr, const RECT *lprect )
707 int i;
709 EnableWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_MIX), FALSE);
710 CC_PrepareColorGraph(infoPtr);
711 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
712 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
713 for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
714 ShowWindow( GetDlgItem(infoPtr->hwndSelf, i), SW_SHOW);
715 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_SOLID), SW_SHOW);
716 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_ADD), SW_SHOW);
717 ShowWindow( GetDlgItem(infoPtr->hwndSelf, 1090), SW_SHOW);
719 if (lprect)
720 SetWindowPos(infoPtr->hwndSelf, 0, 0, 0, lprect->right-lprect->left,
721 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
723 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL), SW_SHOW);
724 ShowWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT), SW_SHOW);
726 CC_EditSetRGB(infoPtr);
727 CC_EditSetHSL(infoPtr);
728 ShowWindow( GetDlgItem( infoPtr->hwndSelf, COLOR_RAINBOW), SW_SHOW);
729 UpdateWindow( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) );
732 /***********************************************************************
733 * CC_PaintPredefColorArray [internal]
734 * Paints the default standard 48 colors
736 static void CC_PaintPredefColorArray(const CCPRIV *infoPtr, int rows, int cols)
738 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_BOX1);
739 RECT rect, blockrect;
740 HDC hdc;
741 HBRUSH hBrush;
742 int dx, dy, i, j, k;
744 GetClientRect(hwnd, &rect);
745 dx = rect.right / cols;
746 dy = rect.bottom / rows;
747 k = rect.left;
749 hdc = GetDC(hwnd);
750 GetClientRect(hwnd, &rect);
751 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
752 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
753 FillRect(hdc, &rect, hBrush);
754 for ( j = 0; j < rows; j++ )
756 for ( i = 0; i < cols; i++ )
758 hBrush = CreateSolidBrush(predefcolors[j][i]);
759 if (hBrush)
761 blockrect.left = rect.left;
762 blockrect.top = rect.top;
763 blockrect.right = rect.left + dx - DISTANCE;
764 blockrect.bottom = rect.top + dy - DISTANCE;
765 FillRect(hdc, &blockrect, hBrush);
766 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
767 DeleteObject(hBrush);
769 rect.left += dx;
771 rect.top += dy;
772 rect.left = k;
774 ReleaseDC(hwnd, hdc);
775 if (infoPtr->hwndFocus == hwnd)
776 CC_DrawCurrentFocusRect(infoPtr);
778 /***********************************************************************
779 * CC_PaintUserColorArray [internal]
780 * Paint the 16 user-selected colors
782 static void CC_PaintUserColorArray(const CCPRIV *infoPtr, int rows, int cols)
784 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CUSTOM1);
785 RECT rect, blockrect;
786 HDC hdc;
787 HBRUSH hBrush;
788 int dx, dy, i, j, k;
790 GetClientRect(hwnd, &rect);
792 dx = rect.right / cols;
793 dy = rect.bottom / rows;
794 k = rect.left;
796 hdc = GetDC(hwnd);
797 if (hdc)
799 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
800 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
801 FillRect( hdc, &rect, hBrush );
802 for (j = 0; j < rows; j++)
804 for (i = 0; i < cols; i++)
806 hBrush = CreateSolidBrush(infoPtr->lpcc->lpCustColors[i+j*cols]);
807 if (hBrush)
809 blockrect.left = rect.left;
810 blockrect.top = rect.top;
811 blockrect.right = rect.left + dx - DISTANCE;
812 blockrect.bottom = rect.top + dy - DISTANCE;
813 FillRect(hdc, &blockrect, hBrush);
814 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
815 DeleteObject(hBrush);
817 rect.left += dx;
819 rect.top += dy;
820 rect.left = k;
822 ReleaseDC(hwnd, hdc);
824 if (infoPtr->hwndFocus == hwnd)
825 CC_DrawCurrentFocusRect(infoPtr);
829 /***********************************************************************
830 * CC_HookCallChk [internal]
832 static BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
834 if (lpcc)
835 if(lpcc->Flags & CC_ENABLEHOOK)
836 if (lpcc->lpfnHook)
837 return TRUE;
838 return FALSE;
841 /***********************************************************************
842 * CC_WMInitDialog [internal]
844 static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
846 CHOOSECOLORW *cc = (CHOOSECOLORW*)lParam;
847 int i, res;
848 int r, g, b;
849 HWND hwnd;
850 RECT rect;
851 POINT point;
852 CCPRIV *lpp;
854 TRACE("WM_INITDIALOG lParam=%08IX\n", lParam);
856 if (cc->lStructSize != sizeof(CHOOSECOLORW))
858 EndDialog(hDlg, 0);
859 return FALSE;
862 lpp = heap_alloc_zero(sizeof(*lpp));
863 lpp->lpcc = cc;
864 lpp->hwndSelf = hDlg;
866 SetPropW( hDlg, L"colourdialogprop", lpp );
868 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
869 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
870 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
872 #if 0
873 cpos = MAKELONG(5,7); /* init */
874 if (lpp->lpcc->Flags & CC_RGBINIT)
876 for (i = 0; i < 6; i++)
877 for (j = 0; j < 8; j++)
878 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
880 cpos = MAKELONG(i,j);
881 goto found;
884 found:
885 /* FIXME: Draw_a_focus_rect & set_init_values */
886 #endif
888 GetWindowRect(hDlg, &lpp->fullsize);
889 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
891 hwnd = GetDlgItem(hDlg, COLOR_MIX);
892 EnableWindow(hwnd, FALSE);
894 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
896 rect = lpp->fullsize;
897 res = rect.bottom - rect.top;
898 hwnd = GetDlgItem(hDlg, COLOR_RAINBOW); /* cut at left border */
899 point.x = point.y = 0;
900 ClientToScreen(hwnd, &point);
901 ScreenToClient(hDlg,&point);
902 GetClientRect(hDlg, &rect);
903 point.x += GetSystemMetrics(SM_CXDLGFRAME);
904 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
906 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
907 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
908 for (i = COLOR_HUEACCEL; i <= COLOR_BLUEACCEL; i++)
909 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
910 ShowWindow( GetDlgItem(hDlg, COLOR_SOLID), SW_HIDE);
911 ShowWindow( GetDlgItem(hDlg, COLOR_ADD), SW_HIDE);
912 ShowWindow( GetDlgItem(hDlg, COLOR_RAINBOW), SW_HIDE);
913 ShowWindow( GetDlgItem(hDlg, COLOR_CURRENT), SW_HIDE);
914 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
916 else
917 CC_SwitchToFullSize(lpp, NULL);
918 res = TRUE;
919 for (i = COLOR_HUE; i <= COLOR_BLUE; i++)
920 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
921 if (CC_HookCallChk(lpp->lpcc))
923 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
926 /* Set the initial values of the color chooser dialog */
927 r = GetRValue(lpp->lpcc->rgbResult);
928 g = GetGValue(lpp->lpcc->rgbResult);
929 b = GetBValue(lpp->lpcc->rgbResult);
931 CC_PaintSelectedColor(lpp);
932 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
933 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
934 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
936 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
937 SetDlgItemInt(hDlg, COLOR_HUE, lpp->h, TRUE);
938 SetDlgItemInt(hDlg, COLOR_SAT, lpp->s, TRUE);
939 SetDlgItemInt(hDlg, COLOR_LUM, lpp->l, TRUE);
940 SetDlgItemInt(hDlg, COLOR_RED, r, TRUE);
941 SetDlgItemInt(hDlg, COLOR_GREEN, g, TRUE);
942 SetDlgItemInt(hDlg, COLOR_BLUE, b, TRUE);
944 CC_PaintCross(lpp);
945 CC_PaintTriangle(lpp);
947 return res;
951 /***********************************************************************
952 * CC_WMCommand [internal]
954 static LRESULT CC_WMCommand(CCPRIV *lpp, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl)
956 int r, g, b, i, xx;
957 UINT cokmsg;
958 HDC hdc;
959 COLORREF *cr;
961 TRACE("CC_WMCommand wParam=%Ix lParam=%Ix\n", wParam, lParam);
962 switch (LOWORD(wParam))
964 case COLOR_RED: /* edit notify RGB */
965 case COLOR_GREEN:
966 case COLOR_BLUE:
967 if (notifyCode == EN_UPDATE && !lpp->updating)
969 i = CC_CheckDigitsInEdit(hwndCtl, 255);
970 r = GetRValue(lpp->lpcc->rgbResult);
971 g = GetGValue(lpp->lpcc->rgbResult);
972 b= GetBValue(lpp->lpcc->rgbResult);
973 xx = 0;
974 switch (LOWORD(wParam))
976 case COLOR_RED: if ((xx = (i != r))) r = i; break;
977 case COLOR_GREEN: if ((xx = (i != g))) g = i; break;
978 case COLOR_BLUE: if ((xx = (i != b))) b = i; break;
980 if (xx) /* something has changed */
982 lpp->lpcc->rgbResult = RGB(r, g, b);
983 CC_PaintSelectedColor(lpp);
984 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
985 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
986 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
987 CC_EditSetHSL(lpp);
988 CC_PaintCross(lpp);
989 CC_PaintTriangle(lpp);
992 break;
994 case COLOR_HUE: /* edit notify HSL */
995 case COLOR_SAT:
996 case COLOR_LUM:
997 if (notifyCode == EN_UPDATE && !lpp->updating)
999 i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == COLOR_HUE ? 239 : 240);
1000 xx = 0;
1001 switch (LOWORD(wParam))
1003 case COLOR_HUE: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1004 case COLOR_SAT: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1005 case COLOR_LUM: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1007 if (xx) /* something has changed */
1009 lpp->lpcc->rgbResult = CC_HSLtoRGB(lpp->h, lpp->s, lpp->l);
1010 CC_PaintSelectedColor(lpp);
1011 CC_EditSetRGB(lpp);
1012 CC_PaintCross(lpp);
1013 CC_PaintTriangle(lpp);
1016 break;
1018 case COLOR_MIX:
1019 CC_SwitchToFullSize(lpp, &lpp->fullsize);
1020 SetFocus( GetDlgItem(lpp->hwndSelf, COLOR_HUE));
1021 break;
1023 case COLOR_ADD: /* add colors ... column by column */
1024 cr = lpp->lpcc->lpCustColors;
1025 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1026 if (++lpp->nextuserdef == 16)
1027 lpp->nextuserdef = 0;
1028 CC_PaintUserColorArray(lpp, 2, 8);
1029 break;
1031 case COLOR_SOLID: /* resulting color */
1032 hdc = GetDC(lpp->hwndSelf);
1033 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1034 ReleaseDC(lpp->hwndSelf, hdc);
1035 CC_EditSetRGB(lpp);
1036 CC_PaintSelectedColor(lpp);
1037 lpp->h = CC_RGBtoHSL('H', lpp->lpcc->rgbResult);
1038 lpp->s = CC_RGBtoHSL('S', lpp->lpcc->rgbResult);
1039 lpp->l = CC_RGBtoHSL('L', lpp->lpcc->rgbResult);
1040 CC_EditSetHSL(lpp);
1041 CC_PaintCross(lpp);
1042 CC_PaintTriangle(lpp);
1043 break;
1045 case pshHelp: /* Help! */ /* The Beatles, 1965 ;-) */
1046 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1047 if (lpp->lpcc->hwndOwner)
1048 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1049 if ( CC_HookCallChk(lpp->lpcc))
1050 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, lpp->hwndSelf,
1051 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1052 break;
1054 case IDOK :
1055 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1056 if (lpp->lpcc->hwndOwner)
1057 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1058 break; /* do NOT close */
1059 EndDialog(lpp->hwndSelf, 1) ;
1060 return TRUE ;
1062 case IDCANCEL :
1063 EndDialog(lpp->hwndSelf, 0) ;
1064 return TRUE ;
1067 return FALSE;
1070 /***********************************************************************
1071 * CC_WMPaint [internal]
1073 static LRESULT CC_WMPaint( CCPRIV *lpp )
1075 PAINTSTRUCT ps;
1077 BeginPaint(lpp->hwndSelf, &ps);
1078 /* we have to paint dialog children except text and buttons */
1079 CC_PaintPredefColorArray(lpp, 6, 8);
1080 CC_PaintUserColorArray(lpp, 2, 8);
1081 CC_PaintLumBar(lpp);
1082 CC_PaintTriangle(lpp);
1083 CC_PaintSelectedColor(lpp);
1084 CC_PaintColorGraph(lpp);
1085 CC_PaintCross(lpp);
1086 EndPaint(lpp->hwndSelf, &ps);
1088 return TRUE;
1091 /***********************************************************************
1092 * CC_WMLButtonUp [internal]
1094 static LRESULT CC_WMLButtonUp( CCPRIV *infoPtr )
1096 if (infoPtr->capturedGraph)
1098 infoPtr->capturedGraph = 0;
1099 ReleaseCapture();
1100 CC_PaintCross(infoPtr);
1101 return 1;
1103 return 0;
1106 /***********************************************************************
1107 * CC_WMMouseMove [internal]
1109 static LRESULT CC_WMMouseMove( CCPRIV *infoPtr, LPARAM lParam )
1111 if (infoPtr->capturedGraph)
1113 int *ptrh = NULL, *ptrs = &infoPtr->l;
1114 if (infoPtr->capturedGraph == COLOR_RAINBOW)
1116 ptrh = &infoPtr->h;
1117 ptrs = &infoPtr->s;
1119 if (CC_MouseCheckColorGraph( infoPtr->hwndSelf, infoPtr->capturedGraph, ptrh, ptrs, lParam))
1121 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1122 CC_EditSetRGB(infoPtr);
1123 CC_EditSetHSL(infoPtr);
1124 CC_PaintCross(infoPtr);
1125 CC_PaintTriangle(infoPtr);
1126 CC_PaintSelectedColor(infoPtr);
1128 else
1130 ReleaseCapture();
1131 infoPtr->capturedGraph = 0;
1133 return 1;
1135 return 0;
1138 /***********************************************************************
1139 * CC_WMLButtonDown [internal]
1141 static LRESULT CC_WMLButtonDown( CCPRIV *infoPtr, LPARAM lParam )
1143 int i = 0;
1145 if (CC_MouseCheckPredefColorArray(infoPtr, 6, 8, lParam))
1146 i = 1;
1147 else
1148 if (CC_MouseCheckUserColorArray(infoPtr, 2, 8, lParam))
1149 i = 1;
1150 else
1151 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_RAINBOW, &infoPtr->h, &infoPtr->s, lParam))
1153 i = 2;
1154 infoPtr->capturedGraph = COLOR_RAINBOW;
1156 else
1157 if (CC_MouseCheckColorGraph(infoPtr->hwndSelf, COLOR_LUMSCROLL, NULL, &infoPtr->l, lParam))
1159 i = 2;
1160 infoPtr->capturedGraph = COLOR_LUMSCROLL;
1162 if ( i == 2 )
1164 SetCapture(infoPtr->hwndSelf);
1165 infoPtr->lpcc->rgbResult = CC_HSLtoRGB(infoPtr->h, infoPtr->s, infoPtr->l);
1167 if ( i == 1 )
1169 infoPtr->h = CC_RGBtoHSL('H', infoPtr->lpcc->rgbResult);
1170 infoPtr->s = CC_RGBtoHSL('S', infoPtr->lpcc->rgbResult);
1171 infoPtr->l = CC_RGBtoHSL('L', infoPtr->lpcc->rgbResult);
1173 if (i)
1175 CC_EditSetRGB(infoPtr);
1176 CC_EditSetHSL(infoPtr);
1177 CC_PaintCross(infoPtr);
1178 CC_PaintTriangle(infoPtr);
1179 CC_PaintSelectedColor(infoPtr);
1180 return TRUE;
1182 return FALSE;
1185 /***********************************************************************
1186 * ColorDlgProc32 [internal]
1189 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1190 WPARAM wParam, LPARAM lParam )
1193 int res;
1194 CCPRIV *lpp = GetPropW( hDlg, L"colourdialogprop" );
1196 if (message != WM_INITDIALOG)
1198 if (!lpp)
1199 return FALSE;
1200 res = 0;
1201 if (CC_HookCallChk(lpp->lpcc))
1202 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1203 if ( res )
1204 return res;
1207 /* FIXME: SetRGB message
1208 if (message && message == msetrgb)
1209 return HandleSetRGB(hDlg, lParam);
1212 switch (message)
1214 case WM_INITDIALOG:
1215 return CC_WMInitDialog(hDlg, wParam, lParam);
1216 case WM_NCDESTROY:
1217 DeleteDC(lpp->hdcMem);
1218 DeleteObject(lpp->hbmMem);
1219 heap_free(lpp);
1220 RemovePropW( hDlg, L"colourdialogprop" );
1221 break;
1222 case WM_COMMAND:
1223 if (CC_WMCommand(lpp, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1224 return TRUE;
1225 break;
1226 case WM_PAINT:
1227 if (CC_WMPaint(lpp))
1228 return TRUE;
1229 break;
1230 case WM_LBUTTONDBLCLK:
1231 if (CC_MouseCheckResultWindow(hDlg, lParam))
1232 return TRUE;
1233 break;
1234 case WM_MOUSEMOVE:
1235 if (CC_WMMouseMove(lpp, lParam))
1236 return TRUE;
1237 break;
1238 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1239 if (CC_WMLButtonUp(lpp))
1240 return TRUE;
1241 break;
1242 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1243 if (CC_WMLButtonDown(lpp, lParam))
1244 return TRUE;
1245 break;
1247 return FALSE ;
1250 /***********************************************************************
1251 * ChooseColorW (COMDLG32.@)
1253 * Create a color dialog box.
1255 * PARAMS
1256 * lpChCol [I/O] in: information to initialize the dialog box.
1257 * out: User's color selection
1259 * RETURNS
1260 * TRUE: Ok button clicked.
1261 * FALSE: Cancel button clicked, or error.
1263 BOOL WINAPI ChooseColorW( CHOOSECOLORW *lpChCol )
1265 HANDLE hDlgTmpl = 0;
1266 const void *template;
1268 TRACE("(%p)\n", lpChCol);
1270 if (!lpChCol) return FALSE;
1272 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1274 if (!(template = LockResource(lpChCol->hInstance)))
1276 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1277 return FALSE;
1280 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1282 HRSRC hResInfo;
1283 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1284 lpChCol->lpTemplateName,
1285 (LPWSTR)RT_DIALOG)))
1287 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1288 return FALSE;
1290 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1291 !(template = LockResource(hDlgTmpl)))
1293 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1294 return FALSE;
1297 else
1299 HRSRC hResInfo;
1300 HGLOBAL hDlgTmpl;
1301 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, L"CHOOSE_COLOR", (LPWSTR)RT_DIALOG)))
1303 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1304 return FALSE;
1306 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1307 !(template = LockResource(hDlgTmpl)))
1309 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1310 return FALSE;
1314 return DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1315 ColorDlgProc, (LPARAM)lpChCol);
1318 /***********************************************************************
1319 * ChooseColorA (COMDLG32.@)
1321 * See ChooseColorW.
1323 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1326 LPWSTR template_name = NULL;
1327 BOOL ret;
1329 CHOOSECOLORW *lpcc = heap_alloc_zero(sizeof(*lpcc));
1330 lpcc->lStructSize = sizeof(*lpcc);
1331 lpcc->hwndOwner = lpChCol->hwndOwner;
1332 lpcc->hInstance = lpChCol->hInstance;
1333 lpcc->rgbResult = lpChCol->rgbResult;
1334 lpcc->lpCustColors = lpChCol->lpCustColors;
1335 lpcc->Flags = lpChCol->Flags;
1336 lpcc->lCustData = lpChCol->lCustData;
1337 lpcc->lpfnHook = lpChCol->lpfnHook;
1338 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1339 if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
1340 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1341 template_name = heap_alloc( len * sizeof(WCHAR) );
1342 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1343 lpcc->lpTemplateName = template_name;
1344 } else {
1345 lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1349 ret = ChooseColorW(lpcc);
1351 if (ret)
1352 lpChCol->rgbResult = lpcc->rgbResult;
1354 heap_free(template_name);
1355 heap_free(lpcc);
1356 return ret;