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