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 10cdf0e10cSrcweir * 11*5b190011SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 20*5b190011SAndrew Rist *************************************************************/ 21*5b190011SAndrew Rist 22*5b190011SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_sd.hxx" 25cdf0e10cSrcweir 26cdf0e10cSrcweir #include "CenterViewFocusModule.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "framework/ConfigurationController.hxx" 29cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 30cdf0e10cSrcweir #include "framework/ViewShellWrapper.hxx" 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include "DrawController.hxx" 33cdf0e10cSrcweir #include "ViewShellBase.hxx" 34cdf0e10cSrcweir #include "ViewShellManager.hxx" 35cdf0e10cSrcweir #include "strings.hrc" 36cdf0e10cSrcweir #include "sdresid.hxx" 37cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp> 38cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <toolkit/awt/vclxdevice.hxx> 41cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir using namespace ::com::sun::star; 44cdf0e10cSrcweir using namespace ::com::sun::star::uno; 45cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 46cdf0e10cSrcweir 47cdf0e10cSrcweir using ::rtl::OUString; 48cdf0e10cSrcweir using ::sd::framework::FrameworkHelper; 49cdf0e10cSrcweir 50cdf0e10cSrcweir 51cdf0e10cSrcweir namespace sd { namespace framework { 52cdf0e10cSrcweir 53cdf0e10cSrcweir //===== CenterViewFocusModule ==================================================== 54cdf0e10cSrcweir 55cdf0e10cSrcweir CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController) 56cdf0e10cSrcweir : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex), 57cdf0e10cSrcweir mbValid(false), 58cdf0e10cSrcweir mxConfigurationController(), 59cdf0e10cSrcweir mpBase(NULL), 60cdf0e10cSrcweir mbNewViewCreated(false) 61cdf0e10cSrcweir { 62cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 63cdf0e10cSrcweir if (xControllerManager.is()) 64cdf0e10cSrcweir { 65cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController(); 66cdf0e10cSrcweir 67cdf0e10cSrcweir // Tunnel through the controller to obtain a ViewShellBase. 68cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY); 69cdf0e10cSrcweir if (xTunnel.is()) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 72cdf0e10cSrcweir xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 73cdf0e10cSrcweir if (pController != NULL) 74cdf0e10cSrcweir mpBase = pController->GetViewShellBase(); 75cdf0e10cSrcweir } 76cdf0e10cSrcweir 77cdf0e10cSrcweir // Check, if all required objects do exist. 78cdf0e10cSrcweir if (mxConfigurationController.is() && mpBase!=NULL) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir mbValid = true; 81cdf0e10cSrcweir } 82cdf0e10cSrcweir } 83cdf0e10cSrcweir 84cdf0e10cSrcweir if (mbValid) 85cdf0e10cSrcweir { 86cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 87cdf0e10cSrcweir this, 88cdf0e10cSrcweir FrameworkHelper::msConfigurationUpdateEndEvent, 89cdf0e10cSrcweir Any()); 90cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 91cdf0e10cSrcweir this, 92cdf0e10cSrcweir FrameworkHelper::msResourceActivationEvent, 93cdf0e10cSrcweir Any()); 94cdf0e10cSrcweir } 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir 98cdf0e10cSrcweir 99cdf0e10cSrcweir 100cdf0e10cSrcweir CenterViewFocusModule::~CenterViewFocusModule (void) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir } 103cdf0e10cSrcweir 104cdf0e10cSrcweir 105cdf0e10cSrcweir 106cdf0e10cSrcweir 107cdf0e10cSrcweir void SAL_CALL CenterViewFocusModule::disposing (void) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir if (mxConfigurationController.is()) 110cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 111cdf0e10cSrcweir 112cdf0e10cSrcweir mbValid = false; 113cdf0e10cSrcweir mxConfigurationController = NULL; 114cdf0e10cSrcweir mpBase = NULL; 115cdf0e10cSrcweir } 116cdf0e10cSrcweir 117cdf0e10cSrcweir 118cdf0e10cSrcweir 119cdf0e10cSrcweir 120cdf0e10cSrcweir void SAL_CALL CenterViewFocusModule::notifyConfigurationChange ( 121cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent) 122cdf0e10cSrcweir throw (RuntimeException) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir if (mbValid) 125cdf0e10cSrcweir { 126cdf0e10cSrcweir if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent)) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir HandleNewView(rEvent.Configuration); 129cdf0e10cSrcweir } 130cdf0e10cSrcweir else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent)) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix)) 133cdf0e10cSrcweir mbNewViewCreated = true; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir } 136cdf0e10cSrcweir } 137cdf0e10cSrcweir 138cdf0e10cSrcweir 139cdf0e10cSrcweir 140cdf0e10cSrcweir 141cdf0e10cSrcweir void CenterViewFocusModule::HandleNewView ( 142cdf0e10cSrcweir const Reference<XConfiguration>& rxConfiguration) 143cdf0e10cSrcweir { 144cdf0e10cSrcweir if (mbNewViewCreated) 145cdf0e10cSrcweir { 146cdf0e10cSrcweir mbNewViewCreated = false; 147cdf0e10cSrcweir // Make the center pane the active one. Tunnel through the 148cdf0e10cSrcweir // controller to obtain a ViewShell pointer. 149cdf0e10cSrcweir 150cdf0e10cSrcweir Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources( 151cdf0e10cSrcweir FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL), 152cdf0e10cSrcweir FrameworkHelper::msViewURLPrefix, 153cdf0e10cSrcweir AnchorBindingMode_DIRECT)); 154cdf0e10cSrcweir Reference<XView> xView; 155cdf0e10cSrcweir if (xViewIds.getLength() > 0) 156cdf0e10cSrcweir xView = Reference<XView>( 157cdf0e10cSrcweir mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY); 158cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY); 159cdf0e10cSrcweir if (xTunnel.is() && mpBase!=NULL) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>( 162cdf0e10cSrcweir xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId())); 163cdf0e10cSrcweir if (pViewShellWrapper != NULL) 164cdf0e10cSrcweir { 165cdf0e10cSrcweir ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell(); 166cdf0e10cSrcweir if (pViewShell.get() != NULL) 167cdf0e10cSrcweir mpBase->GetViewShellManager()->MoveToTop(*pViewShell); 168cdf0e10cSrcweir } 169cdf0e10cSrcweir } 170cdf0e10cSrcweir } 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir 174cdf0e10cSrcweir 175cdf0e10cSrcweir 176cdf0e10cSrcweir void SAL_CALL CenterViewFocusModule::disposing ( 177cdf0e10cSrcweir const lang::EventObject& rEvent) 178cdf0e10cSrcweir throw (RuntimeException) 179cdf0e10cSrcweir { 180cdf0e10cSrcweir if (mxConfigurationController.is()) 181cdf0e10cSrcweir if (rEvent.Source == mxConfigurationController) 182cdf0e10cSrcweir { 183cdf0e10cSrcweir mbValid = false; 184cdf0e10cSrcweir mxConfigurationController = NULL; 185cdf0e10cSrcweir mpBase = NULL; 186cdf0e10cSrcweir } 187cdf0e10cSrcweir } 188cdf0e10cSrcweir 189cdf0e10cSrcweir 190cdf0e10cSrcweir 191cdf0e10cSrcweir } } // end of namespace sd::framework 192