Diffstat (limited to 'noncore/apps/opie-reader/StyleConsts.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/apps/opie-reader/StyleConsts.h | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/noncore/apps/opie-reader/StyleConsts.h b/noncore/apps/opie-reader/StyleConsts.h new file mode 100644 index 0000000..b6dd861 --- a/dev/null +++ b/noncore/apps/opie-reader/StyleConsts.h | |||
@@ -0,0 +1,113 @@ | |||
1 | #ifndef __STYLECONSTS_H | ||
2 | #define __STYLECONSTS_H | ||
3 | |||
4 | typedef unsigned short StyleType; | ||
5 | |||
6 | class CStyle | ||
7 | { | ||
8 | // 15 14 13-5 4 3 2 1 0 | ||
9 | //bold italic spare align align fs fs fs | ||
10 | static const StyleType m_Bold = 1 << 15; | ||
11 | static const StyleType m_Italic = 1 << 14; | ||
12 | static const StyleType m_FontMask = 7; | ||
13 | static const StyleType m_FontBase = 3; | ||
14 | |||
15 | static const StyleType m_AlignShift = 3; | ||
16 | static const StyleType m_AlignMask = 3 << m_AlignShift; | ||
17 | static const StyleType m_EveryBit = 0xffff; | ||
18 | |||
19 | |||
20 | StyleType sty; | ||
21 | |||
22 | void unjustify() { sty &= m_EveryBit ^ m_AlignMask; } | ||
23 | unsigned char red, green, blue; | ||
24 | unsigned long data; | ||
25 | bool isLink; | ||
26 | public: | ||
27 | unsigned char Red() { return red; } | ||
28 | unsigned char Green() { return green; } | ||
29 | unsigned char Blue() { return blue; } | ||
30 | void setColour(unsigned char r, unsigned char g, unsigned char b) | ||
31 | { | ||
32 | red = r; | ||
33 | green = g; | ||
34 | blue = b; | ||
35 | } | ||
36 | static const StyleType m_AlignLeft = 0; | ||
37 | static const StyleType m_AlignRight = 1 << m_AlignShift; | ||
38 | static const StyleType m_AlignCentre = 2 << m_AlignShift; | ||
39 | static const StyleType m_AlignJustify = 3 << m_AlignShift; | ||
40 | CStyle() | ||
41 | : | ||
42 | sty(m_FontBase), | ||
43 | red(0), green(0), blue(0), | ||
44 | data(0), isLink(false) | ||
45 | {} | ||
46 | // CStyle(const int _fs) : sty(m_FontBase+_fs) {} | ||
47 | |||
48 | void unset() | ||
49 | { | ||
50 | sty = m_FontBase; | ||
51 | red = green = blue = 0; | ||
52 | data = 0; | ||
53 | isLink = false; | ||
54 | } | ||
55 | |||
56 | void setBold() { sty |= m_Bold; } | ||
57 | void setItalic() { sty |= m_Italic; } | ||
58 | void unsetBold() { sty &= m_EveryBit ^ m_Bold; } | ||
59 | void unsetItalic() { sty &= m_EveryBit ^ m_Italic; } | ||
60 | bool isBold() { return ((sty & m_Bold) != 0); } | ||
61 | bool isItalic() { return ((sty & m_Italic) != 0); } | ||
62 | |||
63 | void setLeftJustify() | ||
64 | { | ||
65 | unjustify(); | ||
66 | sty |= m_AlignLeft; | ||
67 | } | ||
68 | void setRightJustify() | ||
69 | { | ||
70 | unjustify(); | ||
71 | sty |= m_AlignRight; | ||
72 | } | ||
73 | void setCentreJustify() | ||
74 | { | ||
75 | unjustify(); | ||
76 | sty |= m_AlignCentre; | ||
77 | } | ||
78 | void setFullJustify() | ||
79 | { | ||
80 | unjustify(); | ||
81 | sty |= m_AlignJustify; | ||
82 | } | ||
83 | StyleType getJustify() | ||
84 | { | ||
85 | return sty & m_AlignMask; | ||
86 | } | ||
87 | |||
88 | void setFontSize(int _fs) | ||
89 | { | ||
90 | sty &= m_EveryBit ^ m_FontMask; | ||
91 | sty |= m_FontBase + _fs; | ||
92 | } | ||
93 | int getFontSize() | ||
94 | { | ||
95 | return (sty & m_FontMask) - m_FontBase; | ||
96 | } | ||
97 | bool operator!=(const CStyle& rhs) | ||
98 | { | ||
99 | return | ||
100 | ( | ||
101 | (sty != rhs.sty) || (red != rhs.red) || (green != rhs.green) || | ||
102 | (blue != rhs.blue) || | ||
103 | (data != rhs.data) || | ||
104 | (isLink != rhs.isLink) | ||
105 | ); | ||
106 | } | ||
107 | void setLink(bool _l) { isLink = _l; } | ||
108 | bool getLink() { return isLink; } | ||
109 | void setData(unsigned long _d) { data = _d; } | ||
110 | unsigned long getData() { return data; } | ||
111 | }; | ||
112 | |||
113 | #endif | ||