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