summaryrefslogtreecommitdiffstats
path: root/khotkeys/shared/conditions.h
blob: ff1af7d074f8a642d5547347c78db49cf7d85cd6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/****************************************************************************

 KHotKeys
 
 Copyright (C) 1999-2001 Lubos Lunak <l.lunak@kde.org>

 Distributed under the terms of the GNU General Public License version 2.
 
****************************************************************************/

#ifndef _CONDITIONS_H_
#define _CONDITIONS_H_

#include <tqobject.h>
#include <tqptrlist.h>
#include <tqstring.h>

#include "khotkeysglobal.h"
#include "windows.h"

#include <X11/Xlib.h>
#include <fixx11h.h>

class TDEConfig;

namespace KHotKeys
{

class Action_data_base;
class Action_data;
class Condition_list_base;

class KDE_EXPORT Condition
    {
    public:
        Condition( Condition_list_base* parent_P );
        Condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual ~Condition();
        virtual bool match() const = 0;
        virtual void updated() const; // called when the condition changes
        virtual void cfg_write( TDEConfig& cfg_P ) const = 0;
        virtual const TQString description() const = 0;
        virtual Condition* copy( Condition_list_base* parent_P ) const = 0;
        const Condition_list_base* parent() const;
        Condition_list_base* parent();
        static Condition* create_cfg_read( TDEConfig& cfg_P, Condition_list_base* parent_P );
    protected:
        Condition_list_base* const _parent;
    KHOTKEYS_DISABLE_COPY( Condition );
    };
        
class KDE_EXPORT Condition_list_base
    : public Condition, public TQPtrList< Condition > // inheritance ?
    {
    typedef Condition base;
    public:
        Condition_list_base( Condition_list_base* parent_P );
        Condition_list_base( const TQPtrList< Condition >& children_P,
            Condition_list_base* parent_P );
        Condition_list_base( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual ~Condition_list_base();
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual bool accepts_children() const;
        typedef TQPtrListIterator< Condition > Iterator;
    };

class KDE_EXPORT Condition_list
    : public Condition_list_base
    {
    typedef Condition_list_base base;
    public:
        Condition_list( const TQString& comment_P, Action_data_base* data_P );
        Condition_list( TDEConfig& cfg_P, Action_data_base* data_P );
        void cfg_write( TDEConfig& cfg_P ) const;
        Condition_list* copy( Action_data_base* data_P ) const;
        virtual bool match() const;
        const TQString& comment() const;
        void set_data( Action_data_base* data_P );
        virtual void updated() const;
        virtual Condition_list* copy( Condition_list_base* parent_P ) const;
        virtual const TQString description() const;
    private:
        TQString _comment;
        Action_data_base* data;
    };

class KDE_EXPORT Active_window_condition
    : public TQObject, public Condition
    {
    Q_OBJECT
    typedef Condition base;
    public:
        Active_window_condition( Windowdef_list* window_P, Condition_list_base* parent_P );
        Active_window_condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual ~Active_window_condition();
        virtual bool match() const;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        const Windowdef_list* window() const;
#ifndef COVARIANT_RETURN_BROKEN
        virtual Active_window_condition* copy( Condition_list_base* parent_P ) const;
#else
        virtual Condition* copy( Condition_list_base* parent_P ) const;
#endif
        virtual const TQString description() const;
    public slots:
        void active_window_changed( WId );
    private:
        void init();
        void set_match();
        Windowdef_list* _window;
        bool is_match;
    };
            
class KDE_EXPORT Existing_window_condition
    : public TQObject, public Condition
    {
    Q_OBJECT
    typedef Condition base;
    public:
        Existing_window_condition( Windowdef_list* window_P, Condition_list_base* parent_P );
        Existing_window_condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual ~Existing_window_condition();
        virtual bool match() const;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        const Windowdef_list* window() const;
#ifndef COVARIANT_RETURN_BROKEN
        virtual Existing_window_condition* copy( Condition_list_base* parent_P ) const;
#else
        virtual Condition* copy( Condition_list_base* parent_P ) const;
#endif
        virtual const TQString description() const;
    public slots:
        void window_added( WId w_P );
        void window_removed( WId w_P );
    private:
        void init();
        void set_match( WId w_P = None );
        Windowdef_list* _window;
        bool is_match;
    };

class KDE_EXPORT Not_condition
    : public Condition_list_base
    {
    typedef Condition_list_base base;
    public:
        Not_condition( Condition_list_base* parent_P );
        Not_condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual bool match() const;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual Not_condition* copy( Condition_list_base* parent_P ) const;
        virtual const TQString description() const;
        const Condition* condition() const;
        virtual bool accepts_children() const;
    };
            
class KDE_EXPORT And_condition
    : public Condition_list_base
    {
    typedef Condition_list_base base;
    public:
        And_condition( Condition_list_base* parent_P );
        And_condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual bool match() const;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual And_condition* copy( Condition_list_base* parent_P ) const;
        virtual const TQString description() const;
    };
            
class KDE_EXPORT Or_condition
    : public Condition_list_base
    {
    typedef Condition_list_base base;
    public:
        Or_condition( Condition_list_base* parent_P );
        Or_condition( TDEConfig& cfg_P, Condition_list_base* parent_P );
        virtual bool match() const;
        virtual void cfg_write( TDEConfig& cfg_P ) const;
        virtual Or_condition* copy( Condition_list_base* parent_P ) const;
        virtual const TQString description() const;
    };
            
//***************************************************************************
// Inline
//***************************************************************************

// Condition

inline
const Condition_list_base* Condition::parent() const
    {
    return _parent;
    }
    
inline
Condition_list_base* Condition::parent()
    {
    return _parent;
    }
    
// Condition_list_base

inline
Condition_list_base::Condition_list_base( Condition_list_base* parent_P )
    : Condition( parent_P ), TQPtrList< Condition >()
    {
    }

inline
Condition_list_base::Condition_list_base( const TQPtrList< Condition >& children_P,
    Condition_list_base* parent_P )
    : Condition( parent_P ), TQPtrList< Condition >( children_P )
    {
    }

// Condition_list

inline
Condition_list::Condition_list( const TQString& comment_P, Action_data_base* data_P )
    : Condition_list_base( NULL ), _comment( comment_P ), data( data_P )
    {
    }

inline
const TQString& Condition_list::comment() const
    {
    return _comment;
    }

// Active_window_condition

inline
Active_window_condition::Active_window_condition( Windowdef_list* window_P,
    Condition_list_base* parent_P )
    : Condition( parent_P ), _window( window_P )
    {
    init();
    set_match();
    }
    
inline
const Windowdef_list* Active_window_condition::window() const
    {
    return _window;
    }

// Existing_window_condition

inline
Existing_window_condition::Existing_window_condition( Windowdef_list* window_P,
    Condition_list_base* parent_P )
    : Condition( parent_P ), _window( window_P ), is_match( false )
    {
    init();
    set_match();
    }
    
inline
const Windowdef_list* Existing_window_condition::window() const
    {
    return _window;
    }

// Not_condition

inline
Not_condition::Not_condition( Condition_list_base* parent_P )
    : Condition_list_base( parent_P )
    {
    }
    
inline
const Condition* Not_condition::condition() const
    {
    return getFirst();
    }

// And_condition

inline
And_condition::And_condition( Condition_list_base* parent_P )
    : Condition_list_base( parent_P )
    {
    }
    
// Or_condition

inline
Or_condition::Or_condition( Condition_list_base* parent_P )
    : Condition_list_base( parent_P )
    {
    }
    
} // namespace KHotKeys

#endif