[Libreoffice-commits] core.git: cui/source cui/uiconfig

Muhammet Kara muhammet.kara at pardus.org.tr
Thu Apr 12 16:38:57 UTC 2018


 cui/source/customize/SvxMenuConfigPage.cxx    |    6 +
 cui/source/customize/SvxToolbarConfigPage.cxx |   50 +++++++++++++
 cui/source/customize/cfg.cxx                  |   94 ++++++++++++++++++++++++++
 cui/source/inc/cfg.hxx                        |    6 +
 cui/uiconfig/ui/menuassignpage.ui             |   32 ++++++++
 5 files changed, 184 insertions(+), 4 deletions(-)

New commits:
commit 3ba75bf050336bef3738a92a7a942622b9326498
Author: Muhammet Kara <muhammet.kara at pardus.org.tr>
Date:   Thu Apr 12 10:17:31 2018 +0300

    tdf#114260: Allow setting toolbar style in the gear menu
    
    of the Customize dialog.
    
    Change-Id: I69e39175a235446dd75fe59324298b9c59ee2d81
    Reviewed-on: https://gerrit.libreoffice.org/52774
    Reviewed-by: Heiko Tietze <tietze.heiko at gmail.com>
    Tested-by: Heiko Tietze <tietze.heiko at gmail.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx
index efaadbe11a0b..cfa7996563fd 100644
--- a/cui/source/customize/SvxMenuConfigPage.cxx
+++ b/cui/source/customize/SvxMenuConfigPage.cxx
@@ -143,6 +143,12 @@ SvxMenuConfigPage::SvxMenuConfigPage(vcl::Window *pParent, const SfxItemSet& rSe
     pPopup->EnableItem( pPopup->GetItemId("restoreItem"), false );
     pPopup->RemoveDisabledEntries();
 
+    PopupMenu* pGearMenu = m_pGearBtn->GetPopupMenu();
+    pGearMenu->EnableItem( pGearMenu->GetItemId("gear_iconAndText"), false );
+    pGearMenu->EnableItem( pGearMenu->GetItemId("gear_iconOnly"), false );
+    pGearMenu->EnableItem( pGearMenu->GetItemId("gear_textOnly"), false );
+    pGearMenu->RemoveDisabledEntries();
+
     if ( !bIsMenuBar )
     {
         //TODO: Remove this when the gear button is implemented for context menus
diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx
index c09d354cb9e5..f3b64a304e08 100644
--- a/cui/source/customize/SvxToolbarConfigPage.cxx
+++ b/cui/source/customize/SvxToolbarConfigPage.cxx
@@ -339,6 +339,7 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbarEntry, SvTreeListBox *, void
 IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void )
 {
     OString sIdent = pButton->GetCurItemIdent();
+    SvxConfigEntry* pCurrentToolbar = GetTopLevelSelection();
 
     if (sIdent == "gear_add")
     {
@@ -402,9 +403,7 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void )
     }
     else if (sIdent == "gear_delete")
     {
-        SvxConfigEntry* pToolbar = GetTopLevelSelection();
-
-        if ( pToolbar && pToolbar->IsDeletable() )
+        if ( pCurrentToolbar && pCurrentToolbar->IsDeletable() )
         {
             DeleteSelectedTopLevel();
             UpdateButtonStates();
@@ -443,6 +442,29 @@ IMPL_LINK( SvxToolbarConfigPage, GearHdl, MenuButton *, pButton, void )
             m_pTopLevelListBox->SelectEntryPos( nSelectionPos );
         }
     }
+    else if (sIdent == "gear_iconOnly" || sIdent == "gear_textOnly" || sIdent == "gear_iconAndText")
+    {
+        ToolbarSaveInData* pSaveInData = static_cast<ToolbarSaveInData*>( GetSaveInData() );
+
+        if (pCurrentToolbar == nullptr || pSaveInData == nullptr)
+        {
+            SAL_WARN("cui.customize", "NULL toolbar or savein data");
+            return;
+        }
+
+        sal_Int32 nStyle = 0;
+        if (sIdent == "gear_iconOnly")
+            nStyle = 0;
+        else if (sIdent == "gear_textOnly")
+            nStyle = 1;
+        else if (sIdent == "gear_iconAndText")
+            nStyle = 2;
+
+        pCurrentToolbar->SetStyle( nStyle );
+        pSaveInData->SetSystemStyle( m_xFrame, pCurrentToolbar->GetCommand(), nStyle );
+
+        m_pTopLevelListBox->GetSelectHdl().Call( *m_pTopLevelListBox );
+    }
     else
     {
         //This block should never be reached
@@ -788,6 +810,7 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbar, ListBox&, void )
         //TODO: Disable related buttons
         m_pInsertBtn->Enable( false );
         m_pResetBtn->Enable( false );
+        m_pGearBtn->Enable( false );
 
         return;
     }
