From 2349ba4cf9adaded573727a5a6c806da2bcbf0b3 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 18 Nov 2007 19:25:14 +0000 Subject: [PATCH] no real changes: just some cleanup, better error handling and (unsuccessful) attemps to retrieve CC_FULLOPEN value from the dialog git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50055 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/colordlg.cpp | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/src/msw/colordlg.cpp b/src/msw/colordlg.cpp index 23141f07e6..60affe9fc6 100644 --- a/src/msw/colordlg.cpp +++ b/src/msw/colordlg.cpp @@ -116,14 +116,17 @@ bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) int wxColourDialog::ShowModal() { + // initialize the struct used by Windows CHOOSECOLOR chooseColorStruct; - COLORREF custColours[16]; memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); int i; - for (i = 0; i < 16; 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()) + if ( m_colourData.m_custColours[i].IsOk() ) custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]); else custColours[i] = RGB(255,255,255); @@ -139,30 +142,36 @@ int wxColourDialog::ShowModal() chooseColorStruct.lCustData = (LPARAM)this; chooseColorStruct.lpfnHook = wxColourDialogHookProc; - if (m_colourData.GetChooseFull()) + if ( m_colourData.GetChooseFull() ) 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_dataColour, chooseColorStruct.rgbResult); - return success ? wxID_OK : wxID_CANCEL; + // 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 wxID_OK; } // ---------------------------------------------------------------------------- -- 2.45.2