LibreOffice Module forms (master) 1
featuredispatcher.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include "featuredispatcher.hxx"
21#include <osl/diagnose.h>
23
24#include <utility>
25
26
27namespace frm
28{
29
30
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::frame;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::util;
35
37 :m_aFeatureURL(std::move( _aURL ))
38 ,m_aStatusListeners( m_aMutex )
39 ,m_pEditView( &_rView )
40 ,m_bDisposed( false )
41 {
42 }
43
44
46 {
47 if ( !m_bDisposed )
48 {
49 acquire();
50 dispose();
51 }
52 }
53
54
56 {
57 EventObject aEvent( *this );
59
60 ::osl::ClearableMutexGuard aGuard( m_aMutex );
61 m_bDisposed = true;
62 disposing( aGuard );
63 }
64
65
66 void ORichTextFeatureDispatcher::disposing( ::osl::ClearableMutexGuard& /*_rClearBeforeNotify*/ )
67 {
68 m_pEditView = nullptr;
69 }
70
71
72 void SAL_CALL ORichTextFeatureDispatcher::addStatusListener( const Reference< XStatusListener >& _rxControl, const URL& _rURL )
73 {
74 OSL_ENSURE( !m_bDisposed, "ORichTextFeatureDispatcher::addStatusListener: already disposed!" );
75 if ( m_bDisposed )
76 throw DisposedException();
77
78 OSL_ENSURE( _rURL.Complete == getFeatureURL().Complete, "ORichTextFeatureDispatcher::addStatusListener: invalid URL!" );
79 if ( _rURL.Complete == getFeatureURL().Complete )
80 if ( _rxControl.is() )
81 {
82 m_aStatusListeners.addInterface( _rxControl );
83 doNotify( _rxControl, buildStatusEvent() );
84 }
85 }
86
87
88 void SAL_CALL ORichTextFeatureDispatcher::removeStatusListener( const Reference< XStatusListener >& _rxControl, const URL& /*_rURL*/ )
89 {
91 }
92
93
95 {
97 }
98
99
101 {
102 FeatureStateEvent aEvent;
103 aEvent.IsEnabled = false;
104 aEvent.Source = *const_cast< ORichTextFeatureDispatcher* >( this );
105 aEvent.FeatureURL = getFeatureURL();
106 aEvent.Requery = false;
107 return aEvent;
108 }
109
110
112 {
113 FeatureStateEvent aEvent( buildStatusEvent() );
115 while ( aIter.hasMoreElements() )
116 doNotify( aIter.next(), aEvent );
117 }
118
119
120 void ORichTextFeatureDispatcher::doNotify( const Reference< XStatusListener >& _rxListener, const FeatureStateEvent& _rEvent )
121 {
122 OSL_PRECOND( _rxListener.is(), "ORichTextFeatureDispatcher::doNotify: invalid listener!" );
123 if ( _rxListener.is() )
124 {
125 try
126 {
127 _rxListener->statusChanged( _rEvent );
128 }
129 catch( const Exception& )
130 {
131 TOOLS_WARN_EXCEPTION( "forms.richtext", "ORichTextFeatureDispatcher::doNotify" );
132 }
133 }
134 }
135
136
137} // namespace frm
138
139
140/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
css::uno::Reference< ListenerT > const & next()
mutable::osl::Mutex m_aMutex
const css::util::URL & getFeatureURL() const
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &_rxControl, const css::util::URL &_rURL) override
::comphelper::OInterfaceContainerHelper3< css::frame::XStatusListener > m_aStatusListeners
void dispose()
clean up resources associated with this instance
static void doNotify(const css::uno::Reference< css::frame::XStatusListener > &_rxListener, const css::frame::FeatureStateEvent &_rEvent)
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &_rxControl, const css::util::URL &_rURL) override
ORichTextFeatureDispatcher(EditView &_rView, css::util::URL _aURL)
virtual css::frame::FeatureStateEvent buildStatusEvent() const
::comphelper::OInterfaceContainerHelper3< css::frame::XStatusListener > & getStatusListeners()
virtual void disposing(::osl::ClearableMutexGuard &_rClearBeforeNotify)
virtual ~ORichTextFeatureDispatcher() override
#define TOOLS_WARN_EXCEPTION(area, stream)
bool m_bDisposed
std::mutex m_aMutex
@ Exception
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25