diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-12-22 11:59:36 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-12-22 12:05:09 +0100 |
commit | ee1eb926550028da6e5e44089d4706798f94e0bb (patch) | |
tree | 485bb5c8b45083f4af26c05b75af2286059ed0e3 | |
parent | 27aa4dccf24fca018e19e563e000051f7f9af62e (diff) |
Improve usability of the Page Break control.
- use the same fade in/out values that we use for headers/footers
- clicking on the line opens the menu too
- clicking outside the menu hides the button
- leaving the line or the button hides the button immediately
-rw-r--r-- | sw/source/ui/docvw/PageBreakWin.cxx | 77 | ||||
-rw-r--r-- | sw/source/ui/inc/PageBreakWin.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/vcl/menubtn.hxx | 3 |
3 files changed, 50 insertions, 32 deletions
diff --git a/sw/source/ui/docvw/PageBreakWin.cxx b/sw/source/ui/docvw/PageBreakWin.cxx index 9279c00c8a07..7c1f00ef977d 100644 --- a/sw/source/ui/docvw/PageBreakWin.cxx +++ b/sw/source/ui/docvw/PageBreakWin.cxx @@ -68,7 +68,7 @@ using namespace drawinglayer::primitive2d; namespace { - B2DPolygon lcl_CreatePolygon( B2DRectangle aBounds, bool bMirror ) + static B2DPolygon lcl_CreatePolygon( B2DRectangle aBounds, bool bMirror ) { B2DPolygon aRetval; const double nRadius = 1; @@ -164,17 +164,33 @@ namespace SwDashedLine( pParent, rColor ), m_pWin( pWin ) {}; - virtual void MouseMove( const MouseEvent& rMEvt ); + virtual void MouseButtonDown( const MouseEvent& rMEvt ); }; void SwBreakDashedLine::MouseMove( const MouseEvent& rMEvt ) { if ( rMEvt.IsLeaveWindow() ) - m_pWin->Fade( false ); + { + // don't fade if we just move to the 'button' + Rectangle aRect( m_pWin->GetPosPixel(), m_pWin->GetSizePixel() ); + Point aEventPos( GetPosPixel() + rMEvt.GetPosPixel() ); + if ( !aRect.IsInside( aEventPos ) ) + m_pWin->Fade( false ); + } else if ( !m_pWin->IsVisible() ) m_pWin->Fade( true ); } + + void SwBreakDashedLine::MouseButtonDown( const MouseEvent& rMEvt ) + { + sal_uInt16 nItemId = m_pWin->GetPopupMenu()->Execute( this, rMEvt.GetPosPixel() ); + if ( nItemId ) + { + m_pWin->SetCurItemId( nItemId ); + m_pWin->Select(); + } + } } SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm ) : @@ -195,9 +211,10 @@ SwPageBreakWin::SwPageBreakWin( SwEditWin* pEditWin, const SwPageFrm* pPageFrm ) // Create the popup menu m_pPopupMenu = new PopupMenu( SW_RES( MN_PAGEBREAK_BUTTON ) ); + m_pPopupMenu->SetDeactivateHdl( LINK( this, SwPageBreakWin, HideHandler ) ); SetPopupMenu( m_pPopupMenu ); - m_aFadeTimer.SetTimeout( 500 ); + m_aFadeTimer.SetTimeout( 50 ); m_aFadeTimer.SetTimeoutHdl( LINK( this, SwPageBreakWin, FadeHandler ) ); } @@ -383,7 +400,13 @@ void SwPageBreakWin::Select( ) void SwPageBreakWin::MouseMove( const MouseEvent& rMEvt ) { if ( rMEvt.IsLeaveWindow() ) - Fade( false ); + { + // don't fade if we just move to the 'line', or the popup menu is open + Rectangle aRect( m_pLine->GetPosPixel(), m_pLine->GetSizePixel() ); + Point aEventPos( GetPosPixel() + rMEvt.GetPosPixel() ); + if ( !aRect.IsInside( aEventPos ) && !PopupMenu::IsInExecute() ) + Fade( false ); + } else if ( !IsVisible() ) Fade( true ); } @@ -457,13 +480,13 @@ void SwPageBreakWin::UpdatePosition( ) long nRight = std::min( nPgRight + aBtnSize.getWidth() - ARROW_WIDTH / 2, aVisArea.Right() ); nBtnLeft = nRight - aBtnSize.getWidth(); if ( IsVisible() ) - nLineRight = nBtnLeft - ARROW_WIDTH / 2; + nLineRight = nBtnLeft; } else { nBtnLeft = std::max( nPgLeft - aBtnSize.Width() + ARROW_WIDTH / 2, aVisArea.Left() ); if ( IsVisible() ) - nLineLeft = nBtnLeft + aBtnSize.Width( ) + ARROW_WIDTH / 2; + nLineLeft = nBtnLeft + aBtnSize.Width(); } // Set the button position @@ -493,22 +516,26 @@ void SwPageBreakWin::SetReadonly( bool bReadonly ) void SwPageBreakWin::Fade( bool bFadeIn ) { - if ( !PopupMenu::IsInExecute() ) - { - m_bIsAppearing = bFadeIn; - if ( !m_bDestroyed && m_aFadeTimer.IsActive( ) ) - m_aFadeTimer.Stop(); - if ( !m_bDestroyed ) - m_aFadeTimer.Start( ); - } + m_bIsAppearing = bFadeIn; + if ( !m_bDestroyed && m_aFadeTimer.IsActive( ) ) + m_aFadeTimer.Stop(); + if ( !m_bDestroyed ) + m_aFadeTimer.Start( ); +} + +IMPL_LINK( SwPageBreakWin, HideHandler, void *, EMPTYARG ) +{ + Fade( false ); + + return 0; } IMPL_LINK( SwPageBreakWin, FadeHandler, Timer *, EMPTYARG ) { if ( m_bIsAppearing && m_nFadeRate > 0 ) - m_nFadeRate -= 10; + m_nFadeRate -= 25; else if ( !m_bIsAppearing && m_nFadeRate < 100 ) - m_nFadeRate += 10; + m_nFadeRate += 25; if ( m_nFadeRate != 100 && !IsVisible() ) Show(); @@ -520,20 +547,8 @@ IMPL_LINK( SwPageBreakWin, FadeHandler, Timer *, EMPTYARG ) Invalidate(); } - if ( IsVisible( ) ) - { - if ( m_nFadeRate > 0 ) - m_aFadeTimer.SetTimeout( 100 ); - else - { - m_aFadeTimer.SetTimeout( 3000 ); - } - - if ( m_nFadeRate > 0 && m_nFadeRate < 100 ) - m_aFadeTimer.Start(); - } - else - m_aFadeTimer.SetTimeout( 500 ); + if ( IsVisible( ) && m_nFadeRate > 0 && m_nFadeRate < 100 ) + m_aFadeTimer.Start(); return 0; } diff --git a/sw/source/ui/inc/PageBreakWin.hxx b/sw/source/ui/inc/PageBreakWin.hxx index bac664c6ac37..fa2631c787b4 100644 --- a/sw/source/ui/inc/PageBreakWin.hxx +++ b/sw/source/ui/inc/PageBreakWin.hxx @@ -70,6 +70,8 @@ public: private: bool ShowOnRight(); + /// Hide the button (used when the popup menu is closed by clicking outside) + DECL_LINK( HideHandler, void * ); DECL_LINK( FadeHandler, Timer * ); }; diff --git a/vcl/inc/vcl/menubtn.hxx b/vcl/inc/vcl/menubtn.hxx index 1e65504b97bc..b9bdd8162194 100644 --- a/vcl/inc/vcl/menubtn.hxx +++ b/vcl/inc/vcl/menubtn.hxx @@ -88,7 +88,8 @@ public: void SetPopupMenu( PopupMenu* pNewMenu ); PopupMenu* GetPopupMenu() const { return mpMenu; } - sal_uInt16 GetCurItemId() const { return mnCurItemId; } + sal_uInt16 GetCurItemId() const { return mnCurItemId; } + void SetCurItemId( sal_uInt16 nItemId ) { mnCurItemId = nItemId; } void SetActivateHdl( const Link& rLink ) { maActivateHdl = rLink; } const Link& GetActivateHdl() const { return maActivateHdl; } |