OLD | NEW |
| (Empty) |
1 // Copyright 2006-2009 Google Inc. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 // you may not use this file except in compliance with the License. | |
5 // You may obtain a copy of the License at | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 // ======================================================================== | |
15 // | |
16 // static_ex.h : This class extends static control functionality to display | |
17 // formatted text and hyper-links | |
18 // | |
19 // Currently it supports the following formatting options: | |
20 // bold - <b>bold</b> | |
21 // italic - <i>italic</i> | |
22 // underscore - <u>underlined</u> | |
23 // color - <color=ff0000>red</color> | |
24 // size - <size=14>14 points text</size> | |
25 // hyperlink - <a=http://www.google.com>click here</a> | |
26 // formatting options could be nested (except hyperlink) | |
27 // | |
28 // Some fonts (including Tahoma) often overhang one pixel (for example in "W") | |
29 // so StaticEx is created with default 1 pixel margin on the left and right, | |
30 // use set_margins() to overwrite default values if you need to. | |
31 | |
32 | |
33 #ifndef OMAHA_UI_UILIB_STATIC_EX_H_ | |
34 #define OMAHA_UI_UILIB_STATIC_EX_H_ | |
35 | |
36 #include <windows.h> | |
37 #include <atlbase.h> | |
38 #include <atlwin.h> | |
39 #include <string> | |
40 #include <vector> | |
41 #include "omaha/ui/uilib/node.h" | |
42 #include "omaha/ui/uilib/static_line.h" | |
43 | |
44 | |
45 // Windows control notification codes are all negative, so any positive number | |
46 // should do here. http://goo.gl/NPaBF. | |
47 const UINT NM_STATICEX = NM_FIRST + 0x400; | |
48 | |
49 // extension of NMHDR to provide StaticEx specific info in notification message | |
50 struct NMSTATICEX { | |
51 NMHDR header; | |
52 const TCHAR* action; | |
53 }; | |
54 | |
55 class StaticEx : public CWindowImpl<StaticEx> { | |
56 public: | |
57 DECLARE_WND_SUPERCLASS(NULL, _T("STATIC")) | |
58 | |
59 StaticEx(); | |
60 virtual ~StaticEx(); | |
61 | |
62 void set_margins(const RECT& rect); | |
63 void set_margins(int left, int top, int right, int bottom); | |
64 RECT margins() const { return margins_; } | |
65 | |
66 void set_background_color(COLORREF back_color); | |
67 COLORREF background_color() const { return background_color_; } | |
68 void ResetBackgroundColor() { use_background_color_ = false; } | |
69 | |
70 // set ellipsis style (DT_END_ELLIPSIS | DT_WORD_ELLIPSIS |DT_PATH_ELLIPSIS) | |
71 // elipsis are supported only in a single line control, calling this function | |
72 // with not 0 argument will set control style to SS_LEFTNOWORDWRAP | |
73 void set_ellipsis(int ellipsis); | |
74 int ellipsis() const { return ellipsis_; } | |
75 | |
76 static const int kBorderNone; | |
77 static const int kBorderLeft; | |
78 static const int kBorderTop; | |
79 static const int kBorderRight; | |
80 static const int kBorderBottom; | |
81 static const int kBorderAll; | |
82 | |
83 // use constants above to set border, you can combine them using "|" | |
84 void set_border(int border); | |
85 int border() const { return border_; } | |
86 | |
87 void set_border_color(COLORREF border_color); | |
88 COLORREF border_color() const { return border_color_; } | |
89 | |
90 // this function doesn't change how control is shown | |
91 // it just calculates minimum control height to fit the text given | |
92 // the control width. if width is 0 it will use current control width | |
93 int GetMinimumHeight(int width); | |
94 | |
95 BEGIN_MSG_MAP(StaticEx) | |
96 MESSAGE_HANDLER(WM_SETTEXT, OnSetText) | |
97 MESSAGE_HANDLER(kGetTextMessage, OnGetText) | |
98 MESSAGE_HANDLER(kGetTextLengthMessage, OnGetTextLength) | |
99 MESSAGE_HANDLER(WM_PAINT, OnPaint) | |
100 MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) | |
101 MESSAGE_HANDLER(WM_LBUTTONUP, OnLButtonUp) | |
102 MESSAGE_HANDLER(WM_SETCURSOR, OnSetCursor) | |
103 END_MSG_MAP() | |
104 | |
105 LRESULT OnSetText(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
106 // OnGetText and OnGetTextLength work with full text including formatting tags | |
107 // to get readable text (without formatting info) call GetWindowText or | |
108 // send WM_GETTEXT | |
109 LRESULT OnGetText(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
110 LRESULT OnGetTextLength(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled)
; // NOLINT | |
111 | |
112 LRESULT OnPaint(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
113 LRESULT OnEraseBkgnd(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
114 LRESULT OnLButtonUp(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
115 LRESULT OnSetCursor(UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled);
// NOLINT | |
116 | |
117 BOOL SubclassWindow(HWND hWnd); | |
118 HWND UnsubclassWindow(BOOL bForce = FALSE); | |
119 | |
120 private: | |
121 void Reset(); | |
122 void ParseText(); | |
123 CString GetReadableText(); | |
124 int FindOpenBracket(const TCHAR* string); | |
125 void EraseNodes(); | |
126 void EraseLines(std::vector<StaticLine*>* lines); | |
127 HFONT default_font() const { return default_font_; } | |
128 | |
129 void PrePaint(HDC dc, std::vector<StaticLine*>* lines, | |
130 const std::vector<Node*>& nodes, RECT rect, DWORD style, | |
131 int ellipsis); | |
132 void Paint(HDC hdc, const std::vector<StaticLine*>& lines, RECT rect, | |
133 DWORD style, int ellipsis); | |
134 void DrawBorder(HDC hdc, const CRect& rect); | |
135 HCURSOR GetHandCursor(); | |
136 | |
137 CString text_; | |
138 | |
139 CRect margins_; | |
140 COLORREF background_color_; | |
141 bool use_background_color_; | |
142 int ellipsis_; | |
143 int border_; | |
144 COLORREF border_color_; | |
145 | |
146 std::vector<Node*> nodes_; | |
147 std::vector<StaticLine*> lines_; | |
148 | |
149 HFONT default_font_; | |
150 | |
151 static HCURSOR hand_cursor_; | |
152 | |
153 static const UINT kGetTextMessage = WM_APP + 1; | |
154 static const UINT kGetTextLengthMessage = WM_APP + 2; | |
155 | |
156 DISALLOW_EVIL_CONSTRUCTORS(StaticEx); | |
157 }; | |
158 | |
159 #endif // OMAHA_UI_UILIB_STATIC_EX_H_ | |
OLD | NEW |