ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

colordlg.c
Go to the documentation of this file.
00001 /*
00002  * COMMDLG - Color Dialog
00003  *
00004  * Copyright 1994 Martin Ayotte
00005  * Copyright 1996 Albrecht Kleine
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00020  */
00021 
00022 /* BUGS : still seems to not refresh correctly
00023    sometimes, especially when 2 instances of the
00024    dialog are loaded at the same time */
00025 
00026 #include <ctype.h>
00027 #include <stdlib.h>
00028 #include <stdarg.h>
00029 #include <stdio.h>
00030 #include <string.h>
00031 #include "windef.h"
00032 #include "winbase.h"
00033 #include "wingdi.h"
00034 #include "winuser.h"
00035 #include "commdlg.h"
00036 #include "dlgs.h"
00037 #include "wine/debug.h"
00038 #include "cderr.h"
00039 #include "cdlg.h"
00040 
00041 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
00042 
00043 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
00044 
00045 #define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
00046 
00047 static const COLORREF predefcolors[6][8]=
00048 {
00049  { 0x008080FFL, 0x0080FFFFL, 0x0080FF80L, 0x0080FF00L,
00050    0x00FFFF80L, 0x00FF8000L, 0x00C080FFL, 0x00FF80FFL },
00051  { 0x000000FFL, 0x0000FFFFL, 0x0000FF80L, 0x0040FF00L,
00052    0x00FFFF00L, 0x00C08000L, 0x00C08080L, 0x00FF00FFL },
00053 
00054  { 0x00404080L, 0x004080FFL, 0x0000FF00L, 0x00808000L,
00055    0x00804000L, 0x00FF8080L, 0x00400080L, 0x008000FFL },
00056  { 0x00000080L, 0x000080FFL, 0x00008000L, 0x00408000L,
00057    0x00FF0000L, 0x00A00000L, 0x00800080L, 0x00FF0080L },
00058 
00059  { 0x00000040L, 0x00004080L, 0x00004000L, 0x00404000L,
00060    0x00800000L, 0x00400000L, 0x00400040L, 0x00800040L },
00061  { 0x00000000L, 0x00008080L, 0x00408080L, 0x00808080L,
00062    0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
00063 };
00064 
00065 static const WCHAR szColourDialogProp[] = {
00066     'c','o','l','o','u','r','d','i','a','l','o','g','p','r','o','p',0 };
00067 
00068 /* Chose Color PRIVATE Structure:
00069  *
00070  * This structure is duplicated in the 16 bit code with
00071  * an extra member
00072  */
00073 
00074 typedef struct CCPRIVATE
00075 {
00076     LPCHOOSECOLORW lpcc; /* points to public known data structure */
00077     int nextuserdef;     /* next free place in user defined color array */
00078     HDC hdcMem;          /* color graph used for BitBlt() */
00079     HBITMAP hbmMem;      /* color graph bitmap */
00080     RECT fullsize;       /* original dialog window size */
00081     UINT msetrgb;        /* # of SETRGBSTRING message (today not used)  */
00082     RECT old3angle;      /* last position of l-marker */
00083     RECT oldcross;       /* last position of color/saturation marker */
00084     BOOL updating;       /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
00085     int h;
00086     int s;
00087     int l;               /* for temporary storing of hue,sat,lum */
00088     int capturedGraph;   /* control mouse captured */
00089     RECT focusRect;      /* rectangle last focused item */
00090     HWND hwndFocus;      /* handle last focused item */
00091 } CCPRIV, *LPCCPRIV;
00092 
00093 /***********************************************************************
00094  *                             CC_HSLtoRGB                    [internal]
00095  */
00096 static int CC_HSLtoRGB(char c, int hue, int sat, int lum)
00097 {
00098  int res = 0, maxrgb;
00099 
00100  /* hue */
00101  switch(c)
00102  {
00103   case 'R': if (hue > 80)  hue -= 80; else hue += 160; break;
00104   case 'G': if (hue > 160) hue -= 160; else hue += 80; break;
00105   case 'B': break;
00106  }
00107 
00108  /* l below 120 */
00109  maxrgb = (256 * min(120,lum)) / 120;  /* 0 .. 256 */
00110  if (hue < 80)
00111   res = 0;
00112  else
00113   if (hue < 120)
00114   {
00115    res = (hue - 80) * maxrgb;           /* 0...10240 */
00116    res /= 40;                        /* 0...256 */
00117   }
00118   else
00119    if (hue < 200)
00120     res = maxrgb;
00121    else
00122     {
00123      res= (240 - hue) * maxrgb;
00124      res /= 40;
00125     }
00126  res = res - maxrgb / 2;                 /* -128...128 */
00127 
00128  /* saturation */
00129  res = maxrgb / 2 + (sat * res) / 240;    /* 0..256 */
00130 
00131  /* lum above 120 */
00132  if (lum > 120 && res < 256)
00133   res += ((lum - 120) * (256 - res)) / 120;
00134 
00135  return min(res, 255);
00136 }
00137 
00138 /***********************************************************************
00139  *                             CC_RGBtoHSL                    [internal]
00140  */
00141 static int CC_RGBtoHSL(char c, int r, int g, int b)
00142 {
00143  WORD maxi, mini, mmsum, mmdif, result = 0;
00144  int iresult = 0;
00145 
00146  maxi = max(r, b);
00147  maxi = max(maxi, g);
00148  mini = min(r, b);
00149  mini = min(mini, g);
00150 
00151  mmsum = maxi + mini;
00152  mmdif = maxi - mini;
00153 
00154  switch(c)
00155  {
00156   /* lum */
00157   case 'L': mmsum *= 120;              /* 0...61200=(255+255)*120 */
00158        result = mmsum / 255;        /* 0...240 */
00159        break;
00160   /* saturation */
00161   case 'S': if (!mmsum)
00162         result = 0;
00163        else
00164         if (!mini || maxi == 255)
00165          result = 240;
00166        else
00167        {
00168         result = mmdif * 240;       /* 0...61200=255*240 */
00169         result /= (mmsum > 255 ? 510 - mmsum : mmsum); /* 0..255 */
00170        }
00171        break;
00172   /* hue */
00173   case 'H': if (!mmdif)
00174         result = 160;
00175        else
00176        {
00177         if (maxi == r)
00178         {
00179          iresult = 40 * (g - b);       /* -10200 ... 10200 */
00180          iresult /= (int) mmdif;    /* -40 .. 40 */
00181          if (iresult < 0)
00182           iresult += 240;          /* 0..40 and 200..240 */
00183         }
00184         else
00185          if (maxi == g)
00186          {
00187           iresult = 40 * (b - r);
00188           iresult /= (int) mmdif;
00189           iresult += 80;           /* 40 .. 120 */
00190          }
00191          else
00192           if (maxi == b)
00193           {
00194            iresult = 40 * (r - g);
00195            iresult /= (int) mmdif;
00196            iresult += 160;         /* 120 .. 200 */
00197           }
00198         result = iresult;
00199        }
00200        break;
00201  }
00202  return result;    /* is this integer arithmetic precise enough ? */
00203 }
00204 
00205 
00206 /***********************************************************************
00207  *                  CC_DrawCurrentFocusRect                       [internal]
00208  */
00209 static void CC_DrawCurrentFocusRect( const CCPRIV *lpp )
00210 {
00211   if (lpp->hwndFocus)
00212   {
00213     HDC hdc = GetDC(lpp->hwndFocus);
00214     DrawFocusRect(hdc, &lpp->focusRect);
00215     ReleaseDC(lpp->hwndFocus, hdc);
00216   }
00217 }
00218 
00219 /***********************************************************************
00220  *                  CC_DrawFocusRect                       [internal]
00221  */
00222 static void CC_DrawFocusRect( LPCCPRIV lpp, HWND hwnd, int x, int y, int rows, int cols)
00223 {
00224   RECT rect;
00225   int dx, dy;
00226   HDC hdc;
00227 
00228   CC_DrawCurrentFocusRect(lpp); /* remove current focus rect */
00229   /* calculate new rect */
00230   GetClientRect(hwnd, &rect);
00231   dx = (rect.right - rect.left) / cols;
00232   dy = (rect.bottom - rect.top) / rows;
00233   rect.left += (x * dx) - 2;
00234   rect.top += (y * dy) - 2;
00235   rect.right = rect.left + dx;
00236   rect.bottom = rect.top + dy;
00237   /* draw it */
00238   hdc = GetDC(hwnd);
00239   DrawFocusRect(hdc, &rect);
00240   CopyRect(&lpp->focusRect, &rect);
00241   lpp->hwndFocus = hwnd;
00242   ReleaseDC(hwnd, hdc);
00243 }
00244 
00245 #define DISTANCE 4
00246 
00247 /***********************************************************************
00248  *                CC_MouseCheckPredefColorArray               [internal]
00249  *                returns 1 if one of the predefined colors is clicked
00250  */
00251 static int CC_MouseCheckPredefColorArray( LPCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
00252         LPARAM lParam )
00253 {
00254  HWND hwnd;
00255  POINT point;
00256  RECT rect;
00257  int dx, dy, x, y;
00258 
00259  CONV_LPARAMTOPOINT(lParam, &point);
00260  ClientToScreen(hDlg, &point);
00261  hwnd = GetDlgItem(hDlg, dlgitem);
00262  GetWindowRect(hwnd, &rect);
00263  if (PtInRect(&rect, point))
00264  {
00265   dx = (rect.right - rect.left) / cols;
00266   dy = (rect.bottom - rect.top) / rows;
00267   ScreenToClient(hwnd, &point);
00268 
00269   if (point.x % dx < ( dx - DISTANCE) && point.y % dy < ( dy - DISTANCE))
00270   {
00271    x = point.x / dx;
00272    y = point.y / dy;
00273    lpp->lpcc->rgbResult = predefcolors[y][x];
00274    CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
00275    return 1;
00276   }
00277  }
00278  return 0;
00279 }
00280 
00281 /***********************************************************************
00282  *                  CC_MouseCheckUserColorArray               [internal]
00283  *                  return 1 if the user clicked a color
00284  */
00285 static int CC_MouseCheckUserColorArray( LPCCPRIV lpp, HWND hDlg, int dlgitem, int rows, int cols,
00286         LPARAM lParam )
00287 {
00288  HWND hwnd;
00289  POINT point;
00290  RECT rect;
00291  int dx, dy, x, y;
00292  COLORREF *crarr = lpp->lpcc->lpCustColors;
00293 
00294  CONV_LPARAMTOPOINT(lParam, &point);
00295  ClientToScreen(hDlg, &point);
00296  hwnd = GetDlgItem(hDlg, dlgitem);
00297  GetWindowRect(hwnd, &rect);
00298  if (PtInRect(&rect, point))
00299  {
00300   dx = (rect.right - rect.left) / cols;
00301   dy = (rect.bottom - rect.top) / rows;
00302   ScreenToClient(hwnd, &point);
00303 
00304   if (point.x % dx < (dx - DISTANCE) && point.y % dy < (dy - DISTANCE))
00305   {
00306    x = point.x / dx;
00307    y = point.y / dy;
00308    lpp->lpcc->rgbResult = crarr[x + (cols * y) ];
00309    CC_DrawFocusRect(lpp, hwnd, x, y, rows, cols);
00310    return 1;
00311   }
00312  }
00313  return 0;
00314 }
00315 
00316 #define MAXVERT  240
00317 #define MAXHORI  239
00318 
00319 /*  240  ^......        ^^ 240
00320      |     .        ||
00321     SAT  |     .        || LUM
00322      |     .        ||
00323      +-----> 239   ----
00324        HUE
00325 */
00326 /***********************************************************************
00327  *                  CC_MouseCheckColorGraph                   [internal]
00328  */
00329 static int CC_MouseCheckColorGraph( HWND hDlg, int dlgitem, int *hori, int *vert, LPARAM lParam )
00330 {
00331  HWND hwnd;
00332  POINT point;
00333  RECT rect;
00334  long x,y;
00335 
00336  CONV_LPARAMTOPOINT(lParam, &point);
00337  ClientToScreen(hDlg, &point);
00338  hwnd = GetDlgItem( hDlg, dlgitem );
00339  GetWindowRect(hwnd, &rect);
00340 
00341  if (!PtInRect(&rect, point))
00342   return 0;
00343 
00344  GetClientRect(hwnd, &rect);
00345  ScreenToClient(hwnd, &point);
00346 
00347  x = (long) point.x * MAXHORI;
00348  x /= rect.right;
00349  y = (long) (rect.bottom - point.y) * MAXVERT;
00350  y /= rect.bottom;
00351 
00352  if (x < 0) x = 0;
00353  if (y < 0) y = 0;
00354  if (x > MAXHORI) x = MAXHORI;
00355  if (y > MAXVERT) y = MAXVERT;
00356 
00357  if (hori)
00358   *hori = x;
00359  if (vert)
00360   *vert = y;
00361 
00362  return 1;
00363 }
00364 /***********************************************************************
00365  *                  CC_MouseCheckResultWindow                 [internal]
00366  *                  test if double click one of the result colors
00367  */
00368 static int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
00369 {
00370  HWND hwnd;
00371  POINT point;
00372  RECT rect;
00373 
00374  CONV_LPARAMTOPOINT(lParam, &point);
00375  ClientToScreen(hDlg, &point);
00376  hwnd = GetDlgItem(hDlg, 0x2c5);
00377  GetWindowRect(hwnd, &rect);
00378  if (PtInRect(&rect, point))
00379  {
00380   PostMessageA(hDlg, WM_COMMAND, 0x2c9, 0);
00381   return 1;
00382  }
00383  return 0;
00384 }
00385 
00386 /***********************************************************************
00387  *                       CC_CheckDigitsInEdit                 [internal]
00388  */
00389 static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
00390 {
00391  int i, k, m, result, value;
00392  long editpos;
00393  char buffer[30];
00394 
00395  GetWindowTextA(hwnd, buffer, sizeof(buffer));
00396  m = strlen(buffer);
00397  result = 0;
00398 
00399  for (i = 0 ; i < m ; i++)
00400   if (buffer[i] < '0' || buffer[i] > '9')
00401   {
00402    for (k = i + 1; k <= m; k++)  /* delete bad character */
00403    {
00404     buffer[i] = buffer[k];
00405     m--;
00406    }
00407    buffer[m] = 0;
00408    result = 1;
00409   }
00410 
00411  value = atoi(buffer);
00412  if (value > maxval)       /* build a new string */
00413  {
00414   sprintf(buffer, "%d", maxval);
00415   result = 2;
00416  }
00417  if (result)
00418  {
00419   editpos = SendMessageA(hwnd, EM_GETSEL, 0, 0);
00420   SetWindowTextA(hwnd, buffer );
00421   SendMessageA(hwnd, EM_SETSEL, 0, editpos);
00422  }
00423  return value;
00424 }
00425 
00426 
00427 
00428 /***********************************************************************
00429  *                    CC_PaintSelectedColor                   [internal]
00430  */
00431 static void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
00432 {
00433  RECT rect;
00434  HDC  hdc;
00435  HBRUSH hBrush;
00436  HWND hwnd = GetDlgItem(hDlg, 0x2c5);
00437  if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
00438  {
00439   hdc = GetDC(hwnd);
00440   GetClientRect(hwnd, &rect) ;
00441   hBrush = CreateSolidBrush(cr);
00442   if (hBrush)
00443   {
00444    FillRect(hdc, &rect, hBrush);
00445    DrawEdge(hdc, &rect, BDR_SUNKENOUTER, BF_RECT);
00446    DeleteObject(hBrush);
00447   }
00448   ReleaseDC(hwnd, hdc);
00449  }
00450 }
00451 
00452 /***********************************************************************
00453  *                    CC_PaintTriangle                        [internal]
00454  */
00455 static void CC_PaintTriangle( HWND hDlg, int y)
00456 {
00457  HDC hDC;
00458  long temp;
00459  int w = LOWORD(GetDialogBaseUnits()) / 2;
00460  POINT points[3];
00461  int height;
00462  int oben;
00463  RECT rect;
00464  HBRUSH hbr;
00465  HWND hwnd = GetDlgItem(hDlg, 0x2be);
00466  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00467 
00468  if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6)))   /* if full size */
00469  {
00470    GetClientRect(hwnd, &rect);
00471    height = rect.bottom;
00472    hDC = GetDC(hDlg);
00473    points[0].y = rect.top;
00474    points[0].x = rect.right;     /*  |  /|  */
00475    ClientToScreen(hwnd, points); /*  | / |  */
00476    ScreenToClient(hDlg, points); /*  |<  |  */
00477    oben = points[0].y;           /*  | \ |  */
00478                                  /*  |  \|  */
00479    temp = (long)height * (long)y;
00480    points[0].x += 1;
00481    points[0].y = oben + height - temp / (long)MAXVERT;
00482    points[1].y = points[0].y + w;
00483    points[2].y = points[0].y - w;
00484    points[2].x = points[1].x = points[0].x + w;
00485 
00486    hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
00487    if (!hbr) hbr = GetSysColorBrush(COLOR_BTNFACE);
00488    FillRect(hDC, &lpp->old3angle, hbr);
00489    lpp->old3angle.left  = points[0].x;
00490    lpp->old3angle.right = points[1].x + 1;
00491    lpp->old3angle.top   = points[2].y - 1;
00492    lpp->old3angle.bottom= points[1].y + 1;
00493 
00494    hbr = SelectObject(hDC, GetStockObject(BLACK_BRUSH));
00495    Polygon(hDC, points, 3);
00496    SelectObject(hDC, hbr);
00497 
00498    ReleaseDC(hDlg, hDC);
00499  }
00500 }
00501 
00502 
00503 /***********************************************************************
00504  *                    CC_PaintCross                           [internal]
00505  */
00506 static void CC_PaintCross( HWND hDlg, int x, int y)
00507 {
00508  HDC hDC;
00509  int w = GetDialogBaseUnits() - 1;
00510  int wc = GetDialogBaseUnits() * 3 / 4;
00511  HWND hwnd = GetDlgItem(hDlg, 0x2c6);
00512  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00513  RECT rect;
00514  POINT point, p;
00515  HPEN hPen;
00516 
00517  if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
00518  {
00519    GetClientRect(hwnd, &rect);
00520    hDC = GetDC(hwnd);
00521    SelectClipRgn( hDC, CreateRectRgnIndirect(&rect));
00522 
00523    point.x = ((long)rect.right * (long)x) / (long)MAXHORI;
00524    point.y = rect.bottom - ((long)rect.bottom * (long)y) / (long)MAXVERT;
00525    if ( lpp->oldcross.left != lpp->oldcross.right )
00526      BitBlt(hDC, lpp->oldcross.left, lpp->oldcross.top,
00527               lpp->oldcross.right - lpp->oldcross.left,
00528               lpp->oldcross.bottom - lpp->oldcross.top,
00529               lpp->hdcMem, lpp->oldcross.left, lpp->oldcross.top, SRCCOPY);
00530    lpp->oldcross.left   = point.x - w - 1;
00531    lpp->oldcross.right  = point.x + w + 1;
00532    lpp->oldcross.top    = point.y - w - 1;
00533    lpp->oldcross.bottom = point.y + w + 1;
00534 
00535    hPen = CreatePen(PS_SOLID, 3, 0x000000); /* -black- color */
00536    hPen = SelectObject(hDC, hPen);
00537    MoveToEx(hDC, point.x - w, point.y, &p);
00538    LineTo(hDC, point.x - wc, point.y);
00539    MoveToEx(hDC, point.x + wc, point.y, &p);
00540    LineTo(hDC, point.x + w, point.y);
00541    MoveToEx(hDC, point.x, point.y - w, &p);
00542    LineTo(hDC, point.x, point.y - wc);
00543    MoveToEx(hDC, point.x, point.y + wc, &p);
00544    LineTo(hDC, point.x, point.y + w);
00545    DeleteObject( SelectObject(hDC, hPen));
00546 
00547    ReleaseDC(hwnd, hDC);
00548  }
00549 }
00550 
00551 
00552 #define XSTEPS 48
00553 #define YSTEPS 24
00554 
00555 
00556 /***********************************************************************
00557  *                    CC_PrepareColorGraph                    [internal]
00558  */
00559 static void CC_PrepareColorGraph( HWND hDlg )
00560 {
00561  int sdif, hdif, xdif, ydif, r, g, b, hue, sat;
00562  HWND hwnd = GetDlgItem(hDlg, 0x2c6);
00563  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00564  HBRUSH hbrush;
00565  HDC hdc ;
00566  RECT rect, client;
00567  HCURSOR hcursor = SetCursor( LoadCursorW(0, (LPCWSTR)IDC_WAIT) );
00568 
00569  GetClientRect(hwnd, &client);
00570  hdc = GetDC(hwnd);
00571  lpp->hdcMem = CreateCompatibleDC(hdc);
00572  lpp->hbmMem = CreateCompatibleBitmap(hdc, client.right, client.bottom);
00573  SelectObject(lpp->hdcMem, lpp->hbmMem);
00574 
00575  xdif = client.right / XSTEPS;
00576  ydif = client.bottom / YSTEPS+1;
00577  hdif = 239 / XSTEPS;
00578  sdif = 240 / YSTEPS;
00579  for (rect.left = hue = 0; hue < 239 + hdif; hue += hdif)
00580  {
00581   rect.right = rect.left + xdif;
00582   rect.bottom = client.bottom;
00583   for(sat = 0; sat < 240 + sdif; sat += sdif)
00584   {
00585    rect.top = rect.bottom - ydif;
00586    r = CC_HSLtoRGB('R', hue, sat, 120);
00587    g = CC_HSLtoRGB('G', hue, sat, 120);
00588    b = CC_HSLtoRGB('B', hue, sat, 120);
00589    hbrush = CreateSolidBrush( RGB(r, g, b));
00590    FillRect(lpp->hdcMem, &rect, hbrush);
00591    DeleteObject(hbrush);
00592    rect.bottom = rect.top;
00593   }
00594   rect.left = rect.right;
00595  }
00596  ReleaseDC(hwnd, hdc);
00597  SetCursor(hcursor);
00598 }
00599 
00600 /***********************************************************************
00601  *                          CC_PaintColorGraph                [internal]
00602  */
00603 static void CC_PaintColorGraph( HWND hDlg )
00604 {
00605  HWND hwnd = GetDlgItem( hDlg, 0x2c6 );
00606  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00607  HDC  hDC;
00608  RECT rect;
00609  if (IsWindowVisible(hwnd))   /* if full size */
00610  {
00611   if (!lpp->hdcMem)
00612    CC_PrepareColorGraph(hDlg);   /* should not be necessary */
00613 
00614   hDC = GetDC(hwnd);
00615   GetClientRect(hwnd, &rect);
00616   if (lpp->hdcMem)
00617       BitBlt(hDC, 0, 0, rect.right, rect.bottom, lpp->hdcMem, 0, 0, SRCCOPY);
00618   else
00619       WARN("choose color: hdcMem is not defined\n");
00620   ReleaseDC(hwnd, hDC);
00621  }
00622 }
00623 
00624 /***********************************************************************
00625  *                           CC_PaintLumBar                   [internal]
00626  */
00627 static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
00628 {
00629  HWND hwnd = GetDlgItem(hDlg, 0x2be);
00630  RECT rect, client;
00631  int lum, ldif, ydif, r, g, b;
00632  HBRUSH hbrush;
00633  HDC hDC;
00634 
00635  if (IsWindowVisible(hwnd))
00636  {
00637   hDC = GetDC(hwnd);
00638   GetClientRect(hwnd, &client);
00639   rect = client;
00640 
00641   ldif = 240 / YSTEPS;
00642   ydif = client.bottom / YSTEPS+1;
00643   for (lum = 0; lum < 240 + ldif; lum += ldif)
00644   {
00645    rect.top = max(0, rect.bottom - ydif);
00646    r = CC_HSLtoRGB('R', hue, sat, lum);
00647    g = CC_HSLtoRGB('G', hue, sat, lum);
00648    b = CC_HSLtoRGB('B', hue, sat, lum);
00649    hbrush = CreateSolidBrush( RGB(r, g, b) );
00650    FillRect(hDC, &rect, hbrush);
00651    DeleteObject(hbrush);
00652    rect.bottom = rect.top;
00653   }
00654   GetClientRect(hwnd, &rect);
00655   DrawEdge(hDC, &rect, BDR_SUNKENOUTER, BF_RECT);
00656   ReleaseDC(hwnd, hDC);
00657  }
00658 }
00659 
00660 /***********************************************************************
00661  *                             CC_EditSetRGB                  [internal]
00662  */
00663 static void CC_EditSetRGB( HWND hDlg, COLORREF cr )
00664 {
00665  char buffer[10];
00666  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00667  int r = GetRValue(cr);
00668  int g = GetGValue(cr);
00669  int b = GetBValue(cr);
00670  if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
00671  {
00672    lpp->updating = TRUE;
00673    sprintf(buffer, "%d", r);
00674    SetWindowTextA( GetDlgItem(hDlg, 0x2c2), buffer);
00675    sprintf(buffer, "%d", g);
00676    SetWindowTextA( GetDlgItem(hDlg, 0x2c3), buffer);
00677    sprintf( buffer, "%d", b );
00678    SetWindowTextA( GetDlgItem(hDlg, 0x2c4),buffer);
00679    lpp->updating = FALSE;
00680  }
00681 }
00682 
00683 /***********************************************************************
00684  *                             CC_EditSetHSL                  [internal]
00685  */
00686 static void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
00687 {
00688  char buffer[10];
00689  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00690 
00691  if (IsWindowVisible( GetDlgItem(hDlg, 0x2c6) ))   /* if full size */
00692  {
00693    lpp->updating = TRUE;
00694    sprintf(buffer, "%d", h);
00695    SetWindowTextA( GetDlgItem(hDlg, 0x2bf), buffer);
00696    sprintf(buffer, "%d", s);
00697    SetWindowTextA( GetDlgItem(hDlg, 0x2c0), buffer);
00698    sprintf(buffer, "%d", l);
00699    SetWindowTextA( GetDlgItem(hDlg, 0x2c1), buffer);
00700    lpp->updating = FALSE;
00701  }
00702  CC_PaintLumBar(hDlg, h, s);
00703 }
00704 
00705 /***********************************************************************
00706  *                       CC_SwitchToFullSize                  [internal]
00707  */
00708 static void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPCRECT lprect )
00709 {
00710  int i;
00711  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00712 
00713  EnableWindow( GetDlgItem(hDlg, 0x2cf), FALSE);
00714  CC_PrepareColorGraph(hDlg);
00715  for (i = 0x2bf; i < 0x2c5; i++)
00716    ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
00717  for (i = 0x2d3; i < 0x2d9; i++)
00718    ShowWindow( GetDlgItem(hDlg, i), SW_SHOW);
00719  ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_SHOW);
00720  ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_SHOW);
00721  ShowWindow( GetDlgItem(hDlg, 1090), SW_SHOW);
00722 
00723  if (lprect)
00724   SetWindowPos(hDlg, 0, 0, 0, lprect->right-lprect->left,
00725    lprect->bottom-lprect->top, SWP_NOMOVE|SWP_NOZORDER);
00726 
00727  ShowWindow( GetDlgItem(hDlg, 0x2be), SW_SHOW);
00728  ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_SHOW);
00729 
00730  CC_EditSetRGB(hDlg, result);
00731  CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
00732  ShowWindow( GetDlgItem( hDlg, 0x2c6), SW_SHOW);
00733  UpdateWindow( GetDlgItem(hDlg, 0x2c6) );
00734 }
00735 
00736 /***********************************************************************
00737  *                           CC_PaintPredefColorArray         [internal]
00738  *                Paints the default standard 48 colors
00739  */
00740 static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
00741 {
00742  HWND hwnd = GetDlgItem(hDlg, 0x2d0);
00743  RECT rect, blockrect;
00744  HDC  hdc;
00745  HBRUSH hBrush;
00746  int dx, dy, i, j, k;
00747  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00748 
00749  GetClientRect(hwnd, &rect);
00750  dx = rect.right / cols;
00751  dy = rect.bottom / rows;
00752  k = rect.left;
00753 
00754  hdc = GetDC(hwnd);
00755  GetClientRect(hwnd, &rect);
00756  hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
00757  if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
00758  FillRect(hdc, &rect, hBrush);
00759  for ( j = 0; j < rows; j++ )
00760  {
00761   for ( i = 0; i < cols; i++ )
00762   {
00763    hBrush = CreateSolidBrush(predefcolors[j][i]);
00764    if (hBrush)
00765    {
00766     blockrect.left = rect.left;
00767     blockrect.top = rect.top;
00768     blockrect.right = rect.left + dx - DISTANCE;
00769     blockrect.bottom = rect.top + dy - DISTANCE;
00770     FillRect(hdc, &blockrect, hBrush);
00771     DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
00772     DeleteObject(hBrush);
00773    }
00774    rect.left += dx;
00775   }
00776   rect.top += dy;
00777   rect.left = k;
00778  }
00779  ReleaseDC(hwnd, hdc);
00780  if (lpp->hwndFocus == hwnd)
00781    CC_DrawCurrentFocusRect(lpp);
00782 }
00783 /***********************************************************************
00784  *                             CC_PaintUserColorArray         [internal]
00785  *               Paint the 16 user-selected colors
00786  */
00787 static void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, const COLORREF *lpcr )
00788 {
00789  HWND hwnd = GetDlgItem(hDlg, 0x2d1);
00790  RECT rect, blockrect;
00791  HDC  hdc;
00792  HBRUSH hBrush;
00793  int dx, dy, i, j, k;
00794  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00795 
00796  GetClientRect(hwnd, &rect);
00797 
00798  dx = rect.right / cols;
00799  dy = rect.bottom / rows;
00800  k = rect.left;
00801 
00802  hdc = GetDC(hwnd);
00803  if (hdc)
00804  {
00805   hBrush = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND);
00806   if (!hBrush) hBrush = GetSysColorBrush(COLOR_BTNFACE);
00807   FillRect( hdc, &rect, hBrush );
00808   for (j = 0; j < rows; j++)
00809   {
00810    for (i = 0; i < cols; i++)
00811    {
00812     hBrush = CreateSolidBrush(lpcr[i+j*cols]);
00813     if (hBrush)
00814     {
00815      blockrect.left = rect.left;
00816      blockrect.top = rect.top;
00817      blockrect.right = rect.left + dx - DISTANCE;
00818      blockrect.bottom = rect.top + dy - DISTANCE;
00819      FillRect(hdc, &blockrect, hBrush);
00820      DrawEdge(hdc, &blockrect, BDR_SUNKEN, BF_RECT);
00821      DeleteObject(hBrush);
00822     }
00823     rect.left += dx;
00824    }
00825    rect.top += dy;
00826    rect.left = k;
00827   }
00828   ReleaseDC(hwnd, hdc);
00829  }
00830  if (lpp->hwndFocus == hwnd)
00831    CC_DrawCurrentFocusRect(lpp);
00832 }
00833 
00834 
00835 /***********************************************************************
00836  *                             CC_HookCallChk                 [internal]
00837  */
00838 static BOOL CC_HookCallChk( const CHOOSECOLORW *lpcc )
00839 {
00840  if (lpcc)
00841   if(lpcc->Flags & CC_ENABLEHOOK)
00842    if (lpcc->lpfnHook)
00843     return TRUE;
00844  return FALSE;
00845 }
00846 
00847 /***********************************************************************
00848  *                              CC_WMInitDialog                  [internal]
00849  */
00850 static LRESULT CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
00851 {
00852    int i, res;
00853    int r, g, b;
00854    HWND hwnd;
00855    RECT rect;
00856    POINT point;
00857    LPCCPRIV lpp;
00858 
00859    TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
00860    lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
00861 
00862    lpp->lpcc = (LPCHOOSECOLORW) lParam;
00863    if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
00864    {
00865        HeapFree(GetProcessHeap(), 0, lpp);
00866        EndDialog (hDlg, 0) ;
00867        return FALSE;
00868    }
00869 
00870    SetPropW( hDlg, szColourDialogProp, lpp );
00871 
00872    if (!(lpp->lpcc->Flags & CC_SHOWHELP))
00873       ShowWindow( GetDlgItem(hDlg,0x40e), SW_HIDE);
00874    lpp->msetrgb = RegisterWindowMessageA(SETRGBSTRINGA);
00875 
00876 #if 0
00877    cpos = MAKELONG(5,7); /* init */
00878    if (lpp->lpcc->Flags & CC_RGBINIT)
00879    {
00880      for (i = 0; i < 6; i++)
00881        for (j = 0; j < 8; j++)
00882         if (predefcolors[i][j] == lpp->lpcc->rgbResult)
00883         {
00884           cpos = MAKELONG(i,j);
00885           goto found;
00886         }
00887    }
00888    found:
00889    /* FIXME: Draw_a_focus_rect & set_init_values */
00890 #endif
00891 
00892    GetWindowRect(hDlg, &lpp->fullsize);
00893    if (lpp->lpcc->Flags & CC_FULLOPEN || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
00894    {
00895       hwnd = GetDlgItem(hDlg, 0x2cf);
00896       EnableWindow(hwnd, FALSE);
00897    }
00898    if (!(lpp->lpcc->Flags & CC_FULLOPEN ) || lpp->lpcc->Flags & CC_PREVENTFULLOPEN)
00899    {
00900       rect = lpp->fullsize;
00901       res = rect.bottom - rect.top;
00902       hwnd = GetDlgItem(hDlg, 0x2c6); /* cut at left border */
00903       point.x = point.y = 0;
00904       ClientToScreen(hwnd, &point);
00905       ScreenToClient(hDlg,&point);
00906       GetClientRect(hDlg, &rect);
00907       point.x += GetSystemMetrics(SM_CXDLGFRAME);
00908       SetWindowPos(hDlg, 0, 0, 0, point.x, res, SWP_NOMOVE|SWP_NOZORDER);
00909 
00910       for (i = 0x2bf; i < 0x2c5; i++)
00911          ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
00912       for (i = 0x2d3; i < 0x2d9; i++)
00913          ShowWindow( GetDlgItem(hDlg, i), SW_HIDE);
00914       ShowWindow( GetDlgItem(hDlg, 0x2c9), SW_HIDE);
00915       ShowWindow( GetDlgItem(hDlg, 0x2c8), SW_HIDE);
00916       ShowWindow( GetDlgItem(hDlg, 0x2c6), SW_HIDE);
00917       ShowWindow( GetDlgItem(hDlg, 0x2c5), SW_HIDE);
00918       ShowWindow( GetDlgItem(hDlg, 1090 ), SW_HIDE);
00919    }
00920    else
00921       CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, NULL);
00922    res = TRUE;
00923    for (i = 0x2bf; i < 0x2c5; i++)
00924      SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0);  /* max 3 digits:  xyz  */
00925    if (CC_HookCallChk(lpp->lpcc))
00926    {
00927           res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
00928    }
00929 
00930    /* Set the initial values of the color chooser dialog */
00931    r = GetRValue(lpp->lpcc->rgbResult);
00932    g = GetGValue(lpp->lpcc->rgbResult);
00933    b = GetBValue(lpp->lpcc->rgbResult);
00934 
00935    CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
00936    lpp->h = CC_RGBtoHSL('H', r, g, b);
00937    lpp->s = CC_RGBtoHSL('S', r, g, b);
00938    lpp->l = CC_RGBtoHSL('L', r, g, b);
00939 
00940    /* Doing it the long way because CC_EditSetRGB/HSL doesn't seem to work */
00941    SetDlgItemInt(hDlg, 703, lpp->h, TRUE);
00942    SetDlgItemInt(hDlg, 704, lpp->s, TRUE);
00943    SetDlgItemInt(hDlg, 705, lpp->l, TRUE);
00944    SetDlgItemInt(hDlg, 706, r, TRUE);
00945    SetDlgItemInt(hDlg, 707, g, TRUE);
00946    SetDlgItemInt(hDlg, 708, b, TRUE);
00947 
00948    CC_PaintCross(hDlg, lpp->h, lpp->s);
00949    CC_PaintTriangle(hDlg, lpp->l);
00950 
00951    return res;
00952 }
00953 
00954 
00955 /***********************************************************************
00956  *                              CC_WMCommand                  [internal]
00957  */
00958 static LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode, HWND hwndCtl )
00959 {
00960     int  r, g, b, i, xx;
00961     UINT cokmsg;
00962     HDC hdc;
00963     COLORREF *cr;
00964     LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
00965 
00966     TRACE("CC_WMCommand wParam=%lx lParam=%lx\n", wParam, lParam);
00967     switch (LOWORD(wParam))
00968     {
00969           case 0x2c2:  /* edit notify RGB */
00970       case 0x2c3:
00971       case 0x2c4:
00972            if (notifyCode == EN_UPDATE && !lpp->updating)
00973              {
00974                i = CC_CheckDigitsInEdit(hwndCtl, 255);
00975                r = GetRValue(lpp->lpcc->rgbResult);
00976                g = GetGValue(lpp->lpcc->rgbResult);
00977                b= GetBValue(lpp->lpcc->rgbResult);
00978                xx = 0;
00979                switch (LOWORD(wParam))
00980                {
00981                 case 0x2c2: if ((xx = (i != r))) r = i; break;
00982                 case 0x2c3: if ((xx = (i != g))) g = i; break;
00983                 case 0x2c4: if ((xx = (i != b))) b = i; break;
00984                }
00985                if (xx) /* something has changed */
00986                {
00987                 lpp->lpcc->rgbResult = RGB(r, g, b);
00988                 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
00989                 lpp->h = CC_RGBtoHSL('H', r, g, b);
00990                 lpp->s = CC_RGBtoHSL('S', r, g, b);
00991                 lpp->l = CC_RGBtoHSL('L', r, g, b);
00992                 CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
00993                 CC_PaintCross(hDlg, lpp->h, lpp->s);
00994                 CC_PaintTriangle(hDlg, lpp->l);
00995                }
00996              }
00997          break;
00998 
00999       case 0x2bf:  /* edit notify HSL */
01000       case 0x2c0:
01001       case 0x2c1:
01002            if (notifyCode == EN_UPDATE && !lpp->updating)
01003              {
01004                i = CC_CheckDigitsInEdit(hwndCtl , LOWORD(wParam) == 0x2bf ? 239:240);
01005                xx = 0;
01006                switch (LOWORD(wParam))
01007                {
01008                 case 0x2bf: if ((xx = ( i != lpp->h))) lpp->h = i; break;
01009                 case 0x2c0: if ((xx = ( i != lpp->s))) lpp->s = i; break;
01010                 case 0x2c1: if ((xx = ( i != lpp->l))) lpp->l = i; break;
01011                }
01012                if (xx) /* something has changed */
01013                {
01014                 r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
01015                 g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
01016                 b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
01017                 lpp->lpcc->rgbResult = RGB(r, g, b);
01018                 CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
01019                 CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
01020                 CC_PaintCross(hDlg, lpp->h, lpp->s);
01021                 CC_PaintTriangle(hDlg, lpp->l);
01022                }
01023              }
01024            break;
01025 
01026           case 0x2cf:
01027                CC_SwitchToFullSize(hDlg, lpp->lpcc->rgbResult, &lpp->fullsize);
01028            SetFocus( GetDlgItem(hDlg, 0x2bf));
01029            break;
01030 
01031           case 0x2c8:    /* add colors ... column by column */
01032                cr = lpp->lpcc->lpCustColors;
01033                cr[(lpp->nextuserdef % 2) * 8 + lpp->nextuserdef / 2] = lpp->lpcc->rgbResult;
01034                if (++lpp->nextuserdef == 16)
01035            lpp->nextuserdef = 0;
01036            CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
01037            break;
01038 
01039           case 0x2c9:              /* resulting color */
01040            hdc = GetDC(hDlg);
01041            lpp->lpcc->rgbResult = GetNearestColor(hdc, lpp->lpcc->rgbResult);
01042            ReleaseDC(hDlg, hdc);
01043            CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
01044            CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
01045            r = GetRValue(lpp->lpcc->rgbResult);
01046            g = GetGValue(lpp->lpcc->rgbResult);
01047            b = GetBValue(lpp->lpcc->rgbResult);
01048            lpp->h = CC_RGBtoHSL('H', r, g, b);
01049            lpp->s = CC_RGBtoHSL('S', r, g, b);
01050            lpp->l = CC_RGBtoHSL('L', r, g, b);
01051            CC_EditSetHSL(hDlg, lpp->h, lpp->s, lpp->l);
01052            CC_PaintCross(hDlg, lpp->h, lpp->s);
01053            CC_PaintTriangle(hDlg, lpp->l);
01054            break;
01055 
01056       case 0x40e:           /* Help! */ /* The Beatles, 1965  ;-) */
01057            i = RegisterWindowMessageA(HELPMSGSTRINGA);
01058                    if (lpp->lpcc->hwndOwner)
01059                SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
01060                    if ( CC_HookCallChk(lpp->lpcc))
01061                CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
01062                   WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
01063            break;
01064 
01065           case IDOK :
01066         cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
01067             if (lpp->lpcc->hwndOwner)
01068             if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
01069             break;    /* do NOT close */
01070         EndDialog(hDlg, 1) ;
01071         return TRUE ;
01072 
01073       case IDCANCEL :
01074         EndDialog(hDlg, 0) ;
01075         return TRUE ;
01076 
01077        }
01078        return FALSE;
01079 }
01080 
01081 /***********************************************************************
01082  *                              CC_WMPaint                    [internal]
01083  */
01084 static LRESULT CC_WMPaint( HWND hDlg )
01085 {
01086     PAINTSTRUCT ps;
01087     LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
01088 
01089     BeginPaint(hDlg, &ps);
01090     /* we have to paint dialog children except text and buttons */
01091     CC_PaintPredefColorArray(hDlg, 6, 8);
01092     CC_PaintUserColorArray(hDlg, 2, 8, lpp->lpcc->lpCustColors);
01093     CC_PaintLumBar(hDlg, lpp->h, lpp->s);
01094     CC_PaintTriangle(hDlg, lpp->l);
01095     CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
01096     CC_PaintColorGraph(hDlg);
01097     CC_PaintCross(hDlg, lpp->h, lpp->s);
01098     EndPaint(hDlg, &ps);
01099 
01100     return TRUE;
01101 }
01102 
01103 /***********************************************************************
01104  *                              CC_WMLButtonUp              [internal]
01105  */
01106 static LRESULT CC_WMLButtonUp( HWND hDlg )
01107 {
01108    LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
01109 
01110    if (lpp->capturedGraph)
01111    {
01112        lpp->capturedGraph = 0;
01113        ReleaseCapture();
01114        CC_PaintCross(hDlg, lpp->h, lpp->s);
01115        return 1;
01116    }
01117    return 0;
01118 }
01119 
01120 /***********************************************************************
01121  *                              CC_WMMouseMove              [internal]
01122  */
01123 static LRESULT CC_WMMouseMove( HWND hDlg, LPARAM lParam )
01124 {
01125    LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
01126    int r, g, b;
01127 
01128    if (lpp->capturedGraph)
01129    {
01130       int *ptrh = NULL, *ptrs = &lpp->l;
01131       if (lpp->capturedGraph == 0x2c6)
01132       {
01133           ptrh = &lpp->h;
01134           ptrs = &lpp->s;
01135       }
01136       if (CC_MouseCheckColorGraph( hDlg, lpp->capturedGraph, ptrh, ptrs, lParam))
01137       {
01138           r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
01139           g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
01140           b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
01141           lpp->lpcc->rgbResult = RGB(r, g, b);
01142           CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
01143           CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
01144           CC_PaintCross(hDlg, lpp->h, lpp->s);
01145           CC_PaintTriangle(hDlg, lpp->l);
01146           CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
01147       }
01148       else
01149       {
01150           ReleaseCapture();
01151           lpp->capturedGraph = 0;
01152       }
01153       return 1;
01154    }
01155    return 0;
01156 }
01157 
01158 /***********************************************************************
01159  *                              CC_WMLButtonDown              [internal]
01160  */
01161 static LRESULT CC_WMLButtonDown( HWND hDlg, LPARAM lParam )
01162 {
01163    LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
01164    int r, g, b, i;
01165    i = 0;
01166 
01167    if (CC_MouseCheckPredefColorArray(lpp, hDlg, 0x2d0, 6, 8, lParam))
01168       i = 1;
01169    else
01170       if (CC_MouseCheckUserColorArray(lpp, hDlg, 0x2d1, 2, 8, lParam))
01171          i = 1;
01172       else
01173      if (CC_MouseCheckColorGraph(hDlg, 0x2c6, &lpp->h, &lpp->s, lParam))
01174          {
01175         i = 2;
01176             lpp->capturedGraph = 0x2c6;
01177          }
01178      else
01179         if (CC_MouseCheckColorGraph(hDlg, 0x2be, NULL, &lpp->l, lParam))
01180             {
01181            i = 2;
01182                lpp->capturedGraph = 0x2be;
01183             }
01184    if ( i == 2 )
01185    {
01186       SetCapture(hDlg);
01187       r = CC_HSLtoRGB('R', lpp->h, lpp->s, lpp->l);
01188       g = CC_HSLtoRGB('G', lpp->h, lpp->s, lpp->l);
01189       b = CC_HSLtoRGB('B', lpp->h, lpp->s, lpp->l);
01190       lpp->lpcc->rgbResult = RGB(r, g, b);
01191    }
01192    if ( i == 1 )
01193    {
01194       r = GetRValue(lpp->lpcc->rgbResult);
01195       g = GetGValue(lpp->lpcc->rgbResult);
01196       b = GetBValue(lpp->lpcc->rgbResult);
01197       lpp->h = CC_RGBtoHSL('H', r, g, b);
01198       lpp->s = CC_RGBtoHSL('S', r, g, b);
01199       lpp->l = CC_RGBtoHSL('L', r, g, b);
01200    }
01201    if (i)
01202    {
01203       CC_EditSetRGB(hDlg, lpp->lpcc->rgbResult);
01204       CC_EditSetHSL(hDlg,lpp->h, lpp->s, lpp->l);
01205       CC_PaintCross(hDlg, lpp->h, lpp->s);
01206       CC_PaintTriangle(hDlg, lpp->l);
01207       CC_PaintSelectedColor(hDlg, lpp->lpcc->rgbResult);
01208       return TRUE;
01209    }
01210    return FALSE;
01211 }
01212 
01213 /***********************************************************************
01214  *           ColorDlgProc32 [internal]
01215  *
01216  */
01217 static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
01218                                    WPARAM wParam, LPARAM lParam )
01219 {
01220 
01221  int res;
01222  LPCCPRIV lpp = GetPropW( hDlg, szColourDialogProp );
01223 
01224  if (message != WM_INITDIALOG)
01225  {
01226   if (!lpp)
01227      return FALSE;
01228   res = 0;
01229   if (CC_HookCallChk(lpp->lpcc))
01230      res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, message, wParam, lParam);
01231   if ( res )
01232      return res;
01233  }
01234 
01235  /* FIXME: SetRGB message
01236  if (message && message == msetrgb)
01237     return HandleSetRGB(hDlg, lParam);
01238  */
01239 
01240  switch (message)
01241     {
01242       case WM_INITDIALOG:
01243                     return CC_WMInitDialog(hDlg, wParam, lParam);
01244       case WM_NCDESTROY:
01245                     DeleteDC(lpp->hdcMem);
01246                     DeleteObject(lpp->hbmMem);
01247                         HeapFree(GetProcessHeap(), 0, lpp);
01248                         RemovePropW( hDlg, szColourDialogProp );
01249                     break;
01250       case WM_COMMAND:
01251                     if (CC_WMCommand( hDlg, wParam, lParam, HIWORD(wParam), (HWND) lParam))
01252                        return TRUE;
01253                     break;
01254       case WM_PAINT:
01255                     if (CC_WMPaint(hDlg))
01256                        return TRUE;
01257                     break;
01258       case WM_LBUTTONDBLCLK:
01259                     if (CC_MouseCheckResultWindow(hDlg, lParam))
01260               return TRUE;
01261             break;
01262       case WM_MOUSEMOVE:
01263                     if (CC_WMMouseMove(hDlg, lParam))
01264               return TRUE;
01265             break;
01266       case WM_LBUTTONUP:  /* FIXME: ClipCursor off (if in color graph)*/
01267                         if (CC_WMLButtonUp(hDlg))
01268                            return TRUE;
01269             break;
01270       case WM_LBUTTONDOWN:/* FIXME: ClipCursor on  (if in color graph)*/
01271                     if (CC_WMLButtonDown(hDlg, lParam))
01272                        return TRUE;
01273                     break;
01274     }
01275      return FALSE ;
01276 }
01277 
01278 /***********************************************************************
01279  *            ChooseColorW  (COMDLG32.@)
01280  *
01281  * Create a color dialog box.
01282  *
01283  * PARAMS
01284  *  lpChCol [I/O] in:  information to initialize the dialog box.
01285  *                out: User's color selection
01286  *
01287  * RETURNS
01288  *  TRUE:  Ok button clicked.
01289  *  FALSE: Cancel button clicked, or error.
01290  */
01291 BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
01292 {
01293     HANDLE hDlgTmpl = 0;
01294     BOOL bRet = FALSE;
01295     LPCVOID template;
01296 
01297     TRACE("ChooseColor\n");
01298     if (!lpChCol) return FALSE;
01299 
01300     if (lpChCol->Flags & CC_ENABLETEMPLATEHANDLE)
01301     {
01302         if (!(template = LockResource(lpChCol->hInstance)))
01303         {
01304             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
01305             return FALSE;
01306         }
01307     }
01308     else if (lpChCol->Flags & CC_ENABLETEMPLATE)
01309     {
01310     HRSRC hResInfo;
01311         if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
01312                                         lpChCol->lpTemplateName,
01313                                         (LPWSTR)RT_DIALOG)))
01314         {
01315             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
01316             return FALSE;
01317         }
01318         if (!(hDlgTmpl = LoadResource((HINSTANCE)lpChCol->hInstance, hResInfo)) ||
01319             !(template = LockResource(hDlgTmpl)))
01320         {
01321             COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
01322             return FALSE;
01323         }
01324     }
01325     else
01326     {
01327     HRSRC hResInfo;
01328     HGLOBAL hDlgTmpl;
01329     static const WCHAR wszCHOOSE_COLOR[] = {'C','H','O','O','S','E','_','C','O','L','O','R',0};
01330     if (!(hResInfo = FindResourceW(COMDLG32_hInstance, wszCHOOSE_COLOR, (LPWSTR)RT_DIALOG)))
01331     {
01332         COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
01333         return FALSE;
01334     }
01335     if (!(hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo )) ||
01336         !(template = LockResource(hDlgTmpl)))
01337     {
01338         COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
01339         return FALSE;
01340     }
01341     }
01342 
01343     bRet = DialogBoxIndirectParamW(COMDLG32_hInstance, template, lpChCol->hwndOwner,
01344                      ColorDlgProc, (LPARAM)lpChCol);
01345     return bRet;
01346 }
01347 
01348 /***********************************************************************
01349  *            ChooseColorA  (COMDLG32.@)
01350  *
01351  * See ChooseColorW.
01352  */
01353 BOOL WINAPI ChooseColorA( LPCHOOSECOLORA lpChCol )
01354 
01355 {
01356   LPWSTR template_name = NULL;
01357   BOOL ret;
01358 
01359   LPCHOOSECOLORW lpcc = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW));
01360   lpcc->lStructSize = sizeof(*lpcc);
01361   lpcc->hwndOwner = lpChCol->hwndOwner;
01362   lpcc->hInstance = lpChCol->hInstance;
01363   lpcc->rgbResult = lpChCol->rgbResult;
01364   lpcc->lpCustColors = lpChCol->lpCustColors;
01365   lpcc->Flags = lpChCol->Flags;
01366   lpcc->lCustData = lpChCol->lCustData;
01367   lpcc->lpfnHook = lpChCol->lpfnHook;
01368   if ((lpcc->Flags & CC_ENABLETEMPLATE) && (lpChCol->lpTemplateName)) {
01369       if (!IS_INTRESOURCE(lpChCol->lpTemplateName)) {
01370       INT len = MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, NULL, 0);
01371           template_name = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) );
01372           MultiByteToWideChar( CP_ACP, 0, lpChCol->lpTemplateName, -1, template_name, len );
01373           lpcc->lpTemplateName = template_name;
01374       } else {
01375       lpcc->lpTemplateName = (LPCWSTR)lpChCol->lpTemplateName;
01376       }
01377   }
01378 
01379   ret = ChooseColorW(lpcc);
01380 
01381   if (ret)
01382       lpChCol->rgbResult = lpcc->rgbResult;
01383   HeapFree(GetProcessHeap(), 0, template_name);
01384   HeapFree(GetProcessHeap(), 0, lpcc);
01385   return ret;
01386 }

Generated on Sun May 27 2012 04:23:06 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.