1 /*
2  *  ppui/Event.h
3  *
4  *  Copyright 2009 Peter Barth
5  *
6  *  This file is part of Milkytracker.
7  *
8  *  Milkytracker is free software: you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation, either version 3 of the License, or
11  *  (at your option) any later version.
12  *
13  *  Milkytracker is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with Milkytracker.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 /////////////////////////////////////////////////////////////////
24 //
25 //	PPEvent classes
26 //
27 /////////////////////////////////////////////////////////////////
28 #ifndef EVENT__H
29 #define EVENT__H
30 
31 #include "Object.h"
32 #include "BasicTypes.h"
33 
34 // key states
35 enum KeyModifiers
36 {
37 	KeyModifierALT = 1,
38 	KeyModifierSHIFT = 2,
39 	KeyModifierCTRL = 4
40 };
41 
42 struct TMouseWheelEventParams
43 {
44 	PPPoint pos;
45 	pp_int32 deltaX;
46 	pp_int32 deltaY;
47 };
48 
49 void setKeyModifier(KeyModifiers eModifier);
50 void clearKeyModifier(KeyModifiers eModifier);
51 void setForceKeyModifier(KeyModifiers eModifier);
52 void clearForceKeyModifier(KeyModifiers eModifier);
53 pp_uint32 getKeyModifier();
54 
55 enum EEventDescriptor
56 {
57 	eInvalid = 0,
58 	eLMouseDown,
59 	eLMouseUp,
60 	eLMouseDoubleClick,
61 	eLMouseDrag,
62 	eLMouseRepeat,
63 	eRMouseDown,
64 	eRMouseUp,
65 	eRMouseDoubleClick,
66 	eRMouseDrag,
67 	eRMouseRepeat,
68 	eMMouseDown,
69 	eMMouseUp,
70 	eMMouseDoubleClick,
71 	eMMouseDrag,
72 	eMMouseRepeat,
73 	eMouseMoved,
74 	eMouseEntered,
75 	eMouseLeft,
76 	eMouseWheelMoved,
77 	eBarPosChanged,
78 	eBarScrollUp,
79 	eBarScrollDown,
80 	eKeyDown,
81 	eKeyChar,
82 	eKeyUp,
83 	eFileDragDropped,
84 	eFileSystemChanged,
85 	eFocusGained,
86 	eFocusLost,
87 	eFocusGainedNoRepaint,
88 	eFocusLostNoRepaint,
89 	eRemovedContextMenu,
90 	eCommand,					// e.g. button pressed once
91 	eCommandRight,				// e.g. right button pressed once
92 	eCommandRepeat,				// e.g. button stays pressed
93 	ePreSelection,				// e.g. list box selection is about to change
94 	eSelection,					// e.g. list box selection has been made
95 	eValueChanged,
96 	eUpdated,
97 	eUpdateChanged,
98 	eConfirmed,					// e.g. ok-press
99 	eCanceled,					// e.g. cancel-press
100 	eTimer,
101 	eFullScreen,
102 	eAppQuit
103 };
104 
105 /////////////////////////////////////////////////////////////////
106 //	Basic event class
107 /////////////////////////////////////////////////////////////////
108 class PPEvent : public PPObject
109 {
110 private:
111 	EEventDescriptor ID;
112 
113 	unsigned char userData[256];
114 	pp_int32 dataSize;
115 	pp_int32 metaData;
116 
117 public:
PPEvent()118 	PPEvent() :
119 		ID(eInvalid),
120 		dataSize(0),
121 		metaData(0)
122 	{
123 	}
124 
125 	PPEvent(EEventDescriptor ID, pp_int32 theMetaData = 0) :
ID(ID)126 		ID(ID),
127 		dataSize(0),
128 		metaData(theMetaData)
129 	{
130 	}
131 
132 	PPEvent(EEventDescriptor ID, void* dataPtr, pp_int32 dSize, pp_int32 theMetaData = 0) :
ID(ID)133 		ID(ID),
134 		dataSize(dSize),
135 		metaData(theMetaData)
136 	{
137 		if (dSize <= (signed)sizeof(userData))
138 			memcpy(userData, dataPtr, dataSize);
139 		else
140 			exit(0);
141 	}
142 
PPEvent(const PPEvent & event)143 	PPEvent(const PPEvent& event) :
144 		ID(event.ID),
145 		dataSize(event.dataSize),
146 		metaData(event.metaData)
147 	{
148 		memcpy(this->userData, event.userData, event.dataSize);
149 	}
150 
getID()151 	EEventDescriptor getID() const { return ID; }
152 
getDataPtr()153 	const void* getDataPtr() const { return userData; }
getDataSize()154 	pp_int32 getDataSize() const { return dataSize; }
155 
getMetaData()156 	pp_int32 getMetaData() const { return metaData; }
157 
cancel()158 	void cancel() { ID = eInvalid; }
159 
isMouseEvent()160 	bool isMouseEvent() const
161 	{
162 		switch (ID)
163 		{
164 			case eLMouseDown:
165 			case eLMouseUp:
166 			case eLMouseDoubleClick:
167 			case eLMouseDrag:
168 			case eLMouseRepeat:
169 			case eRMouseDown:
170 			case eRMouseUp:
171 			case eRMouseDoubleClick:
172 			case eRMouseDrag:
173 			case eRMouseRepeat:
174 			case eMMouseDown:
175 			case eMMouseUp:
176 			case eMMouseDoubleClick:
177 			case eMMouseDrag:
178 			case eMMouseRepeat:
179 			case eMouseMoved:
180 			case eMouseEntered:
181 			case eMouseLeft:
182 			case eMouseWheelMoved:
183 				return true;
184 			default:
185 				return false;
186 		}
187 	}
188 };
189 
190 /////////////////////////////////////////////////////////////////
191 //	Interface for EventListenerInterface
192 /////////////////////////////////////////////////////////////////
193 class EventListenerInterface : public PPObject
194 {
195 public:
196 	virtual pp_int32 handleEvent(PPObject* sender, PPEvent* event) = 0;
197 };
198 
199 enum
200 {
201 	PP_MESSAGEBOX_BUTTON_YES		= 31000,
202 	PP_MESSAGEBOX_BUTTON_OK			= 31000,
203 	PP_MESSAGEBOX_BUTTON_NO			= 31001,
204 	PP_MESSAGEBOX_BUTTON_CANCEL		= 31002,
205 	PP_MESSAGEBOX_BUTTON_USER1		= 31003,
206 	PP_MESSAGEBOX_BUTTON_USER2		= 31004,
207 	PP_MESSAGEBOX_BUTTON_USER3		= 31005,
208 	PP_MESSAGEBOX_BUTTON_USER4		= 31006,
209 	PP_MESSAGEBOX_BUTTON_USER5		= 31007,
210 	PP_MESSAGEBOX_BUTTON_USER6		= 31008,
211 	PP_MESSAGEBOX_BUTTON_USER7		= 31009,
212 	PP_MESSAGEBOX_BUTTON_USER8		= 31010,
213 	PP_MESSAGEBOX_BUTTON_USER9		= 31011,
214 	PP_MESSAGEBOX_BUTTON_USER10		= 31012,
215 	PP_MESSAGEBOX_BUTTON_USER11		= 31013,
216 	PP_MESSAGEBOX_BUTTON_USER12		= 31014,
217 	PP_MESSAGEBOX_BUTTON_USER13		= 31015,
218 	PP_MESSAGEBOX_BUTTON_USER14		= 31016,
219 	PP_MESSAGEBOX_BUTTON_USER15		= 31017,
220 
221 	PP_DEFAULT_ID					= 0x12345678
222 };
223 
224 class DialogResponder
225 {
226 public:
ActionOkay(PPObject * sender)227 	virtual pp_int32 ActionOkay(PPObject* sender)	{ return 0; }
ActionCancel(PPObject * sender)228 	virtual pp_int32 ActionCancel(PPObject* sender) { return 0; }
ActionNo(PPObject * sender)229 	virtual pp_int32 ActionNo(PPObject* sender)		{ return 0; }
ActionUser1(PPObject * sender)230 	virtual pp_int32 ActionUser1(PPObject* sender)	{ return 0; }
ActionUser2(PPObject * sender)231 	virtual pp_int32 ActionUser2(PPObject* sender)	{ return 0; }
ActionUser3(PPObject * sender)232 	virtual pp_int32 ActionUser3(PPObject* sender)	{ return 0; }
ActionUser4(PPObject * sender)233 	virtual pp_int32 ActionUser4(PPObject* sender)	{ return 0; }
234 };
235 
236 #endif
237