00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkView_DEFINED
00018 #define SkView_DEFINED
00019
00020 #include "SkEventSink.h"
00021 #include "SkRect.h"
00022 #include "SkDOM.h"
00023 #include "SkTDict.h"
00024
00025 class SkCanvas;
00026 class SkLayerView;
00027
00033 class SkView : public SkEventSink {
00034 public:
00035 enum Flag_Shift {
00036 kVisible_Shift,
00037 kEnabled_Shift,
00038 kFocusable_Shift,
00039 kFlexH_Shift,
00040 kFlexV_Shift,
00041
00042 kFlagShiftCount
00043 };
00044 enum Flag_Mask {
00045 kVisible_Mask = 1 << kVisible_Shift,
00046 kEnabled_Mask = 1 << kEnabled_Shift,
00047 kFocusable_Mask = 1 << kFocusable_Shift,
00048 kFlexH_Mask = 1 << kFlexH_Shift,
00049 kFlexV_Mask = 1 << kFlexV_Shift,
00050
00051 kAllFlagMasks = (uint32_t)(0 - 1) >> (32 - kFlagShiftCount)
00052 };
00053
00054 SkView(uint32_t flags = 0);
00055 virtual ~SkView();
00056
00059 uint32_t getFlags() const { return fFlags; }
00062 void setFlags(uint32_t flags);
00063
00066 int isVisible() const { return fFlags & kVisible_Mask; }
00067 int isEnabled() const { return fFlags & kEnabled_Mask; }
00068 int isFocusable() const { return fFlags & kFocusable_Mask; }
00070 void setVisibleP(bool);
00071 void setEnabledP(bool);
00072 void setFocusableP(bool);
00073
00075 SkScalar width() const { return fWidth; }
00077 SkScalar height() const { return fHeight; }
00079 void setSize(SkScalar width, SkScalar height);
00080 void setSize(const SkPoint& size) { this->setSize(size.fX, size.fY); }
00081 void setWidth(SkScalar width) { this->setSize(width, fHeight); }
00082 void setHeight(SkScalar height) { this->setSize(fWidth, height); }
00084 void getLocalBounds(SkRect* bounds) const;
00085
00087 SkScalar locX() const { return fLoc.fX; }
00089 SkScalar locY() const { return fLoc.fY; }
00091 void setLoc(SkScalar x, SkScalar y);
00092 void setLoc(const SkPoint& loc) { this->setLoc(loc.fX, loc.fY); }
00093 void setLocX(SkScalar x) { this->setLoc(x, fLoc.fY); }
00094 void setLocY(SkScalar y) { this->setLoc(fLoc.fX, y); }
00096 void offset(SkScalar dx, SkScalar dy);
00097
00099 void draw(SkCanvas* canvas);
00104 void inval(SkRect* rectOrNull);
00105
00106
00107
00108 SkView* getFocusView() const;
00109 bool hasFocus() const;
00110
00111 enum FocusDirection {
00112 kNext_FocusDirection,
00113 kPrev_FocusDirection,
00114
00115 kFocusDirectionCount
00116 };
00117 bool acceptFocus();
00118 SkView* moveFocus(FocusDirection);
00119
00120
00121
00122 class Click {
00123 public:
00124 Click(SkView* target);
00125 virtual ~Click();
00126
00127 const char* getType() const { return fType; }
00128 bool isType(const char type[]) const;
00129 void setType(const char type[]);
00130 void copyType(const char type[]);
00131
00132 enum State {
00133 kDown_State,
00134 kMoved_State,
00135 kUp_State
00136 };
00137 SkPoint fOrig, fPrev, fCurr;
00138 SkIPoint fIOrig, fIPrev, fICurr;
00139 State fState;
00140 private:
00141 SkEventSinkID fTargetID;
00142 char* fType;
00143 bool fWeOwnTheType;
00144
00145 void resetType();
00146
00147 friend class SkView;
00148 };
00149 Click* findClickHandler(SkScalar x, SkScalar y);
00150
00151 static void DoClickDown(Click*, int x, int y);
00152 static void DoClickMoved(Click*, int x, int y);
00153 static void DoClickUp(Click*, int x, int y);
00154
00159 SkView* sendEventToParents(const SkEvent&);
00162 bool postEvent(SkEvent* evt, SkEventSinkID sinkID, SkMSec delay) { return evt->post(sinkID, delay); }
00163
00164
00165
00167 SkView* getParent() const { return fParent; }
00168 SkView* attachChildToFront(SkView* child);
00173 SkView* attachChildToBack(SkView* child);
00177 void detachFromParent();
00183 void detachAllChildren();
00184
00187 void globalToLocal(SkPoint* pt) const { if (pt) this->globalToLocal(pt->fX, pt->fY, pt); }
00191 void globalToLocal(SkScalar globalX, SkScalar globalY, SkPoint* local) const;
00192
00200 class F2BIter {
00201 public:
00202 F2BIter(const SkView* parent);
00203 SkView* next();
00204 private:
00205 SkView* fFirstChild, *fChild;
00206 };
00207
00215 class B2FIter {
00216 public:
00217 B2FIter(const SkView* parent);
00218 SkView* next();
00219 private:
00220 SkView* fFirstChild, *fChild;
00221 };
00222
00229 class Artist : public SkRefCnt {
00230 public:
00231 void draw(SkView*, SkCanvas*);
00232 void inflate(const SkDOM&, const SkDOM::Node*);
00233 protected:
00234 virtual void onDraw(SkView*, SkCanvas*) = 0;
00235 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
00236 };
00240 Artist* getArtist() const;
00245 Artist* setArtist(Artist* artist);
00246
00253 class Layout : public SkRefCnt {
00254 public:
00255 void layoutChildren(SkView* parent);
00256 void inflate(const SkDOM&, const SkDOM::Node*);
00257 protected:
00258 virtual void onLayoutChildren(SkView* parent) = 0;
00259 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
00260 };
00261
00265 Layout* getLayout() const;
00270 Layout* setLayout(Layout*, bool invokeLayoutNow = true);
00273 void invokeLayout();
00274
00277 void inflate(const SkDOM& dom, const SkDOM::Node* node);
00285 void postInflate(const SkTDict<SkView*>& ids);
00286
00287 SkDEBUGCODE(void dump(bool recurse) const;)
00288
00289 protected:
00291 virtual void onDraw(SkCanvas*);
00293 virtual void onSizeChange();
00298 virtual bool handleInval(const SkRect&);
00300 virtual SkCanvas* beforeChildren(SkCanvas* c) { return c; }
00302 virtual void afterChildren(SkCanvas* orig) {}
00303
00305 virtual void beforeChild(SkView* child, SkCanvas* canvas) {}
00307 virtual void afterChild(SkView* child, SkCanvas* canvas) {}
00308
00311 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
00315 virtual bool onClick(Click*);
00317 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00321 virtual void onPostInflate(const SkTDict<SkView*>&);
00322
00323 public:
00324
00325 virtual void onFocusChange(bool gainFocusP);
00326 protected:
00327
00328
00329 virtual bool onGetFocusView(SkView**) const { return false; }
00330 virtual bool onSetFocusView(SkView*) { return false; }
00331
00332 private:
00333 SkScalar fWidth, fHeight;
00334 SkPoint fLoc;
00335 SkView* fParent;
00336 SkView* fFirstChild;
00337 SkView* fNextSibling;
00338 SkView* fPrevSibling;
00339 uint8_t fFlags;
00340 uint8_t fContainsFocus;
00341
00342 friend class B2FIter;
00343 friend class F2BIter;
00344
00345 friend class SkLayerView;
00346
00347 bool setFocusView(SkView* fvOrNull);
00348 SkView* acceptFocus(FocusDirection);
00349 void detachFromParent_NoLayout();
00350 };
00351
00352 #endif
00353