]> git.saurik.com Git - wxWidgets.git/blob - src/msw/nativdlg.cpp
Added generic drag image source file
[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
9 // Licence: wxWindows licence
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__)
38 #include "wx/spinbutt.h"
39 #endif
40 #include "wx/msw/private.h"
41
42 // ---------------------------------------------------------------------------
43 // global functions
44 // ---------------------------------------------------------------------------
45
46 extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message,
47 WPARAM wParam, LPARAM lParam);
48
49 // ===========================================================================
50 // implementation
51 // ===========================================================================
52
53 bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id)
54 {
55 m_windowId = id;
56
57 wxWindowCreationHook hook(this);
58 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(),
59 MAKEINTRESOURCE(id),
60 parent ? (HWND)parent->GetHWND() : 0,
61 (DLGPROC) wxDlgProc);
62
63 if ( !m_hWnd )
64 return FALSE;
65
66 SubclassWin(GetHWND());
67
68 if ( parent )
69 parent->AddChild(this);
70 else
71 wxTopLevelWindows.Append(this);
72
73 // Enumerate all children
74 HWND hWndNext;
75 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
76
77 wxWindow* child = NULL;
78 if (hWndNext)
79 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
80
81 while (hWndNext != (HWND) NULL)
82 {
83 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
84 if (hWndNext)
85 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
86 }
87
88 return TRUE;
89 }
90
91 bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
92 {
93 SetName(name);
94
95 wxWindowCreationHook hook(this);
96 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
97 name.c_str(),
98 parent ? (HWND)parent->GetHWND() : 0,
99 (DLGPROC)wxDlgProc);
100
101 if ( !m_hWnd )
102 return FALSE;
103
104 SubclassWin(GetHWND());
105
106 if ( parent )
107 parent->AddChild(this);
108 else
109 wxTopLevelWindows.Append(this);
110
111 // Enumerate all children
112 HWND hWndNext;
113 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
114
115 wxWindow* child = NULL;
116 if (hWndNext)
117 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
118
119 while (hWndNext != (HWND) NULL)
120 {
121 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
122 if (hWndNext)
123 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
124 }
125
126 return TRUE;
127 }
128
129 // ---------------------------------------------------------------------------
130 // look for child by id
131 // ---------------------------------------------------------------------------
132
133 wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
134 {
135 if ( m_windowId == id )
136 return this;
137
138 wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
139 while ( node )
140 {
141 wxWindow* child = node->GetData();
142 wxWindow* win = child->GetWindowChild1(id);
143 if ( win )
144 return win;
145
146 node = node->GetNext();
147 }
148
149 return NULL;
150 }
151
152 wxWindow* wxWindow::GetWindowChild(wxWindowID id)
153 {
154 wxWindow* win = GetWindowChild1(id);
155 if ( !win )
156 {
157 HWND hWnd = ::GetDlgItem((HWND) GetHWND(), id);
158
159 if (hWnd)
160 {
161 wxWindow* child = CreateWindowFromHWND(this, (WXHWND) hWnd);
162 if (child)
163 {
164 child->AddChild(this);
165 return child;
166 }
167 }
168 }
169
170 return NULL;
171 }
172
173 // ---------------------------------------------------------------------------
174 // create wxWin window from a native HWND
175 // ---------------------------------------------------------------------------
176
177 wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
178 {
179 wxString str(wxGetWindowClass(hWnd));
180 str.UpperCase();
181
182 long id = wxGetWindowId(hWnd);
183 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
184
185 wxWindow* win = NULL;
186
187 if (str == wxT("BUTTON"))
188 {
189 int style1 = (style & 0xFF);
190 if ((style1 == BS_3STATE) || (style1 == BS_AUTO3STATE) || (style1 == BS_AUTOCHECKBOX) ||
191 (style1 == BS_CHECKBOX))
192 {
193 win = new wxCheckBox;
194 }
195 else if ((style1 == BS_AUTORADIOBUTTON) || (style1 == BS_RADIOBUTTON))
196 {
197 win = new wxRadioButton;
198 }
199 #if wxUSE_BMPBUTTON
200 #if defined(__WIN32__) && defined(BS_BITMAP)
201 else if (style & BS_BITMAP)
202 {
203 // TODO: how to find the bitmap?
204 win = new wxBitmapButton;
205 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
206 }
207 #endif
208 else if (style1 == BS_OWNERDRAW)
209 {
210 // TODO: how to find the bitmap?
211 // TODO: can't distinguish between bitmap button and bitmap static.
212 // Change implementation of wxStaticBitmap to SS_BITMAP.
213 // PROBLEM: this assumes that we're using resource-based bitmaps.
214 // So maybe need 2 implementations of bitmap buttons/static controls,
215 // with a switch in the drawing code. Call default proc if BS_BITMAP.
216 win = new wxBitmapButton;
217 }
218 #endif
219 else if ((style1 == BS_PUSHBUTTON) || (style1 == BS_DEFPUSHBUTTON))
220 {
221 win = new wxButton;
222 }
223 else if (style1 == BS_GROUPBOX)
224 {
225 win = new wxStaticBox;
226 }
227 else
228 {
229 wxLogError(wxT("Don't know what kind of button this is: id = %ld"),
230 id);
231 }
232 }
233 else if (str == wxT("COMBOBOX"))
234 {
235 win = new wxComboBox;
236 }
237 // TODO: Problem if the user creates a multiline - but not rich text - text control,
238 // since wxWin assumes RichEdit control for this. Should have m_isRichText in
239 // wxTextCtrl. Also, convert as much of the window style as is necessary
240 // for correct functioning.
241 // Could have wxWindow::AdoptAttributesFromHWND(WXHWND)
242 // to be overridden by each control class.
243 else if (str == wxT("EDIT"))
244 {
245 win = new wxTextCtrl;
246 }
247 else if (str == wxT("LISTBOX"))
248 {
249 win = new wxListBox;
250 }
251 else if (str == wxT("SCROLLBAR"))
252 {
253 win = new wxScrollBar;
254 }
255 #if defined(__WIN95__) && wxUSE_SPINBTN
256 else if (str == wxT("MSCTLS_UPDOWN32"))
257 {
258 win = new wxSpinButton;
259 }
260 #endif
261 #if wxUSE_SLIDER
262 else if (str == wxT("MSCTLS_TRACKBAR32"))
263 {
264 // Need to ascertain if it's horiz or vert
265 win = new wxSlider;
266 }
267 #endif // wxUSE_SLIDER
268 else if (str == wxT("STATIC"))
269 {
270 int style1 = (style & 0xFF);
271
272 if ((style1 == SS_LEFT) || (style1 == SS_RIGHT)
273 #ifndef __WXWINCE__
274 || (style1 == SS_SIMPLE)
275 #endif
276 )
277 win = new wxStaticText;
278 #if wxUSE_STATBMP
279 #if defined(__WIN32__) && defined(BS_BITMAP)
280 else if (style1 == SS_BITMAP)
281 {
282 win = new wxStaticBitmap;
283
284 // Help! this doesn't correspond with the wxWin implementation.
285 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
286 }
287 #endif
288 #endif /* wxUSE_STATBMP */
289 }
290 else
291 {
292 wxString msg(wxT("Don't know how to convert from Windows class "));
293 msg += str;
294 wxLogError(msg);
295 }
296
297 if (win)
298 {
299 parent->AddChild(win);
300 win->SetEventHandler(win);
301 win->SetHWND(hWnd);
302 win->SetId(id);
303 win->SubclassWin(hWnd);
304 win->AdoptAttributesFromHWND();
305 win->SetupColours();
306 }
307
308 return win;
309 }
310
311 // Make sure the window style (etc.) reflects the HWND style (roughly)
312 void wxWindow::AdoptAttributesFromHWND(void)
313 {
314 HWND hWnd = (HWND) GetHWND();
315 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
316
317 if (style & WS_VSCROLL)
318 m_windowStyle |= wxVSCROLL;
319 if (style & WS_HSCROLL)
320 m_windowStyle |= wxHSCROLL;
321 }
322