]>
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__) && !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
;
187 #if defined(__WIN32__) && defined(BS_BITMAP)
188 else if (style
& BS_BITMAP
)
190 // TODO: how to find the bitmap?
191 win
= new wxBitmapButton
;
192 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
195 else if (style1
== BS_OWNERDRAW
)
197 // TODO: how to find the bitmap?
198 // TODO: can't distinguish between bitmap button and bitmap static.
199 // Change implementation of wxStaticBitmap to SS_BITMAP.
200 // PROBLEM: this assumes that we're using resource-based bitmaps.
201 // So maybe need 2 implementations of bitmap buttons/static controls,
202 // with a switch in the drawing code. Call default proc if BS_BITMAP.
203 win
= new wxBitmapButton
;
206 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
210 else if (style1
== BS_GROUPBOX
)
212 win
= new wxStaticBox
;
216 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
220 else if (str
== wxT("COMBOBOX"))
222 win
= new wxComboBox
;
224 // TODO: Problem if the user creates a multiline - but not rich text - text control,
225 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
226 // wxTextCtrl. Also, convert as much of the window style as is necessary
227 // for correct functioning.
228 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
229 // to be overridden by each control class.
230 else if (str
== wxT("EDIT"))
232 win
= new wxTextCtrl
;
234 else if (str
== wxT("LISTBOX"))
238 else if (str
== wxT("SCROLLBAR"))
240 win
= new wxScrollBar
;
242 #if defined(__WIN95__) && !defined(__TWIN32__) && wxUSE_SPINBTN
243 else if (str
== wxT("MSCTLS_UPDOWN32"))
245 win
= new wxSpinButton
;
249 else if (str
== wxT("MSCTLS_TRACKBAR32"))
251 // Need to ascertain if it's horiz or vert
254 #endif // wxUSE_SLIDER
255 else if (str
== wxT("STATIC"))
257 int style1
= (style
& 0xFF);
259 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
) || (style1
== SS_SIMPLE
))
260 win
= new wxStaticText
;
262 #if defined(__WIN32__) && defined(BS_BITMAP)
263 else if (style1
== SS_BITMAP
)
265 win
= new wxStaticBitmap
;
267 // Help! this doesn't correspond with the wxWin implementation.
268 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
271 #endif /* wxUSE_STATBMP */
275 wxString
msg(wxT("Don't know how to convert from Windows class "));
282 parent
->AddChild(win
);
283 win
->SetEventHandler(win
);
286 win
->SubclassWin(hWnd
);
287 win
->AdoptAttributesFromHWND();
294 // Make sure the window style (etc.) reflects the HWND style (roughly)
295 void wxWindow::AdoptAttributesFromHWND(void)
297 HWND hWnd
= (HWND
) GetHWND();
298 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
300 if (style
& WS_VSCROLL
)
301 m_windowStyle
|= wxVSCROLL
;
302 if (style
& WS_HSCROLL
)
303 m_windowStyle
|= wxHSCROLL
;