@@ -795,6 +818,27 @@ IMPL_LINK_NOARG( SvxToolbarConfigPage, SelectToolbar, ListBox&, void )
     {
         m_pInsertBtn->Enable();
         m_pResetBtn->Enable();
+        m_pGearBtn->Enable();
+    }
+
+    PopupMenu* pGearMenu = m_pGearBtn->GetPopupMenu();
+    switch( pToolbar->GetStyle() )
+    {
+        case 0:
+        {
+            pGearMenu->CheckItem( pGearMenu->GetItemId("gear_iconOnly") );
+            break;
+        }
+        case 1:
+        {
+            pGearMenu->CheckItem( pGearMenu->GetItemId("gear_textOnly") );
+            break;
+        }
+        case 2:
+        {
+            pGearMenu->CheckItem( pGearMenu->GetItemId("gear_iconAndText") );
+            break;
+        }
     }
 
     SvxEntries* pEntries = pToolbar->GetEntries();
diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx
index 02c4d5c834f0..f8a2aa420835 100644
--- a/cui/source/customize/cfg.cxx
+++ b/cui/source/customize/cfg.cxx
@@ -50,6 +50,7 @@
 #include <svtools/treelistentry.hxx>
 #include <svtools/viewdataentry.hxx>
 #include <tools/diagnose_ex.h>
+#include <toolkit/helper/vclunohelper.hxx>
 
 #include <algorithm>
 #include <strings.hrc>
@@ -2169,6 +2170,99 @@ sal_Int32 ToolbarSaveInData::GetSystemStyle( const OUString& rResourceURL )
     return result;
 }
 
