OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../../core/include/fxcrt/fx_safe_types.h" | 7 #include "../../../core/include/fxcrt/fx_safe_types.h" |
8 #include "../../../core/include/fxcrt/fx_xml.h" | 8 #include "../../../core/include/fxcrt/fx_xml.h" |
9 #include "../../include/pdfwindow/PDFWindow.h" | 9 #include "../../include/pdfwindow/PDFWindow.h" |
10 #include "../../include/pdfwindow/PWL_Caret.h" | 10 #include "../../include/pdfwindow/PWL_Caret.h" |
11 #include "../../include/pdfwindow/PWL_Edit.h" | 11 #include "../../include/pdfwindow/PWL_Edit.h" |
12 #include "../../include/pdfwindow/PWL_EditCtrl.h" | 12 #include "../../include/pdfwindow/PWL_EditCtrl.h" |
13 #include "../../include/pdfwindow/PWL_FontMap.h" | 13 #include "../../include/pdfwindow/PWL_FontMap.h" |
14 #include "../../include/pdfwindow/PWL_ScrollBar.h" | 14 #include "../../include/pdfwindow/PWL_ScrollBar.h" |
15 #include "../../include/pdfwindow/PWL_Utils.h" | 15 #include "../../include/pdfwindow/PWL_Utils.h" |
16 #include "../../include/pdfwindow/PWL_Wnd.h" | 16 #include "../../include/pdfwindow/PWL_Wnd.h" |
17 | 17 |
18 /* ---------------------------- CPWL_Edit ------------------------------ */ | 18 /* ---------------------------- CPWL_Edit ------------------------------ */ |
19 | 19 |
20 CPWL_Edit::CPWL_Edit() : m_pFillerNotify(NULL), | 20 CPWL_Edit::CPWL_Edit() |
21 m_pSpellCheck(NULL), | 21 : m_pFillerNotify(NULL), m_pSpellCheck(NULL), m_bFocus(FALSE) { |
22 m_bFocus(FALSE) | 22 m_pFormFiller = NULL; |
23 { | 23 } |
24 m_pFormFiller = NULL; | 24 |
25 } | 25 CPWL_Edit::~CPWL_Edit() { |
26 | 26 ASSERT(m_bFocus == FALSE); |
27 CPWL_Edit::~CPWL_Edit() | 27 } |
28 { | 28 |
29 ASSERT(m_bFocus == FALSE); | 29 CFX_ByteString CPWL_Edit::GetClassName() const { |
30 } | 30 return PWL_CLASSNAME_EDIT; |
31 | 31 } |
32 CFX_ByteString CPWL_Edit::GetClassName() const | 32 |
33 { | 33 void CPWL_Edit::OnDestroy() {} |
34 return PWL_CLASSNAME_EDIT; | 34 |
35 } | 35 void CPWL_Edit::SetText(const FX_WCHAR* csText) { |
36 | 36 CFX_WideString swText = csText; |
37 void CPWL_Edit::OnDestroy() | 37 |
38 { | 38 if (HasFlag(PES_RICH)) { |
39 } | 39 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); |
40 | 40 |
41 void CPWL_Edit::SetText(const FX_WCHAR* csText) | 41 if (CXML_Element* pXML = |
42 { | 42 CXML_Element::Parse(sValue.c_str(), sValue.GetLength())) { |
43 CFX_WideString swText = csText; | 43 int32_t nCount = pXML->CountChildren(); |
44 | 44 FX_BOOL bFirst = TRUE; |
45 if (HasFlag(PES_RICH)) | 45 |
46 { | 46 swText.Empty(); |
47 CFX_ByteString sValue = CFX_ByteString::FromUnicode(swText); | 47 |
48 | 48 for (int32_t i = 0; i < nCount; i++) { |
49 if (CXML_Element * pXML = CXML_Element::Parse(sValue.c_str(), sV
alue.GetLength())) | 49 if (CXML_Element* pSubElement = pXML->GetElement(i)) { |
50 { | 50 CFX_ByteString tag = pSubElement->GetTagName(); |
51 int32_t nCount = pXML->CountChildren(); | 51 if (tag.EqualNoCase("p")) { |
52 FX_BOOL bFirst = TRUE; | 52 int nChild = pSubElement->CountChildren(); |
53 | 53 CFX_WideString swSection; |
54 swText.Empty(); | 54 for (int32_t j = 0; j < nChild; j++) { |
55 | 55 swSection += pSubElement->GetContent(j); |
56 for (int32_t i=0; i<nCount; i++) | 56 } |
57 { | 57 |
58 if (CXML_Element * pSubElement = pXML->GetElemen
t(i)) | 58 if (bFirst) |
59 { | 59 bFirst = FALSE; |
60 CFX_ByteString tag=pSubElement->GetTagNa
me(); | 60 else |
61 if (tag.EqualNoCase("p")) | 61 swText += FWL_VKEY_Return; |
62 { | 62 swText += swSection; |
63 int nChild = pSubElement->CountC
hildren(); | 63 } |
64 CFX_WideString swSection; | 64 } |
65 for(int32_t j=0; j<nChild; j++) | 65 } |
66 { | 66 |
67 swSection += pSubElement
->GetContent(j); | 67 delete pXML; |
68 } | 68 } |
69 | 69 } |
70 if (bFirst)bFirst = FALSE; | 70 |
71 else | 71 m_pEdit->SetText(swText.c_str()); |
72 swText += FWL_VKEY_Retur
n; | 72 } |
73 swText += swSection; | 73 |
74 } | 74 void CPWL_Edit::RePosChildWnd() { |
75 } | 75 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
76 } | 76 CPDF_Rect rcWindow = m_rcOldWindow; |
77 | 77 CPDF_Rect rcVScroll = |
78 delete pXML; | 78 CPDF_Rect(rcWindow.right, rcWindow.bottom, |
79 } | 79 rcWindow.right + PWL_SCROLLBAR_WIDTH, rcWindow.top); |
80 } | 80 pVSB->Move(rcVScroll, TRUE, FALSE); |
81 | 81 } |
82 m_pEdit->SetText(swText.c_str()); | 82 |
83 } | 83 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) |
84 | 84 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
85 void CPWL_Edit::RePosChildWnd() | 85 GetClientRect(), 1.0f)); //+1 for caret beside border |
86 { | 86 |
87 if (CPWL_ScrollBar * pVSB = GetVScrollBar()) { | 87 CPWL_EditCtrl::RePosChildWnd(); |
88 CPDF_Rect rcWindow = m_rcOldWindow; | 88 } |
89 CPDF_Rect rcVScroll = CPDF_Rect(rcWindow.right, | 89 |
90 rcWindow.bottom, | 90 CPDF_Rect CPWL_Edit::GetClientRect() const { |
91 rcWindow.right + PWL_SCROLLBAR_WIDTH, | 91 CPDF_Rect rcClient = CPWL_Utils::DeflateRect( |
92 rcWindow.top); | 92 GetWindowRect(), (FX_FLOAT)(GetBorderWidth() + GetInnerBorderWidth())); |
93 pVSB->Move(rcVScroll, TRUE, FALSE); | 93 |
94 } | 94 if (CPWL_ScrollBar* pVSB = GetVScrollBar()) { |
95 | 95 if (pVSB->IsVisible()) { |
96 if (m_pEditCaret && !HasFlag(PES_TEXTOVERFLOW)) | 96 rcClient.right -= PWL_SCROLLBAR_WIDTH; |
97 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetClientRect(
),1.0f)); //+1 for caret beside border | 97 } |
98 | 98 } |
99 CPWL_EditCtrl::RePosChildWnd(); | 99 |
100 } | 100 return rcClient; |
101 | 101 } |
102 CPDF_Rect CPWL_Edit::GetClientRect() const | 102 |
103 { | 103 void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, |
104 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(GetWindowRect(),(FX_FLOAT)(
GetBorderWidth()+GetInnerBorderWidth())); | 104 FX_BOOL bPaint /* = TRUE*/) { |
105 | 105 m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint); |
106 if (CPWL_ScrollBar * pVSB = GetVScrollBar()) | 106 } |
107 { | 107 |
108 if (pVSB->IsVisible()) | 108 void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, |
109 { | 109 FX_BOOL bPaint /* = TRUE*/) { |
110 rcClient.right -= PWL_SCROLLBAR_WIDTH; | 110 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); |
111 } | 111 } |
112 } | 112 |
113 | 113 FX_BOOL CPWL_Edit::CanSelectAll() const { |
114 return rcClient; | 114 return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); |
115 } | 115 } |
116 | 116 |
117 void CPWL_Edit::SetAlignFormatH(PWL_EDIT_ALIGNFORMAT_H nFormat, FX_BOOL bPaint/*
= TRUE*/) | 117 FX_BOOL CPWL_Edit::CanClear() const { |
118 { | 118 return !IsReadOnly() && m_pEdit->IsSelected(); |
119 m_pEdit->SetAlignmentH((int32_t)nFormat, bPaint); | 119 } |
120 } | 120 |
121 | 121 FX_BOOL CPWL_Edit::CanCopy() const { |
122 void CPWL_Edit::SetAlignFormatV(PWL_EDIT_ALIGNFORMAT_V nFormat, FX_BOOL bPaint/*
= TRUE*/) | 122 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && |
123 { | 123 m_pEdit->IsSelected(); |
124 m_pEdit->SetAlignmentV((int32_t)nFormat, bPaint); | 124 } |
125 } | 125 |
126 | 126 FX_BOOL CPWL_Edit::CanCut() const { |
127 FX_BOOL CPWL_Edit::CanSelectAll() const | 127 return CanCopy() && !IsReadOnly(); |
128 { | 128 } |
129 return GetSelectWordRange() != m_pEdit->GetWholeWordRange(); | 129 |
130 } | 130 FX_BOOL CPWL_Edit::CanPaste() const { |
131 | 131 if (IsReadOnly()) |
132 FX_BOOL CPWL_Edit::CanClear() const | 132 return FALSE; |
133 { | 133 |
134 return !IsReadOnly() && m_pEdit->IsSelected(); | 134 CFX_WideString swClipboard; |
135 } | 135 if (IFX_SystemHandler* pSH = GetSystemHandler()) |
136 | 136 swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
137 FX_BOOL CPWL_Edit::CanCopy() const | 137 |
138 { | 138 return !swClipboard.IsEmpty(); |
139 return !HasFlag(PES_PASSWORD) && !HasFlag(PES_NOREAD) && m_pEdit->IsSel
ected(); | 139 } |
140 } | 140 |
141 | 141 void CPWL_Edit::CopyText() { |
142 FX_BOOL CPWL_Edit::CanCut() const | 142 if (!CanCopy()) |
143 { | 143 return; |
144 return CanCopy() && !IsReadOnly(); | 144 |
145 } | 145 CFX_WideString str = m_pEdit->GetSelText(); |
146 | 146 |
147 FX_BOOL CPWL_Edit::CanPaste() const | 147 if (IFX_SystemHandler* pSH = GetSystemHandler()) |
148 { | 148 pSH->SetClipboardText(GetAttachedHWnd(), str); |
149 if (IsReadOnly()) return FALSE; | 149 } |
150 | 150 |
151 CFX_WideString swClipboard; | 151 void CPWL_Edit::PasteText() { |
152 if (IFX_SystemHandler* pSH = GetSystemHandler()) | 152 if (!CanPaste()) |
153 swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); | 153 return; |
154 | 154 |
155 return !swClipboard.IsEmpty(); | 155 CFX_WideString swClipboard; |
156 } | 156 if (IFX_SystemHandler* pSH = GetSystemHandler()) |
157 | 157 swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); |
158 void CPWL_Edit::CopyText() | 158 |
159 { | 159 if (m_pFillerNotify) { |
160 if (!CanCopy()) return; | 160 FX_BOOL bRC = TRUE; |
161 | 161 FX_BOOL bExit = FALSE; |
162 CFX_WideString str = m_pEdit->GetSelText(); | 162 CFX_WideString strChangeEx; |
163 | 163 int nSelStart = 0; |
164 if (IFX_SystemHandler* pSH = GetSystemHandler()) | 164 int nSelEnd = 0; |
165 pSH->SetClipboardText(GetAttachedHWnd(), str); | 165 GetSel(nSelStart, nSelEnd); |
166 } | 166 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), 0, swClipboard, |
167 | 167 strChangeEx, nSelStart, nSelEnd, TRUE, |
168 void CPWL_Edit::PasteText() | 168 bRC, bExit, 0); |
169 { | 169 if (!bRC) |
170 if (!CanPaste()) return; | 170 return; |
171 | 171 if (bExit) |
172 CFX_WideString swClipboard; | 172 return; |
173 if (IFX_SystemHandler* pSH = GetSystemHandler()) | 173 } |
174 swClipboard = pSH->GetClipboardText(GetAttachedHWnd()); | 174 |
175 | 175 if (swClipboard.GetLength() > 0) { |
176 if (m_pFillerNotify) | 176 Clear(); |
177 { | 177 InsertText(swClipboard.c_str()); |
178 FX_BOOL bRC = TRUE; | 178 } |
179 FX_BOOL bExit = FALSE; | 179 |
180 CFX_WideString strChangeEx; | 180 if (m_pFillerNotify) { |
181 int nSelStart = 0; | 181 FX_BOOL bExit = FALSE; |
182 int nSelEnd = 0; | 182 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit, 0); |
183 GetSel(nSelStart, nSelEnd); | 183 if (bExit) |
184 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), 0 ,
swClipboard, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, 0); | 184 return; |
185 if (!bRC) return; | 185 } |
186 if (bExit) return; | 186 } |
187 } | 187 |
188 | 188 void CPWL_Edit::CutText() { |
189 if (swClipboard.GetLength() > 0) | 189 if (!CanCut()) |
190 { | 190 return; |
191 Clear(); | 191 |
192 InsertText(swClipboard.c_str()); | 192 CFX_WideString str = m_pEdit->GetSelText(); |
193 } | 193 |
194 | 194 if (IFX_SystemHandler* pSH = GetSystemHandler()) |
195 if (m_pFillerNotify) | 195 pSH->SetClipboardText(GetAttachedHWnd(), str); |
196 { | 196 |
197 FX_BOOL bExit = FALSE; | 197 m_pEdit->Clear(); |
198 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit
,0); | 198 } |
199 if (bExit) return; | 199 |
200 } | 200 void CPWL_Edit::OnCreated() { |
201 } | 201 CPWL_EditCtrl::OnCreated(); |
202 | 202 |
203 void CPWL_Edit::CutText() | 203 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
204 { | 204 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); |
205 if (!CanCut()) return; | 205 pScroll->SetTransparency(255); |
206 | 206 } |
207 CFX_WideString str = m_pEdit->GetSelText(); | 207 |
208 | 208 SetParamByFlag(); |
209 if (IFX_SystemHandler* pSH = GetSystemHandler()) | 209 |
210 pSH->SetClipboardText(GetAttachedHWnd(), str); | 210 m_rcOldWindow = GetWindowRect(); |
211 | 211 |
212 m_pEdit->Clear(); | 212 m_pEdit->SetOprNotify(this); |
213 } | 213 m_pEdit->EnableOprNotify(TRUE); |
214 | 214 } |
215 void CPWL_Edit::OnCreated() | 215 |
216 { | 216 void CPWL_Edit::SetParamByFlag() { |
217 CPWL_EditCtrl::OnCreated(); | 217 if (HasFlag(PES_RIGHT)) { |
218 | 218 m_pEdit->SetAlignmentH(2, FALSE); |
219 if (CPWL_ScrollBar * pScroll = GetVScrollBar()) | 219 } else if (HasFlag(PES_MIDDLE)) { |
220 { | 220 m_pEdit->SetAlignmentH(1, FALSE); |
221 pScroll->RemoveFlag(PWS_AUTOTRANSPARENT); | 221 } else { |
222 pScroll->SetTransparency(255); | 222 m_pEdit->SetAlignmentH(0, FALSE); |
223 } | 223 } |
224 | 224 |
225 SetParamByFlag(); | 225 if (HasFlag(PES_BOTTOM)) { |
226 | 226 m_pEdit->SetAlignmentV(2, FALSE); |
227 m_rcOldWindow = GetWindowRect(); | 227 } else if (HasFlag(PES_CENTER)) { |
228 | 228 m_pEdit->SetAlignmentV(1, FALSE); |
229 m_pEdit->SetOprNotify(this); | 229 } else { |
230 m_pEdit->EnableOprNotify(TRUE); | 230 m_pEdit->SetAlignmentV(0, FALSE); |
231 } | 231 } |
232 | 232 |
233 void CPWL_Edit::SetParamByFlag() | 233 if (HasFlag(PES_PASSWORD)) { |
234 { | 234 m_pEdit->SetPasswordChar('*', FALSE); |
235 if (HasFlag(PES_RIGHT)) | 235 } |
236 { | 236 |
237 m_pEdit->SetAlignmentH(2, FALSE); | 237 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE); |
238 } | 238 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE); |
239 else if (HasFlag(PES_MIDDLE)) | 239 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE); |
240 { | 240 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE); |
241 m_pEdit->SetAlignmentH(1, FALSE); | 241 m_pEdit->EnableUndo(HasFlag(PES_UNDO)); |
242 } | 242 |
243 else | 243 if (HasFlag(PES_TEXTOVERFLOW)) { |
244 { | 244 SetClipRect(CPDF_Rect(0.0f, 0.0f, 0.0f, 0.0f)); |
245 m_pEdit->SetAlignmentH(0, FALSE); | 245 m_pEdit->SetTextOverflow(TRUE, FALSE); |
246 } | 246 } else { |
247 | 247 if (m_pEditCaret) { |
248 if (HasFlag(PES_BOTTOM)) | 248 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect( |
249 { | 249 GetClientRect(), 1.0f)); //+1 for caret beside border |
250 m_pEdit->SetAlignmentV(2, FALSE); | 250 } |
251 } | 251 } |
252 else if (HasFlag(PES_CENTER)) | 252 |
253 { | 253 if (HasFlag(PES_SPELLCHECK)) { |
254 m_pEdit->SetAlignmentV(1, FALSE); | 254 m_pSpellCheck = GetCreationParam().pSpellCheck; |
255 } | 255 } |
256 else | 256 } |
257 { | 257 |
258 m_pEdit->SetAlignmentV(0, FALSE); | 258 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf& sAppStream) { |
259 } | 259 CPWL_Wnd::GetThisAppearanceStream(sAppStream); |
260 | 260 |
261 if (HasFlag(PES_PASSWORD)) | 261 CPDF_Rect rcClient = GetClientRect(); |
262 { | 262 CFX_ByteTextBuf sLine; |
263 m_pEdit->SetPasswordChar('*', FALSE); | 263 |
264 } | 264 int32_t nCharArray = m_pEdit->GetCharArray(); |
265 | 265 |
266 m_pEdit->SetMultiLine(HasFlag(PES_MULTILINE), FALSE); | 266 if (nCharArray > 0) { |
267 m_pEdit->SetAutoReturn(HasFlag(PES_AUTORETURN), FALSE); | 267 switch (GetBorderStyle()) { |
268 m_pEdit->SetAutoFontSize(HasFlag(PWS_AUTOFONTSIZE), FALSE); | 268 case PBS_SOLID: { |
269 m_pEdit->SetAutoScroll(HasFlag(PES_AUTOSCROLL), FALSE); | 269 sLine << "q\n" << GetBorderWidth() << " w\n" |
270 m_pEdit->EnableUndo(HasFlag(PES_UNDO)); | 270 << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
271 | 271 << " 2 J 0 j\n"; |
272 if (HasFlag(PES_TEXTOVERFLOW)) | 272 |
273 { | 273 for (int32_t i = 1; i < nCharArray; i++) { |
274 SetClipRect(CPDF_Rect(0.0f,0.0f,0.0f,0.0f)); | 274 sLine << rcClient.left + |
275 m_pEdit->SetTextOverflow(TRUE, FALSE); | 275 ((rcClient.right - rcClient.left) / nCharArray) * i |
276 } | 276 << " " << rcClient.bottom << " m\n" |
277 else | 277 << rcClient.left + |
278 { | 278 ((rcClient.right - rcClient.left) / nCharArray) * i |
279 if (m_pEditCaret) | 279 << " " << rcClient.top << " l S\n"; |
280 { | 280 } |
281 m_pEditCaret->SetClipRect(CPWL_Utils::InflateRect(GetCli
entRect(),1.0f)); //+1 for caret beside border | 281 |
282 } | 282 sLine << "Q\n"; |
283 } | 283 } break; |
284 | 284 case PBS_DASH: { |
285 if (HasFlag(PES_SPELLCHECK)) | 285 sLine << "q\n" << GetBorderWidth() << " w\n" |
286 { | 286 << CPWL_Utils::GetColorAppStream(GetBorderColor(), FALSE) |
287 m_pSpellCheck = GetCreationParam().pSpellCheck; | 287 << " 2 J 0 j\n" |
288 } | 288 << "[" << GetBorderDash().nDash << " " << GetBorderDash().nGap |
289 } | 289 << "] " << GetBorderDash().nPhase << " d\n"; |
290 | 290 |
291 void CPWL_Edit::GetThisAppearanceStream(CFX_ByteTextBuf & sAppStream) | 291 for (int32_t i = 1; i < nCharArray; i++) { |
292 { | 292 sLine << rcClient.left + |
293 CPWL_Wnd::GetThisAppearanceStream(sAppStream); | 293 ((rcClient.right - rcClient.left) / nCharArray) * i |
294 | 294 << " " << rcClient.bottom << " m\n" |
295 CPDF_Rect rcClient = GetClientRect(); | 295 << rcClient.left + |
296 CFX_ByteTextBuf sLine; | 296 ((rcClient.right - rcClient.left) / nCharArray) * i |
297 | 297 << " " << rcClient.top << " l S\n"; |
298 int32_t nCharArray = m_pEdit->GetCharArray(); | 298 } |
299 | 299 |
300 if (nCharArray > 0) | 300 sLine << "Q\n"; |
301 { | 301 } break; |
302 switch (GetBorderStyle()) | 302 } |
303 { | 303 } |
304 case PBS_SOLID: | 304 |
305 { | 305 sAppStream << sLine; |
306 sLine << "q\n" << GetBorderWidth() << " w\n" | 306 |
307 << CPWL_Utils::GetColorAppStream(GetBord
erColor(),FALSE) << " 2 J 0 j\n"; | 307 CFX_ByteTextBuf sText; |
308 | 308 |
309 for (int32_t i=1;i<nCharArray;i++) | 309 CPDF_Point ptOffset = CPDF_Point(0.0f, 0.0f); |
310 { | 310 |
311 sLine << rcClient.left + ((rcClient.righ
t - rcClient.left)/nCharArray)*i << " " | 311 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); |
312 << rcClient.bottom << " m\n" | 312 CPVT_WordRange wrSelect = GetSelectWordRange(); |
313 << rcClient.left + ((rcClient.ri
ght - rcClient.left)/nCharArray)*i << " " | 313 CPVT_WordRange wrVisible = |
314 << rcClient.top << " l S\n"; | 314 (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdit->GetVisibleWordRange()); |
315 } | 315 CPVT_WordRange wrSelBefore(wrWhole.BeginPos, wrSelect.BeginPos); |
316 | 316 CPVT_WordRange wrSelAfter(wrSelect.EndPos, wrWhole.EndPos); |
317 sLine << "Q\n"; | 317 |
318 } | 318 CPVT_WordRange wrTemp = |
319 break; | 319 CPWL_Utils::OverlapWordRange(GetSelectWordRange(), wrVisible); |
320 case PBS_DASH: | 320 CFX_ByteString sEditSel = |
321 { | 321 CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wrTemp); |
322 sLine << "q\n" << GetBorderWidth() << " w\n" | 322 |
323 << CPWL_Utils::GetColorAppStream(GetBord
erColor(),FALSE) << " 2 J 0 j\n" | 323 if (sEditSel.GetLength() > 0) |
324 << "[" << GetBorderDash().nDash << " " | 324 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR) |
325 << GetBorderDash().nGap << "] " | 325 << sEditSel; |
326 << GetBorderDash().nPhase << " d\n"; | 326 |
327 | 327 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelBefore); |
328 for (int32_t i=1;i<nCharArray;i++) | 328 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream( |
329 { | 329 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
330 sLine << rcClient.left + ((rcClient.righ
t - rcClient.left)/nCharArray)*i << " " | 330 m_pEdit->GetPasswordChar()); |
331 << rcClient.bottom << " m\n" | 331 |
332 << rcClient.left + ((rcClient.ri
ght - rcClient.left)/nCharArray)*i << " " | 332 if (sEditBefore.GetLength() > 0) |
333 << rcClient.top << " l S\n"; | 333 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) |
334 } | 334 << sEditBefore << "ET\n"; |
335 | 335 |
336 sLine << "Q\n"; | 336 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelect); |
337 } | 337 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream( |
338 break; | 338 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
339 } | 339 m_pEdit->GetPasswordChar()); |
340 } | 340 |
341 | 341 if (sEditMid.GetLength() > 0) |
342 sAppStream << sLine; | 342 sText << "BT\n" |
343 | 343 << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_GRAY, 1)) |
344 CFX_ByteTextBuf sText; | 344 << sEditMid << "ET\n"; |
345 | 345 |
346 CPDF_Point ptOffset = CPDF_Point(0.0f,0.0f); | 346 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible, wrSelAfter); |
347 | 347 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream( |
348 CPVT_WordRange wrWhole = m_pEdit->GetWholeWordRange(); | 348 m_pEdit, ptOffset, &wrTemp, !HasFlag(PES_CHARARRAY), |
349 CPVT_WordRange wrSelect = GetSelectWordRange(); | 349 m_pEdit->GetPasswordChar()); |
350 CPVT_WordRange wrVisible = (HasFlag(PES_TEXTOVERFLOW) ? wrWhole : m_pEdi
t->GetVisibleWordRange()); | 350 |
351 CPVT_WordRange wrSelBefore(wrWhole.BeginPos,wrSelect.BeginPos); | 351 if (sEditAfter.GetLength() > 0) |
352 CPVT_WordRange wrSelAfter(wrSelect.EndPos,wrWhole.EndPos); | 352 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) |
353 | 353 << sEditAfter << "ET\n"; |
354 CPVT_WordRange wrTemp = CPWL_Utils::OverlapWordRange(GetSelectWordRange(
),wrVisible); | 354 |
355 CFX_ByteString sEditSel = CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOff
set, | 355 if (HasFlag(PES_SPELLCHECK)) { |
356 &wrTemp); | 356 CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream( |
357 | 357 m_pEdit, m_pSpellCheck, ptOffset, &wrVisible); |
358 if (sEditSel.GetLength() > 0) | 358 if (sSpellCheck.GetLength() > 0) |
359 sText << CPWL_Utils::GetColorAppStream(PWL_DEFAULT_SELBACKCOLOR)
<< sEditSel ; | 359 sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORTYPE_RGB, 1, 0, 0), |
360 | 360 FALSE) |
361 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelBefore); | 361 << sSpellCheck; |
362 CFX_ByteString sEditBefore = CPWL_Utils::GetEditAppStream(m_pEdit, ptOff
set, | 362 } |
363 &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordCh
ar()); | 363 |
364 | 364 if (sText.GetLength() > 0) { |
365 if (sEditBefore.GetLength() > 0) | 365 CPDF_Rect rcClient = GetClientRect(); |
366 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
<< sEditBefore << "ET\n"; | 366 sAppStream << "q\n/Tx BMC\n"; |
367 | 367 |
368 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelect); | 368 if (!HasFlag(PES_TEXTOVERFLOW)) |
369 CFX_ByteString sEditMid = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset
, | 369 sAppStream << rcClient.left << " " << rcClient.bottom << " " |
370 &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordCh
ar()); | 370 << rcClient.right - rcClient.left << " " |
371 | 371 << rcClient.top - rcClient.bottom << " re W n\n"; |
372 if (sEditMid.GetLength() > 0) | 372 |
373 sText << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLO
RTYPE_GRAY,1)) << sEditMid << "ET\n"; | 373 sAppStream << sText; |
374 | 374 |
375 wrTemp = CPWL_Utils::OverlapWordRange(wrVisible,wrSelAfter); | 375 sAppStream << "EMC\nQ\n"; |
376 CFX_ByteString sEditAfter = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffs
et, | 376 } |
377 &wrTemp, !HasFlag(PES_CHARARRAY), m_pEdit->GetPasswordCh
ar()); | 377 } |
378 | 378 |
379 if (sEditAfter.GetLength() > 0) | 379 void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, |
380 sText << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
<< sEditAfter<< "ET\n"; | 380 CPDF_Matrix* pUser2Device) { |
381 | 381 CPWL_Wnd::DrawThisAppearance(pDevice, pUser2Device); |
382 if (HasFlag(PES_SPELLCHECK)) | 382 |
383 { | 383 CPDF_Rect rcClient = GetClientRect(); |
384 CFX_ByteString sSpellCheck = CPWL_Utils::GetSpellCheckAppStream(
m_pEdit, m_pSpellCheck, ptOffset, &wrVisible); | 384 CFX_ByteTextBuf sLine; |
385 if (sSpellCheck.GetLength() > 0) | 385 |
386 sText << CPWL_Utils::GetColorAppStream(CPWL_Color(COLORT
YPE_RGB,1,0,0),FALSE) << sSpellCheck; | 386 int32_t nCharArray = m_pEdit->GetCharArray(); |
387 } | 387 FX_SAFE_INT32 nCharArraySafe = nCharArray; |
388 | 388 nCharArraySafe -= 1; |
389 if (sText.GetLength() > 0) | 389 nCharArraySafe *= 2; |
390 { | 390 |
391 CPDF_Rect rcClient = GetClientRect(); | 391 if (nCharArray > 0 && nCharArraySafe.IsValid()) { |
392 sAppStream << "q\n/Tx BMC\n"; | 392 switch (GetBorderStyle()) { |
393 | 393 case PBS_SOLID: { |
394 if (!HasFlag(PES_TEXTOVERFLOW)) | 394 CFX_GraphStateData gsd; |
395 sAppStream << rcClient.left << " " << rcClient.bottom <<
" " | 395 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
396 << rcClient.right - rcClient.left << " " << rcCl
ient.top - rcClient.bottom << " re W n\n"; | 396 |
397 | 397 CFX_PathData path; |
398 sAppStream << sText; | 398 path.SetPointCount(nCharArraySafe.ValueOrDie()); |
399 | 399 |
400 sAppStream << "EMC\nQ\n"; | 400 for (int32_t i = 0; i < nCharArray - 1; i++) { |
401 } | 401 path.SetPoint( |
402 } | 402 i * 2, |
403 | 403 rcClient.left + |
404 void CPWL_Edit::DrawThisAppearance(CFX_RenderDevice* pDevice, CPDF_Matrix* pUser
2Device) | 404 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
405 { | 405 rcClient.bottom, FXPT_MOVETO); |
406 CPWL_Wnd::DrawThisAppearance(pDevice,pUser2Device); | 406 path.SetPoint( |
407 | 407 i * 2 + 1, |
408 CPDF_Rect rcClient = GetClientRect(); | 408 rcClient.left + |
409 CFX_ByteTextBuf sLine; | 409 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
410 | 410 rcClient.top, FXPT_LINETO); |
411 int32_t nCharArray = m_pEdit->GetCharArray(); | 411 } |
412 FX_SAFE_INT32 nCharArraySafe = nCharArray; | 412 if (path.GetPointCount() > 0) |
413 nCharArraySafe -= 1; | 413 pDevice->DrawPath( |
414 nCharArraySafe *= 2; | 414 &path, pUser2Device, &gsd, 0, |
415 | 415 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
416 if (nCharArray > 0 && nCharArraySafe.IsValid()) | 416 FXFILL_ALTERNATE); |
417 { | 417 } break; |
418 switch (GetBorderStyle()) | 418 case PBS_DASH: { |
419 { | 419 CFX_GraphStateData gsd; |
420 case PBS_SOLID: | 420 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); |
421 { | 421 |
422 CFX_GraphStateData gsd; | 422 gsd.SetDashCount(2); |
423 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); | 423 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().nDash; |
424 | 424 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().nGap; |
425 CFX_PathData path; | 425 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPhase; |
426 path.SetPointCount(nCharArraySafe.ValueOrDie()); | 426 |
427 | 427 CFX_PathData path; |
428 for (int32_t i=0; i<nCharArray-1; i++) | 428 path.SetPointCount(nCharArraySafe.ValueOrDie()); |
429 { | 429 |
430 path.SetPoint(i*2, rcClient.left + ((rcC
lient.right - rcClient.left)/nCharArray)*(i+1), | 430 for (int32_t i = 0; i < nCharArray - 1; i++) { |
431 rcClient.bottom, FXPT_MOVETO); | 431 path.SetPoint( |
432 path.SetPoint(i*2+1, rcClient.left + ((r
cClient.right - rcClient.left)/nCharArray)*(i+1), | 432 i * 2, |
433 rcClient.top, FXPT_LINETO); | 433 rcClient.left + |
434 } | 434 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
435 if (path.GetPointCount() > 0) | 435 rcClient.bottom, FXPT_MOVETO); |
436 pDevice->DrawPath(&path, pUser2Device, &
gsd,0, | 436 path.SetPoint( |
437 CPWL_Utils::PWLColorToFXColor(Ge
tBorderColor(),255), FXFILL_ALTERNATE); | 437 i * 2 + 1, |
438 } | 438 rcClient.left + |
439 break; | 439 ((rcClient.right - rcClient.left) / nCharArray) * (i + 1), |
440 case PBS_DASH: | 440 rcClient.top, FXPT_LINETO); |
441 { | 441 } |
442 CFX_GraphStateData gsd; | 442 if (path.GetPointCount() > 0) |
443 gsd.m_LineWidth = (FX_FLOAT)GetBorderWidth(); | 443 pDevice->DrawPath( |
444 | 444 &path, pUser2Device, &gsd, 0, |
445 gsd.SetDashCount(2); | 445 CPWL_Utils::PWLColorToFXColor(GetBorderColor(), 255), |
446 gsd.m_DashArray[0] = (FX_FLOAT)GetBorderDash().n
Dash; | 446 FXFILL_ALTERNATE); |
447 gsd.m_DashArray[1] = (FX_FLOAT)GetBorderDash().n
Gap; | 447 } break; |
448 gsd.m_DashPhase = (FX_FLOAT)GetBorderDash().nPha
se; | 448 } |
449 | 449 } |
450 CFX_PathData path; | 450 |
451 path.SetPointCount(nCharArraySafe.ValueOrDie()); | 451 CPDF_Rect rcClip; |
452 | 452 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); |
453 for (int32_t i=0; i<nCharArray-1; i++) | 453 CPVT_WordRange* pRange = NULL; |
454 { | 454 |
455 path.SetPoint(i*2, rcClient.left + ((rcC
lient.right - rcClient.left)/nCharArray)*(i+1), | 455 if (!HasFlag(PES_TEXTOVERFLOW)) { |
456 rcClient.bottom, FXPT_MOVETO); | 456 rcClip = GetClientRect(); |
457 path.SetPoint(i*2+1, rcClient.left + ((r
cClient.right - rcClient.left)/nCharArray)*(i+1), | 457 pRange = &wrRange; |
458 rcClient.top, FXPT_LINETO); | 458 } |
459 } | 459 IFX_SystemHandler* pSysHandler = GetSystemHandler(); |
460 if (path.GetPointCount() > 0) | 460 IFX_Edit::DrawEdit( |
461 pDevice->DrawPath(&path, pUser2Device, &
gsd,0, | 461 pDevice, pUser2Device, m_pEdit, |
462 CPWL_Utils::PWLColorToFXColor(Ge
tBorderColor(),255), FXFILL_ALTERNATE); | 462 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
463 } | 463 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTransparency()), |
464 break; | 464 rcClip, CPDF_Point(0.0f, 0.0f), pRange, pSysHandler, m_pFormFiller); |
465 } | 465 |
466 } | 466 if (HasFlag(PES_SPELLCHECK)) { |
467 | 467 CPWL_Utils::DrawEditSpellCheck(pDevice, pUser2Device, m_pEdit, rcClip, |
468 CPDF_Rect rcClip; | 468 CPDF_Point(0.0f, 0.0f), pRange, |
469 CPVT_WordRange wrRange = m_pEdit->GetVisibleWordRange(); | 469 GetCreationParam().pSpellCheck); |
470 CPVT_WordRange* pRange = NULL; | 470 } |
471 | 471 } |
472 if (!HasFlag(PES_TEXTOVERFLOW)) | 472 |
473 { | 473 FX_BOOL CPWL_Edit::OnLButtonDown(const CPDF_Point& point, FX_DWORD nFlag) { |
474 rcClip = GetClientRect(); | 474 CPWL_Wnd::OnLButtonDown(point, nFlag); |
475 pRange = &wrRange; | 475 |
476 } | 476 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
477 IFX_SystemHandler* pSysHandler = GetSystemHandler(); | 477 if (m_bMouseDown) |
478 IFX_Edit::DrawEdit(pDevice,pUser2Device,m_pEdit, | 478 InvalidateRect(); |
479 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency())
, | 479 |
480 CPWL_Utils::PWLColorToFXColor(GetTextStrokeColor(), GetTranspare
ncy()), | 480 m_bMouseDown = TRUE; |
481 rcClip,CPDF_Point(0.0f,0.0f),pRange, pSysHandler, m_pFormFiller)
; | 481 SetCapture(); |
482 | 482 |
483 if (HasFlag(PES_SPELLCHECK)) | 483 m_pEdit->OnMouseDown(point, IsSHIFTpressed(nFlag), IsCTRLpressed(nFlag)); |
484 { | 484 } |
485 CPWL_Utils::DrawEditSpellCheck(pDevice,pUser2Device,m_pEdit,rcCl
ip, | 485 |
486 CPDF_Point(0.0f,0.0f),pRange, GetCreationParam().pSpellC
heck); | 486 return TRUE; |
487 } | 487 } |
488 } | 488 |
489 | 489 FX_BOOL CPWL_Edit::OnLButtonDblClk(const CPDF_Point& point, FX_DWORD nFlag) { |
490 FX_BOOL CPWL_Edit::OnLButtonDown(const CPDF_Point & point, FX_DWORD nFlag) | 490 CPWL_Wnd::OnLButtonDblClk(point, nFlag); |
491 { | 491 |
492 CPWL_Wnd::OnLButtonDown(point,nFlag); | 492 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) { |
493 | 493 m_pEdit->SelectAll(); |
494 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) | 494 } |
495 { | 495 |
496 if (m_bMouseDown) | 496 return TRUE; |
497 InvalidateRect(); | 497 } |
498 | 498 |
499 m_bMouseDown = TRUE; | 499 #define WM_PWLEDIT_UNDO 0x01 |
500 SetCapture(); | 500 #define WM_PWLEDIT_REDO 0x02 |
501 | 501 #define WM_PWLEDIT_CUT 0x03 |
502 m_pEdit->OnMouseDown(point,IsSHIFTpressed(nFlag),IsCTRLpressed(n
Flag)); | 502 #define WM_PWLEDIT_COPY 0x04 |
503 } | 503 #define WM_PWLEDIT_PASTE 0x05 |
504 | 504 #define WM_PWLEDIT_DELETE 0x06 |
505 return TRUE; | 505 #define WM_PWLEDIT_SELECTALL 0x07 |
506 } | 506 #define WM_PWLEDIT_SUGGEST 0x08 |
507 | 507 |
508 FX_BOOL CPWL_Edit::OnLButtonDblClk(const CPDF_Point & point, FX_DWORD nFlag) | 508 FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point& point, FX_DWORD nFlag) { |
509 { | 509 if (m_bMouseDown) |
510 CPWL_Wnd::OnLButtonDblClk(point, nFlag); | 510 return FALSE; |
511 | 511 |
512 if (HasFlag(PES_TEXTOVERFLOW) || ClientHitTest(point)) | 512 CPWL_Wnd::OnRButtonUp(point, nFlag); |
513 { | 513 |
514 m_pEdit->SelectAll(); | 514 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) |
515 } | 515 return TRUE; |
516 | 516 |
517 return TRUE; | 517 IFX_SystemHandler* pSH = GetSystemHandler(); |
518 } | 518 if (!pSH) |
519 | 519 return FALSE; |
520 #define WM_PWLEDIT_UNDO 0x01 | 520 |
521 #define WM_PWLEDIT_REDO 0x02 | 521 SetFocus(); |
522 #define WM_PWLEDIT_CUT 0x03 | 522 |
523 #define WM_PWLEDIT_COPY 0x04 | 523 CPVT_WordRange wrLatin = GetLatinWordsRange(point); |
524 #define WM_PWLEDIT_PASTE 0x05 | 524 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); |
525 #define WM_PWLEDIT_DELETE 0x06 | 525 |
526 #define WM_PWLEDIT_SELECTALL 0x07 | 526 FX_HMENU hPopup = pSH->CreatePopupMenu(); |
527 #define WM_PWLEDIT_SUGGEST 0x08 | 527 if (!hPopup) |
528 | 528 return FALSE; |
529 FX_BOOL CPWL_Edit::OnRButtonUp(const CPDF_Point & point, FX_DWORD nFlag) | 529 |
530 { | 530 CFX_ByteStringArray sSuggestWords; |
531 if (m_bMouseDown) return FALSE; | 531 CPDF_Point ptPopup = point; |
532 | 532 |
533 CPWL_Wnd::OnRButtonUp(point, nFlag); | 533 if (!IsReadOnly()) { |
534 | 534 if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) { |
535 if (!HasFlag(PES_TEXTOVERFLOW) && !ClientHitTest(point)) return TRUE; | 535 if (m_pSpellCheck) { |
536 | 536 CFX_ByteString sLatin = CFX_ByteString::FromUnicode(swLatin); |
537 IFX_SystemHandler* pSH = GetSystemHandler(); | 537 |
538 if (!pSH) return FALSE; | 538 if (!m_pSpellCheck->CheckWord(sLatin)) { |
539 | 539 m_pSpellCheck->SuggestWords(sLatin, sSuggestWords); |
540 SetFocus(); | 540 |
541 | 541 int32_t nSuggest = sSuggestWords.GetSize(); |
542 CPVT_WordRange wrLatin = GetLatinWordsRange(point); | 542 |
543 CFX_WideString swLatin = m_pEdit->GetRangeText(wrLatin); | 543 for (int32_t nWord = 0; nWord < nSuggest; nWord++) { |
544 | 544 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SUGGEST + nWord, |
545 FX_HMENU hPopup = pSH->CreatePopupMenu(); | 545 sSuggestWords[nWord].UTF8Decode()); |
546 if (!hPopup) return FALSE; | 546 } |
547 | 547 |
548 CFX_ByteStringArray sSuggestWords; | 548 if (nSuggest > 0) |
549 CPDF_Point ptPopup = point; | 549 pSH->AppendMenuItem(hPopup, 0, L""); |
550 | 550 |
551 if (!IsReadOnly()) | 551 ptPopup = GetWordRightBottomPoint(wrLatin.EndPos); |
552 { | 552 } |
553 if (HasFlag(PES_SPELLCHECK) && !swLatin.IsEmpty()) | 553 } |
554 { | 554 } |
555 if (m_pSpellCheck) | 555 } |
556 { | 556 |
557 CFX_ByteString sLatin = CFX_ByteString::FromUnic
ode(swLatin); | 557 IPWL_Provider* pProvider = GetProvider(); |
558 | 558 |
559 if (!m_pSpellCheck->CheckWord(sLatin)) | 559 if (HasFlag(PES_UNDO)) { |
560 { | 560 pSH->AppendMenuItem( |
561 m_pSpellCheck->SuggestWords(sLatin,sSugg
estWords); | 561 hPopup, WM_PWLEDIT_UNDO, |
562 | 562 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"); |
563 int32_t nSuggest = sSuggestWords.GetSize
(); | 563 pSH->AppendMenuItem( |
564 | 564 hPopup, WM_PWLEDIT_REDO, |
565 for (int32_t nWord=0; nWord<nSuggest; nW
ord++) | 565 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"); |
566 { | 566 pSH->AppendMenuItem(hPopup, 0, L""); |
567 pSH->AppendMenuItem(hPopup, WM_P
WLEDIT_SUGGEST+nWord, sSuggestWords[nWord].UTF8Decode()); | 567 |
568 } | 568 if (!m_pEdit->CanUndo()) |
569 | 569 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE); |
570 if (nSuggest > 0) | 570 if (!m_pEdit->CanRedo()) |
571 pSH->AppendMenuItem(hPopup, 0, L
""); | 571 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE); |
572 | 572 } |
573 ptPopup = GetWordRightBottomPoint(wrLati
n.EndPos); | 573 |
574 } | 574 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, |
575 } | 575 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t"); |
576 } | 576 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, |
577 } | 577 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy"); |
578 | 578 pSH->AppendMenuItem( |
579 IPWL_Provider* pProvider = GetProvider(); | 579 hPopup, WM_PWLEDIT_PASTE, |
580 | 580 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste"); |
581 if (HasFlag(PES_UNDO)) | 581 pSH->AppendMenuItem( |
582 { | 582 hPopup, WM_PWLEDIT_DELETE, |
583 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_UNDO, | 583 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete"); |
584 pProvider ? pProvider->LoadPopupMenuString(0) : L"&Undo"
); | 584 |
585 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_REDO, | 585 CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd()); |
586 pProvider ? pProvider->LoadPopupMenuString(1) : L"&Redo"
); | 586 if (swText.IsEmpty()) |
587 pSH->AppendMenuItem(hPopup, 0, L""); | 587 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
588 | 588 |
589 if (!m_pEdit->CanUndo()) | 589 if (!m_pEdit->IsSelected()) { |
590 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_UNDO, FALSE); | 590 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
591 if (!m_pEdit->CanRedo()) | 591 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
592 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_REDO, FALSE); | 592 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
593 } | 593 } |
594 | 594 |
595 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_CUT, | 595 if (IsReadOnly()) { |
596 pProvider ? pProvider->LoadPopupMenuString(2) : L"Cu&t"); | 596 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
597 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_COPY, | 597 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); |
598 pProvider ? pProvider->LoadPopupMenuString(3) : L"&Copy"); | 598 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); |
599 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_PASTE, | 599 } |
600 pProvider ? pProvider->LoadPopupMenuString(4) : L"&Paste"); | 600 |
601 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_DELETE, | 601 if (HasFlag(PES_PASSWORD)) { |
602 pProvider ? pProvider->LoadPopupMenuString(5) : L"&Delete"); | 602 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
603 | 603 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
604 CFX_WideString swText = pSH->GetClipboardText(GetAttachedHWnd()); | 604 } |
605 if (swText.IsEmpty()) | 605 |
606 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); | 606 if (HasFlag(PES_NOREAD)) { |
607 | 607 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); |
608 if (!m_pEdit->IsSelected()) | 608 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); |
609 { | 609 } |
610 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); | 610 |
611 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); | 611 pSH->AppendMenuItem(hPopup, 0, L""); |
612 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); | 612 pSH->AppendMenuItem( |
613 } | 613 hPopup, WM_PWLEDIT_SELECTALL, |
614 | 614 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All"); |
615 if (IsReadOnly()) | 615 |
616 { | 616 if (m_pEdit->GetTotalWords() == 0) { |
617 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); | 617 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE); |
618 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_DELETE, FALSE); | 618 } |
619 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_PASTE, FALSE); | 619 |
620 } | 620 int32_t x, y; |
621 | 621 PWLtoWnd(ptPopup, x, y); |
622 if (HasFlag(PES_PASSWORD)) | 622 pSH->ClientToScreen(GetAttachedHWnd(), x, y); |
623 { | 623 pSH->SetCursor(FXCT_ARROW); |
624 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); | 624 int32_t nCmd = pSH->TrackPopupMenu(hPopup, x, y, GetAttachedHWnd()); |
625 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); | 625 |
626 } | 626 switch (nCmd) { |
627 | 627 case WM_PWLEDIT_UNDO: |
628 if (HasFlag(PES_NOREAD)) | 628 Undo(); |
629 { | 629 break; |
630 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_CUT, FALSE); | 630 case WM_PWLEDIT_REDO: |
631 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_COPY, FALSE); | 631 Redo(); |
632 } | 632 break; |
633 | 633 case WM_PWLEDIT_CUT: |
634 pSH->AppendMenuItem(hPopup, 0, L""); | 634 CutText(); |
635 pSH->AppendMenuItem(hPopup, WM_PWLEDIT_SELECTALL, | 635 break; |
636 pProvider ? pProvider->LoadPopupMenuString(6) : L"&Select All"); | 636 case WM_PWLEDIT_COPY: |
637 | 637 CopyText(); |
638 if (m_pEdit->GetTotalWords() == 0) | 638 break; |
639 { | 639 case WM_PWLEDIT_PASTE: |
640 pSH->EnableMenuItem(hPopup, WM_PWLEDIT_SELECTALL, FALSE); | 640 PasteText(); |
641 } | 641 break; |
642 | 642 case WM_PWLEDIT_DELETE: |
643 int32_t x, y; | 643 Clear(); |
644 PWLtoWnd(ptPopup, x, y); | 644 break; |
645 pSH->ClientToScreen(GetAttachedHWnd(), x, y); | 645 case WM_PWLEDIT_SELECTALL: |
646 pSH->SetCursor(FXCT_ARROW); | 646 SelectAll(); |
647 int32_t nCmd = pSH->TrackPopupMenu(hPopup, | 647 break; |
648 x, | 648 case WM_PWLEDIT_SUGGEST + 0: |
649 y, | 649 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
650 GetAttachedHWnd()); | 650 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
651 | 651 ReplaceSel(sSuggestWords[0].UTF8Decode().c_str()); |
652 | 652 break; |
653 switch (nCmd) | 653 case WM_PWLEDIT_SUGGEST + 1: |
654 { | 654 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
655 case WM_PWLEDIT_UNDO: | 655 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
656 Undo(); | 656 ReplaceSel(sSuggestWords[1].UTF8Decode().c_str()); |
657 break; | 657 break; |
658 case WM_PWLEDIT_REDO: | 658 case WM_PWLEDIT_SUGGEST + 2: |
659 Redo(); | 659 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
660 break; | 660 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
661 case WM_PWLEDIT_CUT: | 661 ReplaceSel(sSuggestWords[2].UTF8Decode().c_str()); |
662 CutText(); | 662 break; |
663 break; | 663 case WM_PWLEDIT_SUGGEST + 3: |
664 case WM_PWLEDIT_COPY: | 664 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
665 CopyText(); | 665 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
666 break; | 666 ReplaceSel(sSuggestWords[3].UTF8Decode().c_str()); |
667 case WM_PWLEDIT_PASTE: | 667 break; |
668 PasteText(); | 668 case WM_PWLEDIT_SUGGEST + 4: |
669 break; | 669 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos), |
670 case WM_PWLEDIT_DELETE: | 670 m_pEdit->WordPlaceToWordIndex(wrLatin.EndPos)); |
671 Clear(); | 671 ReplaceSel(sSuggestWords[4].UTF8Decode().c_str()); |
672 break; | 672 break; |
673 case WM_PWLEDIT_SELECTALL: | 673 default: |
674 SelectAll(); | 674 break; |
675 break; | 675 } |
676 case WM_PWLEDIT_SUGGEST + 0: | 676 |
677 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->
WordPlaceToWordIndex(wrLatin.EndPos)); | 677 pSH->DestroyMenu(hPopup); |
678 ReplaceSel(sSuggestWords[0].UTF8Decode().c_str()); | 678 |
679 break; | 679 return TRUE; |
680 case WM_PWLEDIT_SUGGEST + 1: | 680 } |
681 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->
WordPlaceToWordIndex(wrLatin.EndPos)); | 681 |
682 ReplaceSel(sSuggestWords[1].UTF8Decode().c_str()); | 682 void CPWL_Edit::OnSetFocus() { |
683 break; | 683 SetEditCaret(TRUE); |
684 case WM_PWLEDIT_SUGGEST + 2: | 684 |
685 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->
WordPlaceToWordIndex(wrLatin.EndPos)); | 685 if (!IsReadOnly()) { |
686 ReplaceSel(sSuggestWords[2].UTF8Decode().c_str()); | 686 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
687 break; | 687 pFocusHandler->OnSetFocus(this); |
688 case WM_PWLEDIT_SUGGEST + 3: | 688 } |
689 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->
WordPlaceToWordIndex(wrLatin.EndPos)); | 689 |
690 ReplaceSel(sSuggestWords[3].UTF8Decode().c_str()); | 690 m_bFocus = TRUE; |
691 break; | 691 } |
692 case WM_PWLEDIT_SUGGEST + 4: | 692 |
693 SetSel(m_pEdit->WordPlaceToWordIndex(wrLatin.BeginPos),m_pEdit->
WordPlaceToWordIndex(wrLatin.EndPos)); | 693 void CPWL_Edit::OnKillFocus() { |
694 ReplaceSel(sSuggestWords[4].UTF8Decode().c_str()); | 694 ShowVScrollBar(FALSE); |
695 break; | 695 |
696 default: | 696 m_pEdit->SelectNone(); |
697 break; | 697 SetCaret(FALSE, CPDF_Point(0.0f, 0.0f), CPDF_Point(0.0f, 0.0f)); |
698 } | 698 |
699 | 699 SetCharSet(0); |
700 pSH->DestroyMenu(hPopup); | 700 |
701 | 701 if (!IsReadOnly()) { |
702 return TRUE; | 702 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) |
703 } | 703 pFocusHandler->OnKillFocus(this); |
704 | 704 } |
705 void CPWL_Edit::OnSetFocus() | 705 |
706 { | 706 m_bFocus = FALSE; |
707 SetEditCaret(TRUE); | 707 } |
708 | 708 |
709 if (!IsReadOnly()) | 709 void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint /* = TRUE*/) { |
710 { | 710 m_pEdit->SetHorzScale(nHorzScale, bPaint); |
711 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) | 711 } |
712 pFocusHandler->OnSetFocus(this); | 712 |
713 } | 713 void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint /* = TRUE*/) { |
714 | 714 m_pEdit->SetCharSpace(fCharSpace, bPaint); |
715 m_bFocus = TRUE; | 715 } |
716 } | 716 |
717 | 717 void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, |
718 void CPWL_Edit::OnKillFocus() | 718 FX_BOOL bPaint /* = TRUE*/) { |
719 { | 719 m_pEdit->SetLineLeading(fLineLeading, bPaint); |
720 ShowVScrollBar(FALSE); | 720 } |
721 | 721 |
722 m_pEdit->SelectNone(); | 722 CFX_ByteString CPWL_Edit::GetSelectAppearanceStream( |
723 SetCaret(FALSE, CPDF_Point(0.0f,0.0f), CPDF_Point(0.0f,0.0f)); | 723 const CPDF_Point& ptOffset) const { |
724 | 724 CPVT_WordRange wr = GetSelectWordRange(); |
725 SetCharSet(0); | 725 return CPWL_Utils::GetEditSelAppStream(m_pEdit, ptOffset, &wr); |
726 | 726 } |
727 if (!IsReadOnly()) | 727 |
728 { | 728 CPVT_WordRange CPWL_Edit::GetSelectWordRange() const { |
729 if (IPWL_FocusHandler* pFocusHandler = GetFocusHandler()) | 729 if (m_pEdit->IsSelected()) { |
730 pFocusHandler->OnKillFocus(this); | 730 int32_t nStart = -1; |
731 } | 731 int32_t nEnd = -1; |
732 | 732 |
733 m_bFocus = FALSE; | 733 m_pEdit->GetSel(nStart, nEnd); |
734 } | 734 |
735 | 735 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); |
736 void CPWL_Edit::SetHorzScale(int32_t nHorzScale, FX_BOOL bPaint/* = TRUE*/) | 736 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); |
737 { | 737 |
738 m_pEdit->SetHorzScale(nHorzScale, bPaint); | 738 return CPVT_WordRange(wpStart, wpEnd); |
739 } | 739 } |
740 | 740 |
741 void CPWL_Edit::SetCharSpace(FX_FLOAT fCharSpace, FX_BOOL bPaint/* = TRUE*/) | 741 return CPVT_WordRange(); |
742 { | 742 } |
743 m_pEdit->SetCharSpace(fCharSpace, bPaint); | 743 |
744 } | 744 CFX_ByteString CPWL_Edit::GetTextAppearanceStream( |
745 | 745 const CPDF_Point& ptOffset) const { |
746 void CPWL_Edit::SetLineLeading(FX_FLOAT fLineLeading, FX_BOOL bPaint/* = TRUE*/) | 746 CFX_ByteTextBuf sRet; |
747 { | 747 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit, ptOffset); |
748 m_pEdit->SetLineLeading(fLineLeading, bPaint); | 748 |
749 } | 749 if (sEdit.GetLength() > 0) { |
750 | 750 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor()) << sEdit |
751 CFX_ByteString CPWL_Edit::GetSelectAppearanceStream(const CPDF_Point & ptOffset)
const | 751 << "ET\n"; |
752 { | 752 } |
753 CPVT_WordRange wr = GetSelectWordRange(); | 753 |
754 return CPWL_Utils::GetEditSelAppStream(m_pEdit,ptOffset,&wr); | 754 return sRet.GetByteString(); |
755 } | 755 } |
756 | 756 |
757 CPVT_WordRange CPWL_Edit::GetSelectWordRange() const | 757 CFX_ByteString CPWL_Edit::GetCaretAppearanceStream( |
758 { | 758 const CPDF_Point& ptOffset) const { |
759 if (m_pEdit->IsSelected()) | 759 if (m_pEditCaret) |
760 { | 760 return m_pEditCaret->GetCaretAppearanceStream(ptOffset); |
761 int32_t nStart = -1; | 761 |
762 int32_t nEnd = -1; | 762 return CFX_ByteString(); |
763 | 763 } |
764 m_pEdit->GetSel(nStart, nEnd); | 764 |
765 | 765 CPDF_Point CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) { |
766 CPVT_WordPlace wpStart = m_pEdit->WordIndexToWordPlace(nStart); | 766 CPDF_Point pt(0.0f, 0.0f); |
767 CPVT_WordPlace wpEnd = m_pEdit->WordIndexToWordPlace(nEnd); | 767 |
768 | 768 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
769 return CPVT_WordRange(wpStart,wpEnd); | 769 CPVT_WordPlace wpOld = pIterator->GetAt(); |
770 } | 770 pIterator->SetAt(wpWord); |
771 | 771 CPVT_Word word; |
772 return CPVT_WordRange(); | 772 if (pIterator->GetWord(word)) { |
773 } | 773 pt = CPDF_Point(word.ptWord.x + word.fWidth, |
774 | 774 word.ptWord.y + word.fDescent); |
775 CFX_ByteString CPWL_Edit::GetTextAppearanceStream(const CPDF_Point & ptOffset) c
onst | 775 } |
776 { | 776 |
777 CFX_ByteTextBuf sRet; | 777 pIterator->SetAt(wpOld); |
778 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(m_pEdit,ptOffset); | 778 } |
779 | 779 |
780 if (sEdit.GetLength() > 0) | 780 return pt; |
781 { | 781 } |
782 sRet << "BT\n" << CPWL_Utils::GetColorAppStream(GetTextColor())
<< sEdit << "ET\n"; | 782 |
783 } | 783 FX_BOOL CPWL_Edit::IsTextFull() const { |
784 | 784 return m_pEdit->IsTextFull(); |
785 return sRet.GetByteString(); | 785 } |
786 } | 786 |
787 | 787 FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, |
788 CFX_ByteString CPWL_Edit::GetCaretAppearanceStream(const CPDF_Point & ptOffset)
const | 788 const CPDF_Rect& rcPlate, |
789 { | 789 int32_t nCharArray) { |
790 if (m_pEditCaret) | 790 if (pFont && !pFont->IsStandardFont()) { |
791 return m_pEditCaret->GetCaretAppearanceStream(ptOffset); | 791 FX_RECT rcBBox; |
792 | 792 pFont->GetFontBBox(rcBBox); |
793 return CFX_ByteString(); | 793 |
794 } | 794 CPDF_Rect rcCell = rcPlate; |
795 | 795 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.Width(); |
796 CPDF_Point CPWL_Edit::GetWordRightBottomPoint(const CPVT_WordPlace& wpWord) | 796 FX_FLOAT ydiv = -rcCell.Height() * 1000.0f / rcBBox.Height(); |
797 { | 797 |
798 CPDF_Point pt(0.0f, 0.0f); | 798 return xdiv < ydiv ? xdiv : ydiv; |
799 | 799 } |
800 if (IFX_Edit_Iterator * pIterator = m_pEdit->GetIterator()) | 800 |
801 { | 801 return 0.0f; |
802 CPVT_WordPlace wpOld = pIterator->GetAt(); | 802 } |
803 pIterator->SetAt(wpWord); | 803 |
804 CPVT_Word word; | 804 void CPWL_Edit::SetCharArray(int32_t nCharArray) { |
805 if (pIterator->GetWord(word)) | 805 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) { |
806 { | 806 m_pEdit->SetCharArray(nCharArray); |
807 pt = CPDF_Point(word.ptWord.x + word.fWidth, word.ptWord
.y + word.fDescent); | 807 m_pEdit->SetTextOverflow(TRUE); |
808 } | 808 |
809 | 809 if (HasFlag(PWS_AUTOFONTSIZE)) { |
810 pIterator->SetAt(wpOld); | 810 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) { |
811 } | 811 FX_FLOAT fFontSize = GetCharArrayAutoFontSize( |
812 | 812 pFontMap->GetPDFFont(0), GetClientRect(), nCharArray); |
813 return pt; | 813 if (fFontSize > 0.0f) { |
814 } | 814 m_pEdit->SetAutoFontSize(FALSE); |
815 | 815 m_pEdit->SetFontSize(fFontSize); |
816 FX_BOOL CPWL_Edit::IsTextFull() const | 816 } |
817 { | 817 } |
818 return m_pEdit->IsTextFull(); | 818 } |
819 } | 819 } |
820 | 820 } |
821 FX_FLOAT CPWL_Edit::GetCharArrayAutoFontSize(CPDF_Font* pFont, const CPDF_Rect&
rcPlate, int32_t nCharArray) | 821 |
822 { | 822 void CPWL_Edit::SetLimitChar(int32_t nLimitChar) { |
823 if (pFont && !pFont->IsStandardFont()) | 823 m_pEdit->SetLimitChar(nLimitChar); |
824 { | 824 } |
825 FX_RECT rcBBox; | 825 |
826 pFont->GetFontBBox(rcBBox); | 826 void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) { |
827 | 827 m_pEdit->Clear(); |
828 CPDF_Rect rcCell = rcPlate; | 828 m_pEdit->InsertText(csText); |
829 FX_FLOAT xdiv = rcCell.Width() / nCharArray * 1000.0f / rcBBox.W
idth(); | 829 } |
830 FX_FLOAT ydiv = - rcCell.Height() * 1000.0f / rcBBox.Height(); | 830 |
831 | 831 CPDF_Rect CPWL_Edit::GetFocusRect() const { |
832 return xdiv < ydiv ? xdiv : ydiv; | 832 return CPDF_Rect(); |
833 } | 833 } |
834 | 834 |
835 return 0.0f; | 835 void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) { |
836 } | 836 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
837 | 837 if (bShow) { |
838 void CPWL_Edit::SetCharArray(int32_t nCharArray) | 838 if (!pScroll->IsVisible()) { |
839 { | 839 pScroll->SetVisible(TRUE); |
840 if (HasFlag(PES_CHARARRAY) && nCharArray > 0) | 840 CPDF_Rect rcWindow = GetWindowRect(); |
841 { | 841 m_rcOldWindow = rcWindow; |
842 m_pEdit->SetCharArray(nCharArray); | 842 rcWindow.right += PWL_SCROLLBAR_WIDTH; |
843 m_pEdit->SetTextOverflow(TRUE); | 843 Move(rcWindow, TRUE, TRUE); |
844 | 844 } |
845 if (HasFlag(PWS_AUTOFONTSIZE)) | 845 } else { |
846 { | 846 if (pScroll->IsVisible()) { |
847 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) | 847 pScroll->SetVisible(FALSE); |
848 { | 848 Move(m_rcOldWindow, TRUE, TRUE); |
849 FX_FLOAT fFontSize = GetCharArrayAutoFontSize(pF
ontMap->GetPDFFont(0), GetClientRect(), nCharArray); | 849 } |
850 if (fFontSize > 0.0f) | 850 } |
851 { | 851 } |
852 m_pEdit->SetAutoFontSize(FALSE); | 852 } |
853 m_pEdit->SetFontSize(fFontSize); | 853 |
854 } | 854 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const { |
855 } | 855 if (CPWL_ScrollBar* pScroll = GetVScrollBar()) { |
856 } | 856 return pScroll->IsVisible(); |
857 } | 857 } |
858 } | 858 |
859 | 859 return FALSE; |
860 void CPWL_Edit::SetLimitChar(int32_t nLimitChar) | 860 } |
861 { | 861 |
862 m_pEdit->SetLimitChar(nLimitChar); | 862 void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) { |
863 } | 863 if (bEnabled) |
864 | 864 AddFlag(PES_SPELLCHECK); |
865 void CPWL_Edit::ReplaceSel(const FX_WCHAR* csText) | 865 else |
866 { | 866 RemoveFlag(PES_SPELLCHECK); |
867 m_pEdit->Clear(); | 867 } |
868 m_pEdit->InsertText(csText); | 868 |
869 } | 869 FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) { |
870 | 870 if (m_bMouseDown) |
871 CPDF_Rect CPWL_Edit::GetFocusRect() const | 871 return TRUE; |
872 { | 872 |
873 return CPDF_Rect(); | 873 if (nChar == FWL_VKEY_Delete) { |
874 } | 874 if (m_pFillerNotify) { |
875 | 875 FX_BOOL bRC = TRUE; |
876 void CPWL_Edit::ShowVScrollBar(FX_BOOL bShow) | 876 FX_BOOL bExit = FALSE; |
877 { | 877 CFX_WideString strChange; |
878 if (CPWL_ScrollBar * pScroll = GetVScrollBar()) | 878 CFX_WideString strChangeEx; |
879 { | 879 |
880 if (bShow) | 880 int nSelStart = 0; |
881 { | 881 int nSelEnd = 0; |
882 if (!pScroll->IsVisible()) | 882 GetSel(nSelStart, nSelEnd); |
883 { | 883 |
884 pScroll->SetVisible(TRUE); | 884 if (nSelStart == nSelEnd) |
885 CPDF_Rect rcWindow = GetWindowRect(); | 885 nSelEnd = nSelStart + 1; |
886 m_rcOldWindow = rcWindow; | 886 m_pFillerNotify->OnBeforeKeyStroke( |
887 rcWindow.right += PWL_SCROLLBAR_WIDTH; | 887 TRUE, GetAttachedData(), FWL_VKEY_Delete, strChange, strChangeEx, |
888 Move(rcWindow, TRUE, TRUE); | 888 nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag); |
889 } | 889 if (!bRC) |
890 } | 890 return FALSE; |
891 else | 891 if (bExit) |
892 { | 892 return FALSE; |
893 if (pScroll->IsVisible()) | 893 } |
894 { | 894 } |
895 pScroll->SetVisible(FALSE); | 895 |
896 Move(m_rcOldWindow, TRUE, TRUE); | 896 FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); |
897 } | 897 |
898 } | 898 if (nChar == FWL_VKEY_Delete) { |
899 } | 899 if (m_pFillerNotify) { |
900 } | 900 FX_BOOL bExit = FALSE; |
901 | 901 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit, nFlag); |
902 FX_BOOL CPWL_Edit::IsVScrollBarVisible() const | 902 if (bExit) |
903 { | 903 return FALSE; |
904 if (CPWL_ScrollBar * pScroll = GetVScrollBar()) | 904 } |
905 { | 905 } |
906 return pScroll->IsVisible(); | 906 |
907 } | 907 // In case of implementation swallow the OnKeyDown event. |
908 | 908 if (IsProceedtoOnChar(nChar, nFlag)) |
909 return FALSE; | 909 return TRUE; |
910 } | 910 |
911 | 911 return bRet; |
912 void CPWL_Edit::EnableSpellCheck(FX_BOOL bEnabled) | |
913 { | |
914 if (bEnabled) | |
915 AddFlag(PES_SPELLCHECK); | |
916 else | |
917 RemoveFlag(PES_SPELLCHECK); | |
918 } | |
919 | |
920 FX_BOOL CPWL_Edit::OnKeyDown(FX_WORD nChar, FX_DWORD nFlag) | |
921 { | |
922 if (m_bMouseDown) return TRUE; | |
923 | |
924 if (nChar == FWL_VKEY_Delete) | |
925 { | |
926 if (m_pFillerNotify) | |
927 { | |
928 FX_BOOL bRC = TRUE; | |
929 FX_BOOL bExit = FALSE; | |
930 CFX_WideString strChange; | |
931 CFX_WideString strChangeEx; | |
932 | |
933 int nSelStart = 0; | |
934 int nSelEnd = 0; | |
935 GetSel(nSelStart, nSelEnd); | |
936 | |
937 if (nSelStart == nSelEnd) | |
938 nSelEnd = nSelStart + 1; | |
939 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData
(), FWL_VKEY_Delete, strChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExi
t, nFlag); | |
940 if (!bRC) return FALSE; | |
941 if (bExit) return FALSE; | |
942 } | |
943 } | |
944 | |
945 FX_BOOL bRet = CPWL_EditCtrl::OnKeyDown(nChar, nFlag); | |
946 | |
947 if (nChar == FWL_VKEY_Delete) | |
948 { | |
949 if (m_pFillerNotify) | |
950 { | |
951 FX_BOOL bExit = FALSE; | |
952 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(
), bExit,nFlag); | |
953 if (bExit) return FALSE; | |
954 } | |
955 } | |
956 | |
957 //In case of implementation swallow the OnKeyDown event. | |
958 if(IsProceedtoOnChar(nChar, nFlag)) | |
959 return TRUE; | |
960 | |
961 return bRet; | |
962 } | 912 } |
963 | 913 |
964 /** | 914 /** |
965 *In case of implementation swallow the OnKeyDown event. | 915 *In case of implementation swallow the OnKeyDown event. |
966 *If the event is swallowed, implementation may do other unexpected things, which
is not the control means to do. | 916 *If the event is swallowed, implementation may do other unexpected things, which |
| 917 *is not the control means to do. |
967 */ | 918 */ |
968 FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag) | 919 FX_BOOL CPWL_Edit::IsProceedtoOnChar(FX_WORD nKeyCode, FX_DWORD nFlag) { |
969 { | 920 FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
970 | 921 FX_BOOL bAlt = IsALTpressed(nFlag); |
971 FX_BOOL bCtrl = IsCTRLpressed(nFlag); | 922 if (bCtrl && !bAlt) { |
972 FX_BOOL bAlt = IsALTpressed(nFlag); | 923 // hot keys for edit control. |
973 if(bCtrl && !bAlt) | 924 switch (nKeyCode) { |
974 { | 925 case 'C': |
975 //hot keys for edit control. | 926 case 'V': |
976 switch(nKeyCode) | 927 case 'X': |
977 { | 928 case 'A': |
978 case 'C': | 929 case 'Z': |
979 case 'V': | 930 return TRUE; |
980 case 'X': | 931 default: |
981 case 'A': | 932 break; |
982 case 'Z': | 933 } |
983 return TRUE; | 934 } |
984 default: | 935 // control characters. |
985 break; | 936 switch (nKeyCode) { |
986 } | 937 case FWL_VKEY_Escape: |
987 } | 938 case FWL_VKEY_Back: |
988 //control characters. | 939 case FWL_VKEY_Return: |
989 switch(nKeyCode) | 940 case FWL_VKEY_Space: |
990 { | 941 return TRUE; |
991 case FWL_VKEY_Escape: | 942 default: |
992 case FWL_VKEY_Back: | 943 break; |
993 case FWL_VKEY_Return: | 944 } |
994 case FWL_VKEY_Space: | 945 return FALSE; |
995 return TRUE; | 946 } |
996 default: | 947 |
997 break; | 948 FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag) { |
998 } | 949 if (m_bMouseDown) |
999 return FALSE; | 950 return TRUE; |
1000 | 951 |
1001 } | 952 FX_BOOL bRC = TRUE; |
1002 | 953 FX_BOOL bExit = FALSE; |
1003 FX_BOOL CPWL_Edit::OnChar(FX_WORD nChar, FX_DWORD nFlag) | 954 |
1004 { | 955 FX_BOOL bCtrl = IsCTRLpressed(nFlag); |
1005 if (m_bMouseDown) return TRUE; | 956 if (!bCtrl) { |
1006 | 957 if (m_pFillerNotify) { |
1007 FX_BOOL bRC = TRUE; | 958 CFX_WideString swChange; |
1008 FX_BOOL bExit = FALSE; | 959 int32_t nKeyCode; |
1009 | 960 |
1010 FX_BOOL bCtrl = IsCTRLpressed(nFlag); | 961 int nSelStart = 0; |
1011 if (!bCtrl) | 962 int nSelEnd = 0; |
1012 { | 963 GetSel(nSelStart, nSelEnd); |
1013 if (m_pFillerNotify) | 964 |
1014 { | 965 switch (nChar) { |
1015 CFX_WideString swChange; | 966 case FWL_VKEY_Back: |
1016 int32_t nKeyCode; | 967 nKeyCode = nChar; |
1017 | 968 if (nSelStart == nSelEnd) |
1018 int nSelStart = 0; | 969 nSelStart = nSelEnd - 1; |
1019 int nSelEnd = 0; | 970 break; |
1020 GetSel(nSelStart, nSelEnd); | 971 case FWL_VKEY_Return: |
1021 | 972 nKeyCode = nChar; |
1022 switch (nChar) | 973 break; |
1023 { | 974 default: |
1024 case FWL_VKEY_Back: | 975 nKeyCode = 0; |
1025 nKeyCode = nChar; | 976 swChange += nChar; |
1026 if (nSelStart == nSelEnd) | 977 break; |
1027 nSelStart = nSelEnd - 1; | 978 } |
1028 break; | 979 |
1029 case FWL_VKEY_Return: | 980 CFX_WideString strChangeEx; |
1030 nKeyCode = nChar; | 981 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData(), nKeyCode, |
1031 break; | 982 swChange, strChangeEx, nSelStart, |
1032 default: | 983 nSelEnd, TRUE, bRC, bExit, nFlag); |
1033 nKeyCode = 0; | 984 } |
1034 swChange += nChar; | 985 } |
1035 break; | 986 |
1036 } | 987 if (!bRC) |
1037 | 988 return TRUE; |
1038 CFX_WideString strChangeEx; | 989 if (bExit) |
1039 m_pFillerNotify->OnBeforeKeyStroke(TRUE, GetAttachedData
(), nKeyCode, swChange, strChangeEx, nSelStart, nSelEnd, TRUE, bRC, bExit, nFlag
); | 990 return FALSE; |
1040 } | 991 |
1041 } | 992 if (IFX_Edit_FontMap* pFontMap = GetFontMap()) { |
1042 | 993 int32_t nOldCharSet = GetCharSet(); |
1043 if (!bRC) return TRUE; | 994 int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAULT_CHARSET); |
1044 if (bExit) return FALSE; | 995 if (nOldCharSet != nNewCharSet) { |
1045 | 996 SetCharSet(nNewCharSet); |
1046 if (IFX_Edit_FontMap * pFontMap = GetFontMap()) | 997 } |
1047 { | 998 } |
1048 int32_t nOldCharSet = GetCharSet(); | 999 FX_BOOL bRet = CPWL_EditCtrl::OnChar(nChar, nFlag); |
1049 int32_t nNewCharSet = pFontMap->CharSetFromUnicode(nChar, DEFAUL
T_CHARSET); | 1000 |
1050 if(nOldCharSet != nNewCharSet) | 1001 if (!bCtrl) { |
1051 { | 1002 if (m_pFillerNotify) { |
1052 SetCharSet(nNewCharSet); | 1003 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(), bExit, nFlag); |
1053 } | 1004 if (bExit) |
1054 } | 1005 return FALSE; |
1055 FX_BOOL bRet = CPWL_EditCtrl::OnChar(nChar,nFlag); | 1006 } |
1056 | 1007 } |
1057 if (!bCtrl) | 1008 |
1058 { | 1009 return bRet; |
1059 if (m_pFillerNotify) | 1010 } |
1060 { | 1011 |
1061 m_pFillerNotify->OnAfterKeyStroke(TRUE, GetAttachedData(
), bExit,nFlag); | 1012 FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, |
1062 if (bExit) return FALSE; | 1013 const CPDF_Point& point, |
1063 } | 1014 FX_DWORD nFlag) { |
1064 } | 1015 if (HasFlag(PES_MULTILINE)) { |
1065 | 1016 CPDF_Point ptScroll = GetScrollPos(); |
1066 return bRet; | 1017 |
1067 } | 1018 if (zDelta > 0) { |
1068 | 1019 ptScroll.y += GetFontSize(); |
1069 FX_BOOL CPWL_Edit::OnMouseWheel(short zDelta, const CPDF_Point & point, FX_DWORD
nFlag) | 1020 } else { |
1070 { | 1021 ptScroll.y -= GetFontSize(); |
1071 if (HasFlag(PES_MULTILINE)) | 1022 } |
1072 { | 1023 SetScrollPos(ptScroll); |
1073 CPDF_Point ptScroll = GetScrollPos(); | 1024 |
1074 | 1025 return TRUE; |
1075 if (zDelta > 0) | 1026 } |
1076 { | 1027 |
1077 ptScroll.y += GetFontSize(); | 1028 return FALSE; |
1078 } | 1029 } |
1079 else | 1030 |
1080 { | 1031 void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, |
1081 ptScroll.y -= GetFontSize(); | 1032 const CPVT_WordPlace& oldplace) { |
1082 } | 1033 if (HasFlag(PES_SPELLCHECK)) { |
1083 SetScrollPos(ptScroll); | 1034 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1084 | 1035 GetLatinWordsRange(place))); |
1085 return TRUE; | 1036 } |
1086 } | 1037 |
1087 | 1038 if (m_pEditNotify) { |
1088 return FALSE; | 1039 m_pEditNotify->OnInsertReturn(place, oldplace); |
1089 } | 1040 } |
1090 | 1041 } |
1091 void CPWL_Edit::OnInsertReturn(const CPVT_WordPlace& place, const CPVT_WordPlace
& oldplace) | 1042 |
1092 { | 1043 void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, |
1093 if (HasFlag(PES_SPELLCHECK)) | 1044 const CPVT_WordPlace& oldplace) { |
1094 { | 1045 if (HasFlag(PES_SPELLCHECK)) { |
1095 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1046 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1096 } | 1047 GetLatinWordsRange(place))); |
1097 | 1048 } |
1098 if (m_pEditNotify) | 1049 |
1099 { | 1050 if (m_pEditNotify) { |
1100 m_pEditNotify->OnInsertReturn(place, oldplace); | 1051 m_pEditNotify->OnBackSpace(place, oldplace); |
1101 } | 1052 } |
1102 } | 1053 } |
1103 | 1054 |
1104 void CPWL_Edit::OnBackSpace(const CPVT_WordPlace& place, const CPVT_WordPlace& o
ldplace) | 1055 void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, |
1105 { | 1056 const CPVT_WordPlace& oldplace) { |
1106 if (HasFlag(PES_SPELLCHECK)) | 1057 if (HasFlag(PES_SPELLCHECK)) { |
1107 { | 1058 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1108 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1059 GetLatinWordsRange(place))); |
1109 } | 1060 } |
1110 | 1061 |
1111 if (m_pEditNotify) | 1062 if (m_pEditNotify) { |
1112 { | 1063 m_pEditNotify->OnDelete(place, oldplace); |
1113 m_pEditNotify->OnBackSpace(place, oldplace); | 1064 } |
1114 } | 1065 } |
1115 } | 1066 |
1116 | 1067 void CPWL_Edit::OnClear(const CPVT_WordPlace& place, |
1117 void CPWL_Edit::OnDelete(const CPVT_WordPlace& place, const CPVT_WordPlace& oldp
lace) | 1068 const CPVT_WordPlace& oldplace) { |
1118 { | 1069 if (HasFlag(PES_SPELLCHECK)) { |
1119 if (HasFlag(PES_SPELLCHECK)) | 1070 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1120 { | 1071 GetLatinWordsRange(place))); |
1121 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1072 } |
1122 } | 1073 |
1123 | 1074 if (m_pEditNotify) { |
1124 if (m_pEditNotify) | 1075 m_pEditNotify->OnClear(place, oldplace); |
1125 { | 1076 } |
1126 m_pEditNotify->OnDelete(place, oldplace); | 1077 } |
1127 } | 1078 |
1128 } | 1079 void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, |
1129 | 1080 const CPVT_WordPlace& oldplace) { |
1130 void CPWL_Edit::OnClear(const CPVT_WordPlace& place, const CPVT_WordPlace& oldpl
ace) | 1081 if (HasFlag(PES_SPELLCHECK)) { |
1131 { | 1082 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1132 if (HasFlag(PES_SPELLCHECK)) | 1083 GetLatinWordsRange(place))); |
1133 { | 1084 } |
1134 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1085 |
1135 } | 1086 if (m_pEditNotify) { |
1136 | 1087 m_pEditNotify->OnInsertWord(place, oldplace); |
1137 if (m_pEditNotify) | 1088 } |
1138 { | 1089 } |
1139 m_pEditNotify->OnClear(place, oldplace); | 1090 |
1140 } | 1091 void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, |
1141 } | 1092 const CPVT_WordPlace& oldplace) {} |
1142 | 1093 |
1143 void CPWL_Edit::OnInsertWord(const CPVT_WordPlace& place, const CPVT_WordPlace&
oldplace) | 1094 void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, |
1144 { | 1095 const CPVT_WordPlace& oldplace) { |
1145 if (HasFlag(PES_SPELLCHECK)) | 1096 if (HasFlag(PES_SPELLCHECK)) { |
1146 { | 1097 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(oldplace), |
1147 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1098 GetLatinWordsRange(place))); |
1148 } | 1099 } |
1149 | 1100 |
1150 if (m_pEditNotify) | 1101 if (m_pEditNotify) { |
1151 { | 1102 m_pEditNotify->OnInsertText(place, oldplace); |
1152 m_pEditNotify->OnInsertWord(place, oldplace); | 1103 } |
1153 } | 1104 } |
1154 } | 1105 |
1155 | 1106 void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) { |
1156 void CPWL_Edit::OnSetText(const CPVT_WordPlace& place, const CPVT_WordPlace& old
place) | 1107 if (m_pEditNotify) { |
1157 { | 1108 m_pEditNotify->OnAddUndo(this); |
1158 } | 1109 } |
1159 | 1110 } |
1160 void CPWL_Edit::OnInsertText(const CPVT_WordPlace& place, const CPVT_WordPlace&
oldplace) | 1111 |
1161 { | 1112 CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, |
1162 if (HasFlag(PES_SPELLCHECK)) | 1113 const CPVT_WordRange& wr2) { |
1163 { | 1114 CPVT_WordRange wrRet; |
1164 m_pEdit->RefreshWordRange(CombineWordRange(GetLatinWordsRange(ol
dplace),GetLatinWordsRange(place))); | 1115 |
1165 } | 1116 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) { |
1166 | 1117 wrRet.BeginPos = wr1.BeginPos; |
1167 if (m_pEditNotify) | 1118 } else { |
1168 { | 1119 wrRet.BeginPos = wr2.BeginPos; |
1169 m_pEditNotify->OnInsertText(place, oldplace); | 1120 } |
1170 } | 1121 |
1171 } | 1122 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) { |
1172 | 1123 wrRet.EndPos = wr2.EndPos; |
1173 void CPWL_Edit::OnAddUndo(IFX_Edit_UndoItem* pUndoItem) | 1124 } else { |
1174 { | 1125 wrRet.EndPos = wr1.EndPos; |
1175 if (m_pEditNotify) | 1126 } |
1176 { | 1127 |
1177 m_pEditNotify->OnAddUndo(this); | 1128 return wrRet; |
1178 } | 1129 } |
1179 } | 1130 |
1180 | 1131 CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPDF_Point& point) const { |
1181 CPVT_WordRange CPWL_Edit::CombineWordRange(const CPVT_WordRange& wr1, const CPVT
_WordRange& wr2) | 1132 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE); |
1182 { | 1133 } |
1183 CPVT_WordRange wrRet; | 1134 |
1184 | 1135 CPVT_WordRange CPWL_Edit::GetLatinWordsRange( |
1185 if (wr1.BeginPos.WordCmp(wr2.BeginPos) < 0) | 1136 const CPVT_WordPlace& place) const { |
1186 { | 1137 return GetSameWordsRange(place, TRUE, FALSE); |
1187 wrRet.BeginPos = wr1.BeginPos; | 1138 } |
1188 } | 1139 |
1189 else | 1140 CPVT_WordRange CPWL_Edit::GetArabicWordsRange( |
1190 { | 1141 const CPVT_WordPlace& place) const { |
1191 wrRet.BeginPos = wr2.BeginPos; | 1142 return GetSameWordsRange(place, FALSE, TRUE); |
1192 } | 1143 } |
1193 | 1144 |
1194 if (wr1.EndPos.WordCmp(wr2.EndPos) < 0) | 1145 #define PWL_ISARABICWORD(word) \ |
1195 { | 1146 ((word >= 0x0600 && word <= 0x06FF) || (word >= 0xFB50 && word <= 0xFEFC)) |
1196 wrRet.EndPos = wr2.EndPos; | 1147 |
1197 } | 1148 CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace& place, |
1198 else | 1149 FX_BOOL bLatin, |
1199 { | 1150 FX_BOOL bArabic) const { |
1200 wrRet.EndPos = wr1.EndPos; | 1151 CPVT_WordRange range; |
1201 } | 1152 |
1202 | 1153 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) { |
1203 return wrRet; | 1154 CPVT_Word wordinfo; |
1204 } | 1155 CPVT_WordPlace wpStart(place), wpEnd(place); |
1205 | 1156 pIterator->SetAt(place); |
1206 CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPDF_Point& point) const | 1157 |
1207 { | 1158 if (bLatin) { |
1208 return GetSameWordsRange(m_pEdit->SearchWordPlace(point), TRUE, FALSE); | 1159 while (pIterator->NextWord()) { |
1209 } | 1160 if (pIterator->GetWord(wordinfo) && |
1210 | 1161 FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
1211 CPVT_WordRange CPWL_Edit::GetLatinWordsRange(const CPVT_WordPlace & place) const | 1162 wpEnd = pIterator->GetAt(); |
1212 { | 1163 continue; |
1213 return GetSameWordsRange(place, TRUE, FALSE); | 1164 } else |
1214 } | 1165 break; |
1215 | 1166 }; |
1216 CPVT_WordRange CPWL_Edit::GetArabicWordsRange(const CPVT_WordPlace & place) cons
t | 1167 } else if (bArabic) { |
1217 { | 1168 while (pIterator->NextWord()) { |
1218 return GetSameWordsRange(place, FALSE, TRUE); | 1169 if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word)) { |
1219 } | 1170 wpEnd = pIterator->GetAt(); |
1220 | 1171 continue; |
1221 #define PWL_ISARABICWORD(word) ((word >= 0x0600 && word <= 0x06FF) || (word >= 0
xFB50 && word <= 0xFEFC)) | 1172 } else |
1222 | 1173 break; |
1223 CPVT_WordRange CPWL_Edit::GetSameWordsRange(const CPVT_WordPlace & place, FX_BOO
L bLatin, FX_BOOL bArabic) const | 1174 }; |
1224 { | 1175 } |
1225 CPVT_WordRange range; | 1176 |
1226 | 1177 pIterator->SetAt(place); |
1227 if (IFX_Edit_Iterator* pIterator = m_pEdit->GetIterator()) | 1178 |
1228 { | 1179 if (bLatin) { |
1229 CPVT_Word wordinfo; | 1180 do { |
1230 CPVT_WordPlace wpStart(place),wpEnd(place); | 1181 if (pIterator->GetWord(wordinfo) && |
1231 pIterator->SetAt(place); | 1182 FX_EDIT_ISLATINWORD(wordinfo.Word)) { |
1232 | 1183 continue; |
1233 if (bLatin) | 1184 } else { |
1234 { | 1185 wpStart = pIterator->GetAt(); |
1235 while (pIterator->NextWord()) | 1186 break; |
1236 { | 1187 } |
1237 if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLA
TINWORD(wordinfo.Word)) | 1188 } while (pIterator->PrevWord()); |
1238 { | 1189 } else if (bArabic) { |
1239 wpEnd = pIterator->GetAt(); | 1190 do { |
1240 continue; | 1191 if (pIterator->GetWord(wordinfo) && PWL_ISARABICWORD(wordinfo.Word)) { |
1241 } | 1192 continue; |
1242 else | 1193 } else { |
1243 break; | 1194 wpStart = pIterator->GetAt(); |
1244 }; | 1195 break; |
1245 } | 1196 } |
1246 else if (bArabic) | 1197 } while (pIterator->PrevWord()); |
1247 { | 1198 } |
1248 while (pIterator->NextWord()) | 1199 |
1249 { | 1200 range.Set(wpStart, wpEnd); |
1250 if (pIterator->GetWord(wordinfo) && PWL_ISARABIC
WORD(wordinfo.Word)) | 1201 } |
1251 { | 1202 |
1252 wpEnd = pIterator->GetAt(); | 1203 return range; |
1253 continue; | 1204 } |
1254 } | 1205 |
1255 else | 1206 void CPWL_Edit::AjustArabicWords(const CPVT_WordRange& wr) {} |
1256 break; | 1207 |
1257 }; | 1208 void CPWL_Edit::GeneratePageObjects( |
1258 } | 1209 CPDF_PageObjects* pPageObjects, |
1259 | 1210 const CPDF_Point& ptOffset, |
1260 pIterator->SetAt(place); | 1211 CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) { |
1261 | 1212 IFX_Edit::GeneratePageObjects( |
1262 if (bLatin) | 1213 pPageObjects, m_pEdit, ptOffset, NULL, |
1263 { | 1214 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
1264 do | 1215 ObjArray); |
1265 { | |
1266 if (pIterator->GetWord(wordinfo) && FX_EDIT_ISLA
TINWORD(wordinfo.Word)) | |
1267 { | |
1268 continue; | |
1269 } | |
1270 else | |
1271 { | |
1272 wpStart = pIterator->GetAt(); | |
1273 break; | |
1274 } | |
1275 } | |
1276 while (pIterator->PrevWord()); | |
1277 } | |
1278 else if (bArabic) | |
1279 { | |
1280 do | |
1281 { | |
1282 if (pIterator->GetWord(wordinfo) && PWL_ISARABIC
WORD(wordinfo.Word)) | |
1283 { | |
1284 continue; | |
1285 } | |
1286 else | |
1287 { | |
1288 wpStart = pIterator->GetAt(); | |
1289 break; | |
1290 } | |
1291 } | |
1292 while (pIterator->PrevWord()); | |
1293 } | |
1294 | |
1295 range.Set(wpStart,wpEnd); | |
1296 } | |
1297 | |
1298 return range; | |
1299 } | |
1300 | |
1301 void CPWL_Edit::AjustArabicWords(const CPVT_WordRange& wr) | |
1302 { | |
1303 } | 1216 } |
1304 | 1217 |
1305 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, | 1218 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, |
1306 » » » » » » » » » »
const CPDF_Point& ptOffset, CFX_ArrayTemplate<CPDF_TextObject*>& ObjArray) | 1219 const CPDF_Point& ptOffset) { |
1307 { | 1220 CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; |
1308 » IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPW
L_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray); | 1221 IFX_Edit::GeneratePageObjects( |
1309 } | 1222 pPageObjects, m_pEdit, ptOffset, NULL, |
1310 | 1223 CPWL_Utils::PWLColorToFXColor(GetTextColor(), GetTransparency()), |
1311 void CPWL_Edit::GeneratePageObjects(CPDF_PageObjects* pPageObjects, | 1224 ObjArray); |
1312 » » » » » » » » » const CP
DF_Point& ptOffset) | 1225 } |
1313 { | |
1314 » CFX_ArrayTemplate<CPDF_TextObject*> ObjArray; | |
1315 » IFX_Edit::GeneratePageObjects(pPageObjects, m_pEdit, ptOffset, NULL, CPW
L_Utils::PWLColorToFXColor(GetTextColor(),GetTransparency()), ObjArray); | |
1316 } | |
1317 | |
OLD | NEW |