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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
|
#ifndef __DW_LAYOUT_HH__
#define __DW_LAYOUT_HH__
#ifndef __INCLUDED_FROM_DW_CORE_HH__
# error Do not include this file directly, use "core.hh" instead.
#endif
namespace dw {
namespace core {
/**
* \brief The central class for managing and drawing a widget tree.
*
* \sa\ref dw-overview, \ref dw-layout-widgets, \ref dw-layout-views
*/
class Layout: public object::Object
{
friend class Widget;
public:
/**
* \brief Receiver interface different signals.
*
* May be extended
*/
class Receiver: public lout::signal::Receiver
{
public:
virtual void canvasSizeChanged (int width, int ascent, int descent);
};
private:
class Emitter: public lout::signal::Emitter
{
private:
enum { CANVAS_SIZE_CHANGED };
protected:
bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
int argc, lout::object::Object **argv);
public:
inline void connectLayout (Receiver *receiver) { connect (receiver); }
void emitCanvasSizeChanged (int width, int ascent, int descent);
};
Emitter emitter;
class Anchor: public object::Object
{
public:
char *name;
Widget *widget;
int y;
~Anchor ();
};
Platform *platform;
container::typed::List <View> *views;
Widget *topLevel, *widgetAtPoint;
/* The state, which must be projected into the views. */
style::Color *bgColor;
style::Cursor cursor;
int canvasWidth, canvasAscent, canvasDescent;
bool usesViewport;
int scrollX, scrollY, viewportWidth, viewportHeight;
bool canvasHeightGreater;
int hScrollbarThickness, vScrollbarThickness;
HPosition scrollTargetHpos;
VPosition scrollTargetVpos;
int scrollTargetX, scrollTargetY, scrollTargetWidth, scrollTargetHeight;
char *requestedAnchor;
int scrollIdleId, resizeIdleId;
bool scrollIdleNotInterrupted;
/* Anchors of the widget tree */
container::typed::HashTable <object::String, Anchor> *anchorsTable;
SelectionState selectionState;
FindtextState findtextState;
enum ButtonEventType { BUTTON_PRESS, BUTTON_RELEASE, MOTION_NOTIFY };
Widget *getWidgetAtPoint (int x, int y);
void moveToWidget (Widget *newWidgetAtPoint, ButtonState state);
/**
* \brief Emit the necessary crossing events, when the mouse pointer has
* moved to position (\em x, \em );
*/
void moveToWidgetAtPoint (int x, int y, ButtonState state)
{ moveToWidget (getWidgetAtPoint (x, y), state); }
/**
* \brief Emit the necessary crossing events, when the mouse pointer
* has moved out of the view.
*/
void moveOutOfView (ButtonState state) { moveToWidget (NULL, state); }
bool processMouseEvent (MousePositionEvent *event, ButtonEventType type,
bool mayBeSuppressed);
bool buttonEvent (ButtonEventType type, View *view,
int numPressed, int x, int y, ButtonState state,
int button);
void resizeIdle ();
void setSizeHints ();
void draw (View *view, Rectangle *area);
void scrollTo0(HPosition hpos, VPosition vpos,
int x, int y, int width, int height,
bool scrollingInterrupted);
void scrollIdle ();
void adjustScrollPos ();
static bool calcScrollInto (int targetValue, int requestedSize,
int *value, int viewportSize);
void updateAnchor ();
/* Widget */
char *addAnchor (Widget *widget, const char* name);
char *addAnchor (Widget *widget, const char* name, int y);
void changeAnchor (Widget *widget, char* name, int y);
void removeAnchor (Widget *widget, char* name);
void setCursor (style::Cursor cursor);
void updateCursor ();
void updateBgColor ();
void queueDraw (int x, int y, int width, int height);
void queueDrawExcept (int x, int y, int width, int height,
int ex, int ey, int ewidth, int eheight);
void queueResize ();
void removeWidget ();
public:
Layout (Platform *platform);
~Layout ();
misc::ZoneAllocator *textZone;
void addWidget (Widget *widget);
void setWidget (Widget *widget);
void attachView (View *view);
void detachView (View *view);
inline bool getUsesViewport () { return usesViewport; }
inline int getWidthViewport () { return viewportWidth; }
inline int getHeightViewport () { return viewportHeight; }
inline int getScrollPosX () { return scrollX; }
inline int getScrollPosY () { return scrollY; }
/* public */
void scrollTo (HPosition hpos, VPosition vpos,
int x, int y, int width, int height);
void setAnchor (const char *anchor);
/* View */
inline void expose (View *view, Rectangle *area) { draw (view, area); }
/**
* \brief This function is called by a view, to delegate a button press
* event.
*
* \em numPressed is 1 for simple presses, 2 for double presses etc. (more
* that 2 is never needed), \em x and \em y the world coordinates, and
* \em button the number of the button pressed.
*/
inline bool buttonPress (View *view, int numPressed, int x, int y,
ButtonState state, int button)
{
return buttonEvent (BUTTON_PRESS, view, numPressed, x, y, state, button);
}
/**
* \brief This function is called by a view, to delegate a button press
* event.
*
* Arguments are similar to dw::core::Layout::buttonPress.
*/
inline bool buttonRelease (View *view, int numPressed, int x, int y,
ButtonState state, int button)
{
return buttonEvent (BUTTON_RELEASE, view, numPressed, x, y, state,
button);
}
bool motionNotify (View *view, int x, int y, ButtonState state);
void enterNotify (View *view, int x, int y, ButtonState state);
void leaveNotify (View *view, ButtonState state);
void scrollPosChanged (View *view, int x, int y);
void viewportSizeChanged (View *view, int width, int height);
/* delegated */
inline int textWidth (style::Font *font, const char *text, int len)
{
return platform->textWidth (font, text, len);
}
inline int nextGlyph (const char *text, int idx)
{
return platform->nextGlyph (text, idx);
}
inline int prevGlyph (const char *text, int idx)
{
return platform->prevGlyph (text, idx);
}
inline float dpiX ()
{
return platform->dpiX ();
}
inline float dpiY ()
{
return platform->dpiY ();
}
inline style::Font *createFont (style::FontAttrs *attrs, bool tryEverything)
{
return platform->createFont (attrs, tryEverything);
}
inline style::Color *createColor (int color)
{
return platform->createColor (color);
}
inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height)
{
return platform->createImgbuf (type, width, height);
}
inline void copySelection(const char *text)
{
platform->copySelection(text);
}
inline ui::ResourceFactory *getResourceFactory ()
{
return platform->getResourceFactory ();
}
inline void connect (Receiver *receiver) {
emitter.connectLayout (receiver); }
/** \brief See dw::core::FindtextState::search. */
inline FindtextState::Result search (const char *str, bool caseSens,
int backwards)
{ return findtextState.search (str, caseSens, backwards); }
/** \brief See dw::core::FindtextState::resetSearch. */
inline void resetSearch () { findtextState.resetSearch (); }
};
} // namespace dw
} // namespace core
#endif // __DW_LAYOUT_HH__
|