]>
Commit | Line | Data |
---|---|---|
0e320a79 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/os2/spinbutt.cpp |
0e320a79 | 3 | // Purpose: wxSpinButton |
409c9842 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
409c9842 | 6 | // Created: 10/15/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
409c9842 | 8 | // Copyright: (c) David Webster |
65571936 | 9 | // Licence: wxWindows licence |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | ||
16 | #ifndef WX_PRECOMP | |
17 | #include "wx/wx.h" | |
0e320a79 | 18 | #endif |
7e99520b | 19 | #if wxUSE_SPINBTN |
0e320a79 | 20 | |
409c9842 DW |
21 | // Can't resolve reference to CreateUpDownControl in |
22 | // TWIN32, but could probably use normal CreateWindow instead. | |
23 | ||
24 | ||
0e320a79 | 25 | #include "wx/spinbutt.h" |
3bfbab1e | 26 | |
3c299c3a DW |
27 | extern void wxAssociateWinWithHandle( HWND hWnd |
28 | ,wxWindowOS2* pWin | |
29 | ); | |
3c299c3a | 30 | |
409c9842 DW |
31 | #include "wx/os2/private.h" |
32 | ||
33 | // ============================================================================ | |
34 | // implementation | |
35 | // ============================================================================ | |
36 | ||
37 | // ---------------------------------------------------------------------------- | |
38 | // wxWin macros | |
39 | // ---------------------------------------------------------------------------- | |
0e320a79 | 40 | |
409c9842 | 41 | bool wxSpinButton::Create( |
3c299c3a DW |
42 | wxWindow* pParent |
43 | , wxWindowID vId | |
44 | , const wxPoint& rPos | |
45 | , const wxSize& rSize | |
46 | , long lStyle | |
47 | , const wxString& rsName | |
409c9842 | 48 | ) |
0e320a79 | 49 | { |
3c299c3a DW |
50 | int nX = rPos.x; |
51 | int nY = rPos.y; | |
52 | int nWidth = rSize.x; | |
53 | int nHeight = rSize.y; | |
d8a3f66c | 54 | SWP vSwp; |
3c299c3a DW |
55 | |
56 | m_min = 0; | |
57 | m_max = 100; | |
58 | if (vId == -1) | |
59 | m_windowId = NewControlId(); | |
60 | else | |
61 | m_windowId = vId; | |
adfe3164 SN |
62 | if (pParent) |
63 | { | |
64 | m_backgroundColour = pParent->GetBackgroundColour(); | |
65 | m_foregroundColour = pParent->GetForegroundColour(); | |
66 | } | |
3c299c3a DW |
67 | SetName(rsName); |
68 | SetParent(pParent); | |
69 | m_windowStyle = lStyle; | |
70 | ||
71 | // | |
72 | // Get the right size for the control | |
73 | // | |
74 | if (nWidth <= 0 || nHeight <= 0 ) | |
75 | { | |
76 | wxSize vSize = DoGetBestSize(); | |
0e320a79 | 77 | |
3c299c3a DW |
78 | if (nWidth <= 0 ) |
79 | nWidth = vSize.x; | |
80 | if (nHeight <= 0 ) | |
81 | nHeight = vSize.y; | |
82 | } | |
83 | if (nX < 0 ) | |
84 | nX = 0; | |
85 | if (nY < 0 ) | |
86 | nY = 0; | |
87 | ||
bdc43642 VZ |
88 | long lSstyle = WS_VISIBLE | |
89 | WS_TABSTOP | | |
90 | SPBS_MASTER | // We use only single field spin buttons | |
91 | SPBS_NUMERICONLY; // We default to numeric data | |
3c299c3a DW |
92 | |
93 | if (m_windowStyle & wxCLIP_SIBLINGS ) | |
94 | lSstyle |= WS_CLIPSIBLINGS; | |
95 | ||
3c299c3a DW |
96 | m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) |
97 | ,WC_SPINBUTTON | |
98 | ,(PSZ)NULL | |
99 | ,lSstyle | |
100 | ,0L, 0L, 0L, 0L | |
101 | ,GetWinHwnd(pParent) | |
102 | ,HWND_TOP | |
103 | ,(HMENU)vId | |
8787320b | 104 | ,NULL |
3c299c3a DW |
105 | ,NULL |
106 | ); | |
107 | if (m_hWnd == 0) | |
108 | { | |
109 | return FALSE; | |
110 | } | |
8787320b | 111 | SetRange(m_min, m_max); |
3c299c3a DW |
112 | if(pParent) |
113 | pParent->AddChild((wxSpinButton *)this); | |
114 | ||
d8a3f66c DW |
115 | ::WinQueryWindowPos(m_hWnd, &vSwp); |
116 | SetXComp(vSwp.x); | |
22c68581 | 117 | SetYComp(vSwp.y-5); // compensate for the associated TextControl border |
61a028dc SN |
118 | |
119 | SetFont(*wxSMALL_FONT); | |
3c299c3a DW |
120 | // |
121 | // For OS/2 we want to hide the text portion so we can substitute an | |
22c68581 SN |
122 | // independent text ctrl in its place. |
123 | // Therefore we must override any user given width with our best guess. | |
3c299c3a | 124 | // |
22c68581 SN |
125 | SetSize( nX - GetXComp() |
126 | ,nY - GetYComp() | |
127 | ,nWidth | |
3c299c3a DW |
128 | ,nHeight |
129 | ); | |
130 | wxAssociateWinWithHandle( m_hWnd | |
131 | ,(wxWindowOS2*)this | |
132 | ); | |
8787320b SN |
133 | #if 0 |
134 | // FIXME: | |
135 | // Apparently, this does not work, as it crashes in setvalue/setrange calls | |
136 | // What's it supposed to do anyway? | |
3c299c3a DW |
137 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); |
138 | fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc); | |
8787320b | 139 | #endif |
3c299c3a DW |
140 | return TRUE; |
141 | } // end of wxSpinButton::Create | |
0e320a79 DW |
142 | |
143 | wxSpinButton::~wxSpinButton() | |
144 | { | |
3c299c3a | 145 | } // end of wxSpinButton::~wxSpinButton |
0e320a79 | 146 | |
409c9842 DW |
147 | // ---------------------------------------------------------------------------- |
148 | // size calculation | |
149 | // ---------------------------------------------------------------------------- | |
150 | ||
e78c4d50 | 151 | wxSize wxSpinButton::DoGetBestSize() const |
409c9842 | 152 | { |
3c299c3a | 153 | // |
61a028dc SN |
154 | // OS/2 PM does not really have system metrics so we'll just set it to |
155 | // a square based on its height. | |
3c299c3a | 156 | // |
61a028dc SN |
157 | RECTL vRect; |
158 | ::WinQueryWindowRect(GetHwnd(),&vRect); | |
159 | return wxSize(vRect.yTop,vRect.yTop); | |
3c299c3a | 160 | } // end of wxSpinButton::DoGetBestSize |
409c9842 DW |
161 | |
162 | // ---------------------------------------------------------------------------- | |
0e320a79 | 163 | // Attributes |
409c9842 | 164 | // ---------------------------------------------------------------------------- |
0e320a79 DW |
165 | |
166 | int wxSpinButton::GetValue() const | |
167 | { | |
3c299c3a DW |
168 | long lVal = 0L; |
169 | char zVal[10]; | |
170 | ||
171 | ::WinSendMsg( GetHwnd() | |
172 | ,SPBM_QUERYVALUE | |
173 | ,MPFROMP(zVal) | |
174 | ,MPFROM2SHORT( (USHORT)10 | |
175 | ,SPBQ_UPDATEIFVALID | |
176 | ) | |
177 | ); | |
178 | lVal = atol(zVal); | |
179 | return ((int)lVal); | |
180 | } // end of wxSpinButton::GetValue | |
181 | ||
6670f564 WS |
182 | bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation), |
183 | WXWORD WXUNUSED(wParam), | |
184 | WXWORD wPos, | |
185 | WXHWND hControl ) | |
0e320a79 | 186 | { |
637b7e4f | 187 | wxCHECK_MSG(hControl, false, wxT("scrolling what?") ); |
0e320a79 | 188 | |
6670f564 WS |
189 | wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId ); |
190 | int nVal = (int)wPos; // cast is important for negative values! | |
409c9842 | 191 | |
3c299c3a DW |
192 | vEvent.SetPosition(nVal); |
193 | vEvent.SetEventObject(this); | |
937013e0 | 194 | return(HandleWindowEvent(vEvent)); |
3c299c3a | 195 | } // end of wxSpinButton::OS2OnScroll |
409c9842 | 196 | |
6670f564 WS |
197 | bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd), |
198 | WXWORD WXUNUSED(wId) ) | |
409c9842 | 199 | { |
6670f564 | 200 | return false; |
3c299c3a | 201 | } // end of wxSpinButton::OS2Command |
409c9842 | 202 | |
3c299c3a DW |
203 | void wxSpinButton::SetRange( |
204 | int nMinVal | |
205 | , int nMaxVal | |
206 | ) | |
0e320a79 | 207 | { |
3c299c3a DW |
208 | m_min = nMinVal; |
209 | m_max = nMaxVal; | |
210 | ||
211 | ::WinSendMsg( GetHwnd() | |
212 | ,SPBM_SETLIMITS | |
213 | ,MPFROMLONG(nMaxVal) | |
214 | ,MPFROMLONG(nMinVal) | |
215 | ); | |
216 | } // end of wxSpinButton::SetRange | |
217 | ||
218 | void wxSpinButton::SetValue( | |
219 | int nValue | |
220 | ) | |
221 | { | |
222 | ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0)); | |
223 | } // end of wxSpinButton::SetValue | |
0e320a79 | 224 | |
7e99520b | 225 | #endif //wxUSE_SPINBTN |