]>
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 | ||
88 | long lSstyle = 0L; | |
89 | ||
90 | lSstyle = WS_VISIBLE | | |
91 | WS_TABSTOP | | |
92 | SPBS_MASTER | // We use only single field spin buttons | |
93 | SPBS_NUMERICONLY; // We default to numeric data | |
94 | ||
95 | if (m_windowStyle & wxCLIP_SIBLINGS ) | |
96 | lSstyle |= WS_CLIPSIBLINGS; | |
97 | ||
3c299c3a DW |
98 | m_hWnd = (WXHWND)::WinCreateWindow( GetWinHwnd(pParent) |
99 | ,WC_SPINBUTTON | |
100 | ,(PSZ)NULL | |
101 | ,lSstyle | |
102 | ,0L, 0L, 0L, 0L | |
103 | ,GetWinHwnd(pParent) | |
104 | ,HWND_TOP | |
105 | ,(HMENU)vId | |
8787320b | 106 | ,NULL |
3c299c3a DW |
107 | ,NULL |
108 | ); | |
109 | if (m_hWnd == 0) | |
110 | { | |
111 | return FALSE; | |
112 | } | |
8787320b | 113 | SetRange(m_min, m_max); |
3c299c3a DW |
114 | if(pParent) |
115 | pParent->AddChild((wxSpinButton *)this); | |
116 | ||
d8a3f66c DW |
117 | ::WinQueryWindowPos(m_hWnd, &vSwp); |
118 | SetXComp(vSwp.x); | |
22c68581 | 119 | SetYComp(vSwp.y-5); // compensate for the associated TextControl border |
61a028dc SN |
120 | |
121 | SetFont(*wxSMALL_FONT); | |
3c299c3a DW |
122 | // |
123 | // For OS/2 we want to hide the text portion so we can substitute an | |
22c68581 SN |
124 | // independent text ctrl in its place. |
125 | // Therefore we must override any user given width with our best guess. | |
3c299c3a | 126 | // |
22c68581 SN |
127 | SetSize( nX - GetXComp() |
128 | ,nY - GetYComp() | |
129 | ,nWidth | |
3c299c3a DW |
130 | ,nHeight |
131 | ); | |
132 | wxAssociateWinWithHandle( m_hWnd | |
133 | ,(wxWindowOS2*)this | |
134 | ); | |
8787320b SN |
135 | #if 0 |
136 | // FIXME: | |
137 | // Apparently, this does not work, as it crashes in setvalue/setrange calls | |
138 | // What's it supposed to do anyway? | |
3c299c3a DW |
139 | ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this); |
140 | fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc); | |
8787320b | 141 | #endif |
3c299c3a DW |
142 | return TRUE; |
143 | } // end of wxSpinButton::Create | |
0e320a79 DW |
144 | |
145 | wxSpinButton::~wxSpinButton() | |
146 | { | |
3c299c3a | 147 | } // end of wxSpinButton::~wxSpinButton |
0e320a79 | 148 | |
409c9842 DW |
149 | // ---------------------------------------------------------------------------- |
150 | // size calculation | |
151 | // ---------------------------------------------------------------------------- | |
152 | ||
e78c4d50 | 153 | wxSize wxSpinButton::DoGetBestSize() const |
409c9842 | 154 | { |
3c299c3a | 155 | // |
61a028dc SN |
156 | // OS/2 PM does not really have system metrics so we'll just set it to |
157 | // a square based on its height. | |
3c299c3a | 158 | // |
61a028dc SN |
159 | RECTL vRect; |
160 | ::WinQueryWindowRect(GetHwnd(),&vRect); | |
161 | return wxSize(vRect.yTop,vRect.yTop); | |
3c299c3a | 162 | } // end of wxSpinButton::DoGetBestSize |
409c9842 DW |
163 | |
164 | // ---------------------------------------------------------------------------- | |
0e320a79 | 165 | // Attributes |
409c9842 | 166 | // ---------------------------------------------------------------------------- |
0e320a79 DW |
167 | |
168 | int wxSpinButton::GetValue() const | |
169 | { | |
3c299c3a DW |
170 | long lVal = 0L; |
171 | char zVal[10]; | |
172 | ||
173 | ::WinSendMsg( GetHwnd() | |
174 | ,SPBM_QUERYVALUE | |
175 | ,MPFROMP(zVal) | |
176 | ,MPFROM2SHORT( (USHORT)10 | |
177 | ,SPBQ_UPDATEIFVALID | |
178 | ) | |
179 | ); | |
180 | lVal = atol(zVal); | |
181 | return ((int)lVal); | |
182 | } // end of wxSpinButton::GetValue | |
183 | ||
6670f564 WS |
184 | bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation), |
185 | WXWORD WXUNUSED(wParam), | |
186 | WXWORD wPos, | |
187 | WXHWND hControl ) | |
0e320a79 | 188 | { |
637b7e4f | 189 | wxCHECK_MSG(hControl, false, wxT("scrolling what?") ); |
0e320a79 | 190 | |
6670f564 WS |
191 | wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId ); |
192 | int nVal = (int)wPos; // cast is important for negative values! | |
409c9842 | 193 | |
3c299c3a DW |
194 | vEvent.SetPosition(nVal); |
195 | vEvent.SetEventObject(this); | |
937013e0 | 196 | return(HandleWindowEvent(vEvent)); |
3c299c3a | 197 | } // end of wxSpinButton::OS2OnScroll |
409c9842 | 198 | |
6670f564 WS |
199 | bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd), |
200 | WXWORD WXUNUSED(wId) ) | |
409c9842 | 201 | { |
6670f564 | 202 | return false; |
3c299c3a | 203 | } // end of wxSpinButton::OS2Command |
409c9842 | 204 | |
3c299c3a DW |
205 | void wxSpinButton::SetRange( |
206 | int nMinVal | |
207 | , int nMaxVal | |
208 | ) | |
0e320a79 | 209 | { |
3c299c3a DW |
210 | m_min = nMinVal; |
211 | m_max = nMaxVal; | |
212 | ||
213 | ::WinSendMsg( GetHwnd() | |
214 | ,SPBM_SETLIMITS | |
215 | ,MPFROMLONG(nMaxVal) | |
216 | ,MPFROMLONG(nMinVal) | |
217 | ); | |
218 | } // end of wxSpinButton::SetRange | |
219 | ||
220 | void wxSpinButton::SetValue( | |
221 | int nValue | |
222 | ) | |
223 | { | |
224 | ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE, MPFROMLONG(nValue), MPARAM(0)); | |
225 | } // end of wxSpinButton::SetValue | |
0e320a79 | 226 | |
7e99520b | 227 | #endif //wxUSE_SPINBTN |