[Libreoffice-commits] core.git: include/svl sc/source

Tamas Bunth tamas.bunth at collabora.co.uk
Fri Oct 20 08:30:39 UTC 2017


 include/svl/hint.hxx            |    1 +
 sc/source/ui/inc/content.hxx    |    1 +
 sc/source/ui/inc/navipi.hxx     |    1 +
 sc/source/ui/navipi/content.cxx |   37 +++++++++++++++++++++++++++++++++++++
 sc/source/ui/navipi/navipi.cxx  |   33 +++++++++++++++++++++++++++++++++
 sc/source/ui/unoobj/viewuno.cxx |    3 +++
 6 files changed, 76 insertions(+)

New commits:
commit 1c80246e5ff8aeb3e05384d86766a56aa878c7be
Author: Tamas Bunth <tamas.bunth at collabora.co.uk>
Date:   Thu Oct 19 16:57:06 2017 +0200

    tdf#112100 Select shape name in Navigator
    
    After the selection of a shape the shape name is selected in the Navigator
    tab under the Drawing Objects entry.
    
    It scrolls to the corresponding entry as well in case the scrollbar is
    visible.
    
    Change-Id: I298e8fe6bdab01eb20c53e1730812192c46770c5
    Reviewed-on: https://gerrit.libreoffice.org/43566
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Tamás Bunth <btomi96 at gmail.com>

diff --git a/include/svl/hint.hxx b/include/svl/hint.hxx
index 2b9c4131a884..2a0e981802b3 100644
--- a/include/svl/hint.hxx
+++ b/include/svl/hint.hxx
@@ -86,6 +86,7 @@ enum class SfxHintId {
     ScKillEditView,
     ScKillEditViewNoPaint,
     ScHiddenRowsChanged,
+    ScSelectionChanged,
 
 // SC accessibility hints
     ScAccTableChanged,
diff --git a/sc/source/ui/inc/content.hxx b/sc/source/ui/inc/content.hxx
index 89660103c71a..21d201c60f9b 100644
--- a/sc/source/ui/inc/content.hxx
+++ b/sc/source/ui/inc/content.hxx
@@ -141,6 +141,7 @@ public:
     void    SetManualDoc(const OUString& rName);
     bool    LoadFile(const OUString& rUrl);
     void    SelectDoc(const OUString& rName);
+    bool    SelectEntryByName(const ScContentId nRoot, const OUString& rName);
 
     const OUString& GetHiddenTitle() const    { return aHiddenTitle; }
 
diff --git a/sc/source/ui/inc/navipi.hxx b/sc/source/ui/inc/navipi.hxx
index 0afc636c9072..95ad856bea39 100644
--- a/sc/source/ui/inc/navipi.hxx
+++ b/sc/source/ui/inc/navipi.hxx
@@ -224,6 +224,7 @@ private:
     void    SetCurrentTableStr( const OUString& rName );
     void    SetCurrentObject( const OUString& rName );
     void    SetCurrentDoc( const OUString& rDocName );
+    void    UpdateSelection();
 
     static ScTabViewShell*  GetTabViewShell();
     static ScNavigatorSettings* GetNavigatorSettings();
diff --git a/sc/source/ui/navipi/content.cxx b/sc/source/ui/navipi/content.cxx
index a3df348c16a0..e82ddfe976bc 100644
--- a/sc/source/ui/navipi/content.cxx
+++ b/sc/source/ui/navipi/content.cxx
@@ -1626,6 +1626,43 @@ void ScContentTree::SelectDoc(const OUString& rName)      // rName like shown in
     }
 }
 
