diff options
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/sdi/appslots.sdi | 5 | ||||
-rw-r--r-- | sfx2/sdi/sfx.sdi | 16 | ||||
-rw-r--r-- | sfx2/source/appl/appserv.cxx | 242 | ||||
-rw-r--r-- | sfx2/source/notebookbar/SfxNotebookBar.cxx | 92 | ||||
-rw-r--r-- | sfx2/source/sidebar/SidebarController.cxx | 12 |
5 files changed, 354 insertions, 13 deletions
diff --git a/sfx2/sdi/appslots.sdi b/sfx2/sdi/appslots.sdi index 85191e6666fb..d103b962669a 100644 --- a/sfx2/sdi/appslots.sdi +++ b/sfx2/sdi/appslots.sdi @@ -166,6 +166,11 @@ interface Application SID_RECENTFILELIST [ ] + SID_TOOLBAR_MODE + [ + ExecMethod = MiscExec_Impl ; + StateMethod = MiscState_Impl ; + ] SID_AVAILABLE_TOOLBARS [ ExecMethod = MiscExec_Impl ; diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi index b80b5fdde711..3afeb51b32d2 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -5401,6 +5401,22 @@ SfxVoidItem RecentFileList SID_RECENTFILELIST GroupId = GID_APPLICATION; ] +SfxVoidItem ToolbarMode SID_TOOLBAR_MODE +(SfxStringItem Mode SID_TOOLBAR_MODE) +[ + AutoUpdate = FALSE, + FastCall = FALSE, + ReadOnlyDoc = TRUE, + Toggle = FALSE, + Container = FALSE, + RecordAbsolute = FALSE, + RecordPerSet; + + AccelConfig = FALSE, + MenuConfig = TRUE, + ToolBoxConfig = FALSE, + GroupId = GID_APPLICATION; +] SfxVoidItem AvailableToolbars SID_AVAILABLE_TOOLBARS (SfxStringItem Toolbar SID_AVAILABLE_TOOLBARS) diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx index 7a0d18a3f7ee..0014f059c469 100644 --- a/sfx2/source/appl/appserv.cxx +++ b/sfx2/source/appl/appserv.cxx @@ -38,6 +38,8 @@ #include <com/sun/star/task/XJobExecutor.hpp> #include <com/sun/star/text/ModuleDispatcher.hpp> #include <com/sun/star/ui/dialogs/AddressBookSourcePilot.hpp> +#include <com/sun/star/ui/UIElementType.hpp> +#include <com/sun/star/ui/XUIElement.hpp> #include <com/sun/star/uno/Reference.hxx> #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/util/CloseVetoException.hpp> @@ -70,9 +72,11 @@ #include <vcl/stdtext.hxx> #include <rtl/ustrbuf.hxx> #include <osl/file.hxx> +#include <vcl/EnumContext.hxx> #include <unotools/pathoptions.hxx> #include <unotools/moduleoptions.hxx> +#include <unotools/viewoptions.hxx> #include <svtools/helpopt.hxx> #include <toolkit/helper/vclunohelper.hxx> #include <unotools/bootstrap.hxx> @@ -118,8 +122,14 @@ #include <sfx2/sfxhelp.hxx> #include <sfx2/zoomitem.hxx> #include <sfx2/templatedlg.hxx> +#include <sfx2/sidebar/Sidebar.hxx> +#include <sfx2/notebookbar/SfxNotebookBar.hxx> +#include <sfx2/sidebar/SidebarController.hxx> +#include <comphelper/types.hxx> #include <officecfg/Office/Common.hxx> +#include <officecfg/Office/UI/ToolbarMode.hxx> +#include <unotools/confignode.hxx> #include <officecfg/Setup.hxx> #include <memory> @@ -133,9 +143,32 @@ using namespace ::com::sun::star::script; using namespace ::com::sun::star::system; using namespace ::com::sun::star::lang; using namespace ::com::sun::star::document; +using namespace ::com::sun::star::ui; namespace { + OUString lcl_getAppName( vcl::EnumContext::Application eApp ) + { + switch ( eApp ) + { + case vcl::EnumContext::Application::Application_Writer: + return OUString( "Writer" ); + break; + case vcl::EnumContext::Application::Application_Calc: + return OUString( "Calc" ); + break; + case vcl::EnumContext::Application::Application_Impress: + return OUString( "Impress" ); + break; + case vcl::EnumContext::Application::Application_Draw: + return OUString( "Draw" ); + break; + default: + return OUString( "" ); + break; + } + } + // lp#527938, debian#602953, fdo#33266, i#105408 bool lcl_isBaseAvailable() { @@ -652,6 +685,215 @@ void SfxApplication::MiscExec_Impl( SfxRequest& rReq ) break; } + case SID_TOOLBAR_MODE: + { + const SfxStringItem* pModeName = rReq.GetArg<SfxStringItem>( SID_TOOLBAR_MODE ); + + if ( !pModeName ) + { + bDone = true; + break; + } + + OUString aNewName(pModeName->GetValue()); + uno::Reference< uno::XComponentContext > xContext = + ::comphelper::getProcessComponentContext(); + + Reference<XDesktop2> xDesktop = Desktop::create( xContext ); + Reference<XFrame> xFrame = xDesktop->getActiveFrame(); + + const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( xContext ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum( xModuleManager->identify( xFrame ) ); + + OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); + aPath.append( lcl_getAppName(eApp) ); + + const utl::OConfigurationTreeRoot aAppNode( + xContext, + aPath.makeStringAndClear(), + true); + if ( !aAppNode.isValid() ) + { + bDone = true; + break; + } + + OUString aCurrentMode = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + + if ( aCurrentMode.compareTo( aNewName ) == 0 ) + { + bDone = true; + break; + } + + aAppNode.setNodeValue( "Active", makeAny( aNewName ) ); + aAppNode.commit(); + + Reference<css::beans::XPropertySet> xPropSet( xFrame, UNO_QUERY ); + Reference<css::frame::XLayoutManager> xLayoutManager; + if ( xPropSet.is() ) + { + try + { + Any aValue = xPropSet->getPropertyValue( "LayoutManager" ); + aValue >>= xLayoutManager; + } + catch ( const css::uno::RuntimeException& ) + { + throw; + } + catch ( css::uno::Exception& ) + { + } + } + + if ( xLayoutManager.is() ) + { + css::uno::Sequence<OUString> aMandatoryToolbars; + css::uno::Sequence<OUString> aUserToolbars; + std::vector<OUString> aBackupList; + OUString aSidebarMode; + bool bCorrectMode = true; + + aPath = OUStringBuffer("org.openoffice.Office.UI.ToolbarMode/Applications/"); + aPath.append( lcl_getAppName(eApp) ); + aPath.append( "/Modes" ); + + // Read mode settings + const utl::OConfigurationTreeRoot aModesNode( + xContext, + aPath.makeStringAndClear(), + true); + if ( !aModesNode.isValid() ) + { + bDone = true; + break; + } + + const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); + + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + { + const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aModeNode.isValid() ) + continue; + + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + + if ( aCommandArg.compareTo( aNewName ) == 0 ) + { + aMandatoryToolbars = aModeNode.getNodeValue( "Toolbars" ).get< uno::Sequence<OUString> >(); + aUserToolbars = aModeNode.getNodeValue( "UserToolbars" ).get< uno::Sequence<OUString> >(); + aSidebarMode = comphelper::getString( aModeNode.getNodeValue( "Sidebar" ) ); + break; + } + } + + if ( bCorrectMode ) + { + // Backup visible toolbar list and hide all toolbars + Sequence<Reference<XUIElement>> aUIElements = xLayoutManager->getElements(); + for ( sal_Int32 i = 0; i < aUIElements.getLength(); i++ ) + { + Reference< XUIElement > xUIElement( aUIElements[i] ); + Reference< XPropertySet > xPropertySet( aUIElements[i], UNO_QUERY ); + if ( xPropertySet.is() && xUIElement.is() ) + { + try + { + OUString aResName; + sal_Int16 nType( -1 ); + xPropertySet->getPropertyValue( "Type" ) >>= nType; + xPropertySet->getPropertyValue( "ResourceURL" ) >>= aResName; + + if (( nType == css::ui::UIElementType::TOOLBAR ) && + !aResName.isEmpty() ) + { + if ( xLayoutManager->isElementVisible( aResName ) ) + aBackupList.push_back( aResName ); + xLayoutManager->hideElement( aResName ); + } + } + catch ( const Exception& ) + { + } + } + } + + // Show toolbars + for ( OUString& rName : aMandatoryToolbars ) + { + xLayoutManager->createElement( rName ); + xLayoutManager->showElement( rName ); + } + + for ( OUString& rName : aUserToolbars ) + { + xLayoutManager->createElement( rName ); + xLayoutManager->showElement( rName ); + } + + // Sidebar + if ( SfxViewFrame::Current() ) + SfxViewFrame::Current()->ShowChildWindow( SID_SIDEBAR ); + + sfx2::sidebar::SidebarController* pSidebar = + sfx2::sidebar::SidebarController::GetSidebarControllerForFrame( xFrame ); + if ( pSidebar ) + { + if ( aSidebarMode.compareTo( "Arrow" ) == 0 ) + { + pSidebar->FadeOut(); + } + else if ( aSidebarMode.compareTo( "Tabs" ) == 0 ) + { + pSidebar->FadeIn(); + pSidebar->RequestOpenDeck(); + pSidebar->RequestCloseDeck(); + } + else if ( aSidebarMode.compareTo( "Opened" ) == 0 ) + { + pSidebar->FadeIn(); + pSidebar->RequestOpenDeck(); + } + } + + // Show/Hide the Notebookbar + for ( SfxObjectShell *pObjSh = SfxObjectShell::GetFirst(); + pObjSh; + pObjSh = SfxObjectShell::GetNext( *pObjSh ) ) + { + const SfxPoolItem *pItem; + pObjSh->GetDispatcher()->QueryState(SID_NOTEBOOKBAR, pItem); + } + + // Save settings + css::uno::Sequence<OUString> aBackup( aBackupList.size() ); + for ( size_t i = 0; i < aBackupList.size(); ++i ) + aBackup[i] = aBackupList[i]; + + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + { + const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aModeNode.isValid() ) + continue; + + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + + if ( aCommandArg.compareTo( aCurrentMode ) == 0 ) + { + aModeNode.setNodeValue( "UserToolbars", makeAny( aBackup ) ); + break; + } + } + aModesNode.commit(); + } + } + + bDone = true; + break; + } case SID_AVAILABLE_TOOLBARS: { const SfxStringItem* pToolbarName = rReq.GetArg<SfxStringItem>(SID_AVAILABLE_TOOLBARS); diff --git a/sfx2/source/notebookbar/SfxNotebookBar.cxx b/sfx2/source/notebookbar/SfxNotebookBar.cxx index c20e35e865a8..64be63f50da0 100644 --- a/sfx2/source/notebookbar/SfxNotebookBar.cxx +++ b/sfx2/source/notebookbar/SfxNotebookBar.cxx @@ -22,10 +22,15 @@ #include <com/sun/star/frame/XLayoutManager.hpp> #include "NotebookBarPopupMenu.hxx" #include <officecfg/Office/UI/Notebookbar.hxx> +#include <com/sun/star/frame/XModuleManager.hpp> +#include <com/sun/star/frame/ModuleManager.hpp> +#include <unotools/confignode.hxx> +#include <comphelper/types.hxx> using namespace sfx2; using namespace css::uno; using namespace css::ui; +using namespace css; #define MENUBAR_STR "private:resource/menubar/menubar" @@ -41,35 +46,94 @@ void SfxNotebookBar::CloseMethod(SfxBindings& rBindings) void SfxNotebookBar::CloseMethod(SystemWindow* pSysWindow) { - if (pSysWindow && pSysWindow->GetNotebookBar()) - pSysWindow->CloseNotebookBar(); + if (pSysWindow) + { + RemoveListeners(pSysWindow); + if(pSysWindow->GetNotebookBar()) + pSysWindow->CloseNotebookBar(); + } m_xLayoutManager.clear(); m_xFrame.clear(); } bool SfxNotebookBar::IsActive() { - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - return aViewOpt.IsVisible(); + const Reference<frame::XModuleManager> xModuleManager = frame::ModuleManager::create( ::comphelper::getProcessComponentContext() ); + vcl::EnumContext::Application eApp = vcl::EnumContext::GetApplicationEnum(xModuleManager->identify(m_xFrame)); + + OUStringBuffer aPath("org.openoffice.Office.UI.ToolbarMode/Applications/"); + switch ( eApp ) + { + case vcl::EnumContext::Application::Application_Writer: + aPath.append("Writer"); + break; + case vcl::EnumContext::Application::Application_Calc: + aPath.append("Calc"); + break; + case vcl::EnumContext::Application::Application_Impress: + aPath.append("Impress"); + break; + case vcl::EnumContext::Application::Application_Draw: + aPath.append("Draw"); + break; + default: + break; + } + + const utl::OConfigurationTreeRoot aAppNode( + ::comphelper::getProcessComponentContext(), + aPath.makeStringAndClear(), + false); + if ( !aAppNode.isValid() ) + return false; + + OUString aActive = comphelper::getString( aAppNode.getNodeValue( "Active" ) ); + + const utl::OConfigurationNode aModesNode = aAppNode.openNode("Modes"); + const Sequence<OUString> aModeNodeNames( aModesNode.getNodeNames() ); + const sal_Int32 nCount( aModeNodeNames.getLength() ); + bool bNotebookbarVisible = false; + + for ( sal_Int32 nReadIndex = 0; nReadIndex < nCount; ++nReadIndex ) + { + const utl::OConfigurationNode aModeNode( aModesNode.openNode( aModeNodeNames[nReadIndex] ) ); + if ( !aModeNode.isValid() ) + continue; + + OUString aCommandArg = comphelper::getString( aModeNode.getNodeValue( "CommandArg" ) ); + + if ( aCommandArg.compareTo( aActive ) == 0 ) + { + bNotebookbarVisible = comphelper::getBOOL( aModeNode.getNodeValue( "HasNotebookbar" ) ); + break; + } + } + return bNotebookbarVisible; } -void SfxNotebookBar::ExecMethod(SfxBindings& rBindings) +void SfxNotebookBar::ExecMethod(SfxBindings& rBindings, const OUString& rUIName) { - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - aViewOpt.SetVisible(!aViewOpt.IsVisible()); + // Save active UI file name + if ( !rUIName.isEmpty() ) + { + std::shared_ptr<comphelper::ConfigurationChanges> batch( + comphelper::ConfigurationChanges::create( ::comphelper::getProcessComponentContext() ) ); + officecfg::Office::UI::Notebookbar::Active::set( rUIName, batch ); + batch->commit(); + } // trigger the StateMethod rBindings.Invalidate(SID_NOTEBOOKBAR); rBindings.Update(); } -void SfxNotebookBar::StateMethod(SfxBindings& rBindings, const OUString& rUIFile) +bool SfxNotebookBar::StateMethod(SfxBindings& rBindings, const OUString& rUIFile) { SfxFrame& rFrame = rBindings.GetDispatcher_Impl()->GetFrame()->GetFrame(); - StateMethod(rFrame.GetSystemWindow(), rFrame.GetFrameInterface(), rUIFile); + return StateMethod(rFrame.GetSystemWindow(), rFrame.GetFrameInterface(), rUIFile); } -void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, +bool SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, const Reference<css::frame::XFrame> & xFrame, const OUString& rUIFile) { @@ -88,9 +152,7 @@ void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, } } - SvtViewOptions aViewOpt(E_WINDOW, "notebookbar"); - - if (aViewOpt.IsVisible()) + if (IsActive()) { RemoveListeners(pSysWindow); @@ -122,9 +184,13 @@ void SfxNotebookBar::StateMethod(SystemWindow* pSysWindow, } } } + + return true; } else if (auto pNotebookBar = pSysWindow->GetNotebookBar()) pNotebookBar->Hide(); + + return false; } void SfxNotebookBar::RemoveListeners(SystemWindow* pSysWindow) diff --git a/sfx2/source/sidebar/SidebarController.cxx b/sfx2/source/sidebar/SidebarController.cxx index e61cd8431f09..0aa352c1666f 100644 --- a/sfx2/source/sidebar/SidebarController.cxx +++ b/sfx2/source/sidebar/SidebarController.cxx @@ -1303,6 +1303,18 @@ void SidebarController::updateModel(const css::uno::Reference<css::frame::XModel mpResourceManager->UpdateModel(xModel); } +void SidebarController::FadeOut() +{ + if (mpSplitWindow) + mpSplitWindow->FadeOut(); +} + +void SidebarController::FadeIn() +{ + if (mpSplitWindow) + mpSplitWindow->FadeIn(); +} + } } // end of namespace sfx2::sidebar |