Support emulation of the privileged mov dr7,eax instruction.
[wine] / dlls / commdlg / colordlg.c
index f18b706..4490da1 100644 (file)
 #include "windef.h"
 #include "winbase.h"
 #include "wingdi.h"
-#include "wine/winbase16.h"
-#include "wine/winuser16.h"
 #include "winuser.h"
 #include "commdlg.h"
 #include "dlgs.h"
 #include "wine/debug.h"
 #include "cderr.h"
+#include "cdlg.h"
 
 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
 
-#include "cdlg.h"
-#include "colordlg.h"
-
 static INT_PTR CALLBACK ColorDlgProc( HWND hWnd, UINT wMsg, WPARAM wParam, LPARAM lParam );
 
-#define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = SLOWORD(lp); (p)->y = SHIWORD(lp); } while(0)
+#define CONV_LPARAMTOPOINT(lp,p) do { (p)->x = (short)LOWORD(lp); (p)->y = (short)HIWORD(lp); } while(0)
 
 static const COLORREF predefcolors[6][8]=
 {
@@ -66,10 +62,35 @@ static const COLORREF predefcolors[6][8]=
    0x00808040L, 0x00C0C0C0L, 0x00400040L, 0x00FFFFFFL },
 };
 
+/* Chose Color PRIVATE Structure:
+ *
+ * This structure is duplicated in the 16 bit code with
+ * a extra member
+ */
+
+typedef struct CCPRIVATE
+{
+    LPCHOOSECOLORW lpcc; /* points to public known data structure */
+    int nextuserdef;     /* next free place in user defined color array */
+    HDC hdcMem;          /* color graph used for BitBlt() */
+    HBITMAP hbmMem;      /* color graph bitmap */
+    RECT fullsize;       /* original dialog window size */
+    UINT msetrgb;        /* # of SETRGBSTRING message (today not used)  */
+    RECT old3angle;      /* last position of l-marker */
+    RECT oldcross;       /* last position of color/satuation marker */
+    BOOL updating;       /* to prevent recursive WM_COMMAND/EN_UPDATE processing */
+    int h;
+    int s;
+    int l;               /* for temporary storing of hue,sat,lum */
+    int capturedGraph;   /* control mouse captured */
+    RECT focusRect;      /* rectangle last focused item */
+    HWND hwndFocus;      /* handle last focused item */
+} *LCCPRIV;
+
 /***********************************************************************
  *                             CC_HSLtoRGB                    [internal]
  */
