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