X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/dba006200f4b262f2381cfcbc2657cd0680502c3..0d1903dbda864780eec30efdc4e91776bdbfd21b:/src/motif/spinbutt.cpp diff --git a/src/motif/spinbutt.cpp b/src/motif/spinbutt.cpp index b0f2e76d94..334a676070 100644 --- a/src/motif/spinbutt.cpp +++ b/src/motif/spinbutt.cpp @@ -1,21 +1,25 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: spinbutt.cpp +// Name: src/motif/spinbutt.cpp // Purpose: wxSpinButton // Author: Julian Smart // Modified by: // Created: 17/09/98 -// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// -#ifdef __GNUG__ - #pragma implementation "spinbutt.h" -#endif +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#if wxUSE_SPINBTN #include "wx/spinbutt.h" + +#ifndef WX_PRECOMP + #include "wx/timer.h" +#endif + #include "wx/spinctrl.h" -#include "wx/timer.h" #ifdef __VMS__ #pragma message disable nosimpint @@ -74,7 +78,7 @@ class wxArrowButton : public wxControl { friend class wxArrowButtonTimer; public: - wxArrowButton( int increment ) + wxArrowButton( int increment ) : m_increment( increment ), m_timer( 0 ) {} @@ -88,7 +92,7 @@ public: Create( parent, id, d, pos, size ); } - ~wxArrowButton() + virtual ~wxArrowButton() { delete m_timer; } bool Create( wxSpinButton* parent, wxWindowID id, ArrowDirection d, @@ -175,15 +179,17 @@ void wxArrowButton::StopTimerCallback( Widget w, XtPointer clientData, return; wxArrowButton* btn = (wxArrowButton*)clientData; - delete btn->m_timer; - btn->m_timer = 0; + wxDELETE(btn->m_timer); } -bool wxArrowButton::Create( wxSpinButton* parent, wxWindowID id, +bool wxArrowButton::Create( wxSpinButton* parent, + wxWindowID WXUNUSED(id), ArrowDirection d, const wxPoint& pos, const wxSize& size ) { - int arrow_dir; + wxCHECK_MSG( parent, false, wxT("must have a valid parent") ); + + int arrow_dir = XmARROW_UP; switch( d ) { @@ -201,13 +207,16 @@ bool wxArrowButton::Create( wxSpinButton* parent, wxWindowID id, break; } - if( parent ) parent->AddChild( this ); + parent->AddChild( this ); + PreCreation(); Widget parentWidget = (Widget) parent->GetClientWidget(); m_mainWidget = (WXWidget) XtVaCreateManagedWidget( "XmArrowButton", xmArrowButtonWidgetClass, parentWidget, XmNarrowDirection, arrow_dir, + XmNborderWidth, 0, + XmNshadowThickness, 0, NULL ); XtAddCallback( (Widget) m_mainWidget, @@ -220,20 +229,18 @@ bool wxArrowButton::Create( wxSpinButton* parent, wxWindowID id, XmNactivateCallback, (XtCallbackProc) StopTimerCallback, (XtPointer) this ); + PostCreation(); AttachWidget( parent, m_mainWidget, (WXWidget) NULL, pos.x, pos.y, size.x, size.y ); - return TRUE; + return true; } // ---------------------------------------------------------------------------- // wxSpinButton // ---------------------------------------------------------------------------- -IMPLEMENT_DYNAMIC_CLASS(wxSpinButton, wxControl); -IMPLEMENT_DYNAMIC_CLASS(wxSpinEvent, wxNotifyEvent); - -static void CalcSizes( wxPoint pt, wxSize sz, +static void CalcSizes( const wxPoint& pt, const wxSize& sz, wxPoint& pt1, wxSize& sz1, wxPoint& pt2, wxSize& sz2, bool isVertical ) @@ -265,26 +272,24 @@ bool wxSpinButton::Create( wxWindow *parent, wxWindowID id, if( !wxControl::Create( parent, id, pos, newSize, style ) ) { - return FALSE; + return false; } SetName(name); - InitBase(); - - m_windowId = ( id == -1 ) ? NewControlId() : id; + m_windowId = ( id == wxID_ANY ) ? NewControlId() : id; bool isVert = IsVertical(); wxPoint pt1, pt2; wxSize sz1, sz2; CalcSizes( wxPoint(0,0), newSize, pt1, sz1, pt2, sz2, isVert ); - m_up = new wxArrowButton( this, -1, isVert ? wxARROW_UP : wxARROW_LEFT, + m_up = new wxArrowButton( this, -1, isVert ? wxARROW_UP : wxARROW_RIGHT, pt1, sz1, 1 ); m_down = new wxArrowButton( this, -1, - isVert ? wxARROW_DOWN : wxARROW_RIGHT, + isVert ? wxARROW_DOWN : wxARROW_LEFT, pt2, sz2, -1 ); - return TRUE; + return true; } wxSpinButton::~wxSpinButton() @@ -304,16 +309,11 @@ void wxSpinButton::DoMoveWindow(int x, int y, int width, int height) m_down->SetSize( pt2.x, pt2.y, sz2.x, sz2.y ); } -void wxSpinButton::DoSetSize(int x, int y, int width, int height, - int sizeFlags) +void wxSpinButton::DoSetSize(int x, int y, int width, int height, int sizeFlags) { - if( sizeFlags & wxSIZE_AUTO_WIDTH && width == -1 ) - width = 30; - if( sizeFlags & wxSIZE_AUTO_HEIGHT && height == -1 ) - height = 30; - if( sizeFlags & wxSIZE_USE_EXISTING && width == -1 ) + if ( (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) && width == -1 ) width = GetSize().x; - if( sizeFlags & wxSIZE_USE_EXISTING && height == -1 ) + if ( (sizeFlags & wxSIZE_ALLOW_MINUS_ONE) && height == -1 ) height = GetSize().y; wxControl::DoSetSize(x, y, width, height, 0); @@ -326,8 +326,20 @@ void wxSpinButton::Increment( int delta ) int npos = m_pos + delta; - if( npos < m_min ) npos = m_min; - if( npos > m_max ) npos = m_max; + if( npos < m_min ) + { + if( GetWindowStyle() & wxSP_WRAP ) + npos = m_max; + else + npos = m_min; + } + if( npos > m_max ) + { + if( GetWindowStyle() & wxSP_WRAP ) + npos = m_min; + else + npos = m_max; + } if( npos == m_pos ) return; wxSpinEvent event( delta > 0 ? wxEVT_SCROLL_LINEUP : wxEVT_SCROLL_LINEDOWN, @@ -335,7 +347,7 @@ void wxSpinButton::Increment( int delta ) event.SetPosition( npos ); event.SetEventObject( this ); - GetEventHandler()->ProcessEvent( event ); + HandleWindowEvent( event ); if( event.IsAllowed() ) { @@ -343,13 +355,13 @@ void wxSpinButton::Increment( int delta ) event.SetEventType( wxEVT_SCROLL_THUMBTRACK ); event.SetPosition( m_pos ); - GetEventHandler()->ProcessEvent( event ); + HandleWindowEvent( event ); } } wxSize wxSpinButton::DoGetBestSize() const { - return IsVertical() ? wxSize( 24, 34 ) : wxSize( 34, 24 ); + return IsVertical() ? wxSize( 20, 30 ) : wxSize( 30, 20 ); } // Attributes @@ -384,3 +396,5 @@ void wxSpinButton::ChangeForegroundColour() { // TODO } + +#endif // wxUSE_SPINBTN