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