Dillo
style.hh
Go to the documentation of this file.
1 #ifndef __DW_STYLE_HH__
2 #define __DW_STYLE_HH__
3 
4 #include <stdint.h>
5 
6 #ifndef __INCLUDED_FROM_DW_CORE_HH__
7 # error Do not include this file directly, use "core.hh" instead.
8 #endif
9 
10 namespace dw {
11 namespace core {
12 
193 namespace style {
194 
195 enum Cursor {
211 };
212 
216 };
217 
229 };
230 
237 };
238 
248 };
249 
255 };
256 
272 };
273 
274 enum LineType {
278 };
279 
283 };
284 
307 };
308 
309 enum FontStyle {
313 };
314 
318 };
319 
326 };
327 
334 };
335 
374 typedef int Length;
375 
377 inline Length createAbsLength(int n) { return (n << 2) | 1; }
378 
380 inline Length createPerLength(double v) {
381  return ((int)(v * (1 << 18)) & ~3) | 2; }
382 
384 inline Length createRelLength(double v) {
385  return ((int)(v * (1 << 18)) & ~3) | 3; }
386 
388 inline bool isAbsLength(Length l) { return (l & 3) == 1; }
389 
391 inline bool isPerLength(Length l) { return (l & 3) == 2; }
392 
394 inline bool isRelLength(Length l) { return (l & 3) == 3; }
395 
397 inline int absLengthVal(Length l) { return l >> 2; }
398 
400 inline double perLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
401 
403 inline double relLengthVal(Length l) { return (double)(l & ~3) / (1 << 18); }
404 
405 enum {
408 };
409 
416 class Box
417 {
418 public:
419  /* in future also percentages */
421 
422  inline void setVal(int val) { top = right = bottom = left = val; }
423  inline bool equals (Box *other) {
424  return top == other->top &&
425  right == other->right &&
426  bottom == other->bottom &&
427  left == other->left;
428  }
429  inline int hashValue () {
430  return top + right + bottom + left;
431  }
432 };
433 
434 class Font;
435 class Color;
436 class Tooltip;
437 
442 {
443 public:
445  int textDecoration; /* No TextDecoration because of problems converting
446  * TextDecoration <-> int */
448 
451  char textAlignChar; /* In future, strings will be supported. */
453 
456 
459  struct { Color *top, *right, *bottom, *left; } borderColor;
461 
467 
468  int x_link;
469  int x_img;
471  char x_lang[2]; /* Either x_lang[0] == x_lang[1] == 0 (no language
472  set), or x_lang contains the RFC 1766 country
473  code in lower case letters. (Only two letters
474  allowed, currently.) */
475 
476  void initValues ();
477  void resetValues ();
478 
479  bool sizeDiffs (StyleAttrs *otherStyleAttrs);
480 
481  inline void setBorderColor(Color *val) {
482  borderColor.top = borderColor.right = borderColor.bottom
483  = borderColor.left = val; }
484  inline void setBorderStyle(BorderStyle val) {
485  borderStyle.top = borderStyle.right = borderStyle.bottom
486  = borderStyle.left = val; }
487 
488  inline int boxOffsetX ()
489  {
490  return margin.left + borderWidth.left + padding.left;
491  }
492  inline int boxRestWidth ()
493  {
495  }
496  inline int boxDiffWidth () { return boxOffsetX () + boxRestWidth (); }
497  inline int boxOffsetY ()
498  {
499  return margin.top + borderWidth.top + padding.top;
500  }
501  inline int boxRestHeight ()
502  {
504  }
505  inline int boxDiffHeight () { return boxOffsetY () + boxRestHeight (); }
506 
507  inline bool hasBackground () { return backgroundColor != NULL; }
508 
509  bool equals (lout::object::Object *other);
510  int hashValue ();
511 };
512 
513 
517 class Style: public StyleAttrs
518 {
519 private:
520  static int totalRef;
521  int refCount;
523 
524  Style (StyleAttrs *attrs);
525 
526 protected:
527  ~Style();
528 
529  void copyAttrs (StyleAttrs *attrs);
530 
531 public:
532  inline static Style *create (Layout *layout, StyleAttrs *attrs)
533  {
534  Style *style = styleTable->get (attrs);
535  if (style) {
536  style->ref ();
537  } else {
538  style = new Style (attrs);
539  styleTable->put(style, style);
540  }
541  return style;
542  }
543 
544  inline void ref () { refCount++; }
545  inline void unref () { if (--refCount == 0) delete this; }
546 };
547 
548 
553 {
554 public:
555  TooltipAttrs(const char *text): lout::object::String(text) { }
556 };
557 
561 class Tooltip: public TooltipAttrs
562 {
563 private:
564  int refCount;
565 
566 protected:
567  Tooltip (const char *text): TooltipAttrs(text) { refCount = 0; }
568 
569 public:
570  static Tooltip *create (dw::core::Layout *layout, const char *text);
571  inline void ref () { refCount++; }
572  inline void unref ()
573  { if (--refCount == 0) delete this; }
574 
575  inline virtual void onEnter () { }
576  inline virtual void onLeave () { }
577  inline virtual void onMotion () { }
578 };
579 
580 
585 {
586 public:
587  const char *name;
588  int size;
589  int weight;
593 
594  bool equals(lout::object::Object *other);
595  int hashValue();
596 };
597 
598 
602 class Font: public FontAttrs
603 {
604 private:
605  int refCount;
606 
607  static Font *create0 (Layout *layout, FontAttrs *attrs, bool tryEverything);
608 
609 protected:
610  inline Font () { refCount = 0; }
611  virtual ~Font ();
612 
613  void copyAttrs (FontAttrs *attrs);
614 
615 public:
618  int xHeight;
619 
620  static Font *create (Layout *layout, FontAttrs *attrs);
621  static bool exists (Layout *layout, const char *name);
622 
623  inline void ref () { refCount++; }
624  inline void unref () { if (--refCount == 0) delete this; }
625 };
626 
627 
632 {
633 protected:
634  int color;
635 
636 public:
637  inline ColorAttrs(int color)
638  {
639  this->color = color;
640  }
641 
642  inline int getColor () { return color; }
643 
644  bool equals(lout::object::Object *other);
645  int hashValue();
646 };
647 
648 
652 class Color: public ColorAttrs
653 {
654 private:
655  int refCount;
656 
657  void remove(dw::core::Layout *layout);
658  int shadeColor (int color, int d);
659 
660 protected:
661  inline Color (int color): ColorAttrs (color) {
662  refCount = 0; }
663  virtual ~Color ();
664 
665 public:
668 
669 protected:
670  int shadeColor (int color, Shading shading);
671 
672 public:
673  static Color *create (Layout *layout, int color);
674 
675  inline void ref () { refCount++; }
676  inline void unref ()
677  { if (--refCount == 0) delete this; }
678 };
679 
680 void drawBorder (View *view, Rectangle *area,
681  int x, int y, int width, int height,
682  Style *style, bool inverse);
683 void drawBackground (View *view, Rectangle *area,
684  int x, int y, int width, int height,
685  Style *style, bool inverse);
686 void numtostr (int num, char *buf, int buflen, ListStyleType listStyleType);
687 
688 } // namespace style
689 } // namespace dw
690 } // namespace core
691 
692 #endif // __DW_STYLE_HH__
693