X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2bda0e173844e8e0f8acf4e8ad8b5c26e5c6fe5d..4ca64d4137439844a5e6c95b4da16f32cf7840ab:/src/msw/colordlg.cpp?ds=sidebyside diff --git a/src/msw/colordlg.cpp b/src/msw/colordlg.cpp index e18bb2af6b..66a70b0eb5 100644 --- a/src/msw/colordlg.cpp +++ b/src/msw/colordlg.cpp @@ -1,82 +1,114 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: colordlg.cpp +// Name: src/msw/colordlg.cpp // Purpose: wxColourDialog class // Author: Julian Smart // Modified by: // Created: 01/02/97 // RCS-ID: $Id$ -// Copyright: (c) Julian Smart and Markus Holzem -// Licence: wxWindows licence +// Copyright: (c) Julian Smart +// Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ -#pragma implementation "colordlg.h" -#endif +// ============================================================================ +// declarations +// ============================================================================ + +// ---------------------------------------------------------------------------- +// headers +// ---------------------------------------------------------------------------- // For compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" #ifdef __BORLANDC__ -#pragma hdrstop + #pragma hdrstop #endif -#ifndef WX_PRECOMP -#include -#include "wx/defs.h" -#include "wx/pen.h" -#include "wx/brush.h" -#include "wx/gdicmn.h" -#include "wx/utils.h" -#include "wx/frame.h" -#include "wx/dialog.h" -#include "wx/msgdlg.h" -#endif +#if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__)) -#include +#include "wx/colordlg.h" -#ifndef __WIN32__ -#include +#ifndef WX_PRECOMP + #include "wx/msw/wrapcdlg.h" + #include + #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/msw/private.h" -#include "wx/colordlg.h" -#include "wx/cmndata.h" -#include #include #include -#define wxDIALOG_DEFAULT_X 300 -#define wxDIALOG_DEFAULT_Y 300 +// ---------------------------------------------------------------------------- +// wxWin macros +// ---------------------------------------------------------------------------- -#if !USE_SHARED_LIBRARY IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) -#endif -/* - * wxColourDialog - */ +// ============================================================================ +// implementation +// ============================================================================ + +// ---------------------------------------------------------------------------- +// colour dialog hook proc +// ---------------------------------------------------------------------------- -wxColourDialog::wxColourDialog(void) +UINT_PTR CALLBACK +wxColourDialogHookProc(HWND hwnd, + UINT uiMsg, + WPARAM WXUNUSED(wParam), + LPARAM lParam) { - dialogParent = NULL; + if ( uiMsg == WM_INITDIALOG ) + { + CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam; + wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData; + + ::SetWindowText(hwnd, dialog->GetTitle()); + + wxPoint pos = dialog->GetPosition(); + if ( pos != wxDefaultPosition ) + { + ::SetWindowPos(hwnd, NULL /* Z-order: ignored */, + pos.x, pos.y, -1, -1, + SWP_NOSIZE | SWP_NOZORDER); + } + } + + return 0; +} + +// ---------------------------------------------------------------------------- +// wxColourDialog +// ---------------------------------------------------------------------------- + +wxColourDialog::wxColourDialog() +{ + m_pos = wxDefaultPosition; } wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data) { - Create(parent, data); + m_pos = wxDefaultPosition; + + Create(parent, data); } bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) { - dialogParent = parent; - - if (data) - colourData = *data; - return TRUE; + m_parent = parent; + if (data) + m_colourData = *data; + + return true; } -int wxColourDialog::ShowModal(void) +int wxColourDialog::ShowModal() { CHOOSECOLOR chooseColorStruct; COLORREF custColours[16]; @@ -84,26 +116,33 @@ int wxColourDialog::ShowModal(void) int i; for (i = 0; i < 16; i++) - custColours[i] = RGB(colourData.custColours[i].Red(), colourData.custColours[i].Green(), colourData.custColours[i].Blue()); + { + if (m_colourData.m_custColours[i].Ok()) + custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]); + else + custColours[i] = RGB(255,255,255); + } chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); - chooseColorStruct.hwndOwner = (HWND) (dialogParent ? (HWND) dialogParent->GetHWND() : NULL); - chooseColorStruct.rgbResult = RGB(colourData.dataColour.Red(), colourData.dataColour.Green(), colourData.dataColour.Blue()); + if ( m_parent ) + chooseColorStruct.hwndOwner = GetHwndOf(m_parent); + chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour); chooseColorStruct.lpCustColors = custColours; - chooseColorStruct.Flags = CC_RGBINIT; + chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; + chooseColorStruct.lCustData = (LPARAM)this; + chooseColorStruct.lpfnHook = wxColourDialogHookProc; - if (!colourData.GetChooseFull()) - chooseColorStruct.Flags |= CC_PREVENTFULLOPEN; + if (m_colourData.GetChooseFull()) + chooseColorStruct.Flags |= CC_FULLOPEN; // Do the modal dialog - bool success = (ChooseColor(&(chooseColorStruct)) != 0); + bool success = ::ChooseColor(&(chooseColorStruct)) != 0; // Try to highlight the correct window (the parent) - HWND hWndParent = 0; if (GetParent()) { - hWndParent = (HWND) GetParent()->GetHWND(); + HWND hWndParent = (HWND) GetParent()->GetHWND(); if (hWndParent) ::BringWindowToTop(hWndParent); } @@ -112,13 +151,72 @@ int wxColourDialog::ShowModal(void) // Restore values for (i = 0; i < 16; i++) { - colourData.custColours[i].Set(GetRValue(custColours[i]), GetGValue(custColours[i]), - GetBValue(custColours[i])); + wxRGBToColour(m_colourData.m_custColours[i], custColours[i]); } - colourData.dataColour.Set(GetRValue(chooseColorStruct.rgbResult), GetGValue(chooseColorStruct.rgbResult), - GetBValue(chooseColorStruct.rgbResult)); + wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult); return success ? wxID_OK : wxID_CANCEL; } +// ---------------------------------------------------------------------------- +// title +// ---------------------------------------------------------------------------- + +void wxColourDialog::SetTitle(const wxString& title) +{ + m_title = title; +} + +wxString wxColourDialog::GetTitle() const +{ + return m_title; +} + +// ---------------------------------------------------------------------------- +// position/size +// ---------------------------------------------------------------------------- + +void wxColourDialog::DoGetPosition(int *x, int *y) const +{ + if ( x ) + *x = m_pos.x; + if ( y ) + *y = m_pos.y; +} + +void wxColourDialog::DoSetSize(int x, int y, + int WXUNUSED(width), int WXUNUSED(height), + int WXUNUSED(sizeFlags)) +{ + if ( x != wxDefaultCoord ) + m_pos.x = x; + + if ( y != wxDefaultCoord ) + m_pos.y = y; + + // ignore the size params - we can't change the size of a standard dialog + return; +} + +// NB: of course, both of these functions are completely bogus, but it's better +// than nothing +void wxColourDialog::DoGetSize(int *width, int *height) const +{ + // the standard dialog size + if ( width ) + *width = 225; + if ( height ) + *height = 324; +} + +void wxColourDialog::DoGetClientSize(int *width, int *height) const +{ + // the standard dialog size + if ( width ) + *width = 219; + if ( height ) + *height = 299; +} + +#endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)