Merge branch 'master' into blender2.8
[blender.git] / intern / ghost / intern / GHOST_C-api.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_C-api.cpp
29  *  \ingroup GHOST
30  *
31  * C Api for GHOST
32  */
33
34 #include <stdlib.h>
35
36 #include "intern/GHOST_Debug.h"
37 #include "GHOST_C-api.h"
38 #include "GHOST_ISystem.h"
39 #include "GHOST_IEvent.h"
40 #include "GHOST_IEventConsumer.h"
41 #include "intern/GHOST_CallbackEventConsumer.h"
42
43 GHOST_SystemHandle GHOST_CreateSystem(void)
44 {
45         GHOST_ISystem::createSystem();
46         GHOST_ISystem *system = GHOST_ISystem::getSystem();
47
48         return (GHOST_SystemHandle)system;
49 }
50
51
52
53 GHOST_TSuccess GHOST_DisposeSystem(GHOST_SystemHandle systemhandle)
54 {
55         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
56
57         return system->disposeSystem();
58 }
59
60
61 GHOST_EventConsumerHandle GHOST_CreateEventConsumer(GHOST_EventCallbackProcPtr eventCallback,
62                                                     GHOST_TUserDataPtr userdata)
63 {
64         return (GHOST_EventConsumerHandle) new GHOST_CallbackEventConsumer(eventCallback, userdata);
65 }
66
67
68 GHOST_TSuccess GHOST_DisposeEventConsumer(GHOST_EventConsumerHandle consumerhandle)
69 {
70         delete ((GHOST_CallbackEventConsumer *)consumerhandle);
71         return GHOST_kSuccess;
72 }
73
74
75 GHOST_TUns64 GHOST_GetMilliSeconds(GHOST_SystemHandle systemhandle)
76 {
77         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
78
79         return system->getMilliSeconds();
80 }
81
82
83
84 GHOST_TimerTaskHandle GHOST_InstallTimer(GHOST_SystemHandle systemhandle,
85                                          GHOST_TUns64 delay,
86                                          GHOST_TUns64 interval,
87                                          GHOST_TimerProcPtr timerproc,
88                                          GHOST_TUserDataPtr userdata)
89 {
90         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
91
92         return (GHOST_TimerTaskHandle) system->installTimer(delay, interval, timerproc, userdata);
93 }
94
95
96
97 GHOST_TSuccess GHOST_RemoveTimer(GHOST_SystemHandle systemhandle,
98                                  GHOST_TimerTaskHandle timertaskhandle)
99 {
100         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
101         GHOST_ITimerTask *timertask = (GHOST_ITimerTask *) timertaskhandle;
102
103         return system->removeTimer(timertask);
104 }
105
106
107
108 GHOST_TUns8 GHOST_GetNumDisplays(GHOST_SystemHandle systemhandle)
109 {
110         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
111
112         return system->getNumDisplays();
113 }
114
115
116
117 void GHOST_GetMainDisplayDimensions(GHOST_SystemHandle systemhandle,
118                                     GHOST_TUns32 *width,
119                                     GHOST_TUns32 *height)
120 {
121         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
122
123         system->getMainDisplayDimensions(*width, *height);
124 }
125
126 void GHOST_GetAllDisplayDimensions(GHOST_SystemHandle systemhandle,
127                                     GHOST_TUns32 *width,
128                                     GHOST_TUns32 *height)
129 {
130         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
131
132         system->getAllDisplayDimensions(*width, *height);
133 }
134
135 GHOST_ContextHandle GHOST_CreateOpenGLContext(GHOST_SystemHandle systemhandle)
136 {
137         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
138
139         return (GHOST_ContextHandle) system->createOffscreenContext();
140 }
141
142 GHOST_TSuccess GHOST_DisposeOpenGLContext(GHOST_SystemHandle systemhandle,
143                                              GHOST_ContextHandle contexthandle)
144 {
145         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
146         GHOST_IContext *context = (GHOST_IContext *) contexthandle;
147
148         return system->disposeContext(context);
149 }
150
151 GHOST_WindowHandle GHOST_CreateWindow(GHOST_SystemHandle systemhandle,
152                                       const char *title,
153                                       GHOST_TInt32 left,
154                                       GHOST_TInt32 top,
155                                       GHOST_TUns32 width,
156                                       GHOST_TUns32 height,
157                                       GHOST_TWindowState state,
158                                       GHOST_TDrawingContextType type,
159                                       GHOST_GLSettings glSettings)
160 {
161         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
162
163         return (GHOST_WindowHandle) system->createWindow(title, left, top, width, height,
164                                                          state, type, glSettings, false);
165 }
166
167 GHOST_TUserDataPtr GHOST_GetWindowUserData(GHOST_WindowHandle windowhandle)
168 {
169         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
170
171         return window->getUserData();
172 }
173 void GHOST_SetWindowUserData(GHOST_WindowHandle windowhandle, GHOST_TUserDataPtr userdata)
174 {
175         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
176
177         window->setUserData(userdata);
178 }
179
180 GHOST_TSuccess GHOST_DisposeWindow(GHOST_SystemHandle systemhandle,
181                                    GHOST_WindowHandle windowhandle)
182 {
183         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
184         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
185
186         return system->disposeWindow(window);
187 }
188
189
190
191 int GHOST_ValidWindow(GHOST_SystemHandle systemhandle,
192                       GHOST_WindowHandle windowhandle)
193 {
194         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
195         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
196
197         return (int) system->validWindow(window);
198 }
199
200
201
202 GHOST_WindowHandle GHOST_BeginFullScreen(GHOST_SystemHandle systemhandle,
203                                          GHOST_DisplaySetting *setting,
204                                          const int stereoVisual)
205 {
206         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
207         GHOST_IWindow *window = NULL;
208         bool bstereoVisual;
209
210         if (stereoVisual)
211                 bstereoVisual = true;
212         else
213                 bstereoVisual = false;
214
215         system->beginFullScreen(*setting, &window, bstereoVisual);
216
217         return (GHOST_WindowHandle)window;
218 }
219
220
221
222 GHOST_TSuccess GHOST_EndFullScreen(GHOST_SystemHandle systemhandle)
223 {
224         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
225
226         return system->endFullScreen();
227 }
228
229
230
231 int GHOST_GetFullScreen(GHOST_SystemHandle systemhandle)
232 {
233         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
234
235         return (int) system->getFullScreen();
236 }
237
238
239
240 int GHOST_ProcessEvents(GHOST_SystemHandle systemhandle, int waitForEvent)
241 {
242         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
243
244         return (int) system->processEvents(waitForEvent ? true : false);
245 }
246
247
248
249 void GHOST_DispatchEvents(GHOST_SystemHandle systemhandle)
250 {
251         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
252
253         system->dispatchEvents();
254 }
255
256
257 GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
258 {
259         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
260
261         return system->addEventConsumer((GHOST_CallbackEventConsumer *)consumerhandle);
262 }
263
264 GHOST_TSuccess GHOST_RemoveEventConsumer(GHOST_SystemHandle systemhandle, GHOST_EventConsumerHandle consumerhandle)
265 {
266         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
267
268         return system->removeEventConsumer((GHOST_CallbackEventConsumer *)consumerhandle);
269 }
270
271 GHOST_TSuccess GHOST_SetProgressBar(GHOST_WindowHandle windowhandle, float progress)
272 {
273         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
274
275         return window->setProgressBar(progress);
276 }
277
278 GHOST_TSuccess GHOST_EndProgressBar(GHOST_WindowHandle windowhandle)
279 {
280         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
281
282         return window->endProgressBar();
283 }
284
285
286 GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle)
287 {
288         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
289
290         return window->getCursorShape();
291 }
292
293
294
295 GHOST_TSuccess GHOST_SetCursorShape(GHOST_WindowHandle windowhandle,
296                                     GHOST_TStandardCursor cursorshape)
297 {
298         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
299
300         return window->setCursorShape(cursorshape);
301 }
302
303 GHOST_TSuccess GHOST_SetCustomCursorShape(GHOST_WindowHandle windowhandle,
304                                           GHOST_TUns8 bitmap[16][2],
305                                           GHOST_TUns8 mask[16][2],
306                                           int hotX,
307                                           int hotY)
308 {
309         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
310
311         return window->setCustomCursorShape(bitmap, mask, hotX, hotY);
312 }
313
314 GHOST_TSuccess GHOST_SetCustomCursorShapeEx(GHOST_WindowHandle windowhandle,
315                                             GHOST_TUns8 *bitmap,
316                                             GHOST_TUns8 *mask,
317                                             int sizex,
318                                             int sizey,
319                                             int hotX,
320                                             int hotY,
321                                             int fg_color,
322                                             int bg_color)
323 {
324         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
325
326         return window->setCustomCursorShape(bitmap, mask, sizex, sizey,
327                                             hotX, hotY, fg_color, bg_color);
328 }
329
330
331
332 int GHOST_GetCursorVisibility(GHOST_WindowHandle windowhandle)
333 {
334         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
335
336         return (int) window->getCursorVisibility();
337 }
338
339
340
341 GHOST_TSuccess GHOST_SetCursorVisibility(GHOST_WindowHandle windowhandle,
342                                          int visible)
343 {
344         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
345
346         return window->setCursorVisibility(visible ? true : false);
347 }
348
349
350
351 GHOST_TSuccess GHOST_GetCursorPosition(GHOST_SystemHandle systemhandle,
352                                        GHOST_TInt32 *x,
353                                        GHOST_TInt32 *y)
354 {
355         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
356
357         return system->getCursorPosition(*x, *y);
358 }
359
360
361
362 GHOST_TSuccess GHOST_SetCursorPosition(GHOST_SystemHandle systemhandle,
363                                        GHOST_TInt32 x,
364                                        GHOST_TInt32 y)
365 {
366         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
367
368         return system->setCursorPosition(x, y);
369 }
370
371
372 GHOST_TSuccess GHOST_SetCursorGrab(GHOST_WindowHandle windowhandle,
373                                    GHOST_TGrabCursorMode mode,
374                                    int bounds[4], const int mouse_ungrab_xy[2])
375 {
376         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
377         GHOST_Rect bounds_rect;
378         GHOST_TInt32 mouse_xy[2];
379
380         if (bounds) {
381                 bounds_rect = GHOST_Rect(bounds[0], bounds[1], bounds[2], bounds[3]);
382         }
383         if (mouse_ungrab_xy) {
384                 mouse_xy[0] = mouse_ungrab_xy[0];
385                 mouse_xy[1] = mouse_ungrab_xy[1];
386         }
387
388         return window->setCursorGrab(mode,
389                                      bounds ? &bounds_rect : NULL,
390                                      mouse_ungrab_xy ? mouse_xy : NULL);
391 }
392
393
394 GHOST_TSuccess GHOST_GetModifierKeyState(GHOST_SystemHandle systemhandle,
395                                          GHOST_TModifierKeyMask mask,
396                                          int *isDown)
397 {
398         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
399         GHOST_TSuccess result;
400         bool isdown = false;
401
402         result = system->getModifierKeyState(mask, isdown);
403         *isDown = (int) isdown;
404
405         return result;
406 }
407
408
409
410 GHOST_TSuccess GHOST_GetButtonState(GHOST_SystemHandle systemhandle,
411                                     GHOST_TButtonMask mask,
412                                     int *isDown)
413 {
414         GHOST_ISystem *system = (GHOST_ISystem *) systemhandle;
415         GHOST_TSuccess result;
416         bool isdown = false;
417
418         result = system->getButtonState(mask, isdown);
419         *isDown = (int) isdown;
420
421         return result;
422 }
423
424
425 #ifdef WITH_INPUT_NDOF
426 void GHOST_setNDOFDeadZone(float deadzone)
427 {
428         GHOST_ISystem *system = GHOST_ISystem::getSystem();
429         system->setNDOFDeadZone(deadzone);
430 }
431 #endif
432
433 void GHOST_setAcceptDragOperation(GHOST_WindowHandle windowhandle, GHOST_TInt8 canAccept)
434 {
435         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
436
437         window->setAcceptDragOperation(canAccept);
438 }
439
440
441 GHOST_TEventType GHOST_GetEventType(GHOST_EventHandle eventhandle)
442 {
443         GHOST_IEvent *event = (GHOST_IEvent *) eventhandle;
444
445         return event->getType();
446 }
447
448
449
450 GHOST_TUns64 GHOST_GetEventTime(GHOST_EventHandle eventhandle)
451 {
452         GHOST_IEvent *event = (GHOST_IEvent *) eventhandle;
453
454         return event->getTime();
455 }
456
457
458 GHOST_WindowHandle GHOST_GetEventWindow(GHOST_EventHandle eventhandle)
459 {
460         GHOST_IEvent *event = (GHOST_IEvent *) eventhandle;
461
462         return (GHOST_WindowHandle) event->getWindow();
463 }
464
465
466 GHOST_TEventDataPtr GHOST_GetEventData(GHOST_EventHandle eventhandle)
467 {
468         GHOST_IEvent *event = (GHOST_IEvent *) eventhandle;
469
470         return event->getData();
471 }
472
473
474
475 GHOST_TimerProcPtr GHOST_GetTimerProc(GHOST_TimerTaskHandle timertaskhandle)
476 {
477         GHOST_ITimerTask *timertask = (GHOST_ITimerTask *) timertaskhandle;
478
479         return timertask->getTimerProc();
480 }
481
482
483
484 void GHOST_SetTimerProc(GHOST_TimerTaskHandle timertaskhandle,
485                         GHOST_TimerProcPtr timerproc)
486 {
487         GHOST_ITimerTask *timertask = (GHOST_ITimerTask *) timertaskhandle;
488
489         timertask->setTimerProc(timerproc);
490 }
491
492
493
494 GHOST_TUserDataPtr GHOST_GetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle)
495 {
496         GHOST_ITimerTask *timertask = (GHOST_ITimerTask *) timertaskhandle;
497
498         return timertask->getUserData();
499 }
500
501
502
503 void GHOST_SetTimerTaskUserData(GHOST_TimerTaskHandle timertaskhandle,
504                                 GHOST_TUserDataPtr userdata)
505 {
506         GHOST_ITimerTask *timertask = (GHOST_ITimerTask *) timertaskhandle;
507
508         timertask->setUserData(userdata);
509 }
510
511
512
513 int GHOST_GetValid(GHOST_WindowHandle windowhandle)
514 {
515         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
516
517         return (int) window->getValid();
518 }
519
520
521
522 GHOST_TDrawingContextType GHOST_GetDrawingContextType(GHOST_WindowHandle windowhandle)
523 {
524         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
525
526         return window->getDrawingContextType();
527 }
528
529
530
531 GHOST_TSuccess GHOST_SetDrawingContextType(GHOST_WindowHandle windowhandle,
532                                            GHOST_TDrawingContextType type)
533 {
534         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
535
536         return window->setDrawingContextType(type);
537 }
538
539
540
541 void GHOST_SetTitle(GHOST_WindowHandle windowhandle,
542                     const char *title)
543 {
544         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
545
546         window->setTitle(title);
547 }
548
549
550 char *GHOST_GetTitle(GHOST_WindowHandle windowhandle)
551 {
552         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
553         STR_String title;
554
555         window->getTitle(title);
556
557         char *ctitle = (char *) malloc(title.Length() + 1);
558
559         if (ctitle == NULL) {
560                 return NULL;
561         }
562
563         strcpy(ctitle, title.Ptr());
564
565         return ctitle;
566 }
567
568
569
570 GHOST_RectangleHandle GHOST_GetWindowBounds(GHOST_WindowHandle windowhandle)
571 {
572         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
573         GHOST_Rect *rectangle = NULL;
574
575         rectangle = new GHOST_Rect();
576         window->getWindowBounds(*rectangle);
577
578         return (GHOST_RectangleHandle)rectangle;
579 }
580
581
582
583 GHOST_RectangleHandle GHOST_GetClientBounds(GHOST_WindowHandle windowhandle)
584 {
585         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
586         GHOST_Rect *rectangle = NULL;
587
588         rectangle = new GHOST_Rect();
589         window->getClientBounds(*rectangle);
590
591         return (GHOST_RectangleHandle)rectangle;
592 }
593
594
595
596 void GHOST_DisposeRectangle(GHOST_RectangleHandle rectanglehandle)
597 {
598         delete (GHOST_Rect *) rectanglehandle;
599 }
600
601
602
603 GHOST_TSuccess GHOST_SetClientWidth(GHOST_WindowHandle windowhandle,
604                                     GHOST_TUns32 width)
605 {
606         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
607
608         return window->setClientWidth(width);
609 }
610
611
612
613 GHOST_TSuccess GHOST_SetClientHeight(GHOST_WindowHandle windowhandle,
614                                      GHOST_TUns32 height)
615 {
616         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
617
618         return window->setClientHeight(height);
619 }
620
621
622
623 GHOST_TSuccess GHOST_SetClientSize(GHOST_WindowHandle windowhandle,
624                                    GHOST_TUns32 width,
625                                    GHOST_TUns32 height)
626 {
627         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
628
629         return window->setClientSize(width, height);
630 }
631
632
633
634 void GHOST_ScreenToClient(GHOST_WindowHandle windowhandle,
635                           GHOST_TInt32 inX,
636                           GHOST_TInt32 inY,
637                           GHOST_TInt32 *outX,
638                           GHOST_TInt32 *outY)
639 {
640         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
641
642         window->screenToClient(inX, inY, *outX, *outY);
643 }
644
645
646
647 void GHOST_ClientToScreen(GHOST_WindowHandle windowhandle,
648                           GHOST_TInt32 inX,
649                           GHOST_TInt32 inY,
650                           GHOST_TInt32 *outX,
651                           GHOST_TInt32 *outY)
652 {
653         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
654
655         window->clientToScreen(inX, inY, *outX, *outY);
656 }
657
658
659
660 GHOST_TWindowState GHOST_GetWindowState(GHOST_WindowHandle windowhandle)
661 {
662         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
663
664         return window->getState();
665 }
666
667
668
669 GHOST_TSuccess GHOST_SetWindowState(GHOST_WindowHandle windowhandle,
670                                     GHOST_TWindowState state)
671 {
672         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
673
674         return window->setState(state);
675 }
676
677
678 GHOST_TSuccess GHOST_SetWindowModifiedState(GHOST_WindowHandle windowhandle, GHOST_TUns8 isUnsavedChanges)
679 {
680         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
681
682         return window->setModifiedState(isUnsavedChanges);
683 }
684
685
686 GHOST_TSuccess GHOST_SetWindowOrder(GHOST_WindowHandle windowhandle,
687                                     GHOST_TWindowOrder order)
688 {
689         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
690
691         return window->setOrder(order);
692 }
693
694
695
696 GHOST_TSuccess GHOST_SwapWindowBuffers(GHOST_WindowHandle windowhandle)
697 {
698         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
699
700         return window->swapBuffers();
701 }
702
703 GHOST_TSuccess GHOST_SetSwapInterval(GHOST_WindowHandle windowhandle, int interval)
704 {
705         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
706
707         return window->setSwapInterval(interval);
708 }
709
710 GHOST_TSuccess GHOST_GetSwapInterval(GHOST_WindowHandle windowhandle, int* intervalOut)
711 {
712         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
713
714         return window->getSwapInterval(*intervalOut);
715 }
716
717
718 GHOST_TUns16 GHOST_GetNumOfAASamples(GHOST_WindowHandle windowhandle)
719 {
720         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
721
722         return window->getNumOfAASamples();
723 }
724
725 GHOST_TSuccess GHOST_ActivateWindowDrawingContext(GHOST_WindowHandle windowhandle)
726 {
727         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
728
729         return window->activateDrawingContext();
730 }
731
732 GHOST_TSuccess GHOST_ActivateOpenGLContext(GHOST_ContextHandle contexthandle)
733 {
734         GHOST_IContext *context = (GHOST_IContext *) contexthandle;
735
736         return context->activateDrawingContext();
737 }
738
739 GHOST_TSuccess GHOST_ReleaseOpenGLContext(GHOST_ContextHandle contexthandle)
740 {
741         GHOST_IContext *context = (GHOST_IContext *) contexthandle;
742
743         return context->releaseDrawingContext();
744 }
745
746 GHOST_TSuccess GHOST_InvalidateWindow(GHOST_WindowHandle windowhandle)
747 {
748         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
749
750         return window->invalidate();
751 }
752
753
754 extern const GHOST_TabletData *GHOST_GetTabletData(GHOST_WindowHandle windowhandle)
755 {
756         return ((GHOST_IWindow *)windowhandle)->GetTabletData();
757 }
758
759
760 GHOST_TInt32 GHOST_GetWidthRectangle(GHOST_RectangleHandle rectanglehandle)
761 {
762         return ((GHOST_Rect *)rectanglehandle)->getWidth();
763 }
764
765
766
767 GHOST_TInt32 GHOST_GetHeightRectangle(GHOST_RectangleHandle rectanglehandle)
768 {
769         return ((GHOST_Rect *)rectanglehandle)->getHeight();
770 }
771
772
773
774 void GHOST_GetRectangle(GHOST_RectangleHandle rectanglehandle,
775                         GHOST_TInt32 *l,
776                         GHOST_TInt32 *t,
777                         GHOST_TInt32 *r,
778                         GHOST_TInt32 *b)
779 {
780         GHOST_Rect *rect = (GHOST_Rect *) rectanglehandle;
781
782         *l = rect->m_l;
783         *t = rect->m_t;
784         *r = rect->m_r;
785         *b = rect->m_b;
786 }
787
788
789 void GHOST_SetRectangle(GHOST_RectangleHandle rectanglehandle,
790                         GHOST_TInt32 l,
791                         GHOST_TInt32 t,
792                         GHOST_TInt32 r,
793                         GHOST_TInt32 b)
794 {
795         ((GHOST_Rect *)rectanglehandle)->set(l, t, r, b);
796 }
797
798
799
800 GHOST_TSuccess GHOST_IsEmptyRectangle(GHOST_RectangleHandle rectanglehandle)
801 {
802         GHOST_TSuccess result = GHOST_kFailure;
803
804         if (((GHOST_Rect *)rectanglehandle)->isEmpty())
805                 result = GHOST_kSuccess;
806
807         return result;
808 }
809
810
811
812 GHOST_TSuccess GHOST_IsValidRectangle(GHOST_RectangleHandle rectanglehandle)
813 {
814         GHOST_TSuccess result = GHOST_kFailure;
815
816         if (((GHOST_Rect *)rectanglehandle)->isValid())
817                 result = GHOST_kSuccess;
818
819         return result;
820 }
821
822
823
824 void GHOST_InsetRectangle(GHOST_RectangleHandle rectanglehandle,
825                           GHOST_TInt32 i)
826 {
827         ((GHOST_Rect *)rectanglehandle)->inset(i);
828 }
829
830
831
832 void GHOST_UnionRectangle(GHOST_RectangleHandle rectanglehandle,
833                           GHOST_RectangleHandle anotherrectanglehandle)
834 {
835         ((GHOST_Rect *)rectanglehandle)->unionRect(*(GHOST_Rect *)anotherrectanglehandle);
836 }
837
838
839
840 void GHOST_UnionPointRectangle(GHOST_RectangleHandle rectanglehandle,
841                                GHOST_TInt32 x,
842                                GHOST_TInt32 y)
843 {
844         ((GHOST_Rect *)rectanglehandle)->unionPoint(x, y);
845 }
846
847
848
849 GHOST_TSuccess GHOST_IsInsideRectangle(GHOST_RectangleHandle rectanglehandle,
850                                        GHOST_TInt32 x,
851                                        GHOST_TInt32 y)
852 {
853         GHOST_TSuccess result = GHOST_kFailure;
854
855         if (((GHOST_Rect *)rectanglehandle)->isInside(x, y))
856                 result = GHOST_kSuccess;
857
858         return result;
859 }
860
861
862
863 GHOST_TVisibility GHOST_GetRectangleVisibility(GHOST_RectangleHandle rectanglehandle,
864                                                GHOST_RectangleHandle anotherrectanglehandle)
865 {
866         GHOST_TVisibility visible = GHOST_kNotVisible;
867
868         visible = ((GHOST_Rect *)rectanglehandle)->getVisibility(*(GHOST_Rect *)anotherrectanglehandle);
869
870         return visible;
871 }
872
873
874
875 void GHOST_SetCenterRectangle(GHOST_RectangleHandle rectanglehandle,
876                               GHOST_TInt32 cx,
877                               GHOST_TInt32 cy)
878 {
879         ((GHOST_Rect *)rectanglehandle)->setCenter(cx, cy);
880 }
881
882
883
884 void GHOST_SetRectangleCenter(GHOST_RectangleHandle rectanglehandle,
885                               GHOST_TInt32 cx,
886                               GHOST_TInt32 cy,
887                               GHOST_TInt32 w,
888                               GHOST_TInt32 h)
889 {
890         ((GHOST_Rect *)rectanglehandle)->setCenter(cx, cy, w, h);
891 }
892
893
894
895 GHOST_TSuccess GHOST_ClipRectangle(GHOST_RectangleHandle rectanglehandle,
896                                    GHOST_RectangleHandle anotherrectanglehandle)
897 {
898         GHOST_TSuccess result = GHOST_kFailure;
899
900         if (((GHOST_Rect *)rectanglehandle)->clip(*(GHOST_Rect *)anotherrectanglehandle))
901                 result = GHOST_kSuccess;
902
903         return result;
904 }
905
906 GHOST_TUns8 *GHOST_getClipboard(int selection)
907 {
908         GHOST_ISystem *system = GHOST_ISystem::getSystem();
909         return system->getClipboard(selection);
910 }
911
912 void GHOST_putClipboard(GHOST_TInt8 *buffer, int selection)
913 {
914         GHOST_ISystem *system = GHOST_ISystem::getSystem();
915         system->putClipboard(buffer, selection);
916 }
917
918 int GHOST_toggleConsole(int action)
919 {
920         GHOST_ISystem *system = GHOST_ISystem::getSystem();
921         return system->toggleConsole(action);
922 }
923
924 int GHOST_SupportsNativeDialogs(void)
925 {
926         GHOST_ISystem *system = GHOST_ISystem::getSystem();
927         return system->supportsNativeDialogs();
928 }
929
930 int GHOST_confirmQuit(GHOST_WindowHandle windowhandle)
931 {
932         GHOST_ISystem *system = GHOST_ISystem::getSystem();
933         return system->confirmQuit((GHOST_IWindow *) windowhandle);
934 }
935
936 int GHOST_UseNativePixels(void)
937 {
938         GHOST_ISystem *system = GHOST_ISystem::getSystem();
939         return system->useNativePixel();
940 }
941
942 float GHOST_GetNativePixelSize(GHOST_WindowHandle windowhandle)
943 {
944         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
945         if (window)
946                 return window->getNativePixelSize();
947         return 1.0f;
948 }
949
950 GHOST_TUns16 GHOST_GetDPIHint(GHOST_WindowHandle windowhandle)
951 {
952         GHOST_IWindow *window = (GHOST_IWindow *)windowhandle;
953         return window->getDPIHint();
954 }
955
956 #ifdef WITH_INPUT_IME
957
958 void GHOST_BeginIME(GHOST_WindowHandle windowhandle,
959                     GHOST_TInt32 x, GHOST_TInt32 y,
960                     GHOST_TInt32 w, GHOST_TInt32 h,
961                     int complete)
962 {
963         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
964         window->beginIME(x, y, w, h, complete);
965 }
966
967 void GHOST_EndIME(GHOST_WindowHandle windowhandle)
968 {
969         GHOST_IWindow *window = (GHOST_IWindow *) windowhandle;
970         window->endIME();
971 }
972
973 #endif  /* WITH_INPUT_IME */