]>
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 #include "wx/spinbutt.h"
38 #include "wx/msw/private.h"
40 // ---------------------------------------------------------------------------
42 // ---------------------------------------------------------------------------
44 extern wxWindow
*wxWndHook
;
45 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
,
46 WPARAM wParam
, LPARAM lParam
);
48 // ===========================================================================
50 // ===========================================================================
52 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
56 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
)wxGetInstance(),
58 parent
? (HWND
)parent
->GetHWND() : 0,
65 SubclassWin(GetHWND());
68 parent
->AddChild(this);
70 wxTopLevelWindows
.Append(this);
72 // Enumerate all children
74 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
76 wxWindow
* child
= NULL
;
78 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
80 while (hWndNext
!= (HWND
) NULL
)
82 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
84 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
90 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
95 m_hWnd
= (WXHWND
)::CreateDialog((HINSTANCE
) wxGetInstance(),
97 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
;
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("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(_T("Don't know what kind of button this is: id = %d"),
218 else if (str
== "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
== "EDIT")
230 win
= new wxTextCtrl
;
232 else if (str
== "LISTBOX")
236 else if (str
== "SCROLLBAR")
238 win
= new wxScrollBar
;
240 #if defined(__WIN95__) && !defined(__TWIN32__)
241 else if (str
== "MSCTLS_UPDOWN32")
243 win
= new wxSpinButton
;
246 else if (str
== "MSCTLS_TRACKBAR32")
248 // Need to ascertain if it's horiz or vert
251 else if (str
== "STATIC")
253 int style1
= (style
& 0xFF);
255 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
) || (style1
== SS_SIMPLE
))
256 win
= new wxStaticText
;
257 #if defined(__WIN32__) && defined(BS_BITMAP)
258 else if (style1
== SS_BITMAP
)
260 win
= new wxStaticBitmap
;
262 // Help! this doesn't correspond with the wxWin implementation.
263 wxLogError("Please make SS_BITMAP statics into owner-draw buttons.");
269 wxString
msg("Don't know how to convert from Windows class ");
276 parent
->AddChild(win
);
277 win
->SetEventHandler(win
);
280 win
->SubclassWin(hWnd
);
281 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
;