comdlg32: Added Dutch translations.
[wine/winequartzdrv.git] / dlls / comdlg32 / colordlg.c
blob777b0bd8d2ac83b2aca3ce2d9de5362779623717
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "winuser.h"
35 #include "commdlg.h"
36 #include "dlgs.h"
37 #include "wine/debug.h"
38 #include "cderr.h"
39 #include "cdlg.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
43 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
45 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
47 static const COLORREF predefcolors[6][8]=
49 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
50 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
51 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
52 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
54 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
55 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
56 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
57 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
59 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
60 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
61 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
62 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
65 static const WCHAR szColourDialogProp[] = {
66 'c','o','l','o','u','r','d','i','a','l','o','g','p','r','o','p',0 };
68 /* Chose Color PRIVATE Structure:
70 * This structure is duplicated in the 16 bit code with
71 * an extra member
74 typedef struct CCPRIVATE
76 LPCHOOSECOLORW lpcc; /* points to public known data structure */
77 int nextuserdef; /* next free place in user defined color array */
78 HDC hdcMem; /* color graph used for BitBlt() */
79 HBITMAP hbmMem; /* color graph bitmap */
80 RECT fullsize; /* original dialog window size */
81 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
82 RECT old3angle; /* last position of l-marker */
83 RECT oldcross; /* last position of color/satuation marker */
84 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
85 int h;
86 int s;
87 int l; /* for temporary storing of hue,sat,lum */
88 int capturedGraph; /* control mouse captured */
89 RECT focusRect; /* rectangle last focused item */
90 HWND hwndFocus; /* handle last focused item */
91 } CCPRIV, *LPCCPRIV;
93 /***********************************************************************
94 * CC_HSLtoRGB [internal]
96 int CC_HSLtoRGB(char c, int hue, int sat, int lum)
98 int res = 0, maxrgb;
100 /* hue */
101 switch(c)
103 case 'R': if (hue > 80) hue -= 80; else hue += 160; break;
104 case 'G': if (hue > 160) hue -= 160; else hue += 80; break;
105 case 'B': break;
108 /* l below 120 */
109 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
110 if (hue < 80)
111 res = 0;
112 else
113 if (hue < 120)
115 res = (hue - 80) * maxrgb; /* 0...10240 */
116 res /= 40; /* 0...256 */
118 else
119 if (hue < 200)
120 res = maxrgb;
121 else
123 res= (240 - hue) * maxrgb;
124 res /= 40;
126 res = res - maxrgb / 2; /* -128...128 */
128 /* saturation */
129 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
131 /* lum above 120 */
132 if (lum > 120 && res < 256)
133 res += ((lum - 120) * (256 - res)) / 120;
135 return min(res, 255);
138 /***********************************************************************
139 * CC_RGBtoHSL [internal]
141 int CC_RGBtoHSL(char c, int r, int g, int b)
143 WORD maxi, mini, mmsum, mmdif, result = 0;
144 int iresult = 0;
146 maxi = max(r, b);
147 maxi = max(maxi, g);
148 mini = min(r, b);
149 mini = min(mini, g);
151 mmsum = maxi + mini;
152 mmdif = maxi - mini;
154 switch(c)
156 /* lum */
157 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
158 result = mmsum / 255; /* 0...240 */
159 break;
160 /* saturation */
161 case 'S': if (!mmsum)
162 result = 0;
163 else
164 if (!mini || maxi == 255)
165 result = 240;
166 else
168 result = mmdif * 240; /* 0...61200=255*240 */
169 result /= (mmsum > 255 ? mmsum = 510 - mmsum : mmsum); /* 0..255 */
171 break;
172 /* hue */
173 case 'H': if (!mmdif)
174 result = 160;
175 else
177 if (maxi == r)
179 iresult = 40 * (g - b); /* -10200 ... 10200 */
180 iresult /= (int) mmdif; /* -40 .. 40 */
181 if (iresult < 0)
182 iresult += 240; /* 0..40 and 200..240 */
184 else
185 if (maxi == g)
187 iresult = 40 * (b - r);
188 iresult /= (int) mmdif;
189 iresult += 80; /* 40 .. 120 */
191 else
192 if (maxi == b)
194 iresult = 40 * (r - g);
195 iresult /= (int) mmdif;
196 iresult += 160; /* 120 .. 200 */
198 result = iresult;
200 break;
202 return result; /* is this integer arithmetic precise enough ? */
206 /***********************************************************************
207 * CC_DrawCurrentFocusRect [internal]
209 static void CC_DrawCurrentFocusRect( const CCPRIV *lpp )
211 if (lpp->hwndFocus)
213 HDC hdc = GetDC(lpp->hwndFocus);
214 DrawFocusRect(hdc, &lpp->focusRect);
215 ReleaseDC(lpp->hwndFocus, hdc);
219 /***********************************************************************
220 * CC_DrawFocusRect [internal]
222 static void CC_DrawFocusRect( LPCCPRIV lpp, HWND hwnd, int x, int y, int rows, int cols)
224 RECT rect;
225 int dx, dy;
226 HDC hdc;
228 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
229 /* calculate new rect */
230 GetClientRect(hwnd, &rect);
231 dx = (rect.right - rect.left) / cols;
232 dy = (rect.bottom - rect.top) / rows;
233 rect.left += (x * dx) - 2;
234 rect.top += (y * dy) - 2;
235 rect.right = rect.left + dx;
236 rect.bottom = rect.top + dy;
237 /* draw it */
238 hdc = GetDC(hwnd);
239 DrawFocusRect(hdc, &rect);
240 CopyRect(&lpp->focusRect, &rect);
241 lpp->hwndFocus = hwnd;
242 ReleaseDC(hwnd, hdc);
245 #define DISTANCE 4
247 /***********************************************************************
248 * CC_MouseCheckPredefColorArray [internal]
249 * returns 1 if one of the predefined colors is clicked
251 static int CC_MouseCheckPredefColorArray( LPCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
252 LPARAM lParam )
254 HWND hwnd;
255 POINT point;
256 RECT rect;
257 int dx, dy, x, y;
259 CONV_LPARAMTOPOINT(lParam, &point);
260 ClientToScreen(hDlg, &point);
261 hwnd = GetDlgItem(hDlg, dlgitem);
262 GetWindowRect(hwnd, &rect);
263 if (PtInRect(&rect, point))
265 dx = (rect.right - rect.left) / cols;
266 dy = (rect.bottom - rect.top) / rows;
267 ScreenToClient(hwnd, &point);
269 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
271 x = point.x / dx;
272 y = point.y / dy;
273 lpp->lpcc->rgbResult = predefcolors[y][x];
274 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
275 return 1;
278 return 0;
281 /***********************************************************************
282 * CC_MouseCheckUserColorArray [internal]
283 * return 1 if the user clicked a color
285 static int CC_MouseCheckUserColorArray( LPCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
286 LPARAM lParam )
288 HWND hwnd;
289 POINT point;
290 RECT rect;
291 int dx, dy, x, y;
292 COLORREF *crarr = lpp->lpcc->lpCustColors;
294 CONV_LPARAMTOPOINT(lParam, &point);
295 ClientToScreen(hDlg, &point);
296 hwnd = GetDlgItem(hDlg, dlgitem);
297 GetWindowRect(hwnd, &rect);
298 if (PtInRect(&rect, point))
300 dx = (rect.right - rect.left) / cols;
301 dy = (rect.bottom - rect.top) / rows;
302 ScreenToClient(hwnd, &point);
304 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
306 x = point.x / dx;
307 y = point.y / dy;
308 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
309 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
310 return 1;
313 return 0;
316 #define MAXVERT 240
317 #define MAXHORI 239
319 /* 240 ^...... ^^ 240
320 | . ||
321 SAT | . || LUM
322 | . ||
323 +-----> 239 ----
326 /***********************************************************************
327 * CC_MouseCheckColorGraph [internal]
329 static int CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
331 HWND hwnd;
332 POINT point;
333 RECT rect;
334 long x,y;
336 CONV_LPARAMTOPOINT(lParam, &point);
337 ClientToScreen(hDlg, &point);
338 hwnd = GetDlgItem( hDlg, dlgitem );
339 GetWindowRect(hwnd, &rect);
341 if (!PtInRect(&rect, point))
342 return 0;
344 GetClientRect(hwnd, &rect);
345 ScreenToClient(hwnd, &point);
347 x = (long) point.x * MAXHORI;
348 x /= rect.right;
349 y = (long) (rect.bottom - point.y) * MAXVERT;
350 y /= rect.bottom;
352 if (x < 0) x = 0;
353 if (y < 0) y = 0;
354 if (x > MAXHORI) x = MAXHORI;
355 if (y > MAXVERT) y = MAXVERT;
357 if (hori)
358 *hori = x;
359 if (vert)
360 *vert = y;
362 return 1;
364 /***********************************************************************
365 * CC_MouseCheckResultWindow [internal]
366 * test if double click one of the result colors
368 int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
370 HWND hwnd;
371 POINT point;
372 RECT rect;
374 CONV_LPARAMTOPOINT(lParam, &point);
375 ClientToScreen(hDlg, &point);
376 hwnd = GetDlgItem(hDlg, 0x2c5);
377 GetWindowRect(hwnd, &rect);
378 if (PtInRect(&rect, point))
380 PostMessageA(hDlg, WM_COMMAND, 0x2c9, 0);
381 return 1;
383 return 0;
386 /***********************************************************************
387 * CC_CheckDigitsInEdit [internal]
389 int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
391 int i, k, m, result, value;
392 long editpos;
393 char buffer[30];
395 GetWindowTextA(hwnd, buffer, sizeof(buffer));
396 m = strlen(buffer);
397 result = 0;
399 for (i = 0 ; i < m ; i++)
400 if (buffer[i] < '0' || buffer[i] > '9')
402 for (k = i + 1; k <= m; k++) /* delete bad character */
404 buffer[i] = buffer[k];
405 m--;
407 buffer[m] = 0;
408 result = 1;
411 value = atoi(buffer);
412 if (value > maxval) /* build a new string */
414 sprintf(buffer, "%d", maxval);
415 result = 2;
417 if (result)
419 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
420 SetWindowTextA(hwnd, buffer );
421 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
423 return value;
428 /***********************************************************************
429 * CC_PaintSelectedColor [internal]
431 void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
433 RECT rect;
434 HDC hdc;
435 HBRUSH hBrush;
436 HWND hwnd = GetDlgItem(hDlg, 0x2c5);
437 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
439 hdc = GetDC(hwnd);
440 GetClientRect(hwnd, &rect) ;
441 hBrush = CreateSolidBrush(cr);
442 if (hBrush)
444 FillRect(hdc, &rect, hBrush);
445 DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
447 ReleaseDC(hwnd, hdc);
451 /***********************************************************************
452 * CC_PaintTriangle [internal]
454 void CC_PaintTriangle( HWND hDlg, int y)
456 HDC hDC;
457 long temp;
458 int w = LOWORD(GetDialogBaseUnits()) / 2;
459 POINT points[3];
460 int height;
461 int oben;
462 RECT rect;
463 HBRUSH hbr;
464 HWND hwnd = GetDlgItem(hDlg, 0x2be);
465 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
467 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6))) /* if full size */
469 GetClientRect(hwnd, &rect);
470 height = rect.bottom;
471 hDC = GetDC(hDlg);
472 points[0].y = rect.top;
473 points[0].x = rect.right; /* | /| */
474 ClientToScreen(hwnd, points); /* | / | */
475 ScreenToClient(hDlg, points); /* |< | */
476 oben = points[0].y; /* | \ | */
477 /* | \| */
478 temp = (long)height * (long)y;
479 points[0].x += 1;
480 points[0].y = oben + height - temp / (long)MAXVERT;
481 points[1].y = points[0].y + w;
482 points[2].y = points[0].y - w;
483 points[2].x = points[1].x = points[0].x + w;
485 hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
486 if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
487 FillRect(hDC, &lpp->old3angle, hbr);
488 lpp->old3angle.left = points[0].x;
489 lpp->old3angle.right = points[1].x + 1;
490 lpp->old3angle.top = points[2].y - 1;
491 lpp->old3angle.bottom= points[1].y + 1;
493 hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
494 Polygon(hDC, points, 3);
495 SelectObject(hDC, hbr);
497 ReleaseDC(hDlg, hDC);
502 /***********************************************************************
503 * CC_PaintCross [internal]
505 void CC_PaintCross( HWND hDlg, int x, int y)
507 HDC hDC;
508 int w = GetDialogBaseUnits() - 1;
509 int wc = GetDialogBaseUnits() * 3 / 4;
510 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
511 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
512 RECT rect;
513 POINT point, p;
514 HPEN hPen;
516 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
518 GetClientRect(hwnd, &rect);
519 hDC = GetDC(hwnd);
520 SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
522 point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
523 point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
524 if ( lpp->oldcross.left != lpp->oldcross.right )
525 BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
526 lpp->oldcross.right - lpp->oldcross.left,
527 lpp->oldcross.bottom - lpp->oldcross.top,
528 lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
529 lpp->oldcross.left = point.x - w - 1;
530 lpp->oldcross.right = point.x + w + 1;
531 lpp->oldcross.top = point.y - w - 1;
532 lpp->oldcross.bottom = point.y + w + 1;
534 hPen = CreatePen(PS_SOLID, 3, 0x000000); /* -black- color */
535 hPen = SelectObject(hDC, hPen);
536 MoveToEx(hDC, point.x - w, point.y, &p);
537 LineTo(hDC, point.x - wc, point.y);
538 MoveToEx(hDC, point.x + wc, point.y, &p);
539 LineTo(hDC, point.x + w, point.y);
540 MoveToEx(hDC, point.x, point.y - w, &p);
541 LineTo(hDC, point.x, point.y - wc);
542 MoveToEx(hDC, point.x, point.y + wc, &p);
543 LineTo(hDC, point.x, point.y + w);
544 DeleteObject( SelectObject(hDC, hPen));
546 ReleaseDC(hwnd, hDC);
551 #define XSTEPS 48
552 #define YSTEPS 24
555 /***********************************************************************
556 * CC_PrepareColorGraph [internal]
558 static void CC_PrepareColorGraph( HWND hDlg )
560 int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
561 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
562 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
563 HBRUSH hbrush;
564 HDC hdc ;
565 RECT rect, client;
566 HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
568 GetClientRect(hwnd, &client);
569 hdc = GetDC(hwnd);
570 lpp->hdcMem = CreateCompatibleDC(hdc);
571 lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
572 SelectObject(lpp->hdcMem, lpp->hbmMem);
574 xdif = client.right / XSTEPS;
575 ydif = client.bottom / YSTEPS+1;
576 hdif = 239 / XSTEPS;
577 sdif = 240 / YSTEPS;
578 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
580 rect.right = rect.left + xdif;
581 rect.bottom = client.bottom;
582 for(sat = 0; sat < 240 + sdif; sat += sdif)
584 rect.top = rect.bottom - ydif;
585 r = CC_HSLtoRGB('R', hue, sat, 120);
586 g = CC_HSLtoRGB('G', hue, sat, 120);
587 b = CC_HSLtoRGB('B', hue, sat, 120);
588 hbrush = CreateSolidBrush( RGB(r, g, b));
589 FillRect(lpp->hdcMem, &rect, hbrush);
590 DeleteObject(hbrush);
591 rect.bottom = rect.top;
593 rect.left = rect.right;
595 ReleaseDC(hwnd, hdc);
596 SetCursor(hcursor);
599 /***********************************************************************
600 * CC_PaintColorGraph [internal]
602 static void CC_PaintColorGraph( HWND hDlg )
604 HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
605 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
606 HDC hDC;
607 RECT rect;
608 if (IsWindowVisible(hwnd)) /* if full size */
610 if (!lpp->hdcMem)
611 CC_PrepareColorGraph(hDlg); /* should not be necessary */
613 hDC = GetDC(hwnd);
614 GetClientRect(hwnd, &rect);
615 if (lpp->hdcMem)
616 BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
617 else
618 WARN("choose color: hdcMem is not defined\n");
619 ReleaseDC(hwnd, hDC);
623 /***********************************************************************
624 * CC_PaintLumBar [internal]
626 static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
628 HWND hwnd = GetDlgItem(hDlg, 0x2be);
629 RECT rect, client;
630 int lum, ldif, ydif, r, g, b;
631 HBRUSH hbrush;
632 HDC hDC;
634 if (IsWindowVisible(hwnd))
636 hDC = GetDC(hwnd);
637 GetClientRect(hwnd, &client);
638 rect = client;
640 ldif = 240 / YSTEPS;
641 ydif = client.bottom / YSTEPS+1;
642 for (lum = 0; lum < 240 + ldif; lum += ldif)
644 rect.top = max(0, rect.bottom - ydif);
645 r = CC_HSLtoRGB('R', hue, sat, lum);
646 g = CC_HSLtoRGB('G', hue, sat, lum);
647 b = CC_HSLtoRGB('B', hue, sat, lum);
648 hbrush = CreateSolidBrush( RGB(r, g, b) );
649 FillRect(hDC, &rect, hbrush);
650 DeleteObject(hbrush);
651 rect.bottom = rect.top;
653 GetClientRect(hwnd, &rect);
654 DrawEdge(hDC, &rect, BDR_SUNKENOUTER, BF_RECT);
655 ReleaseDC(hwnd, hDC);
659 /***********************************************************************
660 * CC_EditSetRGB [internal]
662 void CC_EditSetRGB( HWND hDlg, COLORREF cr )
664 char buffer[10];
665 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
666 int r = GetRValue(cr);
667 int g = GetGValue(cr);
668 int b = GetBValue(cr);
669 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
671 lpp->updating = TRUE;
672 sprintf(buffer, "%d", r);
673 SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
674 sprintf(buffer, "%d", g);
675 SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
676 sprintf( buffer, "%d", b );
677 SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
678 lpp->updating = FALSE;
682 /***********************************************************************
683 * CC_EditSetHSL [internal]
685 void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
687 char buffer[10];
688 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
690 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
692 lpp->updating = TRUE;
693 sprintf(buffer, "%d", h);
694 SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
695 sprintf(buffer, "%d", s);
696 SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
697 sprintf(buffer, "%d", l);
698 SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
699 lpp->updating = FALSE;
701 CC_PaintLumBar(hDlg, h, s);
704 /***********************************************************************
705 * CC_SwitchToFullSize [internal]
707 void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPCRECT lprect )
709 int i;
710 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
712 EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
713 CC_PrepareColorGraph(hDlg);
714 for (i = 0x2bf; i < 0x2c5; i++)
715 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
716 for (i = 0x2d3; i < 0x2d9; i++)
717 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
718 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
719 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
720 ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);
722 if (lprect)
723 SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
724 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
726 ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
727 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);
729 CC_EditSetRGB(hDlg, result);
730 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
731 ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
732 UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
735 /***********************************************************************
736 * CC_PaintPredefColorArray [internal]
737 * Paints the default standard 48 colors
739 static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
741 HWND hwnd = GetDlgItem(hDlg, 0x2d0);
742 RECT rect, blockrect;
743 HDC hdc;
744 HBRUSH hBrush;
745 int dx, dy, i, j, k;
746 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
748 GetClientRect(hwnd, &rect);
749 dx = rect.right / cols;
750 dy = rect.bottom / rows;
751 k = rect.left;
753 hdc = GetDC(hwnd);
754 GetClientRect(hwnd, &rect);
755 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
756 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
757 FillRect(hdc, &rect, hBrush);
758 for ( j = 0; j < rows; j++ )
760 for ( i = 0; i < cols; i++ )
762 hBrush = CreateSolidBrush(predefcolors[j][i]);
763 if (hBrush)
765 blockrect.left = rect.left;
766 blockrect.top = rect.top;
767 blockrect.right = rect.left + dx - DISTANCE;
768 blockrect.bottom = rect.top + dy - DISTANCE;
769 FillRect(hdc, &blockrect, hBrush);
770 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
771 DeleteObject(hBrush);
773 rect.left += dx;
775 rect.top += dy;
776 rect.left = k;
778 ReleaseDC(hwnd, hdc);
779 if (lpp->hwndFocus == hwnd)
780 CC_DrawCurrentFocusRect(lpp);
782 /***********************************************************************
783 * CC_PaintUserColorArray [internal]
784 * Paint the 16 user-selected colors
786 void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, const COLORREF *lpcr )
788 HWND hwnd = GetDlgItem(hDlg, 0x2d1);
789 RECT rect, blockrect;
790 HDC hdc;
791 HBRUSH hBrush;
792 int dx, dy, i, j, k;
793 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
795 GetClientRect(hwnd, &rect);
797 dx = rect.right / cols;
798 dy = rect.bottom / rows;
799 k = rect.left;
801 hdc = GetDC(hwnd);
802 if (hdc)
804 hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
805 if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
806 FillRect( hdc, &rect, hBrush );
807 for (j = 0; j < rows; j++)
809 for (i = 0; i < cols; i++)
811 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
812 if (hBrush)
814 blockrect.left = rect.left;
815 blockrect.top = rect.top;
816 blockrect.right = rect.left + dx - DISTANCE;
817 blockrect.bottom = rect.top + dy - DISTANCE;
818 FillRect(hdc, &blockrect, hBrush);
819 DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
820 DeleteObject(hBrush);
822 rect.left += dx;
824 rect.top += dy;
825 rect.left = k;
827 ReleaseDC(hwnd, hdc);
829 if (lpp->hwndFocus == hwnd)
830 CC_DrawCurrentFocusRect(lpp);
834 /***********************************************************************
835 * CC_HookCallChk [internal]
837 BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
839 if (lpcc)
840 if(lpcc->Flags & CC_ENABLEHOOK)
841 if (lpcc->lpfnHook)
842 return TRUE;
843 return FALSE;
846 /***********************************************************************
847 * CC_WMInitDialog [internal]
849 static LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
851 int i, res;
852 int r, g, b;
853 HWND hwnd;
854 RECT rect;
855 POINT point;
856 LPCCPRIV lpp;
858 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
859 lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
861 lpp->lpcc = (LPCHOOSECOLORW) lParam;
862 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
864 HeapFree(GetProcessHeap(), 0, lpp);
865 EndDialog (hDlg, 0) ;
866 return FALSE;
869 SetPropW( hDlg, szColourDialogProp, lpp );
871 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
872 ShowWindow( GetDlgItem(hDlg,0x40e), 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, 0x2cf);
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, 0x2c6); /* 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 = 0x2bf; i < 0x2c5; i++)
910 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
911 for (i = 0x2d3; i < 0x2d9; i++)
912 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
913 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
914 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
915 ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
916 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
917 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
919 else
920 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
921 res = TRUE;
922 for (i = 0x2bf; i < 0x2c5; 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(hDlg, lpp->lpcc->rgbResult);
935 lpp->h = CC_RGBtoHSL('H', r, g, b);
936 lpp->s = CC_RGBtoHSL('S', r, g, b);
937 lpp->l = CC_RGBtoHSL('L', r, g, b);
939 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
940 SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
941 SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
942 SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
943 SetDlgItemInt(hDlg, 706, r, TRUE);
944 SetDlgItemInt(hDlg, 707, g, TRUE);
945 SetDlgItemInt(hDlg, 708, b, TRUE);
947 CC_PaintCross(hDlg, lpp->h, lpp->s);
948 CC_PaintTriangle(hDlg, lpp->l);
950 return res;
954 /***********************************************************************
955 * CC_WMCommand [internal]
957 LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
959 int r, g, b, i, xx;
960 UINT cokmsg;
961 HDC hdc;
962 COLORREF *cr;
963 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
964 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam, lParam);
965 switch (LOWORD(wParam))
967 case 0x2c2: /* edit notify RGB */
968 case 0x2c3:
969 case 0x2c4:
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 0x2c2: if ((xx = (i != r))) r = i; break;
980 case 0x2c3: if ((xx = (i != g))) g = i; break;
981 case 0x2c4: if ((xx = (i != b))) b = i; break;
983 if (xx) /* something has changed */
985 lpp->lpcc->rgbResult = RGB(r, g, b);
986 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
987 lpp->h = CC_RGBtoHSL('H', r, g, b);
988 lpp->s = CC_RGBtoHSL('S', r, g, b);
989 lpp->l = CC_RGBtoHSL('L', r, g, b);
990 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
991 CC_PaintCross(hDlg, lpp->h, lpp->s);
992 CC_PaintTriangle(hDlg, lpp->l);
995 break;
997 case 0x2bf: /* edit notify HSL */
998 case 0x2c0:
999 case 0x2c1:
1000 if (notifyCode == EN_UPDATE && !lpp->updating)
1002 i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == 0x2bf ? 239:240);
1003 xx = 0;
1004 switch (LOWORD(wParam))
1006 case 0x2bf: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1007 case 0x2c0: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1008 case 0x2c1: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1010 if (xx) /* something has changed */
1012 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1013 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1014 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1015 lpp->lpcc->rgbResult = RGB(r, g, b);
1016 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1017 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1018 CC_PaintCross(hDlg, lpp->h, lpp->s);
1019 CC_PaintTriangle(hDlg, lpp->l);
1022 break;
1024 case 0x2cf:
1025 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, &lpp->fullsize);
1026 SetFocus( GetDlgItem(hDlg, 0x2bf));
1027 break;
1029 case 0x2c8: /* add colors ... column by column */
1030 cr = lpp->lpcc->lpCustColors;
1031 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1032 if (++lpp->nextuserdef == 16)
1033 lpp->nextuserdef = 0;
1034 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1035 break;
1037 case 0x2c9: /* resulting color */
1038 hdc = GetDC(hDlg);
1039 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1040 ReleaseDC(hDlg, hdc);
1041 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1042 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1043 r = GetRValue(lpp->lpcc->rgbResult);
1044 g = GetGValue(lpp->lpcc->rgbResult);
1045 b = GetBValue(lpp->lpcc->rgbResult);
1046 lpp->h = CC_RGBtoHSL('H', r, g, b);
1047 lpp->s = CC_RGBtoHSL('S', r, g, b);
1048 lpp->l = CC_RGBtoHSL('L', r, g, b);
1049 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
1050 CC_PaintCross(hDlg, lpp->h, lpp->s);
1051 CC_PaintTriangle(hDlg, lpp->l);
1052 break;
1054 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1055 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1056 if (lpp->lpcc->hwndOwner)
1057 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1058 if ( CC_HookCallChk(lpp->lpcc))
1059 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
1060 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1061 break;
1063 case IDOK :
1064 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1065 if (lpp->lpcc->hwndOwner)
1066 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1067 break; /* do NOT close */
1068 EndDialog(hDlg, 1) ;
1069 return TRUE ;
1071 case IDCANCEL :
1072 EndDialog(hDlg, 0) ;
1073 return TRUE ;
1076 return FALSE;
1079 /***********************************************************************
1080 * CC_WMPaint [internal]
1082 LRESULT CC_WMPaint( HWND hDlg, WPARAM wParam, LPARAM lParam )
1084 PAINTSTRUCT ps;
1085 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
1087 BeginPaint(hDlg, &ps);
1088 /* we have to paint dialog children except text and buttons */
1089 CC_PaintPredefColorArray(hDlg, 6, 8);
1090 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1091 CC_PaintLumBar(hDlg, lpp->h, lpp->s);
1092 CC_PaintTriangle(hDlg, lpp->l);
1093 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1094 CC_PaintColorGraph(hDlg);
1095 CC_PaintCross(hDlg, lpp->h, lpp->s);
1096 EndPaint(hDlg, &ps);
1098 return TRUE;
1101 /***********************************************************************
1102 * CC_WMLButtonUp [internal]
1104 LRESULT CC_WMLButtonUp( HWND hDlg, WPARAM wParam, LPARAM lParam )
1106 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
1107 if (lpp->capturedGraph)
1109 lpp->capturedGraph = 0;
1110 ReleaseCapture();
1111 CC_PaintCross(hDlg, lpp->h, lpp->s);
1112 return 1;
1114 return 0;
1117 /***********************************************************************
1118 * CC_WMMouseMove [internal]
1120 LRESULT CC_WMMouseMove( HWND hDlg, LPARAM lParam )
1122 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
1123 int r, g, b;
1125 if (lpp->capturedGraph)
1127 int *ptrh = NULL, *ptrs = &lpp->l;
1128 if (lpp->capturedGraph == 0x2c6)
1130 ptrh = &lpp->h;
1131 ptrs = &lpp->s;
1133 if (CC_MouseCheckColorGraph( hDlg, lpp->capturedGraph, ptrh, ptrs, lParam))
1135 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1136 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1137 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1138 lpp->lpcc->rgbResult = RGB(r, g, b);
1139 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1140 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1141 CC_PaintCross(hDlg, lpp->h, lpp->s);
1142 CC_PaintTriangle(hDlg, lpp->l);
1143 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1145 else
1147 ReleaseCapture();
1148 lpp->capturedGraph = 0;
1150 return 1;
1152 return 0;
1155 /***********************************************************************
1156 * CC_WMLButtonDown [internal]
1158 LRESULT CC_WMLButtonDown( HWND hDlg, WPARAM wParam, LPARAM lParam )
1160 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
1161 int r, g, b, i;
1162 i = 0;
1164 if (CC_MouseCheckPredefColorArray(lpp, hDlg, 0x2d0, 6, 8, lParam))
1165 i = 1;
1166 else
1167 if (CC_MouseCheckUserColorArray(lpp, hDlg, 0x2d1, 2, 8, lParam))
1168 i = 1;
1169 else
1170 if (CC_MouseCheckColorGraph(hDlg, 0x2c6, &lpp->h, &lpp->s, lParam))
1172 i = 2;
1173 lpp->capturedGraph = 0x2c6;
1175 else
1176 if (CC_MouseCheckColorGraph(hDlg, 0x2be, NULL, &lpp->l, lParam))
1178 i = 2;
1179 lpp->capturedGraph = 0x2be;
1181 if ( i == 2 )
1183 SetCapture(hDlg);
1184 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1185 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1186 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1187 lpp->lpcc->rgbResult = RGB(r, g, b);
1189 if ( i == 1 )
1191 r = GetRValue(lpp->lpcc->rgbResult);
1192 g = GetGValue(lpp->lpcc->rgbResult);
1193 b = GetBValue(lpp->lpcc->rgbResult);
1194 lpp->h = CC_RGBtoHSL('H', r, g, b);
1195 lpp->s = CC_RGBtoHSL('S', r, g, b);
1196 lpp->l = CC_RGBtoHSL('L', r, g, b);
1198 if (i)
1200 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1201 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1202 CC_PaintCross(hDlg, lpp->h, lpp->s);
1203 CC_PaintTriangle(hDlg, lpp->l);
1204 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1205 return TRUE;
1207 return FALSE;
1210 /***********************************************************************
1211 * ColorDlgProc32 [internal]
1214 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1215 WPARAM wParam, LPARAM lParam )
1218 int res;
1219 LPCCPRIV lpp = (LPCCPRIV) GetPropW( hDlg, szColourDialogProp );
1220 if (message != WM_INITDIALOG)
1222 if (!lpp)
1223 return FALSE;
1224 res = 0;
1225 if (CC_HookCallChk(lpp->lpcc))
1226 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1227 if ( res )
1228 return res;
1231 /* FIXME: SetRGB message
1232 if (message && message == msetrgb)
1233 return HandleSetRGB(hDlg, lParam);
1236 switch (message)
1238 case WM_INITDIALOG:
1239 return CC_WMInitDialog(hDlg, wParam, lParam);
1240 case WM_NCDESTROY:
1241 DeleteDC(lpp->hdcMem);
1242 DeleteObject(lpp->hbmMem);
1243 HeapFree(GetProcessHeap(), 0, lpp);
1244 RemovePropW( hDlg, szColourDialogProp );
1245 break;
1246 case WM_COMMAND:
1247 if (CC_WMCommand( hDlg, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1248 return TRUE;
1249 break;
1250 case WM_PAINT:
1251 if ( CC_WMPaint(hDlg, wParam, lParam))
1252 return TRUE;
1253 break;
1254 case WM_LBUTTONDBLCLK:
1255 if (CC_MouseCheckResultWindow(hDlg, lParam))
1256 return TRUE;
1257 break;
1258 case WM_MOUSEMOVE:
1259 if (CC_WMMouseMove(hDlg, lParam))
1260 return TRUE;
1261 break;
1262 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1263 if (CC_WMLButtonUp(hDlg, wParam, lParam))
1264 return TRUE;
1265 break;
1266 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1267 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1268 return TRUE;
1269 break;
1271 return FALSE ;
1274 /***********************************************************************
1275 * ChooseColorW (COMDLG32.@)
1277 * Create a color dialog box.
1279 * PARAMS
1280 * lpChCol [I/O] in: information to initialize the dialog box.
1281 * out: User's color selection
1283 * RETURNS
1284 * TRUE: Ok button clicked.
1285 * FALSE: Cancel button clicked, or error.
1287 BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
1289 HANDLE hDlgTmpl = 0;
1290 BOOL bRet = FALSE;
1291 LPCVOID template;
1293 TRACE("ChooseColor\n");
1294 if (!lpChCol) return FALSE;
1296 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1298 if (!(template = LockResource(lpChCol->hInstance)))
1300 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1301 return FALSE;
1304 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1306 HRSRC hResInfo;
1307 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1308 lpChCol->lpTemplateName,
1309 (LPWSTR)RT_DIALOG)))
1311 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1312 return FALSE;
1314 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1315 !(template = LockResource(hDlgTmpl)))
1317 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1318 return FALSE;
1321 else
1323 HRSRC hResInfo;
1324 HGLOBAL hDlgTmpl;
1325 static const WCHAR wszCHOOSE_COLOR[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1326 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, wszCHOOSE_COLOR, (LPWSTR)RT_DIALOG)))
1328 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1329 return FALSE;
1331 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1332 !(template = LockResource(hDlgTmpl)))
1334 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1335 return FALSE;
1339 bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1340 ColorDlgProc, (LPARAM)lpChCol);
1341 return bRet;
1344 /***********************************************************************
1345 * ChooseColorA (COMDLG32.@)
1347 * See ChooseColorW.
1349 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1352 LPWSTR template_name = NULL;
1353 BOOL ret;
1355 LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
1356 lpcc->lStructSize = sizeof(*lpcc);
1357 lpcc->hwndOwner = lpChCol->hwndOwner;
1358 lpcc->hInstance = lpChCol->hInstance;
1359 lpcc->rgbResult = lpChCol->rgbResult;
1360 lpcc->lpCustColors = lpChCol->lpCustColors;
1361 lpcc->Flags = lpChCol->Flags;
1362 lpcc->lCustData = lpChCol->lCustData;
1363 lpcc->lpfnHook = lpChCol->lpfnHook;
1364 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1365 if (HIWORD(lpChCol->lpTemplateName)) {
1366 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1367 template_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1368 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
1369 lpcc->lpTemplateName = template_name;
1370 } else {
1371 lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
1375 ret = ChooseColorW(lpcc);
1377 if (ret)
1378 lpChCol->rgbResult = lpcc->rgbResult;
1379 HeapFree(GetProcessHeap(), 0, template_name);
1380 HeapFree(GetProcessHeap(), 0, lpcc);
1381 return ret;