122de8995SAndre Fischer /************************************************************** 222de8995SAndre Fischer * 322de8995SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 422de8995SAndre Fischer * or more contributor license agreements. See the NOTICE file 522de8995SAndre Fischer * distributed with this work for additional information 622de8995SAndre Fischer * regarding copyright ownership. The ASF licenses this file 722de8995SAndre Fischer * to you under the Apache License, Version 2.0 (the 822de8995SAndre Fischer * "License"); you may not use this file except in compliance 922de8995SAndre Fischer * with the License. You may obtain a copy of the License at 1022de8995SAndre Fischer * 1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1222de8995SAndre Fischer * 1322de8995SAndre Fischer * Unless required by applicable law or agreed to in writing, 1422de8995SAndre Fischer * software distributed under the License is distributed on an 1522de8995SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1622de8995SAndre Fischer * KIND, either express or implied. See the License for the 1722de8995SAndre Fischer * specific language governing permissions and limitations 1822de8995SAndre Fischer * under the License. 1922de8995SAndre Fischer * 2022de8995SAndre Fischer *************************************************************/ 2122de8995SAndre Fischer 2222de8995SAndre Fischer #include "precompiled_sfx2.hxx" 2322de8995SAndre Fischer 2422de8995SAndre Fischer #include "SidebarController.hxx" 2522de8995SAndre Fischer #include "Deck.hxx" 267a32b0c8SAndre Fischer #include "DeckTitleBar.hxx" 2722de8995SAndre Fischer #include "Panel.hxx" 28b9e67834SAndre Fischer #include "SidebarPanel.hxx" 29ff12d537SAndre Fischer #include "SidebarResource.hxx" 3022de8995SAndre Fischer #include "TabBar.hxx" 31b9e67834SAndre Fischer #include "sfx2/sidebar/Theme.hxx" 327a32b0c8SAndre Fischer #include "SidebarDockingWindow.hxx" 337a32b0c8SAndre Fischer #include "Context.hxx" 34*54eaaa32SAndre Fischer #include "Tools.hxx" 35ff12d537SAndre Fischer 3622de8995SAndre Fischer #include "sfxresid.hxx" 3722de8995SAndre Fischer #include "sfx2/sfxsids.hrc" 387a32b0c8SAndre Fischer #include "sfx2/titledockwin.hxx" 39ff12d537SAndre Fischer #include "sfxlocal.hrc" 40ff12d537SAndre Fischer #include <vcl/floatwin.hxx> 417a32b0c8SAndre Fischer #include "splitwin.hxx" 4295a18594SAndre Fischer #include <svl/smplhint.hxx> 4395a18594SAndre Fischer #include <tools/link.hxx> 44ff12d537SAndre Fischer #include <comphelper/componentfactory.hxx> 4595a18594SAndre Fischer #include <comphelper/processfactory.hxx> 46ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 47ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 4822de8995SAndre Fischer 49f120fe41SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp> 50f120fe41SAndre Fischer #include <com/sun/star/lang/XInitialization.hpp> 5122de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> 5222de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp> 5395a18594SAndre Fischer #include <com/sun/star/ui/XUIElementFactory.hpp> 54f120fe41SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp> 55f120fe41SAndre Fischer #include <com/sun/star/util/URL.hpp> 5622de8995SAndre Fischer 5722de8995SAndre Fischer #include <boost/bind.hpp> 58f120fe41SAndre Fischer #include <boost/function.hpp> 597a32b0c8SAndre Fischer #include <boost/scoped_array.hpp> 6022de8995SAndre Fischer 6122de8995SAndre Fischer 6222de8995SAndre Fischer using namespace css; 6322de8995SAndre Fischer using namespace cssu; 6495a18594SAndre Fischer using ::rtl::OUString; 6522de8995SAndre Fischer 6602c50d82SAndre Fischer 6722de8995SAndre Fischer 68ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 6922de8995SAndre Fischer 70ff12d537SAndre Fischer namespace { 71ff12d537SAndre Fischer enum MenuId 72ff12d537SAndre Fischer { 73ff12d537SAndre Fischer MID_UNLOCK_TASK_PANEL = 1, 74ff12d537SAndre Fischer MID_LOCK_TASK_PANEL, 75ff12d537SAndre Fischer MID_CUSTOMIZATION, 76ff12d537SAndre Fischer MID_RESTORE_DEFAULT, 77ff12d537SAndre Fischer MID_FIRST_PANEL, 78ff12d537SAndre Fischer MID_FIRST_HIDE = 1000 79ff12d537SAndre Fischer }; 80ff12d537SAndre Fischer } 8122de8995SAndre Fischer 8222de8995SAndre Fischer 8322de8995SAndre Fischer SidebarController::SidebarController ( 847a32b0c8SAndre Fischer SidebarDockingWindow* pParentWindow, 8522de8995SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 8622de8995SAndre Fischer : SidebarControllerInterfaceBase(m_aMutex), 87f120fe41SAndre Fischer mpCurrentDeck(), 8822de8995SAndre Fischer mpParentWindow(pParentWindow), 89ff12d537SAndre Fischer mpTabBar(new TabBar( 90ff12d537SAndre Fischer mpParentWindow, 91ff12d537SAndre Fischer rxFrame, 92ff12d537SAndre Fischer ::boost::bind(&SidebarController::SwitchToDeck, this, _1), 9395a18594SAndre Fischer ::boost::bind(&SidebarController::ShowPopupMenu, this, _1,_2,_3))), 9495a18594SAndre Fischer mxFrame(rxFrame), 957a32b0c8SAndre Fischer maCurrentContext(OUString(), OUString()), 9695a18594SAndre Fischer msCurrentDeckId(A2S("PropertyDeck")), 977a32b0c8SAndre Fischer maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)), 987a32b0c8SAndre Fischer mbIsDeckClosed(false), 997a32b0c8SAndre Fischer mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()) 10022de8995SAndre Fischer { 10122de8995SAndre Fischer if (pParentWindow == NULL) 10222de8995SAndre Fischer { 10322de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL); 10422de8995SAndre Fischer return; 10522de8995SAndre Fischer } 10622de8995SAndre Fischer 10722de8995SAndre Fischer // Listen for context change events. 10822de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 10922de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 11022de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 11122de8995SAndre Fischer if (xMultiplexer.is()) 11222de8995SAndre Fischer xMultiplexer->addContextChangeEventListener( 11322de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this), 11495a18594SAndre Fischer mxFrame->getController()); 11522de8995SAndre Fischer 11622de8995SAndre Fischer // Listen for window events. 11722de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler)); 118b9e67834SAndre Fischer 119b9e67834SAndre Fischer // Listen for theme property changes. 120b9e67834SAndre Fischer Theme::GetPropertySet()->addPropertyChangeListener( 121b9e67834SAndre Fischer A2S(""), 122b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 123f120fe41SAndre Fischer 124f120fe41SAndre Fischer SwitchToDeck(A2S("default")); 12522de8995SAndre Fischer } 12622de8995SAndre Fischer 12722de8995SAndre Fischer 12822de8995SAndre Fischer 12922de8995SAndre Fischer 13022de8995SAndre Fischer SidebarController::~SidebarController (void) 13122de8995SAndre Fischer { 13222de8995SAndre Fischer } 13322de8995SAndre Fischer 13422de8995SAndre Fischer 13522de8995SAndre Fischer 13622de8995SAndre Fischer 13722de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void) 13822de8995SAndre Fischer { 13922de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 14022de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 14122de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 14222de8995SAndre Fischer if (xMultiplexer.is()) 14322de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 14422de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 14522de8995SAndre Fischer 14622de8995SAndre Fischer if (mpParentWindow != NULL) 14722de8995SAndre Fischer { 14822de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 14922de8995SAndre Fischer mpParentWindow = NULL; 15022de8995SAndre Fischer } 151b9e67834SAndre Fischer 152f120fe41SAndre Fischer if (mpCurrentDeck) 153b9e67834SAndre Fischer { 154f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 155f120fe41SAndre Fischer OSL_TRACE("deleting deck window subtree"); 156f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 157f120fe41SAndre Fischer mpCurrentDeck.reset(); 158b9e67834SAndre Fischer } 159b9e67834SAndre Fischer 160580828edSAndre Fischer mpTabBar.reset(); 161580828edSAndre Fischer 162b9e67834SAndre Fischer Theme::GetPropertySet()->removePropertyChangeListener( 163b9e67834SAndre Fischer A2S(""), 164b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 16522de8995SAndre Fischer } 16622de8995SAndre Fischer 16722de8995SAndre Fischer 16822de8995SAndre Fischer 16922de8995SAndre Fischer 17022de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) 17122de8995SAndre Fischer throw(cssu::RuntimeException) 17222de8995SAndre Fischer { 17395a18594SAndre Fischer UpdateConfigurations( 1747a32b0c8SAndre Fischer Context( 17595a18594SAndre Fischer rEvent.ApplicationName, 17695a18594SAndre Fischer rEvent.ContextName)); 17722de8995SAndre Fischer } 17822de8995SAndre Fischer 17922de8995SAndre Fischer 18022de8995SAndre Fischer 18122de8995SAndre Fischer 18222de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject) 18322de8995SAndre Fischer throw(cssu::RuntimeException) 18422de8995SAndre Fischer { 18595a18594SAndre Fischer (void)rEventObject; 186f120fe41SAndre Fischer 187f120fe41SAndre Fischer dispose(); 18822de8995SAndre Fischer } 18922de8995SAndre Fischer 19022de8995SAndre Fischer 19122de8995SAndre Fischer 19222de8995SAndre Fischer 193b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent) 194b9e67834SAndre Fischer throw(cssu::RuntimeException) 19595a18594SAndre Fischer { 19695a18594SAndre Fischer (void)rEvent; 19795a18594SAndre Fischer 19895a18594SAndre Fischer maPropertyChangeForwarder.RequestCall(); 19995a18594SAndre Fischer } 20095a18594SAndre Fischer 20195a18594SAndre Fischer 20295a18594SAndre Fischer 20395a18594SAndre Fischer 2047a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void) 2057a32b0c8SAndre Fischer throw(cssu::RuntimeException) 2067a32b0c8SAndre Fischer { 207f120fe41SAndre Fischer if (mpCurrentDeck) 208f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 2097a32b0c8SAndre Fischer RestrictWidth(); 2107a32b0c8SAndre Fischer } 2117a32b0c8SAndre Fischer 2127a32b0c8SAndre Fischer 2137a32b0c8SAndre Fischer 2147a32b0c8SAndre Fischer 21595a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void) 216b9e67834SAndre Fischer { 217b9e67834SAndre Fischer DataChangedEvent aEvent (DATACHANGED_USER); 218b9e67834SAndre Fischer mpParentWindow->NotifyAllChilds(aEvent); 219b9e67834SAndre Fischer mpParentWindow->Invalidate(INVALIDATE_CHILDREN); 220b9e67834SAndre Fischer } 221b9e67834SAndre Fischer 222b9e67834SAndre Fischer 223b9e67834SAndre Fischer 224b9e67834SAndre Fischer 22522de8995SAndre Fischer void SidebarController::NotifyResize (void) 22622de8995SAndre Fischer { 22795a18594SAndre Fischer if (mpTabBar == NULL) 22895a18594SAndre Fischer { 22995a18594SAndre Fischer OSL_ASSERT(mpTabBar!=NULL); 23095a18594SAndre Fischer return; 23195a18594SAndre Fischer } 23295a18594SAndre Fischer 23395a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent(); 23495a18594SAndre Fischer 23595a18594SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 23695a18594SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height()); 23795a18594SAndre Fischer 2387a32b0c8SAndre Fischer // Place the deck. 239f120fe41SAndre Fischer if (mpCurrentDeck) 2407a32b0c8SAndre Fischer { 241f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight); 242f120fe41SAndre Fischer mpCurrentDeck->Show(); 243f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 24422de8995SAndre Fischer } 24595a18594SAndre Fischer 2467a32b0c8SAndre Fischer // Place the tab bar. 24795a18594SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight); 24895a18594SAndre Fischer mpTabBar->Show(); 2497a32b0c8SAndre Fischer 2507a32b0c8SAndre Fischer // Determine if the closer of the deck can be shown. 251f120fe41SAndre Fischer if (mpCurrentDeck) 2527a32b0c8SAndre Fischer { 253f120fe41SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 2547a32b0c8SAndre Fischer if (pTitleBar != NULL && pTitleBar->IsVisible()) 2557a32b0c8SAndre Fischer pTitleBar->SetCloserVisible(CanModifyChildWindowWidth()); 2567a32b0c8SAndre Fischer } 2577a32b0c8SAndre Fischer 2587a32b0c8SAndre Fischer if (nWidth > TabBar::GetDefaultWidth()) 2597a32b0c8SAndre Fischer mnSavedSidebarWidth = nWidth; 2607a32b0c8SAndre Fischer 2617a32b0c8SAndre Fischer RestrictWidth(); 2627a32b0c8SAndre Fischer #ifdef DEBUG 263f120fe41SAndre Fischer if (mpCurrentDeck) 2647a32b0c8SAndre Fischer { 265f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 2667a32b0c8SAndre Fischer sal_Int32 nPanelIndex (0); 267f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 268f120fe41SAndre Fischer iPanel(mpCurrentDeck->GetPanels().begin()), 269f120fe41SAndre Fischer iEnd(mpCurrentDeck->GetPanels().end()); 2707a32b0c8SAndre Fischer iPanel!=iEnd; 2717a32b0c8SAndre Fischer ++iPanel,++nPanelIndex) 2727a32b0c8SAndre Fischer { 2737a32b0c8SAndre Fischer OSL_TRACE("panel %d:", nPanelIndex); 2747a32b0c8SAndre Fischer (*iPanel)->PrintWindowTree(); 2757a32b0c8SAndre Fischer } 2767a32b0c8SAndre Fischer } 2777a32b0c8SAndre Fischer #endif 27822de8995SAndre Fischer } 27922de8995SAndre Fischer 28022de8995SAndre Fischer 28122de8995SAndre Fischer 28222de8995SAndre Fischer 2837a32b0c8SAndre Fischer void SidebarController::UpdateConfigurations (const Context& rContext) 28422de8995SAndre Fischer { 28595a18594SAndre Fischer if (maCurrentContext != rContext) 28695a18594SAndre Fischer { 28795a18594SAndre Fischer maCurrentContext = rContext; 28895a18594SAndre Fischer 28995a18594SAndre Fischer // Notify the tab bar about the updated set of decks. 29095a18594SAndre Fischer ResourceManager::IdContainer aDeckIds; 29195a18594SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 29295a18594SAndre Fischer aDeckIds, 29395a18594SAndre Fischer rContext, 29495a18594SAndre Fischer mxFrame); 29595a18594SAndre Fischer mpTabBar->SetDecks(aDeckIds); 29695a18594SAndre Fischer 29795a18594SAndre Fischer // Check if the current deck is among the matching decks. 29895a18594SAndre Fischer bool bCurrentDeckMatches (false); 29995a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 30095a18594SAndre Fischer iDeck(aDeckIds.begin()), 30195a18594SAndre Fischer iEnd(aDeckIds.end()); 30295a18594SAndre Fischer iDeck!=iEnd; 30395a18594SAndre Fischer ++iDeck) 30495a18594SAndre Fischer { 30595a18594SAndre Fischer if (iDeck->equals(msCurrentDeckId)) 30695a18594SAndre Fischer { 30795a18594SAndre Fischer bCurrentDeckMatches = true; 30895a18594SAndre Fischer break; 30995a18594SAndre Fischer } 31095a18594SAndre Fischer } 311ff12d537SAndre Fischer 31295a18594SAndre Fischer DeckDescriptor const* pDeckDescriptor = NULL; 31395a18594SAndre Fischer if ( ! bCurrentDeckMatches) 31495a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetBestMatchingDeck(rContext, mxFrame); 31595a18594SAndre Fischer else 31695a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(msCurrentDeckId); 31795a18594SAndre Fischer if (pDeckDescriptor != NULL) 31895a18594SAndre Fischer { 31995a18594SAndre Fischer msCurrentDeckId = pDeckDescriptor->msId; 32095a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, rContext); 32195a18594SAndre Fischer } 322*54eaaa32SAndre Fischer 323*54eaaa32SAndre Fischer #ifdef DEBUG 324*54eaaa32SAndre Fischer // Show the context name in the deck title bar. 325*54eaaa32SAndre Fischer if (mpCurrentDeck) 326*54eaaa32SAndre Fischer { 327*54eaaa32SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 328*54eaaa32SAndre Fischer if (pTitleBar != NULL) 329*54eaaa32SAndre Fischer pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+rContext.msContext+A2S(")")); 330*54eaaa32SAndre Fischer } 331*54eaaa32SAndre Fischer #endif 33295a18594SAndre Fischer } 333ff12d537SAndre Fischer } 334ff12d537SAndre Fischer 335ff12d537SAndre Fischer 33622de8995SAndre Fischer 337ff12d537SAndre Fischer 338ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 33995a18594SAndre Fischer const ::rtl::OUString& rsDeckId) 340ff12d537SAndre Fischer { 3417a32b0c8SAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId) || mbIsDeckClosed) 34295a18594SAndre Fischer { 34395a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId); 34495a18594SAndre Fischer if (pDeckDescriptor != NULL) 34595a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 34695a18594SAndre Fischer } 34722de8995SAndre Fischer } 34822de8995SAndre Fischer 34922de8995SAndre Fischer 35022de8995SAndre Fischer 35122de8995SAndre Fischer 352ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 35322de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 3547a32b0c8SAndre Fischer const Context& rContext) 35522de8995SAndre Fischer { 35695a18594SAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)) 35795a18594SAndre Fischer { 35895a18594SAndre Fischer // When the deck changes then destroy the deck and all panels 35995a18594SAndre Fischer // and create everything new. 360f120fe41SAndre Fischer if (mpCurrentDeck) 36195a18594SAndre Fischer { 362f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 363f120fe41SAndre Fischer mpCurrentDeck.reset(); 36495a18594SAndre Fischer } 36595a18594SAndre Fischer 36695a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId; 36795a18594SAndre Fischer } 3687a32b0c8SAndre Fischer 3697a32b0c8SAndre Fischer // Reopen the deck when necessary. 3707a32b0c8SAndre Fischer OpenDeck(); 3717a32b0c8SAndre Fischer 372ff12d537SAndre Fischer // Determine the panels to display in the deck. 373f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors; 374ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 375f120fe41SAndre Fischer aPanelContextDescriptors, 376ff12d537SAndre Fischer rContext, 377ff12d537SAndre Fischer rDeckDescriptor.msId, 378ff12d537SAndre Fischer mxFrame); 379ff12d537SAndre Fischer 380*54eaaa32SAndre Fischer if (aPanelContextDescriptors.empty()) 381*54eaaa32SAndre Fischer { 382*54eaaa32SAndre Fischer // There are no panels to be displayed in the current context. 383*54eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty) 384*54eaaa32SAndre Fischer { 385*54eaaa32SAndre Fischer // Switch to the "empty" context and try again. 386*54eaaa32SAndre Fischer SwitchToDeck( 387*54eaaa32SAndre Fischer rDeckDescriptor, 388*54eaaa32SAndre Fischer Context( 389*54eaaa32SAndre Fischer rContext.msApplication, 390*54eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty))); 391*54eaaa32SAndre Fischer return; 392*54eaaa32SAndre Fischer } 393*54eaaa32SAndre Fischer else 394*54eaaa32SAndre Fischer { 395*54eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have 396*54eaaa32SAndre Fischer // to live with an empty deck. 397*54eaaa32SAndre Fischer } 398*54eaaa32SAndre Fischer } 399*54eaaa32SAndre Fischer 400f120fe41SAndre Fischer if (mpCurrentDeck 401f120fe41SAndre Fischer && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors)) 40202c50d82SAndre Fischer { 40302c50d82SAndre Fischer // Requested set of panels is identical to the current set of 40402c50d82SAndre Fischer // panels => Nothing to do. 40502c50d82SAndre Fischer return; 40602c50d82SAndre Fischer } 40702c50d82SAndre Fischer 40895a18594SAndre Fischer // Provide a configuration and Deck object. 409f120fe41SAndre Fischer if ( ! mpCurrentDeck) 41022de8995SAndre Fischer { 411f120fe41SAndre Fischer mpCurrentDeck.reset( 412f120fe41SAndre Fischer new Deck( 413f120fe41SAndre Fischer rDeckDescriptor, 414f120fe41SAndre Fischer mpParentWindow, 415f120fe41SAndre Fischer ::boost::bind(&SidebarController::CloseDeck, this))); 416*54eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle; 41795a18594SAndre Fischer } 418f120fe41SAndre Fischer if ( ! mpCurrentDeck) 419f120fe41SAndre Fischer return; 420f120fe41SAndre Fischer 42195a18594SAndre Fischer // Update the panel list. 422f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size()); 423f120fe41SAndre Fischer SharedPanelContainer aNewPanels; 424f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels()); 42595a18594SAndre Fischer aNewPanels.resize(nNewPanelCount); 4267a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0); 42702c50d82SAndre Fischer bool bHasPanelSetChanged (false); 4287a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex) 42995a18594SAndre Fischer { 430f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor ( 431f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]); 43295a18594SAndre Fischer 43395a18594SAndre Fischer // Find the corresponding panel among the currently active 43495a18594SAndre Fischer // panels. 435f120fe41SAndre Fischer SharedPanelContainer::const_iterator iPanel (::std::find_if( 436f120fe41SAndre Fischer rCurrentPanels.begin(), 437f120fe41SAndre Fischer rCurrentPanels.end(), 438f120fe41SAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)))); 439f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end()) 440ff12d537SAndre Fischer { 441f120fe41SAndre Fischer // Panel already exists in current deck. Reuse it. 4427a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel; 443f120fe41SAndre Fischer OSL_TRACE(" reusing panel %s", S2A(rPanelContexDescriptor.msId)); 444ff12d537SAndre Fischer } 445ff12d537SAndre Fischer else 446ff12d537SAndre Fischer { 44795a18594SAndre Fischer // Panel does not yet exist. Create it. 4487a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel( 449f120fe41SAndre Fischer rPanelContexDescriptor.msId, 450f120fe41SAndre Fischer mpCurrentDeck->GetPanelParentWindow(), 451f120fe41SAndre Fischer rPanelContexDescriptor.msMenuCommand); 452f120fe41SAndre Fischer OSL_TRACE(" creating panel %s", S2A(rPanelContexDescriptor.msId)); 45302c50d82SAndre Fischer bHasPanelSetChanged = true; 454ff12d537SAndre Fischer } 4557a32b0c8SAndre Fischer if (aNewPanels[nWriteIndex] != NULL) 45602c50d82SAndre Fischer { 457f120fe41SAndre Fischer // Depending on the context we have to collapse the panel. 458f120fe41SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible); 459f120fe41SAndre Fischer 460f120fe41SAndre Fischer ++nWriteIndex; 46102c50d82SAndre Fischer } 462f120fe41SAndre Fischer 46395a18594SAndre Fischer } 464f120fe41SAndre Fischer aNewPanels.resize(nWriteIndex); 46595a18594SAndre Fischer 46695a18594SAndre Fischer // Activate the deck and the new set of panels. 467f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel( 46895a18594SAndre Fischer 0, 46995a18594SAndre Fischer 0, 47095a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 47195a18594SAndre Fischer mpParentWindow->GetSizePixel().Height()); 472f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels); 473f120fe41SAndre Fischer mpCurrentDeck->Show(); 474ff12d537SAndre Fischer 475ff12d537SAndre Fischer // Tell the tab bar to highlight the button associated with the 476ff12d537SAndre Fischer // deck. 477ff12d537SAndre Fischer mpTabBar->HighlightDeck(rDeckDescriptor.msId); 4787a32b0c8SAndre Fischer 4797a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle); 4807a32b0c8SAndre Fischer 48102c50d82SAndre Fischer if (bHasPanelSetChanged) 48202c50d82SAndre Fischer NotifyResize(); 48302c50d82SAndre Fischer } 48402c50d82SAndre Fischer 48502c50d82SAndre Fischer 48602c50d82SAndre Fischer 48702c50d82SAndre Fischer 48802c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual ( 489f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels, 490f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels) 49102c50d82SAndre Fischer { 49202c50d82SAndre Fischer OSL_TRACE("current panel list:"); 493f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 49402c50d82SAndre Fischer iPanel(rCurrentPanels.begin()), 49502c50d82SAndre Fischer iEnd(rCurrentPanels.end()); 49602c50d82SAndre Fischer iPanel!=iEnd; 49702c50d82SAndre Fischer ++iPanel) 49802c50d82SAndre Fischer { 49902c50d82SAndre Fischer OSL_TRACE(" panel %s", S2A((*iPanel)->GetId())); 50002c50d82SAndre Fischer } 50102c50d82SAndre Fischer 50202c50d82SAndre Fischer OSL_TRACE("requested panels: "); 503f120fe41SAndre Fischer for (ResourceManager::PanelContextDescriptorContainer::const_iterator 504f120fe41SAndre Fischer iId(rRequestedPanels.begin()), 505f120fe41SAndre Fischer iEnd(rRequestedPanels.end()); 50602c50d82SAndre Fischer iId!=iEnd; 50702c50d82SAndre Fischer ++iId) 50802c50d82SAndre Fischer { 509f120fe41SAndre Fischer OSL_TRACE(" panel %s", S2A(iId->msId)); 51002c50d82SAndre Fischer } 51102c50d82SAndre Fischer 512f120fe41SAndre Fischer if (rCurrentPanels.size() != rRequestedPanels.size()) 51302c50d82SAndre Fischer return false; 51402c50d82SAndre Fischer for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex) 51502c50d82SAndre Fischer { 51602c50d82SAndre Fischer if (rCurrentPanels[nIndex] == NULL) 51702c50d82SAndre Fischer return false; 518f120fe41SAndre Fischer if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId)) 51902c50d82SAndre Fischer return false; 52002c50d82SAndre Fischer } 52102c50d82SAndre Fischer return true; 52222de8995SAndre Fischer } 52322de8995SAndre Fischer 52422de8995SAndre Fischer 52522de8995SAndre Fischer 52622de8995SAndre Fischer 527f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel ( 52895a18594SAndre Fischer const OUString& rsPanelId, 529f120fe41SAndre Fischer ::Window* pParentWindow, 530f120fe41SAndre Fischer const OUString& rsMenuCommand) 53195a18594SAndre Fischer { 53295a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId); 53395a18594SAndre Fischer if (pPanelDescriptor == NULL) 534f120fe41SAndre Fischer return SharedPanel(); 5357a32b0c8SAndre Fischer 5367a32b0c8SAndre Fischer #ifdef DEBUG 5377a32b0c8SAndre Fischer // Prevent the panel not being created in the same memory of an old panel. 5387a32b0c8SAndre Fischer ::boost::scoped_array<char> pUnused (new char[sizeof(Panel)]); 5397a32b0c8SAndre Fischer OSL_TRACE("allocated memory at %x", pUnused.get()); 5407a32b0c8SAndre Fischer #endif 5417a32b0c8SAndre Fischer 54295a18594SAndre Fischer // Create the panel which is the parent window of the UIElement. 543f120fe41SAndre Fischer SharedPanel pPanel (new Panel( 54495a18594SAndre Fischer *pPanelDescriptor, 5457a32b0c8SAndre Fischer pParentWindow, 546f120fe41SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()), 547f120fe41SAndre Fischer rsMenuCommand.getLength()>0 548f120fe41SAndre Fischer ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rsMenuCommand) 549f120fe41SAndre Fischer : ::boost::function<void(void)>())); 55095a18594SAndre Fischer 55195a18594SAndre Fischer // Create the XUIElement. 55295a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 55395a18594SAndre Fischer pPanel->GetComponentInterface(), 554f120fe41SAndre Fischer pPanelDescriptor->msImplementationURL)); 55595a18594SAndre Fischer if (xUIElement.is()) 55695a18594SAndre Fischer { 55795a18594SAndre Fischer // Initialize the panel and add it to the active deck. 55895a18594SAndre Fischer pPanel->SetUIElement(xUIElement); 55995a18594SAndre Fischer } 56095a18594SAndre Fischer else 56195a18594SAndre Fischer { 562f120fe41SAndre Fischer pPanel.reset(); 56395a18594SAndre Fischer } 56495a18594SAndre Fischer 56595a18594SAndre Fischer return pPanel; 56695a18594SAndre Fischer } 56795a18594SAndre Fischer 56895a18594SAndre Fischer 56995a18594SAndre Fischer 57095a18594SAndre Fischer 571ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 572ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 573f120fe41SAndre Fischer const ::rtl::OUString& rsImplementationURL) 57422de8995SAndre Fischer { 57522de8995SAndre Fischer try 57622de8995SAndre Fischer { 57722de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 57822de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 57922de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 58022de8995SAndre Fischer UNO_QUERY_THROW); 581ff12d537SAndre Fischer 5827a32b0c8SAndre Fischer // Create the XUIElement. 58322de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 58422de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 585ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 586b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow); 587b9e67834SAndre Fischer if (pSfxDockingWindow != NULL) 588b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings()))); 5897a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet()); 5907a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this)))); 5917a32b0c8SAndre Fischer 592b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement( 593ff12d537SAndre Fischer xUIElementFactory->createUIElement( 594ff12d537SAndre Fischer rsImplementationURL, 5957a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())), 596ff12d537SAndre Fischer UNO_QUERY_THROW); 597b9e67834SAndre Fischer 598b9e67834SAndre Fischer return xUIElement; 59922de8995SAndre Fischer } 60022de8995SAndre Fischer catch(Exception& rException) 60122de8995SAndre Fischer { 60222de8995SAndre Fischer OSL_TRACE("caught exception: %s", 60322de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 60422de8995SAndre Fischer // For some reason we can not create the actual panel. 60522de8995SAndre Fischer // Probably because its factory was not properly registered. 60622de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 60722de8995SAndre Fischer // source of the error. 608ff12d537SAndre Fischer 609ff12d537SAndre Fischer return NULL; 61022de8995SAndre Fischer } 61122de8995SAndre Fischer } 61222de8995SAndre Fischer 61322de8995SAndre Fischer 61422de8995SAndre Fischer 61522de8995SAndre Fischer 61622de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 61722de8995SAndre Fischer { 61822de8995SAndre Fischer if (pEvent != NULL) 61922de8995SAndre Fischer { 62022de8995SAndre Fischer switch (pEvent->GetId()) 62122de8995SAndre Fischer { 62222de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 62322de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 62422de8995SAndre Fischer break; 62522de8995SAndre Fischer 62622de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 62722de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 62822de8995SAndre Fischer NotifyResize(); 62922de8995SAndre Fischer break; 63022de8995SAndre Fischer 631ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 632ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 633ff12d537SAndre Fischer // changes in theme (high contrast mode). 634ff12d537SAndre Fischer Theme::HandleDataChange(); 635ff12d537SAndre Fischer mpParentWindow->Invalidate(); 636ff12d537SAndre Fischer break; 637ff12d537SAndre Fischer 63822de8995SAndre Fischer case SFX_HINT_DYING: 63922de8995SAndre Fischer dispose(); 64022de8995SAndre Fischer break; 64122de8995SAndre Fischer 64222de8995SAndre Fischer default: 64322de8995SAndre Fischer break; 64422de8995SAndre Fischer } 64522de8995SAndre Fischer } 64622de8995SAndre Fischer 64722de8995SAndre Fischer return sal_True; 64822de8995SAndre Fischer } 64922de8995SAndre Fischer 65022de8995SAndre Fischer 65122de8995SAndre Fischer 65222de8995SAndre Fischer 65395a18594SAndre Fischer void SidebarController::ShowPopupMenu ( 65495a18594SAndre Fischer const Rectangle& rButtonBox, 65595a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 65695a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 65722de8995SAndre Fischer { 65895a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData); 659ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 660ff12d537SAndre Fischer 661ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 662ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 663ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 664ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 66522de8995SAndre Fischer } 66622de8995SAndre Fischer 66722de8995SAndre Fischer 66822de8995SAndre Fischer 66922de8995SAndre Fischer 670f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const 671f120fe41SAndre Fischer { 672f120fe41SAndre Fischer try 673f120fe41SAndre Fischer { 674f120fe41SAndre Fischer util::URL aURL; 675f120fe41SAndre Fischer aURL.Complete = rsMenuCommand; 676f120fe41SAndre Fischer 677f120fe41SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 678f120fe41SAndre Fischer const Reference<util::XURLTransformer> xParser ( 679f120fe41SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 680f120fe41SAndre Fischer UNO_QUERY_THROW); 681f120fe41SAndre Fischer xParser->parseStrict(aURL); 682f120fe41SAndre Fischer Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW); 683f120fe41SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(aURL, OUString(), 0)); 684f120fe41SAndre Fischer if (xDispatch.is()) 685f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 686f120fe41SAndre Fischer } 687f120fe41SAndre Fischer catch(Exception& rException) 688f120fe41SAndre Fischer { 689f120fe41SAndre Fischer OSL_TRACE("caught exception: %s", 690f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 691f120fe41SAndre Fischer } 692f120fe41SAndre Fischer } 693f120fe41SAndre Fischer 694f120fe41SAndre Fischer 695f120fe41SAndre Fischer 696f120fe41SAndre Fischer 69795a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu ( 69895a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 69995a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 70022de8995SAndre Fischer { 701ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 702ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 703ff12d537SAndre Fischer if (pMenuWindow != NULL) 704ff12d537SAndre Fischer { 705ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 706ff12d537SAndre Fischer } 707ff12d537SAndre Fischer 708ff12d537SAndre Fischer SidebarResource aLocalResource; 709ff12d537SAndre Fischer 710ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 711ff12d537SAndre Fischer // them visible or hide them. 71222de8995SAndre Fischer { 71395a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_PANEL); 71495a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 71595a18594SAndre Fischer iItem(rDeckSelectionData.begin()), 71695a18594SAndre Fischer iEnd(rDeckSelectionData.end()); 71795a18594SAndre Fischer iItem!=iEnd; 71895a18594SAndre Fischer ++iItem) 71995a18594SAndre Fischer { 72095a18594SAndre Fischer pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK); 72195a18594SAndre Fischer pMenu->CheckItem(nIndex, iItem->get<2>()); 72295a18594SAndre Fischer ++nIndex; 72395a18594SAndre Fischer } 72422de8995SAndre Fischer } 72522de8995SAndre Fischer 72695a18594SAndre Fischer pMenu->InsertSeparator(); 72795a18594SAndre Fischer 728ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 729ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 730ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 731ff12d537SAndre Fischer else 732ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 733ff12d537SAndre Fischer 734ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 735ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 73695a18594SAndre Fischer { 73795a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_HIDE); 73895a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 73995a18594SAndre Fischer iItem(rDeckShowData.begin()), 74095a18594SAndre Fischer iEnd(rDeckShowData.end()); 74195a18594SAndre Fischer iItem!=iEnd; 74295a18594SAndre Fischer ++iItem) 74395a18594SAndre Fischer { 74495a18594SAndre Fischer pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE); 74595a18594SAndre Fischer pCustomizationMenu->CheckItem(nIndex, iItem->get<2>()); 74695a18594SAndre Fischer ++nIndex; 74795a18594SAndre Fischer } 74895a18594SAndre Fischer } 74995a18594SAndre Fischer 750ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 751ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 752ff12d537SAndre Fischer 753ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 754ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 755ff12d537SAndre Fischer 756ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 757ff12d537SAndre Fischer 758ff12d537SAndre Fischer return pMenu; 75922de8995SAndre Fischer } 76022de8995SAndre Fischer 76122de8995SAndre Fischer 76222de8995SAndre Fischer 76322de8995SAndre Fischer 764ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 76522de8995SAndre Fischer { 766ff12d537SAndre Fischer if (pMenu == NULL) 767ff12d537SAndre Fischer { 7687a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!"); 769ff12d537SAndre Fischer return 0; 770ff12d537SAndre Fischer } 77122de8995SAndre Fischer 772ff12d537SAndre Fischer pMenu->Deactivate(); 773ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 774ff12d537SAndre Fischer switch (nIndex) 77522de8995SAndre Fischer { 776ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 777ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 778ff12d537SAndre Fischer break; 779ff12d537SAndre Fischer 780ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 781ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 782ff12d537SAndre Fischer break; 783ff12d537SAndre Fischer 784ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 785ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 786ff12d537SAndre Fischer break; 787ff12d537SAndre Fischer 788ff12d537SAndre Fischer default: 789ff12d537SAndre Fischer { 790ff12d537SAndre Fischer try 791ff12d537SAndre Fischer { 792ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 79395a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL)); 794ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 795ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 796ff12d537SAndre Fischer } 797ff12d537SAndre Fischer catch (RuntimeException&) 798ff12d537SAndre Fischer { 799ff12d537SAndre Fischer } 800ff12d537SAndre Fischer } 801ff12d537SAndre Fischer break; 80222de8995SAndre Fischer } 803ff12d537SAndre Fischer 804ff12d537SAndre Fischer return 1; 80522de8995SAndre Fischer } 80622de8995SAndre Fischer 80722de8995SAndre Fischer 808ff12d537SAndre Fischer 809ff12d537SAndre Fischer 8107a32b0c8SAndre Fischer void SidebarController::CloseDeck (void) 8117a32b0c8SAndre Fischer { 8127a32b0c8SAndre Fischer if ( ! mbIsDeckClosed) 8137a32b0c8SAndre Fischer { 8147a32b0c8SAndre Fischer mbIsDeckClosed = true; 8157a32b0c8SAndre Fischer if ( ! mpParentWindow->IsFloatingMode()) 8167a32b0c8SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth()); 8177a32b0c8SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE); 8187a32b0c8SAndre Fischer 819f120fe41SAndre Fischer if (mpCurrentDeck) 820f120fe41SAndre Fischer mpCurrentDeck->Hide(); 8217a32b0c8SAndre Fischer 8227a32b0c8SAndre Fischer NotifyResize(); 8237a32b0c8SAndre Fischer } 8247a32b0c8SAndre Fischer } 8257a32b0c8SAndre Fischer 8267a32b0c8SAndre Fischer 8277a32b0c8SAndre Fischer 8287a32b0c8SAndre Fischer 8297a32b0c8SAndre Fischer void SidebarController::OpenDeck (void) 8307a32b0c8SAndre Fischer { 8317a32b0c8SAndre Fischer if (mbIsDeckClosed) 8327a32b0c8SAndre Fischer { 8337a32b0c8SAndre Fischer mbIsDeckClosed = false; 8347a32b0c8SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth); 8357a32b0c8SAndre Fischer 836f120fe41SAndre Fischer if (mpCurrentDeck) 837f120fe41SAndre Fischer mpCurrentDeck->Show(); 8387a32b0c8SAndre Fischer 8397a32b0c8SAndre Fischer NotifyResize(); 8407a32b0c8SAndre Fischer } 8417a32b0c8SAndre Fischer } 8427a32b0c8SAndre Fischer 8437a32b0c8SAndre Fischer 8447a32b0c8SAndre Fischer 8457a32b0c8SAndre Fischer 8467a32b0c8SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void) const 8477a32b0c8SAndre Fischer { 8487a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8497a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8507a32b0c8SAndre Fischer { 8517a32b0c8SAndre Fischer OSL_ASSERT(pSplitWindow!=NULL); 8527a32b0c8SAndre Fischer return 0; 8537a32b0c8SAndre Fischer } 8547a32b0c8SAndre Fischer 8557a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8567a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8577a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8587a32b0c8SAndre Fischer 8597a32b0c8SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn)); 8607a32b0c8SAndre Fischer 8617a32b0c8SAndre Fischer return nRowCount == 1; 8627a32b0c8SAndre Fischer } 8637a32b0c8SAndre Fischer 8647a32b0c8SAndre Fischer 8657a32b0c8SAndre Fischer 8667a32b0c8SAndre Fischer 8677a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth) 8687a32b0c8SAndre Fischer { 8697a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8707a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8717a32b0c8SAndre Fischer return 0; 8727a32b0c8SAndre Fischer 8737a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8747a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8757a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8767a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn)); 8777a32b0c8SAndre Fischer 8787a32b0c8SAndre Fischer Window* pWindow = mpParentWindow; 8797a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel()); 8807a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel()); 8817a32b0c8SAndre Fischer 8827a32b0c8SAndre Fischer pSplitWindow->MoveWindow( 8837a32b0c8SAndre Fischer mpParentWindow, 8847a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()), 8857a32b0c8SAndre Fischer nColumn, 8867a32b0c8SAndre Fischer nRow); 8877a32b0c8SAndre Fischer 8887a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth); 8897a32b0c8SAndre Fischer } 8907a32b0c8SAndre Fischer 8917a32b0c8SAndre Fischer 8927a32b0c8SAndre Fischer 8937a32b0c8SAndre Fischer 8947a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void) 8957a32b0c8SAndre Fischer { 8967a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8977a32b0c8SAndre Fischer if (pSplitWindow != NULL) 8987a32b0c8SAndre Fischer { 8997a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow)); 9007a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId)); 9017a32b0c8SAndre Fischer // Minimum width is always that of the tabbar. 9027a32b0c8SAndre Fischer const sal_Int32 nMinimumWidth (TabBar::GetDefaultWidth()); 9037a32b0c8SAndre Fischer // Maximum width depends on whether the deck is open or closed. 9047a32b0c8SAndre Fischer const sal_Int32 nMaximumWidth ( 9057a32b0c8SAndre Fischer mbIsDeckClosed 9067a32b0c8SAndre Fischer ? TabBar::GetDefaultWidth() 9077a32b0c8SAndre Fischer : 400); 9087a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange( 9097a32b0c8SAndre Fischer nSetId, 9107a32b0c8SAndre Fischer Range(nMinimumWidth, nMaximumWidth)); 9117a32b0c8SAndre Fischer if (nMinimumWidth == nMaximumWidth) 9127a32b0c8SAndre Fischer pSplitWindow->SetItemSize(nSetId, nMinimumWidth); 9137a32b0c8SAndre Fischer } 9147a32b0c8SAndre Fischer } 9157a32b0c8SAndre Fischer 916ff12d537SAndre Fischer 917ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 918