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