svn merge ^/trunk/blender -r41226:41227 .
[blender.git] / intern / ghost / intern / GHOST_EventPrinter.cpp
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
19  * All rights reserved.
20  *
21  * The Original Code is: all of this file.
22  *
23  * Contributor(s): none yet.
24  *
25  * ***** END GPL LICENSE BLOCK *****
26  */
27
28 /** \file ghost/intern/GHOST_EventPrinter.cpp
29  *  \ingroup GHOST
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 #include <stdio.h>
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                 char str[32]= {'\0'};
86                 getKeyString(keyData->key, str);
87                 std::cout << "GHOST_kEventKeyUp, key: " << str;
88                 }
89                 break;
90         case GHOST_kEventKeyDown:
91                 {
92                 GHOST_TEventKeyData* keyData = (GHOST_TEventKeyData*)((GHOST_IEvent*)event)->getData();
93                 char str[32]= {'\0'};
94                 getKeyString(keyData->key, str);
95                 std::cout << "GHOST_kEventKeyDown, key: " << str;
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, char str[32]) const
187 {
188         if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
189                 sprintf(str, "%c", (char)key);
190         } else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
191                 sprintf(str, "Numpad %d", (key - GHOST_kKeyNumpad0));
192 #if defined(__sun__) || defined(__sun)
193         } else if (key == 268828432) { /* solaris keyboards are messed up */
194                  /* This should really test XK_F11 but that doesn't work */
195                 strcpy(str, "F11");
196         } else if (key == 268828433) { /* solaris keyboards are messed up */
197                  /* This should really test XK_F12 but that doesn't work */
198                 strcpy(str, "F12");
199 #endif
200         } else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
201                 sprintf(str, "F%d", key - GHOST_kKeyF1 + 1);
202         } else {
203                 const char *tstr= NULL;
204                 switch (key) {
205                 case GHOST_kKeyBackSpace:
206                         tstr = "BackSpace";
207                         break;
208                 case GHOST_kKeyTab:
209                         tstr = "Tab";
210                         break;
211                 case GHOST_kKeyLinefeed:
212                         tstr = "Linefeed";
213                         break;
214                 case GHOST_kKeyClear:
215                         tstr = "Clear";
216                         break;
217                 case GHOST_kKeyEnter:
218                         tstr = "Enter";
219                         break;
220                 case GHOST_kKeyEsc:
221                         tstr = "Esc";
222                         break;
223                 case GHOST_kKeySpace:
224                         tstr = "Space";
225                         break;
226                 case GHOST_kKeyQuote:
227                         tstr = "Quote";
228                         break;
229                 case GHOST_kKeyBackslash:
230                         tstr = "\\";
231                         break;
232                 case GHOST_kKeyAccentGrave:
233                         tstr = "`";
234                         break;
235                 case GHOST_kKeyLeftShift:
236                         tstr = "LeftShift";
237                         break;
238                 case GHOST_kKeyRightShift:
239                         tstr = "RightShift";
240                         break;
241                 case GHOST_kKeyLeftControl:
242                         tstr = "LeftControl";
243                         break;
244                 case GHOST_kKeyRightControl:
245                         tstr = "RightControl";
246                         break;
247                 case GHOST_kKeyLeftAlt:
248                         tstr = "LeftAlt";
249                         break;
250                 case GHOST_kKeyRightAlt:
251                         tstr = "RightAlt";
252                         break;
253                 case GHOST_kKeyOS:
254                         tstr = "OS";
255                         break;
256                 case GHOST_kKeyGrLess:
257             // PC german!
258                         tstr = "GrLess";
259                         break;
260                 case GHOST_kKeyCapsLock:
261                         tstr = "CapsLock";
262                         break;
263                 case GHOST_kKeyNumLock:
264                         tstr = "NumLock";
265                         break;
266                 case GHOST_kKeyScrollLock:
267                         tstr = "ScrollLock";
268                         break;
269                 case GHOST_kKeyLeftArrow:
270                         tstr = "LeftArrow";
271                         break;
272                 case GHOST_kKeyRightArrow:
273                         tstr = "RightArrow";
274                         break;
275                 case GHOST_kKeyUpArrow:
276                         tstr = "UpArrow";
277                         break;
278                 case GHOST_kKeyDownArrow:
279                         tstr = "DownArrow";
280                         break;
281                 case GHOST_kKeyPrintScreen:
282                         tstr = "PrintScreen";
283                         break;
284                 case GHOST_kKeyPause:
285                         tstr = "Pause";
286                         break;
287                 case GHOST_kKeyInsert:
288                         tstr = "Insert";
289                         break;
290                 case GHOST_kKeyDelete:
291                         tstr = "Delete";
292                         break;
293                 case GHOST_kKeyHome:
294                         tstr = "Home";
295                         break;
296                 case GHOST_kKeyEnd:
297                         tstr = "End";
298                         break;
299                 case GHOST_kKeyUpPage:
300                         tstr = "UpPage";
301                         break;
302                 case GHOST_kKeyDownPage:
303                         tstr = "DownPage";
304                         break;
305                 case GHOST_kKeyNumpadPeriod:
306                         tstr = "NumpadPeriod";
307                         break;
308                 case GHOST_kKeyNumpadEnter:
309                         tstr = "NumpadEnter";
310                         break;
311                 case GHOST_kKeyNumpadPlus:
312                         tstr = "NumpadPlus";
313                         break;
314                 case GHOST_kKeyNumpadMinus:
315                         tstr = "NumpadMinus";
316                         break;
317                 case GHOST_kKeyNumpadAsterisk:
318                         tstr = "NumpadAsterisk";
319                         break;
320                 case GHOST_kKeyNumpadSlash:
321                         tstr = "NumpadSlash";
322                         break;
323                 case GHOST_kKeyMediaPlay:
324                         tstr = "MediaPlayPause";
325                         break;
326                 case GHOST_kKeyMediaStop:
327                         tstr = "MediaStop";
328                         break;
329                 case GHOST_kKeyMediaFirst:
330                         tstr = "MediaFirst";
331                         break;
332                 case GHOST_kKeyMediaLast:
333                         tstr = "MediaLast";
334                         break;
335                 default:
336                         tstr = "unknown";
337                         break;
338                 }
339
340                 sprintf(str, "%s", tstr);
341         }
342 }
343