+bool ScContentTree::SelectEntryByName(const ScContentId nRoot, const OUString& rName)
+{
+    SvTreeListEntry* pParent = pRootNodes[ nRoot ];
+
+    if( !pParent->HasChildren() )
+        return false;
+
+    SvTreeListEntry* pEntry = FirstChild( pParent );
+    while( pEntry )
+    {
+        if( GetEntryText( pEntry ) == rName )
+        {
+            bool bRet = SvTreeListBox::Select( pEntry );
+
+            // Scroll to the selected item
+            if( SvTreeListBox::GetVScroll()->IsVisible() )
+            {
+                long nBeforeCount = 0;
+                SvTreeList* pList = GetModel();
+                SvTreeListEntry* pRoot = pList->First();
+                while( pRoot != pParent )
+                {
+                    ++nBeforeCount;
+                    pRoot = pList->Next( pRoot );
+                }
+                SvTreeListBox::ScrollToAbsPos( pEntry->GetChildListPos()
+                            + nBeforeCount );
+            }
+
+            return bRet;
+        }
+        pEntry = Next( pEntry );
+    }
+
+    return false;
+}
+
 void ScContentTree::ApplyNavigatorSettings()
 {
     const ScNavigatorSettings* pSettings = ScNavigatorDlg::GetNavigatorSettings();
diff --git a/sc/source/ui/navipi/navipi.cxx b/sc/source/ui/navipi/navipi.cxx
index 6ef08f8561fb..536a97e12496 100644
--- a/sc/source/ui/navipi/navipi.cxx
+++ b/sc/source/ui/navipi/navipi.cxx
@@ -50,6 +50,10 @@
 
 #include <algorithm>
 
+#include <com/sun/star/uno/Reference.hxx>
+
+using namespace com::sun::star;
+
 //  maximum values for UI
 #define SCNAV_MAXCOL        (MAXCOLCOUNT)
 // macro is sufficient since only used in ctor
@@ -665,6 +669,9 @@ void ScNavigatorDlg::Notify( SfxBroadcaster&, const SfxHint& rHint )
                     aLbEntries->ObjectFresh( ScContentId::DRAWING );
                     aLbEntries->ObjectFresh( ScContentId::GRAPHIC );
                     break;
+                case SfxHintId::ScSelectionChanged:
+                    UpdateSelection();
+                    break;
                 default:
                     break;
             }
@@ -785,6 +792,32 @@ void ScNavigatorDlg::SetCurrentDoc( const OUString& rDocName )        // activat
                               { &aDocItem });
 }
 
+void ScNavigatorDlg::UpdateSelection()
+{
+    ScTabViewShell* pViewSh = GetTabViewShell();
+    if( !pViewSh )
+        return;
+
+    uno::Reference< drawing::XShapes > xShapes = pViewSh->getSelectedXShapes();
+    if( xShapes )
+    {
+        uno::Reference< container::XIndexAccess > xIndexAccess(
+                xShapes, uno::UNO_QUERY_THROW );
+        if( xIndexAccess->getCount() > 1 )
+            return;
+        uno::Reference< drawing::XShape > xShape;
+        if( xIndexAccess->getByIndex(0) >>= xShape )
+        {
+            uno::Reference< beans::XPropertySet > xProps( xShape, uno::UNO_QUERY_THROW );
+            OUString sName;
+            if( ( xProps->getPropertyValue("Name") >>= sName ) && !sName.isEmpty() )
+            {
+                aLbEntries->SelectEntryByName( ScContentId::DRAWING, sName );
+            }
+        }
+    }
+}
+
 ScTabViewShell* ScNavigatorDlg::GetTabViewShell()
 {
     return dynamic_cast<ScTabViewShell*>( SfxViewShell::Current()  );
diff --git a/sc/source/ui/unoobj/viewuno.cxx b/sc/source/ui/unoobj/viewuno.cxx
index dc757a29b797..c14fddcab42a 100644
--- a/sc/source/ui/unoobj/viewuno.cxx
+++ b/sc/source/ui/unoobj/viewuno.cxx
@@ -1720,6 +1720,9 @@ void ScTabViewObj::SelectionChanged()
             /*ErrCode eRet =*/ pDocSh->CallXScript( *pScript, aParams, aRet, aOutArgsIndex, aOutArgs );
         }
     }
+
+    SfxApplication::Get()->Broadcast( SfxHint( SfxHintId::ScSelectionChanged ) );
+
     if ( !mbLeftMousePressed ) // selection still in progress
     {
         try


More information about the Libreoffice-commits mailing list