Blender V2.61 - r43446

GHOST_WindowManager.cpp

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