]> git.saurik.com Git - wxWidgets.git/blob - src/os2/control.cpp
rtti api mods added
[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 #ifdef __GNUG__
13 #pragma implementation "control.h"
14 #endif
15
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"
23 #include "wx/scrolwin.h"
24 #include "wx/log.h"
25 #endif
26 #include "wx/os2/private.h"
27 #include "wx/control.h"
28
29 IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow)
30
31 BEGIN_EVENT_TABLE(wxControl, wxWindow)
32 EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground)
33 END_EVENT_TABLE()
34
35 // Item members
36 wxControl::wxControl()
37 {
38 } // end of wxControl::wxControl
39
40 bool wxControl::Create(
41 wxWindow* pParent
42 , wxWindowID vId
43 , const wxPoint& rPos
44 , const wxSize& rSize
45 , long lStyle
46 , const wxValidator& rValidator
47 , const wxString& rsName
48 )
49 {
50 bool bRval = wxWindow::Create( pParent
51 ,vId
52 ,rPos
53 ,rSize
54 ,lStyle
55 ,rsName
56 );
57 if (bRval)
58 {
59 #if wxUSE_VALIDATORS
60 SetValidator(rValidator);
61 #endif
62 }
63 return bRval;
64 } // end of wxControl::Create
65
66 wxControl::~wxControl()
67 {
68 m_isBeingDeleted = TRUE;
69 }
70
71 bool wxControl::OS2CreateControl(
72 const wxChar* zClassname
73 , const wxString& rsLabel
74 , const wxPoint& rPos
75 , const wxSize& rSize
76 , long lStyle
77 )
78 {
79 WXDWORD dwExstyle;
80 WXDWORD dwStyle = OS2GetStyle( lStyle
81 ,&dwExstyle
82 );
83
84 return OS2CreateControl( zClassname
85 ,dwStyle
86 ,rPos
87 ,rSize
88 ,rsLabel
89 ,dwExstyle
90 );
91 } // end of wxControl::OS2CreateControl
92
93 bool wxControl::OS2CreateControl(
94 const wxChar* zClassname
95 , WXDWORD dwStyle
96 , const wxPoint& rPos
97 , const wxSize& rSize
98 , const wxString& rsLabel
99 , WXDWORD dwExstyle
100 )
101 {
102 bool bWant3D = FALSE;
103
104 //
105 // Doesn't do anything at all under OS/2
106 //
107 if (dwExstyle == (WXDWORD)-1)
108 {
109 dwExstyle = Determine3DEffects(WS_EX_CLIENTEDGE, &bWant3D);
110 }
111 //
112 // All controls should have these styles (wxWindows creates all controls
113 // visible by default)
114 //
115 if (m_isShown )
116 dwStyle |= WS_VISIBLE;
117
118 wxWindow* pParent = GetParent();
119 PSZ zClass;
120
121 if (!pParent)
122 return FALSE;
123
124 if ((strcmp(zClassname, "COMBOBOX")) == 0)
125 zClass = WC_COMBOBOX;
126 else if ((strcmp(zClassname, "STATIC")) == 0)
127 zClass = WC_STATIC;
128 else if ((strcmp(zClassname, "BUTTON")) == 0)
129 zClass = WC_BUTTON;
130 else if ((strcmp(zClassname, "NOTEBOOK")) == 0)
131 zClass = WC_NOTEBOOK;
132 else if ((strcmp(zClassname, "CONTAINER")) == 0)
133 zClass = WC_CONTAINER;
134 dwStyle |= WS_VISIBLE;
135
136 m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle
137 ,(PSZ)zClass // Window class
138 ,(PSZ)rsLabel.c_str() // Initial Text
139 ,(ULONG)dwStyle // Style flags
140 ,(LONG)0 // X pos of origin
141 ,(LONG)0 // Y pos of origin
142 ,(LONG)0 // control width
143 ,(LONG)0 // control height
144 ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent
145 ,HWND_TOP // initial z position
146 ,(ULONG)GetId() // Window identifier
147 ,NULL // no control data
148 ,NULL // no Presentation parameters
149 );
150
151 if ( !m_hWnd )
152 {
153 #ifdef __WXDEBUG__
154 wxLogError(wxT("Failed to create a control of class '%s'"), zClassname);
155 #endif // DEBUG
156
157 return FALSE;
158 }
159 //
160 // Subclass again for purposes of dialog editing mode
161 //
162 SubclassWin(m_hWnd);
163
164 //
165 // Controls use the same font and colours as their parent dialog by default
166 //
167 InheritAttributes();
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(
189 WXHDC hWxDC
190 , WXHWND hWnd
191 , WXUINT uCtlColor
192 , WXUINT uMessage
193 , WXWPARAM wParam
194 , WXLPARAM lParam
195 )
196 {
197 HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2
198 wxColour vColFore = GetForegroundColour();
199 wxColour vColBack = GetBackgroundColour();
200
201 if (GetParent()->GetTransparentBackground())
202 ::GpiSetBackMix(hPS, BM_LEAVEALONE);
203 else
204 ::GpiSetBackMix(hPS, BM_OVERPAINT);
205
206 ::GpiSetBackColor(hPS, vColBack.GetPixel());
207 ::GpiSetColor(hPS, vColFore.GetPixel());
208
209 wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack
210 ,wxSOLID
211 );
212 return (WXHBRUSH)pBrush->GetResourceHandle();
213 } // end of wxControl::OnCtlColor
214
215 void wxControl::OnEraseBackground(
216 wxEraseEvent& rEvent
217 )
218 {
219 RECTL vRect;
220 HPS hPS = rEvent.GetDC()->GetHPS();
221 SIZEL vSize = {0,0};
222
223 ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT);
224 ::WinQueryWindowRect((HWND)GetHwnd(), &vRect);
225 ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel());
226 } // end of wxControl::OnEraseBackground
227
228 WXDWORD wxControl::OS2GetStyle(
229 long lStyle
230 , WXDWORD* pdwExstyle
231 ) const
232 {
233 long dwStyle = wxWindow::OS2GetStyle( lStyle
234 ,pdwExstyle
235 );
236
237 if (AcceptsFocus())
238 {
239 dwStyle |= WS_TABSTOP;
240 }
241 return dwStyle;
242 } // end of wxControl::OS2GetStyle
243
244 // ---------------------------------------------------------------------------
245 // global functions
246 // ---------------------------------------------------------------------------
247
248 // Call this repeatedly for several wnds to find the overall size
249 // of the widget.
250 // Call it initially with -1 for all values in rect.
251 // Keep calling for other widgets, and rect will be modified
252 // to calculate largest bounding rectangle.
253 void wxFindMaxSize(
254 WXHWND hWnd
255 , RECT* pRect
256 )
257 {
258 int nLeft = pRect->xLeft;
259 int nRight = pRect->xRight;
260 int nTop = pRect->yTop;
261 int nBottom = pRect->yBottom;
262
263 ::WinQueryWindowRect((HWND)hWnd, pRect);
264
265 if (nLeft < 0)
266 return;
267
268 if (nLeft < pRect->xLeft)
269 pRect->xLeft = nLeft;
270
271 if (nRight > pRect->xRight)
272 pRect->xRight = nRight;
273
274 if (nTop < pRect->yTop)
275 pRect->yTop = nTop;
276
277 if (nBottom > pRect->yBottom)
278 pRect->yBottom = nBottom;
279 } // end of wxFindMaxSize
280
281