Stubs for LsaFreeMemory, LsaQueryInformationPolicy, LsaClose.
[wine] / dlls / commdlg / colordlg.c
1 /*
2  * COMMDLG - File Dialog
3  *
4  * Copyright 1994 Martin Ayotte
5  * Copyright 1996 Albrecht Kleine
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include "winbase.h"
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
14 #include "ldt.h"
15 #include "heap.h"
16 #include "commdlg.h"
17 #include "resource.h"
18 #include "dialog.h"
19 #include "dlgs.h"
20 #include "module.h"
21 #include "debugtools.h"
22 #include "winproc.h"
23 #include "cderr.h"
24
25 DEFAULT_DEBUG_CHANNEL(commdlg)
26
27 #include "cdlg.h"
28
29 /***********************************************************************
30  *           ColorDlgProc [internal]
31  *
32  * FIXME: Convert to real 32-bit message processing
33  */
34 static LRESULT WINAPI ColorDlgProc(HWND hDlg, UINT msg,
35                                    WPARAM wParam, LPARAM lParam)
36 {
37     UINT16 msg16;
38     MSGPARAM16 mp16;
39
40     mp16.lParam = lParam;
41     if (WINPROC_MapMsg32ATo16( hDlg, msg, wParam,
42                                &msg16, &mp16.wParam, &mp16.lParam ) == -1)
43         return 0;
44     mp16.lResult = ColorDlgProc16( (HWND16)hDlg, msg16, mp16.wParam, mp16.lParam );
45
46     WINPROC_UnmapMsg32ATo16( hDlg, msg, wParam, lParam, &mp16 );
47     return mp16.lResult;
48 }
49
50 /***********************************************************************
51  *           ChooseColor   (COMMDLG.5)
52  */
53 BOOL16 WINAPI ChooseColor16(LPCHOOSECOLOR16 lpChCol)
54 {
55     HINSTANCE16 hInst;
56     HANDLE16 hDlgTmpl = 0;
57     BOOL16 bRet = FALSE, win32Format = FALSE;
58     LPCVOID template;
59     HWND hwndDialog;
60
61     TRACE("ChooseColor\n");
62     if (!lpChCol) return FALSE;    
63
64     if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
65     {
66         if (!(template = LockResource16( lpChCol->hInstance )))
67         {
68             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
69             return FALSE;
70         }
71     }
72     else if (lpChCol->Flags & CC_ENABLETEMPLATE)
73     {
74         HANDLE16 hResInfo;
75         if (!(hResInfo = FindResource16(lpChCol->hInstance,
76                                         lpChCol->lpTemplateName,
77                                         RT_DIALOG16)))
78         {
79             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
80             return FALSE;
81         }
82         if (!(hDlgTmpl = LoadResource16( lpChCol->hInstance, hResInfo )) ||
83             !(template = LockResource16( hDlgTmpl )))
84         {
85             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
86             return FALSE;
87         }
88     }
89     else
90     {
91         HANDLE hResInfo, hDlgTmpl;
92         if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_COLOR", RT_DIALOGA)))
93         {
94             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
95             return FALSE;
96         }
97         if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
98             !(template = LockResource( hDlgTmpl )))
99         {
100             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
101             return FALSE;
102         }
103         win32Format = TRUE;
104     }
105
106     hInst = GetWindowLongA( lpChCol->hwndOwner, GWL_HINSTANCE );
107     hwndDialog = DIALOG_CreateIndirect( hInst, template, win32Format,
108                                         lpChCol->hwndOwner,
109                                         (DLGPROC16)ColorDlgProc,
110                                         (DWORD)lpChCol, WIN_PROC_32A );
111     if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpChCol->hwndOwner);
112     if (hDlgTmpl) FreeResource16( hDlgTmpl );
113
114     return bRet;
115 }
116
117
118 static const COLORREF predefcolors[6][8]=
119 {
120  { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
121    0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
122  { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
123    0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
124
125  { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
126    0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
127  { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
128    0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
129
130  { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
131    0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
132  { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
133    0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
134 };
135
136 struct CCPRIVATE
137 {
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 */
147  int h;
148  int s;
149  int l;               /* for temporary storing of hue,sat,lum */
150 };
151
152 /***********************************************************************
153  *                             CC_HSLtoRGB                    [internal]
154  */
155 static int CC_HSLtoRGB(char c,int hue,int sat,int lum)
156 {
157  int res=0,maxrgb;
158
159  /* hue */
160  switch(c)
161  {
162   case 'R':if (hue>80)  hue-=80;  else hue+=160; break;
163   case 'G':if (hue>160) hue-=160; else hue+=80;  break;
164   case 'B':break;
165  }
166
167  /* l below 120 */
168  maxrgb=(256*MIN(120,lum))/120;  /* 0 .. 256 */
169  if (hue< 80)
170   res=0;
171  else
172   if (hue< 120)
173   {
174    res=(hue-80)* maxrgb;           /* 0...10240 */
175    res/=40;                        /* 0...256 */
176   }
177   else
178    if (hue< 200)
179     res=maxrgb;
180    else
181     {
182      res=(240-hue)* maxrgb;
183      res/=40;
184     }
185  res=res-maxrgb/2;                 /* -128...128 */
186
187  /* saturation */
188  res=maxrgb/2 + (sat*res) /240;    /* 0..256 */
189
190  /* lum above 120 */
191  if (lum>120 && res<256)
192   res+=((lum-120) * (256-res))/120;
193
194  return MIN(res,255);
195 }
196
197 /***********************************************************************
198  *                             CC_RGBtoHSL                    [internal]
199  */
200 static int CC_RGBtoHSL(char c,int r,int g,int b)
201 {
202  WORD maxi,mini,mmsum,mmdif,result=0;
203  int iresult=0;
204
205  maxi=MAX(r,b);
206  maxi=MAX(maxi,g);
207  mini=MIN(r,b);
208  mini=MIN(mini,g);
209
210  mmsum=maxi+mini;
211  mmdif=maxi-mini;
212
213  switch(c)
214  {
215   /* lum */
216   case 'L':mmsum*=120;              /* 0...61200=(255+255)*120 */
217            result=mmsum/255;        /* 0...240 */
218            break;
219   /* saturation */
220   case 'S':if (!mmsum)
221             result=0;
222            else
223             if (!mini || maxi==255)
224              result=240;
225            else
226            {
227             result=mmdif*240;       /* 0...61200=255*240 */
228             result/= (mmsum>255 ? mmsum=510-mmsum : mmsum); /* 0..255 */
229            }
230            break;
231   /* hue */
232   case 'H':if (!mmdif)
233             result=160;
234            else
235            {
236             if (maxi==r)
237             {
238              iresult=40*(g-b);       /* -10200 ... 10200 */
239              iresult/=(int)mmdif;    /* -40 .. 40 */
240              if (iresult<0)
241               iresult+=240;          /* 0..40 and 200..240 */
242             }
243             else
244              if (maxi==g)
245              {
246               iresult=40*(b-r);
247               iresult/=(int)mmdif;
248               iresult+=80;           /* 40 .. 120 */
249              }
250              else
251               if (maxi==b)
252               {
253                iresult=40*(r-g);
254                iresult/=(int)mmdif;
255                iresult+=160;         /* 120 .. 200 */
256               }
257             result=iresult;
258            }
259            break;
260  }
261  return result;    /* is this integer arithmetic precise enough ? */
262 }
263
264 #define DISTANCE 4
265
266 /***********************************************************************
267  *                CC_MouseCheckPredefColorArray               [internal]
268  */
269 static int CC_MouseCheckPredefColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
270             LPARAM lParam,COLORREF *cr)
271 {
272  HWND16 hwnd;
273  POINT16 point = MAKEPOINT16(lParam);
274  RECT16 rect;
275  int dx,dy,x,y;
276
277  ClientToScreen16(hDlg,&point);
278  hwnd=GetDlgItem(hDlg,dlgitem);
279  GetWindowRect16(hwnd,&rect);
280  if (PtInRect16(&rect,point))
281  {
282   dx=(rect.right-rect.left)/cols;
283   dy=(rect.bottom-rect.top)/rows;
284   ScreenToClient16(hwnd,&point);
285
286   if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
287   {
288    x=point.x/dx;
289    y=point.y/dy;
290    *cr=predefcolors[y][x];
291    /* FIXME: Draw_a_Focus_Rect() */
292    return 1;
293   }
294  }
295  return 0;
296 }
297
298 /***********************************************************************
299  *                  CC_MouseCheckUserColorArray               [internal]
300  */
301 static int CC_MouseCheckUserColorArray(HWND16 hDlg,int dlgitem,int rows,int cols,
302             LPARAM lParam,COLORREF *cr,COLORREF*crarr)
303 {
304  HWND16 hwnd;
305  POINT16 point = MAKEPOINT16(lParam);
306  RECT16 rect;
307  int dx,dy,x,y;
308
309  ClientToScreen16(hDlg,&point);
310  hwnd=GetDlgItem(hDlg,dlgitem);
311  GetWindowRect16(hwnd,&rect);
312  if (PtInRect16(&rect,point))
313  {
314   dx=(rect.right-rect.left)/cols;
315   dy=(rect.bottom-rect.top)/rows;
316   ScreenToClient16(hwnd,&point);
317
318   if (point.x % dx < (dx-DISTANCE) && point.y % dy < (dy-DISTANCE))
319   {
320    x=point.x/dx;
321    y=point.y/dy;
322    *cr=crarr[x+cols*y];
323    /* FIXME: Draw_a_Focus_Rect() */
324    return 1;
325   }
326  }
327  return 0;
328 }
329
330 #define MAXVERT  240
331 #define MAXHORI  239
332
333 /*  240  ^......        ^^ 240
334          |     .        ||
335     SAT  |     .        || LUM
336          |     .        ||
337          +-----> 239   ----
338            HUE
339 */
340 /***********************************************************************
341  *                  CC_MouseCheckColorGraph                   [internal]
342  */
343 static int CC_MouseCheckColorGraph(HWND16 hDlg,int dlgitem,int *hori,int *vert,LPARAM lParam)
344 {
345  HWND hwnd;
346  POINT16 point = MAKEPOINT16(lParam);
347  RECT16 rect;
348  long x,y;
349
350  ClientToScreen16(hDlg,&point);
351  hwnd=GetDlgItem(hDlg,dlgitem);
352  GetWindowRect16(hwnd,&rect);
353  if (PtInRect16(&rect,point))
354  {
355   GetClientRect16(hwnd,&rect);
356   ScreenToClient16(hwnd,&point);
357
358   x=(long)point.x*MAXHORI;
359   x/=rect.right;
360   y=(long)(rect.bottom-point.y)*MAXVERT;
361   y/=rect.bottom;
362
363   if (hori)
364    *hori=x;
365   if (vert)
366    *vert=y;
367   return 1;
368  }
369  else
370   return 0;
371 }
372 /***********************************************************************
373  *                  CC_MouseCheckResultWindow                 [internal]
374  */
375 static int CC_MouseCheckResultWindow(HWND16 hDlg,LPARAM lParam)
376 {
377  HWND16 hwnd;
378  POINT16 point = MAKEPOINT16(lParam);
379  RECT16 rect;
380
381  ClientToScreen16(hDlg,&point);
382  hwnd=GetDlgItem(hDlg,0x2c5);
383  GetWindowRect16(hwnd,&rect);
384  if (PtInRect16(&rect,point))
385  {
386   PostMessage16(hDlg,WM_COMMAND,0x2c9,0);
387   return 1;
388  }
389  return 0;
390 }
391
392 /***********************************************************************
393  *                       CC_CheckDigitsInEdit                 [internal]
394  */
395 static int CC_CheckDigitsInEdit(HWND16 hwnd,int maxval)
396 {
397  int i,k,m,result,value;
398  long editpos;
399  char buffer[30];
400  GetWindowTextA(hwnd,buffer,sizeof(buffer));
401  m=strlen(buffer);
402  result=0;
403
404  for (i=0;i<m;i++)
405   if (buffer[i]<'0' || buffer[i]>'9')
406   {
407    for (k=i+1;k<=m;k++)   /* delete bad character */
408    {
409     buffer[i]=buffer[k];
410     m--;
411    }
412    buffer[m]=0;
413    result=1;
414   }
415
416  value=atoi(buffer);
417  if (value>maxval)       /* build a new string */
418  {
419   sprintf(buffer,"%d",maxval);
420   result=2;
421  }
422  if (result)
423  {
424   editpos=SendMessage16(hwnd,EM_GETSEL16,0,0);
425   SetWindowTextA(hwnd,buffer);
426   SendMessage16(hwnd,EM_SETSEL16,0,editpos);
427  }
428  return value;
429 }
430
431
432
433 /***********************************************************************
434  *                    CC_PaintSelectedColor                   [internal]
435  */
436 static void CC_PaintSelectedColor(HWND16 hDlg,COLORREF cr)
437 {
438  RECT16 rect;
439  HDC  hdc;
440  HBRUSH hBrush;
441  HWND hwnd=GetDlgItem(hDlg,0x2c5);
442  if (IsWindowVisible(GetDlgItem(hDlg,0x2c6)))   /* if full size */
443  {
444   hdc=GetDC(hwnd);
445   GetClientRect16 (hwnd, &rect) ;
446   hBrush = CreateSolidBrush(cr);
447   if (hBrush)
448   {
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));
453    if (hBrush)
454    {
455     hBrush= SelectObject (hdc, hBrush) ;
456     Rectangle( hdc, rect.right/2-1,rect.top,rect.right,rect.bottom);
457     DeleteObject( SelectObject (hdc, hBrush)) ;
458    }
459   }
460   ReleaseDC(hwnd,hdc);
461  }
462 }
463
464 /***********************************************************************
465  *                    CC_PaintTriangle                        [internal]
466  */
467 static void CC_PaintTriangle(HWND16 hDlg,int y)
468 {
469  HDC hDC;
470  long temp;
471  int w=GetDialogBaseUnits();
472  POINT16 points[3];
473  int height;
474  int oben;
475  RECT16 rect;
476  HWND16 hwnd=GetDlgItem(hDlg,0x2be);
477  struct CCPRIVATE *lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
478
479  if (IsWindowVisible(GetDlgItem(hDlg,0x2c6)))   /* if full size */
480  {
481    GetClientRect16(hwnd,&rect);
482    height=rect.bottom;
483    hDC=GetDC(hDlg);
484
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;                 /*  | \ |  */
490                                      /*  |  \|  */
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;
496
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);
504    ReleaseDC(hDlg,hDC);
505  }
506 }
507
508
509 /***********************************************************************
510  *                    CC_PaintCross                           [internal]
511  */
512 static void CC_PaintCross(HWND16 hDlg,int x,int y)
513 {
514  HDC hDC;
515  int w=GetDialogBaseUnits();
516  HWND16 hwnd=GetDlgItem(hDlg,0x2c6);
517  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
518  RECT16 rect;
519  POINT16 point;
520  HPEN hPen;
521
522  if (IsWindowVisible(GetDlgItem(hDlg,0x2c6)))   /* if full size */
523  {
524    GetClientRect16(hwnd,&rect);
525    hDC=GetDC(hwnd);
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; 
540
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));
546    ReleaseDC(hwnd,hDC);
547  }
548 }
549
550
551 #define XSTEPS 48
552 #define YSTEPS 24
553
554
555 /***********************************************************************
556  *                    CC_PrepareColorGraph                    [internal]
557  */
558 static void CC_PrepareColorGraph(HWND16 hDlg)    
559 {
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);  
563  HBRUSH hbrush;
564  HDC hdc ;
565  RECT16 rect,client;
566  HCURSOR16 hcursor=SetCursor16(LoadCursor16(0,IDC_WAIT16));
567
568  GetClientRect16(hwnd,&client);
569  hdc=GetDC(hwnd);
570  lpp->hdcMem = CreateCompatibleDC(hdc);
571  lpp->hbmMem = CreateCompatibleBitmap(hdc,client.right,client.bottom);
572  SelectObject(lpp->hdcMem,lpp->hbmMem);
573
574  xdif=client.right /XSTEPS;
575  ydif=client.bottom/YSTEPS+1;
576  hdif=239/XSTEPS;
577  sdif=240/YSTEPS;
578  for(rect.left=hue=0;hue<239+hdif;hue+=hdif)
579  {
580   rect.right=rect.left+xdif;
581   rect.bottom=client.bottom;
582   for(sat=0;sat<240+sdif;sat+=sdif)
583   {
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;
592   }
593   rect.left=rect.right;
594  }
595  ReleaseDC(hwnd,hdc);
596  SetCursor16(hcursor);
597 }
598
599 /***********************************************************************
600  *                          CC_PaintColorGraph                [internal]
601  */
602 static void CC_PaintColorGraph(HWND16 hDlg)
603 {
604  HWND hwnd=GetDlgItem(hDlg,0x2c6);
605  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
606  HDC  hDC;
607  RECT16 rect;
608  if (IsWindowVisible(hwnd))   /* if full size */
609  {
610   if (!lpp->hdcMem)
611    CC_PrepareColorGraph(hDlg);   /* should not be necessary */
612
613   hDC=GetDC(hwnd);
614   GetClientRect16(hwnd,&rect);
615   if (lpp->hdcMem)
616       BitBlt(hDC,0,0,rect.right,rect.bottom,lpp->hdcMem,0,0,SRCCOPY);
617   else
618     WARN("choose color: hdcMem is not defined\n");
619   ReleaseDC(hwnd,hDC);
620  }
621 }
622 /***********************************************************************
623  *                           CC_PaintLumBar                   [internal]
624  */
625 static void CC_PaintLumBar(HWND16 hDlg,int hue,int sat)
626 {
627  HWND hwnd=GetDlgItem(hDlg,0x2be);
628  RECT16 rect,client;
629  int lum,ldif,ydif,r,g,b;
630  HBRUSH hbrush;
631  HDC hDC;
632
633  if (IsWindowVisible(hwnd))
634  {
635   hDC=GetDC(hwnd);
636   GetClientRect16(hwnd,&client);
637   rect=client;
638
639   ldif=240/YSTEPS;
640   ydif=client.bottom/YSTEPS+1;
641   for(lum=0;lum<240+ldif;lum+=ldif)
642   {
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;
651   }
652   GetClientRect16(hwnd,&rect);
653   FrameRect16(hDC,&rect,GetStockObject(BLACK_BRUSH));
654   ReleaseDC(hwnd,hDC);
655  }
656 }
657
658 /***********************************************************************
659  *                             CC_EditSetRGB                  [internal]
660  */
661 static void CC_EditSetRGB(HWND16 hDlg,COLORREF cr)
662 {
663  char buffer[10];
664  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
665  int r=GetRValue(cr);
666  int g=GetGValue(cr);
667  int b=GetBValue(cr);
668  if (IsWindowVisible(GetDlgItem(hDlg,0x2c6)))   /* if full size */
669  {
670    lpp->updating=TRUE;
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);
677    lpp->updating=FALSE;
678  }
679 }
680
681 /***********************************************************************
682  *                             CC_EditSetHSL                  [internal]
683  */
684 static void CC_EditSetHSL(HWND16 hDlg,int h,int s,int l)
685 {
686  char buffer[10];
687  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
688  lpp->updating=TRUE;
689  if (IsWindowVisible(GetDlgItem(hDlg,0x2c6)))   /* if full size */
690  {
691    lpp->updating=TRUE;
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);
698    lpp->updating=FALSE;
699  }
700  CC_PaintLumBar(hDlg,h,s);
701 }
702
703 /***********************************************************************
704  *                       CC_SwitchToFullSize                  [internal]
705  */
706 static void CC_SwitchToFullSize(HWND16 hDlg,COLORREF result,LPRECT16 lprect)
707 {
708  int i;
709  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
710  
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);
719
720  if (lprect)
721   SetWindowPos(hDlg,0,0,0,lprect->right-lprect->left,
722    lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
723
724  ShowWindow(GetDlgItem(hDlg,0x2c6),SW_SHOW);
725  ShowWindow(GetDlgItem(hDlg,0x2be),SW_SHOW);
726  ShowWindow(GetDlgItem(hDlg,0x2c5),SW_SHOW);
727
728  CC_EditSetRGB(hDlg,result);
729  CC_EditSetHSL(hDlg,lpp->h,lpp->s,lpp->l);
730 }
731
732 /***********************************************************************
733  *                           CC_PaintPredefColorArray         [internal]
734  */
735 static void CC_PaintPredefColorArray(HWND16 hDlg,int rows,int cols)
736 {
737  HWND hwnd=GetDlgItem(hDlg,0x2d0);
738  RECT16 rect;
739  HDC  hdc;
740  HBRUSH hBrush;
741  int dx,dy,i,j,k;
742
743  GetClientRect16(hwnd,&rect);
744  dx=rect.right/cols;
745  dy=rect.bottom/rows;
746  k=rect.left;
747
748  hdc=GetDC(hwnd);
749  GetClientRect16 (hwnd, &rect) ;
750
751  for (j=0;j<rows;j++)
752  {
753   for (i=0;i<cols;i++)
754   {
755    hBrush = CreateSolidBrush(predefcolors[j][i]);
756    if (hBrush)
757    {
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)) ;
763    }
764   }
765   rect.top=rect.top+dy;
766   rect.left=k;
767  }
768  ReleaseDC(hwnd,hdc);
769  /* FIXME: draw_a_focus_rect */
770 }
771 /***********************************************************************
772  *                             CC_PaintUserColorArray         [internal]
773  */
774 static void CC_PaintUserColorArray(HWND16 hDlg,int rows,int cols,COLORREF* lpcr)
775 {
776  HWND hwnd=GetDlgItem(hDlg,0x2d1);
777  RECT16 rect;
778  HDC  hdc;
779  HBRUSH hBrush;
780  int dx,dy,i,j,k;
781
782  GetClientRect16(hwnd,&rect);
783
784  dx=rect.right/cols;
785  dy=rect.bottom/rows;
786  k=rect.left;
787
788  hdc=GetDC(hwnd);
789  if (hdc)
790  {
791   for (j=0;j<rows;j++)
792   {
793    for (i=0;i<cols;i++)
794    {
795     hBrush = CreateSolidBrush(lpcr[i+j*cols]);
796     if (hBrush)
797     {
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)) ;
803     }
804    }
805    rect.top=rect.top+dy;
806    rect.left=k;
807   }
808   ReleaseDC(hwnd,hdc);
809  }
810  /* FIXME: draw_a_focus_rect */
811 }
812
813
814
815 /***********************************************************************
816  *                             CC_HookCallChk                 [internal]
817  */
818 static BOOL CC_HookCallChk(LPCHOOSECOLOR16 lpcc)
819 {
820  if (lpcc)
821   if(lpcc->Flags & CC_ENABLEHOOK)
822    if (lpcc->lpfnHook)
823     return TRUE;
824  return FALSE;
825 }
826
827 /***********************************************************************
828  *                            CC_WMInitDialog                 [internal]
829  */
830 static LONG CC_WMInitDialog(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam) 
831 {
832    int i,res;
833    int r, g, b;
834    HWND16 hwnd;
835    RECT16 rect;
836    POINT16 point;
837    struct CCPRIVATE * lpp; 
838    
839    TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
840    lpp=calloc(1,sizeof(struct CCPRIVATE));
841    lpp->lpcc=(LPCHOOSECOLOR16)lParam;
842
843    if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLOR16))
844    {
845       EndDialog (hDlg, 0) ;
846       return FALSE;
847    }
848    SetWindowLongA(hDlg, DWL_USER, (LONG)lpp); 
849
850    if (!(lpp->lpcc->Flags & CC_SHOWHELP))
851       ShowWindow(GetDlgItem(hDlg,0x40e),SW_HIDE);
852    lpp->msetrgb=RegisterWindowMessageA( SETRGBSTRING );
853
854 #if 0
855    cpos=MAKELONG(5,7); /* init */
856    if (lpp->lpcc->Flags & CC_RGBINIT)
857    {
858      for (i=0;i<6;i++)
859        for (j=0;j<8;j++)
860         if (predefcolors[i][j]==lpp->lpcc->rgbResult)
861         {
862           cpos=MAKELONG(i,j);
863           goto found;
864         }
865    }
866    found:
867    /* FIXME: Draw_a_focus_rect & set_init_values */
868 #endif
869
870    GetWindowRect16(hDlg,&lpp->fullsize);
871    if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
872    {
873       hwnd=GetDlgItem(hDlg,0x2cf);
874       EnableWindow(hwnd,FALSE);
875    }
876    if (!(lpp->lpcc->Flags & CC_FULLOPEN) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
877    {
878       rect=lpp->fullsize;
879       res=rect.bottom-rect.top;
880       hwnd=GetDlgItem(hDlg,0x2c6); /* cut at left border */
881       point.x=point.y=0;
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);
887
888       ShowWindow(GetDlgItem(hDlg,0x2c6),SW_HIDE);
889       ShowWindow(GetDlgItem(hDlg,0x2c5),SW_HIDE);
890    }
891    else
892       CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,NULL);
893    res=TRUE;
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);
898
899    
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);
904
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);
909
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);
917
918    CC_PaintCross(hDlg,lpp->h,lpp->s);
919    CC_PaintTriangle(hDlg,lpp->l);
920
921    return res;
922 }
923
924 /***********************************************************************
925  *                              CC_WMCommand                  [internal]
926  */
927 static LRESULT CC_WMCommand(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam) 
928 {
929     int r,g,b,i,xx;
930     UINT16 cokmsg;
931     HDC hdc;
932     COLORREF *cr;
933     struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
934     TRACE("CC_WMCommand wParam=%x lParam=%lx\n",wParam,lParam);
935     switch (wParam)
936     {
937           case 0x2c2:  /* edit notify RGB */
938           case 0x2c3:
939           case 0x2c4:
940                if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
941                          {
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);
946                            xx=0;
947                            switch (wParam)
948                            {
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;
952                            }
953                            if (xx) /* something has changed */
954                            {
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);
963                            }
964                          }
965                  break;
966                  
967           case 0x2bf:  /* edit notify HSL */
968           case 0x2c0:
969           case 0x2c1:
970                if (HIWORD(lParam)==EN_UPDATE && !lpp->updating)
971                          {
972                            i=CC_CheckDigitsInEdit(LOWORD(lParam),wParam==0x2bf?239:240);
973                            xx=0;
974                            switch (wParam)
975                            {
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;
979                            }
980                            if (xx) /* something has changed */
981                            {
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);
990                            }
991                          }
992                break;
993                
994           case 0x2cf:
995                CC_SwitchToFullSize(hDlg,lpp->lpcc->rgbResult,&lpp->fullsize);
996                InvalidateRect( hDlg, NULL, TRUE );
997                SetFocus(GetDlgItem(hDlg,0x2bf));
998                break;
999
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)
1004                    lpp->nextuserdef=0;
1005                CC_PaintUserColorArray(hDlg,2,8,PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors));
1006                break;
1007
1008           case 0x2c9:              /* resulting color */
1009                hdc=GetDC(hDlg);
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);
1023                break;
1024
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);
1032                break;
1033
1034           case IDOK :
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 */
1039
1040                 EndDialog (hDlg, 1) ;
1041                 return TRUE ;
1042         
1043           case IDCANCEL :
1044                 EndDialog (hDlg, 0) ;
1045                 return TRUE ;
1046
1047        }
1048        return FALSE;
1049 }
1050
1051 /***********************************************************************
1052  *                              CC_WMPaint                    [internal]
1053  */
1054 static LRESULT CC_WMPaint(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam) 
1055 {
1056     HDC hdc;
1057     PAINTSTRUCT ps;
1058     struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
1059
1060     hdc=BeginPaint(hDlg,&ps);
1061     EndPaint(hDlg,&ps);
1062     /* we have to paint dialog children except text and buttons */
1063  
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);
1071
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 */
1079  return TRUE;
1080 }
1081
1082
1083 /***********************************************************************
1084  *                              CC_WMLButtonDown              [internal]
1085  */
1086 static LRESULT CC_WMLButtonDown(HWND16 hDlg, WPARAM16 wParam, LPARAM lParam) 
1087 {
1088    struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
1089    int r,g,b,i;
1090    i=0;
1091    if (CC_MouseCheckPredefColorArray(hDlg,0x2d0,6,8,lParam,&lpp->lpcc->rgbResult))
1092       i=1;
1093    else
1094       if (CC_MouseCheckUserColorArray(hDlg,0x2d1,2,8,lParam,&lpp->lpcc->rgbResult,
1095               PTR_SEG_TO_LIN(lpp->lpcc->lpCustColors)))
1096          i=1;
1097       else
1098          if (CC_MouseCheckColorGraph(hDlg,0x2c6,&lpp->h,&lpp->s,lParam))
1099             i=2;
1100          else
1101             if (CC_MouseCheckColorGraph(hDlg,0x2be,NULL,&lpp->l,lParam))
1102                i=2;
1103    if (i==2)
1104    {
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);
1109    }
1110    if (i==1)
1111    {
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);
1118    }
1119    if (i)
1120    {
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);
1126       return TRUE;
1127    }
1128    return FALSE;
1129 }
1130
1131 /***********************************************************************
1132  *           ColorDlgProc   (COMMDLG.8)
1133  */
1134 LRESULT WINAPI ColorDlgProc16(HWND16 hDlg, UINT16 message,
1135                             WPARAM16 wParam, LONG lParam)
1136 {
1137  int res;
1138  struct CCPRIVATE * lpp=(struct CCPRIVATE *)GetWindowLongA(hDlg, DWL_USER); 
1139  if (message!=WM_INITDIALOG)
1140  {
1141   if (!lpp)
1142      return FALSE;
1143   res=0;
1144   if (CC_HookCallChk(lpp->lpcc))
1145      res=CallWindowProc16((WNDPROC16)lpp->lpcc->lpfnHook,hDlg,message,wParam,lParam);
1146   if (res)
1147      return res;
1148  }
1149
1150  /* FIXME: SetRGB message
1151  if (message && message==msetrgb)
1152     return HandleSetRGB(hDlg,lParam);
1153  */
1154
1155  switch (message)
1156         {
1157           case WM_INITDIALOG:
1158                         return CC_WMInitDialog(hDlg,wParam,lParam);
1159           case WM_NCDESTROY:
1160                         DeleteDC(lpp->hdcMem); 
1161                         DeleteObject(lpp->hbmMem); 
1162                         free(lpp);
1163                         SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
1164                         break;
1165           case WM_COMMAND:
1166                         if (CC_WMCommand(hDlg, wParam, lParam))
1167                            return TRUE;
1168                         break;     
1169           case WM_PAINT:
1170                         if (CC_WMPaint(hDlg, wParam, lParam))
1171                            return TRUE;
1172                         break;
1173           case WM_LBUTTONDBLCLK:
1174                         if (CC_MouseCheckResultWindow(hDlg,lParam))
1175                           return TRUE;
1176                         break;
1177           case WM_MOUSEMOVE:  /* FIXME: calculate new hue,sat,lum (if in color graph) */
1178                         break;
1179           case WM_LBUTTONUP:  /* FIXME: ClipCursor off (if in color graph)*/
1180                         break;
1181           case WM_LBUTTONDOWN:/* FIXME: ClipCursor on  (if in color graph)*/
1182                         if (CC_WMLButtonDown(hDlg, wParam, lParam))
1183                            return TRUE;
1184                         break;     
1185         }
1186      return FALSE ;
1187 }
1188
1189 /***********************************************************************
1190  *            ChooseColorA  (COMDLG32.1)
1191  */
1192 BOOL WINAPI ChooseColorA(LPCHOOSECOLORA lpChCol )
1193
1194 {
1195   BOOL16 ret;
1196   char *str = NULL;
1197   COLORREF* ccref=SEGPTR_ALLOC(64);
1198   LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
1199
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);
1213   
1214   ret = ChooseColor16(lpcc16);
1215
1216   if(ret)
1217       lpChCol->rgbResult = lpcc16->rgbResult;
1218
1219   if(str)
1220     SEGPTR_FREE(str);
1221   memcpy(lpChCol->lpCustColors,ccref,64);
1222   SEGPTR_FREE(ccref);
1223   SEGPTR_FREE(lpcc16);
1224   return (BOOL)ret;
1225 }
1226
1227 /***********************************************************************
1228  *            ChooseColorW  (COMDLG32.2)
1229  */
1230 BOOL WINAPI ChooseColorW(LPCHOOSECOLORW lpChCol )
1231
1232 {
1233   BOOL16 ret;
1234   char *str = NULL;
1235   COLORREF* ccref=SEGPTR_ALLOC(64);
1236   LPCHOOSECOLOR16 lpcc16=SEGPTR_ALLOC(sizeof(CHOOSECOLOR16));
1237
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);
1251   
1252   ret = ChooseColor16(lpcc16);
1253
1254   if(ret)
1255       lpChCol->rgbResult = lpcc16->rgbResult;
1256
1257   if(str)
1258     SEGPTR_FREE(str);
1259   memcpy(lpChCol->lpCustColors,ccref,64);
1260   SEGPTR_FREE(ccref);
1261   SEGPTR_FREE(lpcc16);
1262   return (BOOL)ret;
1263 }