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" 3454eaaa32SAndre 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 7222de8995SAndre 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 7922de8995SAndre 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 { 139*65908a7eSAndre Fischer maFocusManager.Clear(); 140*65908a7eSAndre Fischer 14122de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 14222de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 14322de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 14422de8995SAndre Fischer if (xMultiplexer.is()) 14522de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 14622de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 14722de8995SAndre Fischer 14822de8995SAndre Fischer if (mpParentWindow != NULL) 14922de8995SAndre Fischer { 15022de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 15122de8995SAndre Fischer mpParentWindow = NULL; 15222de8995SAndre Fischer } 153b9e67834SAndre Fischer 154f120fe41SAndre Fischer if (mpCurrentDeck) 155b9e67834SAndre Fischer { 156f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 157f120fe41SAndre Fischer OSL_TRACE("deleting deck window subtree"); 158f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 159f120fe41SAndre Fischer mpCurrentDeck.reset(); 160b9e67834SAndre Fischer } 161b9e67834SAndre Fischer 162580828edSAndre Fischer mpTabBar.reset(); 163580828edSAndre Fischer 164b9e67834SAndre Fischer Theme::GetPropertySet()->removePropertyChangeListener( 165b9e67834SAndre Fischer A2S(""), 166b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 16722de8995SAndre Fischer } 16822de8995SAndre Fischer 16922de8995SAndre Fischer 17022de8995SAndre Fischer 17122de8995SAndre Fischer 17222de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) 17322de8995SAndre Fischer throw(cssu::RuntimeException) 17422de8995SAndre Fischer { 17595a18594SAndre Fischer UpdateConfigurations( 1767a32b0c8SAndre Fischer Context( 17795a18594SAndre Fischer rEvent.ApplicationName, 17895a18594SAndre Fischer rEvent.ContextName)); 17922de8995SAndre Fischer } 18022de8995SAndre Fischer 18122de8995SAndre Fischer 18222de8995SAndre Fischer 18322de8995SAndre Fischer 18422de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject) 18522de8995SAndre Fischer throw(cssu::RuntimeException) 18622de8995SAndre Fischer { 18795a18594SAndre Fischer (void)rEventObject; 18895a18594SAndre Fischer 189f120fe41SAndre Fischer dispose(); 19022de8995SAndre Fischer } 19122de8995SAndre Fischer 19222de8995SAndre Fischer 19322de8995SAndre Fischer 19422de8995SAndre Fischer 195b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent) 196b9e67834SAndre Fischer throw(cssu::RuntimeException) 197b9e67834SAndre Fischer { 19895a18594SAndre Fischer (void)rEvent; 19995a18594SAndre Fischer 20095a18594SAndre Fischer maPropertyChangeForwarder.RequestCall(); 20195a18594SAndre Fischer } 20295a18594SAndre Fischer 20395a18594SAndre Fischer 20495a18594SAndre Fischer 20595a18594SAndre Fischer 2067a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void) 2077a32b0c8SAndre Fischer throw(cssu::RuntimeException) 2087a32b0c8SAndre Fischer { 209f120fe41SAndre Fischer if (mpCurrentDeck) 210f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 2117a32b0c8SAndre Fischer RestrictWidth(); 2127a32b0c8SAndre Fischer } 2137a32b0c8SAndre Fischer 2147a32b0c8SAndre Fischer 2157a32b0c8SAndre Fischer 2167a32b0c8SAndre Fischer 21795a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void) 21895a18594SAndre Fischer { 219b9e67834SAndre Fischer DataChangedEvent aEvent (DATACHANGED_USER); 220b9e67834SAndre Fischer mpParentWindow->NotifyAllChilds(aEvent); 221b9e67834SAndre Fischer mpParentWindow->Invalidate(INVALIDATE_CHILDREN); 222b9e67834SAndre Fischer } 223b9e67834SAndre Fischer 224b9e67834SAndre Fischer 225b9e67834SAndre Fischer 226b9e67834SAndre Fischer 22722de8995SAndre Fischer void SidebarController::NotifyResize (void) 22822de8995SAndre Fischer { 22995a18594SAndre Fischer if (mpTabBar == NULL) 23022de8995SAndre Fischer { 23195a18594SAndre Fischer OSL_ASSERT(mpTabBar!=NULL); 23295a18594SAndre Fischer return; 233ff12d537SAndre Fischer } 23495a18594SAndre Fischer 23595a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent(); 23622de8995SAndre Fischer 237ff12d537SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 238ff12d537SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height()); 23995a18594SAndre Fischer 2407a32b0c8SAndre Fischer // Place the deck. 241f120fe41SAndre Fischer if (mpCurrentDeck) 2427a32b0c8SAndre Fischer { 243f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight); 244f120fe41SAndre Fischer mpCurrentDeck->Show(); 245f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 246ff12d537SAndre Fischer } 24795a18594SAndre Fischer 2487a32b0c8SAndre Fischer // Place the tab bar. 24995a18594SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight); 25095a18594SAndre Fischer mpTabBar->Show(); 2517a32b0c8SAndre Fischer 2527a32b0c8SAndre Fischer // Determine if the closer of the deck can be shown. 253f120fe41SAndre Fischer if (mpCurrentDeck) 2547a32b0c8SAndre Fischer { 255f120fe41SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 2567a32b0c8SAndre Fischer if (pTitleBar != NULL && pTitleBar->IsVisible()) 2577a32b0c8SAndre Fischer pTitleBar->SetCloserVisible(CanModifyChildWindowWidth()); 2587a32b0c8SAndre Fischer } 2597a32b0c8SAndre Fischer 2607a32b0c8SAndre Fischer if (nWidth > TabBar::GetDefaultWidth()) 2617a32b0c8SAndre Fischer mnSavedSidebarWidth = nWidth; 2627a32b0c8SAndre Fischer 2637a32b0c8SAndre Fischer RestrictWidth(); 2647a32b0c8SAndre Fischer #ifdef DEBUG 265f120fe41SAndre Fischer if (mpCurrentDeck) 2667a32b0c8SAndre Fischer { 267f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 2687a32b0c8SAndre Fischer sal_Int32 nPanelIndex (0); 269f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 270f120fe41SAndre Fischer iPanel(mpCurrentDeck->GetPanels().begin()), 271f120fe41SAndre Fischer iEnd(mpCurrentDeck->GetPanels().end()); 2727a32b0c8SAndre Fischer iPanel!=iEnd; 2737a32b0c8SAndre Fischer ++iPanel,++nPanelIndex) 2747a32b0c8SAndre Fischer { 2757a32b0c8SAndre Fischer OSL_TRACE("panel %d:", nPanelIndex); 2767a32b0c8SAndre Fischer (*iPanel)->PrintWindowTree(); 2777a32b0c8SAndre Fischer } 2787a32b0c8SAndre Fischer } 2797a32b0c8SAndre Fischer #endif 280ff12d537SAndre Fischer } 28122de8995SAndre Fischer 282ff12d537SAndre Fischer 283ff12d537SAndre Fischer 284ff12d537SAndre Fischer 2857a32b0c8SAndre Fischer void SidebarController::UpdateConfigurations (const Context& rContext) 28695a18594SAndre Fischer { 28795a18594SAndre Fischer if (maCurrentContext != rContext) 288ff12d537SAndre Fischer { 289ff12d537SAndre Fischer maCurrentContext = rContext; 290ff12d537SAndre Fischer 29195a18594SAndre Fischer // Notify the tab bar about the updated set of decks. 29295a18594SAndre Fischer ResourceManager::IdContainer aDeckIds; 293ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 29495a18594SAndre Fischer aDeckIds, 29522de8995SAndre Fischer rContext, 296ff12d537SAndre Fischer mxFrame); 29795a18594SAndre Fischer mpTabBar->SetDecks(aDeckIds); 29822de8995SAndre Fischer 29995a18594SAndre Fischer // Check if the current deck is among the matching decks. 30095a18594SAndre Fischer bool bCurrentDeckMatches (false); 30195a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 30295a18594SAndre Fischer iDeck(aDeckIds.begin()), 30395a18594SAndre Fischer iEnd(aDeckIds.end()); 30495a18594SAndre Fischer iDeck!=iEnd; 30595a18594SAndre Fischer ++iDeck) 30695a18594SAndre Fischer { 30795a18594SAndre Fischer if (iDeck->equals(msCurrentDeckId)) 30895a18594SAndre Fischer { 30995a18594SAndre Fischer bCurrentDeckMatches = true; 31095a18594SAndre Fischer break; 31195a18594SAndre Fischer } 31295a18594SAndre Fischer } 31395a18594SAndre Fischer 31495a18594SAndre Fischer DeckDescriptor const* pDeckDescriptor = NULL; 31595a18594SAndre Fischer if ( ! bCurrentDeckMatches) 31695a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetBestMatchingDeck(rContext, mxFrame); 31795a18594SAndre Fischer else 31895a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(msCurrentDeckId); 319ff12d537SAndre Fischer if (pDeckDescriptor != NULL) 32095a18594SAndre Fischer { 32195a18594SAndre Fischer msCurrentDeckId = pDeckDescriptor->msId; 322ff12d537SAndre Fischer SwitchToDeck(*pDeckDescriptor, rContext); 32322de8995SAndre Fischer } 32454eaaa32SAndre Fischer 32554eaaa32SAndre Fischer #ifdef DEBUG 32654eaaa32SAndre Fischer // Show the context name in the deck title bar. 32754eaaa32SAndre Fischer if (mpCurrentDeck) 32854eaaa32SAndre Fischer { 32954eaaa32SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 33054eaaa32SAndre Fischer if (pTitleBar != NULL) 33154eaaa32SAndre Fischer pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+rContext.msContext+A2S(")")); 33254eaaa32SAndre Fischer } 33354eaaa32SAndre Fischer #endif 33495a18594SAndre Fischer } 33595a18594SAndre Fischer } 33622de8995SAndre Fischer 33722de8995SAndre Fischer 33822de8995SAndre Fischer 33922de8995SAndre Fischer 340ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 34195a18594SAndre Fischer const ::rtl::OUString& rsDeckId) 342ff12d537SAndre Fischer { 3437a32b0c8SAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId) || mbIsDeckClosed) 34495a18594SAndre Fischer { 34595a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId); 34695a18594SAndre Fischer if (pDeckDescriptor != NULL) 34795a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 34895a18594SAndre Fischer } 349ff12d537SAndre Fischer } 350ff12d537SAndre Fischer 351ff12d537SAndre Fischer 352ff12d537SAndre Fischer 353ff12d537SAndre Fischer 354ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 35522de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 3567a32b0c8SAndre Fischer const Context& rContext) 35722de8995SAndre Fischer { 358*65908a7eSAndre Fischer maFocusManager.Clear(); 359*65908a7eSAndre Fischer 36095a18594SAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)) 36195a18594SAndre Fischer { 36295a18594SAndre Fischer // When the deck changes then destroy the deck and all panels 36395a18594SAndre Fischer // and create everything new. 364f120fe41SAndre Fischer if (mpCurrentDeck) 36595a18594SAndre Fischer { 366f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 367f120fe41SAndre Fischer mpCurrentDeck.reset(); 36895a18594SAndre Fischer } 36995a18594SAndre Fischer 37095a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId; 37195a18594SAndre Fischer } 37295a18594SAndre Fischer 3737a32b0c8SAndre Fischer // Reopen the deck when necessary. 3747a32b0c8SAndre Fischer OpenDeck(); 3757a32b0c8SAndre Fischer 376ff12d537SAndre Fischer // Determine the panels to display in the deck. 377f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors; 378ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 379f120fe41SAndre Fischer aPanelContextDescriptors, 380ff12d537SAndre Fischer rContext, 381ff12d537SAndre Fischer rDeckDescriptor.msId, 382ff12d537SAndre Fischer mxFrame); 383ff12d537SAndre Fischer 38454eaaa32SAndre Fischer if (aPanelContextDescriptors.empty()) 38554eaaa32SAndre Fischer { 38654eaaa32SAndre Fischer // There are no panels to be displayed in the current context. 38754eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty) 38854eaaa32SAndre Fischer { 38954eaaa32SAndre Fischer // Switch to the "empty" context and try again. 39054eaaa32SAndre Fischer SwitchToDeck( 39154eaaa32SAndre Fischer rDeckDescriptor, 39254eaaa32SAndre Fischer Context( 39354eaaa32SAndre Fischer rContext.msApplication, 39454eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty))); 39554eaaa32SAndre Fischer return; 39654eaaa32SAndre Fischer } 39754eaaa32SAndre Fischer else 39854eaaa32SAndre Fischer { 39954eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have 40054eaaa32SAndre Fischer // to live with an empty deck. 40154eaaa32SAndre Fischer } 40254eaaa32SAndre Fischer } 40354eaaa32SAndre Fischer 404f120fe41SAndre Fischer if (mpCurrentDeck 405f120fe41SAndre Fischer && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors)) 40602c50d82SAndre Fischer { 40702c50d82SAndre Fischer // Requested set of panels is identical to the current set of 40802c50d82SAndre Fischer // panels => Nothing to do. 40902c50d82SAndre Fischer return; 41002c50d82SAndre Fischer } 41102c50d82SAndre Fischer 41295a18594SAndre Fischer // Provide a configuration and Deck object. 413f120fe41SAndre Fischer if ( ! mpCurrentDeck) 41422de8995SAndre Fischer { 415f120fe41SAndre Fischer mpCurrentDeck.reset( 416f120fe41SAndre Fischer new Deck( 4177a32b0c8SAndre Fischer rDeckDescriptor, 4187a32b0c8SAndre Fischer mpParentWindow, 419f120fe41SAndre Fischer ::boost::bind(&SidebarController::CloseDeck, this))); 42054eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle; 42195a18594SAndre Fischer } 422f120fe41SAndre Fischer if ( ! mpCurrentDeck) 423f120fe41SAndre Fischer return; 424ff12d537SAndre Fischer 42595a18594SAndre Fischer // Update the panel list. 426f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size()); 427f120fe41SAndre Fischer SharedPanelContainer aNewPanels; 428f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels()); 42995a18594SAndre Fischer aNewPanels.resize(nNewPanelCount); 4307a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0); 43102c50d82SAndre Fischer bool bHasPanelSetChanged (false); 4327a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex) 433ff12d537SAndre Fischer { 434f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor ( 435f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]); 43695a18594SAndre Fischer 43795a18594SAndre Fischer // Find the corresponding panel among the currently active 43895a18594SAndre Fischer // panels. 439f120fe41SAndre Fischer SharedPanelContainer::const_iterator iPanel (::std::find_if( 440f120fe41SAndre Fischer rCurrentPanels.begin(), 441f120fe41SAndre Fischer rCurrentPanels.end(), 442f120fe41SAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)))); 443f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end()) 44495a18594SAndre Fischer { 445f120fe41SAndre Fischer // Panel already exists in current deck. Reuse it. 4467a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel; 447f120fe41SAndre Fischer OSL_TRACE(" reusing panel %s", S2A(rPanelContexDescriptor.msId)); 448ff12d537SAndre Fischer } 449ff12d537SAndre Fischer else 450ff12d537SAndre Fischer { 45195a18594SAndre Fischer // Panel does not yet exist. Create it. 4527a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel( 453f120fe41SAndre Fischer rPanelContexDescriptor.msId, 454f120fe41SAndre Fischer mpCurrentDeck->GetPanelParentWindow(), 455f120fe41SAndre Fischer rPanelContexDescriptor.msMenuCommand); 456f120fe41SAndre Fischer OSL_TRACE(" creating panel %s", S2A(rPanelContexDescriptor.msId)); 45702c50d82SAndre Fischer bHasPanelSetChanged = true; 458ff12d537SAndre Fischer } 4597a32b0c8SAndre Fischer if (aNewPanels[nWriteIndex] != NULL) 460f120fe41SAndre Fischer { 461f120fe41SAndre Fischer // Depending on the context we have to collapse the panel. 462f120fe41SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible); 463f120fe41SAndre Fischer 4647a32b0c8SAndre Fischer ++nWriteIndex; 46522de8995SAndre Fischer } 466f120fe41SAndre Fischer 467f120fe41SAndre Fischer } 4687a32b0c8SAndre Fischer aNewPanels.resize(nWriteIndex); 46922de8995SAndre Fischer 47095a18594SAndre Fischer // Activate the deck and the new set of panels. 471f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel( 47295a18594SAndre Fischer 0, 47395a18594SAndre Fischer 0, 47495a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 47595a18594SAndre Fischer mpParentWindow->GetSizePixel().Height()); 476f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels); 477f120fe41SAndre Fischer mpCurrentDeck->Show(); 478ff12d537SAndre Fischer 479ff12d537SAndre Fischer // Tell the tab bar to highlight the button associated with the 480ff12d537SAndre Fischer // deck. 481ff12d537SAndre Fischer mpTabBar->HighlightDeck(rDeckDescriptor.msId); 4827a32b0c8SAndre Fischer 4837a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle); 4847a32b0c8SAndre Fischer 48502c50d82SAndre Fischer if (bHasPanelSetChanged) 4867a32b0c8SAndre Fischer NotifyResize(); 487*65908a7eSAndre Fischer 488*65908a7eSAndre Fischer // Tell the focus manager about the new panels and tab bar 489*65908a7eSAndre Fischer // buttons. 490*65908a7eSAndre Fischer maFocusManager.SetPanels(aNewPanels); 491*65908a7eSAndre Fischer mpTabBar->UpdateFocusManager(maFocusManager); 49222de8995SAndre Fischer } 49322de8995SAndre Fischer 49422de8995SAndre Fischer 49522de8995SAndre Fischer 49622de8995SAndre Fischer 49702c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual ( 498f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels, 499f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels) 50002c50d82SAndre Fischer { 50102c50d82SAndre Fischer OSL_TRACE("current panel list:"); 502f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 50302c50d82SAndre Fischer iPanel(rCurrentPanels.begin()), 50402c50d82SAndre Fischer iEnd(rCurrentPanels.end()); 50502c50d82SAndre Fischer iPanel!=iEnd; 50602c50d82SAndre Fischer ++iPanel) 50702c50d82SAndre Fischer { 50802c50d82SAndre Fischer OSL_TRACE(" panel %s", S2A((*iPanel)->GetId())); 50902c50d82SAndre Fischer } 51002c50d82SAndre Fischer 51102c50d82SAndre Fischer OSL_TRACE("requested panels: "); 512f120fe41SAndre Fischer for (ResourceManager::PanelContextDescriptorContainer::const_iterator 513f120fe41SAndre Fischer iId(rRequestedPanels.begin()), 514f120fe41SAndre Fischer iEnd(rRequestedPanels.end()); 51502c50d82SAndre Fischer iId!=iEnd; 51602c50d82SAndre Fischer ++iId) 51702c50d82SAndre Fischer { 518f120fe41SAndre Fischer OSL_TRACE(" panel %s", S2A(iId->msId)); 51902c50d82SAndre Fischer } 52002c50d82SAndre Fischer 521f120fe41SAndre Fischer if (rCurrentPanels.size() != rRequestedPanels.size()) 52202c50d82SAndre Fischer return false; 52302c50d82SAndre Fischer for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex) 52402c50d82SAndre Fischer { 52502c50d82SAndre Fischer if (rCurrentPanels[nIndex] == NULL) 52602c50d82SAndre Fischer return false; 527f120fe41SAndre Fischer if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId)) 52802c50d82SAndre Fischer return false; 52902c50d82SAndre Fischer } 53002c50d82SAndre Fischer return true; 53102c50d82SAndre Fischer } 53202c50d82SAndre Fischer 53302c50d82SAndre Fischer 53402c50d82SAndre Fischer 53502c50d82SAndre Fischer 536f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel ( 53795a18594SAndre Fischer const OUString& rsPanelId, 538f120fe41SAndre Fischer ::Window* pParentWindow, 539f120fe41SAndre Fischer const OUString& rsMenuCommand) 54095a18594SAndre Fischer { 54195a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId); 54295a18594SAndre Fischer if (pPanelDescriptor == NULL) 543f120fe41SAndre Fischer return SharedPanel(); 54495a18594SAndre Fischer 5457a32b0c8SAndre Fischer #ifdef DEBUG 5467a32b0c8SAndre Fischer // Prevent the panel not being created in the same memory of an old panel. 5477a32b0c8SAndre Fischer ::boost::scoped_array<char> pUnused (new char[sizeof(Panel)]); 5487a32b0c8SAndre Fischer OSL_TRACE("allocated memory at %x", pUnused.get()); 5497a32b0c8SAndre Fischer #endif 5507a32b0c8SAndre Fischer 55195a18594SAndre Fischer // Create the panel which is the parent window of the UIElement. 552f120fe41SAndre Fischer SharedPanel pPanel (new Panel( 55395a18594SAndre Fischer *pPanelDescriptor, 5547a32b0c8SAndre Fischer pParentWindow, 555f120fe41SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()), 556f120fe41SAndre Fischer rsMenuCommand.getLength()>0 557f120fe41SAndre Fischer ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rsMenuCommand) 558f120fe41SAndre Fischer : ::boost::function<void(void)>())); 55995a18594SAndre Fischer 56095a18594SAndre Fischer // Create the XUIElement. 56195a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 56295a18594SAndre Fischer pPanel->GetComponentInterface(), 563f120fe41SAndre Fischer pPanelDescriptor->msImplementationURL)); 56495a18594SAndre Fischer if (xUIElement.is()) 56595a18594SAndre Fischer { 56695a18594SAndre Fischer // Initialize the panel and add it to the active deck. 56795a18594SAndre Fischer pPanel->SetUIElement(xUIElement); 56895a18594SAndre Fischer } 56995a18594SAndre Fischer else 57095a18594SAndre Fischer { 571f120fe41SAndre Fischer pPanel.reset(); 57295a18594SAndre Fischer } 57395a18594SAndre Fischer 57495a18594SAndre Fischer return pPanel; 57595a18594SAndre Fischer } 57695a18594SAndre Fischer 57795a18594SAndre Fischer 57895a18594SAndre Fischer 57995a18594SAndre Fischer 580ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 581ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 582f120fe41SAndre Fischer const ::rtl::OUString& rsImplementationURL) 58322de8995SAndre Fischer { 58422de8995SAndre Fischer try 58522de8995SAndre Fischer { 58622de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 58722de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 58822de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 58922de8995SAndre Fischer UNO_QUERY_THROW); 59022de8995SAndre Fischer 591ff12d537SAndre Fischer // Create the XUIElement. 59222de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 59322de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 594ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 595b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow); 596b9e67834SAndre Fischer if (pSfxDockingWindow != NULL) 597b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings()))); 5987a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet()); 5997a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this)))); 6007a32b0c8SAndre Fischer 601b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement( 60222de8995SAndre Fischer xUIElementFactory->createUIElement( 603ff12d537SAndre Fischer rsImplementationURL, 6047a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())), 605ff12d537SAndre Fischer UNO_QUERY_THROW); 606b9e67834SAndre Fischer 607b9e67834SAndre Fischer return xUIElement; 60822de8995SAndre Fischer } 60922de8995SAndre Fischer catch(Exception& rException) 61022de8995SAndre Fischer { 61122de8995SAndre Fischer OSL_TRACE("caught exception: %s", 61222de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 61322de8995SAndre Fischer // For some reason we can not create the actual panel. 61422de8995SAndre Fischer // Probably because its factory was not properly registered. 61522de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 61622de8995SAndre Fischer // source of the error. 617ff12d537SAndre Fischer 618ff12d537SAndre Fischer return NULL; 61922de8995SAndre Fischer } 62022de8995SAndre Fischer } 62122de8995SAndre Fischer 62222de8995SAndre Fischer 62322de8995SAndre Fischer 62422de8995SAndre Fischer 62522de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 62622de8995SAndre Fischer { 62722de8995SAndre Fischer if (pEvent != NULL) 62822de8995SAndre Fischer { 62922de8995SAndre Fischer switch (pEvent->GetId()) 63022de8995SAndre Fischer { 63122de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 63222de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 63322de8995SAndre Fischer break; 63422de8995SAndre Fischer 63522de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 63622de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 63722de8995SAndre Fischer NotifyResize(); 63822de8995SAndre Fischer break; 63922de8995SAndre Fischer 640ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 641ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 642ff12d537SAndre Fischer // changes in theme (high contrast mode). 643ff12d537SAndre Fischer Theme::HandleDataChange(); 644ff12d537SAndre Fischer mpParentWindow->Invalidate(); 645ff12d537SAndre Fischer break; 646ff12d537SAndre Fischer 64722de8995SAndre Fischer case SFX_HINT_DYING: 64822de8995SAndre Fischer dispose(); 64922de8995SAndre Fischer break; 65022de8995SAndre Fischer 65122de8995SAndre Fischer default: 65222de8995SAndre Fischer break; 65322de8995SAndre Fischer } 65422de8995SAndre Fischer } 65522de8995SAndre Fischer 65622de8995SAndre Fischer return sal_True; 65722de8995SAndre Fischer } 65822de8995SAndre Fischer 65922de8995SAndre Fischer 66022de8995SAndre Fischer 66122de8995SAndre Fischer 66295a18594SAndre Fischer void SidebarController::ShowPopupMenu ( 66395a18594SAndre Fischer const Rectangle& rButtonBox, 66495a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 66595a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 66622de8995SAndre Fischer { 66795a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData); 668ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 669ff12d537SAndre Fischer 670ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 671ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 672ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 673ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 67422de8995SAndre Fischer } 67522de8995SAndre Fischer 67622de8995SAndre Fischer 67722de8995SAndre Fischer 67822de8995SAndre Fischer 679f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const 680f120fe41SAndre Fischer { 681f120fe41SAndre Fischer try 682f120fe41SAndre Fischer { 683f120fe41SAndre Fischer util::URL aURL; 684f120fe41SAndre Fischer aURL.Complete = rsMenuCommand; 685f120fe41SAndre Fischer 686f120fe41SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 687f120fe41SAndre Fischer const Reference<util::XURLTransformer> xParser ( 688f120fe41SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 689f120fe41SAndre Fischer UNO_QUERY_THROW); 690f120fe41SAndre Fischer xParser->parseStrict(aURL); 691f120fe41SAndre Fischer Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW); 692f120fe41SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(aURL, OUString(), 0)); 693f120fe41SAndre Fischer if (xDispatch.is()) 694f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 695f120fe41SAndre Fischer } 696f120fe41SAndre Fischer catch(Exception& rException) 697f120fe41SAndre Fischer { 698f120fe41SAndre Fischer OSL_TRACE("caught exception: %s", 699f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 700f120fe41SAndre Fischer } 701f120fe41SAndre Fischer } 702f120fe41SAndre Fischer 703f120fe41SAndre Fischer 704f120fe41SAndre Fischer 705f120fe41SAndre Fischer 70695a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu ( 70795a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 70895a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 70922de8995SAndre Fischer { 710ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 711ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 712ff12d537SAndre Fischer if (pMenuWindow != NULL) 71322de8995SAndre Fischer { 714ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 71522de8995SAndre Fischer } 71622de8995SAndre Fischer 717ff12d537SAndre Fischer SidebarResource aLocalResource; 718ff12d537SAndre Fischer 719ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 720ff12d537SAndre Fischer // them visible or hide them. 721ff12d537SAndre Fischer { 72295a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_PANEL); 72395a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 72495a18594SAndre Fischer iItem(rDeckSelectionData.begin()), 72595a18594SAndre Fischer iEnd(rDeckSelectionData.end()); 72695a18594SAndre Fischer iItem!=iEnd; 72795a18594SAndre Fischer ++iItem) 72895a18594SAndre Fischer { 72995a18594SAndre Fischer pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK); 73095a18594SAndre Fischer pMenu->CheckItem(nIndex, iItem->get<2>()); 73195a18594SAndre Fischer ++nIndex; 732ff12d537SAndre Fischer } 73395a18594SAndre Fischer } 73495a18594SAndre Fischer 73595a18594SAndre Fischer pMenu->InsertSeparator(); 736ff12d537SAndre Fischer 737ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 738ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 739ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 740ff12d537SAndre Fischer else 741ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 742ff12d537SAndre Fischer 743ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 744ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 74595a18594SAndre Fischer { 74695a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_HIDE); 74795a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 74895a18594SAndre Fischer iItem(rDeckShowData.begin()), 74995a18594SAndre Fischer iEnd(rDeckShowData.end()); 75095a18594SAndre Fischer iItem!=iEnd; 75195a18594SAndre Fischer ++iItem) 75295a18594SAndre Fischer { 75395a18594SAndre Fischer pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE); 75495a18594SAndre Fischer pCustomizationMenu->CheckItem(nIndex, iItem->get<2>()); 75595a18594SAndre Fischer ++nIndex; 75695a18594SAndre Fischer } 75795a18594SAndre Fischer } 75895a18594SAndre Fischer 759ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 760ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 761ff12d537SAndre Fischer 762ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 763ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 764ff12d537SAndre Fischer 765ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 766ff12d537SAndre Fischer 767ff12d537SAndre Fischer return pMenu; 76822de8995SAndre Fischer } 76922de8995SAndre Fischer 77022de8995SAndre Fischer 77122de8995SAndre Fischer 77222de8995SAndre Fischer 773ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 77422de8995SAndre Fischer { 775ff12d537SAndre Fischer if (pMenu == NULL) 77622de8995SAndre Fischer { 7777a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!"); 778ff12d537SAndre Fischer return 0; 77922de8995SAndre Fischer } 780ff12d537SAndre Fischer 781ff12d537SAndre Fischer pMenu->Deactivate(); 782ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 783ff12d537SAndre Fischer switch (nIndex) 784ff12d537SAndre Fischer { 785ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 786ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 787ff12d537SAndre Fischer break; 788ff12d537SAndre Fischer 789ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 790ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 791ff12d537SAndre Fischer break; 792ff12d537SAndre Fischer 793ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 794ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 795ff12d537SAndre Fischer break; 796ff12d537SAndre Fischer 797ff12d537SAndre Fischer default: 798ff12d537SAndre Fischer { 799ff12d537SAndre Fischer try 800ff12d537SAndre Fischer { 801ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 80295a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL)); 803ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 804ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 805ff12d537SAndre Fischer } 806ff12d537SAndre Fischer catch (RuntimeException&) 807ff12d537SAndre Fischer { 808ff12d537SAndre Fischer } 809ff12d537SAndre Fischer } 810ff12d537SAndre Fischer break; 811ff12d537SAndre Fischer } 812ff12d537SAndre Fischer 813ff12d537SAndre Fischer return 1; 81422de8995SAndre Fischer } 81522de8995SAndre Fischer 81622de8995SAndre Fischer 817ff12d537SAndre Fischer 818ff12d537SAndre Fischer 8197a32b0c8SAndre Fischer void SidebarController::CloseDeck (void) 8207a32b0c8SAndre Fischer { 8217a32b0c8SAndre Fischer if ( ! mbIsDeckClosed) 8227a32b0c8SAndre Fischer { 8237a32b0c8SAndre Fischer mbIsDeckClosed = true; 8247a32b0c8SAndre Fischer if ( ! mpParentWindow->IsFloatingMode()) 8257a32b0c8SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth()); 8267a32b0c8SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE); 8277a32b0c8SAndre Fischer 828f120fe41SAndre Fischer if (mpCurrentDeck) 829f120fe41SAndre Fischer mpCurrentDeck->Hide(); 8307a32b0c8SAndre Fischer 8317a32b0c8SAndre Fischer NotifyResize(); 8327a32b0c8SAndre Fischer } 8337a32b0c8SAndre Fischer } 8347a32b0c8SAndre Fischer 8357a32b0c8SAndre Fischer 8367a32b0c8SAndre Fischer 8377a32b0c8SAndre Fischer 8387a32b0c8SAndre Fischer void SidebarController::OpenDeck (void) 8397a32b0c8SAndre Fischer { 8407a32b0c8SAndre Fischer if (mbIsDeckClosed) 8417a32b0c8SAndre Fischer { 8427a32b0c8SAndre Fischer mbIsDeckClosed = false; 8437a32b0c8SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth); 8447a32b0c8SAndre Fischer 845f120fe41SAndre Fischer if (mpCurrentDeck) 846f120fe41SAndre Fischer mpCurrentDeck->Show(); 8477a32b0c8SAndre Fischer 8487a32b0c8SAndre Fischer NotifyResize(); 8497a32b0c8SAndre Fischer } 8507a32b0c8SAndre Fischer } 8517a32b0c8SAndre Fischer 8527a32b0c8SAndre Fischer 8537a32b0c8SAndre Fischer 8547a32b0c8SAndre Fischer 855*65908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void) 856*65908a7eSAndre Fischer { 857*65908a7eSAndre Fischer return maFocusManager; 858*65908a7eSAndre Fischer } 859*65908a7eSAndre Fischer 860*65908a7eSAndre Fischer 861*65908a7eSAndre Fischer 862*65908a7eSAndre Fischer 8637a32b0c8SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void) const 8647a32b0c8SAndre Fischer { 8657a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8667a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8677a32b0c8SAndre Fischer { 8687a32b0c8SAndre Fischer OSL_ASSERT(pSplitWindow!=NULL); 8697a32b0c8SAndre Fischer return 0; 8707a32b0c8SAndre Fischer } 8717a32b0c8SAndre Fischer 8727a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8737a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8747a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8757a32b0c8SAndre Fischer 8767a32b0c8SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn)); 8777a32b0c8SAndre Fischer 8787a32b0c8SAndre Fischer return nRowCount == 1; 8797a32b0c8SAndre Fischer } 8807a32b0c8SAndre Fischer 8817a32b0c8SAndre Fischer 8827a32b0c8SAndre Fischer 8837a32b0c8SAndre Fischer 8847a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth) 8857a32b0c8SAndre Fischer { 8867a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8877a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8887a32b0c8SAndre Fischer return 0; 8897a32b0c8SAndre Fischer 8907a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8917a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8927a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8937a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn)); 8947a32b0c8SAndre Fischer 8957a32b0c8SAndre Fischer Window* pWindow = mpParentWindow; 8967a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel()); 8977a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel()); 8987a32b0c8SAndre Fischer 8997a32b0c8SAndre Fischer pSplitWindow->MoveWindow( 9007a32b0c8SAndre Fischer mpParentWindow, 9017a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()), 9027a32b0c8SAndre Fischer nColumn, 9037a32b0c8SAndre Fischer nRow); 9047a32b0c8SAndre Fischer 9057a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth); 9067a32b0c8SAndre Fischer } 9077a32b0c8SAndre Fischer 9087a32b0c8SAndre Fischer 9097a32b0c8SAndre Fischer 9107a32b0c8SAndre Fischer 9117a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void) 9127a32b0c8SAndre Fischer { 9137a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 9147a32b0c8SAndre Fischer if (pSplitWindow != NULL) 9157a32b0c8SAndre Fischer { 9167a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow)); 9177a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId)); 9187a32b0c8SAndre Fischer // Minimum width is always that of the tabbar. 9197a32b0c8SAndre Fischer const sal_Int32 nMinimumWidth (TabBar::GetDefaultWidth()); 9207a32b0c8SAndre Fischer // Maximum width depends on whether the deck is open or closed. 9217a32b0c8SAndre Fischer const sal_Int32 nMaximumWidth ( 9227a32b0c8SAndre Fischer mbIsDeckClosed 9237a32b0c8SAndre Fischer ? TabBar::GetDefaultWidth() 9247a32b0c8SAndre Fischer : 400); 9257a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange( 9267a32b0c8SAndre Fischer nSetId, 9277a32b0c8SAndre Fischer Range(nMinimumWidth, nMaximumWidth)); 9287a32b0c8SAndre Fischer if (nMinimumWidth == nMaximumWidth) 9297a32b0c8SAndre Fischer pSplitWindow->SetItemSize(nSetId, nMinimumWidth); 9307a32b0c8SAndre Fischer } 9317a32b0c8SAndre Fischer } 9327a32b0c8SAndre Fischer 933ff12d537SAndre Fischer 934ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 935