Lumiera  0.pre.03
»edit your freedom«
window-locator.cpp
Go to the documentation of this file.
1 /*
2  WindowLocator - manage all top level windows
3 
4  Copyright (C) Lumiera.org
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
23 
35 #include "lib/util.hpp"
36 
37 #include <memory>
38 #include <list>
39 
40 using util::isnil;
41 using std::list;
42 
43 
44 namespace stage {
45 namespace ctrl {
46 
47  using workspace::WorkspaceWindow;
48 
49 
50 
51  PanelLocator::PanelLocator (WindowList& all_top_level_wndows)
52  : windowList_{all_top_level_wndows}
53  { }
54 
55 
56 
57  WindowLocator::WindowLocator (GlobalCtx& globals)
58  : globalCtx_{globals}
59  , windowList_{}
60  , panelLoc_{windowList_}
61  , elementAccess_{*this, panelLoc_}
62  { }
63 
64  WindowLocator::~WindowLocator () { }
65 
66 
67 
68  void
69  WindowLocator::newWindow ()
70  {
71  PWindow window (new WorkspaceWindow{globalCtx_.uiManager_});
72  REQUIRE(window);
73 
74  window->signal_delete_event().connect(sigc::mem_fun(
75  this, &WindowLocator::on_window_closed));
76 
77  windowList_.push_back(window);
78 
79  window->show();
80 
81  updateCloseWindowInMenus();
82  }
83 
84 
90  void
91  WindowLocator::closeWindow()
92  {
93  findActiveWindow().hide();
94  }
95 
96 
105  WindowLocator::findActiveWindow()
106  {
107  REQUIRE (not isnil (windowList_));
108 
109  for (auto pwin : windowList_)
110  if (pwin->is_active())
111  return *pwin;
112 
113  // use the first window in list when none is active
114  return *windowList_.front();
115  }
116 
117 
123  WindowLocator::findFocusWindow()
124  {
125  REQUIRE (not isnil (windowList_));
126 
127  for (auto pwin : windowList_)
128  if (pwin->has_focus())
129  return *pwin;
130 
131  // use the first window in list when none has focus
132  return *windowList_.front();
133  }
134 
135 
136  bool
137  WindowLocator::on_window_closed (GdkEventAny* event)
138  {
139  REQUIRE(event);
140  REQUIRE(event->window);
141 
142  list<PWindow>::iterator iterator{windowList_.begin()};
143 
144  while (iterator != windowList_.end())
145  {
146  PWindow workspace_window(*iterator);
147  REQUIRE(workspace_window);
148 
149  Glib::RefPtr<Gdk::Window> window = workspace_window->get_window();
150  REQUIRE(window);
151  if (window->gobj() == event->window)
152  {
153  // This window has been closed
154  iterator = windowList_.erase(iterator);
155  }
156  else
157  iterator++;
158  }
159 
160  if (windowList_.empty())
161  // All windows have been closed - we should exit
162  globalCtx_.uiManager_.terminateUI();
163 
164  updateCloseWindowInMenus();
165 
166  // Unless this is false, the window won't close
167  return false;
168  }
169 
170 
171  void
172  WindowLocator::updateCloseWindowInMenus()
173  {
174  globalCtx_.uiManager_.allowCloseWindow ( 1 < windowList_.size());
175  }
176 
177 
184  panel::Panel&
185  PanelLocator::preliminary_impl_PanelLookup (int typeID)
186  {
187  REQUIRE (not isnil(windowList_));
188 
189  for (auto window : windowList_)
190  if (window->getPanelManager().hasPanel (typeID))
191  return window->getPanelManager().showPanel (typeID);
192 
193  // no instance of the desired panel type exists yet...
194  for (auto window : windowList_)
195  if (window->is_active())
196  return window->getPanelManager().showPanel (typeID);
197 
198  // use the first window in list when none is active
199  return windowList_.front()->getPanelManager().showPanel (typeID);
200  }
201 
202 
203 
204 
205 
206 }}// namespace stage::ctrl
Dependency context to hold all the global UI top-level entities.
The base class for all dockable panels.
Definition: panel.hpp:49
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:46
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Access and query front-end to locate, access and place docking panels.
Manager for all top level application windows.
The main Lumiera workspace window.
A service to discover and access raw UI elements in a cross cutting way.
This file contains the definition of the main workspace window parent, which is the toplevel parent o...