15d39f272SZheng Fan /************************************************************** 25d39f272SZheng Fan * 35d39f272SZheng Fan * Licensed to the Apache Software Foundation (ASF) under one 45d39f272SZheng Fan * or more contributor license agreements. See the NOTICE file 55d39f272SZheng Fan * distributed with this work for additional information 65d39f272SZheng Fan * regarding copyright ownership. The ASF licenses this file 75d39f272SZheng Fan * to you under the Apache License, Version 2.0 (the 85d39f272SZheng Fan * "License"); you may not use this file except in compliance 95d39f272SZheng Fan * with the License. You may obtain a copy of the License at 105d39f272SZheng Fan * 115d39f272SZheng Fan * http://www.apache.org/licenses/LICENSE-2.0 125d39f272SZheng Fan * 135d39f272SZheng Fan * Unless required by applicable law or agreed to in writing, 145d39f272SZheng Fan * software distributed under the License is distributed on an 155d39f272SZheng Fan * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 165d39f272SZheng Fan * KIND, either express or implied. See the License for the 175d39f272SZheng Fan * specific language governing permissions and limitations 185d39f272SZheng Fan * under the License. 195d39f272SZheng Fan * 205d39f272SZheng Fan *************************************************************/ 215d39f272SZheng Fan 225d39f272SZheng Fan #include "svx/sidebar/SelectionChangeHandler.hxx" 235d39f272SZheng Fan #include "svx/sidebar/SelectionAnalyzer.hxx" 245d39f272SZheng Fan #include "svx/sidebar/ContextChangeEventMultiplexer.hxx" 255d39f272SZheng Fan #include "svx/svdmrkv.hxx" 265d39f272SZheng Fan 275d39f272SZheng Fan #include <sfx2/sidebar/EnumContext.hxx> 285d39f272SZheng Fan #include <sfx2/shell.hxx> 295d39f272SZheng Fan 305d39f272SZheng Fan 315d39f272SZheng Fan using namespace css; 325d39f272SZheng Fan using namespace cssu; 335d39f272SZheng Fan 345d39f272SZheng Fan using namespace sfx2::sidebar; 355d39f272SZheng Fan 365d39f272SZheng Fan namespace svx { namespace sidebar { 375d39f272SZheng Fan 385d39f272SZheng Fan SelectionChangeHandler::SelectionChangeHandler ( 39*2a3f8a0eSAndre Fischer const boost::function<rtl::OUString(void)>& rSelectionChangeCallback, 405d39f272SZheng Fan const Reference<frame::XController>& rxController, 415d39f272SZheng Fan const EnumContext::Context eDefaultContext) 425d39f272SZheng Fan : SelectionChangeHandlerInterfaceBase(m_aMutex), 435d39f272SZheng Fan maSelectionChangeCallback(rSelectionChangeCallback), 445d39f272SZheng Fan mxController(rxController), 455d39f272SZheng Fan meDefaultContext(eDefaultContext), 465d39f272SZheng Fan mbIsConnected(false) 475d39f272SZheng Fan { 485d39f272SZheng Fan } 495d39f272SZheng Fan 505d39f272SZheng Fan 515d39f272SZheng Fan 525d39f272SZheng Fan 535d39f272SZheng Fan SelectionChangeHandler::~SelectionChangeHandler (void) 545d39f272SZheng Fan { 555d39f272SZheng Fan } 565d39f272SZheng Fan 575d39f272SZheng Fan 585d39f272SZheng Fan 595d39f272SZheng Fan 605d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::selectionChanged (const lang::EventObject&) 615d39f272SZheng Fan throw (uno::RuntimeException) 625d39f272SZheng Fan { 635d39f272SZheng Fan if (maSelectionChangeCallback) 645d39f272SZheng Fan { 65*2a3f8a0eSAndre Fischer const EnumContext::Context eContext ( 66*2a3f8a0eSAndre Fischer EnumContext::GetContextEnum(maSelectionChangeCallback())); 675d39f272SZheng Fan ContextChangeEventMultiplexer::NotifyContextChange( 685d39f272SZheng Fan mxController, 695d39f272SZheng Fan eContext==EnumContext::Context_Unknown 705d39f272SZheng Fan ? meDefaultContext 715d39f272SZheng Fan : eContext); 725d39f272SZheng Fan } 735d39f272SZheng Fan } 745d39f272SZheng Fan 755d39f272SZheng Fan 765d39f272SZheng Fan 775d39f272SZheng Fan 785d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::disposing (const lang::EventObject&) 795d39f272SZheng Fan throw (uno::RuntimeException) 805d39f272SZheng Fan { 815d39f272SZheng Fan } 825d39f272SZheng Fan 835d39f272SZheng Fan 845d39f272SZheng Fan 855d39f272SZheng Fan 865d39f272SZheng Fan void SAL_CALL SelectionChangeHandler::disposing (void) 875d39f272SZheng Fan throw (uno::RuntimeException) 885d39f272SZheng Fan { 895d39f272SZheng Fan if (mbIsConnected) 905d39f272SZheng Fan Disconnect(); 915d39f272SZheng Fan } 925d39f272SZheng Fan 935d39f272SZheng Fan 945d39f272SZheng Fan 955d39f272SZheng Fan 965d39f272SZheng Fan void SelectionChangeHandler::Connect (void) 975d39f272SZheng Fan { 985d39f272SZheng Fan uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); 995d39f272SZheng Fan if (xSupplier.is()) 1005d39f272SZheng Fan { 1015d39f272SZheng Fan mbIsConnected = true; 1025d39f272SZheng Fan xSupplier->addSelectionChangeListener(this); 1035d39f272SZheng Fan } 1045d39f272SZheng Fan } 1055d39f272SZheng Fan 1065d39f272SZheng Fan 1075d39f272SZheng Fan 1085d39f272SZheng Fan 1095d39f272SZheng Fan void SelectionChangeHandler::Disconnect (void) 1105d39f272SZheng Fan { 1115d39f272SZheng Fan uno::Reference<view::XSelectionSupplier> xSupplier (mxController, uno::UNO_QUERY); 1125d39f272SZheng Fan if (xSupplier.is()) 1135d39f272SZheng Fan { 1145d39f272SZheng Fan mbIsConnected = false; 1155d39f272SZheng Fan xSupplier->removeSelectionChangeListener(this); 1165d39f272SZheng Fan } 1175d39f272SZheng Fan } 1185d39f272SZheng Fan 1195d39f272SZheng Fan 1205d39f272SZheng Fan } } // end of namespace svx::sidebar 121