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(GetHwnd(), id
);
152 win
= CreateWindowFromHWND(this, (WXHWND
) hwnd
);
159 // ---------------------------------------------------------------------------
160 // create wxWin window from a native HWND
161 // ---------------------------------------------------------------------------
163 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
165 wxString
str(wxGetWindowClass(hWnd
));
168 long id
= wxGetWindowId(hWnd
);
169 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
171 wxWindow
* win
= NULL
;
173 if (str
== wxT("BUTTON"))
175 int style1
= (style
& 0xFF);
177 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
178 (style1
== BS_CHECKBOX
))
180 win
= new wxCheckBox
;
185 if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
187 win
= new wxRadioButton
;
192 #if defined(__WIN32__) && defined(BS_BITMAP)
193 if (style
& BS_BITMAP
)
195 // TODO: how to find the bitmap?
196 win
= new wxBitmapButton
;
197 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
201 if (style1
== BS_OWNERDRAW
)
203 // TODO: how to find the bitmap?
204 // TODO: can't distinguish between bitmap button and bitmap static.
205 // Change implementation of wxStaticBitmap to SS_BITMAP.
206 // PROBLEM: this assumes that we're using resource-based bitmaps.
207 // So maybe need 2 implementations of bitmap buttons/static controls,
208 // with a switch in the drawing code. Call default proc if BS_BITMAP.
209 win
= new wxBitmapButton
;
214 if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
221 if (style1
== BS_GROUPBOX
)
223 win
= new wxStaticBox
;
228 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
233 else if (str
== wxT("COMBOBOX"))
235 win
= new wxComboBox
;
239 // TODO: Problem if the user creates a multiline - but not rich text - text control,
240 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
241 // wxTextCtrl. Also, convert as much of the window style as is necessary
242 // for correct functioning.
243 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
244 // to be overridden by each control class.
245 else if (str
== wxT("EDIT"))
247 win
= new wxTextCtrl
;
251 else if (str
== wxT("LISTBOX"))
257 else if (str
== wxT("SCROLLBAR"))
259 win
= new wxScrollBar
;
263 else if (str
== wxT("MSCTLS_UPDOWN32"))
265 win
= new wxSpinButton
;
269 else if (str
== wxT("MSCTLS_TRACKBAR32"))
271 // Need to ascertain if it's horiz or vert
274 #endif // wxUSE_SLIDER
276 else if (str
== wxT("STATIC"))
278 int style1
= (style
& 0xFF);
280 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
282 || (style1
== SS_SIMPLE
)
285 win
= new wxStaticText
;
287 #if defined(__WIN32__) && defined(BS_BITMAP)
288 else if (style1
== SS_BITMAP
)
290 win
= new wxStaticBitmap
;
292 // Help! this doesn't correspond with the wxWin implementation.
293 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
296 #endif /* wxUSE_STATBMP */
301 wxString
msg(wxT("Don't know how to convert from Windows class "));
308 parent
->AddChild(win
);
309 win
->SetEventHandler(win
);
312 win
->SubclassWin(hWnd
);
313 win
->AdoptAttributesFromHWND();
320 // Make sure the window style (etc.) reflects the HWND style (roughly)
321 void wxWindow::AdoptAttributesFromHWND(void)
323 HWND hWnd
= (HWND
) GetHWND();
324 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
326 if (style
& WS_VSCROLL
)
327 m_windowStyle
|= wxVSCROLL
;
328 if (style
& WS_HSCROLL
)
329 m_windowStyle
|= wxHSCROLL
;