]>
Commit | Line | Data |
---|---|---|
2bda0e17 | 1 | ///////////////////////////////////////////////////////////////////////////// |
f6bcfd97 | 2 | // Name: src/msw/colordlg.cpp |
2bda0e17 KB |
3 | // Purpose: wxColourDialog class |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 01/02/97 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
f6bcfd97 BP |
12 | // ============================================================================ |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
2bda0e17 KB |
20 | // For compilers that support precompilation, includes "wx.h". |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
f6bcfd97 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
ce5d92e1 WS |
27 | #if wxUSE_COLOURDLG && !(defined(__SMARTPHONE__) && defined(__WXWINCE__)) |
28 | ||
29 | #include "wx/colordlg.h" | |
691745ab | 30 | #include "wx/modalhook.h" |
ce5d92e1 | 31 | |
2bda0e17 | 32 | #ifndef WX_PRECOMP |
57bd4c60 | 33 | #include "wx/msw/wrapcdlg.h" |
f6bcfd97 | 34 | #include <stdio.h> |
f6bcfd97 BP |
35 | #include "wx/colour.h" |
36 | #include "wx/gdicmn.h" | |
37 | #include "wx/utils.h" | |
18680f86 | 38 | #include "wx/math.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
2bda0e17 | 41 | #include "wx/msw/private.h" |
4676948b | 42 | |
2bda0e17 KB |
43 | #include <stdlib.h> |
44 | #include <string.h> | |
45 | ||
82c63878 VZ |
46 | // ---------------------------------------------------------------------------- |
47 | // globals | |
48 | // ---------------------------------------------------------------------------- | |
49 | ||
50 | // standard colors dialog size for the Windows systems | |
51 | // this is ok if color dialog created with standart color | |
52 | // and "Define Custom Colors" extension not shown | |
53 | static wxRect gs_rectDialog(0, 0, 222, 324); | |
54 | ||
f6bcfd97 BP |
55 | // ---------------------------------------------------------------------------- |
56 | // wxWin macros | |
57 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 58 | |
2bda0e17 | 59 | IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) |
2bda0e17 | 60 | |
f6bcfd97 BP |
61 | // ============================================================================ |
62 | // implementation | |
63 | // ============================================================================ | |
64 | ||
65 | // ---------------------------------------------------------------------------- | |
66 | // colour dialog hook proc | |
67 | // ---------------------------------------------------------------------------- | |
68 | ||
975b6bcf VZ |
69 | UINT_PTR CALLBACK |
70 | wxColourDialogHookProc(HWND hwnd, | |
71 | UINT uiMsg, | |
72 | WPARAM WXUNUSED(wParam), | |
73 | LPARAM lParam) | |
f6bcfd97 BP |
74 | { |
75 | if ( uiMsg == WM_INITDIALOG ) | |
76 | { | |
77 | CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam; | |
82c63878 | 78 | wxColourDialog * const |
5c33522f | 79 | dialog = reinterpret_cast<wxColourDialog *>(pCC->lCustData); |
f6bcfd97 | 80 | |
e42aab7f | 81 | const wxString title = dialog->GetTitle(); |
283db411 | 82 | if ( !title.empty() ) |
017dc06b | 83 | ::SetWindowText(hwnd, title.t_str()); |
f63e3ebb | 84 | |
82c63878 | 85 | dialog->MSWOnInitDone((WXHWND)hwnd); |
f6bcfd97 BP |
86 | } |
87 | ||
88 | return 0; | |
89 | } | |
90 | ||
91 | // ---------------------------------------------------------------------------- | |
92 | // wxColourDialog | |
93 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 94 | |
82c63878 | 95 | void wxColourDialog::Init() |
2bda0e17 | 96 | { |
82c63878 VZ |
97 | m_movedWindow = false; |
98 | m_centreDir = 0; | |
99 | ||
100 | // reset to zero, otherwise the wx routines won't size the window the | |
101 | // second time the dialog is shown, because they would believe it already | |
102 | // has the requested size/position | |
103 | gs_rectDialog.x = | |
104 | gs_rectDialog.y = 0; | |
2bda0e17 KB |
105 | } |
106 | ||
107 | bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) | |
108 | { | |
f6bcfd97 BP |
109 | m_parent = parent; |
110 | if (data) | |
111 | m_colourData = *data; | |
bbcdf8bc | 112 | |
02b7b6b0 | 113 | return true; |
2bda0e17 KB |
114 | } |
115 | ||
f6bcfd97 | 116 | int wxColourDialog::ShowModal() |
2bda0e17 | 117 | { |
691745ab | 118 | WX_HOOK_MODAL_DIALOG(); |
643e9cf9 | 119 | |
2349ba4c | 120 | // initialize the struct used by Windows |
2bda0e17 | 121 | CHOOSECOLOR chooseColorStruct; |
2bda0e17 KB |
122 | memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); |
123 | ||
05be97a8 | 124 | size_t i; |
2349ba4c VZ |
125 | |
126 | // and transfer data from m_colourData to it | |
127 | COLORREF custColours[16]; | |
128 | for ( i = 0; i < WXSIZEOF(custColours); i++ ) | |
393c836c | 129 | { |
6869b469 FM |
130 | if ( m_colourData.GetCustomColour(i).IsOk() ) |
131 | custColours[i] = wxColourToRGB(m_colourData.GetCustomColour(i)); | |
393c836c VS |
132 | else |
133 | custColours[i] = RGB(255,255,255); | |
134 | } | |
2bda0e17 KB |
135 | |
136 | chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); | |
f6bcfd97 BP |
137 | if ( m_parent ) |
138 | chooseColorStruct.hwndOwner = GetHwndOf(m_parent); | |
6869b469 | 139 | chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.GetColour()); |
2bda0e17 KB |
140 | chooseColorStruct.lpCustColors = custColours; |
141 | ||
f6bcfd97 BP |
142 | chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; |
143 | chooseColorStruct.lCustData = (LPARAM)this; | |
144 | chooseColorStruct.lpfnHook = wxColourDialogHookProc; | |
2bda0e17 | 145 | |
2349ba4c | 146 | if ( m_colourData.GetChooseFull() ) |
cf75c1b4 | 147 | chooseColorStruct.Flags |= CC_FULLOPEN; |
2bda0e17 | 148 | |
2349ba4c VZ |
149 | // do show the modal dialog |
150 | if ( !::ChooseColor(&chooseColorStruct) ) | |
2bda0e17 | 151 | { |
2349ba4c VZ |
152 | // 0 error means the dialog was simply cancelled, i.e. no real error |
153 | // occurred | |
154 | const DWORD err = CommDlgExtendedError(); | |
155 | if ( err ) | |
43b2d5e7 | 156 | { |
2349ba4c | 157 | wxLogError(_("Colour selection dialog failed with error %0lx."), err); |
43b2d5e7 | 158 | } |
2349ba4c VZ |
159 | |
160 | return wxID_CANCEL; | |
2bda0e17 KB |
161 | } |
162 | ||
163 | ||
2349ba4c VZ |
164 | // transfer the values chosen by user back into m_colourData |
165 | for ( i = 0; i < WXSIZEOF(custColours); i++ ) | |
2bda0e17 | 166 | { |
f4efd805 | 167 | wxRGBToColour(m_colourData.m_custColours[i], custColours[i]); |
2bda0e17 KB |
168 | } |
169 | ||
6869b469 | 170 | wxRGBToColour(m_colourData.GetColour(), chooseColorStruct.rgbResult); |
2bda0e17 | 171 | |
2349ba4c VZ |
172 | // this doesn't seem to work (contrary to what MSDN implies) on current |
173 | // Windows versions: CC_FULLOPEN is never set on return if it wasn't | |
174 | // initially set and vice versa | |
175 | //m_colourData.SetChooseFull((chooseColorStruct.Flags & CC_FULLOPEN) != 0); | |
176 | ||
177 | return wxID_OK; | |
2bda0e17 KB |
178 | } |
179 | ||
f6bcfd97 BP |
180 | // ---------------------------------------------------------------------------- |
181 | // title | |
182 | // ---------------------------------------------------------------------------- | |
183 | ||
184 | void wxColourDialog::SetTitle(const wxString& title) | |
185 | { | |
186 | m_title = title; | |
187 | } | |
188 | ||
ba14d986 | 189 | wxString wxColourDialog::GetTitle() const |
f6bcfd97 BP |
190 | { |
191 | return m_title; | |
192 | } | |
193 | ||
194 | // ---------------------------------------------------------------------------- | |
195 | // position/size | |
196 | // ---------------------------------------------------------------------------- | |
197 | ||
f63e3ebb VZ |
198 | void wxColourDialog::DoGetPosition(int *x, int *y) const |
199 | { | |
200 | if ( x ) | |
82c63878 | 201 | *x = gs_rectDialog.x; |
f63e3ebb | 202 | if ( y ) |
82c63878 | 203 | *y = gs_rectDialog.y; |
f63e3ebb VZ |
204 | } |
205 | ||
82c63878 | 206 | void wxColourDialog::DoCentre(int dir) |
f6bcfd97 | 207 | { |
82c63878 VZ |
208 | m_centreDir = dir; |
209 | ||
210 | // it's unnecessary to do anything else at this stage as we'll redo it in | |
211 | // MSWOnInitDone() anyhow | |
212 | } | |
f63e3ebb | 213 | |
82c63878 VZ |
214 | void wxColourDialog::DoMoveWindow(int x, int y, int WXUNUSED(w), int WXUNUSED(h)) |
215 | { | |
216 | gs_rectDialog.x = x; | |
217 | gs_rectDialog.y = y; | |
f63e3ebb | 218 | |
82c63878 VZ |
219 | // our HWND is only set when we're called from MSWOnInitDone(), test if |
220 | // this is the case | |
221 | HWND hwnd = GetHwnd(); | |
222 | if ( hwnd ) | |
223 | { | |
224 | // size of the dialog can't be changed because the controls are not | |
225 | // laid out correctly then | |
226 | ::SetWindowPos(hwnd, HWND_TOP, x, y, 0, 0, SWP_NOZORDER | SWP_NOSIZE); | |
227 | } | |
228 | else // just remember that we were requested to move the window | |
229 | { | |
230 | m_movedWindow = true; | |
231 | ||
232 | // if Centre() had been called before, it shouldn't be taken into | |
233 | // account now | |
234 | m_centreDir = 0; | |
235 | } | |
f6bcfd97 BP |
236 | } |
237 | ||
f6bcfd97 BP |
238 | void wxColourDialog::DoGetSize(int *width, int *height) const |
239 | { | |
f6bcfd97 | 240 | if ( width ) |
82c63878 | 241 | *width = gs_rectDialog.width; |
f6bcfd97 | 242 | if ( height ) |
82c63878 | 243 | *height = gs_rectDialog.height; |
f6bcfd97 BP |
244 | } |
245 | ||
246 | void wxColourDialog::DoGetClientSize(int *width, int *height) const | |
247 | { | |
f6bcfd97 | 248 | if ( width ) |
82c63878 | 249 | *width = gs_rectDialog.width; |
f6bcfd97 | 250 | if ( height ) |
82c63878 VZ |
251 | *height = gs_rectDialog.height; |
252 | } | |
253 | ||
254 | void wxColourDialog::MSWOnInitDone(WXHWND hDlg) | |
255 | { | |
256 | // set HWND so that our DoMoveWindow() works correctly | |
257 | SetHWND(hDlg); | |
258 | ||
259 | if ( m_centreDir ) | |
260 | { | |
261 | // now we have the real dialog size, remember it | |
262 | RECT rect; | |
263 | ::GetWindowRect((HWND)hDlg, &rect); | |
264 | gs_rectDialog = wxRectFromRECT(rect); | |
265 | ||
266 | // and position the window correctly: notice that we must use the base | |
267 | // class version as our own doesn't do anything except setting flags | |
268 | wxDialog::DoCentre(m_centreDir); | |
269 | } | |
270 | else if ( m_movedWindow ) // need to just move it to the correct place | |
271 | { | |
272 | SetPosition(GetPosition()); | |
273 | } | |
274 | ||
275 | // we shouldn't destroy hDlg, so disassociate from it | |
276 | SetHWND(NULL); | |
f6bcfd97 | 277 | } |
f63e3ebb | 278 | |
3180bc0e | 279 | #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__) |