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 */
37 #include "wine/debug.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
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 */
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 */
93 /***********************************************************************
94 * CC_HSLtoRGB [internal]
96 int CC_HSLtoRGB(char c
, int hue
, int sat
, int lum
)
103 case 'R': if (hue
> 80) hue
-= 80; else hue
+= 160; break;
104 case 'G': if (hue
> 160) hue
-= 160; else hue
+= 80; break;
109 maxrgb
= (256 * min(120,lum
)) / 120; /* 0 .. 256 */
115 res
= (hue
- 80) * maxrgb
; /* 0...10240 */
116 res
/= 40; /* 0...256 */
123 res
= (240 - hue
) * maxrgb
;
126 res
= res
- maxrgb
/ 2; /* -128...128 */
129 res
= maxrgb
/ 2 + (sat
* res
) / 240; /* 0..256 */
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;
157 case 'L': mmsum
*= 120; /* 0...61200=(255+255)*120 */
158 result
= mmsum
/ 255; /* 0...240 */
161 case 'S': if (!mmsum
)
164 if (!mini
|| maxi
== 255)
168 result
= mmdif
* 240; /* 0...61200=255*240 */
169 result
/= (mmsum
> 255 ? mmsum
= 510 - mmsum
: mmsum
); /* 0..255 */
173 case 'H': if (!mmdif
)
179 iresult
= 40 * (g
- b
); /* -10200 ... 10200 */
180 iresult
/= (int) mmdif
; /* -40 .. 40 */
182 iresult
+= 240; /* 0..40 and 200..240 */
187 iresult
= 40 * (b
- r
);
188 iresult
/= (int) mmdif
;
189 iresult
+= 80; /* 40 .. 120 */
194 iresult
= 40 * (r
- g
);
195 iresult
/= (int) mmdif
;
196 iresult
+= 160; /* 120 .. 200 */
202 return result
; /* is this integer arithmetic precise enough ? */
206 /***********************************************************************
207 * CC_DrawCurrentFocusRect [internal]
209 static void CC_DrawCurrentFocusRect( const CCPRIV
*lpp
)
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
)
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
;
239 DrawFocusRect(hdc
, &rect
);
240 CopyRect(&lpp
->focusRect
, &rect
);
241 lpp
->hwndFocus
= hwnd
;
242 ReleaseDC(hwnd
, hdc
);
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
,
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
))
273 lpp
->lpcc
->rgbResult
= predefcolors
[y
][x
];
274 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
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
,
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
))
308 lpp
->lpcc
->rgbResult
= crarr
[x
+ (cols
* y
) ];
309 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
319 /* 240 ^...... ^^ 240
326 /***********************************************************************
327 * CC_MouseCheckColorGraph [internal]
329 static int CC_MouseCheckColorGraph( HWND hDlg
, int dlgitem
, int *hori
, int *vert
, LPARAM lParam
)
336 CONV_LPARAMTOPOINT(lParam
, &point
);
337 ClientToScreen(hDlg
, &point
);
338 hwnd
= GetDlgItem( hDlg
, dlgitem
);
339 GetWindowRect(hwnd
, &rect
);
341 if (!PtInRect(&rect
, point
))
344 GetClientRect(hwnd
, &rect
);
345 ScreenToClient(hwnd
, &point
);
347 x
= (long) point
.x
* MAXHORI
;
349 y
= (long) (rect
.bottom
- point
.y
) * MAXVERT
;
354 if (x
> MAXHORI
) x
= MAXHORI
;
355 if (y
> MAXVERT
) y
= MAXVERT
;
364 /***********************************************************************
365 * CC_MouseCheckResultWindow [internal]
366 * test if double click one of the result colors
368 int CC_MouseCheckResultWindow( HWND hDlg
, LPARAM lParam
)
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);
386 /***********************************************************************
387 * CC_CheckDigitsInEdit [internal]
389 int CC_CheckDigitsInEdit( HWND hwnd
, int maxval
)
391 int i
, k
, m
, result
, value
;
395 GetWindowTextA(hwnd
, buffer
, sizeof(buffer
));
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
];
411 value
= atoi(buffer
);
412 if (value
> maxval
) /* build a new string */
414 sprintf(buffer
, "%d", maxval
);
419 editpos
= SendMessageA(hwnd
, EM_GETSEL
, 0, 0);
420 SetWindowTextA(hwnd
, buffer
);
421 SendMessageA(hwnd
, EM_SETSEL
, 0, editpos
);
428 /***********************************************************************
429 * CC_PaintSelectedColor [internal]
431 void CC_PaintSelectedColor( HWND hDlg
, COLORREF cr
)
436 HWND hwnd
= GetDlgItem(hDlg
, 0x2c5);
437 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
440 GetClientRect(hwnd
, &rect
) ;
441 hBrush
= CreateSolidBrush(cr
);
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
)
458 int w
= LOWORD(GetDialogBaseUnits()) / 2;
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
;
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
; /* | \ | */
478 temp
= (long)height
* (long)y
;
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
)
508 int w
= GetDialogBaseUnits() - 1;
509 int wc
= GetDialogBaseUnits() * 3 / 4;
510 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
511 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
516 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
518 GetClientRect(hwnd
, &rect
);
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
);
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
);
566 HCURSOR hcursor
= SetCursor( LoadCursorW(0, (LPCWSTR
)IDC_WAIT
) );
568 GetClientRect(hwnd
, &client
);
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;
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
);
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
);
608 if (IsWindowVisible(hwnd
)) /* if full size */
611 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
614 GetClientRect(hwnd
, &rect
);
616 BitBlt(hDC
, 0, 0, rect
.right
, rect
.bottom
, lpp
->hdcMem
, 0, 0, SRCCOPY
);
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);
630 int lum
, ldif
, ydif
, r
, g
, b
;
634 if (IsWindowVisible(hwnd
))
637 GetClientRect(hwnd
, &client
);
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
)
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
)
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
)
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
);
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
;
746 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
748 GetClientRect(hwnd
, &rect
);
749 dx
= rect
.right
/ cols
;
750 dy
= rect
.bottom
/ rows
;
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
]);
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
);
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
;
793 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
795 GetClientRect(hwnd
, &rect
);
797 dx
= rect
.right
/ cols
;
798 dy
= rect
.bottom
/ rows
;
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
]);
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
);
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
)
840 if(lpcc
->Flags
& CC_ENABLEHOOK
)
846 /***********************************************************************
847 * CC_WMInitDialog [internal]
849 static LONG
CC_WMInitDialog( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
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) ;
869 SetPropW( hDlg
, szColourDialogProp
, lpp
);
871 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
872 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
873 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRINGA
);
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
);
888 /* FIXME: Draw_a_focus_rect & set_init_values */
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
);
920 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, NULL
);
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
);
954 /***********************************************************************
955 * CC_WMCommand [internal]
957 LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
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 */
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
);
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
);
997 case 0x2bf: /* edit notify HSL */
1000 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
1002 i
= CC_CheckDigitsInEdit(hwndCtl
, LOWORD(wParam
) == 0x2bf ? 239:240);
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
);
1025 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1026 SetFocus( GetDlgItem(hDlg
, 0x2bf));
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
);
1037 case 0x2c9: /* resulting color */
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
);
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
);
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) ;
1072 EndDialog(hDlg
, 0) ;
1079 /***********************************************************************
1080 * CC_WMPaint [internal]
1082 LRESULT
CC_WMPaint( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
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
);
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;
1111 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1117 /***********************************************************************
1118 * CC_WMMouseMove [internal]
1120 LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1122 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1125 if (lpp
->capturedGraph
)
1127 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1128 if (lpp
->capturedGraph
== 0x2c6)
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
);
1148 lpp
->capturedGraph
= 0;
1155 /***********************************************************************
1156 * CC_WMLButtonDown [internal]
1158 LRESULT
CC_WMLButtonDown( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1160 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1164 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1167 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1170 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1173 lpp
->capturedGraph
= 0x2c6;
1176 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1179 lpp
->capturedGraph
= 0x2be;
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
);
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
);
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
);
1210 /***********************************************************************
1211 * ColorDlgProc32 [internal]
1214 static INT_PTR CALLBACK
ColorDlgProc( HWND hDlg
, UINT message
,
1215 WPARAM wParam
, LPARAM lParam
)
1219 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1220 if (message
!= WM_INITDIALOG
)
1225 if (CC_HookCallChk(lpp
->lpcc
))
1226 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1231 /* FIXME: SetRGB message
1232 if (message && message == msetrgb)
1233 return HandleSetRGB(hDlg, lParam);
1239 return CC_WMInitDialog(hDlg
, wParam
, lParam
);
1241 DeleteDC(lpp
->hdcMem
);
1242 DeleteObject(lpp
->hbmMem
);
1243 HeapFree(GetProcessHeap(), 0, lpp
);
1244 RemovePropW( hDlg
, szColourDialogProp
);
1247 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1251 if ( CC_WMPaint(hDlg
, wParam
, lParam
))
1254 case WM_LBUTTONDBLCLK
:
1255 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1259 if (CC_WMMouseMove(hDlg
, lParam
))
1262 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1263 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1266 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1267 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1274 /***********************************************************************
1275 * ChooseColorW (COMDLG32.@)
1277 * Create a color dialog box.
1280 * lpChCol [I/O] in: information to initialize the dialog box.
1281 * out: User's color selection
1284 * TRUE: Ok button clicked.
1285 * FALSE: Cancel button clicked, or error.
1287 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1289 HANDLE hDlgTmpl
= 0;
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
);
1304 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1307 if (!(hResInfo
= FindResourceW((HINSTANCE
)lpChCol
->hInstance
,
1308 lpChCol
->lpTemplateName
,
1309 (LPWSTR
)RT_DIALOG
)))
1311 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1314 if (!(hDlgTmpl
= LoadResource((HINSTANCE
)lpChCol
->hInstance
, hResInfo
)) ||
1315 !(template = LockResource(hDlgTmpl
)))
1317 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
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
);
1331 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1332 !(template = LockResource(hDlgTmpl
)))
1334 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1339 bRet
= DialogBoxIndirectParamW(COMDLG32_hInstance
, template, lpChCol
->hwndOwner
,
1340 ColorDlgProc
, (LPARAM
)lpChCol
);
1344 /***********************************************************************
1345 * ChooseColorA (COMDLG32.@)
1349 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1352 LPWSTR template_name
= NULL
;
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
;
1371 lpcc
->lpTemplateName
= (LPCWSTR
)lpChCol
->lpTemplateName
;
1375 ret
= ChooseColorW(lpcc
);
1378 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1379 HeapFree(GetProcessHeap(), 0, template_name
);
1380 HeapFree(GetProcessHeap(), 0, lpcc
);