Files
test2/intern/ghost/intern/GHOST_WindowManager.cpp

219 lines
5.1 KiB
C++
Raw Normal View History

2011-02-25 11:28:33 +00:00
/*
* ***** BEGIN GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
2002-10-12 11:37:38 +00:00
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
2010-02-12 13:34:04 +00:00
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
2002-10-12 11:37:38 +00:00
*
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
* All rights reserved.
*
* The Original Code is: all of this file.
*
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
2002-10-12 11:37:38 +00:00
*/
2011-02-25 11:28:33 +00:00
/** \file ghost/intern/GHOST_WindowManager.cpp
* \ingroup GHOST
*/
2002-10-12 11:37:38 +00:00
/**
* Copyright (C) 2001 NaN Technologies B.V.
* \author Maarten Gribnau
* \date May 11, 2001
2002-10-12 11:37:38 +00:00
*/
#include "GHOST_WindowManager.h"
2002-10-12 11:37:38 +00:00
#include <algorithm>
#include "GHOST_Debug.h"
#include "GHOST_Window.h"
GHOST_WindowManager::GHOST_WindowManager() :
m_fullScreenWindow(0),
m_activeWindow(0),
m_activeWindowBeforeFullScreen(0)
2002-10-12 11:37:38 +00:00
{
}
GHOST_WindowManager::~GHOST_WindowManager()
{
/* m_windows is freed by GHOST_System::disposeWindow */
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_WindowManager::addWindow(GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success = GHOST_kFailure;
if (window) {
if (!getWindowFound(window)) {
// Store the pointer to the window
m_windows.push_back(window);
success = GHOST_kSuccess;
}
}
return success;
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_WindowManager::removeWindow(const GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success = GHOST_kFailure;
if (window) {
if (window == m_fullScreenWindow) {
endFullScreen();
}
else {
2012-05-19 09:57:55 +00:00
std::vector<GHOST_IWindow *>::iterator result = find(m_windows.begin(), m_windows.end(), window);
2002-10-12 11:37:38 +00:00
if (result != m_windows.end()) {
setWindowInactive(window);
m_windows.erase(result);
success = GHOST_kSuccess;
}
}
}
return success;
}
2012-05-19 09:57:55 +00:00
bool GHOST_WindowManager::getWindowFound(const GHOST_IWindow *window) const
2002-10-12 11:37:38 +00:00
{
bool found = false;
if (window) {
2012-05-19 09:57:55 +00:00
if (getFullScreen() && (window == m_fullScreenWindow)) {
found = true;
}
else {
std::vector<GHOST_IWindow *>::const_iterator result = find(m_windows.begin(), m_windows.end(), window);
if (result != m_windows.end()) {
found = true;
}
}
2002-10-12 11:37:38 +00:00
}
return found;
}
bool GHOST_WindowManager::getFullScreen(void) const
{
return m_fullScreenWindow != NULL;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_IWindow *GHOST_WindowManager::getFullScreenWindow(void) const
2002-10-12 11:37:38 +00:00
{
2012-05-19 09:57:55 +00:00
return m_fullScreenWindow;
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_WindowManager::beginFullScreen(GHOST_IWindow *window,
bool /*stereoVisual*/)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success = GHOST_kFailure;
GHOST_ASSERT(window, "GHOST_WindowManager::beginFullScreen(): invalid window");
GHOST_ASSERT(window->getValid(), "GHOST_WindowManager::beginFullScreen(): invalid window");
if (!getFullScreen()) {
m_fullScreenWindow = window;
m_activeWindowBeforeFullScreen = getActiveWindow();
2002-10-12 11:37:38 +00:00
setActiveWindow(m_fullScreenWindow);
m_fullScreenWindow->beginFullScreen();
2002-10-12 11:37:38 +00:00
success = GHOST_kSuccess;
}
return success;
}
GHOST_TSuccess GHOST_WindowManager::endFullScreen(void)
{
GHOST_TSuccess success = GHOST_kFailure;
if (getFullScreen()) {
if (m_fullScreenWindow != NULL) {
2002-10-12 11:37:38 +00:00
//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
setWindowInactive(m_fullScreenWindow);
m_fullScreenWindow->endFullScreen();
2002-10-12 11:37:38 +00:00
delete m_fullScreenWindow;
//GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
m_fullScreenWindow = NULL;
if (m_activeWindowBeforeFullScreen) {
setActiveWindow(m_activeWindowBeforeFullScreen);
}
2002-10-12 11:37:38 +00:00
}
2012-05-19 09:57:55 +00:00
success = GHOST_kSuccess;
2002-10-12 11:37:38 +00:00
}
return success;
}
2012-05-19 09:57:55 +00:00
GHOST_TSuccess GHOST_WindowManager::setActiveWindow(GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
GHOST_TSuccess success = GHOST_kSuccess;
if (window != m_activeWindow) {
if (getWindowFound(window)) {
m_activeWindow = window;
}
else {
success = GHOST_kFailure;
}
}
return success;
}
2012-05-19 09:57:55 +00:00
GHOST_IWindow *GHOST_WindowManager::getActiveWindow(void) const
2002-10-12 11:37:38 +00:00
{
return m_activeWindow;
}
2012-05-19 09:57:55 +00:00
void GHOST_WindowManager::setWindowInactive(const GHOST_IWindow *window)
2002-10-12 11:37:38 +00:00
{
if (window == m_activeWindow) {
m_activeWindow = NULL;
2002-10-12 11:37:38 +00:00
}
}
std::vector<GHOST_IWindow *> &GHOST_WindowManager::getWindows()
{
2002-10-12 11:37:38 +00:00
return m_windows;
}
2012-05-19 09:57:55 +00:00
GHOST_IWindow *GHOST_WindowManager::getWindowAssociatedWithOSWindow(void *osWindow)
{
2012-05-19 09:57:55 +00:00
std::vector<GHOST_IWindow *>::iterator iter;
for (iter = m_windows.begin(); iter != m_windows.end(); ++iter) {
if ((*iter)->getOSWindow() == osWindow)
return *iter;
}
return NULL;
}
bool GHOST_WindowManager::getAnyModifiedState()
{
bool isAnyModified = false;
2012-05-19 09:57:55 +00:00
std::vector<GHOST_IWindow *>::iterator iter;
for (iter = m_windows.begin(); iter != m_windows.end(); ++iter) {
if ((*iter)->getModifiedState())
isAnyModified = true;
}
return isAnyModified;
2010-09-03 03:30:20 +00:00
}