bump product version to 5.0.4.1
[LibreOffice.git] / forms / source / component / EventThread.hxx
blobb152c7322ec54881d2f85e59ba2731b025dea2f1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
21 #define INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
23 #include <sal/config.h>
25 #include <vector>
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>
34 #include <osl/conditn.hxx>
35 #include <cppuhelper/component.hxx>
36 #include <comphelper/uno3.hxx>
37 using namespace comphelper;
40 namespace frm
44 typedef ::osl::Thread OComponentEventThread_TBASE;
45 class OComponentEventThread
46 :public OComponentEventThread_TBASE
47 ,public ::com::sun::star::lang::XEventListener
48 ,public ::cppu::OWeakObject
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;
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
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
63 protected:
65 // XThread
66 virtual void SAL_CALL run() SAL_OVERRIDE;
68 virtual void SAL_CALL onTerminated() SAL_OVERRIDE;
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;
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;
83 public:
85 // UNO Anbindung
86 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;
89 OComponentEventThread(::cppu::OComponentHelper* pCompImpl);
90 virtual ~OComponentEventThread();
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 );
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;
99 // Resolve ambiguity: both OWeakObject and OObject have these memory operators
100 void * SAL_CALL operator new( size_t size ) throw() { return osl::Thread::operator new(size); }
101 void SAL_CALL operator delete( void * p ) throw() { osl::Thread::operator delete(p); }
103 private:
104 void implStarted( );
105 void implTerminated( );
107 void impl_clearEventQueue();
111 } // namespace frm
114 #endif // INCLUDED_FORMS_SOURCE_COMPONENT_EVENTTHREAD_HXX
116 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */