]>
Commit | Line | Data |
---|---|---|
2bda0e17 KB |
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 | ||
debe6624 | 34 | bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id) |
2bda0e17 KB |
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 != 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 | ||
debe6624 | 94 | wxWindow* wxWindow::GetWindowChild1(wxWindowID& id) |
2bda0e17 KB |
95 | { |
96 | if ( m_windowId == id ) | |
97 | return this; | |
98 | ||
c0ed460c | 99 | wxNode *node = GetChildren().First(); |
2bda0e17 KB |
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 | ||
debe6624 | 112 | wxWindow* wxWindow::GetWindowChild(wxWindowID& id) |
2bda0e17 KB |
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 | GetClassNameA((HWND) hWnd, buf, 256); | |
144 | #endif | |
145 | #endif | |
146 | ||
147 | wxString str(buf); | |
148 | str.UpperCase(); | |
149 | ||
150 | #ifndef __WIN32__ | |
151 | long id = (long) GetWindowWord((HWND) hWnd, GWW_ID); | |
152 | #else | |
153 | long id = GetWindowLong((HWND) hWnd, GWL_ID); | |
154 | #endif | |
155 | ||
156 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
157 | ||
158 | wxWindow* win = NULL; | |
159 | ||
160 | if (str == "BUTTON") | |
161 | { | |
162 | int style1 = (style & 0xFF); | |
163 | if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) || | |
164 | (style1 == BS_CHECKBOX)) | |
165 | { | |
166 | win = new wxCheckBox; | |
167 | } | |
168 | else if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON)) | |
169 | { | |
170 | win = new wxRadioButton; | |
171 | } | |
172 | #ifdef __WIN32__ | |
173 | else if (style & BS_BITMAP) | |
174 | { | |
175 | // TODO: how to find the bitmap? | |
176 | win = new wxBitmapButton; | |
44c4a334 | 177 | wxLogError("Have not yet implemented bitmap button as BS_BITMAP button."); |
2bda0e17 KB |
178 | } |
179 | #endif | |
180 | else if (style1 == BS_OWNERDRAW) | |
181 | { | |
182 | // TODO: how to find the bitmap? | |
183 | // TODO: can't distinguish between bitmap button and bitmap static. | |
184 | // Change implementation of wxStaticBitmap to SS_BITMAP. | |
185 | // PROBLEM: this assumes that we're using resource-based bitmaps. | |
186 | // So maybe need 2 implementations of bitmap buttons/static controls, | |
187 | // with a switch in the drawing code. Call default proc if BS_BITMAP. | |
188 | win = new wxBitmapButton; | |
189 | } | |
190 | else if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON)) | |
191 | { | |
192 | win = new wxButton; | |
193 | } | |
194 | else if (style1 == BS_GROUPBOX) | |
195 | { | |
196 | win = new wxStaticBox; | |
197 | } | |
198 | else | |
199 | { | |
200 | char buf[256]; | |
201 | sprintf(buf, "Don't know what kind of button this is: id = %d", (int) id); | |
44c4a334 | 202 | wxLogError(buf); |
2bda0e17 KB |
203 | } |
204 | } | |
205 | else if (str == "COMBOBOX") | |
206 | { | |
207 | win = new wxComboBox; | |
208 | } | |
209 | // TODO: Problem if the user creates a multiline - but not rich text - text control, | |
210 | // since wxWin assumes RichEdit control for this. Should have m_isRichText in | |
211 | // wxTextCtrl. Also, convert as much of the window style as is necessary | |
212 | // for correct functioning. | |
213 | // Could have wxWindow::AdoptAttributesFromHWND(WXHWND) | |
214 | // to be overridden by each control class. | |
215 | else if (str == "EDIT") | |
216 | { | |
217 | win = new wxTextCtrl; | |
218 | } | |
219 | else if (str == "LISTBOX") | |
220 | { | |
221 | win = new wxListBox; | |
222 | } | |
223 | else if (str == "SCROLLBAR") | |
224 | { | |
225 | win = new wxScrollBar; | |
226 | } | |
227 | #if defined(__WIN95__) | |
228 | else if (str == "MSCTLS_UPDOWN32") | |
229 | { | |
87d1e11f | 230 | win = new wxSpinButton; |
2bda0e17 KB |
231 | } |
232 | #endif | |
233 | else if (str == "MSCTLS_TRACKBAR32") | |
234 | { | |
235 | // Need to ascertain if it's horiz or vert | |
236 | win = new wxSlider; | |
237 | } | |
238 | else if (str == "STATIC") | |
239 | { | |
240 | int style1 = (style & 0xFF); | |
241 | ||
242 | if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) || (style1 == SS_SIMPLE)) | |
243 | win = new wxStaticText; | |
244 | #ifdef __WIN32__ | |
245 | else if (style1 == SS_BITMAP) | |
246 | { | |
247 | win = new wxStaticBitmap; | |
248 | ||
249 | // Help! this doesn't correspond with the wxWin implementation. | |
44c4a334 | 250 | wxLogError("Please make SS_BITMAP statics into owner-draw buttons."); |
2bda0e17 KB |
251 | } |
252 | #endif | |
253 | } | |
254 | else | |
255 | { | |
256 | wxString msg("Don't know how to convert from Windows class "); | |
257 | msg += str; | |
44c4a334 | 258 | wxLogError(msg); |
2bda0e17 KB |
259 | } |
260 | ||
261 | if (win) | |
262 | { | |
263 | parent->AddChild(win); | |
264 | win->SetEventHandler(win); | |
265 | win->SetHWND(hWnd); | |
266 | win->SetId(id); | |
267 | win->SubclassWin(hWnd); | |
268 | win->AdoptAttributesFromHWND(); | |
269 | win->SetupColours(); | |
270 | ||
271 | return win; | |
272 | } | |
273 | else | |
274 | return NULL; | |
275 | } | |
276 | ||
277 | // Make sure the window style (etc.) reflects the HWND style (roughly) | |
278 | void wxWindow::AdoptAttributesFromHWND(void) | |
279 | { | |
280 | HWND hWnd = (HWND) GetHWND(); | |
281 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
282 | ||
283 | if (style & WS_VSCROLL) | |
284 | m_windowStyle |= wxVSCROLL; | |
285 | if (style & WS_HSCROLL) | |
286 | m_windowStyle |= wxHSCROLL; | |
287 | } | |
288 | ||
289 |