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