1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Native dialog loading code (part of wxWindow)
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // ===========================================================================
14 // ===========================================================================
16 // ---------------------------------------------------------------------------
18 // ---------------------------------------------------------------------------
21 #pragma implementation
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
37 #if defined(__WIN95__) && !defined(__TWIN32__)
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
);
77 wxWindow
* child
= NULL
;
79 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
81 while (hWndNext
!= (HWND
) NULL
)
83 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
85 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
91 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
95 wxWindowCreationHook
hook(this);
96 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
98 parent
? (HWND
)parent
->GetHWND() : 0,
104 SubclassWin(GetHWND());
107 parent
->AddChild(this);
109 wxTopLevelWindows
.Append(this);
111 // FIXME why don't we enum all children here?
116 // ---------------------------------------------------------------------------
117 // look for child by id
118 // ---------------------------------------------------------------------------
120 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
122 if ( m_windowId
== id
)
125 wxWindowList::Node
*node
= GetChildren().GetFirst();
128 wxWindow
* child
= node
->GetData();
129 wxWindow
* win
= child
->GetWindowChild1(id
);
133 node
= node
->GetNext();
139 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
141 wxWindow
* win
= GetWindowChild1(id
);
144 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
148 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
151 child
->AddChild(this);
160 // ---------------------------------------------------------------------------
161 // create wxWin window from a native HWND
162 // ---------------------------------------------------------------------------
164 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
166 wxString
str(wxGetWindowClass(hWnd
));
169 long id
= wxGetWindowId(hWnd
);
170 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
172 wxWindow
* win
= NULL
;
174 if (str
== wxT("BUTTON"))
176 int style1
= (style
& 0xFF);
177 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
178 (style1
== BS_CHECKBOX
))
180 win
= new wxCheckBox
;
182 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
184 win
= new wxRadioButton
;
186 #if defined(__WIN32__) && defined(BS_BITMAP)
187 else if (style
& BS_BITMAP
)
189 // TODO: how to find the bitmap?
190 win
= new wxBitmapButton
;
191 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
194 else if (style1
== BS_OWNERDRAW
)
196 // TODO: how to find the bitmap?
197 // TODO: can't distinguish between bitmap button and bitmap static.
198 // Change implementation of wxStaticBitmap to SS_BITMAP.
199 // PROBLEM: this assumes that we're using resource-based bitmaps.
200 // So maybe need 2 implementations of bitmap buttons/static controls,
201 // with a switch in the drawing code. Call default proc if BS_BITMAP.
202 win
= new wxBitmapButton
;
204 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
208 else if (style1
== BS_GROUPBOX
)
210 win
= new wxStaticBox
;
214 wxLogError(wxT("Don't know what kind of button this is: id = %d"),
218 else if (str
== wxT("COMBOBOX"))
220 win
= new wxComboBox
;
222 // TODO: Problem if the user creates a multiline - but not rich text - text control,
223 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
224 // wxTextCtrl. Also, convert as much of the window style as is necessary
225 // for correct functioning.
226 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
227 // to be overridden by each control class.
228 else if (str
== wxT("EDIT"))
230 win
= new wxTextCtrl
;
232 else if (str
== wxT("LISTBOX"))
236 else if (str
== wxT("SCROLLBAR"))
238 win
= new wxScrollBar
;
240 #if defined(__WIN95__) && !defined(__TWIN32__) && wxUSE_SPINBTN
241 else if (str
== wxT("MSCTLS_UPDOWN32"))
243 win
= new wxSpinButton
;
247 else if (str
== wxT("MSCTLS_TRACKBAR32"))
249 // Need to ascertain if it's horiz or vert
252 #endif // wxUSE_SLIDER
253 else if (str
== wxT("STATIC"))
255 int style1
= (style
& 0xFF);
257 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
) || (style1
== SS_SIMPLE
))
258 win
= new wxStaticText
;
259 #if defined(__WIN32__) && defined(BS_BITMAP)
260 else if (style1
== SS_BITMAP
)
262 win
= new wxStaticBitmap
;
264 // Help! this doesn't correspond with the wxWin implementation.
265 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
271 wxString
msg(wxT("Don't know how to convert from Windows class "));
278 parent
->AddChild(win
);
279 win
->SetEventHandler(win
);
282 win
->SubclassWin(hWnd
);
283 win
->AdoptAttributesFromHWND();
290 // Make sure the window style (etc.) reflects the HWND style (roughly)
291 void wxWindow::AdoptAttributesFromHWND(void)
293 HWND hWnd
= (HWND
) GetHWND();
294 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
296 if (style
& WS_VSCROLL
)
297 m_windowStyle
|= wxVSCROLL
;
298 if (style
& WS_HSCROLL
)
299 m_windowStyle
|= wxHSCROLL
;