1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "precompiled_sd.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "ViewTabBarModule.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 33*cdf0e10cSrcweir #include "framework/ConfigurationController.hxx" 34*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XTabBar.hpp> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir #include "strings.hrc" 38*cdf0e10cSrcweir #include "sdresid.hxx" 39*cdf0e10cSrcweir 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::com::sun::star; 42*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 43*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir using ::rtl::OUString; 46*cdf0e10cSrcweir using ::sd::framework::FrameworkHelper; 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir static const sal_Int32 ResourceActivationRequestEvent = 0; 51*cdf0e10cSrcweir static const sal_Int32 ResourceDeactivationRequestEvent = 1; 52*cdf0e10cSrcweir static const sal_Int32 ResourceActivationEvent = 2; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace sd { namespace framework { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir //===== ViewTabBarModule ================================================== 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir ViewTabBarModule::ViewTabBarModule ( 61*cdf0e10cSrcweir const Reference<frame::XController>& rxController, 62*cdf0e10cSrcweir const Reference<XResourceId>& rxViewTabBarId) 63*cdf0e10cSrcweir : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex), 64*cdf0e10cSrcweir mxConfigurationController(), 65*cdf0e10cSrcweir mxViewTabBarId(rxViewTabBarId) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir if (xControllerManager.is()) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController(); 72*cdf0e10cSrcweir if (mxConfigurationController.is()) 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 75*cdf0e10cSrcweir this, 76*cdf0e10cSrcweir FrameworkHelper::msResourceActivationRequestEvent, 77*cdf0e10cSrcweir makeAny(ResourceActivationRequestEvent)); 78*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 79*cdf0e10cSrcweir this, 80*cdf0e10cSrcweir FrameworkHelper::msResourceDeactivationRequestEvent, 81*cdf0e10cSrcweir makeAny(ResourceDeactivationRequestEvent)); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir UpdateViewTabBar(NULL); 84*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 85*cdf0e10cSrcweir this, 86*cdf0e10cSrcweir FrameworkHelper::msResourceActivationEvent, 87*cdf0e10cSrcweir makeAny(ResourceActivationEvent)); 88*cdf0e10cSrcweir } 89*cdf0e10cSrcweir } 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir ViewTabBarModule::~ViewTabBarModule (void) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::disposing (void) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir if (mxConfigurationController.is()) 105*cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir mxConfigurationController = NULL; 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::notifyConfigurationChange ( 114*cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent) 115*cdf0e10cSrcweir throw (RuntimeException) 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir if (mxConfigurationController.is()) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir sal_Int32 nEventType = 0; 120*cdf0e10cSrcweir rEvent.UserData >>= nEventType; 121*cdf0e10cSrcweir switch (nEventType) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir case ResourceActivationRequestEvent: 124*cdf0e10cSrcweir if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT)) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir mxConfigurationController->requestResourceActivation( 127*cdf0e10cSrcweir mxViewTabBarId, 128*cdf0e10cSrcweir ResourceActivationMode_ADD); 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir break; 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir case ResourceDeactivationRequestEvent: 133*cdf0e10cSrcweir if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT)) 134*cdf0e10cSrcweir { 135*cdf0e10cSrcweir mxConfigurationController->requestResourceDeactivation(mxViewTabBarId); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir break; 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir case ResourceActivationEvent: 140*cdf0e10cSrcweir if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY)); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir 151*cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::disposing ( 152*cdf0e10cSrcweir const lang::EventObject& rEvent) 153*cdf0e10cSrcweir throw (RuntimeException) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir if (mxConfigurationController.is() 156*cdf0e10cSrcweir && rEvent.Source == mxConfigurationController) 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir // Without the configuration controller this class can do nothing. 159*cdf0e10cSrcweir mxConfigurationController = NULL; 160*cdf0e10cSrcweir disposing(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar) 168*cdf0e10cSrcweir { 169*cdf0e10cSrcweir if (mxConfigurationController.is()) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir Reference<XTabBar> xBar (rxTabBar); 172*cdf0e10cSrcweir if ( ! xBar.is()) 173*cdf0e10cSrcweir xBar = Reference<XTabBar>( 174*cdf0e10cSrcweir mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY); 175*cdf0e10cSrcweir 176*cdf0e10cSrcweir if (xBar.is()) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir TabBarButton aEmptyButton; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor()); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir TabBarButton aImpressViewButton; 183*cdf0e10cSrcweir aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId( 184*cdf0e10cSrcweir FrameworkHelper::msImpressViewURL, 185*cdf0e10cSrcweir xAnchor); 186*cdf0e10cSrcweir aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE)); 187*cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aImpressViewButton)) 188*cdf0e10cSrcweir xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton); 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir TabBarButton aOutlineViewButton; 191*cdf0e10cSrcweir aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId( 192*cdf0e10cSrcweir FrameworkHelper::msOutlineViewURL, 193*cdf0e10cSrcweir xAnchor); 194*cdf0e10cSrcweir aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE)); 195*cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aOutlineViewButton)) 196*cdf0e10cSrcweir xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton); 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir TabBarButton aNotesViewButton; 199*cdf0e10cSrcweir aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId( 200*cdf0e10cSrcweir FrameworkHelper::msNotesViewURL, 201*cdf0e10cSrcweir xAnchor); 202*cdf0e10cSrcweir aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE)); 203*cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aNotesViewButton)) 204*cdf0e10cSrcweir xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir TabBarButton aHandoutViewButton; 207*cdf0e10cSrcweir aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId( 208*cdf0e10cSrcweir FrameworkHelper::msHandoutViewURL, 209*cdf0e10cSrcweir xAnchor); 210*cdf0e10cSrcweir aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE)); 211*cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aHandoutViewButton)) 212*cdf0e10cSrcweir xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir } } // end of namespace sd::framework 221