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