xref: /AOO41X/main/forms/source/component/EventThread.hxx (revision 2d785d7ea953737df3731803a26e291d82066c5a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _FRM_EVENT_THREAD_HXX_
25 #define _FRM_EVENT_THREAD_HXX_
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 <vos/thread.hxx>
32 
33 
34 #include <osl/conditn.hxx>
35 #include <cppuhelper/component.hxx>
36 #include <comphelper/stl_types.hxx>
37 #include <comphelper/uno3.hxx>
38 using namespace comphelper;
39 
40 //.........................................................................
41 namespace frm
42 {
43 //.........................................................................
44 
45 // ***************************************************************************************************
46 // ***************************************************************************************************
47 
48 typedef ::vos::OThread  OComponentEventThread_TBASE;
49 class OComponentEventThread
50             :public OComponentEventThread_TBASE
51             ,public ::com::sun::star::lang::XEventListener
52             ,public ::cppu::OWeakObject
53 {
54     DECLARE_STL_VECTOR(::com::sun::star::lang::EventObject*, ThreadEvents);
55     DECLARE_STL_VECTOR(::com::sun::star::uno::Reference< ::com::sun::star::uno::XAdapter> , ThreadObjects);
56     DECLARE_STL_VECTOR(sal_Bool,    ThreadBools);
57 
58     ::osl::Mutex                    m_aMutex;
59     ::osl::Condition                m_aCond;            // Queue gefuellt?
60     ThreadEvents                    m_aEvents;          // Event-Queue
61     ThreadObjects                   m_aControls;        // Control fuer Submit
62     ThreadBools                     m_aFlags;           // Flags fuer Submit/Reset
63 
64     ::cppu::OComponentHelper*                   m_pCompImpl;    // Implementierung des Controls
65     ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent>   m_xComp;        // ::com::sun::star::lang::XComponent des Controls
66 
67 protected:
68 
69     // XThread
70     virtual void SAL_CALL run();
71 
72     virtual void SAL_CALL kill();
73     virtual void SAL_CALL onTerminated();
74 
75     // Die folgende Methode wird gerufen um das Event unter Beruecksichtigung
76     // seines Typs zu duplizieren.
77     virtual ::com::sun::star::lang::EventObject* cloneEvent(const ::com::sun::star::lang::EventObject* _pEvt) const = 0;
78 
79     // Ein Event bearbeiten. Der Mutex ist dabei nicht gelockt, pCompImpl
80     // bleibt aber in jedem Fall gueltig. Bei pEvt kann es sich auch um
81     // einen abgeleiteten Typ handeln, naemlich den, den cloneEvent
82     // zurueckgibt. rControl ist nur gesetzt, wenn beim addEvent ein
83     // Control uebergeben wurde. Da das Control nur als WeakRef gehalten
84     // wird kann es auch zwischenzeitlich verschwinden.
85     virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
86                                const ::com::sun::star::lang::EventObject* _pEvt,
87                                const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& _rControl,
88                                sal_Bool _bFlag) = 0;
89 
90 public:
91 
92     // UNO Anbindung
93     DECLARE_UNO3_DEFAULTS(OComponentEventThread, OWeakObject);
94     virtual ::com::sun::star::uno::Any SAL_CALL queryInterface(const ::com::sun::star::uno::Type& _rType) throw (::com::sun::star::uno::RuntimeException);
95 
96     OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
97     virtual ~OComponentEventThread();
98 
99     void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, sal_Bool bFlag = sal_False );
100     void addEvent( const ::com::sun::star::lang::EventObject* _pEvt, const ::com::sun::star::uno::Reference< ::com::sun::star::awt::XControl>& rControl,
101                    sal_Bool bFlag = sal_False );
102 
103     // ::com::sun::star::lang::XEventListener
104     virtual void SAL_CALL disposing(const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
105 
106 /* resolve ambiguity : both OWeakObject and OObject have these memory operators */
operator new(size_t size)107     void * SAL_CALL operator new( size_t size ) throw() { return OThread::operator new(size); }
operator delete(void * p)108     void SAL_CALL operator delete( void * p ) throw() { OThread::operator delete(p); }
109 
110 private:
111     void    implStarted( );
112     void    implTerminated( );
113 
114     void    impl_clearEventQueue();
115 };
116 
117 //.........................................................................
118 }   // namespace frm
119 //.........................................................................
120 
121 #endif // _FRM_EVENT_THREAD_HXX_
122 
123