| 1 |
sf-pippijn |
1.1 |
/* panel.cc |
| 2 |
|
|
* This file is part of NDK++ library |
| 3 |
|
|
* Copyright (c) 2003,2004 by Stanislav Ievlev |
| 4 |
|
|
* |
| 5 |
|
|
* This file is covered by the GNU Library General Public License, |
| 6 |
sf-pippijn |
1.4 |
* which should be included with libndk as the file COPYING. |
| 7 |
sf-pippijn |
1.1 |
*/ |
| 8 |
sf-pippijn |
1.4 |
#include <ndk/pen.hh> |
| 9 |
|
|
#include <ndk/palette.hh> |
| 10 |
sf-pippijn |
1.1 |
|
| 11 |
sf-pippijn |
1.4 |
#include <ndk/panel.hh> |
| 12 |
|
|
#include <ndk/application.hh> |
| 13 |
sf-pippijn |
1.1 |
|
| 14 |
sf-pippijn |
1.3 |
#include <algorithm> |
| 15 |
sf-pippijn |
1.1 |
|
| 16 |
|
|
ndk::panel::panel (panel *parent) |
| 17 |
sf-pippijn |
1.3 |
: parent_ (parent) |
| 18 |
sf-pippijn |
1.1 |
, events_ (parent ? parent->events () : 0, this) |
| 19 |
|
|
{ |
| 20 |
sf-pippijn |
1.3 |
/* create panel object */ |
| 21 |
|
|
panel_ = new_panel (win ()); |
| 22 |
|
|
if (!panel_) |
| 23 |
|
|
throw std::runtime_error ("new_panel failed"); |
| 24 |
|
|
if (parent_) |
| 25 |
|
|
{ |
| 26 |
|
|
move_panel (panel_, parent_->y (), parent_->x ()); /* move to default position relative to father */ |
| 27 |
|
|
parent_->add_child (this); /* append itself to the father */ |
| 28 |
|
|
} |
| 29 |
|
|
hide (); /* hide widget by default */ |
| 30 |
|
|
|
| 31 |
sf-pippijn |
1.1 |
events ()->on_system (ndk::slot (&panel::at_system, this)); |
| 32 |
|
|
} |
| 33 |
|
|
|
| 34 |
sf-pippijn |
1.3 |
ndk::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 |
|
|
ndk::panel::add_child (panel *item) |
| 43 |
|
|
{ |
| 44 |
|
|
childs_.push_back (item); /* append a new child to the list */ |
| 45 |
|
|
} |
| 46 |
|
|
|
| 47 |
|
|
void |
| 48 |
|
|
ndk::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 |
|
|
ndk::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 |
|
|
ndk::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 |
|
|
ndk::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 |
|
|
ndk::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 |
|
|
ndk::panel::hidden () const |
| 97 |
|
|
{ |
| 98 |
|
|
return ::panel_hidden (panel_) == TRUE; |
| 99 |
|
|
} |
| 100 |
|
|
|
| 101 |
|
|
bool |
| 102 |
|
|
ndk::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 |
|
|
ndk::panel::prepare (bool recursive) |
| 114 |
|
|
{ |
| 115 |
|
|
draw (); |
| 116 |
|
|
if (recursive) |
| 117 |
|
|
foreach (panel *child, childs_) |
| 118 |
|
|
child->prepare (); |
| 119 |
|
|
} |
| 120 |
|
|
|
| 121 |
|
|
void |
| 122 |
|
|
ndk::panel::visualize (bool recursive) |
| 123 |
|
|
{ |
| 124 |
|
|
prepare (recursive); |
| 125 |
|
|
show (); |
| 126 |
|
|
} |
| 127 |
|
|
|
| 128 |
|
|
void |
| 129 |
|
|
ndk::panel::move (int new_x, int new_y, coords_type type) |
| 130 |
|
|
{ |
| 131 |
|
|
/* save difference */ |
| 132 |
|
|
int const diffx = new_x - x (); |
| 133 |
|
|
int const diffy = new_y - y (); |
| 134 |
|
|
bool const abs_type = type == absolute || type == rel_parent; |
| 135 |
|
|
|
| 136 |
|
|
if (type == rel_parent && parent ()) |
| 137 |
|
|
{ |
| 138 |
|
|
new_x += parent ()->x (); |
| 139 |
|
|
new_y += parent ()->y (); |
| 140 |
|
|
} |
| 141 |
|
|
|
| 142 |
|
|
move_panel ( panel_ |
| 143 |
|
|
, abs_type ? new_y : y () + new_y |
| 144 |
|
|
, abs_type ? new_x : x () + new_x |
| 145 |
|
|
); |
| 146 |
|
|
|
| 147 |
|
|
/* childs_ always moving in relative coordinates */ |
| 148 |
|
|
foreach (panel *p, childs_) |
| 149 |
|
|
p->move (abs_type ? diffx : new_x, abs_type ? diffy : new_y); |
| 150 |
|
|
} |
| 151 |
|
|
|
| 152 |
sf-pippijn |
1.1 |
/** |
| 153 |
|
|
* @todo add support for palette |
| 154 |
|
|
*/ |
| 155 |
|
|
void |
| 156 |
|
|
ndk::panel::draw () |
| 157 |
|
|
{ |
| 158 |
sf-pippijn |
1.3 |
pen (*this).fill (palette::instance ().find (colors::panel)->second); |
| 159 |
sf-pippijn |
1.1 |
} |
| 160 |
|
|
|
| 161 |
|
|
int |
| 162 |
|
|
ndk::panel::padding () const |
| 163 |
|
|
{ |
| 164 |
|
|
return 0; |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
|
|
void |
| 168 |
|
|
ndk::panel::emit (int type) |
| 169 |
|
|
{ |
| 170 |
|
|
events_.emit (type); |
| 171 |
|
|
} |
| 172 |
|
|
|
| 173 |
|
|
ndk::engine * |
| 174 |
|
|
ndk::panel::events () |
| 175 |
|
|
{ |
| 176 |
|
|
return &events_; |
| 177 |
|
|
} |
| 178 |
|
|
|
| 179 |
|
|
void |
| 180 |
|
|
ndk::panel::in_focus (panel &other) |
| 181 |
|
|
{ |
| 182 |
|
|
events_.in_focus (other.events ()); |
| 183 |
|
|
} |
| 184 |
|
|
|
| 185 |
|
|
void |
| 186 |
|
|
ndk::panel::focus () |
| 187 |
|
|
{ |
| 188 |
|
|
if (parent ()) |
| 189 |
|
|
{ |
| 190 |
|
|
dynamic_cast<panel &> (*parent ()).focus (); |
| 191 |
|
|
dynamic_cast<panel &> (*parent ()).in_focus (*this); |
| 192 |
|
|
} |
| 193 |
|
|
else |
| 194 |
sf-pippijn |
1.3 |
ndk::app->in_focus (*this); |
| 195 |
sf-pippijn |
1.1 |
} |
| 196 |
|
|
|
| 197 |
|
|
ndk::event::result |
| 198 |
sf-pippijn |
1.2 |
ndk::panel::at_system (event const &ev) |
| 199 |
sf-pippijn |
1.1 |
{ |
| 200 |
|
|
if (!ev.sender_ && engine::enter_focus == ev.type_) |
| 201 |
|
|
{ |
| 202 |
|
|
top (); |
| 203 |
|
|
return event::accepted; |
| 204 |
|
|
} |
| 205 |
|
|
return event::ignored; |
| 206 |
|
|
} |