]>
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/private.h" | |
26 | ||
27 | IMPLEMENT_ABSTRACT_CLASS(wxControl, wxWindow) | |
28 | ||
29 | BEGIN_EVENT_TABLE(wxControl, wxWindow) | |
30 | EVT_ERASE_BACKGROUND(wxControl::OnEraseBackground) | |
31 | END_EVENT_TABLE() | |
32 | ||
33 | // Item members | |
34 | wxControl::wxControl() | |
35 | { | |
36 | } // end of wxControl::wxControl | |
37 | ||
38 | bool wxControl::Create( wxWindow* pParent, | |
39 | wxWindowID vId, | |
40 | const wxPoint& rPos, | |
41 | const wxSize& rSize, | |
42 | long lStyle, | |
43 | const wxValidator& rValidator, | |
44 | const wxString& rsName ) | |
45 | { | |
46 | bool bRval = wxWindow::Create( pParent | |
47 | ,vId | |
48 | ,rPos | |
49 | ,rSize | |
50 | ,lStyle | |
51 | ,rsName | |
52 | ); | |
53 | if (bRval) | |
54 | { | |
55 | #if wxUSE_VALIDATORS | |
56 | SetValidator(rValidator); | |
57 | #endif | |
58 | } | |
59 | return bRval; | |
60 | } // end of wxControl::Create | |
61 | ||
62 | wxControl::~wxControl() | |
63 | { | |
64 | m_isBeingDeleted = true; | |
65 | } | |
66 | ||
67 | bool wxControl::OS2CreateControl( const wxChar* zClassname, | |
68 | const wxString& rsLabel, | |
69 | const wxPoint& rPos, | |
70 | const wxSize& rSize, | |
71 | long lStyle ) | |
72 | { | |
73 | WXDWORD dwExstyle; | |
74 | WXDWORD dwStyle = OS2GetStyle( lStyle, &dwExstyle ); | |
75 | ||
76 | return OS2CreateControl( zClassname | |
77 | ,dwStyle | |
78 | ,rPos | |
79 | ,rSize | |
80 | ,rsLabel | |
81 | ,dwExstyle | |
82 | ); | |
83 | } // end of wxControl::OS2CreateControl | |
84 | ||
85 | bool wxControl::OS2CreateControl( const wxChar* zClassname, | |
86 | WXDWORD dwStyle, | |
87 | const wxPoint& rPos, | |
88 | const wxSize& rSize, | |
89 | const wxString& rsLabel, | |
90 | WXDWORD dwExstyle ) | |
91 | { | |
92 | // | |
93 | // Doesn't do anything at all under OS/2 | |
94 | // | |
95 | if (dwExstyle == (WXDWORD)-1) | |
96 | { | |
97 | dwExstyle = 0; | |
98 | (void) OS2GetStyle(GetWindowStyle(), &dwExstyle); | |
99 | } | |
100 | // | |
101 | // All controls should have these styles (wxWidgets creates all controls | |
102 | // visible by default) | |
103 | // | |
104 | if (m_isShown ) | |
105 | dwStyle |= WS_VISIBLE; | |
106 | ||
107 | wxWindow* pParent = GetParent(); | |
108 | PSZ zClass = ""; | |
109 | ||
110 | if (!pParent) | |
111 | return false; | |
112 | ||
113 | if ((wxStrcmp(zClassname, _T("COMBOBOX"))) == 0) | |
114 | zClass = WC_COMBOBOX; | |
115 | else if ((wxStrcmp(zClassname, _T("STATIC"))) == 0) | |
116 | zClass = WC_STATIC; | |
117 | else if ((wxStrcmp(zClassname, _T("BUTTON"))) == 0) | |
118 | zClass = WC_BUTTON; | |
119 | else if ((wxStrcmp(zClassname, _T("NOTEBOOK"))) == 0) | |
120 | zClass = WC_NOTEBOOK; | |
121 | else if ((wxStrcmp(zClassname, _T("CONTAINER"))) == 0) | |
122 | zClass = WC_CONTAINER; | |
123 | if ((zClass == WC_STATIC) || (zClass == WC_BUTTON)) | |
124 | dwStyle |= DT_MNEMONIC; | |
125 | ||
126 | m_dwStyle = dwStyle; | |
127 | m_label = rsLabel; | |
128 | wxString label; | |
129 | if (dwStyle & DT_MNEMONIC) | |
130 | label = ::wxPMTextToLabel(m_label); | |
131 | else | |
132 | label = m_label; | |
133 | ||
134 | // clipping siblings does not yet work | |
135 | dwStyle &= ~WS_CLIPSIBLINGS; | |
136 | ||
137 | m_hWnd = (WXHWND)::WinCreateWindow( (HWND)GetHwndOf(pParent) // Parent window handle | |
138 | ,zClass // Window class | |
139 | ,label.c_str() // Initial Text | |
140 | ,(ULONG)dwStyle // Style flags | |
141 | ,(LONG)0 // X pos of origin | |
142 | ,(LONG)0 // Y pos of origin | |
143 | ,(LONG)0 // control width | |
144 | ,(LONG)0 // control height | |
145 | ,(HWND)GetHwndOf(pParent) // owner window handle (same as parent | |
146 | ,HWND_TOP // initial z position | |
147 | ,(ULONG)GetId() // Window identifier | |
148 | ,NULL // no control data | |
149 | ,NULL // no Presentation parameters | |
150 | ); | |
151 | ||
152 | if ( !m_hWnd ) | |
153 | { | |
154 | #ifdef __WXDEBUG__ | |
155 | wxLogError(wxT("Failed to create a control of class '%s'"), zClassname); | |
156 | #endif // DEBUG | |
157 | ||
158 | return false; | |
159 | } | |
160 | // | |
161 | // Subclass again for purposes of dialog editing mode | |
162 | // | |
163 | SubclassWin(m_hWnd); | |
164 | ||
165 | // | |
166 | // Controls use the same colours as their parent dialog by default | |
167 | // | |
168 | InheritAttributes(); | |
169 | // | |
170 | // All OS/2 ctrls use the small font | |
171 | // | |
172 | SetFont(*wxSMALL_FONT); | |
173 | ||
174 | SetXComp(0); | |
175 | SetYComp(0); | |
176 | SetSize( rPos.x, rPos.y, rSize.x, rSize.y ); | |
177 | return true; | |
178 | } // end of wxControl::OS2CreateControl | |
179 | ||
180 | wxSize wxControl::DoGetBestSize() const | |
181 | { | |
182 | return wxSize(DEFAULT_ITEM_WIDTH, DEFAULT_ITEM_HEIGHT); | |
183 | } // end of wxControl::DoGetBestSize | |
184 | ||
185 | bool wxControl::ProcessCommand(wxCommandEvent& event) | |
186 | { | |
187 | return HandleWindowEvent(event); | |
188 | } | |
189 | ||
190 | WXHBRUSH wxControl::OnCtlColor(WXHDC hWxDC, | |
191 | WXHWND WXUNUSED(hWnd), | |
192 | WXUINT WXUNUSED(uCtlColor), | |
193 | WXUINT WXUNUSED(uMessage), | |
194 | WXWPARAM WXUNUSED(wParam), | |
195 | WXLPARAM WXUNUSED(lParam)) | |
196 | { | |
197 | HPS hPS = (HPS)hWxDC; // pass in a PS handle in OS/2 | |
198 | wxColour vColFore = GetForegroundColour(); | |
199 | wxColour vColBack = GetBackgroundColour(); | |
200 | ||
201 | if (GetParent()->GetTransparentBackground()) | |
202 | ::GpiSetBackMix(hPS, BM_LEAVEALONE); | |
203 | else | |
204 | ::GpiSetBackMix(hPS, BM_OVERPAINT); | |
205 | ||
206 | ::GpiSetBackColor(hPS, vColBack.GetPixel()); | |
207 | ::GpiSetColor(hPS, vColFore.GetPixel()); | |
208 | ||
209 | wxBrush* pBrush = wxTheBrushList->FindOrCreateBrush( vColBack | |
210 | ,wxSOLID | |
211 | ); | |
212 | return (WXHBRUSH)pBrush->GetResourceHandle(); | |
213 | } // end of wxControl::OnCtlColor | |
214 | ||
215 | void wxControl::OnEraseBackground( wxEraseEvent& rEvent ) | |
216 | { | |
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 | ||
226 | WXDWORD wxControl::OS2GetStyle( long lStyle, WXDWORD* pdwExstyle ) const | |
227 | { | |
228 | long dwStyle = wxWindow::OS2GetStyle( lStyle, pdwExstyle ); | |
229 | ||
230 | if (AcceptsFocusFromKeyboard()) | |
231 | { | |
232 | dwStyle |= WS_TABSTOP; | |
233 | } | |
234 | return dwStyle; | |
235 | } // end of wxControl::OS2GetStyle | |
236 | ||
237 | void wxControl::SetLabel( const wxString& rsLabel ) | |
238 | { | |
239 | if(rsLabel != m_label) | |
240 | { | |
241 | m_label = rsLabel; | |
242 | wxString label; | |
243 | if (m_dwStyle & DT_MNEMONIC) | |
244 | label = ::wxPMTextToLabel(m_label); | |
245 | else | |
246 | label = m_label; | |
247 | ::WinSetWindowText(GetHwnd(), label.c_str()); | |
248 | } | |
249 | } // end of wxControl::SetLabel | |
250 | ||
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. | |
260 | void wxFindMaxSize( | |
261 | WXHWND hWnd | |
262 | , RECT* pRect | |
263 | ) | |
264 | { | |
265 | int nLeft = pRect->xLeft; | |
266 | int nRight = pRect->xRight; | |
267 | int nTop = pRect->yTop; | |
268 | int nBottom = pRect->yBottom; | |
269 | ||
270 | ::WinQueryWindowRect((HWND)hWnd, pRect); | |
271 | ||
272 | if (nLeft < 0) | |
273 | return; | |
274 | ||
275 | if (nLeft < pRect->xLeft) | |
276 | pRect->xLeft = nLeft; | |
277 | ||
278 | if (nRight > pRect->xRight) | |
279 | pRect->xRight = nRight; | |
280 | ||
281 | if (nTop > pRect->yTop) | |
282 | pRect->yTop = nTop; | |
283 | ||
284 | if (nBottom < pRect->yBottom) | |
285 | pRect->yBottom = nBottom; | |
286 | } // end of wxFindMaxSize |