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