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> 44*22f77e9eSAndre Fischer #include <toolkit/helper/vclunohelper.hxx> 45*22f77e9eSAndre 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> 58*22f77e9eSAndre 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 7022de8995SAndre Fischer 71ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 7222de8995SAndre Fischer 73ff12d537SAndre Fischer namespace { 74ff12d537SAndre Fischer enum MenuId 7522de8995SAndre Fischer { 76ff12d537SAndre Fischer MID_UNLOCK_TASK_PANEL = 1, 77ff12d537SAndre Fischer MID_LOCK_TASK_PANEL, 78ff12d537SAndre Fischer MID_CUSTOMIZATION, 79ff12d537SAndre Fischer MID_RESTORE_DEFAULT, 80ff12d537SAndre Fischer MID_FIRST_PANEL, 81ff12d537SAndre Fischer MID_FIRST_HIDE = 1000 8222de8995SAndre Fischer }; 83ff12d537SAndre Fischer } 8422de8995SAndre Fischer 8522de8995SAndre Fischer 8622de8995SAndre Fischer SidebarController::SidebarController ( 877a32b0c8SAndre Fischer SidebarDockingWindow* pParentWindow, 8822de8995SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 8922de8995SAndre Fischer : SidebarControllerInterfaceBase(m_aMutex), 90f120fe41SAndre Fischer mpCurrentDeck(), 9122de8995SAndre Fischer mpParentWindow(pParentWindow), 92ff12d537SAndre Fischer mpTabBar(new TabBar( 93ff12d537SAndre Fischer mpParentWindow, 94ff12d537SAndre Fischer rxFrame, 95ff12d537SAndre Fischer ::boost::bind(&SidebarController::SwitchToDeck, this, _1), 9695a18594SAndre Fischer ::boost::bind(&SidebarController::ShowPopupMenu, this, _1,_2,_3))), 9795a18594SAndre Fischer mxFrame(rxFrame), 987a32b0c8SAndre Fischer maCurrentContext(OUString(), OUString()), 9995a18594SAndre Fischer msCurrentDeckId(A2S("PropertyDeck")), 1007a32b0c8SAndre Fischer maPropertyChangeForwarder(::boost::bind(&SidebarController::BroadcastPropertyChange, this)), 1017a32b0c8SAndre Fischer mbIsDeckClosed(false), 1027a32b0c8SAndre Fischer mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()) 10322de8995SAndre Fischer { 10422de8995SAndre Fischer if (pParentWindow == NULL) 10522de8995SAndre Fischer { 10622de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL); 10722de8995SAndre Fischer return; 10822de8995SAndre Fischer } 10922de8995SAndre Fischer 11022de8995SAndre Fischer // Listen for context change events. 11122de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 11222de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 11322de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 11422de8995SAndre Fischer if (xMultiplexer.is()) 11522de8995SAndre Fischer xMultiplexer->addContextChangeEventListener( 11622de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this), 11795a18594SAndre Fischer mxFrame->getController()); 11822de8995SAndre Fischer 11922de8995SAndre Fischer // Listen for window events. 12022de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler)); 121b9e67834SAndre Fischer 122b9e67834SAndre Fischer // Listen for theme property changes. 123b9e67834SAndre Fischer Theme::GetPropertySet()->addPropertyChangeListener( 124b9e67834SAndre Fischer A2S(""), 125b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 126f120fe41SAndre Fischer 127f120fe41SAndre Fischer SwitchToDeck(A2S("default")); 12822de8995SAndre Fischer } 12922de8995SAndre Fischer 13022de8995SAndre Fischer 13122de8995SAndre Fischer 13222de8995SAndre Fischer 13322de8995SAndre Fischer SidebarController::~SidebarController (void) 13422de8995SAndre Fischer { 13522de8995SAndre Fischer } 13622de8995SAndre Fischer 13722de8995SAndre Fischer 13822de8995SAndre Fischer 13922de8995SAndre Fischer 14022de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void) 14122de8995SAndre Fischer { 14265908a7eSAndre Fischer maFocusManager.Clear(); 14365908a7eSAndre Fischer 14422de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 14522de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 14622de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 14722de8995SAndre Fischer if (xMultiplexer.is()) 14822de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 14922de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 15022de8995SAndre Fischer 15122de8995SAndre Fischer if (mpParentWindow != NULL) 15222de8995SAndre Fischer { 15322de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 15422de8995SAndre Fischer mpParentWindow = NULL; 15522de8995SAndre Fischer } 156b9e67834SAndre Fischer 157f120fe41SAndre Fischer if (mpCurrentDeck) 158b9e67834SAndre Fischer { 159f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 160f120fe41SAndre Fischer OSL_TRACE("deleting deck window subtree"); 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; 19195a18594SAndre 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) 200b9e67834SAndre 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) 22195a18594SAndre 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) 23322de8995SAndre Fischer { 23495a18594SAndre Fischer OSL_ASSERT(mpTabBar!=NULL); 23595a18594SAndre Fischer return; 236ff12d537SAndre Fischer } 23795a18594SAndre Fischer 23895a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent(); 23922de8995SAndre Fischer 240ff12d537SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 241ff12d537SAndre 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(); 249ff12d537SAndre 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(); 2677a32b0c8SAndre Fischer #ifdef DEBUG 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 283ff12d537SAndre Fischer } 28422de8995SAndre Fischer 285ff12d537SAndre Fischer 286ff12d537SAndre Fischer 287ff12d537SAndre Fischer 2887a32b0c8SAndre Fischer void SidebarController::UpdateConfigurations (const Context& rContext) 28995a18594SAndre Fischer { 29095a18594SAndre Fischer if (maCurrentContext != rContext) 291ff12d537SAndre Fischer { 292ff12d537SAndre Fischer maCurrentContext = rContext; 293ff12d537SAndre Fischer 29495a18594SAndre Fischer // Notify the tab bar about the updated set of decks. 29595a18594SAndre Fischer ResourceManager::IdContainer aDeckIds; 296ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 29795a18594SAndre Fischer aDeckIds, 29822de8995SAndre Fischer rContext, 299ff12d537SAndre Fischer mxFrame); 30095a18594SAndre Fischer mpTabBar->SetDecks(aDeckIds); 30122de8995SAndre 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 } 31695a18594SAndre 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); 322ff12d537SAndre Fischer if (pDeckDescriptor != NULL) 32395a18594SAndre Fischer { 32495a18594SAndre Fischer msCurrentDeckId = pDeckDescriptor->msId; 325ff12d537SAndre Fischer SwitchToDeck(*pDeckDescriptor, rContext); 32622de8995SAndre Fischer } 32754eaaa32SAndre Fischer 32854eaaa32SAndre Fischer #ifdef DEBUG 32954eaaa32SAndre Fischer // Show the context name in the deck title bar. 33054eaaa32SAndre Fischer if (mpCurrentDeck) 33154eaaa32SAndre Fischer { 33254eaaa32SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 33354eaaa32SAndre Fischer if (pTitleBar != NULL) 33454eaaa32SAndre Fischer pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+rContext.msContext+A2S(")")); 33554eaaa32SAndre Fischer } 33654eaaa32SAndre Fischer #endif 33795a18594SAndre Fischer } 33895a18594SAndre Fischer } 33922de8995SAndre Fischer 34022de8995SAndre Fischer 34122de8995SAndre Fischer 34222de8995SAndre Fischer 343ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 34495a18594SAndre Fischer const ::rtl::OUString& rsDeckId) 345ff12d537SAndre Fischer { 3467a32b0c8SAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId) || mbIsDeckClosed) 34795a18594SAndre Fischer { 34895a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId); 34995a18594SAndre Fischer if (pDeckDescriptor != NULL) 35095a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 35195a18594SAndre Fischer } 352ff12d537SAndre Fischer } 353ff12d537SAndre Fischer 354ff12d537SAndre Fischer 355ff12d537SAndre Fischer 356ff12d537SAndre Fischer 357ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 35822de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 3597a32b0c8SAndre Fischer const Context& rContext) 36022de8995SAndre Fischer { 36165908a7eSAndre Fischer maFocusManager.Clear(); 36265908a7eSAndre Fischer 36395a18594SAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)) 36495a18594SAndre Fischer { 36595a18594SAndre Fischer // When the deck changes then destroy the deck and all panels 36695a18594SAndre Fischer // and create everything new. 367f120fe41SAndre Fischer if (mpCurrentDeck) 36895a18594SAndre Fischer { 369f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 370f120fe41SAndre Fischer mpCurrentDeck.reset(); 37195a18594SAndre Fischer } 37295a18594SAndre Fischer 37395a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId; 37495a18594SAndre Fischer } 37595a18594SAndre Fischer 3767a32b0c8SAndre Fischer // Reopen the deck when necessary. 3777a32b0c8SAndre Fischer OpenDeck(); 3787a32b0c8SAndre Fischer 379ff12d537SAndre Fischer // Determine the panels to display in the deck. 380f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors; 381ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 382f120fe41SAndre Fischer aPanelContextDescriptors, 383ff12d537SAndre Fischer rContext, 384ff12d537SAndre Fischer rDeckDescriptor.msId, 385ff12d537SAndre Fischer mxFrame); 386ff12d537SAndre Fischer 38754eaaa32SAndre Fischer if (aPanelContextDescriptors.empty()) 38854eaaa32SAndre Fischer { 38954eaaa32SAndre Fischer // There are no panels to be displayed in the current context. 39054eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty) 39154eaaa32SAndre Fischer { 39254eaaa32SAndre Fischer // Switch to the "empty" context and try again. 39354eaaa32SAndre Fischer SwitchToDeck( 39454eaaa32SAndre Fischer rDeckDescriptor, 39554eaaa32SAndre Fischer Context( 39654eaaa32SAndre Fischer rContext.msApplication, 39754eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty))); 39854eaaa32SAndre Fischer return; 39954eaaa32SAndre Fischer } 40054eaaa32SAndre Fischer else 40154eaaa32SAndre Fischer { 40254eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have 40354eaaa32SAndre Fischer // to live with an empty deck. 40454eaaa32SAndre Fischer } 40554eaaa32SAndre Fischer } 40654eaaa32SAndre Fischer 407f120fe41SAndre Fischer if (mpCurrentDeck 408f120fe41SAndre Fischer && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors)) 40902c50d82SAndre Fischer { 41002c50d82SAndre Fischer // Requested set of panels is identical to the current set of 41102c50d82SAndre Fischer // panels => Nothing to do. 41202c50d82SAndre Fischer return; 41302c50d82SAndre Fischer } 41402c50d82SAndre Fischer 41595a18594SAndre Fischer // Provide a configuration and Deck object. 416f120fe41SAndre Fischer if ( ! mpCurrentDeck) 41722de8995SAndre Fischer { 418f120fe41SAndre Fischer mpCurrentDeck.reset( 419f120fe41SAndre Fischer new Deck( 4207a32b0c8SAndre Fischer rDeckDescriptor, 4217a32b0c8SAndre Fischer mpParentWindow, 422f120fe41SAndre Fischer ::boost::bind(&SidebarController::CloseDeck, this))); 42354eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle; 42495a18594SAndre Fischer } 425f120fe41SAndre Fischer if ( ! mpCurrentDeck) 426f120fe41SAndre Fischer return; 427ff12d537SAndre Fischer 42895a18594SAndre Fischer // Update the panel list. 429f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size()); 430f120fe41SAndre Fischer SharedPanelContainer aNewPanels; 431f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels()); 43295a18594SAndre Fischer aNewPanels.resize(nNewPanelCount); 4337a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0); 43402c50d82SAndre Fischer bool bHasPanelSetChanged (false); 4357a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex) 436ff12d537SAndre Fischer { 437f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor ( 438f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]); 43995a18594SAndre Fischer 44095a18594SAndre Fischer // Find the corresponding panel among the currently active 44195a18594SAndre Fischer // panels. 442f120fe41SAndre Fischer SharedPanelContainer::const_iterator iPanel (::std::find_if( 443f120fe41SAndre Fischer rCurrentPanels.begin(), 444f120fe41SAndre Fischer rCurrentPanels.end(), 445f120fe41SAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)))); 446f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end()) 44795a18594SAndre Fischer { 448f120fe41SAndre Fischer // Panel already exists in current deck. Reuse it. 4497a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel; 450f120fe41SAndre Fischer OSL_TRACE(" reusing panel %s", S2A(rPanelContexDescriptor.msId)); 451ff12d537SAndre Fischer } 452ff12d537SAndre Fischer else 453ff12d537SAndre Fischer { 45495a18594SAndre Fischer // Panel does not yet exist. Create it. 4557a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel( 456f120fe41SAndre Fischer rPanelContexDescriptor.msId, 457f120fe41SAndre Fischer mpCurrentDeck->GetPanelParentWindow(), 458f120fe41SAndre Fischer rPanelContexDescriptor.msMenuCommand); 459f120fe41SAndre Fischer OSL_TRACE(" creating panel %s", S2A(rPanelContexDescriptor.msId)); 46002c50d82SAndre Fischer bHasPanelSetChanged = true; 461ff12d537SAndre Fischer } 4627a32b0c8SAndre Fischer if (aNewPanels[nWriteIndex] != NULL) 463f120fe41SAndre Fischer { 464f120fe41SAndre Fischer // Depending on the context we have to collapse the panel. 465f120fe41SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible); 466f120fe41SAndre Fischer 4677a32b0c8SAndre Fischer ++nWriteIndex; 46822de8995SAndre Fischer } 469f120fe41SAndre Fischer 470f120fe41SAndre Fischer } 4717a32b0c8SAndre Fischer aNewPanels.resize(nWriteIndex); 47222de8995SAndre Fischer 47395a18594SAndre Fischer // Activate the deck and the new set of panels. 474f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel( 47595a18594SAndre Fischer 0, 47695a18594SAndre Fischer 0, 47795a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 47895a18594SAndre Fischer mpParentWindow->GetSizePixel().Height()); 479f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels); 480f120fe41SAndre Fischer mpCurrentDeck->Show(); 481ff12d537SAndre Fischer 482ff12d537SAndre Fischer // Tell the tab bar to highlight the button associated with the 483ff12d537SAndre Fischer // deck. 484ff12d537SAndre Fischer mpTabBar->HighlightDeck(rDeckDescriptor.msId); 4857a32b0c8SAndre Fischer 4867a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle); 4877a32b0c8SAndre Fischer 48802c50d82SAndre Fischer if (bHasPanelSetChanged) 4897a32b0c8SAndre Fischer NotifyResize(); 49065908a7eSAndre Fischer 49165908a7eSAndre Fischer // Tell the focus manager about the new panels and tab bar 49265908a7eSAndre Fischer // buttons. 49365908a7eSAndre Fischer maFocusManager.SetPanels(aNewPanels); 49465908a7eSAndre Fischer mpTabBar->UpdateFocusManager(maFocusManager); 49522de8995SAndre Fischer } 49622de8995SAndre Fischer 49722de8995SAndre Fischer 49822de8995SAndre Fischer 49922de8995SAndre Fischer 50002c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual ( 501f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels, 502f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels) 50302c50d82SAndre Fischer { 504*22f77e9eSAndre Fischer #ifdef DEBUG 50502c50d82SAndre Fischer OSL_TRACE("current panel list:"); 506f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 50702c50d82SAndre Fischer iPanel(rCurrentPanels.begin()), 50802c50d82SAndre Fischer iEnd(rCurrentPanels.end()); 50902c50d82SAndre Fischer iPanel!=iEnd; 51002c50d82SAndre Fischer ++iPanel) 51102c50d82SAndre Fischer { 51202c50d82SAndre Fischer OSL_TRACE(" panel %s", S2A((*iPanel)->GetId())); 51302c50d82SAndre Fischer } 51402c50d82SAndre Fischer 51502c50d82SAndre Fischer OSL_TRACE("requested panels: "); 516f120fe41SAndre Fischer for (ResourceManager::PanelContextDescriptorContainer::const_iterator 517f120fe41SAndre Fischer iId(rRequestedPanels.begin()), 518f120fe41SAndre Fischer iEnd(rRequestedPanels.end()); 51902c50d82SAndre Fischer iId!=iEnd; 52002c50d82SAndre Fischer ++iId) 52102c50d82SAndre Fischer { 522f120fe41SAndre Fischer OSL_TRACE(" panel %s", S2A(iId->msId)); 52302c50d82SAndre Fischer } 524*22f77e9eSAndre Fischer #endif 52502c50d82SAndre Fischer 526f120fe41SAndre Fischer if (rCurrentPanels.size() != rRequestedPanels.size()) 52702c50d82SAndre Fischer return false; 52802c50d82SAndre Fischer for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex) 52902c50d82SAndre Fischer { 53002c50d82SAndre Fischer if (rCurrentPanels[nIndex] == NULL) 53102c50d82SAndre Fischer return false; 532f120fe41SAndre Fischer if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId)) 53302c50d82SAndre Fischer return false; 53402c50d82SAndre Fischer } 53502c50d82SAndre Fischer return true; 53602c50d82SAndre Fischer } 53702c50d82SAndre Fischer 53802c50d82SAndre Fischer 53902c50d82SAndre Fischer 54002c50d82SAndre Fischer 541f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel ( 54295a18594SAndre Fischer const OUString& rsPanelId, 543f120fe41SAndre Fischer ::Window* pParentWindow, 544f120fe41SAndre Fischer const OUString& rsMenuCommand) 54595a18594SAndre Fischer { 54695a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId); 54795a18594SAndre Fischer if (pPanelDescriptor == NULL) 548f120fe41SAndre Fischer return SharedPanel(); 54995a18594SAndre Fischer 5507a32b0c8SAndre Fischer #ifdef DEBUG 5517a32b0c8SAndre Fischer // Prevent the panel not being created in the same memory of an old panel. 5527a32b0c8SAndre Fischer ::boost::scoped_array<char> pUnused (new char[sizeof(Panel)]); 5537a32b0c8SAndre Fischer OSL_TRACE("allocated memory at %x", pUnused.get()); 5547a32b0c8SAndre Fischer #endif 5557a32b0c8SAndre Fischer 55695a18594SAndre Fischer // Create the panel which is the parent window of the UIElement. 557f120fe41SAndre Fischer SharedPanel pPanel (new Panel( 55895a18594SAndre Fischer *pPanelDescriptor, 5597a32b0c8SAndre Fischer pParentWindow, 560f120fe41SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()), 561f120fe41SAndre Fischer rsMenuCommand.getLength()>0 562f120fe41SAndre Fischer ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rsMenuCommand) 563f120fe41SAndre Fischer : ::boost::function<void(void)>())); 56495a18594SAndre Fischer 56595a18594SAndre Fischer // Create the XUIElement. 56695a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 56795a18594SAndre Fischer pPanel->GetComponentInterface(), 568*22f77e9eSAndre Fischer pPanelDescriptor->msImplementationURL, 569*22f77e9eSAndre Fischer pPanelDescriptor->mbWantsCanvas)); 57095a18594SAndre Fischer if (xUIElement.is()) 57195a18594SAndre Fischer { 57295a18594SAndre Fischer // Initialize the panel and add it to the active deck. 57395a18594SAndre Fischer pPanel->SetUIElement(xUIElement); 57495a18594SAndre Fischer } 57595a18594SAndre Fischer else 57695a18594SAndre Fischer { 577f120fe41SAndre Fischer pPanel.reset(); 57895a18594SAndre Fischer } 57995a18594SAndre Fischer 58095a18594SAndre Fischer return pPanel; 58195a18594SAndre Fischer } 58295a18594SAndre Fischer 58395a18594SAndre Fischer 58495a18594SAndre Fischer 58595a18594SAndre Fischer 586ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 587ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 588*22f77e9eSAndre Fischer const ::rtl::OUString& rsImplementationURL, 589*22f77e9eSAndre Fischer const bool bWantsCanvas) 59022de8995SAndre Fischer { 59122de8995SAndre Fischer try 59222de8995SAndre Fischer { 59322de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 59422de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 59522de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 59622de8995SAndre Fischer UNO_QUERY_THROW); 59722de8995SAndre Fischer 598ff12d537SAndre Fischer // Create the XUIElement. 59922de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 60022de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 601ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 602b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow); 603b9e67834SAndre Fischer if (pSfxDockingWindow != NULL) 604b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings()))); 6057a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet()); 6067a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this)))); 607*22f77e9eSAndre Fischer if (bWantsCanvas) 608*22f77e9eSAndre Fischer { 609*22f77e9eSAndre Fischer Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas()); 610*22f77e9eSAndre Fischer aCreationArguments.put("Canvas", makeAny(xCanvas)); 611*22f77e9eSAndre Fischer } 6127a32b0c8SAndre Fischer 613b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement( 61422de8995SAndre Fischer xUIElementFactory->createUIElement( 615ff12d537SAndre Fischer rsImplementationURL, 6167a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())), 617ff12d537SAndre Fischer UNO_QUERY_THROW); 618b9e67834SAndre Fischer 619b9e67834SAndre Fischer return xUIElement; 62022de8995SAndre Fischer } 62122de8995SAndre Fischer catch(Exception& rException) 62222de8995SAndre Fischer { 62322de8995SAndre Fischer OSL_TRACE("caught exception: %s", 62422de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 62522de8995SAndre Fischer // For some reason we can not create the actual panel. 62622de8995SAndre Fischer // Probably because its factory was not properly registered. 62722de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 62822de8995SAndre Fischer // source of the error. 629ff12d537SAndre Fischer 630ff12d537SAndre Fischer return NULL; 63122de8995SAndre Fischer } 63222de8995SAndre Fischer } 63322de8995SAndre Fischer 63422de8995SAndre Fischer 63522de8995SAndre Fischer 63622de8995SAndre Fischer 63722de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 63822de8995SAndre Fischer { 63922de8995SAndre Fischer if (pEvent != NULL) 64022de8995SAndre Fischer { 64122de8995SAndre Fischer switch (pEvent->GetId()) 64222de8995SAndre Fischer { 64322de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 64422de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 64522de8995SAndre Fischer break; 64622de8995SAndre Fischer 64722de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 64822de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 64922de8995SAndre Fischer NotifyResize(); 65022de8995SAndre Fischer break; 65122de8995SAndre Fischer 652ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 653ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 654ff12d537SAndre Fischer // changes in theme (high contrast mode). 655ff12d537SAndre Fischer Theme::HandleDataChange(); 656ff12d537SAndre Fischer mpParentWindow->Invalidate(); 657ff12d537SAndre Fischer break; 658ff12d537SAndre Fischer 65922de8995SAndre Fischer case SFX_HINT_DYING: 66022de8995SAndre Fischer dispose(); 66122de8995SAndre Fischer break; 66222de8995SAndre Fischer 66322de8995SAndre Fischer default: 66422de8995SAndre Fischer break; 66522de8995SAndre Fischer } 66622de8995SAndre Fischer } 66722de8995SAndre Fischer 66822de8995SAndre Fischer return sal_True; 66922de8995SAndre Fischer } 67022de8995SAndre Fischer 67122de8995SAndre Fischer 67222de8995SAndre Fischer 67322de8995SAndre Fischer 67495a18594SAndre Fischer void SidebarController::ShowPopupMenu ( 67595a18594SAndre Fischer const Rectangle& rButtonBox, 67695a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 67795a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 67822de8995SAndre Fischer { 67995a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData); 680ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 681ff12d537SAndre Fischer 682ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 683ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 684ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 685ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 68622de8995SAndre Fischer } 68722de8995SAndre Fischer 68822de8995SAndre Fischer 68922de8995SAndre Fischer 69022de8995SAndre Fischer 691f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const 692f120fe41SAndre Fischer { 693f120fe41SAndre Fischer try 694f120fe41SAndre Fischer { 695f120fe41SAndre Fischer util::URL aURL; 696f120fe41SAndre Fischer aURL.Complete = rsMenuCommand; 697f120fe41SAndre Fischer 698f120fe41SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 699f120fe41SAndre Fischer const Reference<util::XURLTransformer> xParser ( 700f120fe41SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 701f120fe41SAndre Fischer UNO_QUERY_THROW); 702f120fe41SAndre Fischer xParser->parseStrict(aURL); 703f120fe41SAndre Fischer Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW); 704f120fe41SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(aURL, OUString(), 0)); 705f120fe41SAndre Fischer if (xDispatch.is()) 706f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 707f120fe41SAndre Fischer } 708f120fe41SAndre Fischer catch(Exception& rException) 709f120fe41SAndre Fischer { 710f120fe41SAndre Fischer OSL_TRACE("caught exception: %s", 711f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 712f120fe41SAndre Fischer } 713f120fe41SAndre Fischer } 714f120fe41SAndre Fischer 715f120fe41SAndre Fischer 716f120fe41SAndre Fischer 717f120fe41SAndre Fischer 71895a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu ( 71995a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 72095a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 72122de8995SAndre Fischer { 722ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 723ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 724ff12d537SAndre Fischer if (pMenuWindow != NULL) 72522de8995SAndre Fischer { 726ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 72722de8995SAndre Fischer } 72822de8995SAndre Fischer 729ff12d537SAndre Fischer SidebarResource aLocalResource; 730ff12d537SAndre Fischer 731ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 732ff12d537SAndre Fischer // them visible or hide them. 733ff12d537SAndre Fischer { 73495a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_PANEL); 73595a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 73695a18594SAndre Fischer iItem(rDeckSelectionData.begin()), 73795a18594SAndre Fischer iEnd(rDeckSelectionData.end()); 73895a18594SAndre Fischer iItem!=iEnd; 73995a18594SAndre Fischer ++iItem) 74095a18594SAndre Fischer { 74195a18594SAndre Fischer pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK); 74295a18594SAndre Fischer pMenu->CheckItem(nIndex, iItem->get<2>()); 74395a18594SAndre Fischer ++nIndex; 744ff12d537SAndre Fischer } 74595a18594SAndre Fischer } 74695a18594SAndre Fischer 74795a18594SAndre Fischer pMenu->InsertSeparator(); 748ff12d537SAndre Fischer 749ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 750ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 751ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 752ff12d537SAndre Fischer else 753ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 754ff12d537SAndre Fischer 755ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 756ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 75795a18594SAndre Fischer { 75895a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_HIDE); 75995a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 76095a18594SAndre Fischer iItem(rDeckShowData.begin()), 76195a18594SAndre Fischer iEnd(rDeckShowData.end()); 76295a18594SAndre Fischer iItem!=iEnd; 76395a18594SAndre Fischer ++iItem) 76495a18594SAndre Fischer { 76595a18594SAndre Fischer pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE); 76695a18594SAndre Fischer pCustomizationMenu->CheckItem(nIndex, iItem->get<2>()); 76795a18594SAndre Fischer ++nIndex; 76895a18594SAndre Fischer } 76995a18594SAndre Fischer } 77095a18594SAndre Fischer 771ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 772ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 773ff12d537SAndre Fischer 774ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 775ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 776ff12d537SAndre Fischer 777ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 778ff12d537SAndre Fischer 779ff12d537SAndre Fischer return pMenu; 78022de8995SAndre Fischer } 78122de8995SAndre Fischer 78222de8995SAndre Fischer 78322de8995SAndre Fischer 78422de8995SAndre Fischer 785ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 78622de8995SAndre Fischer { 787ff12d537SAndre Fischer if (pMenu == NULL) 78822de8995SAndre Fischer { 7897a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!"); 790ff12d537SAndre Fischer return 0; 79122de8995SAndre Fischer } 792ff12d537SAndre Fischer 793ff12d537SAndre Fischer pMenu->Deactivate(); 794ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 795ff12d537SAndre Fischer switch (nIndex) 796ff12d537SAndre Fischer { 797ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 798ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 799ff12d537SAndre Fischer break; 800ff12d537SAndre Fischer 801ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 802ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 803ff12d537SAndre Fischer break; 804ff12d537SAndre Fischer 805ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 806ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 807ff12d537SAndre Fischer break; 808ff12d537SAndre Fischer 809ff12d537SAndre Fischer default: 810ff12d537SAndre Fischer { 811ff12d537SAndre Fischer try 812ff12d537SAndre Fischer { 813ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 81495a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL)); 815ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 816ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 817ff12d537SAndre Fischer } 818ff12d537SAndre Fischer catch (RuntimeException&) 819ff12d537SAndre Fischer { 820ff12d537SAndre Fischer } 821ff12d537SAndre Fischer } 822ff12d537SAndre Fischer break; 823ff12d537SAndre Fischer } 824ff12d537SAndre Fischer 825ff12d537SAndre Fischer return 1; 82622de8995SAndre Fischer } 82722de8995SAndre Fischer 82822de8995SAndre Fischer 829ff12d537SAndre Fischer 830ff12d537SAndre Fischer 8317a32b0c8SAndre Fischer void SidebarController::CloseDeck (void) 8327a32b0c8SAndre Fischer { 8337a32b0c8SAndre Fischer if ( ! mbIsDeckClosed) 8347a32b0c8SAndre Fischer { 8357a32b0c8SAndre Fischer mbIsDeckClosed = true; 8367a32b0c8SAndre Fischer if ( ! mpParentWindow->IsFloatingMode()) 8377a32b0c8SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth()); 8387a32b0c8SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE); 8397a32b0c8SAndre Fischer 840f120fe41SAndre Fischer if (mpCurrentDeck) 841f120fe41SAndre Fischer mpCurrentDeck->Hide(); 8427a32b0c8SAndre Fischer 8437a32b0c8SAndre Fischer NotifyResize(); 8447a32b0c8SAndre Fischer } 8457a32b0c8SAndre Fischer } 8467a32b0c8SAndre Fischer 8477a32b0c8SAndre Fischer 8487a32b0c8SAndre Fischer 8497a32b0c8SAndre Fischer 8507a32b0c8SAndre Fischer void SidebarController::OpenDeck (void) 8517a32b0c8SAndre Fischer { 8527a32b0c8SAndre Fischer if (mbIsDeckClosed) 8537a32b0c8SAndre Fischer { 8547a32b0c8SAndre Fischer mbIsDeckClosed = false; 8557a32b0c8SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth); 8567a32b0c8SAndre Fischer 857f120fe41SAndre Fischer if (mpCurrentDeck) 858f120fe41SAndre Fischer mpCurrentDeck->Show(); 8597a32b0c8SAndre Fischer 8607a32b0c8SAndre Fischer NotifyResize(); 8617a32b0c8SAndre Fischer } 8627a32b0c8SAndre Fischer } 8637a32b0c8SAndre Fischer 8647a32b0c8SAndre Fischer 8657a32b0c8SAndre Fischer 8667a32b0c8SAndre Fischer 86765908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void) 86865908a7eSAndre Fischer { 86965908a7eSAndre Fischer return maFocusManager; 87065908a7eSAndre Fischer } 87165908a7eSAndre Fischer 87265908a7eSAndre Fischer 87365908a7eSAndre Fischer 87465908a7eSAndre Fischer 8757a32b0c8SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void) const 8767a32b0c8SAndre Fischer { 8777a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8787a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8797a32b0c8SAndre Fischer { 8807a32b0c8SAndre Fischer OSL_ASSERT(pSplitWindow!=NULL); 8817a32b0c8SAndre Fischer return 0; 8827a32b0c8SAndre Fischer } 8837a32b0c8SAndre Fischer 8847a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8857a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8867a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8877a32b0c8SAndre Fischer 8887a32b0c8SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn)); 8897a32b0c8SAndre Fischer 8907a32b0c8SAndre Fischer return nRowCount == 1; 8917a32b0c8SAndre Fischer } 8927a32b0c8SAndre Fischer 8937a32b0c8SAndre Fischer 8947a32b0c8SAndre Fischer 8957a32b0c8SAndre Fischer 8967a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth) 8977a32b0c8SAndre Fischer { 8987a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8997a32b0c8SAndre Fischer if (pSplitWindow == NULL) 9007a32b0c8SAndre Fischer return 0; 9017a32b0c8SAndre Fischer 9027a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 9037a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 9047a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 9057a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn)); 9067a32b0c8SAndre Fischer 9077a32b0c8SAndre Fischer Window* pWindow = mpParentWindow; 9087a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel()); 9097a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel()); 9107a32b0c8SAndre Fischer 9117a32b0c8SAndre Fischer pSplitWindow->MoveWindow( 9127a32b0c8SAndre Fischer mpParentWindow, 9137a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()), 9147a32b0c8SAndre Fischer nColumn, 9157a32b0c8SAndre Fischer nRow); 9167a32b0c8SAndre Fischer 9177a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth); 9187a32b0c8SAndre Fischer } 9197a32b0c8SAndre Fischer 9207a32b0c8SAndre Fischer 9217a32b0c8SAndre Fischer 9227a32b0c8SAndre Fischer 9237a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void) 9247a32b0c8SAndre Fischer { 9257a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 9267a32b0c8SAndre Fischer if (pSplitWindow != NULL) 9277a32b0c8SAndre Fischer { 9287a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow)); 9297a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId)); 9307a32b0c8SAndre Fischer // Minimum width is always that of the tabbar. 9317a32b0c8SAndre Fischer const sal_Int32 nMinimumWidth (TabBar::GetDefaultWidth()); 9327a32b0c8SAndre Fischer // Maximum width depends on whether the deck is open or closed. 9337a32b0c8SAndre Fischer const sal_Int32 nMaximumWidth ( 9347a32b0c8SAndre Fischer mbIsDeckClosed 9357a32b0c8SAndre Fischer ? TabBar::GetDefaultWidth() 9367a32b0c8SAndre Fischer : 400); 9377a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange( 9387a32b0c8SAndre Fischer nSetId, 9397a32b0c8SAndre Fischer Range(nMinimumWidth, nMaximumWidth)); 9407a32b0c8SAndre Fischer if (nMinimumWidth == nMaximumWidth) 9417a32b0c8SAndre Fischer pSplitWindow->SetItemSize(nSetId, nMinimumWidth); 9427a32b0c8SAndre Fischer } 9437a32b0c8SAndre Fischer } 9447a32b0c8SAndre Fischer 945ff12d537SAndre Fischer 946ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 947