GHOST Cocoa: move y origin top/bottom conversions out of windowmanager module
[blender.git] / intern / ghost / intern / GHOST_Window.cpp
1 /*
2  * $Id$
3  * ***** BEGIN GPL LICENSE BLOCK *****
4  *
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.
9  *
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.
14  *
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  *
19  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
20  * All rights reserved.
21  *
22  * The Original Code is: all of this file.
23  *
24  * Contributor(s): none yet.
25  *
26  * ***** END GPL LICENSE BLOCK *****
27  */
28
29 /** \file ghost/intern/GHOST_Window.cpp
30  *  \ingroup GHOST
31  */
32
33
34 /**
35  * Copyright (C) 2001 NaN Technologies B.V.
36  * @author      Maarten Gribnau
37  * @date        May 10, 2001
38  */
39
40 #include "GHOST_Window.h"
41
42
43 GHOST_Window::GHOST_Window(
44         GHOST_TUns32 width, GHOST_TUns32 height,
45         GHOST_TWindowState state,
46         GHOST_TDrawingContextType type,
47         const bool stereoVisual,
48         const GHOST_TUns16 numOfAASamples)
49 :
50         m_drawingContextType(type),
51         m_cursorVisible(true),
52         m_cursorGrab(GHOST_kGrabDisable),
53         m_cursorShape(GHOST_kStandardCursorDefault),
54         m_stereoVisual(stereoVisual),
55         m_numOfAASamples(numOfAASamples)
56 {
57         m_isUnsavedChanges = false;
58         m_canAcceptDragOperation = false;
59         
60         m_progressBarVisible = false;
61         
62     m_cursorGrabAccumPos[0] = 0;
63     m_cursorGrabAccumPos[1] = 0;
64
65     m_fullScreen = state == GHOST_kWindowStateFullScreen;
66     if (m_fullScreen) {
67         m_fullScreenWidth = width;
68         m_fullScreenHeight = height;
69     }
70 }
71
72
73 GHOST_Window::~GHOST_Window()
74 {
75 }
76
77 void* GHOST_Window::getOSWindow() const
78 {
79         return NULL;
80 }
81
82 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
83 {
84         GHOST_TSuccess success = GHOST_kSuccess;
85         if (type != m_drawingContextType) {
86                 success = removeDrawingContext();
87                 if (success) {
88                         success = installDrawingContext(type);
89                         m_drawingContextType = type;
90                 }
91                 else {
92                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
93                 }
94         }
95         return success;
96 }
97
98 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
99 {
100         if (setWindowCursorVisibility(visible)) {
101                 m_cursorVisible = visible;
102                 return GHOST_kSuccess;
103         }
104         else {
105                 return GHOST_kFailure;
106         }
107 }
108
109 GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds)
110 {
111         if(m_cursorGrab == mode)
112                 return GHOST_kSuccess;
113
114         if (setWindowCursorGrab(mode)) {
115
116                 if(mode==GHOST_kGrabDisable)
117                         m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1;
118                 else if (bounds) {
119                         m_cursorGrabBounds= *bounds;
120                 } else { /* if bounds not defined, use window */
121                         getClientBounds(m_cursorGrabBounds);
122                 }
123                 m_cursorGrab = mode;
124                 return GHOST_kSuccess;
125         }
126         else {
127                 return GHOST_kFailure;
128         }
129 }
130
131 GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
132 {
133         bounds= m_cursorGrabBounds;
134         return (bounds.m_l==-1 && bounds.m_r==-1) ? GHOST_kFailure : GHOST_kSuccess;
135 }
136
137 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
138 {
139         if (setWindowCursorShape(cursorShape)) {
140                 m_cursorShape = cursorShape;
141                 return GHOST_kSuccess;
142         }
143         else {
144                 return GHOST_kFailure;
145         }
146 }
147
148 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
149                                                                                                          int hotX, int hotY)
150 {
151         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
152                                                                         16, 16, hotX, hotY, 0, 1 );
153 }
154
155 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
156                                                                                                         int sizex, int sizey, int hotX, int hotY,
157                                                                                                         int fg_color, int bg_color )
158 {
159         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
160                 m_cursorShape = GHOST_kStandardCursorCustom;
161                 return GHOST_kSuccess;
162         }
163         else {
164                 return GHOST_kFailure;
165         }
166 }
167
168 void GHOST_Window::setAcceptDragOperation(bool canAccept)
169 {
170         m_canAcceptDragOperation = canAccept;
171 }
172
173 bool GHOST_Window::canAcceptDragOperation() const
174 {
175         return m_canAcceptDragOperation;
176 }
177
178 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
179 {
180         m_isUnsavedChanges = isUnsavedChanges;
181         
182         return GHOST_kSuccess;
183 }
184
185 bool GHOST_Window::getModifiedState()
186 {
187         return m_isUnsavedChanges;
188 }