]> git.saurik.com Git - wxWidgets.git/blame - src/msw/nativdlg.cpp
added missing -univ package control files.
[wxWidgets.git] / src / msw / nativdlg.cpp
CommitLineData
2bda0e17
KB
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
cc2b7472 9// Licence: wxWindows license
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
cc2b7472
VZ
12// ===========================================================================
13// declarations
14// ===========================================================================
15
16// ---------------------------------------------------------------------------
17// headers
18// ---------------------------------------------------------------------------
19
2bda0e17 20#ifdef __GNUG__
cc2b7472 21 #pragma implementation
2bda0e17
KB
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
cc2b7472 28 #pragma hdrstop
2bda0e17
KB
29#endif
30
31#ifndef WX_PRECOMP
cc2b7472
VZ
32 #include <stdio.h>
33
34 #include "wx/wx.h"
2bda0e17
KB
35#endif
36
3372145d 37#if defined(__WIN95__) && !defined(__TWIN32__)
2bda0e17 38#include "wx/spinbutt.h"
3372145d 39#endif
2bda0e17
KB
40#include "wx/msw/private.h"
41
cc2b7472
VZ
42// ---------------------------------------------------------------------------
43// global functions
44// ---------------------------------------------------------------------------
45
2bda0e17 46extern wxWindow *wxWndHook;
cc2b7472
VZ
47extern LONG APIENTRY _EXPORT wxDlgProc(HWND hWnd, UINT message,
48 WPARAM wParam, LPARAM lParam);
49
50// ===========================================================================
51// implementation
52// ===========================================================================
2bda0e17 53
debe6624 54bool wxWindow::LoadNativeDialog(wxWindow* parent, wxWindowID& id)
2bda0e17 55{
cc2b7472 56 m_windowId = id;
2bda0e17 57 wxWndHook = this;
cc2b7472
VZ
58 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE)wxGetInstance(),
59 MAKEINTRESOURCE(id),
60 parent ? (HWND)parent->GetHWND() : 0,
61 (DLGPROC) wxDlgProc);
2bda0e17
KB
62 wxWndHook = NULL;
63
cc2b7472
VZ
64 if ( !m_hWnd )
65 return FALSE;
2bda0e17 66
cc2b7472 67 SubclassWin(GetHWND());
2bda0e17 68
cc2b7472
VZ
69 if ( parent )
70 parent->AddChild(this);
71 else
72 wxTopLevelWindows.Append(this);
2bda0e17 73
cc2b7472 74 // Enumerate all children
2bda0e17
KB
75 HWND hWndNext;
76 hWndNext = ::GetWindow((HWND) m_hWnd, GW_CHILD);
77
cc2b7472
VZ
78 wxWindow* child = NULL;
79 if (hWndNext)
80 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
2bda0e17 81
57c208c5 82 while (hWndNext != (HWND) NULL)
2bda0e17 83 {
cc2b7472
VZ
84 hWndNext = ::GetWindow(hWndNext, GW_HWNDNEXT);
85 if (hWndNext)
86 child = CreateWindowFromHWND(this, (WXHWND) hWndNext);
2bda0e17
KB
87 }
88
cc2b7472 89 return TRUE;
2bda0e17
KB
90}
91
92bool wxWindow::LoadNativeDialog(wxWindow* parent, const wxString& name)
93{
cc2b7472 94 SetName(name);
2bda0e17
KB
95
96 wxWndHook = this;
cc2b7472
VZ
97 m_hWnd = (WXHWND)::CreateDialog((HINSTANCE) wxGetInstance(),
98 name.c_str(),
99 parent ? (HWND)parent->GetHWND() : 0,
100 (DLGPROC)wxDlgProc);
2bda0e17
KB
101 wxWndHook = NULL;
102
cc2b7472
VZ
103 if ( !m_hWnd )
104 return FALSE;
2bda0e17 105
cc2b7472 106 SubclassWin(GetHWND());
2bda0e17 107
cc2b7472
VZ
108 if ( parent )
109 parent->AddChild(this);
110 else
111 wxTopLevelWindows.Append(this);
2bda0e17 112
cc2b7472 113 // FIXME why don't we enum all children here?
2bda0e17 114
cc2b7472 115 return TRUE;
2bda0e17
KB
116}
117
cc2b7472
VZ
118// ---------------------------------------------------------------------------
119// look for child by id
120// ---------------------------------------------------------------------------
121
122wxWindow* wxWindow::GetWindowChild1(wxWindowID id)
2bda0e17 123{
cc2b7472
VZ
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;
2bda0e17
KB
139}
140
cc2b7472 141wxWindow* wxWindow::GetWindowChild(wxWindowID id)
2bda0e17 142{
cc2b7472
VZ
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;
2bda0e17
KB
160}
161
cc2b7472
VZ
162// ---------------------------------------------------------------------------
163// create wxWin window from a native HWND
164// ---------------------------------------------------------------------------
2bda0e17
KB
165
166wxWindow* wxWindow::CreateWindowFromHWND(wxWindow* parent, WXHWND hWnd)
167{
cc2b7472
VZ
168 wxString str(wxGetWindowClass(hWnd));
169 str.UpperCase();
2bda0e17 170
cc2b7472
VZ
171 long id = wxGetWindowId(hWnd);
172 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
2bda0e17 173
cc2b7472 174 wxWindow* win = NULL;
2bda0e17 175
223d09f6 176 if (str == wxT("BUTTON"))
cc2b7472
VZ
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 }
2432b92d 188#if defined(__WIN32__) && defined(BS_BITMAP)
cc2b7472
VZ
189 else if (style & BS_BITMAP)
190 {
191 // TODO: how to find the bitmap?
192 win = new wxBitmapButton;
223d09f6 193 wxLogError(wxT("Have not yet implemented bitmap button as BS_BITMAP button."));
cc2b7472 194 }
2bda0e17 195#endif
cc2b7472
VZ
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 {
223d09f6 216 wxLogError(wxT("Don't know what kind of button this is: id = %d"),
cc2b7472
VZ
217 id);
218 }
219 }
223d09f6 220 else if (str == wxT("COMBOBOX"))
cc2b7472
VZ
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.
223d09f6 230 else if (str == wxT("EDIT"))
cc2b7472
VZ
231 {
232 win = new wxTextCtrl;
233 }
223d09f6 234 else if (str == wxT("LISTBOX"))
cc2b7472
VZ
235 {
236 win = new wxListBox;
237 }
223d09f6 238 else if (str == wxT("SCROLLBAR"))
cc2b7472
VZ
239 {
240 win = new wxScrollBar;
241 }
f6bcfd97 242#if defined(__WIN95__) && !defined(__TWIN32__) && wxUSE_SPINBTN
223d09f6 243 else if (str == wxT("MSCTLS_UPDOWN32"))
cc2b7472
VZ
244 {
245 win = new wxSpinButton;
246 }
2bda0e17 247#endif
1e6feb95 248#if wxUSE_SLIDER
223d09f6 249 else if (str == wxT("MSCTLS_TRACKBAR32"))
cc2b7472
VZ
250 {
251 // Need to ascertain if it's horiz or vert
252 win = new wxSlider;
253 }
1e6feb95 254#endif // wxUSE_SLIDER
223d09f6 255 else if (str == wxT("STATIC"))
cc2b7472
VZ
256 {
257 int style1 = (style & 0xFF);
258
259 if ((style1 == SS_LEFT) || (style1 == SS_RIGHT) || (style1 == SS_SIMPLE))
260 win = new wxStaticText;
2432b92d 261#if defined(__WIN32__) && defined(BS_BITMAP)
cc2b7472
VZ
262 else if (style1 == SS_BITMAP)
263 {
264 win = new wxStaticBitmap;
2bda0e17 265
cc2b7472 266 // Help! this doesn't correspond with the wxWin implementation.
223d09f6 267 wxLogError(wxT("Please make SS_BITMAP statics into owner-draw buttons."));
cc2b7472 268 }
2bda0e17 269#endif
cc2b7472
VZ
270 }
271 else
272 {
223d09f6 273 wxString msg(wxT("Don't know how to convert from Windows class "));
cc2b7472
VZ
274 msg += str;
275 wxLogError(msg);
276 }
277
278 if (win)
279 {
280 parent->AddChild(win);
281 win->SetEventHandler(win);
282 win->SetHWND(hWnd);
283 win->SetId(id);
284 win->SubclassWin(hWnd);
285 win->AdoptAttributesFromHWND();
286 win->SetupColours();
cc2b7472 287 }
3ca6a5f0
BP
288
289 return win;
2bda0e17
KB
290}
291
292// Make sure the window style (etc.) reflects the HWND style (roughly)
293void wxWindow::AdoptAttributesFromHWND(void)
294{
cc2b7472
VZ
295 HWND hWnd = (HWND) GetHWND();
296 long style = GetWindowLong((HWND) hWnd, GWL_STYLE);
2bda0e17 297
cc2b7472
VZ
298 if (style & WS_VSCROLL)
299 m_windowStyle |= wxVSCROLL;
300 if (style & WS_HSCROLL)
301 m_windowStyle |= wxHSCROLL;
2bda0e17
KB
302}
303