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 */
34 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
40 static INT_PTR CALLBACK
ColorDlgProc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
);
42 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
44 static const COLORREF predefcolors
[6][8]=
46 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
47 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
48 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
49 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
51 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
52 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
53 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
54 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
56 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
57 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
58 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
59 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
62 static const WCHAR szColourDialogProp
[] = {
63 'c','o','l','o','u','r','d','i','a','l','o','g','p','r','o','p',0 };
65 /* Chose Color PRIVATE Structure:
67 * This structure is duplicated in the 16 bit code with
71 typedef struct CCPRIVATE
73 LPCHOOSECOLORW lpcc
; /* points to public known data structure */
74 HWND hwndSelf
; /* dialog window */
75 int nextuserdef
; /* next free place in user defined color array */
76 HDC hdcMem
; /* color graph used for BitBlt() */
77 HBITMAP hbmMem
; /* color graph bitmap */
78 RECT fullsize
; /* original dialog window size */
79 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
80 RECT old3angle
; /* last position of l-marker */
81 RECT oldcross
; /* last position of color/saturation marker */
82 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
85 int l
; /* for temporary storing of hue,sat,lum */
86 int capturedGraph
; /* control mouse captured */
87 RECT focusRect
; /* rectangle last focused item */
88 HWND hwndFocus
; /* handle last focused item */
91 static int hsl_to_x(int hue
, int sat
, int lum
)
96 maxrgb
= (256 * min(120,lum
)) / 120; /* 0 .. 256 */
102 res
= (hue
- 80) * maxrgb
; /* 0...10240 */
103 res
/= 40; /* 0...256 */
110 res
= (240 - hue
) * maxrgb
;
113 res
= res
- maxrgb
/ 2; /* -128...128 */
116 res
= maxrgb
/ 2 + (sat
* res
) / 240; /* 0..256 */
119 if (lum
> 120 && res
< 256)
120 res
+= ((lum
- 120) * (256 - res
)) / 120;
122 return min(res
, 255);
125 /***********************************************************************
126 * CC_HSLtoRGB [internal]
128 static COLORREF
CC_HSLtoRGB(int hue
, int sat
, int lum
)
133 h
= hue
> 80 ? hue
-80 : hue
+160;
134 r
= hsl_to_x(h
, sat
, lum
);
136 h
= hue
> 160 ? hue
-160 : hue
+80;
137 g
= hsl_to_x(h
, sat
, lum
);
139 b
= hsl_to_x(hue
, sat
, lum
);
144 /***********************************************************************
145 * CC_RGBtoHSL [internal]
147 static int CC_RGBtoHSL(char c
, COLORREF rgb
)
149 WORD maxi
, mini
, mmsum
, mmdif
, result
= 0;
150 int iresult
= 0, r
, g
, b
;
167 case 'L': mmsum
*= 120; /* 0...61200=(255+255)*120 */
168 result
= mmsum
/ 255; /* 0...240 */
171 case 'S': if (!mmsum
)
174 if (!mini
|| maxi
== 255)
178 result
= mmdif
* 240; /* 0...61200=255*240 */
179 result
/= (mmsum
> 255 ? 510 - mmsum
: mmsum
); /* 0..255 */
183 case 'H': if (!mmdif
)
189 iresult
= 40 * (g
- b
); /* -10200 ... 10200 */
190 iresult
/= (int) mmdif
; /* -40 .. 40 */
192 iresult
+= 240; /* 0..40 and 200..240 */
197 iresult
= 40 * (b
- r
);
198 iresult
/= (int) mmdif
;
199 iresult
+= 80; /* 40 .. 120 */
204 iresult
= 40 * (r
- g
);
205 iresult
/= (int) mmdif
;
206 iresult
+= 160; /* 120 .. 200 */
212 return result
; /* is this integer arithmetic precise enough ? */
216 /***********************************************************************
217 * CC_DrawCurrentFocusRect [internal]
219 static void CC_DrawCurrentFocusRect( const CCPRIV
*lpp
)
223 HDC hdc
= GetDC(lpp
->hwndFocus
);
224 DrawFocusRect(hdc
, &lpp
->focusRect
);
225 ReleaseDC(lpp
->hwndFocus
, hdc
);
229 /***********************************************************************
230 * CC_DrawFocusRect [internal]
232 static void CC_DrawFocusRect(CCPRIV
*lpp
, HWND hwnd
, int x
, int y
, int rows
, int cols
)
238 CC_DrawCurrentFocusRect(lpp
); /* remove current focus rect */
239 /* calculate new rect */
240 GetClientRect(hwnd
, &rect
);
241 dx
= (rect
.right
- rect
.left
) / cols
;
242 dy
= (rect
.bottom
- rect
.top
) / rows
;
243 rect
.left
+= (x
* dx
) - 2;
244 rect
.top
+= (y
* dy
) - 2;
245 rect
.right
= rect
.left
+ dx
;
246 rect
.bottom
= rect
.top
+ dy
;
249 DrawFocusRect(hdc
, &rect
);
250 CopyRect(&lpp
->focusRect
, &rect
);
251 lpp
->hwndFocus
= hwnd
;
252 ReleaseDC(hwnd
, hdc
);
257 /***********************************************************************
258 * CC_MouseCheckPredefColorArray [internal]
259 * returns TRUE if one of the predefined colors is clicked
261 static BOOL
CC_MouseCheckPredefColorArray(CCPRIV
*lpp
, int rows
, int cols
, LPARAM lParam
)
268 CONV_LPARAMTOPOINT(lParam
, &point
);
269 ClientToScreen(lpp
->hwndSelf
, &point
);
270 hwnd
= GetDlgItem(lpp
->hwndSelf
, IDC_COLOR_PREDEF
);
271 GetWindowRect(hwnd
, &rect
);
272 if (PtInRect(&rect
, point
))
274 dx
= (rect
.right
- rect
.left
) / cols
;
275 dy
= (rect
.bottom
- rect
.top
) / rows
;
276 ScreenToClient(hwnd
, &point
);
278 if (point
.x
% dx
< ( dx
- DISTANCE
) && point
.y
% dy
< ( dy
- DISTANCE
))
282 lpp
->lpcc
->rgbResult
= predefcolors
[y
][x
];
283 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
290 /***********************************************************************
291 * CC_MouseCheckUserColorArray [internal]
292 * return TRUE if the user clicked a color
294 static BOOL
CC_MouseCheckUserColorArray(CCPRIV
*lpp
, int rows
, int cols
, LPARAM lParam
)
300 COLORREF
*crarr
= lpp
->lpcc
->lpCustColors
;
302 CONV_LPARAMTOPOINT(lParam
, &point
);
303 ClientToScreen(lpp
->hwndSelf
, &point
);
304 hwnd
= GetDlgItem(lpp
->hwndSelf
, IDC_COLOR_USRDEF
);
305 GetWindowRect(hwnd
, &rect
);
306 if (PtInRect(&rect
, point
))
308 dx
= (rect
.right
- rect
.left
) / cols
;
309 dy
= (rect
.bottom
- rect
.top
) / rows
;
310 ScreenToClient(hwnd
, &point
);
312 if (point
.x
% dx
< (dx
- DISTANCE
) && point
.y
% dy
< (dy
- DISTANCE
))
316 lpp
->lpcc
->rgbResult
= crarr
[x
+ (cols
* y
) ];
317 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
327 /* 240 ^...... ^^ 240
334 /***********************************************************************
335 * CC_MouseCheckColorGraph [internal]
337 static BOOL
CC_MouseCheckColorGraph( HWND hDlg
, int dlgitem
, int *hori
, int *vert
, LPARAM lParam
)
344 CONV_LPARAMTOPOINT(lParam
, &point
);
345 ClientToScreen(hDlg
, &point
);
346 hwnd
= GetDlgItem( hDlg
, dlgitem
);
347 GetWindowRect(hwnd
, &rect
);
349 if (!PtInRect(&rect
, point
))
352 GetClientRect(hwnd
, &rect
);
353 ScreenToClient(hwnd
, &point
);
355 x
= (long) point
.x
* MAXHORI
;
357 y
= (long) (rect
.bottom
- point
.y
) * MAXVERT
;
362 if (x
> MAXHORI
) x
= MAXHORI
;
363 if (y
> MAXVERT
) y
= MAXVERT
;
372 /***********************************************************************
373 * CC_MouseCheckResultWindow [internal]
374 * test if double click one of the result colors
376 static BOOL
CC_MouseCheckResultWindow( HWND hDlg
, LPARAM lParam
)
382 CONV_LPARAMTOPOINT(lParam
, &point
);
383 ClientToScreen(hDlg
, &point
);
384 hwnd
= GetDlgItem(hDlg
, IDC_COLOR_RESULT
);
385 GetWindowRect(hwnd
, &rect
);
386 if (PtInRect(&rect
, point
))
388 PostMessageA(hDlg
, WM_COMMAND
, IDC_COLOR_RES
, 0);
394 /***********************************************************************
395 * CC_CheckDigitsInEdit [internal]
397 static int CC_CheckDigitsInEdit( HWND hwnd
, int maxval
)
399 int i
, k
, m
, result
, value
;
403 GetWindowTextA(hwnd
, buffer
, sizeof(buffer
));
407 for (i
= 0 ; i
< m
; i
++)
408 if (buffer
[i
] < '0' || buffer
[i
] > '9')
410 for (k
= i
+ 1; k
<= m
; k
++) /* delete bad character */
412 buffer
[i
] = buffer
[k
];
419 value
= atoi(buffer
);
420 if (value
> maxval
) /* build a new string */
422 sprintf(buffer
, "%d", maxval
);
427 editpos
= SendMessageA(hwnd
, EM_GETSEL
, 0, 0);
428 SetWindowTextA(hwnd
, buffer
);
429 SendMessageA(hwnd
, EM_SETSEL
, 0, editpos
);
436 /***********************************************************************
437 * CC_PaintSelectedColor [internal]
439 static void CC_PaintSelectedColor(const CCPRIV
*infoPtr
)
441 if (IsWindowVisible( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
) )) /* if full size */
446 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_RESULT
);
449 GetClientRect(hwnd
, &rect
) ;
450 hBrush
= CreateSolidBrush(infoPtr
->lpcc
->rgbResult
);
453 FillRect(hdc
, &rect
, hBrush
);
454 DrawEdge(hdc
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
455 DeleteObject(hBrush
);
457 ReleaseDC(hwnd
, hdc
);
461 /***********************************************************************
462 * CC_PaintTriangle [internal]
464 static void CC_PaintTriangle(CCPRIV
*infoPtr
)
468 int w
= LOWORD(GetDialogBaseUnits()) / 2;
474 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_LUMBAR
);
476 if (IsWindowVisible( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
))) /* if full size */
478 GetClientRect(hwnd
, &rect
);
479 height
= rect
.bottom
;
480 hDC
= GetDC(infoPtr
->hwndSelf
);
481 points
[0].y
= rect
.top
;
482 points
[0].x
= rect
.right
; /* | /| */
483 ClientToScreen(hwnd
, points
); /* | / | */
484 ScreenToClient(infoPtr
->hwndSelf
, points
); /* |< | */
485 oben
= points
[0].y
; /* | \ | */
487 temp
= (long)height
* (long)infoPtr
->l
;
489 points
[0].y
= oben
+ height
- temp
/ (long)MAXVERT
;
490 points
[1].y
= points
[0].y
+ w
;
491 points
[2].y
= points
[0].y
- w
;
492 points
[2].x
= points
[1].x
= points
[0].x
+ w
;
494 hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
495 if (!hbr
) hbr
= GetSysColorBrush(COLOR_BTNFACE
);
496 FillRect(hDC
, &infoPtr
->old3angle
, hbr
);
497 infoPtr
->old3angle
.left
= points
[0].x
;
498 infoPtr
->old3angle
.right
= points
[1].x
+ 1;
499 infoPtr
->old3angle
.top
= points
[2].y
- 1;
500 infoPtr
->old3angle
.bottom
= points
[1].y
+ 1;
502 hbr
= SelectObject(hDC
, GetStockObject(BLACK_BRUSH
));
503 Polygon(hDC
, points
, 3);
504 SelectObject(hDC
, hbr
);
506 ReleaseDC(infoPtr
->hwndSelf
, hDC
);
511 /***********************************************************************
512 * CC_PaintCross [internal]
514 static void CC_PaintCross(CCPRIV
*infoPtr
)
516 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
);
518 if (IsWindowVisible(hwnd
)) /* if full size */
521 int w
= GetDialogBaseUnits() - 1;
522 int wc
= GetDialogBaseUnits() * 3 / 4;
531 GetClientRect(hwnd
, &rect
);
533 SelectClipRgn( hDC
, CreateRectRgnIndirect(&rect
));
535 point
.x
= ((long)rect
.right
* (long)x
) / (long)MAXHORI
;
536 point
.y
= rect
.bottom
- ((long)rect
.bottom
* (long)y
) / (long)MAXVERT
;
537 if ( infoPtr
->oldcross
.left
!= infoPtr
->oldcross
.right
)
538 BitBlt(hDC
, infoPtr
->oldcross
.left
, infoPtr
->oldcross
.top
,
539 infoPtr
->oldcross
.right
- infoPtr
->oldcross
.left
,
540 infoPtr
->oldcross
.bottom
- infoPtr
->oldcross
.top
,
541 infoPtr
->hdcMem
, infoPtr
->oldcross
.left
, infoPtr
->oldcross
.top
, SRCCOPY
);
542 infoPtr
->oldcross
.left
= point
.x
- w
- 1;
543 infoPtr
->oldcross
.right
= point
.x
+ w
+ 1;
544 infoPtr
->oldcross
.top
= point
.y
- w
- 1;
545 infoPtr
->oldcross
.bottom
= point
.y
+ w
+ 1;
547 hPen
= CreatePen(PS_SOLID
, 3, RGB(0, 0, 0)); /* -black- color */
548 hPen
= SelectObject(hDC
, hPen
);
549 MoveToEx(hDC
, point
.x
- w
, point
.y
, &p
);
550 LineTo(hDC
, point
.x
- wc
, point
.y
);
551 MoveToEx(hDC
, point
.x
+ wc
, point
.y
, &p
);
552 LineTo(hDC
, point
.x
+ w
, point
.y
);
553 MoveToEx(hDC
, point
.x
, point
.y
- w
, &p
);
554 LineTo(hDC
, point
.x
, point
.y
- wc
);
555 MoveToEx(hDC
, point
.x
, point
.y
+ wc
, &p
);
556 LineTo(hDC
, point
.x
, point
.y
+ w
);
557 DeleteObject( SelectObject(hDC
, hPen
));
559 ReleaseDC(hwnd
, hDC
);
568 /***********************************************************************
569 * CC_PrepareColorGraph [internal]
571 static void CC_PrepareColorGraph(CCPRIV
*infoPtr
)
573 int sdif
, hdif
, xdif
, ydif
, hue
, sat
;
574 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
);
578 HCURSOR hcursor
= SetCursor( LoadCursorW(0, (LPCWSTR
)IDC_WAIT
) );
580 GetClientRect(hwnd
, &client
);
582 infoPtr
->hdcMem
= CreateCompatibleDC(hdc
);
583 infoPtr
->hbmMem
= CreateCompatibleBitmap(hdc
, client
.right
, client
.bottom
);
584 SelectObject(infoPtr
->hdcMem
, infoPtr
->hbmMem
);
586 xdif
= client
.right
/ XSTEPS
;
587 ydif
= client
.bottom
/ YSTEPS
+1;
590 for (rect
.left
= hue
= 0; hue
< 239 + hdif
; hue
+= hdif
)
592 rect
.right
= rect
.left
+ xdif
;
593 rect
.bottom
= client
.bottom
;
594 for(sat
= 0; sat
< 240 + sdif
; sat
+= sdif
)
596 rect
.top
= rect
.bottom
- ydif
;
597 hbrush
= CreateSolidBrush(CC_HSLtoRGB(hue
, sat
, 120));
598 FillRect(infoPtr
->hdcMem
, &rect
, hbrush
);
599 DeleteObject(hbrush
);
600 rect
.bottom
= rect
.top
;
602 rect
.left
= rect
.right
;
604 ReleaseDC(hwnd
, hdc
);
608 /***********************************************************************
609 * CC_PaintColorGraph [internal]
611 static void CC_PaintColorGraph(CCPRIV
*infoPtr
)
613 HWND hwnd
= GetDlgItem( infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
);
617 if (IsWindowVisible(hwnd
)) /* if full size */
619 if (!infoPtr
->hdcMem
)
620 CC_PrepareColorGraph(infoPtr
); /* should not be necessary */
623 GetClientRect(hwnd
, &rect
);
625 BitBlt(hDC
, 0, 0, rect
.right
, rect
.bottom
, infoPtr
->hdcMem
, 0, 0, SRCCOPY
);
627 WARN("choose color: hdcMem is not defined\n");
628 ReleaseDC(hwnd
, hDC
);
632 /***********************************************************************
633 * CC_PaintLumBar [internal]
635 static void CC_PaintLumBar(const CCPRIV
*infoPtr
)
637 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_LUMBAR
);
643 if (IsWindowVisible(hwnd
))
646 GetClientRect(hwnd
, &client
);
650 ydif
= client
.bottom
/ YSTEPS
+1;
651 for (lum
= 0; lum
< 240 + ldif
; lum
+= ldif
)
653 rect
.top
= max(0, rect
.bottom
- ydif
);
654 hbrush
= CreateSolidBrush(CC_HSLtoRGB(infoPtr
->h
, infoPtr
->s
, lum
));
655 FillRect(hDC
, &rect
, hbrush
);
656 DeleteObject(hbrush
);
657 rect
.bottom
= rect
.top
;
659 GetClientRect(hwnd
, &rect
);
660 DrawEdge(hDC
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
661 ReleaseDC(hwnd
, hDC
);
665 /***********************************************************************
666 * CC_EditSetRGB [internal]
668 static void CC_EditSetRGB( CCPRIV
*infoPtr
)
670 if (IsWindowVisible( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
) )) /* if full size */
672 COLORREF cr
= infoPtr
->lpcc
->rgbResult
;
673 int r
= GetRValue(cr
);
674 int g
= GetGValue(cr
);
675 int b
= GetBValue(cr
);
678 infoPtr
->updating
= TRUE
;
679 sprintf(buffer
, "%d", r
);
680 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_R
), buffer
);
681 sprintf(buffer
, "%d", g
);
682 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_G
), buffer
);
683 sprintf( buffer
, "%d", b
);
684 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_B
), buffer
);
685 infoPtr
->updating
= FALSE
;
689 /***********************************************************************
690 * CC_EditSetHSL [internal]
692 static void CC_EditSetHSL( CCPRIV
*infoPtr
)
694 if (IsWindowVisible( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
) )) /* if full size */
698 infoPtr
->updating
= TRUE
;
699 sprintf(buffer
, "%d", infoPtr
->h
);
700 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_H
), buffer
);
701 sprintf(buffer
, "%d", infoPtr
->s
);
702 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_S
), buffer
);
703 sprintf(buffer
, "%d", infoPtr
->l
);
704 SetWindowTextA( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_EDIT_L
), buffer
);
705 infoPtr
->updating
= FALSE
;
707 CC_PaintLumBar(infoPtr
);
710 /***********************************************************************
711 * CC_SwitchToFullSize [internal]
713 static void CC_SwitchToFullSize( CCPRIV
*infoPtr
, const RECT
*lprect
)
717 EnableWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_DEFINE
), FALSE
);
718 CC_PrepareColorGraph(infoPtr
);
719 for (i
= IDC_COLOR_EDIT_H
; i
<= IDC_COLOR_EDIT_B
; i
++)
720 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, i
), SW_SHOW
);
721 for (i
= IDC_COLOR_HL
; i
<= IDC_COLOR_BL
; i
++)
722 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, i
), SW_SHOW
);
723 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_RES
), SW_SHOW
);
724 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_ADD
), SW_SHOW
);
725 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, 1090), SW_SHOW
);
728 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, lprect
->right
-lprect
->left
,
729 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
731 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_LUMBAR
), SW_SHOW
);
732 ShowWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_RESULT
), SW_SHOW
);
734 CC_EditSetRGB(infoPtr
);
735 CC_EditSetHSL(infoPtr
);
736 ShowWindow( GetDlgItem( infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
), SW_SHOW
);
737 UpdateWindow( GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
) );
740 /***********************************************************************
741 * CC_PaintPredefColorArray [internal]
742 * Paints the default standard 48 colors
744 static void CC_PaintPredefColorArray(const CCPRIV
*infoPtr
, int rows
, int cols
)
746 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_PREDEF
);
747 RECT rect
, blockrect
;
752 GetClientRect(hwnd
, &rect
);
753 dx
= rect
.right
/ cols
;
754 dy
= rect
.bottom
/ rows
;
758 GetClientRect(hwnd
, &rect
);
759 hBrush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
760 if (!hBrush
) hBrush
= GetSysColorBrush(COLOR_BTNFACE
);
761 FillRect(hdc
, &rect
, hBrush
);
762 for ( j
= 0; j
< rows
; j
++ )
764 for ( i
= 0; i
< cols
; i
++ )
766 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
769 blockrect
.left
= rect
.left
;
770 blockrect
.top
= rect
.top
;
771 blockrect
.right
= rect
.left
+ dx
- DISTANCE
;
772 blockrect
.bottom
= rect
.top
+ dy
- DISTANCE
;
773 FillRect(hdc
, &blockrect
, hBrush
);
774 DrawEdge(hdc
, &blockrect
, BDR_SUNKEN
, BF_RECT
);
775 DeleteObject(hBrush
);
782 ReleaseDC(hwnd
, hdc
);
783 if (infoPtr
->hwndFocus
== hwnd
)
784 CC_DrawCurrentFocusRect(infoPtr
);
786 /***********************************************************************
787 * CC_PaintUserColorArray [internal]
788 * Paint the 16 user-selected colors
790 static void CC_PaintUserColorArray(const CCPRIV
*infoPtr
, int rows
, int cols
)
792 HWND hwnd
= GetDlgItem(infoPtr
->hwndSelf
, IDC_COLOR_USRDEF
);
793 RECT rect
, blockrect
;
798 GetClientRect(hwnd
, &rect
);
800 dx
= rect
.right
/ cols
;
801 dy
= rect
.bottom
/ rows
;
807 hBrush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
808 if (!hBrush
) hBrush
= GetSysColorBrush(COLOR_BTNFACE
);
809 FillRect( hdc
, &rect
, hBrush
);
810 for (j
= 0; j
< rows
; j
++)
812 for (i
= 0; i
< cols
; i
++)
814 hBrush
= CreateSolidBrush(infoPtr
->lpcc
->lpCustColors
[i
+j
*cols
]);
817 blockrect
.left
= rect
.left
;
818 blockrect
.top
= rect
.top
;
819 blockrect
.right
= rect
.left
+ dx
- DISTANCE
;
820 blockrect
.bottom
= rect
.top
+ dy
- DISTANCE
;
821 FillRect(hdc
, &blockrect
, hBrush
);
822 DrawEdge(hdc
, &blockrect
, BDR_SUNKEN
, BF_RECT
);
823 DeleteObject(hBrush
);
830 ReleaseDC(hwnd
, hdc
);
832 if (infoPtr
->hwndFocus
== hwnd
)
833 CC_DrawCurrentFocusRect(infoPtr
);
837 /***********************************************************************
838 * CC_HookCallChk [internal]
840 static BOOL
CC_HookCallChk( const CHOOSECOLORW
*lpcc
)
843 if(lpcc
->Flags
& CC_ENABLEHOOK
)
849 /***********************************************************************
850 * CC_WMInitDialog [internal]
852 static LRESULT
CC_WMInitDialog( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
854 CHOOSECOLORW
*cc
= (CHOOSECOLORW
*)lParam
;
862 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
864 if (cc
->lStructSize
!= sizeof(CHOOSECOLORW
))
870 lpp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct CCPRIVATE
) );
872 lpp
->hwndSelf
= hDlg
;
874 SetPropW( hDlg
, szColourDialogProp
, lpp
);
876 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
877 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
878 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRINGA
);
881 cpos
= MAKELONG(5,7); /* init */
882 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
884 for (i
= 0; i
< 6; i
++)
885 for (j
= 0; j
< 8; j
++)
886 if (predefcolors
[i
][j
] == lpp
->lpcc
->rgbResult
)
888 cpos
= MAKELONG(i
,j
);
893 /* FIXME: Draw_a_focus_rect & set_init_values */
896 GetWindowRect(hDlg
, &lpp
->fullsize
);
897 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
899 hwnd
= GetDlgItem(hDlg
, IDC_COLOR_DEFINE
);
900 EnableWindow(hwnd
, FALSE
);
902 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
904 rect
= lpp
->fullsize
;
905 res
= rect
.bottom
- rect
.top
;
906 hwnd
= GetDlgItem(hDlg
, IDC_COLOR_GRAPH
); /* cut at left border */
907 point
.x
= point
.y
= 0;
908 ClientToScreen(hwnd
, &point
);
909 ScreenToClient(hDlg
,&point
);
910 GetClientRect(hDlg
, &rect
);
911 point
.x
+= GetSystemMetrics(SM_CXDLGFRAME
);
912 SetWindowPos(hDlg
, 0, 0, 0, point
.x
, res
, SWP_NOMOVE
|SWP_NOZORDER
);
914 for (i
= IDC_COLOR_EDIT_H
; i
<= IDC_COLOR_EDIT_B
; i
++)
915 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
916 for (i
= IDC_COLOR_HL
; i
<= IDC_COLOR_BL
; i
++)
917 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
918 ShowWindow( GetDlgItem(hDlg
, IDC_COLOR_RES
), SW_HIDE
);
919 ShowWindow( GetDlgItem(hDlg
, IDC_COLOR_ADD
), SW_HIDE
);
920 ShowWindow( GetDlgItem(hDlg
, IDC_COLOR_GRAPH
), SW_HIDE
);
921 ShowWindow( GetDlgItem(hDlg
, IDC_COLOR_RESULT
), SW_HIDE
);
922 ShowWindow( GetDlgItem(hDlg
, 1090 ), SW_HIDE
);
925 CC_SwitchToFullSize(lpp
, NULL
);
927 for (i
= IDC_COLOR_EDIT_H
; i
<= IDC_COLOR_EDIT_B
; i
++)
928 SendMessageA( GetDlgItem(hDlg
, i
), EM_LIMITTEXT
, 3, 0); /* max 3 digits: xyz */
929 if (CC_HookCallChk(lpp
->lpcc
))
931 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
934 /* Set the initial values of the color chooser dialog */
935 r
= GetRValue(lpp
->lpcc
->rgbResult
);
936 g
= GetGValue(lpp
->lpcc
->rgbResult
);
937 b
= GetBValue(lpp
->lpcc
->rgbResult
);
939 CC_PaintSelectedColor(lpp
);
940 lpp
->h
= CC_RGBtoHSL('H', lpp
->lpcc
->rgbResult
);
941 lpp
->s
= CC_RGBtoHSL('S', lpp
->lpcc
->rgbResult
);
942 lpp
->l
= CC_RGBtoHSL('L', lpp
->lpcc
->rgbResult
);
944 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
945 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_H
, lpp
->h
, TRUE
);
946 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_S
, lpp
->s
, TRUE
);
947 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_L
, lpp
->l
, TRUE
);
948 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_R
, r
, TRUE
);
949 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_G
, g
, TRUE
);
950 SetDlgItemInt(hDlg
, IDC_COLOR_EDIT_B
, b
, TRUE
);
953 CC_PaintTriangle(lpp
);
959 /***********************************************************************
960 * CC_WMCommand [internal]
962 static LRESULT
CC_WMCommand(CCPRIV
*lpp
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
969 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam
, lParam
);
970 switch (LOWORD(wParam
))
972 case IDC_COLOR_EDIT_R
: /* edit notify RGB */
973 case IDC_COLOR_EDIT_G
:
974 case IDC_COLOR_EDIT_B
:
975 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
977 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
978 r
= GetRValue(lpp
->lpcc
->rgbResult
);
979 g
= GetGValue(lpp
->lpcc
->rgbResult
);
980 b
= GetBValue(lpp
->lpcc
->rgbResult
);
982 switch (LOWORD(wParam
))
984 case IDC_COLOR_EDIT_R
: if ((xx
= (i
!= r
))) r
= i
; break;
985 case IDC_COLOR_EDIT_G
: if ((xx
= (i
!= g
))) g
= i
; break;
986 case IDC_COLOR_EDIT_B
: if ((xx
= (i
!= b
))) b
= i
; break;
988 if (xx
) /* something has changed */
990 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
991 CC_PaintSelectedColor(lpp
);
992 lpp
->h
= CC_RGBtoHSL('H', lpp
->lpcc
->rgbResult
);
993 lpp
->s
= CC_RGBtoHSL('S', lpp
->lpcc
->rgbResult
);
994 lpp
->l
= CC_RGBtoHSL('L', lpp
->lpcc
->rgbResult
);
997 CC_PaintTriangle(lpp
);
1002 case IDC_COLOR_EDIT_H
: /* edit notify HSL */
1003 case IDC_COLOR_EDIT_S
:
1004 case IDC_COLOR_EDIT_L
:
1005 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
1007 i
= CC_CheckDigitsInEdit(hwndCtl
, LOWORD(wParam
) == IDC_COLOR_EDIT_H
? 239 : 240);
1009 switch (LOWORD(wParam
))
1011 case IDC_COLOR_EDIT_H
: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
1012 case IDC_COLOR_EDIT_S
: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
1013 case IDC_COLOR_EDIT_L
: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
1015 if (xx
) /* something has changed */
1017 lpp
->lpcc
->rgbResult
= CC_HSLtoRGB(lpp
->h
, lpp
->s
, lpp
->l
);
1018 CC_PaintSelectedColor(lpp
);
1021 CC_PaintTriangle(lpp
);
1026 case IDC_COLOR_DEFINE
:
1027 CC_SwitchToFullSize(lpp
, &lpp
->fullsize
);
1028 SetFocus( GetDlgItem(lpp
->hwndSelf
, IDC_COLOR_EDIT_H
));
1031 case IDC_COLOR_ADD
: /* add colors ... column by column */
1032 cr
= lpp
->lpcc
->lpCustColors
;
1033 cr
[(lpp
->nextuserdef
% 2) * 8 + lpp
->nextuserdef
/ 2] = lpp
->lpcc
->rgbResult
;
1034 if (++lpp
->nextuserdef
== 16)
1035 lpp
->nextuserdef
= 0;
1036 CC_PaintUserColorArray(lpp
, 2, 8);
1039 case IDC_COLOR_RES
: /* resulting color */
1040 hdc
= GetDC(lpp
->hwndSelf
);
1041 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1042 ReleaseDC(lpp
->hwndSelf
, hdc
);
1044 CC_PaintSelectedColor(lpp
);
1045 lpp
->h
= CC_RGBtoHSL('H', lpp
->lpcc
->rgbResult
);
1046 lpp
->s
= CC_RGBtoHSL('S', lpp
->lpcc
->rgbResult
);
1047 lpp
->l
= CC_RGBtoHSL('L', lpp
->lpcc
->rgbResult
);
1050 CC_PaintTriangle(lpp
);
1053 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1054 i
= RegisterWindowMessageA(HELPMSGSTRINGA
);
1055 if (lpp
->lpcc
->hwndOwner
)
1056 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1057 if ( CC_HookCallChk(lpp
->lpcc
))
1058 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, lpp
->hwndSelf
,
1059 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1063 cokmsg
= RegisterWindowMessageA(COLOROKSTRINGA
);
1064 if (lpp
->lpcc
->hwndOwner
)
1065 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1066 break; /* do NOT close */
1067 EndDialog(lpp
->hwndSelf
, 1) ;
1071 EndDialog(lpp
->hwndSelf
, 0) ;
1078 /***********************************************************************
1079 * CC_WMPaint [internal]
1081 static LRESULT
CC_WMPaint( CCPRIV
*lpp
)
1085 BeginPaint(lpp
->hwndSelf
, &ps
);
1086 /* we have to paint dialog children except text and buttons */
1087 CC_PaintPredefColorArray(lpp
, 6, 8);
1088 CC_PaintUserColorArray(lpp
, 2, 8);
1089 CC_PaintLumBar(lpp
);
1090 CC_PaintTriangle(lpp
);
1091 CC_PaintSelectedColor(lpp
);
1092 CC_PaintColorGraph(lpp
);
1094 EndPaint(lpp
->hwndSelf
, &ps
);
1099 /***********************************************************************
1100 * CC_WMLButtonUp [internal]
1102 static LRESULT
CC_WMLButtonUp( CCPRIV
*infoPtr
)
1104 if (infoPtr
->capturedGraph
)
1106 infoPtr
->capturedGraph
= 0;
1108 CC_PaintCross(infoPtr
);
1114 /***********************************************************************
1115 * CC_WMMouseMove [internal]
1117 static LRESULT
CC_WMMouseMove( CCPRIV
*infoPtr
, LPARAM lParam
)
1119 if (infoPtr
->capturedGraph
)
1121 int *ptrh
= NULL
, *ptrs
= &infoPtr
->l
;
1122 if (infoPtr
->capturedGraph
== IDC_COLOR_GRAPH
)
1127 if (CC_MouseCheckColorGraph( infoPtr
->hwndSelf
, infoPtr
->capturedGraph
, ptrh
, ptrs
, lParam
))
1129 infoPtr
->lpcc
->rgbResult
= CC_HSLtoRGB(infoPtr
->h
, infoPtr
->s
, infoPtr
->l
);
1130 CC_EditSetRGB(infoPtr
);
1131 CC_EditSetHSL(infoPtr
);
1132 CC_PaintCross(infoPtr
);
1133 CC_PaintTriangle(infoPtr
);
1134 CC_PaintSelectedColor(infoPtr
);
1139 infoPtr
->capturedGraph
= 0;
1146 /***********************************************************************
1147 * CC_WMLButtonDown [internal]
1149 static LRESULT
CC_WMLButtonDown( CCPRIV
*infoPtr
, LPARAM lParam
)
1153 if (CC_MouseCheckPredefColorArray(infoPtr
, 6, 8, lParam
))
1156 if (CC_MouseCheckUserColorArray(infoPtr
, 2, 8, lParam
))
1159 if (CC_MouseCheckColorGraph(infoPtr
->hwndSelf
, IDC_COLOR_GRAPH
, &infoPtr
->h
, &infoPtr
->s
, lParam
))
1162 infoPtr
->capturedGraph
= IDC_COLOR_GRAPH
;
1165 if (CC_MouseCheckColorGraph(infoPtr
->hwndSelf
, IDC_COLOR_LUMBAR
, NULL
, &infoPtr
->l
, lParam
))
1168 infoPtr
->capturedGraph
= IDC_COLOR_LUMBAR
;
1172 SetCapture(infoPtr
->hwndSelf
);
1173 infoPtr
->lpcc
->rgbResult
= CC_HSLtoRGB(infoPtr
->h
, infoPtr
->s
, infoPtr
->l
);
1177 infoPtr
->h
= CC_RGBtoHSL('H', infoPtr
->lpcc
->rgbResult
);
1178 infoPtr
->s
= CC_RGBtoHSL('S', infoPtr
->lpcc
->rgbResult
);
1179 infoPtr
->l
= CC_RGBtoHSL('L', infoPtr
->lpcc
->rgbResult
);
1183 CC_EditSetRGB(infoPtr
);
1184 CC_EditSetHSL(infoPtr
);
1185 CC_PaintCross(infoPtr
);
1186 CC_PaintTriangle(infoPtr
);
1187 CC_PaintSelectedColor(infoPtr
);
1193 /***********************************************************************
1194 * ColorDlgProc32 [internal]
1197 static INT_PTR CALLBACK
ColorDlgProc( HWND hDlg
, UINT message
,
1198 WPARAM wParam
, LPARAM lParam
)
1202 CCPRIV
*lpp
= GetPropW( hDlg
, szColourDialogProp
);
1204 if (message
!= WM_INITDIALOG
)
1209 if (CC_HookCallChk(lpp
->lpcc
))
1210 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1215 /* FIXME: SetRGB message
1216 if (message && message == msetrgb)
1217 return HandleSetRGB(hDlg, lParam);
1223 return CC_WMInitDialog(hDlg
, wParam
, lParam
);
1225 DeleteDC(lpp
->hdcMem
);
1226 DeleteObject(lpp
->hbmMem
);
1227 HeapFree(GetProcessHeap(), 0, lpp
);
1228 RemovePropW( hDlg
, szColourDialogProp
);
1231 if (CC_WMCommand(lpp
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1235 if (CC_WMPaint(lpp
))
1238 case WM_LBUTTONDBLCLK
:
1239 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1243 if (CC_WMMouseMove(lpp
, lParam
))
1246 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1247 if (CC_WMLButtonUp(lpp
))
1250 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1251 if (CC_WMLButtonDown(lpp
, lParam
))
1258 /***********************************************************************
1259 * ChooseColorW (COMDLG32.@)
1261 * Create a color dialog box.
1264 * lpChCol [I/O] in: information to initialize the dialog box.
1265 * out: User's color selection
1268 * TRUE: Ok button clicked.
1269 * FALSE: Cancel button clicked, or error.
1271 BOOL WINAPI
ChooseColorW( CHOOSECOLORW
*lpChCol
)
1273 HANDLE hDlgTmpl
= 0;
1274 const void *template;
1276 TRACE("(%p)\n", lpChCol
);
1278 if (!lpChCol
) return FALSE
;
1280 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1282 if (!(template = LockResource(lpChCol
->hInstance
)))
1284 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1288 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1291 if (!(hResInfo
= FindResourceW((HINSTANCE
)lpChCol
->hInstance
,
1292 lpChCol
->lpTemplateName
,
1293 (LPWSTR
)RT_DIALOG
)))
1295 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1298 if (!(hDlgTmpl
= LoadResource((HINSTANCE
)lpChCol
->hInstance
, hResInfo
)) ||
1299 !(template = LockResource(hDlgTmpl
)))
1301 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1309 static const WCHAR wszCHOOSE_COLOR
[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1310 if (!(hResInfo
= FindResourceW(COMDLG32_hInstance
, wszCHOOSE_COLOR
, (LPWSTR
)RT_DIALOG
)))
1312 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1315 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1316 !(template = LockResource(hDlgTmpl
)))
1318 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1323 return DialogBoxIndirectParamW(COMDLG32_hInstance
, template, lpChCol
->hwndOwner
,
1324 ColorDlgProc
, (LPARAM
)lpChCol
);
1327 /***********************************************************************
1328 * ChooseColorA (COMDLG32.@)
1332 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1335 LPWSTR template_name
= NULL
;
1338 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1339 lpcc
->lStructSize
= sizeof(*lpcc
);
1340 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1341 lpcc
->hInstance
= lpChCol
->hInstance
;
1342 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1343 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1344 lpcc
->Flags
= lpChCol
->Flags
;
1345 lpcc
->lCustData
= lpChCol
->lCustData
;
1346 lpcc
->lpfnHook
= lpChCol
->lpfnHook
;
1347 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1348 if (!IS_INTRESOURCE(lpChCol
->lpTemplateName
)) {
1349 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, NULL
, 0);
1350 template_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1351 MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, template_name
, len
);
1352 lpcc
->lpTemplateName
= template_name
;
1354 lpcc
->lpTemplateName
= (LPCWSTR
)lpChCol
->lpTemplateName
;
1358 ret
= ChooseColorW(lpcc
);
1361 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1362 HeapFree(GetProcessHeap(), 0, template_name
);
1363 HeapFree(GetProcessHeap(), 0, lpcc
);