Line data Source code
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 :
21 : #include "fltlst.hxx"
22 :
23 : #include <com/sun/star/uno/Sequence.hxx>
24 : #include <com/sun/star/uno/Any.hxx>
25 : #include <com/sun/star/document/FilterConfigRefresh.hpp>
26 : #include <comphelper/processfactory.hxx>
27 :
28 : #include <sfx2/sfxuno.hxx>
29 : #include <sfx2/docfac.hxx>
30 :
31 : #include <vcl/svapp.hxx>
32 : #include <osl/mutex.hxx>
33 :
34 : //*****************************************************************************************************************
35 : // namespaces
36 : //*****************************************************************************************************************
37 : using namespace ::com::sun::star;
38 :
39 :
40 : class SfxRefreshListener : public ::cppu::WeakImplHelper1<com::sun::star::util::XRefreshListener>
41 : {
42 : private:
43 : SfxFilterListener *m_pOwner;
44 :
45 : public:
46 65 : SfxRefreshListener(SfxFilterListener *pOwner)
47 65 : : m_pOwner(pOwner)
48 : {
49 65 : }
50 :
51 128 : virtual ~SfxRefreshListener()
52 64 : {
53 128 : }
54 :
55 : // util.XRefreshListener
56 0 : virtual void SAL_CALL refreshed( const ::com::sun::star::lang::EventObject& rEvent )
57 : throw(com::sun::star::uno::RuntimeException)
58 : {
59 0 : m_pOwner->refreshed(rEvent);
60 0 : }
61 :
62 : // lang.XEventListener
63 0 : virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& rEvent)
64 : throw(com::sun::star::uno::RuntimeException)
65 : {
66 0 : m_pOwner->disposing(rEvent);
67 0 : }
68 : };
69 :
70 : /*-************************************************************************************************************//**
71 : @short ctor
72 : @descr These initialize an instance of a SfxFilterListener class. Created object listen automaticly
73 : on right FilterFactory-Service for all changes and synchronize right SfxFilterContainer with
74 : corresponding framework-cache.
75 : We use given "sFactory" value to decide which query must be used to fill "pContainer" with new values.
76 : Given "pContainer" hold us alive as uno reference and we use it to syschronize it with framework caches.
77 : We will die, if he die! see dtor for further information.
78 :
79 : @seealso dtor
80 : @seealso class framework::FilterCache
81 : @seealso service ::document::FilterFactory
82 :
83 : @param "sFactory" , short name of module which contains filter container
84 : @param "pContainer", pointer to filter container which will be informed
85 : @return -
86 :
87 : @onerror We show some assertions in non product version.
88 : Otherwise we do nothing!
89 : @threadsafe yes
90 : *//*-*************************************************************************************************************/
91 65 : SfxFilterListener::SfxFilterListener()
92 : {
93 65 : m_xFilterCache = document::FilterConfigRefresh::create( comphelper::getProcessComponentContext() );
94 65 : m_xFilterCacheListener = new SfxRefreshListener(this);
95 65 : m_xFilterCache->addRefreshListener( m_xFilterCacheListener );
96 65 : }
97 :
98 65 : SfxFilterListener::~SfxFilterListener()
99 : {
100 65 : }
101 :
102 0 : void SAL_CALL SfxFilterListener::refreshed( const lang::EventObject& aSource ) throw( uno::RuntimeException )
103 : {
104 0 : SolarMutexGuard aGuard;
105 0 : uno::Reference< util::XRefreshable > xContainer( aSource.Source, uno::UNO_QUERY );
106 0 : if(
107 0 : (xContainer.is() ) &&
108 0 : (xContainer==m_xFilterCache)
109 : )
110 : {
111 0 : SfxFilterContainer::ReadFilters_Impl( sal_True );
112 0 : }
113 0 : }
114 :
115 0 : void SAL_CALL SfxFilterListener::disposing( const lang::EventObject& aSource ) throw( uno::RuntimeException )
116 : {
117 0 : SolarMutexGuard aGuard;
118 0 : uno::Reference< util::XRefreshable > xNotifier( aSource.Source, uno::UNO_QUERY );
119 0 : if (!xNotifier.is())
120 0 : return;
121 :
122 0 : if (xNotifier == m_xFilterCache)
123 0 : m_xFilterCache.clear();
124 408 : }
125 :
126 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|