summaryrefslogtreecommitdiffstats
path: root/kexi/core/kexievents.h
blob: f65ff132a379f7a5577a8f0f5f6816b21b445caa (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
/* This file is part of the KDE project
   Copyright (C) 2004 Cedric Pasteur <cedric.pasteur@free.fr>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KFORMDESIGNEREVENTS_H
#define KFORMDESIGNEREVENTS_H

#include <tqvaluelist.h>
#include <tqguardedptr.h>

class TQDomNode;
class TQObject;

//! A simple class to store events
/*! There are three different types of events (an maybe more in the future):
  * signal to slot: sender and receiver are both widgets.
  * signal to user function: whenever the signal is emitted, a function in the form script is called.
  * signal to action: the signal activates an application action (eg addNewRecord in Kexi)
  (other :* global signal to user function: an application global signal (new window opened, etc.) calls a user script function)

 \todo  add aliases for slot()?? (eg actionName())
 */
class KEXICORE_EXPORT Event
{
	public:
		Event(TQObject *sender, const TQCString &signal,
			TQObject *receiver, const TQCString &slot);
		Event(TQObject *sender, const TQCString &signal,
			const TQCString &functionName);
		Event() : m_type(Slot) {;}
		~Event() {;}

		enum { Slot=1000, UserFunction, Action }; //! Event types
		int  type() {return  m_type; }
		void  setType(int type) { m_type = type; }

		TQObject*  sender() const { return m_sender; }
		TQObject*  receiver() const { return m_receiver; }
		TQCString  signal() const { return m_signal; }
		TQCString  slot() const { return m_slot; }

		void  setSender(TQObject *o) { m_sender = o; }
		void  setReceiver(TQObject *o) { m_receiver = o; }
		void  setSignal(const TQCString &s) { m_signal = s; }
		void  setSlot(const TQCString &s) { m_slot = s; }

	protected:
		TQGuardedPtr<TQObject> m_sender;
		TQCString m_signal;
		TQGuardedPtr<TQObject> m_receiver;
		TQCString m_slot;
		int  m_type;
};

class KEXICORE_EXPORT EventList : protected TQValueList<Event*>
{
	public:
		EventList() {;}
		~EventList() {;}

		/*! Adds an event in list. Other overload are available, so that
		 other classes don't have to use Event class in simple cases. */
		void addEvent(Event *event);
		void addEvent(TQObject *sender, const TQCString &signal, TQObject *receiver, const TQCString &slot);
		void addEvent(TQObject *sender, const TQCString &signal, const TQCString &action);
		/*! Removes the Event \a event from the FormScript's list. */
		void  removeEvent(Event *event);

		/*! \return A list of events related to widget \a name (ie where Event::sender()
		 or Event::receiver() == name). */
		EventList*  allEventsForObject(TQObject *object);
		/*! Replace all ocurrences of \a oldname with \a newName inside the list. */
		//void  renameWidget(const TQCString &oldName, const TQCString &newName);
		/*! Removes all events related to widget \a name. Called eg when widget is destroyed. */
		void  removeAllEventsForObject(TQObject *object);

		// make some TQValueList function accessible by other classes
		TQValueListConstIterator<Event*>  constBegin() const { return TQValueList<Event*>::constBegin(); } 
		TQValueListConstIterator<Event*>  constEnd() const { return TQValueList<Event*>::constEnd(); } 
		bool  isEmpty() const { return TQValueList<Event*>::isEmpty(); }
};


#endif