Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: xfa/fwl/basewidget/fwl_tooltipctrlimp.cpp

Issue 2432423002: Merge the CFWL_*Imp classes into the IFWL_* classes. (Closed)
Patch Set: Review feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/basewidget/fwl_tooltipctrlimp.h ('k') | xfa/fwl/basewidget/ifwl_barcode.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fwl/basewidget/fwl_tooltipctrlimp.h"
8
9 #include "xfa/fde/tto/fde_textout.h"
10 #include "xfa/fwl/basewidget/ifwl_tooltip.h"
11 #include "xfa/fwl/core/cfwl_themebackground.h"
12 #include "xfa/fwl/core/cfwl_themepart.h"
13 #include "xfa/fwl/core/cfwl_themetext.h"
14 #include "xfa/fwl/core/fwl_formimp.h"
15 #include "xfa/fwl/core/fwl_noteimp.h"
16 #include "xfa/fwl/core/fwl_widgetimp.h"
17 #include "xfa/fwl/core/ifwl_themeprovider.h"
18 #include "xfa/fwl/theme/cfwl_widgettp.h"
19
20 // static
21 IFWL_ToolTip* IFWL_ToolTip::Create(const CFWL_WidgetImpProperties& properties,
22 IFWL_Widget* pOuter) {
23 IFWL_ToolTip* pToolTip = new IFWL_ToolTip;
24 CFWL_ToolTipImp* pToolTipImpl = new CFWL_ToolTipImp(properties, pOuter);
25 pToolTip->SetImpl(pToolTipImpl);
26 pToolTipImpl->SetInterface(pToolTip);
27 return pToolTip;
28 }
29
30 void IFWL_ToolTip::SetAnchor(const CFX_RectF& rtAnchor) {
31 static_cast<CFWL_ToolTipImp*>(GetImpl())->SetAnchor(rtAnchor);
32 }
33
34 void IFWL_ToolTip::Show() {
35 static_cast<CFWL_ToolTipImp*>(GetImpl())->Show();
36 }
37
38 void IFWL_ToolTip::Hide() {
39 static_cast<CFWL_ToolTipImp*>(GetImpl())->Hide();
40 }
41
42 IFWL_ToolTip::IFWL_ToolTip() {}
43
44 CFWL_ToolTipImp::CFWL_ToolTipImp(const CFWL_WidgetImpProperties& properties,
45 IFWL_Widget* pOuter)
46 : CFWL_FormImp(properties, pOuter),
47 m_bBtnDown(FALSE),
48 m_dwTTOStyles(FDE_TTOSTYLE_SingleLine),
49 m_iTTOAlign(FDE_TTOALIGNMENT_Center),
50 m_pTimerInfoShow(nullptr),
51 m_pTimerInfoHide(nullptr) {
52 m_rtClient.Set(0, 0, 0, 0);
53 m_rtCaption.Set(0, 0, 0, 0);
54 m_rtAnchor.Set(0, 0, 0, 0);
55 m_TimerShow.m_pToolTip = this;
56 m_TimerHide.m_pToolTip = this;
57 }
58
59 CFWL_ToolTipImp::~CFWL_ToolTipImp() {}
60
61 FWL_Error CFWL_ToolTipImp::GetClassName(CFX_WideString& wsClass) const {
62 wsClass = FWL_CLASS_ToolTip;
63 return FWL_Error::Succeeded;
64 }
65
66 FWL_Type CFWL_ToolTipImp::GetClassID() const {
67 return FWL_Type::ToolTip;
68 }
69
70 FWL_Error CFWL_ToolTipImp::Initialize() {
71 m_pProperties->m_dwStyles |= FWL_WGTSTYLE_Popup;
72 m_pProperties->m_dwStyles &= ~FWL_WGTSTYLE_Child;
73 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded)
74 return FWL_Error::Indefinite;
75
76 m_pDelegate = new CFWL_ToolTipImpDelegate(this);
77 return FWL_Error::Succeeded;
78 }
79
80 FWL_Error CFWL_ToolTipImp::Finalize() {
81 delete m_pDelegate;
82 m_pDelegate = nullptr;
83 return CFWL_WidgetImp::Finalize();
84 }
85 FWL_Error CFWL_ToolTipImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
86 if (bAutoSize) {
87 rect.Set(0, 0, 0, 0);
88 if (!m_pProperties->m_pThemeProvider) {
89 m_pProperties->m_pThemeProvider = GetAvailableTheme();
90 }
91 CFX_WideString wsCaption;
92 IFWL_ToolTipDP* pData =
93 static_cast<IFWL_ToolTipDP*>(m_pProperties->m_pDataProvider);
94 if (pData) {
95 pData->GetCaption(m_pInterface, wsCaption);
96 }
97 int32_t iLen = wsCaption.GetLength();
98 if (iLen > 0) {
99 CFX_SizeF sz = CalcTextSize(wsCaption, m_pProperties->m_pThemeProvider);
100 rect.Set(0, 0, sz.x, sz.y);
101 rect.width += 25;
102 rect.height += 16;
103 }
104 CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
105 } else {
106 rect = m_pProperties->m_rtWidget;
107 }
108 return FWL_Error::Succeeded;
109 }
110 FWL_Error CFWL_ToolTipImp::Update() {
111 if (IsLocked()) {
112 return FWL_Error::Indefinite;
113 }
114 if (!m_pProperties->m_pThemeProvider) {
115 m_pProperties->m_pThemeProvider = GetAvailableTheme();
116 }
117 UpdateTextOutStyles();
118 GetClientRect(m_rtClient);
119 m_rtCaption = m_rtClient;
120 return FWL_Error::Succeeded;
121 }
122 FWL_Error CFWL_ToolTipImp::GetClientRect(CFX_RectF& rect) {
123 FX_FLOAT x = 0;
124 FX_FLOAT y = 0;
125 FX_FLOAT t = 0;
126 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
127 if (pTheme) {
128 CFWL_ThemePart part;
129 part.m_pWidget = m_pInterface;
130 x = *static_cast<FX_FLOAT*>(
131 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::CXBorder));
132 y = *static_cast<FX_FLOAT*>(
133 pTheme->GetCapacity(&part, CFWL_WidgetCapacity::CYBorder));
134 }
135 rect = m_pProperties->m_rtWidget;
136 rect.Offset(-rect.left, -rect.top);
137 rect.Deflate(x, t, x, y);
138 return FWL_Error::Succeeded;
139 }
140
141 FWL_Error CFWL_ToolTipImp::DrawWidget(CFX_Graphics* pGraphics,
142 const CFX_Matrix* pMatrix) {
143 if (!pGraphics || !m_pProperties->m_pThemeProvider)
144 return FWL_Error::Indefinite;
145
146 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
147 DrawBkground(pGraphics, pTheme, pMatrix);
148 DrawText(pGraphics, pTheme, pMatrix);
149 return FWL_Error::Succeeded;
150 }
151
152 void CFWL_ToolTipImp::DrawBkground(CFX_Graphics* pGraphics,
153 IFWL_ThemeProvider* pTheme,
154 const CFX_Matrix* pMatrix) {
155 CFWL_ThemeBackground param;
156 param.m_pWidget = m_pInterface;
157 param.m_iPart = CFWL_Part::Background;
158 param.m_dwStates = m_pProperties->m_dwStates;
159 param.m_pGraphics = pGraphics;
160 if (pMatrix) {
161 param.m_matrix.Concat(*pMatrix);
162 }
163 param.m_rtPart = m_rtClient;
164 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
165 param.m_pData = &m_rtCaption;
166 }
167 pTheme->DrawBackground(&param);
168 }
169 void CFWL_ToolTipImp::DrawText(CFX_Graphics* pGraphics,
170 IFWL_ThemeProvider* pTheme,
171 const CFX_Matrix* pMatrix) {
172 if (!m_pProperties->m_pDataProvider)
173 return;
174 CFX_WideString wsCaption;
175 m_pProperties->m_pDataProvider->GetCaption(m_pInterface, wsCaption);
176 if (wsCaption.IsEmpty()) {
177 return;
178 }
179 CFWL_ThemeText param;
180 param.m_pWidget = m_pInterface;
181 param.m_iPart = CFWL_Part::Caption;
182 param.m_dwStates = m_pProperties->m_dwStates;
183 param.m_pGraphics = pGraphics;
184 if (pMatrix) {
185 param.m_matrix.Concat(*pMatrix);
186 }
187 param.m_rtPart = m_rtCaption;
188 param.m_wsText = wsCaption;
189 param.m_dwTTOStyles = m_dwTTOStyles;
190 param.m_iTTOAlign = m_iTTOAlign;
191 pTheme->DrawText(&param);
192 }
193 void CFWL_ToolTipImp::UpdateTextOutStyles() {
194 m_iTTOAlign = FDE_TTOALIGNMENT_Center;
195 m_dwTTOStyles = FDE_TTOSTYLE_SingleLine;
196 if (m_pProperties->m_dwStyleExes & FWL_WGTSTYLE_RTLReading) {
197 m_dwTTOStyles |= FDE_TTOSTYLE_RTL;
198 }
199 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_TTP_Multiline) {
200 m_dwTTOStyles &= ~FDE_TTOSTYLE_SingleLine;
201 }
202 }
203
204 void CFWL_ToolTipImp::SetAnchor(const CFX_RectF& rtAnchor) {
205 m_rtAnchor = rtAnchor;
206 }
207
208 void CFWL_ToolTipImp::Show() {
209 IFWL_ToolTipDP* pData =
210 static_cast<IFWL_ToolTipDP*>(m_pProperties->m_pDataProvider);
211 int32_t nInitDelay = pData->GetInitialDelay(m_pInterface);
212 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible))
213 m_pTimerInfoShow = m_TimerShow.StartTimer(nInitDelay, false);
214 }
215
216 void CFWL_ToolTipImp::Hide() {
217 SetStates(FWL_WGTSTATE_Invisible, TRUE);
218 if (m_pTimerInfoHide) {
219 m_pTimerInfoHide->StopTimer();
220 m_pTimerInfoHide = nullptr;
221 }
222 if (m_pTimerInfoShow) {
223 m_pTimerInfoShow->StopTimer();
224 m_pTimerInfoShow = nullptr;
225 }
226 }
227
228 void CFWL_ToolTipImp::SetStates(uint32_t dwStates, FX_BOOL bSet) {
229 if ((dwStates & FWL_WGTSTATE_Invisible) && !bSet) {
230 IFWL_ToolTipDP* pData =
231 static_cast<IFWL_ToolTipDP*>(m_pProperties->m_pDataProvider);
232 int32_t nAutoPopDelay = pData->GetAutoPopDelay(m_pInterface);
233 m_pTimerInfoHide = m_TimerHide.StartTimer(nAutoPopDelay, false);
234 }
235 CFWL_WidgetImp::SetStates(dwStates, bSet);
236 }
237
238 void CFWL_ToolTipImp::RefreshToolTipPos() {
239 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_TTP_NoAnchor) == 0) {
240 CFX_RectF rtPopup;
241 CFX_RectF rtWidget(m_pProperties->m_rtWidget);
242 CFX_RectF rtAnchor(m_rtAnchor);
243 rtPopup.Set(0, 0, 0, 0);
244 FX_FLOAT fx = rtAnchor.Center().x + 20;
245 FX_FLOAT fy = rtAnchor.Center().y + 20;
246 rtPopup.Set(fx, fy, rtWidget.Width(), rtWidget.Height());
247 FX_FLOAT fScreenWidth = 0;
248 FX_FLOAT fScreenHeight = 0;
249 GetScreenSize(fScreenWidth, fScreenHeight);
250 if (rtPopup.bottom() > fScreenHeight) {
251 rtPopup.Offset(0, fScreenHeight - rtPopup.bottom());
252 }
253 if (rtPopup.right() > fScreenWidth) {
254 rtPopup.Offset(fScreenWidth - rtPopup.right(), 0);
255 }
256 if (rtPopup.left < 0) {
257 rtPopup.Offset(0 - rtPopup.left, 0);
258 }
259 if (rtPopup.top < 0) {
260 rtPopup.Offset(0, 0 - rtPopup.top);
261 }
262 SetWidgetRect(rtPopup);
263 Update();
264 }
265 }
266 CFWL_ToolTipImp::CFWL_ToolTipTimer::CFWL_ToolTipTimer(CFWL_ToolTipImp* pToolTip)
267 : m_pToolTip(pToolTip) {}
268
269 void CFWL_ToolTipImp::CFWL_ToolTipTimer::Run(IFWL_TimerInfo* pTimerInfo) {
270 if (m_pToolTip->m_pTimerInfoShow == pTimerInfo &&
271 m_pToolTip->m_pTimerInfoShow) {
272 if (m_pToolTip->GetStates() & FWL_WGTSTATE_Invisible) {
273 m_pToolTip->SetStates(FWL_WGTSTATE_Invisible, FALSE);
274 m_pToolTip->RefreshToolTipPos();
275 m_pToolTip->m_pTimerInfoShow->StopTimer();
276 m_pToolTip->m_pTimerInfoShow = nullptr;
277 return;
278 }
279 }
280 if (m_pToolTip->m_pTimerInfoHide == pTimerInfo &&
281 m_pToolTip->m_pTimerInfoHide) {
282 m_pToolTip->SetStates(FWL_WGTSTATE_Invisible, TRUE);
283 m_pToolTip->m_pTimerInfoHide->StopTimer();
284 m_pToolTip->m_pTimerInfoHide = nullptr;
285 }
286 }
287
288 CFWL_ToolTipImpDelegate::CFWL_ToolTipImpDelegate(CFWL_ToolTipImp* pOwner)
289 : m_pOwner(pOwner) {}
290
291 void CFWL_ToolTipImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {
292 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage);
293 }
294
295 void CFWL_ToolTipImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {}
296
297 void CFWL_ToolTipImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics,
298 const CFX_Matrix* pMatrix) {
299 m_pOwner->DrawWidget(pGraphics, pMatrix);
300 }
OLDNEW
« no previous file with comments | « xfa/fwl/basewidget/fwl_tooltipctrlimp.h ('k') | xfa/fwl/basewidget/ifwl_barcode.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698