]> git.saurik.com Git - wxWidgets.git/blame - src/msw/nativdlg.cpp
Hopefully fixed library names generated by wx-config for OS/2's PM port.
[wxWidgets.git] / src / msw / nativdlg.cpp
CommitLineData
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 8// Copyright: (c) Julian Smart
65571936 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
cc2b7472
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
14f355c2 20#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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
46extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message,
47 WPARAM wParam, LPARAM lParam);
48
49// ===========================================================================
50// implementation
51// ===========================================================================
2bda0e17 52
debe6624 53bool 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 63 if ( !m_hWnd )
078cf5cb 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 77 if (hWndNext)
196be0f1 78 CreateWindowFromHWND(this, (WXHWND) hWndNext);
2bda0e17 79
57c208c5 80 while (hWndNext != (HWND) NULL)
2bda0e17 81 {
cc2b7472
VZ
82 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
83 if (hWndNext)
196be0f1 84 CreateWindowFromHWND(this, (WXHWND) hWndNext);
2bda0e17
KB
85 }
86
078cf5cb 87 return true;
2bda0e17
KB
88}
89
90bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
91{
cc2b7472 92 SetName(name);
2bda0e17 93
b225f659 94 wxWindowCreationHook hook(this);
cc2b7472
VZ
95 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
96 name.c_str(),
97 parent ? (HWND)parent->GetHWND() : 0,
98 (DLGPROC)wxDlgProc);
2bda0e17 99
cc2b7472 100 if ( !m_hWnd )
078cf5cb 101 return false;
2bda0e17 102
cc2b7472 103 SubclassWin(GetHWND());
2bda0e17 104
cc2b7472
VZ
105 if ( parent )
106 parent->AddChild(this);
107 else
108 wxTopLevelWindows.Append(this);
2bda0e17 109
f032bf3d
JS
110 // Enumerate all children
111 HWND hWndNext;
112 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
113
f032bf3d 114 if (hWndNext)
196be0f1 115 CreateWindowFromHWND(this, (WXHWND) hWndNext);
f032bf3d
JS
116
117 while (hWndNext != (HWND) NULL)
118 {
119 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
120 if (hWndNext)
196be0f1 121 CreateWindowFromHWND(this, (WXHWND) hWndNext);
f032bf3d 122 }
2bda0e17 123
078cf5cb 124 return true;
2bda0e17
KB
125}
126
cc2b7472
VZ
127// ---------------------------------------------------------------------------
128// look for child by id
129// ---------------------------------------------------------------------------
130
131wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
2bda0e17 132{
cc2b7472
VZ
133 if ( m_windowId == id )
134 return this;
135
222ed1d6 136 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
cc2b7472
VZ
137 while ( node )
138 {
139 wxWindow* child = node->GetData();
140 wxWindow* win = child->GetWindowChild1(id);
141 if ( win )
142 return win;
143
144 node = node->GetNext();
145 }
146
147 return NULL;
2bda0e17
KB
148}
149
cc2b7472 150wxWindow* wxWindow::GetWindowChild(wxWindowID id)
2bda0e17 151{
cc2b7472
VZ
152 wxWindow* win = GetWindowChild1(id);
153 if ( !win )
154 {
155 HWND hWnd = ::GetDlgItem((HWND) GetHWND(), id);
156
157 if (hWnd)
158 {
159 wxWindow* child = CreateWindowFromHWND(this, (WXHWND) hWnd);
160 if (child)
161 {
162 child->AddChild(this);
163 return child;
164 }
165 }
166 }
167
168 return NULL;
2bda0e17
KB
169}
170
cc2b7472
VZ
171// ---------------------------------------------------------------------------
172// create wxWin window from a native HWND
173// ---------------------------------------------------------------------------
2bda0e17
KB
174
175wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
176{
cc2b7472
VZ
177 wxString str(wxGetWindowClass(hWnd));
178 str.UpperCase();
2bda0e17 179
cc2b7472
VZ
180 long id = wxGetWindowId(hWnd);
181 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
2bda0e17 182
cc2b7472 183 wxWindow* win = NULL;
2bda0e17 184
223d09f6 185 if (str == wxT("BUTTON"))
cc2b7472
VZ
186 {
187 int style1 = (style & 0xFF);
461dae94 188#if wxUSE_CHECKBOX
cc2b7472
VZ
189 if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) ||
190 (style1 == BS_CHECKBOX))
191 {
192 win = new wxCheckBox;
193 }
461dae94
VZ
194 else
195#endif
196#if wxUSE_RADIOBTN
197 if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON))
cc2b7472
VZ
198 {
199 win = new wxRadioButton;
200 }
461dae94
VZ
201 else
202#endif
8c18da2e 203#if wxUSE_BMPBUTTON
2432b92d 204#if defined(__WIN32__) && defined(BS_BITMAP)
461dae94 205 if (style & BS_BITMAP)
cc2b7472
VZ
206 {
207 // TODO: how to find the bitmap?
208 win = new wxBitmapButton;
223d09f6 209 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
cc2b7472 210 }
461dae94 211 else
2bda0e17 212#endif
461dae94 213 if (style1 == BS_OWNERDRAW)
cc2b7472
VZ
214 {
215 // TODO: how to find the bitmap?
216 // TODO: can't distinguish between bitmap button and bitmap static.
217 // Change implementation of wxStaticBitmap to SS_BITMAP.
218 // PROBLEM: this assumes that we're using resource-based bitmaps.
219 // So maybe need 2 implementations of bitmap buttons/static controls,
220 // with a switch in the drawing code. Call default proc if BS_BITMAP.
221 win = new wxBitmapButton;
222 }
461dae94 223 else
8c18da2e 224#endif
461dae94
VZ
225#if wxUSE_BUTTON
226 if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON))
cc2b7472
VZ
227 {
228 win = new wxButton;
229 }
461dae94
VZ
230 else
231#endif
232#if wxUSE_STATBOX
233 if (style1 == BS_GROUPBOX)
cc2b7472
VZ
234 {
235 win = new wxStaticBox;
236 }
237 else
461dae94 238#endif
cc2b7472 239 {
92aff599 240 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
cc2b7472
VZ
241 id);
242 }
243 }
461dae94 244#if wxUSE_COMBOBOX
223d09f6 245 else if (str == wxT("COMBOBOX"))
cc2b7472
VZ
246 {
247 win = new wxComboBox;
248 }
461dae94
VZ
249#endif
250#if wxUSE_TEXTCTRL
cc2b7472
VZ
251 // TODO: Problem if the user creates a multiline - but not rich text - text control,
252 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
253 // wxTextCtrl. Also, convert as much of the window style as is necessary
254 // for correct functioning.
255 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
256 // to be overridden by each control class.
223d09f6 257 else if (str == wxT("EDIT"))
cc2b7472
VZ
258 {
259 win = new wxTextCtrl;
260 }
461dae94
VZ
261#endif
262#if wxUSE_LISTBOX
223d09f6 263 else if (str == wxT("LISTBOX"))
cc2b7472
VZ
264 {
265 win = new wxListBox;
266 }
461dae94
VZ
267#endif
268#if wxUSE_SCROLLBAR
223d09f6 269 else if (str == wxT("SCROLLBAR"))
cc2b7472
VZ
270 {
271 win = new wxScrollBar;
272 }
461dae94 273#endif
b39dbf34 274#if defined(__WIN95__) && wxUSE_SPINBTN
223d09f6 275 else if (str == wxT("MSCTLS_UPDOWN32"))
cc2b7472
VZ
276 {
277 win = new wxSpinButton;
278 }
2bda0e17 279#endif
1e6feb95 280#if wxUSE_SLIDER
223d09f6 281 else if (str == wxT("MSCTLS_TRACKBAR32"))
cc2b7472
VZ
282 {
283 // Need to ascertain if it's horiz or vert
284 win = new wxSlider;
285 }
1e6feb95 286#endif // wxUSE_SLIDER
461dae94 287#if wxUSE_STATTEXT
223d09f6 288 else if (str == wxT("STATIC"))
cc2b7472
VZ
289 {
290 int style1 = (style & 0xFF);
291
4676948b
JS
292 if ((style1 == SS_LEFT) || (style1 == SS_RIGHT)
293#ifndef __WXWINCE__
294 || (style1 == SS_SIMPLE)
295#endif
296 )
cc2b7472 297 win = new wxStaticText;
8c18da2e 298#if wxUSE_STATBMP
2432b92d 299#if defined(__WIN32__) && defined(BS_BITMAP)
cc2b7472
VZ
300 else if (style1 == SS_BITMAP)
301 {
302 win = new wxStaticBitmap;
2bda0e17 303
cc2b7472 304 // Help! this doesn't correspond with the wxWin implementation.
223d09f6 305 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
cc2b7472 306 }
2bda0e17 307#endif
078cf5cb 308#endif /* wxUSE_STATBMP */
cc2b7472 309 }
461dae94 310#endif
cc2b7472
VZ
311 else
312 {
223d09f6 313 wxString msg(wxT("Don't know how to convert from Windows class "));
cc2b7472
VZ
314 msg += str;
315 wxLogError(msg);
316 }
317
318 if (win)
319 {
320 parent->AddChild(win);
321 win->SetEventHandler(win);
322 win->SetHWND(hWnd);
323 win->SetId(id);
324 win->SubclassWin(hWnd);
325 win->AdoptAttributesFromHWND();
326 win->SetupColours();
cc2b7472 327 }
3ca6a5f0
BP
328
329 return win;
2bda0e17
KB
330}
331
332// Make sure the window style (etc.) reflects the HWND style (roughly)
333void wxWindow::AdoptAttributesFromHWND(void)
334{
cc2b7472
VZ
335 HWND hWnd = (HWND) GetHWND();
336 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
2bda0e17 337
cc2b7472
VZ
338 if (style & WS_VSCROLL)
339 m_windowStyle |= wxVSCROLL;
340 if (style & WS_HSCROLL)
341 m_windowStyle |= wxHSCROLL;
2bda0e17
KB
342}
343