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