1*5b190011SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*5b190011SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*5b190011SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*5b190011SAndrew Rist * distributed with this work for additional information 6*5b190011SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*5b190011SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*5b190011SAndrew Rist * "License"); you may not use this file except in compliance 9*5b190011SAndrew Rist * with the License. You may obtain a copy of the License at 10*5b190011SAndrew Rist * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*5b190011SAndrew Rist * 13*5b190011SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*5b190011SAndrew Rist * software distributed under the License is distributed on an 15*5b190011SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*5b190011SAndrew Rist * KIND, either express or implied. See the License for the 17*5b190011SAndrew Rist * specific language governing permissions and limitations 18*5b190011SAndrew Rist * under the License. 19*5b190011SAndrew Rist * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_sd.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "ViewTabBarModule.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 29cdf0e10cSrcweir #include "framework/ConfigurationController.hxx" 30cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp> 31cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XTabBar.hpp> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include "strings.hrc" 34cdf0e10cSrcweir #include "sdresid.hxx" 35cdf0e10cSrcweir 36cdf0e10cSrcweir 37cdf0e10cSrcweir using namespace ::com::sun::star; 38cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 40cdf0e10cSrcweir 41cdf0e10cSrcweir using ::rtl::OUString; 42cdf0e10cSrcweir using ::sd::framework::FrameworkHelper; 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace { 45cdf0e10cSrcweir 46cdf0e10cSrcweir static const sal_Int32 ResourceActivationRequestEvent = 0; 47cdf0e10cSrcweir static const sal_Int32 ResourceDeactivationRequestEvent = 1; 48cdf0e10cSrcweir static const sal_Int32 ResourceActivationEvent = 2; 49cdf0e10cSrcweir 50cdf0e10cSrcweir } 51cdf0e10cSrcweir 52cdf0e10cSrcweir namespace sd { namespace framework { 53cdf0e10cSrcweir 54cdf0e10cSrcweir //===== ViewTabBarModule ================================================== 55cdf0e10cSrcweir 56cdf0e10cSrcweir ViewTabBarModule::ViewTabBarModule ( 57cdf0e10cSrcweir const Reference<frame::XController>& rxController, 58cdf0e10cSrcweir const Reference<XResourceId>& rxViewTabBarId) 59cdf0e10cSrcweir : ViewTabBarModuleInterfaceBase(MutexOwner::maMutex), 60cdf0e10cSrcweir mxConfigurationController(), 61cdf0e10cSrcweir mxViewTabBarId(rxViewTabBarId) 62cdf0e10cSrcweir { 63cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 64cdf0e10cSrcweir 65cdf0e10cSrcweir if (xControllerManager.is()) 66cdf0e10cSrcweir { 67cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController(); 68cdf0e10cSrcweir if (mxConfigurationController.is()) 69cdf0e10cSrcweir { 70cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 71cdf0e10cSrcweir this, 72cdf0e10cSrcweir FrameworkHelper::msResourceActivationRequestEvent, 73cdf0e10cSrcweir makeAny(ResourceActivationRequestEvent)); 74cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 75cdf0e10cSrcweir this, 76cdf0e10cSrcweir FrameworkHelper::msResourceDeactivationRequestEvent, 77cdf0e10cSrcweir makeAny(ResourceDeactivationRequestEvent)); 78cdf0e10cSrcweir 79cdf0e10cSrcweir UpdateViewTabBar(NULL); 80cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 81cdf0e10cSrcweir this, 82cdf0e10cSrcweir FrameworkHelper::msResourceActivationEvent, 83cdf0e10cSrcweir makeAny(ResourceActivationEvent)); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir } 86cdf0e10cSrcweir } 87cdf0e10cSrcweir 88cdf0e10cSrcweir 89cdf0e10cSrcweir 90cdf0e10cSrcweir 91cdf0e10cSrcweir ViewTabBarModule::~ViewTabBarModule (void) 92cdf0e10cSrcweir { 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::disposing (void) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir if (mxConfigurationController.is()) 101cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 102cdf0e10cSrcweir 103cdf0e10cSrcweir mxConfigurationController = NULL; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::notifyConfigurationChange ( 110cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent) 111cdf0e10cSrcweir throw (RuntimeException) 112cdf0e10cSrcweir { 113cdf0e10cSrcweir if (mxConfigurationController.is()) 114cdf0e10cSrcweir { 115cdf0e10cSrcweir sal_Int32 nEventType = 0; 116cdf0e10cSrcweir rEvent.UserData >>= nEventType; 117cdf0e10cSrcweir switch (nEventType) 118cdf0e10cSrcweir { 119cdf0e10cSrcweir case ResourceActivationRequestEvent: 120cdf0e10cSrcweir if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT)) 121cdf0e10cSrcweir { 122cdf0e10cSrcweir mxConfigurationController->requestResourceActivation( 123cdf0e10cSrcweir mxViewTabBarId, 124cdf0e10cSrcweir ResourceActivationMode_ADD); 125cdf0e10cSrcweir } 126cdf0e10cSrcweir break; 127cdf0e10cSrcweir 128cdf0e10cSrcweir case ResourceDeactivationRequestEvent: 129cdf0e10cSrcweir if (mxViewTabBarId->isBoundTo(rEvent.ResourceId, AnchorBindingMode_DIRECT)) 130cdf0e10cSrcweir { 131cdf0e10cSrcweir mxConfigurationController->requestResourceDeactivation(mxViewTabBarId); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir break; 134cdf0e10cSrcweir 135cdf0e10cSrcweir case ResourceActivationEvent: 136cdf0e10cSrcweir if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY)); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir 145cdf0e10cSrcweir 146cdf0e10cSrcweir 147cdf0e10cSrcweir void SAL_CALL ViewTabBarModule::disposing ( 148cdf0e10cSrcweir const lang::EventObject& rEvent) 149cdf0e10cSrcweir throw (RuntimeException) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if (mxConfigurationController.is() 152cdf0e10cSrcweir && rEvent.Source == mxConfigurationController) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir // Without the configuration controller this class can do nothing. 155cdf0e10cSrcweir mxConfigurationController = NULL; 156cdf0e10cSrcweir disposing(); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir 161cdf0e10cSrcweir 162cdf0e10cSrcweir 163cdf0e10cSrcweir void ViewTabBarModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir if (mxConfigurationController.is()) 166cdf0e10cSrcweir { 167cdf0e10cSrcweir Reference<XTabBar> xBar (rxTabBar); 168cdf0e10cSrcweir if ( ! xBar.is()) 169cdf0e10cSrcweir xBar = Reference<XTabBar>( 170cdf0e10cSrcweir mxConfigurationController->getResource(mxViewTabBarId), UNO_QUERY); 171cdf0e10cSrcweir 172cdf0e10cSrcweir if (xBar.is()) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir TabBarButton aEmptyButton; 175cdf0e10cSrcweir 176cdf0e10cSrcweir Reference<XResourceId> xAnchor (mxViewTabBarId->getAnchor()); 177cdf0e10cSrcweir 178cdf0e10cSrcweir TabBarButton aImpressViewButton; 179cdf0e10cSrcweir aImpressViewButton.ResourceId = FrameworkHelper::CreateResourceId( 180cdf0e10cSrcweir FrameworkHelper::msImpressViewURL, 181cdf0e10cSrcweir xAnchor); 182cdf0e10cSrcweir aImpressViewButton.ButtonLabel = String(SdResId(STR_DRAW_MODE)); 183cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aImpressViewButton)) 184cdf0e10cSrcweir xBar->addTabBarButtonAfter(aImpressViewButton, aEmptyButton); 185cdf0e10cSrcweir 186cdf0e10cSrcweir TabBarButton aOutlineViewButton; 187cdf0e10cSrcweir aOutlineViewButton.ResourceId = FrameworkHelper::CreateResourceId( 188cdf0e10cSrcweir FrameworkHelper::msOutlineViewURL, 189cdf0e10cSrcweir xAnchor); 190cdf0e10cSrcweir aOutlineViewButton.ButtonLabel = String(SdResId(STR_OUTLINE_MODE)); 191cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aOutlineViewButton)) 192cdf0e10cSrcweir xBar->addTabBarButtonAfter(aOutlineViewButton, aImpressViewButton); 193cdf0e10cSrcweir 194cdf0e10cSrcweir TabBarButton aNotesViewButton; 195cdf0e10cSrcweir aNotesViewButton.ResourceId = FrameworkHelper::CreateResourceId( 196cdf0e10cSrcweir FrameworkHelper::msNotesViewURL, 197cdf0e10cSrcweir xAnchor); 198cdf0e10cSrcweir aNotesViewButton.ButtonLabel = String(SdResId(STR_NOTES_MODE)); 199cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aNotesViewButton)) 200cdf0e10cSrcweir xBar->addTabBarButtonAfter(aNotesViewButton, aOutlineViewButton); 201cdf0e10cSrcweir 202cdf0e10cSrcweir TabBarButton aHandoutViewButton; 203cdf0e10cSrcweir aHandoutViewButton.ResourceId = FrameworkHelper::CreateResourceId( 204cdf0e10cSrcweir FrameworkHelper::msHandoutViewURL, 205cdf0e10cSrcweir xAnchor); 206cdf0e10cSrcweir aHandoutViewButton.ButtonLabel = String(SdResId(STR_HANDOUT_MODE)); 207cdf0e10cSrcweir if ( ! xBar->hasTabBarButton(aHandoutViewButton)) 208cdf0e10cSrcweir xBar->addTabBarButtonAfter(aHandoutViewButton, aNotesViewButton); 209cdf0e10cSrcweir } 210cdf0e10cSrcweir } 211cdf0e10cSrcweir } 212cdf0e10cSrcweir 213cdf0e10cSrcweir 214cdf0e10cSrcweir 215cdf0e10cSrcweir 216cdf0e10cSrcweir } } // end of namespace sd::framework 217