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)
5  2008, Joel Holdsworth <joel@airwebreathe.org.uk>
6 
7   **Lumiera** is free software; you can redistribute it and/or modify it
8   under the terms of the GNU General Public License as published by the
9   Free Software Foundation; either version 2 of the License, or (at your
10   option) any later version. See the file COPYING for further details.
11 
12 * *****************************************************************/
13 
14 
26 #include "lib/util.hpp"
27 
28 #include <memory>
29 #include <list>
30 
31 using util::isnil;
32 using std::list;
33 
34 
35 namespace stage {
36 namespace ctrl {
37 
38  using workspace::WorkspaceWindow;
39 
40 
41 
42  PanelLocator::PanelLocator (WindowList& all_top_level_wndows)
43  : windowList_{all_top_level_wndows}
44  { }
45 
46 
47 
48  WindowLocator::WindowLocator (GlobalCtx& globals)
49  : globalCtx_{globals}
50  , windowList_{}
51  , panelLoc_{windowList_}
52  , elementAccess_{*this, panelLoc_}
53  { }
54 
55  WindowLocator::~WindowLocator () { }
56 
57 
58 
59  void
60  WindowLocator::newWindow ()
61  {
62  PWindow window (new WorkspaceWindow{globalCtx_.uiManager_});
63  REQUIRE(window);
64 
65  window->signal_delete_event().connect(sigc::mem_fun(
66  this, &WindowLocator::on_window_closed));
67 
68  windowList_.push_back(window);
69 
70  window->show();
71 
72  updateCloseWindowInMenus();
73  }
74 
75 
81  void
82  WindowLocator::closeWindow()
83  {
84  findActiveWindow().hide();
85  }
86 
87 
96  WindowLocator::findActiveWindow()
97  {
98  REQUIRE (not isnil (windowList_));
99 
100  for (auto pwin : windowList_)
101  if (pwin->is_active())
102  return *pwin;
103 
104  // use the first window in list when none is active
105  return *windowList_.front();
106  }
107 
108 
114  WindowLocator::findFocusWindow()
115  {
116  REQUIRE (not isnil (windowList_));
117 
118  for (auto pwin : windowList_)
119  if (pwin->has_focus())
120  return *pwin;
121 
122  // use the first window in list when none has focus
123  return *windowList_.front();
124  }
125 
126 
127  bool
128  WindowLocator::on_window_closed (GdkEventAny* event)
129  {
130  REQUIRE(event);
131  REQUIRE(event->window);
132 
133  list<PWindow>::iterator iterator{windowList_.begin()};
134 
135  while (iterator != windowList_.end())
136  {
137  PWindow workspace_window(*iterator);
138  REQUIRE(workspace_window);
139 
140  Glib::RefPtr<Gdk::Window> window = workspace_window->get_window();
141  REQUIRE(window);
142  if (window->gobj() == event->window)
143  {
144  // This window has been closed
145  iterator = windowList_.erase(iterator);
146  }
147  else
148  iterator++;
149  }
150 
151  if (windowList_.empty())
152  // All windows have been closed - we should exit
153  globalCtx_.uiManager_.terminateUI();
154 
155  updateCloseWindowInMenus();
156 
157  // Unless this is false, the window won't close
158  return false;
159  }
160 
161 
162  void
163  WindowLocator::updateCloseWindowInMenus()
164  {
165  globalCtx_.uiManager_.allowCloseWindow ( 1 < windowList_.size());
166  }
167 
168 
175  panel::Panel&
176  PanelLocator::preliminary_impl_PanelLookup (int typeID)
177  {
178  REQUIRE (not isnil(windowList_));
179 
180  for (auto window : windowList_)
181  if (window->getPanelManager().hasPanel (typeID))
182  return window->getPanelManager().showPanel (typeID);
183 
184  // no instance of the desired panel type exists yet...
185  for (auto window : windowList_)
186  if (window->is_active())
187  return window->getPanelManager().showPanel (typeID);
188 
189  // use the first window in list when none is active
190  return windowList_.front()->getPanelManager().showPanel (typeID);
191  }
192 
193 
194 
195 
196 
197 }}// namespace stage::ctrl
Dependency context to hold all the global UI top-level entities.
The base class for all dockable panels.
Definition: panel.hpp:40
Lumiera GTK UI implementation root.
Definition: guifacade.cpp:37
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...