+void ToolbarSaveInData::SetSystemStyle(
+    const uno::Reference< frame::XFrame >& xFrame,
+    const OUString& rResourceURL,
+    sal_Int32 nStyle )
+{
+    // change the style using the API
+    SetSystemStyle( rResourceURL, nStyle );
+
+    // this code is a temporary hack as the UI is not updating after
+    // changing the toolbar style via the API
+    uno::Reference< css::frame::XLayoutManager > xLayoutManager;
+    vcl::Window *window = nullptr;
+
+    uno::Reference< beans::XPropertySet > xPropSet( xFrame, uno::UNO_QUERY );
+    if ( xPropSet.is() )
+    {
+        uno::Any a = xPropSet->getPropertyValue( "LayoutManager" );
+        a >>= xLayoutManager;
+    }
+
+    if ( xLayoutManager.is() )
+    {
+        uno::Reference< css::ui::XUIElement > xUIElement =
+            xLayoutManager->getElement( rResourceURL );
+
+        // check reference before we call getRealInterface. The layout manager
+        // can only provide references for elements that have been created
+        // before. It's possible that the current element is not available.
+        uno::Reference< css::awt::XWindow > xWindow;
+        if ( xUIElement.is() )
+            xWindow.set( xUIElement->getRealInterface(), uno::UNO_QUERY );
+
+        window = VCLUnoHelper::GetWindow( xWindow ).get();
+    }
+
+    if ( window != nullptr && window->GetType() == WindowType::TOOLBOX )
+    {
+        ToolBox* toolbox = static_cast<ToolBox*>(window);
+
+        if ( nStyle == 0 )
+        {
+            toolbox->SetButtonType( ButtonType::SYMBOLONLY );
+        }
+        else if ( nStyle == 1 )
+        {
+            toolbox->SetButtonType( ButtonType::TEXT );
+        }
+        if ( nStyle == 2 )
+        {
+            toolbox->SetButtonType( ButtonType::SYMBOLTEXT );
+        }
+    }
+}
+
+void ToolbarSaveInData::SetSystemStyle(
+    const OUString& rResourceURL,
+    sal_Int32 nStyle )
+{
+    if ( rResourceURL.startsWith( "private" ) &&
+         m_xPersistentWindowState.is() &&
+         m_xPersistentWindowState->hasByName( rResourceURL ) )
+    {
+        try
+        {
+            uno::Sequence< beans::PropertyValue > aProps;
+
+            uno::Any a( m_xPersistentWindowState->getByName( rResourceURL ) );
+
+            if ( a >>= aProps )
+            {
+                for ( sal_Int32 i = 0; i < aProps.getLength(); ++i )
+                {
+                    if ( aProps[ i ].Name == ITEM_DESCRIPTOR_STYLE )
+                    {
+                        aProps[ i ].Value <<= nStyle;
+                        break;
+                    }
+                }
+            }
+
+            uno::Reference< container::XNameReplace >
+                xNameReplace( m_xPersistentWindowState, uno::UNO_QUERY );
+
+            xNameReplace->replaceByName( rResourceURL, uno::Any( aProps ) );
+        }
+        catch ( uno::Exception& )
+        {
+            // do nothing, a default value is returned
+            SAL_WARN("cui.customize", "Exception setting toolbar style");
+        }
+    }
+}
+
 OUString ToolbarSaveInData::GetSystemUIName( const OUString& rResourceURL )
 {
     OUString result;
diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx
index 69f42cae7aee..bb8ce1b24f60 100644
--- a/cui/source/inc/cfg.hxx
+++ b/cui/source/inc/cfg.hxx
@@ -559,6 +559,12 @@ public:
 
     sal_Int32       GetSystemStyle( const OUString& rResourceURL );
 
+    void            SetSystemStyle( const OUString& rResourceURL, sal_Int32 nStyle );
+
+    void            SetSystemStyle(
+                        const css::uno::Reference< css::frame::XFrame >& xFrame,
+                        const OUString& rResourceURL, sal_Int32 nStyle );
+
     SvxEntries*     GetEntries() override;
     void            SetEntries( std::unique_ptr<SvxEntries> ) override;
     bool            HasSettings() override;
diff --git a/cui/uiconfig/ui/menuassignpage.ui b/cui/uiconfig/ui/menuassignpage.ui
index fcaaf20f71d7..556043cb2274 100644
--- a/cui/uiconfig/ui/menuassignpage.ui
+++ b/cui/uiconfig/ui/menuassignpage.ui
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<!-- Generated with glade 3.20.0 -->
+<!-- Generated with glade 3.22.0 -->
 <interface domain="cui">
   <requires lib="gtk+" version="3.18"/>
   <requires lib="LibreOffice" version="1.0"/>
@@ -38,6 +38,36 @@
         <property name="use_underline">True</property>
       </object>
     </child>
+    <child>
+      <object class="GtkSeparatorMenuItem" id="gear_separator">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioMenuItem" id="gear_iconAndText">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes" context="menuassignpage|gear_iconAndText">Icon _and text</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioMenuItem" id="gear_iconOnly">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes" context="menuassignpage|gear_iconOnly">_Icon only</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
+    <child>
+      <object class="GtkRadioMenuItem" id="gear_textOnly">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="label" translatable="yes" context="menuassignpage|gear_textOnly">_Text only</property>
+        <property name="use_underline">True</property>
+      </object>
+    </child>
   </object>
   <object class="GtkImage" id="image1">
     <property name="visible">True</property>


More information about the Libreoffice-commits mailing list