]> git.saurik.com Git - wxWidgets.git/blob - src/os2/spinbutt.cpp
Fix splitting message into title in body in MSW wxProgressDialog.
[wxWidgets.git] / src / os2 / spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/os2/spinbutt.cpp
3 // Purpose: wxSpinButton
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/15/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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"
18 #endif
19 #if wxUSE_SPINBTN
20
21 // Can't resolve reference to CreateUpDownControl in
22 // TWIN32, but could probably use normal CreateWindow instead.
23
24
25 #include "wx/spinbutt.h"
26
27 extern void wxAssociateWinWithHandle( HWND hWnd
28 ,wxWindowOS2* pWin
29 );
30
31 #include "wx/os2/private.h"
32
33 // ============================================================================
34 // implementation
35 // ============================================================================
36
37 // ----------------------------------------------------------------------------
38 // wxWin macros
39 // ----------------------------------------------------------------------------
40
41 bool wxSpinButton::Create(
42 wxWindow* pParent
43 , wxWindowID vId
44 , const wxPoint& rPos
45 , const wxSize& rSize
46 , long lStyle
47 , const wxString& rsName
48 )
49 {
50 int nX = rPos.x;
51 int nY = rPos.y;
52 int nWidth = rSize.x;
53 int nHeight = rSize.y;
54 SWP vSwp;
55
56 m_min = 0;
57 m_max = 100;
58 if (vId == -1)
59 m_windowId = NewControlId();
60 else
61 m_windowId = vId;
62 if (pParent)
63 {
64 m_backgroundColour = pParent->GetBackgroundColour();
65 m_foregroundColour = pParent->GetForegroundColour();
66 }
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();
77
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
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
106 ,NULL
107 ,NULL
108 );
109 if (m_hWnd == 0)
110 {
111 return FALSE;
112 }
113 SetRange(m_min, m_max);
114 if(pParent)
115 pParent->AddChild((wxSpinButton *)this);
116
117 ::WinQueryWindowPos(m_hWnd, &vSwp);
118 SetXComp(vSwp.x);
119 SetYComp(vSwp.y-5); // compensate for the associated TextControl border
120
121 SetFont(*wxSMALL_FONT);
122 //
123 // For OS/2 we want to hide the text portion so we can substitute an
124 // independent text ctrl in its place.
125 // Therefore we must override any user given width with our best guess.
126 //
127 SetSize( nX - GetXComp()
128 ,nY - GetYComp()
129 ,nWidth
130 ,nHeight
131 );
132 wxAssociateWinWithHandle( m_hWnd
133 ,(wxWindowOS2*)this
134 );
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?
139 ::WinSetWindowULong(GetHwnd(), QWL_USER, (LONG)this);
140 fnWndProcSpinCtrl = (WXFARPROC)::WinSubclassWindow(m_hWnd, (PFNWP)wxSpinCtrlWndProc);
141 #endif
142 return TRUE;
143 } // end of wxSpinButton::Create
144
145 wxSpinButton::~wxSpinButton()
146 {
147 } // end of wxSpinButton::~wxSpinButton
148
149 // ----------------------------------------------------------------------------
150 // size calculation
151 // ----------------------------------------------------------------------------
152
153 wxSize wxSpinButton::DoGetBestSize() const
154 {
155 //
156 // OS/2 PM does not really have system metrics so we'll just set it to
157 // a square based on its height.
158 //
159 RECTL vRect;
160 ::WinQueryWindowRect(GetHwnd(),&vRect);
161 return wxSize(vRect.yTop,vRect.yTop);
162 } // end of wxSpinButton::DoGetBestSize
163
164 // ----------------------------------------------------------------------------
165 // Attributes
166 // ----------------------------------------------------------------------------
167
168 int wxSpinButton::GetValue() const
169 {
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
184 bool wxSpinButton::OS2OnScroll( int WXUNUSED(nOrientation),
185 WXWORD WXUNUSED(wParam),
186 WXWORD wPos,
187 WXHWND hControl )
188 {
189 wxCHECK_MSG(hControl, false, wxT("scrolling what?") );
190
191 wxSpinEvent vEvent( wxEVT_SCROLL_THUMBTRACK, m_windowId );
192 int nVal = (int)wPos; // cast is important for negative values!
193
194 vEvent.SetPosition(nVal);
195 vEvent.SetEventObject(this);
196 return(HandleWindowEvent(vEvent));
197 } // end of wxSpinButton::OS2OnScroll
198
199 bool wxSpinButton::OS2Command( WXUINT WXUNUSED(uCmd),
200 WXWORD WXUNUSED(wId) )
201 {
202 return false;
203 } // end of wxSpinButton::OS2Command
204
205 void wxSpinButton::SetRange(
206 int nMinVal
207 , int nMaxVal
208 )
209 {
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
226
227 #endif //wxUSE_SPINBTN