]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/nativdlg.cpp
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 // ---------------------------------------------------------------------------
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::Node
*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
) || (style1
== SS_SIMPLE
))
273 win
= new wxStaticText
;
275 #if defined(__WIN32__) && defined(BS_BITMAP)
276 else if (style1
== SS_BITMAP
)
278 win
= new wxStaticBitmap
;
280 // Help! this doesn't correspond with the wxWin implementation.
281 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
284 #endif /* wxUSE_STATBMP */
288 wxString
msg(wxT("Don't know how to convert from Windows class "));
295 parent
->AddChild(win
);
296 win
->SetEventHandler(win
);
299 win
->SubclassWin(hWnd
);
300 win
->AdoptAttributesFromHWND();
307 // Make sure the window style (etc.) reflects the HWND style (roughly)
308 void wxWindow::AdoptAttributesFromHWND(void)
310 HWND hWnd
= (HWND
) GetHWND();
311 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
313 if (style
& WS_VSCROLL
)
314 m_windowStyle
|= wxVSCROLL
;
315 if (style
& WS_HSCROLL
)
316 m_windowStyle
|= wxHSCROLL
;