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