xref: /trunk/main/forms/source/component/EventThread.hxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _FRM_EVENT_THREAD_HXX_
29 #define _FRM_EVENT_THREAD_HXX_
30 
31 #include <com/sun/star/lang/XEventListener.hpp>
32 #include <com/sun/star/lang/EventObject.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/awt/XControl.hpp>
35 #include <vos/thread.hxx>
36 
37 
38 #include <osl/conditn.hxx>
39 #include <cppuhelper/component.hxx>
40 #include <comphelper/stl_types.hxx>
41 #include <comphelper/uno3.hxx>
42 using namespace comphelper;
43 
44 //.........................................................................
45 namespace frm
46 {
47 //.........................................................................
48 
49 // ***************************************************************************************************
50 // ***************************************************************************************************
51 
52 typedef ::vos::OThread  OComponentEventThread_TBASE;
53 class OComponentEventThread
54             :public OComponentEventThread_TBASE
55             ,public ::com::sun::star::lang::XEventListener
56             ,public ::cppu::OWeakObject
57 {
58     DECLARE_STL_VECTOR(::com::sun::star::lang::EventObject*, ThreadEvents);
59     DECLARE_STL_VECTOR(::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter> , ThreadObjects);
60     DECLARE_STL_VECTOR(sal_Bool,    ThreadBools);
61 
62     ::osl::Mutex                    m_aMutex;
63     ::osl::Condition                m_aCond;            // Queue gefuellt?
64     ThreadEvents                    m_aEvents;          // Event-Queue
65     ThreadObjects                   m_aControls;        // Control fuer Submit
66     ThreadBools                     m_aFlags;           // Flags fuer Submit/Reset
67 
68     ::cppu::OComponentHelper*                   m_pCompImpl;    // Implementierung des Controls
69     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>   m_xComp;        // ::com::sun::star::lang::XComponent des Controls
70 
71 protected:
72 
73     // XThread
74     virtual void SAL_CALL run();
75 
76     virtual void SAL_CALL kill();
77     virtual void SAL_CALL onTerminated();
78 
79     // Die folgende Methode wird gerufen um das Event unter Beruecksichtigung
80     // seines Typs zu duplizieren.
81     virtual ::com::sun::star::lang::EventObject* cloneEvent(const ::com::sun::star::lang::EventObject* _pEvt) const = 0;
82 
83     // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl
84     // bleibt aber in jedem Fall gueltig. Bei pEvt kann es sich auch um
85     // einen abgeleiteten Typ handeln, naemlich den, den cloneEvent
86     // zurueckgibt. rControl ist nur gesetzt, wenn beim addEvent ein
87     // Control uebergeben wurde. Da das Control nur als WeakRef gehalten
88     // wird kann es auch zwischenzeitlich verschwinden.
89     virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
90                                const ::com::sun::star::lang::EventObject* _pEvt,
91                                const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& _rControl,
92                                sal_Bool _bFlag) = 0;
93 
94 public:
95 
96     // UNO Anbindung
97     DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject);
98     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
99 
100     OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
101     virtual ~OComponentEventThread();
102 
103     void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, sal_Bool bFlag = sal_False );
104     void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& rControl,
105                    sal_Bool bFlag = sal_False );
106 
107     // ::com::sun::star::lang::XEventListener
108     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
109 
110 /* resolve ambiguity : both OWeakObject and OObject have these memory operators */
111     void * SAL_CALL operator new( size_t size ) throw() { return OThread::operator new(size); }
112     void SAL_CALL operator delete( void * p ) throw() { OThread::operator delete(p); }
113 
114 private:
115     void    implStarted( );
116     void    implTerminated( );
117 
118     void    impl_clearEventQueue();
119 };
120 
121 //.........................................................................
122 }   // namespace frm
123 //.........................................................................
124 
125 #endif // _FRM_EVENT_THREAD_HXX_
126 
127