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 #include "svx/sidebar/SelectionChangeHandler.hxx" 23 #include "svx/sidebar/SelectionAnalyzer.hxx" 24 #include "svx/sidebar/ContextChangeEventMultiplexer.hxx" 25 #include "svx/svdmrkv.hxx" 26 27 #include <sfx2/sidebar/EnumContext.hxx> 28 #include <sfx2/shell.hxx> 29 30 31 using namespace css; 32 using namespace cssu; 33 34 using namespace sfx2::sidebar; 35 36 namespace svx { namespace sidebar { 37 38 SelectionChangeHandler::SelectionChangeHandler ( 39 const boost::function<rtl::OUString(void)>& rSelectionChangeCallback, 40 const Reference<frame::XController>& rxController, 41 const EnumContext::Context eDefaultContext) 42 : SelectionChangeHandlerInterfaceBase(m_aMutex), 43 maSelectionChangeCallback(rSelectionChangeCallback), 44 mxController(rxController), 45 meDefaultContext(eDefaultContext), 46 mbIsConnected(false) 47 { 48 } 49 50 51 52 53 SelectionChangeHandler::~SelectionChangeHandler (void) 54 { 55 } 56 57 58 59 60 void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&) 61 throw (uno::RuntimeException) 62 { 63 if (maSelectionChangeCallback) 64 { 65 const EnumContext::Context eContext ( 66 EnumContext::GetContextEnum(maSelectionChangeCallback())); 67 ContextChangeEventMultiplexer::NotifyContextChange( 68 mxController, 69 eContext==EnumContext::Context_Unknown 70 ? meDefaultContext 71 : eContext); 72 } 73 } 74 75 76 77 78 void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&) 79 throw (uno::RuntimeException) 80 { 81 } 82 83 84 85 86 void SAL_CALL SelectionChangeHandler::disposing (void) 87 throw (uno::RuntimeException) 88 { 89 if (mbIsConnected) 90 Disconnect(); 91 } 92 93 94 95 96 void SelectionChangeHandler::Connect (void) 97 { 98 uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); 99 if (xSupplier.is()) 100 { 101 mbIsConnected = true; 102 xSupplier->addSelectionChangeListener(this); 103 } 104 } 105 106 107 108 109 void SelectionChangeHandler::Disconnect (void) 110 { 111 uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); 112 if (xSupplier.is()) 113 { 114 mbIsConnected = false; 115 xSupplier->removeSelectionChangeListener(this); 116 } 117 } 118 119 120 } } // end of namespace svx::sidebar 121