1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/msw/nativdlg.cpp
3 // Purpose: Native dialog loading code (part of wxWindow)
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
20 // For compilers that support precompilation, includes "wx.h".
21 #include "wx/wxprec.h"
33 #include "wx/spinbutt.h"
34 #include "wx/msw/private.h"
36 // ---------------------------------------------------------------------------
38 // ---------------------------------------------------------------------------
40 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
41 WPARAM wParam
, LPARAM lParam
);
43 // ===========================================================================
45 // ===========================================================================
47 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
51 wxWindowCreationHook
hook(this);
52 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
54 parent
? (HWND
)parent
->GetHWND() : 0,
60 SubclassWin(GetHWND());
63 parent
->AddChild(this);
65 wxTopLevelWindows
.Append(this);
67 // Enumerate all children
69 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
72 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
74 while (hWndNext
!= (HWND
) NULL
)
76 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
78 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
84 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
88 wxWindowCreationHook
hook(this);
89 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
91 parent
? (HWND
)parent
->GetHWND() : 0,
97 SubclassWin(GetHWND());
100 parent
->AddChild(this);
102 wxTopLevelWindows
.Append(this);
104 // Enumerate all children
106 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
109 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
111 while (hWndNext
!= (HWND
) NULL
)
113 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
115 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
121 // ---------------------------------------------------------------------------
122 // look for child by id
123 // ---------------------------------------------------------------------------
125 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
127 if ( m_windowId
== id
)
130 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
133 wxWindow
* child
= node
->GetData();
134 wxWindow
* win
= child
->GetWindowChild1(id
);
138 node
= node
->GetNext();
144 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
146 wxWindow
* win
= GetWindowChild1(id
);
149 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
153 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
156 child
->AddChild(this);
165 // ---------------------------------------------------------------------------
166 // create wxWin window from a native HWND
167 // ---------------------------------------------------------------------------
169 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
171 wxString
str(wxGetWindowClass(hWnd
));
174 long id
= wxGetWindowId(hWnd
);
175 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
177 wxWindow
* win
= NULL
;
179 if (str
== wxT("BUTTON"))
181 int style1
= (style
& 0xFF);
183 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
184 (style1
== BS_CHECKBOX
))
186 win
= new wxCheckBox
;
191 if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
193 win
= new wxRadioButton
;
198 #if defined(__WIN32__) && defined(BS_BITMAP)
199 if (style
& BS_BITMAP
)
201 // TODO: how to find the bitmap?
202 win
= new wxBitmapButton
;
203 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
207 if (style1
== BS_OWNERDRAW
)
209 // TODO: how to find the bitmap?
210 // TODO: can't distinguish between bitmap button and bitmap static.
211 // Change implementation of wxStaticBitmap to SS_BITMAP.
212 // PROBLEM: this assumes that we're using resource-based bitmaps.
213 // So maybe need 2 implementations of bitmap buttons/static controls,
214 // with a switch in the drawing code. Call default proc if BS_BITMAP.
215 win
= new wxBitmapButton
;
220 if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
227 if (style1
== BS_GROUPBOX
)
229 win
= new wxStaticBox
;
234 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
239 else if (str
== wxT("COMBOBOX"))
241 win
= new wxComboBox
;
245 // TODO: Problem if the user creates a multiline - but not rich text - text control,
246 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
247 // wxTextCtrl. Also, convert as much of the window style as is necessary
248 // for correct functioning.
249 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
250 // to be overridden by each control class.
251 else if (str
== wxT("EDIT"))
253 win
= new wxTextCtrl
;
257 else if (str
== wxT("LISTBOX"))
263 else if (str
== wxT("SCROLLBAR"))
265 win
= new wxScrollBar
;
269 else if (str
== wxT("MSCTLS_UPDOWN32"))
271 win
= new wxSpinButton
;
275 else if (str
== wxT("MSCTLS_TRACKBAR32"))
277 // Need to ascertain if it's horiz or vert
280 #endif // wxUSE_SLIDER
282 else if (str
== wxT("STATIC"))
284 int style1
= (style
& 0xFF);
286 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
288 || (style1
== SS_SIMPLE
)
291 win
= new wxStaticText
;
293 #if defined(__WIN32__) && defined(BS_BITMAP)
294 else if (style1
== SS_BITMAP
)
296 win
= new wxStaticBitmap
;
298 // Help! this doesn't correspond with the wxWin implementation.
299 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
302 #endif /* wxUSE_STATBMP */
307 wxString
msg(wxT("Don't know how to convert from Windows class "));
314 parent
->AddChild(win
);
315 win
->SetEventHandler(win
);
318 win
->SubclassWin(hWnd
);
319 win
->AdoptAttributesFromHWND();
326 // Make sure the window style (etc.) reflects the HWND style (roughly)
327 void wxWindow::AdoptAttributesFromHWND(void)
329 HWND hWnd
= (HWND
) GetHWND();
330 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
332 if (style
& WS_VSCROLL
)
333 m_windowStyle
|= wxVSCROLL
;
334 if (style
& WS_HSCROLL
)
335 m_windowStyle
|= wxHSCROLL
;