1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/colordlg.cpp
3 // Purpose: wxColourDialog class
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
27 #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__))
29 #include "wx/colordlg.h"
33 #include "wx/colour.h"
34 #include "wx/gdicmn.h"
36 #include "wx/dialog.h"
37 #include "wx/cmndata.h"
40 #include "wx/msw/private.h"
42 #include "wx/msw/wrapcdlg.h"
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
51 IMPLEMENT_DYNAMIC_CLASS(wxColourDialog
, wxDialog
)
53 // ============================================================================
55 // ============================================================================
57 // ----------------------------------------------------------------------------
58 // colour dialog hook proc
59 // ----------------------------------------------------------------------------
62 wxColourDialogHookProc(HWND hwnd
,
64 WPARAM
WXUNUSED(wParam
),
67 if ( uiMsg
== WM_INITDIALOG
)
69 CHOOSECOLOR
*pCC
= (CHOOSECOLOR
*)lParam
;
70 wxColourDialog
*dialog
= (wxColourDialog
*)pCC
->lCustData
;
72 ::SetWindowText(hwnd
, dialog
->GetTitle());
74 wxPoint pos
= dialog
->GetPosition();
75 if ( pos
!= wxDefaultPosition
)
77 ::SetWindowPos(hwnd
, NULL
/* Z-order: ignored */,
79 SWP_NOSIZE
| SWP_NOZORDER
);
86 // ----------------------------------------------------------------------------
88 // ----------------------------------------------------------------------------
90 wxColourDialog::wxColourDialog()
92 m_pos
= wxDefaultPosition
;
95 wxColourDialog::wxColourDialog(wxWindow
*parent
, wxColourData
*data
)
97 m_pos
= wxDefaultPosition
;
102 bool wxColourDialog::Create(wxWindow
*parent
, wxColourData
*data
)
106 m_colourData
= *data
;
111 int wxColourDialog::ShowModal()
113 CHOOSECOLOR chooseColorStruct
;
114 COLORREF custColours
[16];
115 memset(&chooseColorStruct
, 0, sizeof(CHOOSECOLOR
));
118 for (i
= 0; i
< 16; i
++)
120 if (m_colourData
.m_custColours
[i
].Ok())
121 custColours
[i
] = wxColourToRGB(m_colourData
.m_custColours
[i
]);
123 custColours
[i
] = RGB(255,255,255);
126 chooseColorStruct
.lStructSize
= sizeof(CHOOSECOLOR
);
128 chooseColorStruct
.hwndOwner
= GetHwndOf(m_parent
);
129 chooseColorStruct
.rgbResult
= wxColourToRGB(m_colourData
.m_dataColour
);
130 chooseColorStruct
.lpCustColors
= custColours
;
132 chooseColorStruct
.Flags
= CC_RGBINIT
| CC_ENABLEHOOK
;
133 chooseColorStruct
.lCustData
= (LPARAM
)this;
134 chooseColorStruct
.lpfnHook
= wxColourDialogHookProc
;
136 if (m_colourData
.GetChooseFull())
137 chooseColorStruct
.Flags
|= CC_FULLOPEN
;
139 // Do the modal dialog
140 bool success
= ::ChooseColor(&(chooseColorStruct
)) != 0;
142 // Try to highlight the correct window (the parent)
145 HWND hWndParent
= (HWND
) GetParent()->GetHWND();
147 ::BringWindowToTop(hWndParent
);
152 for (i
= 0; i
< 16; i
++)
154 wxRGBToColour(m_colourData
.m_custColours
[i
], custColours
[i
]);
157 wxRGBToColour(m_colourData
.m_dataColour
, chooseColorStruct
.rgbResult
);
159 return success
? wxID_OK
: wxID_CANCEL
;
162 // ----------------------------------------------------------------------------
164 // ----------------------------------------------------------------------------
166 void wxColourDialog::SetTitle(const wxString
& title
)
171 wxString
wxColourDialog::GetTitle() const
176 // ----------------------------------------------------------------------------
178 // ----------------------------------------------------------------------------
180 void wxColourDialog::DoGetPosition(int *x
, int *y
) const
188 void wxColourDialog::DoSetSize(int x
, int y
,
189 int WXUNUSED(width
), int WXUNUSED(height
),
190 int WXUNUSED(sizeFlags
))
192 if ( x
!= wxDefaultCoord
)
195 if ( y
!= wxDefaultCoord
)
198 // ignore the size params - we can't change the size of a standard dialog
202 // NB: of course, both of these functions are completely bogus, but it's better
204 void wxColourDialog::DoGetSize(int *width
, int *height
) const
206 // the standard dialog size
213 void wxColourDialog::DoGetClientSize(int *width
, int *height
) const
215 // the standard dialog size
222 #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__)