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