]>
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 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include "wx/spinbutt.h"
29 #include "wx/msw/private.h"
31 extern wxWindow
*wxWndHook
;
32 extern LONG APIENTRY _EXPORT
wxDlgProc(HWND hWnd
, UINT message
, WPARAM wParam
, LPARAM lParam
);
34 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, wxWindowID
& id
)
38 m_hWnd
= (WXHWND
) ::CreateDialog((HINSTANCE
) wxGetInstance(), MAKEINTRESOURCE(id
),
39 (HWND
) (parent
? parent
->GetHWND() : (WXHWND
) NULL
), (DLGPROC
) wxDlgProc
);
45 SubclassWin(GetHWND());
48 wxTopLevelWindows
.Append(this);
51 parent
->AddChild(this);
53 // Enumerate all children
55 hWndNext
= ::GetWindow((HWND
) m_hWnd
, GW_CHILD
);
57 wxWindow
* child
= NULL
;
59 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
61 while (hWndNext
!= (HWND
) NULL
)
63 hWndNext
= ::GetWindow(hWndNext
, GW_HWNDNEXT
);
65 child
= CreateWindowFromHWND(this, (WXHWND
) hWndNext
);
71 bool wxWindow::LoadNativeDialog(wxWindow
* parent
, const wxString
& name
)
76 m_hWnd
= (WXHWND
) ::CreateDialog((HINSTANCE
) wxGetInstance(), (const char *) name
,
77 (HWND
) (parent
? parent
->GetHWND() : (WXHWND
) NULL
), (DLGPROC
) wxDlgProc
);
83 SubclassWin(GetHWND());
86 wxTopLevelWindows
.Append(this);
89 parent
->AddChild(this);
94 wxWindow
* wxWindow::GetWindowChild1(wxWindowID
& id
)
96 if ( m_windowId
== id
)
99 wxNode
*node
= GetChildren().First();
102 wxWindow
* child
= (wxWindow
*) node
->Data();
103 wxWindow
* win
= child
->GetWindowChild1(id
);
112 wxWindow
* wxWindow::GetWindowChild(wxWindowID
& id
)
114 wxWindow
* win
= GetWindowChild1(id
);
117 HWND hWnd
= ::GetDlgItem((HWND
) GetHWND(), id
);
121 wxWindow
* child
= CreateWindowFromHWND(this, (WXHWND
) hWnd
);
124 child
->AddChild(this);
133 wxWindow
* wxWindow::CreateWindowFromHWND(wxWindow
* parent
, WXHWND hWnd
)
138 GetClassName((HWND
) hWnd
, buf
, 256);
141 GetClassNameW((HWND
) hWnd
, buf
, 256);
144 GetClassName((HWND
) hWnd
, buf
, 256);
146 GetClassNameA((HWND
) hWnd
, buf
, 256);
155 long id
= (long) GetWindowWord((HWND
) hWnd
, GWW_ID
);
157 long id
= GetWindowLong((HWND
) hWnd
, GWL_ID
);
160 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
162 wxWindow
* win
= NULL
;
166 int style1
= (style
& 0xFF);
167 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
168 (style1
== BS_CHECKBOX
))
170 win
= new wxCheckBox
;
172 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
174 win
= new wxRadioButton
;
176 #if defined(__WIN32__) && defined(BS_BITMAP)
177 else if (style
& BS_BITMAP
)
179 // TODO: how to find the bitmap?
180 win
= new wxBitmapButton
;
181 wxLogError("Have not yet implemented bitmap button as BS_BITMAP button.");
184 else if (style1
== BS_OWNERDRAW
)
186 // TODO: how to find the bitmap?
187 // TODO: can't distinguish between bitmap button and bitmap static.
188 // Change implementation of wxStaticBitmap to SS_BITMAP.
189 // PROBLEM: this assumes that we're using resource-based bitmaps.
190 // So maybe need 2 implementations of bitmap buttons/static controls,
191 // with a switch in the drawing code. Call default proc if BS_BITMAP.
192 win
= new wxBitmapButton
;
194 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
198 else if (style1
== BS_GROUPBOX
)
200 win
= new wxStaticBox
;
205 sprintf(buf
, "Don't know what kind of button this is: id = %d", (int) id
);
209 else if (str
== "COMBOBOX")
211 win
= new wxComboBox
;
213 // TODO: Problem if the user creates a multiline - but not rich text - text control,
214 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
215 // wxTextCtrl. Also, convert as much of the window style as is necessary
216 // for correct functioning.
217 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
218 // to be overridden by each control class.
219 else if (str
== "EDIT")
221 win
= new wxTextCtrl
;
223 else if (str
== "LISTBOX")
227 else if (str
== "SCROLLBAR")
229 win
= new wxScrollBar
;
231 #if defined(__WIN95__) && !defined(__TWIN32__)
232 else if (str
== "MSCTLS_UPDOWN32")
234 win
= new wxSpinButton
;
237 else if (str
== "MSCTLS_TRACKBAR32")
239 // Need to ascertain if it's horiz or vert
242 else if (str
== "STATIC")
244 int style1
= (style
& 0xFF);
246 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
) || (style1
== SS_SIMPLE
))
247 win
= new wxStaticText
;
248 #if defined(__WIN32__) && defined(BS_BITMAP)
249 else if (style1
== SS_BITMAP
)
251 win
= new wxStaticBitmap
;
253 // Help! this doesn't correspond with the wxWin implementation.
254 wxLogError("Please make SS_BITMAP statics into owner-draw buttons.");
260 wxString
msg("Don't know how to convert from Windows class ");
267 parent
->AddChild(win
);
268 win
->SetEventHandler(win
);
271 win
->SubclassWin(hWnd
);
272 win
->AdoptAttributesFromHWND();
281 // Make sure the window style (etc.) reflects the HWND style (roughly)
282 void wxWindow::AdoptAttributesFromHWND(void)
284 HWND hWnd
= (HWND
) GetHWND();
285 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
287 if (style
& WS_VSCROLL
)
288 m_windowStyle
|= wxVSCROLL
;
289 if (style
& WS_HSCROLL
)
290 m_windowStyle
|= wxHSCROLL
;