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