ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/cf.schmorp.de/dclient/src/backend/ncxx/panel.cpp
Revision: 1.2
Committed: Mon Oct 18 06:54:02 2010 UTC (16 years ago) by sf-pippijn
Branch: MAIN
Changes since 1.1: +6 -6 lines
Log Message:
gcc 4.5; moved some code; background colour support

File Contents

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