]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/nativdlg.cpp
a8b9eb10ccc9078765dcaba0171d2e1065ee7de9
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
!= 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);
143 GetClassNameA((HWND
) hWnd
, buf
, 256);
151 long id
= (long) GetWindowWord((HWND
) hWnd
, GWW_ID
);
153 long id
= GetWindowLong((HWND
) hWnd
, GWL_ID
);
156 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
158 wxWindow
* win
= NULL
;
162 int style1
= (style
& 0xFF);
163 if ((style1
== BS_3STATE
) || (style1
== BS_AUTO3STATE
) || (style1
== BS_AUTOCHECKBOX
) ||
164 (style1
== BS_CHECKBOX
))
166 win
= new wxCheckBox
;
168 else if ((style1
== BS_AUTORADIOBUTTON
) || (style1
== BS_RADIOBUTTON
))
170 win
= new wxRadioButton
;
173 else if (style
& BS_BITMAP
)
175 // TODO: how to find the bitmap?
176 win
= new wxBitmapButton
;
177 wxMessageBox("Have not yet implemented bitmap button as BS_BITMAP button.");
180 else if (style1
== BS_OWNERDRAW
)
182 // TODO: how to find the bitmap?
183 // TODO: can't distinguish between bitmap button and bitmap static.
184 // Change implementation of wxStaticBitmap to SS_BITMAP.
185 // PROBLEM: this assumes that we're using resource-based bitmaps.
186 // So maybe need 2 implementations of bitmap buttons/static controls,
187 // with a switch in the drawing code. Call default proc if BS_BITMAP.
188 win
= new wxBitmapButton
;
190 else if ((style1
== BS_PUSHBUTTON
) || (style1
== BS_DEFPUSHBUTTON
))
194 else if (style1
== BS_GROUPBOX
)
196 win
= new wxStaticBox
;
201 sprintf(buf
, "Don't know what kind of button this is: id = %d", (int) id
);
205 else if (str
== "COMBOBOX")
207 win
= new wxComboBox
;
209 // TODO: Problem if the user creates a multiline - but not rich text - text control,
210 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
211 // wxTextCtrl. Also, convert as much of the window style as is necessary
212 // for correct functioning.
213 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
214 // to be overridden by each control class.
215 else if (str
== "EDIT")
217 win
= new wxTextCtrl
;
219 else if (str
== "LISTBOX")
223 else if (str
== "SCROLLBAR")
225 win
= new wxScrollBar
;
227 #if defined(__WIN95__)
228 else if (str
== "MSCTLS_UPDOWN32")
230 win
= new wxSpinButton
;
233 else if (str
== "MSCTLS_TRACKBAR32")
235 // Need to ascertain if it's horiz or vert
238 else if (str
== "STATIC")
240 int style1
= (style
& 0xFF);
242 if ((style1
== SS_LEFT
) || (style1
== SS_RIGHT
) || (style1
== SS_SIMPLE
))
243 win
= new wxStaticText
;
245 else if (style1
== SS_BITMAP
)
247 win
= new wxStaticBitmap
;
249 // Help! this doesn't correspond with the wxWin implementation.
250 wxMessageBox("Please make SS_BITMAP statics into owner-draw buttons.");
256 wxString
msg("Don't know how to convert from Windows class ");
263 parent
->AddChild(win
);
264 win
->SetEventHandler(win
);
267 win
->SubclassWin(hWnd
);
268 win
->AdoptAttributesFromHWND();
277 // Make sure the window style (etc.) reflects the HWND style (roughly)
278 void wxWindow::AdoptAttributesFromHWND(void)
280 HWND hWnd
= (HWND
) GetHWND();
281 long style
= GetWindowLong((HWND
) hWnd
, GWL_STYLE
);
283 if (style
& WS_VSCROLL
)
284 m_windowStyle
|= wxVSCROLL
;
285 if (style
& WS_HSCROLL
)
286 m_windowStyle
|= wxHSCROLL
;