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