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 "ToolBarModule.hxx" 27 #include "ViewShellBase.hxx" 28 #include "DrawController.hxx" 29 #include "framework/FrameworkHelper.hxx" 30 #include "framework/ConfigurationController.hxx" 31 32 33 using namespace ::com::sun::star; 34 using namespace ::com::sun::star::uno; 35 using namespace ::com::sun::star::drawing::framework; 36 37 using ::rtl::OUString; 38 using ::sd::framework::FrameworkHelper; 39 40 namespace { 41 static const sal_Int32 gnConfigurationUpdateStartEvent(0); 42 static const sal_Int32 gnConfigurationUpdateEndEvent(1); 43 static const sal_Int32 gnResourceActivationRequestEvent(2); 44 static const sal_Int32 gnResourceDeactivationRequestEvent(3); 45 } 46 47 namespace sd { namespace framework { 48 49 //===== ToolBarModule ========================================================= 50 51 ToolBarModule::ToolBarModule ( 52 const Reference<frame::XController>& rxController) 53 : ToolBarModuleInterfaceBase(m_aMutex), 54 mxConfigurationController(), 55 mpBase(NULL), 56 mpToolBarManagerLock(), 57 mbMainViewSwitchUpdatePending(false) 58 { 59 // Tunnel through the controller to obtain a ViewShellBase. 60 Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY); 61 if (xTunnel.is()) 62 { 63 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 64 xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 65 if (pController != NULL) 66 mpBase = pController->GetViewShellBase(); 67 } 68 69 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 70 if (xControllerManager.is()) 71 { 72 mxConfigurationController = xControllerManager->getConfigurationController(); 73 if (mxConfigurationController.is()) 74 { 75 mxConfigurationController->addConfigurationChangeListener( 76 this, 77 FrameworkHelper::msConfigurationUpdateStartEvent, 78 makeAny(gnConfigurationUpdateStartEvent)); 79 mxConfigurationController->addConfigurationChangeListener( 80 this, 81 FrameworkHelper::msConfigurationUpdateEndEvent, 82 makeAny(gnConfigurationUpdateEndEvent)); 83 mxConfigurationController->addConfigurationChangeListener( 84 this, 85 FrameworkHelper::msResourceActivationRequestEvent, 86 makeAny(gnResourceActivationRequestEvent)); 87 mxConfigurationController->addConfigurationChangeListener( 88 this, 89 FrameworkHelper::msResourceDeactivationRequestEvent, 90 makeAny(gnResourceDeactivationRequestEvent)); 91 } 92 } 93 } 94 95 96 97 98 ToolBarModule::~ToolBarModule (void) 99 { 100 } 101 102 103 104 105 void SAL_CALL ToolBarModule::disposing (void) 106 { 107 if (mxConfigurationController.is()) 108 mxConfigurationController->removeConfigurationChangeListener(this); 109 110 mxConfigurationController = NULL; 111 } 112 113 114 115 116 void SAL_CALL ToolBarModule::notifyConfigurationChange ( 117 const ConfigurationChangeEvent& rEvent) 118 { 119 if (mxConfigurationController.is()) 120 { 121 sal_Int32 nEventType = 0; 122 rEvent.UserData >>= nEventType; 123 switch (nEventType) 124 { 125 case gnConfigurationUpdateStartEvent: 126 HandleUpdateStart(); 127 break; 128 129 case gnConfigurationUpdateEndEvent: 130 HandleUpdateEnd(); 131 break; 132 133 case gnResourceActivationRequestEvent: 134 case gnResourceDeactivationRequestEvent: 135 // Remember the request for the activation or deactivation 136 // of the center pane view. When that happens then on end 137 // of the next configuration update the set of visible tool 138 // bars will be updated. 139 if ( ! mbMainViewSwitchUpdatePending) 140 if (rEvent.ResourceId->getResourceURL().match( 141 FrameworkHelper::msViewURLPrefix) 142 && rEvent.ResourceId->isBoundToURL( 143 FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT)) 144 { 145 mbMainViewSwitchUpdatePending = true; 146 } 147 break; 148 } 149 } 150 } 151 152 153 154 155 //----------------------------------------------------------------------------- 156 157 158 void ToolBarModule::HandleUpdateStart (void) 159 { 160 // Lock the ToolBarManager and tell it to lock the ViewShellManager as 161 // well. This way the ToolBarManager can optimize the releasing of 162 // locks and arranging of updates of both tool bars and the view shell 163 // stack. 164 if (mpBase != NULL) 165 { 166 ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager()); 167 mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager)); 168 pToolBarManager->LockViewShellManager(); 169 } 170 } 171 172 173 174 175 void ToolBarModule::HandleUpdateEnd (void) 176 { 177 if (mbMainViewSwitchUpdatePending) 178 { 179 mbMainViewSwitchUpdatePending = false; 180 // Update the set of visible tool bars and deactivate those that are 181 // no longer visible. This is done before the old view shell is 182 // destroyed in order to avoid unnecessary updates of those tool 183 // bars. 184 ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager()); 185 ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper ( 186 FrameworkHelper::Instance(*mpBase)); 187 ViewShell* pViewShell 188 = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get(); 189 if (pViewShell != NULL) 190 { 191 pToolBarManager->MainViewShellChanged(*pViewShell); 192 pToolBarManager->SelectionHasChanged( 193 *pViewShell, 194 *pViewShell->GetView()); 195 pToolBarManager->PreUpdate(); 196 } 197 else 198 { 199 pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE); 200 pToolBarManager->PreUpdate(); 201 } 202 } 203 204 // Releasing the update lock of the ToolBarManager will let the 205 // ToolBarManager with the help of the ViewShellManager take care of 206 // updating tool bars and view shell with the minimal amount of 207 // shell stack modifications and tool bar updates. 208 mpToolBarManagerLock.reset(); 209 } 210 211 212 213 214 void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent) 215 { 216 if (mxConfigurationController.is() 217 && rEvent.Source == mxConfigurationController) 218 { 219 // Without the configuration controller this class can do nothing. 220 mxConfigurationController = NULL; 221 dispose(); 222 } 223 } 224 225 226 227 228 } } // end of namespace sd::framework 229