2 * COMMDLG - File Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
15 #include "wine/winbase16.h"
16 #include "wine/winuser16.h"
23 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(commdlg
);
31 /***********************************************************************
32 * ColorDlgProc [internal]
34 * FIXME: Convert to real 32-bit message processing
36 static LRESULT WINAPI
ColorDlgProc(HWND hDlg
, UINT msg
,
37 WPARAM wParam
, LPARAM lParam
)
43 if (WINPROC_MapMsg32ATo16( hDlg
, msg
, wParam
,
44 &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
46 mp16
.lResult
= ColorDlgProc16( (HWND16
)hDlg
, msg16
, mp16
.wParam
, mp16
.lParam
);
48 WINPROC_UnmapMsg32ATo16( hDlg
, msg
, wParam
, lParam
, &mp16
);
52 /***********************************************************************
53 * ChooseColor (COMMDLG.5)
55 BOOL16 WINAPI
ChooseColor16(LPCHOOSECOLOR16 lpChCol
)
58 HANDLE16 hDlgTmpl
= 0;
59 BOOL16 bRet
= FALSE
, win32Format
= FALSE
;
63 TRACE("ChooseColor\n");
64 if (!lpChCol
) return FALSE
;
66 if (lpChCol
->Flags
& CC_ENABLETEMPLATEHANDLE
)
68 if (!(template = LockResource16( lpChCol
->hInstance
)))
70 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
74 else if (lpChCol
->Flags
& CC_ENABLETEMPLATE
)
77 if (!(hResInfo
= FindResource16(lpChCol
->hInstance
,
78 lpChCol
->lpTemplateName
,
81 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
84 if (!(hDlgTmpl
= LoadResource16( lpChCol
->hInstance
, hResInfo
)) ||
85 !(template = LockResource16( hDlgTmpl
)))
87 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
93 HANDLE hResInfo
, hDlgTmpl
;
94 if (!(hResInfo
= FindResourceA(COMMDLG_hInstance32
, "CHOOSE_COLOR", RT_DIALOGA
)))
96 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE
);
99 if (!(hDlgTmpl
= LoadResource(COMMDLG_hInstance32
, hResInfo
)) ||
100 !(template = LockResource( hDlgTmpl
)))
102 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE
);
108 hInst
= GetWindowLongA( lpChCol
->hwndOwner
, GWL_HINSTANCE
);
109 hwndDialog
= DIALOG_CreateIndirect( hInst
, template, win32Format
,
111 (DLGPROC16
)ColorDlgProc
,
112 (DWORD
)lpChCol
, WIN_PROC_32A
);
113 if (hwndDialog
) bRet
= DIALOG_DoDialogBox( hwndDialog
, lpChCol
->hwndOwner
);
114 if (hDlgTmpl
) FreeResource16( hDlgTmpl
);
120 static const COLORREF predefcolors
[6][8]=
122 { 0x008080FFL
, 0x0080FFFFL
, 0x0080FF80L
, 0x0080FF00L
,
123 0x00FFFF80L
, 0x00FF8000L
, 0x00C080FFL
, 0x00FF80FFL
},
124 { 0x000000FFL
, 0x0000FFFFL
, 0x0000FF80L
, 0x0040FF00L
,
125 0x00FFFF00L
, 0x00C08000L
, 0x00C08080L
, 0x00FF00FFL
},
127 { 0x00404080L
, 0x004080FFL
, 0x0000FF00L
, 0x00808000L
,
128 0x00804000L
, 0x00FF8080L
, 0x00400080L
, 0x008000FFL
},
129 { 0x00000080L
, 0x000080FFL
, 0x00008000L
, 0x00408000L
,
130 0x00FF0000L
, 0x00A00000L
, 0x00800080L
, 0x00FF0080L
},
132 { 0x00000040L
, 0x00004080L
, 0x00004000L
, 0x00404000L
,
133 0x00800000L
, 0x00400000L
, 0x00400040L
, 0x00800040L
},
134 { 0x00000000L
, 0x00008080L
, 0x00408080L
, 0x00808080L
,
135 0x00808040L
, 0x00C0C0C0L
, 0x00400040L
, 0x00FFFFFFL
},
140 LPCHOOSECOLOR16 lpcc
; /* points to public known data structure */
141 int nextuserdef
; /* next free place in user defined color array */
142 HDC16 hdcMem
; /* color graph used for BitBlt() */
143 HBITMAP16 hbmMem
; /* color graph bitmap */
144 RECT16 fullsize
; /* original dialog window size */
145 UINT16 msetrgb
; /* # of SETRGBSTRING message (today not used) */
146 RECT16 old3angle
; /* last position of l-marker */
147 RECT16 oldcross
; /* last position of color/satuation marker */
148 BOOL updating
; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
151 int l
; /* for temporary storing of hue,sat,lum */
154 /***********************************************************************
155 * CC_HSLtoRGB [internal]
157 static int CC_HSLtoRGB(char c
,int hue
,int sat
,int lum
)
164 case 'R':if (hue
>80) hue
-=80; else hue
+=160; break;
165 case 'G':if (hue
>160) hue
-=160; else hue
+=80; break;
170 maxrgb
=(256*min(120,lum
))/120; /* 0 .. 256 */
176 res
=(hue
-80)* maxrgb
; /* 0...10240 */
177 res
/=40; /* 0...256 */
184 res
=(240-hue
)* maxrgb
;
187 res
=res
-maxrgb
/2; /* -128...128 */
190 res
=maxrgb
/2 + (sat
*res
) /240; /* 0..256 */
193 if (lum
>120 && res
<256)
194 res
+=((lum
-120) * (256-res
))/120;
199 /***********************************************************************
200 * CC_RGBtoHSL [internal]
202 static int CC_RGBtoHSL(char c
,int r
,int g
,int b
)
204 WORD maxi
,mini
,mmsum
,mmdif
,result
=0;
218 case 'L':mmsum
*=120; /* 0...61200=(255+255)*120 */
219 result
=mmsum
/255; /* 0...240 */
225 if (!mini
|| maxi
==255)
229 result
=mmdif
*240; /* 0...61200=255*240 */
230 result
/= (mmsum
>255 ? mmsum
=510-mmsum
: mmsum
); /* 0..255 */
240 iresult
=40*(g
-b
); /* -10200 ... 10200 */
241 iresult
/=(int)mmdif
; /* -40 .. 40 */
243 iresult
+=240; /* 0..40 and 200..240 */
250 iresult
+=80; /* 40 .. 120 */
257 iresult
+=160; /* 120 .. 200 */
263 return result
; /* is this integer arithmetic precise enough ? */
268 /***********************************************************************
269 * CC_MouseCheckPredefColorArray [internal]
271 static int CC_MouseCheckPredefColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
272 LPARAM lParam
,COLORREF
*cr
)
275 POINT16 point
= MAKEPOINT16(lParam
);
279 ClientToScreen16(hDlg
,&point
);
280 hwnd
=GetDlgItem(hDlg
,dlgitem
);
281 GetWindowRect16(hwnd
,&rect
);
282 if (PtInRect16(&rect
,point
))
284 dx
=(rect
.right
-rect
.left
)/cols
;
285 dy
=(rect
.bottom
-rect
.top
)/rows
;
286 ScreenToClient16(hwnd
,&point
);
288 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
292 *cr
=predefcolors
[y
][x
];
293 /* FIXME: Draw_a_Focus_Rect() */
300 /***********************************************************************
301 * CC_MouseCheckUserColorArray [internal]
303 static int CC_MouseCheckUserColorArray(HWND16 hDlg
,int dlgitem
,int rows
,int cols
,
304 LPARAM lParam
,COLORREF
*cr
,COLORREF
*crarr
)
307 POINT16 point
= MAKEPOINT16(lParam
);
311 ClientToScreen16(hDlg
,&point
);
312 hwnd
=GetDlgItem(hDlg
,dlgitem
);
313 GetWindowRect16(hwnd
,&rect
);
314 if (PtInRect16(&rect
,point
))
316 dx
=(rect
.right
-rect
.left
)/cols
;
317 dy
=(rect
.bottom
-rect
.top
)/rows
;
318 ScreenToClient16(hwnd
,&point
);
320 if (point
.x
% dx
< (dx
-DISTANCE
) && point
.y
% dy
< (dy
-DISTANCE
))
325 /* FIXME: Draw_a_Focus_Rect() */
335 /* 240 ^...... ^^ 240
342 /***********************************************************************
343 * CC_MouseCheckColorGraph [internal]
345 static int CC_MouseCheckColorGraph(HWND16 hDlg
,int dlgitem
,int *hori
,int *vert
,LPARAM lParam
)
348 POINT16 point
= MAKEPOINT16(lParam
);
352 ClientToScreen16(hDlg
,&point
);
353 hwnd
=GetDlgItem(hDlg
,dlgitem
);
354 GetWindowRect16(hwnd
,&rect
);
355 if (PtInRect16(&rect
,point
))
357 GetClientRect16(hwnd
,&rect
);
358 ScreenToClient16(hwnd
,&point
);
360 x
=(long)point
.x
*MAXHORI
;
362 y
=(long)(rect
.bottom
-point
.y
)*MAXVERT
;
374 /***********************************************************************
375 * CC_MouseCheckResultWindow [internal]
377 static int CC_MouseCheckResultWindow(HWND16 hDlg
,LPARAM lParam
)
380 POINT16 point
= MAKEPOINT16(lParam
);
383 ClientToScreen16(hDlg
,&point
);
384 hwnd
=GetDlgItem(hDlg
,0x2c5);
385 GetWindowRect16(hwnd
,&rect
);
386 if (PtInRect16(&rect
,point
))
388 PostMessage16(hDlg
,WM_COMMAND
,0x2c9,0);
394 /***********************************************************************
395 * CC_CheckDigitsInEdit [internal]
397 static int CC_CheckDigitsInEdit(HWND16 hwnd
,int maxval
)
399 int i
,k
,m
,result
,value
;
402 GetWindowTextA(hwnd
,buffer
,sizeof(buffer
));
407 if (buffer
[i
]<'0' || buffer
[i
]>'9')
409 for (k
=i
+1;k
<=m
;k
++) /* delete bad character */
419 if (value
>maxval
) /* build a new string */
421 sprintf(buffer
,"%d",maxval
);
426 editpos
=SendMessage16(hwnd
,EM_GETSEL16
,0,0);
427 SetWindowTextA(hwnd
,buffer
);
428 SendMessage16(hwnd
,EM_SETSEL16
,0,editpos
);
435 /***********************************************************************
436 * CC_PaintSelectedColor [internal]
438 static void CC_PaintSelectedColor(HWND16 hDlg
,COLORREF cr
)
443 HWND hwnd
=GetDlgItem(hDlg
,0x2c5);
444 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
447 GetClientRect16 (hwnd
, &rect
) ;
448 hBrush
= CreateSolidBrush(cr
);
451 hBrush
= SelectObject (hdc
, hBrush
) ;
452 Rectangle(hdc
, rect
.left
,rect
.top
,rect
.right
/2,rect
.bottom
);
453 DeleteObject (SelectObject (hdc
,hBrush
)) ;
454 hBrush
=CreateSolidBrush(GetNearestColor(hdc
,cr
));
457 hBrush
= SelectObject (hdc
, hBrush
) ;
458 Rectangle( hdc
, rect
.right
/2-1,rect
.top
,rect
.right
,rect
.bottom
);
459 DeleteObject( SelectObject (hdc
, hBrush
)) ;
466 /***********************************************************************
467 * CC_PaintTriangle [internal]
469 static void CC_PaintTriangle(HWND16 hDlg
,int y
)
473 int w
=GetDialogBaseUnits();
478 HWND16 hwnd
=GetDlgItem(hDlg
,0x2be);
479 struct CCPRIVATE
*lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
481 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
483 GetClientRect16(hwnd
,&rect
);
487 points
[0].y
=rect
.top
;
488 points
[0].x
=rect
.right
; /* | /| */
489 ClientToScreen16(hwnd
,points
); /* | / | */
490 ScreenToClient16(hDlg
,points
); /* |< | */
491 oben
=points
[0].y
; /* | \ | */
493 temp
=(long)height
*(long)y
;
494 points
[0].y
=oben
+height
-temp
/(long)MAXVERT
;
495 points
[1].y
=points
[0].y
+w
;
496 points
[2].y
=points
[0].y
-w
;
497 points
[2].x
=points
[1].x
=points
[0].x
+ w
;
499 if (lpp
->old3angle
.left
)
500 FillRect16(hDC
,&lpp
->old3angle
,GetStockObject(WHITE_BRUSH
));
501 lpp
->old3angle
.left
=points
[0].x
;
502 lpp
->old3angle
.right
=points
[1].x
+1;
503 lpp
->old3angle
.top
=points
[2].y
-1;
504 lpp
->old3angle
.bottom
=points
[1].y
+1;
505 Polygon16(hDC
,points
,3);
511 /***********************************************************************
512 * CC_PaintCross [internal]
514 static void CC_PaintCross(HWND16 hDlg
,int x
,int y
)
517 int w
=GetDialogBaseUnits();
518 HWND16 hwnd
=GetDlgItem(hDlg
,0x2c6);
519 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
524 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
526 GetClientRect16(hwnd
,&rect
);
528 SelectClipRgn(hDC
,CreateRectRgnIndirect16(&rect
));
529 hPen
=CreatePen(PS_SOLID
,2,0);
530 hPen
=SelectObject(hDC
,hPen
);
531 point
.x
=((long)rect
.right
*(long)x
)/(long)MAXHORI
;
532 point
.y
=rect
.bottom
-((long)rect
.bottom
*(long)y
)/(long)MAXVERT
;
533 if (lpp
->oldcross
.left
!=lpp
->oldcross
.right
)
534 BitBlt(hDC
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,
535 lpp
->oldcross
.right
-lpp
->oldcross
.left
,
536 lpp
->oldcross
.bottom
-lpp
->oldcross
.top
,
537 lpp
->hdcMem
,lpp
->oldcross
.left
,lpp
->oldcross
.top
,SRCCOPY
);
538 lpp
->oldcross
.left
=point
.x
-w
-1;
539 lpp
->oldcross
.right
=point
.x
+w
+1;
540 lpp
->oldcross
.top
=point
.y
-w
-1;
541 lpp
->oldcross
.bottom
=point
.y
+w
+1;
543 MoveTo16(hDC
,point
.x
-w
,point
.y
);
544 LineTo(hDC
,point
.x
+w
,point
.y
);
545 MoveTo16(hDC
,point
.x
,point
.y
-w
);
546 LineTo(hDC
,point
.x
,point
.y
+w
);
547 DeleteObject(SelectObject(hDC
,hPen
));
557 /***********************************************************************
558 * CC_PrepareColorGraph [internal]
560 static void CC_PrepareColorGraph(HWND16 hDlg
)
562 int sdif
,hdif
,xdif
,ydif
,r
,g
,b
,hue
,sat
;
563 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
564 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
568 HCURSOR16 hcursor
=SetCursor16(LoadCursor16(0,IDC_WAIT16
));
570 GetClientRect16(hwnd
,&client
);
572 lpp
->hdcMem
= CreateCompatibleDC(hdc
);
573 lpp
->hbmMem
= CreateCompatibleBitmap(hdc
,client
.right
,client
.bottom
);
574 SelectObject(lpp
->hdcMem
,lpp
->hbmMem
);
576 xdif
=client
.right
/XSTEPS
;
577 ydif
=client
.bottom
/YSTEPS
+1;
580 for(rect
.left
=hue
=0;hue
<239+hdif
;hue
+=hdif
)
582 rect
.right
=rect
.left
+xdif
;
583 rect
.bottom
=client
.bottom
;
584 for(sat
=0;sat
<240+sdif
;sat
+=sdif
)
586 rect
.top
=rect
.bottom
-ydif
;
587 r
=CC_HSLtoRGB('R',hue
,sat
,120);
588 g
=CC_HSLtoRGB('G',hue
,sat
,120);
589 b
=CC_HSLtoRGB('B',hue
,sat
,120);
590 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
591 FillRect16(lpp
->hdcMem
,&rect
,hbrush
);
592 DeleteObject(hbrush
);
593 rect
.bottom
=rect
.top
;
595 rect
.left
=rect
.right
;
598 SetCursor16(hcursor
);
601 /***********************************************************************
602 * CC_PaintColorGraph [internal]
604 static void CC_PaintColorGraph(HWND16 hDlg
)
606 HWND hwnd
=GetDlgItem(hDlg
,0x2c6);
607 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
610 if (IsWindowVisible(hwnd
)) /* if full size */
613 CC_PrepareColorGraph(hDlg
); /* should not be necessary */
616 GetClientRect16(hwnd
,&rect
);
618 BitBlt(hDC
,0,0,rect
.right
,rect
.bottom
,lpp
->hdcMem
,0,0,SRCCOPY
);
620 WARN("choose color: hdcMem is not defined\n");
624 /***********************************************************************
625 * CC_PaintLumBar [internal]
627 static void CC_PaintLumBar(HWND16 hDlg
,int hue
,int sat
)
629 HWND hwnd
=GetDlgItem(hDlg
,0x2be);
631 int lum
,ldif
,ydif
,r
,g
,b
;
635 if (IsWindowVisible(hwnd
))
638 GetClientRect16(hwnd
,&client
);
642 ydif
=client
.bottom
/YSTEPS
+1;
643 for(lum
=0;lum
<240+ldif
;lum
+=ldif
)
645 rect
.top
=max(0,rect
.bottom
-ydif
);
646 r
=CC_HSLtoRGB('R',hue
,sat
,lum
);
647 g
=CC_HSLtoRGB('G',hue
,sat
,lum
);
648 b
=CC_HSLtoRGB('B',hue
,sat
,lum
);
649 hbrush
=CreateSolidBrush(RGB(r
,g
,b
));
650 FillRect16(hDC
,&rect
,hbrush
);
651 DeleteObject(hbrush
);
652 rect
.bottom
=rect
.top
;
654 GetClientRect16(hwnd
,&rect
);
655 FrameRect16(hDC
,&rect
,GetStockObject(BLACK_BRUSH
));
660 /***********************************************************************
661 * CC_EditSetRGB [internal]
663 static void CC_EditSetRGB(HWND16 hDlg
,COLORREF cr
)
666 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
670 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
673 sprintf(buffer
,"%d",r
);
674 SetWindowTextA(GetDlgItem(hDlg
,0x2c2),buffer
);
675 sprintf(buffer
,"%d",g
);
676 SetWindowTextA(GetDlgItem(hDlg
,0x2c3),buffer
);
677 sprintf(buffer
,"%d",b
);
678 SetWindowTextA(GetDlgItem(hDlg
,0x2c4),buffer
);
683 /***********************************************************************
684 * CC_EditSetHSL [internal]
686 static void CC_EditSetHSL(HWND16 hDlg
,int h
,int s
,int l
)
689 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
691 if (IsWindowVisible(GetDlgItem(hDlg
,0x2c6))) /* if full size */
694 sprintf(buffer
,"%d",h
);
695 SetWindowTextA(GetDlgItem(hDlg
,0x2bf),buffer
);
696 sprintf(buffer
,"%d",s
);
697 SetWindowTextA(GetDlgItem(hDlg
,0x2c0),buffer
);
698 sprintf(buffer
,"%d",l
);
699 SetWindowTextA(GetDlgItem(hDlg
,0x2c1),buffer
);
702 CC_PaintLumBar(hDlg
,h
,s
);
705 /***********************************************************************
706 * CC_SwitchToFullSize [internal]
708 static void CC_SwitchToFullSize(HWND16 hDlg
,COLORREF result
,LPRECT16 lprect
)
711 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
713 EnableWindow(GetDlgItem(hDlg
,0x2cf),FALSE
);
714 CC_PrepareColorGraph(hDlg
);
715 for (i
=0x2bf;i
<0x2c5;i
++)
716 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
717 for (i
=0x2d3;i
<0x2d9;i
++)
718 EnableWindow(GetDlgItem(hDlg
,i
),TRUE
);
719 EnableWindow(GetDlgItem(hDlg
,0x2c9),TRUE
);
720 EnableWindow(GetDlgItem(hDlg
,0x2c8),TRUE
);
723 SetWindowPos(hDlg
,0,0,0,lprect
->right
-lprect
->left
,
724 lprect
->bottom
-lprect
->top
, SWP_NOMOVE
|SWP_NOZORDER
);
726 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_SHOW
);
727 ShowWindow(GetDlgItem(hDlg
,0x2be),SW_SHOW
);
728 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_SHOW
);
730 CC_EditSetRGB(hDlg
,result
);
731 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
734 /***********************************************************************
735 * CC_PaintPredefColorArray [internal]
737 static void CC_PaintPredefColorArray(HWND16 hDlg
,int rows
,int cols
)
739 HWND hwnd
=GetDlgItem(hDlg
,0x2d0);
745 GetClientRect16(hwnd
,&rect
);
751 GetClientRect16 (hwnd
, &rect
) ;
757 hBrush
= CreateSolidBrush(predefcolors
[j
][i
]);
760 hBrush
= SelectObject (hdc
, hBrush
) ;
761 Rectangle(hdc
, rect
.left
, rect
.top
,
762 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
763 rect
.left
=rect
.left
+dx
;
764 DeleteObject( SelectObject (hdc
, hBrush
)) ;
767 rect
.top
=rect
.top
+dy
;
771 /* FIXME: draw_a_focus_rect */
773 /***********************************************************************
774 * CC_PaintUserColorArray [internal]
776 static void CC_PaintUserColorArray(HWND16 hDlg
,int rows
,int cols
,COLORREF
* lpcr
)
778 HWND hwnd
=GetDlgItem(hDlg
,0x2d1);
784 GetClientRect16(hwnd
,&rect
);
797 hBrush
= CreateSolidBrush(lpcr
[i
+j
*cols
]);
800 hBrush
= SelectObject (hdc
, hBrush
) ;
801 Rectangle( hdc
, rect
.left
, rect
.top
,
802 rect
.left
+dx
-DISTANCE
, rect
.top
+dy
-DISTANCE
);
803 rect
.left
=rect
.left
+dx
;
804 DeleteObject( SelectObject (hdc
, hBrush
)) ;
807 rect
.top
=rect
.top
+dy
;
812 /* FIXME: draw_a_focus_rect */
817 /***********************************************************************
818 * CC_HookCallChk [internal]
820 static BOOL
CC_HookCallChk(LPCHOOSECOLOR16 lpcc
)
823 if(lpcc
->Flags
& CC_ENABLEHOOK
)
829 /***********************************************************************
830 * CC_WMInitDialog [internal]
832 static LONG
CC_WMInitDialog(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
839 struct CCPRIVATE
* lpp
;
841 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam
);
842 lpp
=calloc(1,sizeof(struct CCPRIVATE
));
843 lpp
->lpcc
=(LPCHOOSECOLOR16
)lParam
;
845 if (lpp
->lpcc
->lStructSize
!= sizeof(CHOOSECOLOR16
))
847 EndDialog (hDlg
, 0) ;
850 SetWindowLongA(hDlg
, DWL_USER
, (LONG
)lpp
);
852 if (!(lpp
->lpcc
->Flags
& CC_SHOWHELP
))
853 ShowWindow(GetDlgItem(hDlg
,0x40e),SW_HIDE
);
854 lpp
->msetrgb
=RegisterWindowMessageA( SETRGBSTRING
);
857 cpos
=MAKELONG(5,7); /* init */
858 if (lpp
->lpcc
->Flags
& CC_RGBINIT
)
862 if (predefcolors
[i
][j
]==lpp
->lpcc
->rgbResult
)
869 /* FIXME: Draw_a_focus_rect & set_init_values */
872 GetWindowRect16(hDlg
,&lpp
->fullsize
);
873 if (lpp
->lpcc
->Flags
& CC_FULLOPEN
|| lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
875 hwnd
=GetDlgItem(hDlg
,0x2cf);
876 EnableWindow(hwnd
,FALSE
);
878 if (!(lpp
->lpcc
->Flags
& CC_FULLOPEN
) || lpp
->lpcc
->Flags
& CC_PREVENTFULLOPEN
)
881 res
=rect
.bottom
-rect
.top
;
882 hwnd
=GetDlgItem(hDlg
,0x2c6); /* cut at left border */
884 ClientToScreen16(hwnd
,&point
);
885 ScreenToClient16(hDlg
,&point
);
886 GetClientRect16(hDlg
,&rect
);
887 point
.x
+=GetSystemMetrics(SM_CXDLGFRAME
);
888 SetWindowPos(hDlg
,0,0,0,point
.x
,res
,SWP_NOMOVE
|SWP_NOZORDER
);
890 ShowWindow(GetDlgItem(hDlg
,0x2c6),SW_HIDE
);
891 ShowWindow(GetDlgItem(hDlg
,0x2c5),SW_HIDE
);
894 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,NULL
);
896 for (i
=0x2bf;i
<0x2c5;i
++)
897 SendMessage16(GetDlgItem(hDlg
,i
),EM_LIMITTEXT16
,3,0); /* max 3 digits: xyz */
898 if (CC_HookCallChk(lpp
->lpcc
))
899 res
=CallWindowProc16((WNDPROC16
)lpp
->lpcc
->lpfnHook
,hDlg
,WM_INITDIALOG
,wParam
,lParam
);
902 /* Set the initial values of the color chooser dialog */
903 r
= GetRValue(lpp
->lpcc
->rgbResult
);
904 g
= GetGValue(lpp
->lpcc
->rgbResult
);
905 b
= GetBValue(lpp
->lpcc
->rgbResult
);
907 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
908 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
909 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
910 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
912 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
913 SetDlgItemInt(hDlg
, 703, lpp
->h
, TRUE
);
914 SetDlgItemInt(hDlg
, 704, lpp
->s
, TRUE
);
915 SetDlgItemInt(hDlg
, 705, lpp
->l
, TRUE
);
916 SetDlgItemInt(hDlg
, 706, r
, TRUE
);
917 SetDlgItemInt(hDlg
, 707, g
, TRUE
);
918 SetDlgItemInt(hDlg
, 708, b
, TRUE
);
920 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
921 CC_PaintTriangle(hDlg
,lpp
->l
);
926 /***********************************************************************
927 * CC_WMCommand [internal]
929 static LRESULT
CC_WMCommand(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
935 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
936 TRACE("CC_WMCommand wParam=%x lParam=%lx\n",wParam
,lParam
);
939 case 0x2c2: /* edit notify RGB */
942 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
944 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),255);
945 r
=GetRValue(lpp
->lpcc
->rgbResult
);
946 g
=GetGValue(lpp
->lpcc
->rgbResult
);
947 b
=GetBValue(lpp
->lpcc
->rgbResult
);
951 case 0x2c2:if ((xx
=(i
!=r
))) r
=i
;break;
952 case 0x2c3:if ((xx
=(i
!=g
))) g
=i
;break;
953 case 0x2c4:if ((xx
=(i
!=b
))) b
=i
;break;
955 if (xx
) /* something has changed */
957 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
958 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
959 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
960 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
961 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
962 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
963 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
964 CC_PaintTriangle(hDlg
,lpp
->l
);
969 case 0x2bf: /* edit notify HSL */
972 if (HIWORD(lParam
)==EN_UPDATE
&& !lpp
->updating
)
974 i
=CC_CheckDigitsInEdit(LOWORD(lParam
),wParam
==0x2bf?239:240);
978 case 0x2bf:if ((xx
=(i
!=lpp
->h
))) lpp
->h
=i
;break;
979 case 0x2c0:if ((xx
=(i
!=lpp
->s
))) lpp
->s
=i
;break;
980 case 0x2c1:if ((xx
=(i
!=lpp
->l
))) lpp
->l
=i
;break;
982 if (xx
) /* something has changed */
984 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
985 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
986 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
987 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
988 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
989 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
990 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
991 CC_PaintTriangle(hDlg
,lpp
->l
);
997 CC_SwitchToFullSize(hDlg
,lpp
->lpcc
->rgbResult
,&lpp
->fullsize
);
998 InvalidateRect( hDlg
, NULL
, TRUE
);
999 SetFocus(GetDlgItem(hDlg
,0x2bf));
1002 case 0x2c8: /* add colors ... column by column */
1003 cr
=PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
);
1004 cr
[(lpp
->nextuserdef
%2)*8 + lpp
->nextuserdef
/2]=lpp
->lpcc
->rgbResult
;
1005 if (++lpp
->nextuserdef
==16)
1007 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
1010 case 0x2c9: /* resulting color */
1012 lpp
->lpcc
->rgbResult
=GetNearestColor(hdc
,lpp
->lpcc
->rgbResult
);
1013 ReleaseDC(hDlg
,hdc
);
1014 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1015 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1016 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1017 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1018 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1019 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1020 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1021 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1022 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1023 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1024 CC_PaintTriangle(hDlg
,lpp
->l
);
1027 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1028 i
=RegisterWindowMessageA( HELPMSGSTRING
);
1029 if (lpp
->lpcc
->hwndOwner
)
1030 SendMessage16(lpp
->lpcc
->hwndOwner
,i
,0,(LPARAM
)lpp
->lpcc
);
1031 if (CC_HookCallChk(lpp
->lpcc
))
1032 CallWindowProc16((WNDPROC16
)lpp
->lpcc
->lpfnHook
,hDlg
,
1033 WM_COMMAND
,psh15
,(LPARAM
)lpp
->lpcc
);
1037 cokmsg
=RegisterWindowMessageA( COLOROKSTRING
);
1038 if (lpp
->lpcc
->hwndOwner
)
1039 if (SendMessage16(lpp
->lpcc
->hwndOwner
,cokmsg
,0,(LPARAM
)lpp
->lpcc
))
1040 break; /* do NOT close */
1042 EndDialog (hDlg
, 1) ;
1046 EndDialog (hDlg
, 0) ;
1053 /***********************************************************************
1054 * CC_WMPaint [internal]
1056 static LRESULT
CC_WMPaint(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1060 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
1062 hdc
=BeginPaint(hDlg
,&ps
);
1064 /* we have to paint dialog children except text and buttons */
1066 CC_PaintPredefColorArray(hDlg
,6,8);
1067 CC_PaintUserColorArray(hDlg
,2,8,PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
));
1068 CC_PaintColorGraph(hDlg
);
1069 CC_PaintLumBar(hDlg
,lpp
->h
,lpp
->s
);
1070 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1071 CC_PaintTriangle(hDlg
,lpp
->l
);
1072 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1074 /* special necessary for Wine */
1075 ValidateRect(GetDlgItem(hDlg
,0x2d0),NULL
);
1076 ValidateRect(GetDlgItem(hDlg
,0x2d1),NULL
);
1077 ValidateRect(GetDlgItem(hDlg
,0x2c6),NULL
);
1078 ValidateRect(GetDlgItem(hDlg
,0x2be),NULL
);
1079 ValidateRect(GetDlgItem(hDlg
,0x2c5),NULL
);
1080 /* hope we can remove it later -->FIXME */
1085 /***********************************************************************
1086 * CC_WMLButtonDown [internal]
1088 static LRESULT
CC_WMLButtonDown(HWND16 hDlg
, WPARAM16 wParam
, LPARAM lParam
)
1090 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
1093 if (CC_MouseCheckPredefColorArray(hDlg
,0x2d0,6,8,lParam
,&lpp
->lpcc
->rgbResult
))
1096 if (CC_MouseCheckUserColorArray(hDlg
,0x2d1,2,8,lParam
,&lpp
->lpcc
->rgbResult
,
1097 PTR_SEG_TO_LIN(lpp
->lpcc
->lpCustColors
)))
1100 if (CC_MouseCheckColorGraph(hDlg
,0x2c6,&lpp
->h
,&lpp
->s
,lParam
))
1103 if (CC_MouseCheckColorGraph(hDlg
,0x2be,NULL
,&lpp
->l
,lParam
))
1107 r
=CC_HSLtoRGB('R',lpp
->h
,lpp
->s
,lpp
->l
);
1108 g
=CC_HSLtoRGB('G',lpp
->h
,lpp
->s
,lpp
->l
);
1109 b
=CC_HSLtoRGB('B',lpp
->h
,lpp
->s
,lpp
->l
);
1110 lpp
->lpcc
->rgbResult
=RGB(r
,g
,b
);
1114 r
=GetRValue(lpp
->lpcc
->rgbResult
);
1115 g
=GetGValue(lpp
->lpcc
->rgbResult
);
1116 b
=GetBValue(lpp
->lpcc
->rgbResult
);
1117 lpp
->h
=CC_RGBtoHSL('H',r
,g
,b
);
1118 lpp
->s
=CC_RGBtoHSL('S',r
,g
,b
);
1119 lpp
->l
=CC_RGBtoHSL('L',r
,g
,b
);
1123 CC_EditSetRGB(hDlg
,lpp
->lpcc
->rgbResult
);
1124 CC_EditSetHSL(hDlg
,lpp
->h
,lpp
->s
,lpp
->l
);
1125 CC_PaintCross(hDlg
,lpp
->h
,lpp
->s
);
1126 CC_PaintTriangle(hDlg
,lpp
->l
);
1127 CC_PaintSelectedColor(hDlg
,lpp
->lpcc
->rgbResult
);
1133 /***********************************************************************
1134 * ColorDlgProc (COMMDLG.8)
1136 LRESULT WINAPI
ColorDlgProc16(HWND16 hDlg
, UINT16 message
,
1137 WPARAM16 wParam
, LONG lParam
)
1140 struct CCPRIVATE
* lpp
=(struct CCPRIVATE
*)GetWindowLongA(hDlg
, DWL_USER
);
1141 if (message
!=WM_INITDIALOG
)
1146 if (CC_HookCallChk(lpp
->lpcc
))
1147 res
=CallWindowProc16((WNDPROC16
)lpp
->lpcc
->lpfnHook
,hDlg
,message
,wParam
,lParam
);
1152 /* FIXME: SetRGB message
1153 if (message && message==msetrgb)
1154 return HandleSetRGB(hDlg,lParam);
1160 return CC_WMInitDialog(hDlg
,wParam
,lParam
);
1162 DeleteDC(lpp
->hdcMem
);
1163 DeleteObject(lpp
->hbmMem
);
1165 SetWindowLongA(hDlg
, DWL_USER
, 0L); /* we don't need it anymore */
1168 if (CC_WMCommand(hDlg
, wParam
, lParam
))
1172 if (CC_WMPaint(hDlg
, wParam
, lParam
))
1175 case WM_LBUTTONDBLCLK
:
1176 if (CC_MouseCheckResultWindow(hDlg
,lParam
))
1179 case WM_MOUSEMOVE
: /* FIXME: calculate new hue,sat,lum (if in color graph) */
1181 case WM_LBUTTONUP
: /* FIXME: ClipCursor off (if in color graph)*/
1183 case WM_LBUTTONDOWN
:/* FIXME: ClipCursor on (if in color graph)*/
1184 if (CC_WMLButtonDown(hDlg
, wParam
, lParam
))
1191 /***********************************************************************
1192 * ChooseColorA (COMDLG32.1)
1194 BOOL WINAPI
ChooseColorA(LPCHOOSECOLORA lpChCol
)
1199 COLORREF
* ccref
=SEGPTR_ALLOC(64);
1200 LPCHOOSECOLOR16 lpcc16
=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16
));
1202 memset(lpcc16
,'\0',sizeof(*lpcc16
));
1203 lpcc16
->lStructSize
=sizeof(*lpcc16
);
1204 lpcc16
->hwndOwner
=lpChCol
->hwndOwner
;
1205 lpcc16
->hInstance
=MapHModuleLS(lpChCol
->hInstance
);
1206 lpcc16
->rgbResult
=lpChCol
->rgbResult
;
1207 memcpy(ccref
,lpChCol
->lpCustColors
,64);
1208 lpcc16
->lpCustColors
=(COLORREF
*)SEGPTR_GET(ccref
);
1209 lpcc16
->Flags
=lpChCol
->Flags
;
1210 lpcc16
->lCustData
=lpChCol
->lCustData
;
1211 lpcc16
->lpfnHook
=(LPCCHOOKPROC16
)lpChCol
->lpfnHook
;
1212 if (lpChCol
->lpTemplateName
)
1213 str
= SEGPTR_STRDUP(lpChCol
->lpTemplateName
);
1214 lpcc16
->lpTemplateName
=SEGPTR_GET(str
);
1216 ret
= ChooseColor16(lpcc16
);
1219 lpChCol
->rgbResult
= lpcc16
->rgbResult
;
1223 memcpy(lpChCol
->lpCustColors
,ccref
,64);
1225 SEGPTR_FREE(lpcc16
);
1229 /***********************************************************************
1230 * ChooseColorW (COMDLG32.2)
1232 BOOL WINAPI
ChooseColorW(LPCHOOSECOLORW lpChCol
)
1237 COLORREF
* ccref
=SEGPTR_ALLOC(64);
1238 LPCHOOSECOLOR16 lpcc16
=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16
));
1240 memset(lpcc16
,'\0',sizeof(*lpcc16
));
1241 lpcc16
->lStructSize
=sizeof(*lpcc16
);
1242 lpcc16
->hwndOwner
=lpChCol
->hwndOwner
;
1243 lpcc16
->hInstance
=MapHModuleLS(lpChCol
->hInstance
);
1244 lpcc16
->rgbResult
=lpChCol
->rgbResult
;
1245 memcpy(ccref
,lpChCol
->lpCustColors
,64);
1246 lpcc16
->lpCustColors
=(COLORREF
*)SEGPTR_GET(ccref
);
1247 lpcc16
->Flags
=lpChCol
->Flags
;
1248 lpcc16
->lCustData
=lpChCol
->lCustData
;
1249 lpcc16
->lpfnHook
=(LPCCHOOKPROC16
)lpChCol
->lpfnHook
;
1250 if (lpChCol
->lpTemplateName
)
1251 str
= SEGPTR_STRDUP_WtoA(lpChCol
->lpTemplateName
);
1252 lpcc16
->lpTemplateName
=SEGPTR_GET(str
);
1254 ret
= ChooseColor16(lpcc16
);
1257 lpChCol
->rgbResult
= lpcc16
->rgbResult
;
1261 memcpy(lpChCol
->lpCustColors
,ccref
,64);
1263 SEGPTR_FREE(lpcc16
);