]> git.saurik.com Git - wxWidgets.git/blob - src/msw/nativdlg.cpp
removed old xpm code
[wxWidgets.git] / src / msw / nativdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: nativdlg.cpp
3 // Purpose: Native dialog loading code (part of wxWindow)
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 // ===========================================================================
13 // declarations
14 // ===========================================================================
15
16 // ---------------------------------------------------------------------------
17 // headers
18 // ---------------------------------------------------------------------------
19
20 #ifdef __GNUG__
21 #pragma implementation
22 #endif
23
24 // For compilers that support precompilation, includes "wx.h".
25 #include "wx/wxprec.h"
26
27 #ifdef __BORLANDC__
28 #pragma hdrstop
29 #endif
30
31 #ifndef WX_PRECOMP
32 #include <stdio.h>
33
34 #include "wx/wx.h"
35 #endif
36
37 #if defined(__WIN95__) && !defined(__TWIN32__)
38 #include "wx/spinbutt.h"
39 #endif
40 #include "wx/msw/private.h"
41
42 // ---------------------------------------------------------------------------
43 // global functions
44 // ---------------------------------------------------------------------------
45
46 extern wxWindow *wxWndHook;
47 extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message,
48 WPARAM wParam, LPARAM lParam);
49
50 // ===========================================================================
51 // implementation
52 // ===========================================================================
53
54 bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id)
55 {
56 m_windowId = id;
57 wxWndHook = this;
58 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(),
59 MAKEINTRESOURCE(id),
60 parent ? (HWND)parent->GetHWND() : 0,
61 (DLGPROC) wxDlgProc);
62 wxWndHook = NULL;
63
64 if ( !m_hWnd )
65 return FALSE;
66
67 SubclassWin(GetHWND());
68
69 if ( parent )
70 parent->AddChild(this);
71 else
72 wxTopLevelWindows.Append(this);
73
74 // Enumerate all children
75 HWND hWndNext;
76 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
77
78 wxWindow* child = NULL;
79 if (hWndNext)
80 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
81
82 while (hWndNext != (HWND) NULL)
83 {
84 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
85 if (hWndNext)
86 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
87 }
88
89 return TRUE;
90 }
91
92 bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
93 {
94 SetName(name);
95
96 wxWndHook = this;
97 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
98 name.c_str(),
99 parent ? (HWND)parent->GetHWND() : 0,
100 (DLGPROC)wxDlgProc);
101 wxWndHook = NULL;
102
103 if ( !m_hWnd )
104 return FALSE;
105
106 SubclassWin(GetHWND());
107
108 if ( parent )
109 parent->AddChild(this);
110 else
111 wxTopLevelWindows.Append(this);
112
113 // FIXME why don't we enum all children here?
114
115 return TRUE;
116 }
117
118 // ---------------------------------------------------------------------------
119 // look for child by id
120 // ---------------------------------------------------------------------------
121
122 wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
123 {
124 if ( m_windowId == id )
125 return this;
126
127 wxWindowList::Node *node = GetChildren().GetFirst();
128 while ( node )
129 {
130 wxWindow* child = node->GetData();
131 wxWindow* win = child->GetWindowChild1(id);
132 if ( win )
133 return win;
134
135 node = node->GetNext();
136 }
137
138 return NULL;
139 }
140
141 wxWindow* wxWindow::GetWindowChild(wxWindowID id)
142 {
143 wxWindow* win = GetWindowChild1(id);
144 if ( !win )
145 {
146 HWND hWnd = ::GetDlgItem((HWND) GetHWND(), id);
147
148 if (hWnd)
149 {
150 wxWindow* child = CreateWindowFromHWND(this, (WXHWND) hWnd);
151 if (child)
152 {
153 child->AddChild(this);
154 return child;
155 }
156 }
157 }
158
159 return NULL;
160 }
161
162 // ---------------------------------------------------------------------------
163 // create wxWin window from a native HWND
164 // ---------------------------------------------------------------------------
165
166 wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
167 {
168 wxString str(wxGetWindowClass(hWnd));
169 str.UpperCase();
170
171 long id = wxGetWindowId(hWnd);
172 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
173
174 wxWindow* win = NULL;
175
176 if (str == wxT("BUTTON"))
177 {
178 int style1 = (style & 0xFF);
179 if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) ||
180 (style1 == BS_CHECKBOX))
181 {
182 win = new wxCheckBox;
183 }
184 else if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON))
185 {
186 win = new wxRadioButton;
187 }
188 #if defined(__WIN32__) && defined(BS_BITMAP)
189 else if (style & BS_BITMAP)
190 {
191 // TODO: how to find the bitmap?
192 win = new wxBitmapButton;
193 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
194 }
195 #endif
196 else if (style1 == BS_OWNERDRAW)
197 {
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;
205 }
206 else if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON))
207 {
208 win = new wxButton;
209 }
210 else if (style1 == BS_GROUPBOX)
211 {
212 win = new wxStaticBox;
213 }
214 else
215 {
216 wxLogError(wxT("Don't know what kind of button this is: id = %d"),
217 id);
218 }
219 }
220 else if (str == wxT("COMBOBOX"))
221 {
222 win = new wxComboBox;
223 }
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"))
231 {
232 win = new wxTextCtrl;
233 }
234 else if (str == wxT("LISTBOX"))
235 {
236 win = new wxListBox;
237 }
238 else if (str == wxT("SCROLLBAR"))
239 {
240 win = new wxScrollBar;
241 }
242 #if defined(__WIN95__) && !defined(__TWIN32__) && wxUSE_SPINBTN
243 else if (str == wxT("MSCTLS_UPDOWN32"))
244 {
245 win = new wxSpinButton;
246 }
247 #endif
248 else if (str == wxT("MSCTLS_TRACKBAR32"))
249 {
250 // Need to ascertain if it's horiz or vert
251 win = new wxSlider;
252 }
253 else if (str == wxT("STATIC"))
254 {
255 int style1 = (style & 0xFF);
256
257 if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) || (style1 == SS_SIMPLE))
258 win = new wxStaticText;
259 #if defined(__WIN32__) && defined(BS_BITMAP)
260 else if (style1 == SS_BITMAP)
261 {
262 win = new wxStaticBitmap;
263
264 // Help! this doesn't correspond with the wxWin implementation.
265 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
266 }
267 #endif
268 }
269 else
270 {
271 wxString msg(wxT("Don't know how to convert from Windows class "));
272 msg += str;
273 wxLogError(msg);
274 }
275
276 if (win)
277 {
278 parent->AddChild(win);
279 win->SetEventHandler(win);
280 win->SetHWND(hWnd);
281 win->SetId(id);
282 win->SubclassWin(hWnd);
283 win->AdoptAttributesFromHWND();
284 win->SetupColours();
285 }
286
287 return win;
288 }
289
290 // Make sure the window style (etc.) reflects the HWND style (roughly)
291 void wxWindow::AdoptAttributesFromHWND(void)
292 {
293 HWND hWnd = (HWND) GetHWND();
294 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
295
296 if (style & WS_VSCROLL)
297 m_windowStyle |= wxVSCROLL;
298 if (style & WS_HSCROLL)
299 m_windowStyle |= wxHSCROLL;
300 }
301