1 //******************************************************************************
2 //  Copyright (c) 2005-2013 by Jan Van hijfte
3 //
4 //  See the included file COPYING.TXT for details about the copyright.
5 //
6 //  This program is distributed in the hope that it will be useful,
7 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
8 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 //******************************************************************************
10 
11 
12 #ifndef QGUIAPPLICATION_HOOK_H
13 #define QGUIAPPLICATION_HOOK_H
14 
15 #include <qguiapplication.h>
16 
17 #include "qcoreapplication_hook.h"
18 
19 class QGuiApplication_hook : public QCoreApplication_hook {
20   Q_OBJECT
21   public:
QGuiApplication_hook(QObject * handle)22     QGuiApplication_hook(QObject *handle) : QCoreApplication_hook(handle) {
23       fontDatabaseChanged_event.func = NULL;
24       screenAdded_event.func = NULL;
25       lastWindowClosed_event.func = NULL;
26       focusObjectChanged_event.func = NULL;
27       focusWindowChanged_event.func = NULL;
28       commitDataRequest_event.func = NULL;
29       saveStateRequest_event.func = NULL;
30     }
hook_fontDatabaseChanged(QHook & hook)31     void hook_fontDatabaseChanged(QHook &hook) {
32       if ( !fontDatabaseChanged_event.func )
33         connect(handle, SIGNAL(fontDatabaseChanged()), this, SLOT(fontDatabaseChanged_hook()));
34       fontDatabaseChanged_event = hook;
35       if ( !hook.func )
36         disconnect(handle, SIGNAL(fontDatabaseChanged()), this, SLOT(fontDatabaseChanged_hook()));
37     }
hook_screenAdded(QHook & hook)38     void hook_screenAdded(QHook &hook) {
39       if ( !screenAdded_event.func )
40         connect(handle, SIGNAL(screenAdded(QScreen*)), this, SLOT(screenAdded_hook(QScreen*)));
41       screenAdded_event = hook;
42       if ( !hook.func )
43         disconnect(handle, SIGNAL(screenAdded(QScreen*)), this, SLOT(screenAdded_hook(QScreen*)));
44     }
hook_lastWindowClosed(QHook & hook)45     void hook_lastWindowClosed(QHook &hook) {
46       if ( !lastWindowClosed_event.func )
47         connect(handle, SIGNAL(lastWindowClosed()), this, SLOT(lastWindowClosed_hook()));
48       lastWindowClosed_event = hook;
49       if ( !hook.func )
50         disconnect(handle, SIGNAL(lastWindowClosed()), this, SLOT(lastWindowClosed_hook()));
51     }
hook_focusObjectChanged(QHook & hook)52     void hook_focusObjectChanged(QHook &hook) {
53       if ( !focusObjectChanged_event.func )
54         connect(handle, SIGNAL(focusObjectChanged(QObject*)), this, SLOT(focusObjectChanged_hook(QObject*)));
55       focusObjectChanged_event = hook;
56       if ( !hook.func )
57         disconnect(handle, SIGNAL(focusObjectChanged(QObject*)), this, SLOT(focusObjectChanged_hook(QObject*)));
58     }
hook_focusWindowChanged(QHook & hook)59     void hook_focusWindowChanged(QHook &hook) {
60       if ( !focusWindowChanged_event.func )
61         connect(handle, SIGNAL(focusWindowChanged(QWindow*)), this, SLOT(focusWindowChanged_hook(QWindow*)));
62       focusWindowChanged_event = hook;
63       if ( !hook.func )
64         disconnect(handle, SIGNAL(focusWindowChanged(QWindow*)), this, SLOT(focusWindowChanged_hook(QWindow*)));
65     }
hook_commitDataRequest(QHook & hook)66     void hook_commitDataRequest(QHook &hook) {
67       if ( !commitDataRequest_event.func )
68         connect(handle, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(commitDataRequest_hook(QSessionManager&)));
69       commitDataRequest_event = hook;
70       if ( !hook.func )
71         disconnect(handle, SIGNAL(commitDataRequest(QSessionManager&)), this, SLOT(commitDataRequest_hook(QSessionManager&)));
72     }
hook_saveStateRequest(QHook & hook)73     void hook_saveStateRequest(QHook &hook) {
74       if ( !saveStateRequest_event.func )
75         connect(handle, SIGNAL(saveStateRequest(QSessionManager&)), this, SLOT(saveStateRequest_hook(QSessionManager&)));
76       saveStateRequest_event = hook;
77       if ( !hook.func )
78         disconnect(handle, SIGNAL(saveStateRequest(QSessionManager&)), this, SLOT(saveStateRequest_hook(QSessionManager&)));
79     }
80 
81   private slots:
fontDatabaseChanged_hook()82     void fontDatabaseChanged_hook() {
83       if ( fontDatabaseChanged_event.func ) {
84         typedef void (*func_type)(void *data);
85 	(*(func_type)fontDatabaseChanged_event.func)(fontDatabaseChanged_event.data);
86       }
87     }
screenAdded_hook(QScreen * screen)88     void screenAdded_hook(QScreen* screen) {
89       if ( screenAdded_event.func ) {
90         typedef void (*func_type)(void *data, QScreenH screen);
91 	(*(func_type)screenAdded_event.func)(screenAdded_event.data, (QScreenH)screen);
92       }
93     }
lastWindowClosed_hook()94     void lastWindowClosed_hook() {
95       if ( lastWindowClosed_event.func ) {
96         typedef void (*func_type)(void *data);
97 	(*(func_type)lastWindowClosed_event.func)(lastWindowClosed_event.data);
98       }
99     }
focusObjectChanged_hook(QObject * focusObject)100     void focusObjectChanged_hook(QObject* focusObject) {
101       if ( focusObjectChanged_event.func ) {
102         typedef void (*func_type)(void *data, QObjectH focusObject);
103 	(*(func_type)focusObjectChanged_event.func)(focusObjectChanged_event.data, (QObjectH)focusObject);
104       }
105     }
focusWindowChanged_hook(QWindow * focusWindow)106     void focusWindowChanged_hook(QWindow* focusWindow) {
107       if ( focusWindowChanged_event.func ) {
108         typedef void (*func_type)(void *data, QWindowH focusWindow);
109 	(*(func_type)focusWindowChanged_event.func)(focusWindowChanged_event.data, (QWindowH)focusWindow);
110       }
111     }
commitDataRequest_hook(QSessionManager & sessionManager)112     void commitDataRequest_hook(QSessionManager& sessionManager) {
113       if ( commitDataRequest_event.func ) {
114         typedef void (*func_type)(void *data, QSessionManagerH sessionManager);
115 	(*(func_type)commitDataRequest_event.func)(commitDataRequest_event.data, (QSessionManagerH)&sessionManager);
116       }
117     }
saveStateRequest_hook(QSessionManager & sessionManager)118     void saveStateRequest_hook(QSessionManager& sessionManager) {
119       if ( saveStateRequest_event.func ) {
120         typedef void (*func_type)(void *data, QSessionManagerH sessionManager);
121 	(*(func_type)saveStateRequest_event.func)(saveStateRequest_event.data, (QSessionManagerH)&sessionManager);
122       }
123     }
124   private:
125     QHook fontDatabaseChanged_event;
126     QHook screenAdded_event;
127     QHook lastWindowClosed_event;
128     QHook focusObjectChanged_event;
129     QHook focusWindowChanged_event;
130     QHook commitDataRequest_event;
131     QHook saveStateRequest_event;
132 };
133 
134 
135 #endif
136