2 * COMMDLG - File Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
21 #include "debugtools.h"
25 DEFAULT_DEBUG_CHANNEL(commdlg)
29 /***********************************************************************
30 * ColorDlgProc [internal]
32 * FIXME: Convert to real 32-bit message processing
34 static LRESULT WINAPI ColorDlgProc(HWND hDlg, UINT msg,
35 WPARAM wParam, LPARAM lParam)
41 if (WINPROC_MapMsg32ATo16( hDlg, msg, wParam,
42 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
44 mp16.lResult = ColorDlgProc16( (HWND16)hDlg, msg16, mp16.wParam, mp16.lParam );
46 WINPROC_UnmapMsg32ATo16( hDlg, msg, wParam, lParam, &mp16 );
50 /***********************************************************************
51 * ChooseColor (COMMDLG.5)
53 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
56 HANDLE16 hDlgTmpl = 0;
57 BOOL16 bRet = FALSE, win32Format = FALSE;
61 TRACE("ChooseColor\n");
62 if (!lpChCol) return FALSE;
64 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
66 if (!(template = LockResource16( lpChCol->hInstance )))
68 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
72 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
75 if (!(hResInfo = FindResource16(lpChCol->hInstance,
76 lpChCol->lpTemplateName,
79 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
82 if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
83 !(template = LockResource16( hDlgTmpl )))
85 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
91 HANDLE hResInfo, hDlgTmpl;
92 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_COLOR", RT_DIALOGA)))
94 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
97 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
98 !(template = LockResource( hDlgTmpl )))
100 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
106 hInst = GetWindowLongA( lpChCol->hwndOwner, GWL_HINSTANCE );
107 hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
109 (DLGPROC16)ColorDlgProc,
110 (DWORD)lpChCol, WIN_PROC_32A );
111 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
112 if (hDlgTmpl) FreeResource16( hDlgTmpl );
118 static const COLORREF predefcolors[6][8]=
120 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
121 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
122 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
123 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
125 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
126 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
127 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
128 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
130 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
131 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
132 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
133 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
138 LPCHOOSECOLOR16 lpcc; /* points to public known data structure */
139 int nextuserdef; /* next free place in user defined color array */
140 HDC16 hdcMem; /* color graph used for BitBlt() */
141 HBITMAP16 hbmMem; /* color graph bitmap */
142 RECT16 fullsize; /* original dialog window size */
143 UINT16 msetrgb; /* # of SETRGBSTRING message (today not used) */
144 RECT16 old3angle; /* last position of l-marker */
145 RECT16 oldcross; /* last position of color/satuation marker */
146 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE procesing */
149 int l; /* for temporary storing of hue,sat,lum */
152 /***********************************************************************
153 * CC_HSLtoRGB [internal]
155 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
162 case 'R':if (hue>80) hue-=80; else hue+=160; break;
163 case 'G':if (hue>160) hue-=160; else hue+=80; break;
168 maxrgb=(256*MIN(120,lum))/120; /* 0 .. 256 */
174 res=(hue-80)* maxrgb; /* 0...10240 */
175 res/=40; /* 0...256 */
182 res=(240-hue)* maxrgb;
185 res=res-maxrgb/2; /* -128...128 */
188 res=maxrgb/2 + (sat*res) /240; /* 0..256 */
191 if (lum>120 && res<256)
192 res+=((lum-120) * (256-res))/120;
197 /***********************************************************************
198 * CC_RGBtoHSL [internal]
200 static int CC_RGBtoHSL(char c,int r,int g,int b)
202 WORD maxi,mini,mmsum,mmdif,result=0;
216 case 'L':mmsum*=120; /* 0...61200=(255+255)*120 */
217 result=mmsum/255; /* 0...240 */
223 if (!mini || maxi==255)
227 result=mmdif*240; /* 0...61200=255*240 */
228 result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
238 iresult=40*(g-b); /* -10200 ... 10200 */
239 iresult/=(int)mmdif; /* -40 .. 40 */
241 iresult+=240; /* 0..40 and 200..240 */
248 iresult+=80; /* 40 .. 120 */
255 iresult+=160; /* 120 .. 200 */
261 return result; /* is this integer arithmetic precise enough ? */
266 /***********************************************************************
267 * CC_MouseCheckPredefColorArray [internal]
269 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
270 LPARAM lParam,COLORREF *cr)
273 POINT16 point = MAKEPOINT16(lParam);
277 ClientToScreen16(hDlg,&point);
278 hwnd=GetDlgItem(hDlg,dlgitem);
279 GetWindowRect16(hwnd,&rect);
280 if (PtInRect16(&rect,point))
282 dx=(rect.right-rect.left)/cols;
283 dy=(rect.bottom-rect.top)/rows;
284 ScreenToClient16(hwnd,&point);
286 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
290 *cr=predefcolors[y][x];
291 /* FIXME: Draw_a_Focus_Rect() */
298 /***********************************************************************
299 * CC_MouseCheckUserColorArray [internal]
301 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
302 LPARAM lParam,COLORREF *cr,COLORREF*crarr)
305 POINT16 point = MAKEPOINT16(lParam);
309 ClientToScreen16(hDlg,&point);
310 hwnd=GetDlgItem(hDlg,dlgitem);
311 GetWindowRect16(hwnd,&rect);
312 if (PtInRect16(&rect,point))
314 dx=(rect.right-rect.left)/cols;
315 dy=(rect.bottom-rect.top)/rows;
316 ScreenToClient16(hwnd,&point);
318 if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
323 /* FIXME: Draw_a_Focus_Rect() */
333 /* 240 ^...... ^^ 240
340 /***********************************************************************
341 * CC_MouseCheckColorGraph [internal]
343 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
346 POINT16 point = MAKEPOINT16(lParam);
350 ClientToScreen16(hDlg,&point);
351 hwnd=GetDlgItem(hDlg,dlgitem);
352 GetWindowRect16(hwnd,&rect);
353 if (PtInRect16(&rect,point))
355 GetClientRect16(hwnd,&rect);
356 ScreenToClient16(hwnd,&point);
358 x=(long)point.x*MAXHORI;
360 y=(long)(rect.bottom-point.y)*MAXVERT;
372 /***********************************************************************
373 * CC_MouseCheckResultWindow [internal]
375 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
378 POINT16 point = MAKEPOINT16(lParam);
381 ClientToScreen16(hDlg,&point);
382 hwnd=GetDlgItem(hDlg,0x2c5);
383 GetWindowRect16(hwnd,&rect);
384 if (PtInRect16(&rect,point))
386 PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
392 /***********************************************************************
393 * CC_CheckDigitsInEdit [internal]
395 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
397 int i,k,m,result,value;
400 GetWindowTextA(hwnd,buffer,sizeof(buffer));
405 if (buffer[i]<'0' || buffer[i]>'9')
407 for (k=i+1;k<=m;k++) /* delete bad character */
417 if (value>maxval) /* build a new string */
419 sprintf(buffer,"%d",maxval);
424 editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
425 SetWindowTextA(hwnd,buffer);
426 SendMessage16(hwnd,EM_SETSEL16,0,editpos);
433 /***********************************************************************
434 * CC_PaintSelectedColor [internal]
436 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
441 HWND hwnd=GetDlgItem(hDlg,0x2c5);
442 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
445 GetClientRect16 (hwnd, &rect) ;
446 hBrush = CreateSolidBrush(cr);
449 hBrush = SelectObject (hdc, hBrush) ;
450 Rectangle(hdc, rect.left,rect.top,rect.right/2,rect.bottom);
451 DeleteObject (SelectObject (hdc,hBrush)) ;
452 hBrush=CreateSolidBrush(GetNearestColor(hdc,cr));
455 hBrush= SelectObject (hdc, hBrush) ;
456 Rectangle( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
457 DeleteObject( SelectObject (hdc, hBrush)) ;
464 /***********************************************************************
465 * CC_PaintTriangle [internal]
467 static void CC_PaintTriangle(HWND16 hDlg,int y)
471 int w=GetDialogBaseUnits();
476 HWND16 hwnd=GetDlgItem(hDlg,0x2be);
477 struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
479 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
481 GetClientRect16(hwnd,&rect);
485 points[0].y=rect.top;
486 points[0].x=rect.right; /* | /| */
487 ClientToScreen16(hwnd,points); /* | / | */
488 ScreenToClient16(hDlg,points); /* |< | */
489 oben=points[0].y; /* | \ | */
491 temp=(long)height*(long)y;
492 points[0].y=oben+height -temp/(long)MAXVERT;
493 points[1].y=points[0].y+w;
494 points[2].y=points[0].y-w;
495 points[2].x=points[1].x=points[0].x + w;
497 if (lpp->old3angle.left)
498 FillRect16(hDC,&lpp->old3angle,GetStockObject(WHITE_BRUSH));
499 lpp->old3angle.left =points[0].x;
500 lpp->old3angle.right =points[1].x+1;
501 lpp->old3angle.top =points[2].y-1;
502 lpp->old3angle.bottom=points[1].y+1;
503 Polygon16(hDC,points,3);
509 /***********************************************************************
510 * CC_PaintCross [internal]
512 static void CC_PaintCross(HWND16 hDlg,int x,int y)
515 int w=GetDialogBaseUnits();
516 HWND16 hwnd=GetDlgItem(hDlg,0x2c6);
517 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
522 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
524 GetClientRect16(hwnd,&rect);
526 SelectClipRgn(hDC,CreateRectRgnIndirect16(&rect));
527 hPen=CreatePen(PS_SOLID,2,0);
528 hPen=SelectObject(hDC,hPen);
529 point.x=((long)rect.right*(long)x)/(long)MAXHORI;
530 point.y=rect.bottom-((long)rect.bottom*(long)y)/(long)MAXVERT;
531 if (lpp->oldcross.left!=lpp->oldcross.right)
532 BitBlt(hDC,lpp->oldcross.left,lpp->oldcross.top,
533 lpp->oldcross.right-lpp->oldcross.left,
534 lpp->oldcross.bottom-lpp->oldcross.top,
535 lpp->hdcMem,lpp->oldcross.left,lpp->oldcross.top,SRCCOPY);
536 lpp->oldcross.left =point.x-w-1;
537 lpp->oldcross.right =point.x+w+1;
538 lpp->oldcross.top =point.y-w-1;
539 lpp->oldcross.bottom=point.y+w+1;
541 MoveTo16(hDC,point.x-w,point.y);
542 LineTo(hDC,point.x+w,point.y);
543 MoveTo16(hDC,point.x,point.y-w);
544 LineTo(hDC,point.x,point.y+w);
545 DeleteObject(SelectObject(hDC,hPen));
555 /***********************************************************************
556 * CC_PrepareColorGraph [internal]
558 static void CC_PrepareColorGraph(HWND16 hDlg)
560 int sdif,hdif,xdif,ydif,r,g,b,hue,sat;
561 HWND hwnd=GetDlgItem(hDlg,0x2c6);
562 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
566 HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
568 GetClientRect16(hwnd,&client);
570 lpp->hdcMem = CreateCompatibleDC(hdc);
571 lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
572 SelectObject(lpp->hdcMem,lpp->hbmMem);
574 xdif=client.right /XSTEPS;
575 ydif=client.bottom/YSTEPS+1;
578 for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
580 rect.right=rect.left+xdif;
581 rect.bottom=client.bottom;
582 for(sat=0;sat<240+sdif;sat+=sdif)
584 rect.top=rect.bottom-ydif;
585 r=CC_HSLtoRGB('R',hue,sat,120);
586 g=CC_HSLtoRGB('G',hue,sat,120);
587 b=CC_HSLtoRGB('B',hue,sat,120);
588 hbrush=CreateSolidBrush(RGB(r,g,b));
589 FillRect16(lpp->hdcMem,&rect,hbrush);
590 DeleteObject(hbrush);
591 rect.bottom=rect.top;
593 rect.left=rect.right;
596 SetCursor16(hcursor);
599 /***********************************************************************
600 * CC_PaintColorGraph [internal]
602 static void CC_PaintColorGraph(HWND16 hDlg)
604 HWND hwnd=GetDlgItem(hDlg,0x2c6);
605 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
608 if (IsWindowVisible(hwnd)) /* if full size */
611 CC_PrepareColorGraph(hDlg); /* should not be necessary */
614 GetClientRect16(hwnd,&rect);
616 BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
618 WARN("choose color: hdcMem is not defined\n");
622 /***********************************************************************
623 * CC_PaintLumBar [internal]
625 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
627 HWND hwnd=GetDlgItem(hDlg,0x2be);
629 int lum,ldif,ydif,r,g,b;
633 if (IsWindowVisible(hwnd))
636 GetClientRect16(hwnd,&client);
640 ydif=client.bottom/YSTEPS+1;
641 for(lum=0;lum<240+ldif;lum+=ldif)
643 rect.top=MAX(0,rect.bottom-ydif);
644 r=CC_HSLtoRGB('R',hue,sat,lum);
645 g=CC_HSLtoRGB('G',hue,sat,lum);
646 b=CC_HSLtoRGB('B',hue,sat,lum);
647 hbrush=CreateSolidBrush(RGB(r,g,b));
648 FillRect16(hDC,&rect,hbrush);
649 DeleteObject(hbrush);
650 rect.bottom=rect.top;
652 GetClientRect16(hwnd,&rect);
653 FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
658 /***********************************************************************
659 * CC_EditSetRGB [internal]
661 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
664 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
668 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
671 sprintf(buffer,"%d",r);
672 SetWindowTextA(GetDlgItem(hDlg,0x2c2),buffer);
673 sprintf(buffer,"%d",g);
674 SetWindowTextA(GetDlgItem(hDlg,0x2c3),buffer);
675 sprintf(buffer,"%d",b);
676 SetWindowTextA(GetDlgItem(hDlg,0x2c4),buffer);
681 /***********************************************************************
682 * CC_EditSetHSL [internal]
684 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
687 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
689 if (IsWindowVisible(GetDlgItem(hDlg,0x2c6))) /* if full size */
692 sprintf(buffer,"%d",h);
693 SetWindowTextA(GetDlgItem(hDlg,0x2bf),buffer);
694 sprintf(buffer,"%d",s);
695 SetWindowTextA(GetDlgItem(hDlg,0x2c0),buffer);
696 sprintf(buffer,"%d",l);
697 SetWindowTextA(GetDlgItem(hDlg,0x2c1),buffer);
700 CC_PaintLumBar(hDlg,h,s);
703 /***********************************************************************
704 * CC_SwitchToFullSize [internal]
706 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
709 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
711 EnableWindow(GetDlgItem(hDlg,0x2cf),FALSE);
712 CC_PrepareColorGraph(hDlg);
713 for (i=0x2bf;i<0x2c5;i++)
714 EnableWindow(GetDlgItem(hDlg,i),TRUE);
715 for (i=0x2d3;i<0x2d9;i++)
716 EnableWindow(GetDlgItem(hDlg,i),TRUE);
717 EnableWindow(GetDlgItem(hDlg,0x2c9),TRUE);
718 EnableWindow(GetDlgItem(hDlg,0x2c8),TRUE);
721 SetWindowPos(hDlg,0,0,0,lprect->right-lprect->left,
722 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
724 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
725 ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
726 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
728 CC_EditSetRGB(hDlg,result);
729 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
732 /***********************************************************************
733 * CC_PaintPredefColorArray [internal]
735 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
737 HWND hwnd=GetDlgItem(hDlg,0x2d0);
743 GetClientRect16(hwnd,&rect);
749 GetClientRect16 (hwnd, &rect) ;
755 hBrush = CreateSolidBrush(predefcolors[j][i]);
758 hBrush = SelectObject (hdc, hBrush) ;
759 Rectangle(hdc, rect.left, rect.top,
760 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
761 rect.left=rect.left+dx;
762 DeleteObject( SelectObject (hdc, hBrush)) ;
765 rect.top=rect.top+dy;
769 /* FIXME: draw_a_focus_rect */
771 /***********************************************************************
772 * CC_PaintUserColorArray [internal]
774 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
776 HWND hwnd=GetDlgItem(hDlg,0x2d1);
782 GetClientRect16(hwnd,&rect);
795 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
798 hBrush = SelectObject (hdc, hBrush) ;
799 Rectangle( hdc, rect.left, rect.top,
800 rect.left+dx-DISTANCE, rect.top+dy-DISTANCE);
801 rect.left=rect.left+dx;
802 DeleteObject( SelectObject (hdc, hBrush)) ;
805 rect.top=rect.top+dy;
810 /* FIXME: draw_a_focus_rect */
815 /***********************************************************************
816 * CC_HookCallChk [internal]
818 static BOOL CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
821 if(lpcc->Flags & CC_ENABLEHOOK)
827 /***********************************************************************
828 * CC_WMInitDialog [internal]
830 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
837 struct CCPRIVATE * lpp;
839 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
840 lpp=calloc(1,sizeof(struct CCPRIVATE));
841 lpp->lpcc=(LPCHOOSECOLOR16)lParam;
843 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
845 EndDialog (hDlg, 0) ;
848 SetWindowLongA(hDlg, DWL_USER, (LONG)lpp);
850 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
851 ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
852 lpp->msetrgb=RegisterWindowMessageA( SETRGBSTRING );
855 cpos=MAKELONG(5,7); /* init */
856 if (lpp->lpcc->Flags & CC_RGBINIT)
860 if (predefcolors[i][j]==lpp->lpcc->rgbResult)
867 /* FIXME: Draw_a_focus_rect & set_init_values */
870 GetWindowRect16(hDlg,&lpp->fullsize);
871 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
873 hwnd=GetDlgItem(hDlg,0x2cf);
874 EnableWindow(hwnd,FALSE);
876 if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
879 res=rect.bottom-rect.top;
880 hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
882 ClientToScreen16(hwnd,&point);
883 ScreenToClient16(hDlg,&point);
884 GetClientRect16(hDlg,&rect);
885 point.x+=GetSystemMetrics(SM_CXDLGFRAME);
886 SetWindowPos(hDlg,0,0,0,point.x,res,SWP_NOMOVE|SWP_NOZORDER);
888 ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
889 ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
892 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
894 for (i=0x2bf;i<0x2c5;i++)
895 SendMessage16(GetDlgItem(hDlg,i),EM_LIMITTEXT16,3,0); /* max 3 digits: xyz */
896 if (CC_HookCallChk(lpp->lpcc))
897 res=CallWindowProc16((WNDPROC16)lpp->lpcc->lpfnHook,hDlg,WM_INITDIALOG,wParam,lParam);
900 /* Set the initial values of the color chooser dialog */
901 r = GetRValue(lpp->lpcc->rgbResult);
902 g = GetGValue(lpp->lpcc->rgbResult);
903 b = GetBValue(lpp->lpcc->rgbResult);
905 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
906 lpp->h=CC_RGBtoHSL('H',r,g,b);
907 lpp->s=CC_RGBtoHSL('S',r,g,b);
908 lpp->l=CC_RGBtoHSL('L',r,g,b);
910 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
911 SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
912 SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
913 SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
914 SetDlgItemInt(hDlg, 706, r, TRUE);
915 SetDlgItemInt(hDlg, 707, g, TRUE);
916 SetDlgItemInt(hDlg, 708, b, TRUE);
918 CC_PaintCross(hDlg,lpp->h,lpp->s);
919 CC_PaintTriangle(hDlg,lpp->l);
924 /***********************************************************************
925 * CC_WMCommand [internal]
927 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
933 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
934 TRACE("CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
937 case 0x2c2: /* edit notify RGB */
940 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
942 i=CC_CheckDigitsInEdit(LOWORD(lParam),255);
943 r=GetRValue(lpp->lpcc->rgbResult);
944 g=GetGValue(lpp->lpcc->rgbResult);
945 b=GetBValue(lpp->lpcc->rgbResult);
949 case 0x2c2:if ((xx=(i!=r))) r=i;break;
950 case 0x2c3:if ((xx=(i!=g))) g=i;break;
951 case 0x2c4:if ((xx=(i!=b))) b=i;break;
953 if (xx) /* something has changed */
955 lpp->lpcc->rgbResult=RGB(r,g,b);
956 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
957 lpp->h=CC_RGBtoHSL('H',r,g,b);
958 lpp->s=CC_RGBtoHSL('S',r,g,b);
959 lpp->l=CC_RGBtoHSL('L',r,g,b);
960 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
961 CC_PaintCross(hDlg,lpp->h,lpp->s);
962 CC_PaintTriangle(hDlg,lpp->l);
967 case 0x2bf: /* edit notify HSL */
970 if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
972 i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
976 case 0x2bf:if ((xx=(i!=lpp->h))) lpp->h=i;break;
977 case 0x2c0:if ((xx=(i!=lpp->s))) lpp->s=i;break;
978 case 0x2c1:if ((xx=(i!=lpp->l))) lpp->l=i;break;
980 if (xx) /* something has changed */
982 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
983 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
984 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
985 lpp->lpcc->rgbResult=RGB(r,g,b);
986 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
987 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
988 CC_PaintCross(hDlg,lpp->h,lpp->s);
989 CC_PaintTriangle(hDlg,lpp->l);
995 CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
996 InvalidateRect( hDlg, NULL, TRUE );
997 SetFocus(GetDlgItem(hDlg,0x2bf));
1000 case 0x2c8: /* add colors ... column by column */
1001 cr=PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors);
1002 cr[(lpp->nextuserdef%2)*8 + lpp->nextuserdef/2]=lpp->lpcc->rgbResult;
1003 if (++lpp->nextuserdef==16)
1005 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1008 case 0x2c9: /* resulting color */
1010 lpp->lpcc->rgbResult=GetNearestColor(hdc,lpp->lpcc->rgbResult);
1011 ReleaseDC(hDlg,hdc);
1012 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1013 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1014 r=GetRValue(lpp->lpcc->rgbResult);
1015 g=GetGValue(lpp->lpcc->rgbResult);
1016 b=GetBValue(lpp->lpcc->rgbResult);
1017 lpp->h=CC_RGBtoHSL('H',r,g,b);
1018 lpp->s=CC_RGBtoHSL('S',r,g,b);
1019 lpp->l=CC_RGBtoHSL('L',r,g,b);
1020 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1021 CC_PaintCross(hDlg,lpp->h,lpp->s);
1022 CC_PaintTriangle(hDlg,lpp->l);
1025 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1026 i=RegisterWindowMessageA( HELPMSGSTRING );
1027 if (lpp->lpcc->hwndOwner)
1028 SendMessage16(lpp->lpcc->hwndOwner,i,0,(LPARAM)lpp->lpcc);
1029 if (CC_HookCallChk(lpp->lpcc))
1030 CallWindowProc16((WNDPROC16)lpp->lpcc->lpfnHook,hDlg,
1031 WM_COMMAND,psh15,(LPARAM)lpp->lpcc);
1035 cokmsg=RegisterWindowMessageA( COLOROKSTRING );
1036 if (lpp->lpcc->hwndOwner)
1037 if (SendMessage16(lpp->lpcc->hwndOwner,cokmsg,0,(LPARAM)lpp->lpcc))
1038 break; /* do NOT close */
1040 EndDialog (hDlg, 1) ;
1044 EndDialog (hDlg, 0) ;
1051 /***********************************************************************
1052 * CC_WMPaint [internal]
1054 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
1058 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
1060 hdc=BeginPaint(hDlg,&ps);
1062 /* we have to paint dialog children except text and buttons */
1064 CC_PaintPredefColorArray(hDlg,6,8);
1065 CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1066 CC_PaintColorGraph(hDlg);
1067 CC_PaintLumBar(hDlg,lpp->h,lpp->s);
1068 CC_PaintCross(hDlg,lpp->h,lpp->s);
1069 CC_PaintTriangle(hDlg,lpp->l);
1070 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1072 /* special necessary for Wine */
1073 ValidateRect(GetDlgItem(hDlg,0x2d0),NULL);
1074 ValidateRect(GetDlgItem(hDlg,0x2d1),NULL);
1075 ValidateRect(GetDlgItem(hDlg,0x2c6),NULL);
1076 ValidateRect(GetDlgItem(hDlg,0x2be),NULL);
1077 ValidateRect(GetDlgItem(hDlg,0x2c5),NULL);
1078 /* hope we can remove it later -->FIXME */
1083 /***********************************************************************
1084 * CC_WMLButtonDown [internal]
1086 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam)
1088 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
1091 if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
1094 if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
1095 PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
1098 if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
1101 if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
1105 r=CC_HSLtoRGB('R',lpp->h,lpp->s,lpp->l);
1106 g=CC_HSLtoRGB('G',lpp->h,lpp->s,lpp->l);
1107 b=CC_HSLtoRGB('B',lpp->h,lpp->s,lpp->l);
1108 lpp->lpcc->rgbResult=RGB(r,g,b);
1112 r=GetRValue(lpp->lpcc->rgbResult);
1113 g=GetGValue(lpp->lpcc->rgbResult);
1114 b=GetBValue(lpp->lpcc->rgbResult);
1115 lpp->h=CC_RGBtoHSL('H',r,g,b);
1116 lpp->s=CC_RGBtoHSL('S',r,g,b);
1117 lpp->l=CC_RGBtoHSL('L',r,g,b);
1121 CC_EditSetRGB(hDlg,lpp->lpcc->rgbResult);
1122 CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
1123 CC_PaintCross(hDlg,lpp->h,lpp->s);
1124 CC_PaintTriangle(hDlg,lpp->l);
1125 CC_PaintSelectedColor(hDlg,lpp->lpcc->rgbResult);
1131 /***********************************************************************
1132 * ColorDlgProc (COMMDLG.8)
1134 LRESULT WINAPI ColorDlgProc16(HWND16 hDlg, UINT16 message,
1135 WPARAM16 wParam, LONG lParam)
1138 struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER);
1139 if (message!=WM_INITDIALOG)
1144 if (CC_HookCallChk(lpp->lpcc))
1145 res=CallWindowProc16((WNDPROC16)lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
1150 /* FIXME: SetRGB message
1151 if (message && message==msetrgb)
1152 return HandleSetRGB(hDlg,lParam);
1158 return CC_WMInitDialog(hDlg,wParam,lParam);
1160 DeleteDC(lpp->hdcMem);
1161 DeleteObject(lpp->hbmMem);
1163 SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
1166 if (CC_WMCommand(hDlg, wParam, lParam))
1170 if (CC_WMPaint(hDlg, wParam, lParam))
1173 case WM_LBUTTONDBLCLK:
1174 if (CC_MouseCheckResultWindow(hDlg,lParam))
1177 case WM_MOUSEMOVE: /* FIXME: calculate new hue,sat,lum (if in color graph) */
1179 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1181 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1182 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1189 /***********************************************************************
1190 * ChooseColorA (COMDLG32.1)
1192 BOOL WINAPI ChooseColorA(LPCHOOSECOLORA lpChCol )
1197 COLORREF* ccref=SEGPTR_ALLOC(64);
1198 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
1200 memset(lpcc16,'\0',sizeof(*lpcc16));
1201 lpcc16->lStructSize=sizeof(*lpcc16);
1202 lpcc16->hwndOwner=lpChCol->hwndOwner;
1203 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
1204 lpcc16->rgbResult=lpChCol->rgbResult;
1205 memcpy(ccref,lpChCol->lpCustColors,64);
1206 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
1207 lpcc16->Flags=lpChCol->Flags;
1208 lpcc16->lCustData=lpChCol->lCustData;
1209 lpcc16->lpfnHook=(LPCCHOOKPROC16)lpChCol->lpfnHook;
1210 if (lpChCol->lpTemplateName)
1211 str = SEGPTR_STRDUP(lpChCol->lpTemplateName );
1212 lpcc16->lpTemplateName=SEGPTR_GET(str);
1214 ret = ChooseColor16(lpcc16);
1217 lpChCol->rgbResult = lpcc16->rgbResult;
1221 memcpy(lpChCol->lpCustColors,ccref,64);
1223 SEGPTR_FREE(lpcc16);
1227 /***********************************************************************
1228 * ChooseColorW (COMDLG32.2)
1230 BOOL WINAPI ChooseColorW(LPCHOOSECOLORW lpChCol )
1235 COLORREF* ccref=SEGPTR_ALLOC(64);
1236 LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
1238 memset(lpcc16,'\0',sizeof(*lpcc16));
1239 lpcc16->lStructSize=sizeof(*lpcc16);
1240 lpcc16->hwndOwner=lpChCol->hwndOwner;
1241 lpcc16->hInstance=MapHModuleLS(lpChCol->hInstance);
1242 lpcc16->rgbResult=lpChCol->rgbResult;
1243 memcpy(ccref,lpChCol->lpCustColors,64);
1244 lpcc16->lpCustColors=(COLORREF*)SEGPTR_GET(ccref);
1245 lpcc16->Flags=lpChCol->Flags;
1246 lpcc16->lCustData=lpChCol->lCustData;
1247 lpcc16->lpfnHook=(LPCCHOOKPROC16)lpChCol->lpfnHook;
1248 if (lpChCol->lpTemplateName)
1249 str = SEGPTR_STRDUP_WtoA(lpChCol->lpTemplateName );
1250 lpcc16->lpTemplateName=SEGPTR_GET(str);
1252 ret = ChooseColor16(lpcc16);
1255 lpChCol->rgbResult = lpcc16->rgbResult;
1259 memcpy(lpChCol->lpCustColors,ccref,64);
1261 SEGPTR_FREE(lpcc16);