Cocoa : correctly handle late events sent after window deactivate
[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., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 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 /**
30  * Copyright (C) 2001 NaN Technologies B.V.
31  * @author      Maarten Gribnau
32  * @date        May 10, 2001
33  */
34
35 #ifdef HAVE_CONFIG_H
36 #include <config.h>
37 #endif
38
39 #include "GHOST_Window.h"
40
41
42 GHOST_Window::GHOST_Window(
43         const STR_String& /*title*/,
44         GHOST_TInt32 /*left*/, GHOST_TInt32 /*top*/, 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_cursorGrabAccumPos[0] = 0;
61     m_cursorGrabAccumPos[1] = 0;
62
63     m_fullScreen = state == GHOST_kWindowStateFullScreen;
64     if (m_fullScreen) {
65         m_fullScreenWidth = width;
66         m_fullScreenHeight = height;
67     }
68 }
69
70
71 GHOST_Window::~GHOST_Window()
72 {
73 }
74
75 void* GHOST_Window::getOSWindow() const
76 {
77         return NULL;
78 }
79
80 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
81 {
82         GHOST_TSuccess success = GHOST_kSuccess;
83         if (type != m_drawingContextType) {
84                 success = removeDrawingContext();
85                 if (success) {
86                         success = installDrawingContext(type);
87                         m_drawingContextType = type;
88                 }
89                 else {
90                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
91                 }
92         }
93         return success;
94 }
95
96 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
97 {
98         if (setWindowCursorVisibility(visible)) {
99                 m_cursorVisible = visible;
100                 return GHOST_kSuccess;
101         }
102         else {
103                 return GHOST_kFailure;
104         }
105 }
106
107 GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds)
108 {
109         if(m_cursorGrab == mode)
110                 return GHOST_kSuccess;
111
112         if (setWindowCursorGrab(mode)) {
113
114                 if(mode==GHOST_kGrabDisable)
115                         m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1;
116                 else if (bounds) {
117                         m_cursorGrabBounds= *bounds;
118                 } else { /* if bounds not defined, use window */
119                         getClientBounds(m_cursorGrabBounds);
120                 }
121                 m_cursorGrab = mode;
122                 return GHOST_kSuccess;
123         }
124         else {
125                 return GHOST_kFailure;
126         }
127 }
128
129 GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
130 {
131         bounds= m_cursorGrabBounds;
132         return (bounds.m_l==-1 && bounds.m_r==-1) ? GHOST_kFailure : GHOST_kSuccess;
133 }
134
135 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
136 {
137         if (setWindowCursorShape(cursorShape)) {
138                 m_cursorShape = cursorShape;
139                 return GHOST_kSuccess;
140         }
141         else {
142                 return GHOST_kFailure;
143         }
144 }
145
146 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
147                                                                                                          int hotX, int hotY)
148 {
149         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
150                                                                         16, 16, hotX, hotY, 0, 1 );
151 }
152
153 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
154                                                                                                         int sizex, int sizey, int hotX, int hotY,
155                                                                                                         int fg_color, int bg_color )
156 {
157         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
158                 m_cursorShape = GHOST_kStandardCursorCustom;
159                 return GHOST_kSuccess;
160         }
161         else {
162                 return GHOST_kFailure;
163         }
164 }
165
166 void GHOST_Window::setAcceptDragOperation(bool canAccept)
167 {
168         m_canAcceptDragOperation = canAccept;
169 }
170
171 bool GHOST_Window::canAcceptDragOperation() const
172 {
173         return m_canAcceptDragOperation;
174 }
175
176 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
177 {
178         m_isUnsavedChanges = isUnsavedChanges;
179         
180         return GHOST_kSuccess;
181 }
182
183 bool GHOST_Window::getModifiedState()
184 {
185         return m_isUnsavedChanges;
186 }