mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / comdlg32 / colordlg.c
blobd5254736b244fc8101d422d13d56ad4639e6ef7a
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 long 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 = (long) point.x * MAXHORI;
357 x /= rect.right;
358 y = (long) (rect.bottom - point.y) * MAXVERT;
359 y /= rect.bottom;
361 if (x < 0) x = 0;
362 if (y < 0) y = 0;
363 if (x > MAXHORI) x = MAXHORI;
364 if (y > MAXVERT) y = MAXVERT;
366 if (hori)
367 *hori = x;
368 if (vert)
369 *vert = y;
371 return TRUE;
373 /***********************************************************************
374 * CC_MouseCheckResultWindow [internal]
375 * test if double click one of the result colors
377 static BOOL CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
379 HWND hwnd;
380 POINT point;
381 RECT rect;
383 CONV_LPARAMTOPOINT(lParam, &point);
384 ClientToScreen(hDlg, &point);
385 hwnd = GetDlgItem(hDlg, COLOR_CURRENT);
386 GetWindowRect(hwnd, &rect);
387 if (PtInRect(&rect, point))
389 PostMessageA(hDlg, WM_COMMAND, COLOR_SOLID, 0);
390 return TRUE;
392 return FALSE;
395 /***********************************************************************
396 * CC_CheckDigitsInEdit [internal]
398 static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
400 int i, k, m, result, value;
401 long editpos;
402 char buffer[30];
404 GetWindowTextA(hwnd, buffer, ARRAY_SIZE(buffer));
405 m = strlen(buffer);
406 result = 0;
408 for (i = 0 ; i < m ; i++)
409 if (buffer[i] < '0' || buffer[i] > '9')
411 for (k = i + 1; k <= m; k++) /* delete bad character */
413 buffer[i] = buffer[k];
414 m--;
416 buffer[m] = 0;
417 result = 1;
420 value = atoi(buffer);
421 if (value > maxval) /* build a new string */
423 sprintf(buffer, "%d", maxval);
424 result = 2;
426 if (result)
428 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
429 SetWindowTextA(hwnd, buffer );
430 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
432 return value;
437 /***********************************************************************
438 * CC_PaintSelectedColor [internal]
440 static void CC_PaintSelectedColor(const CCPRIV *infoPtr)
442 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW) )) /* if full size */
444 RECT rect;
445 HDC hdc;
446 HBRUSH hBrush;
447 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_CURRENT);
449 hdc = GetDC(hwnd);
450 GetClientRect(hwnd, &rect) ;
451 hBrush = CreateSolidBrush(infoPtr->lpcc->rgbResult);
452 if (hBrush)
454 FillRect(hdc, &rect, hBrush);
455 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
456 DeleteObject(hBrush);
458 ReleaseDC(hwnd, hdc);
462 /***********************************************************************
463 * CC_PaintTriangle [internal]
465 static void CC_PaintTriangle(CCPRIV *infoPtr)
467 HDC hDC;
468 long temp;
469 int w = LOWORD(GetDialogBaseUnits()) / 2;
470 POINT points[3];
471 int height;
472 int oben;
473 RECT rect;
474 HBRUSH hbr;
475 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_LUMSCROLL);
477 if (IsWindowVisible( GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW))) /* if full size */
479 GetClientRect(hwnd, &rect);
480 height = rect.bottom;
481 hDC = GetDC(infoPtr->hwndSelf);
482 points[0].y = rect.top;
483 points[0].x = rect.right; /* | /| */
484 ClientToScreen(hwnd, points); /* | / | */
485 ScreenToClient(infoPtr->hwndSelf, points); /* |< | */
486 oben = points[0].y; /* | \ | */
487 /* | \| */
488 temp = (long)height * (long)infoPtr->l;
489 points[0].x += 1;
490 points[0].y = oben + height - temp / (long)MAXVERT;
491 points[1].y = points[0].y + w;
492 points[2].y = points[0].y - w;
493 points[2].x = points[1].x = points[0].x + w;
495 hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
496 if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
497 FillRect(hDC, &infoPtr->old3angle, hbr);
498 infoPtr->old3angle.left = points[0].x;
499 infoPtr->old3angle.right = points[1].x + 1;
500 infoPtr->old3angle.top = points[2].y - 1;
501 infoPtr->old3angle.bottom= points[1].y + 1;
503 hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
504 Polygon(hDC, points, 3);
505 SelectObject(hDC, hbr);
507 ReleaseDC(infoPtr->hwndSelf, hDC);
512 /***********************************************************************
513 * CC_PaintCross [internal]
515 static void CC_PaintCross(CCPRIV *infoPtr)
517 HWND hwnd = GetDlgItem(infoPtr->hwndSelf, COLOR_RAINBOW);
519 if (IsWindowVisible(hwnd)) /* if full size */
521 HDC hDC;
522 int w = GetDialogBaseUnits() - 1;
523 int wc = GetDialogBaseUnits() * 3 / 4;
524 RECT rect;
525 POINT point, p;
526 HRGN region;
527 HPEN hPen;
528 int x, y;
530 x = infoPtr->h;
531 y = infoPtr->s;
533 GetClientRect(hwnd, &rect);
534 hDC = GetDC(hwnd);
535 region = CreateRectRgnIndirect(&rect);
536 SelectClipRgn(hDC, region);
537 DeleteObject(region);
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, L"colourdialogprop", 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, L"colourdialogprop" );
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, L"colourdialogprop" );
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 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, L"CHOOSE_COLOR", (LPWSTR)RT_DIALOG)))
1306 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1307 return FALSE;
1309 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1310 !(template = LockResource(hDlgTmpl)))
1312 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1313 return FALSE;
1317 return DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1318 ColorDlgProc, (LPARAM)lpChCol);
1321 /***********************************************************************
1322 * ChooseColorA (COMDLG32.@)
1324 * See ChooseColorW.
1326 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1329 LPWSTR template_name = NULL;
1330 BOOL ret;
1332 CHOOSECOLORW *lpcc = heap_alloc_zero(sizeof(*lpcc));
1333 lpcc->lStructSize = sizeof(*lpcc);
1334 lpcc->hwndOwner = lpChCol->hwndOwner;
1335 lpcc->hInstance = lpChCol->hInstance;
1336 lpcc->rgbResult = lpChCol->rgbResult;
1337 lpcc->lpCustColors = lpChCol->lpCustColors;
1338 lpcc->Flags = lpChCol->Flags;
1339 lpcc->lCustData = lpChCol->lCustData;
1340 lpcc->lpfnHook = lpChCol->lpfnHook;
1341 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1342 if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
1343 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1344 template_name = heap_alloc( len * sizeof(WCHAR) );
1345 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1346 lpcc->lpTemplateName = template_name;
1347 } else {
1348 lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1352 ret = ChooseColorW(lpcc);
1354 if (ret)
1355 lpChCol->rgbResult = lpcc->rgbResult;
1357 heap_free(template_name);
1358 heap_free(lpcc);
1359 return ret;