00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef SkWidget_DEFINED
00018 #define SkWidget_DEFINED
00019
00020 #include "SkView.h"
00021 #include "SkBitmap.h"
00022 #include "SkDOM.h"
00023 #include "SkPaint.h"
00024 #include "SkString.h"
00025 #include "SkTDArray.h"
00026
00028
00029 class SkWidget : public SkView {
00030 public:
00031 SkWidget(uint32_t flags = 0) : SkView(flags | kFocusable_Mask | kEnabled_Mask) {}
00032
00034 void postWidgetEvent();
00035
00036 static void Init();
00037 static void Term();
00038 protected:
00039
00040 virtual void prepareWidgetEvent(SkEvent*);
00041 virtual void onEnabledChange();
00042
00043
00044 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00045
00046 private:
00047 SkEvent fEvent;
00048 typedef SkView INHERITED;
00049 };
00050
00051 class SkHasLabelWidget : public SkWidget {
00052 public:
00053 SkHasLabelWidget(uint32_t flags = 0) : SkWidget(flags) {}
00054
00055 size_t getLabel(SkString* label = NULL) const;
00056 size_t getLabel(char lable[] = NULL) const;
00057 void setLabel(const SkString&);
00058 void setLabel(const char label[]);
00059 void setLabel(const char label[], size_t len);
00060
00061 protected:
00062
00063 virtual void onLabelChange();
00064
00065
00066 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00067
00068 private:
00069 SkString fLabel;
00070 typedef SkWidget INHERITED;
00071 };
00072
00073 class SkButtonWidget : public SkHasLabelWidget {
00074 public:
00075 SkButtonWidget(uint32_t flags = 0) : SkHasLabelWidget(flags), fState(kOff_State) {}
00076
00077 enum State {
00078 kOff_State,
00079 kOn_State,
00080 kUnknown_State
00081 };
00082 State getButtonState() const { return fState; }
00083 void setButtonState(State);
00084
00085 protected:
00087 virtual void onButtonStateChange();
00088
00089
00090 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00091
00092 private:
00093 State fState;
00094 typedef SkHasLabelWidget INHERITED;
00095 };
00096
00097 class SkPushButtonWidget : public SkButtonWidget {
00098 public:
00099 SkPushButtonWidget(uint32_t flags = 0) : SkButtonWidget(flags) {}
00100
00101 protected:
00102 virtual bool onEvent(const SkEvent&);
00103 virtual void onDraw(SkCanvas*);
00104 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
00105 virtual bool onClick(Click* click);
00106
00107 private:
00108 typedef SkButtonWidget INHERITED;
00109 };
00110
00111 class SkCheckBoxWidget : public SkButtonWidget {
00112 public:
00113 SkCheckBoxWidget(uint32_t flags = 0);
00114
00115 protected:
00116 virtual bool onEvent(const SkEvent&);
00117 virtual void onDraw(SkCanvas*);
00118 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00119
00120 private:
00121 typedef SkButtonWidget INHERITED;
00122 };
00123
00124 #include "SkTextBox.h"
00125
00126 class SkStaticTextView : public SkView {
00127 public:
00128 SkStaticTextView(uint32_t flags = 0);
00129 virtual ~SkStaticTextView();
00130
00131 enum Mode {
00132 kFixedSize_Mode,
00133 kAutoWidth_Mode,
00134 kAutoHeight_Mode,
00135
00136 kModeCount
00137 };
00138 Mode getMode() const { return (Mode)fMode; }
00139 void setMode(Mode);
00140
00141 SkTextBox::SpacingAlign getSpacingAlign() const { return (SkTextBox::SpacingAlign)fSpacingAlign; }
00142 void setSpacingAlign(SkTextBox::SpacingAlign);
00143
00144 void getMargin(SkPoint* margin) const;
00145 void setMargin(SkScalar dx, SkScalar dy);
00146
00147 size_t getText(SkString* text = NULL) const;
00148 size_t getText(char text[] = NULL) const;
00149 void setText(const SkString&);
00150 void setText(const char text[]);
00151 void setText(const char text[], size_t len);
00152
00153 void getPaint(SkPaint*) const;
00154 void setPaint(const SkPaint&);
00155
00156 protected:
00157
00158 virtual void onDraw(SkCanvas*);
00159 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00160
00161 private:
00162 SkPoint fMargin;
00163 SkString fText;
00164 SkPaint fPaint;
00165 uint8_t fMode;
00166 uint8_t fSpacingAlign;
00167
00168 void computeSize();
00169
00170 typedef SkView INHERITED;
00171 };
00172
00173 class SkBitmapView : public SkView {
00174 public:
00175 SkBitmapView(uint32_t flags = 0);
00176 virtual ~SkBitmapView();
00177
00178 bool getBitmap(SkBitmap*) const;
00179 void setBitmap(const SkBitmap*, bool viewOwnsPixels);
00180 bool loadBitmapFromFile(const char path[]);
00181
00182 protected:
00183 virtual void onDraw(SkCanvas*);
00184 virtual void onInflate(const SkDOM&, const SkDOM::Node*);
00185
00186 private:
00187 SkBitmap fBitmap;
00188 typedef SkView INHERITED;
00189 };
00190
00192
00193 class SkShader;
00194 class SkInterpolator;
00195
00196 class SkWidgetView : public SkView {
00197 public:
00198 SkWidgetView(uint32_t flags = 0);
00199 virtual ~SkWidgetView();
00200
00201 static const char* GetEventType();
00202 };
00203
00204 class SkSliderView : public SkWidgetView {
00205 public:
00206 SkSliderView(uint32_t flags = 0);
00207
00208 uint16_t getValue() const { return fValue; }
00209 uint16_t getMax() const { return fMax; }
00210
00211 void setMax(U16CPU max);
00212 void setValue(U16CPU value);
00213
00214 protected:
00215 virtual void onDraw(SkCanvas*);
00216 virtual Click* onFindClickHandler(SkScalar x, SkScalar y);
00217 virtual bool onClick(Click*);
00218
00219 private:
00220 uint16_t fValue, fMax;
00221
00222 typedef SkWidgetView INHERITED;
00223 };
00224
00226
00227 class SkHasLabelView : public SkView {
00228 public:
00229 void getLabel(SkString*) const;
00230 void setLabel(const SkString&);
00231 void setLabel(const char label[]);
00232
00233 protected:
00234 SkString fLabel;
00235
00236
00237 virtual void onLabelChange();
00238
00239
00240 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00241 };
00242
00243 class SkPushButtonView : public SkHasLabelView {
00244 public:
00245 SkPushButtonView(uint32_t flags = 0);
00246
00247 protected:
00248 virtual void onDraw(SkCanvas*);
00249 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00250 };
00251
00252 class SkCheckBoxView : public SkHasLabelView {
00253 public:
00254 SkCheckBoxView(uint32_t flags = 0);
00255
00256 enum State {
00257 kOff_State,
00258 kOn_State,
00259 kMaybe_State
00260 };
00261 State getState() const { return fState; }
00262 void setState(State);
00263
00264 protected:
00265 virtual void onDraw(SkCanvas*);
00266 virtual void onInflate(const SkDOM& dom, const SkDOM::Node*);
00267
00268 private:
00269 State fState;
00270 };
00271
00272 class SkProgressView : public SkView {
00273 public:
00274 SkProgressView(uint32_t flags = 0);
00275 virtual ~SkProgressView();
00276
00277 uint16_t getValue() const { return fValue; }
00278 uint16_t getMax() const { return fMax; }
00279
00280 void setMax(U16CPU max);
00281 void setValue(U16CPU value);
00282
00283 protected:
00284 virtual void onDraw(SkCanvas*);
00285 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00286
00287 private:
00288 uint16_t fValue, fMax;
00289 SkShader* fOnShader, *fOffShader;
00290 SkInterpolator* fInterp;
00291 bool fDoInterp;
00292
00293 typedef SkView INHERITED;
00294 };
00295
00296 class SkTextView : public SkView {
00297 public:
00298 SkTextView(uint32_t flags = 0);
00299 virtual ~SkTextView();
00300
00301 enum AnimaDir {
00302 kNeutral_AnimDir,
00303 kForward_AnimDir,
00304 kBackward_AnimDir,
00305 kAnimDirCount
00306 };
00307
00308 void getText(SkString*) const;
00309 void setText(const SkString&, AnimaDir dir = kNeutral_AnimDir);
00310 void setText(const char text[], AnimaDir dir = kNeutral_AnimDir);
00311 void setText(const char text[], size_t len, AnimaDir dir = kNeutral_AnimDir);
00312
00313 void getMargin(SkPoint* margin) const;
00314 void setMargin(const SkPoint&);
00315
00316 SkPaint& paint() { return fPaint; }
00317
00318 protected:
00319 virtual void onDraw(SkCanvas*);
00320 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00321
00322 private:
00323 SkString fText;
00324 SkPaint fPaint;
00325 SkPoint fMargin;
00326
00327 class Interp;
00328 Interp* fInterp;
00329 bool fDoInterp;
00330
00331
00332 void privSetText(const SkString&, AnimaDir dir);
00333
00334 typedef SkView INHERITED;
00335 };
00336
00338
00339 class SkEvent;
00340
00341 class SkListSource : public SkEventSink {
00342 public:
00343 virtual int countRows() = 0;
00344 virtual void getRow(int index, SkString* left, SkString* right) = 0;
00345 virtual SkEvent* getEvent(int index);
00346
00347 static SkListSource* CreateFromDir(const char path[], const char suffix[],
00348 const char targetPrefix[]);
00349 static SkListSource* CreateFromDOM(const SkDOM& dom, const SkDOM::Node* node);
00350 };
00351
00352 class SkListView : public SkWidgetView {
00353 public:
00354 SkListView(uint32_t flags = 0);
00355 virtual ~SkListView();
00356
00357 SkScalar getRowHeight() const { return fRowHeight; }
00358 void setRowHeight(SkScalar);
00359
00362 int getSelection() const { return fCurrIndex; }
00365 void setSelection(int);
00366
00367 void moveSelectionUp();
00368 void moveSelectionDown();
00369
00370 enum Attr {
00371 kBG_Attr,
00372 kNormalText_Attr,
00373 kHiliteText_Attr,
00374 kHiliteCell_Attr,
00375 kAttrCount
00376 };
00377 SkPaint& paint(Attr);
00378
00379 SkListSource* getListSource() const { return fSource; }
00380 SkListSource* setListSource(SkListSource*);
00381
00382 #if 0
00383 enum Action {
00384 kSelectionChange_Action,
00385 kSelectionPicked_Action,
00386 kActionCount
00387 };
00393 void setActionEvent(Action, SkEvent* event);
00394 #endif
00395
00396 protected:
00397 virtual void onDraw(SkCanvas*);
00398 virtual void onSizeChange();
00399 virtual bool onEvent(const SkEvent&);
00400 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00401
00402 private:
00403 SkPaint fPaint[kAttrCount];
00404 SkListSource* fSource;
00405 SkScalar fRowHeight;
00406 int fCurrIndex;
00407 int fScrollIndex;
00408 int fVisibleRowCount;
00409 SkString* fStrCache;
00410
00411 void dirtyStrCache();
00412 void ensureStrCache(int visibleCount);
00413
00414 int logicalToVisualIndex(int index) const { return index - fScrollIndex; }
00415 void invalSelection();
00416 bool getRowRect(int index, SkRect*) const;
00417 void ensureSelectionIsVisible();
00418
00419 typedef SkWidgetView INHERITED;
00420 };
00421
00423
00424 class SkGridView : public SkWidgetView {
00425 public:
00426 SkGridView(uint32_t flags = 0);
00427 virtual ~SkGridView();
00428
00429 void getCellSize(SkPoint*) const;
00430 void setCellSize(SkScalar x, SkScalar y);
00431
00434 int getSelection() const { return fCurrIndex; }
00437 void setSelection(int);
00438
00439 void moveSelectionUp();
00440 void moveSelectionDown();
00441
00442 enum Attr {
00443 kBG_Attr,
00444 kHiliteCell_Attr,
00445 kAttrCount
00446 };
00447 SkPaint& paint(Attr);
00448
00449 SkListSource* getListSource() const { return fSource; }
00450 SkListSource* setListSource(SkListSource*);
00451
00452 protected:
00453 virtual void onDraw(SkCanvas*);
00454 virtual void onSizeChange();
00455 virtual bool onEvent(const SkEvent&);
00456 virtual void onInflate(const SkDOM& dom, const SkDOM::Node* node);
00457
00458 private:
00459 SkView* fScrollBar;
00460 SkPaint fPaint[kAttrCount];
00461 SkListSource* fSource;
00462 int fCurrIndex;
00463
00464 SkPoint fCellSize;
00465 SkIPoint fVisibleCount;
00466
00467 int logicalToVisualIndex(int index) const { return index; }
00468 void invalSelection();
00469 bool getCellRect(int index, SkRect*) const;
00470 void ensureSelectionIsVisible();
00471
00472 typedef SkWidgetView INHERITED;
00473 };
00474
00475 #endif
00476