Dillo v3.1.1-46-g8a360e32
Loading...
Searching...
No Matches
ui.cc
Go to the documentation of this file.
1/*
2 * Dillo Widget
3 *
4 * Copyright 2005-2007 Sebastian Geerken <sgeerken@dillo.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21
22#include "core.hh"
23#include "../lout/debug.hh"
24
25#include <stdio.h>
26
27namespace dw {
28namespace core {
29namespace ui {
30
31using namespace lout;
32using namespace lout::object;
33
34int Embed::CLASS_ID = -1;
35
37{
38 DBG_OBJ_CREATE ("dw::core::ui::Embed");
39 registerName ("dw::core::ui::Embed", &CLASS_ID);
40 this->resource = resource;
41 resource->setEmbed (this);
43}
44
46{
47 delete resource;
49}
50
52{
54 // TODO Correction should perhaps be left to the resouces.
56}
57
65
70
71int Embed::getAvailWidthOfChild (Widget *child, bool forceValue)
72{
73 return resource->getAvailWidthOfChild (child, forceValue);
74}
75
76int Embed::getAvailHeightOfChild (Widget *child, bool forceValue)
77{
78 return resource->getAvailHeightOfChild (child, forceValue);
79}
80
82 Requisition *requisition,
83 void (*splitHeightFun) (int, int*, int*),
84 bool allowDecreaseWidth,
85 bool allowDecreaseHeight)
86{
87 resource->correctRequisitionOfChild (child, requisition, splitHeightFun,
88 allowDecreaseWidth,
89 allowDecreaseHeight);
90}
91
93 bool useAdjustmentWidth)
94{
95 resource->correctExtremesOfChild (child, extremes, useAdjustmentWidth);
96}
97
99{
100 DBG_OBJ_ENTER0 ("resize", 0, "containerSizeChangedForChildren");
102 DBG_OBJ_LEAVE ();
103}
104
110
116
118{
119 bool handled;
120
121 if (event->button == 3) {
122 resource->emitClicked(event);
123 handled = true;
124 } else {
125 handled = false;
126 }
127 return handled;
128}
129
130void Embed::setDisplayed (bool displayed)
131{
132 resource->setDisplayed (displayed);
133}
134
135void Embed::setEnabled (bool enabled)
136{
137 resource->setEnabled (enabled);
138}
139
140void Embed::draw (View *view, Rectangle *area, DrawingContext *context)
141{
142 drawWidgetBox (view, area, false);
143 resource->draw (view, area, context);
144}
145
147{
148 return resource->iterator (mask, atEnd);
149}
150
156
157// ----------------------------------------------------------------------
158
160 *receiver,
161 int signalNo,
162 int argc, Object **argv)
163{
164 ActivateReceiver *ar = (ActivateReceiver*)receiver;
165 Resource *res = (Resource*)((Pointer*)argv[0])->getValue ();
166
167 switch (signalNo) {
168 case 0:
169 ar->activate (res);
170 break;
171 case 1:
172 ar->enter (res);
173 break;
174 case 2:
175 ar->leave (res);
176 break;
177 default:
179 }
180 return false;
181}
182
184{
185 Pointer p (resource);
186 Object *argv[1] = { &p };
187 emitVoid (0, 1, argv);
188}
189
191{
192 Pointer p (resource);
193 Object *argv[1] = { &p };
194 emitVoid (1, 1, argv);
195}
196
198{
199 Pointer p (resource);
200 Object *argv[1] = { &p };
201 emitVoid (2, 1, argv);
202}
203
204// ----------------------------------------------------------------------
205
210
212{
213 this->embed = embed;
214}
215
217{
218 DBG_OBJ_ENTER0 ("resize", 0, "getExtremes");
219
220 /* Simply return the requisition width */
221 Requisition requisition;
222 sizeRequest (&requisition);
223 extremes->minWidth = extremes->maxWidth = requisition.width;
224 extremes->minWidthIntrinsic = extremes->minWidth;
225 extremes->maxWidthIntrinsic = extremes->maxWidth;
226
227 DBG_OBJ_MSGF ("resize", 1, "result: %d / %d",
228 extremes->minWidth, extremes->maxWidth);
229 DBG_OBJ_LEAVE ();
230}
231
233{
234}
235
236int Resource::getAvailWidthOfChild (Widget *child, bool forceValue)
237{
238 // Only used when the resource contains other dillo widgets.
239 misc::notImplemented ("Resource::getAvailWidthOfChild");
240 return 0;
241}
242
243int Resource::getAvailHeightOfChild (Widget *child, bool forceValue)
244{
245 // Only used when the resource contains other dillo widgets.
246 misc::notImplemented ("Resource::getAvailHeightOfChild");
247 return 0;
248}
249
251 Requisition *requisition,
252 void (*splitHeightFun) (int, int*,
253 int*),
254 bool allowDecreaseWidth,
255 bool allowDecreaseHeight)
256{
257 // Only used when the resource contains other dillo widgets.
258 misc::notImplemented ("Resource::correctRequisitionOfChild");
259}
260
262 bool useAdjustmentWidth)
263{
264 // Only used when the resource contains other dillo widgets.
265 misc::notImplemented ("Resource::correctExtremesOfChild");
266}
267
269{
270 // No children by default.
271}
272
273void Resource::setDisplayed (bool displayed)
274{
275}
276
277void Resource::draw (View *view, Rectangle *area, DrawingContext *context)
278{
279}
280
282{
283}
284
286{
288}
289
291{
293}
294
296 int signalNo, int argc,
297 Object **argv)
298{
299 ((ClickedReceiver*)receiver)
300 ->clicked ((Resource*)((Pointer*)argv[0])->getValue (),
301 (EventButton*)((Pointer*)argv[1])->getValue());
302 return false;
303}
304
306 EventButton *event)
307{
308 Pointer p1 (resource);
309 Pointer p2 (event);
310 Object *argv[2] = { &p1, &p2 };
311 emitVoid (0, 2, argv);
312}
313
314// ----------------------------------------------------------------------
315
317{
319 // return new TextIterator (getEmbed (), mask, atEnd, getLabel ());
321 return new EmptyIterator (getEmbed (), mask, atEnd);
322}
323
324// ----------------------------------------------------------------------
325
327{
328 DBG_OBJ_ENTER ("resize", 0, "LayoutReceiver::resizeQueued", "%s",
329 extremesChanged ? "true" : "false");
330 resource->queueResize (extremesChanged);
331 DBG_OBJ_LEAVE ();
332}
333
335{
336 DBG_OBJ_CREATE ("dw::core::ui::ComplexButtonResource");
337 layout = NULL;
338 layoutReceiver.resource = this;
339 click_x = click_y = -1;
340}
341
343{
344 childWidget = widget;
345
346 layout = new Layout (createPlatform ());
347 setLayout (layout);
349 layout->setWidget (widget);
350 layout->connect (&layoutReceiver);
351
352 if (getEmbed ())
353 childWidget->setQuasiParent (getEmbed ());
354}
355
357{
359
360 if (childWidget)
361 childWidget->setQuasiParent (getEmbed ());
362}
363
369
371{
372 DBG_OBJ_ENTER0 ("resize", 0, "sizeRequest");
373
374 Requisition widgetRequisition;
375 childWidget->sizeRequest (&widgetRequisition);
376 requisition->width = widgetRequisition.width + 2 * reliefXThickness ();
377 requisition->ascent = widgetRequisition.ascent + reliefYThickness ();
378 requisition->descent = widgetRequisition.descent + reliefYThickness ();
379
380 DBG_OBJ_MSGF ("resize", 1, "result: %d * (%d + %d)",
381 requisition->width, requisition->ascent, requisition->descent);
382 DBG_OBJ_LEAVE ();
383}
384
386{
387 DBG_OBJ_ENTER0 ("resize", 0, "getExtremes");
388
389 Extremes widgetExtremes;
390 childWidget->getExtremes (&widgetExtremes);
391 extremes->minWidth = widgetExtremes.minWidth + 2 * reliefXThickness ();
392 extremes->maxWidth = widgetExtremes.maxWidth + 2 * reliefXThickness ();
393 extremes->minWidthIntrinsic = extremes->minWidth;
394 extremes->maxWidthIntrinsic = extremes->maxWidth;
395
396 DBG_OBJ_MSGF ("resize", 1, "result: %d / %d",
397 extremes->minWidth, extremes->maxWidth);
398 DBG_OBJ_LEAVE ();
399}
400
404
406{
407 int embedWidth = getEmbed()->getAvailWidth (forceValue);
408 if (embedWidth == -1)
409 return -1;
410 else
411 return misc::max (embedWidth - 2 * reliefXThickness (), 0);
412}
413
415 bool forceValue)
416{
417 int embedHeight = getEmbed()->getAvailHeight (forceValue);
418 if (embedHeight == -1)
419 return -1;
420 else
421 return misc::max (embedHeight - 2 * reliefYThickness (), 0);
422}
423
425 Requisition *requisition,
426 void (*splitHeightFun)
427 (int, int*, int*),
428 bool allowDecreaseWidth,
429 bool allowDecreaseHeight)
430{
431 // Similar to Widget::correctRequisitionOfChild, but for percentage
432 // the relief has to be considered.
433
434 if (style::isPerLength (child->getStyle()->width)) {
435 int availWidth = getEmbed()->getAvailHeight (false);
436 if (availWidth != -1) {
437 int baseWidth = misc::max (availWidth
438 - getEmbed()->boxDiffWidth ()
439 - 2 * reliefXThickness (),
440 0);
441 int newWidth =
442 child->applyPerWidth (baseWidth, child->getStyle()->width);
443 requisition->width = allowDecreaseWidth ?
444 newWidth : misc::max (requisition->width, newWidth);
445 }
446 } else
447 getEmbed()->correctReqWidthOfChildNoRec (child, requisition,
448 allowDecreaseWidth);
449
450 // TODO Percentage heights are ignored again.
451 getEmbed()->correctReqHeightOfChildNoRec(child, requisition,
452 splitHeightFun, allowDecreaseWidth);
453
454}
455
457 Extremes *extremes,
458 bool useAdjustmentWidth)
459{
460 // Similar to Widget::correctExtremesOfChild, but for percentage
461 // the relief has to be considered.
462
463 if (style::isPerLength (child->getStyle()->width)) {
464 int availWidth = getEmbed()->getAvailHeight (false);
465 if (availWidth != -1) {
466 int baseWidth = misc::max (availWidth
467 - getEmbed()->boxDiffWidth ()
468 - 2 * reliefXThickness (),
469 0);
470 extremes->minWidth = extremes->maxWidth =
471 child->applyPerWidth (baseWidth, child->getStyle()->width);
472 }
473 } else
474 getEmbed()->correctExtremesOfChildNoRec (child, extremes,
475 useAdjustmentWidth);
476}
477
479{
480 layout->containerSizeChanged ();
481}
482
484{
489 return new EmptyIterator (getEmbed (), mask, atEnd);
490}
491
492// ----------------------------------------------------------------------
493
495{
496 // return new TextIterator (getEmbed (), mask, atEnd, getText ());
498 return new EmptyIterator (getEmbed (), mask, atEnd);
499}
500
501// ----------------------------------------------------------------------
502
504{
505 //return new TextIterator (getEmbed (), mask, atEnd,
506 // isActivated () ? "[X]" : "[ ]");
508 return new EmptyIterator (getEmbed (), mask, atEnd);
509}
510
511// ----------------------------------------------------------------------
512
516
518{
519 //return new TextIterator (getEmbed (), mask, atEnd,
520 // isActivated () ? "(*)" : "( )");
522 return new EmptyIterator (getEmbed (), mask, atEnd);
523}
524
525} // namespace ui
526} // namespace core
527} // namespace dw
528
Set at the top when drawing.
Definition types.hh:295
This implementation of dw::core::Iterator can be used by widgets with no contents.
Definition iterator.hh:97
Represents a button press or release event.
Definition events.hh:58
Represents a enter or leave notify event.
Definition events.hh:75
Iterators are used to iterate through the contents of a widget.
Definition iterator.hh:20
The central class for managing and drawing a widget tree.
Definition layout.hh:17
dw::core::Shape implemtation for simple rectangles.
Definition types.hh:70
An interface to encapsulate platform dependent drawing.
Definition view.hh:17
The base class of all dillo widgets.
Definition widget.hh:44
virtual void setStyle(style::Style *style)
Change the style of a widget.
Definition widget.cc:1233
virtual void leaveNotifyImpl(EventCrossing *event)
Definition widget.cc:2010
Extremes extremes
Analogue to dw::core::Widget::requisition.
Definition widget.hh:166
Allocation allocation
The current allocation: size and position, always relative to the canvas.
Definition widget.hh:203
int getAvailWidth(bool forceValue)
Return available width including margin/border/padding (extraSpace?), not only the content width.
Definition widget.cc:649
void drawWidgetBox(View *view, Rectangle *area, bool inverse)
Draw borders and background of a widget.
Definition widget.cc:1429
void correctRequisition(Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseWidth, bool allowDecreaseHeight)
Definition widget.cc:744
style::Style * getStyle()
Definition widget.hh:468
Requisition requisition
Size_request() stores the result of the last call of size_request_impl().
Definition widget.hh:160
virtual void enterNotifyImpl(EventCrossing *event)
Definition widget.cc:2002
int getAvailHeight(bool forceValue)
Return available height including margin/border/padding (extraSpace?), not only the content height.
Definition widget.cc:691
style::Style * style
Definition widget.hh:150
virtual int applyPerWidth(int containerWidth, style::Length perWidth)
Definition widget.cc:1674
void correctExtremes(Extremes *extremes, bool useAdjustmentWidth)
Definition widget.cc:821
Iterator * iterator(Content::Type mask, bool atEnd)
Definition ui.cc:503
void resizeQueued(bool extremesChanged)
Definition ui.cc:326
void setEmbed(Embed *embed)
Definition ui.cc:356
int getAvailHeightOfChild(Widget *child, bool forceValue)
Definition ui.cc:414
void sizeRequest(Requisition *requisition)
Definition ui.cc:370
Iterator * iterator(Content::Type mask, bool atEnd)
Definition ui.cc:483
void sizeAllocate(Allocation *allocation)
Definition ui.cc:401
void correctRequisitionOfChild(Widget *child, Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseWidth, bool allowDecreaseHeight)
Definition ui.cc:424
void correctExtremesOfChild(Widget *child, Extremes *extremes, bool useAdjustmentWidth)
Definition ui.cc:456
void init(Widget *widget)
Definition ui.cc:342
void getExtremes(Extremes *extremes)
Definition ui.cc:385
int getAvailWidthOfChild(Widget *child, bool forceValue)
Definition ui.cc:405
A widget for embedding UI widgets.
Definition ui.hh:224
void correctRequisitionOfChild(Widget *child, Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseWidth, bool allowDecreaseHeight)
Definition ui.cc:81
void setEnabled(bool enabled)
Definition ui.cc:135
void correctExtremesOfChild(Widget *child, Extremes *extremes, bool useAdjustmentWidth)
Definition ui.cc:92
void leaveNotifyImpl(core::EventCrossing *event)
Definition ui.cc:111
void enterNotifyImpl(core::EventCrossing *event)
Definition ui.cc:105
void correctReqHeightOfChildNoRec(Widget *child, Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseHeight)
Definition ui.hh:270
int getAvailHeightOfChild(Widget *child, bool forceValue)
Definition ui.cc:76
Resource * resource
Definition ui.hh:228
static int CLASS_ID
Definition ui.hh:252
void draw(View *view, Rectangle *area, DrawingContext *context)
Area is given in widget coordinates.
Definition ui.cc:140
void setDisplayed(bool displayed)
Definition ui.cc:130
Iterator * iterator(Content::Type mask, bool atEnd)
Return an iterator for this widget.
Definition ui.cc:146
int getAvailWidthOfChild(Widget *child, bool forceValue)
Computes the content width available of a child widget.
Definition ui.cc:71
void getExtremesSimpl(Extremes *extremes)
Simple variant, to be implemented by widgets with extremes not depending on positions.
Definition ui.cc:58
void correctReqWidthOfChildNoRec(Widget *child, Requisition *requisition, bool allowDecreaseWidth)
Definition ui.hh:265
void sizeAllocateImpl(Allocation *allocation)
See Sizes of Dillo Widgets.
Definition ui.cc:66
void sizeRequestSimpl(Requisition *requisition)
Simple variant, to be implemented by widgets with sizes not depending on positions.
Definition ui.cc:51
void containerSizeChangedForChildren()
Definition ui.cc:98
bool buttonPressImpl(core::EventButton *event)
Definition ui.cc:117
void setStyle(style::Style *style)
Change the style of a widget.
Definition ui.cc:151
virtual void correctExtremesOfChildNoRec(Widget *child, Extremes *extremes, bool useAdjustmentWidth)
Definition ui.hh:278
Embed(Resource *resource)
Definition ui.cc:36
Iterator * iterator(Content::Type mask, bool atEnd)
Definition ui.cc:316
Iterator * iterator(Content::Type mask, bool atEnd)
Definition ui.cc:517
bool emitToReceiver(lout::signal::Receiver *receiver, int signalNo, int argc, Object **argv)
A sub class must implement this for a call to a single receiver.
Definition ui.cc:159
void emitEnter(Resource *resource)
Definition ui.cc:190
void emitActivate(Resource *resource)
Definition ui.cc:183
void emitLeave(Resource *resource)
Definition ui.cc:197
Receiver interface for the "activate" signal.
Definition ui.hh:297
virtual void activate(Resource *resource)=0
virtual void leave(Resource *resource)=0
virtual void enter(Resource *resource)=0
bool emitToReceiver(lout::signal::Receiver *receiver, int signalNo, int argc, Object **argv)
A sub class must implement this for a call to a single receiver.
Definition ui.cc:295
void emitClicked(Resource *resource, EventButton *event)
Definition ui.cc:305
Receiver interface for the "clicked" signal.
Definition ui.hh:307
Basic interface for all resources.
Definition ui.hh:289
virtual ~Resource()
Definition ui.cc:206
virtual void setEnabled(bool enabled)=0
virtual Iterator * iterator(Content::Type mask, bool atEnd)=0
virtual void containerSizeChangedForChildren()
Definition ui.cc:268
virtual int getAvailWidthOfChild(Widget *child, bool forceValue)
Definition ui.cc:236
virtual int getAvailHeightOfChild(Widget *child, bool forceValue)
Definition ui.cc:243
virtual void sizeAllocate(Allocation *allocation)
Definition ui.cc:232
virtual void setEmbed(Embed *embed)
Definition ui.cc:211
virtual void setDisplayed(bool displayed)
Definition ui.cc:273
virtual void draw(View *view, Rectangle *area, DrawingContext *context)
Definition ui.cc:277
virtual void correctExtremesOfChild(Widget *child, Extremes *extremes, bool useAdjustmentWidth)
Definition ui.cc:261
void emitClicked(EventButton *event)
Definition ui.hh:353
virtual void setStyle(style::Style *style)
Definition ui.cc:281
virtual void correctRequisitionOfChild(Widget *child, Requisition *requisition, void(*splitHeightFun)(int, int *, int *), bool allowDecreaseWidth, bool allowDecreaseHeight)
Definition ui.cc:250
virtual void getExtremes(Extremes *extremes)
Definition ui.cc:216
virtual Embed * getEmbed()
Definition ui.hh:348
ActivateEmitter activateEmitter
Definition ui.hh:338
virtual void sizeRequest(Requisition *requisition)=0
Iterator * iterator(Content::Type mask, bool atEnd)
Definition ui.cc:494
void registerName(const char *className, int *classId)
This method must be called in the constructor for the sub class.
Definition identity.cc:83
This is the base class for many other classes, which defines very common virtual methods.
Definition object.hh:25
An object::Object wrapper for void pointers.
Definition object.hh:100
The base class for signal receiver base classes.
Definition signal.hh:254
#define DBG_OBJ_ENTER0(aspect, prio, funname)
#define DBG_OBJ_DELETE()
#define DBG_OBJ_CREATE(klass)
#define DBG_OBJ_MSGF(aspect, prio, fmt,...)
#define DBG_OBJ_ENTER(aspect, prio, funname, fmt,...)
#define DBG_OBJ_LEAVE()
#define DBG_OBJ_ASSOC_CHILD(child)
static Layout * layout
bool isPerLength(Length l)
Returns true if l is a percentage.
Definition style.hh:445
void splitHeightPreserveAscent(int height, int *ascent, int *descent)
Definition widget.cc:2027
Dw is in this namespace, or sub namespaces of this one.
T min(T a, T b)
Definition misc.hh:20
void notImplemented(const char *name)
Definition misc.hh:56
T max(T a, T b)
Definition misc.hh:21
void assertNotReached()
Definition misc.hh:36
Here, some common classes (or interfaces) are defined, to standardize the access to other classes.
Definition object.cc:30
Represents the allocation, i.e.
Definition types.hh:164