~ci-train-bot/unity/unity-ubuntu-yakkety-landing-089

3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
2
/*
3
* Copyright (C) 2013 Canonical Ltd
4
*
5
* This program is free software: you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License version 3 as
7
* published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
* GNU General Public License for more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
*
17
* Authored by: Marco Trevisan (Treviño) <marco@ubuntu.com>
18
*/
19
20
#include "SessionView.h"
3144.4.42 by Marco Trevisan (Treviño)
SessionButton: extract it from the SessionView
21
#include "SessionButton.h"
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
22
23
#include <UnityCore/GLibWrapper.h>
24
#include <glib/gi18n-lib.h>
3144.4.6 by Marco Trevisan (Treviño)
ShutdownView: add buttons views, use correct padding as provided by design
25
3794.5.6 by Marco Trevisan (Treviño)
UnityWindowView: don't include UnitySettings in the header...
26
#include "unity-shared/RawPixel.h"
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
27
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
28
namespace unity
29
{
30
namespace session
31
{
3144.4.6 by Marco Trevisan (Treviño)
ShutdownView: add buttons views, use correct padding as provided by design
32
3144.4.68 by Marco Trevisan (Treviño)
Session: renaming theme namespace to style
33
namespace style
3144.4.21 by Marco Trevisan (Treviño)
SessionView: use local variables to store parameters
34
{
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
35
  std::string const FONT = "Ubuntu Light";
36
  std::string const TITLE_FONT = FONT+" 15";
37
  std::string const SUBTITLE_FONT = FONT+" 12";
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
38
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
39
  RawPixel const LEFT_RIGHT_PADDING = 30_em;
40
  RawPixel const TOP_PADDING        = 19_em;
41
  RawPixel const BOTTOM_PADDING     = 12_em;
42
  RawPixel const MAIN_SPACE         = 10_em;
43
  RawPixel const BUTTONS_SPACE      = 20_em;
3144.4.21 by Marco Trevisan (Treviño)
SessionView: use local variables to store parameters
44
}
45
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
46
NUX_IMPLEMENT_OBJECT_TYPE(View);
47
3347.5.14 by Marco Trevisan (Treviño)
BackgroundEffectHelper: connect to owner geometry changes to update the requested blur geo
48
View::View(Manager::Ptr const& manager)
49
  : mode(Mode::FULL)
3227.1.9 by Marco Trevisan (Treviño)
SessionView: save the button to key-focus into a RO property
50
  , key_focus_area([this] { return key_focus_area_; })
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
51
  , manager_(manager)
3227.1.9 by Marco Trevisan (Treviño)
SessionView: save the button to key-focus into a RO property
52
  , key_focus_area_(this)
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
53
{
54
  closable = true;
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
55
  main_layout_ = new nux::VLayout();
56
  SetLayout(main_layout_);
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
57
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
58
  title_ = new StaticCairoText("");
3144.4.68 by Marco Trevisan (Treviño)
Session: renaming theme namespace to style
59
  title_->SetFont(style::TITLE_FONT);
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
60
  title_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
61
  title_->SetInputEventSensitivity(false);
62
  title_->SetVisible(false);
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
63
  main_layout_->AddView(title_);
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
64
65
  subtitle_ = new StaticCairoText("");
3144.4.68 by Marco Trevisan (Treviño)
Session: renaming theme namespace to style
66
  subtitle_->SetFont(style::SUBTITLE_FONT);
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
67
  subtitle_->SetTextAlignment(StaticCairoText::AlignState::NUX_ALIGN_LEFT);
68
  subtitle_->SetInputEventSensitivity(false);
69
  subtitle_->SetLines(std::numeric_limits<int>::min());
70
  subtitle_->SetLineSpacing(2);
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
71
  main_layout_->AddView(subtitle_);
3144.4.6 by Marco Trevisan (Treviño)
ShutdownView: add buttons views, use correct padding as provided by design
72
73
  buttons_layout_ = new nux::HLayout();
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
74
  main_layout_->AddLayout(buttons_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_PERCENTAGE, 0.0f);
3144.4.6 by Marco Trevisan (Treviño)
ShutdownView: add buttons views, use correct padding as provided by design
75
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
76
  GetBoundingArea()->mouse_click.connect([this] (int, int, unsigned long, unsigned long) { request_close.emit(); });
77
78
  have_inhibitors.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
79
  manager_->have_other_open_sessions.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateText)));
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
80
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
81
  mode.SetSetterFunction([this] (Mode& target, Mode new_mode) {
82
    if (new_mode == Mode::SHUTDOWN && !manager_->CanShutdown())
83
      new_mode = Mode::LOGOUT;
84
85
    if (target != new_mode)
86
    {
87
      target = new_mode;
88
      return true;
89
    }
90
91
    return false;
92
  });
