00001 #ifndef __DW_WIDGET_HH__
00002 #define __DW_WIDGET_HH__
00003
00004 #ifndef __INCLUDED_FROM_DW_CORE_HH__
00005 # error Do not include this file directly, use "core.hh" instead.
00006 #endif
00007
00008 #include "../lout/identity.hh"
00009
00013 typedef void (*DW_Callback_t)(void *data);
00014
00015 namespace dw {
00016 namespace core {
00017
00023 class Widget: public lout::identity::IdentifiableObject
00024 {
00025 friend class Layout;
00026
00027 protected:
00028 enum Flags {
00033 NEEDS_RESIZE = 1 << 0,
00034
00040 NEEDS_ALLOCATE = 1 << 1,
00041
00046 EXTREMES_CHANGED = 1 << 2,
00047
00054 USES_HINTS = 1 << 3,
00055
00062 HAS_CONTENTS = 1 << 4,
00063
00069 WAS_ALLOCATED = 1 << 5,
00070
00074 BLOCK_LEVEL = 1 << 6,
00075 };
00076
00077 private:
00081 Widget *parent;
00082 style::Style *style;
00083
00084 Flags flags;
00085
00092 Requisition requisition;
00093
00097 Extremes extremes;
00098
00102 style::Color *bgColor;
00103
00107 bool buttonSensitive;
00108
00112 bool buttonSensitiveSet;
00113
00114 public:
00121 int parentRef;
00122
00123 protected:
00124
00129 Allocation allocation;
00130
00131 inline int getHeight () { return allocation.ascent + allocation.descent; }
00132 inline int getContentWidth() { return allocation.width
00133 - style->boxDiffWidth (); }
00134 inline int getContentHeight() { return getHeight ()
00135 - style->boxDiffHeight (); }
00136
00137 Layout *layout;
00138
00139 inline void setFlags (Flags f) { flags = (Flags)(flags | f); }
00140 inline void unsetFlags (Flags f) { flags = (Flags)(flags & ~f); }
00141
00142
00143 inline void queueDraw ()
00144 {
00145 queueDrawArea (0, 0, allocation.width, getHeight());
00146 }
00147 void queueDrawArea (int x, int y, int width, int height);
00148 void queueResize (int ref, bool extremesChanged);
00149
00153 virtual void sizeRequestImpl (Requisition *requisition) = 0;
00154
00158 virtual void getExtremesImpl (Extremes *extremes);
00159
00163 virtual void sizeAllocateImpl (Allocation *allocation);
00164
00169 virtual void resizeDrawImpl () { queueDraw (); };
00170
00174 virtual void markSizeChange (int ref);
00175
00179 virtual void markExtremesChange (int ref);
00180
00181 virtual bool buttonPressImpl (EventButton *event);
00182 virtual bool buttonReleaseImpl (EventButton *event);
00183 virtual bool motionNotifyImpl (EventMotion *event);
00184 virtual void enterNotifyImpl (EventCrossing *event);
00185 virtual void leaveNotifyImpl (EventCrossing *event);
00186
00187 inline char *addAnchor (const char* name)
00188 { return layout->addAnchor (this, name); }
00189
00190 inline char *addAnchor (const char* name, int y)
00191 { return layout->addAnchor (this, name, y); }
00192
00193 inline void changeAnchor (char* name, int y)
00194 { layout->changeAnchor (this, name, y); }
00195
00196 inline void removeAnchor (char* name)
00197 { layout->removeAnchor (this, name); }
00198
00199
00200
00201 inline void setCursor (style::Cursor cursor)
00202 { layout->setCursor (cursor); }
00203
00204 inline bool selectionButtonPress (Iterator *it, int charPos, int linkNo,
00205 EventButton *event, bool withinContent)
00206 { return layout->selectionState.buttonPress (it, charPos, linkNo, event); }
00207
00208 inline bool selectionButtonRelease (Iterator *it, int charPos, int linkNo,
00209 EventButton *event, bool withinContent)
00210 { return layout->selectionState.buttonRelease (it, charPos, linkNo, event);}
00211
00212 inline bool selectionButtonMotion (Iterator *it, int charPos, int linkNo,
00213 EventMotion *event, bool withinContent)
00214 { return layout->selectionState.buttonMotion (it, charPos, linkNo, event); }
00215
00216 inline bool selectionHandleEvent (SelectionState::EventType eventType,
00217 Iterator *it, int charPos, int linkNo,
00218 MousePositionEvent *event)
00219 { return layout->selectionState.handleEvent (eventType, it, charPos, linkNo,
00220 event); }
00221
00222 private:
00223 void *deleteCallbackData;
00224 DW_Callback_t deleteCallbackFunc;
00225
00226 public:
00227 inline void setDeleteCallback(DW_Callback_t func, void *data)
00228 { deleteCallbackFunc = func; deleteCallbackData = data; }
00229
00230 public:
00231 static int CLASS_ID;
00232
00233 Widget ();
00234 ~Widget ();
00235
00236 inline bool needsResize () { return flags & NEEDS_RESIZE; }
00237 inline bool needsAllocate () { return flags & NEEDS_ALLOCATE; }
00238 inline bool extremesChanged () { return flags & EXTREMES_CHANGED; }
00239 inline bool wasAllocated () { return flags & WAS_ALLOCATED; }
00240 inline bool usesHints () { return flags & USES_HINTS; }
00241 inline bool hasContents () { return flags & HAS_CONTENTS; }
00242 inline bool blockLevel () { return flags & BLOCK_LEVEL; }
00243
00244 void setParent (Widget *parent);
00245
00246 inline style::Style *getStyle () { return style; }
00248 inline Allocation *getAllocation () { return &allocation; }
00249
00250 void sizeRequest (Requisition *requisition);
00251 void getExtremes (Extremes *extremes);
00252 void sizeAllocate (Allocation *allocation);
00253 virtual void setWidth (int width);
00254 virtual void setAscent (int ascent);
00255 virtual void setDescent (int descent);
00256
00257 bool intersects (Rectangle *area, Rectangle *intersection);
00258
00260 virtual void draw (View *view, Rectangle *area) = 0;
00261
00262 bool buttonPress (EventButton *event);
00263 bool buttonRelease (EventButton *event);
00264 bool motionNotify (EventMotion *event);
00265 void enterNotify (EventCrossing *event);
00266 void leaveNotify (EventCrossing *event);
00267
00268 virtual void setStyle (style::Style *style);
00269 void setBgColor (style::Color *bgColor);
00270 style::Color *getBgColor ();
00271
00272 void drawBox (View *view, style::Style *style, Rectangle *area,
00273 int x, int y, int width, int height, bool inverse);
00274 void drawWidgetBox (View *view, Rectangle *area, bool inverse);
00275 void drawSelected (View *view, Rectangle *area);
00276
00277 void setButtonSensitive (bool buttonSensitive);
00278 inline bool isButtonSensitive () { return buttonSensitive; }
00279
00280 inline Widget *getParent () { return parent; }
00281 Widget *getTopLevel ();
00282 int getLevel ();
00283 Widget *getNearestCommonAncestor (Widget *otherWidget);
00284
00285 inline Layout *getLayout () { return layout; }
00286
00287 virtual Widget *getWidgetAtPoint (int x, int y, int level);
00288
00289 void scrollTo (HPosition hpos, VPosition vpos,
00290 int x, int y, int width, int height);
00291
00305 virtual Iterator *iterator (Content::Type mask, bool atEnd) = 0;
00306 virtual void removeChild (Widget *child);
00307 };
00308
00309 }
00310 }
00311
00312 #endif // __DW_WIDGET_HH__