| 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 "../../include/fxedit/fxet_stub.h" | 7 #include "../../include/fxedit/fxet_stub.h" |
| 8 #include "../../include/fxedit/fxet_edit.h" | 8 #include "../../include/fxedit/fxet_edit.h" |
| 9 | 9 |
| 10 #define FX_EDIT_UNDO_MAXITEM 10000 | 10 #define FX_EDIT_UNDO_MAXITEM 10000 |
| 11 | 11 |
| 12 /* ---------------------------- CFX_Edit_Iterator ---------------------------- *
/ | 12 /* ---------------------------- CFX_Edit_Iterator ---------------------------- |
| 13 | 13 */ |
| 14 CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit * pEdit,IPDF_VariableText_Iterator
* pVTIterator) : | 14 |
| 15 m_pEdit(pEdit), | 15 CFX_Edit_Iterator::CFX_Edit_Iterator(CFX_Edit* pEdit, |
| 16 m_pVTIterator(pVTIterator) | 16 IPDF_VariableText_Iterator* pVTIterator) |
| 17 { | 17 : m_pEdit(pEdit), m_pVTIterator(pVTIterator) {} |
| 18 } | 18 |
| 19 | 19 CFX_Edit_Iterator::~CFX_Edit_Iterator() {} |
| 20 CFX_Edit_Iterator::~CFX_Edit_Iterator() | 20 |
| 21 { | 21 FX_BOOL CFX_Edit_Iterator::NextWord() { |
| 22 } | 22 return m_pVTIterator->NextWord(); |
| 23 | 23 } |
| 24 FX_BOOL CFX_Edit_Iterator::NextWord() | 24 |
| 25 { | 25 FX_BOOL CFX_Edit_Iterator::NextLine() { |
| 26 return m_pVTIterator->NextWord(); | 26 return m_pVTIterator->NextLine(); |
| 27 } | 27 } |
| 28 | 28 |
| 29 FX_BOOL CFX_Edit_Iterator::NextLine() | 29 FX_BOOL CFX_Edit_Iterator::NextSection() { |
| 30 { | 30 return m_pVTIterator->NextSection(); |
| 31 return m_pVTIterator->NextLine(); | 31 } |
| 32 } | 32 |
| 33 | 33 FX_BOOL CFX_Edit_Iterator::PrevWord() { |
| 34 FX_BOOL CFX_Edit_Iterator::NextSection() | 34 return m_pVTIterator->PrevWord(); |
| 35 { | 35 } |
| 36 return m_pVTIterator->NextSection(); | 36 |
| 37 } | 37 FX_BOOL CFX_Edit_Iterator::PrevLine() { |
| 38 | 38 return m_pVTIterator->PrevLine(); |
| 39 FX_BOOL CFX_Edit_Iterator::PrevWord() | 39 } |
| 40 { | 40 |
| 41 return m_pVTIterator->PrevWord(); | 41 FX_BOOL CFX_Edit_Iterator::PrevSection() { |
| 42 } | 42 return m_pVTIterator->PrevSection(); |
| 43 | 43 } |
| 44 FX_BOOL CFX_Edit_Iterator::PrevLine() | 44 |
| 45 { | 45 FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word& word) const { |
| 46 return m_pVTIterator->PrevLine(); | 46 ASSERT(m_pEdit); |
| 47 } | 47 |
| 48 | 48 if (m_pVTIterator->GetWord(word)) { |
| 49 FX_BOOL CFX_Edit_Iterator::PrevSection() | 49 word.ptWord = m_pEdit->VTToEdit(word.ptWord); |
| 50 { | 50 return TRUE; |
| 51 return m_pVTIterator->PrevSection(); | 51 } |
| 52 } | 52 return FALSE; |
| 53 | 53 } |
| 54 FX_BOOL CFX_Edit_Iterator::GetWord(CPVT_Word & word) const | 54 |
| 55 { | 55 FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line& line) const { |
| 56 ASSERT(m_pEdit); | 56 ASSERT(m_pEdit); |
| 57 | 57 |
| 58 if (m_pVTIterator->GetWord(word)) | 58 if (m_pVTIterator->GetLine(line)) { |
| 59 { | 59 line.ptLine = m_pEdit->VTToEdit(line.ptLine); |
| 60 word.ptWord = m_pEdit->VTToEdit(word.ptWord); | 60 return TRUE; |
| 61 return TRUE; | 61 } |
| 62 } | 62 return FALSE; |
| 63 return FALSE; | 63 } |
| 64 } | 64 |
| 65 | 65 FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section& section) const { |
| 66 FX_BOOL CFX_Edit_Iterator::GetLine(CPVT_Line & line) const | 66 ASSERT(m_pEdit); |
| 67 { | 67 |
| 68 ASSERT(m_pEdit); | 68 if (m_pVTIterator->GetSection(section)) { |
| 69 | 69 section.rcSection = m_pEdit->VTToEdit(section.rcSection); |
| 70 if (m_pVTIterator->GetLine(line)) | 70 return TRUE; |
| 71 { | 71 } |
| 72 line.ptLine = m_pEdit->VTToEdit(line.ptLine); | 72 return FALSE; |
| 73 return TRUE; | 73 } |
| 74 } | 74 |
| 75 return FALSE; | 75 void CFX_Edit_Iterator::SetAt(int32_t nWordIndex) { |
| 76 } | 76 m_pVTIterator->SetAt(nWordIndex); |
| 77 | 77 } |
| 78 FX_BOOL CFX_Edit_Iterator::GetSection(CPVT_Section & section) const | 78 |
| 79 { | 79 void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace& place) { |
| 80 ASSERT(m_pEdit); | 80 m_pVTIterator->SetAt(place); |
| 81 | 81 } |
| 82 if (m_pVTIterator->GetSection(section)) | 82 |
| 83 { | 83 const CPVT_WordPlace& CFX_Edit_Iterator::GetAt() const { |
| 84 section.rcSection = m_pEdit->VTToEdit(section.rcSection); | 84 return m_pVTIterator->GetAt(); |
| 85 return TRUE; | 85 } |
| 86 } | 86 |
| 87 return FALSE; | 87 IFX_Edit* CFX_Edit_Iterator::GetEdit() const { |
| 88 } | 88 return m_pEdit; |
| 89 | 89 } |
| 90 void CFX_Edit_Iterator::SetAt(int32_t nWordIndex) | 90 |
| 91 { | 91 /* --------------------------- CFX_Edit_Provider ------------------------------- |
| 92 m_pVTIterator->SetAt(nWordIndex); | 92 */ |
| 93 } | 93 |
| 94 | 94 CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap* pFontMap) |
| 95 void CFX_Edit_Iterator::SetAt(const CPVT_WordPlace & place) | 95 : m_pFontMap(pFontMap) { |
| 96 { | 96 ASSERT(m_pFontMap != NULL); |
| 97 m_pVTIterator->SetAt(place); | 97 } |
| 98 } | 98 |
| 99 | 99 CFX_Edit_Provider::~CFX_Edit_Provider() {} |
| 100 const CPVT_WordPlace & CFX_Edit_Iterator::GetAt() const | 100 |
| 101 { | 101 IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap() { |
| 102 return m_pVTIterator->GetAt(); | 102 return m_pFontMap; |
| 103 } | 103 } |
| 104 | 104 |
| 105 IFX_Edit* CFX_Edit_Iterator::GetEdit() const | 105 int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex, |
| 106 { | 106 FX_WORD word, |
| 107 return m_pEdit; | 107 int32_t nWordStyle) { |
| 108 } | 108 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) { |
| 109 | 109 FX_DWORD charcode = word; |
| 110 /* --------------------------- CFX_Edit_Provider -------------------------------
*/ | 110 |
| 111 | 111 if (pPDFFont->IsUnicodeCompatible()) |
| 112 CFX_Edit_Provider::CFX_Edit_Provider(IFX_Edit_FontMap * pFontMap) : m_pFontMap(p
FontMap) | 112 charcode = pPDFFont->CharCodeFromUnicode(word); |
| 113 { | 113 else |
| 114 ASSERT(m_pFontMap != NULL); | 114 charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word); |
| 115 } | 115 |
| 116 | 116 if (charcode != -1) |
| 117 CFX_Edit_Provider::~CFX_Edit_Provider() | 117 return pPDFFont->GetCharWidthF(charcode); |
| 118 { | 118 } |
| 119 } | 119 |
| 120 | 120 return 0; |
| 121 IFX_Edit_FontMap* CFX_Edit_Provider::GetFontMap() | 121 } |
| 122 { | 122 |
| 123 return m_pFontMap; | 123 int32_t CFX_Edit_Provider::GetTypeAscent(int32_t nFontIndex) { |
| 124 } | 124 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 125 | 125 return pPDFFont->GetTypeAscent(); |
| 126 int32_t CFX_Edit_Provider::GetCharWidth(int32_t nFontIndex, FX_WORD word, int32_
t nWordStyle) | 126 |
| 127 { | 127 return 0; |
| 128 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) | 128 } |
| 129 { | 129 |
| 130 FX_DWORD charcode = word; | 130 int32_t CFX_Edit_Provider::GetTypeDescent(int32_t nFontIndex) { |
| 131 | 131 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) |
| 132 if (pPDFFont->IsUnicodeCompatible()) | 132 return pPDFFont->GetTypeDescent(); |
| 133 charcode = pPDFFont->CharCodeFromUnicode(word); | 133 |
| 134 else | 134 return 0; |
| 135 charcode = m_pFontMap->CharCodeFromUnicode(nFontIndex, word); | 135 } |
| 136 | 136 |
| 137 if (charcode != -1) | 137 int32_t CFX_Edit_Provider::GetWordFontIndex(FX_WORD word, |
| 138 return pPDFFont->GetCharWidthF(charcode); | 138 int32_t charset, |
| 139 } | 139 int32_t nFontIndex) { |
| 140 | 140 return m_pFontMap->GetWordFontIndex(word, charset, nFontIndex); |
| 141 return 0; | 141 } |
| 142 } | 142 |
| 143 | 143 int32_t CFX_Edit_Provider::GetDefaultFontIndex() { |
| 144 int32_t CFX_Edit_Provider::GetTypeAscent(int32_t nFontIndex) | 144 return 0; |
| 145 { | 145 } |
| 146 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) | 146 |
| 147 return pPDFFont->GetTypeAscent(); | 147 FX_BOOL CFX_Edit_Provider::IsLatinWord(FX_WORD word) { |
| 148 | 148 return FX_EDIT_ISLATINWORD(word); |
| 149 return 0; | 149 } |
| 150 } | 150 |
| 151 | 151 /* --------------------------------- CFX_Edit_Refresh |
| 152 int32_t CFX_Edit_Provider::GetTypeDescent(int32_t nFontIndex) | 152 * --------------------------------- */ |
| 153 { | 153 |
| 154 if (CPDF_Font* pPDFFont = m_pFontMap->GetPDFFont(nFontIndex)) | 154 CFX_Edit_Refresh::CFX_Edit_Refresh() {} |
| 155 return pPDFFont->GetTypeDescent(); | 155 |
| 156 | 156 CFX_Edit_Refresh::~CFX_Edit_Refresh() {} |
| 157 return 0; | 157 |
| 158 } | 158 void CFX_Edit_Refresh::BeginRefresh() { |
| 159 | 159 m_RefreshRects.Empty(); |
| 160 int32_t CFX_Edit_Provider::GetWordFontIndex(FX_WORD word, int32_t charset, int32
_t nFontIndex) | 160 m_OldLineRects = m_NewLineRects; |
| 161 { | 161 } |
| 162 return m_pFontMap->GetWordFontIndex(word,charset,nFontIndex); | 162 |
| 163 } | 163 void CFX_Edit_Refresh::Push(const CPVT_WordRange& linerange, |
| 164 | 164 const CPDF_Rect& rect) { |
| 165 int32_t CFX_Edit_Provider::GetDefaultFontIndex() | 165 m_NewLineRects.Add(linerange, rect); |
| 166 { | 166 } |
| 167 return 0; | 167 |
| 168 } | 168 void CFX_Edit_Refresh::NoAnalyse() { |
| 169 | 169 { |
| 170 FX_BOOL CFX_Edit_Provider::IsLatinWord(FX_WORD word) | 170 for (int32_t i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++) |
| 171 { | 171 if (CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i)) |
| 172 return FX_EDIT_ISLATINWORD(word); | 172 m_RefreshRects.Add(pOldRect->m_rcLine); |
| 173 } | 173 } |
| 174 | 174 |
| 175 /* --------------------------------- CFX_Edit_Refresh --------------------------
------- */ | 175 { |
| 176 | 176 for (int32_t i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++) |
| 177 CFX_Edit_Refresh::CFX_Edit_Refresh() | 177 if (CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i)) |
| 178 { | 178 m_RefreshRects.Add(pNewRect->m_rcLine); |
| 179 } | 179 } |
| 180 | 180 } |
| 181 CFX_Edit_Refresh::~CFX_Edit_Refresh() | 181 |
| 182 { | 182 void CFX_Edit_Refresh::Analyse(int32_t nAlignment) { |
| 183 } | 183 FX_BOOL bLineTopChanged = FALSE; |
| 184 | 184 CPDF_Rect rcResult; |
| 185 void CFX_Edit_Refresh::BeginRefresh() | 185 FX_FLOAT fWidthDiff; |
| 186 { | 186 |
| 187 m_RefreshRects.Empty(); | 187 int32_t szMax = |
| 188 m_OldLineRects = m_NewLineRects; | 188 FX_EDIT_MAX(m_OldLineRects.GetSize(), m_NewLineRects.GetSize()); |
| 189 } | 189 int32_t i = 0; |
| 190 | 190 |
| 191 void CFX_Edit_Refresh::Push(const CPVT_WordRange & linerange,const CPDF_Rect & r
ect) | 191 while (i < szMax) { |
| 192 { | 192 CFX_Edit_LineRect* pOldRect = m_OldLineRects.GetAt(i); |
| 193 m_NewLineRects.Add(linerange,rect); | 193 CFX_Edit_LineRect* pNewRect = m_NewLineRects.GetAt(i); |
| 194 } | 194 |
| 195 | 195 if (pOldRect) { |
| 196 void CFX_Edit_Refresh::NoAnalyse() | 196 if (pNewRect) { |
| 197 { | 197 if (bLineTopChanged) { |
| 198 { | 198 rcResult = pOldRect->m_rcLine; |
| 199 for (int32_t i = 0, sz = m_OldLineRects.GetSize(); i < sz; i++) | 199 rcResult.Union(pNewRect->m_rcLine); |
| 200 if (CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i)) | 200 m_RefreshRects.Add(rcResult); |
| 201 m_RefreshRects.Add(pOldRect->m_rcLine); | 201 } else { |
| 202 } | 202 if (*pNewRect != *pOldRect) { |
| 203 | 203 if (!pNewRect->IsSameTop(*pOldRect) || |
| 204 { | 204 !pNewRect->IsSameHeight(*pOldRect)) { |
| 205 for (int32_t i = 0, sz = m_NewLineRects.GetSize(); i < sz; i++) | 205 bLineTopChanged = TRUE; |
| 206 if (CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i)) | 206 continue; |
| 207 m_RefreshRects.Add(pNewRect->m_rcLine); | 207 } |
| 208 } | 208 |
| 209 } | 209 if (nAlignment == 0) { |
| 210 | 210 if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLine.BeginPos) { |
| 211 void CFX_Edit_Refresh::Analyse(int32_t nAlignment) | 211 rcResult = pOldRect->m_rcLine; |
| 212 { | 212 rcResult.Union(pNewRect->m_rcLine); |
| 213 FX_BOOL bLineTopChanged = FALSE; | 213 m_RefreshRects.Add(rcResult); |
| 214 CPDF_Rect rcResult; | 214 } else { |
| 215 FX_FLOAT fWidthDiff; | 215 if (!pNewRect->IsSameLeft(*pOldRect)) { |
| 216 | 216 rcResult = pOldRect->m_rcLine; |
| 217 int32_t szMax = FX_EDIT_MAX(m_OldLineRects.GetSize(),m_NewLineRects.GetSize(
)); | 217 rcResult.Union(pNewRect->m_rcLine); |
| 218 int32_t i = 0; | 218 } else { |
| 219 | 219 fWidthDiff = |
| 220 while (i < szMax) | 220 pNewRect->m_rcLine.Width() - pOldRect->m_rcLine.Width(); |
| 221 { | 221 rcResult = pNewRect->m_rcLine; |
| 222 CFX_Edit_LineRect * pOldRect = m_OldLineRects.GetAt(i); | 222 if (fWidthDiff > 0.0f) |
| 223 CFX_Edit_LineRect * pNewRect = m_NewLineRects.GetAt(i); | 223 rcResult.left = rcResult.right - fWidthDiff; |
| 224 | 224 else { |
| 225 if (pOldRect) | 225 rcResult.left = rcResult.right; |
| 226 { | 226 rcResult.right += (-fWidthDiff); |
| 227 if (pNewRect) | 227 } |
| 228 { | |
| 229 if (bLineTopChanged) | |
| 230 { | |
| 231 rcResult = pOldRect->m_rcLine; | |
| 232 rcResult.Union(pNewRect->m_rcLine); | |
| 233 m_RefreshRects.Add(rcResult); | |
| 234 } | 228 } |
| 235 else | 229 m_RefreshRects.Add(rcResult); |
| 236 { | 230 } |
| 237 if (*pNewRect != *pOldRect) | 231 } else { |
| 238 { | 232 rcResult = pOldRect->m_rcLine; |
| 239 if (!pNewRect->IsSameTop(*pOldRect) || !pNewRect->IsSame
Height(*pOldRect)) | 233 rcResult.Union(pNewRect->m_rcLine); |
| 240 { | 234 m_RefreshRects.Add(rcResult); |
| 241 bLineTopChanged = TRUE; | |
| 242 continue; | |
| 243 } | |
| 244 | |
| 245 if (nAlignment == 0) | |
| 246 { | |
| 247 if (pNewRect->m_wrLine.BeginPos != pOldRect->m_wrLin
e.BeginPos) | |
| 248 { | |
| 249 rcResult = pOldRect->m_rcLine; | |
| 250 rcResult.Union(pNewRect->m_rcLine); | |
| 251 m_RefreshRects.Add(rcResult); | |
| 252 } | |
| 253 else | |
| 254 { | |
| 255 if (!pNewRect->IsSameLeft(*pOldRect)) | |
| 256 { | |
| 257 rcResult = pOldRect->m_rcLine; | |
| 258 rcResult.Union(pNewRect->m_rcLine); | |
| 259 } | |
| 260 else | |
| 261 { | |
| 262 fWidthDiff = pNewRect->m_rcLine.Width() - pO
ldRect->m_rcLine.Width(); | |
| 263 rcResult = pNewRect->m_rcLine; | |
| 264 if (fWidthDiff > 0.0f) | |
| 265 rcResult.left = rcResult.right - fWidthD
iff; | |
| 266 else | |
| 267 { | |
| 268 rcResult.left = rcResult.right; | |
| 269 rcResult.right += (-fWidthDiff); | |
| 270 } | |
| 271 } | |
| 272 m_RefreshRects.Add(rcResult); | |
| 273 } | |
| 274 } | |
| 275 else | |
| 276 { | |
| 277 rcResult = pOldRect->m_rcLine; | |
| 278 rcResult.Union(pNewRect->m_rcLine); | |
| 279 m_RefreshRects.Add(rcResult); | |
| 280 } | |
| 281 } | |
| 282 else | |
| 283 { | |
| 284 //don't need to do anything | |
| 285 } | |
| 286 } | |
| 287 } | 235 } |
| 288 else | 236 } else { |
| 289 { | 237 // don't need to do anything |
| 290 m_RefreshRects.Add(pOldRect->m_rcLine); | 238 } |
| 291 } | |
| 292 } | 239 } |
| 293 else | 240 } else { |
| 294 { | 241 m_RefreshRects.Add(pOldRect->m_rcLine); |
| 295 if (pNewRect) | 242 } |
| 296 { | 243 } else { |
| 297 m_RefreshRects.Add(pNewRect->m_rcLine); | 244 if (pNewRect) { |
| 298 } | 245 m_RefreshRects.Add(pNewRect->m_rcLine); |
| 299 else | 246 } else { |
| 300 { | 247 // error |
| 301 //error | 248 } |
| 302 } | 249 } |
| 250 i++; |
| 251 } |
| 252 } |
| 253 |
| 254 void CFX_Edit_Refresh::AddRefresh(const CPDF_Rect& rect) { |
| 255 m_RefreshRects.Add(rect); |
| 256 } |
| 257 |
| 258 const CFX_Edit_RectArray* CFX_Edit_Refresh::GetRefreshRects() const { |
| 259 return &m_RefreshRects; |
| 260 } |
| 261 |
| 262 void CFX_Edit_Refresh::EndRefresh() { |
| 263 m_RefreshRects.Empty(); |
| 264 } |
| 265 |
| 266 /* ------------------------------------- CFX_Edit_Undo |
| 267 * ------------------------------------- */ |
| 268 |
| 269 CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize) |
| 270 : m_nCurUndoPos(0), |
| 271 m_nBufSize(nBufsize), |
| 272 m_bModified(FALSE), |
| 273 m_bVirgin(TRUE), |
| 274 m_bWorking(FALSE) {} |
| 275 |
| 276 CFX_Edit_Undo::~CFX_Edit_Undo() { |
| 277 Reset(); |
| 278 } |
| 279 |
| 280 FX_BOOL CFX_Edit_Undo::CanUndo() const { |
| 281 return m_nCurUndoPos > 0; |
| 282 } |
| 283 |
| 284 void CFX_Edit_Undo::Undo() { |
| 285 m_bWorking = TRUE; |
| 286 |
| 287 if (m_nCurUndoPos > 0) { |
| 288 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos - 1); |
| 289 ASSERT(pItem != NULL); |
| 290 |
| 291 pItem->Undo(); |
| 292 |
| 293 m_nCurUndoPos--; |
| 294 m_bModified = (m_nCurUndoPos != 0); |
| 295 } |
| 296 |
| 297 m_bWorking = FALSE; |
| 298 } |
| 299 |
| 300 FX_BOOL CFX_Edit_Undo::CanRedo() const { |
| 301 return m_nCurUndoPos < m_UndoItemStack.GetSize(); |
| 302 } |
| 303 |
| 304 void CFX_Edit_Undo::Redo() { |
| 305 m_bWorking = TRUE; |
| 306 |
| 307 int32_t nStackSize = m_UndoItemStack.GetSize(); |
| 308 |
| 309 if (m_nCurUndoPos < nStackSize) { |
| 310 IFX_Edit_UndoItem* pItem = m_UndoItemStack.GetAt(m_nCurUndoPos); |
| 311 ASSERT(pItem != NULL); |
| 312 |
| 313 pItem->Redo(); |
| 314 |
| 315 m_nCurUndoPos++; |
| 316 m_bModified = (m_nCurUndoPos != 0); |
| 317 } |
| 318 |
| 319 m_bWorking = FALSE; |
| 320 } |
| 321 |
| 322 FX_BOOL CFX_Edit_Undo::IsWorking() const { |
| 323 return m_bWorking; |
| 324 } |
| 325 |
| 326 void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) { |
| 327 ASSERT(!m_bWorking); |
| 328 ASSERT(pItem != NULL); |
| 329 ASSERT(m_nBufSize > 1); |
| 330 |
| 331 if (m_nCurUndoPos < m_UndoItemStack.GetSize()) |
| 332 RemoveTails(); |
| 333 |
| 334 if (m_UndoItemStack.GetSize() >= m_nBufSize) { |
| 335 RemoveHeads(); |
| 336 m_bVirgin = FALSE; |
| 337 } |
| 338 |
| 339 m_UndoItemStack.Add(pItem); |
| 340 m_nCurUndoPos = m_UndoItemStack.GetSize(); |
| 341 |
| 342 m_bModified = (m_nCurUndoPos != 0); |
| 343 } |
| 344 |
| 345 FX_BOOL CFX_Edit_Undo::IsModified() const { |
| 346 return m_bVirgin ? m_bModified : TRUE; |
| 347 } |
| 348 |
| 349 IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(int32_t nIndex) { |
| 350 if (nIndex >= 0 && nIndex < m_UndoItemStack.GetSize()) |
| 351 return m_UndoItemStack.GetAt(nIndex); |
| 352 |
| 353 return NULL; |
| 354 } |
| 355 |
| 356 void CFX_Edit_Undo::RemoveHeads() { |
| 357 ASSERT(m_UndoItemStack.GetSize() > 1); |
| 358 |
| 359 delete m_UndoItemStack.GetAt(0); |
| 360 m_UndoItemStack.RemoveAt(0); |
| 361 } |
| 362 |
| 363 void CFX_Edit_Undo::RemoveTails() { |
| 364 for (int32_t i = m_UndoItemStack.GetSize() - 1; i >= m_nCurUndoPos; i--) { |
| 365 delete m_UndoItemStack.GetAt(i); |
| 366 m_UndoItemStack.RemoveAt(i); |
| 367 } |
| 368 } |
| 369 |
| 370 void CFX_Edit_Undo::Reset() { |
| 371 for (int32_t i = 0, sz = m_UndoItemStack.GetSize(); i < sz; i++) { |
| 372 delete m_UndoItemStack.GetAt(i); |
| 373 } |
| 374 m_nCurUndoPos = 0; |
| 375 m_UndoItemStack.RemoveAll(); |
| 376 } |
| 377 |
| 378 /* -------------------------------- CFX_Edit_GroupUndoItem |
| 379 * -------------------------------- */ |
| 380 |
| 381 CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle) |
| 382 : m_sTitle(sTitle) {} |
| 383 |
| 384 CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() { |
| 385 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { |
| 386 delete m_Items[i]; |
| 387 } |
| 388 |
| 389 m_Items.RemoveAll(); |
| 390 } |
| 391 |
| 392 void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) { |
| 393 ASSERT(pUndoItem != NULL); |
| 394 |
| 395 pUndoItem->SetFirst(FALSE); |
| 396 pUndoItem->SetLast(FALSE); |
| 397 |
| 398 m_Items.Add(pUndoItem); |
| 399 |
| 400 if (m_sTitle.IsEmpty()) |
| 401 m_sTitle = pUndoItem->GetUndoTitle(); |
| 402 } |
| 403 |
| 404 void CFX_Edit_GroupUndoItem::UpdateItems() { |
| 405 if (m_Items.GetSize() > 0) { |
| 406 CFX_Edit_UndoItem* pFirstItem = m_Items[0]; |
| 407 ASSERT(pFirstItem != NULL); |
| 408 pFirstItem->SetFirst(TRUE); |
| 409 |
| 410 CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1]; |
| 411 ASSERT(pLastItem != NULL); |
| 412 pLastItem->SetLast(TRUE); |
| 413 } |
| 414 } |
| 415 |
| 416 void CFX_Edit_GroupUndoItem::Undo() { |
| 417 for (int i = m_Items.GetSize() - 1; i >= 0; i--) { |
| 418 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; |
| 419 ASSERT(pUndoItem != NULL); |
| 420 |
| 421 pUndoItem->Undo(); |
| 422 } |
| 423 } |
| 424 |
| 425 void CFX_Edit_GroupUndoItem::Redo() { |
| 426 for (int i = 0, sz = m_Items.GetSize(); i < sz; i++) { |
| 427 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; |
| 428 ASSERT(pUndoItem != NULL); |
| 429 |
| 430 pUndoItem->Redo(); |
| 431 } |
| 432 } |
| 433 |
| 434 CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() { |
| 435 return m_sTitle; |
| 436 } |
| 437 |
| 438 /* ------------------------------------- CFX_Edit_UndoItem derived classes |
| 439 * ------------------------------------- */ |
| 440 |
| 441 CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit* pEdit, |
| 442 const CPVT_WordPlace& wpOldPlace, |
| 443 const CPVT_WordPlace& wpNewPlace, |
| 444 FX_WORD word, |
| 445 int32_t charset, |
| 446 const CPVT_WordProps* pWordProps) |
| 447 : m_pEdit(pEdit), |
| 448 m_wpOld(wpOldPlace), |
| 449 m_wpNew(wpNewPlace), |
| 450 m_Word(word), |
| 451 m_nCharset(charset), |
| 452 m_WordProps() { |
| 453 if (pWordProps) |
| 454 m_WordProps = *pWordProps; |
| 455 } |
| 456 |
| 457 CFXEU_InsertWord::~CFXEU_InsertWord() {} |
| 458 |
| 459 void CFXEU_InsertWord::Redo() { |
| 460 if (m_pEdit) { |
| 461 m_pEdit->SelectNone(); |
| 462 m_pEdit->SetCaret(m_wpOld); |
| 463 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
| 464 } |
| 465 } |
| 466 |
| 467 void CFXEU_InsertWord::Undo() { |
| 468 if (m_pEdit) { |
| 469 m_pEdit->SelectNone(); |
| 470 m_pEdit->SetCaret(m_wpNew); |
| 471 m_pEdit->Backspace(FALSE, TRUE); |
| 472 } |
| 473 } |
| 474 |
| 475 /* -------------------------------------------------------------------------- */ |
| 476 |
| 477 CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit* pEdit, |
| 478 const CPVT_WordPlace& wpOldPlace, |
| 479 const CPVT_WordPlace& wpNewPlace, |
| 480 const CPVT_SecProps* pSecProps, |
| 481 const CPVT_WordProps* pWordProps) |
| 482 : m_pEdit(pEdit), |
| 483 m_wpOld(wpOldPlace), |
| 484 m_wpNew(wpNewPlace), |
| 485 m_SecProps(), |
| 486 m_WordProps() { |
| 487 if (pSecProps) |
| 488 m_SecProps = *pSecProps; |
| 489 if (pWordProps) |
| 490 m_WordProps = *pWordProps; |
| 491 } |
| 492 |
| 493 CFXEU_InsertReturn::~CFXEU_InsertReturn() {} |
| 494 |
| 495 void CFXEU_InsertReturn::Redo() { |
| 496 if (m_pEdit) { |
| 497 m_pEdit->SelectNone(); |
| 498 m_pEdit->SetCaret(m_wpOld); |
| 499 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 500 } |
| 501 } |
| 502 |
| 503 void CFXEU_InsertReturn::Undo() { |
| 504 if (m_pEdit) { |
| 505 m_pEdit->SelectNone(); |
| 506 m_pEdit->SetCaret(m_wpNew); |
| 507 m_pEdit->Backspace(FALSE, TRUE); |
| 508 } |
| 509 } |
| 510 |
| 511 /* -------------------------------------------------------------------------- */ |
| 512 // CFXEU_Backspace |
| 513 |
| 514 CFXEU_Backspace::CFXEU_Backspace(CFX_Edit* pEdit, |
| 515 const CPVT_WordPlace& wpOldPlace, |
| 516 const CPVT_WordPlace& wpNewPlace, |
| 517 FX_WORD word, |
| 518 int32_t charset, |
| 519 const CPVT_SecProps& SecProps, |
| 520 const CPVT_WordProps& WordProps) |
| 521 : m_pEdit(pEdit), |
| 522 m_wpOld(wpOldPlace), |
| 523 m_wpNew(wpNewPlace), |
| 524 m_Word(word), |
| 525 m_nCharset(charset), |
| 526 m_SecProps(SecProps), |
| 527 m_WordProps(WordProps) {} |
| 528 |
| 529 CFXEU_Backspace::~CFXEU_Backspace() {} |
| 530 |
| 531 void CFXEU_Backspace::Redo() { |
| 532 if (m_pEdit) { |
| 533 m_pEdit->SelectNone(); |
| 534 m_pEdit->SetCaret(m_wpOld); |
| 535 m_pEdit->Backspace(FALSE, TRUE); |
| 536 } |
| 537 } |
| 538 |
| 539 void CFXEU_Backspace::Undo() { |
| 540 if (m_pEdit) { |
| 541 m_pEdit->SelectNone(); |
| 542 m_pEdit->SetCaret(m_wpNew); |
| 543 if (m_wpNew.SecCmp(m_wpOld) != 0) { |
| 544 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 545 } else { |
| 546 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
| 547 } |
| 548 } |
| 549 } |
| 550 |
| 551 /* -------------------------------------------------------------------------- */ |
| 552 // CFXEU_Delete |
| 553 |
| 554 CFXEU_Delete::CFXEU_Delete(CFX_Edit* pEdit, |
| 555 const CPVT_WordPlace& wpOldPlace, |
| 556 const CPVT_WordPlace& wpNewPlace, |
| 557 FX_WORD word, |
| 558 int32_t charset, |
| 559 const CPVT_SecProps& SecProps, |
| 560 const CPVT_WordProps& WordProps, |
| 561 FX_BOOL bSecEnd) |
| 562 : m_pEdit(pEdit), |
| 563 m_wpOld(wpOldPlace), |
| 564 m_wpNew(wpNewPlace), |
| 565 m_Word(word), |
| 566 m_nCharset(charset), |
| 567 m_SecProps(SecProps), |
| 568 m_WordProps(WordProps), |
| 569 m_bSecEnd(bSecEnd) {} |
| 570 |
| 571 CFXEU_Delete::~CFXEU_Delete() {} |
| 572 |
| 573 void CFXEU_Delete::Redo() { |
| 574 if (m_pEdit) { |
| 575 m_pEdit->SelectNone(); |
| 576 m_pEdit->SetCaret(m_wpOld); |
| 577 m_pEdit->Delete(FALSE, TRUE); |
| 578 } |
| 579 } |
| 580 |
| 581 void CFXEU_Delete::Undo() { |
| 582 if (m_pEdit) { |
| 583 m_pEdit->SelectNone(); |
| 584 m_pEdit->SetCaret(m_wpNew); |
| 585 if (m_bSecEnd) { |
| 586 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, TRUE); |
| 587 } else { |
| 588 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, TRUE); |
| 589 } |
| 590 } |
| 591 } |
| 592 |
| 593 /* -------------------------------------------------------------------------- */ |
| 594 // CFXEU_Clear |
| 595 |
| 596 CFXEU_Clear::CFXEU_Clear(CFX_Edit* pEdit, |
| 597 const CPVT_WordRange& wrSel, |
| 598 const CFX_WideString& swText) |
| 599 : m_pEdit(pEdit), m_wrSel(wrSel), m_swText(swText) {} |
| 600 |
| 601 CFXEU_Clear::~CFXEU_Clear() {} |
| 602 |
| 603 void CFXEU_Clear::Redo() { |
| 604 if (m_pEdit) { |
| 605 m_pEdit->SelectNone(); |
| 606 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 607 m_pEdit->Clear(FALSE, TRUE); |
| 608 } |
| 609 } |
| 610 |
| 611 void CFXEU_Clear::Undo() { |
| 612 if (m_pEdit) { |
| 613 m_pEdit->SelectNone(); |
| 614 m_pEdit->SetCaret(m_wrSel.BeginPos); |
| 615 m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, NULL, NULL, FALSE, |
| 616 TRUE); |
| 617 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 618 } |
| 619 } |
| 620 |
| 621 /* -------------------------------------------------------------------------- */ |
| 622 // CFXEU_ClearRich |
| 623 |
| 624 CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit* pEdit, |
| 625 const CPVT_WordPlace& wpOldPlace, |
| 626 const CPVT_WordPlace& wpNewPlace, |
| 627 const CPVT_WordRange& wrSel, |
| 628 FX_WORD word, |
| 629 int32_t charset, |
| 630 const CPVT_SecProps& SecProps, |
| 631 const CPVT_WordProps& WordProps) |
| 632 : m_pEdit(pEdit), |
| 633 m_wpOld(wpOldPlace), |
| 634 m_wpNew(wpNewPlace), |
| 635 m_wrSel(wrSel), |
| 636 m_Word(word), |
| 637 m_nCharset(charset), |
| 638 m_SecProps(SecProps), |
| 639 m_WordProps(WordProps) {} |
| 640 |
| 641 CFXEU_ClearRich::~CFXEU_ClearRich() {} |
| 642 |
| 643 void CFXEU_ClearRich::Redo() { |
| 644 if (m_pEdit && IsLast()) { |
| 645 m_pEdit->SelectNone(); |
| 646 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 647 m_pEdit->Clear(FALSE, TRUE); |
| 648 } |
| 649 } |
| 650 |
| 651 void CFXEU_ClearRich::Undo() { |
| 652 if (m_pEdit) { |
| 653 m_pEdit->SelectNone(); |
| 654 m_pEdit->SetCaret(m_wpOld); |
| 655 if (m_wpNew.SecCmp(m_wpOld) != 0) { |
| 656 m_pEdit->InsertReturn(&m_SecProps, &m_WordProps, FALSE, FALSE); |
| 657 } else { |
| 658 m_pEdit->InsertWord(m_Word, m_nCharset, &m_WordProps, FALSE, FALSE); |
| 659 } |
| 660 |
| 661 if (IsFirst()) { |
| 662 m_pEdit->PaintInsertText(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 663 m_pEdit->SetSel(m_wrSel.BeginPos, m_wrSel.EndPos); |
| 664 } |
| 665 } |
| 666 } |
| 667 /* -------------------------------------------------------------------------- */ |
| 668 // CFXEU_InsertText |
| 669 |
| 670 CFXEU_InsertText::CFXEU_InsertText(CFX_Edit* pEdit, |
| 671 const CPVT_WordPlace& wpOldPlace, |
| 672 const CPVT_WordPlace& wpNewPlace, |
| 673 const CFX_WideString& swText, |
| 674 int32_t charset, |
| 675 const CPVT_SecProps* pSecProps, |
| 676 const CPVT_WordProps* pWordProps) |
| 677 : m_pEdit(pEdit), |
| 678 m_wpOld(wpOldPlace), |
| 679 m_wpNew(wpNewPlace), |
| 680 m_swText(swText), |
| 681 m_nCharset(charset), |
| 682 m_SecProps(), |
| 683 m_WordProps() { |
| 684 if (pSecProps) |
| 685 m_SecProps = *pSecProps; |
| 686 if (pWordProps) |
| 687 m_WordProps = *pWordProps; |
| 688 } |
| 689 |
| 690 CFXEU_InsertText::~CFXEU_InsertText() {} |
| 691 |
| 692 void CFXEU_InsertText::Redo() { |
| 693 if (m_pEdit && IsLast()) { |
| 694 m_pEdit->SelectNone(); |
| 695 m_pEdit->SetCaret(m_wpOld); |
| 696 m_pEdit->InsertText(m_swText.c_str(), m_nCharset, &m_SecProps, &m_WordProps, |
| 697 FALSE, TRUE); |
| 698 } |
| 699 } |
| 700 |
| 701 void CFXEU_InsertText::Undo() { |
| 702 if (m_pEdit) { |
| 703 m_pEdit->SelectNone(); |
| 704 m_pEdit->SetSel(m_wpOld, m_wpNew); |
| 705 m_pEdit->Clear(FALSE, TRUE); |
| 706 } |
| 707 } |
| 708 |
| 709 /* -------------------------------------------------------------------------- */ |
| 710 |
| 711 CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit* pEdit, |
| 712 const CPVT_WordPlace& place, |
| 713 EDIT_PROPS_E ep, |
| 714 const CPVT_SecProps& oldsecprops, |
| 715 const CPVT_WordProps& oldwordprops, |
| 716 const CPVT_SecProps& newsecprops, |
| 717 const CPVT_WordProps& newwordprops, |
| 718 const CPVT_WordRange& range) |
| 719 : m_pEdit(pEdit), |
| 720 m_wpPlace(place), |
| 721 m_wrPlace(range), |
| 722 m_eProps(ep), |
| 723 m_OldSecProps(oldsecprops), |
| 724 m_NewSecProps(newsecprops), |
| 725 m_OldWordProps(oldwordprops), |
| 726 m_NewWordProps(newwordprops) {} |
| 727 |
| 728 CFXEU_SetSecProps::~CFXEU_SetSecProps() {} |
| 729 |
| 730 void CFXEU_SetSecProps::Redo() { |
| 731 if (m_pEdit) { |
| 732 m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_NewSecProps, &m_NewWordProps, |
| 733 m_wrPlace, FALSE); |
| 734 if (IsLast()) { |
| 735 m_pEdit->SelectNone(); |
| 736 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 737 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
| 738 } |
| 739 } |
| 740 } |
| 741 |
| 742 void CFXEU_SetSecProps::Undo() { |
| 743 if (m_pEdit) { |
| 744 m_pEdit->SetSecProps(m_eProps, m_wpPlace, &m_OldSecProps, &m_OldWordProps, |
| 745 m_wrPlace, FALSE); |
| 746 if (IsFirst()) { |
| 747 m_pEdit->SelectNone(); |
| 748 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 749 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
| 750 } |
| 751 } |
| 752 } |
| 753 |
| 754 /* -------------------------------------------------------------------------- */ |
| 755 |
| 756 CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit* pEdit, |
| 757 const CPVT_WordPlace& place, |
| 758 EDIT_PROPS_E ep, |
| 759 const CPVT_WordProps& oldprops, |
| 760 const CPVT_WordProps& newprops, |
| 761 const CPVT_WordRange& range) |
| 762 : m_pEdit(pEdit), |
| 763 m_wpPlace(place), |
| 764 m_wrPlace(range), |
| 765 m_eProps(ep), |
| 766 m_OldWordProps(oldprops), |
| 767 m_NewWordProps(newprops) {} |
| 768 |
| 769 CFXEU_SetWordProps::~CFXEU_SetWordProps() {} |
| 770 |
| 771 void CFXEU_SetWordProps::Redo() { |
| 772 if (m_pEdit) { |
| 773 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_NewWordProps, m_wrPlace, |
| 774 FALSE); |
| 775 if (IsLast()) { |
| 776 m_pEdit->SelectNone(); |
| 777 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 778 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
| 779 } |
| 780 } |
| 781 } |
| 782 |
| 783 void CFXEU_SetWordProps::Undo() { |
| 784 if (m_pEdit) { |
| 785 m_pEdit->SetWordProps(m_eProps, m_wpPlace, &m_OldWordProps, m_wrPlace, |
| 786 FALSE); |
| 787 if (IsFirst()) { |
| 788 m_pEdit->SelectNone(); |
| 789 m_pEdit->PaintSetProps(m_eProps, m_wrPlace); |
| 790 m_pEdit->SetSel(m_wrPlace.BeginPos, m_wrPlace.EndPos); |
| 791 } |
| 792 } |
| 793 } |
| 794 |
| 795 /* ------------------------------------- CFX_Edit |
| 796 * ------------------------------------- */ |
| 797 |
| 798 CFX_Edit::CFX_Edit(IPDF_VariableText* pVT) |
| 799 : m_pVT(pVT), |
| 800 m_pNotify(NULL), |
| 801 m_pOprNotify(NULL), |
| 802 m_pVTProvide(NULL), |
| 803 m_wpCaret(-1, -1, -1), |
| 804 m_wpOldCaret(-1, -1, -1), |
| 805 m_SelState(), |
| 806 m_ptScrollPos(0, 0), |
| 807 m_ptRefreshScrollPos(0, 0), |
| 808 m_bEnableScroll(FALSE), |
| 809 m_pIterator(NULL), |
| 810 m_ptCaret(0.0f, 0.0f), |
| 811 m_Undo(FX_EDIT_UNDO_MAXITEM), |
| 812 m_nAlignment(0), |
| 813 m_bNotifyFlag(FALSE), |
| 814 m_bEnableOverflow(FALSE), |
| 815 m_bEnableRefresh(TRUE), |
| 816 m_rcOldContent(0.0f, 0.0f, 0.0f, 0.0f), |
| 817 m_bEnableUndo(TRUE), |
| 818 m_bNotify(TRUE), |
| 819 m_bOprNotify(FALSE), |
| 820 m_pGroupUndoItem(NULL) { |
| 821 ASSERT(pVT != NULL); |
| 822 } |
| 823 |
| 824 CFX_Edit::~CFX_Edit() { |
| 825 delete m_pVTProvide; |
| 826 m_pVTProvide = NULL; |
| 827 delete m_pIterator; |
| 828 m_pIterator = NULL; |
| 829 ASSERT(m_pGroupUndoItem == NULL); |
| 830 } |
| 831 |
| 832 // public methods |
| 833 |
| 834 void CFX_Edit::Initialize() { |
| 835 m_pVT->Initialize(); |
| 836 SetCaret(m_pVT->GetBeginWordPlace()); |
| 837 SetCaretOrigin(); |
| 838 } |
| 839 |
| 840 void CFX_Edit::SetFontMap(IFX_Edit_FontMap* pFontMap) { |
| 841 delete m_pVTProvide; |
| 842 m_pVT->SetProvider(m_pVTProvide = new CFX_Edit_Provider(pFontMap)); |
| 843 } |
| 844 |
| 845 void CFX_Edit::SetVTProvider(IPDF_VariableText_Provider* pProvider) { |
| 846 m_pVT->SetProvider(pProvider); |
| 847 } |
| 848 |
| 849 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) { |
| 850 m_pNotify = pNotify; |
| 851 } |
| 852 |
| 853 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) { |
| 854 m_pOprNotify = pOprNotify; |
| 855 } |
| 856 |
| 857 IFX_Edit_Iterator* CFX_Edit::GetIterator() { |
| 858 if (!m_pIterator) |
| 859 m_pIterator = new CFX_Edit_Iterator(this, m_pVT->GetIterator()); |
| 860 |
| 861 return m_pIterator; |
| 862 } |
| 863 |
| 864 IPDF_VariableText* CFX_Edit::GetVariableText() { |
| 865 return m_pVT; |
| 866 } |
| 867 |
| 868 IFX_Edit_FontMap* CFX_Edit::GetFontMap() { |
| 869 if (m_pVTProvide) |
| 870 return m_pVTProvide->GetFontMap(); |
| 871 |
| 872 return NULL; |
| 873 } |
| 874 |
| 875 void CFX_Edit::SetPlateRect(const CPDF_Rect& rect, FX_BOOL bPaint /* = TRUE*/) { |
| 876 m_pVT->SetPlateRect(rect); |
| 877 m_ptScrollPos = CPDF_Point(rect.left, rect.top); |
| 878 if (bPaint) |
| 879 Paint(); |
| 880 } |
| 881 |
| 882 void CFX_Edit::SetAlignmentH(int32_t nFormat /* =0 */, |
| 883 FX_BOOL bPaint /* = TRUE*/) { |
| 884 m_pVT->SetAlignment(nFormat); |
| 885 if (bPaint) |
| 886 Paint(); |
| 887 } |
| 888 |
| 889 void CFX_Edit::SetAlignmentV(int32_t nFormat /* =0 */, |
| 890 FX_BOOL bPaint /* = TRUE*/) { |
| 891 m_nAlignment = nFormat; |
| 892 if (bPaint) |
| 893 Paint(); |
| 894 } |
| 895 |
| 896 void CFX_Edit::SetPasswordChar(FX_WORD wSubWord /* ='*' */, |
| 897 FX_BOOL bPaint /* = TRUE*/) { |
| 898 m_pVT->SetPasswordChar(wSubWord); |
| 899 if (bPaint) |
| 900 Paint(); |
| 901 } |
| 902 |
| 903 void CFX_Edit::SetLimitChar(int32_t nLimitChar /* =0 */, |
| 904 FX_BOOL bPaint /* = TRUE*/) { |
| 905 m_pVT->SetLimitChar(nLimitChar); |
| 906 if (bPaint) |
| 907 Paint(); |
| 908 } |
| 909 |
| 910 void CFX_Edit::SetCharArray(int32_t nCharArray /* =0 */, |
| 911 FX_BOOL bPaint /* = TRUE*/) { |
| 912 m_pVT->SetCharArray(nCharArray); |
| 913 if (bPaint) |
| 914 Paint(); |
| 915 } |
| 916 |
| 917 void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace /* =0.0f */, |
| 918 FX_BOOL bPaint /* = TRUE*/) { |
| 919 m_pVT->SetCharSpace(fCharSpace); |
| 920 if (bPaint) |
| 921 Paint(); |
| 922 } |
| 923 |
| 924 void CFX_Edit::SetHorzScale(int32_t nHorzScale /* =100 */, |
| 925 FX_BOOL bPaint /* = TRUE*/) { |
| 926 m_pVT->SetHorzScale(nHorzScale); |
| 927 if (bPaint) |
| 928 Paint(); |
| 929 } |
| 930 |
| 931 void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine /* =TRUE */, |
| 932 FX_BOOL bPaint /* = TRUE*/) { |
| 933 m_pVT->SetMultiLine(bMultiLine); |
| 934 if (bPaint) |
| 935 Paint(); |
| 936 } |
| 937 |
| 938 void CFX_Edit::SetAutoReturn(FX_BOOL bAuto /* =TRUE */, |
| 939 FX_BOOL bPaint /* = TRUE*/) { |
| 940 m_pVT->SetAutoReturn(bAuto); |
| 941 if (bPaint) |
| 942 Paint(); |
| 943 } |
| 944 |
| 945 void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading /* =TRUE */, |
| 946 FX_BOOL bPaint /* = TRUE*/) { |
| 947 m_pVT->SetLineLeading(fLineLeading); |
| 948 if (bPaint) |
| 949 Paint(); |
| 950 } |
| 951 |
| 952 void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto /* =TRUE */, |
| 953 FX_BOOL bPaint /* = TRUE*/) { |
| 954 m_pVT->SetAutoFontSize(bAuto); |
| 955 if (bPaint) |
| 956 Paint(); |
| 957 } |
| 958 |
| 959 void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint /* = TRUE*/) { |
| 960 m_pVT->SetFontSize(fFontSize); |
| 961 if (bPaint) |
| 962 Paint(); |
| 963 } |
| 964 |
| 965 void CFX_Edit::SetAutoScroll(FX_BOOL bAuto /* =TRUE */, |
| 966 FX_BOOL bPaint /* = TRUE*/) { |
| 967 m_bEnableScroll = bAuto; |
| 968 if (bPaint) |
| 969 Paint(); |
| 970 } |
| 971 |
| 972 void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed /*= FALSE*/, |
| 973 FX_BOOL bPaint /* = TRUE*/) { |
| 974 m_bEnableOverflow = bAllowed; |
| 975 if (bPaint) |
| 976 Paint(); |
| 977 } |
| 978 |
| 979 void CFX_Edit::SetSel(int32_t nStartChar, int32_t nEndChar) { |
| 980 if (m_pVT->IsValid()) { |
| 981 if (nStartChar == 0 && nEndChar < 0) { |
| 982 SelectAll(); |
| 983 } else if (nStartChar < 0) { |
| 984 SelectNone(); |
| 985 } else { |
| 986 if (nStartChar < nEndChar) { |
| 987 SetSel(m_pVT->WordIndexToWordPlace(nStartChar), |
| 988 m_pVT->WordIndexToWordPlace(nEndChar)); |
| 989 } else { |
| 990 SetSel(m_pVT->WordIndexToWordPlace(nEndChar), |
| 991 m_pVT->WordIndexToWordPlace(nStartChar)); |
| 992 } |
| 993 } |
| 994 } |
| 995 } |
| 996 |
| 997 void CFX_Edit::SetSel(const CPVT_WordPlace& begin, const CPVT_WordPlace& end) { |
| 998 if (m_pVT->IsValid()) { |
| 999 SelectNone(); |
| 1000 |
| 1001 m_SelState.Set(begin, end); |
| 1002 |
| 1003 SetCaret(m_SelState.EndPos); |
| 1004 |
| 1005 if (m_SelState.IsExist()) { |
| 1006 ScrollToCaret(); |
| 1007 CPVT_WordRange wr(m_SelState.BeginPos, m_SelState.EndPos); |
| 1008 Refresh(RP_OPTIONAL, &wr); |
| 1009 SetCaretInfo(); |
| 1010 } else { |
| 1011 ScrollToCaret(); |
| 1012 SetCaretInfo(); |
| 1013 } |
| 1014 } |
| 1015 } |
| 1016 |
| 1017 void CFX_Edit::GetSel(int32_t& nStartChar, int32_t& nEndChar) const { |
| 1018 nStartChar = -1; |
| 1019 nEndChar = -1; |
| 1020 |
| 1021 if (m_pVT->IsValid()) { |
| 1022 if (m_SelState.IsExist()) { |
| 1023 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) { |
| 1024 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
| 1025 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 1026 } else { |
| 1027 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); |
| 1028 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); |
| 1029 } |
| 1030 } else { |
| 1031 nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 1032 nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 1033 } |
| 1034 } |
| 1035 } |
| 1036 |
| 1037 int32_t CFX_Edit::GetCaret() const { |
| 1038 if (m_pVT->IsValid()) |
| 1039 return m_pVT->WordPlaceToWordIndex(m_wpCaret); |
| 1040 |
| 1041 return -1; |
| 1042 } |
| 1043 |
| 1044 CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const { |
| 1045 return m_wpCaret; |
| 1046 } |
| 1047 |
| 1048 CFX_WideString CFX_Edit::GetText() const { |
| 1049 CFX_WideString swRet; |
| 1050 |
| 1051 if (m_pVT->IsValid()) { |
| 1052 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 1053 FX_BOOL bRich = m_pVT->IsRichText(); |
| 1054 |
| 1055 pIterator->SetAt(0); |
| 1056 |
| 1057 CPVT_Word wordinfo; |
| 1058 CPVT_WordPlace oldplace = pIterator->GetAt(); |
| 1059 while (pIterator->NextWord()) { |
| 1060 CPVT_WordPlace place = pIterator->GetAt(); |
| 1061 |
| 1062 if (pIterator->GetWord(wordinfo)) { |
| 1063 if (bRich) { |
| 1064 swRet += wordinfo.Word; |
| 1065 } else { |
| 1066 swRet += wordinfo.Word; |
| 1067 } |
| 303 } | 1068 } |
| 304 i++; | 1069 |
| 305 } | 1070 if (oldplace.SecCmp(place) != 0) { |
| 306 } | 1071 swRet += 0x0D; |
| 307 | 1072 swRet += 0x0A; |
| 308 void CFX_Edit_Refresh::AddRefresh(const CPDF_Rect & rect) | |
| 309 { | |
| 310 m_RefreshRects.Add(rect); | |
| 311 } | |
| 312 | |
| 313 const CFX_Edit_RectArray * CFX_Edit_Refresh::GetRefreshRects() const | |
| 314 { | |
| 315 return &m_RefreshRects; | |
| 316 } | |
| 317 | |
| 318 void CFX_Edit_Refresh::EndRefresh() | |
| 319 { | |
| 320 m_RefreshRects.Empty(); | |
| 321 } | |
| 322 | |
| 323 /* ------------------------------------- CFX_Edit_Undo -------------------------
------------ */ | |
| 324 | |
| 325 CFX_Edit_Undo::CFX_Edit_Undo(int32_t nBufsize) : m_nCurUndoPos(0), | |
| 326 m_nBufSize(nBufsize), | |
| 327 m_bModified(FALSE), | |
| 328 m_bVirgin(TRUE), | |
| 329 m_bWorking(FALSE) | |
| 330 { | |
| 331 } | |
| 332 | |
| 333 CFX_Edit_Undo::~CFX_Edit_Undo() | |
| 334 { | |
| 335 Reset(); | |
| 336 } | |
| 337 | |
| 338 FX_BOOL CFX_Edit_Undo::CanUndo() const | |
| 339 { | |
| 340 return m_nCurUndoPos > 0; | |
| 341 } | |
| 342 | |
| 343 void CFX_Edit_Undo::Undo() | |
| 344 { | |
| 345 m_bWorking = TRUE; | |
| 346 | |
| 347 if (m_nCurUndoPos > 0) | |
| 348 { | |
| 349 IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos-1); | |
| 350 ASSERT(pItem != NULL); | |
| 351 | |
| 352 pItem->Undo(); | |
| 353 | |
| 354 m_nCurUndoPos--; | |
| 355 m_bModified = (m_nCurUndoPos != 0); | |
| 356 } | |
| 357 | |
| 358 m_bWorking = FALSE; | |
| 359 } | |
| 360 | |
| 361 FX_BOOL CFX_Edit_Undo::CanRedo() const | |
| 362 { | |
| 363 return m_nCurUndoPos < m_UndoItemStack.GetSize(); | |
| 364 } | |
| 365 | |
| 366 void CFX_Edit_Undo::Redo() | |
| 367 { | |
| 368 m_bWorking = TRUE; | |
| 369 | |
| 370 int32_t nStackSize = m_UndoItemStack.GetSize(); | |
| 371 | |
| 372 if (m_nCurUndoPos < nStackSize) | |
| 373 { | |
| 374 IFX_Edit_UndoItem * pItem = m_UndoItemStack.GetAt(m_nCurUndoPos); | |
| 375 ASSERT(pItem != NULL); | |
| 376 | |
| 377 pItem->Redo(); | |
| 378 | |
| 379 m_nCurUndoPos++; | |
| 380 m_bModified = (m_nCurUndoPos != 0); | |
| 381 } | |
| 382 | |
| 383 m_bWorking = FALSE; | |
| 384 } | |
| 385 | |
| 386 FX_BOOL CFX_Edit_Undo::IsWorking() const | |
| 387 { | |
| 388 return m_bWorking; | |
| 389 } | |
| 390 | |
| 391 void CFX_Edit_Undo::AddItem(IFX_Edit_UndoItem* pItem) | |
| 392 { | |
| 393 ASSERT(!m_bWorking); | |
| 394 ASSERT(pItem != NULL); | |
| 395 ASSERT(m_nBufSize > 1); | |
| 396 | |
| 397 if (m_nCurUndoPos < m_UndoItemStack.GetSize()) | |
| 398 RemoveTails(); | |
| 399 | |
| 400 if (m_UndoItemStack.GetSize() >= m_nBufSize) | |
| 401 { | |
| 402 RemoveHeads(); | |
| 403 m_bVirgin = FALSE; | |
| 404 } | |
| 405 | |
| 406 m_UndoItemStack.Add(pItem); | |
| 407 m_nCurUndoPos = m_UndoItemStack.GetSize(); | |
| 408 | |
| 409 m_bModified = (m_nCurUndoPos != 0); | |
| 410 } | |
| 411 | |
| 412 FX_BOOL CFX_Edit_Undo::IsModified() const | |
| 413 { | |
| 414 return m_bVirgin ? m_bModified : TRUE; | |
| 415 } | |
| 416 | |
| 417 IFX_Edit_UndoItem* CFX_Edit_Undo::GetItem(int32_t nIndex) | |
| 418 { | |
| 419 if (nIndex>=0 && nIndex < m_UndoItemStack.GetSize()) | |
| 420 return m_UndoItemStack.GetAt(nIndex); | |
| 421 | |
| 422 return NULL; | |
| 423 } | |
| 424 | |
| 425 void CFX_Edit_Undo::RemoveHeads() | |
| 426 { | |
| 427 ASSERT(m_UndoItemStack.GetSize() > 1); | |
| 428 | |
| 429 delete m_UndoItemStack.GetAt(0); | |
| 430 m_UndoItemStack.RemoveAt(0); | |
| 431 } | |
| 432 | |
| 433 void CFX_Edit_Undo::RemoveTails() | |
| 434 { | |
| 435 for (int32_t i = m_UndoItemStack.GetSize()-1; i >= m_nCurUndoPos; i--) | |
| 436 { | |
| 437 delete m_UndoItemStack.GetAt(i); | |
| 438 m_UndoItemStack.RemoveAt(i); | |
| 439 } | |
| 440 } | |
| 441 | |
| 442 void CFX_Edit_Undo::Reset() | |
| 443 { | |
| 444 for (int32_t i=0, sz=m_UndoItemStack.GetSize(); i < sz; i++) | |
| 445 { | |
| 446 delete m_UndoItemStack.GetAt(i); | |
| 447 } | |
| 448 m_nCurUndoPos = 0; | |
| 449 m_UndoItemStack.RemoveAll(); | |
| 450 } | |
| 451 | |
| 452 /* -------------------------------- CFX_Edit_GroupUndoItem ---------------------
----------- */ | |
| 453 | |
| 454 CFX_Edit_GroupUndoItem::CFX_Edit_GroupUndoItem(const CFX_WideString& sTitle) : m
_sTitle(sTitle) | |
| 455 { | |
| 456 } | |
| 457 | |
| 458 CFX_Edit_GroupUndoItem::~CFX_Edit_GroupUndoItem() | |
| 459 { | |
| 460 for (int i=0,sz=m_Items.GetSize(); i<sz; i++) | |
| 461 { | |
| 462 delete m_Items[i]; | |
| 463 } | |
| 464 | |
| 465 m_Items.RemoveAll(); | |
| 466 } | |
| 467 | |
| 468 void CFX_Edit_GroupUndoItem::AddUndoItem(CFX_Edit_UndoItem* pUndoItem) | |
| 469 { | |
| 470 ASSERT(pUndoItem != NULL); | |
| 471 | |
| 472 pUndoItem->SetFirst(FALSE); | |
| 473 pUndoItem->SetLast(FALSE); | |
| 474 | |
| 475 m_Items.Add(pUndoItem); | |
| 476 | |
| 477 if (m_sTitle.IsEmpty()) | |
| 478 m_sTitle = pUndoItem->GetUndoTitle(); | |
| 479 } | |
| 480 | |
| 481 void CFX_Edit_GroupUndoItem::UpdateItems() | |
| 482 { | |
| 483 if (m_Items.GetSize() > 0) | |
| 484 { | |
| 485 CFX_Edit_UndoItem* pFirstItem = m_Items[0]; | |
| 486 ASSERT(pFirstItem != NULL); | |
| 487 pFirstItem->SetFirst(TRUE); | |
| 488 | |
| 489 CFX_Edit_UndoItem* pLastItem = m_Items[m_Items.GetSize() - 1]; | |
| 490 ASSERT(pLastItem != NULL); | |
| 491 pLastItem->SetLast(TRUE); | |
| 492 } | |
| 493 } | |
| 494 | |
| 495 void CFX_Edit_GroupUndoItem::Undo() | |
| 496 { | |
| 497 for (int i=m_Items.GetSize()-1; i>=0; i--) | |
| 498 { | |
| 499 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; | |
| 500 ASSERT(pUndoItem != NULL); | |
| 501 | |
| 502 pUndoItem->Undo(); | |
| 503 } | |
| 504 } | |
| 505 | |
| 506 void CFX_Edit_GroupUndoItem::Redo() | |
| 507 { | |
| 508 for (int i=0,sz=m_Items.GetSize(); i<sz; i++) | |
| 509 { | |
| 510 CFX_Edit_UndoItem* pUndoItem = m_Items[i]; | |
| 511 ASSERT(pUndoItem != NULL); | |
| 512 | |
| 513 pUndoItem->Redo(); | |
| 514 } | |
| 515 } | |
| 516 | |
| 517 CFX_WideString CFX_Edit_GroupUndoItem::GetUndoTitle() | |
| 518 { | |
| 519 return m_sTitle; | |
| 520 } | |
| 521 | |
| 522 /* ------------------------------------- CFX_Edit_UndoItem derived classes -----
-------------------------------- */ | |
| 523 | |
| 524 CFXEU_InsertWord::CFXEU_InsertWord(CFX_Edit * pEdit, const CPVT_WordPlace & wpOl
dPlace, const CPVT_WordPlace & wpNewPlace, | |
| 525 FX_WORD word, int32_t charset, const CPVT_WordP
rops * pWordProps) | |
| 526 : m_pEdit(pEdit), m_wpOld(wpOldPlace), m_wpNew(wpNewPlace), m_Word(word), m_
nCharset(charset), m_WordProps() | |
| 527 { | |
| 528 if (pWordProps) | |
| 529 m_WordProps = *pWordProps; | |
| 530 } | |
| 531 | |
| 532 CFXEU_InsertWord::~CFXEU_InsertWord() | |
| 533 { | |
| 534 } | |
| 535 | |
| 536 void CFXEU_InsertWord::Redo() | |
| 537 { | |
| 538 if (m_pEdit) | |
| 539 { | |
| 540 m_pEdit->SelectNone(); | |
| 541 m_pEdit->SetCaret(m_wpOld); | |
| 542 m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE); | |
| 543 } | |
| 544 } | |
| 545 | |
| 546 void CFXEU_InsertWord::Undo() | |
| 547 { | |
| 548 if (m_pEdit) | |
| 549 { | |
| 550 m_pEdit->SelectNone(); | |
| 551 m_pEdit->SetCaret(m_wpNew); | |
| 552 m_pEdit->Backspace(FALSE,TRUE); | |
| 553 } | |
| 554 } | |
| 555 | |
| 556 /* -------------------------------------------------------------------------- */ | |
| 557 | |
| 558 CFXEU_InsertReturn::CFXEU_InsertReturn(CFX_Edit * pEdit, const CPVT_WordPlace &
wpOldPlace, const CPVT_WordPlace & wpNewPlace, | |
| 559 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWordProps)
: | |
| 560 m_pEdit(pEdit), | |
| 561 m_wpOld(wpOldPlace), | |
| 562 m_wpNew(wpNewPlace), | |
| 563 m_SecProps(), | |
| 564 m_WordProps() | |
| 565 { | |
| 566 if (pSecProps) | |
| 567 m_SecProps = *pSecProps; | |
| 568 if (pWordProps) | |
| 569 m_WordProps = *pWordProps; | |
| 570 } | |
| 571 | |
| 572 CFXEU_InsertReturn::~CFXEU_InsertReturn() | |
| 573 { | |
| 574 } | |
| 575 | |
| 576 void CFXEU_InsertReturn::Redo() | |
| 577 { | |
| 578 if (m_pEdit) | |
| 579 { | |
| 580 m_pEdit->SelectNone(); | |
| 581 m_pEdit->SetCaret(m_wpOld); | |
| 582 m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE); | |
| 583 } | |
| 584 } | |
| 585 | |
| 586 void CFXEU_InsertReturn::Undo() | |
| 587 { | |
| 588 if (m_pEdit) | |
| 589 { | |
| 590 m_pEdit->SelectNone(); | |
| 591 m_pEdit->SetCaret(m_wpNew); | |
| 592 m_pEdit->Backspace(FALSE,TRUE); | |
| 593 } | |
| 594 } | |
| 595 | |
| 596 /* -------------------------------------------------------------------------- */ | |
| 597 //CFXEU_Backspace | |
| 598 | |
| 599 CFXEU_Backspace::CFXEU_Backspace(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldP
lace, const CPVT_WordPlace & wpNewPlace, | |
| 600 FX_WORD word, int32_t charset, | |
| 601 const CPVT_SecProps & SecProps, const CPVT_WordPr
ops & WordProps) : | |
| 602 m_pEdit(pEdit), | |
| 603 m_wpOld(wpOldPlace), | |
| 604 m_wpNew(wpNewPlace), | |
| 605 m_Word(word), | |
| 606 m_nCharset(charset), | |
| 607 m_SecProps(SecProps), | |
| 608 m_WordProps(WordProps) | |
| 609 { | |
| 610 } | |
| 611 | |
| 612 CFXEU_Backspace::~CFXEU_Backspace() | |
| 613 { | |
| 614 } | |
| 615 | |
| 616 void CFXEU_Backspace::Redo() | |
| 617 { | |
| 618 if (m_pEdit) | |
| 619 { | |
| 620 m_pEdit->SelectNone(); | |
| 621 m_pEdit->SetCaret(m_wpOld); | |
| 622 m_pEdit->Backspace(FALSE,TRUE); | |
| 623 } | |
| 624 } | |
| 625 | |
| 626 void CFXEU_Backspace::Undo() | |
| 627 { | |
| 628 if (m_pEdit) | |
| 629 { | |
| 630 m_pEdit->SelectNone(); | |
| 631 m_pEdit->SetCaret(m_wpNew); | |
| 632 if (m_wpNew.SecCmp(m_wpOld) != 0) | |
| 633 { | |
| 634 m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE); | |
| 635 } | 1073 } |
| 636 else | 1074 |
| 637 { | 1075 oldplace = place; |
| 638 m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE); | 1076 } |
| 1077 } |
| 1078 } |
| 1079 |
| 1080 return swRet; |
| 1081 } |
| 1082 |
| 1083 CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange& range) const { |
| 1084 CFX_WideString swRet; |
| 1085 |
| 1086 if (m_pVT->IsValid()) { |
| 1087 FX_BOOL bRich = m_pVT->IsRichText(); |
| 1088 |
| 1089 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 1090 CPVT_WordRange wrTemp = range; |
| 1091 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 1092 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 1093 pIterator->SetAt(wrTemp.BeginPos); |
| 1094 |
| 1095 CPVT_Word wordinfo; |
| 1096 CPVT_WordPlace oldplace = wrTemp.BeginPos; |
| 1097 while (pIterator->NextWord()) { |
| 1098 CPVT_WordPlace place = pIterator->GetAt(); |
| 1099 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 1100 break; |
| 1101 |
| 1102 if (pIterator->GetWord(wordinfo)) { |
| 1103 if (bRich) { |
| 1104 swRet += wordinfo.Word; |
| 1105 } else { |
| 1106 swRet += wordinfo.Word; |
| 1107 } |
| 639 } | 1108 } |
| 640 } | 1109 |
| 641 } | 1110 if (oldplace.SecCmp(place) != 0) { |
| 642 | 1111 swRet += 0x0D; |
| 643 /* -------------------------------------------------------------------------- */ | 1112 swRet += 0x0A; |
| 644 //CFXEU_Delete | |
| 645 | |
| 646 CFXEU_Delete::CFXEU_Delete(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldPlace,
const CPVT_WordPlace & wpNewPlace, | |
| 647 FX_WORD word, int32_t charset, | |
| 648 const CPVT_SecProps & SecProps, const CPVT_WordPr
ops & WordProps, FX_BOOL bSecEnd) : | |
| 649 m_pEdit(pEdit), | |
| 650 m_wpOld(wpOldPlace), | |
| 651 m_wpNew(wpNewPlace), | |
| 652 m_Word(word), | |
| 653 m_nCharset(charset), | |
| 654 m_SecProps(SecProps), | |
| 655 m_WordProps(WordProps), | |
| 656 m_bSecEnd(bSecEnd) | |
| 657 { | |
| 658 } | |
| 659 | |
| 660 CFXEU_Delete::~CFXEU_Delete() | |
| 661 { | |
| 662 } | |
| 663 | |
| 664 void CFXEU_Delete::Redo() | |
| 665 { | |
| 666 if (m_pEdit) | |
| 667 { | |
| 668 m_pEdit->SelectNone(); | |
| 669 m_pEdit->SetCaret(m_wpOld); | |
| 670 m_pEdit->Delete(FALSE,TRUE); | |
| 671 } | |
| 672 } | |
| 673 | |
| 674 void CFXEU_Delete::Undo() | |
| 675 { | |
| 676 if (m_pEdit) | |
| 677 { | |
| 678 m_pEdit->SelectNone(); | |
| 679 m_pEdit->SetCaret(m_wpNew); | |
| 680 if (m_bSecEnd) | |
| 681 { | |
| 682 m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,TRUE); | |
| 683 } | 1113 } |
| 684 else | 1114 |
| 685 { | 1115 oldplace = place; |
| 686 m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,TRUE); | 1116 } |
| 687 } | 1117 } |
| 688 } | 1118 } |
| 689 } | 1119 |
| 690 | 1120 return swRet; |
| 691 /* -------------------------------------------------------------------------- */ | 1121 } |
| 692 //CFXEU_Clear | 1122 |
| 693 | 1123 CFX_WideString CFX_Edit::GetSelText() const { |
| 694 CFXEU_Clear::CFXEU_Clear(CFX_Edit * pEdit, const CPVT_WordRange & wrSel, const
CFX_WideString & swText) : | 1124 return GetRangeText(m_SelState.ConvertToWordRange()); |
| 695 m_pEdit(pEdit), | 1125 } |
| 696 m_wrSel(wrSel), | 1126 |
| 697 m_swText(swText) | 1127 int32_t CFX_Edit::GetTotalWords() const { |
| 698 { | 1128 return m_pVT->GetTotalWords(); |
| 699 } | 1129 } |
| 700 | 1130 |
| 701 CFXEU_Clear::~CFXEU_Clear() | 1131 int32_t CFX_Edit::GetTotalLines() const { |
| 702 { | 1132 int32_t nLines = 0; |
| 703 } | 1133 |
| 704 | 1134 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 705 void CFXEU_Clear::Redo() | 1135 pIterator->SetAt(0); |
| 706 { | 1136 while (pIterator->NextLine()) |
| 707 if (m_pEdit) | 1137 nLines++; |
| 708 { | 1138 } |
| 709 m_pEdit->SelectNone(); | 1139 |
| 710 m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos); | 1140 return nLines + 1; |
| 711 m_pEdit->Clear(FALSE,TRUE); | 1141 } |
| 712 } | 1142 |
| 713 } | 1143 CPVT_WordRange CFX_Edit::GetSelectWordRange() const { |
| 714 | 1144 return m_SelState.ConvertToWordRange(); |
| 715 void CFXEU_Clear::Undo() | 1145 } |
| 716 { | 1146 |
| 717 if (m_pEdit) | 1147 CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
| 718 { | 1148 const CPVT_WordRange& wr2) { |
| 719 m_pEdit->SelectNone(); | 1149 CPVT_WordRange wrRet; |
| 720 m_pEdit->SetCaret(m_wrSel.BeginPos); | 1150 |
| 721 m_pEdit->InsertText(m_swText.c_str(), DEFAULT_CHARSET, NULL, NULL, FALSE
, TRUE); | 1151 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) { |
| 722 m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos); | 1152 wrRet.BeginPos = wr1.BeginPos; |
| 723 } | 1153 } else { |
| 724 } | 1154 wrRet.BeginPos = wr2.BeginPos; |
| 725 | 1155 } |
| 726 /* -------------------------------------------------------------------------- */ | 1156 |
| 727 //CFXEU_ClearRich | 1157 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
| 728 | 1158 wrRet.EndPos = wr2.EndPos; |
| 729 CFXEU_ClearRich::CFXEU_ClearRich(CFX_Edit * pEdit, const CPVT_WordPlace & wpOldP
lace, const CPVT_WordPlace & wpNewPlace, | 1159 } else { |
| 730 const CPVT_WordRange & wrSel, FX_WORD word, int32
_t charset, | 1160 wrRet.EndPos = wr1.EndPos; |
| 731 const CPVT_SecProps & SecProps, const CPVT_WordPr
ops & WordProps) : | 1161 } |
| 732 m_pEdit(pEdit), | 1162 |
| 733 m_wpOld(wpOldPlace), | 1163 return wrRet; |
| 734 m_wpNew(wpNewPlace), | 1164 } |
| 735 m_wrSel(wrSel), | 1165 |
| 736 m_Word(word), | 1166 FX_BOOL CFX_Edit::IsRichText() const { |
| 737 m_nCharset(charset), | 1167 return m_pVT->IsRichText(); |
| 738 m_SecProps(SecProps), | 1168 } |
| 739 m_WordProps(WordProps) | 1169 |
| 740 { | 1170 void CFX_Edit::SetRichText(FX_BOOL bRichText /* =TRUE */, |
| 741 } | 1171 FX_BOOL bPaint /* = TRUE*/) { |
| 742 | 1172 m_pVT->SetRichText(bRichText); |
| 743 CFXEU_ClearRich::~CFXEU_ClearRich() | 1173 if (bPaint) |
| 744 { | 1174 Paint(); |
| 745 } | 1175 } |
| 746 | 1176 |
| 747 void CFXEU_ClearRich::Redo() | 1177 FX_BOOL CFX_Edit::SetRichFontIndex(int32_t nFontIndex) { |
| 748 { | 1178 CPVT_WordProps WordProps; |
| 749 if (m_pEdit && IsLast()) | 1179 WordProps.nFontIndex = nFontIndex; |
| 750 { | 1180 return SetRichTextProps(EP_FONTINDEX, NULL, &WordProps); |
| 751 m_pEdit->SelectNone(); | 1181 } |
| 752 m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos); | 1182 |
| 753 m_pEdit->Clear(FALSE,TRUE); | 1183 FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize) { |
| 754 } | 1184 CPVT_WordProps WordProps; |
| 755 } | 1185 WordProps.fFontSize = fFontSize; |
| 756 | 1186 return SetRichTextProps(EP_FONTSIZE, NULL, &WordProps); |
| 757 void CFXEU_ClearRich::Undo() | 1187 } |
| 758 { | 1188 |
| 759 if (m_pEdit) | 1189 FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor) { |
| 760 { | 1190 CPVT_WordProps WordProps; |
| 761 m_pEdit->SelectNone(); | 1191 WordProps.dwWordColor = dwColor; |
| 762 m_pEdit->SetCaret(m_wpOld); | 1192 return SetRichTextProps(EP_WORDCOLOR, NULL, &WordProps); |
| 763 if (m_wpNew.SecCmp(m_wpOld) != 0) | 1193 } |
| 764 { | 1194 |
| 765 m_pEdit->InsertReturn(&m_SecProps,&m_WordProps,FALSE,FALSE); | 1195 FX_BOOL CFX_Edit::SetRichTextScript(int32_t nScriptType) { |
| 766 } | 1196 CPVT_WordProps WordProps; |
| 767 else | 1197 WordProps.nScriptType = nScriptType; |
| 768 { | 1198 return SetRichTextProps(EP_SCRIPTTYPE, NULL, &WordProps); |
| 769 m_pEdit->InsertWord(m_Word,m_nCharset,&m_WordProps,FALSE,FALSE); | 1199 } |
| 770 } | 1200 |
| 771 | 1201 FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold) { |
| 772 if (IsFirst()) | 1202 CPVT_WordProps WordProps; |
| 773 { | 1203 if (bBold) |
| 774 m_pEdit->PaintInsertText(m_wrSel.BeginPos,m_wrSel.EndPos); | 1204 WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 775 m_pEdit->SetSel(m_wrSel.BeginPos,m_wrSel.EndPos); | 1205 return SetRichTextProps(EP_BOLD, NULL, &WordProps); |
| 776 } | 1206 } |
| 777 } | 1207 |
| 778 } | 1208 FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic) { |
| 779 /* -------------------------------------------------------------------------- */ | 1209 CPVT_WordProps WordProps; |
| 780 //CFXEU_InsertText | 1210 if (bItalic) |
| 781 | 1211 WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 782 CFXEU_InsertText::CFXEU_InsertText(CFX_Edit * pEdit, const CPVT_WordPlace & wpOl
dPlace, const CPVT_WordPlace & wpNewPlace, | 1212 return SetRichTextProps(EP_ITALIC, NULL, &WordProps); |
| 783 const CFX_WideString & swText, int32_t charset, | 1213 } |
| 784 const CPVT_SecProps * pSecProps, const CPVT_WordP
rops * pWordProps) : | 1214 |
| 785 m_pEdit(pEdit), | 1215 FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline) { |
| 786 m_wpOld(wpOldPlace), | 1216 CPVT_WordProps WordProps; |
| 787 m_wpNew(wpNewPlace), | 1217 if (bUnderline) |
| 788 m_swText(swText), | 1218 WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 789 m_nCharset(charset), | 1219 return SetRichTextProps(EP_UNDERLINE, NULL, &WordProps); |
| 790 m_SecProps(), | 1220 } |
| 791 m_WordProps() | 1221 |
| 792 { | 1222 FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout) { |
| 793 if (pSecProps) | 1223 CPVT_WordProps WordProps; |
| 794 m_SecProps = *pSecProps; | 1224 if (bCrossout) |
| 795 if (pWordProps) | 1225 WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 796 m_WordProps = *pWordProps; | 1226 return SetRichTextProps(EP_CROSSOUT, NULL, &WordProps); |
| 797 } | 1227 } |
| 798 | 1228 |
| 799 CFXEU_InsertText::~CFXEU_InsertText() | 1229 FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace) { |
| 800 { | 1230 CPVT_WordProps WordProps; |
| 801 } | 1231 WordProps.fCharSpace = fCharSpace; |
| 802 | 1232 return SetRichTextProps(EP_CHARSPACE, NULL, &WordProps); |
| 803 void CFXEU_InsertText::Redo() | 1233 } |
| 804 { | 1234 |
| 805 if (m_pEdit && IsLast()) | 1235 FX_BOOL CFX_Edit::SetRichTextHorzScale(int32_t nHorzScale /*= 100*/) { |
| 806 { | 1236 CPVT_WordProps WordProps; |
| 807 m_pEdit->SelectNone(); | 1237 WordProps.nHorzScale = nHorzScale; |
| 808 m_pEdit->SetCaret(m_wpOld); | 1238 return SetRichTextProps(EP_HORZSCALE, NULL, &WordProps); |
| 809 m_pEdit->InsertText(m_swText.c_str(), m_nCharset, &m_SecProps, &m_WordPr
ops, FALSE, TRUE); | 1239 } |
| 810 } | 1240 |
| 811 } | 1241 FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading) { |
| 812 | 1242 CPVT_SecProps SecProps; |
| 813 void CFXEU_InsertText::Undo() | 1243 SecProps.fLineLeading = fLineLeading; |
| 814 { | 1244 return SetRichTextProps(EP_LINELEADING, &SecProps, NULL); |
| 815 if (m_pEdit) | 1245 } |
| 816 { | 1246 |
| 817 m_pEdit->SelectNone(); | 1247 FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent) { |
| 818 m_pEdit->SetSel(m_wpOld,m_wpNew); | 1248 CPVT_SecProps SecProps; |
| 819 m_pEdit->Clear(FALSE,TRUE); | 1249 SecProps.fLineIndent = fLineIndent; |
| 820 } | 1250 return SetRichTextProps(EP_LINEINDENT, &SecProps, NULL); |
| 821 } | 1251 } |
| 822 | 1252 |
| 823 /* -------------------------------------------------------------------------- */ | 1253 FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) { |
| 824 | 1254 CPVT_SecProps SecProps; |
| 825 CFXEU_SetSecProps::CFXEU_SetSecProps(CFX_Edit * pEdit, const CPVT_WordPlace & pl
ace, EDIT_PROPS_E ep, | 1255 SecProps.nAlignment = nAlignment; |
| 826 const CPVT_SecProps & oldsecprops, const CPVT_WordProps & oldwordprops, | 1256 return SetRichTextProps(EP_ALIGNMENT, &SecProps, NULL); |
| 827 const CPVT_SecProps & newsecprops, const CPVT_WordProps & newwordprops,
const CPVT_WordRange & range) | 1257 } |
| 828 : m_pEdit(pEdit), | 1258 |
| 829 m_wpPlace(place), | 1259 FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, |
| 830 m_wrPlace(range), | 1260 const CPVT_SecProps* pSecProps, |
| 831 m_eProps(ep), | 1261 const CPVT_WordProps* pWordProps) { |
| 832 m_OldSecProps(oldsecprops), | 1262 FX_BOOL bSet = FALSE; |
| 833 m_NewSecProps(newsecprops), | 1263 FX_BOOL bSet1, bSet2; |
| 834 m_OldWordProps(oldwordprops), | 1264 if (m_pVT->IsValid() && m_pVT->IsRichText()) { |
| 835 m_NewWordProps(newwordprops) | 1265 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 836 { | 1266 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); |
| 837 } | 1267 |
| 838 | 1268 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 839 CFXEU_SetSecProps::~CFXEU_SetSecProps() | 1269 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 840 { | 1270 pIterator->SetAt(wrTemp.BeginPos); |
| 841 } | 1271 |
| 842 | 1272 BeginGroupUndo(L""); |
| 843 void CFXEU_SetSecProps::Redo() | 1273 ; |
| 844 { | 1274 |
| 845 if (m_pEdit) | 1275 bSet = SetSecProps(eProps, wrTemp.BeginPos, pSecProps, pWordProps, wrTemp, |
| 846 { | 1276 TRUE); |
| 847 m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_NewSecProps,&m_NewWordProps,m
_wrPlace,FALSE); | 1277 |
| 848 if (IsLast()) | 1278 while (pIterator->NextWord()) { |
| 849 { | 1279 CPVT_WordPlace place = pIterator->GetAt(); |
| 850 m_pEdit->SelectNone(); | 1280 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 851 m_pEdit->PaintSetProps(m_eProps,m_wrPlace); | 1281 break; |
| 852 m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos); | 1282 bSet1 = SetSecProps(eProps, place, pSecProps, pWordProps, wrTemp, TRUE); |
| 853 } | 1283 bSet2 = SetWordProps(eProps, place, pWordProps, wrTemp, TRUE); |
| 854 } | 1284 |
| 855 } | 1285 if (!bSet) |
| 856 | 1286 bSet = (bSet1 || bSet2); |
| 857 void CFXEU_SetSecProps::Undo() | 1287 } |
| 858 { | 1288 |
| 859 if (m_pEdit) | 1289 EndGroupUndo(); |
| 860 { | 1290 |
| 861 m_pEdit->SetSecProps(m_eProps,m_wpPlace,&m_OldSecProps,&m_OldWordProps,m
_wrPlace,FALSE); | 1291 if (bSet) { |
| 862 if (IsFirst()) | 1292 PaintSetProps(eProps, wrTemp); |
| 863 { | 1293 } |
| 864 m_pEdit->SelectNone(); | 1294 } |
| 865 m_pEdit->PaintSetProps(m_eProps,m_wrPlace); | 1295 } |
| 866 m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos); | 1296 |
| 867 } | 1297 return bSet; |
| 868 } | 1298 } |
| 869 } | 1299 |
| 870 | 1300 void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange& wr) { |
| 871 /* -------------------------------------------------------------------------- */ | 1301 switch (eProps) { |
| 872 | |
| 873 CFXEU_SetWordProps::CFXEU_SetWordProps(CFX_Edit * pEdit, const CPVT_WordPlace &
place, EDIT_PROPS_E ep, | |
| 874 const CPVT_WordProps & oldprops, const CPVT_WordProps & newprops, const
CPVT_WordRange & range) | |
| 875 : m_pEdit(pEdit), | |
| 876 m_wpPlace(place), | |
| 877 m_wrPlace(range), | |
| 878 m_eProps(ep), | |
| 879 m_OldWordProps(oldprops), | |
| 880 m_NewWordProps(newprops) | |
| 881 { | |
| 882 } | |
| 883 | |
| 884 CFXEU_SetWordProps::~CFXEU_SetWordProps() | |
| 885 { | |
| 886 } | |
| 887 | |
| 888 void CFXEU_SetWordProps::Redo() | |
| 889 { | |
| 890 if (m_pEdit) | |
| 891 { | |
| 892 m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_NewWordProps,m_wrPlace,FALSE
); | |
| 893 if (IsLast()) | |
| 894 { | |
| 895 m_pEdit->SelectNone(); | |
| 896 m_pEdit->PaintSetProps(m_eProps,m_wrPlace); | |
| 897 m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos); | |
| 898 } | |
| 899 } | |
| 900 } | |
| 901 | |
| 902 void CFXEU_SetWordProps::Undo() | |
| 903 { | |
| 904 if (m_pEdit) | |
| 905 { | |
| 906 m_pEdit->SetWordProps(m_eProps,m_wpPlace,&m_OldWordProps,m_wrPlace,FALSE
); | |
| 907 if (IsFirst()) | |
| 908 { | |
| 909 m_pEdit->SelectNone(); | |
| 910 m_pEdit->PaintSetProps(m_eProps,m_wrPlace); | |
| 911 m_pEdit->SetSel(m_wrPlace.BeginPos,m_wrPlace.EndPos); | |
| 912 } | |
| 913 } | |
| 914 } | |
| 915 | |
| 916 /* ------------------------------------- CFX_Edit ------------------------------
------- */ | |
| 917 | |
| 918 CFX_Edit::CFX_Edit(IPDF_VariableText * pVT) : | |
| 919 m_pVT(pVT), | |
| 920 m_pNotify(NULL), | |
| 921 m_pOprNotify(NULL), | |
| 922 m_pVTProvide(NULL), | |
| 923 m_wpCaret(-1,-1,-1), | |
| 924 m_wpOldCaret(-1,-1,-1), | |
| 925 m_SelState(), | |
| 926 m_ptScrollPos(0,0), | |
| 927 m_ptRefreshScrollPos(0,0), | |
| 928 m_bEnableScroll(FALSE), | |
| 929 m_pIterator(NULL), | |
| 930 m_ptCaret(0.0f,0.0f), | |
| 931 m_Undo(FX_EDIT_UNDO_MAXITEM), | |
| 932 m_nAlignment(0), | |
| 933 m_bNotifyFlag(FALSE), | |
| 934 m_bEnableOverflow(FALSE), | |
| 935 m_bEnableRefresh(TRUE), | |
| 936 m_rcOldContent(0.0f,0.0f,0.0f,0.0f), | |
| 937 m_bEnableUndo(TRUE), | |
| 938 m_bNotify(TRUE), | |
| 939 m_bOprNotify(FALSE), | |
| 940 m_pGroupUndoItem(NULL) | |
| 941 { | |
| 942 ASSERT(pVT != NULL); | |
| 943 } | |
| 944 | |
| 945 CFX_Edit::~CFX_Edit() | |
| 946 { | |
| 947 delete m_pVTProvide; | |
| 948 m_pVTProvide = NULL; | |
| 949 delete m_pIterator; | |
| 950 m_pIterator = NULL; | |
| 951 ASSERT(m_pGroupUndoItem == NULL); | |
| 952 } | |
| 953 | |
| 954 // public methods | |
| 955 | |
| 956 void CFX_Edit::Initialize() | |
| 957 { | |
| 958 m_pVT->Initialize(); | |
| 959 SetCaret(m_pVT->GetBeginWordPlace()); | |
| 960 SetCaretOrigin(); | |
| 961 } | |
| 962 | |
| 963 void CFX_Edit::SetFontMap(IFX_Edit_FontMap * pFontMap) | |
| 964 { | |
| 965 delete m_pVTProvide; | |
| 966 m_pVT->SetProvider(m_pVTProvide = new CFX_Edit_Provider(pFontMap)); | |
| 967 } | |
| 968 | |
| 969 void CFX_Edit::SetVTProvider(IPDF_VariableText_Provider* pProvider) | |
| 970 { | |
| 971 m_pVT->SetProvider(pProvider); | |
| 972 } | |
| 973 | |
| 974 void CFX_Edit::SetNotify(IFX_Edit_Notify* pNotify) | |
| 975 { | |
| 976 m_pNotify = pNotify; | |
| 977 } | |
| 978 | |
| 979 void CFX_Edit::SetOprNotify(IFX_Edit_OprNotify* pOprNotify) | |
| 980 { | |
| 981 m_pOprNotify = pOprNotify; | |
| 982 } | |
| 983 | |
| 984 IFX_Edit_Iterator * CFX_Edit::GetIterator() | |
| 985 { | |
| 986 if (!m_pIterator) | |
| 987 m_pIterator = new CFX_Edit_Iterator(this,m_pVT->GetIterator()); | |
| 988 | |
| 989 return m_pIterator; | |
| 990 } | |
| 991 | |
| 992 IPDF_VariableText * CFX_Edit::GetVariableText() | |
| 993 { | |
| 994 return m_pVT; | |
| 995 } | |
| 996 | |
| 997 IFX_Edit_FontMap* CFX_Edit::GetFontMap() | |
| 998 { | |
| 999 if (m_pVTProvide) | |
| 1000 return m_pVTProvide->GetFontMap(); | |
| 1001 | |
| 1002 return NULL; | |
| 1003 } | |
| 1004 | |
| 1005 void CFX_Edit::SetPlateRect(const CPDF_Rect & rect, FX_BOOL bPaint/* = TRUE*/) | |
| 1006 { | |
| 1007 m_pVT->SetPlateRect(rect); | |
| 1008 m_ptScrollPos = CPDF_Point(rect.left,rect.top); | |
| 1009 if (bPaint) Paint(); | |
| 1010 } | |
| 1011 | |
| 1012 void CFX_Edit::SetAlignmentH(int32_t nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/) | |
| 1013 { | |
| 1014 m_pVT->SetAlignment(nFormat); | |
| 1015 if (bPaint) Paint(); | |
| 1016 } | |
| 1017 | |
| 1018 void CFX_Edit::SetAlignmentV(int32_t nFormat/* =0 */, FX_BOOL bPaint/* = TRUE*/) | |
| 1019 { | |
| 1020 m_nAlignment = nFormat; | |
| 1021 if (bPaint) Paint(); | |
| 1022 } | |
| 1023 | |
| 1024 void CFX_Edit::SetPasswordChar(FX_WORD wSubWord/* ='*' */, FX_BOOL bPaint/* = TR
UE*/) | |
| 1025 { | |
| 1026 m_pVT->SetPasswordChar(wSubWord); | |
| 1027 if (bPaint) Paint(); | |
| 1028 } | |
| 1029 | |
| 1030 void CFX_Edit::SetLimitChar(int32_t nLimitChar/* =0 */, FX_BOOL bPaint/* = TRUE*
/) | |
| 1031 { | |
| 1032 m_pVT->SetLimitChar(nLimitChar); | |
| 1033 if (bPaint) Paint(); | |
| 1034 } | |
| 1035 | |
| 1036 void CFX_Edit::SetCharArray(int32_t nCharArray/* =0 */, FX_BOOL bPaint/* = TRUE*
/) | |
| 1037 { | |
| 1038 m_pVT->SetCharArray(nCharArray); | |
| 1039 if (bPaint) Paint(); | |
| 1040 } | |
| 1041 | |
| 1042 void CFX_Edit::SetCharSpace(FX_FLOAT fCharSpace/* =0.0f */, FX_BOOL bPaint/* = T
RUE*/) | |
| 1043 { | |
| 1044 m_pVT->SetCharSpace(fCharSpace); | |
| 1045 if (bPaint) Paint(); | |
| 1046 } | |
| 1047 | |
| 1048 void CFX_Edit::SetHorzScale(int32_t nHorzScale/* =100 */, FX_BOOL bPaint/* = TRU
E*/) | |
| 1049 { | |
| 1050 m_pVT->SetHorzScale(nHorzScale); | |
| 1051 if (bPaint) Paint(); | |
| 1052 } | |
| 1053 | |
| 1054 void CFX_Edit::SetMultiLine(FX_BOOL bMultiLine/* =TRUE */, FX_BOOL bPaint/* = TR
UE*/) | |
| 1055 { | |
| 1056 m_pVT->SetMultiLine(bMultiLine); | |
| 1057 if (bPaint) Paint(); | |
| 1058 } | |
| 1059 | |
| 1060 void CFX_Edit::SetAutoReturn(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/
) | |
| 1061 { | |
| 1062 m_pVT->SetAutoReturn(bAuto); | |
| 1063 if (bPaint) Paint(); | |
| 1064 } | |
| 1065 | |
| 1066 void CFX_Edit::SetLineLeading(FX_FLOAT fLineLeading/* =TRUE */, FX_BOOL bPaint/*
= TRUE*/) | |
| 1067 { | |
| 1068 m_pVT->SetLineLeading(fLineLeading); | |
| 1069 if (bPaint) Paint(); | |
| 1070 } | |
| 1071 | |
| 1072 void CFX_Edit::SetAutoFontSize(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE
*/) | |
| 1073 { | |
| 1074 m_pVT->SetAutoFontSize(bAuto); | |
| 1075 if (bPaint) Paint(); | |
| 1076 } | |
| 1077 | |
| 1078 void CFX_Edit::SetFontSize(FX_FLOAT fFontSize, FX_BOOL bPaint/* = TRUE*/) | |
| 1079 { | |
| 1080 m_pVT->SetFontSize(fFontSize); | |
| 1081 if (bPaint) Paint(); | |
| 1082 } | |
| 1083 | |
| 1084 void CFX_Edit::SetAutoScroll(FX_BOOL bAuto/* =TRUE */, FX_BOOL bPaint/* = TRUE*/
) | |
| 1085 { | |
| 1086 m_bEnableScroll = bAuto; | |
| 1087 if (bPaint) Paint(); | |
| 1088 } | |
| 1089 | |
| 1090 void CFX_Edit::SetTextOverflow(FX_BOOL bAllowed /*= FALSE*/, FX_BOOL bPaint/* =
TRUE*/) | |
| 1091 { | |
| 1092 m_bEnableOverflow = bAllowed; | |
| 1093 if (bPaint) Paint(); | |
| 1094 } | |
| 1095 | |
| 1096 void CFX_Edit::SetSel(int32_t nStartChar,int32_t nEndChar) | |
| 1097 { | |
| 1098 if (m_pVT->IsValid()) | |
| 1099 { | |
| 1100 if (nStartChar == 0 && nEndChar < 0) | |
| 1101 { | |
| 1102 SelectAll(); | |
| 1103 } | |
| 1104 else if (nStartChar < 0) | |
| 1105 { | |
| 1106 SelectNone(); | |
| 1107 } | |
| 1108 else | |
| 1109 { | |
| 1110 if (nStartChar < nEndChar) | |
| 1111 { | |
| 1112 SetSel(m_pVT->WordIndexToWordPlace(nStartChar),m_pVT->WordIndexT
oWordPlace(nEndChar)); | |
| 1113 } | |
| 1114 else | |
| 1115 { | |
| 1116 SetSel(m_pVT->WordIndexToWordPlace(nEndChar),m_pVT->WordIndexToW
ordPlace(nStartChar)); | |
| 1117 } | |
| 1118 } | |
| 1119 } | |
| 1120 } | |
| 1121 | |
| 1122 void CFX_Edit::SetSel(const CPVT_WordPlace & begin,const CPVT_WordPlace & end) | |
| 1123 { | |
| 1124 if (m_pVT->IsValid()) | |
| 1125 { | |
| 1126 SelectNone(); | |
| 1127 | |
| 1128 m_SelState.Set(begin,end); | |
| 1129 | |
| 1130 SetCaret(m_SelState.EndPos); | |
| 1131 | |
| 1132 if (m_SelState.IsExist()) | |
| 1133 { | |
| 1134 ScrollToCaret(); | |
| 1135 CPVT_WordRange wr(m_SelState.BeginPos,m_SelState.EndPos); | |
| 1136 Refresh(RP_OPTIONAL,&wr); | |
| 1137 SetCaretInfo(); | |
| 1138 } | |
| 1139 else | |
| 1140 { | |
| 1141 ScrollToCaret(); | |
| 1142 SetCaretInfo(); | |
| 1143 } | |
| 1144 } | |
| 1145 } | |
| 1146 | |
| 1147 void CFX_Edit::GetSel(int32_t & nStartChar, int32_t & nEndChar) const | |
| 1148 { | |
| 1149 nStartChar = -1; | |
| 1150 nEndChar = -1; | |
| 1151 | |
| 1152 if (m_pVT->IsValid()) | |
| 1153 { | |
| 1154 if (m_SelState.IsExist()) | |
| 1155 { | |
| 1156 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0) | |
| 1157 { | |
| 1158 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); | |
| 1159 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); | |
| 1160 } | |
| 1161 else | |
| 1162 { | |
| 1163 nStartChar = m_pVT->WordPlaceToWordIndex(m_SelState.EndPos); | |
| 1164 nEndChar = m_pVT->WordPlaceToWordIndex(m_SelState.BeginPos); | |
| 1165 } | |
| 1166 } | |
| 1167 else | |
| 1168 { | |
| 1169 nStartChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); | |
| 1170 nEndChar = m_pVT->WordPlaceToWordIndex(m_wpCaret); | |
| 1171 } | |
| 1172 } | |
| 1173 } | |
| 1174 | |
| 1175 int32_t CFX_Edit::GetCaret() const | |
| 1176 { | |
| 1177 if (m_pVT->IsValid()) | |
| 1178 return m_pVT->WordPlaceToWordIndex(m_wpCaret); | |
| 1179 | |
| 1180 return -1; | |
| 1181 } | |
| 1182 | |
| 1183 CPVT_WordPlace CFX_Edit::GetCaretWordPlace() const | |
| 1184 { | |
| 1185 return m_wpCaret; | |
| 1186 } | |
| 1187 | |
| 1188 CFX_WideString CFX_Edit::GetText() const | |
| 1189 { | |
| 1190 CFX_WideString swRet; | |
| 1191 | |
| 1192 if (m_pVT->IsValid()) | |
| 1193 { | |
| 1194 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 1195 { | |
| 1196 FX_BOOL bRich = m_pVT->IsRichText(); | |
| 1197 | |
| 1198 pIterator->SetAt(0); | |
| 1199 | |
| 1200 CPVT_Word wordinfo; | |
| 1201 CPVT_WordPlace oldplace = pIterator->GetAt(); | |
| 1202 while (pIterator->NextWord()) | |
| 1203 { | |
| 1204 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1205 | |
| 1206 if (pIterator->GetWord(wordinfo)) | |
| 1207 { | |
| 1208 if (bRich) | |
| 1209 { | |
| 1210 swRet += wordinfo.Word; | |
| 1211 } | |
| 1212 else | |
| 1213 { | |
| 1214 swRet += wordinfo.Word; | |
| 1215 } | |
| 1216 } | |
| 1217 | |
| 1218 if (oldplace.SecCmp(place) != 0) | |
| 1219 { | |
| 1220 swRet += 0x0D; | |
| 1221 swRet += 0x0A; | |
| 1222 } | |
| 1223 | |
| 1224 oldplace = place; | |
| 1225 } | |
| 1226 } | |
| 1227 } | |
| 1228 | |
| 1229 return swRet; | |
| 1230 } | |
| 1231 | |
| 1232 CFX_WideString CFX_Edit::GetRangeText(const CPVT_WordRange & range) const | |
| 1233 { | |
| 1234 CFX_WideString swRet; | |
| 1235 | |
| 1236 if (m_pVT->IsValid()) | |
| 1237 { | |
| 1238 FX_BOOL bRich = m_pVT->IsRichText(); | |
| 1239 | |
| 1240 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 1241 { | |
| 1242 CPVT_WordRange wrTemp = range; | |
| 1243 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | |
| 1244 m_pVT->UpdateWordPlace(wrTemp.EndPos); | |
| 1245 pIterator->SetAt(wrTemp.BeginPos); | |
| 1246 | |
| 1247 CPVT_Word wordinfo; | |
| 1248 CPVT_WordPlace oldplace = wrTemp.BeginPos; | |
| 1249 while (pIterator->NextWord()) | |
| 1250 { | |
| 1251 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1252 if (place.WordCmp(wrTemp.EndPos) > 0)break; | |
| 1253 | |
| 1254 if (pIterator->GetWord(wordinfo)) | |
| 1255 { | |
| 1256 if (bRich) | |
| 1257 { | |
| 1258 swRet += wordinfo.Word; | |
| 1259 } | |
| 1260 else | |
| 1261 { | |
| 1262 swRet += wordinfo.Word; | |
| 1263 } | |
| 1264 } | |
| 1265 | |
| 1266 if (oldplace.SecCmp(place) != 0) | |
| 1267 { | |
| 1268 swRet += 0x0D; | |
| 1269 swRet += 0x0A; | |
| 1270 } | |
| 1271 | |
| 1272 oldplace = place; | |
| 1273 } | |
| 1274 } | |
| 1275 } | |
| 1276 | |
| 1277 return swRet; | |
| 1278 } | |
| 1279 | |
| 1280 CFX_WideString CFX_Edit::GetSelText() const | |
| 1281 { | |
| 1282 return GetRangeText(m_SelState.ConvertToWordRange()); | |
| 1283 } | |
| 1284 | |
| 1285 int32_t CFX_Edit::GetTotalWords() const | |
| 1286 { | |
| 1287 return m_pVT->GetTotalWords(); | |
| 1288 } | |
| 1289 | |
| 1290 int32_t CFX_Edit::GetTotalLines() const | |
| 1291 { | |
| 1292 int32_t nLines = 0; | |
| 1293 | |
| 1294 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 1295 { | |
| 1296 pIterator->SetAt(0); | |
| 1297 while (pIterator->NextLine()) | |
| 1298 nLines++; | |
| 1299 } | |
| 1300 | |
| 1301 return nLines+1; | |
| 1302 } | |
| 1303 | |
| 1304 CPVT_WordRange CFX_Edit::GetSelectWordRange() const | |
| 1305 { | |
| 1306 return m_SelState.ConvertToWordRange(); | |
| 1307 } | |
| 1308 | |
| 1309 CPVT_WordRange CFX_Edit::CombineWordRange(const CPVT_WordRange & wr1, const CPVT
_WordRange & wr2) | |
| 1310 { | |
| 1311 CPVT_WordRange wrRet; | |
| 1312 | |
| 1313 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) | |
| 1314 { | |
| 1315 wrRet.BeginPos = wr1.BeginPos; | |
| 1316 } | |
| 1317 else | |
| 1318 { | |
| 1319 wrRet.BeginPos = wr2.BeginPos; | |
| 1320 } | |
| 1321 | |
| 1322 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) | |
| 1323 { | |
| 1324 wrRet.EndPos = wr2.EndPos; | |
| 1325 } | |
| 1326 else | |
| 1327 { | |
| 1328 wrRet.EndPos = wr1.EndPos; | |
| 1329 } | |
| 1330 | |
| 1331 return wrRet; | |
| 1332 } | |
| 1333 | |
| 1334 FX_BOOL CFX_Edit::IsRichText() const | |
| 1335 { | |
| 1336 return m_pVT->IsRichText(); | |
| 1337 } | |
| 1338 | |
| 1339 void CFX_Edit::SetRichText(FX_BOOL bRichText/* =TRUE */, FX_BOOL bPaint/* = TRUE
*/) | |
| 1340 { | |
| 1341 m_pVT->SetRichText(bRichText); | |
| 1342 if (bPaint) Paint(); | |
| 1343 } | |
| 1344 | |
| 1345 FX_BOOL CFX_Edit::SetRichFontIndex(int32_t nFontIndex) | |
| 1346 { | |
| 1347 CPVT_WordProps WordProps; | |
| 1348 WordProps.nFontIndex = nFontIndex; | |
| 1349 return SetRichTextProps(EP_FONTINDEX,NULL,&WordProps); | |
| 1350 } | |
| 1351 | |
| 1352 FX_BOOL CFX_Edit::SetRichFontSize(FX_FLOAT fFontSize) | |
| 1353 { | |
| 1354 CPVT_WordProps WordProps; | |
| 1355 WordProps.fFontSize = fFontSize; | |
| 1356 return SetRichTextProps(EP_FONTSIZE,NULL,&WordProps); | |
| 1357 } | |
| 1358 | |
| 1359 FX_BOOL CFX_Edit::SetRichTextColor(FX_COLORREF dwColor) | |
| 1360 { | |
| 1361 CPVT_WordProps WordProps; | |
| 1362 WordProps.dwWordColor = dwColor; | |
| 1363 return SetRichTextProps(EP_WORDCOLOR,NULL,&WordProps); | |
| 1364 } | |
| 1365 | |
| 1366 FX_BOOL CFX_Edit::SetRichTextScript(int32_t nScriptType) | |
| 1367 { | |
| 1368 CPVT_WordProps WordProps; | |
| 1369 WordProps.nScriptType = nScriptType; | |
| 1370 return SetRichTextProps(EP_SCRIPTTYPE,NULL,&WordProps); | |
| 1371 } | |
| 1372 | |
| 1373 FX_BOOL CFX_Edit::SetRichTextBold(FX_BOOL bBold) | |
| 1374 { | |
| 1375 CPVT_WordProps WordProps; | |
| 1376 if (bBold) | |
| 1377 WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; | |
| 1378 return SetRichTextProps(EP_BOLD,NULL,&WordProps); | |
| 1379 } | |
| 1380 | |
| 1381 FX_BOOL CFX_Edit::SetRichTextItalic(FX_BOOL bItalic) | |
| 1382 { | |
| 1383 CPVT_WordProps WordProps; | |
| 1384 if (bItalic) | |
| 1385 WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; | |
| 1386 return SetRichTextProps(EP_ITALIC,NULL,&WordProps); | |
| 1387 } | |
| 1388 | |
| 1389 FX_BOOL CFX_Edit::SetRichTextUnderline(FX_BOOL bUnderline) | |
| 1390 { | |
| 1391 CPVT_WordProps WordProps; | |
| 1392 if (bUnderline) | |
| 1393 WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; | |
| 1394 return SetRichTextProps(EP_UNDERLINE,NULL,&WordProps); | |
| 1395 } | |
| 1396 | |
| 1397 FX_BOOL CFX_Edit::SetRichTextCrossout(FX_BOOL bCrossout) | |
| 1398 { | |
| 1399 CPVT_WordProps WordProps; | |
| 1400 if (bCrossout) | |
| 1401 WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; | |
| 1402 return SetRichTextProps(EP_CROSSOUT,NULL,&WordProps); | |
| 1403 } | |
| 1404 | |
| 1405 FX_BOOL CFX_Edit::SetRichTextCharSpace(FX_FLOAT fCharSpace) | |
| 1406 { | |
| 1407 CPVT_WordProps WordProps; | |
| 1408 WordProps.fCharSpace = fCharSpace; | |
| 1409 return SetRichTextProps(EP_CHARSPACE,NULL,&WordProps); | |
| 1410 } | |
| 1411 | |
| 1412 FX_BOOL CFX_Edit::SetRichTextHorzScale(int32_t nHorzScale /*= 100*/) | |
| 1413 { | |
| 1414 CPVT_WordProps WordProps; | |
| 1415 WordProps.nHorzScale = nHorzScale; | |
| 1416 return SetRichTextProps(EP_HORZSCALE,NULL,&WordProps); | |
| 1417 } | |
| 1418 | |
| 1419 FX_BOOL CFX_Edit::SetRichTextLineLeading(FX_FLOAT fLineLeading) | |
| 1420 { | |
| 1421 CPVT_SecProps SecProps; | |
| 1422 SecProps.fLineLeading = fLineLeading; | |
| 1423 return SetRichTextProps(EP_LINELEADING,&SecProps,NULL); | |
| 1424 } | |
| 1425 | |
| 1426 FX_BOOL CFX_Edit::SetRichTextLineIndent(FX_FLOAT fLineIndent) | |
| 1427 { | |
| 1428 CPVT_SecProps SecProps; | |
| 1429 SecProps.fLineIndent = fLineIndent; | |
| 1430 return SetRichTextProps(EP_LINEINDENT,&SecProps,NULL); | |
| 1431 } | |
| 1432 | |
| 1433 FX_BOOL CFX_Edit::SetRichTextAlignment(int32_t nAlignment) | |
| 1434 { | |
| 1435 CPVT_SecProps SecProps; | |
| 1436 SecProps.nAlignment = nAlignment; | |
| 1437 return SetRichTextProps(EP_ALIGNMENT,&SecProps,NULL); | |
| 1438 } | |
| 1439 | |
| 1440 FX_BOOL CFX_Edit::SetRichTextProps(EDIT_PROPS_E eProps, const CPVT_SecProps * pS
ecProps, const CPVT_WordProps * pWordProps) | |
| 1441 { | |
| 1442 FX_BOOL bSet = FALSE; | |
| 1443 FX_BOOL bSet1,bSet2; | |
| 1444 if (m_pVT->IsValid() && m_pVT->IsRichText()) | |
| 1445 { | |
| 1446 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 1447 { | |
| 1448 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); | |
| 1449 | |
| 1450 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | |
| 1451 m_pVT->UpdateWordPlace(wrTemp.EndPos); | |
| 1452 pIterator->SetAt(wrTemp.BeginPos); | |
| 1453 | |
| 1454 BeginGroupUndo(L"");; | |
| 1455 | |
| 1456 bSet = SetSecProps(eProps,wrTemp.BeginPos,pSecProps,pWordProps,wrTem
p,TRUE); | |
| 1457 | |
| 1458 while (pIterator->NextWord()) | |
| 1459 { | |
| 1460 CPVT_WordPlace place = pIterator->GetAt(); | |
| 1461 if (place.WordCmp(wrTemp.EndPos) > 0) break; | |
| 1462 bSet1 = SetSecProps(eProps,place,pSecProps,pWordProps,wrTemp,TRU
E); | |
| 1463 bSet2 = SetWordProps(eProps,place,pWordProps,wrTemp,TRUE); | |
| 1464 | |
| 1465 if (!bSet) | |
| 1466 bSet = (bSet1 || bSet2); | |
| 1467 } | |
| 1468 | |
| 1469 EndGroupUndo(); | |
| 1470 | |
| 1471 if (bSet) | |
| 1472 { | |
| 1473 PaintSetProps(eProps,wrTemp); | |
| 1474 } | |
| 1475 } | |
| 1476 } | |
| 1477 | |
| 1478 return bSet; | |
| 1479 } | |
| 1480 | |
| 1481 void CFX_Edit::PaintSetProps(EDIT_PROPS_E eProps, const CPVT_WordRange & wr) | |
| 1482 { | |
| 1483 switch(eProps) | |
| 1484 { | |
| 1485 case EP_LINELEADING: | 1302 case EP_LINELEADING: |
| 1486 case EP_LINEINDENT: | 1303 case EP_LINEINDENT: |
| 1487 case EP_ALIGNMENT: | 1304 case EP_ALIGNMENT: |
| 1488 RearrangePart(wr); | 1305 RearrangePart(wr); |
| 1489 ScrollToCaret(); | 1306 ScrollToCaret(); |
| 1490 Refresh(RP_ANALYSE); | 1307 Refresh(RP_ANALYSE); |
| 1491 SetCaretOrigin(); | 1308 SetCaretOrigin(); |
| 1492 SetCaretInfo(); | 1309 SetCaretInfo(); |
| 1493 break; | 1310 break; |
| 1494 case EP_WORDCOLOR: | 1311 case EP_WORDCOLOR: |
| 1495 case EP_UNDERLINE: | 1312 case EP_UNDERLINE: |
| 1496 case EP_CROSSOUT: | 1313 case EP_CROSSOUT: |
| 1497 Refresh(RP_OPTIONAL,&wr); | 1314 Refresh(RP_OPTIONAL, &wr); |
| 1498 break; | 1315 break; |
| 1499 case EP_FONTINDEX: | 1316 case EP_FONTINDEX: |
| 1500 case EP_FONTSIZE: | 1317 case EP_FONTSIZE: |
| 1501 case EP_SCRIPTTYPE: | 1318 case EP_SCRIPTTYPE: |
| 1502 case EP_CHARSPACE: | 1319 case EP_CHARSPACE: |
| 1503 case EP_HORZSCALE: | 1320 case EP_HORZSCALE: |
| 1504 case EP_BOLD: | 1321 case EP_BOLD: |
| 1505 case EP_ITALIC: | 1322 case EP_ITALIC: |
| 1506 RearrangePart(wr); | 1323 RearrangePart(wr); |
| 1507 ScrollToCaret(); | 1324 ScrollToCaret(); |
| 1508 | 1325 |
| 1509 CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos), | 1326 CPVT_WordRange wrRefresh(m_pVT->GetSectionBeginPlace(wr.BeginPos), |
| 1510 m_pVT->GetSectionEndPlace(wr.EndPos)); | 1327 m_pVT->GetSectionEndPlace(wr.EndPos)); |
| 1511 Refresh(RP_ANALYSE,&wrRefresh); | 1328 Refresh(RP_ANALYSE, &wrRefresh); |
| 1512 | 1329 |
| 1513 SetCaretOrigin(); | 1330 SetCaretOrigin(); |
| 1514 SetCaretInfo(); | 1331 SetCaretInfo(); |
| 1515 break; | 1332 break; |
| 1516 } | 1333 } |
| 1517 } | 1334 } |
| 1518 | 1335 |
| 1519 FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place, | 1336 FX_BOOL CFX_Edit::SetSecProps(EDIT_PROPS_E eProps, |
| 1520 const CPVT_SecProps * pSecProps, const CPVT_WordP
rops * pWordProps, | 1337 const CPVT_WordPlace& place, |
| 1521 const CPVT_WordRange & wr, FX_BOOL bAddUndo) | 1338 const CPVT_SecProps* pSecProps, |
| 1522 { | 1339 const CPVT_WordProps* pWordProps, |
| 1523 if (m_pVT->IsValid() && m_pVT->IsRichText()) | 1340 const CPVT_WordRange& wr, |
| 1524 { | 1341 FX_BOOL bAddUndo) { |
| 1525 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | 1342 if (m_pVT->IsValid() && m_pVT->IsRichText()) { |
| 1526 { | 1343 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 1527 FX_BOOL bSet = FALSE; | 1344 FX_BOOL bSet = FALSE; |
| 1528 CPVT_Section secinfo; | 1345 CPVT_Section secinfo; |
| 1529 CPVT_Section OldSecinfo; | 1346 CPVT_Section OldSecinfo; |
| 1530 | 1347 |
| 1531 CPVT_WordPlace oldplace = pIterator->GetAt(); | 1348 CPVT_WordPlace oldplace = pIterator->GetAt(); |
| 1532 | 1349 |
| 1533 if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || eProps ==
EP_ALIGNMENT) | 1350 if (eProps == EP_LINELEADING || eProps == EP_LINEINDENT || |
| 1534 { | 1351 eProps == EP_ALIGNMENT) { |
| 1535 if (pSecProps) | 1352 if (pSecProps) { |
| 1536 { | 1353 pIterator->SetAt(place); |
| 1537 pIterator->SetAt(place); | 1354 if (pIterator->GetSection(secinfo)) { |
| 1538 if (pIterator->GetSection(secinfo)) | 1355 if (bAddUndo) |
| 1539 { | 1356 OldSecinfo = secinfo; |
| 1540 if (bAddUndo) OldSecinfo = secinfo; | 1357 |
| 1541 | 1358 switch (eProps) { |
| 1542 switch(eProps) | 1359 case EP_LINELEADING: |
| 1543 { | 1360 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLeading, |
| 1544 case EP_LINELEADING: | 1361 pSecProps->fLineLeading)) { |
| 1545 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineLead
ing,pSecProps->fLineLeading)) | 1362 secinfo.SecProps.fLineLeading = pSecProps->fLineLeading; |
| 1546 { | 1363 bSet = TRUE; |
| 1547 secinfo.SecProps.fLineLeading = pSecProps->fLine
Leading; | 1364 } |
| 1548 bSet = TRUE; | 1365 break; |
| 1549 } | 1366 case EP_LINEINDENT: |
| 1550 break; | 1367 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineIndent, |
| 1551 case EP_LINEINDENT: | 1368 pSecProps->fLineIndent)) { |
| 1552 if (!FX_EDIT_IsFloatEqual(secinfo.SecProps.fLineInde
nt,pSecProps->fLineIndent)) | 1369 secinfo.SecProps.fLineIndent = pSecProps->fLineIndent; |
| 1553 { | 1370 bSet = TRUE; |
| 1554 secinfo.SecProps.fLineIndent = pSecProps->fLineI
ndent; | 1371 } |
| 1555 bSet = TRUE; | 1372 break; |
| 1556 } | 1373 case EP_ALIGNMENT: |
| 1557 break; | 1374 if (secinfo.SecProps.nAlignment != pSecProps->nAlignment) { |
| 1558 case EP_ALIGNMENT: | 1375 secinfo.SecProps.nAlignment = pSecProps->nAlignment; |
| 1559 if (secinfo.SecProps.nAlignment != pSecProps->nAlign
ment) | 1376 bSet = TRUE; |
| 1560 { | 1377 } |
| 1561 secinfo.SecProps.nAlignment = pSecProps->nAlignm
ent; | 1378 break; |
| 1562 bSet = TRUE; | 1379 default: |
| 1563 } | 1380 break; |
| 1564 break; | |
| 1565 default: | |
| 1566 break; | |
| 1567 } | |
| 1568 } | |
| 1569 } | |
| 1570 } | 1381 } |
| 1571 else | 1382 } |
| 1572 { | 1383 } |
| 1573 if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) | 1384 } else { |
| 1574 { | 1385 if (pWordProps && place == m_pVT->GetSectionBeginPlace(place)) { |
| 1575 pIterator->SetAt(place); | 1386 pIterator->SetAt(place); |
| 1576 if (pIterator->GetSection(secinfo)) | 1387 if (pIterator->GetSection(secinfo)) { |
| 1577 { | 1388 if (bAddUndo) |
| 1578 if (bAddUndo) OldSecinfo = secinfo; | 1389 OldSecinfo = secinfo; |
| 1579 | 1390 |
| 1580 switch(eProps) | 1391 switch (eProps) { |
| 1581 { | 1392 case EP_FONTINDEX: |
| 1582 case EP_FONTINDEX: | 1393 if (secinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
| 1583 if (secinfo.WordProps.nFontIndex != pWordProps->nFon
tIndex) | 1394 secinfo.WordProps.nFontIndex = pWordProps->nFontIndex; |
| 1584 { | 1395 bSet = TRUE; |
| 1585 secinfo.WordProps.nFontIndex = pWordProps->nFont
Index; | 1396 } |
| 1586 bSet = TRUE; | 1397 break; |
| 1587 } | 1398 case EP_FONTSIZE: |
| 1588 break; | 1399 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSize, |
| 1589 case EP_FONTSIZE: | 1400 pWordProps->fFontSize)) { |
| 1590 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fFontSiz
e,pWordProps->fFontSize)) | 1401 secinfo.WordProps.fFontSize = pWordProps->fFontSize; |
| 1591 { | 1402 bSet = TRUE; |
| 1592 secinfo.WordProps.fFontSize = pWordProps->fFontS
ize; | 1403 } |
| 1593 bSet = TRUE; | 1404 break; |
| 1594 } | 1405 case EP_WORDCOLOR: |
| 1595 break; | 1406 if (secinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
| 1596 case EP_WORDCOLOR: | 1407 secinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
| 1597 if (secinfo.WordProps.dwWordColor != pWordProps->dwW
ordColor) | 1408 bSet = TRUE; |
| 1598 { | 1409 } |
| 1599 secinfo.WordProps.dwWordColor = pWordProps->dwWo
rdColor; | 1410 break; |
| 1600 bSet = TRUE; | 1411 case EP_SCRIPTTYPE: |
| 1601 } | 1412 if (secinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
| 1602 break; | 1413 secinfo.WordProps.nScriptType = pWordProps->nScriptType; |
| 1603 case EP_SCRIPTTYPE: | 1414 bSet = TRUE; |
| 1604 if (secinfo.WordProps.nScriptType != pWordProps->nSc
riptType) | 1415 } |
| 1605 { | 1416 break; |
| 1606 secinfo.WordProps.nScriptType = pWordProps->nScr
iptType; | 1417 case EP_CHARSPACE: |
| 1607 bSet = TRUE; | 1418 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpace, |
| 1608 } | 1419 pWordProps->fCharSpace)) { |
| 1609 break; | 1420 secinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
| 1610 case EP_CHARSPACE: | 1421 bSet = TRUE; |
| 1611 if (!FX_EDIT_IsFloatEqual(secinfo.WordProps.fCharSpa
ce,pWordProps->fCharSpace)) | 1422 } |
| 1612 { | 1423 break; |
| 1613 secinfo.WordProps.fCharSpace = pWordProps->fChar
Space; | 1424 case EP_HORZSCALE: |
| 1614 bSet = TRUE; | 1425 if (secinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
| 1615 } | 1426 secinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
| 1616 break; | 1427 bSet = TRUE; |
| 1617 case EP_HORZSCALE: | 1428 } |
| 1618 if (secinfo.WordProps.nHorzScale != pWordProps->nHor
zScale) | 1429 break; |
| 1619 { | 1430 case EP_UNDERLINE: |
| 1620 secinfo.WordProps.nHorzScale = pWordProps->nHorz
Scale; | 1431 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1621 bSet = TRUE; | 1432 if ((secinfo.WordProps.nWordStyle & |
| 1622 } | 1433 PVTWORD_STYLE_UNDERLINE) == 0) { |
| 1623 break; | 1434 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 1624 case EP_UNDERLINE: | 1435 bSet = TRUE; |
| 1625 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE
) | 1436 } |
| 1626 { | 1437 } else { |
| 1627 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_UNDERLINE) == 0) | 1438 if ((secinfo.WordProps.nWordStyle & |
| 1628 { | 1439 PVTWORD_STYLE_UNDERLINE) != 0) { |
| 1629 secinfo.WordProps.nWordStyle |= PVTWORD_STYL
E_UNDERLINE; | 1440 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
| 1630 bSet = TRUE; | 1441 bSet = TRUE; |
| 1631 } | 1442 } |
| 1632 } | 1443 } |
| 1633 else | 1444 break; |
| 1634 { | 1445 case EP_CROSSOUT: |
| 1635 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_UNDERLINE) != 0) | 1446 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1636 { | 1447 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == |
| 1637 secinfo.WordProps.nWordStyle &= ~PVTWORD_STY
LE_UNDERLINE; | 1448 0) { |
| 1638 bSet = TRUE; | 1449 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 1639 } | 1450 bSet = TRUE; |
| 1640 } | 1451 } |
| 1641 break; | 1452 } else { |
| 1642 case EP_CROSSOUT: | 1453 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != |
| 1643 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) | 1454 0) { |
| 1644 { | 1455 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
| 1645 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_CROSSOUT) == 0) | 1456 bSet = TRUE; |
| 1646 { | 1457 } |
| 1647 secinfo.WordProps.nWordStyle |= PVTWORD_STYL
E_CROSSOUT; | 1458 } |
| 1648 bSet = TRUE; | 1459 break; |
| 1649 } | 1460 case EP_BOLD: |
| 1650 } | 1461 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
| 1651 else | 1462 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == |
| 1652 { | 1463 0) { |
| 1653 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_CROSSOUT) != 0) | 1464 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 1654 { | 1465 bSet = TRUE; |
| 1655 secinfo.WordProps.nWordStyle &= ~PVTWORD_STY
LE_CROSSOUT; | 1466 } |
| 1656 bSet = TRUE; | 1467 } else { |
| 1657 } | 1468 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != |
| 1658 } | 1469 0) { |
| 1659 break; | 1470 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
| 1660 case EP_BOLD: | 1471 bSet = TRUE; |
| 1661 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) | 1472 } |
| 1662 { | 1473 } |
| 1663 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_BOLD) == 0) | 1474 break; |
| 1664 { | 1475 case EP_ITALIC: |
| 1665 secinfo.WordProps.nWordStyle |= PVTWORD_STYL
E_BOLD; | 1476 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
| 1666 bSet = TRUE; | 1477 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == |
| 1667 } | 1478 0) { |
| 1668 } | 1479 secinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 1669 else | 1480 bSet = TRUE; |
| 1670 { | 1481 } |
| 1671 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_BOLD) != 0) | 1482 } else { |
| 1672 { | 1483 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != |
| 1673 secinfo.WordProps.nWordStyle &= ~PVTWORD_STY
LE_BOLD; | 1484 0) { |
| 1674 bSet = TRUE; | 1485 secinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
| 1675 } | 1486 bSet = TRUE; |
| 1676 } | 1487 } |
| 1677 break; | 1488 } |
| 1678 case EP_ITALIC: | 1489 break; |
| 1679 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) | 1490 default: |
| 1680 { | 1491 break; |
| 1681 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_ITALIC) == 0) | |
| 1682 { | |
| 1683 secinfo.WordProps.nWordStyle |= PVTWORD_STYL
E_ITALIC; | |
| 1684 bSet = TRUE; | |
| 1685 } | |
| 1686 } | |
| 1687 else | |
| 1688 { | |
| 1689 if ((secinfo.WordProps.nWordStyle & PVTWORD_STYL
E_ITALIC) != 0) | |
| 1690 { | |
| 1691 secinfo.WordProps.nWordStyle &= ~PVTWORD_STY
LE_ITALIC; | |
| 1692 bSet = TRUE; | |
| 1693 } | |
| 1694 } | |
| 1695 break; | |
| 1696 default: | |
| 1697 break; | |
| 1698 } | |
| 1699 } | |
| 1700 } | |
| 1701 } | 1492 } |
| 1702 | 1493 } |
| 1703 if (bSet) | |
| 1704 { | |
| 1705 pIterator->SetSection(secinfo); | |
| 1706 | |
| 1707 if (bAddUndo && m_bEnableUndo) | |
| 1708 { | |
| 1709 AddEditUndoItem(new CFXEU_SetSecProps | |
| 1710 (this,place,eProps,OldSecinfo.SecProps,OldSecinfo.WordPr
ops,secinfo.SecProps,secinfo.WordProps,wr)); | |
| 1711 } | |
| 1712 } | |
| 1713 | |
| 1714 pIterator->SetAt(oldplace); | |
| 1715 | |
| 1716 return bSet; | |
| 1717 } | 1494 } |
| 1718 } | 1495 } |
| 1719 | 1496 |
| 1720 return FALSE; | 1497 if (bSet) { |
| 1721 } | 1498 pIterator->SetSection(secinfo); |
| 1722 | 1499 |
| 1723 FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, const CPVT_WordPlace & place
, | 1500 if (bAddUndo && m_bEnableUndo) { |
| 1724 const CPVT_WordProps * pWordProps, const CPVT_Wo
rdRange & wr, FX_BOOL bAddUndo) | 1501 AddEditUndoItem(new CFXEU_SetSecProps( |
| 1725 { | 1502 this, place, eProps, OldSecinfo.SecProps, OldSecinfo.WordProps, |
| 1726 if (m_pVT->IsValid() && m_pVT->IsRichText()) | 1503 secinfo.SecProps, secinfo.WordProps, wr)); |
| 1727 { | |
| 1728 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 1729 { | |
| 1730 FX_BOOL bSet = FALSE; | |
| 1731 CPVT_Word wordinfo; | |
| 1732 CPVT_Word OldWordinfo; | |
| 1733 | |
| 1734 CPVT_WordPlace oldplace = pIterator->GetAt(); | |
| 1735 | |
| 1736 if (pWordProps) | |
| 1737 { | |
| 1738 pIterator->SetAt(place); | |
| 1739 if (pIterator->GetWord(wordinfo)) | |
| 1740 { | |
| 1741 if (bAddUndo) OldWordinfo = wordinfo; | |
| 1742 | |
| 1743 switch(eProps) | |
| 1744 { | |
| 1745 case EP_FONTINDEX: | |
| 1746 if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIn
dex) | |
| 1747 { | |
| 1748 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) | |
| 1749 { | |
| 1750 wordinfo.WordProps.nFontIndex = pFontMap->GetWor
dFontIndex(wordinfo.Word,wordinfo.nCharset,pWordProps->nFontIndex); | |
| 1751 } | |
| 1752 bSet = TRUE; | |
| 1753 } | |
| 1754 break; | |
| 1755 case EP_FONTSIZE: | |
| 1756 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize,p
WordProps->fFontSize)) | |
| 1757 { | |
| 1758 wordinfo.WordProps.fFontSize = pWordProps->fFontSize
; | |
| 1759 bSet = TRUE; | |
| 1760 } | |
| 1761 break; | |
| 1762 case EP_WORDCOLOR: | |
| 1763 if (wordinfo.WordProps.dwWordColor != pWordProps->dwWord
Color) | |
| 1764 { | |
| 1765 wordinfo.WordProps.dwWordColor = pWordProps->dwWordC
olor; | |
| 1766 bSet = TRUE; | |
| 1767 } | |
| 1768 break; | |
| 1769 case EP_SCRIPTTYPE: | |
| 1770 if (wordinfo.WordProps.nScriptType != pWordProps->nScrip
tType) | |
| 1771 { | |
| 1772 wordinfo.WordProps.nScriptType = pWordProps->nScript
Type; | |
| 1773 bSet = TRUE; | |
| 1774 } | |
| 1775 break; | |
| 1776 case EP_CHARSPACE: | |
| 1777 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace,
pWordProps->fCharSpace)) | |
| 1778 { | |
| 1779 wordinfo.WordProps.fCharSpace = pWordProps->fCharSpa
ce; | |
| 1780 bSet = TRUE; | |
| 1781 } | |
| 1782 break; | |
| 1783 case EP_HORZSCALE: | |
| 1784 if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzSc
ale) | |
| 1785 { | |
| 1786 wordinfo.WordProps.nHorzScale = pWordProps->nHorzSca
le; | |
| 1787 bSet = TRUE; | |
| 1788 } | |
| 1789 break; | |
| 1790 case EP_UNDERLINE: | |
| 1791 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) | |
| 1792 { | |
| 1793 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_U
NDERLINE) == 0) | |
| 1794 { | |
| 1795 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_U
NDERLINE; | |
| 1796 bSet = TRUE; | |
| 1797 } | |
| 1798 } | |
| 1799 else | |
| 1800 { | |
| 1801 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_U
NDERLINE) != 0) | |
| 1802 { | |
| 1803 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_
UNDERLINE; | |
| 1804 bSet = TRUE; | |
| 1805 } | |
| 1806 } | |
| 1807 break; | |
| 1808 case EP_CROSSOUT: | |
| 1809 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) | |
| 1810 { | |
| 1811 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_C
ROSSOUT) == 0) | |
| 1812 { | |
| 1813 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_C
ROSSOUT; | |
| 1814 bSet = TRUE; | |
| 1815 } | |
| 1816 } | |
| 1817 else | |
| 1818 { | |
| 1819 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_C
ROSSOUT) != 0) | |
| 1820 { | |
| 1821 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_
CROSSOUT; | |
| 1822 bSet = TRUE; | |
| 1823 } | |
| 1824 } | |
| 1825 break; | |
| 1826 case EP_BOLD: | |
| 1827 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) | |
| 1828 { | |
| 1829 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_B
OLD) == 0) | |
| 1830 { | |
| 1831 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_B
OLD; | |
| 1832 bSet = TRUE; | |
| 1833 } | |
| 1834 } | |
| 1835 else | |
| 1836 { | |
| 1837 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_B
OLD) != 0) | |
| 1838 { | |
| 1839 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_
BOLD; | |
| 1840 bSet = TRUE; | |
| 1841 } | |
| 1842 } | |
| 1843 break; | |
| 1844 case EP_ITALIC: | |
| 1845 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) | |
| 1846 { | |
| 1847 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_I
TALIC) == 0) | |
| 1848 { | |
| 1849 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_I
TALIC; | |
| 1850 bSet = TRUE; | |
| 1851 } | |
| 1852 } | |
| 1853 else | |
| 1854 { | |
| 1855 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_I
TALIC) != 0) | |
| 1856 { | |
| 1857 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_
ITALIC; | |
| 1858 bSet = TRUE; | |
| 1859 } | |
| 1860 } | |
| 1861 break; | |
| 1862 default: | |
| 1863 break; | |
| 1864 } | |
| 1865 } | |
| 1866 } | |
| 1867 | |
| 1868 if (bSet) | |
| 1869 { | |
| 1870 pIterator->SetWord(wordinfo); | |
| 1871 | |
| 1872 if (bAddUndo && m_bEnableUndo) | |
| 1873 { | |
| 1874 AddEditUndoItem(new CFXEU_SetWordProps | |
| 1875 (this,place,eProps,OldWordinfo.WordProps,wordinfo.WordPr
ops,wr)); | |
| 1876 } | |
| 1877 } | |
| 1878 | |
| 1879 pIterator->SetAt(oldplace); | |
| 1880 return bSet; | |
| 1881 } | 1504 } |
| 1882 } | 1505 } |
| 1883 | 1506 |
| 1884 return FALSE; | 1507 pIterator->SetAt(oldplace); |
| 1885 } | 1508 |
| 1886 | 1509 return bSet; |
| 1887 void CFX_Edit::SetText(const FX_WCHAR* text,int32_t charset /*= DEFAULT_CHARSET*
/, | 1510 } |
| 1888 const CPVT_SecProps * pSecProps /*= NULL*/,const CPVT_Wo
rdProps * pWordProps /*= NULL*/) | 1511 } |
| 1889 { | 1512 |
| 1890 SetText(text,charset,pSecProps,pWordProps,TRUE,TRUE); | 1513 return FALSE; |
| 1891 } | 1514 } |
| 1892 | 1515 |
| 1893 FX_BOOL CFX_Edit::InsertWord(FX_WORD word, int32_t charset /*= DEFAULT_CHARSET*/
, const CPVT_WordProps * pWordProps /*= NULL*/) | 1516 FX_BOOL CFX_Edit::SetWordProps(EDIT_PROPS_E eProps, |
| 1894 { | 1517 const CPVT_WordPlace& place, |
| 1895 return InsertWord(word,charset,pWordProps,TRUE,TRUE); | 1518 const CPVT_WordProps* pWordProps, |
| 1896 } | 1519 const CPVT_WordRange& wr, |
| 1897 | 1520 FX_BOOL bAddUndo) { |
| 1898 FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps /*= NULL*/,const
CPVT_WordProps * pWordProps /*= NULL*/) | 1521 if (m_pVT->IsValid() && m_pVT->IsRichText()) { |
| 1899 { | 1522 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 1900 return InsertReturn(pSecProps,pWordProps,TRUE,TRUE); | 1523 FX_BOOL bSet = FALSE; |
| 1901 } | 1524 CPVT_Word wordinfo; |
| 1902 | 1525 CPVT_Word OldWordinfo; |
| 1903 FX_BOOL CFX_Edit::Backspace() | 1526 |
| 1904 { | 1527 CPVT_WordPlace oldplace = pIterator->GetAt(); |
| 1905 return Backspace(TRUE,TRUE); | 1528 |
| 1906 } | 1529 if (pWordProps) { |
| 1907 | 1530 pIterator->SetAt(place); |
| 1908 FX_BOOL CFX_Edit::Delete() | 1531 if (pIterator->GetWord(wordinfo)) { |
| 1909 { | 1532 if (bAddUndo) |
| 1910 return Delete(TRUE,TRUE); | 1533 OldWordinfo = wordinfo; |
| 1911 } | 1534 |
| 1912 | 1535 switch (eProps) { |
| 1913 FX_BOOL CFX_Edit::Clear() | 1536 case EP_FONTINDEX: |
| 1914 { | 1537 if (wordinfo.WordProps.nFontIndex != pWordProps->nFontIndex) { |
| 1915 return Clear(TRUE,TRUE); | 1538 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) { |
| 1916 } | 1539 wordinfo.WordProps.nFontIndex = pFontMap->GetWordFontIndex( |
| 1917 | 1540 wordinfo.Word, wordinfo.nCharset, pWordProps->nFontIndex); |
| 1918 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, int32_t charset /*= DEFAULT_C
HARSET*/, | 1541 } |
| 1919 const CPVT_SecProps * pSecProps /*= NULL*/,const
CPVT_WordProps * pWordProps /*= NULL*/) | 1542 bSet = TRUE; |
| 1920 { | 1543 } |
| 1921 return InsertText(text,charset,pSecProps,pWordProps,TRUE,TRUE); | 1544 break; |
| 1922 } | 1545 case EP_FONTSIZE: |
| 1923 | 1546 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fFontSize, |
| 1924 FX_FLOAT CFX_Edit::GetFontSize() const | 1547 pWordProps->fFontSize)) { |
| 1925 { | 1548 wordinfo.WordProps.fFontSize = pWordProps->fFontSize; |
| 1926 return m_pVT->GetFontSize(); | 1549 bSet = TRUE; |
| 1927 } | 1550 } |
| 1928 | 1551 break; |
| 1929 FX_WORD CFX_Edit::GetPasswordChar() const | 1552 case EP_WORDCOLOR: |
| 1930 { | 1553 if (wordinfo.WordProps.dwWordColor != pWordProps->dwWordColor) { |
| 1931 return m_pVT->GetPasswordChar(); | 1554 wordinfo.WordProps.dwWordColor = pWordProps->dwWordColor; |
| 1932 } | 1555 bSet = TRUE; |
| 1933 | 1556 } |
| 1934 int32_t CFX_Edit::GetCharArray() const | 1557 break; |
| 1935 { | 1558 case EP_SCRIPTTYPE: |
| 1936 return m_pVT->GetCharArray(); | 1559 if (wordinfo.WordProps.nScriptType != pWordProps->nScriptType) { |
| 1937 } | 1560 wordinfo.WordProps.nScriptType = pWordProps->nScriptType; |
| 1938 | 1561 bSet = TRUE; |
| 1939 CPDF_Rect CFX_Edit::GetPlateRect() const | 1562 } |
| 1940 { | 1563 break; |
| 1941 return m_pVT->GetPlateRect(); | 1564 case EP_CHARSPACE: |
| 1942 } | 1565 if (!FX_EDIT_IsFloatEqual(wordinfo.WordProps.fCharSpace, |
| 1943 | 1566 pWordProps->fCharSpace)) { |
| 1944 CPDF_Rect CFX_Edit::GetContentRect() const | 1567 wordinfo.WordProps.fCharSpace = pWordProps->fCharSpace; |
| 1945 { | 1568 bSet = TRUE; |
| 1946 return VTToEdit(m_pVT->GetContentRect()); | 1569 } |
| 1947 } | 1570 break; |
| 1948 | 1571 case EP_HORZSCALE: |
| 1949 int32_t CFX_Edit::GetHorzScale() const | 1572 if (wordinfo.WordProps.nHorzScale != pWordProps->nHorzScale) { |
| 1950 { | 1573 wordinfo.WordProps.nHorzScale = pWordProps->nHorzScale; |
| 1951 return m_pVT->GetHorzScale(); | 1574 bSet = TRUE; |
| 1952 } | 1575 } |
| 1953 | 1576 break; |
| 1954 FX_FLOAT CFX_Edit::GetCharSpace() const | 1577 case EP_UNDERLINE: |
| 1955 { | 1578 if (pWordProps->nWordStyle & PVTWORD_STYLE_UNDERLINE) { |
| 1956 return m_pVT->GetCharSpace(); | 1579 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) == |
| 1580 0) { |
| 1581 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_UNDERLINE; |
| 1582 bSet = TRUE; |
| 1583 } |
| 1584 } else { |
| 1585 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_UNDERLINE) != |
| 1586 0) { |
| 1587 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_UNDERLINE; |
| 1588 bSet = TRUE; |
| 1589 } |
| 1590 } |
| 1591 break; |
| 1592 case EP_CROSSOUT: |
| 1593 if (pWordProps->nWordStyle & PVTWORD_STYLE_CROSSOUT) { |
| 1594 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) == |
| 1595 0) { |
| 1596 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_CROSSOUT; |
| 1597 bSet = TRUE; |
| 1598 } |
| 1599 } else { |
| 1600 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_CROSSOUT) != |
| 1601 0) { |
| 1602 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_CROSSOUT; |
| 1603 bSet = TRUE; |
| 1604 } |
| 1605 } |
| 1606 break; |
| 1607 case EP_BOLD: |
| 1608 if (pWordProps->nWordStyle & PVTWORD_STYLE_BOLD) { |
| 1609 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) == 0) { |
| 1610 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_BOLD; |
| 1611 bSet = TRUE; |
| 1612 } |
| 1613 } else { |
| 1614 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_BOLD) != 0) { |
| 1615 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_BOLD; |
| 1616 bSet = TRUE; |
| 1617 } |
| 1618 } |
| 1619 break; |
| 1620 case EP_ITALIC: |
| 1621 if (pWordProps->nWordStyle & PVTWORD_STYLE_ITALIC) { |
| 1622 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) == |
| 1623 0) { |
| 1624 wordinfo.WordProps.nWordStyle |= PVTWORD_STYLE_ITALIC; |
| 1625 bSet = TRUE; |
| 1626 } |
| 1627 } else { |
| 1628 if ((wordinfo.WordProps.nWordStyle & PVTWORD_STYLE_ITALIC) != |
| 1629 0) { |
| 1630 wordinfo.WordProps.nWordStyle &= ~PVTWORD_STYLE_ITALIC; |
| 1631 bSet = TRUE; |
| 1632 } |
| 1633 } |
| 1634 break; |
| 1635 default: |
| 1636 break; |
| 1637 } |
| 1638 } |
| 1639 } |
| 1640 |
| 1641 if (bSet) { |
| 1642 pIterator->SetWord(wordinfo); |
| 1643 |
| 1644 if (bAddUndo && m_bEnableUndo) { |
| 1645 AddEditUndoItem(new CFXEU_SetWordProps(this, place, eProps, |
| 1646 OldWordinfo.WordProps, |
| 1647 wordinfo.WordProps, wr)); |
| 1648 } |
| 1649 } |
| 1650 |
| 1651 pIterator->SetAt(oldplace); |
| 1652 return bSet; |
| 1653 } |
| 1654 } |
| 1655 |
| 1656 return FALSE; |
| 1657 } |
| 1658 |
| 1659 void CFX_Edit::SetText(const FX_WCHAR* text, |
| 1660 int32_t charset /*= DEFAULT_CHARSET*/, |
| 1661 const CPVT_SecProps* pSecProps /*= NULL*/, |
| 1662 const CPVT_WordProps* pWordProps /*= NULL*/) { |
| 1663 SetText(text, charset, pSecProps, pWordProps, TRUE, TRUE); |
| 1664 } |
| 1665 |
| 1666 FX_BOOL CFX_Edit::InsertWord(FX_WORD word, |
| 1667 int32_t charset /*= DEFAULT_CHARSET*/, |
| 1668 const CPVT_WordProps* pWordProps /*= NULL*/) { |
| 1669 return InsertWord(word, charset, pWordProps, TRUE, TRUE); |
| 1670 } |
| 1671 |
| 1672 FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps /*= NULL*/, |
| 1673 const CPVT_WordProps* pWordProps /*= NULL*/) { |
| 1674 return InsertReturn(pSecProps, pWordProps, TRUE, TRUE); |
| 1675 } |
| 1676 |
| 1677 FX_BOOL CFX_Edit::Backspace() { |
| 1678 return Backspace(TRUE, TRUE); |
| 1679 } |
| 1680 |
| 1681 FX_BOOL CFX_Edit::Delete() { |
| 1682 return Delete(TRUE, TRUE); |
| 1683 } |
| 1684 |
| 1685 FX_BOOL CFX_Edit::Clear() { |
| 1686 return Clear(TRUE, TRUE); |
| 1687 } |
| 1688 |
| 1689 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, |
| 1690 int32_t charset /*= DEFAULT_CHARSET*/, |
| 1691 const CPVT_SecProps* pSecProps /*= NULL*/, |
| 1692 const CPVT_WordProps* pWordProps /*= NULL*/) { |
| 1693 return InsertText(text, charset, pSecProps, pWordProps, TRUE, TRUE); |
| 1694 } |
| 1695 |
| 1696 FX_FLOAT CFX_Edit::GetFontSize() const { |
| 1697 return m_pVT->GetFontSize(); |
| 1698 } |
| 1699 |
| 1700 FX_WORD CFX_Edit::GetPasswordChar() const { |
| 1701 return m_pVT->GetPasswordChar(); |
| 1702 } |
| 1703 |
| 1704 int32_t CFX_Edit::GetCharArray() const { |
| 1705 return m_pVT->GetCharArray(); |
| 1706 } |
| 1707 |
| 1708 CPDF_Rect CFX_Edit::GetPlateRect() const { |
| 1709 return m_pVT->GetPlateRect(); |
| 1710 } |
| 1711 |
| 1712 CPDF_Rect CFX_Edit::GetContentRect() const { |
| 1713 return VTToEdit(m_pVT->GetContentRect()); |
| 1714 } |
| 1715 |
| 1716 int32_t CFX_Edit::GetHorzScale() const { |
| 1717 return m_pVT->GetHorzScale(); |
| 1718 } |
| 1719 |
| 1720 FX_FLOAT CFX_Edit::GetCharSpace() const { |
| 1721 return m_pVT->GetCharSpace(); |
| 1957 } | 1722 } |
| 1958 | 1723 |
| 1959 // inner methods | 1724 // inner methods |
| 1960 | 1725 |
| 1961 CPVT_WordRange CFX_Edit::GetWholeWordRange() const | 1726 CPVT_WordRange CFX_Edit::GetWholeWordRange() const { |
| 1962 { | 1727 if (m_pVT->IsValid()) |
| 1963 if (m_pVT->IsValid()) | 1728 return CPVT_WordRange(m_pVT->GetBeginWordPlace(), m_pVT->GetEndWordPlace()); |
| 1964 return CPVT_WordRange(m_pVT->GetBeginWordPlace(),m_pVT->GetEndWordPlace(
)); | 1729 |
| 1965 | 1730 return CPVT_WordRange(); |
| 1966 return CPVT_WordRange(); | 1731 } |
| 1967 } | 1732 |
| 1968 | 1733 CPVT_WordRange CFX_Edit::GetVisibleWordRange() const { |
| 1969 CPVT_WordRange CFX_Edit::GetVisibleWordRange() const | 1734 if (m_bEnableOverflow) |
| 1970 { | 1735 return GetWholeWordRange(); |
| 1971 if (m_bEnableOverflow) return GetWholeWordRange(); | 1736 |
| 1972 | 1737 if (m_pVT->IsValid()) { |
| 1973 if (m_pVT->IsValid()) | 1738 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 1974 { | 1739 |
| 1975 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | 1740 CPVT_WordPlace place1 = |
| 1976 | 1741 m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPlate.left, rcPlate.top))); |
| 1977 CPVT_WordPlace place1 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPla
te.left,rcPlate.top))); | 1742 CPVT_WordPlace place2 = m_pVT->SearchWordPlace( |
| 1978 CPVT_WordPlace place2 = m_pVT->SearchWordPlace(EditToVT(CPDF_Point(rcPla
te.right,rcPlate.bottom))); | 1743 EditToVT(CPDF_Point(rcPlate.right, rcPlate.bottom))); |
| 1979 | 1744 |
| 1980 return CPVT_WordRange(place1,place2); | 1745 return CPVT_WordRange(place1, place2); |
| 1981 } | 1746 } |
| 1982 | 1747 |
| 1983 return CPVT_WordRange(); | 1748 return CPVT_WordRange(); |
| 1984 } | 1749 } |
| 1985 | 1750 |
| 1986 CPVT_WordPlace CFX_Edit::SearchWordPlace(const CPDF_Point& point) const | 1751 CPVT_WordPlace CFX_Edit::SearchWordPlace(const CPDF_Point& point) const { |
| 1987 { | 1752 if (m_pVT->IsValid()) { |
| 1988 if (m_pVT->IsValid()) | 1753 return m_pVT->SearchWordPlace(EditToVT(point)); |
| 1989 { | 1754 } |
| 1990 return m_pVT->SearchWordPlace(EditToVT(point)); | 1755 |
| 1991 } | 1756 return CPVT_WordPlace(); |
| 1992 | 1757 } |
| 1993 return CPVT_WordPlace(); | 1758 |
| 1994 } | 1759 void CFX_Edit::Paint() { |
| 1995 | 1760 if (m_pVT->IsValid()) { |
| 1996 void CFX_Edit::Paint() | 1761 RearrangeAll(); |
| 1997 { | 1762 ScrollToCaret(); |
| 1998 if (m_pVT->IsValid()) | 1763 Refresh(RP_NOANALYSE); |
| 1999 { | 1764 SetCaretOrigin(); |
| 2000 RearrangeAll(); | 1765 SetCaretInfo(); |
| 2001 ScrollToCaret(); | 1766 } |
| 2002 Refresh(RP_NOANALYSE); | 1767 } |
| 2003 SetCaretOrigin(); | 1768 |
| 2004 SetCaretInfo(); | 1769 void CFX_Edit::RearrangeAll() { |
| 2005 } | 1770 if (m_pVT->IsValid()) { |
| 2006 } | 1771 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2007 | 1772 m_pVT->RearrangeAll(); |
| 2008 void CFX_Edit::RearrangeAll() | 1773 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2009 { | 1774 SetScrollInfo(); |
| 2010 if (m_pVT->IsValid()) | 1775 SetContentChanged(); |
| 2011 { | 1776 } |
| 2012 m_pVT->UpdateWordPlace(m_wpCaret); | 1777 } |
| 2013 m_pVT->RearrangeAll(); | 1778 |
| 2014 m_pVT->UpdateWordPlace(m_wpCaret); | 1779 void CFX_Edit::RearrangePart(const CPVT_WordRange& range) { |
| 2015 SetScrollInfo(); | 1780 if (m_pVT->IsValid()) { |
| 2016 SetContentChanged(); | 1781 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2017 } | 1782 m_pVT->RearrangePart(range); |
| 2018 } | 1783 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2019 | 1784 SetScrollInfo(); |
| 2020 void CFX_Edit::RearrangePart(const CPVT_WordRange & range) | 1785 SetContentChanged(); |
| 2021 { | 1786 } |
| 2022 if (m_pVT->IsValid()) | 1787 } |
| 2023 { | 1788 |
| 2024 m_pVT->UpdateWordPlace(m_wpCaret); | 1789 void CFX_Edit::SetContentChanged() { |
| 2025 m_pVT->RearrangePart(range); | 1790 if (m_bNotify && m_pNotify) { |
| 2026 m_pVT->UpdateWordPlace(m_wpCaret); | 1791 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 2027 SetScrollInfo(); | 1792 if (rcContent.Width() != m_rcOldContent.Width() || |
| 2028 SetContentChanged(); | 1793 rcContent.Height() != m_rcOldContent.Height()) { |
| 2029 } | 1794 if (!m_bNotifyFlag) { |
| 2030 } | 1795 m_bNotifyFlag = TRUE; |
| 2031 | 1796 m_pNotify->IOnContentChange(rcContent); |
| 2032 void CFX_Edit::SetContentChanged() | 1797 m_bNotifyFlag = FALSE; |
| 2033 { | 1798 } |
| 2034 if (m_bNotify && m_pNotify) | 1799 m_rcOldContent = rcContent; |
| 2035 { | 1800 } |
| 2036 CPDF_Rect rcContent = m_pVT->GetContentRect(); | 1801 } |
| 2037 if (rcContent.Width() != m_rcOldContent.Width() || | 1802 } |
| 2038 rcContent.Height() != m_rcOldContent.Height()) | 1803 |
| 2039 { | 1804 void CFX_Edit::SelectAll() { |
| 2040 if (!m_bNotifyFlag) | 1805 if (m_pVT->IsValid()) { |
| 2041 { | 1806 m_SelState = GetWholeWordRange(); |
| 2042 m_bNotifyFlag = TRUE; | 1807 SetCaret(m_SelState.EndPos); |
| 2043 m_pNotify->IOnContentChange(rcContent); | 1808 |
| 2044 m_bNotifyFlag = FALSE; | 1809 ScrollToCaret(); |
| 2045 } | 1810 CPVT_WordRange wrVisible = GetVisibleWordRange(); |
| 2046 m_rcOldContent = rcContent; | 1811 Refresh(RP_OPTIONAL, &wrVisible); |
| 1812 SetCaretInfo(); |
| 1813 } |
| 1814 } |
| 1815 |
| 1816 void CFX_Edit::SelectNone() { |
| 1817 if (m_pVT->IsValid()) { |
| 1818 if (m_SelState.IsExist()) { |
| 1819 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); |
| 1820 m_SelState.Default(); |
| 1821 Refresh(RP_OPTIONAL, &wrTemp); |
| 1822 } |
| 1823 } |
| 1824 } |
| 1825 |
| 1826 FX_BOOL CFX_Edit::IsSelected() const { |
| 1827 return m_SelState.IsExist(); |
| 1828 } |
| 1829 |
| 1830 CPDF_Point CFX_Edit::VTToEdit(const CPDF_Point& point) const { |
| 1831 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 1832 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 1833 |
| 1834 FX_FLOAT fPadding = 0.0f; |
| 1835 |
| 1836 switch (m_nAlignment) { |
| 1837 case 0: |
| 1838 fPadding = 0.0f; |
| 1839 break; |
| 1840 case 1: |
| 1841 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1842 break; |
| 1843 case 2: |
| 1844 fPadding = rcPlate.Height() - rcContent.Height(); |
| 1845 break; |
| 1846 } |
| 1847 |
| 1848 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left), |
| 1849 point.y - (m_ptScrollPos.y + fPadding - rcPlate.top)); |
| 1850 } |
| 1851 |
| 1852 CPDF_Point CFX_Edit::EditToVT(const CPDF_Point& point) const { |
| 1853 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 1854 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 1855 |
| 1856 FX_FLOAT fPadding = 0.0f; |
| 1857 |
| 1858 switch (m_nAlignment) { |
| 1859 case 0: |
| 1860 fPadding = 0.0f; |
| 1861 break; |
| 1862 case 1: |
| 1863 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; |
| 1864 break; |
| 1865 case 2: |
| 1866 fPadding = rcPlate.Height() - rcContent.Height(); |
| 1867 break; |
| 1868 } |
| 1869 |
| 1870 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left), |
| 1871 point.y + (m_ptScrollPos.y + fPadding - rcPlate.top)); |
| 1872 } |
| 1873 |
| 1874 CPDF_Rect CFX_Edit::VTToEdit(const CPDF_Rect& rect) const { |
| 1875 CPDF_Point ptLeftBottom = VTToEdit(CPDF_Point(rect.left, rect.bottom)); |
| 1876 CPDF_Point ptRightTop = VTToEdit(CPDF_Point(rect.right, rect.top)); |
| 1877 |
| 1878 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y); |
| 1879 } |
| 1880 |
| 1881 CPDF_Rect CFX_Edit::EditToVT(const CPDF_Rect& rect) const { |
| 1882 CPDF_Point ptLeftBottom = EditToVT(CPDF_Point(rect.left, rect.bottom)); |
| 1883 CPDF_Point ptRightTop = EditToVT(CPDF_Point(rect.right, rect.top)); |
| 1884 |
| 1885 return CPDF_Rect(ptLeftBottom.x, ptLeftBottom.y, ptRightTop.x, ptRightTop.y); |
| 1886 } |
| 1887 |
| 1888 void CFX_Edit::SetScrollInfo() { |
| 1889 if (m_bNotify && m_pNotify) { |
| 1890 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 1891 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 1892 |
| 1893 if (!m_bNotifyFlag) { |
| 1894 m_bNotifyFlag = TRUE; |
| 1895 m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, rcContent.left, |
| 1896 rcContent.right, rcPlate.Width() / 3, |
| 1897 rcPlate.Width()); |
| 1898 |
| 1899 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, |
| 1900 rcContent.bottom, rcContent.top, |
| 1901 rcPlate.Height() / 3, rcPlate.Height()); |
| 1902 m_bNotifyFlag = FALSE; |
| 1903 } |
| 1904 } |
| 1905 } |
| 1906 |
| 1907 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) { |
| 1908 if (!m_bEnableScroll) |
| 1909 return; |
| 1910 |
| 1911 if (m_pVT->IsValid()) { |
| 1912 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x, fx)) { |
| 1913 m_ptScrollPos.x = fx; |
| 1914 Refresh(RP_NOANALYSE); |
| 1915 |
| 1916 if (m_bNotify && m_pNotify) { |
| 1917 if (!m_bNotifyFlag) { |
| 1918 m_bNotifyFlag = TRUE; |
| 1919 m_pNotify->IOnSetScrollPosX(fx); |
| 1920 m_bNotifyFlag = FALSE; |
| 2047 } | 1921 } |
| 2048 } | 1922 } |
| 2049 } | 1923 } |
| 2050 | 1924 } |
| 2051 void CFX_Edit::SelectAll() | 1925 } |
| 2052 { | 1926 |
| 2053 if (m_pVT->IsValid()) | 1927 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) { |
| 2054 { | 1928 if (!m_bEnableScroll) |
| 2055 m_SelState = GetWholeWordRange(); | 1929 return; |
| 2056 SetCaret(m_SelState.EndPos); | 1930 |
| 2057 | 1931 if (m_pVT->IsValid()) { |
| 2058 ScrollToCaret(); | 1932 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y, fy)) { |
| 2059 CPVT_WordRange wrVisible = GetVisibleWordRange(); | 1933 m_ptScrollPos.y = fy; |
| 2060 Refresh(RP_OPTIONAL,&wrVisible); | 1934 Refresh(RP_NOANALYSE); |
| 2061 SetCaretInfo(); | 1935 |
| 2062 } | 1936 if (m_bNotify && m_pNotify) { |
| 2063 } | 1937 if (!m_bNotifyFlag) { |
| 2064 | 1938 m_bNotifyFlag = TRUE; |
| 2065 void CFX_Edit::SelectNone() | 1939 m_pNotify->IOnSetScrollPosY(fy); |
| 2066 { | 1940 m_bNotifyFlag = FALSE; |
| 2067 if (m_pVT->IsValid()) | |
| 2068 { | |
| 2069 if (m_SelState.IsExist()) | |
| 2070 { | |
| 2071 CPVT_WordRange wrTemp = m_SelState.ConvertToWordRange(); | |
| 2072 m_SelState.Default(); | |
| 2073 Refresh(RP_OPTIONAL,&wrTemp); | |
| 2074 } | 1941 } |
| 2075 } | 1942 } |
| 2076 } | 1943 } |
| 2077 | 1944 } |
| 2078 FX_BOOL CFX_Edit::IsSelected() const | 1945 } |
| 2079 { | 1946 |
| 2080 return m_SelState.IsExist(); | 1947 void CFX_Edit::SetScrollPos(const CPDF_Point& point) { |
| 2081 } | 1948 SetScrollPosX(point.x); |
| 2082 | 1949 SetScrollPosY(point.y); |
| 2083 CPDF_Point CFX_Edit::VTToEdit(const CPDF_Point & point) const | 1950 SetScrollLimit(); |
| 2084 { | 1951 SetCaretInfo(); |
| 1952 } |
| 1953 |
| 1954 CPDF_Point CFX_Edit::GetScrollPos() const { |
| 1955 return m_ptScrollPos; |
| 1956 } |
| 1957 |
| 1958 void CFX_Edit::SetScrollLimit() { |
| 1959 if (m_pVT->IsValid()) { |
| 2085 CPDF_Rect rcContent = m_pVT->GetContentRect(); | 1960 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 2086 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | 1961 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 2087 | 1962 |
| 2088 FX_FLOAT fPadding = 0.0f; | 1963 if (rcPlate.Width() > rcContent.Width()) { |
| 2089 | 1964 SetScrollPosX(rcPlate.left); |
| 2090 switch (m_nAlignment) | 1965 } else { |
| 2091 { | 1966 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left)) { |
| 2092 case 0: | 1967 SetScrollPosX(rcContent.left); |
| 2093 fPadding = 0.0f; | 1968 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x, |
| 1969 rcContent.right - rcPlate.Width())) { |
| 1970 SetScrollPosX(rcContent.right - rcPlate.Width()); |
| 1971 } |
| 1972 } |
| 1973 |
| 1974 if (rcPlate.Height() > rcContent.Height()) { |
| 1975 SetScrollPosY(rcPlate.top); |
| 1976 } else { |
| 1977 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y, |
| 1978 rcContent.bottom + rcPlate.Height())) { |
| 1979 SetScrollPosY(rcContent.bottom + rcPlate.Height()); |
| 1980 } else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) { |
| 1981 SetScrollPosY(rcContent.top); |
| 1982 } |
| 1983 } |
| 1984 } |
| 1985 } |
| 1986 |
| 1987 void CFX_Edit::ScrollToCaret() { |
| 1988 SetScrollLimit(); |
| 1989 |
| 1990 if (m_pVT->IsValid()) { |
| 1991 CPDF_Point ptHead(0, 0); |
| 1992 CPDF_Point ptFoot(0, 0); |
| 1993 |
| 1994 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 1995 pIterator->SetAt(m_wpCaret); |
| 1996 |
| 1997 CPVT_Word word; |
| 1998 CPVT_Line line; |
| 1999 if (pIterator->GetWord(word)) { |
| 2000 ptHead.x = word.ptWord.x + word.fWidth; |
| 2001 ptHead.y = word.ptWord.y + word.fAscent; |
| 2002 ptFoot.x = word.ptWord.x + word.fWidth; |
| 2003 ptFoot.y = word.ptWord.y + word.fDescent; |
| 2004 } else if (pIterator->GetLine(line)) { |
| 2005 ptHead.x = line.ptLine.x; |
| 2006 ptHead.y = line.ptLine.y + line.fLineAscent; |
| 2007 ptFoot.x = line.ptLine.x; |
| 2008 ptFoot.y = line.ptLine.y + line.fLineDescent; |
| 2009 } |
| 2010 } |
| 2011 |
| 2012 CPDF_Point ptHeadEdit = VTToEdit(ptHead); |
| 2013 CPDF_Point ptFootEdit = VTToEdit(ptFoot); |
| 2014 |
| 2015 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 2016 |
| 2017 if (!FX_EDIT_IsFloatEqual(rcPlate.left, rcPlate.right)) { |
| 2018 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || |
| 2019 FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) { |
| 2020 SetScrollPosX(ptHead.x); |
| 2021 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) { |
| 2022 SetScrollPosX(ptHead.x - rcPlate.Width()); |
| 2023 } |
| 2024 } |
| 2025 |
| 2026 if (!FX_EDIT_IsFloatEqual(rcPlate.top, rcPlate.bottom)) { |
| 2027 if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || |
| 2028 FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) { |
| 2029 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) { |
| 2030 SetScrollPosY(ptFoot.y + rcPlate.Height()); |
| 2031 } |
| 2032 } else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) { |
| 2033 if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) { |
| 2034 SetScrollPosY(ptHead.y); |
| 2035 } |
| 2036 } |
| 2037 } |
| 2038 } |
| 2039 } |
| 2040 |
| 2041 void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan, |
| 2042 const CPVT_WordRange* pRange1, |
| 2043 const CPVT_WordRange* pRange2) { |
| 2044 if (m_bEnableRefresh && m_pVT->IsValid()) { |
| 2045 m_Refresh.BeginRefresh(); |
| 2046 RefreshPushLineRects(GetVisibleWordRange()); |
| 2047 |
| 2048 // if (!FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.x,m_ptScrollPos.x) || |
| 2049 // !FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.y,m_ptScrollPos.y)) |
| 2050 // { |
| 2051 m_Refresh.NoAnalyse(); |
| 2052 m_ptRefreshScrollPos = m_ptScrollPos; |
| 2053 // } |
| 2054 // else |
| 2055 // { |
| 2056 // switch (ePlan) |
| 2057 // { |
| 2058 // case RP_ANALYSE: |
| 2059 // m_Refresh.Analyse(m_pVT->GetAlignment()); |
| 2060 // |
| 2061 // if (pRange1) RefreshPushRandomRects(*pRange1); |
| 2062 // if (pRange2) RefreshPushRandomRects(*pRange2); |
| 2063 // break; |
| 2064 // case RP_NOANALYSE: |
| 2065 // m_Refresh.NoAnalyse(); |
| 2066 // break; |
| 2067 // case RP_OPTIONAL: |
| 2068 // if (pRange1) RefreshPushRandomRects(*pRange1); |
| 2069 // if (pRange2) RefreshPushRandomRects(*pRange2); |
| 2070 // break; |
| 2071 // } |
| 2072 // } |
| 2073 |
| 2074 if (m_bNotify && m_pNotify) { |
| 2075 if (!m_bNotifyFlag) { |
| 2076 m_bNotifyFlag = TRUE; |
| 2077 if (const CFX_Edit_RectArray* pRects = m_Refresh.GetRefreshRects()) { |
| 2078 for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++) |
| 2079 m_pNotify->IOnInvalidateRect(pRects->GetAt(i)); |
| 2080 } |
| 2081 m_bNotifyFlag = FALSE; |
| 2082 } |
| 2083 } |
| 2084 |
| 2085 m_Refresh.EndRefresh(); |
| 2086 } |
| 2087 } |
| 2088 |
| 2089 void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange& wr) { |
| 2090 if (m_pVT->IsValid()) { |
| 2091 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2092 CPVT_WordPlace wpBegin = wr.BeginPos; |
| 2093 m_pVT->UpdateWordPlace(wpBegin); |
| 2094 CPVT_WordPlace wpEnd = wr.EndPos; |
| 2095 m_pVT->UpdateWordPlace(wpEnd); |
| 2096 pIterator->SetAt(wpBegin); |
| 2097 |
| 2098 CPVT_Line lineinfo; |
| 2099 do { |
| 2100 if (!pIterator->GetLine(lineinfo)) |
| 2101 break; |
| 2102 if (lineinfo.lineplace.LineCmp(wpEnd) > 0) |
| 2103 break; |
| 2104 |
| 2105 CPDF_Rect rcLine(lineinfo.ptLine.x, |
| 2106 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2107 lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2108 lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2109 |
| 2110 m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace, lineinfo.lineEnd), |
| 2111 VTToEdit(rcLine)); |
| 2112 |
| 2113 } while (pIterator->NextLine()); |
| 2114 } |
| 2115 } |
| 2116 } |
| 2117 |
| 2118 void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange& wr) { |
| 2119 if (m_pVT->IsValid()) { |
| 2120 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2121 CPVT_WordRange wrTemp = wr; |
| 2122 |
| 2123 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 2124 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 2125 pIterator->SetAt(wrTemp.BeginPos); |
| 2126 |
| 2127 CPVT_Word wordinfo; |
| 2128 CPVT_Line lineinfo; |
| 2129 CPVT_WordPlace place; |
| 2130 |
| 2131 while (pIterator->NextWord()) { |
| 2132 place = pIterator->GetAt(); |
| 2133 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 2134 break; |
| 2135 |
| 2136 pIterator->GetWord(wordinfo); |
| 2137 pIterator->GetLine(lineinfo); |
| 2138 |
| 2139 if (place.LineCmp(wrTemp.BeginPos) == 0 || |
| 2140 place.LineCmp(wrTemp.EndPos) == 0) { |
| 2141 CPDF_Rect rcWord(wordinfo.ptWord.x, |
| 2142 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2143 wordinfo.ptWord.x + wordinfo.fWidth, |
| 2144 lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2145 |
| 2146 m_Refresh.AddRefresh(VTToEdit(rcWord)); |
| 2147 } else { |
| 2148 CPDF_Rect rcLine(lineinfo.ptLine.x, |
| 2149 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2150 lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2151 lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2152 |
| 2153 m_Refresh.AddRefresh(VTToEdit(rcLine)); |
| 2154 |
| 2155 pIterator->NextLine(); |
| 2156 } |
| 2157 } |
| 2158 } |
| 2159 } |
| 2160 } |
| 2161 |
| 2162 void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) { |
| 2163 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2164 CPVT_WordRange wrTemp = wr; |
| 2165 |
| 2166 m_pVT->UpdateWordPlace(wrTemp.BeginPos); |
| 2167 m_pVT->UpdateWordPlace(wrTemp.EndPos); |
| 2168 pIterator->SetAt(wrTemp.BeginPos); |
| 2169 |
| 2170 CPVT_Word wordinfo; |
| 2171 CPVT_Line lineinfo; |
| 2172 CPVT_WordPlace place; |
| 2173 |
| 2174 while (pIterator->NextWord()) { |
| 2175 place = pIterator->GetAt(); |
| 2176 if (place.WordCmp(wrTemp.EndPos) > 0) |
| 2094 break; | 2177 break; |
| 2095 case 1: | 2178 |
| 2096 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; | 2179 pIterator->GetWord(wordinfo); |
| 2097 break; | 2180 pIterator->GetLine(lineinfo); |
| 2098 case 2: | 2181 |
| 2099 fPadding = rcPlate.Height() - rcContent.Height(); | 2182 if (place.LineCmp(wrTemp.BeginPos) == 0 || |
| 2100 break; | 2183 place.LineCmp(wrTemp.EndPos) == 0) { |
| 2101 } | 2184 CPDF_Rect rcWord(wordinfo.ptWord.x, |
| 2102 | 2185 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2103 return CPDF_Point(point.x - (m_ptScrollPos.x - rcPlate.left), | 2186 wordinfo.ptWord.x + wordinfo.fWidth, |
| 2104 point.y - (m_ptScrollPos.y + fPadding - rcPlate.top)); | 2187 lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2105 } | 2188 |
| 2106 | 2189 if (m_bNotify && m_pNotify) { |
| 2107 CPDF_Point CFX_Edit::EditToVT(const CPDF_Point & point) const | 2190 if (!m_bNotifyFlag) { |
| 2108 { | |
| 2109 CPDF_Rect rcContent = m_pVT->GetContentRect(); | |
| 2110 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | |
| 2111 | |
| 2112 FX_FLOAT fPadding = 0.0f; | |
| 2113 | |
| 2114 switch (m_nAlignment) | |
| 2115 { | |
| 2116 case 0: | |
| 2117 fPadding = 0.0f; | |
| 2118 break; | |
| 2119 case 1: | |
| 2120 fPadding = (rcPlate.Height() - rcContent.Height()) * 0.5f; | |
| 2121 break; | |
| 2122 case 2: | |
| 2123 fPadding = rcPlate.Height() - rcContent.Height(); | |
| 2124 break; | |
| 2125 } | |
| 2126 | |
| 2127 return CPDF_Point(point.x + (m_ptScrollPos.x - rcPlate.left), | |
| 2128 point.y + (m_ptScrollPos.y + fPadding - rcPlate.top)); | |
| 2129 } | |
| 2130 | |
| 2131 CPDF_Rect CFX_Edit::VTToEdit(const CPDF_Rect & rect) const | |
| 2132 { | |
| 2133 CPDF_Point ptLeftBottom = VTToEdit(CPDF_Point(rect.left,rect.bottom)); | |
| 2134 CPDF_Point ptRightTop = VTToEdit(CPDF_Point(rect.right,rect.top)); | |
| 2135 | |
| 2136 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y); | |
| 2137 } | |
| 2138 | |
| 2139 CPDF_Rect CFX_Edit::EditToVT(const CPDF_Rect & rect) const | |
| 2140 { | |
| 2141 CPDF_Point ptLeftBottom = EditToVT(CPDF_Point(rect.left,rect.bottom)); | |
| 2142 CPDF_Point ptRightTop = EditToVT(CPDF_Point(rect.right,rect.top)); | |
| 2143 | |
| 2144 return CPDF_Rect(ptLeftBottom.x,ptLeftBottom.y,ptRightTop.x,ptRightTop.y); | |
| 2145 } | |
| 2146 | |
| 2147 void CFX_Edit::SetScrollInfo() | |
| 2148 { | |
| 2149 if (m_bNotify && m_pNotify) | |
| 2150 { | |
| 2151 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | |
| 2152 CPDF_Rect rcContent = m_pVT->GetContentRect(); | |
| 2153 | |
| 2154 if (!m_bNotifyFlag) | |
| 2155 { | |
| 2156 m_bNotifyFlag = TRUE; | 2191 m_bNotifyFlag = TRUE; |
| 2157 m_pNotify->IOnSetScrollInfoX(rcPlate.left, rcPlate.right, | 2192 CPDF_Rect rcRefresh = VTToEdit(rcWord); |
| 2158 rcContent.left, rcContent.right, rcPlate.Width()
/ 3, rcPlate.Width()); | 2193 m_pNotify->IOnInvalidateRect(&rcRefresh); |
| 2159 | |
| 2160 m_pNotify->IOnSetScrollInfoY(rcPlate.bottom, rcPlate.top, | |
| 2161 rcContent.bottom, rcContent.top, rcPlate.Height() / 3, rcPla
te.Height()); | |
| 2162 m_bNotifyFlag = FALSE; | 2194 m_bNotifyFlag = FALSE; |
| 2195 } |
| 2163 } | 2196 } |
| 2164 } | 2197 } else { |
| 2165 } | 2198 CPDF_Rect rcLine(lineinfo.ptLine.x, |
| 2166 | 2199 lineinfo.ptLine.y + lineinfo.fLineDescent, |
| 2167 void CFX_Edit::SetScrollPosX(FX_FLOAT fx) | 2200 lineinfo.ptLine.x + lineinfo.fLineWidth, |
| 2168 { | 2201 lineinfo.ptLine.y + lineinfo.fLineAscent); |
| 2169 if (!m_bEnableScroll) return; | 2202 |
| 2170 | 2203 if (m_bNotify && m_pNotify) { |
| 2171 if (m_pVT->IsValid()) | 2204 if (!m_bNotifyFlag) { |
| 2172 { | 2205 m_bNotifyFlag = TRUE; |
| 2173 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.x,fx)) | 2206 CPDF_Rect rcRefresh = VTToEdit(rcLine); |
| 2174 { | 2207 m_pNotify->IOnInvalidateRect(&rcRefresh); |
| 2175 m_ptScrollPos.x = fx; | 2208 m_bNotifyFlag = FALSE; |
| 2176 Refresh(RP_NOANALYSE); | 2209 } |
| 2177 | |
| 2178 if (m_bNotify && m_pNotify) | |
| 2179 { | |
| 2180 if (!m_bNotifyFlag) | |
| 2181 { | |
| 2182 m_bNotifyFlag = TRUE; | |
| 2183 m_pNotify->IOnSetScrollPosX(fx); | |
| 2184 m_bNotifyFlag = FALSE; | |
| 2185 } | |
| 2186 } | |
| 2187 } | 2210 } |
| 2188 } | 2211 |
| 2189 } | 2212 pIterator->NextLine(); |
| 2190 | 2213 } |
| 2191 void CFX_Edit::SetScrollPosY(FX_FLOAT fy) | 2214 } |
| 2192 { | 2215 } |
| 2193 if (!m_bEnableScroll) return; | 2216 } |
| 2194 | 2217 |
| 2195 if (m_pVT->IsValid()) | 2218 void CFX_Edit::SetCaret(const CPVT_WordPlace& place) { |
| 2196 { | 2219 m_wpOldCaret = m_wpCaret; |
| 2197 if (!FX_EDIT_IsFloatEqual(m_ptScrollPos.y,fy)) | 2220 m_wpCaret = place; |
| 2198 { | 2221 } |
| 2199 m_ptScrollPos.y = fy; | 2222 |
| 2200 Refresh(RP_NOANALYSE); | 2223 void CFX_Edit::SetCaretInfo() { |
| 2201 | 2224 if (m_bNotify && m_pNotify) { |
| 2202 if (m_bNotify && m_pNotify) | 2225 if (!m_bNotifyFlag) { |
| 2203 { | 2226 CPDF_Point ptHead(0.0f, 0.0f), ptFoot(0.0f, 0.0f); |
| 2204 if (!m_bNotifyFlag) | 2227 |
| 2205 { | 2228 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2206 m_bNotifyFlag = TRUE; | 2229 pIterator->SetAt(m_wpCaret); |
| 2207 m_pNotify->IOnSetScrollPosY(fy); | 2230 CPVT_Word word; |
| 2208 m_bNotifyFlag = FALSE; | 2231 CPVT_Line line; |
| 2209 } | 2232 if (pIterator->GetWord(word)) { |
| 2210 } | 2233 ptHead.x = word.ptWord.x + word.fWidth; |
| 2234 ptHead.y = word.ptWord.y + word.fAscent; |
| 2235 ptFoot.x = word.ptWord.x + word.fWidth; |
| 2236 ptFoot.y = word.ptWord.y + word.fDescent; |
| 2237 } else if (pIterator->GetLine(line)) { |
| 2238 ptHead.x = line.ptLine.x; |
| 2239 ptHead.y = line.ptLine.y + line.fLineAscent; |
| 2240 ptFoot.x = line.ptLine.x; |
| 2241 ptFoot.y = line.ptLine.y + line.fLineDescent; |
| 2211 } | 2242 } |
| 2212 } | 2243 } |
| 2213 } | 2244 |
| 2214 | 2245 m_bNotifyFlag = TRUE; |
| 2215 void CFX_Edit::SetScrollPos(const CPDF_Point & point) | 2246 m_pNotify->IOnSetCaret(!m_SelState.IsExist(), VTToEdit(ptHead), |
| 2216 { | 2247 VTToEdit(ptFoot), m_wpCaret); |
| 2217 SetScrollPosX(point.x); | 2248 m_bNotifyFlag = FALSE; |
| 2218 SetScrollPosY(point.y); | 2249 } |
| 2219 SetScrollLimit(); | 2250 } |
| 2251 |
| 2252 SetCaretChange(); |
| 2253 } |
| 2254 |
| 2255 void CFX_Edit::SetCaretChange() { |
| 2256 if (m_wpCaret == m_wpOldCaret) |
| 2257 return; |
| 2258 |
| 2259 if (m_bNotify && m_pVT->IsRichText() && m_pNotify) { |
| 2260 CPVT_SecProps SecProps; |
| 2261 CPVT_WordProps WordProps; |
| 2262 |
| 2263 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2264 pIterator->SetAt(m_wpCaret); |
| 2265 CPVT_Word word; |
| 2266 CPVT_Section section; |
| 2267 |
| 2268 if (pIterator->GetSection(section)) { |
| 2269 SecProps = section.SecProps; |
| 2270 WordProps = section.WordProps; |
| 2271 } |
| 2272 |
| 2273 if (pIterator->GetWord(word)) { |
| 2274 WordProps = word.WordProps; |
| 2275 } |
| 2276 } |
| 2277 |
| 2278 if (!m_bNotifyFlag) { |
| 2279 m_bNotifyFlag = TRUE; |
| 2280 m_pNotify->IOnCaretChange(SecProps, WordProps); |
| 2281 m_bNotifyFlag = FALSE; |
| 2282 } |
| 2283 } |
| 2284 } |
| 2285 |
| 2286 void CFX_Edit::SetCaret(int32_t nPos) { |
| 2287 if (m_pVT->IsValid()) { |
| 2288 SelectNone(); |
| 2289 SetCaret(m_pVT->WordIndexToWordPlace(nPos)); |
| 2290 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2291 |
| 2292 ScrollToCaret(); |
| 2293 SetCaretOrigin(); |
| 2220 SetCaretInfo(); | 2294 SetCaretInfo(); |
| 2221 } | 2295 } |
| 2222 | 2296 } |
| 2223 CPDF_Point CFX_Edit::GetScrollPos() const | 2297 |
| 2224 { | 2298 void CFX_Edit::OnMouseDown(const CPDF_Point& point, |
| 2225 return m_ptScrollPos; | 2299 FX_BOOL bShift, |
| 2226 } | 2300 FX_BOOL bCtrl) { |
| 2227 | 2301 if (m_pVT->IsValid()) { |
| 2228 void CFX_Edit::SetScrollLimit() | 2302 SelectNone(); |
| 2229 { | 2303 SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 2230 if (m_pVT->IsValid()) | 2304 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2231 { | 2305 |
| 2232 CPDF_Rect rcContent = m_pVT->GetContentRect(); | 2306 ScrollToCaret(); |
| 2233 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | 2307 SetCaretOrigin(); |
| 2234 | 2308 SetCaretInfo(); |
| 2235 if (rcPlate.Width() > rcContent.Width()) | 2309 } |
| 2236 { | 2310 } |
| 2237 SetScrollPosX(rcPlate.left); | 2311 |
| 2238 } | 2312 void CFX_Edit::OnMouseMove(const CPDF_Point& point, |
| 2313 FX_BOOL bShift, |
| 2314 FX_BOOL bCtrl) { |
| 2315 if (m_pVT->IsValid()) { |
| 2316 SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); |
| 2317 |
| 2318 if (m_wpCaret != m_wpOldCaret) { |
| 2319 m_SelState.SetEndPos(m_wpCaret); |
| 2320 |
| 2321 ScrollToCaret(); |
| 2322 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2323 Refresh(RP_OPTIONAL, &wr); |
| 2324 SetCaretOrigin(); |
| 2325 SetCaretInfo(); |
| 2326 } |
| 2327 } |
| 2328 } |
| 2329 |
| 2330 void CFX_Edit::OnVK_UP(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2331 if (m_pVT->IsValid()) { |
| 2332 SetCaret(m_pVT->GetUpWordPlace(m_wpCaret, m_ptCaret)); |
| 2333 |
| 2334 if (bShift) { |
| 2335 if (m_SelState.IsExist()) |
| 2336 m_SelState.SetEndPos(m_wpCaret); |
| 2337 else |
| 2338 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2339 |
| 2340 if (m_wpOldCaret != m_wpCaret) { |
| 2341 ScrollToCaret(); |
| 2342 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2343 Refresh(RP_OPTIONAL, &wr); |
| 2344 SetCaretInfo(); |
| 2345 } |
| 2346 } else { |
| 2347 SelectNone(); |
| 2348 |
| 2349 ScrollToCaret(); |
| 2350 SetCaretInfo(); |
| 2351 } |
| 2352 } |
| 2353 } |
| 2354 |
| 2355 void CFX_Edit::OnVK_DOWN(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2356 if (m_pVT->IsValid()) { |
| 2357 SetCaret(m_pVT->GetDownWordPlace(m_wpCaret, m_ptCaret)); |
| 2358 |
| 2359 if (bShift) { |
| 2360 if (m_SelState.IsExist()) |
| 2361 m_SelState.SetEndPos(m_wpCaret); |
| 2362 else |
| 2363 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2364 |
| 2365 if (m_wpOldCaret != m_wpCaret) { |
| 2366 ScrollToCaret(); |
| 2367 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2368 Refresh(RP_OPTIONAL, &wr); |
| 2369 SetCaretInfo(); |
| 2370 } |
| 2371 } else { |
| 2372 SelectNone(); |
| 2373 |
| 2374 ScrollToCaret(); |
| 2375 SetCaretInfo(); |
| 2376 } |
| 2377 } |
| 2378 } |
| 2379 |
| 2380 void CFX_Edit::OnVK_LEFT(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2381 if (m_pVT->IsValid()) { |
| 2382 if (bShift) { |
| 2383 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 2384 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) |
| 2385 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2386 |
| 2387 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2388 |
| 2389 if (m_SelState.IsExist()) |
| 2390 m_SelState.SetEndPos(m_wpCaret); |
| 2391 else |
| 2392 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2393 |
| 2394 if (m_wpOldCaret != m_wpCaret) { |
| 2395 ScrollToCaret(); |
| 2396 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2397 Refresh(RP_OPTIONAL, &wr); |
| 2398 SetCaretInfo(); |
| 2399 } |
| 2400 } else { |
| 2401 if (m_SelState.IsExist()) { |
| 2402 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) |
| 2403 SetCaret(m_SelState.BeginPos); |
| 2239 else | 2404 else |
| 2240 { | 2405 SetCaret(m_SelState.EndPos); |
| 2241 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.x, rcContent.left)) | 2406 |
| 2242 { | |
| 2243 SetScrollPosX(rcContent.left); | |
| 2244 } | |
| 2245 else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.x, rcContent.right - rc
Plate.Width())) | |
| 2246 { | |
| 2247 SetScrollPosX(rcContent.right - rcPlate.Width()); | |
| 2248 } | |
| 2249 } | |
| 2250 | |
| 2251 if (rcPlate.Height() > rcContent.Height()) | |
| 2252 { | |
| 2253 SetScrollPosY(rcPlate.top); | |
| 2254 } | |
| 2255 else | |
| 2256 { | |
| 2257 if (FX_EDIT_IsFloatSmaller(m_ptScrollPos.y, rcContent.bottom + rcPla
te.Height())) | |
| 2258 { | |
| 2259 SetScrollPosY(rcContent.bottom + rcPlate.Height()); | |
| 2260 } | |
| 2261 else if (FX_EDIT_IsFloatBigger(m_ptScrollPos.y, rcContent.top)) | |
| 2262 { | |
| 2263 SetScrollPosY(rcContent.top); | |
| 2264 } | |
| 2265 } | |
| 2266 } | |
| 2267 } | |
| 2268 | |
| 2269 void CFX_Edit::ScrollToCaret() | |
| 2270 { | |
| 2271 SetScrollLimit(); | |
| 2272 | |
| 2273 if (m_pVT->IsValid()) | |
| 2274 { | |
| 2275 CPDF_Point ptHead(0,0); | |
| 2276 CPDF_Point ptFoot(0,0); | |
| 2277 | |
| 2278 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2279 { | |
| 2280 pIterator->SetAt(m_wpCaret); | |
| 2281 | |
| 2282 CPVT_Word word; | |
| 2283 CPVT_Line line; | |
| 2284 if (pIterator->GetWord(word)) | |
| 2285 { | |
| 2286 ptHead.x = word.ptWord.x + word.fWidth; | |
| 2287 ptHead.y = word.ptWord.y + word.fAscent; | |
| 2288 ptFoot.x = word.ptWord.x + word.fWidth; | |
| 2289 ptFoot.y = word.ptWord.y + word.fDescent; | |
| 2290 } | |
| 2291 else if (pIterator->GetLine(line)) | |
| 2292 { | |
| 2293 ptHead.x = line.ptLine.x; | |
| 2294 ptHead.y = line.ptLine.y + line.fLineAscent; | |
| 2295 ptFoot.x = line.ptLine.x; | |
| 2296 ptFoot.y = line.ptLine.y + line.fLineDescent; | |
| 2297 } | |
| 2298 } | |
| 2299 | |
| 2300 CPDF_Point ptHeadEdit = VTToEdit(ptHead); | |
| 2301 CPDF_Point ptFootEdit = VTToEdit(ptFoot); | |
| 2302 | |
| 2303 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | |
| 2304 | |
| 2305 if (!FX_EDIT_IsFloatEqual(rcPlate.left,rcPlate.right)) | |
| 2306 { | |
| 2307 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.x, rcPlate.left) || | |
| 2308 FX_EDIT_IsFloatEqual(ptHeadEdit.x, rcPlate.left)) | |
| 2309 { | |
| 2310 SetScrollPosX(ptHead.x); | |
| 2311 } | |
| 2312 else if (FX_EDIT_IsFloatBigger(ptHeadEdit.x, rcPlate.right)) | |
| 2313 { | |
| 2314 SetScrollPosX(ptHead.x - rcPlate.Width()); | |
| 2315 } | |
| 2316 } | |
| 2317 | |
| 2318 if (!FX_EDIT_IsFloatEqual(rcPlate.top,rcPlate.bottom)) | |
| 2319 { | |
| 2320 if (FX_EDIT_IsFloatSmaller(ptFootEdit.y, rcPlate.bottom) || | |
| 2321 FX_EDIT_IsFloatEqual(ptFootEdit.y, rcPlate.bottom)) | |
| 2322 { | |
| 2323 if (FX_EDIT_IsFloatSmaller(ptHeadEdit.y, rcPlate.top)) | |
| 2324 { | |
| 2325 SetScrollPosY(ptFoot.y + rcPlate.Height()); | |
| 2326 } | |
| 2327 } | |
| 2328 else if (FX_EDIT_IsFloatBigger(ptHeadEdit.y, rcPlate.top)) | |
| 2329 { | |
| 2330 if (FX_EDIT_IsFloatBigger(ptFootEdit.y, rcPlate.bottom)) | |
| 2331 { | |
| 2332 SetScrollPosY(ptHead.y); | |
| 2333 } | |
| 2334 } | |
| 2335 } | |
| 2336 } | |
| 2337 } | |
| 2338 | |
| 2339 void CFX_Edit::Refresh(REFRESH_PLAN_E ePlan,const CPVT_WordRange * pRange1,const
CPVT_WordRange * pRange2) | |
| 2340 { | |
| 2341 if (m_bEnableRefresh && m_pVT->IsValid()) | |
| 2342 { | |
| 2343 m_Refresh.BeginRefresh(); | |
| 2344 RefreshPushLineRects(GetVisibleWordRange()); | |
| 2345 | |
| 2346 // if (!FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.x,m_ptScrollPos.x) || | |
| 2347 // !FX_EDIT_IsFloatEqual(m_ptRefreshScrollPos.y,m_ptScrollPos.y)) | |
| 2348 // { | |
| 2349 m_Refresh.NoAnalyse(); | |
| 2350 m_ptRefreshScrollPos = m_ptScrollPos; | |
| 2351 // } | |
| 2352 // else | |
| 2353 // { | |
| 2354 // switch (ePlan) | |
| 2355 // { | |
| 2356 // case RP_ANALYSE: | |
| 2357 // m_Refresh.Analyse(m_pVT->GetAlignment()); | |
| 2358 // | |
| 2359 // if (pRange1) RefreshPushRandomRects(*pRange1); | |
| 2360 // if (pRange2) RefreshPushRandomRects(*pRange2); | |
| 2361 // break; | |
| 2362 // case RP_NOANALYSE: | |
| 2363 // m_Refresh.NoAnalyse(); | |
| 2364 // break; | |
| 2365 // case RP_OPTIONAL: | |
| 2366 // if (pRange1) RefreshPushRandomRects(*pRange1); | |
| 2367 // if (pRange2) RefreshPushRandomRects(*pRange2); | |
| 2368 // break; | |
| 2369 // } | |
| 2370 // } | |
| 2371 | |
| 2372 if (m_bNotify && m_pNotify) | |
| 2373 { | |
| 2374 if (!m_bNotifyFlag) | |
| 2375 { | |
| 2376 m_bNotifyFlag = TRUE; | |
| 2377 if (const CFX_Edit_RectArray * pRects = m_Refresh.GetRefreshRect
s()) | |
| 2378 { | |
| 2379 for (int32_t i = 0, sz = pRects->GetSize(); i < sz; i++) | |
| 2380 m_pNotify->IOnInvalidateRect(pRects->GetAt(i)); | |
| 2381 } | |
| 2382 m_bNotifyFlag = FALSE; | |
| 2383 } | |
| 2384 } | |
| 2385 | |
| 2386 m_Refresh.EndRefresh(); | |
| 2387 } | |
| 2388 } | |
| 2389 | |
| 2390 void CFX_Edit::RefreshPushLineRects(const CPVT_WordRange & wr) | |
| 2391 { | |
| 2392 if (m_pVT->IsValid()) | |
| 2393 { | |
| 2394 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2395 { | |
| 2396 CPVT_WordPlace wpBegin = wr.BeginPos; | |
| 2397 m_pVT->UpdateWordPlace(wpBegin); | |
| 2398 CPVT_WordPlace wpEnd = wr.EndPos; | |
| 2399 m_pVT->UpdateWordPlace(wpEnd); | |
| 2400 pIterator->SetAt(wpBegin); | |
| 2401 | |
| 2402 CPVT_Line lineinfo; | |
| 2403 do | |
| 2404 { | |
| 2405 if (!pIterator->GetLine(lineinfo))break; | |
| 2406 if (lineinfo.lineplace.LineCmp(wpEnd) > 0)break; | |
| 2407 | |
| 2408 CPDF_Rect rcLine(lineinfo.ptLine.x, | |
| 2409 lineinfo.ptLine.y + lineinfo.fLineDescent, | |
| 2410 lineinfo.ptLine.x + lineinfo.fLineWidth, | |
| 2411 lineinfo.ptLine.y + lineinfo.fLineAscent); | |
| 2412 | |
| 2413 m_Refresh.Push(CPVT_WordRange(lineinfo.lineplace,lineinfo.lineEn
d),VTToEdit(rcLine)); | |
| 2414 | |
| 2415 }while (pIterator->NextLine()); | |
| 2416 } | |
| 2417 } | |
| 2418 } | |
| 2419 | |
| 2420 void CFX_Edit::RefreshPushRandomRects(const CPVT_WordRange & wr) | |
| 2421 { | |
| 2422 if (m_pVT->IsValid()) | |
| 2423 { | |
| 2424 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2425 { | |
| 2426 CPVT_WordRange wrTemp = wr; | |
| 2427 | |
| 2428 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | |
| 2429 m_pVT->UpdateWordPlace(wrTemp.EndPos); | |
| 2430 pIterator->SetAt(wrTemp.BeginPos); | |
| 2431 | |
| 2432 CPVT_Word wordinfo; | |
| 2433 CPVT_Line lineinfo; | |
| 2434 CPVT_WordPlace place; | |
| 2435 | |
| 2436 while (pIterator->NextWord()) | |
| 2437 { | |
| 2438 place = pIterator->GetAt(); | |
| 2439 if (place.WordCmp(wrTemp.EndPos) > 0) break; | |
| 2440 | |
| 2441 pIterator->GetWord(wordinfo); | |
| 2442 pIterator->GetLine(lineinfo); | |
| 2443 | |
| 2444 if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.
EndPos) == 0) | |
| 2445 { | |
| 2446 CPDF_Rect rcWord(wordinfo.ptWord.x, | |
| 2447 lineinfo.ptLine.y + lineinfo.fLineDescen
t, | |
| 2448 wordinfo.ptWord.x + wordinfo.fWidth, | |
| 2449 lineinfo.ptLine.y + lineinfo.fLineAscent
); | |
| 2450 | |
| 2451 m_Refresh.AddRefresh(VTToEdit(rcWord)); | |
| 2452 } | |
| 2453 else | |
| 2454 { | |
| 2455 CPDF_Rect rcLine(lineinfo.ptLine.x, | |
| 2456 lineinfo.ptLine.y + lineinfo.fLineDescen
t, | |
| 2457 lineinfo.ptLine.x + lineinfo.fLineWidth, | |
| 2458 lineinfo.ptLine.y + lineinfo.fLineAscent
); | |
| 2459 | |
| 2460 m_Refresh.AddRefresh(VTToEdit(rcLine)); | |
| 2461 | |
| 2462 pIterator->NextLine(); | |
| 2463 } | |
| 2464 } | |
| 2465 } | |
| 2466 } | |
| 2467 } | |
| 2468 | |
| 2469 void CFX_Edit::RefreshWordRange(const CPVT_WordRange& wr) | |
| 2470 { | |
| 2471 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2472 { | |
| 2473 CPVT_WordRange wrTemp = wr; | |
| 2474 | |
| 2475 m_pVT->UpdateWordPlace(wrTemp.BeginPos); | |
| 2476 m_pVT->UpdateWordPlace(wrTemp.EndPos); | |
| 2477 pIterator->SetAt(wrTemp.BeginPos); | |
| 2478 | |
| 2479 CPVT_Word wordinfo; | |
| 2480 CPVT_Line lineinfo; | |
| 2481 CPVT_WordPlace place; | |
| 2482 | |
| 2483 while (pIterator->NextWord()) | |
| 2484 { | |
| 2485 place = pIterator->GetAt(); | |
| 2486 if (place.WordCmp(wrTemp.EndPos) > 0) break; | |
| 2487 | |
| 2488 pIterator->GetWord(wordinfo); | |
| 2489 pIterator->GetLine(lineinfo); | |
| 2490 | |
| 2491 if (place.LineCmp(wrTemp.BeginPos) == 0 || place.LineCmp(wrTemp.EndP
os) == 0) | |
| 2492 { | |
| 2493 CPDF_Rect rcWord(wordinfo.ptWord.x, | |
| 2494 lineinfo.ptLine.y + lineinfo.fLineDescent, | |
| 2495 wordinfo.ptWord.x + wordinfo.fWidth, | |
| 2496 lineinfo.ptLine.y + lineinfo.fLineAscent); | |
| 2497 | |
| 2498 if (m_bNotify && m_pNotify) | |
| 2499 { | |
| 2500 if (!m_bNotifyFlag) | |
| 2501 { | |
| 2502 m_bNotifyFlag = TRUE; | |
| 2503 CPDF_Rect rcRefresh = VTToEdit(rcWord); | |
| 2504 m_pNotify->IOnInvalidateRect(&rcRefresh); | |
| 2505 m_bNotifyFlag = FALSE; | |
| 2506 } | |
| 2507 } | |
| 2508 } | |
| 2509 else | |
| 2510 { | |
| 2511 CPDF_Rect rcLine(lineinfo.ptLine.x, | |
| 2512 lineinfo.ptLine.y + lineinfo.fLineDescent, | |
| 2513 lineinfo.ptLine.x + lineinfo.fLineWidth, | |
| 2514 lineinfo.ptLine.y + lineinfo.fLineAscent); | |
| 2515 | |
| 2516 if (m_bNotify && m_pNotify) | |
| 2517 { | |
| 2518 if (!m_bNotifyFlag) | |
| 2519 { | |
| 2520 m_bNotifyFlag = TRUE; | |
| 2521 CPDF_Rect rcRefresh = VTToEdit(rcLine); | |
| 2522 m_pNotify->IOnInvalidateRect(&rcRefresh); | |
| 2523 m_bNotifyFlag = FALSE; | |
| 2524 } | |
| 2525 } | |
| 2526 | |
| 2527 pIterator->NextLine(); | |
| 2528 } | |
| 2529 } | |
| 2530 } | |
| 2531 } | |
| 2532 | |
| 2533 void CFX_Edit::SetCaret(const CPVT_WordPlace & place) | |
| 2534 { | |
| 2535 m_wpOldCaret = m_wpCaret; | |
| 2536 m_wpCaret = place; | |
| 2537 } | |
| 2538 | |
| 2539 void CFX_Edit::SetCaretInfo() | |
| 2540 { | |
| 2541 if (m_bNotify && m_pNotify) | |
| 2542 { | |
| 2543 if (!m_bNotifyFlag) | |
| 2544 { | |
| 2545 CPDF_Point ptHead(0.0f,0.0f),ptFoot(0.0f,0.0f); | |
| 2546 | |
| 2547 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2548 { | |
| 2549 pIterator->SetAt(m_wpCaret); | |
| 2550 CPVT_Word word; | |
| 2551 CPVT_Line line; | |
| 2552 if (pIterator->GetWord(word)) | |
| 2553 { | |
| 2554 ptHead.x = word.ptWord.x + word.fWidth; | |
| 2555 ptHead.y = word.ptWord.y + word.fAscent; | |
| 2556 ptFoot.x = word.ptWord.x + word.fWidth; | |
| 2557 ptFoot.y = word.ptWord.y + word.fDescent; | |
| 2558 } | |
| 2559 else if (pIterator->GetLine(line)) | |
| 2560 { | |
| 2561 ptHead.x = line.ptLine.x; | |
| 2562 ptHead.y = line.ptLine.y + line.fLineAscent; | |
| 2563 ptFoot.x = line.ptLine.x; | |
| 2564 ptFoot.y = line.ptLine.y + line.fLineDescent; | |
| 2565 } | |
| 2566 } | |
| 2567 | |
| 2568 m_bNotifyFlag = TRUE; | |
| 2569 m_pNotify->IOnSetCaret(!m_SelState.IsExist(),VTToEdit(ptHead),VTToEd
it(ptFoot), m_wpCaret); | |
| 2570 m_bNotifyFlag = FALSE; | |
| 2571 } | |
| 2572 } | |
| 2573 | |
| 2574 SetCaretChange(); | |
| 2575 } | |
| 2576 | |
| 2577 void CFX_Edit::SetCaretChange() | |
| 2578 { | |
| 2579 if (m_wpCaret == m_wpOldCaret) return; | |
| 2580 | |
| 2581 if (m_bNotify && m_pVT->IsRichText() && m_pNotify) | |
| 2582 { | |
| 2583 CPVT_SecProps SecProps; | |
| 2584 CPVT_WordProps WordProps; | |
| 2585 | |
| 2586 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 2587 { | |
| 2588 pIterator->SetAt(m_wpCaret); | |
| 2589 CPVT_Word word; | |
| 2590 CPVT_Section section; | |
| 2591 | |
| 2592 if (pIterator->GetSection(section)) | |
| 2593 { | |
| 2594 SecProps = section.SecProps; | |
| 2595 WordProps = section.WordProps; | |
| 2596 } | |
| 2597 | |
| 2598 if (pIterator->GetWord(word)) | |
| 2599 { | |
| 2600 WordProps = word.WordProps; | |
| 2601 } | |
| 2602 } | |
| 2603 | |
| 2604 if (!m_bNotifyFlag) | |
| 2605 { | |
| 2606 m_bNotifyFlag = TRUE; | |
| 2607 m_pNotify->IOnCaretChange(SecProps,WordProps); | |
| 2608 m_bNotifyFlag = FALSE; | |
| 2609 } | |
| 2610 } | |
| 2611 } | |
| 2612 | |
| 2613 void CFX_Edit::SetCaret(int32_t nPos) | |
| 2614 { | |
| 2615 if (m_pVT->IsValid()) | |
| 2616 { | |
| 2617 SelectNone(); | 2407 SelectNone(); |
| 2618 SetCaret(m_pVT->WordIndexToWordPlace(nPos)); | 2408 ScrollToCaret(); |
| 2619 m_SelState.Set(m_wpCaret,m_wpCaret); | 2409 SetCaretInfo(); |
| 2410 } else { |
| 2411 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && |
| 2412 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) |
| 2413 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2414 |
| 2415 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); |
| 2620 | 2416 |
| 2621 ScrollToCaret(); | 2417 ScrollToCaret(); |
| 2622 SetCaretOrigin(); | 2418 SetCaretOrigin(); |
| 2623 SetCaretInfo(); | 2419 SetCaretInfo(); |
| 2624 } | 2420 } |
| 2625 } | 2421 } |
| 2626 | 2422 } |
| 2627 void CFX_Edit::OnMouseDown(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl
) | 2423 } |
| 2628 { | 2424 |
| 2629 if (m_pVT->IsValid()) | 2425 void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2630 { | 2426 if (m_pVT->IsValid()) { |
| 2427 if (bShift) { |
| 2428 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2429 |
| 2430 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 2431 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) |
| 2432 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2433 |
| 2434 if (m_SelState.IsExist()) |
| 2435 m_SelState.SetEndPos(m_wpCaret); |
| 2436 else |
| 2437 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2438 |
| 2439 if (m_wpOldCaret != m_wpCaret) { |
| 2440 ScrollToCaret(); |
| 2441 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2442 Refresh(RP_OPTIONAL, &wr); |
| 2443 SetCaretInfo(); |
| 2444 } |
| 2445 } else { |
| 2446 if (m_SelState.IsExist()) { |
| 2447 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0) |
| 2448 SetCaret(m_SelState.BeginPos); |
| 2449 else |
| 2450 SetCaret(m_SelState.EndPos); |
| 2451 |
| 2631 SelectNone(); | 2452 SelectNone(); |
| 2632 SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); | 2453 ScrollToCaret(); |
| 2633 m_SelState.Set(m_wpCaret,m_wpCaret); | 2454 SetCaretInfo(); |
| 2455 } else { |
| 2456 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2457 |
| 2458 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && |
| 2459 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) |
| 2460 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2634 | 2461 |
| 2635 ScrollToCaret(); | 2462 ScrollToCaret(); |
| 2636 SetCaretOrigin(); | 2463 SetCaretOrigin(); |
| 2637 SetCaretInfo(); | 2464 SetCaretInfo(); |
| 2638 } | 2465 } |
| 2639 } | 2466 } |
| 2640 | 2467 } |
| 2641 void CFX_Edit::OnMouseMove(const CPDF_Point & point,FX_BOOL bShift,FX_BOOL bCtrl
) | 2468 } |
| 2642 { | 2469 |
| 2643 if (m_pVT->IsValid()) | 2470 void CFX_Edit::OnVK_HOME(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2644 { | 2471 if (m_pVT->IsValid()) { |
| 2645 SetCaret(m_pVT->SearchWordPlace(EditToVT(point))); | 2472 if (bShift) { |
| 2646 | 2473 if (bCtrl) |
| 2647 if (m_wpCaret != m_wpOldCaret) | 2474 SetCaret(m_pVT->GetBeginWordPlace()); |
| 2648 { | 2475 else |
| 2649 m_SelState.SetEndPos(m_wpCaret); | 2476 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 2650 | 2477 |
| 2651 ScrollToCaret(); | 2478 if (m_SelState.IsExist()) |
| 2652 CPVT_WordRange wr(m_wpOldCaret,m_wpCaret); | 2479 m_SelState.SetEndPos(m_wpCaret); |
| 2653 Refresh(RP_OPTIONAL,&wr); | 2480 else |
| 2654 SetCaretOrigin(); | 2481 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2655 SetCaretInfo(); | 2482 |
| 2656 } | 2483 ScrollToCaret(); |
| 2657 } | 2484 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2658 } | 2485 Refresh(RP_OPTIONAL, &wr); |
| 2659 | 2486 SetCaretInfo(); |
| 2660 void CFX_Edit::OnVK_UP(FX_BOOL bShift,FX_BOOL bCtrl) | 2487 } else { |
| 2661 { | 2488 if (m_SelState.IsExist()) { |
| 2662 if (m_pVT->IsValid()) | 2489 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) < 0) |
| 2663 { | 2490 SetCaret(m_SelState.BeginPos); |
| 2664 SetCaret(m_pVT->GetUpWordPlace(m_wpCaret,m_ptCaret)); | |
| 2665 | |
| 2666 if (bShift) | |
| 2667 { | |
| 2668 if (m_SelState.IsExist()) | |
| 2669 m_SelState.SetEndPos(m_wpCaret); | |
| 2670 else | |
| 2671 m_SelState.Set(m_wpOldCaret,m_wpCaret); | |
| 2672 | |
| 2673 if (m_wpOldCaret != m_wpCaret) | |
| 2674 { | |
| 2675 ScrollToCaret(); | |
| 2676 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); | |
| 2677 Refresh(RP_OPTIONAL, &wr); | |
| 2678 SetCaretInfo(); | |
| 2679 } | |
| 2680 } | |
| 2681 else | 2491 else |
| 2682 { | 2492 SetCaret(m_SelState.EndPos); |
| 2683 SelectNone(); | 2493 |
| 2684 | 2494 SelectNone(); |
| 2685 ScrollToCaret(); | 2495 ScrollToCaret(); |
| 2686 SetCaretInfo(); | 2496 SetCaretInfo(); |
| 2687 } | 2497 } else { |
| 2688 } | 2498 if (bCtrl) |
| 2689 } | 2499 SetCaret(m_pVT->GetBeginWordPlace()); |
| 2690 | |
| 2691 void CFX_Edit::OnVK_DOWN(FX_BOOL bShift,FX_BOOL bCtrl) | |
| 2692 { | |
| 2693 if (m_pVT->IsValid()) | |
| 2694 { | |
| 2695 SetCaret(m_pVT->GetDownWordPlace(m_wpCaret,m_ptCaret)); | |
| 2696 | |
| 2697 if (bShift) | |
| 2698 { | |
| 2699 if (m_SelState.IsExist()) | |
| 2700 m_SelState.SetEndPos(m_wpCaret); | |
| 2701 else | |
| 2702 m_SelState.Set(m_wpOldCaret,m_wpCaret); | |
| 2703 | |
| 2704 if (m_wpOldCaret != m_wpCaret) | |
| 2705 { | |
| 2706 ScrollToCaret(); | |
| 2707 CPVT_WordRange wr(m_wpOldCaret,m_wpCaret); | |
| 2708 Refresh(RP_OPTIONAL, &wr); | |
| 2709 SetCaretInfo(); | |
| 2710 } | |
| 2711 } | |
| 2712 else | 2500 else |
| 2713 { | 2501 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); |
| 2714 SelectNone(); | 2502 |
| 2715 | 2503 ScrollToCaret(); |
| 2716 ScrollToCaret(); | 2504 SetCaretOrigin(); |
| 2717 SetCaretInfo(); | 2505 SetCaretInfo(); |
| 2718 } | 2506 } |
| 2719 } | 2507 } |
| 2720 } | 2508 } |
| 2721 | 2509 } |
| 2722 void CFX_Edit::OnVK_LEFT(FX_BOOL bShift,FX_BOOL bCtrl) | 2510 |
| 2723 { | 2511 void CFX_Edit::OnVK_END(FX_BOOL bShift, FX_BOOL bCtrl) { |
| 2724 if (m_pVT->IsValid()) | 2512 if (m_pVT->IsValid()) { |
| 2725 { | 2513 if (bShift) { |
| 2726 if (bShift) | 2514 if (bCtrl) |
| 2727 { | 2515 SetCaret(m_pVT->GetEndWordPlace()); |
| 2728 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && | 2516 else |
| 2729 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) | 2517 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 2730 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); | 2518 |
| 2731 | 2519 if (m_SelState.IsExist()) |
| 2732 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); | 2520 m_SelState.SetEndPos(m_wpCaret); |
| 2733 | 2521 else |
| 2734 if (m_SelState.IsExist()) | 2522 m_SelState.Set(m_wpOldCaret, m_wpCaret); |
| 2735 m_SelState.SetEndPos(m_wpCaret); | 2523 |
| 2736 else | 2524 ScrollToCaret(); |
| 2737 m_SelState.Set(m_wpOldCaret, m_wpCaret); | 2525 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); |
| 2738 | 2526 Refresh(RP_OPTIONAL, &wr); |
| 2739 if (m_wpOldCaret != m_wpCaret) | 2527 SetCaretInfo(); |
| 2740 { | 2528 } else { |
| 2741 ScrollToCaret(); | 2529 if (m_SelState.IsExist()) { |
| 2742 CPVT_WordRange wr(m_wpOldCaret,m_wpCaret); | 2530 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos) > 0) |
| 2743 Refresh(RP_OPTIONAL,&wr); | 2531 SetCaret(m_SelState.BeginPos); |
| 2744 SetCaretInfo(); | |
| 2745 } | |
| 2746 } | |
| 2747 else | 2532 else |
| 2748 { | 2533 SetCaret(m_SelState.EndPos); |
| 2749 if (m_SelState.IsExist()) | 2534 |
| 2750 { | 2535 SelectNone(); |
| 2751 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0) | 2536 ScrollToCaret(); |
| 2752 SetCaret(m_SelState.BeginPos); | 2537 SetCaretInfo(); |
| 2753 else | 2538 } else { |
| 2754 SetCaret(m_SelState.EndPos); | 2539 if (bCtrl) |
| 2755 | 2540 SetCaret(m_pVT->GetEndWordPlace()); |
| 2756 SelectNone(); | |
| 2757 ScrollToCaret(); | |
| 2758 SetCaretInfo(); | |
| 2759 } | |
| 2760 else | |
| 2761 { | |
| 2762 if (m_wpCaret == m_pVT->GetLineBeginPlace(m_wpCaret) && | |
| 2763 m_wpCaret != m_pVT->GetSectionBeginPlace(m_wpCaret)) | |
| 2764 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); | |
| 2765 | |
| 2766 SetCaret(m_pVT->GetPrevWordPlace(m_wpCaret)); | |
| 2767 | |
| 2768 ScrollToCaret(); | |
| 2769 SetCaretOrigin(); | |
| 2770 SetCaretInfo(); | |
| 2771 } | |
| 2772 } | |
| 2773 } | |
| 2774 } | |
| 2775 | |
| 2776 void CFX_Edit::OnVK_RIGHT(FX_BOOL bShift,FX_BOOL bCtrl) | |
| 2777 { | |
| 2778 if (m_pVT->IsValid()) | |
| 2779 { | |
| 2780 if (bShift) | |
| 2781 { | |
| 2782 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); | |
| 2783 | |
| 2784 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && | |
| 2785 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) | |
| 2786 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); | |
| 2787 | |
| 2788 if (m_SelState.IsExist()) | |
| 2789 m_SelState.SetEndPos(m_wpCaret); | |
| 2790 else | |
| 2791 m_SelState.Set(m_wpOldCaret,m_wpCaret); | |
| 2792 | |
| 2793 if (m_wpOldCaret != m_wpCaret) | |
| 2794 { | |
| 2795 ScrollToCaret(); | |
| 2796 CPVT_WordRange wr(m_wpOldCaret,m_wpCaret); | |
| 2797 Refresh(RP_OPTIONAL,&wr); | |
| 2798 SetCaretInfo(); | |
| 2799 } | |
| 2800 } | |
| 2801 else | 2541 else |
| 2802 { | 2542 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); |
| 2803 if (m_SelState.IsExist()) | 2543 |
| 2804 { | 2544 ScrollToCaret(); |
| 2805 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0) | 2545 SetCaretOrigin(); |
| 2806 SetCaret(m_SelState.BeginPos); | 2546 SetCaretInfo(); |
| 2807 else | 2547 } |
| 2808 SetCaret(m_SelState.EndPos); | 2548 } |
| 2809 | 2549 } |
| 2810 SelectNone(); | 2550 } |
| 2811 ScrollToCaret(); | 2551 |
| 2812 SetCaretInfo(); | 2552 void CFX_Edit::SetText(const FX_WCHAR* text, |
| 2813 } | 2553 int32_t charset, |
| 2814 else | 2554 const CPVT_SecProps* pSecProps, |
| 2815 { | 2555 const CPVT_WordProps* pWordProps, |
| 2816 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); | 2556 FX_BOOL bAddUndo, |
| 2817 | 2557 FX_BOOL bPaint) { |
| 2818 if (m_wpCaret == m_pVT->GetLineEndPlace(m_wpCaret) && | 2558 Empty(); |
| 2819 m_wpCaret != m_pVT->GetSectionEndPlace(m_wpCaret)) | 2559 DoInsertText(CPVT_WordPlace(0, 0, -1), text, charset, pSecProps, pWordProps); |
| 2820 SetCaret(m_pVT->GetNextWordPlace(m_wpCaret)); | 2560 if (bPaint) |
| 2821 | 2561 Paint(); |
| 2822 ScrollToCaret(); | 2562 if (m_bOprNotify && m_pOprNotify) |
| 2823 SetCaretOrigin(); | 2563 m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret); |
| 2824 SetCaretInfo(); | 2564 // if (bAddUndo) |
| 2825 } | 2565 } |
| 2826 } | 2566 |
| 2827 } | 2567 FX_BOOL CFX_Edit::InsertWord(FX_WORD word, |
| 2828 } | 2568 int32_t charset, |
| 2829 | 2569 const CPVT_WordProps* pWordProps, |
| 2830 void CFX_Edit::OnVK_HOME(FX_BOOL bShift,FX_BOOL bCtrl) | 2570 FX_BOOL bAddUndo, |
| 2831 { | 2571 FX_BOOL bPaint) { |
| 2832 if (m_pVT->IsValid()) | 2572 if (IsTextOverflow()) |
| 2833 { | |
| 2834 if (bShift) | |
| 2835 { | |
| 2836 if (bCtrl) | |
| 2837 SetCaret(m_pVT->GetBeginWordPlace()); | |
| 2838 else | |
| 2839 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); | |
| 2840 | |
| 2841 if (m_SelState.IsExist()) | |
| 2842 m_SelState.SetEndPos(m_wpCaret); | |
| 2843 else | |
| 2844 m_SelState.Set(m_wpOldCaret,m_wpCaret); | |
| 2845 | |
| 2846 ScrollToCaret(); | |
| 2847 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); | |
| 2848 Refresh(RP_OPTIONAL, &wr); | |
| 2849 SetCaretInfo(); | |
| 2850 } | |
| 2851 else | |
| 2852 { | |
| 2853 if (m_SelState.IsExist()) | |
| 2854 { | |
| 2855 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)<0) | |
| 2856 SetCaret(m_SelState.BeginPos); | |
| 2857 else | |
| 2858 SetCaret(m_SelState.EndPos); | |
| 2859 | |
| 2860 SelectNone(); | |
| 2861 ScrollToCaret(); | |
| 2862 SetCaretInfo(); | |
| 2863 } | |
| 2864 else | |
| 2865 { | |
| 2866 if (bCtrl) | |
| 2867 SetCaret(m_pVT->GetBeginWordPlace()); | |
| 2868 else | |
| 2869 SetCaret(m_pVT->GetLineBeginPlace(m_wpCaret)); | |
| 2870 | |
| 2871 ScrollToCaret(); | |
| 2872 SetCaretOrigin(); | |
| 2873 SetCaretInfo(); | |
| 2874 } | |
| 2875 } | |
| 2876 } | |
| 2877 } | |
| 2878 | |
| 2879 void CFX_Edit::OnVK_END(FX_BOOL bShift,FX_BOOL bCtrl) | |
| 2880 { | |
| 2881 if (m_pVT->IsValid()) | |
| 2882 { | |
| 2883 if (bShift) | |
| 2884 { | |
| 2885 if (bCtrl) | |
| 2886 SetCaret(m_pVT->GetEndWordPlace()); | |
| 2887 else | |
| 2888 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); | |
| 2889 | |
| 2890 if (m_SelState.IsExist()) | |
| 2891 m_SelState.SetEndPos(m_wpCaret); | |
| 2892 else | |
| 2893 m_SelState.Set(m_wpOldCaret, m_wpCaret); | |
| 2894 | |
| 2895 ScrollToCaret(); | |
| 2896 CPVT_WordRange wr(m_wpOldCaret, m_wpCaret); | |
| 2897 Refresh(RP_OPTIONAL, &wr); | |
| 2898 SetCaretInfo(); | |
| 2899 } | |
| 2900 else | |
| 2901 { | |
| 2902 if (m_SelState.IsExist()) | |
| 2903 { | |
| 2904 if (m_SelState.BeginPos.WordCmp(m_SelState.EndPos)>0) | |
| 2905 SetCaret(m_SelState.BeginPos); | |
| 2906 else | |
| 2907 SetCaret(m_SelState.EndPos); | |
| 2908 | |
| 2909 SelectNone(); | |
| 2910 ScrollToCaret(); | |
| 2911 SetCaretInfo(); | |
| 2912 } | |
| 2913 else | |
| 2914 { | |
| 2915 if (bCtrl) | |
| 2916 SetCaret(m_pVT->GetEndWordPlace()); | |
| 2917 else | |
| 2918 SetCaret(m_pVT->GetLineEndPlace(m_wpCaret)); | |
| 2919 | |
| 2920 ScrollToCaret(); | |
| 2921 SetCaretOrigin(); | |
| 2922 SetCaretInfo(); | |
| 2923 } | |
| 2924 } | |
| 2925 } | |
| 2926 } | |
| 2927 | |
| 2928 void CFX_Edit::SetText(const FX_WCHAR* text,int32_t charset, | |
| 2929 const CPVT_SecProps * pSecProps,const CPVT_WordProps * p
WordProps, FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 2930 { | |
| 2931 Empty(); | |
| 2932 DoInsertText(CPVT_WordPlace(0,0,-1), text, charset, pSecProps, pWordProps); | |
| 2933 if (bPaint) Paint(); | |
| 2934 if (m_bOprNotify && m_pOprNotify) | |
| 2935 m_pOprNotify->OnSetText(m_wpCaret, m_wpOldCaret); | |
| 2936 //if (bAddUndo) | |
| 2937 } | |
| 2938 | |
| 2939 FX_BOOL CFX_Edit::InsertWord(FX_WORD word, int32_t charset, const CPVT_WordProps
* pWordProps, FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 2940 { | |
| 2941 if (IsTextOverflow()) return FALSE; | |
| 2942 | |
| 2943 if (m_pVT->IsValid()) | |
| 2944 { | |
| 2945 m_pVT->UpdateWordPlace(m_wpCaret); | |
| 2946 | |
| 2947 SetCaret(m_pVT->InsertWord(m_wpCaret,word,GetCharSetFromUnicode(word, ch
arset),pWordProps)); | |
| 2948 m_SelState.Set(m_wpCaret,m_wpCaret); | |
| 2949 | |
| 2950 if (m_wpCaret != m_wpOldCaret) | |
| 2951 { | |
| 2952 if (bAddUndo && m_bEnableUndo) | |
| 2953 { | |
| 2954 AddEditUndoItem(new CFXEU_InsertWord(this,m_wpOldCaret,m_wpCaret
,word,charset,pWordProps)); | |
| 2955 } | |
| 2956 | |
| 2957 if (bPaint) | |
| 2958 PaintInsertText(m_wpOldCaret, m_wpCaret); | |
| 2959 | |
| 2960 if (m_bOprNotify && m_pOprNotify) | |
| 2961 m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret); | |
| 2962 | |
| 2963 return TRUE; | |
| 2964 } | |
| 2965 } | |
| 2966 | |
| 2967 return FALSE; | 2573 return FALSE; |
| 2968 } | 2574 |
| 2969 | 2575 if (m_pVT->IsValid()) { |
| 2970 FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps * pSecProps,const CPVT_WordPr
ops * pWordProps, | 2576 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2971 FX_BOOL bAddUndo, FX_BOOL bPaint) | 2577 |
| 2972 { | 2578 SetCaret(m_pVT->InsertWord( |
| 2973 if (IsTextOverflow()) return FALSE; | 2579 m_wpCaret, word, GetCharSetFromUnicode(word, charset), pWordProps)); |
| 2974 | 2580 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2975 if (m_pVT->IsValid()) | 2581 |
| 2976 { | 2582 if (m_wpCaret != m_wpOldCaret) { |
| 2977 m_pVT->UpdateWordPlace(m_wpCaret); | 2583 if (bAddUndo && m_bEnableUndo) { |
| 2978 SetCaret(m_pVT->InsertSection(m_wpCaret,pSecProps,pWordProps)); | 2584 AddEditUndoItem(new CFXEU_InsertWord(this, m_wpOldCaret, m_wpCaret, |
| 2979 m_SelState.Set(m_wpCaret,m_wpCaret); | 2585 word, charset, pWordProps)); |
| 2980 | 2586 } |
| 2981 if (m_wpCaret != m_wpOldCaret) | 2587 |
| 2982 { | 2588 if (bPaint) |
| 2983 if (bAddUndo && m_bEnableUndo) | 2589 PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 2984 { | 2590 |
| 2985 AddEditUndoItem(new CFXEU_InsertReturn(this,m_wpOldCaret,m_wpCar
et,pSecProps,pWordProps)); | 2591 if (m_bOprNotify && m_pOprNotify) |
| 2986 } | 2592 m_pOprNotify->OnInsertWord(m_wpCaret, m_wpOldCaret); |
| 2987 | 2593 |
| 2988 if (bPaint) | 2594 return TRUE; |
| 2989 { | 2595 } |
| 2990 RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); | 2596 } |
| 2991 ScrollToCaret(); | 2597 |
| 2992 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); | 2598 return FALSE; |
| 2993 Refresh(RP_ANALYSE, &wr); | 2599 } |
| 2994 SetCaretOrigin(); | 2600 |
| 2995 SetCaretInfo(); | 2601 FX_BOOL CFX_Edit::InsertReturn(const CPVT_SecProps* pSecProps, |
| 2996 } | 2602 const CPVT_WordProps* pWordProps, |
| 2997 | 2603 FX_BOOL bAddUndo, |
| 2998 if (m_bOprNotify && m_pOprNotify) | 2604 FX_BOOL bPaint) { |
| 2999 m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret); | 2605 if (IsTextOverflow()) |
| 3000 | |
| 3001 return TRUE; | |
| 3002 } | |
| 3003 } | |
| 3004 | |
| 3005 return FALSE; | 2606 return FALSE; |
| 3006 } | 2607 |
| 3007 | 2608 if (m_pVT->IsValid()) { |
| 3008 FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 3009 { | |
| 3010 if (m_pVT->IsValid()) | |
| 3011 { | |
| 3012 if (m_wpCaret == m_pVT->GetBeginWordPlace()) return FALSE; | |
| 3013 | |
| 3014 CPVT_Section section; | |
| 3015 CPVT_Word word; | |
| 3016 | |
| 3017 if (bAddUndo) | |
| 3018 { | |
| 3019 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 3020 { | |
| 3021 pIterator->SetAt(m_wpCaret); | |
| 3022 pIterator->GetSection(section); | |
| 3023 pIterator->GetWord(word); | |
| 3024 } | |
| 3025 } | |
| 3026 | |
| 3027 m_pVT->UpdateWordPlace(m_wpCaret); | |
| 3028 SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); | |
| 3029 m_SelState.Set(m_wpCaret,m_wpCaret); | |
| 3030 | |
| 3031 if (m_wpCaret != m_wpOldCaret) | |
| 3032 { | |
| 3033 if (bAddUndo && m_bEnableUndo) | |
| 3034 { | |
| 3035 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) | |
| 3036 AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCa
ret,word.Word,word.nCharset, | |
| 3037 section.SecProps,section.WordProps)); | |
| 3038 else | |
| 3039 AddEditUndoItem(new CFXEU_Backspace(this,m_wpOldCaret,m_wpCa
ret,word.Word,word.nCharset, | |
| 3040 section.SecProps,word.WordProps)); | |
| 3041 } | |
| 3042 | |
| 3043 if (bPaint) | |
| 3044 { | |
| 3045 RearrangePart(CPVT_WordRange(m_wpCaret,m_wpOldCaret)); | |
| 3046 ScrollToCaret(); | |
| 3047 | |
| 3048 CPVT_WordRange wr; | |
| 3049 if (m_wpCaret.SecCmp(m_wpOldCaret) !=0) | |
| 3050 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),GetVi
sibleWordRange().EndPos); | |
| 3051 else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0) | |
| 3052 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pV
T->GetSectionEndPlace(m_wpCaret)); | |
| 3053 else | |
| 3054 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret),m_pVT
->GetSectionEndPlace(m_wpCaret)); | |
| 3055 | |
| 3056 Refresh(RP_ANALYSE, &wr); | |
| 3057 | |
| 3058 SetCaretOrigin(); | |
| 3059 SetCaretInfo(); | |
| 3060 } | |
| 3061 | |
| 3062 if (m_bOprNotify && m_pOprNotify) | |
| 3063 m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret); | |
| 3064 | |
| 3065 return TRUE; | |
| 3066 } | |
| 3067 } | |
| 3068 | |
| 3069 return FALSE; | |
| 3070 } | |
| 3071 | |
| 3072 FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 3073 { | |
| 3074 if (m_pVT->IsValid()) | |
| 3075 { | |
| 3076 if (m_wpCaret == m_pVT->GetEndWordPlace()) return FALSE; | |
| 3077 | |
| 3078 CPVT_Section section; | |
| 3079 CPVT_Word word; | |
| 3080 | |
| 3081 if (bAddUndo) | |
| 3082 { | |
| 3083 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 3084 { | |
| 3085 pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); | |
| 3086 pIterator->GetSection(section); | |
| 3087 pIterator->GetWord(word); | |
| 3088 } | |
| 3089 } | |
| 3090 | |
| 3091 m_pVT->UpdateWordPlace(m_wpCaret); | |
| 3092 FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); | |
| 3093 | |
| 3094 SetCaret(m_pVT->DeleteWord(m_wpCaret)); | |
| 3095 m_SelState.Set(m_wpCaret,m_wpCaret); | |
| 3096 | |
| 3097 if (bAddUndo && m_bEnableUndo) | |
| 3098 { | |
| 3099 if (bSecEnd) | |
| 3100 AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,wor
d.Word,word.nCharset, | |
| 3101 section.SecProps,section.WordProps,bSecEnd)); | |
| 3102 else | |
| 3103 AddEditUndoItem(new CFXEU_Delete(this,m_wpOldCaret,m_wpCaret,wor
d.Word,word.nCharset, | |
| 3104 section.SecProps,word.WordProps,bSecEnd)); | |
| 3105 } | |
| 3106 | |
| 3107 if (bPaint) | |
| 3108 { | |
| 3109 RearrangePart(CPVT_WordRange(m_wpOldCaret,m_wpCaret)); | |
| 3110 ScrollToCaret(); | |
| 3111 | |
| 3112 CPVT_WordRange wr; | |
| 3113 if (bSecEnd) | |
| 3114 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),GetVis
ibleWordRange().EndPos); | |
| 3115 else if (m_wpCaret.LineCmp(m_wpOldCaret) !=0) | |
| 3116 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret),m_pVT->G
etSectionEndPlace(m_wpCaret)); | |
| 3117 else | |
| 3118 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret),m_pVT-
>GetSectionEndPlace(m_wpCaret)); | |
| 3119 | |
| 3120 Refresh(RP_ANALYSE, &wr); | |
| 3121 | |
| 3122 SetCaretOrigin(); | |
| 3123 SetCaretInfo(); | |
| 3124 } | |
| 3125 | |
| 3126 if (m_bOprNotify && m_pOprNotify) | |
| 3127 m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret); | |
| 3128 | |
| 3129 return TRUE; | |
| 3130 } | |
| 3131 | |
| 3132 return FALSE; | |
| 3133 } | |
| 3134 | |
| 3135 FX_BOOL CFX_Edit::Empty() | |
| 3136 { | |
| 3137 if (m_pVT->IsValid()) | |
| 3138 { | |
| 3139 m_pVT->DeleteWords(GetWholeWordRange()); | |
| 3140 SetCaret(m_pVT->GetBeginWordPlace()); | |
| 3141 | |
| 3142 return TRUE; | |
| 3143 } | |
| 3144 | |
| 3145 return FALSE; | |
| 3146 } | |
| 3147 | |
| 3148 FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 3149 { | |
| 3150 if (m_pVT->IsValid()) | |
| 3151 { | |
| 3152 if (m_SelState.IsExist()) | |
| 3153 { | |
| 3154 CPVT_WordRange range = m_SelState.ConvertToWordRange(); | |
| 3155 | |
| 3156 if (bAddUndo && m_bEnableUndo) | |
| 3157 { | |
| 3158 if (m_pVT->IsRichText()) | |
| 3159 { | |
| 3160 BeginGroupUndo(L""); | |
| 3161 | |
| 3162 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetItera
tor()) | |
| 3163 { | |
| 3164 pIterator->SetAt(range.EndPos); | |
| 3165 | |
| 3166 CPVT_Word wordinfo; | |
| 3167 CPVT_Section secinfo; | |
| 3168 do | |
| 3169 { | |
| 3170 CPVT_WordPlace place = pIterator->GetAt(); | |
| 3171 if (place.WordCmp(range.BeginPos) <= 0)break; | |
| 3172 | |
| 3173 CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(pl
ace); | |
| 3174 | |
| 3175 if (oldplace.SecCmp(place) != 0) | |
| 3176 { | |
| 3177 if (pIterator->GetSection(secinfo)) | |
| 3178 { | |
| 3179 AddEditUndoItem(new CFXEU_ClearRich(this,old
place,place,range,wordinfo.Word, | |
| 3180 wordinfo.nCharset,secinfo.SecProps,secin
fo.WordProps)); | |
| 3181 } | |
| 3182 } | |
| 3183 else | |
| 3184 { | |
| 3185 if (pIterator->GetWord(wordinfo)) | |
| 3186 { | |
| 3187 oldplace = m_pVT->AjustLineHeader(oldplace,T
RUE); | |
| 3188 place = m_pVT->AjustLineHeader(place,TRUE); | |
| 3189 | |
| 3190 AddEditUndoItem(new CFXEU_ClearRich(this,old
place,place,range,wordinfo.Word, | |
| 3191 wordinfo.nCharset,secinfo.SecProps,wordi
nfo.WordProps)); | |
| 3192 } | |
| 3193 } | |
| 3194 }while (pIterator->PrevWord()); | |
| 3195 } | |
| 3196 EndGroupUndo(); | |
| 3197 } | |
| 3198 else | |
| 3199 { | |
| 3200 AddEditUndoItem(new CFXEU_Clear(this,range,GetSelText())); | |
| 3201 } | |
| 3202 } | |
| 3203 | |
| 3204 SelectNone(); | |
| 3205 SetCaret(m_pVT->DeleteWords(range)); | |
| 3206 m_SelState.Set(m_wpCaret,m_wpCaret); | |
| 3207 | |
| 3208 if (bPaint) | |
| 3209 { | |
| 3210 RearrangePart(range); | |
| 3211 ScrollToCaret(); | |
| 3212 | |
| 3213 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); | |
| 3214 Refresh(RP_ANALYSE, &wr); | |
| 3215 | |
| 3216 SetCaretOrigin(); | |
| 3217 SetCaretInfo(); | |
| 3218 } | |
| 3219 | |
| 3220 if (m_bOprNotify && m_pOprNotify) | |
| 3221 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); | |
| 3222 | |
| 3223 return TRUE; | |
| 3224 } | |
| 3225 } | |
| 3226 | |
| 3227 return FALSE; | |
| 3228 } | |
| 3229 | |
| 3230 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, int32_t charset, | |
| 3231 const CPVT_SecProps * pSecProps, const CPVT_WordProps * pWor
dProps, FX_BOOL bAddUndo, FX_BOOL bPaint) | |
| 3232 { | |
| 3233 if (IsTextOverflow()) return FALSE; | |
| 3234 | |
| 3235 m_pVT->UpdateWordPlace(m_wpCaret); | 2609 m_pVT->UpdateWordPlace(m_wpCaret); |
| 3236 SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps)); | 2610 SetCaret(m_pVT->InsertSection(m_wpCaret, pSecProps, pWordProps)); |
| 3237 m_SelState.Set(m_wpCaret,m_wpCaret); | 2611 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 3238 | 2612 |
| 3239 if (m_wpCaret != m_wpOldCaret) | 2613 if (m_wpCaret != m_wpOldCaret) { |
| 3240 { | 2614 if (bAddUndo && m_bEnableUndo) { |
| 3241 if (bAddUndo && m_bEnableUndo) | 2615 AddEditUndoItem(new CFXEU_InsertReturn(this, m_wpOldCaret, m_wpCaret, |
| 3242 { | 2616 pSecProps, pWordProps)); |
| 3243 AddEditUndoItem(new CFXEU_InsertText(this,m_wpOldCaret,m_wpCaret,tex
t,charset,pSecProps,pWordProps)); | 2617 } |
| 3244 } | 2618 |
| 3245 | 2619 if (bPaint) { |
| 3246 if (bPaint) | 2620 RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 3247 PaintInsertText(m_wpOldCaret, m_wpCaret); | |
| 3248 | |
| 3249 if (m_bOprNotify && m_pOprNotify) | |
| 3250 m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); | |
| 3251 | |
| 3252 return TRUE; | |
| 3253 } | |
| 3254 return FALSE; | |
| 3255 } | |
| 3256 | |
| 3257 void CFX_Edit::PaintInsertText(const CPVT_WordPlace & wpOld, const CPVT_WordPlac
e & wpNew) | |
| 3258 { | |
| 3259 if (m_pVT->IsValid()) | |
| 3260 { | |
| 3261 RearrangePart(CPVT_WordRange(wpOld,wpNew)); | |
| 3262 ScrollToCaret(); | 2621 ScrollToCaret(); |
| 3263 | 2622 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); |
| 3264 CPVT_WordRange wr; | |
| 3265 if (m_wpCaret.LineCmp(wpOld) !=0) | |
| 3266 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld),m_pVT->GetSectio
nEndPlace(wpNew)); | |
| 3267 else | |
| 3268 wr = CPVT_WordRange(wpOld,m_pVT->GetSectionEndPlace(wpNew)); | |
| 3269 Refresh(RP_ANALYSE, &wr); | 2623 Refresh(RP_ANALYSE, &wr); |
| 3270 SetCaretOrigin(); | 2624 SetCaretOrigin(); |
| 3271 SetCaretInfo(); | 2625 SetCaretInfo(); |
| 3272 } | 2626 } |
| 3273 } | 2627 |
| 3274 | 2628 if (m_bOprNotify && m_pOprNotify) |
| 3275 FX_BOOL CFX_Edit::Redo() | 2629 m_pOprNotify->OnInsertReturn(m_wpCaret, m_wpOldCaret); |
| 3276 { | 2630 |
| 3277 if (m_bEnableUndo) | 2631 return TRUE; |
| 3278 { | 2632 } |
| 3279 if (m_Undo.CanRedo()) | 2633 } |
| 3280 { | 2634 |
| 3281 m_Undo.Redo(); | 2635 return FALSE; |
| 3282 return TRUE; | 2636 } |
| 2637 |
| 2638 FX_BOOL CFX_Edit::Backspace(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
| 2639 if (m_pVT->IsValid()) { |
| 2640 if (m_wpCaret == m_pVT->GetBeginWordPlace()) |
| 2641 return FALSE; |
| 2642 |
| 2643 CPVT_Section section; |
| 2644 CPVT_Word word; |
| 2645 |
| 2646 if (bAddUndo) { |
| 2647 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2648 pIterator->SetAt(m_wpCaret); |
| 2649 pIterator->GetSection(section); |
| 2650 pIterator->GetWord(word); |
| 2651 } |
| 2652 } |
| 2653 |
| 2654 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2655 SetCaret(m_pVT->BackSpaceWord(m_wpCaret)); |
| 2656 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2657 |
| 2658 if (m_wpCaret != m_wpOldCaret) { |
| 2659 if (bAddUndo && m_bEnableUndo) { |
| 2660 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) |
| 2661 AddEditUndoItem(new CFXEU_Backspace( |
| 2662 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2663 section.SecProps, section.WordProps)); |
| 2664 else |
| 2665 AddEditUndoItem(new CFXEU_Backspace( |
| 2666 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2667 section.SecProps, word.WordProps)); |
| 2668 } |
| 2669 |
| 2670 if (bPaint) { |
| 2671 RearrangePart(CPVT_WordRange(m_wpCaret, m_wpOldCaret)); |
| 2672 ScrollToCaret(); |
| 2673 |
| 2674 CPVT_WordRange wr; |
| 2675 if (m_wpCaret.SecCmp(m_wpOldCaret) != 0) |
| 2676 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret), |
| 2677 GetVisibleWordRange().EndPos); |
| 2678 else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0) |
| 2679 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret), |
| 2680 m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2681 else |
| 2682 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpCaret), |
| 2683 m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2684 |
| 2685 Refresh(RP_ANALYSE, &wr); |
| 2686 |
| 2687 SetCaretOrigin(); |
| 2688 SetCaretInfo(); |
| 2689 } |
| 2690 |
| 2691 if (m_bOprNotify && m_pOprNotify) |
| 2692 m_pOprNotify->OnBackSpace(m_wpCaret, m_wpOldCaret); |
| 2693 |
| 2694 return TRUE; |
| 2695 } |
| 2696 } |
| 2697 |
| 2698 return FALSE; |
| 2699 } |
| 2700 |
| 2701 FX_BOOL CFX_Edit::Delete(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
| 2702 if (m_pVT->IsValid()) { |
| 2703 if (m_wpCaret == m_pVT->GetEndWordPlace()) |
| 2704 return FALSE; |
| 2705 |
| 2706 CPVT_Section section; |
| 2707 CPVT_Word word; |
| 2708 |
| 2709 if (bAddUndo) { |
| 2710 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2711 pIterator->SetAt(m_pVT->GetNextWordPlace(m_wpCaret)); |
| 2712 pIterator->GetSection(section); |
| 2713 pIterator->GetWord(word); |
| 2714 } |
| 2715 } |
| 2716 |
| 2717 m_pVT->UpdateWordPlace(m_wpCaret); |
| 2718 FX_BOOL bSecEnd = (m_wpCaret == m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2719 |
| 2720 SetCaret(m_pVT->DeleteWord(m_wpCaret)); |
| 2721 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2722 |
| 2723 if (bAddUndo && m_bEnableUndo) { |
| 2724 if (bSecEnd) |
| 2725 AddEditUndoItem(new CFXEU_Delete( |
| 2726 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2727 section.SecProps, section.WordProps, bSecEnd)); |
| 2728 else |
| 2729 AddEditUndoItem(new CFXEU_Delete( |
| 2730 this, m_wpOldCaret, m_wpCaret, word.Word, word.nCharset, |
| 2731 section.SecProps, word.WordProps, bSecEnd)); |
| 2732 } |
| 2733 |
| 2734 if (bPaint) { |
| 2735 RearrangePart(CPVT_WordRange(m_wpOldCaret, m_wpCaret)); |
| 2736 ScrollToCaret(); |
| 2737 |
| 2738 CPVT_WordRange wr; |
| 2739 if (bSecEnd) |
| 2740 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret), |
| 2741 GetVisibleWordRange().EndPos); |
| 2742 else if (m_wpCaret.LineCmp(m_wpOldCaret) != 0) |
| 2743 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(m_wpCaret), |
| 2744 m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2745 else |
| 2746 wr = CPVT_WordRange(m_pVT->GetPrevWordPlace(m_wpOldCaret), |
| 2747 m_pVT->GetSectionEndPlace(m_wpCaret)); |
| 2748 |
| 2749 Refresh(RP_ANALYSE, &wr); |
| 2750 |
| 2751 SetCaretOrigin(); |
| 2752 SetCaretInfo(); |
| 2753 } |
| 2754 |
| 2755 if (m_bOprNotify && m_pOprNotify) |
| 2756 m_pOprNotify->OnDelete(m_wpCaret, m_wpOldCaret); |
| 2757 |
| 2758 return TRUE; |
| 2759 } |
| 2760 |
| 2761 return FALSE; |
| 2762 } |
| 2763 |
| 2764 FX_BOOL CFX_Edit::Empty() { |
| 2765 if (m_pVT->IsValid()) { |
| 2766 m_pVT->DeleteWords(GetWholeWordRange()); |
| 2767 SetCaret(m_pVT->GetBeginWordPlace()); |
| 2768 |
| 2769 return TRUE; |
| 2770 } |
| 2771 |
| 2772 return FALSE; |
| 2773 } |
| 2774 |
| 2775 FX_BOOL CFX_Edit::Clear(FX_BOOL bAddUndo, FX_BOOL bPaint) { |
| 2776 if (m_pVT->IsValid()) { |
| 2777 if (m_SelState.IsExist()) { |
| 2778 CPVT_WordRange range = m_SelState.ConvertToWordRange(); |
| 2779 |
| 2780 if (bAddUndo && m_bEnableUndo) { |
| 2781 if (m_pVT->IsRichText()) { |
| 2782 BeginGroupUndo(L""); |
| 2783 |
| 2784 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2785 pIterator->SetAt(range.EndPos); |
| 2786 |
| 2787 CPVT_Word wordinfo; |
| 2788 CPVT_Section secinfo; |
| 2789 do { |
| 2790 CPVT_WordPlace place = pIterator->GetAt(); |
| 2791 if (place.WordCmp(range.BeginPos) <= 0) |
| 2792 break; |
| 2793 |
| 2794 CPVT_WordPlace oldplace = m_pVT->GetPrevWordPlace(place); |
| 2795 |
| 2796 if (oldplace.SecCmp(place) != 0) { |
| 2797 if (pIterator->GetSection(secinfo)) { |
| 2798 AddEditUndoItem(new CFXEU_ClearRich( |
| 2799 this, oldplace, place, range, wordinfo.Word, |
| 2800 wordinfo.nCharset, secinfo.SecProps, secinfo.WordProps)); |
| 2801 } |
| 2802 } else { |
| 2803 if (pIterator->GetWord(wordinfo)) { |
| 2804 oldplace = m_pVT->AjustLineHeader(oldplace, TRUE); |
| 2805 place = m_pVT->AjustLineHeader(place, TRUE); |
| 2806 |
| 2807 AddEditUndoItem(new CFXEU_ClearRich( |
| 2808 this, oldplace, place, range, wordinfo.Word, |
| 2809 wordinfo.nCharset, secinfo.SecProps, wordinfo.WordProps)); |
| 2810 } |
| 2811 } |
| 2812 } while (pIterator->PrevWord()); |
| 2813 } |
| 2814 EndGroupUndo(); |
| 2815 } else { |
| 2816 AddEditUndoItem(new CFXEU_Clear(this, range, GetSelText())); |
| 3283 } | 2817 } |
| 3284 } | 2818 } |
| 3285 | 2819 |
| 2820 SelectNone(); |
| 2821 SetCaret(m_pVT->DeleteWords(range)); |
| 2822 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 2823 |
| 2824 if (bPaint) { |
| 2825 RearrangePart(range); |
| 2826 ScrollToCaret(); |
| 2827 |
| 2828 CPVT_WordRange wr(m_wpOldCaret, GetVisibleWordRange().EndPos); |
| 2829 Refresh(RP_ANALYSE, &wr); |
| 2830 |
| 2831 SetCaretOrigin(); |
| 2832 SetCaretInfo(); |
| 2833 } |
| 2834 |
| 2835 if (m_bOprNotify && m_pOprNotify) |
| 2836 m_pOprNotify->OnClear(m_wpCaret, m_wpOldCaret); |
| 2837 |
| 2838 return TRUE; |
| 2839 } |
| 2840 } |
| 2841 |
| 2842 return FALSE; |
| 2843 } |
| 2844 |
| 2845 FX_BOOL CFX_Edit::InsertText(const FX_WCHAR* text, |
| 2846 int32_t charset, |
| 2847 const CPVT_SecProps* pSecProps, |
| 2848 const CPVT_WordProps* pWordProps, |
| 2849 FX_BOOL bAddUndo, |
| 2850 FX_BOOL bPaint) { |
| 2851 if (IsTextOverflow()) |
| 3286 return FALSE; | 2852 return FALSE; |
| 3287 } | 2853 |
| 3288 | 2854 m_pVT->UpdateWordPlace(m_wpCaret); |
| 3289 FX_BOOL CFX_Edit::Undo() | 2855 SetCaret(DoInsertText(m_wpCaret, text, charset, pSecProps, pWordProps)); |
| 3290 { | 2856 m_SelState.Set(m_wpCaret, m_wpCaret); |
| 3291 if (m_bEnableUndo) | 2857 |
| 3292 { | 2858 if (m_wpCaret != m_wpOldCaret) { |
| 3293 if (m_Undo.CanUndo()) | 2859 if (bAddUndo && m_bEnableUndo) { |
| 3294 { | 2860 AddEditUndoItem(new CFXEU_InsertText(this, m_wpOldCaret, m_wpCaret, text, |
| 3295 m_Undo.Undo(); | 2861 charset, pSecProps, pWordProps)); |
| 3296 return TRUE; | 2862 } |
| 3297 } | 2863 |
| 3298 } | 2864 if (bPaint) |
| 3299 | 2865 PaintInsertText(m_wpOldCaret, m_wpCaret); |
| 3300 return FALSE; | 2866 |
| 3301 } | |
| 3302 | |
| 3303 void CFX_Edit::SetCaretOrigin() | |
| 3304 { | |
| 3305 if (m_pVT->IsValid()) | |
| 3306 { | |
| 3307 if (IPDF_VariableText_Iterator * pIterator = m_pVT->GetIterator()) | |
| 3308 { | |
| 3309 pIterator->SetAt(m_wpCaret); | |
| 3310 CPVT_Word word; | |
| 3311 CPVT_Line line; | |
| 3312 if (pIterator->GetWord(word)) | |
| 3313 { | |
| 3314 m_ptCaret.x = word.ptWord.x + word.fWidth; | |
| 3315 m_ptCaret.y = word.ptWord.y; | |
| 3316 } | |
| 3317 else if (pIterator->GetLine(line)) | |
| 3318 { | |
| 3319 m_ptCaret.x = line.ptLine.x; | |
| 3320 m_ptCaret.y = line.ptLine.y; | |
| 3321 } | |
| 3322 } | |
| 3323 } | |
| 3324 } | |
| 3325 | |
| 3326 int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace & place) const | |
| 3327 { | |
| 3328 if (m_pVT->IsValid()) | |
| 3329 return m_pVT->WordPlaceToWordIndex(place); | |
| 3330 | |
| 3331 return -1; | |
| 3332 } | |
| 3333 | |
| 3334 CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(int32_t index) const | |
| 3335 { | |
| 3336 if (m_pVT->IsValid()) | |
| 3337 return m_pVT->WordIndexToWordPlace(index); | |
| 3338 | |
| 3339 return CPVT_WordPlace(); | |
| 3340 } | |
| 3341 | |
| 3342 FX_BOOL CFX_Edit::IsTextFull() const | |
| 3343 { | |
| 3344 int32_t nTotalWords = m_pVT->GetTotalWords(); | |
| 3345 int32_t nLimitChar = m_pVT->GetLimitChar(); | |
| 3346 int32_t nCharArray = m_pVT->GetCharArray(); | |
| 3347 | |
| 3348 return IsTextOverflow() || (nLimitChar>0 && nTotalWords >= nLimitChar) | |
| 3349 || (nCharArray>0 && nTotalWords >= nCharArray); | |
| 3350 } | |
| 3351 | |
| 3352 FX_BOOL CFX_Edit::IsTextOverflow() const | |
| 3353 { | |
| 3354 if (!m_bEnableScroll && !m_bEnableOverflow) | |
| 3355 { | |
| 3356 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); | |
| 3357 CPDF_Rect rcContent = m_pVT->GetContentRect(); | |
| 3358 | |
| 3359 if (m_pVT->IsMultiLine() && GetTotalLines() > 1) | |
| 3360 { | |
| 3361 if (FX_EDIT_IsFloatBigger(rcContent.Height(),rcPlate.Height())) retu
rn TRUE; | |
| 3362 } | |
| 3363 | |
| 3364 if (FX_EDIT_IsFloatBigger(rcContent.Width(),rcPlate.Width())) return TRU
E; | |
| 3365 } | |
| 3366 | |
| 3367 return FALSE; | |
| 3368 } | |
| 3369 | |
| 3370 CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace & place) const | |
| 3371 { | |
| 3372 return m_pVT->GetLineBeginPlace(place); | |
| 3373 } | |
| 3374 | |
| 3375 CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace & place) const | |
| 3376 { | |
| 3377 return m_pVT->GetLineEndPlace(place); | |
| 3378 } | |
| 3379 | |
| 3380 CPVT_WordPlace CFX_Edit::GetSectionBeginPlace(const CPVT_WordPlace & place) cons
t | |
| 3381 { | |
| 3382 return m_pVT->GetSectionBeginPlace(place); | |
| 3383 } | |
| 3384 | |
| 3385 CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace & place) const | |
| 3386 { | |
| 3387 return m_pVT->GetSectionEndPlace(place); | |
| 3388 } | |
| 3389 | |
| 3390 FX_BOOL CFX_Edit::CanUndo() const | |
| 3391 { | |
| 3392 if (m_bEnableUndo) | |
| 3393 { | |
| 3394 return m_Undo.CanUndo(); | |
| 3395 } | |
| 3396 | |
| 3397 return FALSE; | |
| 3398 } | |
| 3399 | |
| 3400 FX_BOOL CFX_Edit::CanRedo() const | |
| 3401 { | |
| 3402 if (m_bEnableUndo) | |
| 3403 { | |
| 3404 return m_Undo.CanRedo(); | |
| 3405 } | |
| 3406 | |
| 3407 return FALSE; | |
| 3408 } | |
| 3409 | |
| 3410 FX_BOOL CFX_Edit::IsModified() const | |
| 3411 { | |
| 3412 if (m_bEnableUndo) | |
| 3413 { | |
| 3414 return m_Undo.IsModified(); | |
| 3415 } | |
| 3416 | |
| 3417 return FALSE; | |
| 3418 } | |
| 3419 | |
| 3420 void CFX_Edit::EnableRefresh(FX_BOOL bRefresh) | |
| 3421 { | |
| 3422 m_bEnableRefresh = bRefresh; | |
| 3423 } | |
| 3424 | |
| 3425 void CFX_Edit::EnableUndo(FX_BOOL bUndo) | |
| 3426 { | |
| 3427 m_bEnableUndo = bUndo; | |
| 3428 } | |
| 3429 | |
| 3430 void CFX_Edit::EnableNotify(FX_BOOL bNotify) | |
| 3431 { | |
| 3432 m_bNotify = bNotify; | |
| 3433 } | |
| 3434 | |
| 3435 void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) | |
| 3436 { | |
| 3437 m_bOprNotify = bNotify; | |
| 3438 } | |
| 3439 | |
| 3440 FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const | |
| 3441 { | |
| 3442 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) | |
| 3443 { | |
| 3444 CPVT_WordPlace wpOld = pIterator->GetAt(); | |
| 3445 | |
| 3446 pIterator->SetAt(place); | |
| 3447 CPVT_Line line; | |
| 3448 pIterator->GetLine(line); | |
| 3449 | |
| 3450 pIterator->SetAt(wpOld); | |
| 3451 | |
| 3452 return line.ptLine.y + line.fLineAscent; | |
| 3453 } | |
| 3454 | |
| 3455 return 0.0f; | |
| 3456 } | |
| 3457 | |
| 3458 FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const | |
| 3459 { | |
| 3460 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) | |
| 3461 { | |
| 3462 CPVT_WordPlace wpOld = pIterator->GetAt(); | |
| 3463 | |
| 3464 pIterator->SetAt(place); | |
| 3465 CPVT_Line line; | |
| 3466 pIterator->GetLine(line); | |
| 3467 | |
| 3468 pIterator->SetAt(wpOld); | |
| 3469 | |
| 3470 return line.ptLine.y + line.fLineDescent; | |
| 3471 } | |
| 3472 | |
| 3473 return 0.0f; | |
| 3474 } | |
| 3475 | |
| 3476 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, const FX_WCHA
R* text, int32_t charset, | |
| 3477 const CPVT_SecProps * pSecProps, const CPV
T_WordProps * pWordProps) | |
| 3478 { | |
| 3479 CPVT_WordPlace wp = place; | |
| 3480 | |
| 3481 if (m_pVT->IsValid()) | |
| 3482 { | |
| 3483 CFX_WideString sText = text; | |
| 3484 | |
| 3485 for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) | |
| 3486 { | |
| 3487 FX_WORD word = sText[i]; | |
| 3488 switch (word) | |
| 3489 { | |
| 3490 case 0x0D: | |
| 3491 wp = m_pVT->InsertSection(wp,pSecProps,pWordProps); | |
| 3492 if (sText[i+1] == 0x0A) | |
| 3493 i++; | |
| 3494 break; | |
| 3495 case 0x0A: | |
| 3496 wp = m_pVT->InsertSection(wp,pSecProps,pWordProps); | |
| 3497 if (sText[i+1] == 0x0D) | |
| 3498 i++; | |
| 3499 break; | |
| 3500 case 0x09: | |
| 3501 word = 0x20; | |
| 3502 default: | |
| 3503 wp = m_pVT->InsertWord(wp,word,GetCharSetFromUnicode(word, chars
et),pWordProps); | |
| 3504 break; | |
| 3505 } | |
| 3506 } | |
| 3507 } | |
| 3508 | |
| 3509 return wp; | |
| 3510 } | |
| 3511 | |
| 3512 int32_t CFX_Edit::GetCharSetFromUnicode(FX_WORD word, int32_t nOldCharset) | |
| 3513 { | |
| 3514 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) | |
| 3515 return pFontMap->CharSetFromUnicode(word, nOldCharset); | |
| 3516 return nOldCharset; | |
| 3517 } | |
| 3518 | |
| 3519 void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) | |
| 3520 { | |
| 3521 ASSERT(m_pGroupUndoItem == NULL); | |
| 3522 | |
| 3523 m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle); | |
| 3524 } | |
| 3525 | |
| 3526 void CFX_Edit::EndGroupUndo() | |
| 3527 { | |
| 3528 ASSERT(m_pGroupUndoItem != NULL); | |
| 3529 | |
| 3530 m_pGroupUndoItem->UpdateItems(); | |
| 3531 m_Undo.AddItem(m_pGroupUndoItem); | |
| 3532 if (m_bOprNotify && m_pOprNotify) | 2867 if (m_bOprNotify && m_pOprNotify) |
| 3533 m_pOprNotify->OnAddUndo(m_pGroupUndoItem); | 2868 m_pOprNotify->OnInsertText(m_wpCaret, m_wpOldCaret); |
| 3534 m_pGroupUndoItem = NULL; | 2869 |
| 3535 } | 2870 return TRUE; |
| 3536 | 2871 } |
| 3537 void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) | 2872 return FALSE; |
| 3538 { | 2873 } |
| 3539 if (m_pGroupUndoItem) | 2874 |
| 3540 m_pGroupUndoItem->AddUndoItem(pEditUndoItem); | 2875 void CFX_Edit::PaintInsertText(const CPVT_WordPlace& wpOld, |
| 2876 const CPVT_WordPlace& wpNew) { |
| 2877 if (m_pVT->IsValid()) { |
| 2878 RearrangePart(CPVT_WordRange(wpOld, wpNew)); |
| 2879 ScrollToCaret(); |
| 2880 |
| 2881 CPVT_WordRange wr; |
| 2882 if (m_wpCaret.LineCmp(wpOld) != 0) |
| 2883 wr = CPVT_WordRange(m_pVT->GetLineBeginPlace(wpOld), |
| 2884 m_pVT->GetSectionEndPlace(wpNew)); |
| 3541 else | 2885 else |
| 3542 { | 2886 wr = CPVT_WordRange(wpOld, m_pVT->GetSectionEndPlace(wpNew)); |
| 3543 m_Undo.AddItem(pEditUndoItem); | 2887 Refresh(RP_ANALYSE, &wr); |
| 3544 if (m_bOprNotify && m_pOprNotify) | 2888 SetCaretOrigin(); |
| 3545 m_pOprNotify->OnAddUndo(pEditUndoItem); | 2889 SetCaretInfo(); |
| 3546 } | 2890 } |
| 3547 } | 2891 } |
| 3548 | 2892 |
| 3549 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) | 2893 FX_BOOL CFX_Edit::Redo() { |
| 3550 { | 2894 if (m_bEnableUndo) { |
| 3551 m_Undo.AddItem(pUndoItem); | 2895 if (m_Undo.CanRedo()) { |
| 2896 m_Undo.Redo(); |
| 2897 return TRUE; |
| 2898 } |
| 2899 } |
| 2900 |
| 2901 return FALSE; |
| 2902 } |
| 2903 |
| 2904 FX_BOOL CFX_Edit::Undo() { |
| 2905 if (m_bEnableUndo) { |
| 2906 if (m_Undo.CanUndo()) { |
| 2907 m_Undo.Undo(); |
| 2908 return TRUE; |
| 2909 } |
| 2910 } |
| 2911 |
| 2912 return FALSE; |
| 2913 } |
| 2914 |
| 2915 void CFX_Edit::SetCaretOrigin() { |
| 2916 if (m_pVT->IsValid()) { |
| 2917 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 2918 pIterator->SetAt(m_wpCaret); |
| 2919 CPVT_Word word; |
| 2920 CPVT_Line line; |
| 2921 if (pIterator->GetWord(word)) { |
| 2922 m_ptCaret.x = word.ptWord.x + word.fWidth; |
| 2923 m_ptCaret.y = word.ptWord.y; |
| 2924 } else if (pIterator->GetLine(line)) { |
| 2925 m_ptCaret.x = line.ptLine.x; |
| 2926 m_ptCaret.y = line.ptLine.y; |
| 2927 } |
| 2928 } |
| 2929 } |
| 2930 } |
| 2931 |
| 2932 int32_t CFX_Edit::WordPlaceToWordIndex(const CPVT_WordPlace& place) const { |
| 2933 if (m_pVT->IsValid()) |
| 2934 return m_pVT->WordPlaceToWordIndex(place); |
| 2935 |
| 2936 return -1; |
| 2937 } |
| 2938 |
| 2939 CPVT_WordPlace CFX_Edit::WordIndexToWordPlace(int32_t index) const { |
| 2940 if (m_pVT->IsValid()) |
| 2941 return m_pVT->WordIndexToWordPlace(index); |
| 2942 |
| 2943 return CPVT_WordPlace(); |
| 2944 } |
| 2945 |
| 2946 FX_BOOL CFX_Edit::IsTextFull() const { |
| 2947 int32_t nTotalWords = m_pVT->GetTotalWords(); |
| 2948 int32_t nLimitChar = m_pVT->GetLimitChar(); |
| 2949 int32_t nCharArray = m_pVT->GetCharArray(); |
| 2950 |
| 2951 return IsTextOverflow() || (nLimitChar > 0 && nTotalWords >= nLimitChar) || |
| 2952 (nCharArray > 0 && nTotalWords >= nCharArray); |
| 2953 } |
| 2954 |
| 2955 FX_BOOL CFX_Edit::IsTextOverflow() const { |
| 2956 if (!m_bEnableScroll && !m_bEnableOverflow) { |
| 2957 CPDF_Rect rcPlate = m_pVT->GetPlateRect(); |
| 2958 CPDF_Rect rcContent = m_pVT->GetContentRect(); |
| 2959 |
| 2960 if (m_pVT->IsMultiLine() && GetTotalLines() > 1) { |
| 2961 if (FX_EDIT_IsFloatBigger(rcContent.Height(), rcPlate.Height())) |
| 2962 return TRUE; |
| 2963 } |
| 2964 |
| 2965 if (FX_EDIT_IsFloatBigger(rcContent.Width(), rcPlate.Width())) |
| 2966 return TRUE; |
| 2967 } |
| 2968 |
| 2969 return FALSE; |
| 2970 } |
| 2971 |
| 2972 CPVT_WordPlace CFX_Edit::GetLineBeginPlace(const CPVT_WordPlace& place) const { |
| 2973 return m_pVT->GetLineBeginPlace(place); |
| 2974 } |
| 2975 |
| 2976 CPVT_WordPlace CFX_Edit::GetLineEndPlace(const CPVT_WordPlace& place) const { |
| 2977 return m_pVT->GetLineEndPlace(place); |
| 2978 } |
| 2979 |
| 2980 CPVT_WordPlace CFX_Edit::GetSectionBeginPlace( |
| 2981 const CPVT_WordPlace& place) const { |
| 2982 return m_pVT->GetSectionBeginPlace(place); |
| 2983 } |
| 2984 |
| 2985 CPVT_WordPlace CFX_Edit::GetSectionEndPlace(const CPVT_WordPlace& place) const { |
| 2986 return m_pVT->GetSectionEndPlace(place); |
| 2987 } |
| 2988 |
| 2989 FX_BOOL CFX_Edit::CanUndo() const { |
| 2990 if (m_bEnableUndo) { |
| 2991 return m_Undo.CanUndo(); |
| 2992 } |
| 2993 |
| 2994 return FALSE; |
| 2995 } |
| 2996 |
| 2997 FX_BOOL CFX_Edit::CanRedo() const { |
| 2998 if (m_bEnableUndo) { |
| 2999 return m_Undo.CanRedo(); |
| 3000 } |
| 3001 |
| 3002 return FALSE; |
| 3003 } |
| 3004 |
| 3005 FX_BOOL CFX_Edit::IsModified() const { |
| 3006 if (m_bEnableUndo) { |
| 3007 return m_Undo.IsModified(); |
| 3008 } |
| 3009 |
| 3010 return FALSE; |
| 3011 } |
| 3012 |
| 3013 void CFX_Edit::EnableRefresh(FX_BOOL bRefresh) { |
| 3014 m_bEnableRefresh = bRefresh; |
| 3015 } |
| 3016 |
| 3017 void CFX_Edit::EnableUndo(FX_BOOL bUndo) { |
| 3018 m_bEnableUndo = bUndo; |
| 3019 } |
| 3020 |
| 3021 void CFX_Edit::EnableNotify(FX_BOOL bNotify) { |
| 3022 m_bNotify = bNotify; |
| 3023 } |
| 3024 |
| 3025 void CFX_Edit::EnableOprNotify(FX_BOOL bNotify) { |
| 3026 m_bOprNotify = bNotify; |
| 3027 } |
| 3028 |
| 3029 FX_FLOAT CFX_Edit::GetLineTop(const CPVT_WordPlace& place) const { |
| 3030 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 3031 CPVT_WordPlace wpOld = pIterator->GetAt(); |
| 3032 |
| 3033 pIterator->SetAt(place); |
| 3034 CPVT_Line line; |
| 3035 pIterator->GetLine(line); |
| 3036 |
| 3037 pIterator->SetAt(wpOld); |
| 3038 |
| 3039 return line.ptLine.y + line.fLineAscent; |
| 3040 } |
| 3041 |
| 3042 return 0.0f; |
| 3043 } |
| 3044 |
| 3045 FX_FLOAT CFX_Edit::GetLineBottom(const CPVT_WordPlace& place) const { |
| 3046 if (IPDF_VariableText_Iterator* pIterator = m_pVT->GetIterator()) { |
| 3047 CPVT_WordPlace wpOld = pIterator->GetAt(); |
| 3048 |
| 3049 pIterator->SetAt(place); |
| 3050 CPVT_Line line; |
| 3051 pIterator->GetLine(line); |
| 3052 |
| 3053 pIterator->SetAt(wpOld); |
| 3054 |
| 3055 return line.ptLine.y + line.fLineDescent; |
| 3056 } |
| 3057 |
| 3058 return 0.0f; |
| 3059 } |
| 3060 |
| 3061 CPVT_WordPlace CFX_Edit::DoInsertText(const CPVT_WordPlace& place, |
| 3062 const FX_WCHAR* text, |
| 3063 int32_t charset, |
| 3064 const CPVT_SecProps* pSecProps, |
| 3065 const CPVT_WordProps* pWordProps) { |
| 3066 CPVT_WordPlace wp = place; |
| 3067 |
| 3068 if (m_pVT->IsValid()) { |
| 3069 CFX_WideString sText = text; |
| 3070 |
| 3071 for (int32_t i = 0, sz = sText.GetLength(); i < sz; i++) { |
| 3072 FX_WORD word = sText[i]; |
| 3073 switch (word) { |
| 3074 case 0x0D: |
| 3075 wp = m_pVT->InsertSection(wp, pSecProps, pWordProps); |
| 3076 if (sText[i + 1] == 0x0A) |
| 3077 i++; |
| 3078 break; |
| 3079 case 0x0A: |
| 3080 wp = m_pVT->InsertSection(wp, pSecProps, pWordProps); |
| 3081 if (sText[i + 1] == 0x0D) |
| 3082 i++; |
| 3083 break; |
| 3084 case 0x09: |
| 3085 word = 0x20; |
| 3086 default: |
| 3087 wp = m_pVT->InsertWord(wp, word, GetCharSetFromUnicode(word, charset), |
| 3088 pWordProps); |
| 3089 break; |
| 3090 } |
| 3091 } |
| 3092 } |
| 3093 |
| 3094 return wp; |
| 3095 } |
| 3096 |
| 3097 int32_t CFX_Edit::GetCharSetFromUnicode(FX_WORD word, int32_t nOldCharset) { |
| 3098 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) |
| 3099 return pFontMap->CharSetFromUnicode(word, nOldCharset); |
| 3100 return nOldCharset; |
| 3101 } |
| 3102 |
| 3103 void CFX_Edit::BeginGroupUndo(const CFX_WideString& sTitle) { |
| 3104 ASSERT(m_pGroupUndoItem == NULL); |
| 3105 |
| 3106 m_pGroupUndoItem = new CFX_Edit_GroupUndoItem(sTitle); |
| 3107 } |
| 3108 |
| 3109 void CFX_Edit::EndGroupUndo() { |
| 3110 ASSERT(m_pGroupUndoItem != NULL); |
| 3111 |
| 3112 m_pGroupUndoItem->UpdateItems(); |
| 3113 m_Undo.AddItem(m_pGroupUndoItem); |
| 3114 if (m_bOprNotify && m_pOprNotify) |
| 3115 m_pOprNotify->OnAddUndo(m_pGroupUndoItem); |
| 3116 m_pGroupUndoItem = NULL; |
| 3117 } |
| 3118 |
| 3119 void CFX_Edit::AddEditUndoItem(CFX_Edit_UndoItem* pEditUndoItem) { |
| 3120 if (m_pGroupUndoItem) |
| 3121 m_pGroupUndoItem->AddUndoItem(pEditUndoItem); |
| 3122 else { |
| 3123 m_Undo.AddItem(pEditUndoItem); |
| 3552 if (m_bOprNotify && m_pOprNotify) | 3124 if (m_bOprNotify && m_pOprNotify) |
| 3553 m_pOprNotify->OnAddUndo(pUndoItem); | 3125 m_pOprNotify->OnAddUndo(pEditUndoItem); |
| 3554 } | 3126 } |
| 3555 | 3127 } |
| 3128 |
| 3129 void CFX_Edit::AddUndoItem(IFX_Edit_UndoItem* pUndoItem) { |
| 3130 m_Undo.AddItem(pUndoItem); |
| 3131 if (m_bOprNotify && m_pOprNotify) |
| 3132 m_pOprNotify->OnAddUndo(pUndoItem); |
| 3133 } |
| OLD | NEW |