Updated.
[wine/multimedia.git] / dlls / commdlg / colordlg.c
blobd8c3a1ef2589d8a314d766336e84ccd644c20071
1 /*
2 * COMMDLG - Color Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* BUGS : still seems to not refresh correctly
23 sometimes, especially when 2 instances of the
24 dialog are loaded at the same time */
26 #include <ctype.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "wine/winbase16.h"
35 #include "wine/winuser16.h"
36 #include "winuser.h"
37 #include "commdlg.h"
38 #include "dlgs.h"
39 #include "wine/debug.h"
40 #include "cderr.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
44 #include "cdlg.h"
45 #include "colordlg.h"
47 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
49 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
51 static const COLORREF predefcolors[6][8]=
53 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
54 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
55 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
56 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
58 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
59 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
60 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
61 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
63 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
64 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
65 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
66 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
69 /***********************************************************************
70 * CC_HSLtoRGB [internal]
72 int CC_HSLtoRGB(char c, int hue, int sat, int lum)
74 int res = 0, maxrgb;
76 /* hue */
77 switch(c)
79 case 'R': if (hue > 80) hue -= 80; else hue += 160; break;
80 case 'G': if (hue > 160) hue -= 160; else hue += 80; break;
81 case 'B': break;
84 /* l below 120 */
85 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
86 if (hue < 80)
87 res = 0;
88 else
89 if (hue < 120)
91 res = (hue - 80) * maxrgb; /* 0...10240 */
92 res /= 40; /* 0...256 */
94 else
95 if (hue < 200)
96 res = maxrgb;
97 else
99 res= (240 - hue) * maxrgb;
100 res /= 40;
102 res = res - maxrgb / 2; /* -128...128 */
104 /* saturation */
105 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
107 /* lum above 120 */
108 if (lum > 120 && res < 256)
109 res += ((lum - 120) * (256 - res)) / 120;
111 return min(res, 255);
114 /***********************************************************************
115 * CC_RGBtoHSL [internal]
117 int CC_RGBtoHSL(char c, int r, int g, int b)
119 WORD maxi, mini, mmsum, mmdif, result = 0;
120 int iresult = 0;
122 maxi = max(r, b);
123 maxi = max(maxi, g);
124 mini = min(r, b);
125 mini = min(mini, g);
127 mmsum = maxi + mini;
128 mmdif = maxi - mini;
130 switch(c)
132 /* lum */
133 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
134 result = mmsum / 255; /* 0...240 */
135 break;
136 /* saturation */
137 case 'S': if (!mmsum)
138 result = 0;
139 else
140 if (!mini || maxi == 255)
141 result = 240;
142 else
144 result = mmdif * 240; /* 0...61200=255*240 */
145 result /= (mmsum > 255 ? mmsum = 510 - mmsum : mmsum); /* 0..255 */
147 break;
148 /* hue */
149 case 'H': if (!mmdif)
150 result = 160;
151 else
153 if (maxi == r)
155 iresult = 40 * (g - b); /* -10200 ... 10200 */
156 iresult /= (int) mmdif; /* -40 .. 40 */
157 if (iresult < 0)
158 iresult += 240; /* 0..40 and 200..240 */
160 else
161 if (maxi == g)
163 iresult = 40 * (b - r);
164 iresult /= (int) mmdif;
165 iresult += 80; /* 40 .. 120 */
167 else
168 if (maxi == b)
170 iresult = 40 * (r - g);
171 iresult /= (int) mmdif;
172 iresult += 160; /* 120 .. 200 */
174 result = iresult;
176 break;
178 return result; /* is this integer arithmetic precise enough ? */
182 /***********************************************************************
183 * CC_DrawCurrentFocusRect [internal]
185 void CC_DrawCurrentFocusRect( LCCPRIV lpp )
187 if (lpp->hwndFocus)
189 HDC hdc = GetDC(lpp->hwndFocus);
190 DrawFocusRect(hdc, &lpp->focusRect);
191 ReleaseDC(lpp->hwndFocus, hdc);
195 /***********************************************************************
196 * CC_DrawFocusRect [internal]
198 void CC_DrawFocusRect( LCCPRIV lpp, HWND hwnd, int x, int y, int rows, int cols)
200 RECT rect;
201 int dx, dy;
202 HDC hdc;
204 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
205 /* calculate new rect */
206 GetClientRect(hwnd, &rect);
207 dx = (rect.right - rect.left) / cols;
208 dy = (rect.bottom - rect.top) / rows;
209 rect.left += (x * dx) - 2;
210 rect.top += (y * dy) - 2;
211 rect.right = rect.left + dx;
212 rect.bottom = rect.top + dy;
213 /* draw it */
214 hdc = GetDC(hwnd);
215 DrawFocusRect(hdc, &rect);
216 CopyRect(&lpp->focusRect, &rect);
217 lpp->hwndFocus = hwnd;
218 ReleaseDC(hwnd, hdc);
221 #define DISTANCE 4
223 /***********************************************************************
224 * CC_MouseCheckPredefColorArray [internal]
225 * returns 1 if one of the predefined colors is clicked
227 static int CC_MouseCheckPredefColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
228 LPARAM lParam )
230 HWND hwnd;
231 POINT point;
232 RECT rect;
233 int dx, dy, x, y;
235 CONV_LPARAMTOPOINT(lParam, &point);
236 ClientToScreen(hDlg, &point);
237 hwnd = GetDlgItem(hDlg, dlgitem);
238 GetWindowRect(hwnd, &rect);
239 if (PtInRect(&rect, point))
241 dx = (rect.right - rect.left) / cols;
242 dy = (rect.bottom - rect.top) / rows;
243 ScreenToClient(hwnd, &point);
245 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
247 x = point.x / dx;
248 y = point.y / dy;
249 lpp->lpcc->rgbResult = predefcolors[y][x];
250 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
251 return 1;
254 return 0;
257 /***********************************************************************
258 * CC_MouseCheckUserColorArray [internal]
259 * return 1 if the user clicked a color
261 static int CC_MouseCheckUserColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
262 LPARAM lParam )
264 HWND hwnd;
265 POINT point;
266 RECT rect;
267 int dx, dy, x, y;
268 COLORREF *crarr = lpp->lpcc->lpCustColors;
270 CONV_LPARAMTOPOINT(lParam, &point);
271 ClientToScreen(hDlg, &point);
272 hwnd = GetDlgItem(hDlg, dlgitem);
273 GetWindowRect(hwnd, &rect);
274 if (PtInRect(&rect, point))
276 dx = (rect.right - rect.left) / cols;
277 dy = (rect.bottom - rect.top) / rows;
278 ScreenToClient(hwnd, &point);
280 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
282 x = point.x / dx;
283 y = point.y / dy;
284 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
285 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
286 return 1;
289 return 0;
292 #define MAXVERT 240
293 #define MAXHORI 239
295 /* 240 ^...... ^^ 240
296 | . ||
297 SAT | . || LUM
298 | . ||
299 +-----> 239 ----
302 /***********************************************************************
303 * CC_MouseCheckColorGraph [internal]
305 static int CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
307 HWND hwnd;
308 POINT point;
309 RECT rect;
310 long x,y;
312 CONV_LPARAMTOPOINT(lParam, &point);
313 ClientToScreen(hDlg, &point);
314 hwnd = GetDlgItem( hDlg, dlgitem );
315 GetWindowRect(hwnd, &rect);
316 if (PtInRect(&rect, point))
318 GetClientRect(hwnd, &rect);
319 ScreenToClient(hwnd, &point);
321 x = (long) point.x * MAXHORI;
322 x /= rect.right;
323 y = (long) (rect.bottom - point.y) * MAXVERT;
324 y /= rect.bottom;
326 if (hori)
327 *hori = x;
328 if (vert)
329 *vert = y;
330 return 1;
332 else
333 return 0;
335 /***********************************************************************
336 * CC_MouseCheckResultWindow [internal]
337 * test if double click one of the result colors
339 int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
341 HWND hwnd;
342 POINT point;
343 RECT rect;
345 CONV_LPARAMTOPOINT(lParam, &point);
346 ClientToScreen(hDlg, &point);
347 hwnd = GetDlgItem(hDlg, 0x2c5);
348 GetWindowRect(hwnd, &rect);
349 if (PtInRect(&rect, point))
351 PostMessageA(hDlg, WM_COMMAND, 0x2c9, 0);
352 return 1;
354 return 0;
357 /***********************************************************************
358 * CC_CheckDigitsInEdit [internal]
360 int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
362 int i, k, m, result, value;
363 long editpos;
364 char buffer[30];
366 GetWindowTextA(hwnd, buffer, sizeof(buffer));
367 m = strlen(buffer);
368 result = 0;
370 for (i = 0 ; i < m ; i++)
371 if (buffer[i] < '0' || buffer[i] > '9')
373 for (k = i + 1; k <= m; k++) /* delete bad character */
375 buffer[i] = buffer[k];
376 m--;
378 buffer[m] = 0;
379 result = 1;
382 value = atoi(buffer);
383 if (value > maxval) /* build a new string */
385 sprintf(buffer, "%d", maxval);
386 result = 2;
388 if (result)
390 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
391 SetWindowTextA(hwnd, buffer );
392 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
394 return value;
399 /***********************************************************************
400 * CC_PaintSelectedColor [internal]
402 void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
404 RECT rect;
405 HDC hdc;
406 HBRUSH hBrush;
407 HWND hwnd = GetDlgItem(hDlg, 0x2c5);
408 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
410 hdc = GetDC(hwnd);
411 GetClientRect(hwnd, &rect) ;
412 hBrush = CreateSolidBrush(cr);
413 if (hBrush)
415 hBrush = SelectObject(hdc, hBrush) ;
416 Rectangle(hdc, rect.left, rect.top, rect.right/2, rect.bottom);
417 DeleteObject ( SelectObject(hdc, hBrush) ) ;
418 hBrush = CreateSolidBrush( GetNearestColor(hdc, cr) );
419 if (hBrush)
421 hBrush = SelectObject(hdc, hBrush) ;
422 Rectangle(hdc, rect.right/2-1, rect.top, rect.right, rect.bottom);
423 DeleteObject(SelectObject(hdc, hBrush)) ;
426 ReleaseDC(hwnd, hdc);
430 /***********************************************************************
431 * CC_PaintTriangle [internal]
433 void CC_PaintTriangle( HWND hDlg, int y)
435 HDC hDC;
436 long temp;
437 int w = LOWORD(GetDialogBaseUnits());
438 POINT points[3];
439 int height;
440 int oben;
441 RECT rect;
442 HWND hwnd = GetDlgItem(hDlg, 0x2be);
443 LCCPRIV lpp = (LCCPRIV)GetWindowLongA( hDlg, DWL_USER);
445 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6))) /* if full size */
447 GetClientRect(hwnd, &rect);
448 height = rect.bottom;
449 hDC = GetDC(hDlg);
450 points[0].y = rect.top;
451 points[0].x = rect.right; /* | /| */
452 ClientToScreen(hwnd, points); /* | / | */
453 ScreenToClient(hDlg, points); /* |< | */
454 oben = points[0].y; /* | \ | */
455 /* | \| */
456 temp = (long)height * (long)y;
457 points[0].y = oben + height - temp / (long)MAXVERT;
458 points[1].y = points[0].y + w;
459 points[2].y = points[0].y - w;
460 points[2].x = points[1].x = points[0].x + w;
462 FillRect(hDC, &lpp->old3angle, (HBRUSH)GetClassLongA( hwnd, GCL_HBRBACKGROUND));
463 lpp->old3angle.left = points[0].x;
464 lpp->old3angle.right = points[1].x + 1;
465 lpp->old3angle.top = points[2].y - 1;
466 lpp->old3angle.bottom= points[1].y + 1;
467 Polygon(hDC, points, 3);
468 ReleaseDC(hDlg, hDC);
473 /***********************************************************************
474 * CC_PaintCross [internal]
476 void CC_PaintCross( HWND hDlg, int x, int y)
478 HDC hDC;
479 int w = GetDialogBaseUnits();
480 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
481 LCCPRIV lpp = (LCCPRIV)GetWindowLongA( hDlg, DWL_USER );
482 RECT rect;
483 POINT point, p;
484 HPEN hPen;
486 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
488 GetClientRect(hwnd, &rect);
489 hDC = GetDC(hwnd);
490 SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
491 hPen = CreatePen(PS_SOLID, 2, 0xffffff); /* -white- color */
492 hPen = SelectObject(hDC, hPen);
493 point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
494 point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
495 if ( lpp->oldcross.left != lpp->oldcross.right )
496 BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
497 lpp->oldcross.right - lpp->oldcross.left,
498 lpp->oldcross.bottom - lpp->oldcross.top,
499 lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
500 lpp->oldcross.left = point.x - w - 1;
501 lpp->oldcross.right = point.x + w + 1;
502 lpp->oldcross.top = point.y - w - 1;
503 lpp->oldcross.bottom = point.y + w + 1;
505 MoveToEx(hDC, point.x - w, point.y, &p);
506 LineTo(hDC, point.x + w, point.y);
507 MoveToEx(hDC, point.x, point.y - w, &p);
508 LineTo(hDC, point.x, point.y + w);
509 DeleteObject( SelectObject(hDC, hPen)) ;
510 ReleaseDC(hwnd, hDC);
515 #define XSTEPS 48
516 #define YSTEPS 24
519 /***********************************************************************
520 * CC_PrepareColorGraph [internal]
522 static void CC_PrepareColorGraph( HWND hDlg )
524 int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
525 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
526 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
527 HBRUSH hbrush;
528 HDC hdc ;
529 RECT rect, client;
530 HCURSOR hcursor = SetCursor( LoadCursorA(0, (LPSTR)IDC_WAIT) );
532 GetClientRect(hwnd, &client);
533 hdc = GetDC(hwnd);
534 lpp->hdcMem = CreateCompatibleDC(hdc);
535 lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
536 SelectObject(lpp->hdcMem, lpp->hbmMem);
538 xdif = client.right / XSTEPS;
539 ydif = client.bottom / YSTEPS+1;
540 hdif = 239 / XSTEPS;
541 sdif = 240 / YSTEPS;
542 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
544 rect.right = rect.left + xdif;
545 rect.bottom = client.bottom;
546 for(sat = 0; sat < 240 + sdif; sat += sdif)
548 rect.top = rect.bottom - ydif;
549 r = CC_HSLtoRGB('R', hue, sat, 120);
550 g = CC_HSLtoRGB('G', hue, sat, 120);
551 b = CC_HSLtoRGB('B', hue, sat, 120);
552 hbrush = CreateSolidBrush( RGB(r, g, b));
553 FillRect(lpp->hdcMem, &rect, hbrush);
554 DeleteObject(hbrush);
555 rect.bottom = rect.top;
557 rect.left = rect.right;
559 ReleaseDC(hwnd, hdc);
560 SetCursor(hcursor);
563 /***********************************************************************
564 * CC_PaintColorGraph [internal]
566 static void CC_PaintColorGraph( HWND hDlg )
568 HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
569 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
570 HDC hDC;
571 RECT rect;
572 if (IsWindowVisible(hwnd)) /* if full size */
574 if (!lpp->hdcMem)
575 CC_PrepareColorGraph(hDlg); /* should not be necessary */
577 hDC = GetDC(hwnd);
578 GetClientRect(hwnd, &rect);
579 if (lpp->hdcMem)
580 BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
581 else
582 WARN("choose color: hdcMem is not defined\n");
583 ReleaseDC(hwnd, hDC);
587 /***********************************************************************
588 * CC_PaintLumBar [internal]
590 static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
592 HWND hwnd = GetDlgItem(hDlg, 0x2be);
593 RECT rect, client;
594 int lum, ldif, ydif, r, g, b;
595 HBRUSH hbrush;
596 HDC hDC;
598 if (IsWindowVisible(hwnd))
600 hDC = GetDC(hwnd);
601 GetClientRect(hwnd, &client);
602 rect = client;
604 ldif = 240 / YSTEPS;
605 ydif = client.bottom / YSTEPS+1;
606 for (lum = 0; lum < 240 + ldif; lum += ldif)
608 rect.top = max(0, rect.bottom - ydif);
609 r = CC_HSLtoRGB('R', hue, sat, lum);
610 g = CC_HSLtoRGB('G', hue, sat, lum);
611 b = CC_HSLtoRGB('B', hue, sat, lum);
612 hbrush = CreateSolidBrush( RGB(r, g, b) );
613 FillRect(hDC, &rect, hbrush);
614 DeleteObject(hbrush);
615 rect.bottom = rect.top;
617 GetClientRect(hwnd, &rect);
618 FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH) );
619 ReleaseDC(hwnd, hDC);
623 /***********************************************************************
624 * CC_EditSetRGB [internal]
626 void CC_EditSetRGB( HWND hDlg, COLORREF cr )
628 char buffer[10];
629 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
630 int r = GetRValue(cr);
631 int g = GetGValue(cr);
632 int b = GetBValue(cr);
633 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
635 lpp->updating = TRUE;
636 sprintf(buffer, "%d", r);
637 SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
638 sprintf(buffer, "%d", g);
639 SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
640 sprintf( buffer, "%d", b );
641 SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
642 lpp->updating = FALSE;
646 /***********************************************************************
647 * CC_EditSetHSL [internal]
649 void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
651 char buffer[10];
652 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
653 lpp->updating = TRUE;
654 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
656 lpp->updating = TRUE;
657 sprintf(buffer, "%d", h);
658 SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
659 sprintf(buffer, "%d", s);
660 SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
661 sprintf(buffer, "%d", l);
662 SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
663 lpp->updating = FALSE;
665 CC_PaintLumBar(hDlg, h, s);
668 /***********************************************************************
669 * CC_SwitchToFullSize [internal]
671 void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPRECT lprect )
673 int i;
674 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
676 EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
677 CC_PrepareColorGraph(hDlg);
678 for (i = 0x2bf; i < 0x2c5; i++)
679 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
680 for (i = 0x2d3; i < 0x2d9; i++)
681 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
682 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
683 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
684 ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);
686 if (lprect)
687 SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
688 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
690 ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
691 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);
693 CC_EditSetRGB(hDlg, result);
694 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
695 ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
696 UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
699 /***********************************************************************
700 * CC_PaintPredefColorArray [internal]
701 * Paints the default standard 48 colors
703 static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
705 HWND hwnd = GetDlgItem(hDlg, 0x2d0);
706 RECT rect;
707 HDC hdc;
708 HBRUSH hBrush;
709 int dx, dy, i, j, k;
710 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
712 GetClientRect(hwnd, &rect);
713 dx = rect.right / cols;
714 dy = rect.bottom / rows;
715 k = rect.left;
717 hdc = GetDC(hwnd);
718 GetClientRect(hwnd, &rect);
719 FillRect(hdc, &rect, (HBRUSH)GetClassLongA(hwnd, GCL_HBRBACKGROUND));
720 for ( j = 0; j < rows; j++ )
722 for ( i = 0; i < cols; i++ )
724 hBrush = CreateSolidBrush(predefcolors[j][i]);
725 if (hBrush)
727 hBrush = SelectObject(hdc, hBrush);
728 Rectangle(hdc, rect.left, rect.top,
729 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
730 rect.left = rect.left + dx;
731 DeleteObject(SelectObject(hdc, hBrush)) ;
734 rect.top = rect.top + dy;
735 rect.left = k;
737 ReleaseDC(hwnd, hdc);
738 if (lpp->hwndFocus == hwnd)
739 CC_DrawCurrentFocusRect(lpp);
741 /***********************************************************************
742 * CC_PaintUserColorArray [internal]
743 * Paint the 16 user-selected colors
745 void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, COLORREF* lpcr )
747 HWND hwnd = GetDlgItem(hDlg, 0x2d1);
748 RECT rect;
749 HDC hdc;
750 HBRUSH hBrush;
751 int dx, dy, i, j, k;
752 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
754 GetClientRect(hwnd, &rect);
756 dx = rect.right / cols;
757 dy = rect.bottom / rows;
758 k = rect.left;
760 hdc = GetDC(hwnd);
761 if (hdc)
763 FillRect(hdc, &rect, (HBRUSH)GetClassLongA(hwnd, GCL_HBRBACKGROUND) );
764 for (j = 0; j < rows; j++)
766 for (i = 0; i < cols; i++)
768 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
769 if (hBrush)
771 hBrush = SelectObject(hdc, hBrush) ;
772 Rectangle(hdc, rect.left, rect.top,
773 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
774 rect.left = rect.left + dx;
775 DeleteObject( SelectObject(hdc, hBrush) ) ;
778 rect.top = rect.top + dy;
779 rect.left = k;
781 ReleaseDC(hwnd, hdc);
783 if (lpp->hwndFocus == hwnd)
784 CC_DrawCurrentFocusRect(lpp);
789 /***********************************************************************
790 * CC_HookCallChk [internal]
792 BOOL CC_HookCallChk( LPCHOOSECOLORW lpcc )
794 if (lpcc)
795 if(lpcc->Flags & CC_ENABLEHOOK)
796 if (lpcc->lpfnHook)
797 return TRUE;
798 return FALSE;
801 /***********************************************************************
802 * CC_WMInitDialog [internal]
804 LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
806 int i, res;
807 int r, g, b;
808 HWND hwnd;
809 RECT rect;
810 POINT point;
811 LCCPRIV lpp;
813 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
814 lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
816 lpp->lpcc = (LPCHOOSECOLORW) lParam;
817 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
819 HeapFree(GetProcessHeap(), 0, lpp);
820 EndDialog (hDlg, 0) ;
821 return FALSE;
824 SetWindowLongA(hDlg, DWL_USER, (LONG)lpp);
826 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
827 ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
828 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
830 #if 0
831 cpos = MAKELONG(5,7); /* init */
832 if (lpp->lpcc->Flags & CC_RGBINIT)
834 for (i = 0; i < 6; i++)
835 for (j = 0; j < 8; j++)
836 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
838 cpos = MAKELONG(i,j);
839 goto found;
842 found:
843 /* FIXME: Draw_a_focus_rect & set_init_values */
844 #endif
846 GetWindowRect(hDlg, &lpp->fullsize);
847 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
849 hwnd = GetDlgItem(hDlg, 0x2cf);
850 EnableWindow(hwnd, FALSE);
852 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
854 rect = lpp->fullsize;
855 res = rect.bottom - rect.top;
856 hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
857 point.x = point.y = 0;
858 ClientToScreen(hwnd, &point);
859 ScreenToClient(hDlg,&point);
860 GetClientRect(hDlg, &rect);
861 point.x += GetSystemMetrics(SM_CXDLGFRAME);
862 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
864 for (i = 0x2bf; i < 0x2c5; i++)
865 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
866 for (i = 0x2d3; i < 0x2d9; i++)
867 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
868 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
869 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
870 ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
871 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
872 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
874 else
875 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
876 res = TRUE;
877 for (i = 0x2bf; i < 0x2c5; i++)
878 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
879 if (CC_HookCallChk(lpp->lpcc))
881 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
884 /* Set the initial values of the color chooser dialog */
885 r = GetRValue(lpp->lpcc->rgbResult);
886 g = GetGValue(lpp->lpcc->rgbResult);
887 b = GetBValue(lpp->lpcc->rgbResult);
889 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
890 lpp->h = CC_RGBtoHSL('H', r, g, b);
891 lpp->s = CC_RGBtoHSL('S', r, g, b);
892 lpp->l = CC_RGBtoHSL('L', r, g, b);
894 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
895 SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
896 SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
897 SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
898 SetDlgItemInt(hDlg, 706, r, TRUE);
899 SetDlgItemInt(hDlg, 707, g, TRUE);
900 SetDlgItemInt(hDlg, 708, b, TRUE);
902 CC_PaintCross(hDlg, lpp->h, lpp->s);
903 CC_PaintTriangle(hDlg, lpp->l);
905 return res;
909 /***********************************************************************
910 * CC_WMCommand [internal]
912 LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
914 int r, g, b, i, xx;
915 UINT cokmsg;
916 HDC hdc;
917 COLORREF *cr;
918 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
919 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam, lParam);
920 switch (wParam)
922 case 0x2c2: /* edit notify RGB */
923 case 0x2c3:
924 case 0x2c4:
925 if (notifyCode == EN_UPDATE && !lpp->updating)
927 i = CC_CheckDigitsInEdit(hwndCtl, 255);
928 r = GetRValue(lpp->lpcc->rgbResult);
929 g = GetGValue(lpp->lpcc->rgbResult);
930 b= GetBValue(lpp->lpcc->rgbResult);
931 xx = 0;
932 switch (wParam)
934 case 0x2c2: if ((xx = (i != r))) r = i; break;
935 case 0x2c3: if ((xx = (i != g))) g = i; break;
936 case 0x2c4: if ((xx = (i != b))) b = i; break;
938 if (xx) /* something has changed */
940 lpp->lpcc->rgbResult = RGB(r, g, b);
941 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
942 lpp->h = CC_RGBtoHSL('H', r, g, b);
943 lpp->s = CC_RGBtoHSL('S', r, g, b);
944 lpp->l = CC_RGBtoHSL('L', r, g, b);
945 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
946 CC_PaintCross(hDlg, lpp->h, lpp->s);
947 CC_PaintTriangle(hDlg, lpp->l);
950 break;
952 case 0x2bf: /* edit notify HSL */
953 case 0x2c0:
954 case 0x2c1:
955 if (notifyCode == EN_UPDATE && !lpp->updating)
957 i = CC_CheckDigitsInEdit(hwndCtl , wParam == 0x2bf ? 239:240);
958 xx = 0;
959 switch (wParam)
961 case 0x2bf: if ((xx = ( i != lpp->h))) lpp->h = i; break;
962 case 0x2c0: if ((xx = ( i != lpp->s))) lpp->s = i; break;
963 case 0x2c1: if ((xx = ( i != lpp->l))) lpp->l = i; break;
965 if (xx) /* something has changed */
967 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
968 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
969 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
970 lpp->lpcc->rgbResult = RGB(r, g, b);
971 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
972 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
973 CC_PaintCross(hDlg, lpp->h, lpp->s);
974 CC_PaintTriangle(hDlg, lpp->l);
977 break;
979 case 0x2cf:
980 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, &lpp->fullsize);
981 SetFocus( GetDlgItem(hDlg, 0x2bf));
982 break;
984 case 0x2c8: /* add colors ... column by column */
985 cr = lpp->lpcc->lpCustColors;
986 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
987 if (++lpp->nextuserdef == 16)
988 lpp->nextuserdef = 0;
989 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
990 break;
992 case 0x2c9: /* resulting color */
993 hdc = GetDC(hDlg);
994 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
995 ReleaseDC(hDlg, hdc);
996 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
997 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
998 r = GetRValue(lpp->lpcc->rgbResult);
999 g = GetGValue(lpp->lpcc->rgbResult);
1000 b = GetBValue(lpp->lpcc->rgbResult);
1001 lpp->h = CC_RGBtoHSL('H', r, g, b);
1002 lpp->s = CC_RGBtoHSL('S', r, g, b);
1003 lpp->l = CC_RGBtoHSL('L', r, g, b);
1004 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
1005 CC_PaintCross(hDlg, lpp->h, lpp->s);
1006 CC_PaintTriangle(hDlg, lpp->l);
1007 break;
1009 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1010 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1011 if (lpp->lpcc->hwndOwner)
1012 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1013 if ( CC_HookCallChk(lpp->lpcc))
1014 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
1015 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1016 break;
1018 case IDOK :
1019 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1020 if (lpp->lpcc->hwndOwner)
1021 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1022 break; /* do NOT close */
1023 EndDialog(hDlg, 1) ;
1024 return TRUE ;
1026 case IDCANCEL :
1027 EndDialog(hDlg, 0) ;
1028 return TRUE ;
1031 return FALSE;
1034 /***********************************************************************
1035 * CC_WMPaint [internal]
1037 LRESULT CC_WMPaint( HWND hDlg, WPARAM wParam, LPARAM lParam )
1039 HDC hdc;
1040 PAINTSTRUCT ps;
1041 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1043 hdc = BeginPaint(hDlg, &ps);
1044 /* we have to paint dialog children except text and buttons */
1045 CC_PaintPredefColorArray(hDlg, 6, 8);
1046 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1047 CC_PaintLumBar(hDlg, lpp->h, lpp->s);
1048 CC_PaintCross(hDlg, lpp->h, lpp->s);
1049 CC_PaintTriangle(hDlg, lpp->l);
1050 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1051 CC_PaintColorGraph(hDlg);
1052 EndPaint(hDlg, &ps);
1054 return TRUE;
1057 /***********************************************************************
1058 * CC_WMLButtonUp [internal]
1060 LRESULT CC_WMLButtonUp( HWND hDlg, WPARAM wParam, LPARAM lParam )
1062 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1063 if (lpp->capturedGraph)
1065 lpp->capturedGraph = 0;
1066 ReleaseCapture();
1067 CC_PaintCross(hDlg, lpp->h, lpp->s);
1068 return 1;
1070 return 0;
1073 /***********************************************************************
1074 * CC_WMMouseMove [internal]
1076 LRESULT CC_WMMouseMove( HWND hDlg, LPARAM lParam )
1078 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1079 int r, g, b;
1081 if (lpp->capturedGraph)
1083 int *ptrh = NULL, *ptrs = &lpp->l;
1084 if (lpp->capturedGraph == 0x2c6)
1086 ptrh = &lpp->h;
1087 ptrs = &lpp->s;
1089 if (CC_MouseCheckColorGraph( hDlg, lpp->capturedGraph, ptrh, ptrs, lParam))
1091 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1092 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1093 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1094 lpp->lpcc->rgbResult = RGB(r, g, b);
1095 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1096 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1097 CC_PaintCross(hDlg, lpp->h, lpp->s);
1098 CC_PaintTriangle(hDlg, lpp->l);
1099 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1101 else
1103 ReleaseCapture();
1104 lpp->capturedGraph = 0;
1106 return 1;
1108 return 0;
1111 /***********************************************************************
1112 * CC_WMLButtonDown [internal]
1114 LRESULT CC_WMLButtonDown( HWND hDlg, WPARAM wParam, LPARAM lParam )
1116 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1117 int r, g, b, i;
1118 i = 0;
1120 if (CC_MouseCheckPredefColorArray(lpp, hDlg, 0x2d0, 6, 8, lParam))
1121 i = 1;
1122 else
1123 if (CC_MouseCheckUserColorArray(lpp, hDlg, 0x2d1, 2, 8, lParam))
1124 i = 1;
1125 else
1126 if (CC_MouseCheckColorGraph(hDlg, 0x2c6, &lpp->h, &lpp->s, lParam))
1128 i = 2;
1129 lpp->capturedGraph = 0x2c6;
1131 else
1132 if (CC_MouseCheckColorGraph(hDlg, 0x2be, NULL, &lpp->l, lParam))
1134 i = 2;
1135 lpp->capturedGraph = 0x2be;
1137 if ( i == 2 )
1139 SetCapture(hDlg);
1140 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1141 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1142 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1143 lpp->lpcc->rgbResult = RGB(r, g, b);
1145 if ( i == 1 )
1147 r = GetRValue(lpp->lpcc->rgbResult);
1148 g = GetGValue(lpp->lpcc->rgbResult);
1149 b = GetBValue(lpp->lpcc->rgbResult);
1150 lpp->h = CC_RGBtoHSL('H', r, g, b);
1151 lpp->s = CC_RGBtoHSL('S', r, g, b);
1152 lpp->l = CC_RGBtoHSL('L', r, g, b);
1154 if (i)
1156 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1157 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1158 CC_PaintCross(hDlg, lpp->h, lpp->s);
1159 CC_PaintTriangle(hDlg, lpp->l);
1160 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1161 return TRUE;
1163 return FALSE;
1166 /***********************************************************************
1167 * ColorDlgProc32 [internal]
1170 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1171 WPARAM wParam, LPARAM lParam )
1174 int res;
1175 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1176 if (message != WM_INITDIALOG)
1178 if (!lpp)
1179 return FALSE;
1180 res = 0;
1181 if (CC_HookCallChk(lpp->lpcc))
1182 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1183 if ( res )
1184 return res;
1187 /* FIXME: SetRGB message
1188 if (message && message == msetrgb)
1189 return HandleSetRGB(hDlg, lParam);
1192 switch (message)
1194 case WM_INITDIALOG:
1195 return CC_WMInitDialog(hDlg, wParam, lParam);
1196 case WM_NCDESTROY:
1197 DeleteDC(lpp->hdcMem);
1198 DeleteObject(lpp->hbmMem);
1199 HeapFree(GetProcessHeap(), 0, lpp);
1200 SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
1201 break;
1202 case WM_COMMAND:
1203 if (CC_WMCommand( hDlg, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1204 return TRUE;
1205 break;
1206 case WM_PAINT:
1207 if ( CC_WMPaint(hDlg, wParam, lParam))
1208 return TRUE;
1209 break;
1210 case WM_LBUTTONDBLCLK:
1211 if (CC_MouseCheckResultWindow(hDlg, lParam))
1212 return TRUE;
1213 break;
1214 case WM_MOUSEMOVE:
1215 if (CC_WMMouseMove(hDlg, lParam))
1216 return TRUE;
1217 break;
1218 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1219 if (CC_WMLButtonUp(hDlg, wParam, lParam))
1220 return TRUE;
1221 break;
1222 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1223 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1224 return TRUE;
1225 break;
1227 return FALSE ;
1230 /***********************************************************************
1231 * ChooseColorW (COMDLG32.@)
1233 BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
1235 HANDLE hDlgTmpl = 0;
1236 BOOL bRet = FALSE;
1237 LPCVOID template;
1239 TRACE("ChooseColor\n");
1240 if (!lpChCol) return FALSE;
1242 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1244 if (!(template = LockResource(lpChCol->hInstance)))
1246 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1247 return FALSE;
1250 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1252 HRSRC hResInfo;
1253 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1254 lpChCol->lpTemplateName,
1255 (LPWSTR)RT_DIALOG)))
1257 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1258 return FALSE;
1260 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1261 !(template = LockResource(hDlgTmpl)))
1263 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1264 return FALSE;
1267 else
1269 HRSRC hResInfo;
1270 HGLOBAL hDlgTmpl;
1271 if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_COLOR", (LPSTR)RT_DIALOG)))
1273 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1274 return FALSE;
1276 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1277 !(template = LockResource(hDlgTmpl)))
1279 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1280 return FALSE;
1284 bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1285 ColorDlgProc, (DWORD)lpChCol);
1286 return bRet;
1289 /***********************************************************************
1290 * ChooseColorA (COMDLG32.@)
1292 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1295 BOOL ret;
1296 LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
1297 lpcc->lStructSize = sizeof(*lpcc);
1298 lpcc->hwndOwner = lpChCol->hwndOwner;
1299 lpcc->hInstance = lpChCol->hInstance;
1300 lpcc->rgbResult = lpChCol->rgbResult;
1301 lpcc->lpCustColors = lpChCol->lpCustColors;
1302 lpcc->Flags = lpChCol->Flags;
1303 lpcc->lCustData = lpChCol->lCustData;
1304 lpcc->lpfnHook = (LPCCHOOKPROC) lpChCol->lpfnHook;
1305 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1306 if (HIWORD(lpChCol->lpTemplateName)) {
1307 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1308 lpcc->lpTemplateName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1309 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, (LPWSTR)lpcc->lpTemplateName, len );
1310 } else {
1311 lpcc->lpTemplateName = (LPWSTR)lpChCol->lpTemplateName;
1315 ret = ChooseColorW(lpcc);
1317 if (ret)
1318 lpChCol->rgbResult = lpcc->rgbResult;
1319 if (HIWORD(lpcc->lpTemplateName)) HeapFree(GetProcessHeap(), 0, (LPSTR)lpcc->lpTemplateName);
1320 HeapFree(GetProcessHeap(), 0, lpcc);
1321 return ret;