93
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
94
  mode.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateContents)));
3794.5.8 by Marco Trevisan (Treviño)
UnityWindowView: only expose scale instead of the EMConverter, so we get proper notifications
95
  scale.changed.connect(sigc::hide(sigc::mem_fun(this, &View::UpdateViewSize)));
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
96
  UpdateContents();
97
}
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
98
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
99
void View::UpdateContents()
100
{
3806.11.6 by Marco Trevisan (Treviño)
SessionView: immediately cancel and hide the dialog if there's no action we can do
101
  SetVisible(true);
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
102
  PopulateButtons();
103
  UpdateText();
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
104
  UpdateViewSize();
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
105
}
106
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
107
void View::UpdateViewSize()
108
{
3794.5.8 by Marco Trevisan (Treviño)
UnityWindowView: only expose scale instead of the EMConverter, so we get proper notifications
109
  main_layout_->SetTopAndBottomPadding(style::TOP_PADDING.CP(scale()), style::BOTTOM_PADDING.CP(scale()));
110
  main_layout_->SetLeftAndRightPadding(style::LEFT_RIGHT_PADDING.CP(scale()));
111
  main_layout_->SetSpaceBetweenChildren(style::MAIN_SPACE.CP(scale()));
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
112
3794.5.8 by Marco Trevisan (Treviño)
UnityWindowView: only expose scale instead of the EMConverter, so we get proper notifications
113
  title_->SetScale(scale());
114
  subtitle_->SetScale(scale());
3788.4.6 by Brandon Schaefer
* Scale the closeable window button as well.
115
116
  ReloadCloseButtonTexture();
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
117
3794.5.8 by Marco Trevisan (Treviño)
UnityWindowView: only expose scale instead of the EMConverter, so we get proper notifications
118
  buttons_layout_->SetSpaceBetweenChildren(style::BUTTONS_SPACE.CP(scale()));
3806.11.5 by Marco Trevisan (Treviño)
SessionView: add some padding if we only can show one button
119
  auto const& buttons = buttons_layout_->GetChildren();
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
120
3806.11.5 by Marco Trevisan (Treviño)
SessionView: add some padding if we only can show one button
121
  for (auto* area : buttons)
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
122
    static_cast<Button*>(area)->scale = scale();
3806.11.5 by Marco Trevisan (Treviño)
SessionView: add some padding if we only can show one button
123
124
  if (buttons.size() == 1)
125
  {
126
    auto* button = buttons.front();
127
    button->ComputeContentSize();
128
    int padding = button->GetWidth()/2 + style::MAIN_SPACE.CP(scale())/2;
129
    buttons_layout_->SetLeftAndRightPadding(padding, padding);
130
  }
3788.4.1 by Brandon Schaefer
* First stage of Shutdown Dialog HiDPI Support
131
}
132
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
133
void View::UpdateText()
134
{
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
135
  std::string message;
136
  std::string other_users_msg;
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
137
  auto const& real_name = manager_->RealName();
138
  auto const& name = (real_name.empty() ? manager_->UserName() : real_name);
139
3785.4.5 by Andrea Azzarone
Update string.
140
  other_users_msg = _("Other users are logged in. Restarting or shutting down will close their open applications and may cause them to lose work.\n\n");
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
141
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
142
  if (mode() == Mode::SHUTDOWN)
143
  {
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
144
    title_->SetText(_("Shut Down"));
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
145
    title_->SetVisible(true);
146
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
147
    if (manager_->have_other_open_sessions())
148
    {
149
      message += other_users_msg;
150
    }
151
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
152
    if (have_inhibitors())
153
    {
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
154
      message += _("Hi %s, you have open files that you might want to save " \
155
                   "before shutting down. Are you sure you want to continue?");
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
156
    }
157
    else
158
    {
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
159
      message += _("Goodbye, %s. Are you sure you want to close all programs " \
160
                   "and shut down the computer?");
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
161
    }
162
  }
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
163
  else if (mode() == Mode::LOGOUT)
164
  {
165
    title_->SetText(_("Log Out"));
166
    title_->SetVisible(true);
167
168
    if (have_inhibitors())
169
    {
170
      message = _("Hi %s, you have open files that you might want to save " \
171
                  "before logging out. Are you sure you want to continue?");
172
    }
173
    else
174
    {
3240.1.2 by Paolo Rotolo
Shutdown message: replace "!" with ".".
175
      message = _("Goodbye, %s. Are you sure you want to close all programs " \
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
176
                  "and log out from your account?");
177
    }
178
  }
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
179
  else
180
  {
181
    title_->SetVisible(false);
182
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
183
    if (manager_->have_other_open_sessions())
184
    {
185
      message += other_users_msg;
186
    }
187
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
188
    if (have_inhibitors())
189
    {
3144.4.86 by Marco Trevisan (Treviño)
SessionView: don't use a new-line on text message when we have enough space
190
      if (buttons_layout_->GetChildren().size() > 3)
191
      {
192
        // We have enough buttons to show the message without a new line.
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
193
        message += _("Hi %s, you have open files you might want to save. " \
3144.4.86 by Marco Trevisan (Treviño)
SessionView: don't use a new-line on text message when we have enough space
194
                    "Would you like to…");
195
      }
196
      else
197
      {
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
198
        message += _("Hi %s, you have open files you might want to save.\n" \
3144.4.86 by Marco Trevisan (Treviño)
SessionView: don't use a new-line on text message when we have enough space
199
                    "Would you like to…");
200
      }
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
201
    }
202
    else
203
    {
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
204
      message += _("Goodbye, %s. Would you like to…");
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
205
    }
206
  }
207
3769.1.1 by Andrea Azzarone
Add a warning in the session dialog if other sessions are still open.
208
  subtitle_->SetText(glib::String(g_strdup_printf(message.c_str(), name.c_str())).Str());
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
209
}
210
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
211
void View::PopulateButtons()
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
212
{
3144.4.78 by Marco Trevisan (Treviño)
SessionButton, SessionController, SessionView: add some more introspection
213
  debug::Introspectable::RemoveAllChildren();
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
214
  buttons_layout_->Clear();
3806.11.5 by Marco Trevisan (Treviño)
SessionView: add some padding if we only can show one button
215
  buttons_layout_->SetLeftAndRightPadding(0, 0);
3227.1.9 by Marco Trevisan (Treviño)
SessionView: save the button to key-focus into a RO property
216
  key_focus_area_ = this;
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
217
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
218
  if (mode() == Mode::LOGOUT)
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
219
  {
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
220
    if (manager_->is_locked())
221
      return;
222
223
    if (manager_->CanLock())
224
    {
225
      auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
226
      button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
227
      AddButton(button);
228
    }
229
230
    auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
231
    button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
3227.1.9 by Marco Trevisan (Treviño)
SessionView: save the button to key-focus into a RO property
232
    key_focus_area_ = button;
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
233
    AddButton(button);
234
  }
235
  else
236
  {
237
    if (mode() == Mode::FULL)
238
    {
3983.7.1 by Marco Trevisan (Treviño)
SessionView: don't show Lock button if session is currently locked
239
      if (manager_->CanLock() && !manager_->is_locked())
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
240
      {
241
        auto* button = new Button(Button::Action::LOCK, NUX_TRACKER_LOCATION);
242
        button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::LockScreen));
243
        AddButton(button);
244
      }
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
245
246
      if (manager_->CanSuspend())
247
      {
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
248
        auto* button = new Button(Button::Action::SUSPEND, NUX_TRACKER_LOCATION);
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
249
        button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Suspend));
