-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e974cd5
commit cc601da
Showing
7 changed files
with
169 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
//****************************************************************************** | ||
// Copyright (c) 2005-2022 by Matteo Salvi | ||
// | ||
// See the included file COPYING.TXT for details about the copyright. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
//****************************************************************************** | ||
|
||
#ifndef Q_NATIVEEVENTFILTER_HOOK_H | ||
#define Q_NATIVEEVENTFILTER_HOOK_H | ||
|
||
#include <qcoreapplication.h> | ||
#include <qabstractnativeeventfilter.h> | ||
#include "pascalbind.h" | ||
|
||
class Q_NativeEventFilter_hook : public QAbstractNativeEventFilter { | ||
|
||
public: | ||
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) override; | ||
|
||
Q_NativeEventFilter_hook(QCoreApplication *handle) : QAbstractNativeEventFilter() { | ||
this->handle = handle; | ||
this->events.func = NULL; | ||
this->destroyed_event.func = NULL; | ||
} | ||
|
||
virtual ~Q_NativeEventFilter_hook() { | ||
if (handle) { | ||
handle->removeNativeEventFilter(this); | ||
handle = NULL; | ||
} | ||
} | ||
|
||
void hook_installfilter(QHook &hook) { | ||
if (handle) { | ||
if (!events.func) { | ||
handle->installNativeEventFilter(this); | ||
events = hook; | ||
} | ||
if (!hook.func) | ||
handle->removeNativeEventFilter(this); | ||
events = hook; | ||
} | ||
} | ||
void hook_removefilter() { | ||
if (handle) { | ||
handle->removeNativeEventFilter(this); | ||
events.func = NULL; | ||
} | ||
} | ||
|
||
void hook_destroyed(QHook &hook) { | ||
destroyed_event = hook; | ||
} | ||
|
||
protected: | ||
|
||
QCoreApplication *handle; | ||
|
||
private slots: | ||
|
||
void destroyed_hook() { | ||
if ( destroyed_event.func ) { | ||
typedef void (*func_type)(void *data); | ||
(*(func_type)destroyed_event.func)(destroyed_event.data); | ||
} | ||
handle = NULL; | ||
} | ||
|
||
private: | ||
QHook events; | ||
QHook destroyed_event; | ||
}; | ||
|
||
|
||
bool Q_NativeEventFilter_hook::nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result) { | ||
if (events.func) { | ||
Q_NativeEventFilter_hook* sender = this; | ||
typedef bool (*func_type)(void *data, Q_NativeEventFilter_hook* sender, const QByteArray &eventType, void *message); | ||
return (*(func_type)events.func)(events.data, sender, eventType, message); | ||
} | ||
return false; | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//****************************************************************************** | ||
// Copyright (c) 2005-2022 by Matteo Salvi | ||
// | ||
// See the included file COPYING.TXT for details about the copyright. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
//****************************************************************************** | ||
|
||
#include "qnativeeventfilter_hook_c.h" | ||
|
||
Q_NativeEventFilter_hookH Q_NativeEventFilter_hook_Create(QCoreApplicationH handle) | ||
{ | ||
return (Q_NativeEventFilter_hookH) new Q_NativeEventFilter_hook((QCoreApplication*)handle); | ||
} | ||
|
||
void Q_NativeEventFilter_hook_Destroy(Q_NativeEventFilter_hookH handle) | ||
{ | ||
delete (Q_NativeEventFilter_hook *)handle; | ||
} | ||
|
||
void Q_NativeEventFilter_hook_installfilter(Q_NativeEventFilter_hookH handle, QHookH hook) | ||
{ | ||
((Q_NativeEventFilter_hook *)handle)->hook_installfilter(hook); | ||
} | ||
|
||
void Q_NativeEventFilter_hook_destroyed(Q_NativeEventFilter_hookH handle, QHookH hook) | ||
{ | ||
((Q_NativeEventFilter_hook *)handle)->hook_destroyed(hook); | ||
} | ||
|
||
void Q_NativeEventFilter_hook_removefilter(Q_NativeEventFilter_hookH handle) | ||
{ | ||
((Q_NativeEventFilter_hook *)handle)->hook_removefilter(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//****************************************************************************** | ||
// Copyright (c) 2005-2022 by Matteo Salvi | ||
// | ||
// See the included file COPYING.TXT for details about the copyright. | ||
// | ||
// This program is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
//****************************************************************************** | ||
|
||
#ifndef Q_NATIVEEVENTFILTER_HOOK_C_H | ||
#define Q_NATIVEEVENTFILTER_HOOK_C_H | ||
|
||
#include "qnativeeventfilter_hook.h" | ||
#include "pascalbind.h" | ||
|
||
C_EXPORT Q_NativeEventFilter_hookH Q_NativeEventFilter_hook_Create(QCoreApplicationH handle); | ||
C_EXPORT void Q_NativeEventFilter_hook_Destroy(Q_NativeEventFilter_hookH handle); | ||
C_EXPORT void Q_NativeEventFilter_hook_installfilter(Q_NativeEventFilter_hookH handle, QHookH hook); | ||
C_EXPORT void Q_NativeEventFilter_hook_destroyed(Q_NativeEventFilter_hookH handle, QHookH hook); | ||
C_EXPORT void Q_NativeEventFilter_hook_removefilter(Q_NativeEventFilter_hookH handle); | ||
|
||
#endif |