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
);
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 // Enumerate all children
113 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
115 wxWindow
* child
= NULL
;
117 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
119 while (hWndNext
!= (HWND
) NULL
)
121 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
123 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
129 // ---------------------------------------------------------------------------
130 // look for child by id
131 // ---------------------------------------------------------------------------
133 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
135 if ( m_windowId
== id
)
138 wxWindowList::compatibility_iterator node
= GetChildren().GetFirst();
141 wxWindow
* child
= node
->GetData();
142 wxWindow
* win
= child
->GetWindowChild1(id
);
146 node
= node
->GetNext();
152 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
154 wxWindow
* win
= GetWindowChild1(id
);
157 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
161 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
164 child
->AddChild(this);
173 // ---------------------------------------------------------------------------
174 // create wxWin window from a native HWND
175 // ---------------------------------------------------------------------------
177 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
179 wxString
str(wxGetWindowClass(hWnd
));
182 long id
= wxGetWindowId(hWnd
);
183 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
185 wxWindow
* win
= NULL
;
187 if (str
== wxT("BUTTON"))
189 int style1
= (style
& 0xFF);
190 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
191 (style1
== BS_CHECKBOX
))
193 win
= new wxCheckBox
;
195 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
197 win
= new wxRadioButton
;
200 #if defined(__WIN32__) && defined(BS_BITMAP)
201 else 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."));
208 else if (style1
== BS_OWNERDRAW
)
210 // TODO: how to find the bitmap?
211 // TODO: can't distinguish between bitmap button and bitmap static.
212 // Change implementation of wxStaticBitmap to SS_BITMAP.
213 // PROBLEM: this assumes that we're using resource-based bitmaps.
214 // So maybe need 2 implementations of bitmap buttons/static controls,
215 // with a switch in the drawing code. Call default proc if BS_BITMAP.
216 win
= new wxBitmapButton
;
219 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
223 else if (style1
== BS_GROUPBOX
)
225 win
= new wxStaticBox
;
229 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
233 else if (str
== wxT("COMBOBOX"))
235 win
= new wxComboBox
;
237 // TODO: Problem if the user creates a multiline - but not rich text - text control,
238 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
239 // wxTextCtrl. Also, convert as much of the window style as is necessary
240 // for correct functioning.
241 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
242 // to be overridden by each control class.
243 else if (str
== wxT("EDIT"))
245 win
= new wxTextCtrl
;
247 else if (str
== wxT("LISTBOX"))
251 else if (str
== wxT("SCROLLBAR"))
253 win
= new wxScrollBar
;
255 #if defined(__WIN95__) && wxUSE_SPINBTN
256 else if (str
== wxT("MSCTLS_UPDOWN32"))
258 win
= new wxSpinButton
;
262 else if (str
== wxT("MSCTLS_TRACKBAR32"))
264 // Need to ascertain if it's horiz or vert
267 #endif // wxUSE_SLIDER
268 else if (str
== wxT("STATIC"))
270 int style1
= (style
& 0xFF);
272 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
)
274 || (style1
== SS_SIMPLE
)
277 win
= new wxStaticText
;
279 #if defined(__WIN32__) && defined(BS_BITMAP)
280 else if (style1
== SS_BITMAP
)
282 win
= new wxStaticBitmap
;
284 // Help! this doesn't correspond with the wxWin implementation.
285 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
288 #endif /* wxUSE_STATBMP */
292 wxString
msg(wxT("Don't know how to convert from Windows class "));
299 parent
->AddChild(win
);
300 win
->SetEventHandler(win
);
303 win
->SubclassWin(hWnd
);
304 win
->AdoptAttributesFromHWND();
311 // Make sure the window style (etc.) reflects the HWND style (roughly)
312 void wxWindow::AdoptAttributesFromHWND(void)
314 HWND hWnd
= (HWND
) GetHWND();
315 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
317 if (style
& WS_VSCROLL
)
318 m_windowStyle
|= wxVSCROLL
;
319 if (style
& WS_HSCROLL
)
320 m_windowStyle
|= wxHSCROLL
;