Drag'n'drop : moved "setAcceptDragOperation" functions at window level
[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 :
49         m_drawingContextType(type),
50         m_cursorVisible(true),
51         m_cursorGrab(GHOST_kGrabDisable),
52         m_cursorShape(GHOST_kStandardCursorDefault),
53         m_stereoVisual(stereoVisual)
54 {
55         m_isUnsavedChanges = false;
56         m_canAcceptDragOperation = false;
57         
58     m_cursorGrabAccumPos[0] = 0;
59     m_cursorGrabAccumPos[1] = 0;
60
61     m_fullScreen = state == GHOST_kWindowStateFullScreen;
62     if (m_fullScreen) {
63         m_fullScreenWidth = width;
64         m_fullScreenHeight = height;
65     }
66 }
67
68
69 GHOST_Window::~GHOST_Window()
70 {
71 }
72
73
74 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
75 {
76         GHOST_TSuccess success = GHOST_kSuccess;
77         if (type != m_drawingContextType) {
78                 success = removeDrawingContext();
79                 if (success) {
80                         success = installDrawingContext(type);
81                         m_drawingContextType = type;
82                 }
83                 else {
84                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
85                 }
86         }
87         return success;
88 }
89
90 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
91 {
92         if (setWindowCursorVisibility(visible)) {
93                 m_cursorVisible = visible;
94                 return GHOST_kSuccess;
95         }
96         else {
97                 return GHOST_kFailure;
98         }
99 }
100
101 GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds)
102 {
103         if(m_cursorGrab == mode)
104                 return GHOST_kSuccess;
105
106         if (setWindowCursorGrab(mode)) {
107
108                 if(mode==GHOST_kGrabDisable)
109                         m_cursorGrabBounds.m_l= m_cursorGrabBounds.m_r= -1;
110                 else if (bounds) {
111                         m_cursorGrabBounds= *bounds;
112                 }
113                 m_cursorGrab = mode;
114                 return GHOST_kSuccess;
115         }
116         else {
117                 return GHOST_kFailure;
118         }
119 }
120
121 GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
122 {
123         bounds= m_cursorGrabBounds;
124         return (bounds.m_l==-1 && bounds.m_r==-1) ? GHOST_kFailure : GHOST_kSuccess;
125 }
126
127 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
128 {
129         if (setWindowCursorShape(cursorShape)) {
130                 m_cursorShape = cursorShape;
131                 return GHOST_kSuccess;
132         }
133         else {
134                 return GHOST_kFailure;
135         }
136 }
137
138 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
139                                                                                                          int hotX, int hotY)
140 {
141         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
142                                                                         16, 16, hotX, hotY, 0, 1 );
143 }
144
145 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
146                                                                                                         int sizex, int sizey, int hotX, int hotY,
147                                                                                                         int fg_color, int bg_color )
148 {
149         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
150                 m_cursorShape = GHOST_kStandardCursorCustom;
151                 return GHOST_kSuccess;
152         }
153         else {
154                 return GHOST_kFailure;
155         }
156 }
157
158 void GHOST_Window::setAcceptDragOperation(bool canAccept)
159 {
160         m_canAcceptDragOperation = canAccept;
161 }
162
163 bool GHOST_Window::canAcceptDragOperation() const
164 {
165         return m_canAcceptDragOperation;
166 }
167
168 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
169 {
170         m_isUnsavedChanges = isUnsavedChanges;
171         
172         return GHOST_kSuccess;
173 }
174
175 bool GHOST_Window::getModifiedState()
176 {
177         return m_isUnsavedChanges;
178 }