summaryrefslogtreecommitdiff
path: root/dwr/label.hh
blob: 8a069b05360e2d309cdeb7d88b5018e15f72bb74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __DWR_LABEL_HH__
#define __DWR_LABEL_HH__

#include "dwr/hideable.hh"
#include "lout/misc.hh"

namespace rtfl {

namespace dw {

class Label: public Hideable
{
private:
   class LabelIterator: public ::dw::core::Iterator
   {
   private:
      int index;

      LabelIterator (Label *label, ::dw::core::Content::Type mask, int index);

   public:
      LabelIterator (Label *label, ::dw::core::Content::Type mask, bool atEnd);

      lout::object::Object *clone ();
      int compareTo (lout::object::Comparable *other);

      bool next ();
      bool prev ();
      void highlight (int start, int end, ::dw::core::HighlightLayer layer);
      void unhighlight (int direction, ::dw::core::HighlightLayer layer);
      void getAllocation (int start, int end,
                          ::dw::core::Allocation *allocation);
   };

   enum { ITALIC = 2, BOLD = 1 };

   struct Word
   {
      char *text;
      char styleIndex;
      ::dw::core::Requisition size;
   };

   ::dw::core::style::Style *styles[4];
   lout::misc::SimpleVector<Word> *words;
   ::dw::core::Requisition totalSize;
   bool selected, buttonDown;
   int link;
   ::dw::core::Layout::LinkEmitter linkEmitter;

   void clearWords ();
   void clearStyles ();
   void ensureStyles ();
   
protected:
   void sizeRequestImplImpl (::dw::core::Requisition *requisition);
   void getExtremesImplImpl (::dw::core::Extremes *extremes);
   void drawImpl (::dw::core::View *view, ::dw::core::Rectangle *area);

   bool buttonPressImpl (::dw::core::EventButton *event);
   bool buttonReleaseImpl (::dw::core::EventButton *event);
   void leaveNotifyImpl (::dw::core::EventCrossing *event);

public:
   static int CLASS_ID;

   Label (const char *text, int link = -1);
   ~Label ();

   void setText (const char *text);
   inline void setLink (int link) { this->link = link; }

   ::dw::core::Iterator *iterator (::dw::core::Content::Type mask, bool atEnd);
   void setStyle (::dw::core::style::Style *style);

   void select ();
   void unselect ();

   inline void connectLink (::dw::core::Layout::LinkReceiver *receiver)
   { linkEmitter.connectLink (receiver); }
};

} // namespace rtfl

} // namespace dw

#endif // __DWR_LABEL_HH__