3 * ***** BEGIN GPL/BL DUAL 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. The Blender
9 * Foundation also sells licenses for use in proprietary software under
10 * the Blender License. See http://www.blender.org/BL/ for information
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
23 * All rights reserved.
25 * The Original Code is: all of this file.
27 * Contributor(s): none yet.
29 * ***** END GPL/BL DUAL LICENSE BLOCK *****
32 * @file GHOST_WindowCarbon.h
33 * Declaration of GHOST_WindowCarbon class.
36 #ifndef _GHOST_WINDOW_CARBON_H_
37 #define _GHOST_WINDOW_CARBON_H_
40 #error Apple OSX only!
43 #include "GHOST_Window.h"
44 #include "STR_String.h"
46 #include <Carbon/Carbon.h>
52 * Window on Mac OSX/Carbon.
53 * Carbon windows have a size widget in the lower right corner of the window.
54 * To force it to be visible, the height of the client rectangle is reduced so
55 * that applications do not draw in that area. GHOST will manage that area
56 * which is called the gutter.
57 * When OpenGL contexts are active, GHOST will use AGL_BUFFER_RECT to prevent
58 * OpenGL drawing outside the reduced client rectangle.
59 * @author Maarten Gribnau
62 class GHOST_WindowCarbon : public GHOST_Window {
66 * Creates a new window and opens it.
67 * To check if the window was created properly, use the getValid() method.
68 * @param title The text shown in the title bar of the window.
69 * @param left The coordinate of the left edge of the window.
70 * @param top The coordinate of the top edge of the window.
71 * @param width The width the window.
72 * @param height The height the window.
73 * @param state The state the window is initially opened with.
74 * @param type The type of drawing context installed in this window.
75 * @param stereoVisual Stereo visual for quad buffered stereo.
78 const STR_String& title,
83 GHOST_TWindowState state,
84 GHOST_TDrawingContextType type = GHOST_kDrawingContextTypeNone,
85 const bool stereoVisual = false
90 * Closes the window and disposes resources allocated.
92 virtual ~GHOST_WindowCarbon();
95 * Returns indication as to whether the window is valid.
96 * @return The validity of the window.
98 virtual bool getValid() const;
101 * Sets the title displayed in the title bar.
102 * @param title The title to display in the title bar.
104 virtual void setTitle(const STR_String& title);
107 * Returns the title displayed in the title bar.
108 * @param title The title displayed in the title bar.
110 virtual void getTitle(STR_String& title) const;
113 * Returns the window rectangle dimensions.
114 * The dimensions are given in screen coordinates that are relative to the upper-left corner of the screen.
115 * @param bounds The bounding rectangle of the window.
117 virtual void getWindowBounds(GHOST_Rect& bounds) const;
120 * Returns the client rectangle dimensions.
121 * The left and top members of the rectangle are always zero.
122 * @param bounds The bounding rectangle of the cleient area of the window.
124 virtual void getClientBounds(GHOST_Rect& bounds) const;
127 * Resizes client rectangle width.
128 * @param width The new width of the client area of the window.
130 virtual GHOST_TSuccess setClientWidth(GHOST_TUns32 width);
133 * Resizes client rectangle height.
134 * @param height The new height of the client area of the window.
136 virtual GHOST_TSuccess setClientHeight(GHOST_TUns32 height);
139 * Resizes client rectangle.
140 * @param width The new width of the client area of the window.
141 * @param height The new height of the client area of the window.
143 virtual GHOST_TSuccess setClientSize(GHOST_TUns32 width, GHOST_TUns32 height);
146 * Returns the state of the window (normal, minimized, maximized).
147 * @return The state of the window.
149 virtual GHOST_TWindowState getState() const;
152 * Converts a point in screen coordinates to client rectangle coordinates
153 * @param inX The x-coordinate on the screen.
154 * @param inY The y-coordinate on the screen.
155 * @param outX The x-coordinate in the client rectangle.
156 * @param outY The y-coordinate in the client rectangle.
158 virtual void screenToClient(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
161 * Converts a point in screen coordinates to client rectangle coordinates
162 * @param inX The x-coordinate in the client rectangle.
163 * @param inY The y-coordinate in the client rectangle.
164 * @param outX The x-coordinate on the screen.
165 * @param outY The y-coordinate on the screen.
167 virtual void clientToScreen(GHOST_TInt32 inX, GHOST_TInt32 inY, GHOST_TInt32& outX, GHOST_TInt32& outY) const;
170 * Sets the state of the window (normal, minimized, maximized).
171 * @param state The state of the window.
172 * @return Indication of success.
174 virtual GHOST_TSuccess setState(GHOST_TWindowState state);
177 * Sets the order of the window (bottom, top).
178 * @param order The order of the window.
179 * @return Indication of success.
181 virtual GHOST_TSuccess setOrder(GHOST_TWindowOrder order);
184 * Swaps front and back buffers of a window.
185 * @return A boolean success indicator.
187 virtual GHOST_TSuccess swapBuffers();
190 * Updates the drawing context of this window. Needed
191 * whenever the window is changed.
192 * @return Indication of success.
194 GHOST_TSuccess updateDrawingContext();
197 * Activates the drawing context of this window.
198 * @return A boolean success indicator.
200 virtual GHOST_TSuccess activateDrawingContext();
202 virtual void loadCursor(bool visible, GHOST_TStandardCursor cursor) const;
205 * Returns the dirty state of the window when in full-screen mode.
206 * @return Whether it is dirty.
208 virtual bool getFullScreenDirty();
212 * Tries to install a rendering context in this window.
213 * @param type The type of rendering context installed.
214 * @return Indication as to whether installation has succeeded.
216 virtual GHOST_TSuccess installDrawingContext(GHOST_TDrawingContextType type);
219 * Removes the current drawing context.
220 * @return Indication as to whether removal has succeeded.
222 virtual GHOST_TSuccess removeDrawingContext();
225 * Invalidates the contents of this window.
226 * @return Indication of success.
228 virtual GHOST_TSuccess invalidate();
231 * Sets the cursor visibility on the window using
232 * native window system calls.
234 virtual GHOST_TSuccess setWindowCursorVisibility(bool visible);
237 * Sets the cursor shape on the window using
238 * native window system calls.
240 virtual GHOST_TSuccess setWindowCursorShape(GHOST_TStandardCursor shape);
243 * Sets the cursor shape on the window using
244 * native window system calls.
246 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
247 int sizex, int sizey, int hotX, int hotY, int fg_color, int bg_color);
249 virtual GHOST_TSuccess setWindowCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2], int hotX, int hotY);
252 * Converts a string object to a Mac Pascal string.
253 * @param in The string object to be converted.
254 * @param out The converted string.
256 virtual void gen2mac(const STR_String& in, Str255 out) const;
259 * Converts a Mac Pascal string to a string object.
260 * @param in The string to be converted.
261 * @param out The converted string object.
263 virtual void mac2gen(const Str255 in, STR_String& out) const;
265 WindowRef m_windowRef;
269 /** The first created OpenGL context (for sharing display lists) */
270 static AGLContext s_firstaglCtx;
272 Cursor* m_customCursor;
274 /** When running in full-screen this tells whether to refresh the window. */
275 bool m_fullScreenDirty;
278 * The width/height of the size rectangle in the lower right corner of a
279 * Mac/Carbon window. This is also the height of the gutter area.
281 #ifdef GHOST_DRAW_CARBON_GUTTER
282 static const GHOST_TInt32 s_sizeRectSize;
283 #endif // GHOST_DRAW_CARBON_GUTTER
286 #endif // _GHOST_WINDOW_CARBON_H_