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