- Convert HDRVR to a void*.
[wine/multimedia.git] / dlls / commdlg / colordlg.c
blob4e079a02b7fff4cbd926de4d1f515ccb72b409ee
1 /*
2 * COMMDLG - Color Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* BUGS : still seems to not refresh correctly
23 sometimes, especially when 2 instances of the
24 dialog are loaded at the same time */
26 #include <ctype.h>
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include "windef.h"
31 #include "winbase.h"
32 #include "wingdi.h"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
35 #include "commdlg.h"
36 #include "dlgs.h"
37 #include "wine/debug.h"
38 #include "cderr.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
42 #include "cdlg.h"
44 static LRESULT WINAPI ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
46 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = SLOWORD(lp); (p)->y = SHIWORD(lp); } while(0)
48 static const COLORREF predefcolors[6][8]=
50 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
51 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
52 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
53 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
55 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
56 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
57 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
58 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
60 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
61 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
62 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
63 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
66 struct CCPRIVATE
68 LPCHOOSECOLORW lpcc; /* points to public known data structure */
69 LPCHOOSECOLOR16 lpcc16; /* save the 16 bits pointer */
70 int nextuserdef; /* next free place in user defined color array */
71 HDC hdcMem; /* color graph used for BitBlt() */
72 HBITMAP hbmMem; /* color graph bitmap */
73 RECT fullsize; /* original dialog window size */
74 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
75 RECT old3angle; /* last position of l-marker */
76 RECT oldcross; /* last position of color/satuation marker */
77 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
78 int h;
79 int s;
80 int l; /* for temporary storing of hue,sat,lum */
81 int capturedGraph; /* control mouse captured */
82 RECT focusRect; /* rectangle last focused item */
83 HWND hwndFocus; /* handle last focused item */
86 #define LCCPRIV struct CCPRIVATE *
88 /***********************************************************************
89 * CC_HSLtoRGB [internal]
91 static int CC_HSLtoRGB(char c, int hue, int sat, int lum)
93 int res = 0, maxrgb;
95 /* hue */
96 switch(c)
98 case 'R': if (hue > 80) hue -= 80; else hue += 160; break;
99 case 'G': if (hue > 160) hue -= 160; else hue += 80; break;
100 case 'B': break;
103 /* l below 120 */
104 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
105 if (hue < 80)
106 res = 0;
107 else
108 if (hue < 120)
110 res = (hue - 80) * maxrgb; /* 0...10240 */
111 res /= 40; /* 0...256 */
113 else
114 if (hue < 200)
115 res = maxrgb;
116 else
118 res= (240 - hue) * maxrgb;
119 res /= 40;
121 res = res - maxrgb / 2; /* -128...128 */
123 /* saturation */
124 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
126 /* lum above 120 */
127 if (lum > 120 && res < 256)
128 res += ((lum - 120) * (256 - res)) / 120;
130 return min(res, 255);
133 /***********************************************************************
134 * CC_RGBtoHSL [internal]
136 static int CC_RGBtoHSL(char c, int r, int g, int b)
138 WORD maxi, mini, mmsum, mmdif, result = 0;
139 int iresult = 0;
141 maxi = max(r, b);
142 maxi = max(maxi, g);
143 mini = min(r, b);
144 mini = min(mini, g);
146 mmsum = maxi + mini;
147 mmdif = maxi - mini;
149 switch(c)
151 /* lum */
152 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
153 result = mmsum / 255; /* 0...240 */
154 break;
155 /* saturation */
156 case 'S': if (!mmsum)
157 result = 0;
158 else
159 if (!mini || maxi == 255)
160 result = 240;
161 else
163 result = mmdif * 240; /* 0...61200=255*240 */
164 result /= (mmsum > 255 ? mmsum = 510 - mmsum : mmsum); /* 0..255 */
166 break;
167 /* hue */
168 case 'H': if (!mmdif)
169 result = 160;
170 else
172 if (maxi == r)
174 iresult = 40 * (g - b); /* -10200 ... 10200 */
175 iresult /= (int) mmdif; /* -40 .. 40 */
176 if (iresult < 0)
177 iresult += 240; /* 0..40 and 200..240 */
179 else
180 if (maxi == g)
182 iresult = 40 * (b - r);
183 iresult /= (int) mmdif;
184 iresult += 80; /* 40 .. 120 */
186 else
187 if (maxi == b)
189 iresult = 40 * (r - g);
190 iresult /= (int) mmdif;
191 iresult += 160; /* 120 .. 200 */
193 result = iresult;
195 break;
197 return result; /* is this integer arithmetic precise enough ? */
201 /***********************************************************************
202 * CC_DrawCurrentFocusRect [internal]
204 void CC_DrawCurrentFocusRect( LCCPRIV lpp )
206 if (lpp->hwndFocus)
208 HDC hdc = GetDC(lpp->hwndFocus);
209 DrawFocusRect(hdc, &lpp->focusRect);
210 ReleaseDC(lpp->hwndFocus, hdc);
214 /***********************************************************************
215 * CC_DrawFocusRect [internal]
217 void CC_DrawFocusRect( LCCPRIV lpp, HWND hwnd, int x, int y, int rows, int cols)
219 RECT rect;
220 int dx, dy;
221 HDC hdc;
223 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
224 /* calculate new rect */
225 GetClientRect(hwnd, &rect);
226 dx = (rect.right - rect.left) / cols;
227 dy = (rect.bottom - rect.top) / rows;
228 rect.left += (x * dx) - 2;
229 rect.top += (y * dy) - 2;
230 rect.right = rect.left + dx;
231 rect.bottom = rect.top + dy;
232 /* draw it */
233 hdc = GetDC(hwnd);
234 DrawFocusRect(hdc, &rect);
235 CopyRect(&lpp->focusRect, &rect);
236 lpp->hwndFocus = hwnd;
237 ReleaseDC(hwnd, hdc);
240 #define DISTANCE 4
242 /***********************************************************************
243 * CC_MouseCheckPredefColorArray [internal]
244 * returns 1 if one of the predefined colors is clicked
246 static int CC_MouseCheckPredefColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
247 LPARAM lParam )
249 HWND hwnd;
250 POINT point;
251 RECT rect;
252 int dx, dy, x, y;
254 CONV_LPARAMTOPOINT(lParam, &point);
255 ClientToScreen(hDlg, &point);
256 hwnd = GetDlgItem(hDlg, dlgitem);
257 GetWindowRect(hwnd, &rect);
258 if (PtInRect(&rect, point))
260 dx = (rect.right - rect.left) / cols;
261 dy = (rect.bottom - rect.top) / rows;
262 ScreenToClient(hwnd, &point);
264 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
266 x = point.x / dx;
267 y = point.y / dy;
268 lpp->lpcc->rgbResult = predefcolors[y][x];
269 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
270 return 1;
273 return 0;
276 /***********************************************************************
277 * CC_MouseCheckUserColorArray [internal]
278 * return 1 if the user clicked a color
280 static int CC_MouseCheckUserColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
281 LPARAM lParam )
283 HWND hwnd;
284 POINT point;
285 RECT rect;
286 int dx, dy, x, y;
287 COLORREF *crarr = lpp->lpcc->lpCustColors;
289 CONV_LPARAMTOPOINT(lParam, &point);
290 ClientToScreen(hDlg, &point);
291 hwnd = GetDlgItem(hDlg, dlgitem);
292 GetWindowRect(hwnd, &rect);
293 if (PtInRect(&rect, point))
295 dx = (rect.right - rect.left) / cols;
296 dy = (rect.bottom - rect.top) / rows;
297 ScreenToClient(hwnd, &point);
299 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
301 x = point.x / dx;
302 y = point.y / dy;
303 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
304 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
305 return 1;
308 return 0;
311 #define MAXVERT 240
312 #define MAXHORI 239
314 /* 240 ^...... ^^ 240
315 | . ||
316 SAT | . || LUM
317 | . ||
318 +-----> 239 ----
321 /***********************************************************************
322 * CC_MouseCheckColorGraph [internal]
324 static int CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
326 HWND hwnd;
327 POINT point;
328 RECT rect;
329 long x,y;
331 CONV_LPARAMTOPOINT(lParam, &point);
332 ClientToScreen(hDlg, &point);
333 hwnd = GetDlgItem( hDlg, dlgitem );
334 GetWindowRect(hwnd, &rect);
335 if (PtInRect(&rect, point))
337 GetClientRect(hwnd, &rect);
338 ScreenToClient(hwnd, &point);
340 x = (long) point.x * MAXHORI;
341 x /= rect.right;
342 y = (long) (rect.bottom - point.y) * MAXVERT;
343 y /= rect.bottom;
345 if (hori)
346 *hori = x;
347 if (vert)
348 *vert = y;
349 return 1;
351 else
352 return 0;
354 /***********************************************************************
355 * CC_MouseCheckResultWindow [internal]
356 * test if double click one of the result colors
358 static int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
360 HWND hwnd;
361 POINT point;
362 RECT rect;
364 CONV_LPARAMTOPOINT(lParam, &point);
365 ClientToScreen(hDlg, &point);
366 hwnd = GetDlgItem(hDlg, 0x2c5);
367 GetWindowRect(hwnd, &rect);
368 if (PtInRect(&rect, point))
370 PostMessageA(hDlg, WM_COMMAND, 0x2c9, 0);
371 return 1;
373 return 0;
376 /***********************************************************************
377 * CC_CheckDigitsInEdit [internal]
379 static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
381 int i, k, m, result, value;
382 long editpos;
383 char buffer[30];
385 GetWindowTextA(hwnd, buffer, sizeof(buffer));
386 m = strlen(buffer);
387 result = 0;
389 for (i = 0 ; i < m ; i++)
390 if (buffer[i] < '0' || buffer[i] > '9')
392 for (k = i + 1; k <= m; k++) /* delete bad character */
394 buffer[i] = buffer[k];
395 m--;
397 buffer[m] = 0;
398 result = 1;
401 value = atoi(buffer);
402 if (value > maxval) /* build a new string */
404 sprintf(buffer, "%d", maxval);
405 result = 2;
407 if (result)
409 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
410 SetWindowTextA(hwnd, buffer );
411 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
413 return value;
418 /***********************************************************************
419 * CC_PaintSelectedColor [internal]
421 static void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
423 RECT rect;
424 HDC hdc;
425 HBRUSH hBrush;
426 HWND hwnd = GetDlgItem(hDlg, 0x2c5);
427 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
429 hdc = GetDC(hwnd);
430 GetClientRect(hwnd, &rect) ;
431 hBrush = CreateSolidBrush(cr);
432 if (hBrush)
434 hBrush = SelectObject(hdc, hBrush) ;
435 Rectangle(hdc, rect.left, rect.top, rect.right/2, rect.bottom);
436 DeleteObject ( SelectObject(hdc, hBrush) ) ;
437 hBrush = CreateSolidBrush( GetNearestColor(hdc, cr) );
438 if (hBrush)
440 hBrush = SelectObject(hdc, hBrush) ;
441 Rectangle(hdc, rect.right/2-1, rect.top, rect.right, rect.bottom);
442 DeleteObject(SelectObject(hdc, hBrush)) ;
445 ReleaseDC(hwnd, hdc);
449 /***********************************************************************
450 * CC_PaintTriangle [internal]
452 static void CC_PaintTriangle( HWND hDlg, int y)
454 HDC hDC;
455 long temp;
456 int w = LOWORD(GetDialogBaseUnits());
457 POINT points[3];
458 int height;
459 int oben;
460 RECT rect;
461 HWND hwnd = GetDlgItem(hDlg, 0x2be);
462 LCCPRIV lpp = (LCCPRIV)GetWindowLongA( hDlg, DWL_USER);
464 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6))) /* if full size */
466 GetClientRect(hwnd, &rect);
467 height = rect.bottom;
468 hDC = GetDC(hDlg);
469 points[0].y = rect.top;
470 points[0].x = rect.right; /* | /| */
471 ClientToScreen(hwnd, points); /* | / | */
472 ScreenToClient(hDlg, points); /* |< | */
473 oben = points[0].y; /* | \ | */
474 /* | \| */
475 temp = (long)height * (long)y;
476 points[0].y = oben + height - temp / (long)MAXVERT;
477 points[1].y = points[0].y + w;
478 points[2].y = points[0].y - w;
479 points[2].x = points[1].x = points[0].x + w;
481 FillRect(hDC, &lpp->old3angle, GetClassLongA( hwnd, GCL_HBRBACKGROUND));
482 lpp->old3angle.left = points[0].x;
483 lpp->old3angle.right = points[1].x + 1;
484 lpp->old3angle.top = points[2].y - 1;
485 lpp->old3angle.bottom= points[1].y + 1;
486 Polygon(hDC, points, 3);
487 ReleaseDC(hDlg, hDC);
492 /***********************************************************************
493 * CC_PaintCross [internal]
495 static void CC_PaintCross( HWND hDlg, int x, int y)
497 HDC hDC;
498 int w = GetDialogBaseUnits();
499 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
500 LCCPRIV lpp = (LCCPRIV)GetWindowLongA( hDlg, DWL_USER );
501 RECT rect;
502 POINT point, p;
503 HPEN hPen;
505 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
507 GetClientRect(hwnd, &rect);
508 hDC = GetDC(hwnd);
509 SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
510 hPen = CreatePen(PS_SOLID, 2, 0xffffff); /* -white- color */
511 hPen = SelectObject(hDC, hPen);
512 point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
513 point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
514 if ( lpp->oldcross.left != lpp->oldcross.right )
515 BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
516 lpp->oldcross.right - lpp->oldcross.left,
517 lpp->oldcross.bottom - lpp->oldcross.top,
518 lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
519 lpp->oldcross.left = point.x - w - 1;
520 lpp->oldcross.right = point.x + w + 1;
521 lpp->oldcross.top = point.y - w - 1;
522 lpp->oldcross.bottom = point.y + w + 1;
524 MoveToEx(hDC, point.x - w, point.y, &p);
525 LineTo(hDC, point.x + w, point.y);
526 MoveToEx(hDC, point.x, point.y - w, &p);
527 LineTo(hDC, point.x, point.y + w);
528 DeleteObject( SelectObject(hDC, hPen)) ;
529 ReleaseDC(hwnd, hDC);
534 #define XSTEPS 48
535 #define YSTEPS 24
538 /***********************************************************************
539 * CC_PrepareColorGraph [internal]
541 static void CC_PrepareColorGraph( HWND hDlg )
543 int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
544 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
545 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
546 HBRUSH hbrush;
547 HDC hdc ;
548 RECT rect, client;
549 HCURSOR hcursor = SetCursor( LoadCursorA(0, IDC_WAITA) );
551 GetClientRect(hwnd, &client);
552 hdc = GetDC(hwnd);
553 lpp->hdcMem = CreateCompatibleDC(hdc);
554 lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
555 SelectObject(lpp->hdcMem, lpp->hbmMem);
557 xdif = client.right / XSTEPS;
558 ydif = client.bottom / YSTEPS+1;
559 hdif = 239 / XSTEPS;
560 sdif = 240 / YSTEPS;
561 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
563 rect.right = rect.left + xdif;
564 rect.bottom = client.bottom;
565 for(sat = 0; sat < 240 + sdif; sat += sdif)
567 rect.top = rect.bottom - ydif;
568 r = CC_HSLtoRGB('R', hue, sat, 120);
569 g = CC_HSLtoRGB('G', hue, sat, 120);
570 b = CC_HSLtoRGB('B', hue, sat, 120);
571 hbrush = CreateSolidBrush( RGB(r, g, b));
572 FillRect(lpp->hdcMem, &rect, hbrush);
573 DeleteObject(hbrush);
574 rect.bottom = rect.top;
576 rect.left = rect.right;
578 ReleaseDC(hwnd, hdc);
579 SetCursor(hcursor);
582 /***********************************************************************
583 * CC_PaintColorGraph [internal]
585 static void CC_PaintColorGraph( HWND hDlg )
587 HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
588 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
589 HDC hDC;
590 RECT rect;
591 if (IsWindowVisible(hwnd)) /* if full size */
593 if (!lpp->hdcMem)
594 CC_PrepareColorGraph(hDlg); /* should not be necessary */
596 hDC = GetDC(hwnd);
597 GetClientRect(hwnd, &rect);
598 if (lpp->hdcMem)
599 BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
600 else
601 WARN("choose color: hdcMem is not defined\n");
602 ReleaseDC(hwnd, hDC);
606 /***********************************************************************
607 * CC_PaintLumBar [internal]
609 static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
611 HWND hwnd = GetDlgItem(hDlg, 0x2be);
612 RECT rect, client;
613 int lum, ldif, ydif, r, g, b;
614 HBRUSH hbrush;
615 HDC hDC;
617 if (IsWindowVisible(hwnd))
619 hDC = GetDC(hwnd);
620 GetClientRect(hwnd, &client);
621 rect = client;
623 ldif = 240 / YSTEPS;
624 ydif = client.bottom / YSTEPS+1;
625 for (lum = 0; lum < 240 + ldif; lum += ldif)
627 rect.top = max(0, rect.bottom - ydif);
628 r = CC_HSLtoRGB('R', hue, sat, lum);
629 g = CC_HSLtoRGB('G', hue, sat, lum);
630 b = CC_HSLtoRGB('B', hue, sat, lum);
631 hbrush = CreateSolidBrush( RGB(r, g, b) );
632 FillRect(hDC, &rect, hbrush);
633 DeleteObject(hbrush);
634 rect.bottom = rect.top;
636 GetClientRect(hwnd, &rect);
637 FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH) );
638 ReleaseDC(hwnd, hDC);
642 /***********************************************************************
643 * CC_EditSetRGB [internal]
645 static void CC_EditSetRGB( HWND hDlg, COLORREF cr )
647 char buffer[10];
648 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
649 int r = GetRValue(cr);
650 int g = GetGValue(cr);
651 int b = GetBValue(cr);
652 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
654 lpp->updating = TRUE;
655 sprintf(buffer, "%d", r);
656 SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
657 sprintf(buffer, "%d", g);
658 SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
659 sprintf( buffer, "%d", b );
660 SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
661 lpp->updating = FALSE;
665 /***********************************************************************
666 * CC_EditSetHSL [internal]
668 static void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
670 char buffer[10];
671 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
672 lpp->updating = TRUE;
673 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
675 lpp->updating = TRUE;
676 sprintf(buffer, "%d", h);
677 SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
678 sprintf(buffer, "%d", s);
679 SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
680 sprintf(buffer, "%d", l);
681 SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
682 lpp->updating = FALSE;
684 CC_PaintLumBar(hDlg, h, s);
687 /***********************************************************************
688 * CC_SwitchToFullSize [internal]
690 static void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPRECT lprect )
692 int i;
693 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
695 EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
696 CC_PrepareColorGraph(hDlg);
697 for (i = 0x2bf; i < 0x2c5; i++)
698 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
699 for (i = 0x2d3; i < 0x2d9; i++)
700 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
701 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
702 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
703 ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);
705 if (lprect)
706 SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
707 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
709 ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
710 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);
712 CC_EditSetRGB(hDlg, result);
713 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
714 ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
715 UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
718 /***********************************************************************
719 * CC_PaintPredefColorArray [internal]
720 * Paints the default standard 48 colors
722 static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
724 HWND hwnd = GetDlgItem(hDlg, 0x2d0);
725 RECT rect;
726 HDC hdc;
727 HBRUSH hBrush;
728 int dx, dy, i, j, k;
729 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
731 GetClientRect(hwnd, &rect);
732 dx = rect.right / cols;
733 dy = rect.bottom / rows;
734 k = rect.left;
736 hdc = GetDC(hwnd);
737 GetClientRect(hwnd, &rect);
738 FillRect(hdc, &rect, GetClassLongA(hwnd, GCL_HBRBACKGROUND));
739 for ( j = 0; j < rows; j++ )
741 for ( i = 0; i < cols; i++ )
743 hBrush = CreateSolidBrush(predefcolors[j][i]);
744 if (hBrush)
746 hBrush = SelectObject(hdc, hBrush);
747 Rectangle(hdc, rect.left, rect.top,
748 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
749 rect.left = rect.left + dx;
750 DeleteObject(SelectObject(hdc, hBrush)) ;
753 rect.top = rect.top + dy;
754 rect.left = k;
756 ReleaseDC(hwnd, hdc);
757 if (lpp->hwndFocus == hwnd)
758 CC_DrawCurrentFocusRect(lpp);
760 /***********************************************************************
761 * CC_PaintUserColorArray [internal]
762 * Paint the 16 user-selected colors
764 static void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, COLORREF* lpcr )
766 HWND hwnd = GetDlgItem(hDlg, 0x2d1);
767 RECT rect;
768 HDC hdc;
769 HBRUSH hBrush;
770 int dx, dy, i, j, k;
771 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
773 GetClientRect(hwnd, &rect);
775 dx = rect.right / cols;
776 dy = rect.bottom / rows;
777 k = rect.left;
779 hdc = GetDC(hwnd);
780 if (hdc)
782 FillRect(hdc, &rect, GetClassLongA(hwnd, GCL_HBRBACKGROUND) );
783 for (j = 0; j < rows; j++)
785 for (i = 0; i < cols; i++)
787 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
788 if (hBrush)
790 hBrush = SelectObject(hdc, hBrush) ;
791 Rectangle(hdc, rect.left, rect.top,
792 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
793 rect.left = rect.left + dx;
794 DeleteObject( SelectObject(hdc, hBrush) ) ;
797 rect.top = rect.top + dy;
798 rect.left = k;
800 ReleaseDC(hwnd, hdc);
802 if (lpp->hwndFocus == hwnd)
803 CC_DrawCurrentFocusRect(lpp);
808 /***********************************************************************
809 * CC_HookCallChk [internal]
811 static BOOL CC_HookCallChk( LPCHOOSECOLORW lpcc )
813 if (lpcc)
814 if(lpcc->Flags & CC_ENABLEHOOK)
815 if (lpcc->lpfnHook)
816 return TRUE;
817 return FALSE;
821 /***********************************************************************
822 * CC_WMInitDialog [internal]
824 static LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam, BOOL b16 )
826 int i, res;
827 int r, g, b;
828 HWND hwnd;
829 RECT rect;
830 POINT point;
831 LCCPRIV lpp;
833 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
834 lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
835 if (b16)
837 CHOOSECOLORW *ch32;
838 CHOOSECOLOR16 *ch16 = (CHOOSECOLOR16 *) lParam;
839 ch32 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW) );
840 lpp->lpcc = ch32;
841 lpp->lpcc16 = ch16;
842 if (lpp->lpcc16->lStructSize != sizeof(CHOOSECOLOR16) )
844 EndDialog (hDlg, 0) ;
845 return FALSE;
847 ch32->lStructSize = sizeof(CHOOSECOLORW);
848 ch32->hwndOwner = ch16->hwndOwner;
849 ch32->hInstance = ch16->hInstance;
850 ch32->lpCustColors = MapSL(ch16->lpCustColors);
851 ch32->lpfnHook = (LPCCHOOKPROC) ch16->lpfnHook; /* only used as flag */
852 ch32->Flags = ch16->Flags;
854 else
855 lpp->lpcc = (LPCHOOSECOLORW) lParam;
857 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
859 EndDialog (hDlg, 0) ;
860 return FALSE;
862 SetWindowLongA(hDlg, DWL_USER, (LONG)lpp);
864 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
865 ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
866 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
868 #if 0
869 cpos = MAKELONG(5,7); /* init */
870 if (lpp->lpcc->Flags & CC_RGBINIT)
872 for (i = 0; i < 6; i++)
873 for (j = 0; j < 8; j++)
874 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
876 cpos = MAKELONG(i,j);
877 goto found;
880 found:
881 /* FIXME: Draw_a_focus_rect & set_init_values */
882 #endif
884 GetWindowRect(hDlg, &lpp->fullsize);
885 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
887 hwnd = GetDlgItem(hDlg, 0x2cf);
888 EnableWindow(hwnd, FALSE);
890 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
892 rect = lpp->fullsize;
893 res = rect.bottom - rect.top;
894 hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
895 point.x = point.y = 0;
896 ClientToScreen(hwnd, &point);
897 ScreenToClient(hDlg,&point);
898 GetClientRect(hDlg, &rect);
899 point.x += GetSystemMetrics(SM_CXDLGFRAME);
900 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
902 for (i = 0x2bf; i < 0x2c5; i++)
903 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
904 for (i = 0x2d3; i < 0x2d9; i++)
905 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
906 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
907 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
908 ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
909 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
910 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
912 else
913 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
914 res = TRUE;
915 for (i = 0x2bf; i < 0x2c5; i++)
916 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
917 if (CC_HookCallChk(lpp->lpcc))
919 if (b16)
920 res = CallWindowProc16( (WNDPROC16)lpp->lpcc16->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
921 else
922 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
925 /* Set the initial values of the color chooser dialog */
926 r = GetRValue(lpp->lpcc->rgbResult);
927 g = GetGValue(lpp->lpcc->rgbResult);
928 b = GetBValue(lpp->lpcc->rgbResult);
930 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
931 lpp->h = CC_RGBtoHSL('H', r, g, b);
932 lpp->s = CC_RGBtoHSL('S', r, g, b);
933 lpp->l = CC_RGBtoHSL('L', r, g, b);
935 /* Doing it the long way becaus CC_EditSetRGB/HSL doesn'nt seem to work */
936 SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
937 SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
938 SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
939 SetDlgItemInt(hDlg, 706, r, TRUE);
940 SetDlgItemInt(hDlg, 707, g, TRUE);
941 SetDlgItemInt(hDlg, 708, b, TRUE);
943 CC_PaintCross(hDlg, lpp->h, lpp->s);
944 CC_PaintTriangle(hDlg, lpp->l);
946 return res;
950 /***********************************************************************
951 * CC_WMCommand [internal]
953 static LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
955 int r, g, b, i, xx;
956 UINT cokmsg;
957 HDC hdc;
958 COLORREF *cr;
959 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
960 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam, lParam);
961 switch (wParam)
963 case 0x2c2: /* edit notify RGB */
964 case 0x2c3:
965 case 0x2c4:
966 if (notifyCode == EN_UPDATE && !lpp->updating)
968 i = CC_CheckDigitsInEdit(hwndCtl, 255);
969 r = GetRValue(lpp->lpcc->rgbResult);
970 g = GetGValue(lpp->lpcc->rgbResult);
971 b= GetBValue(lpp->lpcc->rgbResult);
972 xx = 0;
973 switch (wParam)
975 case 0x2c2: if ((xx = (i != r))) r = i; break;
976 case 0x2c3: if ((xx = (i != g))) g = i; break;
977 case 0x2c4: if ((xx = (i != b))) b = i; break;
979 if (xx) /* something has changed */
981 lpp->lpcc->rgbResult = RGB(r, g, b);
982 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
983 lpp->h = CC_RGBtoHSL('H', r, g, b);
984 lpp->s = CC_RGBtoHSL('S', r, g, b);
985 lpp->l = CC_RGBtoHSL('L', r, g, b);
986 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
987 CC_PaintCross(hDlg, lpp->h, lpp->s);
988 CC_PaintTriangle(hDlg, lpp->l);
991 break;
993 case 0x2bf: /* edit notify HSL */
994 case 0x2c0:
995 case 0x2c1:
996 if (notifyCode == EN_UPDATE && !lpp->updating)
998 i = CC_CheckDigitsInEdit(hwndCtl , wParam == 0x2bf ? 239:240);
999 xx = 0;
1000 switch (wParam)
1002 case 0x2bf: if ((xx = ( i != lpp->h))) lpp->h = i; break;
1003 case 0x2c0: if ((xx = ( i != lpp->s))) lpp->s = i; break;
1004 case 0x2c1: if ((xx = ( i != lpp->l))) lpp->l = i; break;
1006 if (xx) /* something has changed */
1008 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1009 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1010 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1011 lpp->lpcc->rgbResult = RGB(r, g, b);
1012 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1013 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1014 CC_PaintCross(hDlg, lpp->h, lpp->s);
1015 CC_PaintTriangle(hDlg, lpp->l);
1018 break;
1020 case 0x2cf:
1021 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, &lpp->fullsize);
1022 SetFocus( GetDlgItem(hDlg, 0x2bf));
1023 break;
1025 case 0x2c8: /* add colors ... column by column */
1026 cr = lpp->lpcc->lpCustColors;
1027 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1028 if (++lpp->nextuserdef == 16)
1029 lpp->nextuserdef = 0;
1030 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1031 break;
1033 case 0x2c9: /* resulting color */
1034 hdc = GetDC(hDlg);
1035 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1036 ReleaseDC(hDlg, hdc);
1037 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1038 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1039 r = GetRValue(lpp->lpcc->rgbResult);
1040 g = GetGValue(lpp->lpcc->rgbResult);
1041 b = GetBValue(lpp->lpcc->rgbResult);
1042 lpp->h = CC_RGBtoHSL('H', r, g, b);
1043 lpp->s = CC_RGBtoHSL('S', r, g, b);
1044 lpp->l = CC_RGBtoHSL('L', r, g, b);
1045 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
1046 CC_PaintCross(hDlg, lpp->h, lpp->s);
1047 CC_PaintTriangle(hDlg, lpp->l);
1048 break;
1050 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1051 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1052 if (lpp->lpcc16)
1054 if (lpp->lpcc->hwndOwner)
1055 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc16);
1056 if ( CC_HookCallChk(lpp->lpcc))
1057 CallWindowProc16( (WNDPROC16) lpp->lpcc16->lpfnHook, hDlg,
1058 WM_COMMAND, psh15, (LPARAM)lpp->lpcc16);
1060 else
1062 if (lpp->lpcc->hwndOwner)
1063 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1064 if ( CC_HookCallChk(lpp->lpcc))
1065 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
1066 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1068 break;
1070 case IDOK :
1071 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1072 if (lpp->lpcc16)
1074 if (lpp->lpcc->hwndOwner)
1075 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc16))
1076 break; /* do NOT close */
1078 else
1080 if (lpp->lpcc->hwndOwner)
1081 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1082 break; /* do NOT close */
1084 if (lpp->lpcc16)
1086 BYTE *ptr = MapSL(lpp->lpcc16->lpCustColors);
1087 memcpy(ptr, lpp->lpcc->lpCustColors, sizeof(COLORREF)*16);
1088 lpp->lpcc16->rgbResult = lpp->lpcc->rgbResult;
1090 EndDialog(hDlg, 1) ;
1091 return TRUE ;
1093 case IDCANCEL :
1094 EndDialog(hDlg, 0) ;
1095 return TRUE ;
1098 return FALSE;
1101 /***********************************************************************
1102 * CC_WMPaint [internal]
1104 static LRESULT CC_WMPaint( HWND hDlg, WPARAM wParam, LPARAM lParam )
1106 HDC hdc;
1107 PAINTSTRUCT ps;
1108 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1110 hdc = BeginPaint(hDlg, &ps);
1111 /* we have to paint dialog children except text and buttons */
1112 CC_PaintPredefColorArray(hDlg, 6, 8);
1113 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1114 CC_PaintLumBar(hDlg, lpp->h, lpp->s);
1115 CC_PaintCross(hDlg, lpp->h, lpp->s);
1116 CC_PaintTriangle(hDlg, lpp->l);
1117 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1118 CC_PaintColorGraph(hDlg);
1119 EndPaint(hDlg, &ps);
1121 return TRUE;
1125 /***********************************************************************
1126 * CC_WMLButtonUp [internal]
1128 static LRESULT CC_WMLButtonUp( HWND hDlg, WPARAM wParam, LPARAM lParam )
1130 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1131 if (lpp->capturedGraph)
1133 lpp->capturedGraph = 0;
1134 ReleaseCapture();
1135 CC_PaintCross(hDlg, lpp->h, lpp->s);
1136 return 1;
1138 return 0;
1142 /***********************************************************************
1143 * CC_WMMouseMove [internal]
1145 static LRESULT CC_WMMouseMove( HWND hDlg, LPARAM lParam )
1147 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1148 int r, g, b;
1150 if (lpp->capturedGraph)
1152 int *ptrh = NULL, *ptrs = &lpp->l;
1153 if (lpp->capturedGraph == 0x2c6)
1155 ptrh = &lpp->h;
1156 ptrs = &lpp->s;
1158 if (CC_MouseCheckColorGraph( hDlg, lpp->capturedGraph, ptrh, ptrs, lParam))
1160 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1161 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1162 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1163 lpp->lpcc->rgbResult = RGB(r, g, b);
1164 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1165 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1166 CC_PaintCross(hDlg, lpp->h, lpp->s);
1167 CC_PaintTriangle(hDlg, lpp->l);
1168 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1170 else
1172 ReleaseCapture();
1173 lpp->capturedGraph = 0;
1175 return 1;
1177 return 0;
1179 /***********************************************************************
1180 * CC_WMLButtonDown [internal]
1182 static LRESULT CC_WMLButtonDown( HWND hDlg, WPARAM wParam, LPARAM lParam )
1184 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1185 int r, g, b, i;
1186 i = 0;
1188 if (CC_MouseCheckPredefColorArray(lpp, hDlg, 0x2d0, 6, 8, lParam))
1189 i = 1;
1190 else
1191 if (CC_MouseCheckUserColorArray(lpp, hDlg, 0x2d1, 2, 8, lParam))
1192 i = 1;
1193 else
1194 if (CC_MouseCheckColorGraph(hDlg, 0x2c6, &lpp->h, &lpp->s, lParam))
1196 i = 2;
1197 lpp->capturedGraph = 0x2c6;
1199 else
1200 if (CC_MouseCheckColorGraph(hDlg, 0x2be, NULL, &lpp->l, lParam))
1202 i = 2;
1203 lpp->capturedGraph = 0x2be;
1205 if ( i == 2 )
1207 SetCapture(hDlg);
1208 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1209 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1210 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1211 lpp->lpcc->rgbResult = RGB(r, g, b);
1213 if ( i == 1 )
1215 r = GetRValue(lpp->lpcc->rgbResult);
1216 g = GetGValue(lpp->lpcc->rgbResult);
1217 b = GetBValue(lpp->lpcc->rgbResult);
1218 lpp->h = CC_RGBtoHSL('H', r, g, b);
1219 lpp->s = CC_RGBtoHSL('S', r, g, b);
1220 lpp->l = CC_RGBtoHSL('L', r, g, b);
1222 if (i)
1224 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1225 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1226 CC_PaintCross(hDlg, lpp->h, lpp->s);
1227 CC_PaintTriangle(hDlg, lpp->l);
1228 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1229 return TRUE;
1231 return FALSE;
1235 /***********************************************************************
1236 * ColorDlgProc32 [internal]
1239 static LRESULT WINAPI ColorDlgProc( HWND hDlg, UINT message,
1240 WPARAM wParam, LPARAM lParam )
1243 int res;
1244 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1245 if (message != WM_INITDIALOG)
1247 if (!lpp)
1248 return FALSE;
1249 res = 0;
1250 if (CC_HookCallChk(lpp->lpcc))
1251 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1252 if ( res )
1253 return res;
1256 /* FIXME: SetRGB message
1257 if (message && message == msetrgb)
1258 return HandleSetRGB(hDlg, lParam);
1261 switch (message)
1263 case WM_INITDIALOG:
1264 return CC_WMInitDialog(hDlg, wParam, lParam, FALSE);
1265 case WM_NCDESTROY:
1266 DeleteDC(lpp->hdcMem);
1267 DeleteObject(lpp->hbmMem);
1268 HeapFree(GetProcessHeap(), 0, lpp);
1269 SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
1270 break;
1271 case WM_COMMAND:
1272 if (CC_WMCommand( hDlg, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1273 return TRUE;
1274 break;
1275 case WM_PAINT:
1276 if ( CC_WMPaint(hDlg, wParam, lParam))
1277 return TRUE;
1278 break;
1279 case WM_LBUTTONDBLCLK:
1280 if (CC_MouseCheckResultWindow(hDlg, lParam))
1281 return TRUE;
1282 break;
1283 case WM_MOUSEMOVE:
1284 if (CC_WMMouseMove(hDlg, lParam))
1285 return TRUE;
1286 break;
1287 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1288 if (CC_WMLButtonUp(hDlg, wParam, lParam))
1289 return TRUE;
1290 break;
1291 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1292 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1293 return TRUE;
1294 break;
1296 return FALSE ;
1299 /***********************************************************************
1300 * ColorDlgProc (COMMDLG.8)
1302 LRESULT WINAPI ColorDlgProc16( HWND16 hDlg, UINT16 message,
1303 WPARAM16 wParam, LONG lParam )
1305 int res;
1306 LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
1307 if (message != WM_INITDIALOG)
1309 if (!lpp)
1310 return FALSE;
1311 res=0;
1312 if (CC_HookCallChk(lpp->lpcc))
1313 res = CallWindowProc16( (WNDPROC16)lpp->lpcc16->lpfnHook, hDlg, message, wParam, lParam);
1314 if (res)
1315 return res;
1318 /* FIXME: SetRGB message
1319 if (message && message == msetrgb)
1320 return HandleSetRGB(hDlg, lParam);
1323 switch (message)
1325 case WM_INITDIALOG:
1326 return CC_WMInitDialog(hDlg, wParam, lParam, TRUE);
1327 case WM_NCDESTROY:
1328 DeleteDC(lpp->hdcMem);
1329 DeleteObject(lpp->hbmMem);
1330 HeapFree(GetProcessHeap(), 0, lpp->lpcc);
1331 HeapFree(GetProcessHeap(), 0, lpp);
1332 SetWindowLongA(hDlg, DWL_USER, 0L); /* we don't need it anymore */
1333 break;
1334 case WM_COMMAND:
1335 if (CC_WMCommand(hDlg, wParam, lParam, HIWORD(lParam), (HWND)LOWORD(lParam)))
1336 return TRUE;
1337 break;
1338 case WM_PAINT:
1339 if (CC_WMPaint(hDlg, wParam, lParam))
1340 return TRUE;
1341 break;
1342 case WM_LBUTTONDBLCLK:
1343 if (CC_MouseCheckResultWindow(hDlg,lParam))
1344 return TRUE;
1345 break;
1346 case WM_MOUSEMOVE:
1347 if (CC_WMMouseMove(hDlg, lParam))
1348 return TRUE;
1349 break;
1350 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1351 if (CC_WMLButtonUp(hDlg, wParam, lParam))
1352 return TRUE;
1353 break;
1354 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1355 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1356 return TRUE;
1357 break;
1359 return FALSE ;
1364 /***********************************************************************
1365 * ChooseColor (COMMDLG.5)
1367 BOOL16 WINAPI ChooseColor16( LPCHOOSECOLOR16 lpChCol )
1369 HINSTANCE16 hInst;
1370 HANDLE16 hDlgTmpl16 = 0, hResource16 = 0;
1371 HGLOBAL16 hGlobal16 = 0;
1372 BOOL16 bRet = FALSE;
1373 LPCVOID template;
1374 FARPROC16 ptr;
1376 TRACE("ChooseColor\n");
1377 if (!lpChCol) return FALSE;
1379 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1380 hDlgTmpl16 = lpChCol->hInstance;
1381 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1383 HANDLE16 hResInfo;
1384 if (!(hResInfo = FindResource16(lpChCol->hInstance,
1385 MapSL(lpChCol->lpTemplateName),
1386 RT_DIALOGA)))
1388 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1389 return FALSE;
1391 if (!(hDlgTmpl16 = LoadResource16(lpChCol->hInstance, hResInfo)))
1393 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1394 return FALSE;
1396 hResource16 = hDlgTmpl16;
1398 else
1400 HANDLE hResInfo, hDlgTmpl32;
1401 LPCVOID template32;
1402 DWORD size;
1403 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_COLOR", RT_DIALOGA)))
1405 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1406 return FALSE;
1408 if (!(hDlgTmpl32 = LoadResource(COMMDLG_hInstance32, hResInfo)) ||
1409 !(template32 = LockResource(hDlgTmpl32)))
1411 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1412 return FALSE;
1414 size = SizeofResource(GetModuleHandleA("COMDLG32"), hResInfo);
1415 hGlobal16 = GlobalAlloc16(0, size);
1416 if (!hGlobal16)
1418 COMDLG32_SetCommDlgExtendedError(CDERR_MEMALLOCFAILURE);
1419 ERR("alloc failure for %ld bytes\n", size);
1420 return FALSE;
1422 template = GlobalLock16(hGlobal16);
1423 if (!template)
1425 COMDLG32_SetCommDlgExtendedError(CDERR_MEMLOCKFAILURE);
1426 ERR("global lock failure for %x handle\n", hDlgTmpl16);
1427 GlobalFree16(hGlobal16);
1428 return FALSE;
1430 ConvertDialog32To16((LPVOID)template32, size, (LPVOID)template);
1431 hDlgTmpl16 = hGlobal16;
1434 ptr = GetProcAddress16(GetModuleHandle16("COMMDLG"), (LPCSTR) 8);
1435 hInst = GetWindowLongA(lpChCol->hwndOwner, GWL_HINSTANCE);
1436 bRet = DialogBoxIndirectParam16(hInst, hDlgTmpl16, lpChCol->hwndOwner,
1437 (DLGPROC16) ptr, (DWORD)lpChCol);
1438 if (hResource16) FreeResource16(hDlgTmpl16);
1439 if (hGlobal16)
1441 GlobalUnlock16(hGlobal16);
1442 GlobalFree16(hGlobal16);
1444 return bRet;
1447 /***********************************************************************
1448 * ChooseColorW (COMDLG32.@)
1450 BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
1454 HANDLE hDlgTmpl = 0;
1455 BOOL bRet = FALSE;
1456 LPCVOID template;
1458 TRACE("ChooseColor\n");
1459 if (!lpChCol) return FALSE;
1461 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1463 if (!(template = LockResource(lpChCol->hInstance)))
1465 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1466 return FALSE;
1469 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1471 HANDLE hResInfo;
1472 if (!(hResInfo = FindResourceW(lpChCol->hInstance,
1473 lpChCol->lpTemplateName,
1474 RT_DIALOGW)))
1476 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1477 return FALSE;
1479 if (!(hDlgTmpl = LoadResource(lpChCol->hInstance, hResInfo)) ||
1480 !(template = LockResource(hDlgTmpl)))
1482 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1483 return FALSE;
1486 else
1488 HANDLE hResInfo, hDlgTmpl;
1489 if (!(hResInfo = FindResourceA(COMMDLG_hInstance32, "CHOOSE_COLOR", RT_DIALOGA)))
1491 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1492 return FALSE;
1494 if (!(hDlgTmpl = LoadResource(COMMDLG_hInstance32, hResInfo )) ||
1495 !(template = LockResource(hDlgTmpl)))
1497 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1498 return FALSE;
1502 bRet = DialogBoxIndirectParamW(COMMDLG_hInstance32, template, lpChCol->hwndOwner,
1503 (DLGPROC)ColorDlgProc, (DWORD)lpChCol);
1504 return bRet;
1507 /***********************************************************************
1508 * ChooseColorA (COMDLG32.@)
1510 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1513 BOOL ret;
1514 LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
1515 lpcc->lStructSize = sizeof(*lpcc);
1516 lpcc->hwndOwner = lpChCol->hwndOwner;
1517 lpcc->hInstance = lpChCol->hInstance;
1518 lpcc->rgbResult = lpChCol->rgbResult;
1519 lpcc->lpCustColors = lpChCol->lpCustColors;
1520 lpcc->Flags = lpChCol->Flags;
1521 lpcc->lCustData = lpChCol->lCustData;
1522 lpcc->lpfnHook = (LPCCHOOKPROC) lpChCol->lpfnHook;
1523 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1524 if (HIWORD(lpChCol->lpTemplateName)) {
1525 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1526 lpcc->lpTemplateName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1527 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, (LPWSTR)lpcc->lpTemplateName, len );
1528 } else {
1529 lpcc->lpTemplateName = (LPWSTR)lpChCol->lpTemplateName;
1533 ret = ChooseColorW(lpcc);
1535 if (ret)
1536 lpChCol->rgbResult = lpcc->rgbResult;
1537 if (HIWORD(lpcc->lpTemplateName)) HeapFree(GetProcessHeap(), 0, (LPSTR)lpcc->lpTemplateName);
1538 HeapFree(GetProcessHeap(), 0, lpcc);
1539 return ret;