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 static 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 static 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 ? 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 static 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 static 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 static 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 static void CC_PaintTriangle( HWND hDlg
, int y
)
459 int w
= LOWORD(GetDialogBaseUnits()) / 2;
465 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
466 LPCCPRIV lpp
= 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 static 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
= 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
= 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
= 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 static void CC_EditSetRGB( HWND hDlg
, COLORREF cr
)
666 LPCCPRIV lpp
= 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 static void CC_EditSetHSL( HWND hDlg
, int h
, int s
, int l
)
689 LPCCPRIV lpp
= 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 static void CC_SwitchToFullSize( HWND hDlg
, COLORREF result
, LPCRECT lprect
)
711 LPCCPRIV lpp
= 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
= 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 static 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
= 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 static BOOL
CC_HookCallChk( const CHOOSECOLORW
*lpcc
)
841 if(lpcc
->Flags
& CC_ENABLEHOOK
)
847 /***********************************************************************
848 * CC_WMInitDialog [internal]
850 static LRESULT
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 static LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
964 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
966 TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam
, lParam
);
967 switch (LOWORD(wParam
))
969 case 0x2c2: /* edit notify RGB */
972 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
974 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
975 r
= GetRValue(lpp
->lpcc
->rgbResult
);
976 g
= GetGValue(lpp
->lpcc
->rgbResult
);
977 b
= GetBValue(lpp
->lpcc
->rgbResult
);
979 switch (LOWORD(wParam
))
981 case 0x2c2: if ((xx
= (i
!= r
))) r
= i
; break;
982 case 0x2c3: if ((xx
= (i
!= g
))) g
= i
; break;
983 case 0x2c4: if ((xx
= (i
!= b
))) b
= i
; break;
985 if (xx
) /* something has changed */
987 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
988 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
989 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
990 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
991 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
992 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
993 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
994 CC_PaintTriangle(hDlg
, lpp
->l
);
999 case 0x2bf: /* edit notify HSL */
1002 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
1004 i
= CC_CheckDigitsInEdit(hwndCtl
, LOWORD(wParam
) == 0x2bf ? 239:240);
1006 switch (LOWORD(wParam
))
1008 case 0x2bf: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
1009 case 0x2c0: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
1010 case 0x2c1: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
1012 if (xx
) /* something has changed */
1014 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1015 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1016 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1017 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1018 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1019 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1020 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1021 CC_PaintTriangle(hDlg
, lpp
->l
);
1027 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1028 SetFocus( GetDlgItem(hDlg
, 0x2bf));
1031 case 0x2c8: /* 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(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1039 case 0x2c9: /* resulting color */
1041 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1042 ReleaseDC(hDlg
, hdc
);
1043 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1044 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1045 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1046 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1047 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1048 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1049 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1050 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1051 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
1052 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1053 CC_PaintTriangle(hDlg
, lpp
->l
);
1056 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1057 i
= RegisterWindowMessageA(HELPMSGSTRINGA
);
1058 if (lpp
->lpcc
->hwndOwner
)
1059 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1060 if ( CC_HookCallChk(lpp
->lpcc
))
1061 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, hDlg
,
1062 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1066 cokmsg
= RegisterWindowMessageA(COLOROKSTRINGA
);
1067 if (lpp
->lpcc
->hwndOwner
)
1068 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1069 break; /* do NOT close */
1070 EndDialog(hDlg
, 1) ;
1074 EndDialog(hDlg
, 0) ;
1081 /***********************************************************************
1082 * CC_WMPaint [internal]
1084 static LRESULT
CC_WMPaint( HWND hDlg
)
1087 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
1089 BeginPaint(hDlg
, &ps
);
1090 /* we have to paint dialog children except text and buttons */
1091 CC_PaintPredefColorArray(hDlg
, 6, 8);
1092 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1093 CC_PaintLumBar(hDlg
, lpp
->h
, lpp
->s
);
1094 CC_PaintTriangle(hDlg
, lpp
->l
);
1095 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1096 CC_PaintColorGraph(hDlg
);
1097 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1098 EndPaint(hDlg
, &ps
);
1103 /***********************************************************************
1104 * CC_WMLButtonUp [internal]
1106 static LRESULT
CC_WMLButtonUp( HWND hDlg
)
1108 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
1110 if (lpp
->capturedGraph
)
1112 lpp
->capturedGraph
= 0;
1114 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1120 /***********************************************************************
1121 * CC_WMMouseMove [internal]
1123 static LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1125 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
1128 if (lpp
->capturedGraph
)
1130 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1131 if (lpp
->capturedGraph
== 0x2c6)
1136 if (CC_MouseCheckColorGraph( hDlg
, lpp
->capturedGraph
, ptrh
, ptrs
, lParam
))
1138 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1139 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1140 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1141 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1142 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1143 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1144 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1145 CC_PaintTriangle(hDlg
, lpp
->l
);
1146 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1151 lpp
->capturedGraph
= 0;
1158 /***********************************************************************
1159 * CC_WMLButtonDown [internal]
1161 static LRESULT
CC_WMLButtonDown( HWND hDlg
, LPARAM lParam
)
1163 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
1167 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1170 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1173 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1176 lpp
->capturedGraph
= 0x2c6;
1179 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1182 lpp
->capturedGraph
= 0x2be;
1187 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1188 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1189 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1190 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1194 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1195 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1196 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1197 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1198 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1199 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1203 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1204 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1205 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1206 CC_PaintTriangle(hDlg
, lpp
->l
);
1207 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1213 /***********************************************************************
1214 * ColorDlgProc32 [internal]
1217 static INT_PTR CALLBACK
ColorDlgProc( HWND hDlg
, UINT message
,
1218 WPARAM wParam
, LPARAM lParam
)
1222 LPCCPRIV lpp
= GetPropW( hDlg
, szColourDialogProp
);
1224 if (message
!= WM_INITDIALOG
)
1229 if (CC_HookCallChk(lpp
->lpcc
))
1230 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1235 /* FIXME: SetRGB message
1236 if (message && message == msetrgb)
1237 return HandleSetRGB(hDlg, lParam);
1243 return CC_WMInitDialog(hDlg
, wParam
, lParam
);
1245 DeleteDC(lpp
->hdcMem
);
1246 DeleteObject(lpp
->hbmMem
);
1247 HeapFree(GetProcessHeap(), 0, lpp
);
1248 RemovePropW( hDlg
, szColourDialogProp
);
1251 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1255 if (CC_WMPaint(hDlg
))
1258 case WM_LBUTTONDBLCLK
:
1259 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1263 if (CC_WMMouseMove(hDlg
, lParam
))
1266 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1267 if (CC_WMLButtonUp(hDlg
))
1270 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1271 if (CC_WMLButtonDown(hDlg
, lParam
))
1278 /***********************************************************************
1279 * ChooseColorW (COMDLG32.@)
1281 * Create a color dialog box.
1284 * lpChCol [I/O] in: information to initialize the dialog box.
1285 * out: User's color selection
1288 * TRUE: Ok button clicked.
1289 * FALSE: Cancel button clicked, or error.
1291 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1293 HANDLE hDlgTmpl
= 0;
1297 TRACE("ChooseColor\n");
1298 if (!lpChCol
) return FALSE
;
1300 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1302 if (!(template = LockResource(lpChCol
->hInstance
)))
1304 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1308 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1311 if (!(hResInfo
= FindResourceW((HINSTANCE
)lpChCol
->hInstance
,
1312 lpChCol
->lpTemplateName
,
1313 (LPWSTR
)RT_DIALOG
)))
1315 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1318 if (!(hDlgTmpl
= LoadResource((HINSTANCE
)lpChCol
->hInstance
, hResInfo
)) ||
1319 !(template = LockResource(hDlgTmpl
)))
1321 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1329 static const WCHAR wszCHOOSE_COLOR
[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1330 if (!(hResInfo
= FindResourceW(COMDLG32_hInstance
, wszCHOOSE_COLOR
, (LPWSTR
)RT_DIALOG
)))
1332 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1335 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1336 !(template = LockResource(hDlgTmpl
)))
1338 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1343 bRet
= DialogBoxIndirectParamW(COMDLG32_hInstance
, template, lpChCol
->hwndOwner
,
1344 ColorDlgProc
, (LPARAM
)lpChCol
);
1348 /***********************************************************************
1349 * ChooseColorA (COMDLG32.@)
1353 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1356 LPWSTR template_name
= NULL
;
1359 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1360 lpcc
->lStructSize
= sizeof(*lpcc
);
1361 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1362 lpcc
->hInstance
= lpChCol
->hInstance
;
1363 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1364 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1365 lpcc
->Flags
= lpChCol
->Flags
;
1366 lpcc
->lCustData
= lpChCol
->lCustData
;
1367 lpcc
->lpfnHook
= lpChCol
->lpfnHook
;
1368 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1369 if (!IS_INTRESOURCE(lpChCol
->lpTemplateName
)) {
1370 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, NULL
, 0);
1371 template_name
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1372 MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, template_name
, len
);
1373 lpcc
->lpTemplateName
= template_name
;
1375 lpcc
->lpTemplateName
= (LPCWSTR
)lpChCol
->lpTemplateName
;
1379 ret
= ChooseColorW(lpcc
);
1382 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1383 HeapFree(GetProcessHeap(), 0, template_name
);
1384 HeapFree(GetProcessHeap(), 0, lpcc
);