1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 */ 9 10 #pragma once 11 12 #include <svtools/toolboxcontroller.hxx> 13 #include <com/sun/star/frame/XDispatchProvider.hpp> 14 15 namespace framework { 16 17 /** 18 * A dispatcher that serves as a proxy for style commands with arguments 19 * i.e. .uno:StyleApply?... in order to provide useful status updates to 20 * generic UI elements such as toolbars or menubar. It listens to special 21 * status commands, and computes a boolean status out of them. Then it 22 * forwards that boolean status to the listener, as if it was the status 23 * of the original command. 24 * 25 * Note that the implementation is minimal: Although the UI element appears 26 * to be the owner of the dispatcher, it's still responsible, as usual, to 27 * call removeStatusListener same amount of times as addStatusListener, 28 * otherwise the dispatcher might not be destructed. In addition this 29 * implementation might hold a hard reference on the owner, and it's the 30 * responsibility of the owner to destroy the dispatcher first, in order 31 * to break the cycle. 32 */ 33 class StyleDispatcher final : public cppu::WeakImplHelper< css::frame::XDispatch, css::frame::XStatusListener > 34 { 35 public: 36 StyleDispatcher( const css::uno::Reference< css::frame::XFrame >& rFrame, 37 const css::uno::Reference< css::util::XURLTransformer >& rUrlTransformer, 38 const css::util::URL& rURL ); 39 40 // XDispatch 41 void SAL_CALL dispatch( const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& rArguments ) override; 42 void SAL_CALL addStatusListener( const css::uno::Reference< css::frame::XStatusListener >& rListener, const css::util::URL& rURL ) override; 43 void SAL_CALL removeStatusListener( const css::uno::Reference< css::frame::XStatusListener >& rListener, const css::util::URL& rURL ) override; 44 45 // XStatusListener 46 void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; 47 48 // XEventListener 49 void SAL_CALL disposing( const css::lang::EventObject& rSource ) override; 50 51 private: 52 OUString m_aStyleName, m_aCommand, m_aStatusCommand; 53 css::uno::Reference< css::util::XURLTransformer > m_xUrlTransformer; 54 css::uno::Reference< css::frame::XDispatchProvider > m_xFrame; 55 css::uno::Reference< css::frame::XDispatch > m_xStatusDispatch; 56 css::uno::Reference< css::frame::XStatusListener > m_xOwner; 57 }; 58 59 class StyleToolbarController final : public svt::ToolboxController 60 { 61 public: 62 StyleToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rContext, 63 const css::uno::Reference< css::frame::XFrame >& rFrame, 64 const OUString& rCommand ); 65 66 // XUpdatable 67 void SAL_CALL update() override; 68 69 // XStatusListener 70 void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) override; 71 72 // XComponent 73 void SAL_CALL dispose() override; 74 }; 75 76 } 77 78 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ 79