]>
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 licence | |
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 | |
37 | ,UINT message | |
38 | ,MPARAM wParam | |
39 | ,MPARAM lParam | |
40 | ); | |
41 | ||
42 | // =========================================================================== | |
43 | // implementation | |
44 | // =========================================================================== | |
45 | ||
46 | bool wxWindow::LoadNativeDialog ( | |
47 | wxWindow* pParent | |
48 | , wxWindowID& vId | |
49 | ) | |
50 | { | |
51 | wxWindow* pChild = NULL; | |
52 | HWND hWndOwner; | |
53 | HWND hWndNext = NULLHANDLE; | |
54 | HENUM hEnum; | |
55 | ||
56 | if (pParent) | |
57 | hWndOwner = GetHwndOf(pParent); | |
58 | else | |
59 | hWndOwner = HWND_DESKTOP; | |
60 | ||
61 | m_windowId = vId; | |
62 | wxWndHook = this; | |
63 | ||
64 | m_hWnd = ::WinLoadDlg( HWND_DESKTOP | |
65 | ,hWndOwner | |
66 | ,(PFNWP)wxDlgProc | |
67 | ,NULL | |
68 | ,(ULONG)131 // Caption dialog from the resource file | |
69 | ,(PVOID)this | |
70 | ); | |
71 | wxWndHook = NULL; | |
72 | ||
73 | if ( !m_hWnd ) | |
74 | return FALSE; | |
75 | ||
76 | SubclassWin(GetHWND()); | |
77 | ||
78 | if (pParent) | |
79 | pParent->AddChild(this); | |
80 | else | |
81 | wxTopLevelWindows.Append(this); | |
82 | ||
83 | // | |
84 | // Enumerate the children | |
85 | // | |
86 | hEnum = ::WinBeginEnumWindows(GetHwndOf(pParent)); | |
87 | while ((hWndNext = ::WinGetNextWindow(hEnum)) != NULLHANDLE) | |
88 | pChild = CreateWindowFromHWND( this | |
89 | ,(WXHWND)hWndNext | |
90 | ); | |
91 | ::WinEndEnumWindows(hEnum); | |
92 | return TRUE; | |
93 | } // end of wxWindow::LoadNativeDialog | |
94 | ||
95 | bool wxWindow::LoadNativeDialog ( | |
96 | wxWindow* pParent | |
97 | , const wxString& rsName | |
98 | ) | |
99 | { | |
100 | HWND hWndOwner; | |
101 | ||
102 | if (pParent) | |
103 | hWndOwner = GetHwndOf(pParent); | |
104 | else | |
105 | hWndOwner = HWND_DESKTOP; | |
106 | SetName(rsName); | |
107 | ||
108 | wxWndHook = this; | |
109 | m_hWnd = ::WinLoadDlg( HWND_DESKTOP | |
110 | ,hWndOwner | |
111 | ,(PFNWP)wxDlgProc | |
112 | ,NULL | |
113 | ,(ULONG)131 // Caption dialog from the resource file | |
114 | ,(PVOID)this | |
115 | ); | |
116 | wxWndHook = NULL; | |
117 | ||
118 | if (!m_hWnd) | |
119 | return FALSE; | |
120 | ||
121 | SubclassWin(GetHWND()); | |
122 | ||
123 | if (pParent) | |
124 | pParent->AddChild(this); | |
125 | else | |
126 | wxTopLevelWindows.Append(this); | |
127 | return TRUE; | |
128 | } // end of wxWindow::LoadNativeDialog | |
129 | ||
130 | // --------------------------------------------------------------------------- | |
131 | // look for child by id | |
132 | // --------------------------------------------------------------------------- | |
133 | wxWindow* wxWindow::GetWindowChild1 ( | |
134 | wxWindowID vId | |
135 | ) | |
136 | { | |
137 | if (m_windowId == vId) | |
138 | return this; | |
139 | ||
140 | wxWindowList::Node* pNode = GetChildren().GetFirst(); | |
141 | ||
142 | while (pNode) | |
143 | { | |
144 | wxWindow* pChild = pNode->GetData(); | |
145 | wxWindow* pWin = pChild->GetWindowChild1(vId); | |
146 | ||
147 | if (pWin) | |
148 | return pWin; | |
149 | ||
150 | pNode = pNode->GetNext(); | |
151 | } | |
152 | return NULL; | |
153 | } // end of wxWindow::GetWindowChild1 | |
154 | ||
155 | wxWindow* wxWindow::GetWindowChild ( | |
156 | wxWindowID vId | |
157 | ) | |
158 | { | |
159 | wxWindow* pWin = GetWindowChild1(vId); | |
160 | ||
161 | if (!pWin) | |
162 | { | |
163 | HWND hWnd = 0; // TODO: ::GetDlgItem((HWND) GetHWND(), id); | |
164 | ||
165 | if (hWnd) | |
166 | { | |
167 | wxWindow* pChild = CreateWindowFromHWND( this | |
168 | ,(WXHWND)hWnd | |
169 | ); | |
170 | if (pChild) | |
171 | { | |
172 | pChild->AddChild(this); | |
173 | return pChild; | |
174 | } | |
175 | } | |
176 | } | |
177 | return NULL; | |
178 | } // end of wxWindow::GetWindowChild | |
179 | ||
180 | // --------------------------------------------------------------------------- | |
181 | // create wxWin window from a native HWND | |
182 | // --------------------------------------------------------------------------- | |
183 | ||
184 | wxWindow* wxWindow::CreateWindowFromHWND ( | |
185 | wxWindow* pParent | |
186 | , WXHWND hWnd | |
187 | ) | |
188 | { | |
189 | wxString sStr(wxGetWindowClass(hWnd)); | |
190 | long lId = wxGetWindowId(hWnd); | |
191 | long lStyle = ::WinQueryWindowULong((HWND)hWnd | |
192 | ,QWL_STYLE | |
193 | ); | |
194 | wxWindow* pWin = NULL; | |
195 | ||
196 | sStr.UpperCase(); | |
197 | ||
198 | ||
199 | ||
200 | if (sStr == wxT("BUTTON")) | |
201 | { | |
202 | if (lStyle == BS_AUTOCHECKBOX) | |
203 | { | |
204 | pWin = new wxCheckBox; | |
205 | } | |
206 | else if (lStyle == BS_AUTORADIOBUTTON) | |
207 | { | |
208 | pWin = new wxRadioButton; | |
209 | } | |
210 | else if (lStyle & BS_BITMAP || lStyle == BS_USERBUTTON) | |
211 | { | |
212 | pWin = new wxBitmapButton; | |
213 | } | |
214 | else if (lStyle == BS_PUSHBUTTON) | |
215 | { | |
216 | pWin = new wxButton; | |
217 | } | |
218 | else if (lStyle == SS_GROUPBOX) | |
219 | { | |
220 | pWin = new wxStaticBox; | |
221 | } | |
222 | else | |
223 | { | |
224 | wxLogError(wxT("Don't know what kind of button this is: id = %ld"), | |
225 | lId); | |
226 | } | |
227 | } | |
228 | else if (sStr == wxT("COMBOBOX")) | |
229 | { | |
230 | pWin = new wxComboBox; | |
231 | } | |
232 | else if (sStr == wxT("EDIT")) | |
233 | { | |
234 | pWin = new wxTextCtrl; | |
235 | } | |
236 | else if (sStr == wxT("LISTBOX")) | |
237 | { | |
238 | pWin = new wxListBox; | |
239 | } | |
240 | else if (sStr == wxT("SCROLLBAR")) | |
241 | { | |
242 | pWin = new wxScrollBar; | |
243 | } | |
244 | else if (sStr == wxT("MSCTLS_UPDOWN32")) | |
245 | { | |
246 | pWin = new wxSpinButton; | |
247 | } | |
248 | else if (sStr == wxT("MSCTLS_TRACKBAR32")) | |
249 | { | |
250 | pWin = new wxSlider; | |
251 | } | |
252 | else if (sStr == wxT("STATIC")) | |
253 | { | |
254 | if (lStyle == SS_TEXT) | |
255 | pWin = new wxStaticText; | |
256 | else if (lStyle == SS_ICON) | |
257 | { | |
258 | pWin = new wxStaticBitmap; | |
259 | } | |
260 | } | |
261 | else | |
262 | { | |
263 | wxString sMsg(wxT("Don't know how to convert from Windows class ")); | |
264 | ||
265 | sMsg += sStr; | |
266 | wxLogError(sMsg); | |
267 | } | |
268 | if (pWin) | |
269 | { | |
270 | pParent->AddChild(pWin); | |
271 | pWin->SetEventHandler(pWin); | |
272 | pWin->SetHWND(hWnd); | |
273 | pWin->SetId(lId); | |
274 | pWin->SubclassWin(hWnd); | |
275 | pWin->AdoptAttributesFromHWND(); | |
276 | pWin->SetupColours(); | |
277 | return pWin; | |
278 | } | |
279 | else | |
280 | return NULL; | |
281 | } // end of wxWindow::CreateWindowFromHWND | |
282 | ||
283 | // | |
284 | // Make sure the window style (etc.) reflects the HWND style (roughly) | |
285 | // | |
286 | void wxWindow::AdoptAttributesFromHWND() | |
287 | { | |
288 | // Does nothing under OS/2 | |
289 | } // end of wxWindow::AdoptAttributesFromHWND | |
290 |