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