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