4 #include <lib/base/ebase.h>
5 #include <lib/base/estring.h>
6 #include <lib/gdi/epoint.h>
7 #include <lib/gdi/esize.h>
8 #include <lib/gdi/erect.h>
9 #include <lib/base/eptrlist.h>
10 #include <libsig_comp.h>
11 #include <lib/gdi/grc.h>
12 #include <lib/driver/rc.h>
13 #include <lib/gui/actions.h>
25 changedText, changedFont, changedForegroundColor, changedBackgroundColor,
26 changedSize, changedPosition, changedPixmap, childChangedHelpText,
28 evtAction, evtShortcut
33 const eAction *action;
36 eWidgetEvent(eventType type, int parameter=0): type(type), parameter(parameter) { }
37 eWidgetEvent(eventType type, const eAction *action): type(type), action(action) { }
38 eWidgetEvent(eventType type, const eRCKey &key): type(type), key(&key) { }
41 * \brief Event should be delivered to the focused widget.
43 * \return true if the event should be delivered to the focused widget instead of the widget itself.
57 /** \brief The main widget class. All widgets inherit this class.
58 * eWidget handles focus management.
60 class eWidget: public Object
64 /// Widget was shown with show() or implicit show()
66 /// Widget is visible on screen. Implies stateShow.
72 * \brief Exits a (model) widget.
74 * Quit the local event loop, thus returning the control to the function which called \a exec.
78 void close(int result);
81 * \brief Closes with a returncode of 0 (success).
83 * Synonym to \a close(0);. Useful to use as a slot.
89 * \brief Closes with a returncode of -1 (failure).
91 * Synonym to \a close(-1);. Useful to use as a slot.
96 * \brief Signal is send, when the focus Changed
98 * used from a existing statusbar.
99 * \sa eWidget::focusChanged
101 Signal1<void, const eWidget*> focusChanged;
102 static Signal2< void, ePtrList<eAction>*, int > showHelp;
104 ePtrList<eAction> actionHelpList;
106 ePtrList<eWidget> childlist;
107 static eWidget *root;
118 eWidget *shortcutFocusWidget;
120 ePtrList<eWidget> _focusList;
122 ePtrList<eWidget> actionListener;
123 eWidget *focus, *TLW;
125 /// old top-level focus
132 inline eWidget *getTLW() // pseudoTLW !!
134 return TLW ? TLW : (TLW = (parent && parent->parent) ? parent->getTLW() : this );
136 int result, in_loop, have_focus, just_showing;
143 virtual void willShow();
144 virtual void willHide();
146 virtual void setPalette();
148 void willShowChildren();
149 void willHideChildren();
152 * \brief Hi priority event filter.
154 * This event filter is called before the event is delivered via \a event.
155 * \return 1 if the event should NOT be forwarded.
157 virtual int eventFilter(const eWidgetEvent &event);
160 * \brief Handles an event.
162 * If re-implemented in a widget-sub-class, \c eWidget::event should be called whenever the event is
163 * not processed by the widget.
164 * \return 1 if the event was processed, 0 if ignored. it might be forwarded to other widgets then.
167 virtual int keyDown(int rc);
168 virtual int keyUp(int rc);
170 virtual void gotFocus();
171 virtual void lostFocus();
173 virtual void recalcClientRect();
177 typedef ePtrList<eActionMap> actionMapList;
179 void findAction(eActionPrioritySet &prio, const eRCKey &key, eWidget *context);
180 void addActionMap(eActionMap *map);
181 void removeActionMap(eActionMap *map);
182 actionMapList actionmaps;
183 static actionMapList globalActions;
185 // generic properties
188 gColor backgroundColor, foregroundColor;
190 ePtr<gPixmap> pixmap;
195 virtual int eventHandler(const eWidgetEvent &event);
196 static void addGlobalActionMap(eActionMap *map);
197 static void removeGlobalActionMap(eActionMap *map);
198 inline eWidget *getNonTransparentBackground()
200 if (backgroundColor >= 0)
202 return parent?parent->getNonTransparentBackground():this;
211 void recalcAbsolutePosition();
213 inline const ePoint &getAbsolutePosition() const
218 inline ePoint getRelativePosition(eWidget *e) const
222 for (eWidget *a=parent; a && (a != e); a=a->parent)
223 pos+=a->clientrect.topLeft();
227 virtual void redrawWidget(gPainter *target, const eRect &area);
229 virtual void eraseBackground(gPainter *target, const eRect &area);
232 * \brief Constructs a new eWidget.
233 * \param parent The parent widget. The widget gets automatically removed when the parent gets removed.
234 * \param takefocus Specifies if the widget should be appended to the focus list of the TLW, i.e. if it can
237 eWidget(eWidget *parent=0, int takefocus=0);
240 * \brief Destructs an eWidget and all its childs.
242 * hide() is called when the widget is shown. The set ePixmap is \e not
243 * freed. If the widget acquired focus, it will be removed from the focuslist.
244 * \sa eWidget::setPixmap
249 * \brief Returns a pointer to the focus list.
251 * The focus list is the list of childs which have the \c takefocus flag set.
252 * This list is only maintained for TLWs.
254 ePtrList<eWidget> *focusList() { return &_focusList; }
257 * \brief Resizes the widget.
259 * Sets the size of the widget to the given size. The event \c changedSize event will be generated.
260 * \param size The new size, relative to the position.
262 void resize(const eSize& size);
265 * \brief Resizes clientrect (and the widget).
267 * Sets the clientrect of the widget to the given size. The real size of the widget will be set to met
268 * these requirement. The event \c changedSize event will be generated.
269 * \param size The new size of the clientrect, relative to the position.
271 void cresize(const eSize& size);
274 * \brief Moves the widget.
276 * Set the new position of the widget to the given position. The \c changedPosition event will be generated.
277 * \param position The new position, relative to the parent's \c clientrect.
279 void move(const ePoint& position);
282 * \brief Moves the clientrect (and the widget).
284 * Set the new position of the clientrect to the given position. The \c changedPosition event will be generated.
285 * \param position The new position, relative to the parent's \c clientrect.
287 void cmove(const ePoint& position);
290 * \brief Returns the current size.
292 * \return Current size of the widget, relative to the position.
294 const eSize& getSize() const { return size; }
297 * \brief Returns the current position.
299 * \return Current position, relative to the parent's \c clientrect.
301 const ePoint& getPosition() const { return position; }
304 * \brief Returns the size of the clientrect.
306 * \return The usable size for the childwidgets.
308 eSize getClientSize() const { return clientrect.size(); }
311 * \brief Returns the clientrect.
313 * \return The area usable for the childwidgets.
315 const eRect& getClientRect() const { return clientrect; }
318 * \brief Recursive redraw of a widget.
320 * All client windows get repaint too, but no widgets above. Unless you have a good reason, you shouldn't
321 * use this function and use \c invalidate().
322 * \param area The area which should be repaint. The default is to repaint the whole widget.
323 * \sa eWidget::invalidate
325 void redraw(eRect area=eRect());
328 * \brief Recursive (complete) redraw of a widget.
330 * Redraws the widget including background. This is the function to use if you want to manually redraw something!
331 * \param area The area which should be repaint. The default is to repaint the whole widget.
332 * \param force Forces a parent-invalidate even on non-visible widgets. Shouldn't be used outside eWidget.
333 * \sa eWidget::redraw
335 void invalidate(eRect area=eRect(), int force=0);
338 * \brief Enters modal message loop.
340 * A new event loop will be launched. The function returns when \a close is called.
341 * \return The argument of \a close.
347 * \brief Visually clears the widget.
349 * Clears the widget. This is done on \a hide().
355 * \brief Delivers a widget-event.
357 * Internally calles \a eventFilter, then \a eventHandler() (in some cases of the focused widget)
358 * \param event The event to deliver.
360 int event(const eWidgetEvent &event);
363 * \brief Shows the widget.
365 * If necessary, the widget will be linked into the TLW's active focus list. The widget will
372 * \brief Hides the widget.
374 * The widget will be removed from the screen. All childs will be hidden too.
380 * \brief Returns if the widget is vissible.
382 * \return If the widget and all parents are visible, \c true is returned, else false.
384 int isVisible() { return (state&stateVisible) && ( (!parent) || parent->isVisible() ); }
387 * \brief Possible focus directions.
391 focusDirNext, focusDirPrev, focusDirN, focusDirE, focusDirS, focusDirW
395 * \brief changes the focused widget.
397 * Focuses the next or previous widget of the \c focuslist. An \c gotFocus and \c lostFocus event will be
399 * \param dir The direction, \c focusDirection.
401 void focusNext(int dir=0);
404 * \brief Gives focus to a widget.
406 * Set the focus to the specified widget. The \c focuslist is updated, too.
407 * An \c gotFocus and \c lostFocus event will be generated.
408 * \param newfocus The new widget to focus.
410 void setFocus(eWidget *newfocus);
413 * \brief Sets the widget font.
415 * The font is used for example by the \c eLabel.
417 * \param font The new font used by widget-specific drawing code.
419 void setFont(const gFont &font);
422 * \brief Sets the widget caption or text.
424 * \param label The text to assign to the widget.
426 void setText(const eString &label);
428 const eString& getText() const { return text; }
429 void setBackgroundColor(const gColor& color, bool inv=true);
430 void setForegroundColor(const gColor& color, bool inv=true);
431 void setPixmap(gPixmap *pmap);
432 void setTarget(gDC *target);
433 gDC *getTarget() { return target; }
436 void setLCD(eWidget *lcdtitle, eWidget *lcdelement);
439 void setName(const char *name);
440 const eString& getName() const { return name; }
441 eWidget*& getParent() { return parent; }
442 const gFont& getFont() const { return font; }
444 const gColor& getBackgroundColor() const { return backgroundColor; }
445 const gColor& getForegroundColor() const { return foregroundColor; }
447 int width() { return getSize().width(); }
448 int height() { return getSize().height(); }
450 gPainter *getPainter(eRect area);
452 const eString& getHelpText() const { return helptext; }
454 void setHelpText( const eString&);
456 * \brief Sets a property.
458 * A property is a value/data pair which is used for serializing widgets (like in skinfiles).
459 * These properties are available to all \c "eWidget"-based classes.
460 * \arg \c position, the position of the widget, relative to the parent's childarea. Consider using csize for TLWs.
461 * Positions are specified in a "x:y" manner.
462 * \arg \c cposition, the position of the widget's clientrect (upper left).
463 * This is useful for specifing a position independant of a decoration which might be
464 * different sized. The real position will be calculated to match the requested position.
465 * \arg \c size, the size of the widget. Consider using csize for TLWs. Sizes are specified in a "width:height" manner.
466 * \arg \c csize, the size of the clientrect. The real size will be calculated to match the requested size.
467 * \arg \c text, the text/caption of the widget.
468 * \arg \c font, the primary font used in the widget.
469 * \arg \c name, the name of the widget for referring them.
470 * \arg \c pixmap, an already loaded, named pixmap to be used as the widget's pixmap.
471 * \arg \c foregroundColor, a named color, which will be used for the widget's foreground color.
472 * \arg \c backgroundColor
473 * \param prop The property to be set.
474 * \param value The value to be set.
476 virtual int setProperty(const eString &prop, const eString &value);
478 eWidget *search(const eString &name);
480 eWidget* getFocus() { return focus; }
488 * \brief sets the shortcut (generate evtShortcut)
490 void setShortcut(const eString &shortcut);
491 void setShortcutFocus(eWidget *focus);
493 void addActionToHelpList(eAction *action);
494 void clearHelpList();
495 void setHelpID(int fHelpID);