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