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> 4422f77e9eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 4522f77e9eSAndre Fischer 46ff12d537SAndre Fischer #include <comphelper/componentfactory.hxx> 4795a18594SAndre Fischer #include <comphelper/processfactory.hxx> 48ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 49ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 5022de8995SAndre Fischer 51f120fe41SAndre Fischer #include <com/sun/star/frame/XDispatchProvider.hpp> 52f120fe41SAndre Fischer #include <com/sun/star/lang/XInitialization.hpp> 5322de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> 5422de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp> 5595a18594SAndre Fischer #include <com/sun/star/ui/XUIElementFactory.hpp> 56f120fe41SAndre Fischer #include <com/sun/star/util/XURLTransformer.hpp> 57f120fe41SAndre Fischer #include <com/sun/star/util/URL.hpp> 5822f77e9eSAndre Fischer #include <com/sun/star/rendering/XSpriteCanvas.hpp> 5922de8995SAndre Fischer 6022de8995SAndre Fischer #include <boost/bind.hpp> 61f120fe41SAndre Fischer #include <boost/function.hpp> 627a32b0c8SAndre Fischer #include <boost/scoped_array.hpp> 6322de8995SAndre Fischer 6422de8995SAndre Fischer 6522de8995SAndre Fischer using namespace css; 6622de8995SAndre Fischer using namespace cssu; 6795a18594SAndre Fischer using ::rtl::OUString; 6822de8995SAndre Fischer 6902c50d82SAndre Fischer 70*56798e4bSAndre Fischer #undef VERBOSE 7122de8995SAndre Fischer 72ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 7322de8995SAndre Fischer 74ff12d537SAndre Fischer namespace { 75ff12d537SAndre Fischer enum MenuId 76ff12d537SAndre Fischer { 77ff12d537SAndre Fischer MID_UNLOCK_TASK_PANEL = 1, 78ff12d537SAndre Fischer MID_LOCK_TASK_PANEL, 79ff12d537SAndre Fischer MID_CUSTOMIZATION, 80ff12d537SAndre Fischer MID_RESTORE_DEFAULT, 81ff12d537SAndre Fischer MID_FIRST_PANEL, 82ff12d537SAndre Fischer MID_FIRST_HIDE = 1000 83ff12d537SAndre Fischer }; 84ff12d537SAndre Fischer } 8522de8995SAndre Fischer 8622de8995SAndre Fischer 8722de8995SAndre Fischer SidebarController::SidebarController ( 887a32b0c8SAndre Fischer SidebarDockingWindow* pParentWindow, 8922de8995SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 9022de8995SAndre Fischer : SidebarControllerInterfaceBase(m_aMutex), 91f120fe41SAndre Fischer mpCurrentDeck(), 9222de8995SAndre Fischer mpParentWindow(pParentWindow), 93ff12d537SAndre Fischer mpTabBar(new TabBar( 94ff12d537SAndre Fischer mpParentWindow, 95ff12d537SAndre Fischer rxFrame, 96ff12d537SAndre Fischer ::boost::bind(&SidebarController::SwitchToDeck, this, _1), 9795a18594SAndre Fischer ::boost::bind(&SidebarController::ShowPopupMenu, this, _1,_2,_3))), 9895a18594SAndre Fischer mxFrame(rxFrame), 997a32b0c8SAndre Fischer maCurrentContext(OUString(), OUString()), 10095a18594SAndre Fischer msCurrentDeckId(A2S("PropertyDeck")), 1017a32b0c8SAndre Fischer maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)), 1027a32b0c8SAndre Fischer mbIsDeckClosed(false), 1037a32b0c8SAndre Fischer mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()) 10422de8995SAndre Fischer { 10522de8995SAndre Fischer if (pParentWindow == NULL) 10622de8995SAndre Fischer { 10722de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL); 10822de8995SAndre Fischer return; 10922de8995SAndre Fischer } 11022de8995SAndre Fischer 11122de8995SAndre Fischer // Listen for context change events. 11222de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 11322de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 11422de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 11522de8995SAndre Fischer if (xMultiplexer.is()) 11622de8995SAndre Fischer xMultiplexer->addContextChangeEventListener( 11722de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this), 11895a18594SAndre Fischer mxFrame->getController()); 11922de8995SAndre Fischer 12022de8995SAndre Fischer // Listen for window events. 12122de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler)); 122b9e67834SAndre Fischer 123b9e67834SAndre Fischer // Listen for theme property changes. 124b9e67834SAndre Fischer Theme::GetPropertySet()->addPropertyChangeListener( 125b9e67834SAndre Fischer A2S(""), 126b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 127f120fe41SAndre Fischer 128f120fe41SAndre Fischer SwitchToDeck(A2S("default")); 12922de8995SAndre Fischer } 13022de8995SAndre Fischer 13122de8995SAndre Fischer 13222de8995SAndre Fischer 13322de8995SAndre Fischer 13422de8995SAndre Fischer SidebarController::~SidebarController (void) 13522de8995SAndre Fischer { 13622de8995SAndre Fischer } 13722de8995SAndre Fischer 13822de8995SAndre Fischer 13922de8995SAndre Fischer 14022de8995SAndre Fischer 14122de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void) 14222de8995SAndre Fischer { 14365908a7eSAndre Fischer maFocusManager.Clear(); 14465908a7eSAndre Fischer 14522de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 14622de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 14722de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 14822de8995SAndre Fischer if (xMultiplexer.is()) 14922de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 15022de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 15122de8995SAndre Fischer 15222de8995SAndre Fischer if (mpParentWindow != NULL) 15322de8995SAndre Fischer { 15422de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 15522de8995SAndre Fischer mpParentWindow = NULL; 15622de8995SAndre Fischer } 157b9e67834SAndre Fischer 158f120fe41SAndre Fischer if (mpCurrentDeck) 159b9e67834SAndre Fischer { 160f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 161f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 162f120fe41SAndre Fischer mpCurrentDeck.reset(); 163b9e67834SAndre Fischer } 164b9e67834SAndre Fischer 165580828edSAndre Fischer mpTabBar.reset(); 166580828edSAndre Fischer 167b9e67834SAndre Fischer Theme::GetPropertySet()->removePropertyChangeListener( 168b9e67834SAndre Fischer A2S(""), 169b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 17022de8995SAndre Fischer } 17122de8995SAndre Fischer 17222de8995SAndre Fischer 17322de8995SAndre Fischer 17422de8995SAndre Fischer 17522de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) 17622de8995SAndre Fischer throw(cssu::RuntimeException) 17722de8995SAndre Fischer { 17895a18594SAndre Fischer UpdateConfigurations( 1797a32b0c8SAndre Fischer Context( 18095a18594SAndre Fischer rEvent.ApplicationName, 18195a18594SAndre Fischer rEvent.ContextName)); 18222de8995SAndre Fischer } 18322de8995SAndre Fischer 18422de8995SAndre Fischer 18522de8995SAndre Fischer 18622de8995SAndre Fischer 18722de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject) 18822de8995SAndre Fischer throw(cssu::RuntimeException) 18922de8995SAndre Fischer { 19095a18594SAndre Fischer (void)rEventObject; 191f120fe41SAndre Fischer 192f120fe41SAndre Fischer dispose(); 19322de8995SAndre Fischer } 19422de8995SAndre Fischer 19522de8995SAndre Fischer 19622de8995SAndre Fischer 19722de8995SAndre Fischer 198b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent) 199b9e67834SAndre Fischer throw(cssu::RuntimeException) 20095a18594SAndre Fischer { 20195a18594SAndre Fischer (void)rEvent; 20295a18594SAndre Fischer 20395a18594SAndre Fischer maPropertyChangeForwarder.RequestCall(); 20495a18594SAndre Fischer } 20595a18594SAndre Fischer 20695a18594SAndre Fischer 20795a18594SAndre Fischer 20895a18594SAndre Fischer 2097a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void) 2107a32b0c8SAndre Fischer throw(cssu::RuntimeException) 2117a32b0c8SAndre Fischer { 212f120fe41SAndre Fischer if (mpCurrentDeck) 213f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 2147a32b0c8SAndre Fischer RestrictWidth(); 2157a32b0c8SAndre Fischer } 2167a32b0c8SAndre Fischer 2177a32b0c8SAndre Fischer 2187a32b0c8SAndre Fischer 2197a32b0c8SAndre Fischer 22095a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void) 221b9e67834SAndre Fischer { 222b9e67834SAndre Fischer DataChangedEvent aEvent (DATACHANGED_USER); 223b9e67834SAndre Fischer mpParentWindow->NotifyAllChilds(aEvent); 224b9e67834SAndre Fischer mpParentWindow->Invalidate(INVALIDATE_CHILDREN); 225b9e67834SAndre Fischer } 226b9e67834SAndre Fischer 227b9e67834SAndre Fischer 228b9e67834SAndre Fischer 229b9e67834SAndre Fischer 23022de8995SAndre Fischer void SidebarController::NotifyResize (void) 23122de8995SAndre Fischer { 23295a18594SAndre Fischer if (mpTabBar == NULL) 23395a18594SAndre Fischer { 23495a18594SAndre Fischer OSL_ASSERT(mpTabBar!=NULL); 23595a18594SAndre Fischer return; 23695a18594SAndre Fischer } 23795a18594SAndre Fischer 23895a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent(); 23995a18594SAndre Fischer 24095a18594SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 24195a18594SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height()); 24295a18594SAndre Fischer 2437a32b0c8SAndre Fischer // Place the deck. 244f120fe41SAndre Fischer if (mpCurrentDeck) 2457a32b0c8SAndre Fischer { 246f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight); 247f120fe41SAndre Fischer mpCurrentDeck->Show(); 248f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 24922de8995SAndre Fischer } 25095a18594SAndre Fischer 2517a32b0c8SAndre Fischer // Place the tab bar. 25295a18594SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight); 25395a18594SAndre Fischer mpTabBar->Show(); 2547a32b0c8SAndre Fischer 2557a32b0c8SAndre Fischer // Determine if the closer of the deck can be shown. 256f120fe41SAndre Fischer if (mpCurrentDeck) 2577a32b0c8SAndre Fischer { 258f120fe41SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 2597a32b0c8SAndre Fischer if (pTitleBar != NULL && pTitleBar->IsVisible()) 2607a32b0c8SAndre Fischer pTitleBar->SetCloserVisible(CanModifyChildWindowWidth()); 2617a32b0c8SAndre Fischer } 2627a32b0c8SAndre Fischer 2637a32b0c8SAndre Fischer if (nWidth > TabBar::GetDefaultWidth()) 2647a32b0c8SAndre Fischer mnSavedSidebarWidth = nWidth; 2657a32b0c8SAndre Fischer 2667a32b0c8SAndre Fischer RestrictWidth(); 267*56798e4bSAndre Fischer #ifdef VERBOSE 268f120fe41SAndre Fischer if (mpCurrentDeck) 2697a32b0c8SAndre Fischer { 270f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 2717a32b0c8SAndre Fischer sal_Int32 nPanelIndex (0); 272f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 273f120fe41SAndre Fischer iPanel(mpCurrentDeck->GetPanels().begin()), 274f120fe41SAndre Fischer iEnd(mpCurrentDeck->GetPanels().end()); 2757a32b0c8SAndre Fischer iPanel!=iEnd; 2767a32b0c8SAndre Fischer ++iPanel,++nPanelIndex) 2777a32b0c8SAndre Fischer { 2787a32b0c8SAndre Fischer OSL_TRACE("panel %d:", nPanelIndex); 2797a32b0c8SAndre Fischer (*iPanel)->PrintWindowTree(); 2807a32b0c8SAndre Fischer } 2817a32b0c8SAndre Fischer } 2827a32b0c8SAndre Fischer #endif 28322de8995SAndre Fischer } 28422de8995SAndre Fischer 28522de8995SAndre Fischer 28622de8995SAndre Fischer 28722de8995SAndre Fischer 2887a32b0c8SAndre Fischer void SidebarController::UpdateConfigurations (const Context& rContext) 28922de8995SAndre Fischer { 29095a18594SAndre Fischer if (maCurrentContext != rContext) 29195a18594SAndre Fischer { 29295a18594SAndre Fischer maCurrentContext = rContext; 29395a18594SAndre Fischer 29495a18594SAndre Fischer // Notify the tab bar about the updated set of decks. 29595a18594SAndre Fischer ResourceManager::IdContainer aDeckIds; 29695a18594SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 29795a18594SAndre Fischer aDeckIds, 29895a18594SAndre Fischer rContext, 29995a18594SAndre Fischer mxFrame); 30095a18594SAndre Fischer mpTabBar->SetDecks(aDeckIds); 30195a18594SAndre Fischer 30295a18594SAndre Fischer // Check if the current deck is among the matching decks. 30395a18594SAndre Fischer bool bCurrentDeckMatches (false); 30495a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 30595a18594SAndre Fischer iDeck(aDeckIds.begin()), 30695a18594SAndre Fischer iEnd(aDeckIds.end()); 30795a18594SAndre Fischer iDeck!=iEnd; 30895a18594SAndre Fischer ++iDeck) 30995a18594SAndre Fischer { 31095a18594SAndre Fischer if (iDeck->equals(msCurrentDeckId)) 31195a18594SAndre Fischer { 31295a18594SAndre Fischer bCurrentDeckMatches = true; 31395a18594SAndre Fischer break; 31495a18594SAndre Fischer } 31595a18594SAndre Fischer } 316ff12d537SAndre Fischer 31795a18594SAndre Fischer DeckDescriptor const* pDeckDescriptor = NULL; 31895a18594SAndre Fischer if ( ! bCurrentDeckMatches) 31995a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetBestMatchingDeck(rContext, mxFrame); 32095a18594SAndre Fischer else 32195a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(msCurrentDeckId); 32295a18594SAndre Fischer if (pDeckDescriptor != NULL) 32395a18594SAndre Fischer { 32495a18594SAndre Fischer msCurrentDeckId = pDeckDescriptor->msId; 32595a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, rContext); 326*56798e4bSAndre Fischer 327*56798e4bSAndre Fischer // Tell the tab bar to highlight the button associated 328*56798e4bSAndre Fischer // with the deck. 329*56798e4bSAndre Fischer mpTabBar->HighlightDeck(msCurrentDeckId); 33095a18594SAndre Fischer } 33154eaaa32SAndre Fischer 33254eaaa32SAndre Fischer #ifdef DEBUG 33354eaaa32SAndre Fischer // Show the context name in the deck title bar. 33454eaaa32SAndre Fischer if (mpCurrentDeck) 33554eaaa32SAndre Fischer { 33654eaaa32SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 33754eaaa32SAndre Fischer if (pTitleBar != NULL) 33854eaaa32SAndre Fischer pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+rContext.msContext+A2S(")")); 33954eaaa32SAndre Fischer } 34054eaaa32SAndre Fischer #endif 34195a18594SAndre Fischer } 342ff12d537SAndre Fischer } 343ff12d537SAndre Fischer 344ff12d537SAndre Fischer 34522de8995SAndre Fischer 346ff12d537SAndre Fischer 347ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 34895a18594SAndre Fischer const ::rtl::OUString& rsDeckId) 349ff12d537SAndre Fischer { 3507a32b0c8SAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId) || mbIsDeckClosed) 35195a18594SAndre Fischer { 35295a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId); 35395a18594SAndre Fischer if (pDeckDescriptor != NULL) 35495a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 35595a18594SAndre Fischer } 35622de8995SAndre Fischer } 35722de8995SAndre Fischer 35822de8995SAndre Fischer 35922de8995SAndre Fischer 36022de8995SAndre Fischer 361ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 36222de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 3637a32b0c8SAndre Fischer const Context& rContext) 36422de8995SAndre Fischer { 36565908a7eSAndre Fischer maFocusManager.Clear(); 36665908a7eSAndre Fischer 36795a18594SAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)) 36895a18594SAndre Fischer { 36995a18594SAndre Fischer // When the deck changes then destroy the deck and all panels 37095a18594SAndre Fischer // and create everything new. 371f120fe41SAndre Fischer if (mpCurrentDeck) 37295a18594SAndre Fischer { 373f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 374f120fe41SAndre Fischer mpCurrentDeck.reset(); 37595a18594SAndre Fischer } 37695a18594SAndre Fischer 37795a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId; 37895a18594SAndre Fischer } 3797a32b0c8SAndre Fischer 3807a32b0c8SAndre Fischer // Reopen the deck when necessary. 3817a32b0c8SAndre Fischer OpenDeck(); 3827a32b0c8SAndre Fischer 383ff12d537SAndre Fischer // Determine the panels to display in the deck. 384f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors; 385ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 386f120fe41SAndre Fischer aPanelContextDescriptors, 387ff12d537SAndre Fischer rContext, 388ff12d537SAndre Fischer rDeckDescriptor.msId, 389ff12d537SAndre Fischer mxFrame); 390ff12d537SAndre Fischer 39154eaaa32SAndre Fischer if (aPanelContextDescriptors.empty()) 39254eaaa32SAndre Fischer { 39354eaaa32SAndre Fischer // There are no panels to be displayed in the current context. 39454eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty) 39554eaaa32SAndre Fischer { 39654eaaa32SAndre Fischer // Switch to the "empty" context and try again. 39754eaaa32SAndre Fischer SwitchToDeck( 39854eaaa32SAndre Fischer rDeckDescriptor, 39954eaaa32SAndre Fischer Context( 40054eaaa32SAndre Fischer rContext.msApplication, 40154eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty))); 40254eaaa32SAndre Fischer return; 40354eaaa32SAndre Fischer } 40454eaaa32SAndre Fischer else 40554eaaa32SAndre Fischer { 40654eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have 40754eaaa32SAndre Fischer // to live with an empty deck. 40854eaaa32SAndre Fischer } 40954eaaa32SAndre Fischer } 41054eaaa32SAndre Fischer 411f120fe41SAndre Fischer if (mpCurrentDeck 412f120fe41SAndre Fischer && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors)) 41302c50d82SAndre Fischer { 41402c50d82SAndre Fischer // Requested set of panels is identical to the current set of 41502c50d82SAndre Fischer // panels => Nothing to do. 41602c50d82SAndre Fischer return; 41702c50d82SAndre Fischer } 41802c50d82SAndre Fischer 41995a18594SAndre Fischer // Provide a configuration and Deck object. 420f120fe41SAndre Fischer if ( ! mpCurrentDeck) 42122de8995SAndre Fischer { 422f120fe41SAndre Fischer mpCurrentDeck.reset( 423f120fe41SAndre Fischer new Deck( 424f120fe41SAndre Fischer rDeckDescriptor, 425f120fe41SAndre Fischer mpParentWindow, 426f120fe41SAndre Fischer ::boost::bind(&SidebarController::CloseDeck, this))); 42754eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle; 42895a18594SAndre Fischer } 429f120fe41SAndre Fischer if ( ! mpCurrentDeck) 430f120fe41SAndre Fischer return; 431f120fe41SAndre Fischer 43295a18594SAndre Fischer // Update the panel list. 433f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size()); 434f120fe41SAndre Fischer SharedPanelContainer aNewPanels; 435f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels()); 43695a18594SAndre Fischer aNewPanels.resize(nNewPanelCount); 4377a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0); 43802c50d82SAndre Fischer bool bHasPanelSetChanged (false); 4397a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex) 44095a18594SAndre Fischer { 441f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor ( 442f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]); 44395a18594SAndre Fischer 44495a18594SAndre Fischer // Find the corresponding panel among the currently active 44595a18594SAndre Fischer // panels. 446f120fe41SAndre Fischer SharedPanelContainer::const_iterator iPanel (::std::find_if( 447f120fe41SAndre Fischer rCurrentPanels.begin(), 448f120fe41SAndre Fischer rCurrentPanels.end(), 449f120fe41SAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)))); 450f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end()) 451ff12d537SAndre Fischer { 452f120fe41SAndre Fischer // Panel already exists in current deck. Reuse it. 4537a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel; 454ff12d537SAndre Fischer } 455ff12d537SAndre Fischer else 456ff12d537SAndre Fischer { 45795a18594SAndre Fischer // Panel does not yet exist. Create it. 4587a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel( 459f120fe41SAndre Fischer rPanelContexDescriptor.msId, 460f120fe41SAndre Fischer mpCurrentDeck->GetPanelParentWindow(), 461f120fe41SAndre Fischer rPanelContexDescriptor.msMenuCommand); 46202c50d82SAndre Fischer bHasPanelSetChanged = true; 463ff12d537SAndre Fischer } 4647a32b0c8SAndre Fischer if (aNewPanels[nWriteIndex] != NULL) 46502c50d82SAndre Fischer { 466f120fe41SAndre Fischer // Depending on the context we have to collapse the panel. 467f120fe41SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible); 468f120fe41SAndre Fischer 469f120fe41SAndre Fischer ++nWriteIndex; 47002c50d82SAndre Fischer } 471f120fe41SAndre Fischer 47295a18594SAndre Fischer } 473f120fe41SAndre Fischer aNewPanels.resize(nWriteIndex); 47495a18594SAndre Fischer 47595a18594SAndre Fischer // Activate the deck and the new set of panels. 476f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel( 47795a18594SAndre Fischer 0, 47895a18594SAndre Fischer 0, 47995a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 48095a18594SAndre Fischer mpParentWindow->GetSizePixel().Height()); 481f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels); 482f120fe41SAndre Fischer mpCurrentDeck->Show(); 483ff12d537SAndre Fischer 4847a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle); 4857a32b0c8SAndre Fischer 48602c50d82SAndre Fischer if (bHasPanelSetChanged) 48702c50d82SAndre Fischer NotifyResize(); 48865908a7eSAndre Fischer 48965908a7eSAndre Fischer // Tell the focus manager about the new panels and tab bar 49065908a7eSAndre Fischer // buttons. 49165908a7eSAndre Fischer maFocusManager.SetPanels(aNewPanels); 49265908a7eSAndre Fischer mpTabBar->UpdateFocusManager(maFocusManager); 49302c50d82SAndre Fischer } 49402c50d82SAndre Fischer 49502c50d82SAndre Fischer 49602c50d82SAndre Fischer 49702c50d82SAndre Fischer 49802c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual ( 499f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels, 500f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels) 50102c50d82SAndre Fischer { 502*56798e4bSAndre Fischer #ifdef VERBOSE 50302c50d82SAndre Fischer OSL_TRACE("current panel list:"); 504f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 50502c50d82SAndre Fischer iPanel(rCurrentPanels.begin()), 50602c50d82SAndre Fischer iEnd(rCurrentPanels.end()); 50702c50d82SAndre Fischer iPanel!=iEnd; 50802c50d82SAndre Fischer ++iPanel) 50902c50d82SAndre Fischer { 51002c50d82SAndre Fischer OSL_TRACE(" panel %s", S2A((*iPanel)->GetId())); 51102c50d82SAndre Fischer } 51202c50d82SAndre Fischer 51302c50d82SAndre Fischer OSL_TRACE("requested panels: "); 514f120fe41SAndre Fischer for (ResourceManager::PanelContextDescriptorContainer::const_iterator 515f120fe41SAndre Fischer iId(rRequestedPanels.begin()), 516f120fe41SAndre Fischer iEnd(rRequestedPanels.end()); 51702c50d82SAndre Fischer iId!=iEnd; 51802c50d82SAndre Fischer ++iId) 51902c50d82SAndre Fischer { 520f120fe41SAndre Fischer OSL_TRACE(" panel %s", S2A(iId->msId)); 52102c50d82SAndre Fischer } 52222f77e9eSAndre Fischer #endif 52302c50d82SAndre Fischer 524f120fe41SAndre Fischer if (rCurrentPanels.size() != rRequestedPanels.size()) 52502c50d82SAndre Fischer return false; 52602c50d82SAndre Fischer for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex) 52702c50d82SAndre Fischer { 52802c50d82SAndre Fischer if (rCurrentPanels[nIndex] == NULL) 52902c50d82SAndre Fischer return false; 530f120fe41SAndre Fischer if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId)) 53102c50d82SAndre Fischer return false; 53202c50d82SAndre Fischer } 53302c50d82SAndre Fischer return true; 53422de8995SAndre Fischer } 53522de8995SAndre Fischer 53622de8995SAndre Fischer 53722de8995SAndre Fischer 53822de8995SAndre Fischer 539f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel ( 54095a18594SAndre Fischer const OUString& rsPanelId, 541f120fe41SAndre Fischer ::Window* pParentWindow, 542f120fe41SAndre Fischer const OUString& rsMenuCommand) 54395a18594SAndre Fischer { 54495a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId); 54595a18594SAndre Fischer if (pPanelDescriptor == NULL) 546f120fe41SAndre Fischer return SharedPanel(); 5477a32b0c8SAndre Fischer 54895a18594SAndre Fischer // Create the panel which is the parent window of the UIElement. 549f120fe41SAndre Fischer SharedPanel pPanel (new Panel( 55095a18594SAndre Fischer *pPanelDescriptor, 5517a32b0c8SAndre Fischer pParentWindow, 552f120fe41SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()), 553f120fe41SAndre Fischer rsMenuCommand.getLength()>0 554f120fe41SAndre Fischer ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rsMenuCommand) 555f120fe41SAndre Fischer : ::boost::function<void(void)>())); 55695a18594SAndre Fischer 55795a18594SAndre Fischer // Create the XUIElement. 55895a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 55995a18594SAndre Fischer pPanel->GetComponentInterface(), 56022f77e9eSAndre Fischer pPanelDescriptor->msImplementationURL, 56122f77e9eSAndre Fischer pPanelDescriptor->mbWantsCanvas)); 56295a18594SAndre Fischer if (xUIElement.is()) 56395a18594SAndre Fischer { 56495a18594SAndre Fischer // Initialize the panel and add it to the active deck. 56595a18594SAndre Fischer pPanel->SetUIElement(xUIElement); 56695a18594SAndre Fischer } 56795a18594SAndre Fischer else 56895a18594SAndre Fischer { 569f120fe41SAndre Fischer pPanel.reset(); 57095a18594SAndre Fischer } 57195a18594SAndre Fischer 57295a18594SAndre Fischer return pPanel; 57395a18594SAndre Fischer } 57495a18594SAndre Fischer 57595a18594SAndre Fischer 57695a18594SAndre Fischer 57795a18594SAndre Fischer 578ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 579ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 58022f77e9eSAndre Fischer const ::rtl::OUString& rsImplementationURL, 58122f77e9eSAndre Fischer const bool bWantsCanvas) 58222de8995SAndre Fischer { 58322de8995SAndre Fischer try 58422de8995SAndre Fischer { 58522de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 58622de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 58722de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 58822de8995SAndre Fischer UNO_QUERY_THROW); 589ff12d537SAndre Fischer 5907a32b0c8SAndre Fischer // Create the XUIElement. 59122de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 59222de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 593ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 594b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow); 595b9e67834SAndre Fischer if (pSfxDockingWindow != NULL) 596b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings()))); 5977a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet()); 5987a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this)))); 59922f77e9eSAndre Fischer if (bWantsCanvas) 60022f77e9eSAndre Fischer { 60122f77e9eSAndre Fischer Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas()); 60222f77e9eSAndre Fischer aCreationArguments.put("Canvas", makeAny(xCanvas)); 60322f77e9eSAndre Fischer } 6047a32b0c8SAndre Fischer 605b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement( 606ff12d537SAndre Fischer xUIElementFactory->createUIElement( 607ff12d537SAndre Fischer rsImplementationURL, 6087a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())), 609ff12d537SAndre Fischer UNO_QUERY_THROW); 610b9e67834SAndre Fischer 611b9e67834SAndre Fischer return xUIElement; 61222de8995SAndre Fischer } 61322de8995SAndre Fischer catch(Exception& rException) 61422de8995SAndre Fischer { 61522de8995SAndre Fischer OSL_TRACE("caught exception: %s", 61622de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 61722de8995SAndre Fischer // For some reason we can not create the actual panel. 61822de8995SAndre Fischer // Probably because its factory was not properly registered. 61922de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 62022de8995SAndre Fischer // source of the error. 621ff12d537SAndre Fischer 622ff12d537SAndre Fischer return NULL; 62322de8995SAndre Fischer } 62422de8995SAndre Fischer } 62522de8995SAndre Fischer 62622de8995SAndre Fischer 62722de8995SAndre Fischer 62822de8995SAndre Fischer 62922de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 63022de8995SAndre Fischer { 63122de8995SAndre Fischer if (pEvent != NULL) 63222de8995SAndre Fischer { 63322de8995SAndre Fischer switch (pEvent->GetId()) 63422de8995SAndre Fischer { 63522de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 63622de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 63722de8995SAndre Fischer break; 63822de8995SAndre Fischer 63922de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 64022de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 64122de8995SAndre Fischer NotifyResize(); 64222de8995SAndre Fischer break; 64322de8995SAndre Fischer 644ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 645ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 646ff12d537SAndre Fischer // changes in theme (high contrast mode). 647ff12d537SAndre Fischer Theme::HandleDataChange(); 648ff12d537SAndre Fischer mpParentWindow->Invalidate(); 649ff12d537SAndre Fischer break; 650ff12d537SAndre Fischer 65122de8995SAndre Fischer case SFX_HINT_DYING: 65222de8995SAndre Fischer dispose(); 65322de8995SAndre Fischer break; 65422de8995SAndre Fischer 65522de8995SAndre Fischer default: 65622de8995SAndre Fischer break; 65722de8995SAndre Fischer } 65822de8995SAndre Fischer } 65922de8995SAndre Fischer 66022de8995SAndre Fischer return sal_True; 66122de8995SAndre Fischer } 66222de8995SAndre Fischer 66322de8995SAndre Fischer 66422de8995SAndre Fischer 66522de8995SAndre Fischer 66695a18594SAndre Fischer void SidebarController::ShowPopupMenu ( 66795a18594SAndre Fischer const Rectangle& rButtonBox, 66895a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 66995a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 67022de8995SAndre Fischer { 67195a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData); 672ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 673ff12d537SAndre Fischer 674ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 675ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 676ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 677ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 67822de8995SAndre Fischer } 67922de8995SAndre Fischer 68022de8995SAndre Fischer 68122de8995SAndre Fischer 68222de8995SAndre Fischer 683f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const 684f120fe41SAndre Fischer { 685f120fe41SAndre Fischer try 686f120fe41SAndre Fischer { 687f120fe41SAndre Fischer util::URL aURL; 688f120fe41SAndre Fischer aURL.Complete = rsMenuCommand; 689f120fe41SAndre Fischer 690f120fe41SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 691f120fe41SAndre Fischer const Reference<util::XURLTransformer> xParser ( 692f120fe41SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 693f120fe41SAndre Fischer UNO_QUERY_THROW); 694f120fe41SAndre Fischer xParser->parseStrict(aURL); 695f120fe41SAndre Fischer Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW); 696f120fe41SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(aURL, OUString(), 0)); 697f120fe41SAndre Fischer if (xDispatch.is()) 698f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 699f120fe41SAndre Fischer } 700f120fe41SAndre Fischer catch(Exception& rException) 701f120fe41SAndre Fischer { 702f120fe41SAndre Fischer OSL_TRACE("caught exception: %s", 703f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 704f120fe41SAndre Fischer } 705f120fe41SAndre Fischer } 706f120fe41SAndre Fischer 707f120fe41SAndre Fischer 708f120fe41SAndre Fischer 709f120fe41SAndre Fischer 71095a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu ( 71195a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 71295a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 71322de8995SAndre Fischer { 714ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 715ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 716ff12d537SAndre Fischer if (pMenuWindow != NULL) 717ff12d537SAndre Fischer { 718ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 719ff12d537SAndre Fischer } 720ff12d537SAndre Fischer 721ff12d537SAndre Fischer SidebarResource aLocalResource; 722ff12d537SAndre Fischer 723ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 724ff12d537SAndre Fischer // them visible or hide them. 72522de8995SAndre Fischer { 72695a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_PANEL); 72795a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 72895a18594SAndre Fischer iItem(rDeckSelectionData.begin()), 72995a18594SAndre Fischer iEnd(rDeckSelectionData.end()); 73095a18594SAndre Fischer iItem!=iEnd; 73195a18594SAndre Fischer ++iItem) 73295a18594SAndre Fischer { 73395a18594SAndre Fischer pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK); 73495a18594SAndre Fischer pMenu->CheckItem(nIndex, iItem->get<2>()); 73595a18594SAndre Fischer ++nIndex; 73695a18594SAndre Fischer } 73722de8995SAndre Fischer } 73822de8995SAndre Fischer 73995a18594SAndre Fischer pMenu->InsertSeparator(); 74095a18594SAndre Fischer 741ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 742ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 743ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 744ff12d537SAndre Fischer else 745ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 746ff12d537SAndre Fischer 747ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 748ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 74995a18594SAndre Fischer { 75095a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_HIDE); 75195a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 75295a18594SAndre Fischer iItem(rDeckShowData.begin()), 75395a18594SAndre Fischer iEnd(rDeckShowData.end()); 75495a18594SAndre Fischer iItem!=iEnd; 75595a18594SAndre Fischer ++iItem) 75695a18594SAndre Fischer { 75795a18594SAndre Fischer pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE); 75895a18594SAndre Fischer pCustomizationMenu->CheckItem(nIndex, iItem->get<2>()); 75995a18594SAndre Fischer ++nIndex; 76095a18594SAndre Fischer } 76195a18594SAndre Fischer } 76295a18594SAndre Fischer 763ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 764ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 765ff12d537SAndre Fischer 766ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 767ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 768ff12d537SAndre Fischer 769ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 770ff12d537SAndre Fischer 771ff12d537SAndre Fischer return pMenu; 77222de8995SAndre Fischer } 77322de8995SAndre Fischer 77422de8995SAndre Fischer 77522de8995SAndre Fischer 77622de8995SAndre Fischer 777ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 77822de8995SAndre Fischer { 779ff12d537SAndre Fischer if (pMenu == NULL) 780ff12d537SAndre Fischer { 7817a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!"); 782ff12d537SAndre Fischer return 0; 783ff12d537SAndre Fischer } 78422de8995SAndre Fischer 785ff12d537SAndre Fischer pMenu->Deactivate(); 786ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 787ff12d537SAndre Fischer switch (nIndex) 78822de8995SAndre Fischer { 789ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 790ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 791ff12d537SAndre Fischer break; 792ff12d537SAndre Fischer 793ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 794ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 795ff12d537SAndre Fischer break; 796ff12d537SAndre Fischer 797ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 798ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 799ff12d537SAndre Fischer break; 800ff12d537SAndre Fischer 801ff12d537SAndre Fischer default: 802ff12d537SAndre Fischer { 803ff12d537SAndre Fischer try 804ff12d537SAndre Fischer { 805ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 80695a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL)); 807ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 808ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 809ff12d537SAndre Fischer } 810ff12d537SAndre Fischer catch (RuntimeException&) 811ff12d537SAndre Fischer { 812ff12d537SAndre Fischer } 813ff12d537SAndre Fischer } 814ff12d537SAndre Fischer break; 81522de8995SAndre Fischer } 816ff12d537SAndre Fischer 817ff12d537SAndre Fischer return 1; 81822de8995SAndre Fischer } 81922de8995SAndre Fischer 82022de8995SAndre Fischer 821ff12d537SAndre Fischer 822ff12d537SAndre Fischer 8237a32b0c8SAndre Fischer void SidebarController::CloseDeck (void) 8247a32b0c8SAndre Fischer { 8257a32b0c8SAndre Fischer if ( ! mbIsDeckClosed) 8267a32b0c8SAndre Fischer { 8277a32b0c8SAndre Fischer mbIsDeckClosed = true; 8287a32b0c8SAndre Fischer if ( ! mpParentWindow->IsFloatingMode()) 8297a32b0c8SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth()); 8307a32b0c8SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE); 8317a32b0c8SAndre Fischer 832f120fe41SAndre Fischer if (mpCurrentDeck) 833f120fe41SAndre Fischer mpCurrentDeck->Hide(); 8347a32b0c8SAndre Fischer 8357a32b0c8SAndre Fischer NotifyResize(); 8367a32b0c8SAndre Fischer } 8377a32b0c8SAndre Fischer } 8387a32b0c8SAndre Fischer 8397a32b0c8SAndre Fischer 8407a32b0c8SAndre Fischer 8417a32b0c8SAndre Fischer 8427a32b0c8SAndre Fischer void SidebarController::OpenDeck (void) 8437a32b0c8SAndre Fischer { 8447a32b0c8SAndre Fischer if (mbIsDeckClosed) 8457a32b0c8SAndre Fischer { 8467a32b0c8SAndre Fischer mbIsDeckClosed = false; 8477a32b0c8SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth); 8487a32b0c8SAndre Fischer 849f120fe41SAndre Fischer if (mpCurrentDeck) 850f120fe41SAndre Fischer mpCurrentDeck->Show(); 8517a32b0c8SAndre Fischer 8527a32b0c8SAndre Fischer NotifyResize(); 8537a32b0c8SAndre Fischer } 8547a32b0c8SAndre Fischer } 8557a32b0c8SAndre Fischer 8567a32b0c8SAndre Fischer 8577a32b0c8SAndre Fischer 8587a32b0c8SAndre Fischer 85965908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void) 86065908a7eSAndre Fischer { 86165908a7eSAndre Fischer return maFocusManager; 86265908a7eSAndre Fischer } 86365908a7eSAndre Fischer 86465908a7eSAndre Fischer 86565908a7eSAndre Fischer 86665908a7eSAndre Fischer 8677a32b0c8SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void) const 8687a32b0c8SAndre Fischer { 8697a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8707a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8717a32b0c8SAndre Fischer { 8727a32b0c8SAndre Fischer OSL_ASSERT(pSplitWindow!=NULL); 8737a32b0c8SAndre Fischer return 0; 8747a32b0c8SAndre Fischer } 8757a32b0c8SAndre Fischer 8767a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8777a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8787a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8797a32b0c8SAndre Fischer 8807a32b0c8SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn)); 8817a32b0c8SAndre Fischer 8827a32b0c8SAndre Fischer return nRowCount == 1; 8837a32b0c8SAndre Fischer } 8847a32b0c8SAndre Fischer 8857a32b0c8SAndre Fischer 8867a32b0c8SAndre Fischer 8877a32b0c8SAndre Fischer 8887a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth) 8897a32b0c8SAndre Fischer { 8907a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8917a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8927a32b0c8SAndre Fischer return 0; 8937a32b0c8SAndre Fischer 8947a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8957a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8967a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8977a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn)); 8987a32b0c8SAndre Fischer 8997a32b0c8SAndre Fischer Window* pWindow = mpParentWindow; 9007a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel()); 9017a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel()); 9027a32b0c8SAndre Fischer 9037a32b0c8SAndre Fischer pSplitWindow->MoveWindow( 9047a32b0c8SAndre Fischer mpParentWindow, 9057a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()), 9067a32b0c8SAndre Fischer nColumn, 9077a32b0c8SAndre Fischer nRow); 9087a32b0c8SAndre Fischer 9097a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth); 9107a32b0c8SAndre Fischer } 9117a32b0c8SAndre Fischer 9127a32b0c8SAndre Fischer 9137a32b0c8SAndre Fischer 9147a32b0c8SAndre Fischer 9157a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void) 9167a32b0c8SAndre Fischer { 9177a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 9187a32b0c8SAndre Fischer if (pSplitWindow != NULL) 9197a32b0c8SAndre Fischer { 9207a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow)); 9217a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId)); 9227a32b0c8SAndre Fischer // Minimum width is always that of the tabbar. 9237a32b0c8SAndre Fischer const sal_Int32 nMinimumWidth (TabBar::GetDefaultWidth()); 9247a32b0c8SAndre Fischer // Maximum width depends on whether the deck is open or closed. 9257a32b0c8SAndre Fischer const sal_Int32 nMaximumWidth ( 9267a32b0c8SAndre Fischer mbIsDeckClosed 9277a32b0c8SAndre Fischer ? TabBar::GetDefaultWidth() 9287a32b0c8SAndre Fischer : 400); 9297a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange( 9307a32b0c8SAndre Fischer nSetId, 9317a32b0c8SAndre Fischer Range(nMinimumWidth, nMaximumWidth)); 9327a32b0c8SAndre Fischer if (nMinimumWidth == nMaximumWidth) 9337a32b0c8SAndre Fischer pSplitWindow->SetItemSize(nSetId, nMinimumWidth); 9347a32b0c8SAndre Fischer } 9357a32b0c8SAndre Fischer } 9367a32b0c8SAndre Fischer 937ff12d537SAndre Fischer 938ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 939