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