]> git.saurik.com Git - wxWidgets.git/blame - src/os2/control.cpp
corrected path splitting for mac relative paths
[wxWidgets.git] / src / os2 / control.cpp
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: control.cpp
3// Purpose: wxControl class
45fcbf3b 4// Author: David Webster
0e320a79 5// Modified by:
45fcbf3b 6// Created: 09/17/99
0e320a79 7// RCS-ID: $Id$
45fcbf3b
DW
8// Copyright: (c) Julian Smart and Markus Holzem
9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifdef __GNUG__
13#pragma implementation "control.h"
14#endif
15
45fcbf3b
DW
16// For compilers that support precompilation, includes "wx.h".
17#include "wx/wxprec.h"
18
19#ifndef WX_PRECOMP
20#include "wx/event.h"
21#include "wx/app.h"
22#include "wx/dcclient.h"
a4a16252 23#include "wx/scrolwin.h"
45fcbf3b 24#endif
86de7616 25#include "wx/os2/private.h"
0e320a79
DW
26#include "wx/control.h"
27
0e320a79
DW
28IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
29
30BEGIN_EVENT_TABLE(wxControl, wxWindow)
45fcbf3b 31 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
0e320a79 32END_EVENT_TABLE()
0e320a79
DW
33
34// Item members
35wxControl::wxControl()
36{
45fcbf3b
DW
37
38#if WXWIN_COMPATIBILITY
39 m_callback = 0;
40#endif // WXWIN_COMPATIBILITY
c9cb56f7
DW
41} // end of wxControl::wxControl
42
43bool wxControl::Create(
44 wxWindow* pParent
45, wxWindowID vId
46, const wxPoint& rPos
47, const wxSize& rSize
48, long lStyle
3d62dcb6 49#if wxUSE_VALIDATORS
c9cb56f7 50, const wxValidator& rValidator
3d62dcb6 51#endif
c9cb56f7
DW
52, const wxString& rsName
53)
3d62dcb6 54{
c9cb56f7
DW
55 bool bRval = wxWindow::Create( pParent
56 ,vId
57 ,rPos
58 ,rSize
59 ,lStyle
60 ,rsName
61 );
62 if (bRval)
63 {
3d62dcb6 64#if wxUSE_VALIDATORS
c9cb56f7 65 SetValidator(rValidator);
3d62dcb6
DW
66#endif
67 }
c9cb56f7
DW
68 return bRval;
69} // end of wxControl::Create
3d62dcb6 70
0e320a79
DW
71wxControl::~wxControl()
72{
45fcbf3b 73 m_isBeingDeleted = TRUE;
0e320a79
DW
74}
75
0cf6acbf
DW
76bool wxControl::OS2CreateControl(
77 wxWindow* pParent
78, wxWindowID vId
79, const wxPoint& rPos
80, const wxSize& rSize
81, long lStyle
82#if wxUSE_VALIDATORS
83, const wxValidator& rValidator
84#endif
85, const wxString& rsName
86)
87{
88 //
89 // Even if it's possible to create controls without parents in some port,
90 // it should surely be discouraged because it doesn't work at all under
91 // Windows
92 //
93 if (!CreateBase( pParent
94 ,vId
95 ,rPos
96 ,rSize
97 ,lStyle
98#if wxUSE_VALIDATORS
99 ,rValidator
100#endif
101 ,rsName
102 ))
103 return FALSE;
104 pParent->AddChild(this);
105 return TRUE;
106} // end of wxControl::OS2CreateControl
107
c9cb56f7
DW
108bool wxControl::OS2CreateControl(
109 const wxChar* zClassname
110, WXDWORD dwStyle
111, const wxPoint& rPos
112, const wxSize& rSize
113, const wxString& rsLabel
114, WXDWORD dwExstyle
115)
0e320a79 116{
5d44b24e
DW
117 int nX = rPos.x == -1 ? 0 : rPos.x;
118 int nY = rPos.y == -1 ? 0 : rPos.y;
119 int nW = rSize.x == -1 ? 0 : rSize.x;
120 int nH = rSize.y == -1 ? 0 : rSize.y;
c9cb56f7
DW
121 //
122 // Doesn't do anything at all under OS/2
123 //
124 if (dwExstyle == (WXDWORD)-1)
3d62dcb6 125 {
c9cb56f7 126 dwExstyle = GetExStyle(dwStyle);
3d62dcb6
DW
127 }
128
5d44b24e
DW
129 wxWindow* pParent = GetParent();
130 PSZ zClass;
45fcbf3b 131
5d44b24e 132 if (!pParent)
45fcbf3b 133 return FALSE;
0cf6acbf
DW
134
135 if ((strcmp(zClassname, "COMBOBOX")) == 0)
136 zClass = WC_COMBOBOX;
3c299c3a
DW
137 else if ((strcmp(zClassname, "STATIC")) == 0)
138 zClass = WC_STATIC;
1b086de1
DW
139 else if ((strcmp(zClassname, "BUTTON")) == 0)
140 zClass = WC_BUTTON;
c9cb56f7 141 dwStyle |= WS_VISIBLE;
5d44b24e
DW
142
143 //
144 // If the parent is a scrolled window the controls must
145 // have this style or they will overlap the scrollbars
146 //
147 if (pParent)
148 if (pParent->IsKindOf(CLASSINFO(wxScrolledWindow)) ||
149 pParent->IsKindOf(CLASSINFO(wxGenericScrolledWindow)))
150 dwStyle |= WS_CLIPSIBLINGS;
151
152 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
153 ,(PSZ)zClass // Window class
154 ,(PSZ)rsLabel.c_str() // Initial Text
155 ,(ULONG)dwStyle // Style flags
156 ,(LONG)0 // X pos of origin
157 ,(LONG)0 // Y pos of origin
158 ,(LONG)0 // control width
159 ,(LONG)0 // control height
160 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
161 ,HWND_TOP // initial z position
162 ,(ULONG)GetId() // Window identifier
163 ,NULL // no control data
164 ,NULL // no Presentation parameters
c9cb56f7
DW
165 );
166
5d44b24e
DW
167 if ( !m_hWnd )
168 {
169#ifdef __WXDEBUG__
170 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
171#endif // DEBUG
172
173 return FALSE;
174 }
c9cb56f7
DW
175 //
176 // Subclass again for purposes of dialog editing mode
177 //
45fcbf3b
DW
178 SubclassWin(m_hWnd);
179
c9cb56f7
DW
180 //
181 // Controls use the same font and colours as their parent dialog by default
182 //
45fcbf3b 183 InheritAttributes();
5d44b24e
DW
184 if (nW == 0 || nH == 0)
185 SetBestSize(rSize);
45fcbf3b 186 return TRUE;
c9cb56f7 187} // end of wxControl::OS2CreateControl
0e320a79 188
e78c4d50 189wxSize wxControl::DoGetBestSize() const
0e320a79 190{
45fcbf3b 191 return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT);
c9cb56f7 192} // end of wxControl::DoGetBestSize
0e320a79 193
45fcbf3b 194bool wxControl::ProcessCommand(wxCommandEvent& event)
0e320a79 195{
45fcbf3b
DW
196#if WXWIN_COMPATIBILITY
197 if ( m_callback )
0e320a79 198 {
45fcbf3b
DW
199 (void)(*m_callback)(this, event);
200
201 return TRUE;
0e320a79
DW
202 }
203 else
45fcbf3b
DW
204#endif // WXWIN_COMPATIBILITY
205
206 return GetEventHandler()->ProcessEvent(event);
207}
208
c9cb56f7
DW
209WXHBRUSH wxControl::OnCtlColor(
210 WXHDC hWxDC
211, WXHWND hWnd
212, WXUINT uCtlColor
213, WXUINT uMessage
214, WXWPARAM wParam
215, WXLPARAM lParam
216)
45fcbf3b 217{
c9cb56f7
DW
218 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
219 wxColour vColFore = GetForegroundColour();
220 wxColour vColBack = GetBackgroundColour();
45fcbf3b 221
c9cb56f7
DW
222 if (GetParent()->GetTransparentBackground())
223 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
224 else
225 ::GpiSetBackMix(hPS, BM_OVERPAINT);
45fcbf3b 226
c9cb56f7
DW
227 ::GpiSetBackColor(hPS, vColBack.GetPixel());
228 ::GpiSetColor(hPS, vColFore.GetPixel());
45fcbf3b 229
c9cb56f7
DW
230 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
231 ,wxSOLID
232 );
233 return (WXHBRUSH)pBrush->GetResourceHandle();
234} // end of wxControl::OnCtlColor
0e320a79 235
c9cb56f7
DW
236void wxControl::OnEraseBackground(
237 wxEraseEvent& rEvent
238)
45fcbf3b 239{
c9cb56f7
DW
240 RECTL vRect;
241 HPS hPS = rEvent.GetDC()->GetHPS();
242 SIZEL vSize = {0,0};
243
244 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
245 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
246 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
247} // end of wxControl::OnEraseBackground
248
249WXDWORD wxControl::GetExStyle(
250 WXDWORD& rStyle
251) const
45fcbf3b 252{
c9cb56f7
DW
253 //
254 // Meaningless under OS/2, just return what was sent
255 //
256 WXDWORD exStyle = rStyle;
45fcbf3b
DW
257
258 return exStyle;
c9cb56f7 259} // end of wxControl::GetExStyle
45fcbf3b
DW
260
261// ---------------------------------------------------------------------------
262// global functions
263// ---------------------------------------------------------------------------
264
265// Call this repeatedly for several wnds to find the overall size
266// of the widget.
267// Call it initially with -1 for all values in rect.
268// Keep calling for other widgets, and rect will be modified
269// to calculate largest bounding rectangle.
c9cb56f7
DW
270void wxFindMaxSize(
271 WXHWND hWnd
272, RECT* pRect
273)
0e320a79 274{
c9cb56f7
DW
275 int nLeft = pRect->xLeft;
276 int nRight = pRect->xRight;
277 int nTop = pRect->yTop;
278 int nBottom = pRect->yBottom;
0e320a79 279
c9cb56f7 280 ::WinQueryWindowRect((HWND)hWnd, pRect);
0e320a79 281
c9cb56f7 282 if (nLeft < 0)
45fcbf3b 283 return;
0e320a79 284
c9cb56f7
DW
285 if (nLeft < pRect->xLeft)
286 pRect->xLeft = nLeft;
0e320a79 287
c9cb56f7
DW
288 if (nRight > pRect->xRight)
289 pRect->xRight = nRight;
0e320a79 290
c9cb56f7
DW
291 if (nTop < pRect->yTop)
292 pRect->yTop = nTop;
293
294 if (nBottom > pRect->yBottom)
295 pRect->yBottom = nBottom;
296} // end of wxFindMaxSize
0e320a79 297
0e320a79 298