1 |
/* panel.hh |
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 |
* which should be included with libndk as the file COPYING. |
7 |
*/ |
8 |
#pragma once |
9 |
|
10 |
#include <ndk/transport.hh> |
11 |
#include <ndk/window.hh> |
12 |
|
13 |
#include <curses.h> |
14 |
#include <panel.h> |
15 |
|
16 |
#include <vector> |
17 |
|
18 |
namespace ndk |
19 |
{ |
20 |
/** |
21 |
* meaning of coordinates |
22 |
*/ |
23 |
enum coords_type |
24 |
{ |
25 |
absolute, /**< absolute coordinate of screen */ |
26 |
relative, /**< relative to previous position coordinate */ |
27 |
rel_parent /**< relative to parent coordinate */ |
28 |
}; |
29 |
|
30 |
/** |
31 |
* Extended version of panel, supports all NDK event engine |
32 |
* and general color pallete |
33 |
*/ |
34 |
struct panel |
35 |
: window |
36 |
{ |
37 |
typedef std::vector<panel *> child_vector; /**< list of the panels */ |
38 |
|
39 |
explicit panel (panel *parent = 0); |
40 |
virtual ~panel (); |
41 |
|
42 |
virtual void top (); /**< put this panel on top of all panels in the stack */ |
43 |
virtual void bottom (); /**< put this panel at the bottom of all panels */ |
44 |
virtual void show (); /**< makes a hidden panel visible by placing it on top of the panels */ |
45 |
virtual void hide (); /**< removes the given panel from the panel stack and thus hides it from view */ |
46 |
|
47 |
bool hidden () const; /**< are this widget hidden? */ |
48 |
bool higher (const panel &) const; /**< are we higher other panel */ |
49 |
|
50 |
|
51 |
virtual void draw (); /**< draw widget specific content over general panel */ |
52 |
void prepare (bool recursive = true); /**< draw this widget and all subwidgets */ |
53 |
void visualize (bool recursive = true); /**< equivalent of prepare + show */ |
54 |
|
55 |
/** |
56 |
* move panel to the other place, refresh state of other panels |
57 |
* @param x absolute or relative to previous position x coordinate |
58 |
* @param y absolute or relative to previous position y coordinate |
59 |
* @param |
60 |
*/ |
61 |
virtual void move (int x, int y, coords_type type = relative); |
62 |
|
63 |
panel *parent () const { return parent_; } |
64 |
|
65 |
/** |
66 |
* return padding size from the edge, helps to control drawing area |
67 |
* it's usefull for packing under frames: active area will be |
68 |
* (x()+padding(),x()+width()-padding()) x (y()+padding(),y()+height()-padding()) |
69 |
*/ |
70 |
virtual int padding () const; |
71 |
|
72 |
void emit (int); // gate to emit some events |
73 |
engine *events (); // entry point to events roadway |
74 |
void in_focus (panel &); // set widget as in focus |
75 |
|
76 |
void focus (); |
77 |
|
78 |
protected: |
79 |
void add_child (panel *p); /**< helper to create panel's hieracly */ |
80 |
void del_child (panel *p); /**< delete from the childs list */ |
81 |
|
82 |
private: |
83 |
/* hide dangerous operations */ |
84 |
panel (const panel &other); |
85 |
panel &operator = (const panel &other); |
86 |
|
87 |
PANEL *panel_; /**< internal ncurses panel structure */ |
88 |
panel *parent_; /**< parent panel, if we have*/ |
89 |
child_vector childs_; /**< childs of this */ |
90 |
|
91 |
private: |
92 |
event::result at_system (const event &); |
93 |
engine events_; |
94 |
}; |
95 |
|
96 |
static inline bool |
97 |
operator < (const panel &lhs, const panel &rhs) |
98 |
{ |
99 |
return rhs.higher (lhs); |
100 |
} |
101 |
|
102 |
static inline bool |
103 |
operator > (const panel &lhs, const panel &rhs) |
104 |
{ |
105 |
return lhs.higher (rhs); |
106 |
} |
107 |
} |