forked from yuryfdr/pbtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpbwidget.h
196 lines (170 loc) · 5.95 KB
/
pbwidget.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
/* Copyright (C) 2009 AI */
/* Copyright (C) 2011-2012 Yury P. Fedorchenko (yuryfdr at users.sf.net) */
/*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef PBCONTROL_H
#define PBCONTROL_H
#include <stdio.h>
#include <map>
#include <string>
#include <utility>
#include <algorithm>
#include <vector>
#include <sigc++/sigc++.h>
#include <boost/shared_ptr.hpp>
#undef IVSAPP
#include "inkview.h"
#include "PBImg.h"
#define BORDER_SPACE 4 // space between controls
/**
base class
*/
class PBWidget {
virtual int dispatchMsgToWidgets(int type, int par1, int par2);
protected:
std::string _text;
int _x;
int _y;
int _w;
int _h;
bool _canBeFocused;
bool _drawBorder;
bool _focused;
bool _leaveOnKeys;
bool _visible;
static int defaultFontSize;
static ifont* defaultFont;
static ifont* captionFont;
static ifont* defaultBoldFont;
mutable ifont *_font;
bool _useParentFont;
PBWidget *_focusedWidget;
PBWidget *_parent;
boost::shared_ptr<PBImage> _image;
std::vector <PBWidget*>_children;
std::string _tag;
void clearRegion();
bool update_needed;
virtual void placeWidgets(){};
public:
PBWidget(const std::string & name, PBWidget * parent);
virtual ~ PBWidget(){}
int y() const { return _y; }//< coordinate
void y(int val) { _y = val;update_needed=true; }//< coordinate
int x() const { return _x; }//< coordinate
void x(int val) { _x = val;update_needed=true; }//< coordinate
virtual int w() const { return _w; }//< width
void w(int val) { _w = val;update_needed=true; }
virtual int h() const { return _h; }//< height
void h(int val) { _h = val;update_needed=true; }
/**
set widget size
*/
virtual void setSize(int X, int Y, int W, int H) {
_x = X;
_y = Y;
_w = W;
_h = H;
update_needed=true;
}
/** return true if widget is active*/
bool canBeFocused() const { return _canBeFocused; }
/** set/unset active state of widget*/
void setCanBeFocused(bool value);
/** return true if widget have focus and recieve buttons event*/
bool isFocused() const { return _focused; };
/** set/unset focused state of widget
@param value - is widget must be focused
@param update - update parent widget
*/
void setFocused(bool value,bool update=true);
/** return focused child widget, if noone is focused return NULL */
PBWidget *getFocusedWidget() const;
/** set font to the widget
@arg ifont value - font
@note if not explicitely called widget uses parent font
*/
void setWidgetFont(ifont * value);//< set font
/** recurcive replace widgets font if they font equals to old
@arg ifont old - font that needs to be replaced
@arg ifont value - new font
*/
void replaceWidgetFont(ifont* old,ifont * value);//< set font
/** recurcive replace widgets font if they font equals to old
@arg ifont old - font that needs to be replaced
@arg ifont value - new font
*/
void resetFont(){
setWidgetFont(defaultFont);
}
ifont *getFont() const;
/** return visibility state of widget
@arg noparent - don't check parent visibility
*/
bool isVisible(bool noparent=false) const {
if (!noparent && _parent != 0 && !_parent->isVisible())
return false;
return _visible;
}
/** show/hide widget
@arg bool val - visibility state
@note You must call update of parent widget after changing visibility of it's childs.
This is not automaticaly due to low e-ink redraw speed.
*/
void setVisible(bool val) { _visible = val; }
void hide(){setVisible(false);}
void show(){setVisible(true);}
/** return parent widget */
PBWidget *getParent() const { return _parent; };
boost::shared_ptr<PBImage> getImage() const { return _image; }
void setImage(boost::shared_ptr<PBImage> val) { _image = val; }
std::string getTag()const { return _tag; }
void setTag(const std::string & val) { _tag = val; }
virtual std::string getText()const { return _text; }
virtual void setText(const std::string & val) { _text = val; }
/** event handler of widget - may be reimplemented */
virtual int handle(int type, int par1, int par2);
/**
return true pointer event x y is inside widget
*/
virtual bool eventInside(int X, int Y) {
return (X > x() && X < (x() + w()) && Y > y() && Y < (y() + h()) );
}
virtual void draw();
virtual void drawIfVisible();
/** update redraw the widget
@param bool relayout - force call placeWidget before redraw*/
virtual void update(bool relayout=false);
void addWidget(PBWidget * control);//< add child widget
void erase(PBWidget * control); //< remove child widget
// signals
sigc::signal<void,PBWidget*,bool,bool> onFocusChange;
sigc::signal<void,PBWidget*,bool> onLeave;
sigc::signal<void,PBWidget*> onFocusedWidgetChanged;
virtual void widgetFocusChangeHandler(PBWidget * sender, bool focused,bool update);
virtual void widgetLeaveHandler(PBWidget * sender, bool next);
};
typedef std::vector <PBWidget*>::iterator child_it;
typedef std::vector <PBWidget*>::const_iterator child_cit;
typedef std::vector <PBWidget*>::reverse_iterator child_rev_it;
class PBVScrollBar:public PBWidget {
int pageHeight, totalHeight, value;
public:
PBVScrollBar(const std::string & name, PBWidget * parent):PBWidget(name, parent), pageHeight(0), totalHeight(0), value(0) {
}
virtual void draw();
};
#endif