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);
188 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
189 (style1
== BS_CHECKBOX
))
191 win
= new wxCheckBox
;
193 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
195 win
= new wxRadioButton
;
198 #if defined(__WIN32__) && defined(BS_BITMAP)
199 else 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."));
206 else if (style1
== BS_OWNERDRAW
)
208 // TODO: how to find the bitmap?
209 // TODO: can't distinguish between bitmap button and bitmap static.
210 // Change implementation of wxStaticBitmap to SS_BITMAP.
211 // PROBLEM: this assumes that we're using resource-based bitmaps.
212 // So maybe need 2 implementations of bitmap buttons/static controls,
213 // with a switch in the drawing code. Call default proc if BS_BITMAP.
214 win
= new wxBitmapButton
;
217 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
221 else if (style1
== BS_GROUPBOX
)
223 win
= new wxStaticBox
;
227 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
231 else if (str
== wxT("COMBOBOX"))
233 win
= new wxComboBox
;
235 // TODO: Problem if the user creates a multiline - but not rich text - text control,
236 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
237 // wxTextCtrl. Also, convert as much of the window style as is necessary
238 // for correct functioning.
239 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
240 // to be overridden by each control class.
241 else if (str
== wxT("EDIT"))
243 win
= new wxTextCtrl
;
245 else if (str
== wxT("LISTBOX"))
249 else if (str
== wxT("SCROLLBAR"))
251 win
= new wxScrollBar
;
253 #if defined(__WIN95__) && wxUSE_SPINBTN
254 else if (str
== wxT("MSCTLS_UPDOWN32"))
256 win
= new wxSpinButton
;
260 else if (str
== wxT("MSCTLS_TRACKBAR32"))
262 // Need to ascertain if it's horiz or vert
265 #endif // wxUSE_SLIDER
266 else if (str
== wxT("STATIC"))
268 int style1
= (style
& 0xFF);
270 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
272 || (style1
== SS_SIMPLE
)
275 win
= new wxStaticText
;
277 #if defined(__WIN32__) && defined(BS_BITMAP)
278 else if (style1
== SS_BITMAP
)
280 win
= new wxStaticBitmap
;
282 // Help! this doesn't correspond with the wxWin implementation.
283 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
286 #endif /* wxUSE_STATBMP */
290 wxString
msg(wxT("Don't know how to convert from Windows class "));
297 parent
->AddChild(win
);
298 win
->SetEventHandler(win
);
301 win
->SubclassWin(hWnd
);
302 win
->AdoptAttributesFromHWND();
309 // Make sure the window style (etc.) reflects the HWND style (roughly)
310 void wxWindow::AdoptAttributesFromHWND(void)
312 HWND hWnd
= (HWND
) GetHWND();
313 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
315 if (style
& WS_VSCROLL
)
316 m_windowStyle
|= wxVSCROLL
;
317 if (style
& WS_HSCROLL
)
318 m_windowStyle
|= wxHSCROLL
;