]> git.saurik.com Git - wxWidgets.git/blob - src/msw/nativdlg.cpp
fix wxExecute() return code checks and removed not working code to open URLs in new...
[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 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
22
23 #ifdef __BORLANDC__
24 #pragma hdrstop
25 #endif
26
27 #ifndef WX_PRECOMP
28 #include <stdio.h>
29
30 #include "wx/wx.h"
31 #endif
32
33 #if defined(__WIN95__)
34 #include "wx/spinbutt.h"
35 #endif
36 #include "wx/msw/private.h"
37
38 // ---------------------------------------------------------------------------
39 // global functions
40 // ---------------------------------------------------------------------------
41
42 extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message,
43 WPARAM wParam, LPARAM lParam);
44
45 // ===========================================================================
46 // implementation
47 // ===========================================================================
48
49 bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id)
50 {
51 m_windowId = id;
52
53 wxWindowCreationHook hook(this);
54 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(),
55 MAKEINTRESOURCE(id),
56 parent ? (HWND)parent->GetHWND() : 0,
57 (DLGPROC) wxDlgProc);
58
59 if ( !m_hWnd )
60 return false;
61
62 SubclassWin(GetHWND());
63
64 if ( parent )
65 parent->AddChild(this);
66 else
67 wxTopLevelWindows.Append(this);
68
69 // Enumerate all children
70 HWND hWndNext;
71 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
72
73 if (hWndNext)
74 CreateWindowFromHWND(this, (WXHWND) hWndNext);
75
76 while (hWndNext != (HWND) NULL)
77 {
78 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
79 if (hWndNext)
80 CreateWindowFromHWND(this, (WXHWND) hWndNext);
81 }
82
83 return true;
84 }
85
86 bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
87 {
88 SetName(name);
89
90 wxWindowCreationHook hook(this);
91 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
92 name.c_str(),
93 parent ? (HWND)parent->GetHWND() : 0,
94 (DLGPROC)wxDlgProc);
95
96 if ( !m_hWnd )
97 return false;
98
99 SubclassWin(GetHWND());
100
101 if ( parent )
102 parent->AddChild(this);
103 else
104 wxTopLevelWindows.Append(this);
105
106 // Enumerate all children
107 HWND hWndNext;
108 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
109
110 if (hWndNext)
111 CreateWindowFromHWND(this, (WXHWND) hWndNext);
112
113 while (hWndNext != (HWND) NULL)
114 {
115 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
116 if (hWndNext)
117 CreateWindowFromHWND(this, (WXHWND) hWndNext);
118 }
119
120 return true;
121 }
122
123 // ---------------------------------------------------------------------------
124 // look for child by id
125 // ---------------------------------------------------------------------------
126
127 wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
128 {
129 if ( m_windowId == id )
130 return this;
131
132 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
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;
144 }
145
146 wxWindow* wxWindow::GetWindowChild(wxWindowID id)
147 {
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;
165 }
166
167 // ---------------------------------------------------------------------------
168 // create wxWin window from a native HWND
169 // ---------------------------------------------------------------------------
170
171 wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
172 {
173 wxString str(wxGetWindowClass(hWnd));
174 str.UpperCase();
175
176 long id = wxGetWindowId(hWnd);
177 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
178
179 wxWindow* win = NULL;
180
181 if (str == wxT("BUTTON"))
182 {
183 int style1 = (style & 0xFF);
184 #if wxUSE_CHECKBOX
185 if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) ||
186 (style1 == BS_CHECKBOX))
187 {
188 win = new wxCheckBox;
189 }
190 else
191 #endif
192 #if wxUSE_RADIOBTN
193 if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON))
194 {
195 win = new wxRadioButton;
196 }
197 else
198 #endif
199 #if wxUSE_BMPBUTTON
200 #if defined(__WIN32__) && defined(BS_BITMAP)
201 if (style & BS_BITMAP)
202 {
203 // TODO: how to find the bitmap?
204 win = new wxBitmapButton;
205 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
206 }
207 else
208 #endif
209 if (style1 == BS_OWNERDRAW)
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 }
219 else
220 #endif
221 #if wxUSE_BUTTON
222 if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON))
223 {
224 win = new wxButton;
225 }
226 else
227 #endif
228 #if wxUSE_STATBOX
229 if (style1 == BS_GROUPBOX)
230 {
231 win = new wxStaticBox;
232 }
233 else
234 #endif
235 {
236 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
237 id);
238 }
239 }
240 #if wxUSE_COMBOBOX
241 else if (str == wxT("COMBOBOX"))
242 {
243 win = new wxComboBox;
244 }
245 #endif
246 #if wxUSE_TEXTCTRL
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.
253 else if (str == wxT("EDIT"))
254 {
255 win = new wxTextCtrl;
256 }
257 #endif
258 #if wxUSE_LISTBOX
259 else if (str == wxT("LISTBOX"))
260 {
261 win = new wxListBox;
262 }
263 #endif
264 #if wxUSE_SCROLLBAR
265 else if (str == wxT("SCROLLBAR"))
266 {
267 win = new wxScrollBar;
268 }
269 #endif
270 #if defined(__WIN95__) && wxUSE_SPINBTN
271 else if (str == wxT("MSCTLS_UPDOWN32"))
272 {
273 win = new wxSpinButton;
274 }
275 #endif
276 #if wxUSE_SLIDER
277 else if (str == wxT("MSCTLS_TRACKBAR32"))
278 {
279 // Need to ascertain if it's horiz or vert
280 win = new wxSlider;
281 }
282 #endif // wxUSE_SLIDER
283 #if wxUSE_STATTEXT
284 else if (str == wxT("STATIC"))
285 {
286 int style1 = (style & 0xFF);
287
288 if ((style1 == SS_LEFT) || (style1 == SS_RIGHT)
289 #ifndef __WXWINCE__
290 || (style1 == SS_SIMPLE)
291 #endif
292 )
293 win = new wxStaticText;
294 #if wxUSE_STATBMP
295 #if defined(__WIN32__) && defined(BS_BITMAP)
296 else if (style1 == SS_BITMAP)
297 {
298 win = new wxStaticBitmap;
299
300 // Help! this doesn't correspond with the wxWin implementation.
301 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
302 }
303 #endif
304 #endif /* wxUSE_STATBMP */
305 }
306 #endif
307 else
308 {
309 wxString msg(wxT("Don't know how to convert from Windows class "));
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();
323 }
324
325 return win;
326 }
327
328 // Make sure the window style (etc.) reflects the HWND style (roughly)
329 void wxWindow::AdoptAttributesFromHWND(void)
330 {
331 HWND hWnd = (HWND) GetHWND();
332 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
333
334 if (style & WS_VSCROLL)
335 m_windowStyle |= wxVSCROLL;
336 if (style & WS_HSCROLL)
337 m_windowStyle |= wxHSCROLL;
338 }
339