]>
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" | |
30 | ||
2bda0e17 | 31 | #ifndef WX_PRECOMP |
f6bcfd97 | 32 | #include <stdio.h> |
f6bcfd97 BP |
33 | #include "wx/colour.h" |
34 | #include "wx/gdicmn.h" | |
35 | #include "wx/utils.h" | |
f6bcfd97 | 36 | #include "wx/dialog.h" |
ce5d92e1 | 37 | #include "wx/cmndata.h" |
18680f86 | 38 | #include "wx/math.h" |
2bda0e17 KB |
39 | #endif |
40 | ||
2bda0e17 | 41 | #include "wx/msw/private.h" |
660296aa | 42 | #include "wx/msw/wrapcdlg.h" |
4676948b | 43 | |
2bda0e17 KB |
44 | #include <stdlib.h> |
45 | #include <string.h> | |
46 | ||
f6bcfd97 BP |
47 | // ---------------------------------------------------------------------------- |
48 | // wxWin macros | |
49 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 50 | |
2bda0e17 | 51 | IMPLEMENT_DYNAMIC_CLASS(wxColourDialog, wxDialog) |
2bda0e17 | 52 | |
f6bcfd97 BP |
53 | // ============================================================================ |
54 | // implementation | |
55 | // ============================================================================ | |
56 | ||
57 | // ---------------------------------------------------------------------------- | |
58 | // colour dialog hook proc | |
59 | // ---------------------------------------------------------------------------- | |
60 | ||
975b6bcf VZ |
61 | UINT_PTR CALLBACK |
62 | wxColourDialogHookProc(HWND hwnd, | |
63 | UINT uiMsg, | |
64 | WPARAM WXUNUSED(wParam), | |
65 | LPARAM lParam) | |
f6bcfd97 BP |
66 | { |
67 | if ( uiMsg == WM_INITDIALOG ) | |
68 | { | |
69 | CHOOSECOLOR *pCC = (CHOOSECOLOR *)lParam; | |
70 | wxColourDialog *dialog = (wxColourDialog *)pCC->lCustData; | |
71 | ||
72 | ::SetWindowText(hwnd, dialog->GetTitle()); | |
f63e3ebb VZ |
73 | |
74 | wxPoint pos = dialog->GetPosition(); | |
75 | if ( pos != wxDefaultPosition ) | |
76 | { | |
77 | ::SetWindowPos(hwnd, NULL /* Z-order: ignored */, | |
78 | pos.x, pos.y, -1, -1, | |
79 | SWP_NOSIZE | SWP_NOZORDER); | |
80 | } | |
f6bcfd97 BP |
81 | } |
82 | ||
83 | return 0; | |
84 | } | |
85 | ||
86 | // ---------------------------------------------------------------------------- | |
87 | // wxColourDialog | |
88 | // ---------------------------------------------------------------------------- | |
2bda0e17 | 89 | |
f6bcfd97 | 90 | wxColourDialog::wxColourDialog() |
2bda0e17 | 91 | { |
f63e3ebb | 92 | m_pos = wxDefaultPosition; |
2bda0e17 KB |
93 | } |
94 | ||
95 | wxColourDialog::wxColourDialog(wxWindow *parent, wxColourData *data) | |
96 | { | |
f63e3ebb VZ |
97 | m_pos = wxDefaultPosition; |
98 | ||
f6bcfd97 | 99 | Create(parent, data); |
2bda0e17 KB |
100 | } |
101 | ||
102 | bool wxColourDialog::Create(wxWindow *parent, wxColourData *data) | |
103 | { | |
f6bcfd97 BP |
104 | m_parent = parent; |
105 | if (data) | |
106 | m_colourData = *data; | |
bbcdf8bc | 107 | |
02b7b6b0 | 108 | return true; |
2bda0e17 KB |
109 | } |
110 | ||
f6bcfd97 | 111 | int wxColourDialog::ShowModal() |
2bda0e17 KB |
112 | { |
113 | CHOOSECOLOR chooseColorStruct; | |
114 | COLORREF custColours[16]; | |
115 | memset(&chooseColorStruct, 0, sizeof(CHOOSECOLOR)); | |
116 | ||
117 | int i; | |
118 | for (i = 0; i < 16; i++) | |
393c836c VS |
119 | { |
120 | if (m_colourData.m_custColours[i].Ok()) | |
121 | custColours[i] = wxColourToRGB(m_colourData.m_custColours[i]); | |
122 | else | |
123 | custColours[i] = RGB(255,255,255); | |
124 | } | |
2bda0e17 KB |
125 | |
126 | chooseColorStruct.lStructSize = sizeof(CHOOSECOLOR); | |
f6bcfd97 BP |
127 | if ( m_parent ) |
128 | chooseColorStruct.hwndOwner = GetHwndOf(m_parent); | |
ae500232 | 129 | chooseColorStruct.rgbResult = wxColourToRGB(m_colourData.m_dataColour); |
2bda0e17 KB |
130 | chooseColorStruct.lpCustColors = custColours; |
131 | ||
f6bcfd97 BP |
132 | chooseColorStruct.Flags = CC_RGBINIT | CC_ENABLEHOOK; |
133 | chooseColorStruct.lCustData = (LPARAM)this; | |
134 | chooseColorStruct.lpfnHook = wxColourDialogHookProc; | |
2bda0e17 | 135 | |
cf75c1b4 RD |
136 | if (m_colourData.GetChooseFull()) |
137 | chooseColorStruct.Flags |= CC_FULLOPEN; | |
2bda0e17 KB |
138 | |
139 | // Do the modal dialog | |
f6bcfd97 | 140 | bool success = ::ChooseColor(&(chooseColorStruct)) != 0; |
2bda0e17 KB |
141 | |
142 | // Try to highlight the correct window (the parent) | |
2bda0e17 KB |
143 | if (GetParent()) |
144 | { | |
5cb598ae | 145 | HWND hWndParent = (HWND) GetParent()->GetHWND(); |
2bda0e17 KB |
146 | if (hWndParent) |
147 | ::BringWindowToTop(hWndParent); | |
148 | } | |
149 | ||
150 | ||
151 | // Restore values | |
152 | for (i = 0; i < 16; i++) | |
153 | { | |
ae500232 | 154 | wxRGBToColour(m_colourData.m_custColours[i], custColours[i]); |
2bda0e17 KB |
155 | } |
156 | ||
ae500232 | 157 | wxRGBToColour(m_colourData.m_dataColour, chooseColorStruct.rgbResult); |
2bda0e17 KB |
158 | |
159 | return success ? wxID_OK : wxID_CANCEL; | |
160 | } | |
161 | ||
f6bcfd97 BP |
162 | // ---------------------------------------------------------------------------- |
163 | // title | |
164 | // ---------------------------------------------------------------------------- | |
165 | ||
166 | void wxColourDialog::SetTitle(const wxString& title) | |
167 | { | |
168 | m_title = title; | |
169 | } | |
170 | ||
ba14d986 | 171 | wxString wxColourDialog::GetTitle() const |
f6bcfd97 BP |
172 | { |
173 | return m_title; | |
174 | } | |
175 | ||
176 | // ---------------------------------------------------------------------------- | |
177 | // position/size | |
178 | // ---------------------------------------------------------------------------- | |
179 | ||
f63e3ebb VZ |
180 | void wxColourDialog::DoGetPosition(int *x, int *y) const |
181 | { | |
182 | if ( x ) | |
183 | *x = m_pos.x; | |
184 | if ( y ) | |
185 | *y = m_pos.y; | |
186 | } | |
187 | ||
188 | void wxColourDialog::DoSetSize(int x, int y, | |
f6bcfd97 BP |
189 | int WXUNUSED(width), int WXUNUSED(height), |
190 | int WXUNUSED(sizeFlags)) | |
191 | { | |
02b7b6b0 | 192 | if ( x != wxDefaultCoord ) |
f63e3ebb VZ |
193 | m_pos.x = x; |
194 | ||
02b7b6b0 | 195 | if ( y != wxDefaultCoord ) |
f63e3ebb VZ |
196 | m_pos.y = y; |
197 | ||
198 | // ignore the size params - we can't change the size of a standard dialog | |
f6bcfd97 BP |
199 | return; |
200 | } | |
201 | ||
202 | // NB: of course, both of these functions are completely bogus, but it's better | |
203 | // than nothing | |
204 | void wxColourDialog::DoGetSize(int *width, int *height) const | |
205 | { | |
206 | // the standard dialog size | |
207 | if ( width ) | |
208 | *width = 225; | |
209 | if ( height ) | |
210 | *height = 324; | |
211 | } | |
212 | ||
213 | void wxColourDialog::DoGetClientSize(int *width, int *height) const | |
214 | { | |
215 | // the standard dialog size | |
216 | if ( width ) | |
217 | *width = 219; | |
218 | if ( height ) | |
219 | *height = 299; | |
220 | } | |
f63e3ebb | 221 | |
3180bc0e | 222 | #endif // wxUSE_COLOURDLG && !(__SMARTPHONE__ && __WXWINCE__) |