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