00001 #ifndef __DW_STYLE_HH__
00002 #define __DW_STYLE_HH__
00003
00004 #include <stdint.h>
00005
00006 #ifndef __INCLUDED_FROM_DW_CORE_HH__
00007 # error Do not include this file directly, use "core.hh" instead.
00008 #endif
00009
00010 namespace dw {
00011 namespace core {
00012
00193 namespace style {
00194
00195 enum Cursor {
00196 CURSOR_CROSSHAIR,
00197 CURSOR_DEFAULT,
00198 CURSOR_POINTER,
00199 CURSOR_MOVE,
00200 CURSOR_E_RESIZE,
00201 CURSOR_NE_RESIZE,
00202 CURSOR_NW_RESIZE,
00203 CURSOR_N_RESIZE,
00204 CURSOR_SE_RESIZE,
00205 CURSOR_SW_RESIZE,
00206 CURSOR_S_RESIZE,
00207 CURSOR_W_RESIZE,
00208 CURSOR_TEXT,
00209 CURSOR_WAIT,
00210 CURSOR_HELP
00211 };
00212
00213 enum BorderCollapse {
00214 BORDER_MODEL_SEPARATE,
00215 BORDER_MODEL_COLLAPSE
00216 };
00217
00218 enum BorderStyle {
00219 BORDER_NONE,
00220 BORDER_HIDDEN,
00221 BORDER_DOTTED,
00222 BORDER_DASHED,
00223 BORDER_SOLID,
00224 BORDER_DOUBLE,
00225 BORDER_GROOVE,
00226 BORDER_RIDGE,
00227 BORDER_INSET,
00228 BORDER_OUTSET
00229 };
00230
00231 enum TextAlignType {
00232 TEXT_ALIGN_LEFT,
00233 TEXT_ALIGN_RIGHT,
00234 TEXT_ALIGN_CENTER,
00235 TEXT_ALIGN_JUSTIFY,
00236 TEXT_ALIGN_STRING
00237 };
00238
00239 enum VAlignType {
00240 VALIGN_TOP,
00241 VALIGN_BOTTOM,
00242 VALIGN_MIDDLE,
00243 VALIGN_BASELINE,
00244 VALIGN_SUB,
00245 VALIGN_SUPER,
00246 VALIGN_TEXT_TOP,
00247 VALIGN_TEXT_BOTTOM,
00248 };
00249
00253 enum DisplayType {
00254 DISPLAY_BLOCK,
00255 DISPLAY_INLINE,
00256 DISPLAY_LIST_ITEM,
00257 DISPLAY_NONE,
00258 DISPLAY_TABLE,
00259 DISPLAY_TABLE_ROW_GROUP,
00260 DISPLAY_TABLE_HEADER_GROUP,
00261 DISPLAY_TABLE_FOOTER_GROUP,
00262 DISPLAY_TABLE_ROW,
00263 DISPLAY_TABLE_CELL
00264 };
00265
00266 enum LineType {
00267 LINE_NORMAL,
00268 LINE_DOTTED,
00269 LINE_DASHED
00270 };
00271
00272 enum ListStylePosition {
00273 LIST_STYLE_POSITION_INSIDE,
00274 LIST_STYLE_POSITION_OUTSIDE
00275 };
00276
00277 enum ListStyleType {
00278 LIST_STYLE_TYPE_DISC,
00279 LIST_STYLE_TYPE_CIRCLE,
00280 LIST_STYLE_TYPE_SQUARE,
00281 LIST_STYLE_TYPE_DECIMAL,
00282 LIST_STYLE_TYPE_DECIMAL_LEADING_ZERO,
00283 LIST_STYLE_TYPE_LOWER_ROMAN,
00284 LIST_STYLE_TYPE_UPPER_ROMAN,
00285 LIST_STYLE_TYPE_LOWER_GREEK,
00286 LIST_STYLE_TYPE_LOWER_ALPHA,
00287 LIST_STYLE_TYPE_LOWER_LATIN,
00288 LIST_STYLE_TYPE_UPPER_ALPHA,
00289 LIST_STYLE_TYPE_UPPER_LATIN,
00290 LIST_STYLE_TYPE_HEBREW,
00291 LIST_STYLE_TYPE_ARMENIAN,
00292 LIST_STYLE_TYPE_GEORGIAN,
00293 LIST_STYLE_TYPE_CJK_IDEOGRAPHIC,
00294 LIST_STYLE_TYPE_HIRAGANA,
00295 LIST_STYLE_TYPE_KATAKANA,
00296 LIST_STYLE_TYPE_HIRAGANA_IROHA,
00297 LIST_STYLE_TYPE_KATAKANA_IROHA,
00298 LIST_STYLE_TYPE_NONE
00299 };
00300
00301 enum FontStyle {
00302 FONT_STYLE_NORMAL,
00303 FONT_STYLE_ITALIC,
00304 FONT_STYLE_OBLIQUE
00305 };
00306
00307 enum FontVariant {
00308 FONT_VARIANT_NORMAL,
00309 FONT_VARIANT_SMALL_CAPS
00310 };
00311
00312 enum TextDecoration {
00313 TEXT_DECORATION_NONE = 0,
00314 TEXT_DECORATION_UNDERLINE = 1 << 0,
00315 TEXT_DECORATION_OVERLINE = 1 << 1,
00316 TEXT_DECORATION_LINE_THROUGH = 1 << 2,
00317 TEXT_DECORATION_BLINK = 1 << 3
00318 };
00319
00320 enum WhiteSpace {
00321 WHITE_SPACE_NORMAL,
00322 WHITE_SPACE_PRE,
00323 WHITE_SPACE_NOWRAP,
00324 WHITE_SPACE_PRE_WRAP,
00325 WHITE_SPACE_PRE_LINE,
00326 };
00327
00366 typedef int Length;
00367
00369 inline Length createAbsLength(int n) { return (n << 2) | 1; }
00370
00372 inline Length createPerLength(double v) {
00373 return ((int)(v * (1 << 18)) & ~3) | 2; }
00374
00376 inline Length createRelLength(double v) {
00377 return ((int)(v * (1 << 18)) & ~3) | 3; }
00378
00380 inline bool isAbsLength(Length l) { return (l & 3) == 1; }
00381
00383 inline bool isPerLength(Length l) { return (l & 3) == 2; }
00384
00386 inline bool isRelLength(Length l) { return (l & 3) == 3; }
00387
00389 inline int absLengthVal(Length l) { return l >> 2; }
00390
00392 inline double perLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
00393
00395 inline double relLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
00396
00397 enum {
00399 LENGTH_AUTO = 0
00400 };
00401
00408 class Box
00409 {
00410 public:
00411
00412 int top, right, bottom, left;
00413
00414 inline void setVal(int val) { top = right = bottom = left = val; }
00415 inline bool equals (Box *other) {
00416 return top == other->top &&
00417 right == other->right &&
00418 bottom == other->bottom &&
00419 left == other->left;
00420 }
00421 inline int hashValue () {
00422 return top + right + bottom + left;
00423 }
00424 };
00425
00426 class Font;
00427 class Color;
00428 class Tooltip;
00429
00433 class StyleAttrs : public lout::object::Object
00434 {
00435 public:
00436 Font *font;
00437 int textDecoration;
00438
00439 Color *color, *backgroundColor;
00440
00441 TextAlignType textAlign;
00442 VAlignType valign;
00443 char textAlignChar;
00444
00445 int hBorderSpacing, vBorderSpacing, wordSpacing;
00446 Length width, height, lineHeight, textIndent;
00447
00448 Box margin, borderWidth, padding;
00449 BorderCollapse borderCollapse;
00450 struct { Color *top, *right, *bottom, *left; } borderColor;
00451 struct { BorderStyle top, right, bottom, left; } borderStyle;
00452
00453 DisplayType display;
00454 WhiteSpace whiteSpace;
00455 ListStylePosition listStylePosition;
00456 ListStyleType listStyleType;
00457 Cursor cursor;
00458
00459 int x_link;
00460 int x_img;
00461 Tooltip *x_tooltip;
00462
00463 void initValues ();
00464 void resetValues ();
00465
00466 bool sizeDiffs (StyleAttrs *otherStyleAttrs);
00467
00468 inline void setBorderColor(Color *val) {
00469 borderColor.top = borderColor.right = borderColor.bottom
00470 = borderColor.left = val; }
00471 inline void setBorderStyle(BorderStyle val) {
00472 borderStyle.top = borderStyle.right = borderStyle.bottom
00473 = borderStyle.left = val; }
00474
00475 inline int boxOffsetX ()
00476 {
00477 return margin.left + borderWidth.left + padding.left;
00478 }
00479 inline int boxRestWidth ()
00480 {
00481 return margin.right + borderWidth.right + padding.right;
00482 }
00483 inline int boxDiffWidth () { return boxOffsetX () + boxRestWidth (); }
00484 inline int boxOffsetY ()
00485 {
00486 return margin.top + borderWidth.top + padding.top;
00487 }
00488 inline int boxRestHeight ()
00489 {
00490 return margin.bottom + borderWidth.bottom + padding.bottom;
00491 }
00492 inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); }
00493
00494 inline bool hasBackground () { return backgroundColor != NULL; }
00495
00496 bool equals (lout::object::Object *other);
00497 int hashValue ();
00498 };
00499
00500
00504 class Style: public StyleAttrs
00505 {
00506 private:
00507 static int totalRef;
00508 int refCount;
00509 static lout::container::typed::HashTable <StyleAttrs, Style> *styleTable;
00510
00511 Style (StyleAttrs *attrs);
00512
00513 protected:
00514 ~Style();
00515
00516 void copyAttrs (StyleAttrs *attrs);
00517
00518 public:
00519 inline static Style *create (Layout *layout, StyleAttrs *attrs)
00520 {
00521 Style *style = styleTable->get (attrs);
00522 if (style) {
00523 style->ref ();
00524 } else {
00525 style = new Style (attrs);
00526 styleTable->put(style, style);
00527 }
00528 return style;
00529 }
00530
00531 inline void ref () { refCount++; }
00532 inline void unref () { if (--refCount == 0) delete this; }
00533 };
00534
00535
00539 class TooltipAttrs: public lout::object::String
00540 {
00541 public:
00542 TooltipAttrs(const char *text): lout::object::String(text) { }
00543 };
00544
00548 class Tooltip: public TooltipAttrs
00549 {
00550 private:
00551 int refCount;
00552
00553 protected:
00554 Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; }
00555
00556 public:
00557 static Tooltip *create (dw::core::Layout *layout, const char *text);
00558 inline void ref () { refCount++; }
00559 inline void unref ()
00560 { if (--refCount == 0) delete this; }
00561
00562 inline virtual void onEnter () { }
00563 inline virtual void onLeave () { }
00564 inline virtual void onMotion () { }
00565 };
00566
00567
00571 class FontAttrs: public lout::object::Object
00572 {
00573 public:
00574 const char *name;
00575 int size;
00576 int weight;
00577 int letterSpacing;
00578 FontVariant fontVariant;
00579 FontStyle style;
00580
00581 bool equals(lout::object::Object *other);
00582 int hashValue();
00583 };
00584
00585
00589 class Font: public FontAttrs
00590 {
00591 private:
00592 int refCount;
00593
00594 static Font *create0 (Layout *layout, FontAttrs *attrs, bool tryEverything);
00595
00596 protected:
00597 inline Font () { refCount = 0; }
00598 virtual ~Font ();
00599
00600 void copyAttrs (FontAttrs *attrs);
00601
00602 public:
00603 int ascent, descent;
00604 int spaceWidth;
00605 int xHeight;
00606
00607 static Font *create (Layout *layout, FontAttrs *attrs);
00608 static bool exists (Layout *layout, const char *name);
00609
00610 inline void ref () { refCount++; }
00611 inline void unref () { if (--refCount == 0) delete this; }
00612 };
00613
00614
00618 class ColorAttrs: public lout::object::Object
00619 {
00620 protected:
00621 int color;
00622
00623 public:
00624 inline ColorAttrs(int color)
00625 {
00626 this->color = color;
00627 }
00628
00629 inline int getColor () { return color; }
00630
00631 bool equals(lout::object::Object *other);
00632 int hashValue();
00633 };
00634
00635
00639 class Color: public ColorAttrs
00640 {
00641 private:
00642 int refCount;
00643
00644 void remove(dw::core::Layout *layout);
00645 int shadeColor (int color, int d);
00646
00647 protected:
00648 inline Color (int color): ColorAttrs (color) {
00649 refCount = 0; }
00650 virtual ~Color ();
00651
00652 public:
00653 enum Shading { SHADING_NORMAL, SHADING_INVERSE, SHADING_DARK, SHADING_LIGHT,
00654 SHADING_NUM };
00655
00656 protected:
00657 int shadeColor (int color, Shading shading);
00658
00659 public:
00660 static Color *create (Layout *layout, int color);
00661
00662 inline void ref () { refCount++; }
00663 inline void unref ()
00664 { if (--refCount == 0) delete this; }
00665 };
00666
00667 void drawBorder (View *view, Rectangle *area,
00668 int x, int y, int width, int height,
00669 Style *style, bool inverse);
00670 void drawBackground (View *view, Rectangle *area,
00671 int x, int y, int width, int height,
00672 Style *style, bool inverse);
00673 void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType);
00674
00675 }
00676 }
00677 }
00678
00679 #endif // __DW_STYLE_HH__
00680