122de8995SAndre Fischer /************************************************************** 222de8995SAndre Fischer * 322de8995SAndre Fischer * Licensed to the Apache Software Foundation (ASF) under one 422de8995SAndre Fischer * or more contributor license agreements. See the NOTICE file 522de8995SAndre Fischer * distributed with this work for additional information 622de8995SAndre Fischer * regarding copyright ownership. The ASF licenses this file 722de8995SAndre Fischer * to you under the Apache License, Version 2.0 (the 822de8995SAndre Fischer * "License"); you may not use this file except in compliance 922de8995SAndre Fischer * with the License. You may obtain a copy of the License at 1022de8995SAndre Fischer * 1122de8995SAndre Fischer * http://www.apache.org/licenses/LICENSE-2.0 1222de8995SAndre Fischer * 1322de8995SAndre Fischer * Unless required by applicable law or agreed to in writing, 1422de8995SAndre Fischer * software distributed under the License is distributed on an 1522de8995SAndre Fischer * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 1622de8995SAndre Fischer * KIND, either express or implied. See the License for the 1722de8995SAndre Fischer * specific language governing permissions and limitations 1822de8995SAndre Fischer * under the License. 1922de8995SAndre Fischer * 2022de8995SAndre Fischer *************************************************************/ 2122de8995SAndre Fischer 2222de8995SAndre Fischer #include "precompiled_svx.hxx" 23b9e67834SAndre Fischer 24b9e67834SAndre Fischer #include "svx/sidebar/ContextChangeEventMultiplexer.hxx" 25b9e67834SAndre Fischer 2622de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventObject.hpp> 2722de8995SAndre Fischer #include <com/sun/star/ui/XContextChangeEventMultiplexer.hpp> 2822de8995SAndre Fischer #include <com/sun/star/ui/ContextChangeEventMultiplexer.hpp> 29b9e67834SAndre Fischer #include <com/sun/star/frame/XModuleManager.hpp> 3022de8995SAndre Fischer #include <comphelper/processfactory.hxx> 31b9e67834SAndre Fischer #include <comphelper/componentcontext.hxx> 32*f120fe41SAndre Fischer #include <sfx2/viewsh.hxx> 33b9e67834SAndre Fischer #include <tools/diagnose_ex.h> 3422de8995SAndre Fischer 3522de8995SAndre Fischer using namespace css; 3622de8995SAndre Fischer using namespace cssu; 3722de8995SAndre Fischer 3822de8995SAndre Fischer 3922de8995SAndre Fischer void ContextChangeEventMultiplexer::NotifyContextChange ( 4022de8995SAndre Fischer const cssu::Reference<css::frame::XController>& rxController, 41b9e67834SAndre Fischer const ::sfx2::sidebar::EnumContext::Context eContext) 42b9e67834SAndre Fischer { 4395a18594SAndre Fischer if (rxController.is() && rxController->getFrame().is()) 4422de8995SAndre Fischer { 4522de8995SAndre Fischer const css::ui::ContextChangeEventObject aEvent( 4622de8995SAndre Fischer rxController, 47b9e67834SAndre Fischer GetModuleName(rxController->getFrame()), 48b9e67834SAndre Fischer ::sfx2::sidebar::EnumContext::GetContextName(eContext)); 4922de8995SAndre Fischer 5022de8995SAndre Fischer cssu::Reference<css::ui::XContextChangeEventMultiplexer> xMultiplexer ( 5122de8995SAndre Fischer css::ui::ContextChangeEventMultiplexer::get( 5222de8995SAndre Fischer ::comphelper::getProcessComponentContext())); 5322de8995SAndre Fischer if (xMultiplexer.is()) 5422de8995SAndre Fischer xMultiplexer->broadcastContextChangeEvent(aEvent, rxController); 5522de8995SAndre Fischer } 56b9e67834SAndre Fischer } 57b9e67834SAndre Fischer 58b9e67834SAndre Fischer 59b9e67834SAndre Fischer 60b9e67834SAndre Fischer 61*f120fe41SAndre Fischer void ContextChangeEventMultiplexer::NotifyContextChange ( 62*f120fe41SAndre Fischer SfxViewShell* pViewShell, 63*f120fe41SAndre Fischer const ::sfx2::sidebar::EnumContext::Context eContext) 64*f120fe41SAndre Fischer { 65*f120fe41SAndre Fischer if (pViewShell != NULL) 66*f120fe41SAndre Fischer NotifyContextChange(pViewShell->GetController(), eContext); 67*f120fe41SAndre Fischer } 68*f120fe41SAndre Fischer 69*f120fe41SAndre Fischer 70*f120fe41SAndre Fischer 71*f120fe41SAndre Fischer 72b9e67834SAndre Fischer ::rtl::OUString ContextChangeEventMultiplexer::GetModuleName ( 73b9e67834SAndre Fischer const cssu::Reference<css::frame::XFrame>& rxFrame) 74b9e67834SAndre Fischer { 75b9e67834SAndre Fischer try 76b9e67834SAndre Fischer { 77b9e67834SAndre Fischer const ::comphelper::ComponentContext aContext (::comphelper::getProcessServiceFactory()); 78b9e67834SAndre Fischer const Reference<frame::XModuleManager> xModuleManager ( 79b9e67834SAndre Fischer aContext.createComponent("com.sun.star.frame.ModuleManager" ), 80b9e67834SAndre Fischer UNO_QUERY_THROW ); 81b9e67834SAndre Fischer return xModuleManager->identify(rxFrame); 82b9e67834SAndre Fischer } 83b9e67834SAndre Fischer catch (const Exception&) 84b9e67834SAndre Fischer { 8595a18594SAndre Fischer // An exception typically means that a context change is notified 8695a18594SAndre Fischer // during initialization or destruction of a view. 8795a18594SAndre Fischer // Ignore it. 88b9e67834SAndre Fischer } 89b9e67834SAndre Fischer return ::sfx2::sidebar::EnumContext::GetApplicationName( 90*f120fe41SAndre Fischer ::sfx2::sidebar::EnumContext::Application_None); 91b9e67834SAndre Fischer } 92