ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ncxx/panel.cpp
Revision: 1.6
Committed: Wed Oct 20 05:09:29 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +0 -0 lines
State: FILE REMOVED
Log Message:
unused

File Contents

# Content
1 /* panel.cc
2 * This file is part of ncursesxx library
3 * Copyright (c) 2003,2004 by Stanislav Ievlev
4 *
5 * This file is covered by the GNU Library General Public License,
6 * which should be included with libncursesxx as the file COPYING.
7 */
8 #include <ncurses/panel.hh>
9
10 #include <algorithm>
11 #include <functional>
12 #include <stdexcept>
13
14 #include <iostream>
15
16 /* not using namespace, because curses already have struct with name panel */
17 ncurses::panel::panel (panel *parent)
18 : window ()
19 , panel_ (0)
20 , parent_ (parent)
21 {
22 /* create panel object */
23 panel_ = new_panel (win ());
24 if (!panel_)
25 throw std::runtime_error ("new_panel failed");
26 if (parent_)
27 {
28 move_panel (panel_, parent_->y (), parent_->x ()); /* move to default position relative to father */
29 parent_->add_child (this); /* append itself to the father */
30 }
31 hide (); /* hide widget by default */
32 }
33
34 ncurses::panel::~panel ()
35 {
36 if (parent_)
37 parent_->del_child (this); /* remove child from the parent's list */
38 del_panel (panel_);
39 }
40
41 void
42 ncurses::panel::add_child (panel *item)
43 {
44 childs_.push_back (item); /* append a new child to the list */
45 }
46
47 void
48 ncurses::panel::del_child (panel *item)
49 {
50 childs_.erase (std::remove (childs_.begin (),
51 childs_.end (),
52 item), childs_.end ());
53 }
54
55 void
56 ncurses::panel::top ()
57 {
58 if (hidden ())
59 return; /* we should skip this function if panel hidden */
60 return_unless (::top_panel (panel_) == OK);
61 foreach (panel *p, childs_)
62 p->top ();
63 }
64
65 void
66 ncurses::panel::bottom ()
67 {
68 if (hidden ())
69 return; /* we should skip this function if panel hidden */
70 return_unless (::bottom_panel (panel_) == OK);
71 foreach (panel *p, childs_)
72 p->bottom ();
73 }
74
75 void
76 ncurses::panel::show ()
77 {
78 /* we should skip this function if panel already visible */
79 if (hidden ())
80 return_unless (::show_panel (panel_) == OK);
81 foreach (panel *p, childs_)
82 p->show ();
83 }
84
85 void
86 ncurses::panel::hide ()
87 {
88 /* we should skip this function if panel already hidden */
89 if (!hidden ())
90 return_unless (::hide_panel (panel_) == OK);
91 foreach (panel *p, childs_)
92 p->hide ();
93 }
94
95 bool
96 ncurses::panel::hidden () const
97 {
98 return ::panel_hidden (panel_) == TRUE;
99 }
100
101 bool
102 ncurses::panel::higher (panel const &other) const
103 {
104 PANEL *below = panel_;
105
106 while ((below = panel_below (below)) != 0)
107 if (below == other.panel_)
108 return true;
109 return false;
110 }
111
112 void
113 ncurses::panel::draw ()
114 {
115 }
116
117 void
118 ncurses::panel::prepare (bool recursive)
119 {
120 draw ();
121 if (recursive)
122 foreach (panel *child, childs_)
123 child->prepare ();
124 }
125
126 void
127 ncurses::panel::visualize (bool recursive)
128 {
129 prepare (recursive);
130 show ();
131 }
132
133 void
134 ncurses::panel::move (int new_x, int new_y, coords_type type)
135 {
136 /* save difference */
137 int const diffx = new_x - x ();
138 int const diffy = new_y - y ();
139 bool const abs_type = type == absolute || type == rel_parent;
140
141 if (type == rel_parent && parent ())
142 {
143 new_x += parent ()->x ();
144 new_y += parent ()->y ();
145 }
146
147 move_panel ( panel_
148 , abs_type ? new_y : y () + new_y
149 , abs_type ? new_x : x () + new_x
150 );
151
152 /* childs_ always moving in relative coordinates */
153 foreach (panel *p, childs_)
154 p->move (abs_type ? diffx : new_x, abs_type ? diffy : new_y);
155 }