Cleanup: remove redundant doxygen \file argument
[blender.git] / intern / ghost / intern / GHOST_Window.cpp
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
17  * All rights reserved.
18  */
19
20 /** \file \ingroup GHOST
21  */
22
23
24 /**
25  * Copyright (C) 2001 NaN Technologies B.V.
26  */
27
28 #include "GHOST_Window.h"
29
30 #include "GHOST_ContextNone.h"
31
32 #include <assert.h>
33
34 GHOST_Window::GHOST_Window(
35         GHOST_TUns32 width, GHOST_TUns32 height,
36         GHOST_TWindowState state,
37         const bool wantStereoVisual,
38         const bool /*exclusive*/,
39         const GHOST_TUns16 wantNumOfAASamples)
40     : m_drawingContextType(GHOST_kDrawingContextTypeNone),
41       m_cursorVisible(true),
42       m_cursorGrab(GHOST_kGrabDisable),
43       m_cursorShape(GHOST_kStandardCursorDefault),
44       m_wantStereoVisual(wantStereoVisual),
45       m_wantNumOfAASamples(wantNumOfAASamples),
46       m_context(new GHOST_ContextNone(false, 0))
47 {
48         m_isUnsavedChanges = false;
49         m_canAcceptDragOperation = false;
50
51         m_progressBarVisible = false;
52
53         m_cursorGrabAccumPos[0] = 0;
54         m_cursorGrabAccumPos[1] = 0;
55
56         m_nativePixelSize = 1.0f;
57
58         m_fullScreen = state == GHOST_kWindowStateFullScreen;
59         if (m_fullScreen) {
60                 m_fullScreenWidth = width;
61                 m_fullScreenHeight = height;
62         }
63 }
64
65
66 GHOST_Window::~GHOST_Window()
67 {
68         delete m_context;
69 }
70
71 void *GHOST_Window::getOSWindow() const
72 {
73         return NULL;
74 }
75
76 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
77 {
78         if (type != m_drawingContextType) {
79                 delete m_context;
80                 m_context = NULL;
81
82                 if (type != GHOST_kDrawingContextTypeNone)
83                         m_context = newDrawingContext(type);
84
85                 if (m_context != NULL) {
86                         m_drawingContextType = type;
87                 }
88                 else {
89                         m_context = new GHOST_ContextNone(m_wantStereoVisual, m_wantNumOfAASamples);
90                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
91                 }
92
93                 return (type == m_drawingContextType) ? GHOST_kSuccess : GHOST_kFailure;
94         }
95         else {
96                 return GHOST_kSuccess;
97         }
98 }
99
100 GHOST_TSuccess GHOST_Window::swapBuffers()
101 {
102         return m_context->swapBuffers();
103 }
104
105 GHOST_TSuccess GHOST_Window::setSwapInterval(int interval)
106 {
107         return m_context->setSwapInterval(interval);
108 }
109
110 GHOST_TSuccess GHOST_Window::getSwapInterval(int& intervalOut)
111 {
112         return m_context->getSwapInterval(intervalOut);
113 }
114
115 GHOST_TUns16 GHOST_Window::getNumOfAASamples()
116 {
117         return m_context->getNumOfAASamples();
118 }
119
120 GHOST_TSuccess GHOST_Window::activateDrawingContext()
121 {
122         return m_context->activateDrawingContext();
123 }
124
125 GHOST_TSuccess GHOST_Window::updateDrawingContext()
126 {
127         return m_context->updateDrawingContext();
128 }
129
130 GHOST_TSuccess GHOST_Window::releaseNativeHandles()
131 {
132         return m_context->releaseNativeHandles();
133 }
134
135 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
136 {
137         if (setWindowCursorVisibility(visible)) {
138                 m_cursorVisible = visible;
139                 return GHOST_kSuccess;
140         }
141         else {
142                 return GHOST_kFailure;
143         }
144 }
145
146 GHOST_TSuccess GHOST_Window::setCursorGrab(GHOST_TGrabCursorMode mode, GHOST_Rect *bounds, GHOST_TInt32 mouse_ungrab_xy[2])
147 {
148         if (m_cursorGrab == mode)
149                 return GHOST_kSuccess;
150
151         /* override with new location */
152         if (mouse_ungrab_xy) {
153                 assert(mode == GHOST_kGrabDisable);
154                 m_cursorGrabInitPos[0] = mouse_ungrab_xy[0];
155                 m_cursorGrabInitPos[1] = mouse_ungrab_xy[1];
156         }
157
158         if (setWindowCursorGrab(mode)) {
159
160                 if (mode == GHOST_kGrabDisable)
161                         m_cursorGrabBounds.m_l = m_cursorGrabBounds.m_r = -1;
162                 else if (bounds) {
163                         m_cursorGrabBounds = *bounds;
164                 }
165                 else {  /* if bounds not defined, use window */
166                         getClientBounds(m_cursorGrabBounds);
167                 }
168                 m_cursorGrab = mode;
169                 return GHOST_kSuccess;
170         }
171         else {
172                 return GHOST_kFailure;
173         }
174 }
175
176 GHOST_TSuccess GHOST_Window::getCursorGrabBounds(GHOST_Rect& bounds)
177 {
178         bounds = m_cursorGrabBounds;
179         return (bounds.m_l == -1 && bounds.m_r == -1) ? GHOST_kFailure : GHOST_kSuccess;
180 }
181
182 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
183 {
184         if (setWindowCursorShape(cursorShape)) {
185                 m_cursorShape = cursorShape;
186                 return GHOST_kSuccess;
187         }
188         else {
189                 return GHOST_kFailure;
190         }
191 }
192
193 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
194                                                   int hotX, int hotY)
195 {
196         return setCustomCursorShape((GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask,
197                                     16, 16, hotX, hotY, 0, 1);
198 }
199
200 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask,
201                                                   int sizex, int sizey, int hotX, int hotY,
202                                                   int fg_color, int bg_color)
203 {
204         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey, hotX, hotY, fg_color, bg_color)) {
205                 m_cursorShape = GHOST_kStandardCursorCustom;
206                 return GHOST_kSuccess;
207         }
208         else {
209                 return GHOST_kFailure;
210         }
211 }
212
213 void GHOST_Window::setAcceptDragOperation(bool canAccept)
214 {
215         m_canAcceptDragOperation = canAccept;
216 }
217
218 bool GHOST_Window::canAcceptDragOperation() const
219 {
220         return m_canAcceptDragOperation;
221 }
222
223 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
224 {
225         m_isUnsavedChanges = isUnsavedChanges;
226
227         return GHOST_kSuccess;
228 }
229
230 bool GHOST_Window::getModifiedState()
231 {
232         return m_isUnsavedChanges;
233 }