1 | /* This file is part of the KDE project |
2 | Copyright (C) 1999 Simon Hausmann <hausmann@kde.org> |
3 | (C) 1999 David Faure <faure@kde.org> |
4 | |
5 | This library is free software; you can redistribute it and/or |
6 | modify it under the terms of the GNU Library General Public |
7 | License as published by the Free Software Foundation; either |
8 | version 2 of the License, or (at your option) any later version. |
9 | |
10 | This library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Library General Public License for more details. |
14 | |
15 | You should have received a copy of the GNU Library General Public License |
16 | along with this library; see the file COPYING.LIB. If not, write to |
17 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
18 | Boston, MA 02110-1301, USA. |
19 | */ |
20 | #include <kparts/event.h> |
21 | |
22 | using namespace KParts; |
23 | |
24 | //the answer! |
25 | #define KPARTS_EVENT_MAGIC 42 |
26 | |
27 | class KParts::EventPrivate |
28 | { |
29 | public: |
30 | EventPrivate( const char *eventName ) : |
31 | m_eventName(eventName) |
32 | { |
33 | } |
34 | const char* m_eventName; |
35 | }; |
36 | |
37 | Event::Event( const char *eventName ) |
38 | : QEvent( (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC) ) |
39 | , d( new EventPrivate(eventName) ) |
40 | { |
41 | } |
42 | |
43 | Event::~Event() |
44 | { |
45 | delete d; |
46 | } |
47 | |
48 | const char *Event::eventName() const |
49 | { |
50 | return d->m_eventName; |
51 | } |
52 | |
53 | bool Event::test( const QEvent *event ) |
54 | { |
55 | if ( !event ) |
56 | return false; |
57 | |
58 | return ( event->type() == (QEvent::Type)(QEvent::User + KPARTS_EVENT_MAGIC ) ); |
59 | } |
60 | |
61 | bool Event::test( const QEvent *event, const char *name ) |
62 | { |
63 | if ( !test( event ) ) |
64 | return false; |
65 | |
66 | return ( strcmp( name, ((Event*)event)->eventName() ) == 0 ); |
67 | } |
68 | |
69 | |
70 | /////// GUIActivateEvent //////// |
71 | |
72 | class KParts::GUIActivateEventPrivate |
73 | { |
74 | public: |
75 | GUIActivateEventPrivate( bool activated ) |
76 | : m_bActivated( activated ) |
77 | { |
78 | } |
79 | static const char *s_strGUIActivateEvent; |
80 | bool m_bActivated; |
81 | }; |
82 | |
83 | const char *GUIActivateEventPrivate::s_strGUIActivateEvent = "KParts/GUIActivate" ; |
84 | |
85 | GUIActivateEvent::GUIActivateEvent( bool activated ) : |
86 | Event( GUIActivateEventPrivate::s_strGUIActivateEvent ), |
87 | d( new GUIActivateEventPrivate(activated) ) |
88 | { |
89 | } |
90 | |
91 | GUIActivateEvent::~GUIActivateEvent() |
92 | { |
93 | delete d; |
94 | } |
95 | |
96 | bool GUIActivateEvent::activated() const |
97 | { |
98 | return d->m_bActivated; |
99 | } |
100 | |
101 | bool GUIActivateEvent::test( const QEvent *event ) |
102 | { |
103 | return Event::test( event, GUIActivateEventPrivate::s_strGUIActivateEvent ); |
104 | } |
105 | |
106 | |
107 | /////// PartActivateEvent //////// |
108 | |
109 | class KParts::PartActivateEventPrivate |
110 | { |
111 | public: |
112 | PartActivateEventPrivate( bool activated, |
113 | Part *part, |
114 | QWidget *widget ) : |
115 | m_bActivated( activated ), |
116 | m_part( part ), |
117 | m_widget( widget ) |
118 | { |
119 | } |
120 | static const char *s_strPartActivateEvent; |
121 | bool m_bActivated; |
122 | Part *m_part; |
123 | QWidget *m_widget; |
124 | }; |
125 | |
126 | const char *PartActivateEventPrivate::s_strPartActivateEvent = "KParts/PartActivateEvent" ; |
127 | |
128 | PartActivateEvent::PartActivateEvent( bool activated, |
129 | Part *part, |
130 | QWidget *widget ) : |
131 | Event( PartActivateEventPrivate::s_strPartActivateEvent ), |
132 | d( new PartActivateEventPrivate(activated,part,widget) ) |
133 | { |
134 | } |
135 | |
136 | PartActivateEvent::~PartActivateEvent() |
137 | { |
138 | delete d; |
139 | } |
140 | |
141 | bool PartActivateEvent::activated() const |
142 | { |
143 | return d->m_bActivated; |
144 | } |
145 | |
146 | Part *PartActivateEvent::part() const |
147 | { |
148 | return d->m_part; |
149 | } |
150 | |
151 | QWidget *PartActivateEvent::widget() const |
152 | { |
153 | return d->m_widget; |
154 | } |
155 | |
156 | bool PartActivateEvent::test( const QEvent *event ) |
157 | { |
158 | return Event::test( event, PartActivateEventPrivate::s_strPartActivateEvent ); |
159 | } |
160 | |
161 | |
162 | /////// PartSelectEvent //////// |
163 | |
164 | class KParts::PartSelectEventPrivate |
165 | { |
166 | public: |
167 | PartSelectEventPrivate( bool selected, |
168 | Part *part, |
169 | QWidget *widget ) : |
170 | m_bSelected( selected ), |
171 | m_part( part ), |
172 | m_widget( widget ) |
173 | { |
174 | } |
175 | static const char *s_strPartSelectEvent; |
176 | bool m_bSelected; |
177 | Part *m_part; |
178 | QWidget *m_widget; |
179 | }; |
180 | |
181 | const char *PartSelectEventPrivate::s_strPartSelectEvent = |
182 | "KParts/PartSelectEvent" ; |
183 | |
184 | PartSelectEvent::PartSelectEvent( bool selected, |
185 | Part *part, |
186 | QWidget *widget ) : |
187 | Event( PartSelectEventPrivate::s_strPartSelectEvent ), |
188 | d( new PartSelectEventPrivate(selected,part,widget) ) |
189 | { |
190 | } |
191 | |
192 | PartSelectEvent::~PartSelectEvent() |
193 | { |
194 | delete d; |
195 | } |
196 | |
197 | bool PartSelectEvent::selected() const |
198 | { |
199 | return d->m_bSelected; |
200 | } |
201 | |
202 | Part *PartSelectEvent::part() const |
203 | { |
204 | return d->m_part; |
205 | } |
206 | |
207 | QWidget *PartSelectEvent::widget() const |
208 | { |
209 | return d->m_widget; |
210 | } |
211 | |
212 | bool PartSelectEvent::test( const QEvent *event ) |
213 | { |
214 | return Event::test( event, PartSelectEventPrivate::s_strPartSelectEvent ); |
215 | } |
216 | |
217 | |