Qt 4.8
qwineventnotifier_p.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qwineventnotifier_p.h"
43 
44 #include "qeventdispatcher_win_p.h"
45 #include "qcoreapplication.h"
46 
47 #include <private/qthread_p.h>
48 
50 
51 /*
52  \class QWinEventNotifier
53  \brief The QWinEventNotifier class provides support for the Windows Wait functions.
54 
55  The QWinEventNotifier class makes it possible to use the wait
56  functions on windows in a asynchronous manner. With this class
57  you can register a HANDLE to an event and get notification when
58  that event becomes signalled. The state of the event is not modified
59  in the process so if it is a manual reset event you will need to
60  reset it after the notification.
61 */
62 
63 
65  : QObject(parent), handleToEvent(0), enabled(false)
66 {}
67 
69  : QObject(parent), handleToEvent(hEvent), enabled(false)
70 {
71  Q_D(QObject);
72  QEventDispatcherWin32 *eventDispatcher = qobject_cast<QEventDispatcherWin32 *>(d->threadData->eventDispatcher);
73  Q_ASSERT_X(eventDispatcher, "QWinEventNotifier::QWinEventNotifier()",
74  "Cannot create a win event notifier without a QEventDispatcherWin32");
75  eventDispatcher->registerEventNotifier(this);
76  enabled = true;
77 }
78 
80 {
81  setEnabled(false);
82 }
83 
85 {
86  setEnabled(false);
87  handleToEvent = hEvent;
88 }
89 
91 {
92  return handleToEvent;
93 }
94 
96 {
97  return enabled;
98 }
99 
101 {
102  if (enabled == enable) // no change
103  return;
104  enabled = enable;
105 
106  Q_D(QObject);
107  QEventDispatcherWin32 *eventDispatcher = qobject_cast<QEventDispatcherWin32 *>(d->threadData->eventDispatcher);
108  if (!eventDispatcher) // perhaps application is shutting down
109  return;
110 
111  if (enabled)
112  eventDispatcher->registerEventNotifier(this);
113  else
114  eventDispatcher->unregisterEventNotifier(this);
115 }
116 
118 {
119  if (e->type() == QEvent::ThreadChange) {
120  if (enabled) {
122  Q_ARG(bool, enabled));
123  setEnabled(false);
124  }
125  }
126  QObject::event(e); // will activate filters
127  if (e->type() == QEvent::WinEventAct) {
129  return true;
130  }
131  return false;
132 }
133 
double d
Definition: qnumeric_p.h:62
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
bool event(QEvent *e)
This virtual function receives events to an object and should return true if the event e was recogniz...
#define Q_ARG(type, data)
Definition: qobjectdefs.h:246
T * qobject_cast(QObject *object)
Definition: qobject.h:375
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
virtual bool event(QEvent *)
This virtual function receives events to an object and should return true if the event e was recogniz...
Definition: qobject.cpp:1200
void activated(HANDLE hEvent)
#define Q_D(Class)
Definition: qglobal.h:2482
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
#define emit
Definition: qobjectdefs.h:76
void * HANDLE
Definition: qnamespace.h:1671
void setHandle(HANDLE hEvent)
#define Q_ASSERT_X(cond, where, what)
Definition: qglobal.h:1837
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
QWinEventNotifier(QObject *parent=0)
static bool invokeMethod(QObject *obj, const char *member, Qt::ConnectionType, QGenericReturnArgument ret, QGenericArgument val0=QGenericArgument(0), QGenericArgument val1=QGenericArgument(), QGenericArgument val2=QGenericArgument(), QGenericArgument val3=QGenericArgument(), QGenericArgument val4=QGenericArgument(), QGenericArgument val5=QGenericArgument(), QGenericArgument val6=QGenericArgument(), QGenericArgument val7=QGenericArgument(), QGenericArgument val8=QGenericArgument(), QGenericArgument val9=QGenericArgument())
Invokes the member (a signal or a slot name) on the object obj.
void unregisterEventNotifier(QWinEventNotifier *notifier)
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
void setEnabled(bool enable)
bool registerEventNotifier(QWinEventNotifier *notifier)
#define enabled