Repository navigation
Expand file tree
/
Copy pathUIText.cpp
More file actions
160 lines (144 loc) · 4.16 KB
/
Copy pathUIText.cpp
File metadata and controls
160 lines (144 loc) · 4.16 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "StdAfx.h"
#include "UIText.h"
namespace DuiLib
{
CTextUI::CTextUI() : m_nLinks(0), m_nHoverLink(-1)
{
m_uTextStyle = DT_WORDBREAK;
m_rcTextPadding.left = 2;
m_rcTextPadding.right = 2;
::ZeroMemory(m_rcLinks, sizeof(m_rcLinks));
}
CTextUI::~CTextUI()
{
}
LPCTSTR CTextUI::GetClass() const
{
return _T("TextUI");
}
LPVOID CTextUI::GetInterface(LPCTSTR pstrName)
{
if( _tcscmp(pstrName, DUI_CTR_TEXT) == 0 ) return static_cast<CTextUI*>(this);
return CLabelUI::GetInterface(pstrName);
}
UINT CTextUI::GetControlFlags() const
{
if( IsEnabled() && m_nLinks > 0 ) return UIFLAG_SETCURSOR;
else return 0;
}
CDuiString* CTextUI::GetLinkContent(int iIndex)
{
if( iIndex >= 0 && iIndex < m_nLinks ) return &m_sLinks[iIndex];
return NULL;
}
void CTextUI::DoEvent(TEventUI& event)
{
if( !IsMouseEnabled() && event.Type > UIEVENT__MOUSEBEGIN && event.Type < UIEVENT__MOUSEEND ) {
if( m_pParent != NULL ) m_pParent->DoEvent(event);
else CLabelUI::DoEvent(event);
return;
}
if( event.Type == UIEVENT_SETCURSOR ) {
for( int i = 0; i < m_nLinks; i++ ) {
if( ::PtInRect(&m_rcLinks[i], event.ptMouse) ) {
::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_HAND)));
return;
}
}
}
if( event.Type == UIEVENT_BUTTONDOWN || event.Type == UIEVENT_DBLCLICK && IsEnabled() ) {
for( int i = 0; i < m_nLinks; i++ ) {
if( ::PtInRect(&m_rcLinks[i], event.ptMouse) ) {
Invalidate();
return;
}
}
}
if( event.Type == UIEVENT_BUTTONUP && IsEnabled() ) {
for( int i = 0; i < m_nLinks; i++ ) {
if( ::PtInRect(&m_rcLinks[i], event.ptMouse) ) {
m_pManager->SendNotify(this, DUI_MSGTYPE_LINK, i);
return;
}
}
}
if( event.Type == UIEVENT_CONTEXTMENU )
{
return;
}
// When you move over a link
if( m_nLinks > 0 && event.Type == UIEVENT_MOUSEMOVE && IsEnabled() ) {
int nHoverLink = -1;
for( int i = 0; i < m_nLinks; i++ ) {
if( ::PtInRect(&m_rcLinks[i], event.ptMouse) ) {
nHoverLink = i;
break;
}
}
if(m_nHoverLink != nHoverLink) {
m_nHoverLink = nHoverLink;
Invalidate();
return;
}
}
if( event.Type == UIEVENT_MOUSELEAVE ) {
if( m_nLinks > 0 && IsEnabled() ) {
if(m_nHoverLink != -1) {
m_nHoverLink = -1;
Invalidate();
return;
}
}
}
CLabelUI::DoEvent(event);
}
SIZE CTextUI::EstimateSize(SIZE szAvailable)
{
RECT rcText = { 0, 0, MAX(szAvailable.cx, m_cxyFixed.cx), 9999 };
rcText.left += m_rcTextPadding.left;
rcText.right -= m_rcTextPadding.right;
if( m_bShowHtml ) {
int nLinks = 0;
CRenderEngine::DrawHtmlText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, m_dwTextColor, NULL, NULL, nLinks, DT_CALCRECT | m_uTextStyle);
}
else {
CRenderEngine::DrawText(m_pManager->GetPaintDC(), m_pManager, rcText, m_sText, m_dwTextColor, m_iFont, DT_CALCRECT | m_uTextStyle);
}
SIZE cXY = {rcText.right - rcText.left + m_rcTextPadding.left + m_rcTextPadding.right,
rcText.bottom - rcText.top + m_rcTextPadding.top + m_rcTextPadding.bottom};
if( m_cxyFixed.cy != 0 ) cXY.cy = m_cxyFixed.cy;
return cXY;
}
void CTextUI::PaintText(HDC hDC)
{
if( m_sText.IsEmpty() ) {
m_nLinks = 0;
return;
}
if( m_dwTextColor == 0 ) m_dwTextColor = m_pManager->GetDefaultFontColor();
if( m_dwDisabledTextColor == 0 ) m_dwDisabledTextColor = m_pManager->GetDefaultDisabledColor();
if( m_sText.IsEmpty() ) return;
m_nLinks = lengthof(m_rcLinks);
RECT rc = m_rcItem;
rc.left += m_rcTextPadding.left;
rc.right -= m_rcTextPadding.right;
rc.top += m_rcTextPadding.top;
rc.bottom -= m_rcTextPadding.bottom;
if( IsEnabled() ) {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
m_rcLinks, m_sLinks, m_nLinks, m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwTextColor, \
m_iFont, m_uTextStyle);
}
else {
if( m_bShowHtml )
CRenderEngine::DrawHtmlText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
m_rcLinks, m_sLinks, m_nLinks, m_uTextStyle);
else
CRenderEngine::DrawText(hDC, m_pManager, rc, m_sText, m_dwDisabledTextColor, \
m_iFont, m_uTextStyle);
}
}
}