3a59551
From f4bfce94abc10fbd2d8b37113e27b36c1e79fc61 Mon Sep 17 00:00:00 2001
3a59551
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
3a59551
Date: Fri, 13 Sep 2013 20:13:25 +0100
3a59551
Subject: [PATCH] select sheet menu as a right-click popup to the prev/next
3a59551
 sheet dingus
3a59551
3a59551
Change-Id: Ifc9baeabedeab526d040220e9e45f171b5353bcf
3a59551
---
3a59551
 include/svtools/tabbar.hxx        |  6 ++++
3a59551
 sc/source/ui/inc/tabcont.hxx      |  3 ++
3a59551
 sc/source/ui/view/tabcont.cxx     | 69 ++++++++++++++++++++++++++++++---------
3a59551
 svtools/source/control/tabbar.cxx | 34 +++++++++++++++++--
3a59551
 4 files changed, 93 insertions(+), 19 deletions(-)
3a59551
3a59551
diff --git a/include/svtools/tabbar.hxx b/include/svtools/tabbar.hxx
3a59551
index 0bf3be6..44bcc48 100644
3a59551
--- a/include/svtools/tabbar.hxx
3a59551
+++ b/include/svtools/tabbar.hxx
3a59551
@@ -369,6 +369,7 @@ private:
3a59551
     sal_Bool            mbSelTextColor;
3a59551
     bool            mbMirrored;
3a59551
     bool            mbHasInsertTab; // if true, the tab bar has an extra tab at the end.
3a59551
+    bool            mbScrollAlwaysEnabled;
3a59551
     Link            maSelectHdl;
3a59551
     Link            maDoubleClickHdl;
3a59551
     Link            maSplitHdl;
3a59551
@@ -377,6 +378,7 @@ private:
3a59551
     Link            maStartRenamingHdl;
3a59551
     Link            maAllowRenamingHdl;
3a59551
     Link            maEndRenamingHdl;
3a59551
+    Link            maScrollAreaContextHdl;
3a59551
     size_t          maCurrentItemList;
3a59551
 
3a59551
     using Window::ImplInit;
3a59551
@@ -529,6 +531,8 @@ public:
3a59551
     void            SetStyle( WinBits nStyle );
3a59551
     WinBits         GetStyle() const { return mnWinStyle; }
3a59551
 
3a59551
+    void            SetScrollAlwaysEnabled(bool bScrollAlwaysEnabled);
3a59551
+
3a59551
     Size            CalcWindowSizePixel() const;
3a59551
 
3a59551
     void            SetSelectHdl( const Link& rLink ) { maSelectHdl = rLink; }
3a59551
@@ -547,6 +551,8 @@ public:
3a59551
     const Link&     GetAllowRenamingHdl() const { return maAllowRenamingHdl; }
3a59551
     void            SetEndRenamingHdl( const Link& rLink ) { maEndRenamingHdl = rLink; }
3a59551
     const Link&     GetEndRenamingHdl() const { return maEndRenamingHdl; }
3a59551
+    void            SetScrollAreaContextHdl( const Link& rLink ) { maScrollAreaContextHdl = rLink; }
3a59551
+    const Link&     GetScrollAreaContextHdl() const { return maScrollAreaContextHdl; }
3a59551
 
3a59551
     // accessibility
3a59551
     virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > CreateAccessible();
3a59551
diff --git a/sc/source/ui/inc/tabcont.hxx b/sc/source/ui/inc/tabcont.hxx
3a59551
index c0bde9e..2c87f89 100644
3a59551
--- a/sc/source/ui/inc/tabcont.hxx
3a59551
+++ b/sc/source/ui/inc/tabcont.hxx
3a59551
@@ -46,6 +46,9 @@ private:
3a59551
     sal_uInt16          GetMaxId() const;
3a59551
     SCTAB           GetPrivatDropPos(const Point& rPos );
3a59551
 
3a59551
+    DECL_LINK(ShowPageList, const CommandEvent*);
3a59551
+
3a59551
+    void SwitchToPageId(sal_uInt16 nId);
3a59551
 protected:
3a59551
     virtual void    Select();
3a59551
     virtual void    Command( const CommandEvent& rCEvt );
3a59551
diff --git a/sc/source/ui/view/tabcont.cxx b/sc/source/ui/view/tabcont.cxx
3a59551
index 4fce113..4056748 100644
3a59551
--- a/sc/source/ui/view/tabcont.cxx
3a59551
+++ b/sc/source/ui/view/tabcont.cxx
3a59551
@@ -81,6 +81,39 @@ ScTabControl::ScTabControl( Window* pParent, ScViewData* pData ) :
3a59551
 
