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