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