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

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

Issue 2432423002: Merge the CFWL_*Imp classes into the IFWL_* classes. (Closed)
Patch Set: Review feedback Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « xfa/fwl/basewidget/fwl_editimp.h ('k') | xfa/fwl/basewidget/fwl_formproxyimp.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7 #include "xfa/fwl/basewidget/fwl_editimp.h"
8
9 #include <algorithm>
10 #include <memory>
11 #include <vector>
12
13 #include "third_party/base/stl_util.h"
14 #include "xfa/fde/cfde_txtedtengine.h"
15 #include "xfa/fde/fde_gedevice.h"
16 #include "xfa/fde/fde_render.h"
17 #include "xfa/fde/ifde_txtedtpage.h"
18 #include "xfa/fgas/font/fgas_gefont.h"
19 #include "xfa/fwl/basewidget/fwl_caretimp.h"
20 #include "xfa/fwl/basewidget/fwl_comboboximp.h"
21 #include "xfa/fwl/basewidget/fwl_scrollbarimp.h"
22 #include "xfa/fwl/basewidget/ifwl_caret.h"
23 #include "xfa/fwl/core/cfwl_message.h"
24 #include "xfa/fwl/core/cfwl_themebackground.h"
25 #include "xfa/fwl/core/cfwl_themepart.h"
26 #include "xfa/fwl/core/cfwl_widgetmgr.h"
27 #include "xfa/fwl/core/fwl_widgetimp.h"
28 #include "xfa/fwl/core/ifwl_app.h"
29 #include "xfa/fwl/core/ifwl_themeprovider.h"
30 #include "xfa/fxfa/xfa_ffdoc.h"
31 #include "xfa/fxfa/xfa_ffwidget.h"
32 #include "xfa/fxgraphics/cfx_path.h"
33
34 namespace {
35
36 const int kEditMargin = 3;
37
38 bool FX_EDIT_ISLATINWORD(FX_WCHAR c) {
39 return c == 0x2D || (c <= 0x005A && c >= 0x0041) ||
40 (c <= 0x007A && c >= 0x0061) || (c <= 0x02AF && c >= 0x00C0) ||
41 c == 0x0027;
42 }
43
44 void AddSquigglyPath(CFX_Path* pPathData,
45 FX_FLOAT fStartX,
46 FX_FLOAT fEndX,
47 FX_FLOAT fY,
48 FX_FLOAT fStep) {
49 pPathData->MoveTo(fStartX, fY);
50 int i = 1;
51 for (FX_FLOAT fx = fStartX + fStep; fx < fEndX; fx += fStep, ++i) {
52 pPathData->LineTo(fx, fY + (i & 1) * fStep);
53 }
54 }
55
56 } // namespace
57
58 // static
59 IFWL_Edit* IFWL_Edit::Create(const CFWL_WidgetImpProperties& properties,
60 IFWL_Widget* pOuter) {
61 IFWL_Edit* pEdit = new IFWL_Edit;
62 CFWL_EditImp* pEditImpl = new CFWL_EditImp(properties, pOuter);
63 pEdit->SetImpl(pEditImpl);
64 pEditImpl->SetInterface(pEdit);
65 return pEdit;
66 }
67 // static
68 IFWL_Edit* IFWL_Edit::CreateComboEdit(
69 const CFWL_WidgetImpProperties& properties,
70 IFWL_Widget* pOuter) {
71 IFWL_Edit* pEdit = new IFWL_Edit;
72 CFWL_EditImp* pComboEditImpl = new CFWL_ComboEditImp(properties, pOuter);
73 pEdit->SetImpl(pComboEditImpl);
74 pComboEditImpl->SetInterface(pEdit);
75 return pEdit;
76 }
77 IFWL_Edit::IFWL_Edit() {}
78 FWL_Error IFWL_Edit::SetText(const CFX_WideString& wsText) {
79 return static_cast<CFWL_EditImp*>(GetImpl())->SetText(wsText);
80 }
81 int32_t IFWL_Edit::GetTextLength() const {
82 return static_cast<CFWL_EditImp*>(GetImpl())->GetTextLength();
83 }
84 FWL_Error IFWL_Edit::GetText(CFX_WideString& wsText,
85 int32_t nStart,
86 int32_t nCount) const {
87 return static_cast<CFWL_EditImp*>(GetImpl())->GetText(wsText, nStart, nCount);
88 }
89 FWL_Error IFWL_Edit::ClearText() {
90 return static_cast<CFWL_EditImp*>(GetImpl())->ClearText();
91 }
92 int32_t IFWL_Edit::GetCaretPos() const {
93 return static_cast<CFWL_EditImp*>(GetImpl())->GetCaretPos();
94 }
95 int32_t IFWL_Edit::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) {
96 return static_cast<CFWL_EditImp*>(GetImpl())->SetCaretPos(nIndex, bBefore);
97 }
98 FWL_Error IFWL_Edit::AddSelRange(int32_t nStart, int32_t nCount) {
99 return static_cast<CFWL_EditImp*>(GetImpl())->AddSelRange(nStart, nCount);
100 }
101 int32_t IFWL_Edit::CountSelRanges() {
102 return static_cast<CFWL_EditImp*>(GetImpl())->CountSelRanges();
103 }
104 int32_t IFWL_Edit::GetSelRange(int32_t nIndex, int32_t& nStart) {
105 return static_cast<CFWL_EditImp*>(GetImpl())->GetSelRange(nIndex, nStart);
106 }
107 FWL_Error IFWL_Edit::ClearSelections() {
108 return static_cast<CFWL_EditImp*>(GetImpl())->ClearSelections();
109 }
110 int32_t IFWL_Edit::GetLimit() {
111 return static_cast<CFWL_EditImp*>(GetImpl())->GetLimit();
112 }
113 FWL_Error IFWL_Edit::SetLimit(int32_t nLimit) {
114 return static_cast<CFWL_EditImp*>(GetImpl())->SetLimit(nLimit);
115 }
116 FWL_Error IFWL_Edit::SetAliasChar(FX_WCHAR wAlias) {
117 return static_cast<CFWL_EditImp*>(GetImpl())->SetAliasChar(wAlias);
118 }
119 FWL_Error IFWL_Edit::Insert(int32_t nStart,
120 const FX_WCHAR* lpText,
121 int32_t nLen) {
122 return static_cast<CFWL_EditImp*>(GetImpl())->Insert(nStart, lpText, nLen);
123 }
124 FWL_Error IFWL_Edit::DeleteSelections() {
125 return static_cast<CFWL_EditImp*>(GetImpl())->DeleteSelections();
126 }
127 FWL_Error IFWL_Edit::DeleteRange(int32_t nStart, int32_t nCount) {
128 return static_cast<CFWL_EditImp*>(GetImpl())->DeleteRange(nStart, nCount);
129 }
130 FWL_Error IFWL_Edit::Replace(int32_t nStart,
131 int32_t nLen,
132 const CFX_WideStringC& wsReplace) {
133 return static_cast<CFWL_EditImp*>(GetImpl())
134 ->Replace(nStart, nLen, wsReplace);
135 }
136 FWL_Error IFWL_Edit::DoClipboard(int32_t iCmd) {
137 return static_cast<CFWL_EditImp*>(GetImpl())->DoClipboard(iCmd);
138 }
139 FX_BOOL IFWL_Edit::Copy(CFX_WideString& wsCopy) {
140 return static_cast<CFWL_EditImp*>(GetImpl())->Copy(wsCopy);
141 }
142 FX_BOOL IFWL_Edit::Cut(CFX_WideString& wsCut) {
143 return static_cast<CFWL_EditImp*>(GetImpl())->Cut(wsCut);
144 }
145 FX_BOOL IFWL_Edit::Paste(const CFX_WideString& wsPaste) {
146 return static_cast<CFWL_EditImp*>(GetImpl())->Paste(wsPaste);
147 }
148 FX_BOOL IFWL_Edit::Delete() {
149 return static_cast<CFWL_EditImp*>(GetImpl())->Delete();
150 }
151 FX_BOOL IFWL_Edit::Redo(const IFDE_TxtEdtDoRecord* pRecord) {
152 return static_cast<CFWL_EditImp*>(GetImpl())->Redo(pRecord);
153 }
154 FX_BOOL IFWL_Edit::Undo(const IFDE_TxtEdtDoRecord* pRecord) {
155 return static_cast<CFWL_EditImp*>(GetImpl())->Undo(pRecord);
156 }
157 FX_BOOL IFWL_Edit::Undo() {
158 return static_cast<CFWL_EditImp*>(GetImpl())->Undo();
159 }
160 FX_BOOL IFWL_Edit::Redo() {
161 return static_cast<CFWL_EditImp*>(GetImpl())->Redo();
162 }
163 FX_BOOL IFWL_Edit::CanUndo() {
164 return static_cast<CFWL_EditImp*>(GetImpl())->CanUndo();
165 }
166 FX_BOOL IFWL_Edit::CanRedo() {
167 return static_cast<CFWL_EditImp*>(GetImpl())->CanRedo();
168 }
169 FWL_Error IFWL_Edit::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) {
170 return static_cast<CFWL_EditImp*>(GetImpl())
171 ->SetTabWidth(fTabWidth, bEquidistant);
172 }
173 FWL_Error IFWL_Edit::SetOuter(IFWL_Widget* pOuter) {
174 return static_cast<CFWL_EditImp*>(GetImpl())->SetOuter(pOuter);
175 }
176 FWL_Error IFWL_Edit::SetNumberRange(int32_t iMin, int32_t iMax) {
177 return static_cast<CFWL_EditImp*>(GetImpl())->SetNumberRange(iMin, iMax);
178 }
179 FWL_Error IFWL_Edit::SetBackColor(uint32_t dwColor) {
180 return static_cast<CFWL_EditImp*>(GetImpl())->SetBackgroundColor(dwColor);
181 }
182 FWL_Error IFWL_Edit::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) {
183 return static_cast<CFWL_EditImp*>(GetImpl())->SetFont(wsFont, fSize);
184 }
185 void IFWL_Edit::SetScrollOffset(FX_FLOAT fScrollOffset) {
186 return static_cast<CFWL_EditImp*>(GetImpl())->SetScrollOffset(fScrollOffset);
187 }
188 FX_BOOL IFWL_Edit::GetSuggestWords(CFX_PointF pointf,
189 std::vector<CFX_ByteString>& sSuggest) {
190 return static_cast<CFWL_EditImp*>(GetImpl())
191 ->GetSuggestWords(pointf, sSuggest);
192 }
193 FX_BOOL IFWL_Edit::ReplaceSpellCheckWord(CFX_PointF pointf,
194 const CFX_ByteStringC& bsReplace) {
195 return static_cast<CFWL_EditImp*>(GetImpl())
196 ->ReplaceSpellCheckWord(pointf, bsReplace);
197 }
198
199 CFWL_EditImp::CFWL_EditImp(const CFWL_WidgetImpProperties& properties,
200 IFWL_Widget* pOuter)
201 : CFWL_WidgetImp(properties, pOuter),
202 m_fVAlignOffset(0.0f),
203 m_fScrollOffsetX(0.0f),
204 m_fScrollOffsetY(0.0f),
205 m_bLButtonDown(FALSE),
206 m_nSelStart(0),
207 m_nLimit(-1),
208 m_fSpaceAbove(0),
209 m_fSpaceBelow(0),
210 m_fFontSize(0),
211 m_bSetRange(FALSE),
212 m_iMin(-1),
213 m_iMax(0xFFFFFFF),
214 m_backColor(0),
215 m_updateBackColor(FALSE),
216 m_iCurRecord(-1),
217 m_iMaxRecord(128) {
218 m_rtClient.Reset();
219 m_rtEngine.Reset();
220 m_rtStatic.Reset();
221 }
222
223 CFWL_EditImp::~CFWL_EditImp() {
224 ClearRecord();
225 }
226
227 FWL_Error CFWL_EditImp::GetClassName(CFX_WideString& wsClass) const {
228 wsClass = FWL_CLASS_Edit;
229 return FWL_Error::Succeeded;
230 }
231
232 FWL_Type CFWL_EditImp::GetClassID() const {
233 return FWL_Type::Edit;
234 }
235
236 FWL_Error CFWL_EditImp::Initialize() {
237 if (CFWL_WidgetImp::Initialize() != FWL_Error::Succeeded)
238 return FWL_Error::Indefinite;
239 if (!m_pDelegate)
240 m_pDelegate = new CFWL_EditImpDelegate(this);
241
242 InitCaret();
243 if (!m_pEdtEngine)
244 InitEngine();
245
246 return FWL_Error::Succeeded;
247 }
248
249 FWL_Error CFWL_EditImp::Finalize() {
250 if (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
251 ShowCaret(FALSE);
252 }
253 if (m_pHorzScrollBar) {
254 m_pHorzScrollBar->Finalize();
255 }
256 if (m_pVertScrollBar) {
257 m_pVertScrollBar->Finalize();
258 }
259 delete m_pDelegate;
260 m_pDelegate = nullptr;
261 return CFWL_WidgetImp::Finalize();
262 }
263 FWL_Error CFWL_EditImp::GetWidgetRect(CFX_RectF& rect, FX_BOOL bAutoSize) {
264 if (bAutoSize) {
265 rect.Set(0, 0, 0, 0);
266 if (m_pEdtEngine) {
267 int32_t iTextLen = m_pEdtEngine->GetTextLength();
268 if (iTextLen > 0) {
269 CFX_WideString wsText;
270 m_pEdtEngine->GetText(wsText, 0);
271 CFX_SizeF sz = CalcTextSize(
272 wsText, m_pProperties->m_pThemeProvider,
273 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine);
274 rect.Set(0, 0, sz.x, sz.y);
275 }
276 }
277 CFWL_WidgetImp::GetWidgetRect(rect, TRUE);
278 } else {
279 rect = m_pProperties->m_rtWidget;
280 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
281 if (IsShowScrollBar(TRUE)) {
282 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>(
283 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
284 rect.width += *pfWidth;
285 rect.width += kEditMargin;
286 }
287 if (IsShowScrollBar(FALSE)) {
288 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>(
289 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
290 rect.height += *pfWidth;
291 rect.height += kEditMargin;
292 }
293 }
294 }
295 return FWL_Error::Succeeded;
296 }
297
298 void CFWL_EditImp::SetStates(uint32_t dwStates, FX_BOOL bSet) {
299 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Invisible) ||
300 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
301 ShowCaret(FALSE);
302 }
303 CFWL_WidgetImp::SetStates(dwStates, bSet);
304 }
305
306 FWL_Error CFWL_EditImp::SetWidgetRect(const CFX_RectF& rect) {
307 return CFWL_WidgetImp::SetWidgetRect(rect);
308 }
309 FWL_Error CFWL_EditImp::Update() {
310 if (IsLocked()) {
311 return FWL_Error::Indefinite;
312 }
313 if (!m_pProperties->m_pThemeProvider) {
314 m_pProperties->m_pThemeProvider = GetAvailableTheme();
315 }
316 Layout();
317 if (m_rtClient.IsEmpty()) {
318 return FWL_Error::Indefinite;
319 }
320 UpdateEditEngine();
321 UpdateVAlignment();
322 UpdateScroll();
323 InitCaret();
324 return FWL_Error::Succeeded;
325 }
326
327 FWL_WidgetHit CFWL_EditImp::HitTest(FX_FLOAT fx, FX_FLOAT fy) {
328 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
329 if (IsShowScrollBar(TRUE)) {
330 CFX_RectF rect;
331 m_pVertScrollBar->GetWidgetRect(rect);
332 if (rect.Contains(fx, fy))
333 return FWL_WidgetHit::VScrollBar;
334 }
335 if (IsShowScrollBar(FALSE)) {
336 CFX_RectF rect;
337 m_pHorzScrollBar->GetWidgetRect(rect);
338 if (rect.Contains(fx, fy))
339 return FWL_WidgetHit::HScrollBar;
340 }
341 }
342 if (m_rtClient.Contains(fx, fy))
343 return FWL_WidgetHit::Edit;
344 return FWL_WidgetHit::Unknown;
345 }
346
347 void CFWL_EditImp::AddSpellCheckObj(CFX_Path& PathData,
348 int32_t nStart,
349 int32_t nCount,
350 FX_FLOAT fOffSetX,
351 FX_FLOAT fOffSetY) {
352 FX_FLOAT fStartX = 0.0f;
353 FX_FLOAT fEndX = 0.0f;
354 FX_FLOAT fY = 0.0f;
355 FX_FLOAT fStep = 0.0f;
356 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
357 CFX_RectFArray rectArray;
358 CFX_RectF rectText;
359 const FDE_TXTEDTPARAMS* txtEdtParams = m_pEdtEngine->GetEditParams();
360 FX_FLOAT fAsent = (FX_FLOAT)txtEdtParams->pFont->GetAscent() *
361 txtEdtParams->fFontSize / 1000;
362 pPage->CalcRangeRectArray(nStart, nCount, rectArray);
363 for (int i = 0; i < rectArray.GetSize(); i++) {
364 rectText = rectArray.GetAt(i);
365 fY = rectText.top + fAsent + fOffSetY;
366 fStep = txtEdtParams->fFontSize / 16.0f;
367 fStartX = rectText.left + fOffSetX;
368 fEndX = fStartX + rectText.Width();
369 AddSquigglyPath(&PathData, fStartX, fEndX, fY, fStep);
370 }
371 }
372 int32_t CFWL_EditImp::GetWordAtPoint(CFX_PointF pointf, int32_t& nCount) {
373 return 0;
374 }
375 FX_BOOL CFWL_EditImp::GetSuggestWords(CFX_PointF pointf,
376 std::vector<CFX_ByteString>& sSuggest) {
377 int32_t nWordCount = 0;
378 int32_t nWordStart = GetWordAtPoint(pointf, nWordCount);
379 if (nWordCount < 1) {
380 return FALSE;
381 }
382 CFX_WideString wsSpell;
383 GetText(wsSpell, nWordStart, nWordCount);
384 CFX_ByteString sLatinWord;
385 for (int i = 0; i < nWordCount; i++) {
386 if (!FX_EDIT_ISLATINWORD(wsSpell[i])) {
387 break;
388 }
389 sLatinWord += (FX_CHAR)wsSpell[i];
390 }
391 if (sLatinWord.IsEmpty()) {
392 return FALSE;
393 }
394 CFWL_EvtEdtCheckWord checkWordEvent;
395 checkWordEvent.m_pSrcTarget = m_pInterface;
396 checkWordEvent.bsWord = sLatinWord;
397 checkWordEvent.bCheckWord = TRUE;
398 DispatchEvent(&checkWordEvent);
399 if (checkWordEvent.bCheckWord) {
400 return FALSE;
401 }
402 CFWL_EvtEdtGetSuggestWords suggestWordsEvent;
403 suggestWordsEvent.m_pSrcTarget = m_pInterface;
404 suggestWordsEvent.bsWord = sLatinWord;
405 suggestWordsEvent.bsArraySuggestWords = sSuggest;
406 suggestWordsEvent.bSuggestWords = FALSE;
407 DispatchEvent(&checkWordEvent);
408 return suggestWordsEvent.bSuggestWords;
409 }
410 FX_BOOL CFWL_EditImp::ReplaceSpellCheckWord(CFX_PointF pointf,
411 const CFX_ByteStringC& bsReplace) {
412 int32_t nWordCount = 0;
413 int32_t nWordStart = GetWordAtPoint(pointf, nWordCount);
414 if (nWordCount < 1) {
415 return FALSE;
416 }
417 CFX_WideString wsSpell;
418 GetText(wsSpell, nWordStart, nWordCount);
419 for (int i = 0; i < nWordCount; i++) {
420 if (!FX_EDIT_ISLATINWORD(wsSpell[i])) {
421 nWordCount = i;
422 break;
423 }
424 }
425 int32_t nDestLen = bsReplace.GetLength();
426 CFX_WideString wsDest;
427 FX_WCHAR* pBuffer = wsDest.GetBuffer(nDestLen);
428 for (int32_t i = 0; i < nDestLen; i++) {
429 pBuffer[i] = bsReplace[i];
430 }
431 wsDest.ReleaseBuffer(nDestLen);
432 Replace(nWordStart, nWordCount, wsDest.AsStringC());
433 return TRUE;
434 }
435 void CFWL_EditImp::DrawSpellCheck(CFX_Graphics* pGraphics,
436 const CFX_Matrix* pMatrix) {
437 pGraphics->SaveGraphState();
438 if (pMatrix) {
439 pGraphics->ConcatMatrix(const_cast<CFX_Matrix*>(pMatrix));
440 }
441 FX_ARGB cr = 0xFFFF0000;
442 CFX_Color crLine(cr);
443 CFWL_EvtEdtCheckWord checkWordEvent;
444 checkWordEvent.m_pSrcTarget = m_pInterface;
445 CFX_ByteString sLatinWord;
446 CFX_Path pathSpell;
447 pathSpell.Create();
448 int32_t nStart = 0;
449 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX;
450 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset;
451 CFX_WideString wsSpell;
452 GetText(wsSpell);
453 int32_t nContentLen = wsSpell.GetLength();
454 for (int i = 0; i < nContentLen; i++) {
455 if (FX_EDIT_ISLATINWORD(wsSpell[i])) {
456 if (sLatinWord.IsEmpty()) {
457 nStart = i;
458 }
459 sLatinWord += (FX_CHAR)wsSpell[i];
460 } else {
461 checkWordEvent.bsWord = sLatinWord;
462 checkWordEvent.bCheckWord = TRUE;
463 DispatchEvent(&checkWordEvent);
464 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) {
465 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX,
466 fOffSetY);
467 }
468 sLatinWord.clear();
469 }
470 }
471 checkWordEvent.bsWord = sLatinWord;
472 checkWordEvent.bCheckWord = TRUE;
473 DispatchEvent(&checkWordEvent);
474 if (!sLatinWord.IsEmpty() && !checkWordEvent.bCheckWord) {
475 AddSpellCheckObj(pathSpell, nStart, sLatinWord.GetLength(), fOffSetX,
476 fOffSetY);
477 }
478 if (!pathSpell.IsEmpty()) {
479 CFX_RectF rtClip = m_rtEngine;
480 CFX_Matrix mt;
481 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY);
482 if (pMatrix) {
483 pMatrix->TransformRect(rtClip);
484 mt.Concat(*pMatrix);
485 }
486 pGraphics->SetClipRect(rtClip);
487 pGraphics->SetStrokeColor(&crLine);
488 pGraphics->SetLineWidth(0);
489 pGraphics->StrokePath(&pathSpell, nullptr);
490 }
491 pGraphics->RestoreGraphState();
492 }
493 FWL_Error CFWL_EditImp::DrawWidget(CFX_Graphics* pGraphics,
494 const CFX_Matrix* pMatrix) {
495 if (!pGraphics)
496 return FWL_Error::Indefinite;
497 if (!m_pProperties->m_pThemeProvider)
498 return FWL_Error::Indefinite;
499 if (m_rtClient.IsEmpty()) {
500 return FWL_Error::Indefinite;
501 }
502 IFWL_ThemeProvider* pTheme = m_pProperties->m_pThemeProvider;
503 if (!m_pWidgetMgr->IsFormDisabled()) {
504 DrawTextBk(pGraphics, pTheme, pMatrix);
505 }
506 if (m_pEdtEngine) {
507 DrawContent(pGraphics, pTheme, pMatrix);
508 }
509 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) &&
510 !(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly)) {
511 DrawSpellCheck(pGraphics, pMatrix);
512 }
513 if (HasBorder()) {
514 DrawBorder(pGraphics, CFWL_Part::Border, pTheme, pMatrix);
515 }
516 if (HasEdge()) {
517 DrawEdge(pGraphics, CFWL_Part::Edge, pTheme, pMatrix);
518 }
519 return FWL_Error::Succeeded;
520 }
521 FWL_Error CFWL_EditImp::SetThemeProvider(IFWL_ThemeProvider* pThemeProvider) {
522 if (!pThemeProvider)
523 return FWL_Error::Indefinite;
524 if (m_pHorzScrollBar) {
525 m_pHorzScrollBar->SetThemeProvider(pThemeProvider);
526 }
527 if (m_pVertScrollBar) {
528 m_pVertScrollBar->SetThemeProvider(pThemeProvider);
529 }
530 if (m_pCaret) {
531 m_pCaret->SetThemeProvider(pThemeProvider);
532 }
533 m_pProperties->m_pThemeProvider = pThemeProvider;
534 return FWL_Error::Succeeded;
535 }
536
537 FWL_Error CFWL_EditImp::SetText(const CFX_WideString& wsText) {
538 m_pEdtEngine->SetText(wsText);
539 return FWL_Error::Succeeded;
540 }
541
542 int32_t CFWL_EditImp::GetTextLength() const {
543 if (!m_pEdtEngine)
544 return -1;
545 return m_pEdtEngine->GetTextLength();
546 }
547
548 FWL_Error CFWL_EditImp::GetText(CFX_WideString& wsText,
549 int32_t nStart,
550 int32_t nCount) const {
551 if (!m_pEdtEngine)
552 return FWL_Error::Indefinite;
553
554 m_pEdtEngine->GetText(wsText, nStart, nCount);
555 return FWL_Error::Succeeded;
556 }
557
558 FWL_Error CFWL_EditImp::ClearText() {
559 if (!m_pEdtEngine)
560 return FWL_Error::Indefinite;
561
562 m_pEdtEngine->ClearText();
563 return FWL_Error::Succeeded;
564 }
565
566 int32_t CFWL_EditImp::GetCaretPos() const {
567 if (!m_pEdtEngine)
568 return -1;
569 return m_pEdtEngine->GetCaretPos();
570 }
571
572 int32_t CFWL_EditImp::SetCaretPos(int32_t nIndex, FX_BOOL bBefore) {
573 if (!m_pEdtEngine)
574 return -1;
575 return m_pEdtEngine->SetCaretPos(nIndex, bBefore);
576 }
577
578 FWL_Error CFWL_EditImp::AddSelRange(int32_t nStart, int32_t nCount) {
579 if (!m_pEdtEngine)
580 return FWL_Error::Indefinite;
581
582 m_pEdtEngine->AddSelRange(nStart, nCount);
583 return FWL_Error::Succeeded;
584 }
585
586 int32_t CFWL_EditImp::CountSelRanges() {
587 if (!m_pEdtEngine)
588 return 0;
589 return m_pEdtEngine->CountSelRanges();
590 }
591
592 int32_t CFWL_EditImp::GetSelRange(int32_t nIndex, int32_t& nStart) {
593 if (!m_pEdtEngine)
594 return -1;
595 return m_pEdtEngine->GetSelRange(nIndex, nStart);
596 }
597
598 FWL_Error CFWL_EditImp::ClearSelections() {
599 if (!m_pEdtEngine)
600 return FWL_Error::Indefinite;
601
602 m_pEdtEngine->ClearSelection();
603 return FWL_Error::Succeeded;
604 }
605
606 int32_t CFWL_EditImp::GetLimit() {
607 return m_nLimit;
608 }
609
610 FWL_Error CFWL_EditImp::SetLimit(int32_t nLimit) {
611 m_nLimit = nLimit;
612 if (!m_pEdtEngine)
613 return FWL_Error::Indefinite;
614
615 m_pEdtEngine->SetLimit(nLimit);
616 return FWL_Error::Succeeded;
617 }
618
619 FWL_Error CFWL_EditImp::SetAliasChar(FX_WCHAR wAlias) {
620 if (!m_pEdtEngine)
621 return FWL_Error::Indefinite;
622
623 m_pEdtEngine->SetAliasChar(wAlias);
624 return FWL_Error::Succeeded;
625 }
626
627 FWL_Error CFWL_EditImp::Insert(int32_t nStart,
628 const FX_WCHAR* lpText,
629 int32_t nLen) {
630 if (!m_pEdtEngine)
631 return FWL_Error::Indefinite;
632
633 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
634 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
635 return FWL_Error::Indefinite;
636 }
637 m_pEdtEngine->Insert(nStart, lpText, nLen);
638 return FWL_Error::Succeeded;
639 }
640
641 FWL_Error CFWL_EditImp::DeleteSelections() {
642 if (!m_pEdtEngine)
643 return FWL_Error::Indefinite;
644
645 int32_t iCount = m_pEdtEngine->CountSelRanges();
646 if (iCount > 0)
647 m_pEdtEngine->Delete(-1);
648 return FWL_Error::Succeeded;
649 }
650
651 FWL_Error CFWL_EditImp::DeleteRange(int32_t nStart, int32_t nCount) {
652 if (!m_pEdtEngine)
653 return FWL_Error::Indefinite;
654
655 m_pEdtEngine->DeleteRange(nStart, nCount);
656 return FWL_Error::Succeeded;
657 }
658
659 FWL_Error CFWL_EditImp::Replace(int32_t nStart,
660 int32_t nLen,
661 const CFX_WideStringC& wsReplace) {
662 if (!m_pEdtEngine)
663 return FWL_Error::Indefinite;
664
665 m_pEdtEngine->Replace(nStart, nLen, CFX_WideString(wsReplace));
666 return FWL_Error::Succeeded;
667 }
668
669 FWL_Error CFWL_EditImp::DoClipboard(int32_t iCmd) {
670 if (!m_pEdtEngine)
671 return FWL_Error::Indefinite;
672
673 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
674 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
675 return FWL_Error::Succeeded;
676 }
677 return FWL_Error::Indefinite;
678 }
679
680 FX_BOOL CFWL_EditImp::Copy(CFX_WideString& wsCopy) {
681 if (!m_pEdtEngine)
682 return FALSE;
683
684 int32_t nCount = m_pEdtEngine->CountSelRanges();
685 if (nCount == 0)
686 return FALSE;
687
688 wsCopy.clear();
689 CFX_WideString wsTemp;
690 int32_t nStart, nLength;
691 for (int32_t i = 0; i < nCount; i++) {
692 nLength = m_pEdtEngine->GetSelRange(i, nStart);
693 m_pEdtEngine->GetText(wsTemp, nStart, nLength);
694 wsCopy += wsTemp;
695 wsTemp.clear();
696 }
697 return TRUE;
698 }
699
700 FX_BOOL CFWL_EditImp::Cut(CFX_WideString& wsCut) {
701 if (!m_pEdtEngine)
702 return FALSE;
703
704 int32_t nCount = m_pEdtEngine->CountSelRanges();
705 if (nCount == 0)
706 return FALSE;
707
708 wsCut.clear();
709 CFX_WideString wsTemp;
710 int32_t nStart, nLength;
711 for (int32_t i = 0; i < nCount; i++) {
712 nLength = m_pEdtEngine->GetSelRange(i, nStart);
713 m_pEdtEngine->GetText(wsTemp, nStart, nLength);
714 wsCut += wsTemp;
715 wsTemp.clear();
716 }
717 m_pEdtEngine->Delete(0);
718 return TRUE;
719 }
720
721 FX_BOOL CFWL_EditImp::Paste(const CFX_WideString& wsPaste) {
722 if (!m_pEdtEngine)
723 return FALSE;
724
725 int32_t nCaret = m_pEdtEngine->GetCaretPos();
726 int32_t iError =
727 m_pEdtEngine->Insert(nCaret, wsPaste.c_str(), wsPaste.GetLength());
728 if (iError < 0) {
729 ProcessInsertError(iError);
730 return FALSE;
731 }
732 return TRUE;
733 }
734
735 FX_BOOL CFWL_EditImp::Delete() {
736 if (!m_pEdtEngine)
737 return FALSE;
738
739 int32_t nCount = m_pEdtEngine->CountSelRanges();
740 if (nCount < 1)
741 return FALSE;
742
743 m_pEdtEngine->Delete(0);
744 return TRUE;
745 }
746
747 FX_BOOL CFWL_EditImp::Redo(const IFDE_TxtEdtDoRecord* pRecord) {
748 if (!m_pEdtEngine)
749 return FALSE;
750 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo)
751 return TRUE;
752 return m_pEdtEngine->Redo(pRecord);
753 }
754
755 FX_BOOL CFWL_EditImp::Undo(const IFDE_TxtEdtDoRecord* pRecord) {
756 if (!m_pEdtEngine)
757 return FALSE;
758 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoRedoUndo)
759 return TRUE;
760 return m_pEdtEngine->Undo(pRecord);
761 }
762
763 FX_BOOL CFWL_EditImp::Undo() {
764 if (!CanUndo())
765 return FALSE;
766 return Undo(m_DoRecords[m_iCurRecord--].get());
767 }
768
769 FX_BOOL CFWL_EditImp::Redo() {
770 if (!CanRedo())
771 return FALSE;
772 return Redo(m_DoRecords[++m_iCurRecord].get());
773 }
774
775 FX_BOOL CFWL_EditImp::CanUndo() {
776 return m_iCurRecord >= 0;
777 }
778
779 FX_BOOL CFWL_EditImp::CanRedo() {
780 return m_iCurRecord < pdfium::CollectionSize<int32_t>(m_DoRecords) - 1;
781 }
782
783 FWL_Error CFWL_EditImp::SetTabWidth(FX_FLOAT fTabWidth, FX_BOOL bEquidistant) {
784 if (!m_pEdtEngine)
785 return FWL_Error::Indefinite;
786
787 FDE_TXTEDTPARAMS* pParams = m_pEdtEngine->GetEditParams();
788 pParams->fTabWidth = fTabWidth;
789 pParams->bTabEquidistant = bEquidistant;
790 return FWL_Error::Succeeded;
791 }
792
793 FWL_Error CFWL_EditImp::SetOuter(IFWL_Widget* pOuter) {
794 m_pOuter = pOuter;
795 return FWL_Error::Succeeded;
796 }
797
798 FWL_Error CFWL_EditImp::SetNumberRange(int32_t iMin, int32_t iMax) {
799 m_iMin = iMin;
800 m_iMax = iMax;
801 m_bSetRange = TRUE;
802 return FWL_Error::Succeeded;
803 }
804
805 void CFWL_EditImp::On_CaretChanged(CFDE_TxtEdtEngine* pEdit,
806 int32_t nPage,
807 FX_BOOL bVisible) {
808 if (m_rtEngine.IsEmpty())
809 return;
810 if ((m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0)
811 return;
812
813 FX_BOOL bRepaintContent = UpdateOffset();
814 UpdateCaret();
815 CFX_RectF rtInvalid;
816 rtInvalid.Set(0, 0, 0, 0);
817 FX_BOOL bRepaintScroll = FALSE;
818 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) {
819 IFWL_ScrollBar* pScroll = UpdateScroll();
820 if (pScroll) {
821 pScroll->GetWidgetRect(rtInvalid);
822 bRepaintScroll = TRUE;
823 }
824 }
825 if (bRepaintContent || bRepaintScroll) {
826 if (bRepaintContent) {
827 rtInvalid.Union(m_rtEngine);
828 }
829 Repaint(&rtInvalid);
830 }
831 }
832
833 void CFWL_EditImp::On_TextChanged(CFDE_TxtEdtEngine* pEdit,
834 FDE_TXTEDT_TEXTCHANGE_INFO& ChangeInfo) {
835 uint32_t dwStyleEx = m_pProperties->m_dwStyleExes;
836 if (dwStyleEx & FWL_STYLEEXT_EDT_VAlignMask)
837 UpdateVAlignment();
838
839 IFDE_TxtEdtPage* page = m_pEdtEngine->GetPage(0);
840 FX_FLOAT fContentWidth = page->GetContentsBox().width;
841 FX_FLOAT fContentHeight = page->GetContentsBox().height;
842 CFX_RectF rtTemp;
843 GetClientRect(rtTemp);
844 FX_BOOL bHSelfAdaption =
845 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption;
846 FX_BOOL bVSelfAdaption =
847 m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption;
848 FX_BOOL bNeedUpdate = FALSE;
849 if (bHSelfAdaption || bVSelfAdaption) {
850 CFWL_EvtEdtPreSelfAdaption evt;
851 evt.m_pSrcTarget = m_pInterface;
852 evt.bHSelfAdaption = TRUE;
853 evt.bVSelfAdaption = TRUE;
854 FX_FLOAT fWidth;
855 FX_FLOAT fHight;
856 fWidth = bHSelfAdaption ? fContentWidth : m_pProperties->m_rtWidget.width;
857 fHight = bVSelfAdaption ? fContentHeight : m_pProperties->m_rtWidget.height;
858 evt.rtAfterChange.Set(0, 0, fWidth, fHight);
859 DispatchEvent(&evt);
860 if (!evt.bHSelfAdaption) {
861 ModifyStylesEx(
862 0, FWL_STYLEEXT_EDT_HSelfAdaption | FWL_STYLEEXT_EDT_AutoHScroll);
863 }
864 if (!evt.bVSelfAdaption) {
865 ModifyStylesEx(
866 0, FWL_STYLEEXT_EDT_VSelfAdaption | FWL_STYLEEXT_EDT_AutoVScroll);
867 }
868 bNeedUpdate = (bHSelfAdaption && !evt.bHSelfAdaption) ||
869 (bVSelfAdaption && !evt.bVSelfAdaption);
870 }
871 FX_FLOAT fContentWidth1 = fContentWidth;
872 FX_FLOAT fContentHeight1 = fContentHeight;
873 if (bNeedUpdate) {
874 UpdateEditParams();
875 UpdateEditLayout();
876 IFDE_TxtEdtPage* page1 = m_pEdtEngine->GetPage(0);
877 fContentWidth1 = page1->GetContentsBox().width;
878 fContentHeight1 = page1->GetContentsBox().height;
879 }
880 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption) {
881 rtTemp.width = std::max(m_pProperties->m_rtWidget.width, fContentWidth1);
882 m_pProperties->m_rtWidget.width = fContentWidth1;
883 }
884 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption) {
885 rtTemp.height = std::max(m_pProperties->m_rtWidget.height, fContentHeight1);
886 m_pProperties->m_rtWidget.height = fContentHeight1;
887 }
888 CFWL_EvtEdtTextChanged event;
889 event.m_pSrcTarget = m_pInterface;
890 event.nChangeType = ChangeInfo.nChangeType;
891 event.wsInsert = ChangeInfo.wsInsert;
892 event.wsDelete = ChangeInfo.wsDelete;
893 event.wsPrevText = ChangeInfo.wsPrevText;
894 DispatchEvent(&event);
895 LayoutScrollBar();
896 Repaint(&rtTemp);
897 }
898
899 void CFWL_EditImp::On_SelChanged(CFDE_TxtEdtEngine* pEdit) {
900 CFX_RectF rtTemp;
901 GetClientRect(rtTemp);
902 Repaint(&rtTemp);
903 }
904
905 FX_BOOL CFWL_EditImp::On_PageLoad(CFDE_TxtEdtEngine* pEdit,
906 int32_t nPageIndex,
907 int32_t nPurpose) {
908 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(nPageIndex);
909 if (!pPage)
910 return FALSE;
911 pPage->LoadPage(nullptr, nullptr);
912 return TRUE;
913 }
914
915 FX_BOOL CFWL_EditImp::On_PageUnload(CFDE_TxtEdtEngine* pEdit,
916 int32_t nPageIndex,
917 int32_t nPurpose) {
918 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(nPageIndex);
919 if (!pPage)
920 return FALSE;
921 pPage->UnloadPage(nullptr);
922 return TRUE;
923 }
924
925 void CFWL_EditImp::On_AddDoRecord(CFDE_TxtEdtEngine* pEdit,
926 IFDE_TxtEdtDoRecord* pRecord) {
927 AddDoRecord(pRecord);
928 }
929
930 FX_BOOL CFWL_EditImp::On_Validate(CFDE_TxtEdtEngine* pEdit,
931 CFX_WideString& wsText) {
932 IFWL_Widget* pDst = GetOuter();
933 if (!pDst) {
934 pDst = m_pInterface;
935 }
936 CFWL_EvtEdtValidate event;
937 event.pDstWidget = pDst;
938 event.m_pSrcTarget = m_pInterface;
939 event.wsInsert = wsText;
940 event.bValidate = TRUE;
941 DispatchEvent(&event);
942 return event.bValidate;
943 }
944 FWL_Error CFWL_EditImp::SetBackgroundColor(uint32_t color) {
945 m_backColor = color;
946 m_updateBackColor = TRUE;
947 return FWL_Error::Succeeded;
948 }
949 FWL_Error CFWL_EditImp::SetFont(const CFX_WideString& wsFont, FX_FLOAT fSize) {
950 m_wsFont = wsFont;
951 m_fFontSize = fSize;
952 return FWL_Error::Succeeded;
953 }
954 void CFWL_EditImp::SetScrollOffset(FX_FLOAT fScrollOffset) {
955 m_fScrollOffsetY = fScrollOffset;
956 }
957 void CFWL_EditImp::DrawTextBk(CFX_Graphics* pGraphics,
958 IFWL_ThemeProvider* pTheme,
959 const CFX_Matrix* pMatrix) {
960 CFWL_ThemeBackground param;
961 param.m_pWidget = m_pInterface;
962 param.m_iPart = CFWL_Part::Background;
963 param.m_bStaticBackground = false;
964 param.m_dwStates = m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly
965 ? CFWL_PartState_ReadOnly
966 : CFWL_PartState_Normal;
967 uint32_t dwStates = (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled);
968 if (dwStates) {
969 param.m_dwStates = CFWL_PartState_Disabled;
970 }
971 param.m_pGraphics = pGraphics;
972 param.m_matrix = *pMatrix;
973 param.m_rtPart = m_rtClient;
974 pTheme->DrawBackground(&param);
975 if (!IsShowScrollBar(TRUE) || !IsShowScrollBar(FALSE)) {
976 return;
977 }
978 CFX_RectF rtScorll;
979 m_pHorzScrollBar->GetWidgetRect(rtScorll);
980 CFX_RectF rtStatic;
981 rtStatic.Set(m_rtClient.right() - rtScorll.height,
982 m_rtClient.bottom() - rtScorll.height, rtScorll.height,
983 rtScorll.height);
984 param.m_bStaticBackground = true;
985 param.m_bMaximize = true;
986 param.m_rtPart = rtStatic;
987 pTheme->DrawBackground(&param);
988 }
989 void CFWL_EditImp::DrawContent(CFX_Graphics* pGraphics,
990 IFWL_ThemeProvider* pTheme,
991 const CFX_Matrix* pMatrix) {
992 if (!m_pEdtEngine)
993 return;
994 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
995 if (!pPage)
996 return;
997 pGraphics->SaveGraphState();
998 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) {
999 pGraphics->SaveGraphState();
1000 }
1001 CFX_RectF rtClip = m_rtEngine;
1002 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX;
1003 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset;
1004 CFX_Matrix mt;
1005 mt.Set(1, 0, 0, 1, fOffSetX, fOffSetY);
1006 if (pMatrix) {
1007 pMatrix->TransformRect(rtClip);
1008 mt.Concat(*pMatrix);
1009 }
1010 FX_BOOL bShowSel =
1011 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_NoHideSel) ||
1012 (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused);
1013 if (bShowSel) {
1014 IFWL_Widget* pForm = m_pWidgetMgr->GetSystemFormWidget(m_pInterface);
1015 if (pForm) {
1016 bShowSel = (pForm->GetStates() & FWL_WGTSTATE_Deactivated) !=
1017 FWL_WGTSTATE_Deactivated;
1018 }
1019 }
1020 int32_t nSelCount = m_pEdtEngine->CountSelRanges();
1021 if (bShowSel && nSelCount > 0) {
1022 int32_t nPageCharStart = pPage->GetCharStart();
1023 int32_t nPageCharCount = pPage->GetCharCount();
1024 int32_t nPageCharEnd = nPageCharStart + nPageCharCount - 1;
1025 int32_t nCharCount;
1026 int32_t nCharStart;
1027 CFX_RectFArray rectArr;
1028 int32_t i = 0;
1029 for (i = 0; i < nSelCount; i++) {
1030 nCharCount = m_pEdtEngine->GetSelRange(i, nCharStart);
1031 int32_t nCharEnd = nCharStart + nCharCount - 1;
1032 if (nCharEnd < nPageCharStart || nCharStart > nPageCharEnd) {
1033 continue;
1034 }
1035 int32_t nBgn = std::max(nCharStart, nPageCharStart);
1036 int32_t nEnd = std::min(nCharEnd, nPageCharEnd);
1037 pPage->CalcRangeRectArray(nBgn - nPageCharStart, nEnd - nBgn + 1,
1038 rectArr);
1039 }
1040 int32_t nCount = rectArr.GetSize();
1041 CFX_Path path;
1042 path.Create();
1043 for (i = 0; i < nCount; i++) {
1044 rectArr[i].left += fOffSetX;
1045 rectArr[i].top += fOffSetY;
1046 path.AddRectangle(rectArr[i].left, rectArr[i].top, rectArr[i].width,
1047 rectArr[i].height);
1048 }
1049 pGraphics->SetClipRect(rtClip);
1050 CFWL_ThemeBackground param;
1051 param.m_pGraphics = pGraphics;
1052 param.m_matrix = *pMatrix;
1053 param.m_pWidget = m_pInterface;
1054 param.m_iPart = CFWL_Part::Background;
1055 param.m_pPath = &path;
1056 pTheme->DrawBackground(&param);
1057 }
1058 CFX_RenderDevice* pRenderDev = pGraphics->GetRenderDevice();
1059 if (!pRenderDev)
1060 return;
1061
1062 std::unique_ptr<CFDE_RenderDevice> pRenderDevice(
1063 new CFDE_RenderDevice(pRenderDev, FALSE));
1064 std::unique_ptr<CFDE_RenderContext> pRenderContext(new CFDE_RenderContext);
1065 pRenderDevice->SetClipRect(rtClip);
1066 pRenderContext->StartRender(pRenderDevice.get(), pPage, mt);
1067 pRenderContext->DoRender(nullptr);
1068 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) {
1069 pGraphics->RestoreGraphState();
1070 CFX_Path path;
1071 path.Create();
1072 int32_t iLimit = m_nLimit > 0 ? m_nLimit : 1;
1073 FX_FLOAT fStep = m_rtEngine.width / iLimit;
1074 FX_FLOAT fLeft = m_rtEngine.left + 1;
1075 for (int32_t i = 1; i < iLimit; i++) {
1076 fLeft += fStep;
1077 path.AddLine(fLeft, m_rtClient.top, fLeft, m_rtClient.bottom());
1078 }
1079 CFWL_ThemeBackground param;
1080 param.m_pGraphics = pGraphics;
1081 param.m_matrix = *pMatrix;
1082 param.m_pWidget = m_pInterface;
1083 param.m_iPart = CFWL_Part::CombTextLine;
1084 param.m_pPath = &path;
1085 pTheme->DrawBackground(&param);
1086 }
1087 pGraphics->RestoreGraphState();
1088 }
1089
1090 void CFWL_EditImp::UpdateEditEngine() {
1091 UpdateEditParams();
1092 UpdateEditLayout();
1093 if (m_nLimit > -1) {
1094 m_pEdtEngine->SetLimit(m_nLimit);
1095 }
1096 }
1097 void CFWL_EditImp::UpdateEditParams() {
1098 FDE_TXTEDTPARAMS params;
1099 params.nHorzScale = 100;
1100 params.fPlateWidth = m_rtEngine.width;
1101 params.fPlateHeight = m_rtEngine.height;
1102 if (m_pProperties->m_dwStyles & FWL_WGTSTYLE_RTLLayout) {
1103 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_RTL;
1104 }
1105 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalLayout) {
1106 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_DocVertical;
1107 }
1108 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VerticalChars) {
1109 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CharVertial;
1110 }
1111 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReverseLine) {
1112 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LineReserve;
1113 }
1114 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ArabicShapes) {
1115 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ArabicShapes;
1116 }
1117 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ExpandTab) {
1118 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_ExpandTab;
1119 }
1120 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_CombText) {
1121 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_CombText;
1122 }
1123 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_LastLineHeight) {
1124 params.dwLayoutStyles |= FDE_TEXTEDITLAYOUT_LastLineHeight;
1125 }
1126 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Validate) {
1127 params.dwMode |= FDE_TEXTEDITMODE_Validate;
1128 }
1129 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Password) {
1130 params.dwMode |= FDE_TEXTEDITMODE_Password;
1131 }
1132 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignMask) {
1133 case FWL_STYLEEXT_EDT_HNear: {
1134 params.dwAlignment |= FDE_TEXTEDITALIGN_Left;
1135 break;
1136 }
1137 case FWL_STYLEEXT_EDT_HCenter: {
1138 params.dwAlignment |= FDE_TEXTEDITALIGN_Center;
1139 break;
1140 }
1141 case FWL_STYLEEXT_EDT_HFar: {
1142 params.dwAlignment |= FDE_TEXTEDITALIGN_Right;
1143 break;
1144 }
1145 default: {}
1146 }
1147 switch (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HAlignModeMask) {
1148 case FWL_STYLEEXT_EDT_Justified: {
1149 params.dwAlignment |= FDE_TEXTEDITALIGN_Justified;
1150 break;
1151 }
1152 case FWL_STYLEEXT_EDT_Distributed: {
1153 params.dwAlignment |= FDE_TEXTEDITALIGN_Distributed;
1154 break;
1155 }
1156 default: { params.dwAlignment |= FDE_TEXTEDITALIGN_Normal; }
1157 }
1158 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) {
1159 params.dwMode |= FDE_TEXTEDITMODE_MultiLines;
1160 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) == 0 &&
1161 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) {
1162 params.dwMode |=
1163 FDE_TEXTEDITMODE_AutoLineWrap | FDE_TEXTEDITMODE_LimitArea_Horz;
1164 }
1165 if ((m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) == 0 &&
1166 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoVScroll) == 0) {
1167 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Vert;
1168 } else {
1169 params.fPlateHeight = 0x00FFFFFF;
1170 }
1171 } else {
1172 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_AutoHScroll) == 0) {
1173 params.dwMode |= FDE_TEXTEDITMODE_LimitArea_Horz;
1174 }
1175 }
1176 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
1177 (m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
1178 params.dwMode |= FDE_TEXTEDITMODE_ReadOnly;
1179 }
1180 FX_FLOAT* pFontSize =
1181 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::FontSize));
1182 if (!pFontSize)
1183 return;
1184 m_fFontSize = *pFontSize;
1185 uint32_t* pFontColor =
1186 static_cast<uint32_t*>(GetThemeCapacity(CFWL_WidgetCapacity::TextColor));
1187 if (!pFontColor)
1188 return;
1189 params.dwFontColor = *pFontColor;
1190 FX_FLOAT* pLineHeight =
1191 static_cast<FX_FLOAT*>(GetThemeCapacity(CFWL_WidgetCapacity::LineHeight));
1192 if (!pLineHeight)
1193 return;
1194 params.fLineSpace = *pLineHeight;
1195 CFGAS_GEFont* pFont =
1196 static_cast<CFGAS_GEFont*>(GetThemeCapacity(CFWL_WidgetCapacity::Font));
1197 if (!pFont)
1198 return;
1199 params.pFont = pFont;
1200 params.fFontSize = m_fFontSize;
1201 params.nLineCount = (int32_t)(params.fPlateHeight / params.fLineSpace);
1202 if (params.nLineCount <= 0) {
1203 params.nLineCount = 1;
1204 }
1205 params.fTabWidth = params.fFontSize * 1;
1206 params.bTabEquidistant = TRUE;
1207 params.wLineBreakChar = L'\n';
1208 params.nCharRotation = 0;
1209 params.pEventSink = this;
1210 m_pEdtEngine->SetEditParams(params);
1211 }
1212
1213 void CFWL_EditImp::UpdateEditLayout() {
1214 if (m_pEdtEngine->GetTextLength() <= 0)
1215 m_pEdtEngine->SetTextByStream(nullptr);
1216
1217 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1218 if (pPage)
1219 pPage->UnloadPage(nullptr);
1220
1221 m_pEdtEngine->StartLayout();
1222 m_pEdtEngine->DoLayout(nullptr);
1223 m_pEdtEngine->EndLayout();
1224 pPage = m_pEdtEngine->GetPage(0);
1225 if (pPage)
1226 pPage->LoadPage(nullptr, nullptr);
1227 }
1228
1229 FX_BOOL CFWL_EditImp::UpdateOffset() {
1230 CFX_RectF rtCaret;
1231 m_pEdtEngine->GetCaretRect(rtCaret);
1232 FX_FLOAT fOffSetX = m_rtEngine.left - m_fScrollOffsetX;
1233 FX_FLOAT fOffSetY = m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset;
1234 rtCaret.Offset(fOffSetX, fOffSetY);
1235 const CFX_RectF& rtEidt = m_rtEngine;
1236 if (rtEidt.Contains(rtCaret)) {
1237 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1238 if (!pPage)
1239 return FALSE;
1240
1241 CFX_RectF rtFDE = pPage->GetContentsBox();
1242 rtFDE.Offset(fOffSetX, fOffSetY);
1243 if (rtFDE.right() < rtEidt.right() && m_fScrollOffsetX > 0) {
1244 m_fScrollOffsetX += rtFDE.right() - rtEidt.right();
1245 m_fScrollOffsetX = std::max(m_fScrollOffsetX, 0.0f);
1246 }
1247 if (rtFDE.bottom() < rtEidt.bottom() && m_fScrollOffsetY > 0) {
1248 m_fScrollOffsetY += rtFDE.bottom() - rtEidt.bottom();
1249 m_fScrollOffsetY = std::max(m_fScrollOffsetY, 0.0f);
1250 }
1251 return FALSE;
1252 }
1253
1254 FX_FLOAT offsetX = 0.0;
1255 FX_FLOAT offsetY = 0.0;
1256 if (rtCaret.left < rtEidt.left)
1257 offsetX = rtCaret.left - rtEidt.left;
1258 if (rtCaret.right() > rtEidt.right())
1259 offsetX = rtCaret.right() - rtEidt.right();
1260 if (rtCaret.top < rtEidt.top)
1261 offsetY = rtCaret.top - rtEidt.top;
1262 if (rtCaret.bottom() > rtEidt.bottom())
1263 offsetY = rtCaret.bottom() - rtEidt.bottom();
1264 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption))
1265 m_fScrollOffsetX += offsetX;
1266 if (!(m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption))
1267 m_fScrollOffsetY += offsetY;
1268 if (m_fFontSize > m_rtEngine.height)
1269 m_fScrollOffsetY = 0;
1270 return TRUE;
1271 }
1272
1273 FX_BOOL CFWL_EditImp::UpdateOffset(IFWL_ScrollBar* pScrollBar,
1274 FX_FLOAT fPosChanged) {
1275 if (pScrollBar == m_pHorzScrollBar.get())
1276 m_fScrollOffsetX += fPosChanged;
1277 else
1278 m_fScrollOffsetY += fPosChanged;
1279 return TRUE;
1280 }
1281
1282 void CFWL_EditImp::UpdateVAlignment() {
1283 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1284 if (!pPage)
1285 return;
1286 const CFX_RectF& rtFDE = pPage->GetContentsBox();
1287 FX_FLOAT fOffsetY = 0.0f;
1288 FX_FLOAT fSpaceAbove = 0.0f;
1289 FX_FLOAT fSpaceBelow = 0.0f;
1290 CFX_SizeF* pSpace = static_cast<CFX_SizeF*>(
1291 GetThemeCapacity(CFWL_WidgetCapacity::SpaceAboveBelow));
1292 if (pSpace) {
1293 fSpaceAbove = pSpace->x;
1294 fSpaceBelow = pSpace->y;
1295 }
1296 if (fSpaceAbove < 0.1f) {
1297 fSpaceAbove = 0;
1298 }
1299 if (fSpaceBelow < 0.1f) {
1300 fSpaceBelow = 0;
1301 }
1302 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VCenter) {
1303 fOffsetY = (m_rtEngine.height - rtFDE.height) / 2;
1304 if (fOffsetY < (fSpaceAbove + fSpaceBelow) / 2 &&
1305 fSpaceAbove < fSpaceBelow) {
1306 return;
1307 }
1308 fOffsetY += (fSpaceAbove - fSpaceBelow) / 2;
1309 } else if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VFar) {
1310 fOffsetY = (m_rtEngine.height - rtFDE.height);
1311 fOffsetY -= fSpaceBelow;
1312 } else {
1313 fOffsetY += fSpaceAbove;
1314 }
1315 m_fVAlignOffset = fOffsetY;
1316 if (m_fVAlignOffset < 0) {
1317 m_fVAlignOffset = 0;
1318 }
1319 }
1320 void CFWL_EditImp::UpdateCaret() {
1321 CFX_RectF rtFDE;
1322 m_pEdtEngine->GetCaretRect(rtFDE);
1323 rtFDE.Offset(m_rtEngine.left - m_fScrollOffsetX,
1324 m_rtEngine.top - m_fScrollOffsetY + m_fVAlignOffset);
1325 CFX_RectF rtCaret;
1326 rtCaret.Set(rtFDE.left, rtFDE.top, rtFDE.width, rtFDE.height);
1327 CFX_RectF temp = rtCaret;
1328 CFX_RectF rtClient;
1329 GetClientRect(rtClient);
1330 rtCaret.Intersect(rtClient);
1331 if (rtCaret.left > rtClient.right()) {
1332 FX_FLOAT right = rtCaret.right();
1333 rtCaret.left = rtClient.right() - 1;
1334 rtCaret.width = right - rtCaret.left;
1335 }
1336 FX_BOOL bIntersect = !rtCaret.IsEmpty();
1337 FX_BOOL bShow = TRUE;
1338 FX_BOOL bShowWhole = FALSE;
1339 if (!(m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) || !bIntersect) {
1340 bShow = FALSE;
1341 }
1342 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_HSelfAdaption &&
1343 temp.right() > m_rtEngine.right()) {
1344 bShowWhole = TRUE;
1345 }
1346 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_VSelfAdaption &&
1347 temp.bottom() > m_rtEngine.bottom()) {
1348 bShowWhole = TRUE;
1349 } else {
1350 bShow = (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused && bIntersect);
1351 }
1352 if (bShowWhole) {
1353 rtCaret = temp;
1354 }
1355 ShowCaret(bShow, &rtCaret);
1356 }
1357 IFWL_ScrollBar* CFWL_EditImp::UpdateScroll() {
1358 FX_BOOL bShowHorz =
1359 m_pHorzScrollBar &&
1360 ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0);
1361 FX_BOOL bShowVert =
1362 m_pVertScrollBar &&
1363 ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Invisible) == 0);
1364 if (!bShowHorz && !bShowVert) {
1365 return nullptr;
1366 }
1367 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1368 if (!pPage)
1369 return nullptr;
1370 const CFX_RectF& rtFDE = pPage->GetContentsBox();
1371 IFWL_ScrollBar* pRepaint = nullptr;
1372 if (bShowHorz) {
1373 CFX_RectF rtScroll;
1374 m_pHorzScrollBar->GetWidgetRect(rtScroll);
1375 if (rtScroll.width < rtFDE.width) {
1376 m_pHorzScrollBar->LockUpdate();
1377 FX_FLOAT fRange = rtFDE.width - rtScroll.width;
1378 m_pHorzScrollBar->SetRange(0.0f, fRange);
1379 FX_FLOAT fPos = m_fScrollOffsetX;
1380 if (fPos < 0.0f) {
1381 fPos = 0.0f;
1382 }
1383 if (fPos > fRange) {
1384 fPos = fRange;
1385 }
1386 m_pHorzScrollBar->SetPos(fPos);
1387 m_pHorzScrollBar->SetTrackPos(fPos);
1388 m_pHorzScrollBar->SetPageSize(rtScroll.width);
1389 m_pHorzScrollBar->SetStepSize(rtScroll.width / 10);
1390 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, FALSE);
1391 m_pHorzScrollBar->UnlockUpdate();
1392 m_pHorzScrollBar->Update();
1393 pRepaint = m_pHorzScrollBar.get();
1394 } else if ((m_pHorzScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) {
1395 m_pHorzScrollBar->LockUpdate();
1396 m_pHorzScrollBar->SetRange(0, -1);
1397 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Disabled, TRUE);
1398 m_pHorzScrollBar->UnlockUpdate();
1399 m_pHorzScrollBar->Update();
1400 pRepaint = m_pHorzScrollBar.get();
1401 }
1402 }
1403 if (bShowVert) {
1404 CFX_RectF rtScroll;
1405 m_pVertScrollBar->GetWidgetRect(rtScroll);
1406 if (rtScroll.height < rtFDE.height) {
1407 m_pVertScrollBar->LockUpdate();
1408 FX_FLOAT fStep = m_pEdtEngine->GetEditParams()->fLineSpace;
1409 FX_FLOAT fRange = rtFDE.height - m_rtEngine.height;
1410 if (fRange < fStep) {
1411 fRange = fStep;
1412 }
1413 m_pVertScrollBar->SetRange(0.0f, fRange);
1414 FX_FLOAT fPos = m_fScrollOffsetY;
1415 if (fPos < 0.0f) {
1416 fPos = 0.0f;
1417 }
1418 if (fPos > fRange) {
1419 fPos = fRange;
1420 }
1421 m_pVertScrollBar->SetPos(fPos);
1422 m_pVertScrollBar->SetTrackPos(fPos);
1423 m_pVertScrollBar->SetPageSize(rtScroll.height);
1424 m_pVertScrollBar->SetStepSize(fStep);
1425 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, FALSE);
1426 m_pVertScrollBar->UnlockUpdate();
1427 m_pVertScrollBar->Update();
1428 pRepaint = m_pVertScrollBar.get();
1429 } else if ((m_pVertScrollBar->GetStates() & FWL_WGTSTATE_Disabled) == 0) {
1430 m_pVertScrollBar->LockUpdate();
1431 m_pVertScrollBar->SetRange(0, -1);
1432 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Disabled, TRUE);
1433 m_pVertScrollBar->UnlockUpdate();
1434 m_pVertScrollBar->Update();
1435 pRepaint = m_pVertScrollBar.get();
1436 }
1437 }
1438 return pRepaint;
1439 }
1440 FX_BOOL CFWL_EditImp::IsShowScrollBar(FX_BOOL bVert) {
1441 FX_BOOL bShow =
1442 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus)
1443 ? (m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) ==
1444 FWL_WGTSTATE_Focused
1445 : TRUE;
1446 if (bVert) {
1447 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_VScroll) &&
1448 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine) &&
1449 IsContentHeightOverflow();
1450 }
1451 return bShow && (m_pProperties->m_dwStyles & FWL_WGTSTYLE_HScroll) &&
1452 (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_MultiLine);
1453 }
1454 FX_BOOL CFWL_EditImp::IsContentHeightOverflow() {
1455 if (!m_pEdtEngine)
1456 return FALSE;
1457 IFDE_TxtEdtPage* pPage = m_pEdtEngine->GetPage(0);
1458 if (!pPage)
1459 return FALSE;
1460 return pPage->GetContentsBox().height > m_rtEngine.height + 1.0f;
1461 }
1462 int32_t CFWL_EditImp::AddDoRecord(IFDE_TxtEdtDoRecord* pRecord) {
1463 int32_t nCount = pdfium::CollectionSize<int32_t>(m_DoRecords);
1464 if (m_iCurRecord == nCount - 1) {
1465 if (nCount == m_iMaxRecord) {
1466 m_DoRecords.pop_front();
1467 m_iCurRecord--;
1468 }
1469 } else {
1470 m_DoRecords.erase(m_DoRecords.begin() + m_iCurRecord + 1,
1471 m_DoRecords.end());
1472 }
1473
1474 m_DoRecords.push_back(std::unique_ptr<IFDE_TxtEdtDoRecord>(pRecord));
1475 m_iCurRecord = pdfium::CollectionSize<int32_t>(m_DoRecords) - 1;
1476 return m_iCurRecord;
1477 }
1478 void CFWL_EditImp::Layout() {
1479 GetClientRect(m_rtClient);
1480 m_rtEngine = m_rtClient;
1481 FX_FLOAT* pfWidth = static_cast<FX_FLOAT*>(
1482 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
1483 if (!pfWidth)
1484 return;
1485 FX_FLOAT fWidth = *pfWidth;
1486 if (!m_pOuter) {
1487 CFX_RectF* pUIMargin = static_cast<CFX_RectF*>(
1488 GetThemeCapacity(CFWL_WidgetCapacity::UIMargin));
1489 if (pUIMargin) {
1490 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width,
1491 pUIMargin->height);
1492 }
1493 } else if (m_pOuter->GetClassID() == FWL_Type::DateTimePicker) {
1494 CFWL_ThemePart part;
1495 part.m_pWidget = m_pOuter;
1496 CFX_RectF* pUIMargin =
1497 static_cast<CFX_RectF*>(m_pOuter->GetThemeProvider()->GetCapacity(
1498 &part, CFWL_WidgetCapacity::UIMargin));
1499 if (pUIMargin) {
1500 m_rtEngine.Deflate(pUIMargin->left, pUIMargin->top, pUIMargin->width,
1501 pUIMargin->height);
1502 }
1503 }
1504 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE);
1505 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE);
1506 if (bShowVertScrollbar) {
1507 InitScrollBar();
1508 CFX_RectF rtVertScr;
1509 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
1510 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth,
1511 m_rtClient.height);
1512 } else {
1513 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth,
1514 m_rtClient.height);
1515 if (bShowHorzScrollbar) {
1516 rtVertScr.height -= fWidth;
1517 }
1518 m_rtEngine.width -= fWidth;
1519 }
1520 m_pVertScrollBar->SetWidgetRect(rtVertScr);
1521 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE);
1522 m_pVertScrollBar->Update();
1523 } else if (m_pVertScrollBar) {
1524 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE);
1525 }
1526 if (bShowHorzScrollbar) {
1527 InitScrollBar(FALSE);
1528 CFX_RectF rtHoriScr;
1529 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
1530 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin,
1531 m_rtClient.width, fWidth);
1532 } else {
1533 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth,
1534 m_rtClient.width, fWidth);
1535 if (bShowVertScrollbar) {
1536 rtHoriScr.width -= fWidth;
1537 }
1538 m_rtEngine.height -= fWidth;
1539 }
1540 m_pHorzScrollBar->SetWidgetRect(rtHoriScr);
1541 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE);
1542 m_pHorzScrollBar->Update();
1543 } else if (m_pHorzScrollBar) {
1544 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE);
1545 }
1546 }
1547 void CFWL_EditImp::LayoutScrollBar() {
1548 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ShowScrollbarFocus) ==
1549 0) {
1550 return;
1551 }
1552 FX_FLOAT* pfWidth = nullptr;
1553 FX_BOOL bShowVertScrollbar = IsShowScrollBar(TRUE);
1554 FX_BOOL bShowHorzScrollbar = IsShowScrollBar(FALSE);
1555 if (bShowVertScrollbar) {
1556 if (!m_pVertScrollBar) {
1557 pfWidth = static_cast<FX_FLOAT*>(
1558 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
1559 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0;
1560 InitScrollBar();
1561 CFX_RectF rtVertScr;
1562 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
1563 rtVertScr.Set(m_rtClient.right() + kEditMargin, m_rtClient.top, fWidth,
1564 m_rtClient.height);
1565 } else {
1566 rtVertScr.Set(m_rtClient.right() - fWidth, m_rtClient.top, fWidth,
1567 m_rtClient.height);
1568 if (bShowHorzScrollbar) {
1569 rtVertScr.height -= fWidth;
1570 }
1571 }
1572 m_pVertScrollBar->SetWidgetRect(rtVertScr);
1573 m_pVertScrollBar->Update();
1574 }
1575 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE);
1576 } else if (m_pVertScrollBar) {
1577 m_pVertScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE);
1578 }
1579 if (bShowHorzScrollbar) {
1580 if (!m_pHorzScrollBar) {
1581 if (!pfWidth) {
1582 pfWidth = static_cast<FX_FLOAT*>(
1583 GetThemeCapacity(CFWL_WidgetCapacity::ScrollBarWidth));
1584 }
1585 FX_FLOAT fWidth = pfWidth ? *pfWidth : 0;
1586 InitScrollBar(FALSE);
1587 CFX_RectF rtHoriScr;
1588 if (m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_OuterScrollbar) {
1589 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() + kEditMargin,
1590 m_rtClient.width, fWidth);
1591 } else {
1592 rtHoriScr.Set(m_rtClient.left, m_rtClient.bottom() - fWidth,
1593 m_rtClient.width, fWidth);
1594 if (bShowVertScrollbar) {
1595 rtHoriScr.width -= (fWidth);
1596 }
1597 }
1598 m_pHorzScrollBar->SetWidgetRect(rtHoriScr);
1599 m_pHorzScrollBar->Update();
1600 }
1601 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, FALSE);
1602 } else if (m_pHorzScrollBar) {
1603 m_pHorzScrollBar->SetStates(FWL_WGTSTATE_Invisible, TRUE);
1604 }
1605 if (bShowVertScrollbar || bShowHorzScrollbar) {
1606 UpdateScroll();
1607 }
1608 }
1609
1610 void CFWL_EditImp::DeviceToEngine(CFX_PointF& pt) {
1611 pt.x += m_fScrollOffsetX - m_rtEngine.left;
1612 pt.y += m_fScrollOffsetY - m_rtEngine.top - m_fVAlignOffset;
1613 }
1614
1615 void CFWL_EditImp::InitScrollBar(FX_BOOL bVert) {
1616 if ((bVert && m_pVertScrollBar) || (!bVert && m_pHorzScrollBar)) {
1617 return;
1618 }
1619 CFWL_WidgetImpProperties prop;
1620 prop.m_dwStyleExes = bVert ? FWL_STYLEEXT_SCB_Vert : FWL_STYLEEXT_SCB_Horz;
1621 prop.m_dwStates = FWL_WGTSTATE_Disabled | FWL_WGTSTATE_Invisible;
1622 prop.m_pParent = m_pInterface;
1623 prop.m_pThemeProvider = m_pProperties->m_pThemeProvider;
1624 IFWL_ScrollBar* pScrollBar = IFWL_ScrollBar::Create(prop, m_pInterface);
1625 pScrollBar->Initialize();
1626 (bVert ? &m_pVertScrollBar : &m_pHorzScrollBar)->reset(pScrollBar);
1627 }
1628
1629 void CFWL_EditImp::InitEngine() {
1630 if (!m_pEdtEngine)
1631 m_pEdtEngine.reset(new CFDE_TxtEdtEngine);
1632 }
1633
1634 FX_BOOL FWL_ShowCaret(IFWL_Widget* pWidget,
1635 FX_BOOL bVisible,
1636 const CFX_RectF* pRtAnchor) {
1637 CXFA_FFWidget* pXFAWidget =
1638 static_cast<CXFA_FFWidget*>(pWidget->GetLayoutItem());
1639 if (!pXFAWidget)
1640 return FALSE;
1641
1642 IXFA_DocEnvironment* pDocEnvironment =
1643 pXFAWidget->GetDoc()->GetDocEnvironment();
1644 if (!pDocEnvironment)
1645 return FALSE;
1646
1647 if (bVisible) {
1648 CFX_Matrix mt;
1649 pXFAWidget->GetRotateMatrix(mt);
1650 CFX_RectF rt(*pRtAnchor);
1651 mt.TransformRect(rt);
1652 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, &rt);
1653 return TRUE;
1654 }
1655 pDocEnvironment->DisplayCaret(pXFAWidget, bVisible, pRtAnchor);
1656 return TRUE;
1657 }
1658
1659 void CFWL_EditImp::ShowCaret(FX_BOOL bVisible, CFX_RectF* pRect) {
1660 if (m_pCaret) {
1661 m_pCaret->ShowCaret(bVisible);
1662 if (bVisible && !pRect->IsEmpty()) {
1663 m_pCaret->SetWidgetRect(*pRect);
1664 }
1665 Repaint(&m_rtEngine);
1666 } else {
1667 IFWL_Widget* pOuter = m_pInterface;
1668 if (bVisible) {
1669 pRect->Offset(m_pProperties->m_rtWidget.left,
1670 m_pProperties->m_rtWidget.top);
1671 }
1672 while (pOuter->GetOuter()) {
1673 pOuter = pOuter->GetOuter();
1674 if (bVisible) {
1675 CFX_RectF rtOuter;
1676 pOuter->GetWidgetRect(rtOuter);
1677 pRect->Offset(rtOuter.left, rtOuter.top);
1678 }
1679 }
1680 FWL_ShowCaret(pOuter, bVisible, pRect);
1681 }
1682 }
1683 FX_BOOL CFWL_EditImp::ValidateNumberChar(FX_WCHAR cNum) {
1684 if (!m_pEdtEngine) {
1685 return FALSE;
1686 }
1687 if (!m_bSetRange) {
1688 return TRUE;
1689 }
1690 CFX_WideString wsOld, wsText;
1691 m_pEdtEngine->GetText(wsText, 0);
1692 if (wsText.IsEmpty()) {
1693 if (cNum == L'0') {
1694 return FALSE;
1695 }
1696 return TRUE;
1697 }
1698 int32_t caretPos = m_pEdtEngine->GetCaretPos();
1699 int32_t iSel = CountSelRanges();
1700 if (iSel == 0) {
1701 if (cNum == L'0' && caretPos == 0) {
1702 return FALSE;
1703 }
1704 int32_t nLen = wsText.GetLength();
1705 CFX_WideString l = wsText.Mid(0, caretPos);
1706 CFX_WideString r = wsText.Mid(caretPos, nLen - caretPos);
1707 CFX_WideString wsNew = l + cNum + r;
1708 if (wsNew.GetInteger() <= m_iMax) {
1709 return TRUE;
1710 }
1711 } else {
1712 if (wsText.GetInteger() <= m_iMax) {
1713 return TRUE;
1714 }
1715 }
1716 return FALSE;
1717 }
1718 void CFWL_EditImp::InitCaret() {
1719 if (!m_pCaret) {
1720 if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret)) {
1721 CFWL_WidgetImpProperties prop;
1722 m_pCaret.reset(IFWL_Caret::Create(prop, m_pInterface));
1723 m_pCaret->Initialize();
1724 m_pCaret->SetParent(m_pInterface);
1725 m_pCaret->SetStates(m_pProperties->m_dwStates);
1726 }
1727 } else if ((m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_InnerCaret) ==
1728 0) {
1729 m_pCaret.reset();
1730 }
1731 }
1732
1733 void CFWL_EditImp::ClearRecord() {
1734 m_iCurRecord = -1;
1735 m_DoRecords.clear();
1736 }
1737
1738 void CFWL_EditImp::ProcessInsertError(int32_t iError) {
1739 switch (iError) {
1740 case -2: {
1741 CFWL_EvtEdtTextFull textFullEvent;
1742 textFullEvent.m_pSrcTarget = m_pInterface;
1743 DispatchEvent(&textFullEvent);
1744 break;
1745 }
1746 default: {}
1747 }
1748 }
1749
1750 CFWL_EditImpDelegate::CFWL_EditImpDelegate(CFWL_EditImp* pOwner)
1751 : m_pOwner(pOwner) {}
1752
1753 void CFWL_EditImpDelegate::OnProcessMessage(CFWL_Message* pMessage) {
1754 if (!pMessage)
1755 return;
1756
1757 CFWL_MessageType dwMsgCode = pMessage->GetClassID();
1758 switch (dwMsgCode) {
1759 case CFWL_MessageType::Activate: {
1760 DoActivate(static_cast<CFWL_MsgActivate*>(pMessage));
1761 break;
1762 }
1763 case CFWL_MessageType::Deactivate: {
1764 DoDeactivate(static_cast<CFWL_MsgDeactivate*>(pMessage));
1765 break;
1766 }
1767 case CFWL_MessageType::SetFocus:
1768 case CFWL_MessageType::KillFocus: {
1769 OnFocusChanged(pMessage, dwMsgCode == CFWL_MessageType::SetFocus);
1770 break;
1771 }
1772 case CFWL_MessageType::Mouse: {
1773 CFWL_MsgMouse* pMsg = static_cast<CFWL_MsgMouse*>(pMessage);
1774 switch (pMsg->m_dwCmd) {
1775 case FWL_MouseCommand::LeftButtonDown: {
1776 OnLButtonDown(pMsg);
1777 break;
1778 }
1779 case FWL_MouseCommand::LeftButtonUp: {
1780 OnLButtonUp(pMsg);
1781 break;
1782 }
1783 case FWL_MouseCommand::LeftButtonDblClk: {
1784 OnButtonDblClk(pMsg);
1785 break;
1786 }
1787 case FWL_MouseCommand::Move: {
1788 OnMouseMove(pMsg);
1789 break;
1790 }
1791 case FWL_MouseCommand::RightButtonDown: {
1792 DoButtonDown(pMsg);
1793 break;
1794 }
1795 default:
1796 break;
1797 }
1798 break;
1799 }
1800 case CFWL_MessageType::Key: {
1801 CFWL_MsgKey* pKey = static_cast<CFWL_MsgKey*>(pMessage);
1802 if (pKey->m_dwCmd == FWL_KeyCommand::KeyDown)
1803 OnKeyDown(pKey);
1804 else if (pKey->m_dwCmd == FWL_KeyCommand::Char)
1805 OnChar(pKey);
1806 break;
1807 }
1808 default: {
1809 break;
1810 }
1811 }
1812 CFWL_WidgetImpDelegate::OnProcessMessage(pMessage);
1813 }
1814
1815 void CFWL_EditImpDelegate::OnProcessEvent(CFWL_Event* pEvent) {
1816 if (!pEvent)
1817 return;
1818 if (pEvent->GetClassID() != CFWL_EventType::Scroll)
1819 return;
1820
1821 IFWL_Widget* pSrcTarget = pEvent->m_pSrcTarget;
1822 if ((pSrcTarget == m_pOwner->m_pVertScrollBar.get() &&
1823 m_pOwner->m_pVertScrollBar) ||
1824 (pSrcTarget == m_pOwner->m_pHorzScrollBar.get() &&
1825 m_pOwner->m_pHorzScrollBar)) {
1826 CFWL_EvtScroll* pScrollEvent = static_cast<CFWL_EvtScroll*>(pEvent);
1827 OnScroll(static_cast<IFWL_ScrollBar*>(pSrcTarget),
1828 pScrollEvent->m_iScrollCode, pScrollEvent->m_fPos);
1829 }
1830 }
1831
1832 void CFWL_EditImpDelegate::OnDrawWidget(CFX_Graphics* pGraphics,
1833 const CFX_Matrix* pMatrix) {
1834 m_pOwner->DrawWidget(pGraphics, pMatrix);
1835 }
1836
1837 void CFWL_EditImpDelegate::DoActivate(CFWL_MsgActivate* pMsg) {
1838 m_pOwner->m_pProperties->m_dwStates |= ~FWL_WGTSTATE_Deactivated;
1839 m_pOwner->Repaint(&m_pOwner->m_rtClient);
1840 }
1841 void CFWL_EditImpDelegate::DoDeactivate(CFWL_MsgDeactivate* pMsg) {
1842 m_pOwner->m_pProperties->m_dwStates &= FWL_WGTSTATE_Deactivated;
1843 m_pOwner->Repaint(&m_pOwner->m_rtClient);
1844 }
1845 void CFWL_EditImpDelegate::DoButtonDown(CFWL_MsgMouse* pMsg) {
1846 if ((m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) == 0) {
1847 m_pOwner->SetFocus(TRUE);
1848 }
1849 if (!m_pOwner->m_pEdtEngine) {
1850 m_pOwner->UpdateEditEngine();
1851 }
1852 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0);
1853 if (!pPage)
1854 return;
1855 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy);
1856 m_pOwner->DeviceToEngine(pt);
1857 FX_BOOL bBefore = TRUE;
1858 int32_t nIndex = pPage->GetCharIndex(pt, bBefore);
1859 if (nIndex < 0) {
1860 nIndex = 0;
1861 }
1862 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex, bBefore);
1863 }
1864 void CFWL_EditImpDelegate::OnFocusChanged(CFWL_Message* pMsg, FX_BOOL bSet) {
1865 uint32_t dwStyleEx = m_pOwner->GetStylesEx();
1866 bool bRepaint = !!(dwStyleEx & FWL_STYLEEXT_EDT_InnerCaret);
1867 if (bSet) {
1868 m_pOwner->m_pProperties->m_dwStates |= FWL_WGTSTATE_Focused;
1869 if (!m_pOwner->m_pEdtEngine) {
1870 m_pOwner->UpdateEditEngine();
1871 }
1872 m_pOwner->UpdateVAlignment();
1873 m_pOwner->UpdateOffset();
1874 m_pOwner->UpdateCaret();
1875 } else if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Focused) {
1876 m_pOwner->m_pProperties->m_dwStates &= ~FWL_WGTSTATE_Focused;
1877 m_pOwner->ShowCaret(FALSE);
1878 if (m_pOwner->m_pEdtEngine &&
1879 (dwStyleEx & FWL_STYLEEXT_EDT_NoHideSel) == 0) {
1880 int32_t nSel = m_pOwner->CountSelRanges();
1881 if (nSel > 0) {
1882 m_pOwner->ClearSelections();
1883 bRepaint = TRUE;
1884 }
1885 m_pOwner->SetCaretPos(0);
1886 m_pOwner->UpdateOffset();
1887 }
1888 m_pOwner->ClearRecord();
1889 }
1890 m_pOwner->LayoutScrollBar();
1891 if (bRepaint) {
1892 CFX_RectF rtInvalidate;
1893 rtInvalidate.Set(0, 0, m_pOwner->m_pProperties->m_rtWidget.width,
1894 m_pOwner->m_pProperties->m_rtWidget.height);
1895 m_pOwner->Repaint(&rtInvalidate);
1896 }
1897 }
1898 void CFWL_EditImpDelegate::OnLButtonDown(CFWL_MsgMouse* pMsg) {
1899 DoCursor(pMsg);
1900 if (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled) {
1901 return;
1902 }
1903 m_pOwner->m_bLButtonDown = TRUE;
1904 m_pOwner->SetGrab(TRUE);
1905 DoButtonDown(pMsg);
1906 int32_t nIndex = m_pOwner->m_pEdtEngine->GetCaretPos();
1907 FX_BOOL bRepaint = FALSE;
1908 int32_t iCount = m_pOwner->m_pEdtEngine->CountSelRanges();
1909 if (iCount > 0) {
1910 m_pOwner->m_pEdtEngine->ClearSelection();
1911 bRepaint = TRUE;
1912 }
1913 FX_BOOL bShift = pMsg->m_dwFlags & FWL_KEYFLAG_Shift;
1914 if (bShift && m_pOwner->m_nSelStart != nIndex) {
1915 int32_t iStart = std::min(m_pOwner->m_nSelStart, nIndex);
1916 int32_t iEnd = std::max(m_pOwner->m_nSelStart, nIndex);
1917 m_pOwner->m_pEdtEngine->AddSelRange(iStart, iEnd - iStart);
1918 bRepaint = TRUE;
1919 } else {
1920 m_pOwner->m_nSelStart = nIndex;
1921 }
1922 if (bRepaint) {
1923 m_pOwner->Repaint(&m_pOwner->m_rtEngine);
1924 }
1925 }
1926 void CFWL_EditImpDelegate::OnLButtonUp(CFWL_MsgMouse* pMsg) {
1927 DoCursor(pMsg);
1928 m_pOwner->m_bLButtonDown = FALSE;
1929 m_pOwner->SetGrab(FALSE);
1930 }
1931 void CFWL_EditImpDelegate::OnButtonDblClk(CFWL_MsgMouse* pMsg) {
1932 if (!m_pOwner->m_pEdtEngine)
1933 return;
1934 DoCursor(pMsg);
1935 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0);
1936 if (!pPage)
1937 return;
1938 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy);
1939 m_pOwner->DeviceToEngine(pt);
1940 int32_t nCount = 0;
1941 int32_t nIndex = pPage->SelectWord(pt, nCount);
1942 if (nIndex < 0) {
1943 return;
1944 }
1945 m_pOwner->m_pEdtEngine->AddSelRange(nIndex, nCount);
1946 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex + nCount - 1, FALSE);
1947 m_pOwner->Repaint(&m_pOwner->m_rtEngine);
1948 }
1949 void CFWL_EditImpDelegate::OnMouseMove(CFWL_MsgMouse* pMsg) {
1950 if (!m_pOwner->m_pEdtEngine)
1951 return;
1952 DoCursor(pMsg);
1953 if (m_pOwner->m_nSelStart == -1 || !m_pOwner->m_bLButtonDown) {
1954 return;
1955 }
1956 IFDE_TxtEdtPage* pPage = m_pOwner->m_pEdtEngine->GetPage(0);
1957 if (!pPage)
1958 return;
1959 CFX_PointF pt(pMsg->m_fx, pMsg->m_fy);
1960 m_pOwner->DeviceToEngine(pt);
1961 FX_BOOL bBefore = TRUE;
1962 int32_t nIndex = pPage->GetCharIndex(pt, bBefore);
1963 m_pOwner->m_pEdtEngine->SetCaretPos(nIndex, bBefore);
1964 nIndex = m_pOwner->m_pEdtEngine->GetCaretPos();
1965 m_pOwner->m_pEdtEngine->ClearSelection();
1966 if (nIndex != m_pOwner->m_nSelStart) {
1967 int32_t nLen = m_pOwner->m_pEdtEngine->GetTextLength();
1968 if (m_pOwner->m_nSelStart >= nLen) {
1969 m_pOwner->m_nSelStart = nLen;
1970 }
1971 m_pOwner->m_pEdtEngine->AddSelRange(
1972 std::min(m_pOwner->m_nSelStart, nIndex),
1973 FXSYS_abs(nIndex - m_pOwner->m_nSelStart));
1974 }
1975 }
1976 void CFWL_EditImpDelegate::OnKeyDown(CFWL_MsgKey* pMsg) {
1977 if (!m_pOwner->m_pEdtEngine)
1978 return;
1979 FDE_TXTEDTMOVECARET MoveCaret = MC_MoveNone;
1980 FX_BOOL bShift = pMsg->m_dwFlags & FWL_KEYFLAG_Shift;
1981 FX_BOOL bCtrl = pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl;
1982 uint32_t dwKeyCode = pMsg->m_dwKeyCode;
1983 switch (dwKeyCode) {
1984 case FWL_VKEY_Left: {
1985 MoveCaret = MC_Left;
1986 break;
1987 }
1988 case FWL_VKEY_Right: {
1989 MoveCaret = MC_Right;
1990 break;
1991 }
1992 case FWL_VKEY_Up: {
1993 MoveCaret = MC_Up;
1994 break;
1995 }
1996 case FWL_VKEY_Down: {
1997 MoveCaret = MC_Down;
1998 break;
1999 }
2000 case FWL_VKEY_Home: {
2001 if (bCtrl) {
2002 MoveCaret = MC_Home;
2003 } else {
2004 MoveCaret = MC_LineStart;
2005 }
2006 break;
2007 }
2008 case FWL_VKEY_End: {
2009 if (bCtrl) {
2010 MoveCaret = MC_End;
2011 } else {
2012 MoveCaret = MC_LineEnd;
2013 }
2014 break;
2015 }
2016 case FWL_VKEY_Insert: {
2017 break;
2018 }
2019 case FWL_VKEY_Delete: {
2020 if ((m_pOwner->m_pProperties->m_dwStyleExes &
2021 FWL_STYLEEXT_EDT_ReadOnly) ||
2022 (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
2023 break;
2024 }
2025 int32_t nCaret = m_pOwner->m_pEdtEngine->GetCaretPos();
2026 #if (_FX_OS_ == _FX_MACOSX_)
2027 m_pOwner->m_pEdtEngine->Delete(nCaret, TRUE);
2028 #else
2029 m_pOwner->m_pEdtEngine->Delete(nCaret);
2030 #endif
2031 break;
2032 }
2033 case FWL_VKEY_F2: {
2034 break;
2035 }
2036 case FWL_VKEY_Tab: {
2037 m_pOwner->DispatchKeyEvent(pMsg);
2038 break;
2039 }
2040 default: {
2041 #if (_FX_OS_ == _FX_MACOSX_)
2042 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command) {
2043 #else
2044 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl) {
2045 #endif
2046 if (dwKeyCode == 0x43 || dwKeyCode == 0x63) {
2047 m_pOwner->DoClipboard(1);
2048 return;
2049 }
2050 if (dwKeyCode == 0x58 || dwKeyCode == 0x78) {
2051 m_pOwner->DoClipboard(2);
2052 return;
2053 }
2054 if (dwKeyCode == 0x56 || dwKeyCode == 0x76) {
2055 m_pOwner->DoClipboard(3);
2056 return;
2057 }
2058 }
2059 }
2060 }
2061 if (MoveCaret != MC_MoveNone) {
2062 m_pOwner->m_pEdtEngine->MoveCaretPos(MoveCaret, bShift, bCtrl);
2063 }
2064 }
2065 void CFWL_EditImpDelegate::OnChar(CFWL_MsgKey* pMsg) {
2066 if ((m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_ReadOnly) ||
2067 (m_pOwner->m_pProperties->m_dwStates & FWL_WGTSTATE_Disabled)) {
2068 return;
2069 }
2070 if (!m_pOwner->m_pEdtEngine)
2071 return;
2072 int32_t iError = 0;
2073 FX_WCHAR c = (FX_WCHAR)pMsg->m_dwKeyCode;
2074 int32_t nCaret = m_pOwner->m_pEdtEngine->GetCaretPos();
2075 switch (c) {
2076 case FWL_VKEY_Back: {
2077 m_pOwner->m_pEdtEngine->Delete(nCaret, TRUE);
2078 break;
2079 }
2080 case 0x0A: {
2081 break;
2082 }
2083 case FWL_VKEY_Escape: {
2084 break;
2085 }
2086 case FWL_VKEY_Tab: {
2087 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, L"\t", 1);
2088 break;
2089 }
2090 case FWL_VKEY_Return: {
2091 if (m_pOwner->m_pProperties->m_dwStyleExes &
2092 FWL_STYLEEXT_EDT_WantReturn) {
2093 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, L"\n", 1);
2094 }
2095 break;
2096 }
2097 default: {
2098 if (!m_pOwner->m_pWidgetMgr->IsFormDisabled()) {
2099 if (m_pOwner->m_pProperties->m_dwStyleExes & FWL_STYLEEXT_EDT_Number) {
2100 if (((pMsg->m_dwKeyCode < FWL_VKEY_0) &&
2101 (pMsg->m_dwKeyCode != 0x2E && pMsg->m_dwKeyCode != 0x2D)) ||
2102 pMsg->m_dwKeyCode > FWL_VKEY_9) {
2103 break;
2104 }
2105 if (!m_pOwner->ValidateNumberChar(c)) {
2106 break;
2107 }
2108 }
2109 }
2110 #if (_FX_OS_ == _FX_MACOSX_)
2111 if (pMsg->m_dwFlags & FWL_KEYFLAG_Command)
2112 #else
2113 if (pMsg->m_dwFlags & FWL_KEYFLAG_Ctrl)
2114 #endif
2115 {
2116 break;
2117 }
2118 iError = m_pOwner->m_pEdtEngine->Insert(nCaret, &c, 1);
2119 break;
2120 }
2121 }
2122 if (iError < 0) {
2123 m_pOwner->ProcessInsertError(iError);
2124 }
2125 }
2126 FX_BOOL CFWL_EditImpDelegate::OnScroll(IFWL_ScrollBar* pScrollBar,
2127 uint32_t dwCode,
2128 FX_FLOAT fPos) {
2129 CFX_SizeF fs;
2130 pScrollBar->GetRange(fs.x, fs.y);
2131 FX_FLOAT iCurPos = pScrollBar->GetPos();
2132 FX_FLOAT fStep = pScrollBar->GetStepSize();
2133 switch (dwCode) {
2134 case FWL_SCBCODE_Min: {
2135 fPos = fs.x;
2136 break;
2137 }
2138 case FWL_SCBCODE_Max: {
2139 fPos = fs.y;
2140 break;
2141 }
2142 case FWL_SCBCODE_StepBackward: {
2143 fPos -= fStep;
2144 if (fPos < fs.x + fStep / 2) {
2145 fPos = fs.x;
2146 }
2147 break;
2148 }
2149 case FWL_SCBCODE_StepForward: {
2150 fPos += fStep;
2151 if (fPos > fs.y - fStep / 2) {
2152 fPos = fs.y;
2153 }
2154 break;
2155 }
2156 case FWL_SCBCODE_PageBackward: {
2157 fPos -= pScrollBar->GetPageSize();
2158 if (fPos < fs.x) {
2159 fPos = fs.x;
2160 }
2161 break;
2162 }
2163 case FWL_SCBCODE_PageForward: {
2164 fPos += pScrollBar->GetPageSize();
2165 if (fPos > fs.y) {
2166 fPos = fs.y;
2167 }
2168 break;
2169 }
2170 case FWL_SCBCODE_Pos:
2171 case FWL_SCBCODE_TrackPos: {
2172 break;
2173 }
2174 case FWL_SCBCODE_EndScroll: {
2175 return FALSE;
2176 }
2177 default: {}
2178 }
2179 if (iCurPos != fPos) {
2180 pScrollBar->SetPos(fPos);
2181 pScrollBar->SetTrackPos(fPos);
2182 m_pOwner->UpdateOffset(pScrollBar, fPos - iCurPos);
2183 if (m_pOwner->m_pEdtEngine) {
2184 m_pOwner->UpdateCaret();
2185 }
2186 CFX_RectF rect;
2187 m_pOwner->GetWidgetRect(rect);
2188 CFX_RectF rtInvalidate;
2189 rtInvalidate.Set(0, 0, rect.width + 2, rect.height + 2);
2190 m_pOwner->Repaint(&rtInvalidate);
2191 }
2192 return TRUE;
2193 }
2194 void CFWL_EditImpDelegate::DoCursor(CFWL_MsgMouse* pMsg) {}
OLDNEW
« no previous file with comments | « xfa/fwl/basewidget/fwl_editimp.h ('k') | xfa/fwl/basewidget/fwl_formproxyimp.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698