1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxSpinButton
4 // Author: David Webster
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "spinbutt.h"
14 #pragma implementation "spinbutbase.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
26 // Can't resolve reference to CreateUpDownControl in
27 // TWIN32, but could probably use normal CreateWindow instead.
30 #include "wx/spinbutt.h"
32 extern void wxAssociateWinWithHandle( HWND hWnd
35 static WXFARPROC fnWndProcSpinCtrl
= (WXFARPROC
)NULL
;
37 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
39 #include "wx/os2/private.h"
41 // ============================================================================
43 // ============================================================================
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
49 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
51 bool wxSpinButton::Create(
57 , const wxString
& rsName
63 int nHeight
= rSize
.y
;
69 m_windowId
= NewControlId();
72 m_backgroundColour
= pParent
->GetBackgroundColour();
73 m_foregroundColour
= pParent
->GetForegroundColour();
76 m_windowStyle
= lStyle
;
79 // Get the right size for the control
81 if (nWidth
<= 0 || nHeight
<= 0 )
83 wxSize vSize
= DoGetBestSize();
97 lSstyle
= WS_VISIBLE
|
99 SPBS_MASTER
| // We use only single field spin buttons
100 SPBS_NUMERICONLY
; // We default to numeric data
102 if (m_windowStyle
& wxCLIP_SIBLINGS
)
103 lSstyle
|= WS_CLIPSIBLINGS
;
106 // If the parent is a scrolled window the controls must
107 // have this style or they will overlap the scrollbars
110 if (pParent
->IsKindOf(CLASSINFO(wxScrolledWindow
)) ||
111 pParent
->IsKindOf(CLASSINFO(wxGenericScrolledWindow
)))
112 lSstyle
|= WS_CLIPSIBLINGS
;
116 vCtrlData
.cbSize
= sizeof(SPBCDATA
);
117 vCtrlData
.ulTextLimit
= 10L;
118 vCtrlData
.lLowerLimit
= 0L;
119 vCtrlData
.lUpperLimit
= 100L;
120 vCtrlData
.idMasterSpb
= vId
;
121 vCtrlData
.pHWXCtlData
= NULL
;
123 m_hWnd
= (WXHWND
)::WinCreateWindow( GetWinHwnd(pParent
)
139 pParent
->AddChild((wxSpinButton
*)this);
141 ::WinQueryWindowPos(m_hWnd
, &vSwp
);
144 SetFont(pParent
->GetFont());
146 // For OS/2 we want to hide the text portion so we can substitute an
147 // independent text ctrl in its place. 10 device units does this
154 wxAssociateWinWithHandle( m_hWnd
157 ::WinSetWindowULong(GetHwnd(), QWL_USER
, (LONG
)this);
158 fnWndProcSpinCtrl
= (WXFARPROC
)::WinSubclassWindow(m_hWnd
, (PFNWP
)wxSpinCtrlWndProc
);
160 } // end of wxSpinButton::Create
162 wxSpinButton::~wxSpinButton()
164 } // end of wxSpinButton::~wxSpinButton
166 // ----------------------------------------------------------------------------
168 // ----------------------------------------------------------------------------
170 wxSize
wxSpinButton::DoGetBestSize() const
173 // OS/2 PM does not really have system metrics so we'll just set our best guess
174 // Also we have no horizontal spin buttons.
176 return (wxSize(10,20));
177 } // end of wxSpinButton::DoGetBestSize
179 // ----------------------------------------------------------------------------
181 // ----------------------------------------------------------------------------
183 int wxSpinButton::GetValue() const
189 ::WinSendMsg( GetHwnd()
192 ,MPFROM2SHORT( (USHORT
)10
198 } // end of wxSpinButton::GetValue
200 bool wxSpinButton::OS2OnScroll(
207 wxCHECK_MSG(hControl
, FALSE
, wxT("scrolling what?") )
209 wxSpinEvent
vEvent( wxEVT_SCROLL_THUMBTRACK
212 int nVal
= (int)wPos
; // cast is important for negative values!
214 vEvent
.SetPosition(nVal
);
215 vEvent
.SetEventObject(this);
216 return(GetEventHandler()->ProcessEvent(vEvent
));
217 } // end of wxSpinButton::OS2OnScroll
219 bool wxSpinButton::OS2Command(
225 } // end of wxSpinButton::OS2Command
227 void wxSpinButton::SetRange(
235 ::WinSendMsg( GetHwnd()
240 } // end of wxSpinButton::SetRange
242 void wxSpinButton::SetValue(
246 ::WinSendMsg(GetHwnd(), SPBM_SETCURRENTVALUE
, MPFROMLONG(nValue
), MPARAM(0));
247 } // end of wxSpinButton::SetValue
249 #endif //wxUSE_SPINBTN