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