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 27 matching lines...) Expand all Loading... |
38 c == 0x0027; | 38 c == 0x0027; |
39 } | 39 } |
40 | 40 |
41 void AddSquigglyPath(CFX_Path* pPathData, | 41 void AddSquigglyPath(CFX_Path* pPathData, |
42 FX_FLOAT fStartX, | 42 FX_FLOAT fStartX, |
43 FX_FLOAT fEndX, | 43 FX_FLOAT fEndX, |
44 FX_FLOAT fY, | 44 FX_FLOAT fY, |
45 FX_FLOAT fStep) { | 45 FX_FLOAT fStep) { |
46 pPathData->MoveTo(fStartX, fY); | 46 pPathData->MoveTo(fStartX, fY); |
47 int i = 1; | 47 int i = 1; |
48 for (FX_FLOAT fx = fStartX + fStep; fx < fEndX; fx += fStep, ++i) { | 48 for (FX_FLOAT fx = fStartX + fStep; fx < fEndX; fx += fStep, ++i) |
49 pPathData->LineTo(fx, fY + (i & 1) * fStep); | 49 pPathData->LineTo(fx, fY + (i & 1) * fStep); |
50 } | |
51 } | 50 } |
52 | 51 |
53 } // namespace | 52 } // namespace |
54 | 53 |
55 IFWL_Edit::IFWL_Edit(const IFWL_App* app, | 54 IFWL_Edit::IFWL_Edit(const IFWL_App* app, |
56 std::unique_ptr<CFWL_WidgetProperties> properties, | 55 std::unique_ptr<CFWL_WidgetProperties> properties, |
57 IFWL_Widget* pOuter) | 56 IFWL_Widget* pOuter) |
58 : IFWL_Widget(app, std::move(properties), pOuter), | 57 : IFWL_Widget(app, std::move(properties), pOuter), |
59 m_fVAlignOffset(0.0f), | 58 m_fVAlignOffset(0.0f), |
60 m_fScrollOffsetX(0.0f), | 59 m_fScrollOffsetX(0.0f), |
61 m_fScrollOffsetY(0.0f), | 60 m_fScrollOffsetY(0.0f), |
62 m_bLButtonDown(false), | 61 m_bLButtonDown(false), |
63 m_nSelStart(0), | 62 m_nSelStart(0), |
64 m_nLimit(-1), | 63 m_nLimit(-1), |
65 m_fFontSize(0), | 64 m_fFontSize(0), |
66 m_bSetRange(false), | 65 m_bSetRange(false), |
67 m_iMax(0xFFFFFFF), | 66 m_iMax(0xFFFFFFF), |
68 m_iCurRecord(-1), | 67 m_iCurRecord(-1), |
69 m_iMaxRecord(128) { | 68 m_iMaxRecord(128) { |
70 m_rtClient.Reset(); | 69 m_rtClient.Reset(); |
71 m_rtEngine.Reset(); | 70 m_rtEngine.Reset(); |
72 m_rtStatic.Reset(); | 71 m_rtStatic.Reset(); |
73 | 72 |
74 InitCaret(); | 73 InitCaret(); |
75 } | 74 } |
76 | 75 |
77 IFWL_Edit::~IFWL_Edit() { | 76 IFWL_Edit::~IFWL_Edit() { |
78 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) | 77 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) |
79 ShowCaret(false); | 78 ShowCaret(false); |
80 | |
81 ClearRecord(); | 79 ClearRecord(); |
82 } | 80 } |
83 | 81 |
84 FWL_Type IFWL_Edit::GetClassID() const { | 82 FWL_Type IFWL_Edit::GetClassID() const { |
85 return FWL_Type::Edit; | 83 return FWL_Type::Edit; |
86 } | 84 } |
87 | 85 |
88 void IFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { | 86 void IFWL_Edit::GetWidgetRect(CFX_RectF& rect, bool bAutoSize) { |
89 if (bAutoSize) { | 87 if (!bAutoSize) { |
90 rect.Set(0, 0, 0, 0); | |
91 | |
92 int32_t iTextLen = m_EdtEngine.GetTextLength(); | |
93 if (iTextLen > 0) { | |
94 CFX_WideString wsText; | |
95 m_EdtEngine.GetText(wsText, 0); | |
96 CFX_SizeF sz = CalcTextSize( | |
97 wsText, m_pProperties->m_pThemeProvider, | |
98 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); | |
99 rect.Set(0, 0, sz.x, sz.y); | |
100 } | |
101 IFWL_Widget::GetWidgetRect(rect, true); | |
102 } else { | |
103 rect = m_pProperties->m_rtWidget; | 88 rect = m_pProperties->m_rtWidget; |
104 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 89 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
105 if (IsShowScrollBar(true)) { | 90 if (IsShowScrollBar(true)) { |
106 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 91 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
107 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 92 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
108 rect.width += *pfWidth; | 93 rect.width += *pfWidth; |
109 rect.width += kEditMargin; | 94 rect.width += kEditMargin; |
110 } | 95 } |
111 if (IsShowScrollBar(false)) { | 96 if (IsShowScrollBar(false)) { |
112 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 97 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
113 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 98 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
114 rect.height += *pfWidth; | 99 rect.height += *pfWidth; |
115 rect.height += kEditMargin; | 100 rect.height += kEditMargin; |
116 } | 101 } |
117 } | 102 } |
| 103 return; |
118 } | 104 } |
| 105 |
| 106 rect.Set(0, 0, 0, 0); |
| 107 |
| 108 int32_t iTextLen = m_EdtEngine.GetTextLength(); |
| 109 if (iTextLen > 0) { |
| 110 CFX_WideString wsText; |
| 111 m_EdtEngine.GetText(wsText, 0); |
| 112 CFX_SizeF sz = CalcTextSize( |
| 113 wsText, m_pProperties->m_pThemeProvider, |
| 114 !!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine)); |
| 115 rect.Set(0, 0, sz.x, sz.y); |
| 116 } |
| 117 IFWL_Widget::GetWidgetRect(rect, true); |
119 } | 118 } |
120 | 119 |
121 void IFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { | 120 void IFWL_Edit::SetStates(uint32_t dwStates, bool bSet) { |
122 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || | 121 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) || |
123 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 122 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
124 ShowCaret(false); | 123 ShowCaret(false); |
125 } | 124 } |
126 IFWL_Widget::SetStates(dwStates, bSet); | 125 IFWL_Widget::SetStates(dwStates, bSet); |
127 } | 126 } |
128 | 127 |
129 void IFWL_Edit::Update() { | 128 void IFWL_Edit::Update() { |
130 if (IsLocked()) { | 129 if (IsLocked()) |
131 return; | 130 return; |
132 } | 131 if (!m_pProperties->m_pThemeProvider) |
133 if (!m_pProperties->m_pThemeProvider) { | |
134 m_pProperties->m_pThemeProvider = GetAvailableTheme(); | 132 m_pProperties->m_pThemeProvider = GetAvailableTheme(); |
135 } | 133 |
136 Layout(); | 134 Layout(); |
137 if (m_rtClient.IsEmpty()) { | 135 if (m_rtClient.IsEmpty()) |
138 return; | 136 return; |
139 } | 137 |
140 UpdateEditEngine(); | 138 UpdateEditEngine(); |
141 UpdateVAlignment(); | 139 UpdateVAlignment(); |
142 UpdateScroll(); | 140 UpdateScroll(); |
143 InitCaret(); | 141 InitCaret(); |
144 } | 142 } |
145 | 143 |
146 FWL_WidgetHit IFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { | 144 FWL_WidgetHit IFWL_Edit::HitTest(FX_FLOAT fx, FX_FLOAT fy) { |
147 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 145 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
148 if (IsShowScrollBar(true)) { | 146 if (IsShowScrollBar(true)) { |
149 CFX_RectF rect; | 147 CFX_RectF rect; |
(...skipping 19 matching lines...) Expand all Loading... |
169 FX_FLOAT fOffSetX, | 167 FX_FLOAT fOffSetX, |
170 FX_FLOAT fOffSetY) { | 168 FX_FLOAT fOffSetY) { |
171 FX_FLOAT fStartX = 0.0f; | 169 FX_FLOAT fStartX = 0.0f; |
172 FX_FLOAT fEndX = 0.0f; | 170 FX_FLOAT fEndX = 0.0f; |
173 FX_FLOAT fY = 0.0f; | 171 FX_FLOAT fY = 0.0f; |
174 FX_FLOAT fStep = 0.0f; | 172 FX_FLOAT fStep = 0.0f; |
175 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 173 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
176 CFX_RectFArray rectArray; | 174 CFX_RectFArray rectArray; |
177 CFX_RectF rectText; | 175 CFX_RectF rectText; |
178 const FDE_TXTEDTPARAMS* txtEdtParams = m_EdtEngine.GetEditParams(); | 176 const FDE_TXTEDTPARAMS* txtEdtParams = m_EdtEngine.GetEditParams(); |
179 FX_FLOAT fAsent = (FX_FLOAT)txtEdtParams->pFont->GetAscent() * | 177 FX_FLOAT fAsent = static_cast<FX_FLOAT>(txtEdtParams->pFont->GetAscent()) * |
180 txtEdtParams->fFontSize / 1000; | 178 txtEdtParams->fFontSize / 1000; |
181 pPage->CalcRangeRectArray(nStart, nCount, rectArray); | 179 pPage->CalcRangeRectArray(nStart, nCount, rectArray); |
| 180 |
182 for (int i = 0; i < rectArray.GetSize(); i++) { | 181 for (int i = 0; i < rectArray.GetSize(); i++) { |
183 rectText = rectArray.GetAt(i); | 182 rectText = rectArray.GetAt(i); |
184 fY = rectText.top + fAsent + fOffSetY; | 183 fY = rectText.top + fAsent + fOffSetY; |
185 fStep = txtEdtParams->fFontSize / 16.0f; | 184 fStep = txtEdtParams->fFontSize / 16.0f; |
186 fStartX = rectText.left + fOffSetX; | 185 fStartX = rectText.left + fOffSetX; |
187 fEndX = fStartX + rectText.Width(); | 186 fEndX = fStartX + rectText.Width(); |
188 AddSquigglyPath(&PathData, fStartX, fEndX, fY, fStep); | 187 AddSquigglyPath(&PathData, fStartX, fEndX, fY, fStep); |
189 } | 188 } |
190 } | 189 } |
| 190 |
191 void IFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, | 191 void IFWL_Edit::DrawSpellCheck(CFX_Graphics* pGraphics, |
192 const CFX_Matrix* pMatrix) { | 192 const CFX_Matrix* pMatrix) { |
193 pGraphics->SaveGraphState(); | 193 pGraphics->SaveGraphState(); |
194 if (pMatrix) { | 194 if (pMatrix) |
195 pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix)); | 195 pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix)); |
196 } | 196 |
197 FX_ARGB cr = 0xFFFF0000; | 197 CFX_Color crLine(0xFFFF0000); |
198 CFX_Color crLine(cr); | |
199 CFWL_EvtEdtCheckWord checkWordEvent; | 198 CFWL_EvtEdtCheckWord checkWordEvent; |
200 checkWordEvent.m_pSrcTarget = this; | 199 checkWordEvent.m_pSrcTarget = this; |
| 200 |
201 CFX_ByteString sLatinWord; | 201 CFX_ByteString sLatinWord; |
202 CFX_Path pathSpell; | 202 CFX_Path pathSpell; |
203 pathSpell.Create(); | 203 pathSpell.Create(); |
| 204 |
204 int32_t nStart = 0; | 205 int32_t nStart = 0; |
205 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; | 206 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; |
206 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; | 207 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; |
| 208 |
207 CFX_WideString wsSpell; | 209 CFX_WideString wsSpell; |
208 GetText(wsSpell); | 210 GetText(wsSpell); |
209 int32_t nContentLen = wsSpell.GetLength(); | 211 int32_t nContentLen = wsSpell.GetLength(); |
210 for (int i = 0; i < nContentLen; i++) { | 212 for (int i = 0; i < nContentLen; i++) { |
211 if (FX_EDIT_ISLATINWORD(wsSpell[i])) { | 213 if (FX_EDIT_ISLATINWORD(wsSpell[i])) { |
212 if (sLatinWord.IsEmpty()) { | 214 if (sLatinWord.IsEmpty()) |
213 nStart = i; | 215 nStart = i; |
214 } | |
215 sLatinWord += (FX_CHAR)wsSpell[i]; | 216 sLatinWord += (FX_CHAR)wsSpell[i]; |
216 } else { | 217 continue; |
217 checkWordEvent.bsWord = sLatinWord; | |
218 checkWordEvent.bCheckWord = true; | |
219 DispatchEvent(&checkWordEvent); | |
220 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { | |
221 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, | |
222 fOffSetY); | |
223 } | |
224 sLatinWord.clear(); | |
225 } | 218 } |
| 219 checkWordEvent.bsWord = sLatinWord; |
| 220 checkWordEvent.bCheckWord = true; |
| 221 DispatchEvent(&checkWordEvent); |
| 222 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { |
| 223 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, |
| 224 fOffSetY); |
| 225 } |
| 226 sLatinWord.clear(); |
226 } | 227 } |
| 228 |
227 checkWordEvent.bsWord = sLatinWord; | 229 checkWordEvent.bsWord = sLatinWord; |
228 checkWordEvent.bCheckWord = true; | 230 checkWordEvent.bCheckWord = true; |
229 DispatchEvent(&checkWordEvent); | 231 DispatchEvent(&checkWordEvent); |
| 232 |
230 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { | 233 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) { |
231 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, | 234 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX, |
232 fOffSetY); | 235 fOffSetY); |
233 } | 236 } |
234 if (!pathSpell.IsEmpty()) { | 237 if (!pathSpell.IsEmpty()) { |
235 CFX_RectF rtClip = m_rtEngine; | 238 CFX_RectF rtClip = m_rtEngine; |
236 CFX_Matrix mt; | 239 CFX_Matrix mt; |
237 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); | 240 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); |
238 if (pMatrix) { | 241 if (pMatrix) { |
239 pMatrix->TransformRect(rtClip); | 242 pMatrix->TransformRect(rtClip); |
240 mt.Concat(*pMatrix); | 243 mt.Concat(*pMatrix); |
241 } | 244 } |
242 pGraphics->SetClipRect(rtClip); | 245 pGraphics->SetClipRect(rtClip); |
243 pGraphics->SetStrokeColor(&crLine); | 246 pGraphics->SetStrokeColor(&crLine); |
244 pGraphics->SetLineWidth(0); | 247 pGraphics->SetLineWidth(0); |
245 pGraphics->StrokePath(&pathSpell, nullptr); | 248 pGraphics->StrokePath(&pathSpell, nullptr); |
246 } | 249 } |
247 pGraphics->RestoreGraphState(); | 250 pGraphics->RestoreGraphState(); |
248 } | 251 } |
| 252 |
249 void IFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { | 253 void IFWL_Edit::DrawWidget(CFX_Graphics* pGraphics, const CFX_Matrix* pMatrix) { |
250 if (!pGraphics) | 254 if (!pGraphics) |
251 return; | 255 return; |
252 if (!m_pProperties->m_pThemeProvider) | 256 if (!m_pProperties->m_pThemeProvider) |
253 return; | 257 return; |
254 if (m_rtClient.IsEmpty()) { | 258 if (m_rtClient.IsEmpty()) |
255 return; | 259 return; |
256 } | 260 |
257 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; | 261 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider; |
258 if (!m_pWidgetMgr->IsFormDisabled()) { | 262 if (!m_pWidgetMgr->IsFormDisabled()) |
259 DrawTextBk(pGraphics, pTheme, pMatrix); | 263 DrawTextBk(pGraphics, pTheme, pMatrix); |
260 } | |
261 | |
262 DrawContent(pGraphics, pTheme, pMatrix); | 264 DrawContent(pGraphics, pTheme, pMatrix); |
263 | 265 |
264 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && | 266 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) && |
265 !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { | 267 !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) { |
266 DrawSpellCheck(pGraphics, pMatrix); | 268 DrawSpellCheck(pGraphics, pMatrix); |
267 } | 269 } |
268 if (HasBorder()) { | 270 if (HasBorder()) |
269 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); | 271 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix); |
270 } | 272 if (HasEdge()) |
271 if (HasEdge()) { | |
272 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); | 273 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix); |
273 } | |
274 } | 274 } |
| 275 |
275 void IFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { | 276 void IFWL_Edit::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) { |
276 if (!pThemeProvider) | 277 if (!pThemeProvider) |
277 return; | 278 return; |
278 if (m_pHorzScrollBar) { | 279 if (m_pHorzScrollBar) |
279 m_pHorzScrollBar->SetThemeProvider(pThemeProvider); | 280 m_pHorzScrollBar->SetThemeProvider(pThemeProvider); |
280 } | 281 if (m_pVertScrollBar) |
281 if (m_pVertScrollBar) { | |
282 m_pVertScrollBar->SetThemeProvider(pThemeProvider); | 282 m_pVertScrollBar->SetThemeProvider(pThemeProvider); |
283 } | 283 if (m_pCaret) |
284 if (m_pCaret) { | |
285 m_pCaret->SetThemeProvider(pThemeProvider); | 284 m_pCaret->SetThemeProvider(pThemeProvider); |
286 } | |
287 m_pProperties->m_pThemeProvider = pThemeProvider; | 285 m_pProperties->m_pThemeProvider = pThemeProvider; |
288 } | 286 } |
289 | 287 |
290 void IFWL_Edit::SetText(const CFX_WideString& wsText) { | 288 void IFWL_Edit::SetText(const CFX_WideString& wsText) { |
291 m_EdtEngine.SetText(wsText); | 289 m_EdtEngine.SetText(wsText); |
292 } | 290 } |
293 | 291 |
294 int32_t IFWL_Edit::GetTextLength() const { | 292 int32_t IFWL_Edit::GetTextLength() const { |
295 return m_EdtEngine.GetTextLength(); | 293 return m_EdtEngine.GetTextLength(); |
296 } | 294 } |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
430 rtInvalid.Set(0, 0, 0, 0); | 428 rtInvalid.Set(0, 0, 0, 0); |
431 bool bRepaintScroll = false; | 429 bool bRepaintScroll = false; |
432 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { | 430 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { |
433 IFWL_ScrollBar* pScroll = UpdateScroll(); | 431 IFWL_ScrollBar* pScroll = UpdateScroll(); |
434 if (pScroll) { | 432 if (pScroll) { |
435 pScroll->GetWidgetRect(rtInvalid); | 433 pScroll->GetWidgetRect(rtInvalid); |
436 bRepaintScroll = true; | 434 bRepaintScroll = true; |
437 } | 435 } |
438 } | 436 } |
439 if (bRepaintContent || bRepaintScroll) { | 437 if (bRepaintContent || bRepaintScroll) { |
440 if (bRepaintContent) { | 438 if (bRepaintContent) |
441 rtInvalid.Union(m_rtEngine); | 439 rtInvalid.Union(m_rtEngine); |
442 } | |
443 Repaint(&rtInvalid); | 440 Repaint(&rtInvalid); |
444 } | 441 } |
445 } | 442 } |
446 | 443 |
447 void IFWL_Edit::On_TextChanged(CFDE_TxtEdtEngine* pEdit, | 444 void IFWL_Edit::On_TextChanged(CFDE_TxtEdtEngine* pEdit, |
448 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { | 445 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) { |
449 uint32_t dwStyleEx = m_pProperties->m_dwStyleExes; | 446 uint32_t dwStyleEx = m_pProperties->m_dwStyleExes; |
450 if (dwStyleEx & FWL_STYLEEXT_EDT_VAlignMask) | 447 if (dwStyleEx & FWL_STYLEEXT_EDT_VAlignMask) |
451 UpdateVAlignment(); | 448 UpdateVAlignment(); |
452 | 449 |
(...skipping 22 matching lines...) Expand all Loading... |
475 ModifyStylesEx( | 472 ModifyStylesEx( |
476 0, FWL_STYLEEXT_EDT_HSelfAdaption | FWL_STYLEEXT_EDT_AutoHScroll); | 473 0, FWL_STYLEEXT_EDT_HSelfAdaption | FWL_STYLEEXT_EDT_AutoHScroll); |
477 } | 474 } |
478 if (!evt.bVSelfAdaption) { | 475 if (!evt.bVSelfAdaption) { |
479 ModifyStylesEx( | 476 ModifyStylesEx( |
480 0, FWL_STYLEEXT_EDT_VSelfAdaption | FWL_STYLEEXT_EDT_AutoVScroll); | 477 0, FWL_STYLEEXT_EDT_VSelfAdaption | FWL_STYLEEXT_EDT_AutoVScroll); |
481 } | 478 } |
482 bNeedUpdate = (bHSelfAdaption && !evt.bHSelfAdaption) || | 479 bNeedUpdate = (bHSelfAdaption && !evt.bHSelfAdaption) || |
483 (bVSelfAdaption && !evt.bVSelfAdaption); | 480 (bVSelfAdaption && !evt.bVSelfAdaption); |
484 } | 481 } |
| 482 |
485 FX_FLOAT fContentWidth1 = fContentWidth; | 483 FX_FLOAT fContentWidth1 = fContentWidth; |
486 FX_FLOAT fContentHeight1 = fContentHeight; | 484 FX_FLOAT fContentHeight1 = fContentHeight; |
487 if (bNeedUpdate) { | 485 if (bNeedUpdate) { |
488 UpdateEditParams(); | 486 UpdateEditParams(); |
489 UpdateEditLayout(); | 487 UpdateEditLayout(); |
490 IFDE_TxtEdtPage* page1 = m_EdtEngine.GetPage(0); | 488 IFDE_TxtEdtPage* page1 = m_EdtEngine.GetPage(0); |
491 fContentWidth1 = page1->GetContentsBox().width; | 489 fContentWidth1 = page1->GetContentsBox().width; |
492 fContentHeight1 = page1->GetContentsBox().height; | 490 fContentHeight1 = page1->GetContentsBox().height; |
493 } | 491 } |
494 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption) { | 492 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption) { |
495 rtTemp.width = std::max(m_pProperties->m_rtWidget.width, fContentWidth1); | 493 rtTemp.width = std::max(m_pProperties->m_rtWidget.width, fContentWidth1); |
496 m_pProperties->m_rtWidget.width = fContentWidth1; | 494 m_pProperties->m_rtWidget.width = fContentWidth1; |
497 } | 495 } |
498 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption) { | 496 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption) { |
499 rtTemp.height = std::max(m_pProperties->m_rtWidget.height, fContentHeight1); | 497 rtTemp.height = std::max(m_pProperties->m_rtWidget.height, fContentHeight1); |
500 m_pProperties->m_rtWidget.height = fContentHeight1; | 498 m_pProperties->m_rtWidget.height = fContentHeight1; |
501 } | 499 } |
| 500 |
502 CFWL_EvtEdtTextChanged event; | 501 CFWL_EvtEdtTextChanged event; |
503 event.m_pSrcTarget = this; | 502 event.m_pSrcTarget = this; |
504 event.nChangeType = ChangeInfo.nChangeType; | 503 event.nChangeType = ChangeInfo.nChangeType; |
505 event.wsInsert = ChangeInfo.wsInsert; | 504 event.wsInsert = ChangeInfo.wsInsert; |
506 event.wsDelete = ChangeInfo.wsDelete; | 505 event.wsDelete = ChangeInfo.wsDelete; |
507 event.wsPrevText = ChangeInfo.wsPrevText; | 506 event.wsPrevText = ChangeInfo.wsPrevText; |
508 DispatchEvent(&event); | 507 DispatchEvent(&event); |
509 LayoutScrollBar(); | 508 LayoutScrollBar(); |
510 Repaint(&rtTemp); | 509 Repaint(&rtTemp); |
511 } | 510 } |
512 | 511 |
513 void IFWL_Edit::On_SelChanged(CFDE_TxtEdtEngine* pEdit) { | 512 void IFWL_Edit::On_SelChanged(CFDE_TxtEdtEngine* pEdit) { |
514 CFX_RectF rtTemp; | 513 CFX_RectF rtTemp; |
515 GetClientRect(rtTemp); | 514 GetClientRect(rtTemp); |
516 Repaint(&rtTemp); | 515 Repaint(&rtTemp); |
517 } | 516 } |
518 | 517 |
519 bool IFWL_Edit::On_PageLoad(CFDE_TxtEdtEngine* pEdit, | 518 bool IFWL_Edit::On_PageLoad(CFDE_TxtEdtEngine* pEdit, |
520 int32_t nPageIndex, | 519 int32_t nPageIndex, |
521 int32_t nPurpose) { | 520 int32_t nPurpose) { |
522 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); | 521 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); |
523 if (!pPage) | 522 if (!pPage) |
524 return false; | 523 return false; |
| 524 |
525 pPage->LoadPage(nullptr, nullptr); | 525 pPage->LoadPage(nullptr, nullptr); |
526 return true; | 526 return true; |
527 } | 527 } |
528 | 528 |
529 bool IFWL_Edit::On_PageUnload(CFDE_TxtEdtEngine* pEdit, | 529 bool IFWL_Edit::On_PageUnload(CFDE_TxtEdtEngine* pEdit, |
530 int32_t nPageIndex, | 530 int32_t nPageIndex, |
531 int32_t nPurpose) { | 531 int32_t nPurpose) { |
532 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); | 532 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(nPageIndex); |
533 if (!pPage) | 533 if (!pPage) |
534 return false; | 534 return false; |
| 535 |
535 pPage->UnloadPage(nullptr); | 536 pPage->UnloadPage(nullptr); |
536 return true; | 537 return true; |
537 } | 538 } |
538 | 539 |
539 void IFWL_Edit::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, | 540 void IFWL_Edit::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit, |
540 IFDE_TxtEdtDoRecord* pRecord) { | 541 IFDE_TxtEdtDoRecord* pRecord) { |
541 AddDoRecord(pRecord); | 542 AddDoRecord(pRecord); |
542 } | 543 } |
543 | 544 |
544 bool IFWL_Edit::On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText) { | 545 bool IFWL_Edit::On_Validate(CFDE_TxtEdtEngine* pEdit, CFX_WideString& wsText) { |
545 IFWL_Widget* pDst = GetOuter(); | 546 IFWL_Widget* pDst = GetOuter(); |
546 if (!pDst) { | 547 if (!pDst) |
547 pDst = this; | 548 pDst = this; |
548 } | 549 |
549 CFWL_EvtEdtValidate event; | 550 CFWL_EvtEdtValidate event; |
550 event.pDstWidget = pDst; | 551 event.pDstWidget = pDst; |
551 event.m_pSrcTarget = this; | 552 event.m_pSrcTarget = this; |
552 event.wsInsert = wsText; | 553 event.wsInsert = wsText; |
553 event.bValidate = true; | 554 event.bValidate = true; |
554 DispatchEvent(&event); | 555 DispatchEvent(&event); |
555 return event.bValidate; | 556 return event.bValidate; |
556 } | 557 } |
557 | 558 |
558 void IFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { | 559 void IFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) { |
559 m_fScrollOffsetY = fScrollOffset; | 560 m_fScrollOffsetY = fScrollOffset; |
560 } | 561 } |
561 | 562 |
562 void IFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, | 563 void IFWL_Edit::DrawTextBk(CFX_Graphics* pGraphics, |
563 IFWL_ThemeProvider* pTheme, | 564 IFWL_ThemeProvider* pTheme, |
564 const CFX_Matrix* pMatrix) { | 565 const CFX_Matrix* pMatrix) { |
565 CFWL_ThemeBackground param; | 566 CFWL_ThemeBackground param; |
566 param.m_pWidget = this; | 567 param.m_pWidget = this; |
567 param.m_iPart = CFWL_Part::Background; | 568 param.m_iPart = CFWL_Part::Background; |
568 param.m_bStaticBackground = false; | 569 param.m_bStaticBackground = false; |
569 param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly | 570 param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly |
570 ? CFWL_PartState_ReadOnly | 571 ? CFWL_PartState_ReadOnly |
571 : CFWL_PartState_Normal; | 572 : CFWL_PartState_Normal; |
572 uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); | 573 uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled); |
573 if (dwStates) { | 574 if (dwStates) |
574 param.m_dwStates = CFWL_PartState_Disabled; | 575 param.m_dwStates = CFWL_PartState_Disabled; |
575 } | |
576 param.m_pGraphics = pGraphics; | 576 param.m_pGraphics = pGraphics; |
577 param.m_matrix = *pMatrix; | 577 param.m_matrix = *pMatrix; |
578 param.m_rtPart = m_rtClient; | 578 param.m_rtPart = m_rtClient; |
579 pTheme->DrawBackground(¶m); | 579 pTheme->DrawBackground(¶m); |
580 if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) { | 580 |
| 581 if (!IsShowScrollBar(true) || !IsShowScrollBar(false)) |
581 return; | 582 return; |
582 } | 583 |
583 CFX_RectF rtScorll; | 584 CFX_RectF rtScorll; |
584 m_pHorzScrollBar->GetWidgetRect(rtScorll); | 585 m_pHorzScrollBar->GetWidgetRect(rtScorll); |
| 586 |
585 CFX_RectF rtStatic; | 587 CFX_RectF rtStatic; |
586 rtStatic.Set(m_rtClient.right() - rtScorll.height, | 588 rtStatic.Set(m_rtClient.right() - rtScorll.height, |
587 m_rtClient.bottom() - rtScorll.height, rtScorll.height, | 589 m_rtClient.bottom() - rtScorll.height, rtScorll.height, |
588 rtScorll.height); | 590 rtScorll.height); |
589 param.m_bStaticBackground = true; | 591 param.m_bStaticBackground = true; |
590 param.m_bMaximize = true; | 592 param.m_bMaximize = true; |
591 param.m_rtPart = rtStatic; | 593 param.m_rtPart = rtStatic; |
592 pTheme->DrawBackground(¶m); | 594 pTheme->DrawBackground(¶m); |
593 } | 595 } |
| 596 |
594 void IFWL_Edit::DrawContent(CFX_Graphics* pGraphics, | 597 void IFWL_Edit::DrawContent(CFX_Graphics* pGraphics, |
595 IFWL_ThemeProvider* pTheme, | 598 IFWL_ThemeProvider* pTheme, |
596 const CFX_Matrix* pMatrix) { | 599 const CFX_Matrix* pMatrix) { |
597 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 600 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
598 if (!pPage) | 601 if (!pPage) |
599 return; | 602 return; |
| 603 |
600 pGraphics->SaveGraphState(); | 604 pGraphics->SaveGraphState(); |
601 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { | 605 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) |
602 pGraphics->SaveGraphState(); | 606 pGraphics->SaveGraphState(); |
603 } | 607 |
604 CFX_RectF rtClip = m_rtEngine; | 608 CFX_RectF rtClip = m_rtEngine; |
605 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; | 609 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX; |
606 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; | 610 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset; |
607 CFX_Matrix mt; | 611 CFX_Matrix mt; |
608 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); | 612 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY); |
609 if (pMatrix) { | 613 if (pMatrix) { |
610 pMatrix->TransformRect(rtClip); | 614 pMatrix->TransformRect(rtClip); |
611 mt.Concat(*pMatrix); | 615 mt.Concat(*pMatrix); |
612 } | 616 } |
| 617 |
613 bool bShowSel = (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoHideSel) || | 618 bool bShowSel = (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoHideSel) || |
614 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); | 619 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused); |
615 if (bShowSel) { | 620 if (bShowSel) { |
616 IFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(this); | 621 IFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(this); |
617 if (pForm) { | 622 if (pForm) { |
618 bShowSel = (pForm->GetStates() & FWL_WGTSTATE_Deactivated) != | 623 bShowSel = (pForm->GetStates() & FWL_WGTSTATE_Deactivated) != |
619 FWL_WGTSTATE_Deactivated; | 624 FWL_WGTSTATE_Deactivated; |
620 } | 625 } |
621 } | 626 } |
| 627 |
622 int32_t nSelCount = m_EdtEngine.CountSelRanges(); | 628 int32_t nSelCount = m_EdtEngine.CountSelRanges(); |
623 if (bShowSel && nSelCount > 0) { | 629 if (bShowSel && nSelCount > 0) { |
624 int32_t nPageCharStart = pPage->GetCharStart(); | 630 int32_t nPageCharStart = pPage->GetCharStart(); |
625 int32_t nPageCharCount = pPage->GetCharCount(); | 631 int32_t nPageCharCount = pPage->GetCharCount(); |
626 int32_t nPageCharEnd = nPageCharStart + nPageCharCount - 1; | 632 int32_t nPageCharEnd = nPageCharStart + nPageCharCount - 1; |
627 int32_t nCharCount; | 633 int32_t nCharCount; |
628 int32_t nCharStart; | 634 int32_t nCharStart; |
629 CFX_RectFArray rectArr; | 635 CFX_RectFArray rectArr; |
630 int32_t i = 0; | 636 int32_t i = 0; |
631 for (i = 0; i < nSelCount; i++) { | 637 for (i = 0; i < nSelCount; i++) { |
632 nCharCount = m_EdtEngine.GetSelRange(i, nCharStart); | 638 nCharCount = m_EdtEngine.GetSelRange(i, nCharStart); |
633 int32_t nCharEnd = nCharStart + nCharCount - 1; | 639 int32_t nCharEnd = nCharStart + nCharCount - 1; |
634 if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) { | 640 if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) |
635 continue; | 641 continue; |
636 } | 642 |
637 int32_t nBgn = std::max(nCharStart, nPageCharStart); | 643 int32_t nBgn = std::max(nCharStart, nPageCharStart); |
638 int32_t nEnd = std::min(nCharEnd, nPageCharEnd); | 644 int32_t nEnd = std::min(nCharEnd, nPageCharEnd); |
639 pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1, | 645 pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1, |
640 rectArr); | 646 rectArr); |
641 } | 647 } |
| 648 |
642 int32_t nCount = rectArr.GetSize(); | 649 int32_t nCount = rectArr.GetSize(); |
643 CFX_Path path; | 650 CFX_Path path; |
644 path.Create(); | 651 path.Create(); |
645 for (i = 0; i < nCount; i++) { | 652 for (i = 0; i < nCount; i++) { |
646 rectArr[i].left += fOffSetX; | 653 rectArr[i].left += fOffSetX; |
647 rectArr[i].top += fOffSetY; | 654 rectArr[i].top += fOffSetY; |
648 path.AddRectangle(rectArr[i].left, rectArr[i].top, rectArr[i].width, | 655 path.AddRectangle(rectArr[i].left, rectArr[i].top, rectArr[i].width, |
649 rectArr[i].height); | 656 rectArr[i].height); |
650 } | 657 } |
651 pGraphics->SetClipRect(rtClip); | 658 pGraphics->SetClipRect(rtClip); |
| 659 |
652 CFWL_ThemeBackground param; | 660 CFWL_ThemeBackground param; |
653 param.m_pGraphics = pGraphics; | 661 param.m_pGraphics = pGraphics; |
654 param.m_matrix = *pMatrix; | 662 param.m_matrix = *pMatrix; |
655 param.m_pWidget = this; | 663 param.m_pWidget = this; |
656 param.m_iPart = CFWL_Part::Background; | 664 param.m_iPart = CFWL_Part::Background; |
657 param.m_pPath = &path; | 665 param.m_pPath = &path; |
658 pTheme->DrawBackground(¶m); | 666 pTheme->DrawBackground(¶m); |
659 } | 667 } |
| 668 |
660 CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice(); | 669 CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice(); |
661 if (!pRenderDev) | 670 if (!pRenderDev) |
662 return; | 671 return; |
663 | 672 |
664 std::unique_ptr<CFDE_RenderDevice> pRenderDevice( | 673 std::unique_ptr<CFDE_RenderDevice> pRenderDevice( |
665 new CFDE_RenderDevice(pRenderDev, false)); | 674 new CFDE_RenderDevice(pRenderDev, false)); |
666 std::unique_ptr<CFDE_RenderContext> pRenderContext(new CFDE_RenderContext); | 675 std::unique_ptr<CFDE_RenderContext> pRenderContext(new CFDE_RenderContext); |
667 pRenderDevice->SetClipRect(rtClip); | 676 pRenderDevice->SetClipRect(rtClip); |
668 pRenderContext->StartRender(pRenderDevice.get(), pPage, mt); | 677 pRenderContext->StartRender(pRenderDevice.get(), pPage, mt); |
669 pRenderContext->DoRender(nullptr); | 678 pRenderContext->DoRender(nullptr); |
| 679 |
670 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { | 680 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { |
671 pGraphics->RestoreGraphState(); | 681 pGraphics->RestoreGraphState(); |
672 CFX_Path path; | 682 CFX_Path path; |
673 path.Create(); | 683 path.Create(); |
674 int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1; | 684 int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1; |
675 FX_FLOAT fStep = m_rtEngine.width / iLimit; | 685 FX_FLOAT fStep = m_rtEngine.width / iLimit; |
676 FX_FLOAT fLeft = m_rtEngine.left + 1; | 686 FX_FLOAT fLeft = m_rtEngine.left + 1; |
677 for (int32_t i = 1; i < iLimit; i++) { | 687 for (int32_t i = 1; i < iLimit; i++) { |
678 fLeft += fStep; | 688 fLeft += fStep; |
679 path.AddLine(fLeft, m_rtClient.top, fLeft, m_rtClient.bottom()); | 689 path.AddLine(fLeft, m_rtClient.top, fLeft, m_rtClient.bottom()); |
680 } | 690 } |
| 691 |
681 CFWL_ThemeBackground param; | 692 CFWL_ThemeBackground param; |
682 param.m_pGraphics = pGraphics; | 693 param.m_pGraphics = pGraphics; |
683 param.m_matrix = *pMatrix; | 694 param.m_matrix = *pMatrix; |
684 param.m_pWidget = this; | 695 param.m_pWidget = this; |
685 param.m_iPart = CFWL_Part::CombTextLine; | 696 param.m_iPart = CFWL_Part::CombTextLine; |
686 param.m_pPath = &path; | 697 param.m_pPath = &path; |
687 pTheme->DrawBackground(¶m); | 698 pTheme->DrawBackground(¶m); |
688 } | 699 } |
689 pGraphics->RestoreGraphState(); | 700 pGraphics->RestoreGraphState(); |
690 } | 701 } |
691 | 702 |
692 void IFWL_Edit::UpdateEditEngine() { | 703 void IFWL_Edit::UpdateEditEngine() { |
693 UpdateEditParams(); | 704 UpdateEditParams(); |
694 UpdateEditLayout(); | 705 UpdateEditLayout(); |
695 if (m_nLimit > -1) { | 706 if (m_nLimit > -1) |
696 m_EdtEngine.SetLimit(m_nLimit); | 707 m_EdtEngine.SetLimit(m_nLimit); |
697 } | |
698 } | 708 } |
| 709 |
699 void IFWL_Edit::UpdateEditParams() { | 710 void IFWL_Edit::UpdateEditParams() { |
700 FDE_TXTEDTPARAMS params; | 711 FDE_TXTEDTPARAMS params; |
701 params.nHorzScale = 100; | 712 params.nHorzScale = 100; |
702 params.fPlateWidth = m_rtEngine.width; | 713 params.fPlateWidth = m_rtEngine.width; |
703 params.fPlateHeight = m_rtEngine.height; | 714 params.fPlateHeight = m_rtEngine.height; |
704 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_RTLLayout) { | 715 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_RTLLayout) |
705 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_RTL; | 716 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_RTL; |
706 } | 717 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalLayout) |
707 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalLayout) { | |
708 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_DocVertical; | 718 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_DocVertical; |
709 } | 719 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalChars) |
710 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalChars) { | |
711 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CharVertial; | 720 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CharVertial; |
712 } | 721 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReverseLine) |
713 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReverseLine) { | |
714 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LineReserve; | 722 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LineReserve; |
715 } | 723 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ArabicShapes) |
716 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ArabicShapes) { | |
717 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ArabicShapes; | 724 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ArabicShapes; |
718 } | 725 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ExpandTab) |
719 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ExpandTab) { | |
720 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ExpandTab; | 726 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ExpandTab; |
721 } | 727 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) |
722 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) { | |
723 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CombText; | 728 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CombText; |
724 } | 729 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_LastLineHeight) |
725 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_LastLineHeight) { | |
726 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LastLineHeight; | 730 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LastLineHeight; |
727 } | 731 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate) |
728 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate) { | |
729 params.dwMode |= FDE_TEXTEDITMODE_Validate; | 732 params.dwMode |= FDE_TEXTEDITMODE_Validate; |
730 } | 733 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password) |
731 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password) { | |
732 params.dwMode |= FDE_TEXTEDITMODE_Password; | 734 params.dwMode |= FDE_TEXTEDITMODE_Password; |
733 } | 735 |
734 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) { | 736 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) { |
735 case FWL_STYLEEXT_EDT_HNear: { | 737 case FWL_STYLEEXT_EDT_HNear: { |
736 params.dwAlignment |= FDE_TEXTEDITALIGN_Left; | 738 params.dwAlignment |= FDE_TEXTEDITALIGN_Left; |
737 break; | 739 break; |
738 } | 740 } |
739 case FWL_STYLEEXT_EDT_HCenter: { | 741 case FWL_STYLEEXT_EDT_HCenter: { |
740 params.dwAlignment |= FDE_TEXTEDITALIGN_Center; | 742 params.dwAlignment |= FDE_TEXTEDITALIGN_Center; |
741 break; | 743 break; |
742 } | 744 } |
743 case FWL_STYLEEXT_EDT_HFar: { | 745 case FWL_STYLEEXT_EDT_HFar: { |
744 params.dwAlignment |= FDE_TEXTEDITALIGN_Right; | 746 params.dwAlignment |= FDE_TEXTEDITALIGN_Right; |
745 break; | 747 break; |
746 } | 748 } |
747 default: {} | 749 default: |
| 750 break; |
748 } | 751 } |
749 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) { | 752 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) { |
750 case FWL_STYLEEXT_EDT_Justified: { | 753 case FWL_STYLEEXT_EDT_Justified: { |
751 params.dwAlignment |= FDE_TEXTEDITALIGN_Justified; | 754 params.dwAlignment |= FDE_TEXTEDITALIGN_Justified; |
752 break; | 755 break; |
753 } | 756 } |
754 case FWL_STYLEEXT_EDT_Distributed: { | 757 case FWL_STYLEEXT_EDT_Distributed: { |
755 params.dwAlignment |= FDE_TEXTEDITALIGN_Distributed; | 758 params.dwAlignment |= FDE_TEXTEDITALIGN_Distributed; |
756 break; | 759 break; |
757 } | 760 } |
758 default: { params.dwAlignment |= FDE_TEXTEDITALIGN_Normal; } | 761 default: { |
| 762 params.dwAlignment |= FDE_TEXTEDITALIGN_Normal; |
| 763 break; |
| 764 } |
759 } | 765 } |
760 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { | 766 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) { |
761 params.dwMode |= FDE_TEXTEDITMODE_MultiLines; | 767 params.dwMode |= FDE_TEXTEDITMODE_MultiLines; |
762 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) == 0 && | 768 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) == 0 && |
763 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) { | 769 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) { |
764 params.dwMode |= | 770 params.dwMode |= |
765 FDE_TEXTEDITMODE_AutoLineWrap | FDE_TEXTEDITMODE_LimitArea_Horz; | 771 FDE_TEXTEDITMODE_AutoLineWrap | FDE_TEXTEDITMODE_LimitArea_Horz; |
766 } | 772 } |
767 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 && | 773 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 && |
768 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0) { | 774 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0) { |
769 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Vert; | 775 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Vert; |
770 } else { | 776 } else { |
771 params.fPlateHeight = 0x00FFFFFF; | 777 params.fPlateHeight = 0x00FFFFFF; |
772 } | 778 } |
773 } else { | 779 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == |
774 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) { | 780 0) { |
775 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Horz; | 781 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Horz; |
776 } | |
777 } | 782 } |
778 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || | 783 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || |
779 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 784 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
780 params.dwMode |= FDE_TEXTEDITMODE_ReadOnly; | 785 params.dwMode |= FDE_TEXTEDITMODE_ReadOnly; |
781 } | 786 } |
| 787 |
782 FX_FLOAT* pFontSize = | 788 FX_FLOAT* pFontSize = |
783 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); | 789 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize)); |
784 if (!pFontSize) | 790 if (!pFontSize) |
785 return; | 791 return; |
| 792 |
786 m_fFontSize = *pFontSize; | 793 m_fFontSize = *pFontSize; |
787 uint32_t* pFontColor = | 794 uint32_t* pFontColor = |
788 static_cast<uint32_t*>(GetThemeCapacity(CFWL_WidgetCapacity::TextColor)); | 795 static_cast<uint32_t*>(GetThemeCapacity(CFWL_WidgetCapacity::TextColor)); |
789 if (!pFontColor) | 796 if (!pFontColor) |
790 return; | 797 return; |
| 798 |
791 params.dwFontColor = *pFontColor; | 799 params.dwFontColor = *pFontColor; |
792 FX_FLOAT* pLineHeight = | 800 FX_FLOAT* pLineHeight = |
793 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::LineHeight)); | 801 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::LineHeight)); |
794 if (!pLineHeight) | 802 if (!pLineHeight) |
795 return; | 803 return; |
| 804 |
796 params.fLineSpace = *pLineHeight; | 805 params.fLineSpace = *pLineHeight; |
797 CFGAS_GEFont* pFont = | 806 CFGAS_GEFont* pFont = |
798 static_cast<CFGAS_GEFont*>(GetThemeCapacity(CFWL_WidgetCapacity::Font)); | 807 static_cast<CFGAS_GEFont*>(GetThemeCapacity(CFWL_WidgetCapacity::Font)); |
799 if (!pFont) | 808 if (!pFont) |
800 return; | 809 return; |
| 810 |
801 params.pFont = pFont; | 811 params.pFont = pFont; |
802 params.fFontSize = m_fFontSize; | 812 params.fFontSize = m_fFontSize; |
803 params.nLineCount = (int32_t)(params.fPlateHeight / params.fLineSpace); | 813 params.nLineCount = (int32_t)(params.fPlateHeight / params.fLineSpace); |
804 if (params.nLineCount <= 0) { | 814 if (params.nLineCount <= 0) |
805 params.nLineCount = 1; | 815 params.nLineCount = 1; |
806 } | |
807 params.fTabWidth = params.fFontSize * 1; | 816 params.fTabWidth = params.fFontSize * 1; |
808 params.bTabEquidistant = true; | 817 params.bTabEquidistant = true; |
809 params.wLineBreakChar = L'\n'; | 818 params.wLineBreakChar = L'\n'; |
810 params.nCharRotation = 0; | 819 params.nCharRotation = 0; |
811 params.pEventSink = this; | 820 params.pEventSink = this; |
812 m_EdtEngine.SetEditParams(params); | 821 m_EdtEngine.SetEditParams(params); |
813 } | 822 } |
814 | 823 |
815 void IFWL_Edit::UpdateEditLayout() { | 824 void IFWL_Edit::UpdateEditLayout() { |
816 if (m_EdtEngine.GetTextLength() <= 0) | 825 if (m_EdtEngine.GetTextLength() <= 0) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 m_fScrollOffsetX += fPosChanged; | 886 m_fScrollOffsetX += fPosChanged; |
878 else | 887 else |
879 m_fScrollOffsetY += fPosChanged; | 888 m_fScrollOffsetY += fPosChanged; |
880 return true; | 889 return true; |
881 } | 890 } |
882 | 891 |
883 void IFWL_Edit::UpdateVAlignment() { | 892 void IFWL_Edit::UpdateVAlignment() { |
884 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 893 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
885 if (!pPage) | 894 if (!pPage) |
886 return; | 895 return; |
| 896 |
887 const CFX_RectF& rtFDE = pPage->GetContentsBox(); | 897 const CFX_RectF& rtFDE = pPage->GetContentsBox(); |
888 FX_FLOAT fOffsetY = 0.0f; | 898 FX_FLOAT fOffsetY = 0.0f; |
889 FX_FLOAT fSpaceAbove = 0.0f; | 899 FX_FLOAT fSpaceAbove = 0.0f; |
890 FX_FLOAT fSpaceBelow = 0.0f; | 900 FX_FLOAT fSpaceBelow = 0.0f; |
891 CFX_SizeF* pSpace = static_cast<CFX_SizeF*>( | 901 CFX_SizeF* pSpace = static_cast<CFX_SizeF*>( |
892 GetThemeCapacity(CFWL_WidgetCapacity::SpaceAboveBelow)); | 902 GetThemeCapacity(CFWL_WidgetCapacity::SpaceAboveBelow)); |
893 if (pSpace) { | 903 if (pSpace) { |
894 fSpaceAbove = pSpace->x; | 904 fSpaceAbove = pSpace->x; |
895 fSpaceBelow = pSpace->y; | 905 fSpaceBelow = pSpace->y; |
896 } | 906 } |
897 if (fSpaceAbove < 0.1f) { | 907 if (fSpaceAbove < 0.1f) |
898 fSpaceAbove = 0; | 908 fSpaceAbove = 0; |
899 } | 909 if (fSpaceBelow < 0.1f) |
900 if (fSpaceBelow < 0.1f) { | |
901 fSpaceBelow = 0; | 910 fSpaceBelow = 0; |
902 } | 911 |
903 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) { | 912 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) { |
904 fOffsetY = (m_rtEngine.height - rtFDE.height) / 2; | 913 fOffsetY = (m_rtEngine.height - rtFDE.height) / 2; |
905 if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2 && | 914 if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2 && |
906 fSpaceAbove < fSpaceBelow) { | 915 fSpaceAbove < fSpaceBelow) { |
907 return; | 916 return; |
908 } | 917 } |
909 fOffsetY += (fSpaceAbove - fSpaceBelow) / 2; | 918 fOffsetY += (fSpaceAbove - fSpaceBelow) / 2; |
910 } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) { | 919 } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) { |
911 fOffsetY = (m_rtEngine.height - rtFDE.height); | 920 fOffsetY = (m_rtEngine.height - rtFDE.height); |
912 fOffsetY -= fSpaceBelow; | 921 fOffsetY -= fSpaceBelow; |
913 } else { | 922 } else { |
914 fOffsetY += fSpaceAbove; | 923 fOffsetY += fSpaceAbove; |
915 } | 924 } |
916 m_fVAlignOffset = fOffsetY; | 925 m_fVAlignOffset = std::max(fOffsetY, 0.0f); |
917 if (m_fVAlignOffset < 0) { | |
918 m_fVAlignOffset = 0; | |
919 } | |
920 } | 926 } |
| 927 |
921 void IFWL_Edit::UpdateCaret() { | 928 void IFWL_Edit::UpdateCaret() { |
922 CFX_RectF rtFDE; | 929 CFX_RectF rtFDE; |
923 m_EdtEngine.GetCaretRect(rtFDE); | 930 m_EdtEngine.GetCaretRect(rtFDE); |
| 931 |
924 rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, | 932 rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX, |
925 m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); | 933 m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset); |
926 CFX_RectF rtCaret; | 934 CFX_RectF rtCaret; |
927 rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); | 935 rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height); |
| 936 |
928 CFX_RectF temp = rtCaret; | 937 CFX_RectF temp = rtCaret; |
929 CFX_RectF rtClient; | 938 CFX_RectF rtClient; |
930 GetClientRect(rtClient); | 939 GetClientRect(rtClient); |
931 rtCaret.Intersect(rtClient); | 940 rtCaret.Intersect(rtClient); |
| 941 |
932 if (rtCaret.left > rtClient.right()) { | 942 if (rtCaret.left > rtClient.right()) { |
933 FX_FLOAT right = rtCaret.right(); | 943 FX_FLOAT right = rtCaret.right(); |
934 rtCaret.left = rtClient.right() - 1; | 944 rtCaret.left = rtClient.right() - 1; |
935 rtCaret.width = right - rtCaret.left; | 945 rtCaret.width = right - rtCaret.left; |
936 } | 946 } |
937 bool bIntersect = !rtCaret.IsEmpty(); | 947 |
938 bool bShow = true; | 948 bool bShow = true; |
939 bool bShowWhole = false; | 949 bool bShowWhole = false; |
940 if (!(m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) || !bIntersect) { | 950 if (!(m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) || rtCaret.IsEmpty()) |
941 bShow = false; | 951 bShow = false; |
942 } | |
943 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption && | 952 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption && |
944 temp.right() > m_rtEngine.right()) { | 953 temp.right() > m_rtEngine.right()) { |
945 bShowWhole = true; | 954 bShowWhole = true; |
946 } | 955 } |
947 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption && | 956 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption && |
948 temp.bottom() > m_rtEngine.bottom()) { | 957 temp.bottom() > m_rtEngine.bottom()) { |
949 bShowWhole = true; | 958 bShowWhole = true; |
950 } else { | 959 } else { |
951 bShow = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && bIntersect); | 960 bShow = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && |
| 961 !rtCaret.IsEmpty()); |
952 } | 962 } |
953 if (bShowWhole) { | 963 if (bShowWhole) |
954 rtCaret = temp; | 964 rtCaret = temp; |
955 } | |
956 ShowCaret(bShow, &rtCaret); | 965 ShowCaret(bShow, &rtCaret); |
957 } | 966 } |
| 967 |
958 IFWL_ScrollBar* IFWL_Edit::UpdateScroll() { | 968 IFWL_ScrollBar* IFWL_Edit::UpdateScroll() { |
959 bool bShowHorz = | 969 bool bShowHorz = |
960 m_pHorzScrollBar && | 970 m_pHorzScrollBar && |
961 ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); | 971 ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); |
962 bool bShowVert = | 972 bool bShowVert = |
963 m_pVertScrollBar && | 973 m_pVertScrollBar && |
964 ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); | 974 ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0); |
965 if (!bShowHorz && !bShowVert) { | 975 if (!bShowHorz && !bShowVert) |
966 return nullptr; | 976 return nullptr; |
967 } | 977 |
968 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 978 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
969 if (!pPage) | 979 if (!pPage) |
970 return nullptr; | 980 return nullptr; |
| 981 |
971 const CFX_RectF& rtFDE = pPage->GetContentsBox(); | 982 const CFX_RectF& rtFDE = pPage->GetContentsBox(); |
972 IFWL_ScrollBar* pRepaint = nullptr; | 983 IFWL_ScrollBar* pRepaint = nullptr; |
973 if (bShowHorz) { | 984 if (bShowHorz) { |
974 CFX_RectF rtScroll; | 985 CFX_RectF rtScroll; |
975 m_pHorzScrollBar->GetWidgetRect(rtScroll); | 986 m_pHorzScrollBar->GetWidgetRect(rtScroll); |
976 if (rtScroll.width < rtFDE.width) { | 987 if (rtScroll.width < rtFDE.width) { |
977 m_pHorzScrollBar->LockUpdate(); | 988 m_pHorzScrollBar->LockUpdate(); |
978 FX_FLOAT fRange = rtFDE.width - rtScroll.width; | 989 FX_FLOAT fRange = rtFDE.width - rtScroll.width; |
979 m_pHorzScrollBar->SetRange(0.0f, fRange); | 990 m_pHorzScrollBar->SetRange(0.0f, fRange); |
980 FX_FLOAT fPos = m_fScrollOffsetX; | 991 |
981 if (fPos < 0.0f) { | 992 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetX, 0.0f), fRange); |
982 fPos = 0.0f; | |
983 } | |
984 if (fPos > fRange) { | |
985 fPos = fRange; | |
986 } | |
987 m_pHorzScrollBar->SetPos(fPos); | 993 m_pHorzScrollBar->SetPos(fPos); |
988 m_pHorzScrollBar->SetTrackPos(fPos); | 994 m_pHorzScrollBar->SetTrackPos(fPos); |
989 m_pHorzScrollBar->SetPageSize(rtScroll.width); | 995 m_pHorzScrollBar->SetPageSize(rtScroll.width); |
990 m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); | 996 m_pHorzScrollBar->SetStepSize(rtScroll.width / 10); |
991 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, false); | 997 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, false); |
992 m_pHorzScrollBar->UnlockUpdate(); | 998 m_pHorzScrollBar->UnlockUpdate(); |
993 m_pHorzScrollBar->Update(); | 999 m_pHorzScrollBar->Update(); |
994 pRepaint = m_pHorzScrollBar.get(); | 1000 pRepaint = m_pHorzScrollBar.get(); |
995 } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { | 1001 } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { |
996 m_pHorzScrollBar->LockUpdate(); | 1002 m_pHorzScrollBar->LockUpdate(); |
997 m_pHorzScrollBar->SetRange(0, -1); | 1003 m_pHorzScrollBar->SetRange(0, -1); |
998 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, true); | 1004 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, true); |
999 m_pHorzScrollBar->UnlockUpdate(); | 1005 m_pHorzScrollBar->UnlockUpdate(); |
1000 m_pHorzScrollBar->Update(); | 1006 m_pHorzScrollBar->Update(); |
1001 pRepaint = m_pHorzScrollBar.get(); | 1007 pRepaint = m_pHorzScrollBar.get(); |
1002 } | 1008 } |
1003 } | 1009 } |
| 1010 |
1004 if (bShowVert) { | 1011 if (bShowVert) { |
1005 CFX_RectF rtScroll; | 1012 CFX_RectF rtScroll; |
1006 m_pVertScrollBar->GetWidgetRect(rtScroll); | 1013 m_pVertScrollBar->GetWidgetRect(rtScroll); |
1007 if (rtScroll.height < rtFDE.height) { | 1014 if (rtScroll.height < rtFDE.height) { |
1008 m_pVertScrollBar->LockUpdate(); | 1015 m_pVertScrollBar->LockUpdate(); |
1009 FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; | 1016 FX_FLOAT fStep = m_EdtEngine.GetEditParams()->fLineSpace; |
1010 FX_FLOAT fRange = rtFDE.height - m_rtEngine.height; | 1017 FX_FLOAT fRange = std::max(rtFDE.height - m_rtEngine.height, fStep); |
1011 if (fRange < fStep) { | 1018 |
1012 fRange = fStep; | |
1013 } | |
1014 m_pVertScrollBar->SetRange(0.0f, fRange); | 1019 m_pVertScrollBar->SetRange(0.0f, fRange); |
1015 FX_FLOAT fPos = m_fScrollOffsetY; | 1020 FX_FLOAT fPos = std::min(std::max(m_fScrollOffsetY, 0.0f), fRange); |
1016 if (fPos < 0.0f) { | |
1017 fPos = 0.0f; | |
1018 } | |
1019 if (fPos > fRange) { | |
1020 fPos = fRange; | |
1021 } | |
1022 m_pVertScrollBar->SetPos(fPos); | 1021 m_pVertScrollBar->SetPos(fPos); |
1023 m_pVertScrollBar->SetTrackPos(fPos); | 1022 m_pVertScrollBar->SetTrackPos(fPos); |
1024 m_pVertScrollBar->SetPageSize(rtScroll.height); | 1023 m_pVertScrollBar->SetPageSize(rtScroll.height); |
1025 m_pVertScrollBar->SetStepSize(fStep); | 1024 m_pVertScrollBar->SetStepSize(fStep); |
1026 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, false); | 1025 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, false); |
1027 m_pVertScrollBar->UnlockUpdate(); | 1026 m_pVertScrollBar->UnlockUpdate(); |
1028 m_pVertScrollBar->Update(); | 1027 m_pVertScrollBar->Update(); |
1029 pRepaint = m_pVertScrollBar.get(); | 1028 pRepaint = m_pVertScrollBar.get(); |
1030 } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { | 1029 } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) { |
1031 m_pVertScrollBar->LockUpdate(); | 1030 m_pVertScrollBar->LockUpdate(); |
1032 m_pVertScrollBar->SetRange(0, -1); | 1031 m_pVertScrollBar->SetRange(0, -1); |
1033 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, true); | 1032 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, true); |
1034 m_pVertScrollBar->UnlockUpdate(); | 1033 m_pVertScrollBar->UnlockUpdate(); |
1035 m_pVertScrollBar->Update(); | 1034 m_pVertScrollBar->Update(); |
1036 pRepaint = m_pVertScrollBar.get(); | 1035 pRepaint = m_pVertScrollBar.get(); |
1037 } | 1036 } |
1038 } | 1037 } |
1039 return pRepaint; | 1038 return pRepaint; |
1040 } | 1039 } |
| 1040 |
1041 bool IFWL_Edit::IsShowScrollBar(bool bVert) { | 1041 bool IFWL_Edit::IsShowScrollBar(bool bVert) { |
1042 bool bShow = | 1042 bool bShow = |
1043 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) | 1043 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) |
1044 ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == | 1044 ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == |
1045 FWL_WGTSTATE_Focused | 1045 FWL_WGTSTATE_Focused |
1046 : true; | 1046 : true; |
1047 if (bVert) { | 1047 if (bVert) { |
1048 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) && | 1048 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) && |
1049 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) && | 1049 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) && |
1050 IsContentHeightOverflow(); | 1050 IsContentHeightOverflow(); |
1051 } | 1051 } |
1052 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) && | 1052 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) && |
1053 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine); | 1053 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine); |
1054 } | 1054 } |
| 1055 |
1055 bool IFWL_Edit::IsContentHeightOverflow() { | 1056 bool IFWL_Edit::IsContentHeightOverflow() { |
1056 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 1057 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
1057 if (!pPage) | 1058 if (!pPage) |
1058 return false; | 1059 return false; |
1059 return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; | 1060 return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f; |
1060 } | 1061 } |
| 1062 |
1061 int32_t IFWL_Edit::AddDoRecord(IFDE_TxtEdtDoRecord* pRecord) { | 1063 int32_t IFWL_Edit::AddDoRecord(IFDE_TxtEdtDoRecord* pRecord) { |
1062 int32_t nCount = pdfium::CollectionSize<int32_t>(m_DoRecords); | 1064 int32_t nCount = pdfium::CollectionSize<int32_t>(m_DoRecords); |
1063 if (m_iCurRecord == nCount - 1) { | 1065 if (m_iCurRecord == nCount - 1) { |
1064 if (nCount == m_iMaxRecord) { | 1066 if (nCount == m_iMaxRecord) { |
1065 m_DoRecords.pop_front(); | 1067 m_DoRecords.pop_front(); |
1066 m_iCurRecord--; | 1068 m_iCurRecord--; |
1067 } | 1069 } |
1068 } else { | 1070 } else { |
1069 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, | 1071 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1, |
1070 m_DoRecords.end()); | 1072 m_DoRecords.end()); |
1071 } | 1073 } |
1072 | 1074 |
1073 m_DoRecords.push_back(std::unique_ptr<IFDE_TxtEdtDoRecord>(pRecord)); | 1075 m_DoRecords.push_back(std::unique_ptr<IFDE_TxtEdtDoRecord>(pRecord)); |
1074 m_iCurRecord = pdfium::CollectionSize<int32_t>(m_DoRecords) - 1; | 1076 m_iCurRecord = pdfium::CollectionSize<int32_t>(m_DoRecords) - 1; |
1075 return m_iCurRecord; | 1077 return m_iCurRecord; |
1076 } | 1078 } |
| 1079 |
1077 void IFWL_Edit::Layout() { | 1080 void IFWL_Edit::Layout() { |
1078 GetClientRect(m_rtClient); | 1081 GetClientRect(m_rtClient); |
1079 m_rtEngine = m_rtClient; | 1082 m_rtEngine = m_rtClient; |
1080 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( | 1083 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>( |
1081 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 1084 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
1082 if (!pfWidth) | 1085 if (!pfWidth) |
1083 return; | 1086 return; |
| 1087 |
1084 FX_FLOAT fWidth = *pfWidth; | 1088 FX_FLOAT fWidth = *pfWidth; |
1085 if (!m_pOuter) { | 1089 if (!m_pOuter) { |
1086 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( | 1090 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>( |
1087 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); | 1091 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin)); |
1088 if (pUIMargin) { | 1092 if (pUIMargin) { |
1089 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 1093 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
1090 pUIMargin->height); | 1094 pUIMargin->height); |
1091 } | 1095 } |
1092 } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) { | 1096 } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) { |
1093 CFWL_ThemePart part; | 1097 CFWL_ThemePart part; |
1094 part.m_pWidget = m_pOuter; | 1098 part.m_pWidget = m_pOuter; |
1095 CFX_RectF* pUIMargin = | 1099 CFX_RectF* pUIMargin = |
1096 static_cast<CFX_RectF*>(m_pOuter->GetThemeProvider()->GetCapacity( | 1100 static_cast<CFX_RectF*>(m_pOuter->GetThemeProvider()->GetCapacity( |
1097 &part, CFWL_WidgetCapacity::UIMargin)); | 1101 &part, CFWL_WidgetCapacity::UIMargin)); |
1098 if (pUIMargin) { | 1102 if (pUIMargin) { |
1099 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, | 1103 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width, |
1100 pUIMargin->height); | 1104 pUIMargin->height); |
1101 } | 1105 } |
1102 } | 1106 } |
| 1107 |
1103 bool bShowVertScrollbar = IsShowScrollBar(true); | 1108 bool bShowVertScrollbar = IsShowScrollBar(true); |
1104 bool bShowHorzScrollbar = IsShowScrollBar(false); | 1109 bool bShowHorzScrollbar = IsShowScrollBar(false); |
1105 if (bShowVertScrollbar) { | 1110 if (bShowVertScrollbar) { |
1106 InitScrollBar(); | 1111 InitScrollBar(); |
| 1112 |
1107 CFX_RectF rtVertScr; | 1113 CFX_RectF rtVertScr; |
1108 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1114 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1109 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, | 1115 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, |
1110 m_rtClient.height); | 1116 m_rtClient.height); |
1111 } else { | 1117 } else { |
1112 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, | 1118 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, |
1113 m_rtClient.height); | 1119 m_rtClient.height); |
1114 if (bShowHorzScrollbar) { | 1120 if (bShowHorzScrollbar) |
1115 rtVertScr.height -= fWidth; | 1121 rtVertScr.height -= fWidth; |
1116 } | |
1117 m_rtEngine.width -= fWidth; | 1122 m_rtEngine.width -= fWidth; |
1118 } | 1123 } |
| 1124 |
1119 m_pVertScrollBar->SetWidgetRect(rtVertScr); | 1125 m_pVertScrollBar->SetWidgetRect(rtVertScr); |
1120 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 1126 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
1121 m_pVertScrollBar->Update(); | 1127 m_pVertScrollBar->Update(); |
1122 } else if (m_pVertScrollBar) { | 1128 } else if (m_pVertScrollBar) { |
1123 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 1129 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
1124 } | 1130 } |
| 1131 |
1125 if (bShowHorzScrollbar) { | 1132 if (bShowHorzScrollbar) { |
1126 InitScrollBar(false); | 1133 InitScrollBar(false); |
| 1134 |
1127 CFX_RectF rtHoriScr; | 1135 CFX_RectF rtHoriScr; |
1128 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1136 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1129 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, | 1137 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, |
1130 m_rtClient.width, fWidth); | 1138 m_rtClient.width, fWidth); |
1131 } else { | 1139 } else { |
1132 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, | 1140 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, |
1133 m_rtClient.width, fWidth); | 1141 m_rtClient.width, fWidth); |
1134 if (bShowVertScrollbar) { | 1142 if (bShowVertScrollbar) |
1135 rtHoriScr.width -= fWidth; | 1143 rtHoriScr.width -= fWidth; |
1136 } | |
1137 m_rtEngine.height -= fWidth; | 1144 m_rtEngine.height -= fWidth; |
1138 } | 1145 } |
1139 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); | 1146 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); |
1140 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 1147 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
1141 m_pHorzScrollBar->Update(); | 1148 m_pHorzScrollBar->Update(); |
1142 } else if (m_pHorzScrollBar) { | 1149 } else if (m_pHorzScrollBar) { |
1143 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 1150 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
1144 } | 1151 } |
1145 } | 1152 } |
| 1153 |
1146 void IFWL_Edit::LayoutScrollBar() { | 1154 void IFWL_Edit::LayoutScrollBar() { |
1147 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) == | 1155 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) == |
1148 0) { | 1156 0) { |
1149 return; | 1157 return; |
1150 } | 1158 } |
| 1159 |
1151 FX_FLOAT* pfWidth = nullptr; | 1160 FX_FLOAT* pfWidth = nullptr; |
1152 bool bShowVertScrollbar = IsShowScrollBar(true); | 1161 bool bShowVertScrollbar = IsShowScrollBar(true); |
1153 bool bShowHorzScrollbar = IsShowScrollBar(false); | 1162 bool bShowHorzScrollbar = IsShowScrollBar(false); |
1154 if (bShowVertScrollbar) { | 1163 if (bShowVertScrollbar) { |
1155 if (!m_pVertScrollBar) { | 1164 if (!m_pVertScrollBar) { |
1156 pfWidth = static_cast<FX_FLOAT*>( | 1165 pfWidth = static_cast<FX_FLOAT*>( |
1157 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 1166 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
1158 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; | 1167 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; |
1159 InitScrollBar(); | 1168 InitScrollBar(); |
1160 CFX_RectF rtVertScr; | 1169 CFX_RectF rtVertScr; |
1161 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1170 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1162 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, | 1171 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth, |
1163 m_rtClient.height); | 1172 m_rtClient.height); |
1164 } else { | 1173 } else { |
1165 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, | 1174 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth, |
1166 m_rtClient.height); | 1175 m_rtClient.height); |
1167 if (bShowHorzScrollbar) { | 1176 if (bShowHorzScrollbar) |
1168 rtVertScr.height -= fWidth; | 1177 rtVertScr.height -= fWidth; |
1169 } | |
1170 } | 1178 } |
1171 m_pVertScrollBar->SetWidgetRect(rtVertScr); | 1179 m_pVertScrollBar->SetWidgetRect(rtVertScr); |
1172 m_pVertScrollBar->Update(); | 1180 m_pVertScrollBar->Update(); |
1173 } | 1181 } |
1174 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 1182 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
1175 } else if (m_pVertScrollBar) { | 1183 } else if (m_pVertScrollBar) { |
1176 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 1184 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
1177 } | 1185 } |
| 1186 |
1178 if (bShowHorzScrollbar) { | 1187 if (bShowHorzScrollbar) { |
1179 if (!m_pHorzScrollBar) { | 1188 if (!m_pHorzScrollBar) { |
1180 if (!pfWidth) { | 1189 if (!pfWidth) { |
1181 pfWidth = static_cast<FX_FLOAT*>( | 1190 pfWidth = static_cast<FX_FLOAT*>( |
1182 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); | 1191 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth)); |
1183 } | 1192 } |
| 1193 |
1184 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; | 1194 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0; |
1185 InitScrollBar(false); | 1195 InitScrollBar(false); |
1186 CFX_RectF rtHoriScr; | 1196 CFX_RectF rtHoriScr; |
1187 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { | 1197 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) { |
1188 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, | 1198 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin, |
1189 m_rtClient.width, fWidth); | 1199 m_rtClient.width, fWidth); |
1190 } else { | 1200 } else { |
1191 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, | 1201 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth, |
1192 m_rtClient.width, fWidth); | 1202 m_rtClient.width, fWidth); |
1193 if (bShowVertScrollbar) { | 1203 if (bShowVertScrollbar) |
1194 rtHoriScr.width -= (fWidth); | 1204 rtHoriScr.width -= (fWidth); |
1195 } | |
1196 } | 1205 } |
1197 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); | 1206 m_pHorzScrollBar->SetWidgetRect(rtHoriScr); |
1198 m_pHorzScrollBar->Update(); | 1207 m_pHorzScrollBar->Update(); |
1199 } | 1208 } |
1200 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); | 1209 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, false); |
1201 } else if (m_pHorzScrollBar) { | 1210 } else if (m_pHorzScrollBar) { |
1202 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); | 1211 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, true); |
1203 } | 1212 } |
1204 if (bShowVertScrollbar || bShowHorzScrollbar) { | 1213 if (bShowVertScrollbar || bShowHorzScrollbar) |
1205 UpdateScroll(); | 1214 UpdateScroll(); |
1206 } | |
1207 } | 1215 } |
1208 | 1216 |
1209 void IFWL_Edit::DeviceToEngine(CFX_PointF& pt) { | 1217 void IFWL_Edit::DeviceToEngine(CFX_PointF& pt) { |
1210 pt.x += m_fScrollOffsetX - m_rtEngine.left; | 1218 pt.x += m_fScrollOffsetX - m_rtEngine.left; |
1211 pt.y += m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset; | 1219 pt.y += m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset; |
1212 } | 1220 } |
1213 | 1221 |
1214 void IFWL_Edit::InitScrollBar(bool bVert) { | 1222 void IFWL_Edit::InitScrollBar(bool bVert) { |
1215 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) { | 1223 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) |
1216 return; | 1224 return; |
1217 } | |
1218 | 1225 |
1219 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); | 1226 auto prop = pdfium::MakeUnique<CFWL_WidgetProperties>(); |
1220 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; | 1227 prop->m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz; |
1221 prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; | 1228 prop->m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible; |
1222 prop->m_pParent = this; | 1229 prop->m_pParent = this; |
1223 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; | 1230 prop->m_pThemeProvider = m_pProperties->m_pThemeProvider; |
1224 | 1231 |
1225 IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); | 1232 IFWL_ScrollBar* sb = new IFWL_ScrollBar(m_pOwnerApp, std::move(prop), this); |
1226 if (bVert) | 1233 if (bVert) |
1227 m_pVertScrollBar.reset(sb); | 1234 m_pVertScrollBar.reset(sb); |
(...skipping 15 matching lines...) Expand all Loading... |
1243 return false; | 1250 return false; |
1244 | 1251 |
1245 if (bVisible) { | 1252 if (bVisible) { |
1246 CFX_Matrix mt; | 1253 CFX_Matrix mt; |
1247 pXFAWidget->GetRotateMatrix(mt); | 1254 pXFAWidget->GetRotateMatrix(mt); |
1248 CFX_RectF rt(*pRtAnchor); | 1255 CFX_RectF rt(*pRtAnchor); |
1249 mt.TransformRect(rt); | 1256 mt.TransformRect(rt); |
1250 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt); | 1257 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt); |
1251 return true; | 1258 return true; |
1252 } | 1259 } |
| 1260 |
1253 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor); | 1261 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor); |
1254 return true; | 1262 return true; |
1255 } | 1263 } |
1256 | 1264 |
1257 void IFWL_Edit::ShowCaret(bool bVisible, CFX_RectF* pRect) { | 1265 void IFWL_Edit::ShowCaret(bool bVisible, CFX_RectF* pRect) { |
1258 if (m_pCaret) { | 1266 if (m_pCaret) { |
1259 m_pCaret->ShowCaret(bVisible); | 1267 m_pCaret->ShowCaret(bVisible); |
1260 if (bVisible && !pRect->IsEmpty()) { | 1268 if (bVisible && !pRect->IsEmpty()) |
1261 m_pCaret->SetWidgetRect(*pRect); | 1269 m_pCaret->SetWidgetRect(*pRect); |
| 1270 Repaint(&m_rtEngine); |
| 1271 return; |
| 1272 } |
| 1273 |
| 1274 IFWL_Widget* pOuter = this; |
| 1275 if (bVisible) { |
| 1276 pRect->Offset(m_pProperties->m_rtWidget.left, |
| 1277 m_pProperties->m_rtWidget.top); |
| 1278 } |
| 1279 while (pOuter->GetOuter()) { |
| 1280 pOuter = pOuter->GetOuter(); |
| 1281 if (bVisible) { |
| 1282 CFX_RectF rtOuter; |
| 1283 pOuter->GetWidgetRect(rtOuter); |
| 1284 pRect->Offset(rtOuter.left, rtOuter.top); |
1262 } | 1285 } |
1263 Repaint(&m_rtEngine); | |
1264 } else { | |
1265 IFWL_Widget* pOuter = this; | |
1266 if (bVisible) { | |
1267 pRect->Offset(m_pProperties->m_rtWidget.left, | |
1268 m_pProperties->m_rtWidget.top); | |
1269 } | |
1270 while (pOuter->GetOuter()) { | |
1271 pOuter = pOuter->GetOuter(); | |
1272 if (bVisible) { | |
1273 CFX_RectF rtOuter; | |
1274 pOuter->GetWidgetRect(rtOuter); | |
1275 pRect->Offset(rtOuter.left, rtOuter.top); | |
1276 } | |
1277 } | |
1278 FWL_ShowCaret(pOuter, bVisible, pRect); | |
1279 } | 1286 } |
| 1287 FWL_ShowCaret(pOuter, bVisible, pRect); |
1280 } | 1288 } |
| 1289 |
1281 bool IFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { | 1290 bool IFWL_Edit::ValidateNumberChar(FX_WCHAR cNum) { |
1282 if (!m_bSetRange) { | 1291 if (!m_bSetRange) |
1283 return true; | 1292 return true; |
1284 } | 1293 |
1285 CFX_WideString wsOld, wsText; | 1294 CFX_WideString wsOld, wsText; |
1286 m_EdtEngine.GetText(wsText, 0); | 1295 m_EdtEngine.GetText(wsText, 0); |
1287 if (wsText.IsEmpty()) { | 1296 if (wsText.IsEmpty()) { |
1288 if (cNum == L'0') { | 1297 if (cNum == L'0') |
1289 return false; | 1298 return false; |
1290 } | |
1291 return true; | 1299 return true; |
1292 } | 1300 } |
| 1301 |
1293 int32_t caretPos = m_EdtEngine.GetCaretPos(); | 1302 int32_t caretPos = m_EdtEngine.GetCaretPos(); |
1294 int32_t iSel = CountSelRanges(); | 1303 if (CountSelRanges() == 0) { |
1295 if (iSel == 0) { | 1304 if (cNum == L'0' && caretPos == 0) |
1296 if (cNum == L'0' && caretPos == 0) { | |
1297 return false; | 1305 return false; |
1298 } | 1306 |
1299 int32_t nLen = wsText.GetLength(); | 1307 int32_t nLen = wsText.GetLength(); |
1300 CFX_WideString l = wsText.Mid(0, caretPos); | 1308 CFX_WideString l = wsText.Mid(0, caretPos); |
1301 CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); | 1309 CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos); |
1302 CFX_WideString wsNew = l + cNum + r; | 1310 CFX_WideString wsNew = l + cNum + r; |
1303 if (wsNew.GetInteger() <= m_iMax) { | 1311 if (wsNew.GetInteger() <= m_iMax) |
1304 return true; | 1312 return true; |
1305 } | 1313 return false; |
1306 } else { | |
1307 if (wsText.GetInteger() <= m_iMax) { | |
1308 return true; | |
1309 } | |
1310 } | 1314 } |
| 1315 |
| 1316 if (wsText.GetInteger() <= m_iMax) |
| 1317 return true; |
1311 return false; | 1318 return false; |
1312 } | 1319 } |
| 1320 |
1313 void IFWL_Edit::InitCaret() { | 1321 void IFWL_Edit::InitCaret() { |
1314 if (!m_pCaret) { | 1322 if (!m_pCaret) { |
1315 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { | 1323 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) { |
1316 m_pCaret.reset(new IFWL_Caret( | 1324 m_pCaret.reset(new IFWL_Caret( |
1317 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); | 1325 m_pOwnerApp, pdfium::MakeUnique<CFWL_WidgetProperties>(), this)); |
1318 m_pCaret->SetParent(this); | 1326 m_pCaret->SetParent(this); |
1319 m_pCaret->SetStates(m_pProperties->m_dwStates); | 1327 m_pCaret->SetStates(m_pProperties->m_dwStates); |
1320 } | 1328 } |
1321 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == | 1329 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) == |
1322 0) { | 1330 0) { |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1409 DrawWidget(pGraphics, pMatrix); | 1417 DrawWidget(pGraphics, pMatrix); |
1410 } | 1418 } |
1411 | 1419 |
1412 void IFWL_Edit::DoButtonDown(CFWL_MsgMouse* pMsg) { | 1420 void IFWL_Edit::DoButtonDown(CFWL_MsgMouse* pMsg) { |
1413 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) | 1421 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) |
1414 SetFocus(true); | 1422 SetFocus(true); |
1415 | 1423 |
1416 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); | 1424 IFDE_TxtEdtPage* pPage = m_EdtEngine.GetPage(0); |
1417 if (!pPage) | 1425 if (!pPage) |
1418 return; | 1426 return; |
| 1427 |
1419 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | 1428 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
1420 DeviceToEngine(pt); | 1429 DeviceToEngine(pt); |
1421 bool bBefore = true; | 1430 bool bBefore = true; |
1422 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); | 1431 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); |
1423 if (nIndex < 0) | 1432 if (nIndex < 0) |
1424 nIndex = 0; | 1433 nIndex = 0; |
1425 | 1434 |
1426 m_EdtEngine.SetCaretPos(nIndex, bBefore); | 1435 m_EdtEngine.SetCaretPos(nIndex, bBefore); |
1427 } | 1436 } |
1428 | 1437 |
(...skipping 13 matching lines...) Expand all Loading... |
1442 int32_t nSel = CountSelRanges(); | 1451 int32_t nSel = CountSelRanges(); |
1443 if (nSel > 0) { | 1452 if (nSel > 0) { |
1444 ClearSelections(); | 1453 ClearSelections(); |
1445 bRepaint = true; | 1454 bRepaint = true; |
1446 } | 1455 } |
1447 m_EdtEngine.SetCaretPos(0, true); | 1456 m_EdtEngine.SetCaretPos(0, true); |
1448 UpdateOffset(); | 1457 UpdateOffset(); |
1449 } | 1458 } |
1450 ClearRecord(); | 1459 ClearRecord(); |
1451 } | 1460 } |
| 1461 |
1452 LayoutScrollBar(); | 1462 LayoutScrollBar(); |
1453 if (bRepaint) { | 1463 if (!bRepaint) |
1454 CFX_RectF rtInvalidate; | 1464 return; |
1455 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, | 1465 |
1456 m_pProperties->m_rtWidget.height); | 1466 CFX_RectF rtInvalidate; |
1457 Repaint(&rtInvalidate); | 1467 rtInvalidate.Set(0, 0, m_pProperties->m_rtWidget.width, |
1458 } | 1468 m_pProperties->m_rtWidget.height); |
| 1469 Repaint(&rtInvalidate); |
1459 } | 1470 } |
1460 | 1471 |
1461 void IFWL_Edit::OnLButtonDown(CFWL_MsgMouse* pMsg) { | 1472 void IFWL_Edit::OnLButtonDown(CFWL_MsgMouse* pMsg) { |
1462 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) | 1473 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) |
1463 return; | 1474 return; |
1464 | 1475 |
1465 m_bLButtonDown = true; | 1476 m_bLButtonDown = true; |
1466 SetGrab(true); | 1477 SetGrab(true); |
1467 DoButtonDown(pMsg); | 1478 DoButtonDown(pMsg); |
1468 int32_t nIndex = m_EdtEngine.GetCaretPos(); | 1479 int32_t nIndex = m_EdtEngine.GetCaretPos(); |
1469 bool bRepaint = false; | 1480 bool bRepaint = false; |
1470 int32_t iCount = m_EdtEngine.CountSelRanges(); | 1481 if (m_EdtEngine.CountSelRanges() > 0) { |
1471 if (iCount > 0) { | |
1472 m_EdtEngine.ClearSelection(); | 1482 m_EdtEngine.ClearSelection(); |
1473 bRepaint = true; | 1483 bRepaint = true; |
1474 } | 1484 } |
1475 | 1485 |
1476 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 1486 if ((pMsg->m_dwFlags & FWL_KEYFLAG_Shift) && m_nSelStart != nIndex) { |
1477 if (bShift && m_nSelStart != nIndex) { | |
1478 int32_t iStart = std::min(m_nSelStart, nIndex); | 1487 int32_t iStart = std::min(m_nSelStart, nIndex); |
1479 int32_t iEnd = std::max(m_nSelStart, nIndex); | 1488 int32_t iEnd = std::max(m_nSelStart, nIndex); |
1480 m_EdtEngine.AddSelRange(iStart, iEnd - iStart); | 1489 m_EdtEngine.AddSelRange(iStart, iEnd - iStart); |
1481 bRepaint = true; | 1490 bRepaint = true; |
1482 } else { | 1491 } else { |
1483 m_nSelStart = nIndex; | 1492 m_nSelStart = nIndex; |
1484 } | 1493 } |
1485 if (bRepaint) | 1494 if (bRepaint) |
1486 Repaint(&m_rtEngine); | 1495 Repaint(&m_rtEngine); |
1487 } | 1496 } |
(...skipping 28 matching lines...) Expand all Loading... |
1516 if (!pPage) | 1525 if (!pPage) |
1517 return; | 1526 return; |
1518 | 1527 |
1519 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); | 1528 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy); |
1520 DeviceToEngine(pt); | 1529 DeviceToEngine(pt); |
1521 bool bBefore = true; | 1530 bool bBefore = true; |
1522 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); | 1531 int32_t nIndex = pPage->GetCharIndex(pt, bBefore); |
1523 m_EdtEngine.SetCaretPos(nIndex, bBefore); | 1532 m_EdtEngine.SetCaretPos(nIndex, bBefore); |
1524 nIndex = m_EdtEngine.GetCaretPos(); | 1533 nIndex = m_EdtEngine.GetCaretPos(); |
1525 m_EdtEngine.ClearSelection(); | 1534 m_EdtEngine.ClearSelection(); |
1526 if (nIndex != m_nSelStart) { | |
1527 int32_t nLen = m_EdtEngine.GetTextLength(); | |
1528 if (m_nSelStart >= nLen) | |
1529 m_nSelStart = nLen; | |
1530 | 1535 |
1531 m_EdtEngine.AddSelRange(std::min(m_nSelStart, nIndex), | 1536 if (nIndex == m_nSelStart) |
1532 FXSYS_abs(nIndex - m_nSelStart)); | 1537 return; |
1533 } | 1538 |
| 1539 int32_t nLen = m_EdtEngine.GetTextLength(); |
| 1540 if (m_nSelStart >= nLen) |
| 1541 m_nSelStart = nLen; |
| 1542 |
| 1543 m_EdtEngine.AddSelRange(std::min(m_nSelStart, nIndex), |
| 1544 FXSYS_abs(nIndex - m_nSelStart)); |
1534 } | 1545 } |
1535 | 1546 |
1536 void IFWL_Edit::OnKeyDown(CFWL_MsgKey* pMsg) { | 1547 void IFWL_Edit::OnKeyDown(CFWL_MsgKey* pMsg) { |
1537 FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; | 1548 FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone; |
1538 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); | 1549 bool bShift = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Shift); |
1539 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); | 1550 bool bCtrl = !!(pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl); |
1540 uint32_t dwKeyCode = pMsg->m_dwKeyCode; | 1551 uint32_t dwKeyCode = pMsg->m_dwKeyCode; |
1541 switch (dwKeyCode) { | 1552 switch (dwKeyCode) { |
1542 case FWL_VKEY_Left: { | 1553 case FWL_VKEY_Left: { |
1543 MoveCaret = MC_Left; | 1554 MoveCaret = MC_Left; |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); | 1602 m_EdtEngine.MoveCaretPos(MoveCaret, bShift, bCtrl); |
1592 } | 1603 } |
1593 | 1604 |
1594 void IFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { | 1605 void IFWL_Edit::OnChar(CFWL_MsgKey* pMsg) { |
1595 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || | 1606 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) || |
1596 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { | 1607 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) { |
1597 return; | 1608 return; |
1598 } | 1609 } |
1599 | 1610 |
1600 int32_t iError = 0; | 1611 int32_t iError = 0; |
1601 FX_WCHAR c = (FX_WCHAR)pMsg->m_dwKeyCode; | 1612 FX_WCHAR c = static_cast<FX_WCHAR>(pMsg->m_dwKeyCode); |
1602 int32_t nCaret = m_EdtEngine.GetCaretPos(); | 1613 int32_t nCaret = m_EdtEngine.GetCaretPos(); |
1603 switch (c) { | 1614 switch (c) { |
1604 case FWL_VKEY_Back: | 1615 case FWL_VKEY_Back: |
1605 m_EdtEngine.Delete(nCaret, true); | 1616 m_EdtEngine.Delete(nCaret, true); |
1606 break; | 1617 break; |
1607 case 0x0A: | 1618 case FWL_VKEY_NewLine: |
1608 break; | |
1609 case FWL_VKEY_Escape: | 1619 case FWL_VKEY_Escape: |
1610 break; | 1620 break; |
1611 case FWL_VKEY_Tab: { | 1621 case FWL_VKEY_Tab: { |
1612 iError = m_EdtEngine.Insert(nCaret, L"\t", 1); | 1622 iError = m_EdtEngine.Insert(nCaret, L"\t", 1); |
1613 break; | 1623 break; |
1614 } | 1624 } |
1615 case FWL_VKEY_Return: { | 1625 case FWL_VKEY_Return: { |
1616 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { | 1626 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_WantReturn) { |
1617 iError = m_EdtEngine.Insert(nCaret, L"\n", 1); | 1627 iError = m_EdtEngine.Insert(nCaret, L"\n", 1); |
1618 } | 1628 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1690 } | 1700 } |
1691 break; | 1701 break; |
1692 } | 1702 } |
1693 case FWL_SCBCODE::Pos: | 1703 case FWL_SCBCODE::Pos: |
1694 case FWL_SCBCODE::TrackPos: | 1704 case FWL_SCBCODE::TrackPos: |
1695 case FWL_SCBCODE::None: | 1705 case FWL_SCBCODE::None: |
1696 break; | 1706 break; |
1697 case FWL_SCBCODE::EndScroll: | 1707 case FWL_SCBCODE::EndScroll: |
1698 return false; | 1708 return false; |
1699 } | 1709 } |
1700 if (iCurPos != fPos) { | 1710 if (iCurPos == fPos) |
1701 pScrollBar->SetPos(fPos); | 1711 return true; |
1702 pScrollBar->SetTrackPos(fPos); | |
1703 UpdateOffset(pScrollBar, fPos - iCurPos); | |
1704 UpdateCaret(); | |
1705 | 1712 |
1706 CFX_RectF rect; | 1713 pScrollBar->SetPos(fPos); |
1707 GetWidgetRect(rect); | 1714 pScrollBar->SetTrackPos(fPos); |
1708 CFX_RectF rtInvalidate; | 1715 UpdateOffset(pScrollBar, fPos - iCurPos); |
1709 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); | 1716 UpdateCaret(); |
1710 Repaint(&rtInvalidate); | 1717 |
1711 } | 1718 CFX_RectF rect; |
| 1719 GetWidgetRect(rect); |
| 1720 CFX_RectF rtInvalidate; |
| 1721 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2); |
| 1722 Repaint(&rtInvalidate); |
1712 return true; | 1723 return true; |
1713 } | 1724 } |
OLD | NEW |