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