]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: control.cpp | |
3 | // Purpose: wxControl class | |
45fcbf3b | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
45fcbf3b | 6 | // Created: 09/17/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
6aa89a22 | 8 | // Copyright: (c) Julian Smart |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifdef __GNUG__ | |
13 | #pragma implementation "control.h" | |
14 | #endif | |
15 | ||
45fcbf3b DW |
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" | |
a4a16252 | 23 | #include "wx/scrolwin.h" |
6eb280e9 | 24 | #include "wx/log.h" |
45fcbf3b | 25 | #endif |
86de7616 | 26 | #include "wx/os2/private.h" |
0e320a79 DW |
27 | #include "wx/control.h" |
28 | ||
0e320a79 DW |
29 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) |
30 | ||
31 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
45fcbf3b | 32 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) |
0e320a79 | 33 | END_EVENT_TABLE() |
0e320a79 DW |
34 | |
35 | // Item members | |
36 | wxControl::wxControl() | |
37 | { | |
c9cb56f7 DW |
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 | |
c9cb56f7 | 46 | , const wxValidator& rValidator |
c9cb56f7 DW |
47 | , const wxString& rsName |
48 | ) | |
3d62dcb6 | 49 | { |
c9cb56f7 DW |
50 | bool bRval = wxWindow::Create( pParent |
51 | ,vId | |
52 | ,rPos | |
53 | ,rSize | |
54 | ,lStyle | |
55 | ,rsName | |
56 | ); | |
57 | if (bRval) | |
58 | { | |
3d62dcb6 | 59 | #if wxUSE_VALIDATORS |
c9cb56f7 | 60 | SetValidator(rValidator); |
3d62dcb6 DW |
61 | #endif |
62 | } | |
c9cb56f7 DW |
63 | return bRval; |
64 | } // end of wxControl::Create | |
3d62dcb6 | 65 | |
0e320a79 DW |
66 | wxControl::~wxControl() |
67 | { | |
6670f564 | 68 | m_isBeingDeleted = true; |
0e320a79 DW |
69 | } |
70 | ||
0cf6acbf | 71 | bool wxControl::OS2CreateControl( |
b9b1d6c8 DW |
72 | const wxChar* zClassname |
73 | , const wxString& rsLabel | |
0cf6acbf DW |
74 | , const wxPoint& rPos |
75 | , const wxSize& rSize | |
76 | , long lStyle | |
0cf6acbf DW |
77 | ) |
78 | { | |
b9b1d6c8 DW |
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 | ); | |
0cf6acbf DW |
91 | } // end of wxControl::OS2CreateControl |
92 | ||
6670f564 WS |
93 | bool wxControl::OS2CreateControl( const wxChar* zClassname, |
94 | WXDWORD dwStyle, | |
95 | const wxPoint& rPos, | |
96 | const wxSize& rSize, | |
97 | const wxString& rsLabel, | |
98 | WXDWORD dwExstyle ) | |
0e320a79 | 99 | { |
c9cb56f7 DW |
100 | // |
101 | // Doesn't do anything at all under OS/2 | |
102 | // | |
103 | if (dwExstyle == (WXDWORD)-1) | |
3d62dcb6 | 104 | { |
0093fe11 | 105 | dwExstyle = 0; |
6670f564 | 106 | (void) OS2GetStyle(GetWindowStyle(), &dwExstyle); |
3d62dcb6 | 107 | } |
b9b1d6c8 | 108 | // |
77ffb593 | 109 | // All controls should have these styles (wxWidgets creates all controls |
b9b1d6c8 DW |
110 | // visible by default) |
111 | // | |
cfcebdb1 DW |
112 | if (m_isShown ) |
113 | dwStyle |= WS_VISIBLE; | |
3d62dcb6 | 114 | |
5d44b24e | 115 | wxWindow* pParent = GetParent(); |
322d45dd | 116 | PSZ zClass = ""; |
45fcbf3b | 117 | |
5d44b24e | 118 | if (!pParent) |
45fcbf3b | 119 | return FALSE; |
0cf6acbf | 120 | |
0fba44b4 | 121 | if ((wxStrcmp(zClassname, _T("COMBOBOX"))) == 0) |
0cf6acbf | 122 | zClass = WC_COMBOBOX; |
0fba44b4 | 123 | else if ((wxStrcmp(zClassname, _T("STATIC"))) == 0) |
3c299c3a | 124 | zClass = WC_STATIC; |
0fba44b4 | 125 | else if ((wxStrcmp(zClassname, _T("BUTTON"))) == 0) |
1b086de1 | 126 | zClass = WC_BUTTON; |
0fba44b4 | 127 | else if ((wxStrcmp(zClassname, _T("NOTEBOOK"))) == 0) |
f289196b | 128 | zClass = WC_NOTEBOOK; |
0fba44b4 | 129 | else if ((wxStrcmp(zClassname, _T("CONTAINER"))) == 0) |
4fd899b6 | 130 | zClass = WC_CONTAINER; |
c9cb56f7 | 131 | dwStyle |= WS_VISIBLE; |
5d44b24e | 132 | |
e94d504d SN |
133 | wxString sLabel = ::wxPMTextToLabel(rsLabel); |
134 | ||
5d44b24e DW |
135 | m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle |
136 | ,(PSZ)zClass // Window class | |
e94d504d | 137 | ,(PSZ)sLabel.c_str() // Initial Text |
5d44b24e DW |
138 | ,(ULONG)dwStyle // Style flags |
139 | ,(LONG)0 // X pos of origin | |
140 | ,(LONG)0 // Y pos of origin | |
141 | ,(LONG)0 // control width | |
142 | ,(LONG)0 // control height | |
143 | ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent | |
144 | ,HWND_TOP // initial z position | |
145 | ,(ULONG)GetId() // Window identifier | |
146 | ,NULL // no control data | |
147 | ,NULL // no Presentation parameters | |
c9cb56f7 DW |
148 | ); |
149 | ||
5d44b24e DW |
150 | if ( !m_hWnd ) |
151 | { | |
152 | #ifdef __WXDEBUG__ | |
153 | wxLogError(wxT("Failed to create a control of class '%s'"), zClassname); | |
154 | #endif // DEBUG | |
155 | ||
156 | return FALSE; | |
157 | } | |
c9cb56f7 DW |
158 | // |
159 | // Subclass again for purposes of dialog editing mode | |
160 | // | |
45fcbf3b DW |
161 | SubclassWin(m_hWnd); |
162 | ||
c9cb56f7 | 163 | // |
31d7fc0f | 164 | // Controls use the same colours as their parent dialog by default |
c9cb56f7 | 165 | // |
45fcbf3b | 166 | InheritAttributes(); |
31d7fc0f VZ |
167 | // |
168 | // All OS/2 ctrls use the small font | |
169 | // | |
170 | SetFont(*wxSMALL_FONT); | |
171 | ||
70a2c656 DW |
172 | SetXComp(0); |
173 | SetYComp(0); | |
f289196b DW |
174 | SetSize( rPos.x |
175 | ,rPos.y | |
176 | ,rSize.x | |
177 | ,rSize.y | |
178 | ); | |
6670f564 | 179 | return true; |
c9cb56f7 | 180 | } // end of wxControl::OS2CreateControl |
0e320a79 | 181 | |
e78c4d50 | 182 | wxSize wxControl::DoGetBestSize() const |
0e320a79 | 183 | { |
45fcbf3b | 184 | return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); |
c9cb56f7 | 185 | } // end of wxControl::DoGetBestSize |
0e320a79 | 186 | |
45fcbf3b | 187 | bool wxControl::ProcessCommand(wxCommandEvent& event) |
0e320a79 | 188 | { |
45fcbf3b DW |
189 | return GetEventHandler()->ProcessEvent(event); |
190 | } | |
191 | ||
6670f564 WS |
192 | WXHBRUSH wxControl::OnCtlColor(WXHDC hWxDC, |
193 | WXHWND WXUNUSED(hWnd), | |
194 | WXUINT WXUNUSED(uCtlColor), | |
195 | WXUINT WXUNUSED(uMessage), | |
196 | WXWPARAM WXUNUSED(wParam), | |
197 | WXLPARAM WXUNUSED(lParam)) | |
45fcbf3b | 198 | { |
6670f564 WS |
199 | HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2 |
200 | wxColour vColFore = GetForegroundColour(); | |
201 | wxColour vColBack = GetBackgroundColour(); | |
45fcbf3b | 202 | |
c9cb56f7 DW |
203 | if (GetParent()->GetTransparentBackground()) |
204 | ::GpiSetBackMix(hPS, BM_LEAVEALONE); | |
205 | else | |
206 | ::GpiSetBackMix(hPS, BM_OVERPAINT); | |
45fcbf3b | 207 | |
c9cb56f7 DW |
208 | ::GpiSetBackColor(hPS, vColBack.GetPixel()); |
209 | ::GpiSetColor(hPS, vColFore.GetPixel()); | |
45fcbf3b | 210 | |
6670f564 WS |
211 | wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack |
212 | ,wxSOLID | |
213 | ); | |
c9cb56f7 DW |
214 | return (WXHBRUSH)pBrush->GetResourceHandle(); |
215 | } // end of wxControl::OnCtlColor | |
0e320a79 | 216 | |
c9cb56f7 DW |
217 | void wxControl::OnEraseBackground( |
218 | wxEraseEvent& rEvent | |
219 | ) | |
45fcbf3b | 220 | { |
c9cb56f7 DW |
221 | RECTL vRect; |
222 | HPS hPS = rEvent.GetDC()->GetHPS(); | |
223 | SIZEL vSize = {0,0}; | |
224 | ||
225 | ::GpiSetPS(hPS, &vSize, PU_PELS | GPIF_DEFAULT); | |
226 | ::WinQueryWindowRect((HWND)GetHwnd(), &vRect); | |
227 | ::WinFillRect(hPS, &vRect, GetBackgroundColour().GetPixel()); | |
228 | } // end of wxControl::OnEraseBackground | |
229 | ||
b9b1d6c8 DW |
230 | WXDWORD wxControl::OS2GetStyle( |
231 | long lStyle | |
232 | , WXDWORD* pdwExstyle | |
c9cb56f7 | 233 | ) const |
45fcbf3b | 234 | { |
b9b1d6c8 DW |
235 | long dwStyle = wxWindow::OS2GetStyle( lStyle |
236 | ,pdwExstyle | |
237 | ); | |
45fcbf3b | 238 | |
b9b1d6c8 DW |
239 | if (AcceptsFocus()) |
240 | { | |
241 | dwStyle |= WS_TABSTOP; | |
242 | } | |
243 | return dwStyle; | |
244 | } // end of wxControl::OS2GetStyle | |
45fcbf3b | 245 | |
d37bb826 SN |
246 | void wxControl::SetLabel( |
247 | const wxString& rsLabel | |
248 | ) | |
249 | { | |
250 | wxString sLabel = ::wxPMTextToLabel(rsLabel); | |
251 | ||
0fba44b4 | 252 | ::WinSetWindowText(GetHwnd(), (PSZ)sLabel.c_str()); |
d37bb826 SN |
253 | } // end of wxControl::SetLabel |
254 | ||
45fcbf3b DW |
255 | // --------------------------------------------------------------------------- |
256 | // global functions | |
257 | // --------------------------------------------------------------------------- | |
258 | ||
259 | // Call this repeatedly for several wnds to find the overall size | |
260 | // of the widget. | |
261 | // Call it initially with -1 for all values in rect. | |
262 | // Keep calling for other widgets, and rect will be modified | |
263 | // to calculate largest bounding rectangle. | |
c9cb56f7 DW |
264 | void wxFindMaxSize( |
265 | WXHWND hWnd | |
266 | , RECT* pRect | |
267 | ) | |
0e320a79 | 268 | { |
c9cb56f7 DW |
269 | int nLeft = pRect->xLeft; |
270 | int nRight = pRect->xRight; | |
271 | int nTop = pRect->yTop; | |
272 | int nBottom = pRect->yBottom; | |
0e320a79 | 273 | |
c9cb56f7 | 274 | ::WinQueryWindowRect((HWND)hWnd, pRect); |
0e320a79 | 275 | |
c9cb56f7 | 276 | if (nLeft < 0) |
45fcbf3b | 277 | return; |
0e320a79 | 278 | |
c9cb56f7 DW |
279 | if (nLeft < pRect->xLeft) |
280 | pRect->xLeft = nLeft; | |
0e320a79 | 281 | |
c9cb56f7 DW |
282 | if (nRight > pRect->xRight) |
283 | pRect->xRight = nRight; | |
0e320a79 | 284 | |
09990d5a | 285 | if (nTop > pRect->yTop) |
c9cb56f7 DW |
286 | pRect->yTop = nTop; |
287 | ||
09990d5a | 288 | if (nBottom < pRect->yBottom) |
c9cb56f7 DW |
289 | pRect->yBottom = nBottom; |
290 | } // end of wxFindMaxSize |