]>
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 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 wxWindow
*wxWndHook
;
47 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
48 WPARAM wParam
, LPARAM lParam
);
50 // ===========================================================================
52 // ===========================================================================
54 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
58 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
60 parent
? (HWND
)parent
->GetHWND() : 0,
67 SubclassWin(GetHWND());
70 parent
->AddChild(this);
72 wxTopLevelWindows
.Append(this);
74 // Enumerate all children
76 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
78 wxWindow
* child
= NULL
;
80 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
82 while (hWndNext
!= (HWND
) NULL
)
84 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
86 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
92 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
97 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
99 parent
? (HWND
)parent
->GetHWND() : 0,
106 SubclassWin(GetHWND());
109 parent
->AddChild(this);
111 wxTopLevelWindows
.Append(this);
113 // FIXME why don't we enum all children here?
118 // ---------------------------------------------------------------------------
119 // look for child by id
120 // ---------------------------------------------------------------------------
122 wxWindow
* wxWindow::GetWindowChild1(wxWindowID id
)
124 if ( m_windowId
== id
)
127 wxWindowList::Node
*node
= GetChildren().GetFirst();
130 wxWindow
* child
= node
->GetData();
131 wxWindow
* win
= child
->GetWindowChild1(id
);
135 node
= node
->GetNext();
141 wxWindow
* wxWindow::GetWindowChild(wxWindowID id
)
143 wxWindow
* win
= GetWindowChild1(id
);
146 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
150 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
153 child
->AddChild(this);
162 // ---------------------------------------------------------------------------
163 // create wxWin window from a native HWND
164 // ---------------------------------------------------------------------------
166 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
168 wxString
str(wxGetWindowClass(hWnd
));
171 long id
= wxGetWindowId(hWnd
);
172 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
174 wxWindow
* win
= NULL
;
176 if (str
== wxT("BUTTON"))
178 int style1
= (style
& 0xFF);
179 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
180 (style1
== BS_CHECKBOX
))
182 win
= new wxCheckBox
;
184 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
186 win
= new wxRadioButton
;
188 #if defined(__WIN32__) && defined(BS_BITMAP)
189 else if (style
& BS_BITMAP
)
191 // TODO: how to find the bitmap?
192 win
= new wxBitmapButton
;
193 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
196 else if (style1
== BS_OWNERDRAW
)
198 // TODO: how to find the bitmap?
199 // TODO: can't distinguish between bitmap button and bitmap static.
200 // Change implementation of wxStaticBitmap to SS_BITMAP.
201 // PROBLEM: this assumes that we're using resource-based bitmaps.
202 // So maybe need 2 implementations of bitmap buttons/static controls,
203 // with a switch in the drawing code. Call default proc if BS_BITMAP.
204 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 = %d"),
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
;
261 #if defined(__WIN32__) && defined(BS_BITMAP)
262 else if (style1
== SS_BITMAP
)
264 win
= new wxStaticBitmap
;
266 // Help! this doesn't correspond with the wxWin implementation.
267 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
273 wxString
msg(wxT("Don't know how to convert from Windows class "));
280 parent
->AddChild(win
);
281 win
->SetEventHandler(win
);
284 win
->SubclassWin(hWnd
);
285 win
->AdoptAttributesFromHWND();
292 // Make sure the window style (etc.) reflects the HWND style (roughly)
293 void wxWindow::AdoptAttributesFromHWND(void)
295 HWND hWnd
= (HWND
) GetHWND();
296 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
298 if (style
& WS_VSCROLL
)
299 m_windowStyle
|= wxVSCROLL
;
300 if (style
& WS_HSCROLL
)
301 m_windowStyle
|= wxHSCROLL
;