Dillo v3.2.0-88-g47ab7c70
Loading...
Searching...
No Matches
layout.hh
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 * Copyright 2025 Rodrigo Arias Mallo <rodarima@gmail.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef __DW_LAYOUT_HH__
22#define __DW_LAYOUT_HH__
23
24#ifndef __INCLUDED_FROM_DW_CORE_HH__
25# error Do not include this file directly, use "core.hh" instead.
26#endif
27
28namespace dw {
29namespace core {
30
37{
38 friend class Widget;
39
40private:
42 {
44
45 public:
46 LayoutImgRenderer (Layout *layout) { this->layout = layout; }
47
48 bool readyToDraw ();
49 void getBgArea (int *x, int *y, int *width, int *height);
50 void getRefArea (int *xRef, int *yRef, int *widthRef, int *heightRef);
56 void draw (int x, int y, int width, int height);
57 };
58
60
61public:
68 {
69 public:
70 virtual void resizeQueued (bool extremesChanged);
71 virtual void canvasSizeChanged (int width, int ascent, int descent);
72 };
73
75 {
76 public:
88 virtual bool enter (Widget *widget, int link, int img, int x, int y);
89
96 virtual bool press (Widget *widget, int link, int img, int x, int y,
97 EventButton *event);
98
105 virtual bool release (Widget *widget, int link, int img, int x, int y,
106 EventButton *event);
107
119 virtual bool click (Widget *widget, int link, int img, int x, int y,
120 EventButton *event);
121 };
122
124 {
125 private:
127
128 protected:
129 bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
130 int argc, lout::object::Object **argv);
131
132 public:
133 inline void connectLink (LinkReceiver *receiver) { connect (receiver); }
134
135 bool emitEnter (Widget *widget, int link, int img, int x, int y);
136 bool emitPress (Widget *widget, int link, int img, int x, int y,
137 EventButton *event);
138 bool emitRelease (Widget *widget, int link, int img, int x, int y,
139 EventButton *event);
140 bool emitClick (Widget *widget, int link, int img, int x, int y,
141 EventButton *event);
142 };
143
145
146private:
148 {
149 private:
151
152 protected:
153 bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
154 int argc, lout::object::Object **argv);
155
156 public:
157 inline void connectLayout (Receiver *receiver) { connect (receiver); }
158
159 void emitResizeQueued (bool extremesChanged);
160 void emitCanvasSizeChanged (int width, int ascent, int descent);
161 };
162
164
166 {
167 public:
168 char *name;
170 int y;
171
172 ~Anchor ();
173 };
174
179
180 /* The state, which must be projected into the view. */
186
189
194
198
202
203 /* Anchors of the widget tree */
204 lout::container::typed::HashTable <lout::object::String, Anchor>
206
209
211
212 void detachWidget (Widget *widget);
213
214 Widget *getWidgetAtPoint (int x, int y);
215 void moveToWidget (Widget *newWidgetAtPoint, ButtonState state);
216
221 void moveToWidgetAtPoint (int x, int y, ButtonState state)
222 { moveToWidget (getWidgetAtPoint (x, y), state); }
223
228 void moveOutOfView (ButtonState state) { moveToWidget (NULL, state); }
229
232 int numPressed, int x, int y, ButtonState state,
233 int button);
234 void resizeIdle ();
236 void draw (View *view, Rectangle *area);
237
238 void scrollTo0(HPosition hpos, VPosition vpos,
239 int x, int y, int width, int height,
240 bool scrollingInterrupted);
241 void scrollIdle ();
242 void adjustScrollPos ();
243 static bool calcScrollInto (int targetValue, int requestedSize,
244 int *value, int viewportSize);
247
248 void updateAnchor ();
249
250 /* Widget */
251
252 char *addAnchor (Widget *widget, const char* name);
253 char *addAnchor (Widget *widget, const char* name, int y);
254 void changeAnchor (Widget *widget, char* name, int y);
255 void removeAnchor (Widget *widget, char* name);
257 void updateCursor ();
258 void queueDraw (int x, int y, int width, int height);
259 void queueDrawExcept (int x, int y, int width, int height,
260 int ex, int ey, int ewidth, int eheight);
261 void queueResize (bool extremesChanged);
262 void removeWidget ();
263
264 /* For tests regarding the respective Layout and (mostly) Widget
265 methods. Accessed by respective methods (enter..., leave...,
266 ...Entered) defined here and in Widget. */
267
271
274
275public:
276 Layout (Platform *platform, bool limit=true);
277 ~Layout ();
278
279 inline void connectLink (LinkReceiver *receiver)
280 { linkEmitter.connectLink (receiver); }
281
282 inline bool emitLinkEnter (Widget *w, int link, int img, int x, int y)
283 { return linkEmitter.emitEnter (w, link, img, x, y); }
284
285 inline bool emitLinkPress (Widget *w, int link, int img,
286 int x, int y, EventButton *event)
287 { return linkEmitter.emitPress (w, link, img, x, y, event); }
288
289 inline bool emitLinkRelease (Widget *w, int link, int img,
290 int x, int y, EventButton *event)
291 { return linkEmitter.emitRelease (w, link, img, x, y, event); }
292
293 inline bool emitLinkClick (Widget *w, int link, int img,
294 int x, int y, EventButton *event)
295 { return linkEmitter.emitClick (w, link, img, x, y, event); }
296
298
299 void addWidget (Widget *widget);
300 void setWidget (Widget *widget);
301
302 void attachView (View *view);
303 void detachView (View *view);
304
305 inline bool getUsesViewport () { return usesViewport; }
306 inline int getWidthViewport () { return viewportWidth; }
307 inline int getHeightViewport () { return viewportHeight; }
308 inline int getScrollPosX () { return scrollX; }
309 inline int getScrollPosY () { return scrollY; }
310
311 /* public */
312
313 void scrollTo (HPosition hpos, VPosition vpos,
314 int x, int y, int width, int height);
315 void scroll (ScrollCommand);
316 void setAnchor (const char *anchor);
317
318 /* View */
319
320 inline void expose (View *view, Rectangle *area) {
321 DBG_OBJ_ENTER ("draw", 0, "expose", "%d, %d, %d * %d",
322 area->x, area->y, area->width, area->height);
323 draw (view, area);
324 DBG_OBJ_LEAVE ();
325 }
326
335 inline bool buttonPress (View *view, int numPressed, int x, int y,
336 ButtonState state, int button)
337 {
338 return buttonEvent (BUTTON_PRESS, view, numPressed, x, y, state, button);
339 }
340
341 void containerSizeChanged ();
342
349 inline bool buttonRelease (View *view, int numPressed, int x, int y,
350 ButtonState state, int button)
351 {
352 return buttonEvent (BUTTON_RELEASE, view, numPressed, x, y, state,
353 button);
354 }
355
356 bool motionNotify (View *view, int x, int y, ButtonState state);
357 void enterNotify (View *view, int x, int y, ButtonState state);
358 void leaveNotify (View *view, ButtonState state);
359
360 void scrollPosChanged (View *view, int x, int y);
361 void viewportSizeChanged (View *view, int width, int height);
362
364 {
365 return platform;
366 }
367
368 /* delegated */
369
370 inline int textWidth (style::Font *font, const char *text, int len)
371 {
372 return platform->textWidth (font, text, len);
373 }
374
375 inline char *textToUpper (const char *text, int len)
376 {
377 return platform->textToUpper (text, len);
378 }
379
380 inline char *textToLower (const char *text, int len)
381 {
382 return platform->textToLower (text, len);
383 }
384
385 inline int nextGlyph (const char *text, int idx)
386 {
387 return platform->nextGlyph (text, idx);
388 }
389
390 inline int prevGlyph (const char *text, int idx)
391 {
392 return platform->prevGlyph (text, idx);
393 }
394
395 inline float dpiX ()
396 {
397 return platform->dpiX ();
398 }
399
400 inline float dpiY ()
401 {
402 return platform->dpiY ();
403 }
404
405 inline style::Font *createFont (style::FontAttrs *attrs, bool tryEverything)
406 {
407 return platform->createFont (attrs, tryEverything);
408 }
409
410 inline bool fontExists (const char *name)
411 {
412 return platform->fontExists (name);
413 }
414
415 inline style::Color *createColor (int color)
416 {
417 return platform->createColor (color);
418 }
419
420 inline style::Tooltip *createTooltip (const char *text)
421 {
422 return platform->createTooltip (text);
423 }
424
425 inline void cancelTooltip ()
426 {
427 return platform->cancelTooltip ();
428 }
429
430 inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height,
431 double gamma)
432 {
433 return platform->createImgbuf (type, width, height, gamma);
434 }
435
436 inline void copySelection(const char *text, int destination)
437 {
438 platform->copySelection(text, destination);
439 }
440
441 inline void copyCurrentSelection(int destination)
442 {
443 selectionState.copy(destination);
444 }
445
450
451 inline void connect (Receiver *receiver) {
452 emitter.connectLayout (receiver); }
453
455 inline FindtextState::Result search (const char *str, bool caseSens,
456 int backwards)
457 { return findtextState.search (str, caseSens, backwards); }
458
460 inline void resetSearch () { findtextState.resetSearch (); }
461
462 void setBgColor (style::Color *color);
467
468 inline style::Color* getBgColor () { return bgColor; }
469 inline style::StyleImage* getBgImage () { return bgImage; }
470};
471
472} // namespace core
473} // namespace dw
474
475#endif // __DW_LAYOUT_HH__
476
Represents a button press or release event.
Definition events.hh:58
void resetSearch()
This method is called when the user closes the "find text" dialog.
Definition findtext.cc:151
Result search(const char *key, bool caseSens, bool backwards)
Definition findtext.cc:75
The platform independent interface for image buffers.
Definition imgbuf.hh:162
bool emitToReceiver(lout::signal::Receiver *receiver, int signalNo, int argc, lout::object::Object **argv)
A sub class must implement this for a call to a single receiver.
Definition layout.cc:106
void emitResizeQueued(bool extremesChanged)
Definition layout.cc:130
void connectLayout(Receiver *receiver)
Definition layout.hh:157
void emitCanvasSizeChanged(int width, int ascent, int descent)
Definition layout.cc:137
void draw(int x, int y, int width, int height)
Draw (or queue for drawing) an area, which is given in canvas coordinates.
Definition layout.cc:89
void getBgArea(int *x, int *y, int *width, int *height)
Return the area covered by the background image.
Definition layout.cc:42
style::BackgroundRepeat getBackgroundRepeat()
Definition layout.cc:68
LayoutImgRenderer(Layout *layout)
Definition layout.hh:46
style::BackgroundAttachment getBackgroundAttachment()
Definition layout.cc:74
void getRefArea(int *xRef, int *yRef, int *widthRef, int *heightRef)
Return the "reference area".
Definition layout.cc:49
style::Length getBackgroundPositionX()
Definition layout.cc:79
style::Length getBackgroundPositionY()
Definition layout.cc:84
style::StyleImage * getBackgroundImage()
Definition layout.cc:63
bool readyToDraw()
If this method returns false, nothing is done at all.
Definition layout.cc:37
bool emitEnter(Widget *widget, int link, int img, int x, int y)
Definition layout.cc:217
bool emitToReceiver(lout::signal::Receiver *receiver, int signalNo, int argc, lout::object::Object **argv)
A sub class must implement this for a call to a single receiver.
Definition layout.cc:173
bool emitPress(Widget *widget, int link, int img, int x, int y, EventButton *event)
Definition layout.cc:225
void connectLink(LinkReceiver *receiver)
Definition layout.hh:133
bool emitRelease(Widget *widget, int link, int img, int x, int y, EventButton *event)
Definition layout.cc:233
bool emitClick(Widget *widget, int link, int img, int x, int y, EventButton *event)
Definition layout.cc:241
virtual bool click(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has clicked on a link.
Definition layout.cc:165
virtual bool press(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has pressed the mouse button on a link (but not yet released).
Definition layout.cc:153
virtual bool release(Widget *widget, int link, int img, int x, int y, EventButton *event)
Called, when the user has released the mouse button on a link.
Definition layout.cc:159
virtual bool enter(Widget *widget, int link, int img, int x, int y)
Called, when a link is entered, left, or the position has changed.
Definition layout.cc:147
Receiver interface different signals.
Definition layout.hh:68
virtual void resizeQueued(bool extremesChanged)
Definition layout.cc:96
virtual void canvasSizeChanged(int width, int ascent, int descent)
Definition layout.cc:100
The central class for managing and drawing a widget tree.
Definition layout.hh:37
bool fontExists(const char *name)
Definition layout.hh:410
void copyCurrentSelection(int destination)
Definition layout.hh:441
void attachView(View *view)
Attach a view to the layout.
Definition layout.cc:459
lout::misc::ZoneAllocator * textZone
Definition layout.hh:297
void changeAnchor(Widget *widget, char *name, int y)
Definition layout.cc:774
void detachWidget(Widget *widget)
Definition layout.cc:351
int currHScrollbarThickness()
Definition layout.cc:724
int getScrollPosY()
Definition layout.hh:309
style::Cursor cursor
Definition layout.hh:187
void updateAnchor()
Definition layout.cc:790
bool emitLinkRelease(Widget *w, int link, int img, int x, int y, EventButton *event)
Definition layout.hh:289
FindtextState::Result search(const char *str, bool caseSens, int backwards)
See dw::core::FindtextState::search.
Definition layout.hh:455
void setCursor(style::Cursor cursor)
Definition layout.cc:810
void scrollIdle()
Definition layout.cc:570
void resetSearch()
See dw::core::FindtextState::resetSearch.
Definition layout.hh:460
void enterNotify(View *view, int x, int y, ButtonState state)
This function is called by a view, to delegate a enter notify event.
Definition layout.cc:1093
style::Font * createFont(style::FontAttrs *attrs, bool tryEverything)
Definition layout.hh:405
void queueDraw(int x, int y, int width, int height)
Definition layout.cc:996
bool scrollIdleNotInterrupted
Definition layout.hh:201
Widget * getWidgetAtPoint(int x, int y)
Definition layout.cc:1137
int scrollTargetWidth
Definition layout.hh:197
void containerSizeChanged()
Definition layout.cc:1349
bool motionNotify(View *view, int x, int y, ButtonState state)
This function is called by a view, to delegate a motion notify event.
Definition layout.cc:1075
bool drawAfterScrollReq
Definition layout.hh:190
void cancelTooltip()
Definition layout.hh:425
void setWidget(Widget *widget)
Definition layout.cc:433
int textWidth(style::Font *font, const char *text, int len)
Definition layout.hh:370
bool processMouseEvent(MousePositionEvent *event, ButtonEventType type)
Common processing of press, release and motion events.
Definition layout.cc:1249
style::StyleImage * bgImage
Definition layout.hh:182
void setBgColor(style::Color *color)
Definition layout.cc:826
void detachView(View *view)
Definition layout.cc:511
style::Color * getBgColor()
Definition layout.hh:468
void moveToWidgetAtPoint(int x, int y, ButtonState state)
Emit the necessary crossing events, when the mouse pointer has moved to position (x,...
Definition layout.hh:221
char * addAnchor(Widget *widget, const char *name)
Used, when the widget is not allocated yet.
Definition layout.cc:751
void leaveNotify(View *view, ButtonState state)
This function is called by a view, to delegate a leave notify event.
Definition layout.cc:1114
int getWidthViewport()
Definition layout.hh:306
void expose(View *view, Rectangle *area)
Definition layout.hh:320
lout::container::typed::HashTable< lout::object::String, Anchor > * anchorsTable
Definition layout.hh:205
void queueDrawExcept(int x, int y, int width, int height, int ex, int ey, int ewidth, int eheight)
Definition layout.cc:1009
int nextGlyph(const char *text, int idx)
Definition layout.hh:385
VPosition scrollTargetVpos
Definition layout.hh:196
void viewportSizeChanged(View *view, int width, int height)
Definition layout.cc:1327
HPosition scrollTargetHpos
Definition layout.hh:195
int sizeRequestCounter
Definition layout.hh:269
lout::container::typed::Vector< Widget > * queueResizeList
Definition layout.hh:178
int vScrollbarThickness
Definition layout.hh:193
Platform * getPlatform()
Definition layout.hh:363
LinkEmitter linkEmitter
Definition layout.hh:144
void addWidget(Widget *widget)
Definition layout.cc:371
Imgbuf * createImgbuf(Imgbuf::Type type, int width, int height, double gamma)
Definition layout.hh:430
int queueResizeCounter
Definition layout.hh:268
style::Tooltip * createTooltip(const char *text)
Definition layout.hh:420
bool buttonEvent(ButtonEventType type, View *view, int numPressed, int x, int y, ButtonState state, int button)
Definition layout.cc:1052
SelectionState selectionState
Definition layout.hh:207
void updateCursor()
Definition layout.cc:818
bool emitLinkEnter(Widget *w, int link, int img, int x, int y)
Definition layout.hh:282
void resizeIdle()
Definition layout.cc:870
void draw(View *view, Rectangle *area)
Definition layout.cc:670
style::Color * createColor(int color)
Definition layout.hh:415
void moveToWidget(Widget *newWidgetAtPoint, ButtonState state)
Definition layout.cc:1158
void setBgImage(style::StyleImage *bgImage, style::BackgroundRepeat bgRepeat, style::BackgroundAttachment bgAttachment, style::Length bgPositionX, style::Length bgPositionY)
Definition layout.cc:839
void connect(Receiver *receiver)
Definition layout.hh:451
void moveOutOfView(ButtonState state)
Emit the necessary crossing events, when the mouse pointer has moved out of the view.
Definition layout.hh:228
bool emitLinkClick(Widget *w, int link, int img, int x, int y, EventButton *event)
Definition layout.hh:293
style::StyleImage * getBgImage()
Definition layout.hh:469
bool emitLinkPress(Widget *w, int link, int img, int x, int y, EventButton *event)
Definition layout.hh:285
bool getUsesViewport()
Definition layout.hh:305
void adjustScrollPos()
Definition layout.cc:632
int sizeAllocateCounter
Definition layout.hh:268
int getScrollPosX()
Definition layout.hh:308
char * textToUpper(const char *text, int len)
Definition layout.hh:375
FindtextState findtextState
Definition layout.hh:208
Platform * platform
Definition layout.hh:175
bool buttonRelease(View *view, int numPressed, int x, int y, ButtonState state, int button)
This function is called by a view, to delegate a button press event.
Definition layout.hh:349
style::Color * bgColor
Definition layout.hh:181
void enterResizeIdle()
Definition layout.hh:272
style::BackgroundRepeat bgRepeat
Definition layout.hh:183
void scrollTo0(HPosition hpos, VPosition vpos, int x, int y, int width, int height, bool scrollingInterrupted)
Definition layout.cc:545
Widget * widgetAtPoint
Definition layout.hh:177
void removeWidget()
Definition layout.cc:406
char * textToLower(const char *text, int len)
Definition layout.hh:380
int getExtremesCounter
Definition layout.hh:269
Widget * topLevel
Definition layout.hh:177
void removeAnchor(Widget *widget, char *name)
Definition layout.cc:784
style::BackgroundAttachment bgAttachment
Definition layout.hh:184
static bool calcScrollInto(int targetValue, int requestedSize, int *value, int viewportSize)
Definition layout.cc:645
int scrollTargetHeight
Definition layout.hh:197
void scrollPosChanged(View *view, int x, int y)
Definition layout.cc:1312
int resizeIdleCounter
Definition layout.hh:268
int getHeightViewport()
Definition layout.hh:307
void copySelection(const char *text, int destination)
Definition layout.hh:436
ui::ResourceFactory * getResourceFactory()
Definition layout.hh:446
void scrollTo(HPosition hpos, VPosition vpos, int x, int y, int width, int height)
Scrolls all viewports, so that the region [x, y, width, height] is seen, according to hpos and vpos.
Definition layout.cc:539
void scroll(ScrollCommand)
Definition layout.cc:529
int prevGlyph(const char *text, int idx)
Definition layout.hh:390
style::Length bgPositionX
Definition layout.hh:185
bool buttonPress(View *view, int numPressed, int x, int y, ButtonState state, int button)
This function is called by a view, to delegate a button press event.
Definition layout.hh:335
style::Length bgPositionY
Definition layout.hh:185
int hScrollbarThickness
Definition layout.hh:193
char * requestedAnchor
Definition layout.hh:199
int currVScrollbarThickness()
Definition layout.cc:729
Emitter emitter
Definition layout.hh:163
void connectLink(LinkReceiver *receiver)
Definition layout.hh:279
void setAnchor(const char *anchor)
Sets the anchor to scroll to.
Definition layout.cc:738
bool canvasHeightGreater
Definition layout.hh:192
void queueResize(bool extremesChanged)
Definition layout.cc:1032
LayoutImgRenderer * layoutImgRenderer
Definition layout.hh:59
void leaveResizeIdle()
Definition layout.hh:273
Base class for all mouse events related to a specific position.
Definition events.hh:49
An interface to encapsulate some platform dependencies.
Definition platform.hh:37
virtual float dpiX()=0
Return screen resolution in x-direction.
virtual int textWidth(style::Font *font, const char *text, int len)=0
Return the width of a text, with a given length and font.
virtual ui::ResourceFactory * getResourceFactory()=0
...
virtual int nextGlyph(const char *text, int idx)=0
Return the index of the next glyph in string text.
virtual void copySelection(const char *text, int destination)=0
Copy selected text (0-terminated).
virtual style::Tooltip * createTooltip(const char *text)=0
Create a tooltip.
virtual char * textToUpper(const char *text, int len)=0
Return the string resulting from transforming text to uppercase.
virtual style::Color * createColor(int color)=0
Create a color resource for a given 0xrrggbb value.
virtual char * textToLower(const char *text, int len)=0
Return the string resulting from transforming text to lowercase.
virtual void cancelTooltip()=0
Cancel a tooltip (either shown or requested)
virtual float dpiY()=0
Return screen resolution in y-direction.
virtual style::Font * createFont(style::FontAttrs *attrs, bool tryEverything)=0
Create a (platform dependent) font.
virtual int prevGlyph(const char *text, int idx)=0
Return the index of the previous glyph in string text.
virtual Imgbuf * createImgbuf(Imgbuf::Type type, int width, int height, double gamma)=0
Create a (platform specific) image buffer.
virtual bool fontExists(const char *name)=0
dw::core::Shape implementation for simple rectangles.
Definition types.hh:70
This class handles selections, as well as activation of links, which is closely related.
Definition selection.hh:199
void copy(int selection)
Definition selection.cc:426
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
The base class of all dillo widgets.
Definition widget.hh:44
Useful (but not mandatory) base class for updates of areas with background images.
Definition style.hh:815
A factory for the common resource.
Definition ui.hh:581
Typed version of container::untyped::Vector.
Definition container.hh:447
A simple allocator optimized to handle many small chunks of memory.
Definition misc.hh:631
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:45
The base class for signal emitters.
Definition signal.hh:213
void connect(Receiver *receiver)
Connect a receiver to the emitter.
Definition signal.cc:65
The base class for signal receiver base classes.
Definition signal.hh:254
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
int Length
Type for representing all lengths within dw::core::style.
Definition style.hh:429
ButtonState
Platform independent representation.
Definition events.hh:15
VPosition
Definition types.hh:26
HPosition
Definition types.hh:16
ScrollCommand
Definition types.hh:35
Dw is in this namespace, or sub namespaces of this one.