Blender  V3.3
GHOST_WindowManager.cpp
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright 2001-2002 NaN Holding BV. All rights reserved. */
3 
12 #include "GHOST_WindowManager.h"
13 #include "GHOST_Debug.h"
14 #include "GHOST_Window.h"
15 #include <algorithm>
16 
18  : m_fullScreenWindow(nullptr), m_activeWindow(nullptr), m_activeWindowBeforeFullScreen(nullptr)
19 {
20 }
21 
23 {
24  /* m_windows is freed by GHOST_System::disposeWindow */
25 }
26 
28 {
30  if (window) {
31  if (!getWindowFound(window)) {
32  /* Store the pointer to the window. */
33  m_windows.push_back(window);
34  success = GHOST_kSuccess;
35  }
36  }
37  return success;
38 }
39 
41 {
43  if (window) {
44  if (window == m_fullScreenWindow) {
45  endFullScreen();
46  }
47  else {
48  std::vector<GHOST_IWindow *>::iterator result = find(
49  m_windows.begin(), m_windows.end(), window);
50  if (result != m_windows.end()) {
51  setWindowInactive(window);
52  m_windows.erase(result);
53  success = GHOST_kSuccess;
54  }
55  }
56  }
57  return success;
58 }
59 
61 {
62  bool found = false;
63  if (window) {
64  if (getFullScreen() && (window == m_fullScreenWindow)) {
65  found = true;
66  }
67  else {
68  std::vector<GHOST_IWindow *>::const_iterator result = find(
69  m_windows.begin(), m_windows.end(), window);
70  if (result != m_windows.end()) {
71  found = true;
72  }
73  }
74  }
75  return found;
76 }
77 
79 {
80  return m_fullScreenWindow != nullptr;
81 }
82 
84 {
85  return m_fullScreenWindow;
86 }
87 
89 {
91  GHOST_ASSERT(window, "GHOST_WindowManager::beginFullScreen(): invalid window");
92  GHOST_ASSERT(window->getValid(), "GHOST_WindowManager::beginFullScreen(): invalid window");
93  if (!getFullScreen()) {
94  m_fullScreenWindow = window;
98  success = GHOST_kSuccess;
99  }
100  return success;
101 }
102 
104 {
105  GHOST_TSuccess success = GHOST_kFailure;
106  if (getFullScreen()) {
107  if (m_fullScreenWindow != nullptr) {
108  // GHOST_PRINT("GHOST_WindowManager::endFullScreen(): deleting full-screen window\n");
111  delete m_fullScreenWindow;
112  // GHOST_PRINT("GHOST_WindowManager::endFullScreen(): done\n");
113  m_fullScreenWindow = nullptr;
116  }
117  }
118  success = GHOST_kSuccess;
119  }
120  return success;
121 }
122 
124 {
125  GHOST_TSuccess success = GHOST_kSuccess;
126  if (window != m_activeWindow) {
127  if (getWindowFound(window)) {
128  m_activeWindow = window;
129  }
130  else {
131  success = GHOST_kFailure;
132  }
133  }
134  return success;
135 }
136 
138 {
139  return m_activeWindow;
140 }
141 
143 {
144  if (window == m_activeWindow) {
145  m_activeWindow = nullptr;
146  }
147 }
148 
149 const std::vector<GHOST_IWindow *> &GHOST_WindowManager::getWindows() const
150 {
151  return m_windows;
152 }
153 
155 {
156  std::vector<GHOST_IWindow *>::iterator iter;
157 
158  for (iter = m_windows.begin(); iter != m_windows.end(); ++iter) {
159  if ((*iter)->getOSWindow() == osWindow) {
160  return *iter;
161  }
162  }
163  return nullptr;
164 }
#define GHOST_ASSERT(x, info)
Definition: GHOST_Debug.h:54
GHOST_TSuccess
Definition: GHOST_Types.h:74
@ GHOST_kFailure
Definition: GHOST_Types.h:74
@ GHOST_kSuccess
Definition: GHOST_Types.h:74
virtual GHOST_TSuccess beginFullScreen() const =0
virtual bool getValid() const =0
virtual GHOST_TSuccess endFullScreen() const =0
GHOST_TSuccess addWindow(GHOST_IWindow *window)
GHOST_TSuccess endFullScreen(void)
bool getFullScreen(void) const
std::vector< GHOST_IWindow * > m_windows
GHOST_TSuccess removeWindow(const GHOST_IWindow *window)
GHOST_IWindow * getActiveWindow(void) const
GHOST_IWindow * m_activeWindowBeforeFullScreen
GHOST_IWindow * getWindowAssociatedWithOSWindow(void *osWindow)
const std::vector< GHOST_IWindow * > & getWindows() const
GHOST_IWindow * m_activeWindow
GHOST_TSuccess beginFullScreen(GHOST_IWindow *window, const bool stereoVisual)
GHOST_TSuccess setActiveWindow(GHOST_IWindow *window)
GHOST_IWindow * m_fullScreenWindow
bool getWindowFound(const GHOST_IWindow *window) const
GHOST_IWindow * getFullScreenWindow(void) const
void setWindowInactive(const GHOST_IWindow *window)