Adding support for the "media" play/pause/stop/next/prev buttons
[blender.git] / intern / ghost / intern / GHOST_EventPrinter.cpp
1 /**
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program 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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28 /**
29  * @file        GHOST_EventPrinter.h
30  * Declaration of GHOST_EventPrinter class.
31  */
32
33 #include "GHOST_EventPrinter.h"
34 #include <iostream>
35 #include "GHOST_EventKey.h"
36 #include "GHOST_EventDragnDrop.h"
37 #include "GHOST_Debug.h"
38
39
40 bool GHOST_EventPrinter::processEvent(GHOST_IEvent* event)
41 {
42         bool handled = true;
43         
44         GHOST_ASSERT(event, "event==0");
45
46         if (event->getType() == GHOST_kEventWindowUpdate) return false;
47
48         std::cout << "\nGHOST_EventPrinter::processEvent, time: " << (GHOST_TInt32)event->getTime() << ", type: ";
49         switch (event->getType()) {
50         case GHOST_kEventUnknown:
51                 std::cout << "GHOST_kEventUnknown"; handled = false;    
52                 break;
53
54         case GHOST_kEventButtonUp:
55                 {
56                 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
57                 std::cout << "GHOST_kEventCursorButtonUp, button: " << buttonData->button;
58                 }
59                 break;
60         case GHOST_kEventButtonDown:
61                 {
62                 GHOST_TEventButtonData* buttonData = (GHOST_TEventButtonData*)((GHOST_IEvent*)event)->getData();
63                 std::cout << "GHOST_kEventButtonDown, button: " << buttonData->button;
64                 }
65                 break;
66
67         case GHOST_kEventWheel:
68                 {
69                 GHOST_TEventWheelData* wheelData = (GHOST_TEventWheelData*)((GHOST_IEvent*)event)->getData();
70                 std::cout << "GHOST_kEventWheel, z: " << wheelData->z;
71                 }
72                 break;
73
74         case GHOST_kEventCursorMove:
75                 {
76                 GHOST_TEventCursorData* cursorData = (GHOST_TEventCursorData*)((GHOST_IEvent*)event)->getData();
77                 std::cout << "GHOST_kEventCursorMove, (x,y): (" << cursorData->x << "," << cursorData->y << ")";
78                 }
79                 break;
80
81         case GHOST_kEventKeyUp:
82                 {
83                 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
84                 STR_String str;
85                 getKeyString(keyData->key, str);
86                 std::cout << "GHOST_kEventKeyUp, key: " << str.Ptr();
87                 }
88                 break;
89         case GHOST_kEventKeyDown:
90                 {
91                 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
92                 STR_String str;
93                 getKeyString(keyData->key, str);
94                 std::cout << "GHOST_kEventKeyDown, key: " << str.Ptr();
95                 }
96                 break;
97                         
98         case GHOST_kEventDraggingEntered:
99                 {
100                         GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
101                         std::cout << "GHOST_kEventDraggingEntered, dragged object type : " << dragnDropData->dataType;
102                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
103                 }
104                 break;
105                         
106         case GHOST_kEventDraggingUpdated:
107                 {
108                         GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
109                         std::cout << "GHOST_kEventDraggingUpdated, dragged object type : " << dragnDropData->dataType;
110                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
111                 }
112                 break;
113
114         case GHOST_kEventDraggingExited:
115                 {
116                         GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
117                         std::cout << "GHOST_kEventDraggingExited, dragged object type : " << dragnDropData->dataType;
118                 }
119                 break;
120         
121         case GHOST_kEventDraggingDropDone:
122                 {
123                         GHOST_TEventDragnDropData* dragnDropData = (GHOST_TEventDragnDropData*)((GHOST_IEvent*)event)->getData();
124                         std::cout << "GHOST_kEventDraggingDropDone,";
125                         std::cout << " mouse at x=" << dragnDropData->x << " y=" << dragnDropData->y;
126                         switch (dragnDropData->dataType) {
127                                 case GHOST_kDragnDropTypeString:
128                                         std::cout << " type : GHOST_kDragnDropTypeString,";
129                                         std::cout << "\n  String received = " << (char*)dragnDropData->data;
130                                         break;
131                                 case GHOST_kDragnDropTypeFilenames:
132                                 {
133                                         GHOST_TStringArray *strArray = (GHOST_TStringArray*)dragnDropData->data;
134                                         int i;
135                                         std::cout << " type : GHOST_kDragnDropTypeFilenames,";
136                                         std::cout << "\n  Received " << strArray->count << " filename" << (strArray->count > 1 ? "s:" : ":");
137                                         for (i=0;i<strArray->count;i++)
138                                                 std::cout << "\n        File[" << i << "] : " << strArray->strings[i];
139                                 }
140                                         break;
141                                 default:
142                                         break;
143                         }
144                 }
145                 break;
146
147         case GHOST_kEventOpenMainFile:
148                 {
149                         GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
150                         
151                         if (eventData)
152                                 std::cout << "GHOST_kEventOpenMainFile for path : " << (char*)eventData;
153                         else
154                                 std::cout << "GHOST_kEventOpenMainFile with no path specified!!";
155                 }
156                 break;
157                         
158         case GHOST_kEventQuit:
159                 std::cout << "GHOST_kEventQuit"; 
160                 break;
161         case GHOST_kEventWindowClose:
162                 std::cout << "GHOST_kEventWindowClose"; 
163                 break;
164         case GHOST_kEventWindowActivate:
165                 std::cout << "GHOST_kEventWindowActivate"; 
166                 break;
167         case GHOST_kEventWindowDeactivate:
168                 std::cout << "GHOST_kEventWindowDeactivate"; 
169                 break;
170         case GHOST_kEventWindowUpdate:
171                 std::cout << "GHOST_kEventWindowUpdate"; 
172                 break;
173         case GHOST_kEventWindowSize:
174                 std::cout << "GHOST_kEventWindowSize"; 
175                 break;
176
177         default:
178                 std::cout << "not found"; handled = false; 
179                 break;
180         }
181         return handled;
182 }
183
184
185 void GHOST_EventPrinter::getKeyString(GHOST_TKey key, STR_String& str) const
186 {
187         if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
188                 str = ((char)key);
189         } else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
190                 int number = key - GHOST_kKeyNumpad0;
191                 STR_String numberStr (number);
192                 str = "Numpad";
193                 str += numberStr;
194 #if defined(__sun__) || defined(__sun)
195         } else if (key == 268828432) { /* solaris keyboards are messed up */
196                  /* This should really test XK_F11 but that doesn't work */
197                 str = "F11";
198         } else if (key == 268828433) { /* solaris keyboards are messed up */
199                  /* This should really test XK_F12 but that doesn't work */
200                 str = "F12";
201 #endif
202         } else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
203                 int number = key - GHOST_kKeyF1 + 1;
204                 STR_String numberStr (number);
205                 str = "F";
206                 str += numberStr;
207         } else {
208                 switch (key)
209                 {
210                 case GHOST_kKeyBackSpace:
211                         str = "BackSpace";
212                         break;
213                 case GHOST_kKeyTab:
214                         str = "Tab";
215                         break;
216                 case GHOST_kKeyLinefeed:
217                         str = "Linefeed";
218                         break;
219                 case GHOST_kKeyClear:
220                         str = "Clear";
221                         break;
222                 case GHOST_kKeyEnter:
223                         str = "Enter";
224                         break;
225                 case GHOST_kKeyEsc:
226                         str = "Esc";
227                         break;
228                 case GHOST_kKeySpace:
229                         str = "Space";
230                         break;
231                 case GHOST_kKeyQuote:
232                         str = "Quote";
233                         break;
234                 case GHOST_kKeyBackslash:
235                         str = "\\";
236                         break;
237                 case GHOST_kKeyAccentGrave:
238                         str = "`";
239                         break;
240                 case GHOST_kKeyLeftShift:
241                         str = "LeftShift";
242                         break;
243                 case GHOST_kKeyRightShift:
244                         str = "RightShift";
245                         break;
246                 case GHOST_kKeyLeftControl:
247                         str = "LeftControl";
248                         break;
249                 case GHOST_kKeyRightControl:
250                         str = "RightControl";
251                         break;
252                 case GHOST_kKeyLeftAlt:
253                         str = "LeftAlt";
254                         break;
255                 case GHOST_kKeyRightAlt:
256                         str = "RightAlt";
257                         break;
258                 case GHOST_kKeyOS:
259                         str = "OS";
260                         break;
261                 case GHOST_kKeyGrLess:
262             // PC german!
263                         str = "GrLess";
264                         break;
265                 case GHOST_kKeyCapsLock:
266                         str = "CapsLock";
267                         break;
268                 case GHOST_kKeyNumLock:
269                         str = "NumLock";
270                         break;
271                 case GHOST_kKeyScrollLock:
272                         str = "ScrollLock";
273                         break;
274                 case GHOST_kKeyLeftArrow:
275                         str = "LeftArrow";
276                         break;
277                 case GHOST_kKeyRightArrow:
278                         str = "RightArrow";
279                         break;
280                 case GHOST_kKeyUpArrow:
281                         str = "UpArrow";
282                         break;
283                 case GHOST_kKeyDownArrow:
284                         str = "DownArrow";
285                         break;
286                 case GHOST_kKeyPrintScreen:
287                         str = "PrintScreen";
288                         break;
289                 case GHOST_kKeyPause:
290                         str = "Pause";
291                         break;
292                 case GHOST_kKeyInsert:
293                         str = "Insert";
294                         break;
295                 case GHOST_kKeyDelete:
296                         str = "Delete";
297                         break;
298                 case GHOST_kKeyHome:
299                         str = "Home";
300                         break;
301                 case GHOST_kKeyEnd:
302                         str = "End";
303                         break;
304                 case GHOST_kKeyUpPage:
305                         str = "UpPage";
306                         break;
307                 case GHOST_kKeyDownPage:
308                         str = "DownPage";
309                         break;
310                 case GHOST_kKeyNumpadPeriod:
311                         str = "NumpadPeriod";
312                         break;
313                 case GHOST_kKeyNumpadEnter:
314                         str = "NumpadEnter";
315                         break;
316                 case GHOST_kKeyNumpadPlus:
317                         str = "NumpadPlus";
318                         break;
319                 case GHOST_kKeyNumpadMinus:
320                         str = "NumpadMinus";
321                         break;
322                 case GHOST_kKeyNumpadAsterisk:
323                         str = "NumpadAsterisk";
324                         break;
325                 case GHOST_kKeyNumpadSlash:
326                         str = "NumpadSlash";
327                         break;
328                 case GHOST_kKeyMediaPlay:
329                         str = "MediaPlayPause";
330                         break;
331                 case GHOST_kKeyMediaStop:
332                         str = "MediaStop";
333                         break;
334                 case GHOST_kKeyMediaFirst:
335                         str = "MediaFirst";
336                         break;
337                 case GHOST_kKeyMediaLast:
338                         str = "MediaLast";
339                         break;
340                 default:
341                         str = "unknown";
342                         break;
343                 }
344         }
345 }
346