Fix T67459: Dope Editor, muting channels with shortcut doesn't work
[blender.git] / intern / ghost / intern / GHOST_C-api.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file
21  * \ingroup GHOST
22  *
23  * C Api for GHOST
24  */
25
26 #include <stdlib.h>
27
28 #include "intern/GHOST_Debug.h"
29 #include "GHOST_C-api.h"
30 #include "GHOST_ISystem.h"
31 #include "GHOST_IEvent.h"
32 #include "GHOST_IEventConsumer.h"
33 #include "intern/GHOST_CallbackEventConsumer.h"
34
35 GHOST_SystemHandle GHOST_CreateSystem(void)
36 {
37   GHOST_ISystem::createSystem();
38   GHOST_ISystem *system = GHOST_ISystem::getSystem();
39
40   return (GHOST_SystemHandle)system;
41 }
42
43 GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
44 {
45   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
46
47   return system->disposeSystem();
48 }
49
50 GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback,
51                                                     GHOST_TUserDataPtr userdata)
52 {
53   return (GHOST_EventConsumerHandle) new GHOST_CallbackEventConsumer(eventCallback, userdata);
54 }
55
56 GHOST_TSuccess GHOST_DisposeEventConsumer(GHOST_EventConsumerHandle consumerhandle)
57 {
58   delete ((GHOST_CallbackEventConsumer *)consumerhandle);
59   return GHOST_kSuccess;
60 }
61
62 GHOST_TUns64 GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle)
63 {
64   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
65
66   return system->getMilliSeconds();
67 }
68
69 GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle,
70                                          GHOST_TUns64 delay,
71                                          GHOST_TUns64 interval,
72                                          GHOST_TimerProcPtr timerproc,
73                                          GHOST_TUserDataPtr userdata)
74 {
75   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
76
77   return (GHOST_TimerTaskHandle)system->installTimer(delay, interval, timerproc, userdata);
78 }
79
80 GHOST_TSuccess GHOST_RemoveTimer(GHOST_SystemHandle systemhandle,
81                                  GHOST_TimerTaskHandle timertaskhandle)
82 {
83   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
84   GHOST_ITimerTask *timertask = (GHOST_ITimerTask *)timertaskhandle;
85
86   return system->removeTimer(timertask);
87 }
88
89 GHOST_TUns8 GHOST_GetNumDisplays(GHOST_SystemHandle systemhandle)
90 {
91   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
92
93   return system->getNumDisplays();
94 }
95
96 void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
97                                     GHOST_TUns32 *width,
98                                     GHOST_TUns32 *height)
99 {
100   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
101
102   system->getMainDisplayDimensions(*width, *height);
103 }
104
105 void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
106                                    GHOST_TUns32 *width,
107                                    GHOST_TUns32 *height)
108 {
109   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
110
111   system->getAllDisplayDimensions(*width, *height);
112 }
113
114 GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle)
115 {
116   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
117
118   return (GHOST_ContextHandle)system->createOffscreenContext();
119 }
120
121 GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
122                                           GHOST_ContextHandle contexthandle)
123 {
124   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
125   GHOST_IContext *context = (GHOST_IContext *)contexthandle;
126
127   return system->disposeContext(context);
128 }
129
130 GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
131                                       const char *title,
132                                       GHOST_TInt32 left,
133                                       GHOST_TInt32 top,
134                                       GHOST_TUns32 width,
135                                       GHOST_TUns32 height,
136                                       GHOST_TWindowState state,
137                                       GHOST_TDrawingContextType type,
138                                       GHOST_GLSettings glSettings)
139 {
140   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
141
142   return (GHOST_WindowHandle)system->createWindow(
143       title, left, top, width, height, state, type, glSettings, false);
144 }
145
146 GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
147 {
148   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
149
150   return window->getUserData();
151 }
152 void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata)
153 {
154   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
155
156   window->setUserData(userdata);
157 }
158
159 GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle,
160                                    GHOST_WindowHandle windowhandle)
161 {
162   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
163   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
164
165   return system->disposeWindow(window);
166 }
167
168 int GHOST_ValidWindow(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle)
169 {
170   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
171   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
172
173   return (int)system->validWindow(window);
174 }
175
176 GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle,
177                                          GHOST_DisplaySetting *setting,
178                                          const int stereoVisual)
179 {
180   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
181   GHOST_IWindow *window = NULL;
182   bool bstereoVisual;
183
184   if (stereoVisual)
185     bstereoVisual = true;
186   else
187     bstereoVisual = false;
188
189   system->beginFullScreen(*setting, &window, bstereoVisual);
190
191   return (GHOST_WindowHandle)window;
192 }
193
194 GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle)
195 {
196   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
197
198   return system->endFullScreen();
199 }
200
201 int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
202 {
203   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
204
205   return (int)system->getFullScreen();
206 }
207
208 int GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, int waitForEvent)
209 {
210   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
211
212   return (int)system->processEvents(waitForEvent ? true : false);
213 }
214
215 void GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
216 {
217   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
218
219   system->dispatchEvents();
220 }
221
222 GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle,
223                                       GHOST_EventConsumerHandle consumerhandle)
224 {
225   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
226
227   return system->addEventConsumer((GHOST_CallbackEventConsumer *)consumerhandle);
228 }
229
230 GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle,
231                                          GHOST_EventConsumerHandle consumerhandle)
232 {
233   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
234
235   return system->removeEventConsumer((GHOST_CallbackEventConsumer *)consumerhandle);
236 }
237
238 GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle, float progress)
239 {
240   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
241
242   return window->setProgressBar(progress);
243 }
244
245 GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle)
246 {
247   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
248
249   return window->endProgressBar();
250 }
251
252 GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle)
253 {
254   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
255
256   return window->getCursorShape();
257 }
258
259 GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
260                                     GHOST_TStandardCursor cursorshape)
261 {
262   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
263
264   return window->setCursorShape(cursorshape);
265 }
266
267 GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
268                                           GHOST_TUns8 *bitmap,
269                                           GHOST_TUns8 *mask,
270                                           int sizex,
271                                           int sizey,
272                                           int hotX,
273                                           int hotY,
274                                           GHOST_TUns8 canInvertColor)
275 {
276   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
277
278   return window->setCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, canInvertColor);
279 }
280
281 int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle)
282 {
283   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
284
285   return (int)window->getCursorVisibility();
286 }
287
288 GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle, int visible)
289 {
290   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
291
292   return window->setCursorVisibility(visible ? true : false);
293 }
294
295 GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
296                                        GHOST_TInt32 *x,
297                                        GHOST_TInt32 *y)
298 {
299   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
300
301   return system->getCursorPosition(*x, *y);
302 }
303
304 GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
305                                        GHOST_TInt32 x,
306                                        GHOST_TInt32 y)
307 {
308   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
309
310   return system->setCursorPosition(x, y);
311 }
312
313 GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
314                                    GHOST_TGrabCursorMode mode,
315                                    GHOST_TAxisFlag wrap_axis,
316                                    int bounds[4],
317                                    const int mouse_ungrab_xy[2])
318 {
319   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
320   GHOST_Rect bounds_rect;
321   GHOST_TInt32 mouse_xy[2];
322
323   if (bounds) {
324     bounds_rect = GHOST_Rect(bounds[0], bounds[1], bounds[2], bounds[3]);
325   }
326   if (mouse_ungrab_xy) {
327     mouse_xy[0] = mouse_ungrab_xy[0];
328     mouse_xy[1] = mouse_ungrab_xy[1];
329   }
330
331   return window->setCursorGrab(
332       mode, wrap_axis, bounds ? &bounds_rect : NULL, mouse_ungrab_xy ? mouse_xy : NULL);
333 }
334
335 GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
336                                          GHOST_TModifierKeyMask mask,
337                                          int *isDown)
338 {
339   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
340   GHOST_TSuccess result;
341   bool isdown = false;
342
343   result = system->getModifierKeyState(mask, isdown);
344   *isDown = (int)isdown;
345
346   return result;
347 }
348
349 GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
350                                     GHOST_TButtonMask mask,
351                                     int *isDown)
352 {
353   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
354   GHOST_TSuccess result;
355   bool isdown = false;
356
357   result = system->getButtonState(mask, isdown);
358   *isDown = (int)isdown;
359
360   return result;
361 }
362
363 #ifdef WITH_INPUT_NDOF
364 void GHOST_setNDOFDeadZone(float deadzone)
365 {
366   GHOST_ISystem *system = GHOST_ISystem::getSystem();
367   system->setNDOFDeadZone(deadzone);
368 }
369 #endif
370
371 void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept)
372 {
373   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
374
375   window->setAcceptDragOperation(canAccept);
376 }
377
378 GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
379 {
380   GHOST_IEvent *event = (GHOST_IEvent *)eventhandle;
381
382   return event->getType();
383 }
384
385 GHOST_TUns64 GHOST_GetEventTime(GHOST_EventHandle eventhandle)
386 {
387   GHOST_IEvent *event = (GHOST_IEvent *)eventhandle;
388
389   return event->getTime();
390 }
391
392 GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
393 {
394   GHOST_IEvent *event = (GHOST_IEvent *)eventhandle;
395
396   return (GHOST_WindowHandle)event->getWindow();
397 }
398
399 GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
400 {
401   GHOST_IEvent *event = (GHOST_IEvent *)eventhandle;
402
403   return event->getData();
404 }
405
406 GHOST_TimerProcPtr GHOST_GetTimerProc(GHOST_TimerTaskHandle timertaskhandle)
407 {
408   GHOST_ITimerTask *timertask = (GHOST_ITimerTask *)timertaskhandle;
409
410   return timertask->getTimerProc();
411 }
412
413 void GHOST_SetTimerProc(GHOST_TimerTaskHandle timertaskhandle, GHOST_TimerProcPtr timerproc)
414 {
415   GHOST_ITimerTask *timertask = (GHOST_ITimerTask *)timertaskhandle;
416
417   timertask->setTimerProc(timerproc);
418 }
419
420 GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle)
421 {
422   GHOST_ITimerTask *timertask = (GHOST_ITimerTask *)timertaskhandle;
423
424   return timertask->getUserData();
425 }
426
427 void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle, GHOST_TUserDataPtr userdata)
428 {
429   GHOST_ITimerTask *timertask = (GHOST_ITimerTask *)timertaskhandle;
430
431   timertask->setUserData(userdata);
432 }
433
434 int GHOST_GetValid(GHOST_WindowHandle windowhandle)
435 {
436   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
437
438   return (int)window->getValid();
439 }
440
441 GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle)
442 {
443   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
444
445   return window->getDrawingContextType();
446 }
447
448 GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
449                                            GHOST_TDrawingContextType type)
450 {
451   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
452
453   return window->setDrawingContextType(type);
454 }
455
456 void GHOST_SetTitle(GHOST_WindowHandle windowhandle, const char *title)
457 {
458   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
459
460   window->setTitle(title);
461 }
462
463 char *GHOST_GetTitle(GHOST_WindowHandle windowhandle)
464 {
465   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
466   STR_String title;
467
468   window->getTitle(title);
469
470   char *ctitle = (char *)malloc(title.Length() + 1);
471
472   if (ctitle == NULL) {
473     return NULL;
474   }
475
476   strcpy(ctitle, title.Ptr());
477
478   return ctitle;
479 }
480
481 GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle)
482 {
483   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
484   GHOST_Rect *rectangle = NULL;
485
486   rectangle = new GHOST_Rect();
487   window->getWindowBounds(*rectangle);
488
489   return (GHOST_RectangleHandle)rectangle;
490 }
491
492 GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
493 {
494   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
495   GHOST_Rect *rectangle = NULL;
496
497   rectangle = new GHOST_Rect();
498   window->getClientBounds(*rectangle);
499
500   return (GHOST_RectangleHandle)rectangle;
501 }
502
503 void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
504 {
505   delete (GHOST_Rect *)rectanglehandle;
506 }
507
508 GHOST_TSuccess GHOST_SetClientWidth(GHOST_WindowHandle windowhandle, GHOST_TUns32 width)
509 {
510   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
511
512   return window->setClientWidth(width);
513 }
514
515 GHOST_TSuccess GHOST_SetClientHeight(GHOST_WindowHandle windowhandle, GHOST_TUns32 height)
516 {
517   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
518
519   return window->setClientHeight(height);
520 }
521
522 GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle,
523                                    GHOST_TUns32 width,
524                                    GHOST_TUns32 height)
525 {
526   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
527
528   return window->setClientSize(width, height);
529 }
530
531 void GHOST_ScreenToClient(GHOST_WindowHandle windowhandle,
532                           GHOST_TInt32 inX,
533                           GHOST_TInt32 inY,
534                           GHOST_TInt32 *outX,
535                           GHOST_TInt32 *outY)
536 {
537   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
538
539   window->screenToClient(inX, inY, *outX, *outY);
540 }
541
542 void GHOST_ClientToScreen(GHOST_WindowHandle windowhandle,
543                           GHOST_TInt32 inX,
544                           GHOST_TInt32 inY,
545                           GHOST_TInt32 *outX,
546                           GHOST_TInt32 *outY)
547 {
548   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
549
550   window->clientToScreen(inX, inY, *outX, *outY);
551 }
552
553 GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle)
554 {
555   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
556
557   return window->getState();
558 }
559
560 GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle, GHOST_TWindowState state)
561 {
562   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
563
564   return window->setState(state);
565 }
566
567 GHOST_TSuccess GHOST_SetWindowModifiedState(GHOST_WindowHandle windowhandle,
568                                             GHOST_TUns8 isUnsavedChanges)
569 {
570   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
571
572   return window->setModifiedState(isUnsavedChanges);
573 }
574
575 GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle, GHOST_TWindowOrder order)
576 {
577   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
578
579   return window->setOrder(order);
580 }
581
582 GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
583 {
584   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
585
586   return window->swapBuffers();
587 }
588
589 GHOST_TSuccess GHOST_SetSwapInterval(GHOST_WindowHandle windowhandle, int interval)
590 {
591   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
592
593   return window->setSwapInterval(interval);
594 }
595
596 GHOST_TSuccess GHOST_GetSwapInterval(GHOST_WindowHandle windowhandle, int *intervalOut)
597 {
598   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
599
600   return window->getSwapInterval(*intervalOut);
601 }
602
603 GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
604 {
605   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
606
607   return window->activateDrawingContext();
608 }
609
610 GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
611 {
612   GHOST_IContext *context = (GHOST_IContext *)contexthandle;
613
614   return context->activateDrawingContext();
615 }
616
617 GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
618 {
619   GHOST_IContext *context = (GHOST_IContext *)contexthandle;
620
621   return context->releaseDrawingContext();
622 }
623
624 unsigned int GHOST_GetDefaultOpenGLFramebuffer(GHOST_WindowHandle windowhandle)
625 {
626   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
627
628   return window->getDefaultFramebuffer();
629 }
630
631 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
632 {
633   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
634
635   return window->invalidate();
636 }
637
638 void GHOST_SetTabletAPI(GHOST_SystemHandle systemhandle, GHOST_TTabletAPI api)
639 {
640   GHOST_ISystem *system = (GHOST_ISystem *)systemhandle;
641   system->setTabletAPI(api);
642 }
643
644 const GHOST_TabletData *GHOST_GetTabletData(GHOST_WindowHandle windowhandle)
645 {
646   return ((GHOST_IWindow *)windowhandle)->GetTabletData();
647 }
648
649 GHOST_TInt32 GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
650 {
651   return ((GHOST_Rect *)rectanglehandle)->getWidth();
652 }
653
654 GHOST_TInt32 GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle)
655 {
656   return ((GHOST_Rect *)rectanglehandle)->getHeight();
657 }
658
659 void GHOST_GetRectangle(GHOST_RectangleHandle rectanglehandle,
660                         GHOST_TInt32 *l,
661                         GHOST_TInt32 *t,
662                         GHOST_TInt32 *r,
663                         GHOST_TInt32 *b)
664 {
665   GHOST_Rect *rect = (GHOST_Rect *)rectanglehandle;
666
667   *l = rect->m_l;
668   *t = rect->m_t;
669   *r = rect->m_r;
670   *b = rect->m_b;
671 }
672
673 void GHOST_SetRectangle(GHOST_RectangleHandle rectanglehandle,
674                         GHOST_TInt32 l,
675                         GHOST_TInt32 t,
676                         GHOST_TInt32 r,
677                         GHOST_TInt32 b)
678 {
679   ((GHOST_Rect *)rectanglehandle)->set(l, t, r, b);
680 }
681
682 GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle)
683 {
684   GHOST_TSuccess result = GHOST_kFailure;
685
686   if (((GHOST_Rect *)rectanglehandle)->isEmpty())
687     result = GHOST_kSuccess;
688
689   return result;
690 }
691
692 GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle)
693 {
694   GHOST_TSuccess result = GHOST_kFailure;
695
696   if (((GHOST_Rect *)rectanglehandle)->isValid())
697     result = GHOST_kSuccess;
698
699   return result;
700 }
701
702 void GHOST_InsetRectangle(GHOST_RectangleHandle rectanglehandle, GHOST_TInt32 i)
703 {
704   ((GHOST_Rect *)rectanglehandle)->inset(i);
705 }
706
707 void GHOST_UnionRectangle(GHOST_RectangleHandle rectanglehandle,
708                           GHOST_RectangleHandle anotherrectanglehandle)
709 {
710   ((GHOST_Rect *)rectanglehandle)->unionRect(*(GHOST_Rect *)anotherrectanglehandle);
711 }
712
713 void GHOST_UnionPointRectangle(GHOST_RectangleHandle rectanglehandle,
714                                GHOST_TInt32 x,
715                                GHOST_TInt32 y)
716 {
717   ((GHOST_Rect *)rectanglehandle)->unionPoint(x, y);
718 }
719
720 GHOST_TSuccess GHOST_IsInsideRectangle(GHOST_RectangleHandle rectanglehandle,
721                                        GHOST_TInt32 x,
722                                        GHOST_TInt32 y)
723 {
724   GHOST_TSuccess result = GHOST_kFailure;
725
726   if (((GHOST_Rect *)rectanglehandle)->isInside(x, y))
727     result = GHOST_kSuccess;
728
729   return result;
730 }
731
732 GHOST_TVisibility GHOST_GetRectangleVisibility(GHOST_RectangleHandle rectanglehandle,
733                                                GHOST_RectangleHandle anotherrectanglehandle)
734 {
735   GHOST_TVisibility visible = GHOST_kNotVisible;
736
737   visible = ((GHOST_Rect *)rectanglehandle)->getVisibility(*(GHOST_Rect *)anotherrectanglehandle);
738
739   return visible;
740 }
741
742 void GHOST_SetCenterRectangle(GHOST_RectangleHandle rectanglehandle,
743                               GHOST_TInt32 cx,
744                               GHOST_TInt32 cy)
745 {
746   ((GHOST_Rect *)rectanglehandle)->setCenter(cx, cy);
747 }
748
749 void GHOST_SetRectangleCenter(GHOST_RectangleHandle rectanglehandle,
750                               GHOST_TInt32 cx,
751                               GHOST_TInt32 cy,
752                               GHOST_TInt32 w,
753                               GHOST_TInt32 h)
754 {
755   ((GHOST_Rect *)rectanglehandle)->setCenter(cx, cy, w, h);
756 }
757
758 GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
759                                    GHOST_RectangleHandle anotherrectanglehandle)
760 {
761   GHOST_TSuccess result = GHOST_kFailure;
762
763   if (((GHOST_Rect *)rectanglehandle)->clip(*(GHOST_Rect *)anotherrectanglehandle))
764     result = GHOST_kSuccess;
765
766   return result;
767 }
768
769 GHOST_TUns8 *GHOST_getClipboard(int selection)
770 {
771   GHOST_ISystem *system = GHOST_ISystem::getSystem();
772   return system->getClipboard(selection);
773 }
774
775 void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
776 {
777   GHOST_ISystem *system = GHOST_ISystem::getSystem();
778   system->putClipboard(buffer, selection);
779 }
780
781 int GHOST_toggleConsole(int action)
782 {
783   GHOST_ISystem *system = GHOST_ISystem::getSystem();
784   return system->toggleConsole(action);
785 }
786
787 int GHOST_UseNativePixels(void)
788 {
789   GHOST_ISystem *system = GHOST_ISystem::getSystem();
790   return system->useNativePixel();
791 }
792
793 void GHOST_UseWindowFocus(int use_focus)
794 {
795   GHOST_ISystem *system = GHOST_ISystem::getSystem();
796   return system->useWindowFocus(use_focus);
797 }
798
799 float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
800 {
801   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
802   if (window)
803     return window->getNativePixelSize();
804   return 1.0f;
805 }
806
807 GHOST_TUns16 GHOST_GetDPIHint(GHOST_WindowHandle windowhandle)
808 {
809   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
810   return window->getDPIHint();
811 }
812
813 #ifdef WITH_INPUT_IME
814
815 void GHOST_BeginIME(GHOST_WindowHandle windowhandle,
816                     GHOST_TInt32 x,
817                     GHOST_TInt32 y,
818                     GHOST_TInt32 w,
819                     GHOST_TInt32 h,
820                     int complete)
821 {
822   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
823   window->beginIME(x, y, w, h, complete);
824 }
825
826 void GHOST_EndIME(GHOST_WindowHandle windowhandle)
827 {
828   GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
829   window->endIME();
830 }
831
832 #endif /* WITH_INPUT_IME */