]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: nativdlg.cpp | |
3 | // Purpose: Native dialog loading code (part of wxWindow) | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 04/01/98 | |
7 | // RCS-ID: $Id$ | |
6c9a19aa | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
cc2b7472 VZ |
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__ | |
cc2b7472 | 24 | #pragma hdrstop |
2bda0e17 KB |
25 | #endif |
26 | ||
27 | #ifndef WX_PRECOMP | |
cc2b7472 VZ |
28 | #include <stdio.h> |
29 | ||
30 | #include "wx/wx.h" | |
2bda0e17 KB |
31 | #endif |
32 | ||
b39dbf34 | 33 | #if defined(__WIN95__) |
2bda0e17 | 34 | #include "wx/spinbutt.h" |
3372145d | 35 | #endif |
2bda0e17 KB |
36 | #include "wx/msw/private.h" |
37 | ||
cc2b7472 VZ |
38 | // --------------------------------------------------------------------------- |
39 | // global functions | |
40 | // --------------------------------------------------------------------------- | |
41 | ||
cc2b7472 VZ |
42 | extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message, |
43 | WPARAM wParam, LPARAM lParam); | |
44 | ||
45 | // =========================================================================== | |
46 | // implementation | |
47 | // =========================================================================== | |
2bda0e17 | 48 | |
debe6624 | 49 | bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id) |
2bda0e17 | 50 | { |
cc2b7472 | 51 | m_windowId = id; |
b225f659 VZ |
52 | |
53 | wxWindowCreationHook hook(this); | |
cc2b7472 VZ |
54 | m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(), |
55 | MAKEINTRESOURCE(id), | |
56 | parent ? (HWND)parent->GetHWND() : 0, | |
57 | (DLGPROC) wxDlgProc); | |
2bda0e17 | 58 | |
cc2b7472 | 59 | if ( !m_hWnd ) |
078cf5cb | 60 | return false; |
2bda0e17 | 61 | |
cc2b7472 | 62 | SubclassWin(GetHWND()); |
2bda0e17 | 63 | |
cc2b7472 VZ |
64 | if ( parent ) |
65 | parent->AddChild(this); | |
66 | else | |
67 | wxTopLevelWindows.Append(this); | |
2bda0e17 | 68 | |
cc2b7472 | 69 | // Enumerate all children |
2bda0e17 KB |
70 | HWND hWndNext; |
71 | hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD); | |
72 | ||
cc2b7472 | 73 | if (hWndNext) |
196be0f1 | 74 | CreateWindowFromHWND(this, (WXHWND) hWndNext); |
2bda0e17 | 75 | |
57c208c5 | 76 | while (hWndNext != (HWND) NULL) |
2bda0e17 | 77 | { |
cc2b7472 VZ |
78 | hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT); |
79 | if (hWndNext) | |
196be0f1 | 80 | CreateWindowFromHWND(this, (WXHWND) hWndNext); |
2bda0e17 KB |
81 | } |
82 | ||
078cf5cb | 83 | return true; |
2bda0e17 KB |
84 | } |
85 | ||
86 | bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name) | |
87 | { | |
cc2b7472 | 88 | SetName(name); |
2bda0e17 | 89 | |
b225f659 | 90 | wxWindowCreationHook hook(this); |
cc2b7472 VZ |
91 | m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(), |
92 | name.c_str(), | |
93 | parent ? (HWND)parent->GetHWND() : 0, | |
94 | (DLGPROC)wxDlgProc); | |
2bda0e17 | 95 | |
cc2b7472 | 96 | if ( !m_hWnd ) |
078cf5cb | 97 | return false; |
2bda0e17 | 98 | |
cc2b7472 | 99 | SubclassWin(GetHWND()); |
2bda0e17 | 100 | |
cc2b7472 VZ |
101 | if ( parent ) |
102 | parent->AddChild(this); | |
103 | else | |
104 | wxTopLevelWindows.Append(this); | |
2bda0e17 | 105 | |
f032bf3d JS |
106 | // Enumerate all children |
107 | HWND hWndNext; | |
108 | hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD); | |
109 | ||
f032bf3d | 110 | if (hWndNext) |
196be0f1 | 111 | CreateWindowFromHWND(this, (WXHWND) hWndNext); |
f032bf3d JS |
112 | |
113 | while (hWndNext != (HWND) NULL) | |
114 | { | |
115 | hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT); | |
116 | if (hWndNext) | |
196be0f1 | 117 | CreateWindowFromHWND(this, (WXHWND) hWndNext); |
f032bf3d | 118 | } |
2bda0e17 | 119 | |
078cf5cb | 120 | return true; |
2bda0e17 KB |
121 | } |
122 | ||
cc2b7472 VZ |
123 | // --------------------------------------------------------------------------- |
124 | // look for child by id | |
125 | // --------------------------------------------------------------------------- | |
126 | ||
127 | wxWindow* wxWindow::GetWindowChild1(wxWindowID id) | |
2bda0e17 | 128 | { |
cc2b7472 VZ |
129 | if ( m_windowId == id ) |
130 | return this; | |
131 | ||
222ed1d6 | 132 | wxWindowList::compatibility_iterator node = GetChildren().GetFirst(); |
cc2b7472 VZ |
133 | while ( node ) |
134 | { | |
135 | wxWindow* child = node->GetData(); | |
136 | wxWindow* win = child->GetWindowChild1(id); | |
137 | if ( win ) | |
138 | return win; | |
139 | ||
140 | node = node->GetNext(); | |
141 | } | |
142 | ||
143 | return NULL; | |
2bda0e17 KB |
144 | } |
145 | ||
cc2b7472 | 146 | wxWindow* wxWindow::GetWindowChild(wxWindowID id) |
2bda0e17 | 147 | { |
cc2b7472 VZ |
148 | wxWindow* win = GetWindowChild1(id); |
149 | if ( !win ) | |
150 | { | |
151 | HWND hWnd = ::GetDlgItem((HWND) GetHWND(), id); | |
152 | ||
153 | if (hWnd) | |
154 | { | |
155 | wxWindow* child = CreateWindowFromHWND(this, (WXHWND) hWnd); | |
156 | if (child) | |
157 | { | |
158 | child->AddChild(this); | |
159 | return child; | |
160 | } | |
161 | } | |
162 | } | |
163 | ||
164 | return NULL; | |
2bda0e17 KB |
165 | } |
166 | ||
cc2b7472 VZ |
167 | // --------------------------------------------------------------------------- |
168 | // create wxWin window from a native HWND | |
169 | // --------------------------------------------------------------------------- | |
2bda0e17 KB |
170 | |
171 | wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd) | |
172 | { | |
cc2b7472 VZ |
173 | wxString str(wxGetWindowClass(hWnd)); |
174 | str.UpperCase(); | |
2bda0e17 | 175 | |
cc2b7472 VZ |
176 | long id = wxGetWindowId(hWnd); |
177 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
2bda0e17 | 178 | |
cc2b7472 | 179 | wxWindow* win = NULL; |
2bda0e17 | 180 | |
223d09f6 | 181 | if (str == wxT("BUTTON")) |
cc2b7472 VZ |
182 | { |
183 | int style1 = (style & 0xFF); | |
461dae94 | 184 | #if wxUSE_CHECKBOX |
cc2b7472 VZ |
185 | if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) || |
186 | (style1 == BS_CHECKBOX)) | |
187 | { | |
188 | win = new wxCheckBox; | |
189 | } | |
461dae94 VZ |
190 | else |
191 | #endif | |
192 | #if wxUSE_RADIOBTN | |
193 | if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON)) | |
cc2b7472 VZ |
194 | { |
195 | win = new wxRadioButton; | |
196 | } | |
461dae94 VZ |
197 | else |
198 | #endif | |
8c18da2e | 199 | #if wxUSE_BMPBUTTON |
2432b92d | 200 | #if defined(__WIN32__) && defined(BS_BITMAP) |
461dae94 | 201 | if (style & BS_BITMAP) |
cc2b7472 VZ |
202 | { |
203 | // TODO: how to find the bitmap? | |
204 | win = new wxBitmapButton; | |
223d09f6 | 205 | wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button.")); |
cc2b7472 | 206 | } |
461dae94 | 207 | else |
2bda0e17 | 208 | #endif |
461dae94 | 209 | if (style1 == BS_OWNERDRAW) |
cc2b7472 VZ |
210 | { |
211 | // TODO: how to find the bitmap? | |
212 | // TODO: can't distinguish between bitmap button and bitmap static. | |
213 | // Change implementation of wxStaticBitmap to SS_BITMAP. | |
214 | // PROBLEM: this assumes that we're using resource-based bitmaps. | |
215 | // So maybe need 2 implementations of bitmap buttons/static controls, | |
216 | // with a switch in the drawing code. Call default proc if BS_BITMAP. | |
217 | win = new wxBitmapButton; | |
218 | } | |
461dae94 | 219 | else |
8c18da2e | 220 | #endif |
461dae94 VZ |
221 | #if wxUSE_BUTTON |
222 | if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON)) | |
cc2b7472 VZ |
223 | { |
224 | win = new wxButton; | |
225 | } | |
461dae94 VZ |
226 | else |
227 | #endif | |
228 | #if wxUSE_STATBOX | |
229 | if (style1 == BS_GROUPBOX) | |
cc2b7472 VZ |
230 | { |
231 | win = new wxStaticBox; | |
232 | } | |
233 | else | |
461dae94 | 234 | #endif |
cc2b7472 | 235 | { |
92aff599 | 236 | wxLogError(wxT("Don't know what kind of button this is: id = %ld"), |
cc2b7472 VZ |
237 | id); |
238 | } | |
239 | } | |
461dae94 | 240 | #if wxUSE_COMBOBOX |
223d09f6 | 241 | else if (str == wxT("COMBOBOX")) |
cc2b7472 VZ |
242 | { |
243 | win = new wxComboBox; | |
244 | } | |
461dae94 VZ |
245 | #endif |
246 | #if wxUSE_TEXTCTRL | |
cc2b7472 VZ |
247 | // TODO: Problem if the user creates a multiline - but not rich text - text control, |
248 | // since wxWin assumes RichEdit control for this. Should have m_isRichText in | |
249 | // wxTextCtrl. Also, convert as much of the window style as is necessary | |
250 | // for correct functioning. | |
251 | // Could have wxWindow::AdoptAttributesFromHWND(WXHWND) | |
252 | // to be overridden by each control class. | |
223d09f6 | 253 | else if (str == wxT("EDIT")) |
cc2b7472 VZ |
254 | { |
255 | win = new wxTextCtrl; | |
256 | } | |
461dae94 VZ |
257 | #endif |
258 | #if wxUSE_LISTBOX | |
223d09f6 | 259 | else if (str == wxT("LISTBOX")) |
cc2b7472 VZ |
260 | { |
261 | win = new wxListBox; | |
262 | } | |
461dae94 VZ |
263 | #endif |
264 | #if wxUSE_SCROLLBAR | |
223d09f6 | 265 | else if (str == wxT("SCROLLBAR")) |
cc2b7472 VZ |
266 | { |
267 | win = new wxScrollBar; | |
268 | } | |
461dae94 | 269 | #endif |
b39dbf34 | 270 | #if defined(__WIN95__) && wxUSE_SPINBTN |
223d09f6 | 271 | else if (str == wxT("MSCTLS_UPDOWN32")) |
cc2b7472 VZ |
272 | { |
273 | win = new wxSpinButton; | |
274 | } | |
2bda0e17 | 275 | #endif |
1e6feb95 | 276 | #if wxUSE_SLIDER |
223d09f6 | 277 | else if (str == wxT("MSCTLS_TRACKBAR32")) |
cc2b7472 VZ |
278 | { |
279 | // Need to ascertain if it's horiz or vert | |
280 | win = new wxSlider; | |
281 | } | |
1e6feb95 | 282 | #endif // wxUSE_SLIDER |
461dae94 | 283 | #if wxUSE_STATTEXT |
223d09f6 | 284 | else if (str == wxT("STATIC")) |
cc2b7472 VZ |
285 | { |
286 | int style1 = (style & 0xFF); | |
287 | ||
4676948b JS |
288 | if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) |
289 | #ifndef __WXWINCE__ | |
290 | || (style1 == SS_SIMPLE) | |
291 | #endif | |
292 | ) | |
cc2b7472 | 293 | win = new wxStaticText; |
8c18da2e | 294 | #if wxUSE_STATBMP |
2432b92d | 295 | #if defined(__WIN32__) && defined(BS_BITMAP) |
cc2b7472 VZ |
296 | else if (style1 == SS_BITMAP) |
297 | { | |
298 | win = new wxStaticBitmap; | |
2bda0e17 | 299 | |
cc2b7472 | 300 | // Help! this doesn't correspond with the wxWin implementation. |
223d09f6 | 301 | wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons.")); |
cc2b7472 | 302 | } |
2bda0e17 | 303 | #endif |
078cf5cb | 304 | #endif /* wxUSE_STATBMP */ |
cc2b7472 | 305 | } |
461dae94 | 306 | #endif |
cc2b7472 VZ |
307 | else |
308 | { | |
223d09f6 | 309 | wxString msg(wxT("Don't know how to convert from Windows class ")); |
cc2b7472 VZ |
310 | msg += str; |
311 | wxLogError(msg); | |
312 | } | |
313 | ||
314 | if (win) | |
315 | { | |
316 | parent->AddChild(win); | |
317 | win->SetEventHandler(win); | |
318 | win->SetHWND(hWnd); | |
319 | win->SetId(id); | |
320 | win->SubclassWin(hWnd); | |
321 | win->AdoptAttributesFromHWND(); | |
322 | win->SetupColours(); | |
cc2b7472 | 323 | } |
3ca6a5f0 BP |
324 | |
325 | return win; | |
2bda0e17 KB |
326 | } |
327 | ||
328 | // Make sure the window style (etc.) reflects the HWND style (roughly) | |
329 | void wxWindow::AdoptAttributesFromHWND(void) | |
330 | { | |
cc2b7472 VZ |
331 | HWND hWnd = (HWND) GetHWND(); |
332 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
2bda0e17 | 333 | |
cc2b7472 VZ |
334 | if (style & WS_VSCROLL) |
335 | m_windowStyle |= wxVSCROLL; | |
336 | if (style & WS_HSCROLL) | |
337 | m_windowStyle |= wxHSCROLL; | |
2bda0e17 KB |
338 | } |
339 |