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