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): none yet.
26 * ***** END GPL LICENSE BLOCK *****
29 * @file GHOST_WindowCocoa.h
30 * Declaration of GHOST_WindowCocoa class.
33 #ifndef _GHOST_WINDOW_COCOA_H_
34 #define _GHOST_WINDOW_COCOA_H_
37 #error Apple OSX only!
40 #include "GHOST_Window.h"
41 #include "STR_String.h"
47 * Window on Mac OSX/Cocoa.
48 * Carbon windows have a size widget in the lower right corner of the window.
49 * To force it to be visible, the height of the client rectangle is reduced so
50 * that applications do not draw in that area. GHOST will manage that area
51 * which is called the gutter.
52 * When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
53 * OpenGL drawing outside the reduced client rectangle.
54 * @author Maarten Gribnau
57 class GHOST_WindowCocoa : public GHOST_Window {
61 * Creates a new window and opens it.
62 * To check if the window was created properly, use the getValid() method.
63 * @param title The text shown in the title bar of the window.
64 * @param left The coordinate of the left edge of the window.
65 * @param top The coordinate of the top edge of the window.
66 * @param width The width the window.
67 * @param height The height the window.
68 * @param state The state the window is initially opened with.
69 * @param type The type of drawing context installed in this window.
70 * @param stereoVisual Stereo visual for quad buffered stereo.
73 const STR_String& title,
78 GHOST_TWindowState state,
79 GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
80 const bool stereoVisual = false
85 * Closes the window and disposes resources allocated.
87 virtual ~GHOST_WindowCocoa();
90 * Returns indication as to whether the window is valid.
91 * @return The validity of the window.
93 virtual bool getValid() const;
96 * Sets the title displayed in the title bar.
97 * @param title The title to display in the title bar.
99 virtual void setTitle(const STR_String& title);
102 * Returns the title displayed in the title bar.
103 * @param title The title displayed in the title bar.
105 virtual void getTitle(STR_String& title) const;
108 * Returns the window rectangle dimensions.
109 * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
110 * @param bounds The bounding rectangle of the window.
112 virtual void getWindowBounds(GHOST_Rect& bounds) const;
115 * Returns the client rectangle dimensions.
116 * The left and top members of the rectangle are always zero.
117 * @param bounds The bounding rectangle of the cleient area of the window.
119 virtual void getClientBounds(GHOST_Rect& bounds) const;
122 * Resizes client rectangle width.
123 * @param width The new width of the client area of the window.
125 virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
128 * Resizes client rectangle height.
129 * @param height The new height of the client area of the window.
131 virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
134 * Resizes client rectangle.
135 * @param width The new width of the client area of the window.
136 * @param height The new height of the client area of the window.
138 virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
141 * Returns the state of the window (normal, minimized, maximized).
142 * @return The state of the window.
144 virtual GHOST_TWindowState getState() const;
147 * Converts a point in screen coordinates to client rectangle coordinates
148 * @param inX The x-coordinate on the screen.
149 * @param inY The y-coordinate on the screen.
150 * @param outX The x-coordinate in the client rectangle.
151 * @param outY The y-coordinate in the client rectangle.
153 virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
156 * Converts a point in screen coordinates to client rectangle coordinates
157 * @param inX The x-coordinate in the client rectangle.
158 * @param inY The y-coordinate in the client rectangle.
159 * @param outX The x-coordinate on the screen.
160 * @param outY The y-coordinate on the screen.
162 virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
165 * Sets the state of the window (normal, minimized, maximized).
166 * @param state The state of the window.
167 * @return Indication of success.
169 virtual GHOST_TSuccess setState(GHOST_TWindowState state);
172 * Sets the order of the window (bottom, top).
173 * @param order The order of the window.
174 * @return Indication of success.
176 virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
179 * Swaps front and back buffers of a window.
180 * @return A boolean success indicator.
182 virtual GHOST_TSuccess swapBuffers();
185 * Updates the drawing context of this window. Needed
186 * whenever the window is changed.
187 * @return Indication of success.
189 GHOST_TSuccess updateDrawingContext();
192 * Activates the drawing context of this window.
193 * @return A boolean success indicator.
195 virtual GHOST_TSuccess activateDrawingContext();
197 virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
200 * Returns the dirty state of the window when in full-screen mode.
201 * @return Whether it is dirty.
203 virtual bool getFullScreenDirty();
205 /* accessor for fullscreen window */
206 virtual void setMac_windowState(short value);
207 virtual short getMac_windowState();
210 const GHOST_TabletData* GetTabletData()
211 { return &m_tablet; }
213 GHOST_TabletData& GetCocoaTabletData()
217 * Tries to install a rendering context in this window.
218 * @param type The type of rendering context installed.
219 * @return Indication as to whether installation has succeeded.
221 virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
224 * Removes the current drawing context.
225 * @return Indication as to whether removal has succeeded.
227 virtual GHOST_TSuccess removeDrawingContext();
230 * Invalidates the contents of this window.
231 * @return Indication of success.
233 virtual GHOST_TSuccess invalidate();
236 * Sets the cursor visibility on the window using
237 * native window system calls.
239 virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
242 * Sets the cursor shape on the window using
243 * native window system calls.
245 virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
248 * Sets the cursor shape on the window using
249 * native window system calls.
251 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
252 int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
254 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
257 * Converts a string object to a Mac Pascal string.
258 * @param in The string object to be converted.
259 * @param out The converted string.
261 virtual void gen2mac(const STR_String& in, Str255 out) const;
264 * Converts a Mac Pascal string to a string object.
265 * @param in The string to be converted.
266 * @param out The converted string object.
268 virtual void mac2gen(const Str255 in, STR_String& out) const;
270 WindowRef m_windowRef;
274 /** The first created OpenGL context (for sharing display lists) */
275 static AGLContext s_firstaglCtx;
277 Cursor* m_customCursor;
279 GHOST_TabletData m_tablet;
281 /** When running in full-screen this tells whether to refresh the window. */
282 bool m_fullScreenDirty;
284 /** specific MacOs X full screen window setting as we use partially system mechanism
285 values : 0 not maximizable default
289 this will be reworked when rebuilding GHOST carbon to use new OS X apis
290 in order to be unified with GHOST fullscreen/maximised settings
295 short mac_windowState;
299 * The width/height of the size rectangle in the lower right corner of a
300 * Mac/Carbon window. This is also the height of the gutter area.
302 #ifdef GHOST_DRAW_CARBON_GUTTER
303 static const GHOST_TInt32 s_sizeRectSize;
304 #endif // GHOST_DRAW_CARBON_GUTTER
307 #endif // _GHOST_WINDOW_COCOA_H_