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 7056798e4bSAndre 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)), 102*239cbbc0SAndre Fischer maContextChangeUpdate(::boost::bind(&SidebarController::UpdateConfigurations, this)), 1037a32b0c8SAndre Fischer mbIsDeckClosed(false), 1047a32b0c8SAndre Fischer mnSavedSidebarWidth(pParentWindow->GetSizePixel().Width()) 10522de8995SAndre Fischer { 10622de8995SAndre Fischer if (pParentWindow == NULL) 10722de8995SAndre Fischer { 10822de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL); 10922de8995SAndre Fischer return; 11022de8995SAndre Fischer } 11122de8995SAndre Fischer 11222de8995SAndre Fischer // Listen for context change events. 11322de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 11422de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 11522de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 11622de8995SAndre Fischer if (xMultiplexer.is()) 11722de8995SAndre Fischer xMultiplexer->addContextChangeEventListener( 11822de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this), 11995a18594SAndre Fischer mxFrame->getController()); 12022de8995SAndre Fischer 12122de8995SAndre Fischer // Listen for window events. 12222de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler)); 123b9e67834SAndre Fischer 124b9e67834SAndre Fischer // Listen for theme property changes. 125b9e67834SAndre Fischer Theme::GetPropertySet()->addPropertyChangeListener( 126b9e67834SAndre Fischer A2S(""), 127b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 128f120fe41SAndre Fischer 129f120fe41SAndre Fischer SwitchToDeck(A2S("default")); 13022de8995SAndre Fischer } 13122de8995SAndre Fischer 13222de8995SAndre Fischer 13322de8995SAndre Fischer 13422de8995SAndre Fischer 13522de8995SAndre Fischer SidebarController::~SidebarController (void) 13622de8995SAndre Fischer { 13722de8995SAndre Fischer } 13822de8995SAndre Fischer 13922de8995SAndre Fischer 14022de8995SAndre Fischer 14122de8995SAndre Fischer 14222de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void) 14322de8995SAndre Fischer { 14465908a7eSAndre Fischer maFocusManager.Clear(); 14565908a7eSAndre Fischer 14622de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 14722de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 14822de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 14922de8995SAndre Fischer if (xMultiplexer.is()) 15022de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 15122de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 15222de8995SAndre Fischer 15322de8995SAndre Fischer if (mpParentWindow != NULL) 15422de8995SAndre Fischer { 15522de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 15622de8995SAndre Fischer mpParentWindow = NULL; 15722de8995SAndre Fischer } 158b9e67834SAndre Fischer 159f120fe41SAndre Fischer if (mpCurrentDeck) 160b9e67834SAndre Fischer { 161f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 162f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 163f120fe41SAndre Fischer mpCurrentDeck.reset(); 164b9e67834SAndre Fischer } 165b9e67834SAndre Fischer 166580828edSAndre Fischer mpTabBar.reset(); 167580828edSAndre Fischer 168b9e67834SAndre Fischer Theme::GetPropertySet()->removePropertyChangeListener( 169b9e67834SAndre Fischer A2S(""), 170b9e67834SAndre Fischer static_cast<css::beans::XPropertyChangeListener*>(this)); 17122de8995SAndre Fischer } 17222de8995SAndre Fischer 17322de8995SAndre Fischer 17422de8995SAndre Fischer 17522de8995SAndre Fischer 17622de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) 17722de8995SAndre Fischer throw(cssu::RuntimeException) 17822de8995SAndre Fischer { 179*239cbbc0SAndre Fischer // Update to the requested new context asynchronously to avoid 180*239cbbc0SAndre Fischer // subtle errors caused by SFX2 which in rare cases can not 181*239cbbc0SAndre Fischer // properly handle a synchronous update. 182*239cbbc0SAndre Fischer maRequestedContext = Context( 183*239cbbc0SAndre Fischer rEvent.ApplicationName, 184*239cbbc0SAndre Fischer rEvent.ContextName); 185*239cbbc0SAndre Fischer if (maRequestedContext != maCurrentContext) 186*239cbbc0SAndre Fischer maContextChangeUpdate.RequestCall(); 18722de8995SAndre Fischer } 18822de8995SAndre Fischer 18922de8995SAndre Fischer 19022de8995SAndre Fischer 19122de8995SAndre Fischer 19222de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject) 19322de8995SAndre Fischer throw(cssu::RuntimeException) 19422de8995SAndre Fischer { 19595a18594SAndre Fischer (void)rEventObject; 196f120fe41SAndre Fischer 197f120fe41SAndre Fischer dispose(); 19822de8995SAndre Fischer } 19922de8995SAndre Fischer 20022de8995SAndre Fischer 20122de8995SAndre Fischer 20222de8995SAndre Fischer 203b9e67834SAndre Fischer void SAL_CALL SidebarController::propertyChange (const css::beans::PropertyChangeEvent& rEvent) 204b9e67834SAndre Fischer throw(cssu::RuntimeException) 20595a18594SAndre Fischer { 20695a18594SAndre Fischer (void)rEvent; 20795a18594SAndre Fischer 20895a18594SAndre Fischer maPropertyChangeForwarder.RequestCall(); 20995a18594SAndre Fischer } 21095a18594SAndre Fischer 21195a18594SAndre Fischer 21295a18594SAndre Fischer 21395a18594SAndre Fischer 2147a32b0c8SAndre Fischer void SAL_CALL SidebarController::requestLayout (void) 2157a32b0c8SAndre Fischer throw(cssu::RuntimeException) 2167a32b0c8SAndre Fischer { 217f120fe41SAndre Fischer if (mpCurrentDeck) 218f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 2197a32b0c8SAndre Fischer RestrictWidth(); 2207a32b0c8SAndre Fischer } 2217a32b0c8SAndre Fischer 2227a32b0c8SAndre Fischer 2237a32b0c8SAndre Fischer 2247a32b0c8SAndre Fischer 22595a18594SAndre Fischer void SidebarController::BroadcastPropertyChange (void) 226b9e67834SAndre Fischer { 227b9e67834SAndre Fischer DataChangedEvent aEvent (DATACHANGED_USER); 228b9e67834SAndre Fischer mpParentWindow->NotifyAllChilds(aEvent); 229b9e67834SAndre Fischer mpParentWindow->Invalidate(INVALIDATE_CHILDREN); 230b9e67834SAndre Fischer } 231b9e67834SAndre Fischer 232b9e67834SAndre Fischer 233b9e67834SAndre Fischer 234b9e67834SAndre Fischer 23522de8995SAndre Fischer void SidebarController::NotifyResize (void) 23622de8995SAndre Fischer { 23795a18594SAndre Fischer if (mpTabBar == NULL) 23895a18594SAndre Fischer { 23995a18594SAndre Fischer OSL_ASSERT(mpTabBar!=NULL); 24095a18594SAndre Fischer return; 24195a18594SAndre Fischer } 24295a18594SAndre Fischer 24395a18594SAndre Fischer Window* pParentWindow = mpTabBar->GetParent(); 24495a18594SAndre Fischer 24595a18594SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 24695a18594SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height()); 24795a18594SAndre Fischer 2487a32b0c8SAndre Fischer // Place the deck. 249f120fe41SAndre Fischer if (mpCurrentDeck) 2507a32b0c8SAndre Fischer { 251f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight); 252f120fe41SAndre Fischer mpCurrentDeck->Show(); 253f120fe41SAndre Fischer mpCurrentDeck->RequestLayout(); 25422de8995SAndre Fischer } 25595a18594SAndre Fischer 2567a32b0c8SAndre Fischer // Place the tab bar. 25795a18594SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight); 25895a18594SAndre Fischer mpTabBar->Show(); 2597a32b0c8SAndre Fischer 2607a32b0c8SAndre Fischer // Determine if the closer of the deck can be shown. 261f120fe41SAndre Fischer if (mpCurrentDeck) 2627a32b0c8SAndre Fischer { 263f120fe41SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 2647a32b0c8SAndre Fischer if (pTitleBar != NULL && pTitleBar->IsVisible()) 2657a32b0c8SAndre Fischer pTitleBar->SetCloserVisible(CanModifyChildWindowWidth()); 2667a32b0c8SAndre Fischer } 2677a32b0c8SAndre Fischer 2687a32b0c8SAndre Fischer if (nWidth > TabBar::GetDefaultWidth()) 2697a32b0c8SAndre Fischer mnSavedSidebarWidth = nWidth; 2707a32b0c8SAndre Fischer 2717a32b0c8SAndre Fischer RestrictWidth(); 27256798e4bSAndre Fischer #ifdef VERBOSE 273f120fe41SAndre Fischer if (mpCurrentDeck) 2747a32b0c8SAndre Fischer { 275f120fe41SAndre Fischer mpCurrentDeck->PrintWindowTree(); 2767a32b0c8SAndre Fischer sal_Int32 nPanelIndex (0); 277f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 278f120fe41SAndre Fischer iPanel(mpCurrentDeck->GetPanels().begin()), 279f120fe41SAndre Fischer iEnd(mpCurrentDeck->GetPanels().end()); 2807a32b0c8SAndre Fischer iPanel!=iEnd; 2817a32b0c8SAndre Fischer ++iPanel,++nPanelIndex) 2827a32b0c8SAndre Fischer { 2837a32b0c8SAndre Fischer OSL_TRACE("panel %d:", nPanelIndex); 2847a32b0c8SAndre Fischer (*iPanel)->PrintWindowTree(); 2857a32b0c8SAndre Fischer } 2867a32b0c8SAndre Fischer } 2877a32b0c8SAndre Fischer #endif 28822de8995SAndre Fischer } 28922de8995SAndre Fischer 29022de8995SAndre Fischer 29122de8995SAndre Fischer 29222de8995SAndre Fischer 293*239cbbc0SAndre Fischer void SidebarController::UpdateConfigurations (void) 29422de8995SAndre Fischer { 295*239cbbc0SAndre Fischer if (maCurrentContext != maRequestedContext) 29695a18594SAndre Fischer { 297*239cbbc0SAndre Fischer maCurrentContext = maRequestedContext; 29895a18594SAndre Fischer 29995a18594SAndre Fischer // Notify the tab bar about the updated set of decks. 30095a18594SAndre Fischer ResourceManager::IdContainer aDeckIds; 30195a18594SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 30295a18594SAndre Fischer aDeckIds, 303*239cbbc0SAndre Fischer maCurrentContext, 30495a18594SAndre Fischer mxFrame); 30595a18594SAndre Fischer mpTabBar->SetDecks(aDeckIds); 30695a18594SAndre Fischer 30795a18594SAndre Fischer // Check if the current deck is among the matching decks. 30895a18594SAndre Fischer bool bCurrentDeckMatches (false); 30995a18594SAndre Fischer for (ResourceManager::IdContainer::const_iterator 31095a18594SAndre Fischer iDeck(aDeckIds.begin()), 31195a18594SAndre Fischer iEnd(aDeckIds.end()); 31295a18594SAndre Fischer iDeck!=iEnd; 31395a18594SAndre Fischer ++iDeck) 31495a18594SAndre Fischer { 31595a18594SAndre Fischer if (iDeck->equals(msCurrentDeckId)) 31695a18594SAndre Fischer { 31795a18594SAndre Fischer bCurrentDeckMatches = true; 31895a18594SAndre Fischer break; 31995a18594SAndre Fischer } 32095a18594SAndre Fischer } 321ff12d537SAndre Fischer 32295a18594SAndre Fischer DeckDescriptor const* pDeckDescriptor = NULL; 32395a18594SAndre Fischer if ( ! bCurrentDeckMatches) 324*239cbbc0SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetBestMatchingDeck(maCurrentContext, mxFrame); 32595a18594SAndre Fischer else 32695a18594SAndre Fischer pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(msCurrentDeckId); 32795a18594SAndre Fischer if (pDeckDescriptor != NULL) 32895a18594SAndre Fischer { 32995a18594SAndre Fischer msCurrentDeckId = pDeckDescriptor->msId; 330*239cbbc0SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 33156798e4bSAndre Fischer 33256798e4bSAndre Fischer // Tell the tab bar to highlight the button associated 33356798e4bSAndre Fischer // with the deck. 33456798e4bSAndre Fischer mpTabBar->HighlightDeck(msCurrentDeckId); 33595a18594SAndre Fischer } 33654eaaa32SAndre Fischer 33754eaaa32SAndre Fischer #ifdef DEBUG 33854eaaa32SAndre Fischer // Show the context name in the deck title bar. 33954eaaa32SAndre Fischer if (mpCurrentDeck) 34054eaaa32SAndre Fischer { 34154eaaa32SAndre Fischer DeckTitleBar* pTitleBar = mpCurrentDeck->GetTitleBar(); 34254eaaa32SAndre Fischer if (pTitleBar != NULL) 343*239cbbc0SAndre Fischer pTitleBar->SetTitle(msCurrentDeckTitle+A2S(" (")+maCurrentContext.msContext+A2S(")")); 34454eaaa32SAndre Fischer } 34554eaaa32SAndre Fischer #endif 34695a18594SAndre Fischer } 347ff12d537SAndre Fischer } 348ff12d537SAndre Fischer 349ff12d537SAndre Fischer 35022de8995SAndre Fischer 351ff12d537SAndre Fischer 352ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 35395a18594SAndre Fischer const ::rtl::OUString& rsDeckId) 354ff12d537SAndre Fischer { 3557a32b0c8SAndre Fischer if ( ! msCurrentDeckId.equals(rsDeckId) || mbIsDeckClosed) 35695a18594SAndre Fischer { 35795a18594SAndre Fischer const DeckDescriptor* pDeckDescriptor = ResourceManager::Instance().GetDeckDescriptor(rsDeckId); 35895a18594SAndre Fischer if (pDeckDescriptor != NULL) 35995a18594SAndre Fischer SwitchToDeck(*pDeckDescriptor, maCurrentContext); 36095a18594SAndre Fischer } 36122de8995SAndre Fischer } 36222de8995SAndre Fischer 36322de8995SAndre Fischer 36422de8995SAndre Fischer 36522de8995SAndre Fischer 366ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 36722de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 3687a32b0c8SAndre Fischer const Context& rContext) 36922de8995SAndre Fischer { 37065908a7eSAndre Fischer maFocusManager.Clear(); 37165908a7eSAndre Fischer 37295a18594SAndre Fischer if ( ! msCurrentDeckId.equals(rDeckDescriptor.msId)) 37395a18594SAndre Fischer { 37495a18594SAndre Fischer // When the deck changes then destroy the deck and all panels 37595a18594SAndre Fischer // and create everything new. 376f120fe41SAndre Fischer if (mpCurrentDeck) 37795a18594SAndre Fischer { 378f120fe41SAndre Fischer mpCurrentDeck->Dispose(); 379f120fe41SAndre Fischer mpCurrentDeck.reset(); 38095a18594SAndre Fischer } 38195a18594SAndre Fischer 38295a18594SAndre Fischer msCurrentDeckId = rDeckDescriptor.msId; 38395a18594SAndre Fischer } 3847a32b0c8SAndre Fischer 3857a32b0c8SAndre Fischer // Reopen the deck when necessary. 3867a32b0c8SAndre Fischer OpenDeck(); 3877a32b0c8SAndre Fischer 388ff12d537SAndre Fischer // Determine the panels to display in the deck. 389f120fe41SAndre Fischer ResourceManager::PanelContextDescriptorContainer aPanelContextDescriptors; 390ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 391f120fe41SAndre Fischer aPanelContextDescriptors, 392ff12d537SAndre Fischer rContext, 393ff12d537SAndre Fischer rDeckDescriptor.msId, 394ff12d537SAndre Fischer mxFrame); 395ff12d537SAndre Fischer 39654eaaa32SAndre Fischer if (aPanelContextDescriptors.empty()) 39754eaaa32SAndre Fischer { 39854eaaa32SAndre Fischer // There are no panels to be displayed in the current context. 39954eaaa32SAndre Fischer if (EnumContext::GetContextEnum(rContext.msContext) != EnumContext::Context_Empty) 40054eaaa32SAndre Fischer { 40154eaaa32SAndre Fischer // Switch to the "empty" context and try again. 40254eaaa32SAndre Fischer SwitchToDeck( 40354eaaa32SAndre Fischer rDeckDescriptor, 40454eaaa32SAndre Fischer Context( 40554eaaa32SAndre Fischer rContext.msApplication, 40654eaaa32SAndre Fischer EnumContext::GetContextName(EnumContext::Context_Empty))); 40754eaaa32SAndre Fischer return; 40854eaaa32SAndre Fischer } 40954eaaa32SAndre Fischer else 41054eaaa32SAndre Fischer { 41154eaaa32SAndre Fischer // This is already the "empty" context. Looks like we have 41254eaaa32SAndre Fischer // to live with an empty deck. 41354eaaa32SAndre Fischer } 41454eaaa32SAndre Fischer } 41554eaaa32SAndre Fischer 416f120fe41SAndre Fischer if (mpCurrentDeck 417f120fe41SAndre Fischer && ArePanelSetsEqual(mpCurrentDeck->GetPanels(), aPanelContextDescriptors)) 41802c50d82SAndre Fischer { 41902c50d82SAndre Fischer // Requested set of panels is identical to the current set of 42002c50d82SAndre Fischer // panels => Nothing to do. 42102c50d82SAndre Fischer return; 42202c50d82SAndre Fischer } 42302c50d82SAndre Fischer 42495a18594SAndre Fischer // Provide a configuration and Deck object. 425f120fe41SAndre Fischer if ( ! mpCurrentDeck) 42622de8995SAndre Fischer { 427f120fe41SAndre Fischer mpCurrentDeck.reset( 428f120fe41SAndre Fischer new Deck( 429f120fe41SAndre Fischer rDeckDescriptor, 430f120fe41SAndre Fischer mpParentWindow, 431f120fe41SAndre Fischer ::boost::bind(&SidebarController::CloseDeck, this))); 43254eaaa32SAndre Fischer msCurrentDeckTitle = rDeckDescriptor.msTitle; 43395a18594SAndre Fischer } 434f120fe41SAndre Fischer if ( ! mpCurrentDeck) 435f120fe41SAndre Fischer return; 436f120fe41SAndre Fischer 43795a18594SAndre Fischer // Update the panel list. 438f120fe41SAndre Fischer const sal_Int32 nNewPanelCount (aPanelContextDescriptors.size()); 439f120fe41SAndre Fischer SharedPanelContainer aNewPanels; 440f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels (mpCurrentDeck->GetPanels()); 44195a18594SAndre Fischer aNewPanels.resize(nNewPanelCount); 4427a32b0c8SAndre Fischer sal_Int32 nWriteIndex (0); 44302c50d82SAndre Fischer bool bHasPanelSetChanged (false); 4447a32b0c8SAndre Fischer for (sal_Int32 nReadIndex=0; nReadIndex<nNewPanelCount; ++nReadIndex) 44595a18594SAndre Fischer { 446f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptor& rPanelContexDescriptor ( 447f120fe41SAndre Fischer aPanelContextDescriptors[nReadIndex]); 44895a18594SAndre Fischer 44995a18594SAndre Fischer // Find the corresponding panel among the currently active 45095a18594SAndre Fischer // panels. 451f120fe41SAndre Fischer SharedPanelContainer::const_iterator iPanel (::std::find_if( 452f120fe41SAndre Fischer rCurrentPanels.begin(), 453f120fe41SAndre Fischer rCurrentPanels.end(), 454f120fe41SAndre Fischer ::boost::bind(&Panel::HasIdPredicate, _1, ::boost::cref(rPanelContexDescriptor.msId)))); 455f120fe41SAndre Fischer if (iPanel != rCurrentPanels.end()) 456ff12d537SAndre Fischer { 457f120fe41SAndre Fischer // Panel already exists in current deck. Reuse it. 4587a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = *iPanel; 459ff12d537SAndre Fischer } 460ff12d537SAndre Fischer else 461ff12d537SAndre Fischer { 46295a18594SAndre Fischer // Panel does not yet exist. Create it. 4637a32b0c8SAndre Fischer aNewPanels[nWriteIndex] = CreatePanel( 464f120fe41SAndre Fischer rPanelContexDescriptor.msId, 465f120fe41SAndre Fischer mpCurrentDeck->GetPanelParentWindow(), 466f120fe41SAndre Fischer rPanelContexDescriptor.msMenuCommand); 46702c50d82SAndre Fischer bHasPanelSetChanged = true; 468ff12d537SAndre Fischer } 4697a32b0c8SAndre Fischer if (aNewPanels[nWriteIndex] != NULL) 47002c50d82SAndre Fischer { 471f120fe41SAndre Fischer // Depending on the context we have to collapse the panel. 472f120fe41SAndre Fischer aNewPanels[nWriteIndex]->SetExpanded(rPanelContexDescriptor.mbIsInitiallyVisible); 473f120fe41SAndre Fischer 474f120fe41SAndre Fischer ++nWriteIndex; 47502c50d82SAndre Fischer } 476f120fe41SAndre Fischer 47795a18594SAndre Fischer } 478f120fe41SAndre Fischer aNewPanels.resize(nWriteIndex); 47995a18594SAndre Fischer 48095a18594SAndre Fischer // Activate the deck and the new set of panels. 481f120fe41SAndre Fischer mpCurrentDeck->SetPosSizePixel( 48295a18594SAndre Fischer 0, 48395a18594SAndre Fischer 0, 48495a18594SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 48595a18594SAndre Fischer mpParentWindow->GetSizePixel().Height()); 486f120fe41SAndre Fischer mpCurrentDeck->SetPanels(aNewPanels); 487f120fe41SAndre Fischer mpCurrentDeck->Show(); 488ff12d537SAndre Fischer 4897a32b0c8SAndre Fischer mpParentWindow->SetText(rDeckDescriptor.msTitle); 4907a32b0c8SAndre Fischer 49102c50d82SAndre Fischer if (bHasPanelSetChanged) 49202c50d82SAndre Fischer NotifyResize(); 49365908a7eSAndre Fischer 49465908a7eSAndre Fischer // Tell the focus manager about the new panels and tab bar 49565908a7eSAndre Fischer // buttons. 49665908a7eSAndre Fischer maFocusManager.SetPanels(aNewPanels); 49765908a7eSAndre Fischer mpTabBar->UpdateFocusManager(maFocusManager); 49802c50d82SAndre Fischer } 49902c50d82SAndre Fischer 50002c50d82SAndre Fischer 50102c50d82SAndre Fischer 50202c50d82SAndre Fischer 50302c50d82SAndre Fischer bool SidebarController::ArePanelSetsEqual ( 504f120fe41SAndre Fischer const SharedPanelContainer& rCurrentPanels, 505f120fe41SAndre Fischer const ResourceManager::PanelContextDescriptorContainer& rRequestedPanels) 50602c50d82SAndre Fischer { 50756798e4bSAndre Fischer #ifdef VERBOSE 50802c50d82SAndre Fischer OSL_TRACE("current panel list:"); 509f120fe41SAndre Fischer for (SharedPanelContainer::const_iterator 51002c50d82SAndre Fischer iPanel(rCurrentPanels.begin()), 51102c50d82SAndre Fischer iEnd(rCurrentPanels.end()); 51202c50d82SAndre Fischer iPanel!=iEnd; 51302c50d82SAndre Fischer ++iPanel) 51402c50d82SAndre Fischer { 51502c50d82SAndre Fischer OSL_TRACE(" panel %s", S2A((*iPanel)->GetId())); 51602c50d82SAndre Fischer } 51702c50d82SAndre Fischer 51802c50d82SAndre Fischer OSL_TRACE("requested panels: "); 519f120fe41SAndre Fischer for (ResourceManager::PanelContextDescriptorContainer::const_iterator 520f120fe41SAndre Fischer iId(rRequestedPanels.begin()), 521f120fe41SAndre Fischer iEnd(rRequestedPanels.end()); 52202c50d82SAndre Fischer iId!=iEnd; 52302c50d82SAndre Fischer ++iId) 52402c50d82SAndre Fischer { 525f120fe41SAndre Fischer OSL_TRACE(" panel %s", S2A(iId->msId)); 52602c50d82SAndre Fischer } 52722f77e9eSAndre Fischer #endif 52802c50d82SAndre Fischer 529f120fe41SAndre Fischer if (rCurrentPanels.size() != rRequestedPanels.size()) 53002c50d82SAndre Fischer return false; 53102c50d82SAndre Fischer for (sal_Int32 nIndex=0,nCount=rCurrentPanels.size(); nIndex<nCount; ++nIndex) 53202c50d82SAndre Fischer { 53302c50d82SAndre Fischer if (rCurrentPanels[nIndex] == NULL) 53402c50d82SAndre Fischer return false; 535f120fe41SAndre Fischer if ( ! rCurrentPanels[nIndex]->GetId().equals(rRequestedPanels[nIndex].msId)) 53602c50d82SAndre Fischer return false; 53702c50d82SAndre Fischer } 53802c50d82SAndre Fischer return true; 53922de8995SAndre Fischer } 54022de8995SAndre Fischer 54122de8995SAndre Fischer 54222de8995SAndre Fischer 54322de8995SAndre Fischer 544f120fe41SAndre Fischer SharedPanel SidebarController::CreatePanel ( 54595a18594SAndre Fischer const OUString& rsPanelId, 546f120fe41SAndre Fischer ::Window* pParentWindow, 547f120fe41SAndre Fischer const OUString& rsMenuCommand) 54895a18594SAndre Fischer { 54995a18594SAndre Fischer const PanelDescriptor* pPanelDescriptor = ResourceManager::Instance().GetPanelDescriptor(rsPanelId); 55095a18594SAndre Fischer if (pPanelDescriptor == NULL) 551f120fe41SAndre Fischer return SharedPanel(); 5527a32b0c8SAndre Fischer 55395a18594SAndre Fischer // Create the panel which is the parent window of the UIElement. 554f120fe41SAndre Fischer SharedPanel pPanel (new Panel( 55595a18594SAndre Fischer *pPanelDescriptor, 5567a32b0c8SAndre Fischer pParentWindow, 557f120fe41SAndre Fischer ::boost::bind(&Deck::RequestLayout, mpCurrentDeck.get()), 558f120fe41SAndre Fischer rsMenuCommand.getLength()>0 559f120fe41SAndre Fischer ? ::boost::bind(&SidebarController::ShowDetailMenu,this,rsMenuCommand) 560f120fe41SAndre Fischer : ::boost::function<void(void)>())); 56195a18594SAndre Fischer 56295a18594SAndre Fischer // Create the XUIElement. 56395a18594SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 56495a18594SAndre Fischer pPanel->GetComponentInterface(), 56522f77e9eSAndre Fischer pPanelDescriptor->msImplementationURL, 56622f77e9eSAndre Fischer pPanelDescriptor->mbWantsCanvas)); 56795a18594SAndre Fischer if (xUIElement.is()) 56895a18594SAndre Fischer { 56995a18594SAndre Fischer // Initialize the panel and add it to the active deck. 57095a18594SAndre Fischer pPanel->SetUIElement(xUIElement); 57195a18594SAndre Fischer } 57295a18594SAndre Fischer else 57395a18594SAndre Fischer { 574f120fe41SAndre Fischer pPanel.reset(); 57595a18594SAndre Fischer } 57695a18594SAndre Fischer 57795a18594SAndre Fischer return pPanel; 57895a18594SAndre Fischer } 57995a18594SAndre Fischer 58095a18594SAndre Fischer 58195a18594SAndre Fischer 58295a18594SAndre Fischer 583ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 584ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 58522f77e9eSAndre Fischer const ::rtl::OUString& rsImplementationURL, 58622f77e9eSAndre Fischer const bool bWantsCanvas) 58722de8995SAndre Fischer { 58822de8995SAndre Fischer try 58922de8995SAndre Fischer { 59022de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 59122de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 59222de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 59322de8995SAndre Fischer UNO_QUERY_THROW); 594ff12d537SAndre Fischer 5957a32b0c8SAndre Fischer // Create the XUIElement. 59622de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 59722de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 598ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 599b9e67834SAndre Fischer SfxDockingWindow* pSfxDockingWindow = dynamic_cast<SfxDockingWindow*>(mpParentWindow); 600b9e67834SAndre Fischer if (pSfxDockingWindow != NULL) 601b9e67834SAndre Fischer aCreationArguments.put("SfxBindings", makeAny(sal_uInt64(&pSfxDockingWindow->GetBindings()))); 6027a32b0c8SAndre Fischer aCreationArguments.put("Theme", Theme::GetPropertySet()); 6037a32b0c8SAndre Fischer aCreationArguments.put("Sidebar", makeAny(Reference<ui::XSidebar>(static_cast<ui::XSidebar*>(this)))); 60422f77e9eSAndre Fischer if (bWantsCanvas) 60522f77e9eSAndre Fischer { 60622f77e9eSAndre Fischer Reference<rendering::XSpriteCanvas> xCanvas (VCLUnoHelper::GetWindow(rxWindow)->GetSpriteCanvas()); 60722f77e9eSAndre Fischer aCreationArguments.put("Canvas", makeAny(xCanvas)); 60822f77e9eSAndre Fischer } 6097a32b0c8SAndre Fischer 610b9e67834SAndre Fischer Reference<ui::XUIElement> xUIElement( 611ff12d537SAndre Fischer xUIElementFactory->createUIElement( 612ff12d537SAndre Fischer rsImplementationURL, 6137a32b0c8SAndre Fischer Sequence<beans::PropertyValue>(aCreationArguments.getPropertyValues())), 614ff12d537SAndre Fischer UNO_QUERY_THROW); 615b9e67834SAndre Fischer 616b9e67834SAndre Fischer return xUIElement; 61722de8995SAndre Fischer } 61822de8995SAndre Fischer catch(Exception& rException) 61922de8995SAndre Fischer { 62022de8995SAndre Fischer OSL_TRACE("caught exception: %s", 62122de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 62222de8995SAndre Fischer // For some reason we can not create the actual panel. 62322de8995SAndre Fischer // Probably because its factory was not properly registered. 62422de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 62522de8995SAndre Fischer // source of the error. 626ff12d537SAndre Fischer 627ff12d537SAndre Fischer return NULL; 62822de8995SAndre Fischer } 62922de8995SAndre Fischer } 63022de8995SAndre Fischer 63122de8995SAndre Fischer 63222de8995SAndre Fischer 63322de8995SAndre Fischer 63422de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 63522de8995SAndre Fischer { 63622de8995SAndre Fischer if (pEvent != NULL) 63722de8995SAndre Fischer { 63822de8995SAndre Fischer switch (pEvent->GetId()) 63922de8995SAndre Fischer { 64022de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 64122de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 64222de8995SAndre Fischer break; 64322de8995SAndre Fischer 64422de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 64522de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 64622de8995SAndre Fischer NotifyResize(); 64722de8995SAndre Fischer break; 64822de8995SAndre Fischer 649ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 650ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 651ff12d537SAndre Fischer // changes in theme (high contrast mode). 652ff12d537SAndre Fischer Theme::HandleDataChange(); 653ff12d537SAndre Fischer mpParentWindow->Invalidate(); 654ff12d537SAndre Fischer break; 655ff12d537SAndre Fischer 65622de8995SAndre Fischer case SFX_HINT_DYING: 65722de8995SAndre Fischer dispose(); 65822de8995SAndre Fischer break; 65922de8995SAndre Fischer 66022de8995SAndre Fischer default: 66122de8995SAndre Fischer break; 66222de8995SAndre Fischer } 66322de8995SAndre Fischer } 66422de8995SAndre Fischer 66522de8995SAndre Fischer return sal_True; 66622de8995SAndre Fischer } 66722de8995SAndre Fischer 66822de8995SAndre Fischer 66922de8995SAndre Fischer 67022de8995SAndre Fischer 67195a18594SAndre Fischer void SidebarController::ShowPopupMenu ( 67295a18594SAndre Fischer const Rectangle& rButtonBox, 67395a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 67495a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 67522de8995SAndre Fischer { 67695a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(rDeckSelectionData, rDeckShowData); 677ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 678ff12d537SAndre Fischer 679ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 680ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 681ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 682ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 68322de8995SAndre Fischer } 68422de8995SAndre Fischer 68522de8995SAndre Fischer 68622de8995SAndre Fischer 68722de8995SAndre Fischer 688f120fe41SAndre Fischer void SidebarController::ShowDetailMenu (const ::rtl::OUString& rsMenuCommand) const 689f120fe41SAndre Fischer { 690f120fe41SAndre Fischer try 691f120fe41SAndre Fischer { 692f120fe41SAndre Fischer util::URL aURL; 693f120fe41SAndre Fischer aURL.Complete = rsMenuCommand; 694f120fe41SAndre Fischer 695f120fe41SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 696f120fe41SAndre Fischer const Reference<util::XURLTransformer> xParser ( 697f120fe41SAndre Fischer aComponentContext.createComponent("com.sun.star.util.URLTransformer"), 698f120fe41SAndre Fischer UNO_QUERY_THROW); 699f120fe41SAndre Fischer xParser->parseStrict(aURL); 700f120fe41SAndre Fischer Reference<frame::XDispatchProvider> xProvider (mxFrame, UNO_QUERY_THROW); 701f120fe41SAndre Fischer Reference<frame::XDispatch> xDispatch (xProvider->queryDispatch(aURL, OUString(), 0)); 702f120fe41SAndre Fischer if (xDispatch.is()) 703f120fe41SAndre Fischer xDispatch->dispatch(aURL, Sequence<beans::PropertyValue>()); 704f120fe41SAndre Fischer } 705f120fe41SAndre Fischer catch(Exception& rException) 706f120fe41SAndre Fischer { 707f120fe41SAndre Fischer OSL_TRACE("caught exception: %s", 708f120fe41SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 709f120fe41SAndre Fischer } 710f120fe41SAndre Fischer } 711f120fe41SAndre Fischer 712f120fe41SAndre Fischer 713f120fe41SAndre Fischer 714f120fe41SAndre Fischer 71595a18594SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu ( 71695a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckSelectionData, 71795a18594SAndre Fischer const ::std::vector<TabBar::DeckMenuData>& rDeckShowData) const 71822de8995SAndre Fischer { 719ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 720ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 721ff12d537SAndre Fischer if (pMenuWindow != NULL) 722ff12d537SAndre Fischer { 723ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 724ff12d537SAndre Fischer } 725ff12d537SAndre Fischer 726ff12d537SAndre Fischer SidebarResource aLocalResource; 727ff12d537SAndre Fischer 728ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 729ff12d537SAndre Fischer // them visible or hide them. 73022de8995SAndre Fischer { 73195a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_PANEL); 73295a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 73395a18594SAndre Fischer iItem(rDeckSelectionData.begin()), 73495a18594SAndre Fischer iEnd(rDeckSelectionData.end()); 73595a18594SAndre Fischer iItem!=iEnd; 73695a18594SAndre Fischer ++iItem) 73795a18594SAndre Fischer { 73895a18594SAndre Fischer pMenu->InsertItem(nIndex, iItem->get<0>(), MIB_RADIOCHECK); 73995a18594SAndre Fischer pMenu->CheckItem(nIndex, iItem->get<2>()); 74095a18594SAndre Fischer ++nIndex; 74195a18594SAndre Fischer } 74222de8995SAndre Fischer } 74322de8995SAndre Fischer 74495a18594SAndre Fischer pMenu->InsertSeparator(); 74595a18594SAndre Fischer 746ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 747ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 748ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 749ff12d537SAndre Fischer else 750ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 751ff12d537SAndre Fischer 752ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 753ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 75495a18594SAndre Fischer { 75595a18594SAndre Fischer sal_Int32 nIndex (MID_FIRST_HIDE); 75695a18594SAndre Fischer for(::std::vector<TabBar::DeckMenuData>::const_iterator 75795a18594SAndre Fischer iItem(rDeckShowData.begin()), 75895a18594SAndre Fischer iEnd(rDeckShowData.end()); 75995a18594SAndre Fischer iItem!=iEnd; 76095a18594SAndre Fischer ++iItem) 76195a18594SAndre Fischer { 76295a18594SAndre Fischer pCustomizationMenu->InsertItem(nIndex, iItem->get<0>(), MIB_CHECKABLE); 76395a18594SAndre Fischer pCustomizationMenu->CheckItem(nIndex, iItem->get<2>()); 76495a18594SAndre Fischer ++nIndex; 76595a18594SAndre Fischer } 76695a18594SAndre Fischer } 76795a18594SAndre Fischer 768ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 769ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 770ff12d537SAndre Fischer 771ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 772ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 773ff12d537SAndre Fischer 774ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 775ff12d537SAndre Fischer 776ff12d537SAndre Fischer return pMenu; 77722de8995SAndre Fischer } 77822de8995SAndre Fischer 77922de8995SAndre Fischer 78022de8995SAndre Fischer 78122de8995SAndre Fischer 782ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 78322de8995SAndre Fischer { 784ff12d537SAndre Fischer if (pMenu == NULL) 785ff12d537SAndre Fischer { 7867a32b0c8SAndre Fischer OSL_ENSURE(pMenu!=NULL, "sfx2::sidebar::SidebarController::OnMenuItemSelected: illegal menu!"); 787ff12d537SAndre Fischer return 0; 788ff12d537SAndre Fischer } 78922de8995SAndre Fischer 790ff12d537SAndre Fischer pMenu->Deactivate(); 791ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 792ff12d537SAndre Fischer switch (nIndex) 79322de8995SAndre Fischer { 794ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 795ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 796ff12d537SAndre Fischer break; 797ff12d537SAndre Fischer 798ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 799ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 800ff12d537SAndre Fischer break; 801ff12d537SAndre Fischer 802ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 803ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 804ff12d537SAndre Fischer break; 805ff12d537SAndre Fischer 806ff12d537SAndre Fischer default: 807ff12d537SAndre Fischer { 808ff12d537SAndre Fischer try 809ff12d537SAndre Fischer { 810ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 81195a18594SAndre Fischer SwitchToDeck(mpTabBar->GetDeckIdForIndex(nIndex - MID_FIRST_PANEL)); 812ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 813ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 814ff12d537SAndre Fischer } 815ff12d537SAndre Fischer catch (RuntimeException&) 816ff12d537SAndre Fischer { 817ff12d537SAndre Fischer } 818ff12d537SAndre Fischer } 819ff12d537SAndre Fischer break; 82022de8995SAndre Fischer } 821ff12d537SAndre Fischer 822ff12d537SAndre Fischer return 1; 82322de8995SAndre Fischer } 82422de8995SAndre Fischer 82522de8995SAndre Fischer 826ff12d537SAndre Fischer 827ff12d537SAndre Fischer 8287a32b0c8SAndre Fischer void SidebarController::CloseDeck (void) 8297a32b0c8SAndre Fischer { 8307a32b0c8SAndre Fischer if ( ! mbIsDeckClosed) 8317a32b0c8SAndre Fischer { 8327a32b0c8SAndre Fischer mbIsDeckClosed = true; 8337a32b0c8SAndre Fischer if ( ! mpParentWindow->IsFloatingMode()) 8347a32b0c8SAndre Fischer mnSavedSidebarWidth = SetChildWindowWidth(TabBar::GetDefaultWidth()); 8357a32b0c8SAndre Fischer mpParentWindow->SetStyle(mpParentWindow->GetStyle() & ~WB_SIZEABLE); 8367a32b0c8SAndre Fischer 837f120fe41SAndre Fischer if (mpCurrentDeck) 838f120fe41SAndre Fischer mpCurrentDeck->Hide(); 8397a32b0c8SAndre Fischer 8407a32b0c8SAndre Fischer NotifyResize(); 8417a32b0c8SAndre Fischer } 8427a32b0c8SAndre Fischer } 8437a32b0c8SAndre Fischer 8447a32b0c8SAndre Fischer 8457a32b0c8SAndre Fischer 8467a32b0c8SAndre Fischer 8477a32b0c8SAndre Fischer void SidebarController::OpenDeck (void) 8487a32b0c8SAndre Fischer { 8497a32b0c8SAndre Fischer if (mbIsDeckClosed) 8507a32b0c8SAndre Fischer { 8517a32b0c8SAndre Fischer mbIsDeckClosed = false; 8527a32b0c8SAndre Fischer SetChildWindowWidth(mnSavedSidebarWidth); 8537a32b0c8SAndre Fischer 854f120fe41SAndre Fischer if (mpCurrentDeck) 855f120fe41SAndre Fischer mpCurrentDeck->Show(); 8567a32b0c8SAndre Fischer 8577a32b0c8SAndre Fischer NotifyResize(); 8587a32b0c8SAndre Fischer } 8597a32b0c8SAndre Fischer } 8607a32b0c8SAndre Fischer 8617a32b0c8SAndre Fischer 8627a32b0c8SAndre Fischer 8637a32b0c8SAndre Fischer 86465908a7eSAndre Fischer FocusManager& SidebarController::GetFocusManager (void) 86565908a7eSAndre Fischer { 86665908a7eSAndre Fischer return maFocusManager; 86765908a7eSAndre Fischer } 86865908a7eSAndre Fischer 86965908a7eSAndre Fischer 87065908a7eSAndre Fischer 87165908a7eSAndre Fischer 8727a32b0c8SAndre Fischer bool SidebarController::CanModifyChildWindowWidth (void) const 8737a32b0c8SAndre Fischer { 8747a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8757a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8767a32b0c8SAndre Fischer { 8777a32b0c8SAndre Fischer return 0; 8787a32b0c8SAndre Fischer } 8797a32b0c8SAndre Fischer 8807a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8817a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 8827a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 8837a32b0c8SAndre Fischer 8847a32b0c8SAndre Fischer sal_uInt16 nRowCount (pSplitWindow->GetWindowCount(nColumn)); 8857a32b0c8SAndre Fischer 8867a32b0c8SAndre Fischer return nRowCount == 1; 8877a32b0c8SAndre Fischer } 8887a32b0c8SAndre Fischer 8897a32b0c8SAndre Fischer 8907a32b0c8SAndre Fischer 8917a32b0c8SAndre Fischer 8927a32b0c8SAndre Fischer sal_Int32 SidebarController::SetChildWindowWidth (const sal_Int32 nNewWidth) 8937a32b0c8SAndre Fischer { 8947a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 8957a32b0c8SAndre Fischer if (pSplitWindow == NULL) 8967a32b0c8SAndre Fischer return 0; 8977a32b0c8SAndre Fischer 8987a32b0c8SAndre Fischer sal_uInt16 nRow (0xffff); 8997a32b0c8SAndre Fischer sal_uInt16 nColumn (0xffff); 9007a32b0c8SAndre Fischer pSplitWindow->GetWindowPos(mpParentWindow, nColumn, nRow); 9017a32b0c8SAndre Fischer const long nColumnWidth (pSplitWindow->GetLineSize(nColumn)); 9027a32b0c8SAndre Fischer 9037a32b0c8SAndre Fischer Window* pWindow = mpParentWindow; 9047a32b0c8SAndre Fischer const Point aWindowPosition (pWindow->GetPosPixel()); 9057a32b0c8SAndre Fischer const Size aWindowSize (pWindow->GetSizePixel()); 9067a32b0c8SAndre Fischer 9077a32b0c8SAndre Fischer pSplitWindow->MoveWindow( 9087a32b0c8SAndre Fischer mpParentWindow, 9097a32b0c8SAndre Fischer Size(nNewWidth, aWindowSize.Height()), 9107a32b0c8SAndre Fischer nColumn, 9117a32b0c8SAndre Fischer nRow); 9127a32b0c8SAndre Fischer 9137a32b0c8SAndre Fischer return static_cast<sal_Int32>(nColumnWidth); 9147a32b0c8SAndre Fischer } 9157a32b0c8SAndre Fischer 9167a32b0c8SAndre Fischer 9177a32b0c8SAndre Fischer 9187a32b0c8SAndre Fischer 9197a32b0c8SAndre Fischer void SidebarController::RestrictWidth (void) 9207a32b0c8SAndre Fischer { 9217a32b0c8SAndre Fischer SfxSplitWindow* pSplitWindow = dynamic_cast<SfxSplitWindow*>(mpParentWindow->GetParent()); 9227a32b0c8SAndre Fischer if (pSplitWindow != NULL) 9237a32b0c8SAndre Fischer { 9247a32b0c8SAndre Fischer const sal_uInt16 nId (pSplitWindow->GetItemId(mpParentWindow)); 9257a32b0c8SAndre Fischer const sal_uInt16 nSetId (pSplitWindow->GetSet(nId)); 9267a32b0c8SAndre Fischer // Minimum width is always that of the tabbar. 9277a32b0c8SAndre Fischer const sal_Int32 nMinimumWidth (TabBar::GetDefaultWidth()); 9287a32b0c8SAndre Fischer // Maximum width depends on whether the deck is open or closed. 9297a32b0c8SAndre Fischer const sal_Int32 nMaximumWidth ( 9307a32b0c8SAndre Fischer mbIsDeckClosed 9317a32b0c8SAndre Fischer ? TabBar::GetDefaultWidth() 9327a32b0c8SAndre Fischer : 400); 9337a32b0c8SAndre Fischer pSplitWindow->SetItemSizeRange( 9347a32b0c8SAndre Fischer nSetId, 9357a32b0c8SAndre Fischer Range(nMinimumWidth, nMaximumWidth)); 9367a32b0c8SAndre Fischer if (nMinimumWidth == nMaximumWidth) 9377a32b0c8SAndre Fischer pSplitWindow->SetItemSize(nSetId, nMinimumWidth); 9387a32b0c8SAndre Fischer } 9397a32b0c8SAndre Fischer } 9407a32b0c8SAndre Fischer 941ff12d537SAndre Fischer 942ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 943