1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/nativdlg.cpp
3 // Purpose: Native dialog loading code (part of wxWindow)
4 // Author: Julian Smart
7 // Copyright: (c) Julian Smart
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // ===========================================================================
13 // ===========================================================================
15 // ---------------------------------------------------------------------------
17 // ---------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx.h".
20 #include "wx/wxprec.h"
32 #include "wx/spinbutt.h"
33 #include "wx/msw/private.h"
35 // ---------------------------------------------------------------------------
37 // ---------------------------------------------------------------------------
39 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
40 WPARAM wParam
, LPARAM lParam
);
42 // ===========================================================================
44 // ===========================================================================
46 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
50 wxWindowCreationHook
hook(this);
51 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
53 parent
? (HWND
)parent
->GetHWND() : 0,
59 SubclassWin(GetHWND());
62 parent
->AddChild(this);
64 wxTopLevelWindows
.Append(this);
66 // Enumerate all children
68 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
71 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
73 while (hWndNext
!= (HWND
) NULL
)
75 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
77 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
83 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
87 wxWindowCreationHook
hook(this);
88 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
90 parent
? (HWND
)parent
->GetHWND() : 0,
96 SubclassWin(GetHWND());
99 parent
->AddChild(this);
101 wxTopLevelWindows
.Append(this);
103 // Enumerate all children
105 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
108 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
110 while (hWndNext
!= (HWND
) NULL
)
112 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
114 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
120 // ---------------------------------------------------------------------------
121 // look for child by id
122 // ---------------------------------------------------------------------------
124 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
126 if ( m_windowId
== id
)
129 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
132 wxWindow
* child
= node
->GetData();
133 wxWindow
* win
= child
->GetWindowChild1(id
);
137 node
= node
->GetNext();
143 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
145 wxWindow
* win
= GetWindowChild1(id
);
148 HWND hwnd
= ::GetDlgItem(GetHwnd(), id
);
151 win
= CreateWindowFromHWND(this, (WXHWND
) hwnd
);
158 // ---------------------------------------------------------------------------
159 // create wxWin window from a native HWND
160 // ---------------------------------------------------------------------------
162 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
164 wxCHECK_MSG( parent
, NULL
, wxT("must have valid parent for a control") );
166 wxString
str(wxGetWindowClass(hWnd
));
169 long id
= wxGetWindowId(hWnd
);
170 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
172 wxWindow
* win
= NULL
;
174 if (str
== wxT("BUTTON"))
176 int style1
= (style
& 0xFF);
178 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
179 (style1
== BS_CHECKBOX
))
181 win
= new wxCheckBox
;
186 if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
188 win
= new wxRadioButton
;
193 #if defined(__WIN32__) && defined(BS_BITMAP)
194 if (style
& BS_BITMAP
)
196 // TODO: how to find the bitmap?
197 win
= new wxBitmapButton
;
198 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
202 if (style1
== BS_OWNERDRAW
)
204 // TODO: how to find the bitmap?
205 // TODO: can't distinguish between bitmap button and bitmap static.
206 // Change implementation of wxStaticBitmap to SS_BITMAP.
207 // PROBLEM: this assumes that we're using resource-based bitmaps.
208 // So maybe need 2 implementations of bitmap buttons/static controls,
209 // with a switch in the drawing code. Call default proc if BS_BITMAP.
210 win
= new wxBitmapButton
;
215 if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
222 if (style1
== BS_GROUPBOX
)
224 win
= new wxStaticBox
;
229 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
234 else if (str
== wxT("COMBOBOX"))
236 win
= new wxComboBox
;
240 // TODO: Problem if the user creates a multiline - but not rich text - text control,
241 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
242 // wxTextCtrl. Also, convert as much of the window style as is necessary
243 // for correct functioning.
244 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
245 // to be overridden by each control class.
246 else if (str
== wxT("EDIT"))
248 win
= new wxTextCtrl
;
252 else if (str
== wxT("LISTBOX"))
258 else if (str
== wxT("SCROLLBAR"))
260 win
= new wxScrollBar
;
264 else if (str
== wxT("MSCTLS_UPDOWN32"))
266 win
= new wxSpinButton
;
270 else if (str
== wxT("MSCTLS_TRACKBAR32"))
272 // Need to ascertain if it's horiz or vert
275 #endif // wxUSE_SLIDER
277 else if (str
== wxT("STATIC"))
279 int style1
= (style
& 0xFF);
281 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
283 || (style1
== SS_SIMPLE
)
286 win
= new wxStaticText
;
288 #if defined(__WIN32__) && defined(BS_BITMAP)
289 else if (style1
== SS_BITMAP
)
291 win
= new wxStaticBitmap
;
293 // Help! this doesn't correspond with the wxWin implementation.
294 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
297 #endif /* wxUSE_STATBMP */
302 wxString
msg(wxT("Don't know how to convert from Windows class "));
309 parent
->AddChild(win
);
310 win
->SubclassWin(hWnd
);
311 win
->AdoptAttributesFromHWND();
318 // Make sure the window style (etc.) reflects the HWND style (roughly)
319 void wxWindow::AdoptAttributesFromHWND()
321 SetId(wxGetWindowId(m_hWnd
));
323 long style
= GetWindowLong(GetHwnd(), GWL_STYLE
);
325 if (style
& WS_VSCROLL
)
326 m_windowStyle
|= wxVSCROLL
;
327 if (style
& WS_HSCROLL
)
328 m_windowStyle
|= wxHSCROLL
;