34e9f519a07085945344fd8a4479febc53ce0a02
[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_cursorGrabbed(true),
52         m_cursorShape(GHOST_kStandardCursorDefault),
53         m_stereoVisual(stereoVisual)
54 {
55         m_isUnsavedChanges = false;
56         
57     m_fullScreen = state == GHOST_kWindowStateFullScreen;
58     if (m_fullScreen) {
59         m_fullScreenWidth = width;
60         m_fullScreenHeight = height;
61     }
62 }
63
64
65 GHOST_Window::~GHOST_Window()
66 {
67 }
68
69
70 GHOST_TSuccess GHOST_Window::setDrawingContextType(GHOST_TDrawingContextType type)
71 {
72         GHOST_TSuccess success = GHOST_kSuccess;
73         if (type != m_drawingContextType) {
74                 success = removeDrawingContext();
75                 if (success) {
76                         success = installDrawingContext(type);
77                         m_drawingContextType = type;
78                 }
79                 else {
80                         m_drawingContextType = GHOST_kDrawingContextTypeNone;
81                 }
82         }
83         return success;
84 }
85
86 GHOST_TSuccess GHOST_Window::setCursorVisibility(bool visible)
87 {
88         if (setWindowCursorVisibility(visible)) {
89                 m_cursorVisible = visible;
90                 return GHOST_kSuccess;
91         }
92         else {
93                 return GHOST_kFailure;
94         }
95 }
96
97 GHOST_TSuccess GHOST_Window::setCursorGrab(bool grab)
98 {
99         if(m_cursorGrabbed == grab)
100                 return GHOST_kSuccess;
101
102         if (setWindowCursorGrab(grab)) {
103                 m_cursorGrabbed = grab;
104                 return GHOST_kSuccess;
105         }
106         else {
107                 return GHOST_kFailure;
108         }
109 }
110
111 GHOST_TSuccess GHOST_Window::setCursorShape(GHOST_TStandardCursor cursorShape)
112 {
113         if (setWindowCursorShape(cursorShape)) {
114                 m_cursorShape = cursorShape;
115                 return GHOST_kSuccess;
116         }
117         else {
118                 return GHOST_kFailure;
119         }
120 }
121
122 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 bitmap[16][2], GHOST_TUns8 mask[16][2],
123                                                                                                          int hotX, int hotY)
124 {
125         return setCustomCursorShape( (GHOST_TUns8 *)bitmap, (GHOST_TUns8 *)mask, 
126                                                                         16, 16, hotX, hotY, 0, 1 );
127 }
128
129 GHOST_TSuccess GHOST_Window::setCustomCursorShape(GHOST_TUns8 *bitmap, GHOST_TUns8 *mask, 
130                                                                                                         int sizex, int sizey, int hotX, int hotY,
131                                                                                                         int fg_color, int bg_color )
132 {
133         if (setWindowCustomCursorShape(bitmap, mask, sizex, sizey,hotX, hotY, fg_color, bg_color)) {
134                 m_cursorShape = GHOST_kStandardCursorCustom;
135                 return GHOST_kSuccess;
136         }
137         else {
138                 return GHOST_kFailure;
139         }
140 }
141
142
143 GHOST_TSuccess GHOST_Window::setModifiedState(bool isUnsavedChanges)
144 {
145         m_isUnsavedChanges = isUnsavedChanges;
146         
147         return GHOST_kSuccess;
148 }
149
150 bool GHOST_Window::getModifiedState()
151 {
152         return m_isUnsavedChanges;
153 }