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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 */
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg
);
44 static LRESULT WINAPI
ColorDlgProc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
);
46 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = SLOWORD(lp); (p)->y = SHIWORD(lp); } while(0)
48 static const COLORREF predefcolors
[6][8]=
50 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
51 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
52 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
53 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
55 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
56 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
57 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
58 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
60 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
61 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
62 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
63 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
68 LPCHOOSECOLORW lpcc
; /* points to public known data structure */
69 LPCHOOSECOLOR16 lpcc16
; /* save the 16 bits pointer */
70 int nextuserdef
; /* next free place in user defined color array */
71 HDC hdcMem
; /* color graph used for BitBlt() */
72 HBITMAP hbmMem
; /* color graph bitmap */
73 RECT fullsize
; /* original dialog window size */
74 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
75 RECT old3angle
; /* last position of l-marker */
76 RECT oldcross
; /* last position of color/satuation marker */
77 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
80 int l
; /* for temporary storing of hue,sat,lum */
81 int capturedGraph
; /* control mouse captured */
82 RECT focusRect
; /* rectangle last focused item */
83 HWND hwndFocus
; /* handle last focused item */
86 #define LCCPRIV struct CCPRIVATE *
88 /***********************************************************************
89 * CC_HSLtoRGB [internal]
91 static int CC_HSLtoRGB(char c
, int hue
, int sat
, int lum
)
98 case 'R': if (hue
> 80) hue
-= 80; else hue
+= 160; break;
99 case 'G': if (hue
> 160) hue
-= 160; else hue
+= 80; break;
104 maxrgb
= (256 * min(120,lum
)) / 120; /* 0 .. 256 */
110 res
= (hue
- 80) * maxrgb
; /* 0...10240 */
111 res
/= 40; /* 0...256 */
118 res
= (240 - hue
) * maxrgb
;
121 res
= res
- maxrgb
/ 2; /* -128...128 */
124 res
= maxrgb
/ 2 + (sat
* res
) / 240; /* 0..256 */
127 if (lum
> 120 && res
< 256)
128 res
+= ((lum
- 120) * (256 - res
)) / 120;
130 return min(res
, 255);
133 /***********************************************************************
134 * CC_RGBtoHSL [internal]
136 static int CC_RGBtoHSL(char c
, int r
, int g
, int b
)
138 WORD maxi
, mini
, mmsum
, mmdif
, result
= 0;
152 case 'L': mmsum
*= 120; /* 0...61200=(255+255)*120 */
153 result
= mmsum
/ 255; /* 0...240 */
156 case 'S': if (!mmsum
)
159 if (!mini
|| maxi
== 255)
163 result
= mmdif
* 240; /* 0...61200=255*240 */
164 result
/= (mmsum
> 255 ? mmsum
= 510 - mmsum
: mmsum
); /* 0..255 */
168 case 'H': if (!mmdif
)
174 iresult
= 40 * (g
- b
); /* -10200 ... 10200 */
175 iresult
/= (int) mmdif
; /* -40 .. 40 */
177 iresult
+= 240; /* 0..40 and 200..240 */
182 iresult
= 40 * (b
- r
);
183 iresult
/= (int) mmdif
;
184 iresult
+= 80; /* 40 .. 120 */
189 iresult
= 40 * (r
- g
);
190 iresult
/= (int) mmdif
;
191 iresult
+= 160; /* 120 .. 200 */
197 return result
; /* is this integer arithmetic precise enough ? */
201 /***********************************************************************
202 * CC_DrawCurrentFocusRect [internal]
204 void CC_DrawCurrentFocusRect( LCCPRIV lpp
)
208 HDC hdc
= GetDC(lpp
->hwndFocus
);
209 DrawFocusRect(hdc
, &lpp
->focusRect
);
210 ReleaseDC(lpp
->hwndFocus
, hdc
);
214 /***********************************************************************
215 * CC_DrawFocusRect [internal]
217 void CC_DrawFocusRect( LCCPRIV lpp
, HWND hwnd
, int x
, int y
, int rows
, int cols
)
223 CC_DrawCurrentFocusRect(lpp
); /* remove current focus rect */
224 /* calculate new rect */
225 GetClientRect(hwnd
, &rect
);
226 dx
= (rect
.right
- rect
.left
) / cols
;
227 dy
= (rect
.bottom
- rect
.top
) / rows
;
228 rect
.left
+= (x
* dx
) - 2;
229 rect
.top
+= (y
* dy
) - 2;
230 rect
.right
= rect
.left
+ dx
;
231 rect
.bottom
= rect
.top
+ dy
;
234 DrawFocusRect(hdc
, &rect
);
235 CopyRect(&lpp
->focusRect
, &rect
);
236 lpp
->hwndFocus
= hwnd
;
237 ReleaseDC(hwnd
, hdc
);
242 /***********************************************************************
243 * CC_MouseCheckPredefColorArray [internal]
244 * returns 1 if one of the predefined colors is clicked
246 static int CC_MouseCheckPredefColorArray( LCCPRIV lpp
, HWND hDlg
, int dlgitem
, int rows
, int cols
,
254 CONV_LPARAMTOPOINT(lParam
, &point
);
255 ClientToScreen(hDlg
, &point
);
256 hwnd
= GetDlgItem(hDlg
, dlgitem
);
257 GetWindowRect(hwnd
, &rect
);
258 if (PtInRect(&rect
, point
))
260 dx
= (rect
.right
- rect
.left
) / cols
;
261 dy
= (rect
.bottom
- rect
.top
) / rows
;
262 ScreenToClient(hwnd
, &point
);
264 if (point
.x
% dx
< ( dx
- DISTANCE
) && point
.y
% dy
< ( dy
- DISTANCE
))
268 lpp
->lpcc
->rgbResult
= predefcolors
[y
][x
];
269 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
276 /***********************************************************************
277 * CC_MouseCheckUserColorArray [internal]
278 * return 1 if the user clicked a color
280 static int CC_MouseCheckUserColorArray( LCCPRIV lpp
, HWND hDlg
, int dlgitem
, int rows
, int cols
,
287 COLORREF
*crarr
= lpp
->lpcc
->lpCustColors
;
289 CONV_LPARAMTOPOINT(lParam
, &point
);
290 ClientToScreen(hDlg
, &point
);
291 hwnd
= GetDlgItem(hDlg
, dlgitem
);
292 GetWindowRect(hwnd
, &rect
);
293 if (PtInRect(&rect
, point
))
295 dx
= (rect
.right
- rect
.left
) / cols
;
296 dy
= (rect
.bottom
- rect
.top
) / rows
;
297 ScreenToClient(hwnd
, &point
);
299 if (point
.x
% dx
< (dx
- DISTANCE
) && point
.y
% dy
< (dy
- DISTANCE
))
303 lpp
->lpcc
->rgbResult
= crarr
[x
+ (cols
* y
) ];
304 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
314 /* 240 ^...... ^^ 240
321 /***********************************************************************
322 * CC_MouseCheckColorGraph [internal]
324 static int CC_MouseCheckColorGraph( HWND hDlg
, int dlgitem
, int *hori
, int *vert
, LPARAM lParam
)
331 CONV_LPARAMTOPOINT(lParam
, &point
);
332 ClientToScreen(hDlg
, &point
);
333 hwnd
= GetDlgItem( hDlg
, dlgitem
);
334 GetWindowRect(hwnd
, &rect
);
335 if (PtInRect(&rect
, point
))
337 GetClientRect(hwnd
, &rect
);
338 ScreenToClient(hwnd
, &point
);
340 x
= (long) point
.x
* MAXHORI
;
342 y
= (long) (rect
.bottom
- point
.y
) * MAXVERT
;
354 /***********************************************************************
355 * CC_MouseCheckResultWindow [internal]
356 * test if double click one of the result colors
358 static int CC_MouseCheckResultWindow( HWND hDlg
, LPARAM lParam
)
364 CONV_LPARAMTOPOINT(lParam
, &point
);
365 ClientToScreen(hDlg
, &point
);
366 hwnd
= GetDlgItem(hDlg
, 0x2c5);
367 GetWindowRect(hwnd
, &rect
);
368 if (PtInRect(&rect
, point
))
370 PostMessageA(hDlg
, WM_COMMAND
, 0x2c9, 0);
376 /***********************************************************************
377 * CC_CheckDigitsInEdit [internal]
379 static int CC_CheckDigitsInEdit( HWND hwnd
, int maxval
)
381 int i
, k
, m
, result
, value
;
385 GetWindowTextA(hwnd
, buffer
, sizeof(buffer
));
389 for (i
= 0 ; i
< m
; i
++)
390 if (buffer
[i
] < '0' || buffer
[i
] > '9')
392 for (k
= i
+ 1; k
<= m
; k
++) /* delete bad character */
394 buffer
[i
] = buffer
[k
];
401 value
= atoi(buffer
);
402 if (value
> maxval
) /* build a new string */
404 sprintf(buffer
, "%d", maxval
);
409 editpos
= SendMessageA(hwnd
, EM_GETSEL
, 0, 0);
410 SetWindowTextA(hwnd
, buffer
);
411 SendMessageA(hwnd
, EM_SETSEL
, 0, editpos
);
418 /***********************************************************************
419 * CC_PaintSelectedColor [internal]
421 static void CC_PaintSelectedColor( HWND hDlg
, COLORREF cr
)
426 HWND hwnd
= GetDlgItem(hDlg
, 0x2c5);
427 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
430 GetClientRect(hwnd
, &rect
) ;
431 hBrush
= CreateSolidBrush(cr
);
434 hBrush
= SelectObject(hdc
, hBrush
) ;
435 Rectangle(hdc
, rect
.left
, rect
.top
, rect
.right
/2, rect
.bottom
);
436 DeleteObject ( SelectObject(hdc
, hBrush
) ) ;
437 hBrush
= CreateSolidBrush( GetNearestColor(hdc
, cr
) );
440 hBrush
= SelectObject(hdc
, hBrush
) ;
441 Rectangle(hdc
, rect
.right
/2-1, rect
.top
, rect
.right
, rect
.bottom
);
442 DeleteObject(SelectObject(hdc
, hBrush
)) ;
445 ReleaseDC(hwnd
, hdc
);
449 /***********************************************************************
450 * CC_PaintTriangle [internal]
452 static void CC_PaintTriangle( HWND hDlg
, int y
)
456 int w
= LOWORD(GetDialogBaseUnits());
461 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
462 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA( hDlg
, DWL_USER
);
464 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6))) /* if full size */
466 GetClientRect(hwnd
, &rect
);
467 height
= rect
.bottom
;
469 points
[0].y
= rect
.top
;
470 points
[0].x
= rect
.right
; /* | /| */
471 ClientToScreen(hwnd
, points
); /* | / | */
472 ScreenToClient(hDlg
, points
); /* |< | */
473 oben
= points
[0].y
; /* | \ | */
475 temp
= (long)height
* (long)y
;
476 points
[0].y
= oben
+ height
- temp
/ (long)MAXVERT
;
477 points
[1].y
= points
[0].y
+ w
;
478 points
[2].y
= points
[0].y
- w
;
479 points
[2].x
= points
[1].x
= points
[0].x
+ w
;
481 FillRect(hDC
, &lpp
->old3angle
, GetClassLongA( hwnd
, GCL_HBRBACKGROUND
));
482 lpp
->old3angle
.left
= points
[0].x
;
483 lpp
->old3angle
.right
= points
[1].x
+ 1;
484 lpp
->old3angle
.top
= points
[2].y
- 1;
485 lpp
->old3angle
.bottom
= points
[1].y
+ 1;
486 Polygon(hDC
, points
, 3);
487 ReleaseDC(hDlg
, hDC
);
492 /***********************************************************************
493 * CC_PaintCross [internal]
495 static void CC_PaintCross( HWND hDlg
, int x
, int y
)
498 int w
= GetDialogBaseUnits();
499 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
500 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA( hDlg
, DWL_USER
);
505 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
507 GetClientRect(hwnd
, &rect
);
509 SelectClipRgn( hDC
, CreateRectRgnIndirect(&rect
));
510 hPen
= CreatePen(PS_SOLID
, 2, 0xffffff); /* -white- color */
511 hPen
= SelectObject(hDC
, hPen
);
512 point
.x
= ((long)rect
.right
* (long)x
) / (long)MAXHORI
;
513 point
.y
= rect
.bottom
- ((long)rect
.bottom
* (long)y
) / (long)MAXVERT
;
514 if ( lpp
->oldcross
.left
!= lpp
->oldcross
.right
)
515 BitBlt(hDC
, lpp
->oldcross
.left
, lpp
->oldcross
.top
,
516 lpp
->oldcross
.right
- lpp
->oldcross
.left
,
517 lpp
->oldcross
.bottom
- lpp
->oldcross
.top
,
518 lpp
->hdcMem
, lpp
->oldcross
.left
, lpp
->oldcross
.top
, SRCCOPY
);
519 lpp
->oldcross
.left
= point
.x
- w
- 1;
520 lpp
->oldcross
.right
= point
.x
+ w
+ 1;
521 lpp
->oldcross
.top
= point
.y
- w
- 1;
522 lpp
->oldcross
.bottom
= point
.y
+ w
+ 1;
524 MoveToEx(hDC
, point
.x
- w
, point
.y
, &p
);
525 LineTo(hDC
, point
.x
+ w
, point
.y
);
526 MoveToEx(hDC
, point
.x
, point
.y
- w
, &p
);
527 LineTo(hDC
, point
.x
, point
.y
+ w
);
528 DeleteObject( SelectObject(hDC
, hPen
)) ;
529 ReleaseDC(hwnd
, hDC
);
538 /***********************************************************************
539 * CC_PrepareColorGraph [internal]
541 static void CC_PrepareColorGraph( HWND hDlg
)
543 int sdif
, hdif
, xdif
, ydif
, r
, g
, b
, hue
, sat
;
544 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
545 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
549 HCURSOR hcursor
= SetCursor( LoadCursorA(0, IDC_WAITA
) );
551 GetClientRect(hwnd
, &client
);
553 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
554 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
, client
.right
, client
.bottom
);
555 SelectObject(lpp
->hdcMem
, lpp
->hbmMem
);
557 xdif
= client
.right
/ XSTEPS
;
558 ydif
= client
.bottom
/ YSTEPS
+1;
561 for (rect
.left
= hue
= 0; hue
< 239 + hdif
; hue
+= hdif
)
563 rect
.right
= rect
.left
+ xdif
;
564 rect
.bottom
= client
.bottom
;
565 for(sat
= 0; sat
< 240 + sdif
; sat
+= sdif
)
567 rect
.top
= rect
.bottom
- ydif
;
568 r
= CC_HSLtoRGB('R', hue
, sat
, 120);
569 g
= CC_HSLtoRGB('G', hue
, sat
, 120);
570 b
= CC_HSLtoRGB('B', hue
, sat
, 120);
571 hbrush
= CreateSolidBrush( RGB(r
, g
, b
));
572 FillRect(lpp
->hdcMem
, &rect
, hbrush
);
573 DeleteObject(hbrush
);
574 rect
.bottom
= rect
.top
;
576 rect
.left
= rect
.right
;
578 ReleaseDC(hwnd
, hdc
);
582 /***********************************************************************
583 * CC_PaintColorGraph [internal]
585 static void CC_PaintColorGraph( HWND hDlg
)
587 HWND hwnd
= GetDlgItem( hDlg
, 0x2c6 );
588 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
591 if (IsWindowVisible(hwnd
)) /* if full size */
594 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
597 GetClientRect(hwnd
, &rect
);
599 BitBlt(hDC
, 0, 0, rect
.right
, rect
.bottom
, lpp
->hdcMem
, 0, 0, SRCCOPY
);
601 WARN("choose color: hdcMem is not defined\n");
602 ReleaseDC(hwnd
, hDC
);
606 /***********************************************************************
607 * CC_PaintLumBar [internal]
609 static void CC_PaintLumBar( HWND hDlg
, int hue
, int sat
)
611 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
613 int lum
, ldif
, ydif
, r
, g
, b
;
617 if (IsWindowVisible(hwnd
))
620 GetClientRect(hwnd
, &client
);
624 ydif
= client
.bottom
/ YSTEPS
+1;
625 for (lum
= 0; lum
< 240 + ldif
; lum
+= ldif
)
627 rect
.top
= max(0, rect
.bottom
- ydif
);
628 r
= CC_HSLtoRGB('R', hue
, sat
, lum
);
629 g
= CC_HSLtoRGB('G', hue
, sat
, lum
);
630 b
= CC_HSLtoRGB('B', hue
, sat
, lum
);
631 hbrush
= CreateSolidBrush( RGB(r
, g
, b
) );
632 FillRect(hDC
, &rect
, hbrush
);
633 DeleteObject(hbrush
);
634 rect
.bottom
= rect
.top
;
636 GetClientRect(hwnd
, &rect
);
637 FrameRect(hDC
, &rect
, GetStockObject(BLACK_BRUSH
) );
638 ReleaseDC(hwnd
, hDC
);
642 /***********************************************************************
643 * CC_EditSetRGB [internal]
645 static void CC_EditSetRGB( HWND hDlg
, COLORREF cr
)
648 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
649 int r
= GetRValue(cr
);
650 int g
= GetGValue(cr
);
651 int b
= GetBValue(cr
);
652 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
654 lpp
->updating
= TRUE
;
655 sprintf(buffer
, "%d", r
);
656 SetWindowTextA( GetDlgItem(hDlg
, 0x2c2), buffer
);
657 sprintf(buffer
, "%d", g
);
658 SetWindowTextA( GetDlgItem(hDlg
, 0x2c3), buffer
);
659 sprintf( buffer
, "%d", b
);
660 SetWindowTextA( GetDlgItem(hDlg
, 0x2c4),buffer
);
661 lpp
->updating
= FALSE
;
665 /***********************************************************************
666 * CC_EditSetHSL [internal]
668 static void CC_EditSetHSL( HWND hDlg
, int h
, int s
, int l
)
671 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
672 lpp
->updating
= TRUE
;
673 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
675 lpp
->updating
= TRUE
;
676 sprintf(buffer
, "%d", h
);
677 SetWindowTextA( GetDlgItem(hDlg
, 0x2bf), buffer
);
678 sprintf(buffer
, "%d", s
);
679 SetWindowTextA( GetDlgItem(hDlg
, 0x2c0), buffer
);
680 sprintf(buffer
, "%d", l
);
681 SetWindowTextA( GetDlgItem(hDlg
, 0x2c1), buffer
);
682 lpp
->updating
= FALSE
;
684 CC_PaintLumBar(hDlg
, h
, s
);
687 /***********************************************************************
688 * CC_SwitchToFullSize [internal]
690 static void CC_SwitchToFullSize( HWND hDlg
, COLORREF result
, LPRECT lprect
)
693 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
695 EnableWindow( GetDlgItem(hDlg
, 0x2cf), FALSE
);
696 CC_PrepareColorGraph(hDlg
);
697 for (i
= 0x2bf; i
< 0x2c5; i
++)
698 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
699 for (i
= 0x2d3; i
< 0x2d9; i
++)
700 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
701 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_SHOW
);
702 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_SHOW
);
703 ShowWindow( GetDlgItem(hDlg
, 1090), SW_SHOW
);
706 SetWindowPos(hDlg
, 0, 0, 0, lprect
->right
-lprect
->left
,
707 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
709 ShowWindow( GetDlgItem(hDlg
, 0x2be), SW_SHOW
);
710 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_SHOW
);
712 CC_EditSetRGB(hDlg
, result
);
713 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
714 ShowWindow( GetDlgItem( hDlg
, 0x2c6), SW_SHOW
);
715 UpdateWindow( GetDlgItem(hDlg
, 0x2c6) );
718 /***********************************************************************
719 * CC_PaintPredefColorArray [internal]
720 * Paints the default standard 48 colors
722 static void CC_PaintPredefColorArray( HWND hDlg
, int rows
, int cols
)
724 HWND hwnd
= GetDlgItem(hDlg
, 0x2d0);
729 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
731 GetClientRect(hwnd
, &rect
);
732 dx
= rect
.right
/ cols
;
733 dy
= rect
.bottom
/ rows
;
737 GetClientRect(hwnd
, &rect
);
738 FillRect(hdc
, &rect
, GetClassLongA(hwnd
, GCL_HBRBACKGROUND
));
739 for ( j
= 0; j
< rows
; j
++ )
741 for ( i
= 0; i
< cols
; i
++ )
743 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
746 hBrush
= SelectObject(hdc
, hBrush
);
747 Rectangle(hdc
, rect
.left
, rect
.top
,
748 rect
.left
+ dx
- DISTANCE
, rect
.top
+ dy
- DISTANCE
);
749 rect
.left
= rect
.left
+ dx
;
750 DeleteObject(SelectObject(hdc
, hBrush
)) ;
753 rect
.top
= rect
.top
+ dy
;
756 ReleaseDC(hwnd
, hdc
);
757 if (lpp
->hwndFocus
== hwnd
)
758 CC_DrawCurrentFocusRect(lpp
);
760 /***********************************************************************
761 * CC_PaintUserColorArray [internal]
762 * Paint the 16 user-selected colors
764 static void CC_PaintUserColorArray( HWND hDlg
, int rows
, int cols
, COLORREF
* lpcr
)
766 HWND hwnd
= GetDlgItem(hDlg
, 0x2d1);
771 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
773 GetClientRect(hwnd
, &rect
);
775 dx
= rect
.right
/ cols
;
776 dy
= rect
.bottom
/ rows
;
782 FillRect(hdc
, &rect
, GetClassLongA(hwnd
, GCL_HBRBACKGROUND
) );
783 for (j
= 0; j
< rows
; j
++)
785 for (i
= 0; i
< cols
; i
++)
787 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
790 hBrush
= SelectObject(hdc
, hBrush
) ;
791 Rectangle(hdc
, rect
.left
, rect
.top
,
792 rect
.left
+ dx
- DISTANCE
, rect
.top
+ dy
- DISTANCE
);
793 rect
.left
= rect
.left
+ dx
;
794 DeleteObject( SelectObject(hdc
, hBrush
) ) ;
797 rect
.top
= rect
.top
+ dy
;
800 ReleaseDC(hwnd
, hdc
);
802 if (lpp
->hwndFocus
== hwnd
)
803 CC_DrawCurrentFocusRect(lpp
);
808 /***********************************************************************
809 * CC_HookCallChk [internal]
811 static BOOL
CC_HookCallChk( LPCHOOSECOLORW lpcc
)
814 if(lpcc
->Flags
& CC_ENABLEHOOK
)
821 /***********************************************************************
822 * CC_WMInitDialog [internal]
824 static LONG
CC_WMInitDialog( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, BOOL b16
)
833 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
834 lpp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct CCPRIVATE
) );
838 CHOOSECOLOR16
*ch16
= (CHOOSECOLOR16
*) lParam
;
839 ch32
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
) );
842 if (lpp
->lpcc16
->lStructSize
!= sizeof(CHOOSECOLOR16
) )
844 EndDialog (hDlg
, 0) ;
847 ch32
->lStructSize
= sizeof(CHOOSECOLORW
);
848 ch32
->hwndOwner
= ch16
->hwndOwner
;
849 ch32
->hInstance
= ch16
->hInstance
;
850 ch32
->lpCustColors
= MapSL(ch16
->lpCustColors
);
851 ch32
->lpfnHook
= (LPCCHOOKPROC
) ch16
->lpfnHook
; /* only used as flag */
852 ch32
->Flags
= ch16
->Flags
;
855 lpp
->lpcc
= (LPCHOOSECOLORW
) lParam
;
857 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLORW
) )
859 EndDialog (hDlg
, 0) ;
862 SetWindowLongA(hDlg
, DWL_USER
, (LONG
)lpp
);
864 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
865 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
866 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRINGA
);
869 cpos
= MAKELONG(5,7); /* init */
870 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
872 for (i
= 0; i
< 6; i
++)
873 for (j
= 0; j
< 8; j
++)
874 if (predefcolors
[i
][j
] == lpp
->lpcc
->rgbResult
)
876 cpos
= MAKELONG(i
,j
);
881 /* FIXME: Draw_a_focus_rect & set_init_values */
884 GetWindowRect(hDlg
, &lpp
->fullsize
);
885 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
887 hwnd
= GetDlgItem(hDlg
, 0x2cf);
888 EnableWindow(hwnd
, FALSE
);
890 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
892 rect
= lpp
->fullsize
;
893 res
= rect
.bottom
- rect
.top
;
894 hwnd
= GetDlgItem(hDlg
, 0x2c6); /* cut at left border */
895 point
.x
= point
.y
= 0;
896 ClientToScreen(hwnd
, &point
);
897 ScreenToClient(hDlg
,&point
);
898 GetClientRect(hDlg
, &rect
);
899 point
.x
+= GetSystemMetrics(SM_CXDLGFRAME
);
900 SetWindowPos(hDlg
, 0, 0, 0, point
.x
, res
, SWP_NOMOVE
|SWP_NOZORDER
);
902 for (i
= 0x2bf; i
< 0x2c5; i
++)
903 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
904 for (i
= 0x2d3; i
< 0x2d9; i
++)
905 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
906 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_HIDE
);
907 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_HIDE
);
908 ShowWindow( GetDlgItem(hDlg
, 0x2c6), SW_HIDE
);
909 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_HIDE
);
910 ShowWindow( GetDlgItem(hDlg
, 1090 ), SW_HIDE
);
913 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, NULL
);
915 for (i
= 0x2bf; i
< 0x2c5; i
++)
916 SendMessageA( GetDlgItem(hDlg
, i
), EM_LIMITTEXT
, 3, 0); /* max 3 digits: xyz */
917 if (CC_HookCallChk(lpp
->lpcc
))
920 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
922 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
925 /* Set the initial values of the color chooser dialog */
926 r
= GetRValue(lpp
->lpcc
->rgbResult
);
927 g
= GetGValue(lpp
->lpcc
->rgbResult
);
928 b
= GetBValue(lpp
->lpcc
->rgbResult
);
930 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
931 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
932 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
933 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
935 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
936 SetDlgItemInt(hDlg
, 703, lpp
->h
, TRUE
);
937 SetDlgItemInt(hDlg
, 704, lpp
->s
, TRUE
);
938 SetDlgItemInt(hDlg
, 705, lpp
->l
, TRUE
);
939 SetDlgItemInt(hDlg
, 706, r
, TRUE
);
940 SetDlgItemInt(hDlg
, 707, g
, TRUE
);
941 SetDlgItemInt(hDlg
, 708, b
, TRUE
);
943 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
944 CC_PaintTriangle(hDlg
, lpp
->l
);
950 /***********************************************************************
951 * CC_WMCommand [internal]
953 static LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
959 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
960 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam
, lParam
);
963 case 0x2c2: /* edit notify RGB */
966 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
968 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
969 r
= GetRValue(lpp
->lpcc
->rgbResult
);
970 g
= GetGValue(lpp
->lpcc
->rgbResult
);
971 b
= GetBValue(lpp
->lpcc
->rgbResult
);
975 case 0x2c2: if ((xx
= (i
!= r
))) r
= i
; break;
976 case 0x2c3: if ((xx
= (i
!= g
))) g
= i
; break;
977 case 0x2c4: if ((xx
= (i
!= b
))) b
= i
; break;
979 if (xx
) /* something has changed */
981 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
982 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
983 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
984 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
985 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
986 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
987 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
988 CC_PaintTriangle(hDlg
, lpp
->l
);
993 case 0x2bf: /* edit notify HSL */
996 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
998 i
= CC_CheckDigitsInEdit(hwndCtl
, wParam
== 0x2bf ? 239:240);
1002 case 0x2bf: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
1003 case 0x2c0: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
1004 case 0x2c1: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
1006 if (xx
) /* something has changed */
1008 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1009 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1010 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1011 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1012 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1013 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1014 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1015 CC_PaintTriangle(hDlg
, lpp
->l
);
1021 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1022 SetFocus( GetDlgItem(hDlg
, 0x2bf));
1025 case 0x2c8: /* add colors ... column by column */
1026 cr
= lpp
->lpcc
->lpCustColors
;
1027 cr
[(lpp
->nextuserdef
% 2) * 8 + lpp
->nextuserdef
/ 2] = lpp
->lpcc
->rgbResult
;
1028 if (++lpp
->nextuserdef
== 16)
1029 lpp
->nextuserdef
= 0;
1030 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1033 case 0x2c9: /* resulting color */
1035 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1036 ReleaseDC(hDlg
, hdc
);
1037 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1038 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1039 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1040 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1041 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1042 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1043 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1044 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1045 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
1046 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1047 CC_PaintTriangle(hDlg
, lpp
->l
);
1050 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1051 i
= RegisterWindowMessageA(HELPMSGSTRINGA
);
1054 if (lpp
->lpcc
->hwndOwner
)
1055 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc16
);
1056 if ( CC_HookCallChk(lpp
->lpcc
))
1057 CallWindowProc16( (WNDPROC16
) lpp
->lpcc16
->lpfnHook
, hDlg
,
1058 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc16
);
1062 if (lpp
->lpcc
->hwndOwner
)
1063 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1064 if ( CC_HookCallChk(lpp
->lpcc
))
1065 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, hDlg
,
1066 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1071 cokmsg
= RegisterWindowMessageA(COLOROKSTRINGA
);
1074 if (lpp
->lpcc
->hwndOwner
)
1075 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc16
))
1076 break; /* do NOT close */
1080 if (lpp
->lpcc
->hwndOwner
)
1081 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1082 break; /* do NOT close */
1086 BYTE
*ptr
= MapSL(lpp
->lpcc16
->lpCustColors
);
1087 memcpy(ptr
, lpp
->lpcc
->lpCustColors
, sizeof(COLORREF
)*16);
1088 lpp
->lpcc16
->rgbResult
= lpp
->lpcc
->rgbResult
;
1090 EndDialog(hDlg
, 1) ;
1094 EndDialog(hDlg
, 0) ;
1101 /***********************************************************************
1102 * CC_WMPaint [internal]
1104 static LRESULT
CC_WMPaint( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1108 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1110 hdc
= BeginPaint(hDlg
, &ps
);
1111 /* we have to paint dialog children except text and buttons */
1112 CC_PaintPredefColorArray(hDlg
, 6, 8);
1113 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1114 CC_PaintLumBar(hDlg
, lpp
->h
, lpp
->s
);
1115 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1116 CC_PaintTriangle(hDlg
, lpp
->l
);
1117 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1118 CC_PaintColorGraph(hDlg
);
1119 EndPaint(hDlg
, &ps
);
1125 /***********************************************************************
1126 * CC_WMLButtonUp [internal]
1128 static LRESULT
CC_WMLButtonUp( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1130 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1131 if (lpp
->capturedGraph
)
1133 lpp
->capturedGraph
= 0;
1135 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1142 /***********************************************************************
1143 * CC_WMMouseMove [internal]
1145 static LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1147 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1150 if (lpp
->capturedGraph
)
1152 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1153 if (lpp
->capturedGraph
== 0x2c6)
1158 if (CC_MouseCheckColorGraph( hDlg
, lpp
->capturedGraph
, ptrh
, ptrs
, lParam
))
1160 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1161 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1162 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1163 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1164 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1165 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1166 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1167 CC_PaintTriangle(hDlg
, lpp
->l
);
1168 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1173 lpp
->capturedGraph
= 0;
1179 /***********************************************************************
1180 * CC_WMLButtonDown [internal]
1182 static LRESULT
CC_WMLButtonDown( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1184 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1188 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1191 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1194 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1197 lpp
->capturedGraph
= 0x2c6;
1200 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1203 lpp
->capturedGraph
= 0x2be;
1208 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1209 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1210 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1211 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1215 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1216 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1217 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1218 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1219 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1220 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1224 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1225 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1226 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1227 CC_PaintTriangle(hDlg
, lpp
->l
);
1228 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1235 /***********************************************************************
1236 * ColorDlgProc32 [internal]
1239 static LRESULT WINAPI
ColorDlgProc( HWND hDlg
, UINT message
,
1240 WPARAM wParam
, LPARAM lParam
)
1244 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1245 if (message
!= WM_INITDIALOG
)
1250 if (CC_HookCallChk(lpp
->lpcc
))
1251 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1256 /* FIXME: SetRGB message
1257 if (message && message == msetrgb)
1258 return HandleSetRGB(hDlg, lParam);
1264 return CC_WMInitDialog(hDlg
, wParam
, lParam
, FALSE
);
1266 DeleteDC(lpp
->hdcMem
);
1267 DeleteObject(lpp
->hbmMem
);
1268 HeapFree(GetProcessHeap(), 0, lpp
);
1269 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1272 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1276 if ( CC_WMPaint(hDlg
, wParam
, lParam
))
1279 case WM_LBUTTONDBLCLK
:
1280 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1284 if (CC_WMMouseMove(hDlg
, lParam
))
1287 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1288 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1291 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1292 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1299 /***********************************************************************
1300 * ColorDlgProc (COMMDLG.8)
1302 LRESULT WINAPI
ColorDlgProc16( HWND16 hDlg
, UINT16 message
,
1303 WPARAM16 wParam
, LONG lParam
)
1306 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1307 if (message
!= WM_INITDIALOG
)
1312 if (CC_HookCallChk(lpp
->lpcc
))
1313 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1318 /* FIXME: SetRGB message
1319 if (message && message == msetrgb)
1320 return HandleSetRGB(hDlg, lParam);
1326 return CC_WMInitDialog(hDlg
, wParam
, lParam
, TRUE
);
1328 DeleteDC(lpp
->hdcMem
);
1329 DeleteObject(lpp
->hbmMem
);
1330 HeapFree(GetProcessHeap(), 0, lpp
->lpcc
);
1331 HeapFree(GetProcessHeap(), 0, lpp
);
1332 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1335 if (CC_WMCommand(hDlg
, wParam
, lParam
, HIWORD(lParam
), (HWND
)LOWORD(lParam
)))
1339 if (CC_WMPaint(hDlg
, wParam
, lParam
))
1342 case WM_LBUTTONDBLCLK
:
1343 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
1347 if (CC_WMMouseMove(hDlg
, lParam
))
1350 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1351 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1354 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1355 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1364 /***********************************************************************
1365 * ChooseColor (COMMDLG.5)
1367 BOOL16 WINAPI
ChooseColor16( LPCHOOSECOLOR16 lpChCol
)
1370 HANDLE16 hDlgTmpl16
= 0, hResource16
= 0;
1371 HGLOBAL16 hGlobal16
= 0;
1372 BOOL16 bRet
= FALSE
;
1376 TRACE("ChooseColor\n");
1377 if (!lpChCol
) return FALSE
;
1379 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1380 hDlgTmpl16
= lpChCol
->hInstance
;
1381 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1384 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1385 MapSL(lpChCol
->lpTemplateName
),
1388 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1391 if (!(hDlgTmpl16
= LoadResource16(lpChCol
->hInstance
, hResInfo
)))
1393 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1396 hResource16
= hDlgTmpl16
;
1400 HANDLE hResInfo
, hDlgTmpl32
;
1403 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_COLOR", RT_DIALOGA
)))
1405 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1408 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1409 !(template32
= LockResource(hDlgTmpl32
)))
1411 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1414 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
1415 hGlobal16
= GlobalAlloc16(0, size
);
1418 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
1419 ERR("alloc failure for %ld bytes\n", size
);
1422 template = GlobalLock16(hGlobal16
);
1425 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
1426 ERR("global lock failure for %x handle\n", hDlgTmpl16
);
1427 GlobalFree16(hGlobal16
);
1430 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
1431 hDlgTmpl16
= hGlobal16
;
1434 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 8);
1435 hInst
= GetWindowLongA(lpChCol
->hwndOwner
, GWL_HINSTANCE
);
1436 bRet
= DialogBoxIndirectParam16(hInst
, hDlgTmpl16
, lpChCol
->hwndOwner
,
1437 (DLGPROC16
) ptr
, (DWORD
)lpChCol
);
1438 if (hResource16
) FreeResource16(hDlgTmpl16
);
1441 GlobalUnlock16(hGlobal16
);
1442 GlobalFree16(hGlobal16
);
1447 /***********************************************************************
1448 * ChooseColorW (COMDLG32.@)
1450 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1454 HANDLE hDlgTmpl
= 0;
1458 TRACE("ChooseColor\n");
1459 if (!lpChCol
) return FALSE
;
1461 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1463 if (!(template = LockResource(lpChCol
->hInstance
)))
1465 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1469 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1472 if (!(hResInfo
= FindResourceW(lpChCol
->hInstance
,
1473 lpChCol
->lpTemplateName
,
1476 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1479 if (!(hDlgTmpl
= LoadResource(lpChCol
->hInstance
, hResInfo
)) ||
1480 !(template = LockResource(hDlgTmpl
)))
1482 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1488 HANDLE hResInfo
, hDlgTmpl
;
1489 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_COLOR", RT_DIALOGA
)))
1491 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1494 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1495 !(template = LockResource(hDlgTmpl
)))
1497 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1502 bRet
= DialogBoxIndirectParamW(COMMDLG_hInstance32
, template, lpChCol
->hwndOwner
,
1503 (DLGPROC
)ColorDlgProc
, (DWORD
)lpChCol
);
1507 /***********************************************************************
1508 * ChooseColorA (COMDLG32.@)
1510 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1514 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1515 lpcc
->lStructSize
= sizeof(*lpcc
);
1516 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1517 lpcc
->hInstance
= lpChCol
->hInstance
;
1518 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1519 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1520 lpcc
->Flags
= lpChCol
->Flags
;
1521 lpcc
->lCustData
= lpChCol
->lCustData
;
1522 lpcc
->lpfnHook
= (LPCCHOOKPROC
) lpChCol
->lpfnHook
;
1523 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1524 if (HIWORD(lpChCol
->lpTemplateName
)) {
1525 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, NULL
, 0);
1526 lpcc
->lpTemplateName
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1527 MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, (LPWSTR
)lpcc
->lpTemplateName
, len
);
1529 lpcc
->lpTemplateName
= (LPWSTR
)lpChCol
->lpTemplateName
;
1533 ret
= ChooseColorW(lpcc
);
1536 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1537 if (HIWORD(lpcc
->lpTemplateName
)) HeapFree(GetProcessHeap(), 0, (LPSTR
)lpcc
->lpTemplateName
);
1538 HeapFree(GetProcessHeap(), 0, lpcc
);