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/saturation 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
);
446 DeleteObject(hBrush
);
448 ReleaseDC(hwnd
, hdc
);
452 /***********************************************************************
453 * CC_PaintTriangle [internal]
455 void CC_PaintTriangle( HWND hDlg
, int y
)
459 int w
= LOWORD(GetDialogBaseUnits()) / 2;
465 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
466 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
468 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6))) /* if full size */
470 GetClientRect(hwnd
, &rect
);
471 height
= rect
.bottom
;
473 points
[0].y
= rect
.top
;
474 points
[0].x
= rect
.right
; /* | /| */
475 ClientToScreen(hwnd
, points
); /* | / | */
476 ScreenToClient(hDlg
, points
); /* |< | */
477 oben
= points
[0].y
; /* | \ | */
479 temp
= (long)height
* (long)y
;
481 points
[0].y
= oben
+ height
- temp
/ (long)MAXVERT
;
482 points
[1].y
= points
[0].y
+ w
;
483 points
[2].y
= points
[0].y
- w
;
484 points
[2].x
= points
[1].x
= points
[0].x
+ w
;
486 hbr
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
487 if (!hbr
) hbr
= GetSysColorBrush(COLOR_BTNFACE
);
488 FillRect(hDC
, &lpp
->old3angle
, hbr
);
489 lpp
->old3angle
.left
= points
[0].x
;
490 lpp
->old3angle
.right
= points
[1].x
+ 1;
491 lpp
->old3angle
.top
= points
[2].y
- 1;
492 lpp
->old3angle
.bottom
= points
[1].y
+ 1;
494 hbr
= SelectObject(hDC
, GetStockObject(BLACK_BRUSH
));
495 Polygon(hDC
, points
, 3);
496 SelectObject(hDC
, hbr
);
498 ReleaseDC(hDlg
, hDC
);
503 /***********************************************************************
504 * CC_PaintCross [internal]
506 void CC_PaintCross( HWND hDlg
, int x
, int y
)
509 int w
= GetDialogBaseUnits() - 1;
510 int wc
= GetDialogBaseUnits() * 3 / 4;
511 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
512 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
517 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
519 GetClientRect(hwnd
, &rect
);
521 SelectClipRgn( hDC
, CreateRectRgnIndirect(&rect
));
523 point
.x
= ((long)rect
.right
* (long)x
) / (long)MAXHORI
;
524 point
.y
= rect
.bottom
- ((long)rect
.bottom
* (long)y
) / (long)MAXVERT
;
525 if ( lpp
->oldcross
.left
!= lpp
->oldcross
.right
)
526 BitBlt(hDC
, lpp
->oldcross
.left
, lpp
->oldcross
.top
,
527 lpp
->oldcross
.right
- lpp
->oldcross
.left
,
528 lpp
->oldcross
.bottom
- lpp
->oldcross
.top
,
529 lpp
->hdcMem
, lpp
->oldcross
.left
, lpp
->oldcross
.top
, SRCCOPY
);
530 lpp
->oldcross
.left
= point
.x
- w
- 1;
531 lpp
->oldcross
.right
= point
.x
+ w
+ 1;
532 lpp
->oldcross
.top
= point
.y
- w
- 1;
533 lpp
->oldcross
.bottom
= point
.y
+ w
+ 1;
535 hPen
= CreatePen(PS_SOLID
, 3, 0x000000); /* -black- color */
536 hPen
= SelectObject(hDC
, hPen
);
537 MoveToEx(hDC
, point
.x
- w
, point
.y
, &p
);
538 LineTo(hDC
, point
.x
- wc
, point
.y
);
539 MoveToEx(hDC
, point
.x
+ wc
, point
.y
, &p
);
540 LineTo(hDC
, point
.x
+ w
, point
.y
);
541 MoveToEx(hDC
, point
.x
, point
.y
- w
, &p
);
542 LineTo(hDC
, point
.x
, point
.y
- wc
);
543 MoveToEx(hDC
, point
.x
, point
.y
+ wc
, &p
);
544 LineTo(hDC
, point
.x
, point
.y
+ w
);
545 DeleteObject( SelectObject(hDC
, hPen
));
547 ReleaseDC(hwnd
, hDC
);
556 /***********************************************************************
557 * CC_PrepareColorGraph [internal]
559 static void CC_PrepareColorGraph( HWND hDlg
)
561 int sdif
, hdif
, xdif
, ydif
, r
, g
, b
, hue
, sat
;
562 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
563 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
567 HCURSOR hcursor
= SetCursor( LoadCursorW(0, (LPCWSTR
)IDC_WAIT
) );
569 GetClientRect(hwnd
, &client
);
571 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
572 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
, client
.right
, client
.bottom
);
573 SelectObject(lpp
->hdcMem
, lpp
->hbmMem
);
575 xdif
= client
.right
/ XSTEPS
;
576 ydif
= client
.bottom
/ YSTEPS
+1;
579 for (rect
.left
= hue
= 0; hue
< 239 + hdif
; hue
+= hdif
)
581 rect
.right
= rect
.left
+ xdif
;
582 rect
.bottom
= client
.bottom
;
583 for(sat
= 0; sat
< 240 + sdif
; sat
+= sdif
)
585 rect
.top
= rect
.bottom
- ydif
;
586 r
= CC_HSLtoRGB('R', hue
, sat
, 120);
587 g
= CC_HSLtoRGB('G', hue
, sat
, 120);
588 b
= CC_HSLtoRGB('B', hue
, sat
, 120);
589 hbrush
= CreateSolidBrush( RGB(r
, g
, b
));
590 FillRect(lpp
->hdcMem
, &rect
, hbrush
);
591 DeleteObject(hbrush
);
592 rect
.bottom
= rect
.top
;
594 rect
.left
= rect
.right
;
596 ReleaseDC(hwnd
, hdc
);
600 /***********************************************************************
601 * CC_PaintColorGraph [internal]
603 static void CC_PaintColorGraph( HWND hDlg
)
605 HWND hwnd
= GetDlgItem( hDlg
, 0x2c6 );
606 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
609 if (IsWindowVisible(hwnd
)) /* if full size */
612 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
615 GetClientRect(hwnd
, &rect
);
617 BitBlt(hDC
, 0, 0, rect
.right
, rect
.bottom
, lpp
->hdcMem
, 0, 0, SRCCOPY
);
619 WARN("choose color: hdcMem is not defined\n");
620 ReleaseDC(hwnd
, hDC
);
624 /***********************************************************************
625 * CC_PaintLumBar [internal]
627 static void CC_PaintLumBar( HWND hDlg
, int hue
, int sat
)
629 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
631 int lum
, ldif
, ydif
, r
, g
, b
;
635 if (IsWindowVisible(hwnd
))
638 GetClientRect(hwnd
, &client
);
642 ydif
= client
.bottom
/ YSTEPS
+1;
643 for (lum
= 0; lum
< 240 + ldif
; lum
+= ldif
)
645 rect
.top
= max(0, rect
.bottom
- ydif
);
646 r
= CC_HSLtoRGB('R', hue
, sat
, lum
);
647 g
= CC_HSLtoRGB('G', hue
, sat
, lum
);
648 b
= CC_HSLtoRGB('B', hue
, sat
, lum
);
649 hbrush
= CreateSolidBrush( RGB(r
, g
, b
) );
650 FillRect(hDC
, &rect
, hbrush
);
651 DeleteObject(hbrush
);
652 rect
.bottom
= rect
.top
;
654 GetClientRect(hwnd
, &rect
);
655 DrawEdge(hDC
, &rect
, BDR_SUNKENOUTER
, BF_RECT
);
656 ReleaseDC(hwnd
, hDC
);
660 /***********************************************************************
661 * CC_EditSetRGB [internal]
663 void CC_EditSetRGB( HWND hDlg
, COLORREF cr
)
666 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
667 int r
= GetRValue(cr
);
668 int g
= GetGValue(cr
);
669 int b
= GetBValue(cr
);
670 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
672 lpp
->updating
= TRUE
;
673 sprintf(buffer
, "%d", r
);
674 SetWindowTextA( GetDlgItem(hDlg
, 0x2c2), buffer
);
675 sprintf(buffer
, "%d", g
);
676 SetWindowTextA( GetDlgItem(hDlg
, 0x2c3), buffer
);
677 sprintf( buffer
, "%d", b
);
678 SetWindowTextA( GetDlgItem(hDlg
, 0x2c4),buffer
);
679 lpp
->updating
= FALSE
;
683 /***********************************************************************
684 * CC_EditSetHSL [internal]
686 void CC_EditSetHSL( HWND hDlg
, int h
, int s
, int l
)
689 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
691 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
693 lpp
->updating
= TRUE
;
694 sprintf(buffer
, "%d", h
);
695 SetWindowTextA( GetDlgItem(hDlg
, 0x2bf), buffer
);
696 sprintf(buffer
, "%d", s
);
697 SetWindowTextA( GetDlgItem(hDlg
, 0x2c0), buffer
);
698 sprintf(buffer
, "%d", l
);
699 SetWindowTextA( GetDlgItem(hDlg
, 0x2c1), buffer
);
700 lpp
->updating
= FALSE
;
702 CC_PaintLumBar(hDlg
, h
, s
);
705 /***********************************************************************
706 * CC_SwitchToFullSize [internal]
708 void CC_SwitchToFullSize( HWND hDlg
, COLORREF result
, LPCRECT lprect
)
711 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
713 EnableWindow( GetDlgItem(hDlg
, 0x2cf), FALSE
);
714 CC_PrepareColorGraph(hDlg
);
715 for (i
= 0x2bf; i
< 0x2c5; i
++)
716 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
717 for (i
= 0x2d3; i
< 0x2d9; i
++)
718 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
719 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_SHOW
);
720 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_SHOW
);
721 ShowWindow( GetDlgItem(hDlg
, 1090), SW_SHOW
);
724 SetWindowPos(hDlg
, 0, 0, 0, lprect
->right
-lprect
->left
,
725 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
727 ShowWindow( GetDlgItem(hDlg
, 0x2be), SW_SHOW
);
728 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_SHOW
);
730 CC_EditSetRGB(hDlg
, result
);
731 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
732 ShowWindow( GetDlgItem( hDlg
, 0x2c6), SW_SHOW
);
733 UpdateWindow( GetDlgItem(hDlg
, 0x2c6) );
736 /***********************************************************************
737 * CC_PaintPredefColorArray [internal]
738 * Paints the default standard 48 colors
740 static void CC_PaintPredefColorArray( HWND hDlg
, int rows
, int cols
)
742 HWND hwnd
= GetDlgItem(hDlg
, 0x2d0);
743 RECT rect
, blockrect
;
747 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
749 GetClientRect(hwnd
, &rect
);
750 dx
= rect
.right
/ cols
;
751 dy
= rect
.bottom
/ rows
;
755 GetClientRect(hwnd
, &rect
);
756 hBrush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
757 if (!hBrush
) hBrush
= GetSysColorBrush(COLOR_BTNFACE
);
758 FillRect(hdc
, &rect
, hBrush
);
759 for ( j
= 0; j
< rows
; j
++ )
761 for ( i
= 0; i
< cols
; i
++ )
763 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
766 blockrect
.left
= rect
.left
;
767 blockrect
.top
= rect
.top
;
768 blockrect
.right
= rect
.left
+ dx
- DISTANCE
;
769 blockrect
.bottom
= rect
.top
+ dy
- DISTANCE
;
770 FillRect(hdc
, &blockrect
, hBrush
);
771 DrawEdge(hdc
, &blockrect
, BDR_SUNKEN
, BF_RECT
);
772 DeleteObject(hBrush
);
779 ReleaseDC(hwnd
, hdc
);
780 if (lpp
->hwndFocus
== hwnd
)
781 CC_DrawCurrentFocusRect(lpp
);
783 /***********************************************************************
784 * CC_PaintUserColorArray [internal]
785 * Paint the 16 user-selected colors
787 void CC_PaintUserColorArray( HWND hDlg
, int rows
, int cols
, const COLORREF
*lpcr
)
789 HWND hwnd
= GetDlgItem(hDlg
, 0x2d1);
790 RECT rect
, blockrect
;
794 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
796 GetClientRect(hwnd
, &rect
);
798 dx
= rect
.right
/ cols
;
799 dy
= rect
.bottom
/ rows
;
805 hBrush
= (HBRUSH
)GetClassLongPtrW( hwnd
, GCLP_HBRBACKGROUND
);
806 if (!hBrush
) hBrush
= GetSysColorBrush(COLOR_BTNFACE
);
807 FillRect( hdc
, &rect
, hBrush
);
808 for (j
= 0; j
< rows
; j
++)
810 for (i
= 0; i
< cols
; i
++)
812 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
815 blockrect
.left
= rect
.left
;
816 blockrect
.top
= rect
.top
;
817 blockrect
.right
= rect
.left
+ dx
- DISTANCE
;
818 blockrect
.bottom
= rect
.top
+ dy
- DISTANCE
;
819 FillRect(hdc
, &blockrect
, hBrush
);
820 DrawEdge(hdc
, &blockrect
, BDR_SUNKEN
, BF_RECT
);
821 DeleteObject(hBrush
);
828 ReleaseDC(hwnd
, hdc
);
830 if (lpp
->hwndFocus
== hwnd
)
831 CC_DrawCurrentFocusRect(lpp
);
835 /***********************************************************************
836 * CC_HookCallChk [internal]
838 BOOL
CC_HookCallChk( const CHOOSECOLORW
*lpcc
)
841 if(lpcc
->Flags
& CC_ENABLEHOOK
)
847 /***********************************************************************
848 * CC_WMInitDialog [internal]
850 static LONG
CC_WMInitDialog( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
859 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
860 lpp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct CCPRIVATE
) );
862 lpp
->lpcc
= (LPCHOOSECOLORW
) lParam
;
863 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLORW
) )
865 HeapFree(GetProcessHeap(), 0, lpp
);
866 EndDialog (hDlg
, 0) ;
870 SetPropW( hDlg
, szColourDialogProp
, lpp
);
872 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
873 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
874 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRINGA
);
877 cpos
= MAKELONG(5,7); /* init */
878 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
880 for (i
= 0; i
< 6; i
++)
881 for (j
= 0; j
< 8; j
++)
882 if (predefcolors
[i
][j
] == lpp
->lpcc
->rgbResult
)
884 cpos
= MAKELONG(i
,j
);
889 /* FIXME: Draw_a_focus_rect & set_init_values */
892 GetWindowRect(hDlg
, &lpp
->fullsize
);
893 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
895 hwnd
= GetDlgItem(hDlg
, 0x2cf);
896 EnableWindow(hwnd
, FALSE
);
898 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
900 rect
= lpp
->fullsize
;
901 res
= rect
.bottom
- rect
.top
;
902 hwnd
= GetDlgItem(hDlg
, 0x2c6); /* cut at left border */
903 point
.x
= point
.y
= 0;
904 ClientToScreen(hwnd
, &point
);
905 ScreenToClient(hDlg
,&point
);
906 GetClientRect(hDlg
, &rect
);
907 point
.x
+= GetSystemMetrics(SM_CXDLGFRAME
);
908 SetWindowPos(hDlg
, 0, 0, 0, point
.x
, res
, SWP_NOMOVE
|SWP_NOZORDER
);
910 for (i
= 0x2bf; i
< 0x2c5; i
++)
911 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
912 for (i
= 0x2d3; i
< 0x2d9; i
++)
913 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
914 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_HIDE
);
915 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_HIDE
);
916 ShowWindow( GetDlgItem(hDlg
, 0x2c6), SW_HIDE
);
917 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_HIDE
);
918 ShowWindow( GetDlgItem(hDlg
, 1090 ), SW_HIDE
);
921 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, NULL
);
923 for (i
= 0x2bf; i
< 0x2c5; i
++)
924 SendMessageA( GetDlgItem(hDlg
, i
), EM_LIMITTEXT
, 3, 0); /* max 3 digits: xyz */
925 if (CC_HookCallChk(lpp
->lpcc
))
927 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
930 /* Set the initial values of the color chooser dialog */
931 r
= GetRValue(lpp
->lpcc
->rgbResult
);
932 g
= GetGValue(lpp
->lpcc
->rgbResult
);
933 b
= GetBValue(lpp
->lpcc
->rgbResult
);
935 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
936 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
937 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
938 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
940 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
941 SetDlgItemInt(hDlg
, 703, lpp
->h
, TRUE
);
942 SetDlgItemInt(hDlg
, 704, lpp
->s
, TRUE
);
943 SetDlgItemInt(hDlg
, 705, lpp
->l
, TRUE
);
944 SetDlgItemInt(hDlg
, 706, r
, TRUE
);
945 SetDlgItemInt(hDlg
, 707, g
, TRUE
);
946 SetDlgItemInt(hDlg
, 708, b
, TRUE
);
948 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
949 CC_PaintTriangle(hDlg
, lpp
->l
);
955 /***********************************************************************
956 * CC_WMCommand [internal]
958 LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
964 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
965 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam
, lParam
);
966 switch (LOWORD(wParam
))
968 case 0x2c2: /* edit notify RGB */
971 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
973 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
974 r
= GetRValue(lpp
->lpcc
->rgbResult
);
975 g
= GetGValue(lpp
->lpcc
->rgbResult
);
976 b
= GetBValue(lpp
->lpcc
->rgbResult
);
978 switch (LOWORD(wParam
))
980 case 0x2c2: if ((xx
= (i
!= r
))) r
= i
; break;
981 case 0x2c3: if ((xx
= (i
!= g
))) g
= i
; break;
982 case 0x2c4: if ((xx
= (i
!= b
))) b
= i
; break;
984 if (xx
) /* something has changed */
986 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
987 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
988 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
989 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
990 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
991 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
992 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
993 CC_PaintTriangle(hDlg
, lpp
->l
);
998 case 0x2bf: /* edit notify HSL */
1001 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
1003 i
= CC_CheckDigitsInEdit(hwndCtl
, LOWORD(wParam
) == 0x2bf ? 239:240);
1005 switch (LOWORD(wParam
))
1007 case 0x2bf: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
1008 case 0x2c0: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
1009 case 0x2c1: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
1011 if (xx
) /* something has changed */
1013 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1014 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1015 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1016 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1017 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1018 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1019 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1020 CC_PaintTriangle(hDlg
, lpp
->l
);
1026 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1027 SetFocus( GetDlgItem(hDlg
, 0x2bf));
1030 case 0x2c8: /* add colors ... column by column */
1031 cr
= lpp
->lpcc
->lpCustColors
;
1032 cr
[(lpp
->nextuserdef
% 2) * 8 + lpp
->nextuserdef
/ 2] = lpp
->lpcc
->rgbResult
;
1033 if (++lpp
->nextuserdef
== 16)
1034 lpp
->nextuserdef
= 0;
1035 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1038 case 0x2c9: /* resulting color */
1040 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1041 ReleaseDC(hDlg
, hdc
);
1042 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1043 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1044 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1045 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1046 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1047 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1048 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1049 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1050 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
1051 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1052 CC_PaintTriangle(hDlg
, lpp
->l
);
1055 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1056 i
= RegisterWindowMessageA(HELPMSGSTRINGA
);
1057 if (lpp
->lpcc
->hwndOwner
)
1058 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1059 if ( CC_HookCallChk(lpp
->lpcc
))
1060 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, hDlg
,
1061 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1065 cokmsg
= RegisterWindowMessageA(COLOROKSTRINGA
);
1066 if (lpp
->lpcc
->hwndOwner
)
1067 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1068 break; /* do NOT close */
1069 EndDialog(hDlg
, 1) ;
1073 EndDialog(hDlg
, 0) ;
1080 /***********************************************************************
1081 * CC_WMPaint [internal]
1083 LRESULT
CC_WMPaint( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1086 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1088 BeginPaint(hDlg
, &ps
);
1089 /* we have to paint dialog children except text and buttons */
1090 CC_PaintPredefColorArray(hDlg
, 6, 8);
1091 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1092 CC_PaintLumBar(hDlg
, lpp
->h
, lpp
->s
);
1093 CC_PaintTriangle(hDlg
, lpp
->l
);
1094 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1095 CC_PaintColorGraph(hDlg
);
1096 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1097 EndPaint(hDlg
, &ps
);
1102 /***********************************************************************
1103 * CC_WMLButtonUp [internal]
1105 LRESULT
CC_WMLButtonUp( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1107 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1108 if (lpp
->capturedGraph
)
1110 lpp
->capturedGraph
= 0;
1112 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1118 /***********************************************************************
1119 * CC_WMMouseMove [internal]
1121 LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1123 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1126 if (lpp
->capturedGraph
)
1128 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1129 if (lpp
->capturedGraph
== 0x2c6)
1134 if (CC_MouseCheckColorGraph( hDlg
, lpp
->capturedGraph
, ptrh
, ptrs
, lParam
))
1136 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1137 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1138 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1139 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1140 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1141 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1142 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1143 CC_PaintTriangle(hDlg
, lpp
->l
);
1144 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1149 lpp
->capturedGraph
= 0;
1156 /***********************************************************************
1157 * CC_WMLButtonDown [internal]
1159 LRESULT
CC_WMLButtonDown( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1161 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1165 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1168 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1171 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1174 lpp
->capturedGraph
= 0x2c6;
1177 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1180 lpp
->capturedGraph
= 0x2be;
1185 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1186 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1187 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1188 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1192 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1193 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1194 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1195 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1196 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1197 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1201 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1202 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1203 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1204 CC_PaintTriangle(hDlg
, lpp
->l
);
1205 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1211 /***********************************************************************
1212 * ColorDlgProc32 [internal]
1215 static INT_PTR CALLBACK
ColorDlgProc( HWND hDlg
, UINT message
,
1216 WPARAM wParam
, LPARAM lParam
)
1220 LPCCPRIV lpp
= (LPCCPRIV
) GetPropW( hDlg
, szColourDialogProp
);
1221 if (message
!= WM_INITDIALOG
)
1226 if (CC_HookCallChk(lpp
->lpcc
))
1227 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1232 /* FIXME: SetRGB message
1233 if (message && message == msetrgb)
1234 return HandleSetRGB(hDlg, lParam);
1240 return CC_WMInitDialog(hDlg
, wParam
, lParam
);
1242 DeleteDC(lpp
->hdcMem
);
1243 DeleteObject(lpp
->hbmMem
);
1244 HeapFree(GetProcessHeap(), 0, lpp
);
1245 RemovePropW( hDlg
, szColourDialogProp
);
1248 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1252 if ( CC_WMPaint(hDlg
, wParam
, lParam
))
1255 case WM_LBUTTONDBLCLK
:
1256 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1260 if (CC_WMMouseMove(hDlg
, lParam
))
1263 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1264 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1267 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1268 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1275 /***********************************************************************
1276 * ChooseColorW (COMDLG32.@)
1278 * Create a color dialog box.
1281 * lpChCol [I/O] in: information to initialize the dialog box.
1282 * out: User's color selection
1285 * TRUE: Ok button clicked.
1286 * FALSE: Cancel button clicked, or error.
1288 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1290 HANDLE hDlgTmpl
= 0;
1294 TRACE("ChooseColor\n");
1295 if (!lpChCol
) return FALSE
;
1297 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1299 if (!(template = LockResource(lpChCol
->hInstance
)))
1301 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1305 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1308 if (!(hResInfo
= FindResourceW((HINSTANCE
)lpChCol
->hInstance
,
1309 lpChCol
->lpTemplateName
,
1310 (LPWSTR
)RT_DIALOG
)))
1312 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1315 if (!(hDlgTmpl
= LoadResource((HINSTANCE
)lpChCol
->hInstance
, hResInfo
)) ||
1316 !(template = LockResource(hDlgTmpl
)))
1318 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1326 static const WCHAR wszCHOOSE_COLOR
[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1327 if (!(hResInfo
= FindResourceW(COMDLG32_hInstance
, wszCHOOSE_COLOR
, (LPWSTR
)RT_DIALOG
)))
1329 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1332 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1333 !(template = LockResource(hDlgTmpl
)))
1335 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1340 bRet
= DialogBoxIndirectParamW(COMDLG32_hInstance
, template, lpChCol
->hwndOwner
,
1341 ColorDlgProc
, (LPARAM
)lpChCol
);
1345 /***********************************************************************
1346 * ChooseColorA (COMDLG32.@)
1350 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1353 LPWSTR template_name
= NULL
;
1356 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1357 lpcc
->lStructSize
= sizeof(*lpcc
);
1358 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1359 lpcc
->hInstance
= lpChCol
->hInstance
;
1360 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1361 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1362 lpcc
->Flags
= lpChCol
->Flags
;
1363 lpcc
->lCustData
= lpChCol
->lCustData
;
1364 lpcc
->lpfnHook
= lpChCol
->lpfnHook
;
1365 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1366 if (HIWORD(lpChCol
->lpTemplateName
)) {
1367 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, NULL
, 0);
1368 template_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1369 MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, template_name
, len
);
1370 lpcc
->lpTemplateName
= template_name
;
1372 lpcc
->lpTemplateName
= (LPCWSTR
)lpChCol
->lpTemplateName
;
1376 ret
= ChooseColorW(lpcc
);
1379 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1380 HeapFree(GetProcessHeap(), 0, template_name
);
1381 HeapFree(GetProcessHeap(), 0, lpcc
);