1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_sd.hxx" 29 30 #include "CenterViewFocusModule.hxx" 31 32 #include "framework/ConfigurationController.hxx" 33 #include "framework/FrameworkHelper.hxx" 34 #include "framework/ViewShellWrapper.hxx" 35 36 #include "DrawController.hxx" 37 #include "ViewShellBase.hxx" 38 #include "ViewShellManager.hxx" 39 #include "strings.hrc" 40 #include "sdresid.hxx" 41 #include <com/sun/star/drawing/framework/XControllerManager.hpp> 42 #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 43 44 #include <toolkit/awt/vclxdevice.hxx> 45 #include <sfx2/viewfrm.hxx> 46 47 using namespace ::com::sun::star; 48 using namespace ::com::sun::star::uno; 49 using namespace ::com::sun::star::drawing::framework; 50 51 using ::rtl::OUString; 52 using ::sd::framework::FrameworkHelper; 53 54 55 namespace sd { namespace framework { 56 57 //===== CenterViewFocusModule ==================================================== 58 59 CenterViewFocusModule::CenterViewFocusModule (Reference<frame::XController>& rxController) 60 : CenterViewFocusModuleInterfaceBase(MutexOwner::maMutex), 61 mbValid(false), 62 mxConfigurationController(), 63 mpBase(NULL), 64 mbNewViewCreated(false) 65 { 66 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 67 if (xControllerManager.is()) 68 { 69 mxConfigurationController = xControllerManager->getConfigurationController(); 70 71 // Tunnel through the controller to obtain a ViewShellBase. 72 Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY); 73 if (xTunnel.is()) 74 { 75 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 76 xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 77 if (pController != NULL) 78 mpBase = pController->GetViewShellBase(); 79 } 80 81 // Check, if all required objects do exist. 82 if (mxConfigurationController.is() && mpBase!=NULL) 83 { 84 mbValid = true; 85 } 86 } 87 88 if (mbValid) 89 { 90 mxConfigurationController->addConfigurationChangeListener( 91 this, 92 FrameworkHelper::msConfigurationUpdateEndEvent, 93 Any()); 94 mxConfigurationController->addConfigurationChangeListener( 95 this, 96 FrameworkHelper::msResourceActivationEvent, 97 Any()); 98 } 99 } 100 101 102 103 104 CenterViewFocusModule::~CenterViewFocusModule (void) 105 { 106 } 107 108 109 110 111 void SAL_CALL CenterViewFocusModule::disposing (void) 112 { 113 if (mxConfigurationController.is()) 114 mxConfigurationController->removeConfigurationChangeListener(this); 115 116 mbValid = false; 117 mxConfigurationController = NULL; 118 mpBase = NULL; 119 } 120 121 122 123 124 void SAL_CALL CenterViewFocusModule::notifyConfigurationChange ( 125 const ConfigurationChangeEvent& rEvent) 126 throw (RuntimeException) 127 { 128 if (mbValid) 129 { 130 if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateEndEvent)) 131 { 132 HandleNewView(rEvent.Configuration); 133 } 134 else if (rEvent.Type.equals(FrameworkHelper::msResourceActivationEvent)) 135 { 136 if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix)) 137 mbNewViewCreated = true; 138 } 139 } 140 } 141 142 143 144 145 void CenterViewFocusModule::HandleNewView ( 146 const Reference<XConfiguration>& rxConfiguration) 147 { 148 if (mbNewViewCreated) 149 { 150 mbNewViewCreated = false; 151 // Make the center pane the active one. Tunnel through the 152 // controller to obtain a ViewShell pointer. 153 154 Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources( 155 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL), 156 FrameworkHelper::msViewURLPrefix, 157 AnchorBindingMode_DIRECT)); 158 Reference<XView> xView; 159 if (xViewIds.getLength() > 0) 160 xView = Reference<XView>( 161 mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY); 162 Reference<lang::XUnoTunnel> xTunnel (xView, UNO_QUERY); 163 if (xTunnel.is() && mpBase!=NULL) 164 { 165 ViewShellWrapper* pViewShellWrapper = reinterpret_cast<ViewShellWrapper*>( 166 xTunnel->getSomething(ViewShellWrapper::getUnoTunnelId())); 167 if (pViewShellWrapper != NULL) 168 { 169 ::boost::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell(); 170 if (pViewShell.get() != NULL) 171 mpBase->GetViewShellManager()->MoveToTop(*pViewShell); 172 } 173 } 174 } 175 } 176 177 178 179 180 void SAL_CALL CenterViewFocusModule::disposing ( 181 const lang::EventObject& rEvent) 182 throw (RuntimeException) 183 { 184 if (mxConfigurationController.is()) 185 if (rEvent.Source == mxConfigurationController) 186 { 187 mbValid = false; 188 mxConfigurationController = NULL; 189 mpBase = NULL; 190 } 191 } 192 193 194 195 } } // end of namespace sd::framework 196