summaryrefslogtreecommitdiffstats
path: root/kexi/plugins/forms/kexiformeventhandler.h
blob: e882eeb847dfc357bc015abcfa1769c3c888a19b (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
/* This file is part of the KDE project
   Copyright (C) 2005-2006 Jaroslaw Staniek <[email protected]>

   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 KEXIFORMEVENTHANDLER_H
#define KEXIFORMEVENTHANDLER_H

#include <tqwidget.h>
#include <kaction.h>

class KexiMainWindow;
namespace KexiPart {
	class Info;
}

//! The KexiFormEventHandler class handles events defined within Kexi Forms
/*! For now only "onClickAction" property of Push Button widget is handled:
 It's possible to connect this event to predefined global action. 

 Note: This interface will be extended in the future!

 @see KexiFormPart::slotAssignAction()
 */
class KEXIFORMUTILS_EXPORT KexiFormEventHandler
{
	public:
		KexiFormEventHandler();
		virtual ~KexiFormEventHandler();

		/*! Sets \a mainWidget to be a main widget for this handler.
		 Also find widgets having action assigned and connects them 
		 to appropriate actions. 
		 For now, all of them must be KexiPushButton). 
		 \a mainWin is used to get action list. */
		void setMainWidgetForEventHandling(KexiMainWindow *mainWin, TQWidget* mainWidget);

	protected:
		TQWidget *m_mainWidget;
};

//! @internal form-level action for handling "on click" actions
class KEXIFORMUTILS_EXPORT KexiFormEventAction : public KAction
{
	public:
		//! A structure used in currentActionName()
		class KEXIFORMUTILS_EXPORT ActionData
		{
			public:
				ActionData();

				/*! Decodes action string into action type/action argument parts.
				 Action string has to be in a form of "actiontype:actionarg"
				 - Action type is passed to \a actionType on success. Action type can be "kaction"
					or any of the part names (see KexiPart::Info::objectName()), e.g. "table", "query", etc.
				 - Action argument can be an action name in case of "kaction" type or object name 
					in case of action of type "table", "query", etc.
				 \a ok is set to true on success and to false on failure. On failure no other
				 values are passed. 
				 \return part info if action type is "table", "query", etc., or 0 for "kaction" type. */
				KexiPart::Info* decodeString(TQString& actionType, TQString& actionArg, bool& ok) const;

				//! \return true if the action is empty
				bool isEmpty() const;

				TQString string; //!< action string with prefix, like "kaction:edit_copy" or "table:<tableName>"

				TQString option; //!< option used when name is "table/query/etc.:\<objectName\>" is set;
				                //!< can be set to "open", "design", "editText", etc. 
				                //!< @see ActionToExecuteListView::showActionsForMimeType()
		};

		KexiFormEventAction(KexiMainWindow *mainWin, TQObject* parent, const TQString& actionName, 
			const TQString& objectName, const TQString& actionOption);
		virtual ~KexiFormEventAction();

	public slots:
		//! Activates the action. If the object supports executing (macro, script), 
		//! it is executed; otherwise (table, query, form,...) it is opened in its data view.
		virtual void activate();

	private:
		KexiMainWindow *m_mainWin;
		TQString m_actionName, m_objectName, m_actionOption;
};

#endif