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