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 INT_PTR CALLBACK
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
, (HBRUSH
)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
, (HBRUSH
)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
, (HBRUSH
)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
= HWND_32(ch16
->hwndOwner
);
849 /* Should be an HINSTANCE but MS made a typo */
850 ch32
->hInstance
= HWND_32(ch16
->hInstance
);
851 ch32
->lpCustColors
= MapSL(ch16
->lpCustColors
);
852 ch32
->lpfnHook
= (LPCCHOOKPROC
) ch16
->lpfnHook
; /* only used as flag */
853 ch32
->Flags
= ch16
->Flags
;
856 lpp
->lpcc
= (LPCHOOSECOLORW
) lParam
;
858 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLORW
) )
860 EndDialog (hDlg
, 0) ;
863 SetWindowLongA(hDlg
, DWL_USER
, (LONG
)lpp
);
865 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
866 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
867 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRINGA
);
870 cpos
= MAKELONG(5,7); /* init */
871 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
873 for (i
= 0; i
< 6; i
++)
874 for (j
= 0; j
< 8; j
++)
875 if (predefcolors
[i
][j
] == lpp
->lpcc
->rgbResult
)
877 cpos
= MAKELONG(i
,j
);
882 /* FIXME: Draw_a_focus_rect & set_init_values */
885 GetWindowRect(hDlg
, &lpp
->fullsize
);
886 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
888 hwnd
= GetDlgItem(hDlg
, 0x2cf);
889 EnableWindow(hwnd
, FALSE
);
891 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
893 rect
= lpp
->fullsize
;
894 res
= rect
.bottom
- rect
.top
;
895 hwnd
= GetDlgItem(hDlg
, 0x2c6); /* cut at left border */
896 point
.x
= point
.y
= 0;
897 ClientToScreen(hwnd
, &point
);
898 ScreenToClient(hDlg
,&point
);
899 GetClientRect(hDlg
, &rect
);
900 point
.x
+= GetSystemMetrics(SM_CXDLGFRAME
);
901 SetWindowPos(hDlg
, 0, 0, 0, point
.x
, res
, SWP_NOMOVE
|SWP_NOZORDER
);
903 for (i
= 0x2bf; i
< 0x2c5; i
++)
904 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
905 for (i
= 0x2d3; i
< 0x2d9; i
++)
906 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
907 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_HIDE
);
908 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_HIDE
);
909 ShowWindow( GetDlgItem(hDlg
, 0x2c6), SW_HIDE
);
910 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_HIDE
);
911 ShowWindow( GetDlgItem(hDlg
, 1090 ), SW_HIDE
);
914 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, NULL
);
916 for (i
= 0x2bf; i
< 0x2c5; i
++)
917 SendMessageA( GetDlgItem(hDlg
, i
), EM_LIMITTEXT
, 3, 0); /* max 3 digits: xyz */
918 if (CC_HookCallChk(lpp
->lpcc
))
921 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
,
922 HWND_16(hDlg
), WM_INITDIALOG
, wParam
, lParam
);
924 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
927 /* Set the initial values of the color chooser dialog */
928 r
= GetRValue(lpp
->lpcc
->rgbResult
);
929 g
= GetGValue(lpp
->lpcc
->rgbResult
);
930 b
= GetBValue(lpp
->lpcc
->rgbResult
);
932 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
933 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
934 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
935 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
937 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
938 SetDlgItemInt(hDlg
, 703, lpp
->h
, TRUE
);
939 SetDlgItemInt(hDlg
, 704, lpp
->s
, TRUE
);
940 SetDlgItemInt(hDlg
, 705, lpp
->l
, TRUE
);
941 SetDlgItemInt(hDlg
, 706, r
, TRUE
);
942 SetDlgItemInt(hDlg
, 707, g
, TRUE
);
943 SetDlgItemInt(hDlg
, 708, b
, TRUE
);
945 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
946 CC_PaintTriangle(hDlg
, lpp
->l
);
952 /***********************************************************************
953 * CC_WMCommand [internal]
955 static LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
961 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
962 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam
, lParam
);
965 case 0x2c2: /* edit notify RGB */
968 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
970 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
971 r
= GetRValue(lpp
->lpcc
->rgbResult
);
972 g
= GetGValue(lpp
->lpcc
->rgbResult
);
973 b
= GetBValue(lpp
->lpcc
->rgbResult
);
977 case 0x2c2: if ((xx
= (i
!= r
))) r
= i
; break;
978 case 0x2c3: if ((xx
= (i
!= g
))) g
= i
; break;
979 case 0x2c4: if ((xx
= (i
!= b
))) b
= i
; break;
981 if (xx
) /* something has changed */
983 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
984 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
985 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
986 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
987 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
988 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
989 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
990 CC_PaintTriangle(hDlg
, lpp
->l
);
995 case 0x2bf: /* edit notify HSL */
998 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
1000 i
= CC_CheckDigitsInEdit(hwndCtl
, wParam
== 0x2bf ? 239:240);
1004 case 0x2bf: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
1005 case 0x2c0: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
1006 case 0x2c1: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
1008 if (xx
) /* something has changed */
1010 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1011 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1012 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1013 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1014 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1015 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1016 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1017 CC_PaintTriangle(hDlg
, lpp
->l
);
1023 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1024 SetFocus( GetDlgItem(hDlg
, 0x2bf));
1027 case 0x2c8: /* add colors ... column by column */
1028 cr
= lpp
->lpcc
->lpCustColors
;
1029 cr
[(lpp
->nextuserdef
% 2) * 8 + lpp
->nextuserdef
/ 2] = lpp
->lpcc
->rgbResult
;
1030 if (++lpp
->nextuserdef
== 16)
1031 lpp
->nextuserdef
= 0;
1032 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1035 case 0x2c9: /* resulting color */
1037 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1038 ReleaseDC(hDlg
, hdc
);
1039 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1040 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1041 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1042 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1043 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1044 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1045 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1046 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1047 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
1048 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1049 CC_PaintTriangle(hDlg
, lpp
->l
);
1052 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1053 i
= RegisterWindowMessageA(HELPMSGSTRINGA
);
1056 if (lpp
->lpcc
->hwndOwner
)
1057 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc16
);
1058 if ( CC_HookCallChk(lpp
->lpcc
))
1059 CallWindowProc16( (WNDPROC16
) lpp
->lpcc16
->lpfnHook
,
1060 HWND_16(hDlg
), WM_COMMAND
, psh15
,
1061 (LPARAM
)lpp
->lpcc16
);
1065 if (lpp
->lpcc
->hwndOwner
)
1066 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1067 if ( CC_HookCallChk(lpp
->lpcc
))
1068 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, hDlg
,
1069 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1074 cokmsg
= RegisterWindowMessageA(COLOROKSTRINGA
);
1077 if (lpp
->lpcc
->hwndOwner
)
1078 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc16
))
1079 break; /* do NOT close */
1083 if (lpp
->lpcc
->hwndOwner
)
1084 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1085 break; /* do NOT close */
1089 BYTE
*ptr
= MapSL(lpp
->lpcc16
->lpCustColors
);
1090 memcpy(ptr
, lpp
->lpcc
->lpCustColors
, sizeof(COLORREF
)*16);
1091 lpp
->lpcc16
->rgbResult
= lpp
->lpcc
->rgbResult
;
1093 EndDialog(hDlg
, 1) ;
1097 EndDialog(hDlg
, 0) ;
1104 /***********************************************************************
1105 * CC_WMPaint [internal]
1107 static LRESULT
CC_WMPaint( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1111 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1113 hdc
= BeginPaint(hDlg
, &ps
);
1114 /* we have to paint dialog children except text and buttons */
1115 CC_PaintPredefColorArray(hDlg
, 6, 8);
1116 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1117 CC_PaintLumBar(hDlg
, lpp
->h
, lpp
->s
);
1118 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1119 CC_PaintTriangle(hDlg
, lpp
->l
);
1120 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1121 CC_PaintColorGraph(hDlg
);
1122 EndPaint(hDlg
, &ps
);
1128 /***********************************************************************
1129 * CC_WMLButtonUp [internal]
1131 static LRESULT
CC_WMLButtonUp( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1133 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1134 if (lpp
->capturedGraph
)
1136 lpp
->capturedGraph
= 0;
1138 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1145 /***********************************************************************
1146 * CC_WMMouseMove [internal]
1148 static LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1150 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1153 if (lpp
->capturedGraph
)
1155 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1156 if (lpp
->capturedGraph
== 0x2c6)
1161 if (CC_MouseCheckColorGraph( hDlg
, lpp
->capturedGraph
, ptrh
, ptrs
, lParam
))
1163 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1164 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1165 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1166 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1167 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1168 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1169 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1170 CC_PaintTriangle(hDlg
, lpp
->l
);
1171 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1176 lpp
->capturedGraph
= 0;
1182 /***********************************************************************
1183 * CC_WMLButtonDown [internal]
1185 static LRESULT
CC_WMLButtonDown( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1187 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1191 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1194 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1197 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1200 lpp
->capturedGraph
= 0x2c6;
1203 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1206 lpp
->capturedGraph
= 0x2be;
1211 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1212 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1213 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1214 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1218 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1219 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1220 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1221 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1222 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1223 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1227 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1228 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1229 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1230 CC_PaintTriangle(hDlg
, lpp
->l
);
1231 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1238 /***********************************************************************
1239 * ColorDlgProc32 [internal]
1242 static INT_PTR CALLBACK
ColorDlgProc( HWND hDlg
, UINT message
,
1243 WPARAM wParam
, LPARAM lParam
)
1247 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1248 if (message
!= WM_INITDIALOG
)
1253 if (CC_HookCallChk(lpp
->lpcc
))
1254 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1259 /* FIXME: SetRGB message
1260 if (message && message == msetrgb)
1261 return HandleSetRGB(hDlg, lParam);
1267 return CC_WMInitDialog(hDlg
, wParam
, lParam
, FALSE
);
1269 DeleteDC(lpp
->hdcMem
);
1270 DeleteObject(lpp
->hbmMem
);
1271 HeapFree(GetProcessHeap(), 0, lpp
);
1272 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1275 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1279 if ( CC_WMPaint(hDlg
, wParam
, lParam
))
1282 case WM_LBUTTONDBLCLK
:
1283 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1287 if (CC_WMMouseMove(hDlg
, lParam
))
1290 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1291 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1294 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1295 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1302 /***********************************************************************
1303 * ColorDlgProc (COMMDLG.8)
1305 BOOL16 CALLBACK
ColorDlgProc16( HWND16 hDlg16
, UINT16 message
,
1306 WPARAM16 wParam
, LONG lParam
)
1309 HWND hDlg
= HWND_32(hDlg16
);
1311 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1312 if (message
!= WM_INITDIALOG
)
1317 if (CC_HookCallChk(lpp
->lpcc
))
1318 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
, hDlg16
, message
, wParam
, lParam
);
1323 /* FIXME: SetRGB message
1324 if (message && message == msetrgb)
1325 return HandleSetRGB(hDlg, lParam);
1331 return CC_WMInitDialog(hDlg
, wParam
, lParam
, TRUE
);
1333 DeleteDC(lpp
->hdcMem
);
1334 DeleteObject(lpp
->hbmMem
);
1335 HeapFree(GetProcessHeap(), 0, lpp
->lpcc
);
1336 HeapFree(GetProcessHeap(), 0, lpp
);
1337 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1340 if (CC_WMCommand(hDlg
, wParam
, lParam
,
1341 HIWORD(lParam
), HWND_32(LOWORD(lParam
))))
1345 if (CC_WMPaint(hDlg
, wParam
, lParam
))
1348 case WM_LBUTTONDBLCLK
:
1349 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
1353 if (CC_WMMouseMove(hDlg
, lParam
))
1356 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1357 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1360 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1361 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1370 /***********************************************************************
1371 * ChooseColor (COMMDLG.5)
1373 BOOL16 WINAPI
ChooseColor16( LPCHOOSECOLOR16 lpChCol
)
1376 HANDLE16 hDlgTmpl16
= 0, hResource16
= 0;
1377 HGLOBAL16 hGlobal16
= 0;
1378 BOOL16 bRet
= FALSE
;
1382 TRACE("ChooseColor\n");
1383 if (!lpChCol
) return FALSE
;
1385 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1386 hDlgTmpl16
= lpChCol
->hInstance
;
1387 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1390 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1391 MapSL(lpChCol
->lpTemplateName
),
1394 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1397 if (!(hDlgTmpl16
= LoadResource16(lpChCol
->hInstance
, hResInfo
)))
1399 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1402 hResource16
= hDlgTmpl16
;
1410 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
, "CHOOSE_COLOR", RT_DIALOGA
)))
1412 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1415 if (!(hDlgTmpl32
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1416 !(template32
= LockResource(hDlgTmpl32
)))
1418 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1421 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
1422 hGlobal16
= GlobalAlloc16(0, size
);
1425 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
1426 ERR("alloc failure for %ld bytes\n", size
);
1429 template = GlobalLock16(hGlobal16
);
1432 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
1433 ERR("global lock failure for %x handle\n", hDlgTmpl16
);
1434 GlobalFree16(hGlobal16
);
1437 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
1438 hDlgTmpl16
= hGlobal16
;
1441 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 8);
1442 hInst
= GetWindowLongA(HWND_32(lpChCol
->hwndOwner
), GWL_HINSTANCE
);
1443 bRet
= DialogBoxIndirectParam16(hInst
, hDlgTmpl16
, lpChCol
->hwndOwner
,
1444 (DLGPROC16
) ptr
, (DWORD
)lpChCol
);
1445 if (hResource16
) FreeResource16(hDlgTmpl16
);
1448 GlobalUnlock16(hGlobal16
);
1449 GlobalFree16(hGlobal16
);
1454 /***********************************************************************
1455 * ChooseColorW (COMDLG32.@)
1457 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1459 HANDLE hDlgTmpl
= 0;
1463 TRACE("ChooseColor\n");
1464 if (!lpChCol
) return FALSE
;
1466 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1468 if (!(template = LockResource(lpChCol
->hInstance
)))
1470 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1474 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1477 if (!(hResInfo
= FindResourceW((HINSTANCE
)lpChCol
->hInstance
,
1478 lpChCol
->lpTemplateName
,
1481 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1484 if (!(hDlgTmpl
= LoadResource((HINSTANCE
)lpChCol
->hInstance
, hResInfo
)) ||
1485 !(template = LockResource(hDlgTmpl
)))
1487 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1495 if (!(hResInfo
= FindResourceA(COMDLG32_hInstance
, "CHOOSE_COLOR", RT_DIALOGA
)))
1497 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1500 if (!(hDlgTmpl
= LoadResource(COMDLG32_hInstance
, hResInfo
)) ||
1501 !(template = LockResource(hDlgTmpl
)))
1503 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1508 bRet
= DialogBoxIndirectParamW(COMDLG32_hInstance
, template, lpChCol
->hwndOwner
,
1509 ColorDlgProc
, (DWORD
)lpChCol
);
1513 /***********************************************************************
1514 * ChooseColorA (COMDLG32.@)
1516 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1520 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1521 lpcc
->lStructSize
= sizeof(*lpcc
);
1522 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1523 lpcc
->hInstance
= lpChCol
->hInstance
;
1524 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1525 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1526 lpcc
->Flags
= lpChCol
->Flags
;
1527 lpcc
->lCustData
= lpChCol
->lCustData
;
1528 lpcc
->lpfnHook
= (LPCCHOOKPROC
) lpChCol
->lpfnHook
;
1529 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1530 if (HIWORD(lpChCol
->lpTemplateName
)) {
1531 INT len
= MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, NULL
, 0);
1532 lpcc
->lpTemplateName
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) );
1533 MultiByteToWideChar( CP_ACP
, 0, lpChCol
->lpTemplateName
, -1, (LPWSTR
)lpcc
->lpTemplateName
, len
);
1535 lpcc
->lpTemplateName
= (LPWSTR
)lpChCol
->lpTemplateName
;
1539 ret
= ChooseColorW(lpcc
);
1542 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1543 if (HIWORD(lpcc
->lpTemplateName
)) HeapFree(GetProcessHeap(), 0, (LPSTR
)lpcc
->lpTemplateName
);
1544 HeapFree(GetProcessHeap(), 0, lpcc
);