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 "fpdfsdk/fxedit/include/fxet_edit.h" | 7 #include "fpdfsdk/fxedit/include/fxet_edit.h" |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 if (IsFirst()) { | 741 if (IsFirst()) { |
742 m_pEdit->SelectNone(); | 742 m_pEdit->SelectNone(); |
743 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); | 743 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
744 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); | 744 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
745 } | 745 } |
746 } | 746 } |
747 } | 747 } |
748 | 748 |
749 CFX_Edit::CFX_Edit(CPDF_VariableText* pVT) | 749 CFX_Edit::CFX_Edit(CPDF_VariableText* pVT) |
750 : m_pVT(pVT), | 750 : m_pVT(pVT), |
751 m_pNotify(NULL), | 751 m_pNotify(nullptr), |
752 m_pOprNotify(NULL), | 752 m_pOprNotify(nullptr), |
753 m_pVTProvide(NULL), | |
754 m_wpCaret(-1, -1, -1), | 753 m_wpCaret(-1, -1, -1), |
755 m_wpOldCaret(-1, -1, -1), | 754 m_wpOldCaret(-1, -1, -1), |
756 m_SelState(), | 755 m_SelState(), |
757 m_ptScrollPos(0, 0), | 756 m_ptScrollPos(0, 0), |
758 m_ptRefreshScrollPos(0, 0), | 757 m_ptRefreshScrollPos(0, 0), |
759 m_bEnableScroll(FALSE), | 758 m_bEnableScroll(FALSE), |
760 m_pIterator(NULL), | 759 m_pIterator(nullptr), |
761 m_ptCaret(0.0f, 0.0f), | 760 m_ptCaret(0.0f, 0.0f), |
762 m_Undo(kEditUndoMaxItems), | 761 m_Undo(kEditUndoMaxItems), |
763 m_nAlignment(0), | 762 m_nAlignment(0), |
764 m_bNotifyFlag(FALSE), | 763 m_bNotifyFlag(FALSE), |
765 m_bEnableOverflow(FALSE), | 764 m_bEnableOverflow(FALSE), |
766 m_bEnableRefresh(TRUE), | 765 m_bEnableRefresh(TRUE), |
767 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), | 766 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
768 m_bEnableUndo(TRUE), | 767 m_bEnableUndo(TRUE), |
769 m_bNotify(TRUE), | 768 m_bNotify(TRUE), |
770 m_bOprNotify(FALSE), | 769 m_bOprNotify(FALSE), |
771 m_pGroupUndoItem(NULL) { | 770 m_pGroupUndoItem(nullptr) { |
772 ASSERT(pVT); | 771 ASSERT(pVT); |
773 } | 772 } |
774 | 773 |
775 CFX_Edit::~CFX_Edit() { | 774 CFX_Edit::~CFX_Edit() { |
776 delete m_pVTProvide; | |
777 m_pVTProvide = NULL; | |
778 delete m_pIterator; | |
779 m_pIterator = NULL; | |
780 ASSERT(!m_pGroupUndoItem); | 775 ASSERT(!m_pGroupUndoItem); |
781 } | 776 } |
782 | 777 |
783 void CFX_Edit::Initialize() { | 778 void CFX_Edit::Initialize() { |
784 m_pVT->Initialize(); | 779 m_pVT->Initialize(); |
785 SetCaret(m_pVT->GetBeginWordPlace()); | 780 SetCaret(m_pVT->GetBeginWordPlace()); |
786 SetCaretOrigin(); | 781 SetCaretOrigin(); |
787 } | 782 } |
788 | 783 |
789 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { | 784 void CFX_Edit::SetFontMap(IPVT_FontMap* pFontMap) { |
790 delete m_pVTProvide; | 785 m_pVTProvider.reset(new CFX_Edit_Provider(pFontMap)); |
791 m_pVT->SetProvider(m_pVTProvide = new CFX_Edit_Provider(pFontMap)); | 786 m_pVT->SetProvider(m_pVTProvider.get()); |
792 } | 787 } |
793 | 788 |
794 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { | 789 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { |
795 m_pNotify = pNotify; | 790 m_pNotify = pNotify; |
796 } | 791 } |
797 | 792 |
798 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { | 793 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { |
799 m_pOprNotify = pOprNotify; | 794 m_pOprNotify = pOprNotify; |
800 } | 795 } |
801 | 796 |
802 IFX_Edit_Iterator* CFX_Edit::GetIterator() { | 797 IFX_Edit_Iterator* CFX_Edit::GetIterator() { |
803 if (!m_pIterator) | 798 if (!m_pIterator) |
804 m_pIterator = new CFX_Edit_Iterator(this, m_pVT->GetIterator()); | 799 m_pIterator.reset(new CFX_Edit_Iterator(this, m_pVT->GetIterator())); |
805 | 800 return m_pIterator.get(); |
806 return m_pIterator; | |
807 } | 801 } |
808 | 802 |
809 CPDF_VariableText* CFX_Edit::GetVariableText() { | 803 CPDF_VariableText* CFX_Edit::GetVariableText() { |
810 return m_pVT; | 804 return m_pVT; |
811 } | 805 } |
812 | 806 |
813 IPVT_FontMap* CFX_Edit::GetFontMap() { | 807 IPVT_FontMap* CFX_Edit::GetFontMap() { |
814 if (m_pVTProvide) | 808 return m_pVTProvider ? m_pVTProvider->GetFontMap() : nullptr; |
815 return m_pVTProvide->GetFontMap(); | |
816 | |
817 return NULL; | |
818 } | 809 } |
819 | 810 |
820 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { | 811 void CFX_Edit::SetPlateRect(const CFX_FloatRect& rect, FX_BOOL bPaint) { |
821 m_pVT->SetPlateRect(rect); | 812 m_pVT->SetPlateRect(rect); |
822 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); | 813 m_ptScrollPos = CFX_FloatPoint(rect.left, rect.top); |
823 if (bPaint) | 814 if (bPaint) |
824 Paint(); | 815 Paint(); |
825 } | 816 } |
826 | 817 |
827 void CFX_Edit::SetAlignmentH(int32_t nFormat, FX_BOOL bPaint) { | 818 void CFX_Edit::SetAlignmentH(int32_t nFormat, FX_BOOL bPaint) { |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
973 return -1; | 964 return -1; |
974 } | 965 } |
975 | 966 |
976 CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const { | 967 CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const { |
977 return m_wpCaret; | 968 return m_wpCaret; |
978 } | 969 } |
979 | 970 |
980 CFX_WideString CFX_Edit::GetText() const { | 971 CFX_WideString CFX_Edit::GetText() const { |
981 CFX_WideString swRet; | 972 CFX_WideString swRet; |
982 | 973 |
983 if (m_pVT->IsValid()) { | 974 if (!m_pVT->IsValid()) |
984 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 975 return swRet; |
985 FX_BOOL bRich = m_pVT->IsRichText(); | |
986 | 976 |
987 pIterator->SetAt(0); | 977 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 978 pIterator->SetAt(0); |
988 | 979 |
989 CPVT_Word wordinfo; | 980 CPVT_Word wordinfo; |
990 CPVT_WordPlace oldplace = pIterator->GetAt(); | 981 CPVT_WordPlace oldplace = pIterator->GetAt(); |
991 while (pIterator->NextWord()) { | 982 while (pIterator->NextWord()) { |
992 CPVT_WordPlace place = pIterator->GetAt(); | 983 CPVT_WordPlace place = pIterator->GetAt(); |
993 | 984 |
994 if (pIterator->GetWord(wordinfo)) { | 985 if (pIterator->GetWord(wordinfo)) |
995 if (bRich) { | 986 swRet += wordinfo.Word; |
996 swRet += wordinfo.Word; | |
997 } else { | |
998 swRet += wordinfo.Word; | |
999 } | |
1000 } | |
1001 | 987 |
1002 if (oldplace.SecCmp(place) != 0) { | 988 if (oldplace.SecCmp(place) != 0) |
1003 swRet += 0x0D; | 989 swRet += L"\r\n"; |
1004 swRet += 0x0A; | |
1005 } | |
1006 | 990 |
1007 oldplace = place; | 991 oldplace = place; |
1008 } | |
1009 } | |
1010 } | 992 } |
1011 | 993 |
1012 return swRet; | 994 return swRet; |
1013 } | 995 } |
1014 | 996 |
1015 CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const { | 997 CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const { |
1016 CFX_WideString swRet; | 998 CFX_WideString swRet; |
1017 | 999 |
1018 if (m_pVT->IsValid()) { | 1000 if (!m_pVT->IsValid()) |
1019 FX_BOOL bRich = m_pVT->IsRichText(); | 1001 return swRet; |
1020 | 1002 |
1021 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1003 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1022 CPVT_WordRange wrTemp = range; | 1004 CPVT_WordRange wrTemp = range; |
1023 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | 1005 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
1024 m_pVT->UpdateWordPlace(wrTemp.EndPos); | 1006 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
1025 pIterator->SetAt(wrTemp.BeginPos); | 1007 pIterator->SetAt(wrTemp.BeginPos); |
1026 | 1008 |
1027 CPVT_Word wordinfo; | 1009 CPVT_Word wordinfo; |
1028 CPVT_WordPlace oldplace = wrTemp.BeginPos; | 1010 CPVT_WordPlace oldplace = wrTemp.BeginPos; |
1029 while (pIterator->NextWord()) { | 1011 while (pIterator->NextWord()) { |
1030 CPVT_WordPlace place = pIterator->GetAt(); | 1012 CPVT_WordPlace place = pIterator->GetAt(); |
1031 if (place.WordCmp(wrTemp.EndPos) > 0) | 1013 if (place.WordCmp(wrTemp.EndPos) > 0) |
1032 break; | 1014 break; |
1033 | 1015 |
1034 if (pIterator->GetWord(wordinfo)) { | 1016 if (pIterator->GetWord(wordinfo)) |
1035 if (bRich) { | 1017 swRet += wordinfo.Word; |
1036 swRet += wordinfo.Word; | |
1037 } else { | |
1038 swRet += wordinfo.Word; | |
1039 } | |
1040 } | |
1041 | 1018 |
1042 if (oldplace.SecCmp(place) != 0) { | 1019 if (oldplace.SecCmp(place) != 0) |
1043 swRet += 0x0D; | 1020 swRet += L"\r\n"; |
1044 swRet += 0x0A; | |
1045 } | |
1046 | 1021 |
1047 oldplace = place; | 1022 oldplace = place; |
1048 } | |
1049 } | |
1050 } | 1023 } |
1051 | 1024 |
1052 return swRet; | 1025 return swRet; |
1053 } | 1026 } |
1054 | 1027 |
1055 CFX_WideString CFX_Edit::GetSelText() const { | 1028 CFX_WideString CFX_Edit::GetSelText() const { |
1056 return GetRangeText(m_SelState.ConvertToWordRange()); | 1029 return GetRangeText(m_SelState.ConvertToWordRange()); |
1057 } | 1030 } |
1058 | 1031 |
1059 int32_t CFX_Edit::GetTotalWords() const { | 1032 int32_t CFX_Edit::GetTotalWords() const { |
1060 return m_pVT->GetTotalWords(); | 1033 return m_pVT->GetTotalWords(); |
1061 } | 1034 } |
1062 | 1035 |
1063 int32_t CFX_Edit::GetTotalLines() const { | 1036 int32_t CFX_Edit::GetTotalLines() const { |
1064 int32_t nLines = 0; | 1037 int32_t nLines = 1; |
1065 | 1038 |
1066 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1039 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1067 pIterator->SetAt(0); | 1040 pIterator->SetAt(0); |
1068 while (pIterator->NextLine()) | 1041 while (pIterator->NextLine()) |
1069 nLines++; | 1042 ++nLines; |
1070 } | |
1071 | 1043 |
1072 return nLines + 1; | 1044 return nLines; |
1073 } | 1045 } |
1074 | 1046 |
1075 CPVT_WordRange CFX_Edit::GetSelectWordRange() const { | 1047 CPVT_WordRange CFX_Edit::GetSelectWordRange() const { |
1076 return m_SelState.ConvertToWordRange(); | 1048 return m_SelState.ConvertToWordRange(); |
1077 } | 1049 } |
1078 | 1050 |
1079 CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1, | 1051 CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
1080 const CPVT_WordRange& wr2) { | 1052 const CPVT_WordRange& wr2) { |
1081 CPVT_WordRange wrRet; | 1053 CPVT_WordRange wrRet; |
1082 | 1054 |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1183 | 1155 |
1184 FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) { | 1156 FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) { |
1185 CPVT_SecProps SecProps; | 1157 CPVT_SecProps SecProps; |
1186 SecProps.nAlignment = nAlignment; | 1158 SecProps.nAlignment = nAlignment; |
1187 return SetRichTextProps(EP_ALIGNMENT, &SecProps, NULL); | 1159 return SetRichTextProps(EP_ALIGNMENT, &SecProps, NULL); |
1188 } | 1160 } |
1189 | 1161 |
1190 FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, | 1162 FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, |
1191 const CPVT_SecProps* pSecProps, | 1163 const CPVT_SecProps* pSecProps, |
1192 const CPVT_WordProps* pWordProps) { | 1164 const CPVT_WordProps* pWordProps) { |
1193 FX_BOOL bSet = FALSE; | 1165 if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
1194 FX_BOOL bSet1, bSet2; | 1166 return FALSE; |
1195 if (m_pVT->IsValid() && m_pVT->IsRichText()) { | |
1196 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | |
1197 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); | |
1198 | 1167 |
1199 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | 1168 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1200 m_pVT->UpdateWordPlace(wrTemp.EndPos); | 1169 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); |
1201 pIterator->SetAt(wrTemp.BeginPos); | |
1202 | 1170 |
1203 BeginGroupUndo(L""); | 1171 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
1204 bSet = SetSecProps(eProps, wrTemp.BeginPos, pSecProps, pWordProps, wrTemp, | 1172 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
1205 TRUE); | 1173 pIterator->SetAt(wrTemp.BeginPos); |
1206 | 1174 |
1207 while (pIterator->NextWord()) { | 1175 BeginGroupUndo(L""); |
1208 CPVT_WordPlace place = pIterator->GetAt(); | 1176 FX_BOOL bSet = |
1209 if (place.WordCmp(wrTemp.EndPos) > 0) | 1177 SetSecProps(eProps, wrTemp.BeginPos, pSecProps, pWordProps, wrTemp, TRUE); |
1210 break; | |
1211 bSet1 = SetSecProps(eProps, place, pSecProps, pWordProps, wrTemp, TRUE); | |
1212 bSet2 = SetWordProps(eProps, place, pWordProps, wrTemp, TRUE); | |
1213 | 1178 |
1214 if (!bSet) | 1179 while (pIterator->NextWord()) { |
1215 bSet = (bSet1 || bSet2); | 1180 CPVT_WordPlace place = pIterator->GetAt(); |
1216 } | 1181 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 1182 break; |
| 1183 FX_BOOL bSet1 = |
| 1184 SetSecProps(eProps, place, pSecProps, pWordProps, wrTemp, TRUE); |
| 1185 FX_BOOL bSet2 = SetWordProps(eProps, place, pWordProps, wrTemp, TRUE); |
1217 | 1186 |
1218 EndGroupUndo(); | 1187 if (!bSet) |
| 1188 bSet = (bSet1 || bSet2); |
| 1189 } |
1219 | 1190 |
1220 if (bSet) { | 1191 EndGroupUndo(); |
1221 PaintSetProps(eProps, wrTemp); | 1192 |
1222 } | 1193 if (bSet) |
1223 } | 1194 PaintSetProps(eProps, wrTemp); |
1224 } | |
1225 | 1195 |
1226 return bSet; | 1196 return bSet; |
1227 } | 1197 } |
1228 | 1198 |
1229 void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange& wr) { | 1199 void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange& wr) { |
1230 switch (eProps) { | 1200 switch (eProps) { |
1231 case EP_LINELEADING: | 1201 case EP_LINELEADING: |
1232 case EP_LINEINDENT: | 1202 case EP_LINEINDENT: |
1233 case EP_ALIGNMENT: | 1203 case EP_ALIGNMENT: |
1234 RearrangePart(wr); | 1204 RearrangePart(wr); |
(...skipping 26 matching lines...) Expand all Loading... |
1261 break; | 1231 break; |
1262 } | 1232 } |
1263 } | 1233 } |
1264 | 1234 |
1265 FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, | 1235 FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, |
1266 const CPVT_WordPlace& place, | 1236 const CPVT_WordPlace& place, |
1267 const CPVT_SecProps* pSecProps, | 1237 const CPVT_SecProps* pSecProps, |
1268 const CPVT_WordProps* pWordProps, | 1238 const CPVT_WordProps* pWordProps, |
1269 const CPVT_WordRange& wr, | 1239 const CPVT_WordRange& wr, |
1270 FX_BOOL bAddUndo) { | 1240 FX_BOOL bAddUndo) { |
1271 if (m_pVT->IsValid() && m_pVT->IsRichText()) { | 1241 if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
1272 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1242 return FALSE; |
1273 FX_BOOL bSet = FALSE; | 1243 |
1274 CPVT_Section secinfo; | 1244 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1275 CPVT_Section OldSecinfo; | 1245 FX_BOOL bSet = FALSE; |
1276 | 1246 CPVT_Section secinfo; |
1277 CPVT_WordPlace oldplace = pIterator->GetAt(); | 1247 CPVT_Section OldSecinfo; |
1278 | 1248 |
1279 if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || | 1249 CPVT_WordPlace oldplace = pIterator->GetAt(); |
1280 eProps == EP_ALIGNMENT) { | 1250 |
1281 if (pSecProps) { | 1251 if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || |
1282 pIterator->SetAt(place); | 1252 eProps == EP_ALIGNMENT) { |
1283 if (pIterator->GetSection(secinfo)) { | 1253 if (pSecProps) { |
1284 if (bAddUndo) | 1254 pIterator->SetAt(place); |
1285 OldSecinfo = secinfo; | 1255 if (pIterator->GetSection(secinfo)) { |
1286 | 1256 if (bAddUndo) |
1287 switch (eProps) { | 1257 OldSecinfo = secinfo; |
1288 case EP_LINELEADING: | 1258 |
1289 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading, | 1259 switch (eProps) { |
1290 pSecProps->fLineLeading)) { | 1260 case EP_LINELEADING: |
1291 secinfo.SecProps.fLineLeading = pSecProps->fLineLeading; | 1261 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading, |
1292 bSet = TRUE; | 1262 pSecProps->fLineLeading)) { |
1293 } | 1263 secinfo.SecProps.fLineLeading = pSecProps->fLineLeading; |
1294 break; | 1264 bSet = TRUE; |
1295 case EP_LINEINDENT: | 1265 } |
1296 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent, | 1266 break; |
1297 pSecProps->fLineIndent)) { | 1267 case EP_LINEINDENT: |
1298 secinfo.SecProps.fLineIndent = pSecProps->fLineIndent; | 1268 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent, |
1299 bSet = TRUE; | 1269 pSecProps->fLineIndent)) { |
1300 } | 1270 secinfo.SecProps.fLineIndent = pSecProps->fLineIndent; |
1301 break; | 1271 bSet = TRUE; |
1302 case EP_ALIGNMENT: | 1272 } |
1303 if (secinfo.SecProps.nAlignment != pSecProps->nAlignment) { | 1273 break; |
1304 secinfo.SecProps.nAlignment = pSecProps->nAlignment; | 1274 case EP_ALIGNMENT: |
1305 bSet = TRUE; | 1275 if (secinfo.SecProps.nAlignment != pSecProps->nAlignment) { |
1306 } | 1276 secinfo.SecProps.nAlignment = pSecProps->nAlignment; |
1307 break; | 1277 bSet = TRUE; |
1308 default: | 1278 } |
1309 break; | 1279 break; |
1310 } | 1280 default: |
1311 } | 1281 break; |
1312 } | |
1313 } else { | |
1314 if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) { | |
1315 pIterator->SetAt(place); | |
1316 if (pIterator->GetSection(secinfo)) { | |
1317 if (bAddUndo) | |
1318 OldSecinfo = secinfo; | |
1319 | |
1320 switch (eProps) { | |
1321 case EP_FONTINDEX: | |
1322 if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { | |
1323 secinfo.WordProps.nFontIndex = pWordProps->nFontIndex; | |
1324 bSet = TRUE; | |
1325 } | |
1326 break; | |
1327 case EP_FONTSIZE: | |
1328 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize, | |
1329 pWordProps->fFontSize)) { | |
1330 secinfo.WordProps.fFontSize = pWordProps->fFontSize; | |
1331 bSet = TRUE; | |
1332 } | |
1333 break; | |
1334 case EP_WORDCOLOR: | |
1335 if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { | |
1336 secinfo.WordProps.dwWordColor = pWordProps->dwWordColor; | |
1337 bSet = TRUE; | |
1338 } | |
1339 break; | |
1340 case EP_SCRIPTTYPE: | |
1341 if (secinfo.WordProps.nScriptType != pWordProps->nScriptType) { | |
1342 secinfo.WordProps.nScriptType = pWordProps->nScriptType; | |
1343 bSet = TRUE; | |
1344 } | |
1345 break; | |
1346 case EP_CHARSPACE: | |
1347 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace, | |
1348 pWordProps->fCharSpace)) { | |
1349 secinfo.WordProps.fCharSpace = pWordProps->fCharSpace; | |
1350 bSet = TRUE; | |
1351 } | |
1352 break; | |
1353 case EP_HORZSCALE: | |
1354 if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { | |
1355 secinfo.WordProps.nHorzScale = pWordProps->nHorzScale; | |
1356 bSet = TRUE; | |
1357 } | |
1358 break; | |
1359 case EP_UNDERLINE: | |
1360 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { | |
1361 if ((secinfo.WordProps.nWordStyle & | |
1362 PVTWORD_STYLE_UNDERLINE) == 0) { | |
1363 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; | |
1364 bSet = TRUE; | |
1365 } | |
1366 } else { | |
1367 if ((secinfo.WordProps.nWordStyle & | |
1368 PVTWORD_STYLE_UNDERLINE) != 0) { | |
1369 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; | |
1370 bSet = TRUE; | |
1371 } | |
1372 } | |
1373 break; | |
1374 case EP_CROSSOUT: | |
1375 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { | |
1376 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == | |
1377 0) { | |
1378 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; | |
1379 bSet = TRUE; | |
1380 } | |
1381 } else { | |
1382 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != | |
1383 0) { | |
1384 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; | |
1385 bSet = TRUE; | |
1386 } | |
1387 } | |
1388 break; | |
1389 case EP_BOLD: | |
1390 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { | |
1391 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == | |
1392 0) { | |
1393 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; | |
1394 bSet = TRUE; | |
1395 } | |
1396 } else { | |
1397 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != | |
1398 0) { | |
1399 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; | |
1400 bSet = TRUE; | |
1401 } | |
1402 } | |
1403 break; | |
1404 case EP_ITALIC: | |
1405 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { | |
1406 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == | |
1407 0) { | |
1408 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; | |
1409 bSet = TRUE; | |
1410 } | |
1411 } else { | |
1412 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != | |
1413 0) { | |
1414 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; | |
1415 bSet = TRUE; | |
1416 } | |
1417 } | |
1418 break; | |
1419 default: | |
1420 break; | |
1421 } | |
1422 } | |
1423 } | 1282 } |
1424 } | 1283 } |
1425 | 1284 } |
1426 if (bSet) { | 1285 } else { |
1427 pIterator->SetSection(secinfo); | 1286 if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) { |
1428 | 1287 pIterator->SetAt(place); |
1429 if (bAddUndo && m_bEnableUndo) { | 1288 if (pIterator->GetSection(secinfo)) { |
1430 AddEditUndoItem(new CFXEU_SetSecProps( | 1289 if (bAddUndo) |
1431 this, place, eProps, OldSecinfo.SecProps, OldSecinfo.WordProps, | 1290 OldSecinfo = secinfo; |
1432 secinfo.SecProps, secinfo.WordProps, wr)); | 1291 |
| 1292 switch (eProps) { |
| 1293 case EP_FONTINDEX: |
| 1294 if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
| 1295 secinfo.WordProps.nFontIndex = pWordProps->nFontIndex; |
| 1296 bSet = TRUE; |
| 1297 } |
| 1298 break; |
| 1299 case EP_FONTSIZE: |
| 1300 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize, |
| 1301 pWordProps->fFontSize)) { |
| 1302 secinfo.WordProps.fFontSize = pWordProps->fFontSize; |
| 1303 bSet = TRUE; |
| 1304 } |
| 1305 break; |
| 1306 case EP_WORDCOLOR: |
| 1307 if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
| 1308 secinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
| 1309 bSet = TRUE; |
| 1310 } |
| 1311 break; |
| 1312 case EP_SCRIPTTYPE: |
| 1313 if (secinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
| 1314 secinfo.WordProps.nScriptType = pWordProps->nScriptType; |
| 1315 bSet = TRUE; |
| 1316 } |
| 1317 break; |
| 1318 case EP_CHARSPACE: |
| 1319 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace, |
| 1320 pWordProps->fCharSpace)) { |
| 1321 secinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
| 1322 bSet = TRUE; |
| 1323 } |
| 1324 break; |
| 1325 case EP_HORZSCALE: |
| 1326 if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
| 1327 secinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
| 1328 bSet = TRUE; |
| 1329 } |
| 1330 break; |
| 1331 case EP_UNDERLINE: |
| 1332 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1333 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == |
| 1334 0) { |
| 1335 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 1336 bSet = TRUE; |
| 1337 } |
| 1338 } else { |
| 1339 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != |
| 1340 0) { |
| 1341 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
| 1342 bSet = TRUE; |
| 1343 } |
| 1344 } |
| 1345 break; |
| 1346 case EP_CROSSOUT: |
| 1347 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1348 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == |
| 1349 0) { |
| 1350 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 1351 bSet = TRUE; |
| 1352 } |
| 1353 } else { |
| 1354 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != |
| 1355 0) { |
| 1356 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
| 1357 bSet = TRUE; |
| 1358 } |
| 1359 } |
| 1360 break; |
| 1361 case EP_BOLD: |
| 1362 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
| 1363 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { |
| 1364 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 1365 bSet = TRUE; |
| 1366 } |
| 1367 } else { |
| 1368 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { |
| 1369 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
| 1370 bSet = TRUE; |
| 1371 } |
| 1372 } |
| 1373 break; |
| 1374 case EP_ITALIC: |
| 1375 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
| 1376 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) { |
| 1377 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 1378 bSet = TRUE; |
| 1379 } |
| 1380 } else { |
| 1381 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) { |
| 1382 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
| 1383 bSet = TRUE; |
| 1384 } |
| 1385 } |
| 1386 break; |
| 1387 default: |
| 1388 break; |
1433 } | 1389 } |
1434 } | 1390 } |
1435 | |
1436 pIterator->SetAt(oldplace); | |
1437 | |
1438 return bSet; | |
1439 } | 1391 } |
1440 } | 1392 } |
1441 | 1393 |
1442 return FALSE; | 1394 if (bSet) { |
| 1395 pIterator->SetSection(secinfo); |
| 1396 |
| 1397 if (bAddUndo && m_bEnableUndo) { |
| 1398 AddEditUndoItem(new CFXEU_SetSecProps( |
| 1399 this, place, eProps, OldSecinfo.SecProps, OldSecinfo.WordProps, |
| 1400 secinfo.SecProps, secinfo.WordProps, wr)); |
| 1401 } |
| 1402 } |
| 1403 |
| 1404 pIterator->SetAt(oldplace); |
| 1405 |
| 1406 return bSet; |
1443 } | 1407 } |
1444 | 1408 |
1445 FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, | 1409 FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, |
1446 const CPVT_WordPlace& place, | 1410 const CPVT_WordPlace& place, |
1447 const CPVT_WordProps* pWordProps, | 1411 const CPVT_WordProps* pWordProps, |
1448 const CPVT_WordRange& wr, | 1412 const CPVT_WordRange& wr, |
1449 FX_BOOL bAddUndo) { | 1413 FX_BOOL bAddUndo) { |
1450 if (m_pVT->IsValid() && m_pVT->IsRichText()) { | 1414 if (!m_pVT->IsValid() || !m_pVT->IsRichText()) |
1451 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1415 return FALSE; |
1452 FX_BOOL bSet = FALSE; | 1416 |
1453 CPVT_Word wordinfo; | 1417 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1454 CPVT_Word OldWordinfo; | 1418 FX_BOOL bSet = FALSE; |
1455 | 1419 CPVT_Word wordinfo; |
1456 CPVT_WordPlace oldplace = pIterator->GetAt(); | 1420 CPVT_Word OldWordinfo; |
1457 | 1421 |
1458 if (pWordProps) { | 1422 CPVT_WordPlace oldplace = pIterator->GetAt(); |
1459 pIterator->SetAt(place); | 1423 |
1460 if (pIterator->GetWord(wordinfo)) { | 1424 if (pWordProps) { |
1461 if (bAddUndo) | 1425 pIterator->SetAt(place); |
1462 OldWordinfo = wordinfo; | 1426 if (pIterator->GetWord(wordinfo)) { |
1463 | 1427 if (bAddUndo) |
1464 switch (eProps) { | 1428 OldWordinfo = wordinfo; |
1465 case EP_FONTINDEX: | 1429 |
1466 if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { | 1430 switch (eProps) { |
1467 if (IPVT_FontMap* pFontMap = GetFontMap()) { | 1431 case EP_FONTINDEX: |
1468 wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex( | 1432 if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
1469 wordinfo.Word, wordinfo.nCharset, pWordProps->nFontIndex); | 1433 if (IPVT_FontMap* pFontMap = GetFontMap()) { |
1470 } | 1434 wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex( |
1471 bSet = TRUE; | 1435 wordinfo.Word, wordinfo.nCharset, pWordProps->nFontIndex); |
1472 } | 1436 } |
1473 break; | 1437 bSet = TRUE; |
1474 case EP_FONTSIZE: | 1438 } |
1475 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize, | 1439 break; |
1476 pWordProps->fFontSize)) { | 1440 case EP_FONTSIZE: |
1477 wordinfo.WordProps.fFontSize = pWordProps->fFontSize; | 1441 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize, |
1478 bSet = TRUE; | 1442 pWordProps->fFontSize)) { |
1479 } | 1443 wordinfo.WordProps.fFontSize = pWordProps->fFontSize; |
1480 break; | 1444 bSet = TRUE; |
1481 case EP_WORDCOLOR: | 1445 } |
1482 if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { | 1446 break; |
1483 wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor; | 1447 case EP_WORDCOLOR: |
1484 bSet = TRUE; | 1448 if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
1485 } | 1449 wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
1486 break; | 1450 bSet = TRUE; |
1487 case EP_SCRIPTTYPE: | 1451 } |
1488 if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType) { | 1452 break; |
1489 wordinfo.WordProps.nScriptType = pWordProps->nScriptType; | 1453 case EP_SCRIPTTYPE: |
1490 bSet = TRUE; | 1454 if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
1491 } | 1455 wordinfo.WordProps.nScriptType = pWordProps->nScriptType; |
1492 break; | 1456 bSet = TRUE; |
1493 case EP_CHARSPACE: | 1457 } |
1494 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace, | 1458 break; |
1495 pWordProps->fCharSpace)) { | 1459 case EP_CHARSPACE: |
1496 wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace; | 1460 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace, |
1497 bSet = TRUE; | 1461 pWordProps->fCharSpace)) { |
1498 } | 1462 wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
1499 break; | 1463 bSet = TRUE; |
1500 case EP_HORZSCALE: | 1464 } |
1501 if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { | 1465 break; |
1502 wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale; | 1466 case EP_HORZSCALE: |
1503 bSet = TRUE; | 1467 if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
1504 } | 1468 wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
1505 break; | 1469 bSet = TRUE; |
1506 case EP_UNDERLINE: | 1470 } |
1507 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { | 1471 break; |
1508 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == | 1472 case EP_UNDERLINE: |
1509 0) { | 1473 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
1510 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; | 1474 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == |
1511 bSet = TRUE; | 1475 0) { |
1512 } | 1476 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
1513 } else { | 1477 bSet = TRUE; |
1514 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != | 1478 } |
1515 0) { | 1479 } else { |
1516 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; | 1480 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != |
1517 bSet = TRUE; | 1481 0) { |
1518 } | 1482 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
1519 } | 1483 bSet = TRUE; |
1520 break; | 1484 } |
1521 case EP_CROSSOUT: | 1485 } |
1522 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { | 1486 break; |
1523 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == | 1487 case EP_CROSSOUT: |
1524 0) { | 1488 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
1525 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; | 1489 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == 0) { |
1526 bSet = TRUE; | 1490 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
1527 } | 1491 bSet = TRUE; |
1528 } else { | 1492 } |
1529 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != | 1493 } else { |
1530 0) { | 1494 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != 0) { |
1531 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; | 1495 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
1532 bSet = TRUE; | 1496 bSet = TRUE; |
1533 } | 1497 } |
1534 } | 1498 } |
1535 break; | 1499 break; |
1536 case EP_BOLD: | 1500 case EP_BOLD: |
1537 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { | 1501 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
1538 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { | 1502 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { |
1539 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; | 1503 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
1540 bSet = TRUE; | 1504 bSet = TRUE; |
1541 } | 1505 } |
1542 } else { | 1506 } else { |
1543 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { | 1507 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { |
1544 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; | 1508 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
1545 bSet = TRUE; | 1509 bSet = TRUE; |
1546 } | 1510 } |
1547 } | 1511 } |
1548 break; | 1512 break; |
1549 case EP_ITALIC: | 1513 case EP_ITALIC: |
1550 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { | 1514 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
1551 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == | 1515 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == 0) { |
1552 0) { | 1516 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
1553 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; | 1517 bSet = TRUE; |
1554 bSet = TRUE; | 1518 } |
1555 } | 1519 } else { |
1556 } else { | 1520 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != 0) { |
1557 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != | 1521 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
1558 0) { | 1522 bSet = TRUE; |
1559 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; | 1523 } |
1560 bSet = TRUE; | 1524 } |
1561 } | 1525 break; |
1562 } | 1526 default: |
1563 break; | 1527 break; |
1564 default: | |
1565 break; | |
1566 } | |
1567 } | |
1568 } | 1528 } |
1569 | |
1570 if (bSet) { | |
1571 pIterator->SetWord(wordinfo); | |
1572 | |
1573 if (bAddUndo && m_bEnableUndo) { | |
1574 AddEditUndoItem(new CFXEU_SetWordProps(this, place, eProps, | |
1575 OldWordinfo.WordProps, | |
1576 wordinfo.WordProps, wr)); | |
1577 } | |
1578 } | |
1579 | |
1580 pIterator->SetAt(oldplace); | |
1581 return bSet; | |
1582 } | 1529 } |
1583 } | 1530 } |
1584 | 1531 |
1585 return FALSE; | 1532 if (bSet) { |
| 1533 pIterator->SetWord(wordinfo); |
| 1534 |
| 1535 if (bAddUndo && m_bEnableUndo) { |
| 1536 AddEditUndoItem(new CFXEU_SetWordProps( |
| 1537 this, place, eProps, OldWordinfo.WordProps, wordinfo.WordProps, wr)); |
| 1538 } |
| 1539 } |
| 1540 |
| 1541 pIterator->SetAt(oldplace); |
| 1542 return bSet; |
1586 } | 1543 } |
1587 | 1544 |
1588 void CFX_Edit::SetText(const FX_WCHAR* text, | 1545 void CFX_Edit::SetText(const FX_WCHAR* text, |
1589 int32_t charset, | 1546 int32_t charset, |
1590 const CPVT_SecProps* pSecProps, | 1547 const CPVT_SecProps* pSecProps, |
1591 const CPVT_WordProps* pWordProps) { | 1548 const CPVT_WordProps* pWordProps) { |
1592 SetText(text, charset, pSecProps, pWordProps, TRUE, TRUE); | 1549 SetText(text, charset, pSecProps, pWordProps, TRUE, TRUE); |
1593 } | 1550 } |
1594 | 1551 |
1595 FX_BOOL CFX_Edit::InsertWord(uint16_t word, | 1552 FX_BOOL CFX_Edit::InsertWord(uint16_t word, |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1911 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) { | 1868 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) { |
1912 SetScrollPosY(rcContent.top); | 1869 SetScrollPosY(rcContent.top); |
1913 } | 1870 } |
1914 } | 1871 } |
1915 } | 1872 } |
1916 } | 1873 } |
1917 | 1874 |
1918 void CFX_Edit::ScrollToCaret() { | 1875 void CFX_Edit::ScrollToCaret() { |
1919 SetScrollLimit(); | 1876 SetScrollLimit(); |
1920 | 1877 |
1921 if (m_pVT->IsValid()) { | 1878 if (!m_pVT->IsValid()) |
1922 CFX_FloatPoint ptHead(0, 0); | 1879 return; |
1923 CFX_FloatPoint ptFoot(0, 0); | |
1924 | 1880 |
1925 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1881 CFX_FloatPoint ptHead(0, 0); |
1926 pIterator->SetAt(m_wpCaret); | 1882 CFX_FloatPoint ptFoot(0, 0); |
1927 | 1883 |
1928 CPVT_Word word; | 1884 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
1929 CPVT_Line line; | 1885 pIterator->SetAt(m_wpCaret); |
1930 if (pIterator->GetWord(word)) { | 1886 |
1931 ptHead.x = word.ptWord.x + word.fWidth; | 1887 CPVT_Word word; |
1932 ptHead.y = word.ptWord.y + word.fAscent; | 1888 CPVT_Line line; |
1933 ptFoot.x = word.ptWord.x + word.fWidth; | 1889 if (pIterator->GetWord(word)) { |
1934 ptFoot.y = word.ptWord.y + word.fDescent; | 1890 ptHead.x = word.ptWord.x + word.fWidth; |
1935 } else if (pIterator->GetLine(line)) { | 1891 ptHead.y = word.ptWord.y + word.fAscent; |
1936 ptHead.x = line.ptLine.x; | 1892 ptFoot.x = word.ptWord.x + word.fWidth; |
1937 ptHead.y = line.ptLine.y + line.fLineAscent; | 1893 ptFoot.y = word.ptWord.y + word.fDescent; |
1938 ptFoot.x = line.ptLine.x; | 1894 } else if (pIterator->GetLine(line)) { |
1939 ptFoot.y = line.ptLine.y + line.fLineDescent; | 1895 ptHead.x = line.ptLine.x; |
| 1896 ptHead.y = line.ptLine.y + line.fLineAscent; |
| 1897 ptFoot.x = line.ptLine.x; |
| 1898 ptFoot.y = line.ptLine.y + line.fLineDescent; |
| 1899 } |
| 1900 |
| 1901 CFX_FloatPoint ptHeadEdit = VTToEdit(ptHead); |
| 1902 CFX_FloatPoint ptFootEdit = VTToEdit(ptFoot); |
| 1903 |
| 1904 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); |
| 1905 |
| 1906 if (!FX_EDIT_IsFloatEqual(rcPlate.left, rcPlate.right)) { |
| 1907 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || |
| 1908 FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) { |
| 1909 SetScrollPosX(ptHead.x); |
| 1910 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) { |
| 1911 SetScrollPosX(ptHead.x - rcPlate.Width()); |
| 1912 } |
| 1913 } |
| 1914 |
| 1915 if (!FX_EDIT_IsFloatEqual(rcPlate.top, rcPlate.bottom)) { |
| 1916 if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || |
| 1917 FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) { |
| 1918 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) { |
| 1919 SetScrollPosY(ptFoot.y + rcPlate.Height()); |
1940 } | 1920 } |
1941 } | 1921 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) { |
1942 | 1922 if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) { |
1943 CFX_FloatPoint ptHeadEdit = VTToEdit(ptHead); | 1923 SetScrollPosY(ptHead.y); |
1944 CFX_FloatPoint ptFootEdit = VTToEdit(ptFoot); | |
1945 | |
1946 CFX_FloatRect rcPlate = m_pVT->GetPlateRect(); | |
1947 | |
1948 if (!FX_EDIT_IsFloatEqual(rcPlate.left, rcPlate.right)) { | |
1949 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || | |
1950 FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) { | |
1951 SetScrollPosX(ptHead.x); | |
1952 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) { | |
1953 SetScrollPosX(ptHead.x - rcPlate.Width()); | |
1954 } | |
1955 } | |
1956 | |
1957 if (!FX_EDIT_IsFloatEqual(rcPlate.top, rcPlate.bottom)) { | |
1958 if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || | |
1959 FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) { | |
1960 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) { | |
1961 SetScrollPosY(ptFoot.y + rcPlate.Height()); | |
1962 } | |
1963 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) { | |
1964 if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) { | |
1965 SetScrollPosY(ptHead.y); | |
1966 } | |
1967 } | 1924 } |
1968 } | 1925 } |
1969 } | 1926 } |
1970 } | 1927 } |
1971 | 1928 |
1972 void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan, | 1929 void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan, |
1973 const CPVT_WordRange* pRange1, | 1930 const CPVT_WordRange* pRange1, |
1974 const CPVT_WordRange* pRange2) { | 1931 const CPVT_WordRange* pRange2) { |
1975 if (m_bEnableRefresh && m_pVT->IsValid()) { | 1932 if (m_bEnableRefresh && m_pVT->IsValid()) { |
1976 m_Refresh.BeginRefresh(); | 1933 m_Refresh.BeginRefresh(); |
(...skipping 11 matching lines...) Expand all Loading... |
1988 } | 1945 } |
1989 m_bNotifyFlag = FALSE; | 1946 m_bNotifyFlag = FALSE; |
1990 } | 1947 } |
1991 } | 1948 } |
1992 | 1949 |
1993 m_Refresh.EndRefresh(); | 1950 m_Refresh.EndRefresh(); |
1994 } | 1951 } |
1995 } | 1952 } |
1996 | 1953 |
1997 void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) { | 1954 void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) { |
1998 if (m_pVT->IsValid()) { | 1955 if (!m_pVT->IsValid()) |
1999 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1956 return; |
2000 CPVT_WordPlace wpBegin = wr.BeginPos; | |
2001 m_pVT->UpdateWordPlace(wpBegin); | |
2002 CPVT_WordPlace wpEnd = wr.EndPos; | |
2003 m_pVT->UpdateWordPlace(wpEnd); | |
2004 pIterator->SetAt(wpBegin); | |
2005 | 1957 |
2006 CPVT_Line lineinfo; | 1958 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2007 do { | 1959 CPVT_WordPlace wpBegin = wr.BeginPos; |
2008 if (!pIterator->GetLine(lineinfo)) | 1960 m_pVT->UpdateWordPlace(wpBegin); |
2009 break; | 1961 CPVT_WordPlace wpEnd = wr.EndPos; |
2010 if (lineinfo.lineplace.LineCmp(wpEnd) > 0) | 1962 m_pVT->UpdateWordPlace(wpEnd); |
2011 break; | 1963 pIterator->SetAt(wpBegin); |
2012 | 1964 |
2013 CFX_FloatRect rcLine(lineinfo.ptLine.x, | 1965 CPVT_Line lineinfo; |
2014 lineinfo.ptLine.y + lineinfo.fLineDescent, | 1966 do { |
2015 lineinfo.ptLine.x + lineinfo.fLineWidth, | 1967 if (!pIterator->GetLine(lineinfo)) |
2016 lineinfo.ptLine.y + lineinfo.fLineAscent); | 1968 break; |
| 1969 if (lineinfo.lineplace.LineCmp(wpEnd) > 0) |
| 1970 break; |
2017 | 1971 |
2018 m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd), | 1972 CFX_FloatRect rcLine(lineinfo.ptLine.x, |
2019 VTToEdit(rcLine)); | 1973 lineinfo.ptLine.y + lineinfo.fLineDescent, |
2020 } while (pIterator->NextLine()); | 1974 lineinfo.ptLine.x + lineinfo.fLineWidth, |
2021 } | 1975 lineinfo.ptLine.y + lineinfo.fLineAscent); |
2022 } | 1976 |
| 1977 m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd), |
| 1978 VTToEdit(rcLine)); |
| 1979 } while (pIterator->NextLine()); |
2023 } | 1980 } |
2024 | 1981 |
2025 void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange& wr) { | 1982 void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange& wr) { |
2026 if (m_pVT->IsValid()) { | 1983 if (!m_pVT->IsValid()) |
2027 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 1984 return; |
2028 CPVT_WordRange wrTemp = wr; | |
2029 | 1985 |
2030 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | 1986 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2031 m_pVT->UpdateWordPlace(wrTemp.EndPos); | 1987 CPVT_WordRange wrTemp = wr; |
2032 pIterator->SetAt(wrTemp.BeginPos); | |
2033 | 1988 |
2034 CPVT_Word wordinfo; | 1989 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
2035 CPVT_Line lineinfo; | 1990 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
2036 CPVT_WordPlace place; | 1991 pIterator->SetAt(wrTemp.BeginPos); |
2037 | 1992 |
2038 while (pIterator->NextWord()) { | 1993 CPVT_Word wordinfo; |
2039 place = pIterator->GetAt(); | 1994 CPVT_Line lineinfo; |
2040 if (place.WordCmp(wrTemp.EndPos) > 0) | 1995 CPVT_WordPlace place; |
2041 break; | |
2042 | 1996 |
2043 pIterator->GetWord(wordinfo); | 1997 while (pIterator->NextWord()) { |
2044 pIterator->GetLine(lineinfo); | 1998 place = pIterator->GetAt(); |
| 1999 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 2000 break; |
2045 | 2001 |
2046 if (place.LineCmp(wrTemp.BeginPos) == 0 || | 2002 pIterator->GetWord(wordinfo); |
2047 place.LineCmp(wrTemp.EndPos) == 0) { | 2003 pIterator->GetLine(lineinfo); |
2048 CFX_FloatRect rcWord(wordinfo.ptWord.x, | |
2049 lineinfo.ptLine.y + lineinfo.fLineDescent, | |
2050 wordinfo.ptWord.x + wordinfo.fWidth, | |
2051 lineinfo.ptLine.y + lineinfo.fLineAscent); | |
2052 | 2004 |
2053 m_Refresh.AddRefresh(VTToEdit(rcWord)); | 2005 if (place.LineCmp(wrTemp.BeginPos) == 0 || |
2054 } else { | 2006 place.LineCmp(wrTemp.EndPos) == 0) { |
2055 CFX_FloatRect rcLine(lineinfo.ptLine.x, | 2007 CFX_FloatRect rcWord(wordinfo.ptWord.x, |
2056 lineinfo.ptLine.y + lineinfo.fLineDescent, | 2008 lineinfo.ptLine.y + lineinfo.fLineDescent, |
2057 lineinfo.ptLine.x + lineinfo.fLineWidth, | 2009 wordinfo.ptWord.x + wordinfo.fWidth, |
2058 lineinfo.ptLine.y + lineinfo.fLineAscent); | 2010 lineinfo.ptLine.y + lineinfo.fLineAscent); |
2059 | 2011 |
2060 m_Refresh.AddRefresh(VTToEdit(rcLine)); | 2012 m_Refresh.AddRefresh(VTToEdit(rcWord)); |
| 2013 } else { |
| 2014 CFX_FloatRect rcLine(lineinfo.ptLine.x, |
| 2015 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2016 lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2017 lineinfo.ptLine.y + lineinfo.fLineAscent); |
2061 | 2018 |
2062 pIterator->NextLine(); | 2019 m_Refresh.AddRefresh(VTToEdit(rcLine)); |
2063 } | 2020 |
2064 } | 2021 pIterator->NextLine(); |
2065 } | 2022 } |
2066 } | 2023 } |
2067 } | 2024 } |
2068 | 2025 |
2069 void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { | 2026 void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { |
2070 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2027 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2071 CPVT_WordRange wrTemp = wr; | 2028 CPVT_WordRange wrTemp = wr; |
2072 | 2029 |
2073 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | 2030 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
2074 m_pVT->UpdateWordPlace(wrTemp.EndPos); | 2031 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
2075 pIterator->SetAt(wrTemp.BeginPos); | 2032 pIterator->SetAt(wrTemp.BeginPos); |
2076 | 2033 |
2077 CPVT_Word wordinfo; | 2034 CPVT_Word wordinfo; |
2078 CPVT_Line lineinfo; | 2035 CPVT_Line lineinfo; |
2079 CPVT_WordPlace place; | 2036 CPVT_WordPlace place; |
2080 | 2037 |
2081 while (pIterator->NextWord()) { | 2038 while (pIterator->NextWord()) { |
2082 place = pIterator->GetAt(); | 2039 place = pIterator->GetAt(); |
2083 if (place.WordCmp(wrTemp.EndPos) > 0) | 2040 if (place.WordCmp(wrTemp.EndPos) > 0) |
2084 break; | 2041 break; |
2085 | 2042 |
2086 pIterator->GetWord(wordinfo); | 2043 pIterator->GetWord(wordinfo); |
2087 pIterator->GetLine(lineinfo); | 2044 pIterator->GetLine(lineinfo); |
2088 | 2045 |
2089 if (place.LineCmp(wrTemp.BeginPos) == 0 || | 2046 if (place.LineCmp(wrTemp.BeginPos) == 0 || |
2090 place.LineCmp(wrTemp.EndPos) == 0) { | 2047 place.LineCmp(wrTemp.EndPos) == 0) { |
2091 CFX_FloatRect rcWord(wordinfo.ptWord.x, | 2048 CFX_FloatRect rcWord(wordinfo.ptWord.x, |
2092 lineinfo.ptLine.y + lineinfo.fLineDescent, | 2049 lineinfo.ptLine.y + lineinfo.fLineDescent, |
2093 wordinfo.ptWord.x + wordinfo.fWidth, | 2050 wordinfo.ptWord.x + wordinfo.fWidth, |
2094 lineinfo.ptLine.y + lineinfo.fLineAscent); | 2051 lineinfo.ptLine.y + lineinfo.fLineAscent); |
2095 | 2052 |
2096 if (m_bNotify && m_pNotify) { | 2053 if (m_bNotify && m_pNotify) { |
2097 if (!m_bNotifyFlag) { | 2054 if (!m_bNotifyFlag) { |
2098 m_bNotifyFlag = TRUE; | 2055 m_bNotifyFlag = TRUE; |
2099 CFX_FloatRect rcRefresh = VTToEdit(rcWord); | 2056 CFX_FloatRect rcRefresh = VTToEdit(rcWord); |
2100 m_pNotify->IOnInvalidateRect(&rcRefresh); | 2057 m_pNotify->IOnInvalidateRect(&rcRefresh); |
2101 m_bNotifyFlag = FALSE; | 2058 m_bNotifyFlag = FALSE; |
2102 } | |
2103 } | 2059 } |
2104 } else { | 2060 } |
2105 CFX_FloatRect rcLine(lineinfo.ptLine.x, | 2061 } else { |
2106 lineinfo.ptLine.y + lineinfo.fLineDescent, | 2062 CFX_FloatRect rcLine(lineinfo.ptLine.x, |
2107 lineinfo.ptLine.x + lineinfo.fLineWidth, | 2063 lineinfo.ptLine.y + lineinfo.fLineDescent, |
2108 lineinfo.ptLine.y + lineinfo.fLineAscent); | 2064 lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2065 lineinfo.ptLine.y + lineinfo.fLineAscent); |
2109 | 2066 |
2110 if (m_bNotify && m_pNotify) { | 2067 if (m_bNotify && m_pNotify) { |
2111 if (!m_bNotifyFlag) { | 2068 if (!m_bNotifyFlag) { |
2112 m_bNotifyFlag = TRUE; | 2069 m_bNotifyFlag = TRUE; |
2113 CFX_FloatRect rcRefresh = VTToEdit(rcLine); | 2070 CFX_FloatRect rcRefresh = VTToEdit(rcLine); |
2114 m_pNotify->IOnInvalidateRect(&rcRefresh); | 2071 m_pNotify->IOnInvalidateRect(&rcRefresh); |
2115 m_bNotifyFlag = FALSE; | 2072 m_bNotifyFlag = FALSE; |
2116 } | |
2117 } | 2073 } |
| 2074 } |
2118 | 2075 |
2119 pIterator->NextLine(); | 2076 pIterator->NextLine(); |
2120 } | |
2121 } | 2077 } |
2122 } | 2078 } |
2123 } | 2079 } |
2124 | 2080 |
2125 void CFX_Edit::SetCaret(const CPVT_WordPlace& place) { | 2081 void CFX_Edit::SetCaret(const CPVT_WordPlace& place) { |
2126 m_wpOldCaret = m_wpCaret; | 2082 m_wpOldCaret = m_wpCaret; |
2127 m_wpCaret = place; | 2083 m_wpCaret = place; |
2128 } | 2084 } |
2129 | 2085 |
2130 void CFX_Edit::SetCaretInfo() { | 2086 void CFX_Edit::SetCaretInfo() { |
2131 if (m_bNotify && m_pNotify) { | 2087 if (m_bNotify && m_pNotify) { |
2132 if (!m_bNotifyFlag) { | 2088 if (!m_bNotifyFlag) { |
2133 CFX_FloatPoint ptHead(0.0f, 0.0f), ptFoot(0.0f, 0.0f); | 2089 CFX_FloatPoint ptHead(0.0f, 0.0f), ptFoot(0.0f, 0.0f); |
2134 | 2090 |
2135 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2091 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2136 pIterator->SetAt(m_wpCaret); | 2092 pIterator->SetAt(m_wpCaret); |
2137 CPVT_Word word; | 2093 CPVT_Word word; |
2138 CPVT_Line line; | 2094 CPVT_Line line; |
2139 if (pIterator->GetWord(word)) { | 2095 if (pIterator->GetWord(word)) { |
2140 ptHead.x = word.ptWord.x + word.fWidth; | 2096 ptHead.x = word.ptWord.x + word.fWidth; |
2141 ptHead.y = word.ptWord.y + word.fAscent; | 2097 ptHead.y = word.ptWord.y + word.fAscent; |
2142 ptFoot.x = word.ptWord.x + word.fWidth; | 2098 ptFoot.x = word.ptWord.x + word.fWidth; |
2143 ptFoot.y = word.ptWord.y + word.fDescent; | 2099 ptFoot.y = word.ptWord.y + word.fDescent; |
2144 } else if (pIterator->GetLine(line)) { | 2100 } else if (pIterator->GetLine(line)) { |
2145 ptHead.x = line.ptLine.x; | 2101 ptHead.x = line.ptLine.x; |
2146 ptHead.y = line.ptLine.y + line.fLineAscent; | 2102 ptHead.y = line.ptLine.y + line.fLineAscent; |
2147 ptFoot.x = line.ptLine.x; | 2103 ptFoot.x = line.ptLine.x; |
2148 ptFoot.y = line.ptLine.y + line.fLineDescent; | 2104 ptFoot.y = line.ptLine.y + line.fLineDescent; |
2149 } | |
2150 } | 2105 } |
2151 | 2106 |
2152 m_bNotifyFlag = TRUE; | 2107 m_bNotifyFlag = TRUE; |
2153 m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead), | 2108 m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead), |
2154 VTToEdit(ptFoot), m_wpCaret); | 2109 VTToEdit(ptFoot), m_wpCaret); |
2155 m_bNotifyFlag = FALSE; | 2110 m_bNotifyFlag = FALSE; |
2156 } | 2111 } |
2157 } | 2112 } |
2158 | 2113 |
2159 SetCaretChange(); | 2114 SetCaretChange(); |
2160 } | 2115 } |
2161 | 2116 |
2162 void CFX_Edit::SetCaretChange() { | 2117 void CFX_Edit::SetCaretChange() { |
2163 if (m_wpCaret == m_wpOldCaret) | 2118 if (m_wpCaret == m_wpOldCaret) |
2164 return; | 2119 return; |
2165 | 2120 |
2166 if (m_bNotify && m_pVT->IsRichText() && m_pNotify) { | 2121 if (!m_bNotify || !m_pVT->IsRichText() || !m_pNotify) |
2167 CPVT_SecProps SecProps; | 2122 return; |
2168 CPVT_WordProps WordProps; | |
2169 | 2123 |
2170 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2124 CPVT_SecProps SecProps; |
2171 pIterator->SetAt(m_wpCaret); | 2125 CPVT_WordProps WordProps; |
2172 CPVT_Word word; | |
2173 CPVT_Section section; | |
2174 | 2126 |
2175 if (pIterator->GetSection(section)) { | 2127 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2176 SecProps = section.SecProps; | 2128 pIterator->SetAt(m_wpCaret); |
2177 WordProps = section.WordProps; | 2129 CPVT_Word word; |
2178 } | 2130 CPVT_Section section; |
2179 | 2131 |
2180 if (pIterator->GetWord(word)) { | 2132 if (pIterator->GetSection(section)) { |
2181 WordProps = word.WordProps; | 2133 SecProps = section.SecProps; |
2182 } | 2134 WordProps = section.WordProps; |
2183 } | 2135 } |
2184 | 2136 |
2185 if (!m_bNotifyFlag) { | 2137 if (pIterator->GetWord(word)) |
2186 m_bNotifyFlag = TRUE; | 2138 WordProps = word.WordProps; |
2187 m_pNotify->IOnCaretChange(SecProps, WordProps); | 2139 |
2188 m_bNotifyFlag = FALSE; | 2140 if (!m_bNotifyFlag) { |
2189 } | 2141 m_bNotifyFlag = TRUE; |
| 2142 m_pNotify->IOnCaretChange(SecProps, WordProps); |
| 2143 m_bNotifyFlag = FALSE; |
2190 } | 2144 } |
2191 } | 2145 } |
2192 | 2146 |
2193 void CFX_Edit::SetCaret(int32_t nPos) { | 2147 void CFX_Edit::SetCaret(int32_t nPos) { |
2194 if (m_pVT->IsValid()) { | 2148 if (m_pVT->IsValid()) { |
2195 SelectNone(); | 2149 SelectNone(); |
2196 SetCaret(m_pVT->WordIndexToWordPlace(nPos)); | 2150 SetCaret(m_pVT->WordIndexToWordPlace(nPos)); |
2197 m_SelState.Set(m_wpCaret, m_wpCaret); | 2151 m_SelState.Set(m_wpCaret, m_wpCaret); |
2198 | 2152 |
2199 ScrollToCaret(); | 2153 ScrollToCaret(); |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2543 | 2497 |
2544 FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) { | 2498 FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
2545 if (m_pVT->IsValid()) { | 2499 if (m_pVT->IsValid()) { |
2546 if (m_wpCaret == m_pVT->GetBeginWordPlace()) | 2500 if (m_wpCaret == m_pVT->GetBeginWordPlace()) |
2547 return FALSE; | 2501 return FALSE; |
2548 | 2502 |
2549 CPVT_Section section; | 2503 CPVT_Section section; |
2550 CPVT_Word word; | 2504 CPVT_Word word; |
2551 | 2505 |
2552 if (bAddUndo) { | 2506 if (bAddUndo) { |
2553 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2507 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2554 pIterator->SetAt(m_wpCaret); | 2508 pIterator->SetAt(m_wpCaret); |
2555 pIterator->GetSection(section); | 2509 pIterator->GetSection(section); |
2556 pIterator->GetWord(word); | 2510 pIterator->GetWord(word); |
2557 } | |
2558 } | 2511 } |
2559 | 2512 |
2560 m_pVT->UpdateWordPlace(m_wpCaret); | 2513 m_pVT->UpdateWordPlace(m_wpCaret); |
2561 SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); | 2514 SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); |
2562 m_SelState.Set(m_wpCaret, m_wpCaret); | 2515 m_SelState.Set(m_wpCaret, m_wpCaret); |
2563 | 2516 |
2564 if (m_wpCaret != m_wpOldCaret) { | 2517 if (m_wpCaret != m_wpOldCaret) { |
2565 if (bAddUndo && m_bEnableUndo) { | 2518 if (bAddUndo && m_bEnableUndo) { |
2566 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) | 2519 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) |
2567 AddEditUndoItem(new CFXEU_Backspace( | 2520 AddEditUndoItem(new CFXEU_Backspace( |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2606 | 2559 |
2607 FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) { | 2560 FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
2608 if (m_pVT->IsValid()) { | 2561 if (m_pVT->IsValid()) { |
2609 if (m_wpCaret == m_pVT->GetEndWordPlace()) | 2562 if (m_wpCaret == m_pVT->GetEndWordPlace()) |
2610 return FALSE; | 2563 return FALSE; |
2611 | 2564 |
2612 CPVT_Section section; | 2565 CPVT_Section section; |
2613 CPVT_Word word; | 2566 CPVT_Word word; |
2614 | 2567 |
2615 if (bAddUndo) { | 2568 if (bAddUndo) { |
2616 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2569 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2617 pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); | 2570 pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); |
2618 pIterator->GetSection(section); | 2571 pIterator->GetSection(section); |
2619 pIterator->GetWord(word); | 2572 pIterator->GetWord(word); |
2620 } | |
2621 } | 2573 } |
2622 | 2574 |
2623 m_pVT->UpdateWordPlace(m_wpCaret); | 2575 m_pVT->UpdateWordPlace(m_wpCaret); |
2624 FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); | 2576 FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); |
2625 | 2577 |
2626 SetCaret(m_pVT->DeleteWord(m_wpCaret)); | 2578 SetCaret(m_pVT->DeleteWord(m_wpCaret)); |
2627 m_SelState.Set(m_wpCaret, m_wpCaret); | 2579 m_SelState.Set(m_wpCaret, m_wpCaret); |
2628 | 2580 |
2629 if (bAddUndo && m_bEnableUndo) { | 2581 if (bAddUndo && m_bEnableUndo) { |
2630 if (bSecEnd) | 2582 if (bSecEnd) |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2672 m_pVT->DeleteWords(GetWholeWordRange()); | 2624 m_pVT->DeleteWords(GetWholeWordRange()); |
2673 SetCaret(m_pVT->GetBeginWordPlace()); | 2625 SetCaret(m_pVT->GetBeginWordPlace()); |
2674 | 2626 |
2675 return TRUE; | 2627 return TRUE; |
2676 } | 2628 } |
2677 | 2629 |
2678 return FALSE; | 2630 return FALSE; |
2679 } | 2631 } |
2680 | 2632 |
2681 FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) { | 2633 FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
2682 if (m_pVT->IsValid()) { | 2634 if (!m_pVT->IsValid()) |
2683 if (m_SelState.IsExist()) { | 2635 return FALSE; |
2684 CPVT_WordRange range = m_SelState.ConvertToWordRange(); | |
2685 | 2636 |
2686 if (bAddUndo && m_bEnableUndo) { | 2637 if (!m_SelState.IsExist()) |
2687 if (m_pVT->IsRichText()) { | 2638 return FALSE; |
2688 BeginGroupUndo(L""); | |
2689 | 2639 |
2690 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2640 CPVT_WordRange range = m_SelState.ConvertToWordRange(); |
2691 pIterator->SetAt(range.EndPos); | |
2692 | 2641 |
2693 CPVT_Word wordinfo; | 2642 if (bAddUndo && m_bEnableUndo) { |
2694 CPVT_Section secinfo; | 2643 if (m_pVT->IsRichText()) { |
2695 do { | 2644 BeginGroupUndo(L""); |
2696 CPVT_WordPlace place = pIterator->GetAt(); | |
2697 if (place.WordCmp(range.BeginPos) <= 0) | |
2698 break; | |
2699 | 2645 |
2700 CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place); | 2646 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
| 2647 pIterator->SetAt(range.EndPos); |
2701 | 2648 |
2702 if (oldplace.SecCmp(place) != 0) { | 2649 CPVT_Word wordinfo; |
2703 if (pIterator->GetSection(secinfo)) { | 2650 CPVT_Section secinfo; |
2704 AddEditUndoItem(new CFXEU_ClearRich( | 2651 do { |
2705 this, oldplace, place, range, wordinfo.Word, | 2652 CPVT_WordPlace place = pIterator->GetAt(); |
2706 wordinfo.nCharset, secinfo.SecProps, secinfo.WordProps)); | 2653 if (place.WordCmp(range.BeginPos) <= 0) |
2707 } | 2654 break; |
2708 } else { | |
2709 if (pIterator->GetWord(wordinfo)) { | |
2710 oldplace = m_pVT->AdjustLineHeader(oldplace, TRUE); | |
2711 place = m_pVT->AdjustLineHeader(place, TRUE); | |
2712 | 2655 |
2713 AddEditUndoItem(new CFXEU_ClearRich( | 2656 CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place); |
2714 this, oldplace, place, range, wordinfo.Word, | 2657 |
2715 wordinfo.nCharset, secinfo.SecProps, wordinfo.WordProps)); | 2658 if (oldplace.SecCmp(place) != 0) { |
2716 } | 2659 if (pIterator->GetSection(secinfo)) { |
2717 } | 2660 AddEditUndoItem(new CFXEU_ClearRich( |
2718 } while (pIterator->PrevWord()); | 2661 this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset, |
| 2662 secinfo.SecProps, secinfo.WordProps)); |
2719 } | 2663 } |
2720 EndGroupUndo(); | |
2721 } else { | 2664 } else { |
2722 AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText())); | 2665 if (pIterator->GetWord(wordinfo)) { |
| 2666 oldplace = m_pVT->AdjustLineHeader(oldplace, TRUE); |
| 2667 place = m_pVT->AdjustLineHeader(place, TRUE); |
| 2668 |
| 2669 AddEditUndoItem(new CFXEU_ClearRich( |
| 2670 this, oldplace, place, range, wordinfo.Word, wordinfo.nCharset, |
| 2671 secinfo.SecProps, wordinfo.WordProps)); |
| 2672 } |
2723 } | 2673 } |
2724 } | 2674 } while (pIterator->PrevWord()); |
2725 | 2675 EndGroupUndo(); |
2726 SelectNone(); | 2676 } else { |
2727 SetCaret(m_pVT->DeleteWords(range)); | 2677 AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText())); |
2728 m_SelState.Set(m_wpCaret, m_wpCaret); | |
2729 | |
2730 if (bPaint) { | |
2731 RearrangePart(range); | |
2732 ScrollToCaret(); | |
2733 | |
2734 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); | |
2735 Refresh(RP_ANALYSE, &wr); | |
2736 | |
2737 SetCaretOrigin(); | |
2738 SetCaretInfo(); | |
2739 } | |
2740 | |
2741 if (m_bOprNotify && m_pOprNotify) | |
2742 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); | |
2743 | |
2744 return TRUE; | |
2745 } | 2678 } |
2746 } | 2679 } |
2747 | 2680 |
2748 return FALSE; | 2681 SelectNone(); |
| 2682 SetCaret(m_pVT->DeleteWords(range)); |
| 2683 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2684 |
| 2685 if (bPaint) { |
| 2686 RearrangePart(range); |
| 2687 ScrollToCaret(); |
| 2688 |
| 2689 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); |
| 2690 Refresh(RP_ANALYSE, &wr); |
| 2691 |
| 2692 SetCaretOrigin(); |
| 2693 SetCaretInfo(); |
| 2694 } |
| 2695 |
| 2696 if (m_bOprNotify && m_pOprNotify) |
| 2697 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); |
| 2698 |
| 2699 return TRUE; |
2749 } | 2700 } |
2750 | 2701 |
2751 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, | 2702 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, |
2752 int32_t charset, | 2703 int32_t charset, |
2753 const CPVT_SecProps* pSecProps, | 2704 const CPVT_SecProps* pSecProps, |
2754 const CPVT_WordProps* pWordProps, | 2705 const CPVT_WordProps* pWordProps, |
2755 FX_BOOL bAddUndo, | 2706 FX_BOOL bAddUndo, |
2756 FX_BOOL bPaint) { | 2707 FX_BOOL bPaint) { |
2757 if (IsTextOverflow()) | 2708 if (IsTextOverflow()) |
2758 return FALSE; | 2709 return FALSE; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2812 if (m_Undo.CanUndo()) { | 2763 if (m_Undo.CanUndo()) { |
2813 m_Undo.Undo(); | 2764 m_Undo.Undo(); |
2814 return TRUE; | 2765 return TRUE; |
2815 } | 2766 } |
2816 } | 2767 } |
2817 | 2768 |
2818 return FALSE; | 2769 return FALSE; |
2819 } | 2770 } |
2820 | 2771 |
2821 void CFX_Edit::SetCaretOrigin() { | 2772 void CFX_Edit::SetCaretOrigin() { |
2822 if (m_pVT->IsValid()) { | 2773 if (!m_pVT->IsValid()) |
2823 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2774 return; |
2824 pIterator->SetAt(m_wpCaret); | 2775 |
2825 CPVT_Word word; | 2776 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2826 CPVT_Line line; | 2777 pIterator->SetAt(m_wpCaret); |
2827 if (pIterator->GetWord(word)) { | 2778 CPVT_Word word; |
2828 m_ptCaret.x = word.ptWord.x + word.fWidth; | 2779 CPVT_Line line; |
2829 m_ptCaret.y = word.ptWord.y; | 2780 if (pIterator->GetWord(word)) { |
2830 } else if (pIterator->GetLine(line)) { | 2781 m_ptCaret.x = word.ptWord.x + word.fWidth; |
2831 m_ptCaret.x = line.ptLine.x; | 2782 m_ptCaret.y = word.ptWord.y; |
2832 m_ptCaret.y = line.ptLine.y; | 2783 } else if (pIterator->GetLine(line)) { |
2833 } | 2784 m_ptCaret.x = line.ptLine.x; |
2834 } | 2785 m_ptCaret.y = line.ptLine.y; |
2835 } | 2786 } |
2836 } | 2787 } |
2837 | 2788 |
2838 int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace& place) const { | 2789 int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace& place) const { |
2839 if (m_pVT->IsValid()) | 2790 if (m_pVT->IsValid()) |
2840 return m_pVT->WordPlaceToWordIndex(place); | 2791 return m_pVT->WordPlaceToWordIndex(place); |
2841 | 2792 |
2842 return -1; | 2793 return -1; |
2843 } | 2794 } |
2844 | 2795 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2926 | 2877 |
2927 void CFX_Edit::EnableNotify(FX_BOOL bNotify) { | 2878 void CFX_Edit::EnableNotify(FX_BOOL bNotify) { |
2928 m_bNotify = bNotify; | 2879 m_bNotify = bNotify; |
2929 } | 2880 } |
2930 | 2881 |
2931 void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) { | 2882 void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) { |
2932 m_bOprNotify = bNotify; | 2883 m_bOprNotify = bNotify; |
2933 } | 2884 } |
2934 | 2885 |
2935 FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const { | 2886 FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const { |
2936 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2887 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2937 CPVT_WordPlace wpOld = pIterator->GetAt(); | 2888 CPVT_WordPlace wpOld = pIterator->GetAt(); |
2938 | 2889 |
2939 pIterator->SetAt(place); | 2890 pIterator->SetAt(place); |
2940 CPVT_Line line; | 2891 CPVT_Line line; |
2941 pIterator->GetLine(line); | 2892 pIterator->GetLine(line); |
2942 | 2893 |
2943 pIterator->SetAt(wpOld); | 2894 pIterator->SetAt(wpOld); |
2944 | 2895 |
2945 return line.ptLine.y + line.fLineAscent; | 2896 return line.ptLine.y + line.fLineAscent; |
2946 } | |
2947 | |
2948 return 0.0f; | |
2949 } | 2897 } |
2950 | 2898 |
2951 FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const { | 2899 FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const { |
2952 if (CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator()) { | 2900 CPDF_VariableText::Iterator* pIterator = m_pVT->GetIterator(); |
2953 CPVT_WordPlace wpOld = pIterator->GetAt(); | 2901 CPVT_WordPlace wpOld = pIterator->GetAt(); |
2954 | 2902 |
2955 pIterator->SetAt(place); | 2903 pIterator->SetAt(place); |
2956 CPVT_Line line; | 2904 CPVT_Line line; |
2957 pIterator->GetLine(line); | 2905 pIterator->GetLine(line); |
2958 | 2906 |
2959 pIterator->SetAt(wpOld); | 2907 pIterator->SetAt(wpOld); |
2960 | 2908 |
2961 return line.ptLine.y + line.fLineDescent; | 2909 return line.ptLine.y + line.fLineDescent; |
2962 } | |
2963 | |
2964 return 0.0f; | |
2965 } | 2910 } |
2966 | 2911 |
2967 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, | 2912 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, |
2968 const FX_WCHAR* text, | 2913 const FX_WCHAR* text, |
2969 int32_t charset, | 2914 int32_t charset, |
2970 const CPVT_SecProps* pSecProps, | 2915 const CPVT_SecProps* pSecProps, |
2971 const CPVT_WordProps* pWordProps) { | 2916 const CPVT_WordProps* pWordProps) { |
2972 CPVT_WordPlace wp = place; | 2917 CPVT_WordPlace wp = place; |
2973 | 2918 |
2974 if (m_pVT->IsValid()) { | 2919 if (m_pVT->IsValid()) { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3028 if (m_bOprNotify && m_pOprNotify) | 2973 if (m_bOprNotify && m_pOprNotify) |
3029 m_pOprNotify->OnAddUndo(pEditUndoItem); | 2974 m_pOprNotify->OnAddUndo(pEditUndoItem); |
3030 } | 2975 } |
3031 } | 2976 } |
3032 | 2977 |
3033 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) { | 2978 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) { |
3034 m_Undo.AddItem(pUndoItem); | 2979 m_Undo.AddItem(pUndoItem); |
3035 if (m_bOprNotify && m_pOprNotify) | 2980 if (m_bOprNotify && m_pOprNotify) |
3036 m_pOprNotify->OnAddUndo(pUndoItem); | 2981 m_pOprNotify->OnAddUndo(pUndoItem); |
3037 } | 2982 } |
OLD | NEW |