2 * COMMDLG - Color Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
8 /* BUGS : still seems to not refresh correctly
9 sometimes, especially when 2 instances of the
10 dialog are loaded at the same time */
19 #include "wine/winbase16.h"
20 #include "wine/winuser16.h"
27 #include "debugtools.h"
30 DEFAULT_DEBUG_CHANNEL(commdlg
);
34 static LRESULT WINAPI
ColorDlgProc( HWND hWnd
, UINT wMsg
, WPARAM wParam
, LPARAM lParam
);
36 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = SLOWORD(lp); (p)->y = SHIWORD(lp); } while(0)
38 static const COLORREF predefcolors
[6][8]=
40 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
41 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
42 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
43 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
45 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
46 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
47 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
48 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
50 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
51 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
52 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
53 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
58 LPCHOOSECOLORW lpcc
; /* points to public known data structure */
59 LPCHOOSECOLOR16 lpcc16
; /* save the 16 bits pointer */
60 int nextuserdef
; /* next free place in user defined color array */
61 HDC hdcMem
; /* color graph used for BitBlt() */
62 HBITMAP hbmMem
; /* color graph bitmap */
63 RECT fullsize
; /* original dialog window size */
64 UINT msetrgb
; /* # of SETRGBSTRING message (today not used) */
65 RECT old3angle
; /* last position of l-marker */
66 RECT oldcross
; /* last position of color/satuation marker */
67 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
70 int l
; /* for temporary storing of hue,sat,lum */
71 int capturedGraph
; /* control mouse captured */
72 RECT focusRect
; /* rectangle last focused item */
73 HWND hwndFocus
; /* handle last focused item */
76 #define LCCPRIV struct CCPRIVATE *
78 /***********************************************************************
79 * CC_HSLtoRGB [internal]
81 static int CC_HSLtoRGB(char c
, int hue
, int sat
, int lum
)
88 case 'R': if (hue
> 80) hue
-= 80; else hue
+= 160; break;
89 case 'G': if (hue
> 160) hue
-= 160; else hue
+= 80; break;
94 maxrgb
= (256 * min(120,lum
)) / 120; /* 0 .. 256 */
100 res
= (hue
- 80) * maxrgb
; /* 0...10240 */
101 res
/= 40; /* 0...256 */
108 res
= (240 - hue
) * maxrgb
;
111 res
= res
- maxrgb
/ 2; /* -128...128 */
114 res
= maxrgb
/ 2 + (sat
* res
) / 240; /* 0..256 */
117 if (lum
> 120 && res
< 256)
118 res
+= ((lum
- 120) * (256 - res
)) / 120;
120 return min(res
, 255);
123 /***********************************************************************
124 * CC_RGBtoHSL [internal]
126 static int CC_RGBtoHSL(char c
, int r
, int g
, int b
)
128 WORD maxi
, mini
, mmsum
, mmdif
, result
= 0;
142 case 'L': mmsum
*= 120; /* 0...61200=(255+255)*120 */
143 result
= mmsum
/ 255; /* 0...240 */
146 case 'S': if (!mmsum
)
149 if (!mini
|| maxi
== 255)
153 result
= mmdif
* 240; /* 0...61200=255*240 */
154 result
/= (mmsum
> 255 ? mmsum
= 510 - mmsum
: mmsum
); /* 0..255 */
158 case 'H': if (!mmdif
)
164 iresult
= 40 * (g
- b
); /* -10200 ... 10200 */
165 iresult
/= (int) mmdif
; /* -40 .. 40 */
167 iresult
+= 240; /* 0..40 and 200..240 */
172 iresult
= 40 * (b
- r
);
173 iresult
/= (int) mmdif
;
174 iresult
+= 80; /* 40 .. 120 */
179 iresult
= 40 * (r
- g
);
180 iresult
/= (int) mmdif
;
181 iresult
+= 160; /* 120 .. 200 */
187 return result
; /* is this integer arithmetic precise enough ? */
191 /***********************************************************************
192 * CC_DrawCurrentFocusRect [internal]
194 void CC_DrawCurrentFocusRect( LCCPRIV lpp
)
198 HDC hdc
= GetDC(lpp
->hwndFocus
);
199 DrawFocusRect(hdc
, &lpp
->focusRect
);
200 ReleaseDC(lpp
->hwndFocus
, hdc
);
204 /***********************************************************************
205 * CC_DrawFocusRect [internal]
207 void CC_DrawFocusRect( LCCPRIV lpp
, HWND hwnd
, int x
, int y
, int rows
, int cols
)
213 CC_DrawCurrentFocusRect(lpp
); /* remove current focus rect */
214 /* calculate new rect */
215 GetClientRect(hwnd
, &rect
);
216 dx
= (rect
.right
- rect
.left
) / cols
;
217 dy
= (rect
.bottom
- rect
.top
) / rows
;
218 rect
.left
+= (x
* dx
) - 2;
219 rect
.top
+= (y
* dy
) - 2;
220 rect
.right
= rect
.left
+ dx
;
221 rect
.bottom
= rect
.top
+ dy
;
224 DrawFocusRect(hdc
, &rect
);
225 CopyRect(&lpp
->focusRect
, &rect
);
226 lpp
->hwndFocus
= hwnd
;
227 ReleaseDC(hwnd
, hdc
);
232 /***********************************************************************
233 * CC_MouseCheckPredefColorArray [internal]
234 * returns 1 if one of the predefined colors is clicked
236 static int CC_MouseCheckPredefColorArray( LCCPRIV lpp
, HWND hDlg
, int dlgitem
, int rows
, int cols
,
244 CONV_LPARAMTOPOINT(lParam
, &point
);
245 ClientToScreen(hDlg
, &point
);
246 hwnd
= GetDlgItem(hDlg
, dlgitem
);
247 GetWindowRect(hwnd
, &rect
);
248 if (PtInRect(&rect
, point
))
250 dx
= (rect
.right
- rect
.left
) / cols
;
251 dy
= (rect
.bottom
- rect
.top
) / rows
;
252 ScreenToClient(hwnd
, &point
);
254 if (point
.x
% dx
< ( dx
- DISTANCE
) && point
.y
% dy
< ( dy
- DISTANCE
))
258 lpp
->lpcc
->rgbResult
= predefcolors
[y
][x
];
259 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
266 /***********************************************************************
267 * CC_MouseCheckUserColorArray [internal]
268 * return 1 if the user clicked a color
270 static int CC_MouseCheckUserColorArray( LCCPRIV lpp
, HWND hDlg
, int dlgitem
, int rows
, int cols
,
277 COLORREF
*crarr
= lpp
->lpcc
->lpCustColors
;
279 CONV_LPARAMTOPOINT(lParam
, &point
);
280 ClientToScreen(hDlg
, &point
);
281 hwnd
= GetDlgItem(hDlg
, dlgitem
);
282 GetWindowRect(hwnd
, &rect
);
283 if (PtInRect(&rect
, point
))
285 dx
= (rect
.right
- rect
.left
) / cols
;
286 dy
= (rect
.bottom
- rect
.top
) / rows
;
287 ScreenToClient(hwnd
, &point
);
289 if (point
.x
% dx
< (dx
- DISTANCE
) && point
.y
% dy
< (dy
- DISTANCE
))
293 lpp
->lpcc
->rgbResult
= crarr
[x
+ (cols
* y
) ];
294 CC_DrawFocusRect(lpp
, hwnd
, x
, y
, rows
, cols
);
304 /* 240 ^...... ^^ 240
311 /***********************************************************************
312 * CC_MouseCheckColorGraph [internal]
314 static int CC_MouseCheckColorGraph( HWND hDlg
, int dlgitem
, int *hori
, int *vert
, LPARAM lParam
)
321 CONV_LPARAMTOPOINT(lParam
, &point
);
322 ClientToScreen(hDlg
, &point
);
323 hwnd
= GetDlgItem( hDlg
, dlgitem
);
324 GetWindowRect(hwnd
, &rect
);
325 if (PtInRect(&rect
, point
))
327 GetClientRect(hwnd
, &rect
);
328 ScreenToClient(hwnd
, &point
);
330 x
= (long) point
.x
* MAXHORI
;
332 y
= (long) (rect
.bottom
- point
.y
) * MAXVERT
;
344 /***********************************************************************
345 * CC_MouseCheckResultWindow [internal]
346 * test if double click one of the result colors
348 static int CC_MouseCheckResultWindow( HWND hDlg
, LPARAM lParam
)
354 CONV_LPARAMTOPOINT(lParam
, &point
);
355 ClientToScreen(hDlg
, &point
);
356 hwnd
= GetDlgItem(hDlg
, 0x2c5);
357 GetWindowRect(hwnd
, &rect
);
358 if (PtInRect(&rect
, point
))
360 PostMessageA(hDlg
, WM_COMMAND
, 0x2c9, 0);
366 /***********************************************************************
367 * CC_CheckDigitsInEdit [internal]
369 static int CC_CheckDigitsInEdit( HWND hwnd
, int maxval
)
371 int i
, k
, m
, result
, value
;
375 GetWindowTextA(hwnd
, buffer
, sizeof(buffer
));
379 for (i
= 0 ; i
< m
; i
++)
380 if (buffer
[i
] < '0' || buffer
[i
] > '9')
382 for (k
= i
+ 1; k
<= m
; k
++) /* delete bad character */
384 buffer
[i
] = buffer
[k
];
391 value
= atoi(buffer
);
392 if (value
> maxval
) /* build a new string */
394 sprintf(buffer
, "%d", maxval
);
399 editpos
= SendMessageA(hwnd
, EM_GETSEL
, 0, 0);
400 SetWindowTextA(hwnd
, buffer
);
401 SendMessageA(hwnd
, EM_SETSEL
, 0, editpos
);
408 /***********************************************************************
409 * CC_PaintSelectedColor [internal]
411 static void CC_PaintSelectedColor( HWND hDlg
, COLORREF cr
)
416 HWND hwnd
= GetDlgItem(hDlg
, 0x2c5);
417 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
420 GetClientRect(hwnd
, &rect
) ;
421 hBrush
= CreateSolidBrush(cr
);
424 hBrush
= SelectObject(hdc
, hBrush
) ;
425 Rectangle(hdc
, rect
.left
, rect
.top
, rect
.right
/2, rect
.bottom
);
426 DeleteObject ( SelectObject(hdc
, hBrush
) ) ;
427 hBrush
= CreateSolidBrush( GetNearestColor(hdc
, cr
) );
430 hBrush
= SelectObject(hdc
, hBrush
) ;
431 Rectangle(hdc
, rect
.right
/2-1, rect
.top
, rect
.right
, rect
.bottom
);
432 DeleteObject(SelectObject(hdc
, hBrush
)) ;
435 ReleaseDC(hwnd
, hdc
);
439 /***********************************************************************
440 * CC_PaintTriangle [internal]
442 static void CC_PaintTriangle( HWND hDlg
, int y
)
446 int w
= LOWORD(GetDialogBaseUnits());
451 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
452 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA( hDlg
, DWL_USER
);
454 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6))) /* if full size */
456 GetClientRect(hwnd
, &rect
);
457 height
= rect
.bottom
;
459 points
[0].y
= rect
.top
;
460 points
[0].x
= rect
.right
; /* | /| */
461 ClientToScreen(hwnd
, points
); /* | / | */
462 ScreenToClient(hDlg
, points
); /* |< | */
463 oben
= points
[0].y
; /* | \ | */
465 temp
= (long)height
* (long)y
;
466 points
[0].y
= oben
+ height
- temp
/ (long)MAXVERT
;
467 points
[1].y
= points
[0].y
+ w
;
468 points
[2].y
= points
[0].y
- w
;
469 points
[2].x
= points
[1].x
= points
[0].x
+ w
;
471 FillRect(hDC
, &lpp
->old3angle
, GetClassLongA( hwnd
, GCL_HBRBACKGROUND
));
472 lpp
->old3angle
.left
= points
[0].x
;
473 lpp
->old3angle
.right
= points
[1].x
+ 1;
474 lpp
->old3angle
.top
= points
[2].y
- 1;
475 lpp
->old3angle
.bottom
= points
[1].y
+ 1;
476 Polygon(hDC
, points
, 3);
477 ReleaseDC(hDlg
, hDC
);
482 /***********************************************************************
483 * CC_PaintCross [internal]
485 static void CC_PaintCross( HWND hDlg
, int x
, int y
)
488 int w
= GetDialogBaseUnits();
489 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
490 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA( hDlg
, DWL_USER
);
495 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
497 GetClientRect(hwnd
, &rect
);
499 SelectClipRgn( hDC
, CreateRectRgnIndirect(&rect
));
500 hPen
= CreatePen(PS_SOLID
, 2, 0xffffff); /* -white- color */
501 hPen
= SelectObject(hDC
, hPen
);
502 point
.x
= ((long)rect
.right
* (long)x
) / (long)MAXHORI
;
503 point
.y
= rect
.bottom
- ((long)rect
.bottom
* (long)y
) / (long)MAXVERT
;
504 if ( lpp
->oldcross
.left
!= lpp
->oldcross
.right
)
505 BitBlt(hDC
, lpp
->oldcross
.left
, lpp
->oldcross
.top
,
506 lpp
->oldcross
.right
- lpp
->oldcross
.left
,
507 lpp
->oldcross
.bottom
- lpp
->oldcross
.top
,
508 lpp
->hdcMem
, lpp
->oldcross
.left
, lpp
->oldcross
.top
, SRCCOPY
);
509 lpp
->oldcross
.left
= point
.x
- w
- 1;
510 lpp
->oldcross
.right
= point
.x
+ w
+ 1;
511 lpp
->oldcross
.top
= point
.y
- w
- 1;
512 lpp
->oldcross
.bottom
= point
.y
+ w
+ 1;
514 MoveToEx(hDC
, point
.x
- w
, point
.y
, &p
);
515 LineTo(hDC
, point
.x
+ w
, point
.y
);
516 MoveToEx(hDC
, point
.x
, point
.y
- w
, &p
);
517 LineTo(hDC
, point
.x
, point
.y
+ w
);
518 DeleteObject( SelectObject(hDC
, hPen
)) ;
519 ReleaseDC(hwnd
, hDC
);
528 /***********************************************************************
529 * CC_PrepareColorGraph [internal]
531 static void CC_PrepareColorGraph( HWND hDlg
)
533 int sdif
, hdif
, xdif
, ydif
, r
, g
, b
, hue
, sat
;
534 HWND hwnd
= GetDlgItem(hDlg
, 0x2c6);
535 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
539 HCURSOR hcursor
= SetCursor( LoadCursorA(0, IDC_WAITA
) );
541 GetClientRect(hwnd
, &client
);
543 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
544 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
, client
.right
, client
.bottom
);
545 SelectObject(lpp
->hdcMem
, lpp
->hbmMem
);
547 xdif
= client
.right
/ XSTEPS
;
548 ydif
= client
.bottom
/ YSTEPS
+1;
551 for (rect
.left
= hue
= 0; hue
< 239 + hdif
; hue
+= hdif
)
553 rect
.right
= rect
.left
+ xdif
;
554 rect
.bottom
= client
.bottom
;
555 for(sat
= 0; sat
< 240 + sdif
; sat
+= sdif
)
557 rect
.top
= rect
.bottom
- ydif
;
558 r
= CC_HSLtoRGB('R', hue
, sat
, 120);
559 g
= CC_HSLtoRGB('G', hue
, sat
, 120);
560 b
= CC_HSLtoRGB('B', hue
, sat
, 120);
561 hbrush
= CreateSolidBrush( RGB(r
, g
, b
));
562 FillRect(lpp
->hdcMem
, &rect
, hbrush
);
563 DeleteObject(hbrush
);
564 rect
.bottom
= rect
.top
;
566 rect
.left
= rect
.right
;
568 ReleaseDC(hwnd
, hdc
);
572 /***********************************************************************
573 * CC_PaintColorGraph [internal]
575 static void CC_PaintColorGraph( HWND hDlg
)
577 HWND hwnd
= GetDlgItem( hDlg
, 0x2c6 );
578 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
581 if (IsWindowVisible(hwnd
)) /* if full size */
584 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
587 GetClientRect(hwnd
, &rect
);
589 BitBlt(hDC
, 0, 0, rect
.right
, rect
.bottom
, lpp
->hdcMem
, 0, 0, SRCCOPY
);
591 WARN("choose color: hdcMem is not defined\n");
592 ReleaseDC(hwnd
, hDC
);
596 /***********************************************************************
597 * CC_PaintLumBar [internal]
599 static void CC_PaintLumBar( HWND hDlg
, int hue
, int sat
)
601 HWND hwnd
= GetDlgItem(hDlg
, 0x2be);
603 int lum
, ldif
, ydif
, r
, g
, b
;
607 if (IsWindowVisible(hwnd
))
610 GetClientRect(hwnd
, &client
);
614 ydif
= client
.bottom
/ YSTEPS
+1;
615 for (lum
= 0; lum
< 240 + ldif
; lum
+= ldif
)
617 rect
.top
= max(0, rect
.bottom
- ydif
);
618 r
= CC_HSLtoRGB('R', hue
, sat
, lum
);
619 g
= CC_HSLtoRGB('G', hue
, sat
, lum
);
620 b
= CC_HSLtoRGB('B', hue
, sat
, lum
);
621 hbrush
= CreateSolidBrush( RGB(r
, g
, b
) );
622 FillRect(hDC
, &rect
, hbrush
);
623 DeleteObject(hbrush
);
624 rect
.bottom
= rect
.top
;
626 GetClientRect(hwnd
, &rect
);
627 FrameRect(hDC
, &rect
, GetStockObject(BLACK_BRUSH
) );
628 ReleaseDC(hwnd
, hDC
);
632 /***********************************************************************
633 * CC_EditSetRGB [internal]
635 static void CC_EditSetRGB( HWND hDlg
, COLORREF cr
)
638 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
639 int r
= GetRValue(cr
);
640 int g
= GetGValue(cr
);
641 int b
= GetBValue(cr
);
642 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
644 lpp
->updating
= TRUE
;
645 sprintf(buffer
, "%d", r
);
646 SetWindowTextA( GetDlgItem(hDlg
, 0x2c2), buffer
);
647 sprintf(buffer
, "%d", g
);
648 SetWindowTextA( GetDlgItem(hDlg
, 0x2c3), buffer
);
649 sprintf( buffer
, "%d", b
);
650 SetWindowTextA( GetDlgItem(hDlg
, 0x2c4),buffer
);
651 lpp
->updating
= FALSE
;
655 /***********************************************************************
656 * CC_EditSetHSL [internal]
658 static void CC_EditSetHSL( HWND hDlg
, int h
, int s
, int l
)
661 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
662 lpp
->updating
= TRUE
;
663 if (IsWindowVisible( GetDlgItem(hDlg
, 0x2c6) )) /* if full size */
665 lpp
->updating
= TRUE
;
666 sprintf(buffer
, "%d", h
);
667 SetWindowTextA( GetDlgItem(hDlg
, 0x2bf), buffer
);
668 sprintf(buffer
, "%d", s
);
669 SetWindowTextA( GetDlgItem(hDlg
, 0x2c0), buffer
);
670 sprintf(buffer
, "%d", l
);
671 SetWindowTextA( GetDlgItem(hDlg
, 0x2c1), buffer
);
672 lpp
->updating
= FALSE
;
674 CC_PaintLumBar(hDlg
, h
, s
);
677 /***********************************************************************
678 * CC_SwitchToFullSize [internal]
680 static void CC_SwitchToFullSize( HWND hDlg
, COLORREF result
, LPRECT lprect
)
683 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
685 EnableWindow( GetDlgItem(hDlg
, 0x2cf), FALSE
);
686 CC_PrepareColorGraph(hDlg
);
687 for (i
= 0x2bf; i
< 0x2c5; i
++)
688 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
689 for (i
= 0x2d3; i
< 0x2d9; i
++)
690 ShowWindow( GetDlgItem(hDlg
, i
), SW_SHOW
);
691 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_SHOW
);
692 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_SHOW
);
693 ShowWindow( GetDlgItem(hDlg
, 1090), SW_SHOW
);
696 SetWindowPos(hDlg
, 0, 0, 0, lprect
->right
-lprect
->left
,
697 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
699 ShowWindow( GetDlgItem(hDlg
, 0x2be), SW_SHOW
);
700 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_SHOW
);
702 CC_EditSetRGB(hDlg
, result
);
703 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
704 ShowWindow( GetDlgItem( hDlg
, 0x2c6), SW_SHOW
);
705 UpdateWindow( GetDlgItem(hDlg
, 0x2c6) );
708 /***********************************************************************
709 * CC_PaintPredefColorArray [internal]
710 * Paints the default standard 48 colors
712 static void CC_PaintPredefColorArray( HWND hDlg
, int rows
, int cols
)
714 HWND hwnd
= GetDlgItem(hDlg
, 0x2d0);
719 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
721 GetClientRect(hwnd
, &rect
);
722 dx
= rect
.right
/ cols
;
723 dy
= rect
.bottom
/ rows
;
727 GetClientRect(hwnd
, &rect
);
728 FillRect(hdc
, &rect
, GetClassLongA(hwnd
, GCL_HBRBACKGROUND
));
729 for ( j
= 0; j
< rows
; j
++ )
731 for ( i
= 0; i
< cols
; i
++ )
733 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
736 hBrush
= SelectObject(hdc
, hBrush
);
737 Rectangle(hdc
, rect
.left
, rect
.top
,
738 rect
.left
+ dx
- DISTANCE
, rect
.top
+ dy
- DISTANCE
);
739 rect
.left
= rect
.left
+ dx
;
740 DeleteObject(SelectObject(hdc
, hBrush
)) ;
743 rect
.top
= rect
.top
+ dy
;
746 ReleaseDC(hwnd
, hdc
);
747 if (lpp
->hwndFocus
== hwnd
)
748 CC_DrawCurrentFocusRect(lpp
);
750 /***********************************************************************
751 * CC_PaintUserColorArray [internal]
752 * Paint the 16 user-selected colors
754 static void CC_PaintUserColorArray( HWND hDlg
, int rows
, int cols
, COLORREF
* lpcr
)
756 HWND hwnd
= GetDlgItem(hDlg
, 0x2d1);
761 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
763 GetClientRect(hwnd
, &rect
);
765 dx
= rect
.right
/ cols
;
766 dy
= rect
.bottom
/ rows
;
772 FillRect(hdc
, &rect
, GetClassLongA(hwnd
, GCL_HBRBACKGROUND
) );
773 for (j
= 0; j
< rows
; j
++)
775 for (i
= 0; i
< cols
; i
++)
777 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
780 hBrush
= SelectObject(hdc
, hBrush
) ;
781 Rectangle(hdc
, rect
.left
, rect
.top
,
782 rect
.left
+ dx
- DISTANCE
, rect
.top
+ dy
- DISTANCE
);
783 rect
.left
= rect
.left
+ dx
;
784 DeleteObject( SelectObject(hdc
, hBrush
) ) ;
787 rect
.top
= rect
.top
+ dy
;
790 ReleaseDC(hwnd
, hdc
);
792 if (lpp
->hwndFocus
== hwnd
)
793 CC_DrawCurrentFocusRect(lpp
);
798 /***********************************************************************
799 * CC_HookCallChk [internal]
801 static BOOL
CC_HookCallChk( LPCHOOSECOLORW lpcc
)
804 if(lpcc
->Flags
& CC_ENABLEHOOK
)
811 /***********************************************************************
812 * CC_WMInitDialog [internal]
814 static LONG
CC_WMInitDialog( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, BOOL b16
)
823 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
824 lpp
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct CCPRIVATE
) );
828 CHOOSECOLOR16
*ch16
= (CHOOSECOLOR16
*) lParam
;
829 ch32
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
) );
832 if (lpp
->lpcc16
->lStructSize
!= sizeof(CHOOSECOLOR16
) )
834 EndDialog (hDlg
, 0) ;
837 ch32
->lStructSize
= sizeof(CHOOSECOLORW
);
838 ch32
->hwndOwner
= ch16
->hwndOwner
;
839 ch32
->hInstance
= ch16
->hInstance
;
840 ch32
->lpCustColors
= PTR_SEG_TO_LIN(ch16
->lpCustColors
);
841 ch32
->lpfnHook
= (LPCCHOOKPROC
) ch16
->lpfnHook
; /* only used as flag */
842 ch32
->Flags
= ch16
->Flags
;
845 lpp
->lpcc
= (LPCHOOSECOLORW
) lParam
;
847 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLORW
) )
849 EndDialog (hDlg
, 0) ;
852 SetWindowLongA(hDlg
, DWL_USER
, (LONG
)lpp
);
854 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
855 ShowWindow( GetDlgItem(hDlg
,0x40e), SW_HIDE
);
856 lpp
->msetrgb
= RegisterWindowMessageA(SETRGBSTRING
);
859 cpos
= MAKELONG(5,7); /* init */
860 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
862 for (i
= 0; i
< 6; i
++)
863 for (j
= 0; j
< 8; j
++)
864 if (predefcolors
[i
][j
] == lpp
->lpcc
->rgbResult
)
866 cpos
= MAKELONG(i
,j
);
871 /* FIXME: Draw_a_focus_rect & set_init_values */
874 GetWindowRect(hDlg
, &lpp
->fullsize
);
875 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
877 hwnd
= GetDlgItem(hDlg
, 0x2cf);
878 EnableWindow(hwnd
, FALSE
);
880 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
882 rect
= lpp
->fullsize
;
883 res
= rect
.bottom
- rect
.top
;
884 hwnd
= GetDlgItem(hDlg
, 0x2c6); /* cut at left border */
885 point
.x
= point
.y
= 0;
886 ClientToScreen(hwnd
, &point
);
887 ScreenToClient(hDlg
,&point
);
888 GetClientRect(hDlg
, &rect
);
889 point
.x
+= GetSystemMetrics(SM_CXDLGFRAME
);
890 SetWindowPos(hDlg
, 0, 0, 0, point
.x
, res
, SWP_NOMOVE
|SWP_NOZORDER
);
892 for (i
= 0x2bf; i
< 0x2c5; i
++)
893 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
894 for (i
= 0x2d3; i
< 0x2d9; i
++)
895 ShowWindow( GetDlgItem(hDlg
, i
), SW_HIDE
);
896 ShowWindow( GetDlgItem(hDlg
, 0x2c9), SW_HIDE
);
897 ShowWindow( GetDlgItem(hDlg
, 0x2c8), SW_HIDE
);
898 ShowWindow( GetDlgItem(hDlg
, 0x2c6), SW_HIDE
);
899 ShowWindow( GetDlgItem(hDlg
, 0x2c5), SW_HIDE
);
900 ShowWindow( GetDlgItem(hDlg
, 1090 ), SW_HIDE
);
903 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, NULL
);
905 for (i
= 0x2bf; i
< 0x2c5; i
++)
906 SendMessageA( GetDlgItem(hDlg
, i
), EM_LIMITTEXT
, 3, 0); /* max 3 digits: xyz */
907 if (CC_HookCallChk(lpp
->lpcc
))
910 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
912 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, WM_INITDIALOG
, wParam
, lParam
);
915 /* Set the initial values of the color chooser dialog */
916 r
= GetRValue(lpp
->lpcc
->rgbResult
);
917 g
= GetGValue(lpp
->lpcc
->rgbResult
);
918 b
= GetBValue(lpp
->lpcc
->rgbResult
);
920 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
921 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
922 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
923 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
925 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
926 SetDlgItemInt(hDlg
, 703, lpp
->h
, TRUE
);
927 SetDlgItemInt(hDlg
, 704, lpp
->s
, TRUE
);
928 SetDlgItemInt(hDlg
, 705, lpp
->l
, TRUE
);
929 SetDlgItemInt(hDlg
, 706, r
, TRUE
);
930 SetDlgItemInt(hDlg
, 707, g
, TRUE
);
931 SetDlgItemInt(hDlg
, 708, b
, TRUE
);
933 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
934 CC_PaintTriangle(hDlg
, lpp
->l
);
940 /***********************************************************************
941 * CC_WMCommand [internal]
943 static LRESULT
CC_WMCommand( HWND hDlg
, WPARAM wParam
, LPARAM lParam
, WORD notifyCode
, HWND hwndCtl
)
949 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
950 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam
, lParam
);
953 case 0x2c2: /* edit notify RGB */
956 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
958 i
= CC_CheckDigitsInEdit(hwndCtl
, 255);
959 r
= GetRValue(lpp
->lpcc
->rgbResult
);
960 g
= GetGValue(lpp
->lpcc
->rgbResult
);
961 b
= GetBValue(lpp
->lpcc
->rgbResult
);
965 case 0x2c2: if ((xx
= (i
!= r
))) r
= i
; break;
966 case 0x2c3: if ((xx
= (i
!= g
))) g
= i
; break;
967 case 0x2c4: if ((xx
= (i
!= b
))) b
= i
; break;
969 if (xx
) /* something has changed */
971 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
972 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
973 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
974 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
975 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
976 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
977 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
978 CC_PaintTriangle(hDlg
, lpp
->l
);
983 case 0x2bf: /* edit notify HSL */
986 if (notifyCode
== EN_UPDATE
&& !lpp
->updating
)
988 i
= CC_CheckDigitsInEdit(hwndCtl
, wParam
== 0x2bf ? 239:240);
992 case 0x2bf: if ((xx
= ( i
!= lpp
->h
))) lpp
->h
= i
; break;
993 case 0x2c0: if ((xx
= ( i
!= lpp
->s
))) lpp
->s
= i
; break;
994 case 0x2c1: if ((xx
= ( i
!= lpp
->l
))) lpp
->l
= i
; break;
996 if (xx
) /* something has changed */
998 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
999 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1000 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1001 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1002 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1003 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1004 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1005 CC_PaintTriangle(hDlg
, lpp
->l
);
1011 CC_SwitchToFullSize(hDlg
, lpp
->lpcc
->rgbResult
, &lpp
->fullsize
);
1012 SetFocus( GetDlgItem(hDlg
, 0x2bf));
1015 case 0x2c8: /* add colors ... column by column */
1016 cr
= lpp
->lpcc
->lpCustColors
;
1017 cr
[(lpp
->nextuserdef
% 2) * 8 + lpp
->nextuserdef
/ 2] = lpp
->lpcc
->rgbResult
;
1018 if (++lpp
->nextuserdef
== 16)
1019 lpp
->nextuserdef
= 0;
1020 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1023 case 0x2c9: /* resulting color */
1025 lpp
->lpcc
->rgbResult
= GetNearestColor(hdc
, lpp
->lpcc
->rgbResult
);
1026 ReleaseDC(hDlg
, hdc
);
1027 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1028 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1029 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1030 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1031 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1032 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1033 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1034 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1035 CC_EditSetHSL(hDlg
, lpp
->h
, lpp
->s
, lpp
->l
);
1036 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1037 CC_PaintTriangle(hDlg
, lpp
->l
);
1040 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1041 i
= RegisterWindowMessageA(HELPMSGSTRING
);
1044 if (lpp
->lpcc
->hwndOwner
)
1045 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc16
);
1046 if ( CC_HookCallChk(lpp
->lpcc
))
1047 CallWindowProc16( (WNDPROC16
) lpp
->lpcc16
->lpfnHook
, hDlg
,
1048 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc16
);
1052 if (lpp
->lpcc
->hwndOwner
)
1053 SendMessageA(lpp
->lpcc
->hwndOwner
, i
, 0, (LPARAM
)lpp
->lpcc
);
1054 if ( CC_HookCallChk(lpp
->lpcc
))
1055 CallWindowProcA( (WNDPROC
) lpp
->lpcc
->lpfnHook
, hDlg
,
1056 WM_COMMAND
, psh15
, (LPARAM
)lpp
->lpcc
);
1061 cokmsg
= RegisterWindowMessageA(COLOROKSTRING
);
1064 if (lpp
->lpcc
->hwndOwner
)
1065 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc16
))
1066 break; /* do NOT close */
1070 if (lpp
->lpcc
->hwndOwner
)
1071 if (SendMessageA(lpp
->lpcc
->hwndOwner
, cokmsg
, 0, (LPARAM
)lpp
->lpcc
))
1072 break; /* do NOT close */
1076 BYTE
*ptr
= PTR_SEG_TO_LIN(lpp
->lpcc16
->lpCustColors
);
1077 memcpy(ptr
, lpp
->lpcc
->lpCustColors
, sizeof(COLORREF
)*16);
1078 lpp
->lpcc16
->rgbResult
= lpp
->lpcc
->rgbResult
;
1080 EndDialog(hDlg
, 1) ;
1084 EndDialog(hDlg
, 0) ;
1091 /***********************************************************************
1092 * CC_WMPaint [internal]
1094 static LRESULT
CC_WMPaint( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1098 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1100 hdc
= BeginPaint(hDlg
, &ps
);
1101 /* we have to paint dialog children except text and buttons */
1102 CC_PaintPredefColorArray(hDlg
, 6, 8);
1103 CC_PaintUserColorArray(hDlg
, 2, 8, lpp
->lpcc
->lpCustColors
);
1104 CC_PaintLumBar(hDlg
, lpp
->h
, lpp
->s
);
1105 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1106 CC_PaintTriangle(hDlg
, lpp
->l
);
1107 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1108 CC_PaintColorGraph(hDlg
);
1109 EndPaint(hDlg
, &ps
);
1115 /***********************************************************************
1116 * CC_WMLButtonUp [internal]
1118 static LRESULT
CC_WMLButtonUp( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1120 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1121 if (lpp
->capturedGraph
)
1123 lpp
->capturedGraph
= 0;
1125 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1132 /***********************************************************************
1133 * CC_WMMouseMove [internal]
1135 static LRESULT
CC_WMMouseMove( HWND hDlg
, LPARAM lParam
)
1137 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1140 if (lpp
->capturedGraph
)
1142 int *ptrh
= NULL
, *ptrs
= &lpp
->l
;
1143 if (lpp
->capturedGraph
== 0x2c6)
1148 if (CC_MouseCheckColorGraph( hDlg
, lpp
->capturedGraph
, ptrh
, ptrs
, lParam
))
1150 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1151 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1152 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1153 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1154 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1155 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1156 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1157 CC_PaintTriangle(hDlg
, lpp
->l
);
1158 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1163 lpp
->capturedGraph
= 0;
1169 /***********************************************************************
1170 * CC_WMLButtonDown [internal]
1172 static LRESULT
CC_WMLButtonDown( HWND hDlg
, WPARAM wParam
, LPARAM lParam
)
1174 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1178 if (CC_MouseCheckPredefColorArray(lpp
, hDlg
, 0x2d0, 6, 8, lParam
))
1181 if (CC_MouseCheckUserColorArray(lpp
, hDlg
, 0x2d1, 2, 8, lParam
))
1184 if (CC_MouseCheckColorGraph(hDlg
, 0x2c6, &lpp
->h
, &lpp
->s
, lParam
))
1187 lpp
->capturedGraph
= 0x2c6;
1190 if (CC_MouseCheckColorGraph(hDlg
, 0x2be, NULL
, &lpp
->l
, lParam
))
1193 lpp
->capturedGraph
= 0x2be;
1198 r
= CC_HSLtoRGB('R', lpp
->h
, lpp
->s
, lpp
->l
);
1199 g
= CC_HSLtoRGB('G', lpp
->h
, lpp
->s
, lpp
->l
);
1200 b
= CC_HSLtoRGB('B', lpp
->h
, lpp
->s
, lpp
->l
);
1201 lpp
->lpcc
->rgbResult
= RGB(r
, g
, b
);
1205 r
= GetRValue(lpp
->lpcc
->rgbResult
);
1206 g
= GetGValue(lpp
->lpcc
->rgbResult
);
1207 b
= GetBValue(lpp
->lpcc
->rgbResult
);
1208 lpp
->h
= CC_RGBtoHSL('H', r
, g
, b
);
1209 lpp
->s
= CC_RGBtoHSL('S', r
, g
, b
);
1210 lpp
->l
= CC_RGBtoHSL('L', r
, g
, b
);
1214 CC_EditSetRGB(hDlg
, lpp
->lpcc
->rgbResult
);
1215 CC_EditSetHSL(hDlg
,lpp
->h
, lpp
->s
, lpp
->l
);
1216 CC_PaintCross(hDlg
, lpp
->h
, lpp
->s
);
1217 CC_PaintTriangle(hDlg
, lpp
->l
);
1218 CC_PaintSelectedColor(hDlg
, lpp
->lpcc
->rgbResult
);
1225 /***********************************************************************
1226 * ColorDlgProc32 [internal]
1229 static LRESULT WINAPI
ColorDlgProc( HWND hDlg
, UINT message
,
1230 WPARAM wParam
, LPARAM lParam
)
1234 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1235 if (message
!= WM_INITDIALOG
)
1240 if (CC_HookCallChk(lpp
->lpcc
))
1241 res
= CallWindowProcA( (WNDPROC
)lpp
->lpcc
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1246 /* FIXME: SetRGB message
1247 if (message && message == msetrgb)
1248 return HandleSetRGB(hDlg, lParam);
1254 return CC_WMInitDialog(hDlg
, wParam
, lParam
, FALSE
);
1256 DeleteDC(lpp
->hdcMem
);
1257 DeleteObject(lpp
->hbmMem
);
1258 HeapFree(GetProcessHeap(), 0, lpp
);
1259 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1262 if (CC_WMCommand( hDlg
, wParam
, lParam
, HIWORD(wParam
), (HWND
) lParam
))
1266 if ( CC_WMPaint(hDlg
, wParam
, lParam
))
1269 case WM_LBUTTONDBLCLK
:
1270 if (CC_MouseCheckResultWindow(hDlg
, lParam
))
1274 if (CC_WMMouseMove(hDlg
, lParam
))
1277 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1278 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1281 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1282 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1289 /***********************************************************************
1290 * ColorDlgProc16 (COMMDLG.8)
1292 LRESULT WINAPI
ColorDlgProc16( HWND16 hDlg
, UINT16 message
,
1293 WPARAM16 wParam
, LONG lParam
)
1296 LCCPRIV lpp
= (LCCPRIV
)GetWindowLongA(hDlg
, DWL_USER
);
1297 if (message
!= WM_INITDIALOG
)
1302 if (CC_HookCallChk(lpp
->lpcc
))
1303 res
= CallWindowProc16( (WNDPROC16
)lpp
->lpcc16
->lpfnHook
, hDlg
, message
, wParam
, lParam
);
1308 /* FIXME: SetRGB message
1309 if (message && message == msetrgb)
1310 return HandleSetRGB(hDlg, lParam);
1316 return CC_WMInitDialog(hDlg
, wParam
, lParam
, TRUE
);
1318 DeleteDC(lpp
->hdcMem
);
1319 DeleteObject(lpp
->hbmMem
);
1320 HeapFree(GetProcessHeap(), 0, lpp
->lpcc
);
1321 HeapFree(GetProcessHeap(), 0, lpp
);
1322 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1325 if (CC_WMCommand(hDlg
, wParam
, lParam
, HIWORD(lParam
), (HWND
)LOWORD(lParam
)))
1329 if (CC_WMPaint(hDlg
, wParam
, lParam
))
1332 case WM_LBUTTONDBLCLK
:
1333 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
1337 if (CC_WMMouseMove(hDlg
, lParam
))
1340 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1341 if (CC_WMLButtonUp(hDlg
, wParam
, lParam
))
1344 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1345 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1354 /***********************************************************************
1355 * ChooseColor16 (COMMDLG.5)
1357 BOOL16 WINAPI
ChooseColor16( LPCHOOSECOLOR16 lpChCol
)
1360 HANDLE16 hDlgTmpl16
= 0, hResource16
= 0;
1361 HGLOBAL16 hGlobal16
= 0;
1362 BOOL16 bRet
= FALSE
;
1366 TRACE("ChooseColor\n");
1367 if (!lpChCol
) return FALSE
;
1369 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1370 hDlgTmpl16
= lpChCol
->hInstance
;
1371 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1374 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
1375 PTR_SEG_TO_LIN(lpChCol
->lpTemplateName
),
1378 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1381 if (!(hDlgTmpl16
= LoadResource16(lpChCol
->hInstance
, hResInfo
)))
1383 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1386 hResource16
= hDlgTmpl16
;
1390 HANDLE hResInfo
, hDlgTmpl32
;
1393 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_COLOR", RT_DIALOGA
)))
1395 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1398 if (!(hDlgTmpl32
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1399 !(template32
= LockResource(hDlgTmpl32
)))
1401 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1404 size
= SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo
);
1405 hGlobal16
= GlobalAlloc16(0, size
);
1408 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE
);
1409 ERR("alloc failure for %ld bytes\n", size
);
1412 template = GlobalLock16(hGlobal16
);
1415 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE
);
1416 ERR("global lock failure for %x handle\n", hDlgTmpl16
);
1417 GlobalFree16(hGlobal16
);
1420 ConvertDialog32To16((LPVOID
)template32
, size
, (LPVOID
)template);
1421 hDlgTmpl16
= hGlobal16
;
1424 ptr
= GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR
) 8);
1425 hInst
= GetWindowLongA(lpChCol
->hwndOwner
, GWL_HINSTANCE
);
1426 bRet
= DialogBoxIndirectParam16(hInst
, hDlgTmpl16
, lpChCol
->hwndOwner
,
1427 (DLGPROC16
) ptr
, (DWORD
)lpChCol
);
1428 if (hResource16
) FreeResource16(hDlgTmpl16
);
1431 GlobalUnlock16(hGlobal16
);
1432 GlobalFree16(hGlobal16
);
1437 /***********************************************************************
1438 * ChooseColorW (COMDLG32.2)
1440 BOOL WINAPI
ChooseColorW( LPCHOOSECOLORW lpChCol
)
1444 HANDLE hDlgTmpl
= 0;
1448 TRACE("ChooseColor\n");
1449 if (!lpChCol
) return FALSE
;
1451 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
1453 if (!(template = LockResource(lpChCol
->hInstance
)))
1455 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1459 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
1462 if (!(hResInfo
= FindResourceW(lpChCol
->hInstance
,
1463 lpChCol
->lpTemplateName
,
1466 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1469 if (!(hDlgTmpl
= LoadResource(lpChCol
->hInstance
, hResInfo
)) ||
1470 !(template = LockResource(hDlgTmpl
)))
1472 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1478 HANDLE hResInfo
, hDlgTmpl
;
1479 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_COLOR", RT_DIALOGA
)))
1481 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
1484 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
1485 !(template = LockResource(hDlgTmpl
)))
1487 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
1492 bRet
= DialogBoxIndirectParamW(COMMDLG_hInstance32
, template, lpChCol
->hwndOwner
,
1493 (DLGPROC
)ColorDlgProc
, (DWORD
)lpChCol
);
1497 /***********************************************************************
1498 * ChooseColorA (COMDLG32.1)
1500 BOOL WINAPI
ChooseColorA( LPCHOOSECOLORA lpChCol
)
1504 LPCHOOSECOLORW lpcc
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(CHOOSECOLORW
));
1505 lpcc
->lStructSize
= sizeof(*lpcc
);
1506 lpcc
->hwndOwner
= lpChCol
->hwndOwner
;
1507 lpcc
->hInstance
= lpChCol
->hInstance
;
1508 lpcc
->rgbResult
= lpChCol
->rgbResult
;
1509 lpcc
->lpCustColors
= lpChCol
->lpCustColors
;
1510 lpcc
->Flags
= lpChCol
->Flags
;
1511 lpcc
->lCustData
= lpChCol
->lCustData
;
1512 lpcc
->lpfnHook
= (LPCCHOOKPROC
) lpChCol
->lpfnHook
;
1513 if ((lpcc
->Flags
& CC_ENABLETEMPLATE
) && (lpChCol
->lpTemplateName
)) {
1514 if (HIWORD(lpChCol
->lpTemplateName
))
1515 lpcc
->lpTemplateName
= HEAP_strdupAtoW(GetProcessHeap(), 0, lpChCol
->lpTemplateName
);
1517 lpcc
->lpTemplateName
= (LPWSTR
)lpChCol
->lpTemplateName
;
1520 ret
= ChooseColorW(lpcc
);
1523 lpChCol
->rgbResult
= lpcc
->rgbResult
;
1524 if (HIWORD(lpcc
->lpTemplateName
)) HeapFree(GetProcessHeap(), 0, (LPSTR
)lpcc
->lpTemplateName
);
1525 HeapFree(GetProcessHeap(), 0, lpcc
);