3a59551
     EnableEditMode();
3a59551
     UpdateInputContext();
3a59551
+
3a59551
+    SetScrollAlwaysEnabled(true);
3a59551
+
3a59551
+    SetScrollAreaContextHdl( LINK( this, ScTabControl, ShowPageList ) );
3a59551
+}
3a59551
+
3a59551
+IMPL_LINK(ScTabControl, ShowPageList, const CommandEvent *, pEvent)
3a59551
+{
3a59551
+    PopupMenu aPopup;
3a59551
+
3a59551
+    sal_uInt16 nCurPageId = GetCurPageId();
3a59551
+
3a59551
+    ScDocument* pDoc = pViewData->GetDocument();
3a59551
+    SCTAB nCount = pDoc->GetTableCount();
3a59551
+    for (SCTAB i=0; i
3a59551
+    {
3a59551
+        if (pDoc->IsVisible(i))
3a59551
+        {
3a59551
+            OUString aString;
3a59551
+            if (pDoc->GetName(i, aString))
3a59551
+            {
3a59551
+                sal_uInt16 nId = static_cast<sal_uInt16>(i)+1;
3a59551
+                aPopup.InsertItem(nId, aString, MIB_CHECKABLE);
3a59551
+                if (nId == nCurPageId)
3a59551
+                    aPopup.CheckItem(nId);
3a59551
+            }
3a59551
+        }
3a59551
+    }
3a59551
+
3a59551
+    sal_uInt16 nItemId = aPopup.Execute( this, pEvent->GetMousePosPixel() );
3a59551
+    SwitchToPageId(nItemId);
3a59551
+
3a59551
+    return 0;
3a59551
 }
3a59551
 
3a59551
 ScTabControl::~ScTabControl()
3a59551
@@ -368,6 +401,25 @@ void ScTabControl::SetSheetLayoutRTL( sal_Bool bSheetRTL )
3a59551
     nSelPageIdByMouse = TabBar::PAGE_NOT_FOUND;
3a59551
 }
3a59551
 
3a59551
+void ScTabControl::SwitchToPageId(sal_uInt16 nId)
3a59551
+{
3a59551
+    if (nId)
3a59551
+    {
3a59551
+        sal_Bool bAlreadySelected = IsPageSelected( nId );
3a59551
+        //make the clicked page the current one
3a59551
+        SetCurPageId( nId );
3a59551
+        //change the selection when the current one is not already
3a59551
+        //selected or part of a multi selection
3a59551
+        if(!bAlreadySelected)
3a59551
+        {
3a59551
+            sal_uInt16 nCount = GetMaxId();
3a59551
+
3a59551
+            for (sal_uInt16 i=1; i<=nCount; i++)
3a59551
+                SelectPage( i, i==nId );
3a59551
+            Select();
3a59551
+        }
3a59551
+    }
3a59551
+}
3a59551
 
3a59551
 void ScTabControl::Command( const CommandEvent& rCEvt )
