00001 #ifndef __DW_LAYOUT_HH__
00002 #define __DW_LAYOUT_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 namespace dw {
00009 namespace core {
00010
00016 class Layout: public lout::object::Object
00017 {
00018 friend class Widget;
00019
00020 public:
00026 class Receiver: public lout::signal::Receiver
00027 {
00028 public:
00029 virtual void canvasSizeChanged (int width, int ascent, int descent);
00030 };
00031
00032 class LinkReceiver: public lout::signal::Receiver
00033 {
00034 public:
00046 virtual bool enter (Widget *widget, int link, int img, int x, int y);
00047
00054 virtual bool press (Widget *widget, int link, int img, int x, int y,
00055 EventButton *event);
00056
00063 virtual bool release (Widget *widget, int link, int img, int x, int y,
00064 EventButton *event);
00065
00077 virtual bool click (Widget *widget, int link, int img, int x, int y,
00078 EventButton *event);
00079 };
00080
00081 class LinkEmitter: public lout::signal::Emitter
00082 {
00083 private:
00084 enum { ENTER, PRESS, RELEASE, CLICK };
00085
00086 protected:
00087 bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
00088 int argc, lout::object::Object **argv);
00089
00090 public:
00091 inline void connectLink (LinkReceiver *receiver) { connect (receiver); }
00092
00093 bool emitEnter (Widget *widget, int link, int img, int x, int y);
00094 bool emitPress (Widget *widget, int link, int img, int x, int y,
00095 EventButton *event);
00096 bool emitRelease (Widget *widget, int link, int img, int x, int y,
00097 EventButton *event);
00098 bool emitClick (Widget *widget, int link, int img, int x, int y,
00099 EventButton *event);
00100 };
00101
00102 LinkEmitter linkEmitter;
00103
00104 private:
00105 class Emitter: public lout::signal::Emitter
00106 {
00107 private:
00108 enum { CANVAS_SIZE_CHANGED };
00109
00110 protected:
00111 bool emitToReceiver (lout::signal::Receiver *receiver, int signalNo,
00112 int argc, lout::object::Object **argv);
00113
00114 public:
00115 inline void connectLayout (Receiver *receiver) { connect (receiver); }
00116
00117 void emitCanvasSizeChanged (int width, int ascent, int descent);
00118 };
00119
00120 Emitter emitter;
00121
00122 class Anchor: public lout::object::Object
00123 {
00124 public:
00125 char *name;
00126 Widget *widget;
00127 int y;
00128
00129 ~Anchor ();
00130 };
00131
00132 Platform *platform;
00133 View *view;
00134 Widget *topLevel, *widgetAtPoint;
00135
00136
00137 style::Color *bgColor;
00138 style::Cursor cursor;
00139 int canvasWidth, canvasAscent, canvasDescent;
00140
00141 bool usesViewport, drawAfterScrollReq;
00142 int scrollX, scrollY, viewportWidth, viewportHeight;
00143 bool canvasHeightGreater;
00144 int hScrollbarThickness, vScrollbarThickness;
00145
00146 HPosition scrollTargetHpos;
00147 VPosition scrollTargetVpos;
00148 int scrollTargetX, scrollTargetY, scrollTargetWidth, scrollTargetHeight;
00149
00150 char *requestedAnchor;
00151 int scrollIdleId, resizeIdleId;
00152 bool scrollIdleNotInterrupted;
00153
00154
00155 lout::container::typed::HashTable <lout::object::String, Anchor>
00156 *anchorsTable;
00157
00158 SelectionState selectionState;
00159 FindtextState findtextState;
00160
00161 enum ButtonEventType { BUTTON_PRESS, BUTTON_RELEASE, MOTION_NOTIFY };
00162
00163 Widget *getWidgetAtPoint (int x, int y);
00164 void moveToWidget (Widget *newWidgetAtPoint, ButtonState state);
00165
00170 void moveToWidgetAtPoint (int x, int y, ButtonState state)
00171 { moveToWidget (getWidgetAtPoint (x, y), state); }
00172
00177 void moveOutOfView (ButtonState state) { moveToWidget (NULL, state); }
00178
00179 bool processMouseEvent (MousePositionEvent *event, ButtonEventType type,
00180 bool mayBeSuppressed);
00181 bool buttonEvent (ButtonEventType type, View *view,
00182 int numPressed, int x, int y, ButtonState state,
00183 int button);
00184 void resizeIdle ();
00185 void setSizeHints ();
00186 void draw (View *view, Rectangle *area);
00187
00188 void scrollTo0(HPosition hpos, VPosition vpos,
00189 int x, int y, int width, int height,
00190 bool scrollingInterrupted);
00191 void scrollIdle ();
00192 void adjustScrollPos ();
00193 static bool calcScrollInto (int targetValue, int requestedSize,
00194 int *value, int viewportSize);
00195
00196 void updateAnchor ();
00197
00198
00199
00200 char *addAnchor (Widget *widget, const char* name);
00201 char *addAnchor (Widget *widget, const char* name, int y);
00202 void changeAnchor (Widget *widget, char* name, int y);
00203 void removeAnchor (Widget *widget, char* name);
00204 void setCursor (style::Cursor cursor);
00205 void updateCursor ();
00206 void queueDraw (int x, int y, int width, int height);
00207 void queueDrawExcept (int x, int y, int width, int height,
00208 int ex, int ey, int ewidth, int eheight);
00209 void queueResize ();
00210 void removeWidget ();
00211
00212 public:
00213 Layout (Platform *platform);
00214 ~Layout ();
00215
00216 inline void connectLink (LinkReceiver *receiver)
00217 { linkEmitter.connectLink (receiver); }
00218
00219 inline bool emitLinkEnter (Widget *w, int link, int img, int x, int y)
00220 { return linkEmitter.emitEnter (w, link, img, x, y); }
00221
00222 inline bool emitLinkPress (Widget *w, int link, int img,
00223 int x, int y, EventButton *event)
00224 { return linkEmitter.emitPress (w, link, img, x, y, event); }
00225
00226 inline bool emitLinkRelease (Widget *w, int link, int img,
00227 int x, int y, EventButton *event)
00228 { return linkEmitter.emitRelease (w, link, img, x, y, event); }
00229
00230 inline bool emitLinkClick (Widget *w, int link, int img,
00231 int x, int y, EventButton *event)
00232 { return linkEmitter.emitClick (w, link, img, x, y, event); }
00233
00234 lout::misc::ZoneAllocator *textZone;
00235
00236 void addWidget (Widget *widget);
00237 void setWidget (Widget *widget);
00238
00239 void attachView (View *view);
00240 void detachView (View *view);
00241
00242 inline bool getUsesViewport () { return usesViewport; }
00243 inline int getWidthViewport () { return viewportWidth; }
00244 inline int getHeightViewport () { return viewportHeight; }
00245 inline int getScrollPosX () { return scrollX; }
00246 inline int getScrollPosY () { return scrollY; }
00247
00248
00249
00250 void scrollTo (HPosition hpos, VPosition vpos,
00251 int x, int y, int width, int height);
00252 void scroll (ScrollCommand);
00253 void setAnchor (const char *anchor);
00254
00255
00256
00257 inline void expose (View *view, Rectangle *area) { draw (view, area); }
00258
00267 inline bool buttonPress (View *view, int numPressed, int x, int y,
00268 ButtonState state, int button)
00269 {
00270 return buttonEvent (BUTTON_PRESS, view, numPressed, x, y, state, button);
00271 }
00272
00279 inline bool buttonRelease (View *view, int numPressed, int x, int y,
00280 ButtonState state, int button)
00281 {
00282 return buttonEvent (BUTTON_RELEASE, view, numPressed, x, y, state,
00283 button);
00284 }
00285
00286 bool motionNotify (View *view, int x, int y, ButtonState state);
00287 void enterNotify (View *view, int x, int y, ButtonState state);
00288 void leaveNotify (View *view, ButtonState state);
00289
00290 void scrollPosChanged (View *view, int x, int y);
00291 void viewportSizeChanged (View *view, int width, int height);
00292
00293
00294
00295 inline int textWidth (style::Font *font, const char *text, int len)
00296 {
00297 return platform->textWidth (font, text, len);
00298 }
00299
00300 inline int nextGlyph (const char *text, int idx)
00301 {
00302 return platform->nextGlyph (text, idx);
00303 }
00304
00305 inline int prevGlyph (const char *text, int idx)
00306 {
00307 return platform->prevGlyph (text, idx);
00308 }
00309
00310 inline float dpiX ()
00311 {
00312 return platform->dpiX ();
00313 }
00314
00315 inline float dpiY ()
00316 {
00317 return platform->dpiY ();
00318 }
00319
00320 inline style::Font *createFont (style::FontAttrs *attrs, bool tryEverything)
00321 {
00322 return platform->createFont (attrs, tryEverything);
00323 }
00324
00325 inline bool fontExists (const char *name)
00326 {
00327 return platform->fontExists (name);
00328 }
00329
00330 inline style::Color *createColor (int color)
00331 {
00332 return platform->createColor (color);
00333 }
00334
00335 inline style::Tooltip *createTooltip (const char *text)
00336 {
00337 return platform->createTooltip (text);
00338 }
00339
00340 inline void cancelTooltip ()
00341 {
00342 return platform->cancelTooltip ();
00343 }
00344
00345 inline Imgbuf *createImgbuf (Imgbuf::Type type, int width, int height)
00346 {
00347 return platform->createImgbuf (type, width, height);
00348 }
00349
00350 inline void copySelection(const char *text)
00351 {
00352 platform->copySelection(text);
00353 }
00354
00355 inline ui::ResourceFactory *getResourceFactory ()
00356 {
00357 return platform->getResourceFactory ();
00358 }
00359
00360 inline void connect (Receiver *receiver) {
00361 emitter.connectLayout (receiver); }
00362
00364 inline FindtextState::Result search (const char *str, bool caseSens,
00365 int backwards)
00366 { return findtextState.search (str, caseSens, backwards); }
00367
00369 inline void resetSearch () { findtextState.resetSearch (); }
00370
00371 void setBgColor (style::Color *color);
00372
00373 inline style::Color* getBgColor () { return bgColor; }
00374 };
00375
00376 }
00377 }
00378
00379 #endif // __DW_LAYOUT_HH__
00380