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