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 : #ifndef INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
21 : #define INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
22 :
23 : #include <sal/config.h>
24 :
25 : #include <vector>
26 :
27 : #include <com/sun/star/lang/XEventListener.hpp>
28 : #include <com/sun/star/lang/EventObject.hpp>
29 : #include <com/sun/star/lang/XComponent.hpp>
30 : #include <com/sun/star/awt/XControl.hpp>
31 : #include <osl/thread.hxx>
32 :
33 :
34 : #include <osl/conditn.hxx>
35 : #include <cppuhelper/component.hxx>
36 : #include <comphelper/uno3.hxx>
37 : using namespace comphelper;
38 :
39 :
40 : namespace frm
41 : {
42 :
43 :
44 : typedef ::osl::Thread OComponentEventThread_TBASE;
45 : class OComponentEventThread
46 : :public OComponentEventThread_TBASE
47 : ,public ::com::sun::star::lang::XEventListener
48 : ,public ::cppu::OWeakObject
49 : {
50 : typedef std::vector<css::lang::EventObject*> ThreadEvents;
51 : typedef std::vector< ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter> > ThreadObjects;
52 : typedef std::vector<sal_Bool> ThreadBools;
53 :
54 : ::osl::Mutex m_aMutex;
55 : ::osl::Condition m_aCond; // Queue filled?
56 : ThreadEvents m_aEvents; // EventQueue
57 : ThreadObjects m_aControls; // Control for Submit
58 : ThreadBools m_aFlags; // Flags for Submit/Reset
59 :
60 : ::cppu::OComponentHelper* m_pCompImpl; // Implementation of the Control
61 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent> m_xComp; // ::com::sun::star::lang::XComponent of the Control
62 :
63 : protected:
64 :
65 : // XThread
66 : virtual void SAL_CALL run() SAL_OVERRIDE;
67 :
68 : virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
69 :
70 : // The following method is called to duplicate the Event while respecting it's type.
71 : virtual ::com::sun::star::lang::EventObject* cloneEvent(const ::com::sun::star::lang::EventObject* _pEvt) const = 0;
72 :
73 : // Edit an Event:
74 : // The mutex is not locked, but pCompImpl stays valid in any case.
75 : // pEvt can be a derrived type, namely the one that cloneEvent returns.
76 : // rControl is only set, if a Control has been passed in addEvent.
77 : // Because the Control is only held as a WeakRef, it can disappear in the meantime.
78 : virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
79 : const ::com::sun::star::lang::EventObject* _pEvt,
80 : const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& _rControl,
81 : bool _bFlag) = 0;
82 :
83 : public:
84 :
85 : // UNO Anbindung
86 0 : DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject)
87 : virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
88 :
89 : OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
90 : virtual ~OComponentEventThread();
91 :
92 : void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, bool bFlag = false );
93 : void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& rControl,
94 : bool bFlag = false );
95 :
96 : // ::com::sun::star::lang::XEventListener
97 : virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
98 :
99 : // Resolve ambiguity: both OWeakObject and OObject have these memory operators
100 0 : void * SAL_CALL operator new( size_t size ) throw() { return osl::Thread::operator new(size); }
101 0 : void SAL_CALL operator delete( void * p ) throw() { osl::Thread::operator delete(p); }
102 :
103 : private:
104 : void implStarted( );
105 : void implTerminated( );
106 :
107 : void impl_clearEventQueue();
108 : };
109 :
110 :
111 : } // namespace frm
112 :
113 :
114 : #endif // INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
115 :
116 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|