]>
git.saurik.com Git - wxWidgets.git/blob - src/msw/spinbutt.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: msw/spinbutt.cpp
3 // Purpose: wxSpinButton
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // ============================================================================
14 // ============================================================================
16 // ----------------------------------------------------------------------------
18 // ----------------------------------------------------------------------------
20 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
21 #pragma implementation "spinbutt.h"
22 #pragma implementation "spinbutbase.h"
25 // For compilers that support precompilation, includes "wx.h".
26 #include "wx/wxprec.h"
38 #include "wx/spinbutt.h"
40 IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent
, wxNotifyEvent
)
42 #if defined(__WIN95__)
44 #include "wx/msw/private.h"
46 #if defined(__WIN95__) && !(defined(__GNUWIN32_OLD__) && !defined(__CYGWIN10__))
50 // ============================================================================
52 // ============================================================================
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
59 #if wxUSE_EXTENDED_RTTI
60 WX_DEFINE_FLAGS( wxSpinButtonStyle
)
62 wxBEGIN_FLAGS( wxSpinButtonStyle
)
63 // new style border flags, we put them first to
64 // use them for streaming out
65 wxFLAGS_MEMBER(wxBORDER_SIMPLE
)
66 wxFLAGS_MEMBER(wxBORDER_SUNKEN
)
67 wxFLAGS_MEMBER(wxBORDER_DOUBLE
)
68 wxFLAGS_MEMBER(wxBORDER_RAISED
)
69 wxFLAGS_MEMBER(wxBORDER_STATIC
)
70 wxFLAGS_MEMBER(wxBORDER_NONE
)
72 // old style border flags
73 wxFLAGS_MEMBER(wxSIMPLE_BORDER
)
74 wxFLAGS_MEMBER(wxSUNKEN_BORDER
)
75 wxFLAGS_MEMBER(wxDOUBLE_BORDER
)
76 wxFLAGS_MEMBER(wxRAISED_BORDER
)
77 wxFLAGS_MEMBER(wxSTATIC_BORDER
)
78 wxFLAGS_MEMBER(wxBORDER
)
80 // standard window styles
81 wxFLAGS_MEMBER(wxTAB_TRAVERSAL
)
82 wxFLAGS_MEMBER(wxCLIP_CHILDREN
)
83 wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW
)
84 wxFLAGS_MEMBER(wxWANTS_CHARS
)
85 wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE
)
86 wxFLAGS_MEMBER(wxALWAYS_SHOW_SB
)
87 wxFLAGS_MEMBER(wxVSCROLL
)
88 wxFLAGS_MEMBER(wxHSCROLL
)
90 wxFLAGS_MEMBER(wxSP_HORIZONTAL
)
91 wxFLAGS_MEMBER(wxSP_VERTICAL
)
92 wxFLAGS_MEMBER(wxSP_ARROW_KEYS
)
93 wxFLAGS_MEMBER(wxSP_WRAP
)
95 wxEND_FLAGS( wxSpinButtonStyle
)
97 IMPLEMENT_DYNAMIC_CLASS_XTI(wxSpinButton
, wxControl
,"wx/spinbut.h")
99 wxBEGIN_PROPERTIES_TABLE(wxSpinButton
)
100 wxEVENT_RANGE_PROPERTY( Spin
, wxEVT_SCROLL_TOP
, wxEVT_SCROLL_ENDSCROLL
, wxSpinEvent
)
102 wxPROPERTY( Value
, int , SetValue
, GetValue
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
103 wxPROPERTY( Min
, int , SetMin
, GetMin
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
104 wxPROPERTY( Max
, int , SetMax
, GetMax
, 0 , 0 /*flags*/ , wxT("Helpstring") , wxT("group"))
105 wxPROPERTY_FLAGS( WindowStyle
, wxSpinButtonStyle
, long , SetWindowStyleFlag
, GetWindowStyleFlag
, , 0 /*flags*/ , wxT("Helpstring") , wxT("group")) // style
106 wxEND_PROPERTIES_TABLE()
108 wxBEGIN_HANDLERS_TABLE(wxSpinButton
)
109 wxEND_HANDLERS_TABLE()
111 wxCONSTRUCTOR_5( wxSpinButton
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
113 IMPLEMENT_DYNAMIC_CLASS(wxSpinButton
, wxControl
)
118 // ----------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
122 bool wxSpinButton::Create(wxWindow
*parent
,
127 const wxString
& name
)
129 // basic initialization
132 m_windowId
= (id
== -1) ? NewControlId() : id
;
134 m_backgroundColour
= parent
->GetBackgroundColour() ;
135 m_foregroundColour
= parent
->GetForegroundColour() ;
144 m_windowStyle
= style
;
148 // get the right size for the control
149 if ( width
<= 0 || height
<= 0 )
151 wxSize size
= DoGetBestSize();
163 // translate the styles
164 DWORD wstyle
= WS_VISIBLE
| WS_CHILD
| WS_TABSTOP
| /* WS_CLIPSIBLINGS | */
165 UDS_NOTHOUSANDS
| // never useful, sometimes harmful
166 UDS_SETBUDDYINT
; // it doesn't harm if we don't have buddy
168 if ( m_windowStyle
& wxCLIP_SIBLINGS
)
169 wstyle
|= WS_CLIPSIBLINGS
;
170 if ( m_windowStyle
& wxSP_HORIZONTAL
)
172 if ( m_windowStyle
& wxSP_ARROW_KEYS
)
173 wstyle
|= UDS_ARROWKEYS
;
174 if ( m_windowStyle
& wxSP_WRAP
)
177 // create the UpDown control.
178 m_hWnd
= (WXHWND
)CreateUpDownControl
187 m_min
// initial position
192 wxLogLastError(wxT("CreateUpDownControl"));
199 parent
->AddChild(this);
207 wxSpinButton::~wxSpinButton()
211 // ----------------------------------------------------------------------------
213 // ----------------------------------------------------------------------------
215 wxSize
wxSpinButton::DoGetBestSize() const
217 if ( (GetWindowStyle() & wxSP_VERTICAL
) != 0 )
220 return wxSize(GetSystemMetrics(SM_CXVSCROLL
),
221 2*GetSystemMetrics(SM_CYVSCROLL
));
225 // horizontal control
226 return wxSize(2*GetSystemMetrics(SM_CXHSCROLL
),
227 GetSystemMetrics(SM_CYHSCROLL
));
231 // ----------------------------------------------------------------------------
233 // ----------------------------------------------------------------------------
235 int wxSpinButton::GetValue() const
238 if ( wxTheApp
->GetComCtl32Version() >= 580 )
240 // use the full 32 bit range if available
241 return ::SendMessage(GetHwnd(), UDM_GETPOS32
, 0, 0);
243 #endif // UDM_GETPOS32
245 // we're limited to 16 bit
246 return (short)LOWORD(::SendMessage(GetHwnd(), UDM_GETPOS
, 0, 0));
249 void wxSpinButton::SetValue(int val
)
251 // wxSpinButtonBase::SetValue(val); -- no, it is pure virtual
254 if ( wxTheApp
->GetComCtl32Version() >= 580 )
256 // use the full 32 bit range if available
257 ::SendMessage(GetHwnd(), UDM_SETPOS32
, 0, val
);
259 else // we're limited to 16 bit
260 #endif // UDM_SETPOS32
262 ::SendMessage(GetHwnd(), UDM_SETPOS
, 0, MAKELONG((short) val
, 0));
266 void wxSpinButton::SetRange(int minVal
, int maxVal
)
268 wxSpinButtonBase::SetRange(minVal
, maxVal
);
270 #ifdef UDM_SETRANGE32
271 if ( wxTheApp
->GetComCtl32Version() >= 471 )
273 // use the full 32 bit range if available
274 ::SendMessage(GetHwnd(), UDM_SETRANGE32
, minVal
, maxVal
);
276 else // we're limited to 16 bit
277 #endif // UDM_SETRANGE32
279 ::SendMessage(GetHwnd(), UDM_SETRANGE
, 0,
280 (LPARAM
) MAKELONG((short)maxVal
, (short)minVal
));
284 bool wxSpinButton::MSWOnScroll(int WXUNUSED(orientation
), WXWORD wParam
,
285 WXWORD pos
, WXHWND control
)
287 wxCHECK_MSG( control
, FALSE
, wxT("scrolling what?") )
289 if ( wParam
!= SB_THUMBPOSITION
)
291 // probable SB_ENDSCROLL - we don't react to it
295 wxSpinEvent
event(wxEVT_SCROLL_THUMBTRACK
, m_windowId
);
296 event
.SetPosition((short)pos
); // cast is important for negative values!
297 event
.SetEventObject(this);
299 return GetEventHandler()->ProcessEvent(event
);
302 bool wxSpinButton::MSWOnNotify(int WXUNUSED(idCtrl
), WXLPARAM lParam
, WXLPARAM
*result
)
304 NM_UPDOWN
*lpnmud
= (NM_UPDOWN
*)lParam
;
306 if (lpnmud
->hdr
.hwndFrom
!= GetHwnd()) // make sure it is the right control
309 wxSpinEvent
event(lpnmud
->iDelta
> 0 ? wxEVT_SCROLL_LINEUP
310 : wxEVT_SCROLL_LINEDOWN
,
312 event
.SetPosition(lpnmud
->iPos
+ lpnmud
->iDelta
);
313 event
.SetEventObject(this);
315 bool processed
= GetEventHandler()->ProcessEvent(event
);
317 *result
= event
.IsAllowed() ? 0 : 1;
322 bool wxSpinButton::MSWCommand(WXUINT
WXUNUSED(cmd
), WXWORD
WXUNUSED(id
))
324 // No command messages