250
        AddButton(button);
251
      }
252
253
      if (manager_->CanHibernate())
254
      {
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
255
        auto* button = new Button(Button::Action::HIBERNATE, NUX_TRACKER_LOCATION);
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
256
        button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Hibernate));
257
        AddButton(button);
258
      }
259
    }
260
261
    if (manager_->CanShutdown())
262
    {
3227.1.7 by Marco Trevisan (Treviño)
SessionView: invert the position of reboot/shutdown buttons
263
      auto *button = new Button(Button::Action::REBOOT, NUX_TRACKER_LOCATION);
264
      button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Reboot));
265
      AddButton(button);
266
267
      button = new Button(Button::Action::SHUTDOWN, NUX_TRACKER_LOCATION);
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
268
      button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Shutdown));
3227.1.9 by Marco Trevisan (Treviño)
SessionView: save the button to key-focus into a RO property
269
      key_focus_area_ = (mode() == Mode::SHUTDOWN) ? button : key_focus_area_;
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
270
      AddButton(button);
271
    }
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
272
    else if (mode() == Mode::FULL && !manager_->is_locked())
3144.4.80 by Marco Trevisan (Treviño)
TestSessionView: added tests to check the view elements on mode changes
273
    {
3227.1.2 by Marco Trevisan (Treviño)
SessionButton: generate labels and texture internally by Action
274
      auto* button = new Button(Button::Action::LOGOUT, NUX_TRACKER_LOCATION);
3144.4.80 by Marco Trevisan (Treviño)
TestSessionView: added tests to check the view elements on mode changes
275
      button->activated.connect(sigc::mem_fun(manager_.get(), &Manager::Logout));
276
      AddButton(button);
277
    }
