/* panel.cc * This file is part of ncursesxx library * Copyright (c) 2003,2004 by Stanislav Ievlev * * This file is covered by the GNU Library General Public License, * which should be included with libncursesxx as the file COPYING. */ #include #include #include #include #include /* not using namespace, because curses already have struct with name panel */ ncurses::panel::panel (panel *parent) : window () , panel_ (0) , parent_ (parent) { /* create panel object */ panel_ = new_panel (win ()); if (!panel_) throw std::runtime_error ("new_panel failed"); if (parent_) { move_panel (panel_, parent_->y (), parent_->x ()); /* move to default position relative to father */ parent_->add_child (this); /* append itself to the father */ } hide (); /* hide widget by default */ } ncurses::panel::~panel () { if (parent_) parent_->del_child (this); /* remove child from the parent's list */ del_panel (panel_); } void ncurses::panel::add_child (panel *item) { childs_.push_back (item); /* append a new child to the list */ } void ncurses::panel::del_child (panel *item) { childs_.erase (std::remove (childs_.begin (), childs_.end (), item), childs_.end ()); } void ncurses::panel::top () { if (hidden ()) return; /* we should skip this function if panel hidden */ return_unless (::top_panel (panel_) == OK); foreach (panel *p, childs_) p->top (); } void ncurses::panel::bottom () { if (hidden ()) return; /* we should skip this function if panel hidden */ return_unless (::bottom_panel (panel_) == OK); foreach (panel *p, childs_) p->bottom (); } void ncurses::panel::show () { /* we should skip this function if panel already visible */ if (hidden ()) return_unless (::show_panel (panel_) == OK); foreach (panel *p, childs_) p->show (); } void ncurses::panel::hide () { /* we should skip this function if panel already hidden */ if (!hidden ()) return_unless (::hide_panel (panel_) == OK); foreach (panel *p, childs_) p->hide (); } bool ncurses::panel::hidden () const { return ::panel_hidden (panel_) == TRUE; } bool ncurses::panel::higher (panel const &other) const { PANEL *below = panel_; while ((below = panel_below (below)) != 0) if (below == other.panel_) return true; return false; } void ncurses::panel::draw () { } void ncurses::panel::prepare (bool recursive) { draw (); if (recursive) foreach (panel *child, childs_) child->prepare (); } void ncurses::panel::visualize (bool recursive) { prepare (recursive); show (); } void ncurses::panel::move (int new_x, int new_y, coords_type type) { /* save difference */ int const diffx = new_x - x (); int const diffy = new_y - y (); bool const abs_type = type == absolute || type == rel_parent; if (type == rel_parent && parent ()) { new_x += parent ()->x (); new_y += parent ()->y (); } move_panel ( panel_ , abs_type ? new_y : y () + new_y , abs_type ? new_x : x () + new_x ); /* childs_ always moving in relative coordinates */ foreach (panel *p, childs_) p->move (abs_type ? diffx : new_x, abs_type ? diffy : new_y); }