|
Blender
V2.59
|
00001 /* 00002 * $Id: GHOST_WindowManager.cpp 35152 2011-02-25 11:28:33Z jesterking $ 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): none yet. 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00042 #include "GHOST_WindowManager.h" 00043 #include <algorithm> 00044 #include "GHOST_Debug.h" 00045 #include "GHOST_Window.h" 00046 00047 00048 GHOST_WindowManager::GHOST_WindowManager() : 00049 m_fullScreenWindow(0), 00050 m_activeWindow(0), 00051 m_activeWindowBeforeFullScreen(0) 00052 { 00053 } 00054 00055 00056 GHOST_WindowManager::~GHOST_WindowManager() 00057 { 00058 /* m_windows is freed by GHOST_System::disposeWindow */ 00059 } 00060 00061 00062 GHOST_TSuccess GHOST_WindowManager::addWindow(GHOST_IWindow* window) 00063 { 00064 GHOST_TSuccess success = GHOST_kFailure; 00065 if (window) { 00066 if (!getWindowFound(window)) { 00067 // Store the pointer to the window 00068 m_windows.push_back(window); 00069 success = GHOST_kSuccess; 00070 } 00071 } 00072 return success; 00073 } 00074 00075 00076 GHOST_TSuccess GHOST_WindowManager::removeWindow(const GHOST_IWindow* window) 00077 { 00078 GHOST_TSuccess success = GHOST_kFailure; 00079 if (window) { 00080 if (window == m_fullScreenWindow) { 00081 endFullScreen(); 00082 } 00083 else { 00084 vector<GHOST_IWindow*>::iterator result = find(m_windows.begin(), m_windows.end(), window); 00085 if (result != m_windows.end()) { 00086 setWindowInactive(window); 00087 m_windows.erase(result); 00088 success = GHOST_kSuccess; 00089 } 00090 } 00091 } 00092 return success; 00093 } 00094 00095 00096 bool GHOST_WindowManager::getWindowFound(const GHOST_IWindow* window) const 00097 { 00098 bool found = false; 00099 if (window) { 00100 if (getFullScreen() && (window == m_fullScreenWindow)) { 00101 found = true; 00102 } 00103 else { 00104 vector<GHOST_IWindow*>::const_iterator result = find(m_windows.begin(), m_windows.end(), window); 00105 if (result != m_windows.end()) { 00106 found = true; 00107 } 00108 } 00109 } 00110 return found; 00111 } 00112 00113 00114 bool GHOST_WindowManager::getFullScreen(void) const 00115 { 00116 return m_fullScreenWindow != 0; 00117 } 00118 00119 00120 GHOST_IWindow* GHOST_WindowManager::getFullScreenWindow(void) const 00121 { 00122 return m_fullScreenWindow; 00123 } 00124 00125 00126 GHOST_TSuccess GHOST_WindowManager::beginFullScreen(GHOST_IWindow* window, 00127 bool stereoVisual) 00128 { 00129 GHOST_TSuccess success = GHOST_kFailure; 00130 GHOST_ASSERT(window, "GHOST_WindowManager::beginFullScreen(): invalid window"); 00131 GHOST_ASSERT(window->getValid(), "GHOST_WindowManager::beginFullScreen(): invalid window"); 00132 if (!getFullScreen()) { 00133 m_fullScreenWindow = window; 00134 m_activeWindowBeforeFullScreen = getActiveWindow(); 00135 setActiveWindow(m_fullScreenWindow); 00136 success = GHOST_kSuccess; 00137 } 00138 return success; 00139 } 00140 00141 00142 GHOST_TSuccess GHOST_WindowManager::endFullScreen(void) 00143 { 00144 GHOST_TSuccess success = GHOST_kFailure; 00145 if (getFullScreen()) { 00146 if (m_fullScreenWindow != 0) { 00147 //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n"); 00148 setWindowInactive(m_fullScreenWindow); 00149 delete m_fullScreenWindow; 00150 //GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n"); 00151 m_fullScreenWindow = 0; 00152 if (m_activeWindowBeforeFullScreen) { 00153 setActiveWindow(m_activeWindowBeforeFullScreen); 00154 } 00155 } 00156 success = GHOST_kSuccess; 00157 } 00158 return success; 00159 } 00160 00161 00162 GHOST_TSuccess GHOST_WindowManager::setActiveWindow(GHOST_IWindow* window) 00163 { 00164 GHOST_TSuccess success = GHOST_kSuccess; 00165 if (window != m_activeWindow) { 00166 if (getWindowFound(window)) { 00167 m_activeWindow = window; 00168 } 00169 else { 00170 success = GHOST_kFailure; 00171 } 00172 } 00173 return success; 00174 } 00175 00176 00177 GHOST_IWindow* GHOST_WindowManager::getActiveWindow(void) const 00178 { 00179 return m_activeWindow; 00180 } 00181 00182 00183 void GHOST_WindowManager::setWindowInactive(const GHOST_IWindow* window) 00184 { 00185 if (window == m_activeWindow) { 00186 m_activeWindow = 0; 00187 } 00188 } 00189 00190 00191 std::vector<GHOST_IWindow *> &GHOST_WindowManager::getWindows() 00192 { 00193 return m_windows; 00194 } 00195 00196 00197 GHOST_IWindow* GHOST_WindowManager::getWindowAssociatedWithOSWindow(void* osWindow) 00198 { 00199 std::vector<GHOST_IWindow*>::iterator iter; 00200 00201 for (iter = m_windows.begin(); iter != m_windows.end(); iter++) { 00202 if ((*iter)->getOSWindow() == osWindow) 00203 return *iter; 00204 } 00205 00206 return NULL; 00207 } 00208 00209 bool GHOST_WindowManager::getAnyModifiedState() 00210 { 00211 bool isAnyModified = false; 00212 std::vector<GHOST_IWindow*>::iterator iter; 00213 00214 for (iter = m_windows.begin(); iter != m_windows.end(); iter++) { 00215 if ((*iter)->getModifiedState()) 00216 isAnyModified = true; 00217 } 00218 00219 return isAnyModified; 00220 }