LibreOffice Module forms (master) 1
EventThread.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <sal/config.h>
23
24#include <memory>
25#include <mutex>
26#include <vector>
27
28#include <com/sun/star/lang/XEventListener.hpp>
29#include <com/sun/star/lang/EventObject.hpp>
30#include <com/sun/star/awt/XControl.hpp>
31#include <osl/thread.hxx>
32#include <osl/conditn.hxx>
34#include <comphelper/uno3.hxx>
35#include <rtl/ref.hxx>
36
37
38using namespace comphelper;
39
40
41namespace frm
42{
43
44
45typedef ::osl::Thread OComponentEventThread_TBASE;
48 ,public css::lang::XEventListener
50{
51 typedef std::vector<std::unique_ptr<css::lang::EventObject>> ThreadEvents;
52 typedef std::vector< css::uno::Reference< css::uno::XAdapter> > ThreadObjects;
53
54 std::mutex m_aMutex;
55 ::osl::Condition m_aCond; // Queue filled?
56 ThreadEvents m_aEvents; // EventQueue
57 ThreadObjects m_aControls; // Control for Submit
58 std::vector<bool> m_aFlags; // Flags for Submit/Reset
59
60 rtl::Reference<::cppu::OComponentHelper> m_xComp; // Implementation of the Control
61
62protected:
63
64 // XThread
65 virtual void SAL_CALL run() override;
66
67 virtual void SAL_CALL onTerminated() override;
68
69 // Edit an Event:
70 // The mutex is not locked, but pCompImpl stays valid in any case.
71 // pEvt can be a derived type, namely the one that cloneEvent returns.
72 // rControl is only set, if a Control has been passed in addEvent.
73 // Because the Control is only held as a WeakRef, it can disappear in the meantime.
74 virtual void processEvent( ::cppu::OComponentHelper* _pCompImpl,
75 const css::lang::EventObject* _pEvt,
76 const css::uno::Reference< css::awt::XControl>& _rControl,
77 bool _bFlag) = 0;
78
79public:
80
81 // UNO binding
83 virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type& _rType) override;
84
86 virtual ~OComponentEventThread() override;
87
88 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt );
89 void addEvent( std::unique_ptr<css::lang::EventObject> _pEvt, const css::uno::Reference< css::awt::XControl>& rControl,
90 bool bFlag = false );
91
92 // css::lang::XEventListener
93 virtual void SAL_CALL disposing(const css::lang::EventObject& _rSource ) override;
94
95 // Resolve ambiguity: both OWeakObject and osl::Thread have these memory operators
96 using osl::Thread::operator new;
97 using osl::Thread::operator delete;
98
99private:
101};
102
103
104} // namespace frm
105
106/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void processEvent(::cppu::OComponentHelper *_pCompImpl, const css::lang::EventObject *_pEvt, const css::uno::Reference< css::awt::XControl > &_rControl, bool _bFlag)=0
void addEvent(std::unique_ptr< css::lang::EventObject > _pEvt)
std::vector< bool > m_aFlags
Definition: EventThread.hxx:58
std::vector< std::unique_ptr< css::lang::EventObject > > ThreadEvents
Definition: EventThread.hxx:51
virtual ~OComponentEventThread() override
Definition: EventThread.cxx:49
virtual void SAL_CALL run() override
rtl::Reference<::cppu::OComponentHelper > m_xComp
Definition: EventThread.hxx:60
virtual void SAL_CALL onTerminated() override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &_rType) override
Definition: EventThread.cxx:58
void addEvent(std::unique_ptr< css::lang::EventObject > _pEvt, const css::uno::Reference< css::awt::XControl > &rControl, bool bFlag=false)
std::vector< css::uno::Reference< css::uno::XAdapter > > ThreadObjects
Definition: EventThread.hxx:52
::osl::Condition m_aCond
Definition: EventThread.hxx:55
virtual void SAL_CALL disposing(const css::lang::EventObject &_rSource) override
Definition: EventThread.cxx:77
OComponentEventThread(::cppu::OComponentHelper *pCompImpl)
Definition: EventThread.cxx:34
ListBox is a bit confusing / different from other form components, so here are a few notes:
Definition: BaseListBox.hxx:25
::osl::Thread OComponentEventThread_TBASE
Definition: EventThread.hxx:45
#define DECLARE_UNO3_DEFAULTS(classname, baseclass)