Drop platform support for Solaris & AIX
[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
183         std::cout.flush();
184
185         return handled;
186 }
187
188
189 void GHOST_EventPrinter::getKeyString(GHOST_TKey key, char str[32]) const
190 {
191         if ((key >= GHOST_kKeyComma) && (key <= GHOST_kKeyRightBracket)) {
192                 sprintf(str, "%c", (char)key);
193         }
194         else if ((key >= GHOST_kKeyNumpad0) && (key <= GHOST_kKeyNumpad9)) {
195                 sprintf(str, "Numpad %d", (key - GHOST_kKeyNumpad0));
196         }
197         else if ((key >= GHOST_kKeyF1) && (key <= GHOST_kKeyF24)) {
198                 sprintf(str, "F%d", key - GHOST_kKeyF1 + 1);
199         }
200         else {
201                 const char *tstr = NULL;
202                 switch (key) {
203                         case GHOST_kKeyBackSpace:
204                                 tstr = "BackSpace";
205                                 break;
206                         case GHOST_kKeyTab:
207                                 tstr = "Tab";
208                                 break;
209                         case GHOST_kKeyLinefeed:
210                                 tstr = "Linefeed";
211                                 break;
212                         case GHOST_kKeyClear:
213                                 tstr = "Clear";
214                                 break;
215                         case GHOST_kKeyEnter:
216                                 tstr = "Enter";
217                                 break;
218                         case GHOST_kKeyEsc:
219                                 tstr = "Esc";
220                                 break;
221                         case GHOST_kKeySpace:
222                                 tstr = "Space";
223                                 break;
224                         case GHOST_kKeyQuote:
225                                 tstr = "Quote";
226                                 break;
227                         case GHOST_kKeyBackslash:
228                                 tstr = "\\";
229                                 break;
230                         case GHOST_kKeyAccentGrave:
231                                 tstr = "`";
232                                 break;
233                         case GHOST_kKeyLeftShift:
234                                 tstr = "LeftShift";
235                                 break;
236                         case GHOST_kKeyRightShift:
237                                 tstr = "RightShift";
238                                 break;
239                         case GHOST_kKeyLeftControl:
240                                 tstr = "LeftControl";
241                                 break;
242                         case GHOST_kKeyRightControl:
243                                 tstr = "RightControl";
244                                 break;
245                         case GHOST_kKeyLeftAlt:
246                                 tstr = "LeftAlt";
247                                 break;
248                         case GHOST_kKeyRightAlt:
249                                 tstr = "RightAlt";
250                                 break;
251                         case GHOST_kKeyOS:
252                                 tstr = "OS";
253                                 break;
254                         case GHOST_kKeyGrLess:
255                                 // PC german!
256                                 tstr = "GrLess";
257                                 break;
258                         case GHOST_kKeyCapsLock:
259                                 tstr = "CapsLock";
260                                 break;
261                         case GHOST_kKeyNumLock:
262                                 tstr = "NumLock";
263                                 break;
264                         case GHOST_kKeyScrollLock:
265                                 tstr = "ScrollLock";
266                                 break;
267                         case GHOST_kKeyLeftArrow:
268                                 tstr = "LeftArrow";
269                                 break;
270                         case GHOST_kKeyRightArrow:
271                                 tstr = "RightArrow";
272                                 break;
273                         case GHOST_kKeyUpArrow:
274                                 tstr = "UpArrow";
275                                 break;
276                         case GHOST_kKeyDownArrow:
277                                 tstr = "DownArrow";
278                                 break;
279                         case GHOST_kKeyPrintScreen:
280                                 tstr = "PrintScreen";
281                                 break;
282                         case GHOST_kKeyPause:
283                                 tstr = "Pause";
284                                 break;
285                         case GHOST_kKeyInsert:
286                                 tstr = "Insert";
287                                 break;
288                         case GHOST_kKeyDelete:
289                                 tstr = "Delete";
290                                 break;
291                         case GHOST_kKeyHome:
292                                 tstr = "Home";
293                                 break;
294                         case GHOST_kKeyEnd:
295                                 tstr = "End";
296                                 break;
297                         case GHOST_kKeyUpPage:
298                                 tstr = "UpPage";
299                                 break;
300                         case GHOST_kKeyDownPage:
301                                 tstr = "DownPage";
302                                 break;
303                         case GHOST_kKeyNumpadPeriod:
304                                 tstr = "NumpadPeriod";
305                                 break;
306                         case GHOST_kKeyNumpadEnter:
307                                 tstr = "NumpadEnter";
308                                 break;
309                         case GHOST_kKeyNumpadPlus:
310                                 tstr = "NumpadPlus";
311                                 break;
312                         case GHOST_kKeyNumpadMinus:
313                                 tstr = "NumpadMinus";
314                                 break;
315                         case GHOST_kKeyNumpadAsterisk:
316                                 tstr = "NumpadAsterisk";
317                                 break;
318                         case GHOST_kKeyNumpadSlash:
319                                 tstr = "NumpadSlash";
320                                 break;
321                         case GHOST_kKeyMediaPlay:
322                                 tstr = "MediaPlayPause";
323                                 break;
324                         case GHOST_kKeyMediaStop:
325                                 tstr = "MediaStop";
326                                 break;
327                         case GHOST_kKeyMediaFirst:
328                                 tstr = "MediaFirst";
329                                 break;
330                         case GHOST_kKeyMediaLast:
331                                 tstr = "MediaLast";
332                                 break;
333                         default:
334                                 tstr = "unknown";
335                                 break;
336                 }
337
338                 sprintf(str, "%s", tstr);
339         }
340 }
341