-static int CC_HSLtoRGB(char c, int hue, int sat, int lum)
+int CC_HSLtoRGB(char c, int hue, int sat, int lum)
 {
  int res = 0, maxrgb;
 
@@ -114,7 +135,7 @@ static int CC_HSLtoRGB(char c, int hue, int sat, int lum)
 /***********************************************************************
  *                             CC_RGBtoHSL                    [internal]
  */
-static int CC_RGBtoHSL(char c, int r, int g, int b)
+int CC_RGBtoHSL(char c, int r, int g, int b)
 {
  WORD maxi, mini, mmsum, mmdif, result = 0;
  int iresult = 0;
@@ -357,7 +378,7 @@ int CC_MouseCheckResultWindow( HWND hDlg, LPARAM lParam )
 /***********************************************************************
  *                       CC_CheckDigitsInEdit                 [internal]
  */
-static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
+int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
 {
  int i, k, m, result, value;
  long editpos;
@@ -399,7 +420,7 @@ static int CC_CheckDigitsInEdit( HWND hwnd, int maxval )
 /***********************************************************************
  *                    CC_PaintSelectedColor                   [internal]
  */
-static void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
+void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
 {
  RECT rect;
  HDC  hdc;
@@ -430,7 +451,7 @@ static void CC_PaintSelectedColor( HWND hDlg, COLORREF cr )
 /***********************************************************************
  *                    CC_PaintTriangle                        [internal]
  */
-static void CC_PaintTriangle( HWND hDlg, int y)
+void CC_PaintTriangle( HWND hDlg, int y)
 {
  HDC hDC;
  long temp;
@@ -473,7 +494,7 @@ static void CC_PaintTriangle( HWND hDlg, int y)
 /***********************************************************************
  *                    CC_PaintCross                           [internal]
  */
-static void CC_PaintCross( HWND hDlg, int x, int y)
+void CC_PaintCross( HWND hDlg, int x, int y)
 {
  HDC hDC;
  int w = GetDialogBaseUnits();
@@ -527,7 +548,7 @@ static void CC_PrepareColorGraph( HWND hDlg )
  HBRUSH hbrush;
  HDC hdc ;
  RECT rect, client;
- HCURSOR hcursor = SetCursor( LoadCursorA(0, IDC_WAITA) );
+ HCURSOR hcursor = SetCursor( LoadCursorA(0, (LPSTR)IDC_WAIT) );
 
  GetClientRect(hwnd, &client);
  hdc = GetDC(hwnd);
@@ -623,7 +644,7 @@ static void CC_PaintLumBar( HWND hDlg, int hue, int sat )
 /***********************************************************************
  *                             CC_EditSetRGB                  [internal]
  */
-static void CC_EditSetRGB( HWND hDlg, COLORREF cr )
+void CC_EditSetRGB( HWND hDlg, COLORREF cr )
 {
  char buffer[10];
  LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
@@ -646,7 +667,7 @@ static void CC_EditSetRGB( HWND hDlg, COLORREF cr )
 /***********************************************************************
  *                             CC_EditSetHSL                  [internal]
  */
-static void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
+void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
 {
  char buffer[10];
  LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
@@ -668,7 +689,7 @@ static void CC_EditSetHSL( HWND hDlg, int h, int s, int l )
 /***********************************************************************
  *                       CC_SwitchToFullSize                  [internal]
  */
-static void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPRECT lprect )
+void CC_SwitchToFullSize( HWND hDlg, COLORREF result, LPRECT lprect )
 {
  int i;
  LCCPRIV lpp = (LCCPRIV)GetWindowLongA(hDlg, DWL_USER);
@@ -742,7 +763,7 @@ static void CC_PaintPredefColorArray( HWND hDlg, int rows, int cols)
  *                             CC_PaintUserColorArray         [internal]
  *               Paint the 16 user-selected colors
  */
-static void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, COLORREF* lpcr )
+void CC_PaintUserColorArray( HWND hDlg, int rows, int cols, COLORREF* lpcr )
 {
  HWND hwnd = GetDlgItem(hDlg, 0x2d1);
  RECT rect;
@@ -801,7 +822,7 @@ BOOL CC_HookCallChk( LPCHOOSECOLORW lpcc )
 /***********************************************************************
  *                              CC_WMInitDialog                  [internal]
  */
-LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam, BOOL b16 )
+LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam )
 {
    int i, res;
    int r, g, b;
@@ -812,34 +833,15 @@ LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam, BOOL b16 )
 
    TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
    lpp = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct CCPRIVATE) );
-   if (b16)
-   {
-       CHOOSECOLORW *ch32;
-       CHOOSECOLOR16 *ch16 = (CHOOSECOLOR16 *) lParam;
-       ch32 = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(CHOOSECOLORW) );
-       lpp->lpcc = ch32;
-       lpp->lpcc16 = ch16;
-       if (lpp->lpcc16->lStructSize != sizeof(CHOOSECOLOR16) )
-       {
-           EndDialog (hDlg, 0) ;
-           return FALSE;
-       }
-       ch32->lStructSize = sizeof(CHOOSECOLORW);
-       ch32->hwndOwner = HWND_32(ch16->hwndOwner);
-       /* Should be an HINSTANCE but MS made a typo */
-       ch32->hInstance = HWND_32(ch16->hInstance);
-       ch32->lpCustColors = MapSL(ch16->lpCustColors);
-       ch32->lpfnHook = (LPCCHOOKPROC) ch16->lpfnHook; /* only used as flag */
-       ch32->Flags = ch16->Flags;
-   }
-   else
-       lpp->lpcc = (LPCHOOSECOLORW) lParam;
 
+   lpp->lpcc = (LPCHOOSECOLORW) lParam;
    if (lpp->lpcc->lStructSize != sizeof(CHOOSECOLORW) )
    {
-      EndDialog (hDlg, 0) ;
-      return FALSE;
+       HeapFree(GetProcessHeap(), 0, lpp);
+       EndDialog (hDlg, 0) ;
+       return FALSE;
    }
+
    SetWindowLongA(hDlg, DWL_USER, (LONG)lpp);
 
    if (!(lpp->lpcc->Flags & CC_SHOWHELP))
@@ -897,10 +899,6 @@ LONG CC_WMInitDialog( HWND hDlg, WPARAM wParam, LPARAM lParam, BOOL b16 )
      SendMessageA( GetDlgItem(hDlg, i), EM_LIMITTEXT, 3, 0);  /* max 3 digits:  xyz  */
    if (CC_HookCallChk(lpp->lpcc))
    {
-      if (b16)
-          res = CallWindowProc16( (WNDPROC16)lpp->lpcc16->lpfnHook,
-                                 HWND_16(hDlg), WM_INITDIALOG, wParam, lParam);
-      else
           res = CallWindowProcA( (WNDPROC)lpp->lpcc->lpfnHook, hDlg, WM_INITDIALOG, wParam, lParam);
    }
 
@@ -1031,45 +1029,18 @@ LRESULT CC_WMCommand( HWND hDlg, WPARAM wParam, LPARAM lParam, WORD notifyCode,
 
          case 0x40e:           /* Help! */ /* The Beatles, 1965  ;-) */
               i = RegisterWindowMessageA(HELPMSGSTRINGA);
-               if (lpp->lpcc16)
-               {
-                   if (lpp->lpcc->hwndOwner)
-                      SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc16);
-                   if ( CC_HookCallChk(lpp->lpcc))
-                      CallWindowProc16( (WNDPROC16) lpp->lpcc16->lpfnHook,
-                                        HWND_16(hDlg), WM_COMMAND, psh15,
-                                        (LPARAM)lpp->lpcc16);
-               }
-               else
-               {
                    if (lpp->lpcc->hwndOwner)
                       SendMessageA(lpp->lpcc->hwndOwner, i, 0, (LPARAM)lpp->lpcc);
                    if ( CC_HookCallChk(lpp->lpcc))
                       CallWindowProcA( (WNDPROC) lpp->lpcc->lpfnHook, hDlg,
                          WM_COMMAND, psh15, (LPARAM)lpp->lpcc);
-               }
               break;
 
           case IDOK :
                cokmsg = RegisterWindowMessageA(COLOROKSTRINGA);
-                if (lpp->lpcc16)
-                {
-                   if (lpp->lpcc->hwndOwner)
-                       if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc16))
-                          break;    /* do NOT close */
-                }
-                else
-                {
                    if (lpp->lpcc->hwndOwner)
                        if (SendMessageA(lpp->lpcc->hwndOwner, cokmsg, 0, (LPARAM)lpp->lpcc))
-                          break;    /* do NOT close */
-                }
-                if (lpp->lpcc16)
-                {
-                    BYTE *ptr = MapSL(lpp->lpcc16->lpCustColors);
-                    memcpy(ptr, lpp->lpcc->lpCustColors, sizeof(COLORREF)*16);
-                    lpp->lpcc16->rgbResult = lpp->lpcc->rgbResult;
-                }
+                       break;    /* do NOT close */
                EndDialog(hDlg, 1) ;
                return TRUE ;
 
@@ -1242,7 +1213,7 @@ static INT_PTR CALLBACK ColorDlgProc( HWND hDlg, UINT message,
  switch (message)
        {
          case WM_INITDIALOG:
-                       return CC_WMInitDialog(hDlg, wParam, lParam, FALSE);
+                       return CC_WMInitDialog(hDlg, wParam, lParam);
          case WM_NCDESTROY:
                        DeleteDC(lpp->hdcMem);
                        DeleteObject(lpp->hbmMem);
@@ -1302,7 +1273,7 @@ BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
        HRSRC hResInfo;
         if (!(hResInfo = FindResourceW((HINSTANCE)lpChCol->hInstance,
                                         lpChCol->lpTemplateName,
-                                        RT_DIALOGW)))
+                                        (LPWSTR)RT_DIALOG)))
         {
             COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
             return FALSE;
@@ -1318,7 +1289,7 @@ BOOL WINAPI ChooseColorW( LPCHOOSECOLORW lpChCol )
     {
        HRSRC hResInfo;
        HGLOBAL hDlgTmpl;
-       if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_COLOR", RT_DIALOGA)))
+       if (!(hResInfo = FindResourceA(COMDLG32_hInstance, "CHOOSE_COLOR", (LPSTR)RT_DIALOG)))
        {
            COMDLG32_SetCommDlgExtendedError(CDERR_FINDRESFAILURE);
            return FALSE;