1 /////////////////////////////////////////////////////////////////////////////
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 #if defined(__WIN95__)
34 #include "wx/spinbutt.h"
36 #include "wx/msw/private.h"
38 // ---------------------------------------------------------------------------
40 // ---------------------------------------------------------------------------
42 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
43 WPARAM wParam
, LPARAM lParam
);
45 // ===========================================================================
47 // ===========================================================================
49 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
53 wxWindowCreationHook
hook(this);
54 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
56 parent
? (HWND
)parent
->GetHWND() : 0,
62 SubclassWin(GetHWND());
65 parent
->AddChild(this);
67 wxTopLevelWindows
.Append(this);
69 // Enumerate all children
71 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
74 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
76 while (hWndNext
!= (HWND
) NULL
)
78 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
80 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
86 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
90 wxWindowCreationHook
hook(this);
91 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
93 parent
? (HWND
)parent
->GetHWND() : 0,
99 SubclassWin(GetHWND());
102 parent
->AddChild(this);
104 wxTopLevelWindows
.Append(this);
106 // Enumerate all children
108 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
111 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
113 while (hWndNext
!= (HWND
) NULL
)
115 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
117 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
123 // ---------------------------------------------------------------------------
124 // look for child by id
125 // ---------------------------------------------------------------------------
127 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
129 if ( m_windowId
== id
)
132 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
135 wxWindow
* child
= node
->GetData();
136 wxWindow
* win
= child
->GetWindowChild1(id
);
140 node
= node
->GetNext();
146 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
148 wxWindow
* win
= GetWindowChild1(id
);
151 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
155 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
158 child
->AddChild(this);
167 // ---------------------------------------------------------------------------
168 // create wxWin window from a native HWND
169 // ---------------------------------------------------------------------------
171 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
173 wxString
str(wxGetWindowClass(hWnd
));
176 long id
= wxGetWindowId(hWnd
);
177 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
179 wxWindow
* win
= NULL
;
181 if (str
== wxT("BUTTON"))
183 int style1
= (style
& 0xFF);
185 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
186 (style1
== BS_CHECKBOX
))
188 win
= new wxCheckBox
;
193 if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
195 win
= new wxRadioButton
;
200 #if defined(__WIN32__) && defined(BS_BITMAP)
201 if (style
& BS_BITMAP
)
203 // TODO: how to find the bitmap?
204 win
= new wxBitmapButton
;
205 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
209 if (style1
== BS_OWNERDRAW
)
211 // TODO: how to find the bitmap?
212 // TODO: can't distinguish between bitmap button and bitmap static.
213 // Change implementation of wxStaticBitmap to SS_BITMAP.
214 // PROBLEM: this assumes that we're using resource-based bitmaps.
215 // So maybe need 2 implementations of bitmap buttons/static controls,
216 // with a switch in the drawing code. Call default proc if BS_BITMAP.
217 win
= new wxBitmapButton
;
222 if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
229 if (style1
== BS_GROUPBOX
)
231 win
= new wxStaticBox
;
236 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
241 else if (str
== wxT("COMBOBOX"))
243 win
= new wxComboBox
;
247 // TODO: Problem if the user creates a multiline - but not rich text - text control,
248 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
249 // wxTextCtrl. Also, convert as much of the window style as is necessary
250 // for correct functioning.
251 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
252 // to be overridden by each control class.
253 else if (str
== wxT("EDIT"))
255 win
= new wxTextCtrl
;
259 else if (str
== wxT("LISTBOX"))
265 else if (str
== wxT("SCROLLBAR"))
267 win
= new wxScrollBar
;
270 #if defined(__WIN95__) && wxUSE_SPINBTN
271 else if (str
== wxT("MSCTLS_UPDOWN32"))
273 win
= new wxSpinButton
;
277 else if (str
== wxT("MSCTLS_TRACKBAR32"))
279 // Need to ascertain if it's horiz or vert
282 #endif // wxUSE_SLIDER
284 else if (str
== wxT("STATIC"))
286 int style1
= (style
& 0xFF);
288 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
290 || (style1
== SS_SIMPLE
)
293 win
= new wxStaticText
;
295 #if defined(__WIN32__) && defined(BS_BITMAP)
296 else if (style1
== SS_BITMAP
)
298 win
= new wxStaticBitmap
;
300 // Help! this doesn't correspond with the wxWin implementation.
301 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
304 #endif /* wxUSE_STATBMP */
309 wxString
msg(wxT("Don't know how to convert from Windows class "));
316 parent
->AddChild(win
);
317 win
->SetEventHandler(win
);
320 win
->SubclassWin(hWnd
);
321 win
->AdoptAttributesFromHWND();
328 // Make sure the window style (etc.) reflects the HWND style (roughly)
329 void wxWindow::AdoptAttributesFromHWND(void)
331 HWND hWnd
= (HWND
) GetHWND();
332 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
334 if (style
& WS_VSCROLL
)
335 m_windowStyle
|= wxVSCROLL
;
336 if (style
& WS_HSCROLL
)
337 m_windowStyle
|= wxHSCROLL
;