]>
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$ | |
6c9a19aa JS |
8 | // Copyright: (c) Julian Smart |
9 | // Licence: wxWindows licence | |
2bda0e17 KB |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
cc2b7472 VZ |
12 | // =========================================================================== |
13 | // declarations | |
14 | // =========================================================================== | |
15 | ||
16 | // --------------------------------------------------------------------------- | |
17 | // headers | |
18 | // --------------------------------------------------------------------------- | |
19 | ||
2bda0e17 | 20 | #ifdef __GNUG__ |
cc2b7472 | 21 | #pragma implementation |
2bda0e17 KB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
cc2b7472 | 28 | #pragma hdrstop |
2bda0e17 KB |
29 | #endif |
30 | ||
31 | #ifndef WX_PRECOMP | |
cc2b7472 VZ |
32 | #include <stdio.h> |
33 | ||
34 | #include "wx/wx.h" | |
2bda0e17 KB |
35 | #endif |
36 | ||
b39dbf34 | 37 | #if defined(__WIN95__) |
2bda0e17 | 38 | #include "wx/spinbutt.h" |
3372145d | 39 | #endif |
2bda0e17 KB |
40 | #include "wx/msw/private.h" |
41 | ||
cc2b7472 VZ |
42 | // --------------------------------------------------------------------------- |
43 | // global functions | |
44 | // --------------------------------------------------------------------------- | |
45 | ||
cc2b7472 VZ |
46 | extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message, |
47 | WPARAM wParam, LPARAM lParam); | |
48 | ||
49 | // =========================================================================== | |
50 | // implementation | |
51 | // =========================================================================== | |
2bda0e17 | 52 | |
debe6624 | 53 | bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id) |
2bda0e17 | 54 | { |
cc2b7472 | 55 | m_windowId = id; |
b225f659 VZ |
56 | |
57 | wxWindowCreationHook hook(this); | |
cc2b7472 VZ |
58 | m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(), |
59 | MAKEINTRESOURCE(id), | |
60 | parent ? (HWND)parent->GetHWND() : 0, | |
61 | (DLGPROC) wxDlgProc); | |
2bda0e17 | 62 | |
cc2b7472 VZ |
63 | if ( !m_hWnd ) |
64 | return FALSE; | |
2bda0e17 | 65 | |
cc2b7472 | 66 | SubclassWin(GetHWND()); |
2bda0e17 | 67 | |
cc2b7472 VZ |
68 | if ( parent ) |
69 | parent->AddChild(this); | |
70 | else | |
71 | wxTopLevelWindows.Append(this); | |
2bda0e17 | 72 | |
cc2b7472 | 73 | // Enumerate all children |
2bda0e17 KB |
74 | HWND hWndNext; |
75 | hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD); | |
76 | ||
cc2b7472 VZ |
77 | wxWindow* child = NULL; |
78 | if (hWndNext) | |
79 | child = CreateWindowFromHWND(this, (WXHWND) hWndNext); | |
2bda0e17 | 80 | |
57c208c5 | 81 | while (hWndNext != (HWND) NULL) |
2bda0e17 | 82 | { |
cc2b7472 VZ |
83 | hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT); |
84 | if (hWndNext) | |
85 | child = CreateWindowFromHWND(this, (WXHWND) hWndNext); | |
2bda0e17 KB |
86 | } |
87 | ||
cc2b7472 | 88 | return TRUE; |
2bda0e17 KB |
89 | } |
90 | ||
91 | bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name) | |
92 | { | |
cc2b7472 | 93 | SetName(name); |
2bda0e17 | 94 | |
b225f659 | 95 | wxWindowCreationHook hook(this); |
cc2b7472 VZ |
96 | m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(), |
97 | name.c_str(), | |
98 | parent ? (HWND)parent->GetHWND() : 0, | |
99 | (DLGPROC)wxDlgProc); | |
2bda0e17 | 100 | |
cc2b7472 VZ |
101 | if ( !m_hWnd ) |
102 | return FALSE; | |
2bda0e17 | 103 | |
cc2b7472 | 104 | SubclassWin(GetHWND()); |
2bda0e17 | 105 | |
cc2b7472 VZ |
106 | if ( parent ) |
107 | parent->AddChild(this); | |
108 | else | |
109 | wxTopLevelWindows.Append(this); | |
2bda0e17 | 110 | |
cc2b7472 | 111 | // FIXME why don't we enum all children here? |
2bda0e17 | 112 | |
cc2b7472 | 113 | return TRUE; |
2bda0e17 KB |
114 | } |
115 | ||
cc2b7472 VZ |
116 | // --------------------------------------------------------------------------- |
117 | // look for child by id | |
118 | // --------------------------------------------------------------------------- | |
119 | ||
120 | wxWindow* wxWindow::GetWindowChild1(wxWindowID id) | |
2bda0e17 | 121 | { |
cc2b7472 VZ |
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; | |
2bda0e17 KB |
137 | } |
138 | ||
cc2b7472 | 139 | wxWindow* wxWindow::GetWindowChild(wxWindowID id) |
2bda0e17 | 140 | { |
cc2b7472 VZ |
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; | |
2bda0e17 KB |
158 | } |
159 | ||
cc2b7472 VZ |
160 | // --------------------------------------------------------------------------- |
161 | // create wxWin window from a native HWND | |
162 | // --------------------------------------------------------------------------- | |
2bda0e17 KB |
163 | |
164 | wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd) | |
165 | { | |
cc2b7472 VZ |
166 | wxString str(wxGetWindowClass(hWnd)); |
167 | str.UpperCase(); | |
2bda0e17 | 168 | |
cc2b7472 VZ |
169 | long id = wxGetWindowId(hWnd); |
170 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
2bda0e17 | 171 | |
cc2b7472 | 172 | wxWindow* win = NULL; |
2bda0e17 | 173 | |
223d09f6 | 174 | if (str == wxT("BUTTON")) |
cc2b7472 VZ |
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 | } | |
8c18da2e | 186 | #if wxUSE_BMPBUTTON |
2432b92d | 187 | #if defined(__WIN32__) && defined(BS_BITMAP) |
cc2b7472 VZ |
188 | else if (style & BS_BITMAP) |
189 | { | |
190 | // TODO: how to find the bitmap? | |
191 | win = new wxBitmapButton; | |
223d09f6 | 192 | wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button.")); |
cc2b7472 | 193 | } |
2bda0e17 | 194 | #endif |
cc2b7472 VZ |
195 | else if (style1 == BS_OWNERDRAW) |
196 | { | |
197 | // TODO: how to find the bitmap? | |
198 | // TODO: can't distinguish between bitmap button and bitmap static. | |
199 | // Change implementation of wxStaticBitmap to SS_BITMAP. | |
200 | // PROBLEM: this assumes that we're using resource-based bitmaps. | |
201 | // So maybe need 2 implementations of bitmap buttons/static controls, | |
202 | // with a switch in the drawing code. Call default proc if BS_BITMAP. | |
203 | win = new wxBitmapButton; | |
204 | } | |
8c18da2e | 205 | #endif |
cc2b7472 VZ |
206 | else if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON)) |
207 | { | |
208 | win = new wxButton; | |
209 | } | |
210 | else if (style1 == BS_GROUPBOX) | |
211 | { | |
212 | win = new wxStaticBox; | |
213 | } | |
214 | else | |
215 | { | |
92aff599 | 216 | wxLogError(wxT("Don't know what kind of button this is: id = %ld"), |
cc2b7472 VZ |
217 | id); |
218 | } | |
219 | } | |
223d09f6 | 220 | else if (str == wxT("COMBOBOX")) |
cc2b7472 VZ |
221 | { |
222 | win = new wxComboBox; | |
223 | } | |
224 | // TODO: Problem if the user creates a multiline - but not rich text - text control, | |
225 | // since wxWin assumes RichEdit control for this. Should have m_isRichText in | |
226 | // wxTextCtrl. Also, convert as much of the window style as is necessary | |
227 | // for correct functioning. | |
228 | // Could have wxWindow::AdoptAttributesFromHWND(WXHWND) | |
229 | // to be overridden by each control class. | |
223d09f6 | 230 | else if (str == wxT("EDIT")) |
cc2b7472 VZ |
231 | { |
232 | win = new wxTextCtrl; | |
233 | } | |
223d09f6 | 234 | else if (str == wxT("LISTBOX")) |
cc2b7472 VZ |
235 | { |
236 | win = new wxListBox; | |
237 | } | |
223d09f6 | 238 | else if (str == wxT("SCROLLBAR")) |
cc2b7472 VZ |
239 | { |
240 | win = new wxScrollBar; | |
241 | } | |
b39dbf34 | 242 | #if defined(__WIN95__) && wxUSE_SPINBTN |
223d09f6 | 243 | else if (str == wxT("MSCTLS_UPDOWN32")) |
cc2b7472 VZ |
244 | { |
245 | win = new wxSpinButton; | |
246 | } | |
2bda0e17 | 247 | #endif |
1e6feb95 | 248 | #if wxUSE_SLIDER |
223d09f6 | 249 | else if (str == wxT("MSCTLS_TRACKBAR32")) |
cc2b7472 VZ |
250 | { |
251 | // Need to ascertain if it's horiz or vert | |
252 | win = new wxSlider; | |
253 | } | |
1e6feb95 | 254 | #endif // wxUSE_SLIDER |
223d09f6 | 255 | else if (str == wxT("STATIC")) |
cc2b7472 VZ |
256 | { |
257 | int style1 = (style & 0xFF); | |
258 | ||
259 | if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) || (style1 == SS_SIMPLE)) | |
260 | win = new wxStaticText; | |
8c18da2e | 261 | #if wxUSE_STATBMP |
2432b92d | 262 | #if defined(__WIN32__) && defined(BS_BITMAP) |
cc2b7472 VZ |
263 | else if (style1 == SS_BITMAP) |
264 | { | |
265 | win = new wxStaticBitmap; | |
2bda0e17 | 266 | |
cc2b7472 | 267 | // Help! this doesn't correspond with the wxWin implementation. |
223d09f6 | 268 | wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons.")); |
cc2b7472 | 269 | } |
2bda0e17 | 270 | #endif |
8c18da2e | 271 | #endif /* wxUSE_STATBMP */ |
cc2b7472 VZ |
272 | } |
273 | else | |
274 | { | |
223d09f6 | 275 | wxString msg(wxT("Don't know how to convert from Windows class ")); |
cc2b7472 VZ |
276 | msg += str; |
277 | wxLogError(msg); | |
278 | } | |
279 | ||
280 | if (win) | |
281 | { | |
282 | parent->AddChild(win); | |
283 | win->SetEventHandler(win); | |
284 | win->SetHWND(hWnd); | |
285 | win->SetId(id); | |
286 | win->SubclassWin(hWnd); | |
287 | win->AdoptAttributesFromHWND(); | |
288 | win->SetupColours(); | |
cc2b7472 | 289 | } |
3ca6a5f0 BP |
290 | |
291 | return win; | |
2bda0e17 KB |
292 | } |
293 | ||
294 | // Make sure the window style (etc.) reflects the HWND style (roughly) | |
295 | void wxWindow::AdoptAttributesFromHWND(void) | |
296 | { | |
cc2b7472 VZ |
297 | HWND hWnd = (HWND) GetHWND(); |
298 | long style = GetWindowLong((HWND) hWnd, GWL_STYLE); | |
2bda0e17 | 299 | |
cc2b7472 VZ |
300 | if (style & WS_VSCROLL) |
301 | m_windowStyle |= wxVSCROLL; | |
302 | if (style & WS_HSCROLL) | |
303 | m_windowStyle |= wxHSCROLL; | |
2bda0e17 KB |
304 | } |
305 |