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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #if defined(__WIN95__)
38 #include "wx/spinbutt.h"
40 #include "wx/msw/private.h"
42 // ---------------------------------------------------------------------------
44 // ---------------------------------------------------------------------------
46 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
47 WPARAM wParam
, LPARAM lParam
);
49 // ===========================================================================
51 // ===========================================================================
53 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
57 wxWindowCreationHook
hook(this);
58 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
60 parent
? (HWND
)parent
->GetHWND() : 0,
66 SubclassWin(GetHWND());
69 parent
->AddChild(this);
71 wxTopLevelWindows
.Append(this);
73 // Enumerate all children
75 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
78 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
80 while (hWndNext
!= (HWND
) NULL
)
82 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
84 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
90 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
94 wxWindowCreationHook
hook(this);
95 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
97 parent
? (HWND
)parent
->GetHWND() : 0,
103 SubclassWin(GetHWND());
106 parent
->AddChild(this);
108 wxTopLevelWindows
.Append(this);
110 // Enumerate all children
112 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
115 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
117 while (hWndNext
!= (HWND
) NULL
)
119 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
121 CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
127 // ---------------------------------------------------------------------------
128 // look for child by id
129 // ---------------------------------------------------------------------------
131 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
133 if ( m_windowId
== id
)
136 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
139 wxWindow
* child
= node
->GetData();
140 wxWindow
* win
= child
->GetWindowChild1(id
);
144 node
= node
->GetNext();
150 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
152 wxWindow
* win
= GetWindowChild1(id
);
155 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
159 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
162 child
->AddChild(this);
171 // ---------------------------------------------------------------------------
172 // create wxWin window from a native HWND
173 // ---------------------------------------------------------------------------
175 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
177 wxString
str(wxGetWindowClass(hWnd
));
180 long id
= wxGetWindowId(hWnd
);
181 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
183 wxWindow
* win
= NULL
;
185 if (str
== wxT("BUTTON"))
187 int style1
= (style
& 0xFF);
189 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
190 (style1
== BS_CHECKBOX
))
192 win
= new wxCheckBox
;
197 if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
199 win
= new wxRadioButton
;
204 #if defined(__WIN32__) && defined(BS_BITMAP)
205 if (style
& BS_BITMAP
)
207 // TODO: how to find the bitmap?
208 win
= new wxBitmapButton
;
209 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
213 if (style1
== BS_OWNERDRAW
)
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
;
226 if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
233 if (style1
== BS_GROUPBOX
)
235 win
= new wxStaticBox
;
240 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
245 else if (str
== wxT("COMBOBOX"))
247 win
= new wxComboBox
;
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.
257 else if (str
== wxT("EDIT"))
259 win
= new wxTextCtrl
;
263 else if (str
== wxT("LISTBOX"))
269 else if (str
== wxT("SCROLLBAR"))
271 win
= new wxScrollBar
;
274 #if defined(__WIN95__) && wxUSE_SPINBTN
275 else if (str
== wxT("MSCTLS_UPDOWN32"))
277 win
= new wxSpinButton
;
281 else if (str
== wxT("MSCTLS_TRACKBAR32"))
283 // Need to ascertain if it's horiz or vert
286 #endif // wxUSE_SLIDER
288 else if (str
== wxT("STATIC"))
290 int style1
= (style
& 0xFF);
292 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
294 || (style1
== SS_SIMPLE
)
297 win
= new wxStaticText
;
299 #if defined(__WIN32__) && defined(BS_BITMAP)
300 else if (style1
== SS_BITMAP
)
302 win
= new wxStaticBitmap
;
304 // Help! this doesn't correspond with the wxWin implementation.
305 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
308 #endif /* wxUSE_STATBMP */
313 wxString
msg(wxT("Don't know how to convert from Windows class "));
320 parent
->AddChild(win
);
321 win
->SetEventHandler(win
);
324 win
->SubclassWin(hWnd
);
325 win
->AdoptAttributesFromHWND();
332 // Make sure the window style (etc.) reflects the HWND style (roughly)
333 void wxWindow::AdoptAttributesFromHWND(void)
335 HWND hWnd
= (HWND
) GetHWND();
336 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
338 if (style
& WS_VSCROLL
)
339 m_windowStyle
|= wxVSCROLL
;
340 if (style
& WS_HSCROLL
)
341 m_windowStyle
|= wxHSCROLL
;