3144.4.58 by Marco Trevisan (Treviño)
SessionView: add logout mode
278
  }
3806.11.6 by Marco Trevisan (Treviño)
SessionView: immediately cancel and hide the dialog if there's no action we can do
279
280
  cancel_idle_.reset();
281
  if (buttons_layout_->GetChildren().empty())
282
  {
283
    // There's nothing to show here, let's cancel the action and hide
284
    SetVisible(false);
285
    cancel_idle_.reset(new glib::Idle([this] { request_close.emit(); return false; }));
286
  }
3144.4.43 by Marco Trevisan (Treviño)
SessionView: add an utility function to add a button, handle window hiding there
287
}
288
289
void View::AddButton(Button* button)
290
{
3806.11.4 by Marco Trevisan (Treviño)
SessionView: only show the lock options if we are allowed to lock and not currently locked
291
  button->scale = scale();
3144.4.13 by Marco Trevisan (Treviño)
SessionView: add activate signal to buttons
292
  button->activated.connect([this] {request_hide.emit();});
3144.4.6 by Marco Trevisan (Treviño)
ShutdownView: add buttons views, use correct padding as provided by design
293
  buttons_layout_->AddView(button);
3144.4.78 by Marco Trevisan (Treviño)
SessionButton, SessionController, SessionView: add some more introspection
294
  debug::Introspectable::AddChild(button);
3144.4.43 by Marco Trevisan (Treviño)
SessionView: add an utility function to add a button, handle window hiding there
295
3144.4.44 by Marco Trevisan (Treviño)
SessionView: reset the keyfocus area when a button is deselected
296
  // This resets back the keyboard focus to the view when a button is unselected
297
  button->highlighted.changed.connect([this] (bool value) {
298
    if (!value)
299
      nux::GetWindowCompositor().SetKeyFocusArea(this);
300
  });
301
3144.4.43 by Marco Trevisan (Treviño)
SessionView: add an utility function to add a button, handle window hiding there
302
  // This function ensures that when an item is activated, the button state
303
  // is reset as soon as the parent window has been closed.
304
  button->activated.connect([this, button] {
305
    auto* top_win = static_cast<nux::BaseWindow*>(GetTopLevelViewWindow());
306
    if (top_win && top_win->IsVisible())
307
    {
308
      auto conn = std::make_shared<sigc::connection>();
309
      *conn = top_win->sigHidden.connect([this, button, conn] (nux::BaseWindow*) {
310
        button->highlighted = false;
311
        conn->disconnect();
312
      });
313
    }
314
    else
315
    {
316
      button->highlighted = false;
317
    }
318
  });
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
319
}
320
3144.4.55 by Marco Trevisan (Treviño)
SessionView: update the view so that it adapts to the current mode
321
void View::PreLayoutManagement()
322
{
323
  subtitle_->SetMaximumWidth(buttons_layout_->GetContentWidth());
324
325
  nux::View::PreLayoutManagement();
326
}
327
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
328
nux::Geometry View::GetBackgroundGeometry()
329
{
330
  return GetGeometry();
331
}
332
3144.4.22 by Marco Trevisan (Treviño)
Merging with closable window changes
333
void View::DrawOverlay(nux::GraphicsEngine& GfxContext, bool force_draw, nux::Geometry const& clip)
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
334
{
335
  view_layout_->ProcessDraw(GfxContext, force_draw);
336
}
337
3144.4.41 by Marco Trevisan (Treviño)
SessionView: implement keyboard navigation
338
nux::Area* View::FindKeyFocusArea(unsigned etype, unsigned long key_code, unsigned long modifiers)
339
{
340
  if (etype != nux::NUX_KEYDOWN)
341
    return UnityWindowView::FindKeyFocusArea(etype, key_code, modifiers);
342
343
  if (key_code == NUX_VK_LEFT || key_code == NUX_VK_RIGHT)
344
  {
345
    nux::InputArea* focused = nux::GetWindowCompositor().GetKeyFocusArea();
346
347
    if (!focused || focused == this || !focused->IsChildOf(this))
348
    {
349
      if (key_code == NUX_VK_LEFT)
350
      {
351
        return buttons_layout_->GetChildren().front();
352
      }
353
      else if (key_code == NUX_VK_RIGHT)
354
      {
355
        return buttons_layout_->GetChildren().back();
356
      }
357
    }
358
  }
359
3144.4.66 by Marco Trevisan (Treviño)
SessionView: fallback key analsys to parent object
360
  return UnityWindowView::FindKeyFocusArea(etype, key_code, modifiers);
3144.4.41 by Marco Trevisan (Treviño)
SessionView: implement keyboard navigation
361
}
362
363
nux::Area* View::KeyNavIteration(nux::KeyNavDirection direction)
364
{
365
  if (direction == nux::KEY_NAV_LEFT)
366
    return buttons_layout_->GetChildren().back();
367
  else if (direction == nux::KEY_NAV_RIGHT)
368
    return buttons_layout_->GetChildren().front();
369
370
  return nux::View::KeyNavIteration(direction);
371
}
372
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
373
//
374
// Introspectable methods
375
//
376
std::string View::GetName() const
377
{
378
  return "SessionView";
379
}
380
3506.6.3 by Marco Trevisan (Treviño)
Introspectable: use IntrospectionData class for collecting data from children
381
void View::AddProperties(debug::IntrospectionData& introspection)
3144.4.78 by Marco Trevisan (Treviño)
SessionButton, SessionController, SessionView: add some more introspection
382
{
3506.6.3 by Marco Trevisan (Treviño)
Introspectable: use IntrospectionData class for collecting data from children
383
  UnityWindowView::AddProperties(introspection);
384
  introspection
3144.4.78 by Marco Trevisan (Treviño)
SessionButton, SessionController, SessionView: add some more introspection
385
    .add("mode", static_cast<int>(mode()))
386
    .add("inhibitors", have_inhibitors())
387
    .add("title",title_->GetText())
388
    .add("subtitle",subtitle_->GetText());
389
}
390
3144.4.4 by Marco Trevisan (Treviño)
ShutdownView: first draft implementation
391
} // namespace session
392
} // namespace unity