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