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