1 // Copyright (C) 2010-2015 Petr Pavlu <setup@dagobah.cz>
3 // This file is part of CenterIM.
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.
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/>.
19 /// Window class implementation.
21 /// @ingroup cppconsui
25 #include "CoreManager.h"
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);
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
);
47 COREMANAGER
->removeWindow(*this);
51 int Window::draw(Curses::ViewPort area
, Error
&error
)
53 DRAW(area
.erase(error
));
55 DRAW(Container::draw(area
, error
));
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
));
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
83 bool Window::setFocusChild(Widget
&child
)
87 focus_child_
= &child
;
90 if (COREMANAGER
->getTopWindow() != this)
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
);
117 COREMANAGER
->topWindow(*this);
124 COREMANAGER
->hideWindow(*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
)
170 panel_
= new Panel(AUTOSIZE
, AUTOSIZE
, title
);
171 panel_
->setParent(*this);
172 panel_
->setRealPosition(0, 0);
174 COREMANAGER
->registerWindow(*this);
179 void Window::actionClose()
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: