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