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 */
37 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
43 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
45 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
47 static const COLORREF predefcolors[6][8]=
49 { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
50 0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
51 { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
52 0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
54 { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
55 0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
56 { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
57 0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
59 { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
60 0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
61 { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
62 0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
65 /* Chose Color PRIVATE Structure:
67 * This structure is duplicated in the 16 bit code with
71 typedef struct CCPRIVATE
73 LPCHOOSECOLORW lpcc; /* points to public known data structure */
74 int nextuserdef; /* next free place in user defined color array */
75 HDC hdcMem; /* color graph used for BitBlt() */
76 HBITMAP hbmMem; /* color graph bitmap */
77 RECT fullsize; /* original dialog window size */
78 UINT msetrgb; /* # of SETRGBSTRING message (today not used) */
79 RECT old3angle; /* last position of l-marker */
80 RECT oldcross; /* last position of color/satuation marker */
81 BOOL updating; /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
84 int l; /* for temporary storing of hue,sat,lum */
85 int capturedGraph; /* control mouse captured */
86 RECT focusRect; /* rectangle last focused item */
87 HWND hwndFocus; /* handle last focused item */
90 /***********************************************************************
91 * CC_HSLtoRGB [internal]
93 int CC_HSLtoRGB(char c, int hue, int sat, int lum)
100 case 'R': if (hue > 80) hue -= 80; else hue += 160; break;
101 case 'G': if (hue > 160) hue -= 160; else hue += 80; break;
106 maxrgb = (256 * min(120,lum)) / 120; /* 0 .. 256 */
112 res = (hue - 80) * maxrgb; /* 0...10240 */
113 res /= 40; /* 0...256 */
120 res= (240 - hue) * maxrgb;
123 res = res - maxrgb / 2; /* -128...128 */
126 res = maxrgb / 2 + (sat * res) / 240; /* 0..256 */
129 if (lum > 120 && res < 256)
130 res += ((lum - 120) * (256 - res)) / 120;
132 return min(res, 255);
135 /***********************************************************************
136 * CC_RGBtoHSL [internal]
138 int CC_RGBtoHSL(char c, int r, int g, int b)
140 WORD maxi, mini, mmsum, mmdif, result = 0;
154 case 'L': mmsum *= 120; /* 0...61200=(255+255)*120 */
155 result = mmsum / 255; /* 0...240 */
158 case 'S': if (!mmsum)
161 if (!mini || maxi == 255)
165 result = mmdif * 240; /* 0...61200=255*240 */
166 result /= (mmsum > 255 ? mmsum = 510 - mmsum : mmsum); /* 0..255 */
170 case 'H': if (!mmdif)
176 iresult = 40 * (g - b); /* -10200 ... 10200 */
177 iresult /= (int) mmdif; /* -40 .. 40 */
179 iresult += 240; /* 0..40 and 200..240 */
184 iresult = 40 * (b - r);
185 iresult /= (int) mmdif;
186 iresult += 80; /* 40 .. 120 */
191 iresult = 40 * (r - g);
192 iresult /= (int) mmdif;
193 iresult += 160; /* 120 .. 200 */
199 return result; /* is this integer arithmetic precise enough ? */
203 /***********************************************************************
204 * CC_DrawCurrentFocusRect [internal]
206 static void CC_DrawCurrentFocusRect( LCCPRIV lpp )
210 HDC hdc = GetDC(lpp->hwndFocus);
211 DrawFocusRect(hdc, &lpp->focusRect);
212 ReleaseDC(lpp->hwndFocus, hdc);
216 /***********************************************************************
217 * CC_DrawFocusRect [internal]
219 static void CC_DrawFocusRect( LCCPRIV lpp, HWND hwnd, int x, int y, int rows, int cols)
225 CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
226 /* calculate new rect */
227 GetClientRect(hwnd, &rect);
228 dx = (rect.right - rect.left) / cols;
229 dy = (rect.bottom - rect.top) / rows;
230 rect.left += (x * dx) - 2;
231 rect.top += (y * dy) - 2;
232 rect.right = rect.left + dx;
233 rect.bottom = rect.top + dy;
236 DrawFocusRect(hdc, &rect);
237 CopyRect(&lpp->focusRect, &rect);
238 lpp->hwndFocus = hwnd;
239 ReleaseDC(hwnd, hdc);
244 /***********************************************************************
245 * CC_MouseCheckPredefColorArray [internal]
246 * returns 1 if one of the predefined colors is clicked
248 static int CC_MouseCheckPredefColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
256 CONV_LPARAMTOPOINT(lParam, &point);
257 ClientToScreen(hDlg, &point);
258 hwnd = GetDlgItem(hDlg, dlgitem);
259 GetWindowRect(hwnd, &rect);
260 if (PtInRect(&rect, point))
262 dx = (rect.right - rect.left) / cols;
263 dy = (rect.bottom - rect.top) / rows;
264 ScreenToClient(hwnd, &point);
266 if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
270 lpp->lpcc->rgbResult = predefcolors[y][x];
271 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
278 /***********************************************************************
279 * CC_MouseCheckUserColorArray [internal]
280 * return 1 if the user clicked a color
282 static int CC_MouseCheckUserColorArray( LCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
289 COLORREF *crarr = lpp->lpcc->lpCustColors;
291 CONV_LPARAMTOPOINT(lParam, &point);
292 ClientToScreen(hDlg, &point);
293 hwnd = GetDlgItem(hDlg, dlgitem);
294 GetWindowRect(hwnd, &rect);
295 if (PtInRect(&rect, point))
297 dx = (rect.right - rect.left) / cols;
298 dy = (rect.bottom - rect.top) / rows;
299 ScreenToClient(hwnd, &point);
301 if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
305 lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
306 CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
316 /* 240 ^...... ^^ 240
323 /***********************************************************************
324 * CC_MouseCheckColorGraph [internal]
326 static int CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
333 CONV_LPARAMTOPOINT(lParam, &point);
334 ClientToScreen(hDlg, &point);
335 hwnd = GetDlgItem( hDlg, dlgitem );
336 GetWindowRect(hwnd, &rect);
337 if (PtInRect(&rect, point))
339 GetClientRect(hwnd, &rect);
340 ScreenToClient(hwnd, &point);
342 x = (long) point.x * MAXHORI;
344 y = (long) (rect.bottom - point.y) * MAXVERT;
356 /***********************************************************************
357 * CC_MouseCheckResultWindow [internal]
358 * test if double click one of the result colors
360 int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
366 CONV_LPARAMTOPOINT(lParam, &point);
367 ClientToScreen(hDlg, &point);
368 hwnd = GetDlgItem(hDlg, 0x2c5);
369 GetWindowRect(hwnd, &rect);
370 if (PtInRect(&rect, point))
372 PostMessageA(hDlg, WM_COMMAND, 0x2c9, 0);
378 /***********************************************************************
379 * CC_CheckDigitsInEdit [internal]
381 int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
383 int i, k, m, result, value;
387 GetWindowTextA(hwnd, buffer, sizeof(buffer));
391 for (i = 0 ; i < m ; i++)
392 if (buffer[i] < '0' || buffer[i] > '9')
394 for (k = i + 1; k <= m; k++) /* delete bad character */
396 buffer[i] = buffer[k];
403 value = atoi(buffer);
404 if (value > maxval) /* build a new string */
406 sprintf(buffer, "%d", maxval);
411 editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
412 SetWindowTextA(hwnd, buffer );
413 SendMessageA(hwnd, EM_SETSEL, 0, editpos);
420 /***********************************************************************
421 * CC_PaintSelectedColor [internal]
423 void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
428 HWND hwnd = GetDlgItem(hDlg, 0x2c5);
429 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
432 GetClientRect(hwnd, &rect) ;
433 hBrush = CreateSolidBrush(cr);
436 hBrush = SelectObject(hdc, hBrush) ;
437 Rectangle(hdc, rect.left, rect.top, rect.right/2, rect.bottom);
438 DeleteObject ( SelectObject(hdc, hBrush) ) ;
439 hBrush = CreateSolidBrush( GetNearestColor(hdc, cr) );
442 hBrush = SelectObject(hdc, hBrush) ;
443 Rectangle(hdc, rect.right/2-1, rect.top, rect.right, rect.bottom);
444 DeleteObject(SelectObject(hdc, hBrush)) ;
447 ReleaseDC(hwnd, hdc);
451 /***********************************************************************
452 * CC_PaintTriangle [internal]
454 void CC_PaintTriangle( HWND hDlg, int y)
458 int w = LOWORD(GetDialogBaseUnits());
463 HWND hwnd = GetDlgItem(hDlg, 0x2be);
464 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW( hDlg, DWLP_USER);
466 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6))) /* if full size */
468 GetClientRect(hwnd, &rect);
469 height = rect.bottom;
471 points[0].y = rect.top;
472 points[0].x = rect.right; /* | /| */
473 ClientToScreen(hwnd, points); /* | / | */
474 ScreenToClient(hDlg, points); /* |< | */
475 oben = points[0].y; /* | \ | */
477 temp = (long)height * (long)y;
478 points[0].y = oben + height - temp / (long)MAXVERT;
479 points[1].y = points[0].y + w;
480 points[2].y = points[0].y - w;
481 points[2].x = points[1].x = points[0].x + w;
483 FillRect(hDC, &lpp->old3angle, (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND));
484 lpp->old3angle.left = points[0].x;
485 lpp->old3angle.right = points[1].x + 1;
486 lpp->old3angle.top = points[2].y - 1;
487 lpp->old3angle.bottom= points[1].y + 1;
488 Polygon(hDC, points, 3);
489 ReleaseDC(hDlg, hDC);
494 /***********************************************************************
495 * CC_PaintCross [internal]
497 void CC_PaintCross( HWND hDlg, int x, int y)
500 int w = GetDialogBaseUnits();
501 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
502 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW( hDlg, DWLP_USER );
507 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
509 GetClientRect(hwnd, &rect);
511 SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
512 hPen = CreatePen(PS_SOLID, 2, 0xffffff); /* -white- color */
513 hPen = SelectObject(hDC, hPen);
514 point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
515 point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
516 if ( lpp->oldcross.left != lpp->oldcross.right )
517 BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
518 lpp->oldcross.right - lpp->oldcross.left,
519 lpp->oldcross.bottom - lpp->oldcross.top,
520 lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
521 lpp->oldcross.left = point.x - w - 1;
522 lpp->oldcross.right = point.x + w + 1;
523 lpp->oldcross.top = point.y - w - 1;
524 lpp->oldcross.bottom = point.y + w + 1;
526 MoveToEx(hDC, point.x - w, point.y, &p);
527 LineTo(hDC, point.x + w, point.y);
528 MoveToEx(hDC, point.x, point.y - w, &p);
529 LineTo(hDC, point.x, point.y + w);
530 DeleteObject( SelectObject(hDC, hPen)) ;
531 ReleaseDC(hwnd, hDC);
540 /***********************************************************************
541 * CC_PrepareColorGraph [internal]
543 static void CC_PrepareColorGraph( HWND hDlg )
545 int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
546 HWND hwnd = GetDlgItem(hDlg, 0x2c6);
547 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
551 HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
553 GetClientRect(hwnd, &client);
555 lpp->hdcMem = CreateCompatibleDC(hdc);
556 lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
557 SelectObject(lpp->hdcMem, lpp->hbmMem);
559 xdif = client.right / XSTEPS;
560 ydif = client.bottom / YSTEPS+1;
563 for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
565 rect.right = rect.left + xdif;
566 rect.bottom = client.bottom;
567 for(sat = 0; sat < 240 + sdif; sat += sdif)
569 rect.top = rect.bottom - ydif;
570 r = CC_HSLtoRGB('R', hue, sat, 120);
571 g = CC_HSLtoRGB('G', hue, sat, 120);
572 b = CC_HSLtoRGB('B', hue, sat, 120);
573 hbrush = CreateSolidBrush( RGB(r, g, b));
574 FillRect(lpp->hdcMem, &rect, hbrush);
575 DeleteObject(hbrush);
576 rect.bottom = rect.top;
578 rect.left = rect.right;
580 ReleaseDC(hwnd, hdc);
584 /***********************************************************************
585 * CC_PaintColorGraph [internal]
587 static void CC_PaintColorGraph( HWND hDlg )
589 HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
590 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
593 if (IsWindowVisible(hwnd)) /* if full size */
596 CC_PrepareColorGraph(hDlg); /* should not be necessary */
599 GetClientRect(hwnd, &rect);
601 BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
603 WARN("choose color: hdcMem is not defined\n");
604 ReleaseDC(hwnd, hDC);
608 /***********************************************************************
609 * CC_PaintLumBar [internal]
611 static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
613 HWND hwnd = GetDlgItem(hDlg, 0x2be);
615 int lum, ldif, ydif, r, g, b;
619 if (IsWindowVisible(hwnd))
622 GetClientRect(hwnd, &client);
626 ydif = client.bottom / YSTEPS+1;
627 for (lum = 0; lum < 240 + ldif; lum += ldif)
629 rect.top = max(0, rect.bottom - ydif);
630 r = CC_HSLtoRGB('R', hue, sat, lum);
631 g = CC_HSLtoRGB('G', hue, sat, lum);
632 b = CC_HSLtoRGB('B', hue, sat, lum);
633 hbrush = CreateSolidBrush( RGB(r, g, b) );
634 FillRect(hDC, &rect, hbrush);
635 DeleteObject(hbrush);
636 rect.bottom = rect.top;
638 GetClientRect(hwnd, &rect);
639 FrameRect(hDC, &rect, GetStockObject(BLACK_BRUSH) );
640 ReleaseDC(hwnd, hDC);
644 /***********************************************************************
645 * CC_EditSetRGB [internal]
647 void CC_EditSetRGB( HWND hDlg, COLORREF cr )
650 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
651 int r = GetRValue(cr);
652 int g = GetGValue(cr);
653 int b = GetBValue(cr);
654 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
656 lpp->updating = TRUE;
657 sprintf(buffer, "%d", r);
658 SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
659 sprintf(buffer, "%d", g);
660 SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
661 sprintf( buffer, "%d", b );
662 SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
663 lpp->updating = FALSE;
667 /***********************************************************************
668 * CC_EditSetHSL [internal]
670 void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
673 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
675 if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) )) /* if full size */
677 lpp->updating = TRUE;
678 sprintf(buffer, "%d", h);
679 SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
680 sprintf(buffer, "%d", s);
681 SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
682 sprintf(buffer, "%d", l);
683 SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
684 lpp->updating = FALSE;
686 CC_PaintLumBar(hDlg, h, s);
689 /***********************************************************************
690 * CC_SwitchToFullSize [internal]
692 void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPRECT lprect )
695 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
697 EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
698 CC_PrepareColorGraph(hDlg);
699 for (i = 0x2bf; i < 0x2c5; i++)
700 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
701 for (i = 0x2d3; i < 0x2d9; i++)
702 ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
703 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
704 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
705 ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);
708 SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
709 lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
711 ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
712 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);
714 CC_EditSetRGB(hDlg, result);
715 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
716 ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
717 UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
720 /***********************************************************************
721 * CC_PaintPredefColorArray [internal]
722 * Paints the default standard 48 colors
724 static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
726 HWND hwnd = GetDlgItem(hDlg, 0x2d0);
731 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
733 GetClientRect(hwnd, &rect);
734 dx = rect.right / cols;
735 dy = rect.bottom / rows;
739 GetClientRect(hwnd, &rect);
740 FillRect(hdc, &rect, (HBRUSH)GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND));
741 for ( j = 0; j < rows; j++ )
743 for ( i = 0; i < cols; i++ )
745 hBrush = CreateSolidBrush(predefcolors[j][i]);
748 hBrush = SelectObject(hdc, hBrush);
749 Rectangle(hdc, rect.left, rect.top,
750 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
751 rect.left = rect.left + dx;
752 DeleteObject(SelectObject(hdc, hBrush)) ;
755 rect.top = rect.top + dy;
758 ReleaseDC(hwnd, hdc);
759 if (lpp->hwndFocus == hwnd)
760 CC_DrawCurrentFocusRect(lpp);
762 /***********************************************************************
763 * CC_PaintUserColorArray [internal]
764 * Paint the 16 user-selected colors
766 void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, COLORREF* lpcr )
768 HWND hwnd = GetDlgItem(hDlg, 0x2d1);
773 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
775 GetClientRect(hwnd, &rect);
777 dx = rect.right / cols;
778 dy = rect.bottom / rows;
784 FillRect(hdc, &rect, (HBRUSH)GetClassLongPtrW(hwnd, GCLP_HBRBACKGROUND) );
785 for (j = 0; j < rows; j++)
787 for (i = 0; i < cols; i++)
789 hBrush = CreateSolidBrush(lpcr[i+j*cols]);
792 hBrush = SelectObject(hdc, hBrush) ;
793 Rectangle(hdc, rect.left, rect.top,
794 rect.left + dx - DISTANCE, rect.top + dy - DISTANCE);
795 rect.left = rect.left + dx;
796 DeleteObject( SelectObject(hdc, hBrush) ) ;
799 rect.top = rect.top + dy;
802 ReleaseDC(hwnd, hdc);
804 if (lpp->hwndFocus == hwnd)
805 CC_DrawCurrentFocusRect(lpp);
810 /***********************************************************************
811 * CC_HookCallChk [internal]
813 BOOL CC_HookCallChk( LPCHOOSECOLORW lpcc )
816 if(lpcc->Flags & CC_ENABLEHOOK)
822 /***********************************************************************
823 * CC_WMInitDialog [internal]
825 static LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
834 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
835 lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
837 lpp->lpcc = (LPCHOOSECOLORW) lParam;
838 if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
840 HeapFree(GetProcessHeap(), 0, lpp);
841 EndDialog (hDlg, 0) ;
845 SetWindowLongPtrW(hDlg, DWLP_USER, (LONG_PTR)lpp);
847 if (!(lpp->lpcc->Flags & CC_SHOWHELP))
848 ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
849 lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
852 cpos = MAKELONG(5,7); /* init */
853 if (lpp->lpcc->Flags & CC_RGBINIT)
855 for (i = 0; i < 6; i++)
856 for (j = 0; j < 8; j++)
857 if (predefcolors[i][j] == lpp->lpcc->rgbResult)
859 cpos = MAKELONG(i,j);
864 /* FIXME: Draw_a_focus_rect & set_init_values */
867 GetWindowRect(hDlg, &lpp->fullsize);
868 if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
870 hwnd = GetDlgItem(hDlg, 0x2cf);
871 EnableWindow(hwnd, FALSE);
873 if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
875 rect = lpp->fullsize;
876 res = rect.bottom - rect.top;
877 hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
878 point.x = point.y = 0;
879 ClientToScreen(hwnd, &point);
880 ScreenToClient(hDlg,&point);
881 GetClientRect(hDlg, &rect);
882 point.x += GetSystemMetrics(SM_CXDLGFRAME);
883 SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
885 for (i = 0x2bf; i < 0x2c5; i++)
886 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
887 for (i = 0x2d3; i < 0x2d9; i++)
888 ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
889 ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
890 ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
891 ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
892 ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
893 ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
896 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
898 for (i = 0x2bf; i < 0x2c5; i++)
899 SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0); /* max 3 digits: xyz */
900 if (CC_HookCallChk(lpp->lpcc))
902 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
905 /* Set the initial values of the color chooser dialog */
906 r = GetRValue(lpp->lpcc->rgbResult);
907 g = GetGValue(lpp->lpcc->rgbResult);
908 b = GetBValue(lpp->lpcc->rgbResult);
910 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
911 lpp->h = CC_RGBtoHSL('H', r, g, b);
912 lpp->s = CC_RGBtoHSL('S', r, g, b);
913 lpp->l = CC_RGBtoHSL('L', r, g, b);
915 /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
916 SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
917 SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
918 SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
919 SetDlgItemInt(hDlg, 706, r, TRUE);
920 SetDlgItemInt(hDlg, 707, g, TRUE);
921 SetDlgItemInt(hDlg, 708, b, TRUE);
923 CC_PaintCross(hDlg, lpp->h, lpp->s);
924 CC_PaintTriangle(hDlg, lpp->l);
930 /***********************************************************************
931 * CC_WMCommand [internal]
933 LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
939 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
940 TRACE("CC_WMCommand wParam=%x lParam=%lx\n", wParam, lParam);
941 switch (LOWORD(wParam))
943 case 0x2c2: /* edit notify RGB */
946 if (notifyCode == EN_UPDATE && !lpp->updating)
948 i = CC_CheckDigitsInEdit(hwndCtl, 255);
949 r = GetRValue(lpp->lpcc->rgbResult);
950 g = GetGValue(lpp->lpcc->rgbResult);
951 b= GetBValue(lpp->lpcc->rgbResult);
953 switch (LOWORD(wParam))
955 case 0x2c2: if ((xx = (i != r))) r = i; break;
956 case 0x2c3: if ((xx = (i != g))) g = i; break;
957 case 0x2c4: if ((xx = (i != b))) b = i; break;
959 if (xx) /* something has changed */
961 lpp->lpcc->rgbResult = RGB(r, g, b);
962 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
963 lpp->h = CC_RGBtoHSL('H', r, g, b);
964 lpp->s = CC_RGBtoHSL('S', r, g, b);
965 lpp->l = CC_RGBtoHSL('L', r, g, b);
966 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
967 CC_PaintCross(hDlg, lpp->h, lpp->s);
968 CC_PaintTriangle(hDlg, lpp->l);
973 case 0x2bf: /* edit notify HSL */
976 if (notifyCode == EN_UPDATE && !lpp->updating)
978 i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == 0x2bf ? 239:240);
980 switch (LOWORD(wParam))
982 case 0x2bf: if ((xx = ( i != lpp->h))) lpp->h = i; break;
983 case 0x2c0: if ((xx = ( i != lpp->s))) lpp->s = i; break;
984 case 0x2c1: if ((xx = ( i != lpp->l))) lpp->l = i; break;
986 if (xx) /* something has changed */
988 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
989 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
990 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
991 lpp->lpcc->rgbResult = RGB(r, g, b);
992 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
993 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
994 CC_PaintCross(hDlg, lpp->h, lpp->s);
995 CC_PaintTriangle(hDlg, lpp->l);
1001 CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, &lpp->fullsize);
1002 SetFocus( GetDlgItem(hDlg, 0x2bf));
1005 case 0x2c8: /* add colors ... column by column */
1006 cr = lpp->lpcc->lpCustColors;
1007 cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
1008 if (++lpp->nextuserdef == 16)
1009 lpp->nextuserdef = 0;
1010 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
1013 case 0x2c9: /* resulting color */
1015 lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
1016 ReleaseDC(hDlg, hdc);
1017 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1018 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1019 r = GetRValue(lpp->lpcc->rgbResult);
1020 g = GetGValue(lpp->lpcc->rgbResult);
1021 b = GetBValue(lpp->lpcc->rgbResult);
1022 lpp->h = CC_RGBtoHSL('H', r, g, b);
1023 lpp->s = CC_RGBtoHSL('S', r, g, b);
1024 lpp->l = CC_RGBtoHSL('L', r, g, b);
1025 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
1026 CC_PaintCross(hDlg, lpp->h, lpp->s);
1027 CC_PaintTriangle(hDlg, lpp->l);
1030 case 0x40e: /* Help! */ /* The Beatles, 1965 ;-) */
1031 i = RegisterWindowMessageA(HELPMSGSTRINGA);
1032 if (lpp->lpcc->hwndOwner)
1033 SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
1034 if ( CC_HookCallChk(lpp->lpcc))
1035 CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
1036 WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
1040 cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
1041 if (lpp->lpcc->hwndOwner)
1042 if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
1043 break; /* do NOT close */
1044 EndDialog(hDlg, 1) ;
1048 EndDialog(hDlg, 0) ;
1055 /***********************************************************************
1056 * CC_WMPaint [internal]
1058 LRESULT CC_WMPaint( HWND hDlg, WPARAM wParam, LPARAM lParam )
1061 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
1063 BeginPaint(hDlg, &ps);
1064 /* we have to paint dialog children except text and buttons */
1065 CC_PaintPredefColorArray(hDlg, 6, 8);
1066 CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
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 CC_PaintColorGraph(hDlg);
1072 EndPaint(hDlg, &ps);
1077 /***********************************************************************
1078 * CC_WMLButtonUp [internal]
1080 LRESULT CC_WMLButtonUp( HWND hDlg, WPARAM wParam, LPARAM lParam )
1082 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
1083 if (lpp->capturedGraph)
1085 lpp->capturedGraph = 0;
1087 CC_PaintCross(hDlg, lpp->h, lpp->s);
1093 /***********************************************************************
1094 * CC_WMMouseMove [internal]
1096 LRESULT CC_WMMouseMove( HWND hDlg, LPARAM lParam )
1098 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
1101 if (lpp->capturedGraph)
1103 int *ptrh = NULL, *ptrs = &lpp->l;
1104 if (lpp->capturedGraph == 0x2c6)
1109 if (CC_MouseCheckColorGraph( hDlg, lpp->capturedGraph, ptrh, ptrs, lParam))
1111 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
1112 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
1113 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
1114 lpp->lpcc->rgbResult = RGB(r, g, b);
1115 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1116 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1117 CC_PaintCross(hDlg, lpp->h, lpp->s);
1118 CC_PaintTriangle(hDlg, lpp->l);
1119 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1124 lpp->capturedGraph = 0;
1131 /***********************************************************************
1132 * CC_WMLButtonDown [internal]
1134 LRESULT CC_WMLButtonDown( HWND hDlg, WPARAM wParam, LPARAM lParam )
1136 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
1140 if (CC_MouseCheckPredefColorArray(lpp, hDlg, 0x2d0, 6, 8, lParam))
1143 if (CC_MouseCheckUserColorArray(lpp, hDlg, 0x2d1, 2, 8, lParam))
1146 if (CC_MouseCheckColorGraph(hDlg, 0x2c6, &lpp->h, &lpp->s, lParam))
1149 lpp->capturedGraph = 0x2c6;
1152 if (CC_MouseCheckColorGraph(hDlg, 0x2be, NULL, &lpp->l, lParam))
1155 lpp->capturedGraph = 0x2be;
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);
1167 r = GetRValue(lpp->lpcc->rgbResult);
1168 g = GetGValue(lpp->lpcc->rgbResult);
1169 b = GetBValue(lpp->lpcc->rgbResult);
1170 lpp->h = CC_RGBtoHSL('H', r, g, b);
1171 lpp->s = CC_RGBtoHSL('S', r, g, b);
1172 lpp->l = CC_RGBtoHSL('L', r, g, b);
1176 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
1177 CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
1178 CC_PaintCross(hDlg, lpp->h, lpp->s);
1179 CC_PaintTriangle(hDlg, lpp->l);
1180 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
1186 /***********************************************************************
1187 * ColorDlgProc32 [internal]
1190 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
1191 WPARAM wParam, LPARAM lParam )
1195 LCCPRIV lpp = (LCCPRIV)GetWindowLongPtrW(hDlg, DWLP_USER);
1196 if (message != WM_INITDIALOG)
1201 if (CC_HookCallChk(lpp->lpcc))
1202 res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
1207 /* FIXME: SetRGB message
1208 if (message && message == msetrgb)
1209 return HandleSetRGB(hDlg, lParam);
1215 return CC_WMInitDialog(hDlg, wParam, lParam);
1217 DeleteDC(lpp->hdcMem);
1218 DeleteObject(lpp->hbmMem);
1219 HeapFree(GetProcessHeap(), 0, lpp);
1220 SetWindowLongPtrW(hDlg, DWLP_USER, 0); /* we don't need it anymore */
1223 if (CC_WMCommand( hDlg, wParam, lParam, HIWORD(wParam), (HWND) lParam))
1227 if ( CC_WMPaint(hDlg, wParam, lParam))
1230 case WM_LBUTTONDBLCLK:
1231 if (CC_MouseCheckResultWindow(hDlg, lParam))
1235 if (CC_WMMouseMove(hDlg, lParam))
1238 case WM_LBUTTONUP: /* FIXME: ClipCursor off (if in color graph)*/
1239 if (CC_WMLButtonUp(hDlg, wParam, lParam))
1242 case WM_LBUTTONDOWN:/* FIXME: ClipCursor on (if in color graph)*/
1243 if (CC_WMLButtonDown(hDlg, wParam, lParam))
1250 /***********************************************************************
1251 * ChooseColorW (COMDLG32.@)
1253 * Create a color dialog box.
1256 * lpChCol [I/O] in: information to initialize the dialog box.
1257 * out: User's color selection
1260 * TRUE: Ok button clicked.
1261 * FALSE: Cancel button clicked, or error.
1263 BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
1265 HANDLE hDlgTmpl = 0;
1269 TRACE("ChooseColor\n");
1270 if (!lpChCol) return FALSE;
1272 if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
1274 if (!(template = LockResource(lpChCol->hInstance)))
1276 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1280 else if (lpChCol->Flags & CC_ENABLETEMPLATE)
1283 if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
1284 lpChCol->lpTemplateName,
1285 (LPWSTR)RT_DIALOG)))
1287 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1290 if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
1291 !(template = LockResource(hDlgTmpl)))
1293 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1301 static const WCHAR wszCHOOSE_COLOR[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
1302 if (!(hResInfo = FindResourceW(COMDLG32_hInstance, wszCHOOSE_COLOR, (LPWSTR)RT_DIALOG)))
1304 COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
1307 if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
1308 !(template = LockResource(hDlgTmpl)))
1310 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1315 bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
1316 ColorDlgProc, (LPARAM)lpChCol);
1320 /***********************************************************************
1321 * ChooseColorA (COMDLG32.@)
1325 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
1329 LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
1330 lpcc->lStructSize = sizeof(*lpcc);
1331 lpcc->hwndOwner = lpChCol->hwndOwner;
1332 lpcc->hInstance = lpChCol->hInstance;
1333 lpcc->rgbResult = lpChCol->rgbResult;
1334 lpcc->lpCustColors = lpChCol->lpCustColors;
1335 lpcc->Flags = lpChCol->Flags;
1336 lpcc->lCustData = lpChCol->lCustData;
1337 lpcc->lpfnHook = (LPCCHOOKPROC) lpChCol->lpfnHook;
1338 if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
1339 if (HIWORD(lpChCol->lpTemplateName)) {
1340 INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
1341 lpcc->lpTemplateName = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
1342 MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, (LPWSTR)lpcc->lpTemplateName, len );
1344 lpcc->lpTemplateName = (LPWSTR)lpChCol->lpTemplateName;
1348 ret = ChooseColorW(lpcc);
1351 lpChCol->rgbResult = lpcc->rgbResult;
1352 if (HIWORD(lpcc->lpTemplateName)) HeapFree(GetProcessHeap(), 0, (LPSTR)lpcc->lpTemplateName);
1353 HeapFree(GetProcessHeap(), 0, lpcc);