]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/colordlg.cpp
Added ability to switch off more components of the size page UI
[wxWidgets.git] / src / msw / colordlg.cpp
index 23141f07e61a4232657dcdc4b1a1cb1de6a7d484..688ca17380e51d4ab41f777b304324e109434d99 100644 (file)
@@ -27,6 +27,7 @@
 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
 
 #include "wx/colordlg.h"
 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
 
 #include "wx/colordlg.h"
+#include "wx/testing.h"
 
 #ifndef WX_PRECOMP
     #include "wx/msw/wrapcdlg.h"
 
 #ifndef WX_PRECOMP
     #include "wx/msw/wrapcdlg.h"
@@ -34,8 +35,6 @@
     #include "wx/colour.h"
     #include "wx/gdicmn.h"
     #include "wx/utils.h"
     #include "wx/colour.h"
     #include "wx/gdicmn.h"
     #include "wx/utils.h"
-    #include "wx/dialog.h"
-    #include "wx/cmndata.h"
     #include "wx/math.h"
 #endif
 
     #include "wx/math.h"
 #endif
 
@@ -77,11 +76,11 @@ wxColourDialogHookProc(HWND hwnd,
     {
         CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
         wxColourDialog * const
     {
         CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam;
         wxColourDialog * const
-            dialog = wx_reinterpret_cast(wxColourDialog *, pCC->lCustData);
+            dialog = reinterpret_cast<wxColourDialog *>(pCC->lCustData);
 
         const wxString title = dialog->GetTitle();
         if ( !title.empty() )
 
         const wxString title = dialog->GetTitle();
         if ( !title.empty() )
-            ::SetWindowText(hwnd, title.wx_str());
+            ::SetWindowText(hwnd, title.t_str());
 
         dialog->MSWOnInitDone((WXHWND)hwnd);
     }
 
         dialog->MSWOnInitDone((WXHWND)hwnd);
     }
@@ -116,15 +115,20 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
 
 int wxColourDialog::ShowModal()
 {
 
 int wxColourDialog::ShowModal()
 {
+    WX_TESTING_SHOW_MODAL_HOOK();
+
+    // initialize the struct used by Windows
     CHOOSECOLOR chooseColorStruct;
     CHOOSECOLOR chooseColorStruct;
-    COLORREF custColours[16];
     memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
 
     memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR));
 
-    int i;
-    for (i = 0; i < 16; i++)
+    size_t i;
+
+    // and transfer data from m_colourData to it
+    COLORREF custColours[16];
+    for ( i = 0; i < WXSIZEOF(custColours); i++ )
     {
     {
-        if (m_colourData.m_custColours[i].Ok())
-            custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]);
+        if ( m_colourData.GetCustomColour(i).IsOk() )
+            custColours[i] = wxColourToRGB(m_colourData.GetCustomColour(i));
         else
             custColours[i] = RGB(255,255,255);
     }
         else
             custColours[i] = RGB(255,255,255);
     }
@@ -132,37 +136,45 @@ int wxColourDialog::ShowModal()
     chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
     if ( m_parent )
         chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
     chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR);
     if ( m_parent )
         chooseColorStruct.hwndOwner = GetHwndOf(m_parent);
-    chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour);
+    chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour());
     chooseColorStruct.lpCustColors = custColours;
 
     chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
     chooseColorStruct.lCustData = (LPARAM)this;
     chooseColorStruct.lpfnHook = wxColourDialogHookProc;
 
     chooseColorStruct.lpCustColors = custColours;
 
     chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK;
     chooseColorStruct.lCustData = (LPARAM)this;
     chooseColorStruct.lpfnHook = wxColourDialogHookProc;
 
-    if (m_colourData.GetChooseFull())
+    if ( m_colourData.GetChooseFull() )
         chooseColorStruct.Flags |= CC_FULLOPEN;
 
         chooseColorStruct.Flags |= CC_FULLOPEN;
 
-    // Do the modal dialog
-    bool success = ::ChooseColor(&(chooseColorStruct)) != 0;
-
-    // Try to highlight the correct window (the parent)
-    if (GetParent())
+    // do show the modal dialog
+    if ( !::ChooseColor(&chooseColorStruct) )
     {
     {
-      HWND hWndParent = (HWND) GetParent()->GetHWND();
-      if (hWndParent)
-        ::BringWindowToTop(hWndParent);
+        // 0 error means the dialog was simply cancelled, i.e. no real error
+        // occurred
+        const DWORD err = CommDlgExtendedError();
+        if ( err )
+        {
+            wxLogError(_("Colour selection dialog failed with error %0lx."), err);
+        }
+
+        return wxID_CANCEL;
     }
 
 
     }
 
 
-    // Restore values
-    for (i = 0; i < 16; i++)
+    // transfer the values chosen by user back into m_colourData
+    for ( i = 0; i < WXSIZEOF(custColours); i++ )
     {
       wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
     }
 
     {
       wxRGBToColour(m_colourData.m_custColours[i], custColours[i]);
     }
 
-    wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult);
+    wxRGBToColour(m_colourData.GetColour(), chooseColorStruct.rgbResult);
+
+    // this doesn't seem to work (contrary to what MSDN implies) on current
+    // Windows versions: CC_FULLOPEN is never set on return if it wasn't
+    // initially set and vice versa
+    //m_colourData.SetChooseFull((chooseColorStruct.Flags & CC_FULLOPEN) != 0);
 
 
-    return success ? wxID_OK : wxID_CANCEL;
+    return wxID_OK;
 }
 
 // ----------------------------------------------------------------------------
 }
 
 // ----------------------------------------------------------------------------