Update list of wide characters
[centerim5.git] / cppconsui / Window.cpp
blob8265f54e3c839af246ed2a63ce0b259ec35e417a
1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
2 //
3 // This file is part of CenterIM.
4 //
5 // CenterIM is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // CenterIM is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with CenterIM. If not, see <http://www.gnu.org/licenses/>.
18 /// @file
19 /// Window class implementation.
20 ///
21 /// @ingroup cppconsui
23 #include "Window.h"
25 #include "CoreManager.h"
27 #include <algorithm>
29 namespace CppConsUI {
31 Window::Window(int x, int y, int w, int h, Type t, bool decorated)
32 : Container(w, h), type_(t), decorated_(decorated), closable_(true)
34 initWindow(x, y, nullptr);
37 Window::Window(
38 int x, int y, int w, int h, const char *title, Type t, bool decorated)
39 : Container(w, h), type_(t), decorated_(decorated), closable_(true)
41 initWindow(x, y, title);
44 Window::~Window()
46 hide();
47 COREMANAGER->removeWindow(*this);
48 delete panel_;
51 int Window::draw(Curses::ViewPort area, Error &error)
53 DRAW(area.erase(error));
55 DRAW(Container::draw(area, error));
56 if (decorated_)
57 DRAW(panel_->draw(area, error));
59 // Reverse the top right corner of the window if there is not any focused
60 // widget and the window is the top window. This way the user knows which
61 // window is on the top and can be closed using the Esc key.
62 if (input_child_ == nullptr && COREMANAGER->getTopWindow() == this)
63 DRAW(area.changeAt(real_width_ - 1, 0, 1, Curses::Attr::REVERSE, 0, error));
65 return 0;
68 void Window::setVisibility(bool visible)
70 visible ? show() : hide();
73 Point Window::getAbsolutePosition() const
75 return Point(real_xpos_, real_ypos_);
78 bool Window::isWidgetVisible(const Widget & /*child*/) const
80 return true;
83 bool Window::setFocusChild(Widget &child)
85 cleanFocus();
87 focus_child_ = &child;
88 setInputChild(child);
90 if (COREMANAGER->getTopWindow() != this)
91 return false;
93 return true;
96 Point Window::getAbsolutePosition(const Widget &child) const
98 assert(child.getParent() == this);
100 int child_x = child.getRealLeft();
101 int child_y = child.getRealTop();
103 if (child_x != UNSETPOS && child_y != UNSETPOS) {
104 child_x -= scroll_xpos_;
105 child_y -= scroll_ypos_;
107 if (real_xpos_ != UNSETPOS && real_ypos_ != UNSETPOS)
108 return Point(real_xpos_ + child_x, real_ypos_ + child_y);
111 return Point(UNSETPOS, UNSETPOS);
114 void Window::show()
116 visible_ = true;
117 COREMANAGER->topWindow(*this);
118 signal_show(*this);
121 void Window::hide()
123 visible_ = false;
124 COREMANAGER->hideWindow(*this);
125 signal_hide(*this);
128 void Window::close()
130 signal_close(*this);
131 delete this;
134 void Window::setClosable(bool new_closable)
136 closable_ = new_closable;
139 void Window::signalMoveResize(const Rect &oldsize, const Rect &newsize)
141 COREMANAGER->onWindowMoveResize(*this, oldsize, newsize);
142 Container::signalMoveResize(oldsize, newsize);
145 void Window::signalWishSizeChange(const Size &oldsize, const Size &newsize)
147 COREMANAGER->onWindowWishSizeChange(*this, oldsize, newsize);
148 Container::signalWishSizeChange(oldsize, newsize);
151 void Window::updateArea()
153 panel_->setRealSize(real_width_, real_height_);
154 Container::updateArea();
157 void Window::redraw()
159 COREMANAGER->redraw();
162 void Window::initWindow(int x, int y, const char *title)
164 xpos_ = x;
165 ypos_ = y;
166 visible_ = false;
167 if (decorated_)
168 border_ = 1;
170 panel_ = new Panel(AUTOSIZE, AUTOSIZE, title);
171 panel_->setParent(*this);
172 panel_->setRealPosition(0, 0);
174 COREMANAGER->registerWindow(*this);
176 declareBindables();
179 void Window::actionClose()
181 if (closable_)
182 close();
185 void Window::declareBindables()
187 declareBindable("window", "close-window",
188 sigc::mem_fun(this, &Window::actionClose), InputProcessor::BINDABLE_NORMAL);
191 } // namespace CppConsUI
193 // vim: set tabstop=2 shiftwidth=2 textwidth=80 expandtab: