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" 26*ff12d537SAndre Fischer #include "DeckConfiguration.hxx" 2722de8995SAndre Fischer #include "Panel.hxx" 28*ff12d537SAndre Fischer #include "SidebarResource.hxx" 2922de8995SAndre Fischer #include "TitleBar.hxx" 3022de8995SAndre Fischer #include "TabBar.hxx" 31*ff12d537SAndre Fischer #include "Theme.hxx" 32*ff12d537SAndre Fischer 3322de8995SAndre Fischer #include "sfxresid.hxx" 3422de8995SAndre Fischer #include "sfx2/sfxsids.hrc" 35*ff12d537SAndre Fischer #include "sfxlocal.hrc" 36*ff12d537SAndre Fischer #include <vcl/floatwin.hxx> 37*ff12d537SAndre Fischer #include <vcl/dockwin.hxx> 38*ff12d537SAndre Fischer #include <comphelper/componentfactory.hxx> 39*ff12d537SAndre Fischer #include <comphelper/componentcontext.hxx> 40*ff12d537SAndre Fischer #include <comphelper/namedvaluecollection.hxx> 4122de8995SAndre Fischer 4222de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> 4322de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp> 4422de8995SAndre Fischer 4522de8995SAndre Fischer #include <boost/bind.hpp> 46*ff12d537SAndre Fischer #include <boost/foreach.hpp> 4722de8995SAndre Fischer 4822de8995SAndre Fischer 4922de8995SAndre Fischer using namespace css; 5022de8995SAndre Fischer using namespace cssu; 5122de8995SAndre Fischer 5222de8995SAndre Fischer 5322de8995SAndre Fischer #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 5422de8995SAndre Fischer 55*ff12d537SAndre Fischer namespace sfx2 { namespace sidebar { 5622de8995SAndre Fischer 57*ff12d537SAndre Fischer namespace { 58*ff12d537SAndre Fischer enum MenuId 59*ff12d537SAndre Fischer { 60*ff12d537SAndre Fischer MID_UNLOCK_TASK_PANEL = 1, 61*ff12d537SAndre Fischer MID_LOCK_TASK_PANEL, 62*ff12d537SAndre Fischer MID_CUSTOMIZATION, 63*ff12d537SAndre Fischer MID_RESTORE_DEFAULT, 64*ff12d537SAndre Fischer MID_FIRST_PANEL, 65*ff12d537SAndre Fischer MID_FIRST_HIDE = 1000 66*ff12d537SAndre Fischer }; 67*ff12d537SAndre Fischer } 6822de8995SAndre Fischer 6922de8995SAndre Fischer 7022de8995SAndre Fischer SidebarController::SidebarController ( 71*ff12d537SAndre Fischer DockingWindow* pParentWindow, 7222de8995SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 7322de8995SAndre Fischer : SidebarControllerInterfaceBase(m_aMutex), 7422de8995SAndre Fischer mpCurrentConfiguration(), 7522de8995SAndre Fischer mpParentWindow(pParentWindow), 76*ff12d537SAndre Fischer mpTabBar(new TabBar( 77*ff12d537SAndre Fischer mpParentWindow, 78*ff12d537SAndre Fischer rxFrame, 79*ff12d537SAndre Fischer ::boost::bind(&SidebarController::SwitchToDeck, this, _1), 80*ff12d537SAndre Fischer ::boost::bind(&SidebarController::ShowPopupMenu, this, _1))), 8122de8995SAndre Fischer mxFrame(rxFrame) 8222de8995SAndre Fischer { 8322de8995SAndre Fischer if (pParentWindow == NULL) 8422de8995SAndre Fischer { 8522de8995SAndre Fischer OSL_ASSERT(pParentWindow!=NULL); 8622de8995SAndre Fischer return; 8722de8995SAndre Fischer } 8822de8995SAndre Fischer 89*ff12d537SAndre Fischer UpdateConfigurations(Context(A2S("default"), A2S("default"))); 9022de8995SAndre Fischer 9122de8995SAndre Fischer // Listen for context change events. 9222de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 9322de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 9422de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 9522de8995SAndre Fischer if (xMultiplexer.is()) 9622de8995SAndre Fischer xMultiplexer->addContextChangeEventListener( 9722de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this), 9822de8995SAndre Fischer NULL); 9922de8995SAndre Fischer 10022de8995SAndre Fischer // Listen for window events. 10122de8995SAndre Fischer mpParentWindow->AddEventListener(LINK(this, SidebarController, WindowEventHandler)); 10222de8995SAndre Fischer } 10322de8995SAndre Fischer 10422de8995SAndre Fischer 10522de8995SAndre Fischer 10622de8995SAndre Fischer 10722de8995SAndre Fischer SidebarController::~SidebarController (void) 10822de8995SAndre Fischer { 10922de8995SAndre Fischer } 11022de8995SAndre Fischer 11122de8995SAndre Fischer 11222de8995SAndre Fischer 11322de8995SAndre Fischer 11422de8995SAndre Fischer void SAL_CALL SidebarController::disposing (void) 11522de8995SAndre Fischer { 11622de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 11722de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 11822de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 11922de8995SAndre Fischer if (xMultiplexer.is()) 12022de8995SAndre Fischer xMultiplexer->removeAllContextChangeEventListeners( 12122de8995SAndre Fischer static_cast<css::ui::XContextChangeEventListener*>(this)); 12222de8995SAndre Fischer 12322de8995SAndre Fischer if (mpParentWindow != NULL) 12422de8995SAndre Fischer { 12522de8995SAndre Fischer mpParentWindow->RemoveEventListener(LINK(this, SidebarController, WindowEventHandler)); 12622de8995SAndre Fischer mpParentWindow = NULL; 12722de8995SAndre Fischer } 12822de8995SAndre Fischer } 12922de8995SAndre Fischer 13022de8995SAndre Fischer 13122de8995SAndre Fischer 13222de8995SAndre Fischer 13322de8995SAndre Fischer void SAL_CALL SidebarController::notifyContextChangeEvent (const css::ui::ContextChangeEventObject& rEvent) 13422de8995SAndre Fischer throw(cssu::RuntimeException) 13522de8995SAndre Fischer { 136*ff12d537SAndre Fischer UpdateConfigurations(Context(rEvent.ApplicationName, rEvent.ContextName)); 13722de8995SAndre Fischer } 13822de8995SAndre Fischer 13922de8995SAndre Fischer 14022de8995SAndre Fischer 14122de8995SAndre Fischer 14222de8995SAndre Fischer void SAL_CALL SidebarController::disposing (const css::lang::EventObject& rEventObject) 14322de8995SAndre Fischer throw(cssu::RuntimeException) 14422de8995SAndre Fischer { 14522de8995SAndre Fischer if (mpCurrentConfiguration) 14622de8995SAndre Fischer { 14722de8995SAndre Fischer mpCurrentConfiguration->Disable(); 14822de8995SAndre Fischer mpCurrentConfiguration.reset(); 14922de8995SAndre Fischer } 15022de8995SAndre Fischer if (mpTabBar != NULL) 15122de8995SAndre Fischer { 15222de8995SAndre Fischer mpTabBar->Hide(); 15322de8995SAndre Fischer delete mpTabBar; 15422de8995SAndre Fischer mpTabBar = NULL; 15522de8995SAndre Fischer } 15622de8995SAndre Fischer } 15722de8995SAndre Fischer 15822de8995SAndre Fischer 15922de8995SAndre Fischer 16022de8995SAndre Fischer 16122de8995SAndre Fischer void SidebarController::NotifyResize (void) 16222de8995SAndre Fischer { 16322de8995SAndre Fischer if (mpCurrentConfiguration != NULL) 16422de8995SAndre Fischer { 165*ff12d537SAndre Fischer if (mpCurrentConfiguration->mpDeck==NULL || mpTabBar==NULL) 166*ff12d537SAndre Fischer { 167*ff12d537SAndre Fischer OSL_ASSERT(mpCurrentConfiguration->mpDeck!=NULL && mpTabBar!=NULL); 168*ff12d537SAndre Fischer } 169*ff12d537SAndre Fischer else 170*ff12d537SAndre Fischer { 171*ff12d537SAndre Fischer Window* pParentWindow = mpCurrentConfiguration->mpDeck->GetParent(); 172*ff12d537SAndre Fischer if (pParentWindow==NULL || pParentWindow!=mpTabBar->GetParent()) 173*ff12d537SAndre Fischer { 174*ff12d537SAndre Fischer OSL_ASSERT(mpCurrentConfiguration->mpDeck->GetParent() != NULL); 175*ff12d537SAndre Fischer OSL_ASSERT(mpCurrentConfiguration->mpDeck->GetParent() == mpTabBar->GetParent()); 176*ff12d537SAndre Fischer } 177*ff12d537SAndre Fischer 178*ff12d537SAndre Fischer const sal_Int32 nWidth (pParentWindow->GetSizePixel().Width()); 179*ff12d537SAndre Fischer const sal_Int32 nHeight (pParentWindow->GetSizePixel().Height()); 180*ff12d537SAndre Fischer mpCurrentConfiguration->mpDeck->SetPosSizePixel(0,0, nWidth-TabBar::GetDefaultWidth(), nHeight); 181*ff12d537SAndre Fischer mpCurrentConfiguration->mpDeck->Show(); 182*ff12d537SAndre Fischer mpTabBar->SetPosSizePixel(nWidth-TabBar::GetDefaultWidth(),0,TabBar::GetDefaultWidth(),nHeight); 183*ff12d537SAndre Fischer mpTabBar->Show(); 184*ff12d537SAndre Fischer 185*ff12d537SAndre Fischer mpCurrentConfiguration->mpDeck->RequestLayout(); 186*ff12d537SAndre Fischer } 18722de8995SAndre Fischer } 18822de8995SAndre Fischer } 18922de8995SAndre Fischer 19022de8995SAndre Fischer 19122de8995SAndre Fischer 19222de8995SAndre Fischer 193*ff12d537SAndre Fischer void SidebarController::UpdateConfigurations (const Context& rContext) 19422de8995SAndre Fischer { 195*ff12d537SAndre Fischer maCurrentContext = rContext; 196*ff12d537SAndre Fischer 197*ff12d537SAndre Fischer ResourceManager::DeckContainer aDeckDescriptors; 198*ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingDecks ( 199*ff12d537SAndre Fischer aDeckDescriptors, 20022de8995SAndre Fischer rContext, 201*ff12d537SAndre Fischer mxFrame); 202*ff12d537SAndre Fischer mpTabBar->SetDecks(aDeckDescriptors); 203*ff12d537SAndre Fischer 204*ff12d537SAndre Fischer const DeckDescriptor* pDeckDescriptor (ResourceManager::Instance().GetBestMatchingDeck(rContext, mxFrame)); 205*ff12d537SAndre Fischer if (pDeckDescriptor != NULL) 206*ff12d537SAndre Fischer SwitchToDeck(*pDeckDescriptor, rContext); 207*ff12d537SAndre Fischer } 208*ff12d537SAndre Fischer 209*ff12d537SAndre Fischer 21022de8995SAndre Fischer 211*ff12d537SAndre Fischer 212*ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 213*ff12d537SAndre Fischer const DeckDescriptor& rDeckDescriptor) 214*ff12d537SAndre Fischer { 215*ff12d537SAndre Fischer SwitchToDeck(rDeckDescriptor, maCurrentContext); 21622de8995SAndre Fischer } 21722de8995SAndre Fischer 21822de8995SAndre Fischer 21922de8995SAndre Fischer 22022de8995SAndre Fischer 221*ff12d537SAndre Fischer void SidebarController::SwitchToDeck ( 22222de8995SAndre Fischer const DeckDescriptor& rDeckDescriptor, 223*ff12d537SAndre Fischer const Context& rContext) 22422de8995SAndre Fischer { 225*ff12d537SAndre Fischer // Determine the panels to display in the deck. 226*ff12d537SAndre Fischer ResourceManager::PanelContainer aPanelDescriptors; 227*ff12d537SAndre Fischer ResourceManager::Instance().GetMatchingPanels( 228*ff12d537SAndre Fischer aPanelDescriptors, 229*ff12d537SAndre Fischer rContext, 230*ff12d537SAndre Fischer rDeckDescriptor.msId, 231*ff12d537SAndre Fischer mxFrame); 232*ff12d537SAndre Fischer 233*ff12d537SAndre Fischer // Setup a configuration for the requested deck 234*ff12d537SAndre Fischer // and create the deck. 235*ff12d537SAndre Fischer ::boost::shared_ptr<DeckConfiguration> pConfiguration (new DeckConfiguration); 236*ff12d537SAndre Fischer pConfiguration->mpDeck = new Deck(rDeckDescriptor, mpParentWindow); 237*ff12d537SAndre Fischer 238*ff12d537SAndre Fischer // Create the panels. 239*ff12d537SAndre Fischer for (ResourceManager::PanelContainer::const_iterator 240*ff12d537SAndre Fischer iPanel(aPanelDescriptors.begin()), 241*ff12d537SAndre Fischer iEnd(aPanelDescriptors.end()); 242*ff12d537SAndre Fischer iPanel!=iEnd; 243*ff12d537SAndre Fischer ++iPanel) 24422de8995SAndre Fischer { 245*ff12d537SAndre Fischer // Create the panel which is the parent window of the UIElement. 246*ff12d537SAndre Fischer Panel* pPanel = new Panel( 247*ff12d537SAndre Fischer *iPanel, 248*ff12d537SAndre Fischer pConfiguration->mpDeck, 249*ff12d537SAndre Fischer ::boost::bind(&Deck::RequestLayout,pConfiguration->mpDeck)); 250*ff12d537SAndre Fischer 251*ff12d537SAndre Fischer // Create the XUIElement. 252*ff12d537SAndre Fischer Reference<ui::XUIElement> xUIElement (CreateUIElement( 253*ff12d537SAndre Fischer pPanel->GetComponentInterface(), 254*ff12d537SAndre Fischer iPanel->msImplementationURL)); 255*ff12d537SAndre Fischer if (xUIElement.is()) 256*ff12d537SAndre Fischer { 257*ff12d537SAndre Fischer // Initialize the panel and add it to the active deck. 258*ff12d537SAndre Fischer pPanel->SetUIElement(xUIElement); 259*ff12d537SAndre Fischer pConfiguration->maPanels.push_back(pPanel); 260*ff12d537SAndre Fischer } 261*ff12d537SAndre Fischer else 262*ff12d537SAndre Fischer { 263*ff12d537SAndre Fischer delete pPanel; 264*ff12d537SAndre Fischer } 26522de8995SAndre Fischer } 26622de8995SAndre Fischer 267*ff12d537SAndre Fischer // Activate the new configuration. 268*ff12d537SAndre Fischer MakeConfigurationCurrent(pConfiguration); 269*ff12d537SAndre Fischer 270*ff12d537SAndre Fischer // Tell the tab bar to highlight the button associated with the 271*ff12d537SAndre Fischer // deck. 272*ff12d537SAndre Fischer mpTabBar->HighlightDeck(rDeckDescriptor.msId); 27322de8995SAndre Fischer } 27422de8995SAndre Fischer 27522de8995SAndre Fischer 27622de8995SAndre Fischer 27722de8995SAndre Fischer 278*ff12d537SAndre Fischer Reference<ui::XUIElement> SidebarController::CreateUIElement ( 279*ff12d537SAndre Fischer const Reference<awt::XWindowPeer>& rxWindow, 280*ff12d537SAndre Fischer const ::rtl::OUString& rsImplementationURL) const 28122de8995SAndre Fischer { 28222de8995SAndre Fischer try 28322de8995SAndre Fischer { 28422de8995SAndre Fischer const ::comphelper::ComponentContext aComponentContext (::comphelper::getProcessServiceFactory()); 28522de8995SAndre Fischer const Reference<ui::XUIElementFactory> xUIElementFactory ( 28622de8995SAndre Fischer aComponentContext.createComponent("com.sun.star.ui.UIElementFactoryManager"), 28722de8995SAndre Fischer UNO_QUERY_THROW); 288*ff12d537SAndre Fischer 289*ff12d537SAndre Fischer 290*ff12d537SAndre Fischer // Create the XUIElement. 29122de8995SAndre Fischer ::comphelper::NamedValueCollection aCreationArguments; 29222de8995SAndre Fischer aCreationArguments.put("Frame", makeAny(mxFrame)); 293*ff12d537SAndre Fischer aCreationArguments.put("ParentWindow", makeAny(rxWindow)); 294*ff12d537SAndre Fischer return Reference<ui::XUIElement>( 295*ff12d537SAndre Fischer xUIElementFactory->createUIElement( 296*ff12d537SAndre Fischer rsImplementationURL, 297*ff12d537SAndre Fischer aCreationArguments.getPropertyValues()), 298*ff12d537SAndre Fischer UNO_QUERY_THROW); 29922de8995SAndre Fischer } 30022de8995SAndre Fischer catch(Exception& rException) 30122de8995SAndre Fischer { 30222de8995SAndre Fischer OSL_TRACE("caught exception: %s", 30322de8995SAndre Fischer OUStringToOString(rException.Message, RTL_TEXTENCODING_ASCII_US).getStr()); 30422de8995SAndre Fischer // For some reason we can not create the actual panel. 30522de8995SAndre Fischer // Probably because its factory was not properly registered. 30622de8995SAndre Fischer // TODO: provide feedback to developer to better pinpoint the 30722de8995SAndre Fischer // source of the error. 308*ff12d537SAndre Fischer 309*ff12d537SAndre Fischer return NULL; 31022de8995SAndre Fischer } 31122de8995SAndre Fischer } 31222de8995SAndre Fischer 31322de8995SAndre Fischer 31422de8995SAndre Fischer 31522de8995SAndre Fischer 316*ff12d537SAndre Fischer void SidebarController::MakeConfigurationCurrent (const ::boost::shared_ptr<DeckConfiguration>& rpConfiguration) 31722de8995SAndre Fischer { 318*ff12d537SAndre Fischer if ( ! rpConfiguration || rpConfiguration->mpDeck == NULL) 31922de8995SAndre Fischer return; 32022de8995SAndre Fischer 32122de8995SAndre Fischer // Deactivate the current deck and panels. 32222de8995SAndre Fischer if (mpCurrentConfiguration && mpCurrentConfiguration->mpDeck!=NULL) 32322de8995SAndre Fischer mpCurrentConfiguration->Disable(); 324*ff12d537SAndre Fischer 325*ff12d537SAndre Fischer mpCurrentConfiguration = rpConfiguration; 326*ff12d537SAndre Fischer 327*ff12d537SAndre Fischer mpCurrentConfiguration->mpDeck->SetPosSizePixel( 328*ff12d537SAndre Fischer 0, 329*ff12d537SAndre Fischer 0, 330*ff12d537SAndre Fischer mpParentWindow->GetSizePixel().Width()-TabBar::GetDefaultWidth(), 331*ff12d537SAndre Fischer mpParentWindow->GetSizePixel().Height()); 332*ff12d537SAndre Fischer mpCurrentConfiguration->mpDeck->Show(); 333*ff12d537SAndre Fischer mpCurrentConfiguration->Activate(); 33422de8995SAndre Fischer } 33522de8995SAndre Fischer 33622de8995SAndre Fischer 33722de8995SAndre Fischer 33822de8995SAndre Fischer 33922de8995SAndre Fischer IMPL_LINK(SidebarController, WindowEventHandler, VclWindowEvent*, pEvent) 34022de8995SAndre Fischer { 34122de8995SAndre Fischer if (pEvent != NULL) 34222de8995SAndre Fischer { 34322de8995SAndre Fischer ::Window* pWindow = pEvent->GetWindow(); 34422de8995SAndre Fischer switch (pEvent->GetId()) 34522de8995SAndre Fischer { 34622de8995SAndre Fischer case VCLEVENT_WINDOW_GETFOCUS: 34722de8995SAndre Fischer case VCLEVENT_WINDOW_LOSEFOCUS: 34822de8995SAndre Fischer break; 34922de8995SAndre Fischer 35022de8995SAndre Fischer case VCLEVENT_WINDOW_SHOW: 35122de8995SAndre Fischer case VCLEVENT_WINDOW_RESIZE: 35222de8995SAndre Fischer NotifyResize(); 35322de8995SAndre Fischer break; 35422de8995SAndre Fischer 355*ff12d537SAndre Fischer case VCLEVENT_WINDOW_DATACHANGED: 356*ff12d537SAndre Fischer // Force an update of deck and tab bar to reflect 357*ff12d537SAndre Fischer // changes in theme (high contrast mode). 358*ff12d537SAndre Fischer Theme::HandleDataChange(); 359*ff12d537SAndre Fischer mpParentWindow->Invalidate(); 360*ff12d537SAndre Fischer break; 361*ff12d537SAndre Fischer 36222de8995SAndre Fischer case SFX_HINT_DYING: 36322de8995SAndre Fischer dispose(); 36422de8995SAndre Fischer break; 36522de8995SAndre Fischer 36622de8995SAndre Fischer default: 36722de8995SAndre Fischer break; 36822de8995SAndre Fischer } 36922de8995SAndre Fischer } 37022de8995SAndre Fischer 37122de8995SAndre Fischer return sal_True; 37222de8995SAndre Fischer } 37322de8995SAndre Fischer 37422de8995SAndre Fischer 37522de8995SAndre Fischer 37622de8995SAndre Fischer 377*ff12d537SAndre Fischer void SidebarController::ShowPopupMenu (const Rectangle& rButtonBox) const 37822de8995SAndre Fischer { 379*ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu = CreatePopupMenu(); 380*ff12d537SAndre Fischer pMenu->SetSelectHdl(LINK(this, SidebarController, OnMenuItemSelected)); 381*ff12d537SAndre Fischer 382*ff12d537SAndre Fischer // pass toolbox button rect so the menu can stay open on button up 383*ff12d537SAndre Fischer Rectangle aBox (rButtonBox); 384*ff12d537SAndre Fischer aBox.Move(mpTabBar->GetPosPixel().X(), 0); 385*ff12d537SAndre Fischer pMenu->Execute(mpParentWindow, aBox, POPUPMENU_EXECUTE_DOWN); 38622de8995SAndre Fischer } 38722de8995SAndre Fischer 38822de8995SAndre Fischer 38922de8995SAndre Fischer 39022de8995SAndre Fischer 391*ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> SidebarController::CreatePopupMenu (void) const 39222de8995SAndre Fischer { 393*ff12d537SAndre Fischer ::boost::shared_ptr<PopupMenu> pMenu (new PopupMenu()); 394*ff12d537SAndre Fischer FloatingWindow* pMenuWindow = dynamic_cast<FloatingWindow*>(pMenu->GetWindow()); 395*ff12d537SAndre Fischer if (pMenuWindow != NULL) 396*ff12d537SAndre Fischer { 397*ff12d537SAndre Fischer pMenuWindow->SetPopupModeFlags(pMenuWindow->GetPopupModeFlags() | FLOATWIN_POPUPMODE_NOMOUSEUPCLOSE); 398*ff12d537SAndre Fischer } 399*ff12d537SAndre Fischer 400*ff12d537SAndre Fischer SidebarResource aLocalResource; 401*ff12d537SAndre Fischer 402*ff12d537SAndre Fischer // Add one entry for every tool panel element to individually make 403*ff12d537SAndre Fischer // them visible or hide them. 404*ff12d537SAndre Fischer if (mpTabBar != NULL) 40522de8995SAndre Fischer { 406*ff12d537SAndre Fischer mpTabBar->AddPopupMenuEntries(*pMenu, MID_FIRST_PANEL); 407*ff12d537SAndre Fischer pMenu->InsertSeparator(); 40822de8995SAndre Fischer } 40922de8995SAndre Fischer 410*ff12d537SAndre Fischer // Add entry for docking or un-docking the tool panel. 411*ff12d537SAndre Fischer if (mpParentWindow->IsFloatingMode()) 412*ff12d537SAndre Fischer pMenu->InsertItem(MID_LOCK_TASK_PANEL, String(SfxResId(STR_SFX_DOCK))); 413*ff12d537SAndre Fischer else 414*ff12d537SAndre Fischer pMenu->InsertItem(MID_UNLOCK_TASK_PANEL, String(SfxResId(STR_SFX_UNDOCK))); 415*ff12d537SAndre Fischer 416*ff12d537SAndre Fischer // Add sub menu for customization (hiding of deck tabs.) 417*ff12d537SAndre Fischer PopupMenu* pCustomizationMenu = new PopupMenu(); 418*ff12d537SAndre Fischer mpTabBar->AddCustomizationMenuEntries(*pCustomizationMenu, MID_FIRST_HIDE); 419*ff12d537SAndre Fischer pCustomizationMenu->InsertSeparator(); 420*ff12d537SAndre Fischer pCustomizationMenu->InsertItem(MID_RESTORE_DEFAULT, String(SfxResId(STRING_RESTORE))); 421*ff12d537SAndre Fischer 422*ff12d537SAndre Fischer pMenu->InsertItem(MID_CUSTOMIZATION, String(SfxResId(STRING_CUSTOMIZATION))); 423*ff12d537SAndre Fischer pMenu->SetPopupMenu(MID_CUSTOMIZATION, pCustomizationMenu); 424*ff12d537SAndre Fischer 425*ff12d537SAndre Fischer pMenu->RemoveDisabledEntries(sal_False, sal_False); 426*ff12d537SAndre Fischer 427*ff12d537SAndre Fischer return pMenu; 42822de8995SAndre Fischer } 42922de8995SAndre Fischer 43022de8995SAndre Fischer 43122de8995SAndre Fischer 43222de8995SAndre Fischer 433*ff12d537SAndre Fischer IMPL_LINK(SidebarController, OnMenuItemSelected, Menu*, pMenu) 43422de8995SAndre Fischer { 435*ff12d537SAndre Fischer if (pMenu == NULL) 436*ff12d537SAndre Fischer { 437*ff12d537SAndre Fischer OSL_ENSURE(pMenu!=NULL, "TaskPaneController_Impl::OnMenuItemSelected: illegal menu!"); 438*ff12d537SAndre Fischer return 0; 439*ff12d537SAndre Fischer } 44022de8995SAndre Fischer 441*ff12d537SAndre Fischer pMenu->Deactivate(); 442*ff12d537SAndre Fischer const sal_Int32 nIndex (pMenu->GetCurItemId()); 443*ff12d537SAndre Fischer switch (nIndex) 44422de8995SAndre Fischer { 445*ff12d537SAndre Fischer case MID_UNLOCK_TASK_PANEL: 446*ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_True); 447*ff12d537SAndre Fischer break; 448*ff12d537SAndre Fischer 449*ff12d537SAndre Fischer case MID_LOCK_TASK_PANEL: 450*ff12d537SAndre Fischer mpParentWindow->SetFloatingMode(sal_False); 451*ff12d537SAndre Fischer break; 452*ff12d537SAndre Fischer 453*ff12d537SAndre Fischer case MID_RESTORE_DEFAULT: 454*ff12d537SAndre Fischer mpTabBar->RestoreHideFlags(); 455*ff12d537SAndre Fischer break; 456*ff12d537SAndre Fischer 457*ff12d537SAndre Fischer default: 458*ff12d537SAndre Fischer { 459*ff12d537SAndre Fischer try 460*ff12d537SAndre Fischer { 461*ff12d537SAndre Fischer if (nIndex >= MID_FIRST_PANEL && nIndex<MID_FIRST_HIDE) 462*ff12d537SAndre Fischer SwitchToDeck(mpTabBar->GetDeckDescriptorForIndex(nIndex - MID_FIRST_PANEL)); 463*ff12d537SAndre Fischer else if (nIndex >=MID_FIRST_HIDE) 464*ff12d537SAndre Fischer mpTabBar->ToggleHideFlag(nIndex-MID_FIRST_HIDE); 465*ff12d537SAndre Fischer } 466*ff12d537SAndre Fischer catch (RuntimeException&) 467*ff12d537SAndre Fischer { 468*ff12d537SAndre Fischer } 469*ff12d537SAndre Fischer } 470*ff12d537SAndre Fischer break; 47122de8995SAndre Fischer } 472*ff12d537SAndre Fischer 473*ff12d537SAndre Fischer return 1; 47422de8995SAndre Fischer } 47522de8995SAndre Fischer 47622de8995SAndre Fischer 477*ff12d537SAndre Fischer 478*ff12d537SAndre Fischer 479*ff12d537SAndre Fischer 480*ff12d537SAndre Fischer } } // end of namespace sfx2::sidebar 481