3a59551
 {
3a59551
@@ -387,22 +439,7 @@ void ScTabControl::Command( const CommandEvent& rCEvt )
3a59551
             // if multiple tables are selected and the one under the cursor
3a59551
             // is not part of them then unselect them
3a59551
             sal_uInt16 nId = GetPageId( rCEvt.GetMousePosPixel() );
3a59551
-            if (nId)
3a59551
-            {
3a59551
-                sal_Bool bAlreadySelected = IsPageSelected( nId );
3a59551
-                //make the clicked page the current one
3a59551
-                SetCurPageId( nId );
3a59551
-                //change the selection when the current one is not already
3a59551
-                //selected or part of a multi selection
3a59551
-                if(!bAlreadySelected)
3a59551
-                {
3a59551
-                    sal_uInt16 nCount = GetMaxId();
3a59551
-
3a59551
-                    for (sal_uInt16 i=1; i<=nCount; i++)
3a59551
-                        SelectPage( i, i==nId );
3a59551
-                    Select();
3a59551
-                }
3a59551
-            }
3a59551
+            SwitchToPageId(nId);
3a59551
 
3a59551
             // #i52073# OLE inplace editing has to be stopped before showing the sheet tab context menu
3a59551
             pViewSh->DeactivateOle();
3a59551
diff --git a/svtools/source/control/tabbar.cxx b/svtools/source/control/tabbar.cxx
3a59551
index 4152f9d..c0b8059 100644
3a59551
--- a/svtools/source/control/tabbar.cxx
3a59551
+++ b/svtools/source/control/tabbar.cxx
3a59551
@@ -100,13 +100,33 @@ class ImplTabButton : public PushButton
3a59551
 {
3a59551
 public:
3a59551
                     ImplTabButton( TabBar* pParent, WinBits nWinStyle = 0 ) :
3a59551
-                        PushButton( pParent, nWinStyle | WB_RECTSTYLE | WB_SMALLSTYLE | WB_NOLIGHTBORDER | WB_NOPOINTERFOCUS  ) {}
3a59551
+                    PushButton( pParent, nWinStyle | WB_RECTSTYLE | WB_SMALLSTYLE | WB_NOLIGHTBORDER | WB_NOPOINTERFOCUS  ) {}
3a59551
 
3a59551
     TabBar*         GetParent() const { return (TabBar*)Window::GetParent(); }
3a59551
 
3a59551
     virtual long    PreNotify( NotifyEvent& rNEvt );
3a59551
+
3a59551
+    virtual void    MouseButtonDown( const MouseEvent& rMEvt );
3a59551
+
3a59551
+    virtual void    Command( const CommandEvent& rCEvt );
3a59551
 };
3a59551
 
3a59551
+void ImplTabButton::MouseButtonDown( const MouseEvent& rMEvt )
3a59551
+{
3a59551
+    PushButton::MouseButtonDown(rMEvt);
3a59551
+}
3a59551
+
3a59551
+void ImplTabButton::Command( const CommandEvent& rCEvt )
3a59551
+{
3a59551
+    sal_uInt16 nCmd = rCEvt.GetCommand();
3a59551
+    if ( nCmd == COMMAND_CONTEXTMENU )
3a59551
+    {
3a59551
+        TabBar *pParent = GetParent();
3a59551
+        pParent->maScrollAreaContextHdl.Call((void*)&rCEvt);
3a59551
+    }
3a59551
+    PushButton::Command(rCEvt);
3a59551
+}
3a59551
+
3a59551
 // =======================================================================
3a59551
 
3a59551
 long ImplTabButton::PreNotify( NotifyEvent& rNEvt )
3a59551
@@ -398,6 +418,8 @@ void TabBar::ImplInit( WinBits nWinStyle )
3a59551
     mbSelColor      = sal_False;
3a59551
     mbSelTextColor  = sal_False;
3a59551
     mbMirrored      = sal_False;
3a59551
+    mbMirrored      = sal_False;
3a59551
+    mbScrollAlwaysEnabled = false;
3a59551
 
3a59551
     if ( nWinStyle & WB_3DTAB )
3a59551
         mnOffY++;
3a59551
@@ -752,19 +774,25 @@ void TabBar::ImplEnableControls()
3a59551
         return;
3a59551
 
3a59551
     // Buttons enablen/disblen
3a59551
-    sal_Bool bEnableBtn = mnFirstPos > 0;
3a59551
+    sal_Bool bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos > 0;
3a59551
     if ( mpFirstBtn )
3a59551
         mpFirstBtn->Enable( bEnableBtn );
3a59551
     if ( mpPrevBtn )
3a59551
         mpPrevBtn->Enable( bEnableBtn );
3a59551
 
3a59551
-    bEnableBtn = mnFirstPos < ImplGetLastFirstPos();
3a59551
+    bEnableBtn = mbScrollAlwaysEnabled || mnFirstPos < ImplGetLastFirstPos();
3a59551
     if ( mpNextBtn )
3a59551
         mpNextBtn->Enable( bEnableBtn );
3a59551
     if ( mpLastBtn )
3a59551
         mpLastBtn->Enable( bEnableBtn );
3a59551
 }
3a59551
 
3a59551
+void TabBar::SetScrollAlwaysEnabled(bool bScrollAlwaysEnabled)
3a59551
+{
3a59551
+    mbScrollAlwaysEnabled = bScrollAlwaysEnabled;
3a59551
+    ImplEnableControls();
3a59551
+}
3a59551
+
3a59551
 // -----------------------------------------------------------------------
3a59551
 
3a59551
 void TabBar::ImplShowPage( sal_uInt16 nPos )
3a59551
-- 
3a59551
1.8.3.1
3a59551