OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "xfa/fwl/core/ifwl_edit.h" | 7 #include "xfa/fwl/core/ifwl_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <memory> | 10 #include <memory> |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 85 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
86 ShowCaret(false); | 86 ShowCaret(false); |
87 | 87 |
88 ClearRecord(); | 88 ClearRecord(); |
89 } | 89 } |
90 | 90 |
91 FWL_Type IFWL_Edit::GetClassID() const { | 91 FWL_Type IFWL_Edit::GetClassID() const { |
92 return FWL_Type::Edit; | 92 return FWL_Type::Edit; |
93 } | 93 } |
94 | 94 |
95 FWL_Error IFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 95 void IFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
96 if (bAutoSize) { | 96 if (bAutoSize) { |
97 rect.Set(0, 0, 0, 0); | 97 rect.Set(0, 0, 0, 0); |
98 if (m_pEdtEngine) { | 98 if (m_pEdtEngine) { |
99 int32_t iTextLen = m_pEdtEngine->GetTextLength(); | 99 int32_t iTextLen = m_pEdtEngine->GetTextLength(); |
100 if (iTextLen > 0) { | 100 if (iTextLen > 0) { |
101 CFX_WideString wsText; | 101 CFX_WideString wsText; |
102 m_pEdtEngine->GetText(wsText, 0); | 102 m_pEdtEngine->GetText(wsText, 0); |
103 CFX_SizeF sz = CalcTextSize( | 103 CFX_SizeF sz = CalcTextSize( |
104 wsText, m_pProperties->m_pThemeProvider, | 104 wsText, m_pProperties->m_pThemeProvider, |
105 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); | 105 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); |
(...skipping 11 matching lines...) Expand all Loading... |
117 rect.width += kEditMargin; | 117 rect.width += kEditMargin; |
118 } | 118 } |
119 if (IsShowScrollBar(false)) { | 119 if (IsShowScrollBar(false)) { |
120 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 120 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
121 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 121 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
122 rect.height += *pfWidth; | 122 rect.height += *pfWidth; |
123 rect.height += kEditMargin; | 123 rect.height += kEditMargin; |
124 } | 124 } |
125 } | 125 } |
126 } | 126 } |
127 return FWL_Error::Succeeded; | |
128 } | 127 } |
129 | 128 |
130 void IFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { | 129 void IFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { |
131 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || | 130 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || |
132 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 131 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
133 ShowCaret(false); | 132 ShowCaret(false); |
134 } | 133 } |
135 IFWL_Widget::SetStates(dwStates, bSet); | 134 IFWL_Widget::SetStates(dwStates, bSet); |
136 } | 135 } |
137 | 136 |
138 FWL_Error IFWL_Edit::SetWidgetRect(const CFX_RectF& rect) { | 137 void IFWL_Edit::Update() { |
139 return IFWL_Widget::SetWidgetRect(rect); | |
140 } | |
141 FWL_Error IFWL_Edit::Update() { | |
142 if (IsLocked()) { | 138 if (IsLocked()) { |
143 return FWL_Error::Indefinite; | 139 return; |
144 } | 140 } |
145 if (!m_pProperties->m_pThemeProvider) { | 141 if (!m_pProperties->m_pThemeProvider) { |
146 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 142 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
147 } | 143 } |
148 Layout(); | 144 Layout(); |
149 if (m_rtClient.IsEmpty()) { | 145 if (m_rtClient.IsEmpty()) { |
150 return FWL_Error::Indefinite; | 146 return; |
151 } | 147 } |
152 UpdateEditEngine(); | 148 UpdateEditEngine(); |
153 UpdateVAlignment(); | 149 UpdateVAlignment(); |
154 UpdateScroll(); | 150 UpdateScroll(); |
155 InitCaret(); | 151 InitCaret(); |
156 return FWL_Error::Succeeded; | |
157 } | 152 } |
158 | 153 |
159 FWL_WidgetHit IFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 154 FWL_WidgetHit IFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
160 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 155 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
161 if (IsShowScrollBar(true)) { | 156 if (IsShowScrollBar(true)) { |
162 CFX_RectF rect; | 157 CFX_RectF rect; |
163 m_pVertScrollBar->GetWidgetRect(rect); | 158 m_pVertScrollBar->GetWidgetRect(rect); |
164 if (rect.Contains(fx, fy)) | 159 if (rect.Contains(fx, fy)) |
165 return FWL_WidgetHit::VScrollBar; | 160 return FWL_WidgetHit::VScrollBar; |
166 } | 161 } |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 pMatrix->TransformRect(rtClip); | 310 pMatrix->TransformRect(rtClip); |
316 mt.Concat(*pMatrix); | 311 mt.Concat(*pMatrix); |
317 } | 312 } |
318 pGraphics->SetClipRect(rtClip); | 313 pGraphics->SetClipRect(rtClip); |
319 pGraphics->SetStrokeColor(&crLine); | 314 pGraphics->SetStrokeColor(&crLine); |
320 pGraphics->SetLineWidth(0); | 315 pGraphics->SetLineWidth(0); |
321 pGraphics->StrokePath(&pathSpell, nullptr); | 316 pGraphics->StrokePath(&pathSpell, nullptr); |
322 } | 317 } |
323 pGraphics->RestoreGraphState(); | 318 pGraphics->RestoreGraphState(); |
324 } | 319 } |
325 FWL_Error IFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, | 320 void IFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { |
326 const CFX_Matrix* pMatrix) { | |
327 if (!pGraphics) | 321 if (!pGraphics) |
328 return FWL_Error::Indefinite; | 322 return; |
329 if (!m_pProperties->m_pThemeProvider) | 323 if (!m_pProperties->m_pThemeProvider) |
330 return FWL_Error::Indefinite; | 324 return; |
331 if (m_rtClient.IsEmpty()) { | 325 if (m_rtClient.IsEmpty()) { |
332 return FWL_Error::Indefinite; | 326 return; |
333 } | 327 } |
334 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 328 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
335 if (!m_pWidgetMgr->IsFormDisabled()) { | 329 if (!m_pWidgetMgr->IsFormDisabled()) { |
336 DrawTextBk(pGraphics, pTheme, pMatrix); | 330 DrawTextBk(pGraphics, pTheme, pMatrix); |
337 } | 331 } |
338 if (m_pEdtEngine) { | 332 if (m_pEdtEngine) { |
339 DrawContent(pGraphics, pTheme, pMatrix); | 333 DrawContent(pGraphics, pTheme, pMatrix); |
340 } | 334 } |
341 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && | 335 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && |
342 !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { | 336 !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { |
343 DrawSpellCheck(pGraphics, pMatrix); | 337 DrawSpellCheck(pGraphics, pMatrix); |
344 } | 338 } |
345 if (HasBorder()) { | 339 if (HasBorder()) { |
346 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 340 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
347 } | 341 } |
348 if (HasEdge()) { | 342 if (HasEdge()) { |
349 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 343 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
350 } | 344 } |
351 return FWL_Error::Succeeded; | |
352 } | 345 } |
353 FWL_Error IFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | 346 void IFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
354 if (!pThemeProvider) | 347 if (!pThemeProvider) |
355 return FWL_Error::Indefinite; | 348 return; |
356 if (m_pHorzScrollBar) { | 349 if (m_pHorzScrollBar) { |
357 m_pHorzScrollBar->SetThemeProvider(pThemeProvider); | 350 m_pHorzScrollBar->SetThemeProvider(pThemeProvider); |
358 } | 351 } |
359 if (m_pVertScrollBar) { | 352 if (m_pVertScrollBar) { |
360 m_pVertScrollBar->SetThemeProvider(pThemeProvider); | 353 m_pVertScrollBar->SetThemeProvider(pThemeProvider); |
361 } | 354 } |
362 if (m_pCaret) { | 355 if (m_pCaret) { |
363 m_pCaret->SetThemeProvider(pThemeProvider); | 356 m_pCaret->SetThemeProvider(pThemeProvider); |
364 } | 357 } |
365 m_pProperties->m_pThemeProvider = pThemeProvider; | 358 m_pProperties->m_pThemeProvider = pThemeProvider; |
366 return FWL_Error::Succeeded; | |
367 } | 359 } |
368 | 360 |
369 FWL_Error IFWL_Edit::SetText(const CFX_WideString& wsText) { | 361 FWL_Error IFWL_Edit::SetText(const CFX_WideString& wsText) { |
370 m_pEdtEngine->SetText(wsText); | 362 m_pEdtEngine->SetText(wsText); |
371 return FWL_Error::Succeeded; | 363 return FWL_Error::Succeeded; |
372 } | 364 } |
373 | 365 |
374 int32_t IFWL_Edit::GetTextLength() const { | 366 int32_t IFWL_Edit::GetTextLength() const { |
375 if (!m_pEdtEngine) | 367 if (!m_pEdtEngine) |
376 return -1; | 368 return -1; |
(...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1995 UpdateCaret(); | 1987 UpdateCaret(); |
1996 } | 1988 } |
1997 CFX_RectF rect; | 1989 CFX_RectF rect; |
1998 GetWidgetRect(rect); | 1990 GetWidgetRect(rect); |
1999 CFX_RectF rtInvalidate; | 1991 CFX_RectF rtInvalidate; |
2000 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 1992 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
2001 Repaint(&rtInvalidate); | 1993 Repaint(&rtInvalidate); |
2002 } | 1994 } |
2003 return true; | 1995 return true; |
2004 } | 1996 } |
OLD | NEW |