3 * ***** BEGIN GPL LICENSE BLOCK *****
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.
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.
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.
19 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20 * All rights reserved.
22 * The Original Code is: all of this file.
24 * Contributor(s): Maarten Gribnau 05/2001
25 * Damien Plisson 09/2009
27 * ***** END GPL LICENSE BLOCK *****
30 * @file GHOST_SystemCocoa.h
31 * Declaration of GHOST_SystemCocoa class.
34 #ifndef _GHOST_SYSTEM_COCOA_H_
35 #define _GHOST_SYSTEM_COCOA_H_
38 #error Apple OSX only!
41 //#define __CARBONSOUND__
44 #include "GHOST_System.h"
46 class GHOST_EventCursor;
48 class GHOST_EventWindow;
51 class GHOST_SystemCocoa : public GHOST_System {
63 /***************************************************************************************
64 ** Time(r) functionality
65 ***************************************************************************************/
68 * Returns the system time.
69 * Returns the number of milliseconds since the start of the system process.
70 * Based on ANSI clock() routine.
71 * @return The number of milliseconds.
73 virtual GHOST_TUns64 getMilliSeconds() const;
75 /***************************************************************************************
76 ** Display/window management functionality
77 ***************************************************************************************/
80 * Returns the number of displays on this system.
81 * @return The number of displays.
83 virtual GHOST_TUns8 getNumDisplays() const;
86 * Returns the dimensions of the main display on this system.
87 * @return The dimension of the main display.
89 virtual void getMainDisplayDimensions(GHOST_TUns32& width, GHOST_TUns32& height) const;
92 * Create a new window.
93 * The new window is added to the list of windows managed.
94 * Never explicitly delete the window, use disposeWindow() instead.
95 * @param title The name of the window (displayed in the title bar of the window if the OS supports it).
96 * @param left The coordinate of the left edge of the window.
97 * @param top The coordinate of the top edge of the window.
98 * @param width The width the window.
99 * @param height The height the window.
100 * @param state The state of the window when opened.
101 * @param type The type of drawing context installed in this window.
102 * @param parentWindow Parent (embedder) window
103 * @return The new window (or 0 if creation failed).
105 virtual GHOST_IWindow* createWindow(
106 const STR_String& title,
111 GHOST_TWindowState state,
112 GHOST_TDrawingContextType type,
113 const bool stereoVisual,
114 const GHOST_TEmbedderWindowID parentWindow = 0
117 virtual GHOST_TSuccess beginFullScreen(
118 const GHOST_DisplaySetting& setting,
119 GHOST_IWindow** window,
120 const bool stereoVisual
123 virtual GHOST_TSuccess endFullScreen( void );
125 /***************************************************************************************
126 ** Event management functionality
127 ***************************************************************************************/
130 * Gets events from the system and stores them in the queue.
131 * @param waitForEvent Flag to wait for an event (or return immediately).
132 * @return Indication of the presence of events.
134 virtual bool processEvents(bool waitForEvent);
136 /***************************************************************************************
137 ** Cursor management functionality
138 ***************************************************************************************/
141 * Returns the current location of the cursor (location in screen coordinates)
142 * @param x The x-coordinate of the cursor.
143 * @param y The y-coordinate of the cursor.
144 * @return Indication of success.
146 virtual GHOST_TSuccess getCursorPosition(GHOST_TInt32& x, GHOST_TInt32& y) const;
149 * Updates the location of the cursor (location in screen coordinates).
150 * @param x The x-coordinate of the cursor.
151 * @param y The y-coordinate of the cursor.
152 * @return Indication of success.
154 virtual GHOST_TSuccess setCursorPosition(GHOST_TInt32 x, GHOST_TInt32 y) const;
156 /***************************************************************************************
157 ** Access to mouse button and keyboard states.
158 ***************************************************************************************/
161 * Returns the state of all modifier keys.
162 * @param keys The state of all modifier keys (true == pressed).
163 * @return Indication of success.
165 virtual GHOST_TSuccess getModifierKeys(GHOST_ModifierKeys& keys) const;
168 * Returns the state of the mouse buttons (ouside the message queue).
169 * @param buttons The state of the buttons.
170 * @return Indication of success.
172 virtual GHOST_TSuccess getButtons(GHOST_Buttons& buttons) const;
175 * Returns Clipboard data
176 * @param selection Indicate which buffer to return
177 * @return Returns the selected buffer
179 virtual GHOST_TUns8* getClipboard(bool selection) const;
182 * Puts buffer to system clipboard
183 * @param buffer The buffer to be copied
184 * @param selection Indicates which buffer to copy too, only used on X11
186 virtual void putClipboard(GHOST_TInt8 *buffer, bool selection) const;
190 * Initializes the system.
191 * For now, it justs registers the window class (WNDCLASS).
192 * @return A success value.
194 virtual GHOST_TSuccess init();
197 * Closes the system down.
198 * @return A success value.
200 virtual GHOST_TSuccess exit();
204 * Handles a tablet event.
205 * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
206 * @return Indication whether the event was handled.
208 int handleTabletEvent(void *eventPtr);
210 * Handles a mouse event.
211 * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
212 * @return Indication whether the event was handled.
214 int handleMouseEvent(void *eventPtr);
217 * Handles a key event.
218 * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
219 * @return Indication whether the event was handled.
221 int handleKeyEvent(void *eventPtr);
224 * Handles a window event.
225 * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
226 * @return Indication whether the event was handled.
228 int handleWindowEvent(void *eventPtr);
231 * Handles all basic Mac application stuff for a mouse down event.
232 * @param eventPtr An NSEvent pointer (casted to void* to enable compilation in standard C++)
233 * @return Indication whether the event was handled.
235 // bool handleMouseDown(void *eventPtr);
238 * Handles a Mac menu command.
239 * @param menuResult A Mac menu/item identifier.
240 * @return Indication whether the event was handled.
242 // bool handleMenuCommand(GHOST_TInt32 menuResult);
244 /* callback for blender generated events */
245 // static OSStatus blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData);
249 * Callback for Mac Timer tasks that expire.
250 * @param tmTask Pointer to the timer task that expired.
252 //static void s_timerCallback(TMTaskPtr tmTask);
254 /** Cocoa autoReleasePool (void*) used for enablign standard C++ compilation */
255 void* m_autoReleasePool;
257 /** Event handler reference. */
258 //EventHandlerRef m_handler;
260 /** Start time at initialization. */
261 GHOST_TUns64 m_start_time;
263 /** Mouse buttons state */
264 GHOST_TUns32 m_pressedMouseButtons;
266 /** State of the modifiers. */
267 GHOST_TUns32 m_modifierMask;
269 /** Ignores window size messages (when window is dragged). */
270 bool m_ignoreWindowSizedMessages;
273 #endif // _GHOST_SYSTEM_COCOA_H_