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/fde/cfde_txtedtengine.h" | 7 #include "xfa/fde/cfde_txtedtengine.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return 0; | 198 return 0; |
199 } | 199 } |
200 m_bBefore = bBefore; | 200 m_bBefore = bBefore; |
201 m_nCaret = nIndex; | 201 m_nCaret = nIndex; |
202 MovePage2Char(m_nCaret); | 202 MovePage2Char(m_nCaret); |
203 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); | 203 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); |
204 if (!m_bBefore) { | 204 if (!m_bBefore) { |
205 m_nCaret++; | 205 m_nCaret++; |
206 m_bBefore = true; | 206 m_bBefore = true; |
207 } | 207 } |
208 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) | 208 m_fCaretPosReserve = m_rtCaret.left; |
209 ? m_rtCaret.top | |
210 : m_rtCaret.left; | |
211 m_Param.pEventSink->OnCaretChanged(); | 209 m_Param.pEventSink->OnCaretChanged(); |
212 m_nAnchorPos = -1; | 210 m_nAnchorPos = -1; |
213 return m_nCaret; | 211 return m_nCaret; |
214 } | 212 } |
215 | 213 |
216 int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, | 214 int32_t CFDE_TxtEdtEngine::MoveCaretPos(FDE_TXTEDTMOVECARET eMoveCaret, |
217 bool bShift, | 215 bool bShift, |
218 bool bCtrl) { | 216 bool bCtrl) { |
219 if (IsLocked()) { | 217 if (IsLocked()) { |
220 return 0; | 218 return 0; |
221 } | 219 } |
222 if (m_PagePtrArray.GetSize() <= m_nCaretPage) { | 220 if (m_PagePtrArray.GetSize() <= m_nCaretPage) { |
223 return 0; | 221 return 0; |
224 } | 222 } |
225 bool bSelChange = false; | 223 bool bSelChange = false; |
226 if (IsSelect()) { | 224 if (IsSelect()) { |
227 ClearSelection(); | 225 ClearSelection(); |
228 bSelChange = true; | 226 bSelChange = true; |
229 } | 227 } |
230 if (bShift) { | 228 if (bShift) { |
231 if (m_nAnchorPos == -1) { | 229 if (m_nAnchorPos == -1) { |
232 m_nAnchorPos = m_nCaret; | 230 m_nAnchorPos = m_nCaret; |
233 } | 231 } |
234 } else { | 232 } else { |
235 m_nAnchorPos = -1; | 233 m_nAnchorPos = -1; |
236 } | 234 } |
237 bool bVertical = m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical; | 235 |
238 switch (eMoveCaret) { | 236 switch (eMoveCaret) { |
239 case MC_Left: { | 237 case MC_Left: { |
240 if (bVertical) { | 238 bool bBefore = true; |
241 CFX_PointF ptCaret; | 239 int32_t nIndex = MoveBackward(bBefore); |
242 if (MoveUp(ptCaret)) { | 240 if (nIndex >= 0) { |
243 UpdateCaretIndex(ptCaret); | 241 UpdateCaretRect(nIndex, bBefore); |
244 } | |
245 } else { | |
246 bool bBefore = true; | |
247 int32_t nIndex = MoveBackward(bBefore); | |
248 if (nIndex >= 0) { | |
249 UpdateCaretRect(nIndex, bBefore); | |
250 } | |
251 } | 242 } |
252 } break; | 243 break; |
| 244 } |
253 case MC_Right: { | 245 case MC_Right: { |
254 if (bVertical) { | 246 bool bBefore = true; |
255 CFX_PointF ptCaret; | 247 int32_t nIndex = MoveForward(bBefore); |
256 if (MoveDown(ptCaret)) { | 248 if (nIndex >= 0) { |
257 UpdateCaretIndex(ptCaret); | 249 UpdateCaretRect(nIndex, bBefore); |
258 } | |
259 } else { | |
260 bool bBefore = true; | |
261 int32_t nIndex = MoveForward(bBefore); | |
262 if (nIndex >= 0) { | |
263 UpdateCaretRect(nIndex, bBefore); | |
264 } | |
265 } | 250 } |
266 } break; | 251 break; |
| 252 } |
267 case MC_Up: { | 253 case MC_Up: { |
268 if (bVertical) { | 254 CFX_PointF ptCaret; |
269 bool bBefore = true; | 255 if (MoveUp(ptCaret)) { |
270 int32_t nIndex = MoveBackward(bBefore); | 256 UpdateCaretIndex(ptCaret); |
271 if (nIndex >= 0) { | |
272 UpdateCaretRect(nIndex, bBefore); | |
273 } | |
274 } else { | |
275 CFX_PointF ptCaret; | |
276 if (MoveUp(ptCaret)) { | |
277 UpdateCaretIndex(ptCaret); | |
278 } | |
279 } | 257 } |
280 } break; | 258 break; |
| 259 } |
281 case MC_Down: { | 260 case MC_Down: { |
282 if (bVertical) { | 261 CFX_PointF ptCaret; |
283 bool bBefore = true; | 262 if (MoveDown(ptCaret)) { |
284 int32_t nIndex = MoveForward(bBefore); | 263 UpdateCaretIndex(ptCaret); |
285 if (nIndex >= 0) { | |
286 UpdateCaretRect(nIndex, bBefore); | |
287 } | |
288 } else { | |
289 CFX_PointF ptCaret; | |
290 if (MoveDown(ptCaret)) { | |
291 UpdateCaretIndex(ptCaret); | |
292 } | |
293 } | 264 } |
294 } break; | 265 break; |
| 266 } |
295 case MC_WordBackward: | 267 case MC_WordBackward: |
296 break; | 268 break; |
297 case MC_WordForward: | 269 case MC_WordForward: |
298 break; | 270 break; |
299 case MC_LineStart: | 271 case MC_LineStart: |
300 MoveLineStart(); | 272 MoveLineStart(); |
301 break; | 273 break; |
302 case MC_LineEnd: | 274 case MC_LineEnd: |
303 MoveLineEnd(); | 275 MoveLineEnd(); |
304 break; | 276 break; |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 378 } |
407 } | 379 } |
408 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 380 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
409 CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); | 381 CFX_WideString wsText = GetPreInsertText(m_nCaret, lpBuffer, nLength); |
410 if (!m_Param.pEventSink->OnValidate(wsText)) | 382 if (!m_Param.pEventSink->OnValidate(wsText)) |
411 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 383 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
412 } | 384 } |
413 if (IsSelect()) { | 385 if (IsSelect()) { |
414 DeleteSelect(); | 386 DeleteSelect(); |
415 } | 387 } |
416 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) | 388 m_Param.pEventSink->OnAddDoRecord( |
417 m_Param.pEventSink->OnAddDoRecord( | 389 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_Insert>(this, m_nCaret, lpBuffer, |
418 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_Insert>(this, m_nCaret, lpBuffer, | 390 nLength)); |
419 nLength)); | |
420 | 391 |
421 m_ChangeInfo.wsPrevText = GetText(0, -1); | 392 m_ChangeInfo.wsPrevText = GetText(0, -1); |
422 Inner_Insert(m_nCaret, lpBuffer, nLength); | 393 Inner_Insert(m_nCaret, lpBuffer, nLength); |
423 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; | 394 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Insert; |
424 m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); | 395 m_ChangeInfo.wsInsert = CFX_WideString(lpBuffer, nLength); |
425 nStart = m_nCaret; | 396 nStart = m_nCaret; |
426 nStart += nLength; | 397 nStart += nLength; |
427 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); | 398 FX_WCHAR wChar = m_pTxtBuf->GetCharByIndex(nStart - 1); |
428 bool bBefore = true; | 399 bool bBefore = true; |
429 if (wChar != L'\n' && wChar != L'\r') { | 400 if (wChar != L'\n' && wChar != L'\r') { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 (m_pTxtBuf->GetCharByIndex(nStart) == L'\r') && | 434 (m_pTxtBuf->GetCharByIndex(nStart) == L'\r') && |
464 (m_pTxtBuf->GetCharByIndex(nStart + 1) == L'\n')) { | 435 (m_pTxtBuf->GetCharByIndex(nStart + 1) == L'\n')) { |
465 nCount++; | 436 nCount++; |
466 } | 437 } |
467 } | 438 } |
468 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { | 439 if (m_Param.dwMode & FDE_TEXTEDITMODE_Validate) { |
469 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); | 440 CFX_WideString wsText = GetPreDeleteText(nStart, nCount); |
470 if (!m_Param.pEventSink->OnValidate(wsText)) | 441 if (!m_Param.pEventSink->OnValidate(wsText)) |
471 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; | 442 return FDE_TXTEDT_MODIFY_RET_F_Invalidate; |
472 } | 443 } |
473 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { | 444 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); |
474 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); | 445 m_Param.pEventSink->OnAddDoRecord( |
475 m_Param.pEventSink->OnAddDoRecord( | 446 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>(this, nStart, |
476 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>(this, nStart, | 447 m_nCaret, wsRange)); |
477 m_nCaret, wsRange)); | 448 |
478 } | |
479 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; | 449 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; |
480 m_ChangeInfo.wsDelete = GetText(nStart, nCount); | 450 m_ChangeInfo.wsDelete = GetText(nStart, nCount); |
481 Inner_DeleteRange(nStart, nCount); | 451 Inner_DeleteRange(nStart, nCount); |
482 SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), | 452 SetCaretPos(nStart + ((!bBackspace && nStart > 0) ? -1 : 0), |
483 (bBackspace || nStart == 0)); | 453 (bBackspace || nStart == 0)); |
484 m_Param.pEventSink->OnTextChanged(m_ChangeInfo); | 454 m_Param.pEventSink->OnTextChanged(m_ChangeInfo); |
485 return FDE_TXTEDT_MODIFY_RET_S_Normal; | 455 return FDE_TXTEDT_MODIFY_RET_S_Normal; |
486 } | 456 } |
487 | 457 |
488 int32_t CFDE_TxtEdtEngine::DeleteRange(int32_t nStart, int32_t nCount) { | 458 int32_t CFDE_TxtEdtEngine::DeleteRange(int32_t nStart, int32_t nCount) { |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 for (int i = 0; i < nCount; ++i) | 619 for (int i = 0; i < nCount; ++i) |
650 delete m_SelRangePtrArr[i]; | 620 delete m_SelRangePtrArr[i]; |
651 m_SelRangePtrArr.RemoveAll(); | 621 m_SelRangePtrArr.RemoveAll(); |
652 if (nCount && m_Param.pEventSink) | 622 if (nCount && m_Param.pEventSink) |
653 m_Param.pEventSink->OnSelChanged(); | 623 m_Param.pEventSink->OnSelChanged(); |
654 } | 624 } |
655 | 625 |
656 bool CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) { | 626 bool CFDE_TxtEdtEngine::Redo(const IFDE_TxtEdtDoRecord* pDoRecord) { |
657 if (IsLocked()) | 627 if (IsLocked()) |
658 return false; | 628 return false; |
659 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) | |
660 return false; | |
661 return pDoRecord->Redo(); | 629 return pDoRecord->Redo(); |
662 } | 630 } |
663 | 631 |
664 bool CFDE_TxtEdtEngine::Undo(const IFDE_TxtEdtDoRecord* pDoRecord) { | 632 bool CFDE_TxtEdtEngine::Undo(const IFDE_TxtEdtDoRecord* pDoRecord) { |
665 if (IsLocked()) | 633 if (IsLocked()) |
666 return false; | 634 return false; |
667 if (m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo) | |
668 return false; | |
669 return pDoRecord->Undo(); | 635 return pDoRecord->Undo(); |
670 } | 636 } |
671 | 637 |
672 int32_t CFDE_TxtEdtEngine::StartLayout() { | 638 int32_t CFDE_TxtEdtEngine::StartLayout() { |
673 Lock(); | 639 Lock(); |
674 RemoveAllPages(); | 640 RemoveAllPages(); |
675 m_nLayoutPos = 0; | 641 m_nLayoutPos = 0; |
676 m_nLineCount = 0; | 642 m_nLineCount = 0; |
677 return 0; | 643 return 0; |
678 } | 644 } |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
938 | 904 |
939 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, | 905 void CFDE_TxtEdtEngine::DeleteRange_DoRecord(int32_t nStart, |
940 int32_t nCount, | 906 int32_t nCount, |
941 bool bSel) { | 907 bool bSel) { |
942 ASSERT(nStart >= 0); | 908 ASSERT(nStart >= 0); |
943 if (nCount == -1) { | 909 if (nCount == -1) { |
944 nCount = GetTextLength() - nStart; | 910 nCount = GetTextLength() - nStart; |
945 } | 911 } |
946 ASSERT((nStart + nCount) <= m_pTxtBuf->GetTextLength()); | 912 ASSERT((nStart + nCount) <= m_pTxtBuf->GetTextLength()); |
947 | 913 |
948 if (!(m_Param.dwMode & FDE_TEXTEDITMODE_NoRedoUndo)) { | 914 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); |
949 CFX_WideString wsRange = m_pTxtBuf->GetRange(nStart, nCount); | 915 m_Param.pEventSink->OnAddDoRecord( |
950 m_Param.pEventSink->OnAddDoRecord( | 916 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>( |
951 pdfium::MakeUnique<CFDE_TxtEdtDoRecord_DeleteRange>( | 917 this, nStart, m_nCaret, wsRange, bSel)); |
952 this, nStart, m_nCaret, wsRange, bSel)); | 918 |
953 } | |
954 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; | 919 m_ChangeInfo.nChangeType = FDE_TXTEDT_TEXTCHANGE_TYPE_Delete; |
955 m_ChangeInfo.wsDelete = GetText(nStart, nCount); | 920 m_ChangeInfo.wsDelete = GetText(nStart, nCount); |
956 Inner_DeleteRange(nStart, nCount); | 921 Inner_DeleteRange(nStart, nCount); |
957 } | 922 } |
958 | 923 |
959 void CFDE_TxtEdtEngine::ResetEngine() { | 924 void CFDE_TxtEdtEngine::ResetEngine() { |
960 RemoveAllPages(); | 925 RemoveAllPages(); |
961 RemoveAllParags(); | 926 RemoveAllParags(); |
962 ClearSelection(); | 927 ClearSelection(); |
963 m_nCaret = 0; | 928 m_nCaret = 0; |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1039 } | 1004 } |
1040 } | 1005 } |
1041 | 1006 |
1042 void CFDE_TxtEdtEngine::UpdateTxtBreak() { | 1007 void CFDE_TxtEdtEngine::UpdateTxtBreak() { |
1043 uint32_t dwStyle = m_pTextBreak->GetLayoutStyles(); | 1008 uint32_t dwStyle = m_pTextBreak->GetLayoutStyles(); |
1044 if (m_Param.dwMode & FDE_TEXTEDITMODE_MultiLines) { | 1009 if (m_Param.dwMode & FDE_TEXTEDITMODE_MultiLines) { |
1045 dwStyle &= ~FX_TXTLAYOUTSTYLE_SingleLine; | 1010 dwStyle &= ~FX_TXTLAYOUTSTYLE_SingleLine; |
1046 } else { | 1011 } else { |
1047 dwStyle |= FX_TXTLAYOUTSTYLE_SingleLine; | 1012 dwStyle |= FX_TXTLAYOUTSTYLE_SingleLine; |
1048 } | 1013 } |
1049 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1014 dwStyle &= ~FX_TXTLAYOUTSTYLE_VerticalLayout; |
1050 dwStyle |= FX_TXTLAYOUTSTYLE_VerticalLayout; | 1015 dwStyle &= ~FX_TXTLAYOUTSTYLE_ReverseLine; |
1051 } else { | 1016 dwStyle &= ~FX_TXTLAYOUTSTYLE_RTLReadingOrder; |
1052 dwStyle &= ~FX_TXTLAYOUTSTYLE_VerticalLayout; | 1017 |
1053 } | |
1054 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve) { | |
1055 dwStyle |= FX_TXTLAYOUTSTYLE_ReverseLine; | |
1056 } else { | |
1057 dwStyle &= ~FX_TXTLAYOUTSTYLE_ReverseLine; | |
1058 } | |
1059 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_RTL) { | |
1060 dwStyle |= FX_TXTLAYOUTSTYLE_RTLReadingOrder; | |
1061 } else { | |
1062 dwStyle &= ~FX_TXTLAYOUTSTYLE_RTLReadingOrder; | |
1063 } | |
1064 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText) { | 1018 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText) { |
1065 dwStyle |= FX_TXTLAYOUTSTYLE_CombText; | 1019 dwStyle |= FX_TXTLAYOUTSTYLE_CombText; |
1066 } else { | 1020 } else { |
1067 dwStyle &= ~FX_TXTLAYOUTSTYLE_CombText; | 1021 dwStyle &= ~FX_TXTLAYOUTSTYLE_CombText; |
1068 } | 1022 } |
1069 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CharVertial) { | 1023 |
1070 dwStyle |= FX_TXTLAYOUTSTYLE_VerticalChars; | 1024 dwStyle &= ~FX_TXTLAYOUTSTYLE_VerticalChars; |
1071 } else { | 1025 dwStyle &= ~FX_TXTLAYOUTSTYLE_ExpandTab; |
1072 dwStyle &= ~FX_TXTLAYOUTSTYLE_VerticalChars; | 1026 dwStyle &= ~FX_TXTLAYOUTSTYLE_ArabicContext; |
1073 } | 1027 dwStyle &= ~FX_TXTLAYOUTSTYLE_ArabicShapes; |
1074 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_ExpandTab) { | 1028 |
1075 dwStyle |= FX_TXTLAYOUTSTYLE_ExpandTab; | |
1076 } else { | |
1077 dwStyle &= ~FX_TXTLAYOUTSTYLE_ExpandTab; | |
1078 } | |
1079 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_ArabicContext) { | |
1080 dwStyle |= FX_TXTLAYOUTSTYLE_ArabicContext; | |
1081 } else { | |
1082 dwStyle &= ~FX_TXTLAYOUTSTYLE_ArabicContext; | |
1083 } | |
1084 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_ArabicShapes) { | |
1085 dwStyle |= FX_TXTLAYOUTSTYLE_ArabicShapes; | |
1086 } else { | |
1087 dwStyle &= ~FX_TXTLAYOUTSTYLE_ArabicShapes; | |
1088 } | |
1089 m_pTextBreak->SetLayoutStyles(dwStyle); | 1029 m_pTextBreak->SetLayoutStyles(dwStyle); |
1090 uint32_t dwAligment = 0; | 1030 uint32_t dwAligment = 0; |
1091 if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Justified) { | 1031 if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Justified) { |
1092 dwAligment |= FX_TXTLINEALIGNMENT_Justified; | 1032 dwAligment |= FX_TXTLINEALIGNMENT_Justified; |
1093 } else if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Distributed) { | |
1094 dwAligment |= FX_TXTLINEALIGNMENT_Distributed; | |
1095 } | 1033 } |
1096 if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Center) { | 1034 if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Center) { |
1097 dwAligment |= FX_TXTLINEALIGNMENT_Center; | 1035 dwAligment |= FX_TXTLINEALIGNMENT_Center; |
1098 } else if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Right) { | 1036 } else if (m_Param.dwAlignment & FDE_TEXTEDITALIGN_Right) { |
1099 dwAligment |= FX_TXTLINEALIGNMENT_Right; | 1037 dwAligment |= FX_TXTLINEALIGNMENT_Right; |
1100 } | 1038 } |
1101 m_pTextBreak->SetAlignment(dwAligment); | 1039 m_pTextBreak->SetAlignment(dwAligment); |
1102 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1040 |
1103 if (m_Param.dwMode & FDE_TEXTEDITMODE_AutoLineWrap) { | 1041 if (m_Param.dwMode & FDE_TEXTEDITMODE_AutoLineWrap) { |
1104 m_pTextBreak->SetLineWidth(m_Param.fPlateHeight); | 1042 m_pTextBreak->SetLineWidth(m_Param.fPlateWidth); |
1105 } else { | |
1106 m_pTextBreak->SetLineWidth(kPageWidthMax); | |
1107 } | |
1108 } else { | 1043 } else { |
1109 if (m_Param.dwMode & FDE_TEXTEDITMODE_AutoLineWrap) { | 1044 m_pTextBreak->SetLineWidth(kPageWidthMax); |
1110 m_pTextBreak->SetLineWidth(m_Param.fPlateWidth); | |
1111 } else { | |
1112 m_pTextBreak->SetLineWidth(kPageWidthMax); | |
1113 } | |
1114 } | 1045 } |
| 1046 |
1115 m_nPageLineCount = m_Param.nLineCount; | 1047 m_nPageLineCount = m_Param.nLineCount; |
1116 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText) { | 1048 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText) { |
1117 FX_FLOAT fCombWidth = | 1049 FX_FLOAT fCombWidth = m_Param.fPlateWidth; |
1118 m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical | |
1119 ? m_Param.fPlateHeight | |
1120 : m_Param.fPlateWidth; | |
1121 if (m_nLimit > 0) { | 1050 if (m_nLimit > 0) { |
1122 fCombWidth /= m_nLimit; | 1051 fCombWidth /= m_nLimit; |
1123 } | 1052 } |
1124 m_pTextBreak->SetCombWidth(fCombWidth); | 1053 m_pTextBreak->SetCombWidth(fCombWidth); |
1125 } | 1054 } |
1126 m_pTextBreak->SetFont(m_Param.pFont); | 1055 m_pTextBreak->SetFont(m_Param.pFont); |
1127 m_pTextBreak->SetFontSize(m_Param.fFontSize); | 1056 m_pTextBreak->SetFontSize(m_Param.fFontSize); |
1128 m_pTextBreak->SetTabWidth(m_Param.fTabWidth, m_Param.bTabEquidistant); | 1057 m_pTextBreak->SetTabWidth(m_Param.fTabWidth, m_Param.bTabEquidistant); |
1129 m_pTextBreak->SetDefaultChar(m_Param.wDefChar); | 1058 m_pTextBreak->SetDefaultChar(m_Param.wDefChar); |
1130 m_pTextBreak->SetParagraphBreakChar(m_Param.wLineBreakChar); | 1059 m_pTextBreak->SetParagraphBreakChar(m_Param.wLineBreakChar); |
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1316 nCaret--; | 1245 nCaret--; |
1317 } | 1246 } |
1318 nCaret--; | 1247 nCaret--; |
1319 bBefore = true; | 1248 bBefore = true; |
1320 return nCaret; | 1249 return nCaret; |
1321 } | 1250 } |
1322 | 1251 |
1323 bool CFDE_TxtEdtEngine::MoveUp(CFX_PointF& ptCaret) { | 1252 bool CFDE_TxtEdtEngine::MoveUp(CFX_PointF& ptCaret) { |
1324 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); | 1253 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); |
1325 const CFX_RectF& rtContent = pPage->GetContentsBox(); | 1254 const CFX_RectF& rtContent = pPage->GetContentsBox(); |
1326 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1255 ptCaret.x = m_fCaretPosReserve; |
1327 ptCaret.x = m_rtCaret.left + m_rtCaret.width / 2 - m_Param.fLineSpace; | 1256 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 - m_Param.fLineSpace; |
1328 ptCaret.y = m_fCaretPosReserve; | 1257 if (ptCaret.y < rtContent.top) { |
1329 bool bLineReserve = | 1258 if (m_nCaretPage == 0) { |
1330 !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve); | 1259 return false; |
1331 if (ptCaret.x < rtContent.left) { | |
1332 if (bLineReserve) { | |
1333 if (m_nCaretPage == CountPages() - 1) { | |
1334 return false; | |
1335 } | |
1336 } else { | |
1337 if (m_nCaretPage == 0) { | |
1338 return false; | |
1339 } | |
1340 } | |
1341 if (bLineReserve) { | |
1342 m_nCaretPage++; | |
1343 } else { | |
1344 m_nCaretPage--; | |
1345 } | |
1346 ptCaret.x -= rtContent.left; | |
1347 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | |
1348 ptCaret.x += pCurPage->GetContentsBox().right(); | |
1349 } | 1260 } |
1350 } else { | 1261 ptCaret.y -= rtContent.top; |
1351 ptCaret.x = m_fCaretPosReserve; | 1262 m_nCaretPage--; |
1352 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 - m_Param.fLineSpace; | 1263 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1353 if (ptCaret.y < rtContent.top) { | 1264 ptCaret.y += pCurPage->GetContentsBox().bottom(); |
1354 if (m_nCaretPage == 0) { | |
1355 return false; | |
1356 } | |
1357 ptCaret.y -= rtContent.top; | |
1358 m_nCaretPage--; | |
1359 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | |
1360 ptCaret.y += pCurPage->GetContentsBox().bottom(); | |
1361 } | |
1362 } | 1265 } |
| 1266 |
1363 return true; | 1267 return true; |
1364 } | 1268 } |
1365 | 1269 |
1366 bool CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) { | 1270 bool CFDE_TxtEdtEngine::MoveDown(CFX_PointF& ptCaret) { |
1367 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); | 1271 IFDE_TxtEdtPage* pPage = GetPage(m_nCaretPage); |
1368 const CFX_RectF& rtContent = pPage->GetContentsBox(); | 1272 const CFX_RectF& rtContent = pPage->GetContentsBox(); |
1369 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1273 ptCaret.x = m_fCaretPosReserve; |
1370 ptCaret.x = m_rtCaret.left + m_rtCaret.width / 2 + m_Param.fLineSpace; | 1274 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 + m_Param.fLineSpace; |
1371 ptCaret.y = m_fCaretPosReserve; | 1275 if (ptCaret.y >= rtContent.bottom()) { |
1372 if (ptCaret.x >= rtContent.right()) { | 1276 if (m_nCaretPage == CountPages() - 1) { |
1373 bool bLineReserve = | 1277 return false; |
1374 !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_LineReserve); | |
1375 if (bLineReserve) { | |
1376 if (m_nCaretPage == 0) { | |
1377 return false; | |
1378 } | |
1379 } else { | |
1380 if (m_nCaretPage == CountPages() - 1) { | |
1381 return false; | |
1382 } | |
1383 } | |
1384 if (bLineReserve) { | |
1385 m_nCaretPage--; | |
1386 } else { | |
1387 m_nCaretPage++; | |
1388 } | |
1389 ptCaret.x -= rtContent.right(); | |
1390 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | |
1391 ptCaret.x += pCurPage->GetContentsBox().left; | |
1392 } | 1278 } |
1393 } else { | 1279 ptCaret.y -= rtContent.bottom(); |
1394 ptCaret.x = m_fCaretPosReserve; | 1280 m_nCaretPage++; |
1395 ptCaret.y = m_rtCaret.top + m_rtCaret.height / 2 + m_Param.fLineSpace; | 1281 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); |
1396 if (ptCaret.y >= rtContent.bottom()) { | 1282 ptCaret.y += pCurPage->GetContentsBox().top; |
1397 if (m_nCaretPage == CountPages() - 1) { | |
1398 return false; | |
1399 } | |
1400 ptCaret.y -= rtContent.bottom(); | |
1401 m_nCaretPage++; | |
1402 IFDE_TxtEdtPage* pCurPage = GetPage(m_nCaretPage); | |
1403 ptCaret.y += pCurPage->GetContentsBox().top; | |
1404 } | |
1405 } | 1283 } |
1406 return true; | 1284 return true; |
1407 } | 1285 } |
1408 | 1286 |
1409 bool CFDE_TxtEdtEngine::MoveLineStart() { | 1287 bool CFDE_TxtEdtEngine::MoveLineStart() { |
1410 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; | 1288 int32_t nIndex = m_bBefore ? m_nCaret : m_nCaret - 1; |
1411 FDE_TXTEDTPARAGPOS ParagPos; | 1289 FDE_TXTEDTPARAGPOS ParagPos; |
1412 TextPos2ParagPos(nIndex, ParagPos); | 1290 TextPos2ParagPos(nIndex, ParagPos); |
1413 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; | 1291 CFDE_TxtEdtParag* pParag = m_ParagPtrArray[ParagPos.nParagIndex]; |
1414 pParag->LoadParag(); | 1292 pParag->LoadParag(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1535 | 1413 |
1536 void CFDE_TxtEdtEngine::UpdateCaretRect(int32_t nIndex, bool bBefore) { | 1414 void CFDE_TxtEdtEngine::UpdateCaretRect(int32_t nIndex, bool bBefore) { |
1537 MovePage2Char(nIndex); | 1415 MovePage2Char(nIndex); |
1538 GetCaretRect(m_rtCaret, m_nCaretPage, nIndex, bBefore); | 1416 GetCaretRect(m_rtCaret, m_nCaretPage, nIndex, bBefore); |
1539 m_nCaret = nIndex; | 1417 m_nCaret = nIndex; |
1540 m_bBefore = bBefore; | 1418 m_bBefore = bBefore; |
1541 if (!m_bBefore) { | 1419 if (!m_bBefore) { |
1542 m_nCaret++; | 1420 m_nCaret++; |
1543 m_bBefore = true; | 1421 m_bBefore = true; |
1544 } | 1422 } |
1545 m_fCaretPosReserve = (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) | 1423 m_fCaretPosReserve = m_rtCaret.left; |
1546 ? m_rtCaret.top | |
1547 : m_rtCaret.left; | |
1548 m_Param.pEventSink->OnCaretChanged(); | 1424 m_Param.pEventSink->OnCaretChanged(); |
1549 } | 1425 } |
1550 | 1426 |
1551 void CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret, | 1427 void CFDE_TxtEdtEngine::GetCaretRect(CFX_RectF& rtCaret, |
1552 int32_t nPageIndex, | 1428 int32_t nPageIndex, |
1553 int32_t nCaret, | 1429 int32_t nCaret, |
1554 bool bBefore) { | 1430 bool bBefore) { |
1555 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1431 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1556 m_Param.pEventSink->OnPageLoad(m_nCaretPage); | 1432 m_Param.pEventSink->OnPageLoad(m_nCaretPage); |
1557 bool bCombText = !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText); | 1433 bool bCombText = !!(m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_CombText); |
1558 int32_t nIndexInpage = nCaret - pPage->GetCharStart(); | 1434 int32_t nIndexInpage = nCaret - pPage->GetCharStart(); |
1559 if (bBefore && bCombText && nIndexInpage > 0) { | 1435 if (bBefore && bCombText && nIndexInpage > 0) { |
1560 nIndexInpage--; | 1436 nIndexInpage--; |
1561 bBefore = false; | 1437 bBefore = false; |
1562 } | 1438 } |
1563 int32_t nBIDILevel = pPage->GetCharRect(nIndexInpage, rtCaret, bCombText); | 1439 int32_t nBIDILevel = pPage->GetCharRect(nIndexInpage, rtCaret, bCombText); |
1564 if (m_Param.dwLayoutStyles & FDE_TEXTEDITLAYOUT_DocVertical) { | 1440 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || |
1565 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || | 1441 (FX_IsOdd(nBIDILevel) && bBefore)) { |
1566 (FX_IsOdd(nBIDILevel) && bBefore)) { | 1442 rtCaret.Offset(rtCaret.width - 1.0f, 0); |
1567 rtCaret.Offset(0, rtCaret.height - 1.0f); | 1443 } |
1568 } | 1444 if (rtCaret.width == 0 && rtCaret.left > 1.0f) |
1569 if (rtCaret.height == 0 && rtCaret.top > 1.0f) | 1445 rtCaret.left -= 1.0f; |
1570 rtCaret.top -= 1.0f; | |
1571 | 1446 |
1572 rtCaret.height = 1.0f; | 1447 rtCaret.width = 1.0f; |
1573 } else { | |
1574 if ((!FX_IsOdd(nBIDILevel) && !bBefore) || | |
1575 (FX_IsOdd(nBIDILevel) && bBefore)) { | |
1576 rtCaret.Offset(rtCaret.width - 1.0f, 0); | |
1577 } | |
1578 if (rtCaret.width == 0 && rtCaret.left > 1.0f) | |
1579 rtCaret.left -= 1.0f; | |
1580 | 1448 |
1581 rtCaret.width = 1.0f; | |
1582 } | |
1583 m_Param.pEventSink->OnPageUnload(m_nCaretPage); | 1449 m_Param.pEventSink->OnPageUnload(m_nCaretPage); |
1584 } | 1450 } |
1585 | 1451 |
1586 void CFDE_TxtEdtEngine::UpdateCaretIndex(const CFX_PointF& ptCaret) { | 1452 void CFDE_TxtEdtEngine::UpdateCaretIndex(const CFX_PointF& ptCaret) { |
1587 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; | 1453 IFDE_TxtEdtPage* pPage = m_PagePtrArray[m_nCaretPage]; |
1588 m_Param.pEventSink->OnPageLoad(m_nCaretPage); | 1454 m_Param.pEventSink->OnPageLoad(m_nCaretPage); |
1589 m_nCaret = pPage->GetCharIndex(ptCaret, m_bBefore); | 1455 m_nCaret = pPage->GetCharIndex(ptCaret, m_bBefore); |
1590 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); | 1456 GetCaretRect(m_rtCaret, m_nCaretPage, m_nCaret, m_bBefore); |
1591 if (!m_bBefore) { | 1457 if (!m_bBefore) { |
1592 m_nCaret++; | 1458 m_nCaret++; |
(...skipping 17 matching lines...) Expand all Loading... |
1610 m_SelRangePtrArr.RemoveAt(nCountRange); | 1476 m_SelRangePtrArr.RemoveAt(nCountRange); |
1611 DeleteRange_DoRecord(nSelStart, nSelCount, true); | 1477 DeleteRange_DoRecord(nSelStart, nSelCount, true); |
1612 } | 1478 } |
1613 ClearSelection(); | 1479 ClearSelection(); |
1614 m_Param.pEventSink->OnTextChanged(m_ChangeInfo); | 1480 m_Param.pEventSink->OnTextChanged(m_ChangeInfo); |
1615 m_Param.pEventSink->OnSelChanged(); | 1481 m_Param.pEventSink->OnSelChanged(); |
1616 SetCaretPos(nSelStart, true); | 1482 SetCaretPos(nSelStart, true); |
1617 return; | 1483 return; |
1618 } | 1484 } |
1619 } | 1485 } |
OLD | NEW |