Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(544)

Side by Side Diff: fpdfsdk/src/fsdk_baseform.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "../../third_party/base/nonstd_unique_ptr.h" 7 #include "../../third_party/base/nonstd_unique_ptr.h"
8 #include "../include/fsdk_define.h" 8 #include "../include/fsdk_define.h"
9 #include "../include/fsdk_mgr.h" 9 #include "../include/fsdk_mgr.h"
10 #include "../include/fsdk_baseannot.h" 10 #include "../include/fsdk_baseannot.h"
11 #include "../include/fsdk_baseform.h" 11 #include "../include/fsdk_baseform.h"
12 #include "../include/formfiller/FFL_FormFiller.h" 12 #include "../include/formfiller/FFL_FormFiller.h"
13 #include "../include/fsdk_actionhandler.h" 13 #include "../include/fsdk_actionhandler.h"
14 14
15 #include "../include/javascript/IJavaScript.h" 15 #include "../include/javascript/IJavaScript.h"
16 16
17 //------------------------------------------------------------------------------ ------ 17 //------------------------------------------------------------------------------ ------
18 //* CPDFSDK_Widget 18 //* CPDFSDK_Widget
19 //------------------------------------------------------------------------------ ------ 19 //------------------------------------------------------------------------------ ------
20 20
21 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01) 21 #define IsFloatZero(f) ((f) < 0.01 && (f) > -0.01)
22 #define IsFloatBigger(fa,fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb))) 22 #define IsFloatBigger(fa, fb) ((fa) > (fb) && !IsFloatZero((fa) - (fb)))
23 #define IsFloatSmaller(fa,fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb))) 23 #define IsFloatSmaller(fa, fb) ((fa) < (fb) && !IsFloatZero((fa) - (fb)))
24 #define IsFloatEqual(fa,fb) IsFloatZero((fa)-(fb)) 24 #define IsFloatEqual(fa, fb) IsFloatZero((fa) - (fb))
25 25
26 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot, CPDFSDK_PageView* pPageView, CPDFSDK_InterForm* pInterForm) : 26 CPDFSDK_Widget::CPDFSDK_Widget(CPDF_Annot* pAnnot,
27 CPDFSDK_Annot(pAnnot, pPageView), 27 CPDFSDK_PageView* pPageView,
28 m_pInterForm(pInterForm), 28 CPDFSDK_InterForm* pInterForm)
29 m_nAppAge(0), 29 : CPDFSDK_Annot(pAnnot, pPageView),
30 m_nValueAge(0) 30 m_pInterForm(pInterForm),
31 { 31 m_nAppAge(0),
32 ASSERT(m_pInterForm != NULL); 32 m_nValueAge(0) {
33 } 33 ASSERT(m_pInterForm != NULL);
34 34 }
35 CPDFSDK_Widget::~CPDFSDK_Widget() 35
36 { 36 CPDFSDK_Widget::~CPDFSDK_Widget() {}
37 37
38 } 38 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(
39 39 CPDF_Annot::AppearanceMode mode) {
40 FX_BOOL CPDFSDK_Widget::IsWidgetAppearanceValid(CPDF_Annot::AppearanceMode m ode) 40 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP");
41 { 41 if (pAP == NULL)
42 CPDF_Dictionary* pAP = m_pAnnot->GetAnnotDict()->GetDict("AP"); 42 return FALSE;
43 if (pAP == NULL) return FALSE; 43
44 44 // Choose the right sub-ap
45 // Choose the right sub-ap 45 const FX_CHAR* ap_entry = "N";
46 const FX_CHAR* ap_entry = "N"; 46 if (mode == CPDF_Annot::Down)
47 if (mode == CPDF_Annot::Down) 47 ap_entry = "D";
48 ap_entry = "D"; 48 else if (mode == CPDF_Annot::Rollover)
49 else if (mode == CPDF_Annot::Rollover) 49 ap_entry = "R";
50 ap_entry = "R"; 50 if (!pAP->KeyExist(ap_entry))
51 if (!pAP->KeyExist(ap_entry)) 51 ap_entry = "N";
52 ap_entry = "N"; 52
53 53 // Get the AP stream or subdirectory
54 // Get the AP stream or subdirectory 54 CPDF_Object* psub = pAP->GetElementValue(ap_entry);
55 CPDF_Object* psub = pAP->GetElementValue(ap_entry); 55 if (psub == NULL)
56 if (psub == NULL) return FALSE; 56 return FALSE;
57 57
58 int nFieldType = GetFieldType(); 58 int nFieldType = GetFieldType();
59 switch (nFieldType) 59 switch (nFieldType) {
60 {
61 case FIELDTYPE_PUSHBUTTON: 60 case FIELDTYPE_PUSHBUTTON:
62 case FIELDTYPE_COMBOBOX: 61 case FIELDTYPE_COMBOBOX:
63 case FIELDTYPE_LISTBOX: 62 case FIELDTYPE_LISTBOX:
64 case FIELDTYPE_TEXTFIELD: 63 case FIELDTYPE_TEXTFIELD:
65 case FIELDTYPE_SIGNATURE: 64 case FIELDTYPE_SIGNATURE:
66 return psub->GetType() == PDFOBJ_STREAM; 65 return psub->GetType() == PDFOBJ_STREAM;
67 case FIELDTYPE_CHECKBOX: 66 case FIELDTYPE_CHECKBOX:
68 case FIELDTYPE_RADIOBUTTON: 67 case FIELDTYPE_RADIOBUTTON:
69 if (psub->GetType() == PDFOBJ_DICTIONARY) { 68 if (psub->GetType() == PDFOBJ_DICTIONARY) {
70 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub; 69 CPDF_Dictionary* pSubDict = (CPDF_Dictionary*)psub;
71 return pSubDict->GetStream(GetAppState()) != NULL; 70 return pSubDict->GetStream(GetAppState()) != NULL;
72 } 71 }
73 return FALSE; 72 return FALSE;
74 } 73 }
75 74
76 return TRUE; 75 return TRUE;
77 } 76 }
78 77
79 int CPDFSDK_Widget::GetFieldType() const 78 int CPDFSDK_Widget::GetFieldType() const {
80 { 79 CPDF_FormField* pField = GetFormField();
81 CPDF_FormField* pField = GetFormField(); 80 ASSERT(pField != NULL);
82 ASSERT(pField != NULL); 81
83 82 return pField->GetFieldType();
84 return pField->GetFieldType(); 83 }
85 } 84
86 85 int CPDFSDK_Widget::GetFieldFlags() const {
87 int CPDFSDK_Widget::GetFieldFlags() const 86 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
88 { 87 ASSERT(pPDFInterForm != NULL);
89 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); 88
90 ASSERT(pPDFInterForm != NULL); 89 CPDF_FormControl* pFormControl =
91 90 pPDFInterForm->GetControlByDict(m_pAnnot->GetAnnotDict());
92 CPDF_FormControl* pFormControl = pPDFInterForm->GetControlByDict(m_pAnnot->G etAnnotDict()); 91 CPDF_FormField* pFormField = pFormControl->GetField();
93 CPDF_FormField* pFormField = pFormControl->GetField(); 92 return pFormField->GetFieldFlags();
94 return pFormField->GetFieldFlags(); 93 }
95 } 94
96 95 CFX_ByteString CPDFSDK_Widget::GetSubType() const {
97 CFX_ByteString CPDFSDK_Widget::GetSubType() const 96 int nType = GetFieldType();
98 { 97
99 int nType = GetFieldType(); 98 if (nType == FIELDTYPE_SIGNATURE)
100 99 return BFFT_SIGNATURE;
101 if (nType == FIELDTYPE_SIGNATURE) 100 return CPDFSDK_Annot::GetSubType();
102 return BFFT_SIGNATURE; 101 }
103 return CPDFSDK_Annot::GetSubType(); 102
104 } 103 CPDF_FormField* CPDFSDK_Widget::GetFormField() const {
105 104 ASSERT(m_pInterForm != NULL);
106 CPDF_FormField* CPDFSDK_Widget::GetFormField() const 105
107 { 106 CPDF_FormControl* pCtrl = GetFormControl();
108 ASSERT(m_pInterForm != NULL); 107 ASSERT(pCtrl != NULL);
109 108
110 CPDF_FormControl* pCtrl = GetFormControl(); 109 return pCtrl->GetField();
111 ASSERT(pCtrl != NULL); 110 }
112 111
113 return pCtrl->GetField(); 112 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const {
114 } 113 ASSERT(m_pInterForm != NULL);
115 114
116 CPDF_FormControl* CPDFSDK_Widget::GetFormControl() const 115 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm();
117 { 116 ASSERT(pPDFInterForm != NULL);
118 ASSERT(m_pInterForm != NULL); 117
119 118 return pPDFInterForm->GetControlByDict(GetAnnotDict());
120 CPDF_InterForm* pPDFInterForm = m_pInterForm->GetInterForm(); 119 }
121 ASSERT(pPDFInterForm != NULL); 120
122 121 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm,
123 return pPDFInterForm->GetControlByDict(GetAnnotDict()); 122 CPDF_Dictionary* pAnnotDict) {
124 } 123 ASSERT(pInterForm != NULL);
125 124 ASSERT(pAnnotDict != NULL);
126 CPDF_FormControl* CPDFSDK_Widget::GetFormControl(CPDF_InterForm* pInterForm, CPD F_Dictionary* pAnnotDict) 125
127 { 126 CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict);
128 ASSERT(pInterForm != NULL); 127
129 ASSERT(pAnnotDict != NULL); 128 return pControl;
130 129 }
131 CPDF_FormControl* pControl = pInterForm->GetControlByDict(pAnnotDict); 130
132 131 int CPDFSDK_Widget::GetRotate() const {
133 return pControl; 132 CPDF_FormControl* pCtrl = GetFormControl();
134 } 133 ASSERT(pCtrl != NULL);
135 134
136 int CPDFSDK_Widget::GetRotate() const 135 return pCtrl->GetRotation() % 360;
137 { 136 }
138 CPDF_FormControl* pCtrl = GetFormControl(); 137
139 ASSERT(pCtrl != NULL); 138 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const {
140 139 CPDF_FormControl* pFormCtrl = GetFormControl();
141 return pCtrl->GetRotation() % 360; 140 ASSERT(pFormCtrl != NULL);
142 } 141
143 142 int iColorType = 0;
144 FX_BOOL CPDFSDK_Widget::GetFillColor(FX_COLORREF& color) const 143 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType));
145 { 144
146 CPDF_FormControl* pFormCtrl = GetFormControl(); 145 return iColorType != COLORTYPE_TRANSPARENT;
147 ASSERT(pFormCtrl != NULL); 146 }
148 147
149 int iColorType = 0; 148 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const {
150 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBackgroundColor(iColorType)); 149 CPDF_FormControl* pFormCtrl = GetFormControl();
150 ASSERT(pFormCtrl != NULL);
151
152 int iColorType = 0;
153 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType));
154
155 return iColorType != COLORTYPE_TRANSPARENT;
156 }
157
158 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const {
159 CPDF_FormControl* pFormCtrl = GetFormControl();
160 ASSERT(pFormCtrl != NULL);
161
162 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
163 if (da.HasColor()) {
164 FX_ARGB argb;
165 int iColorType = COLORTYPE_TRANSPARENT;
166 da.GetColor(argb, iColorType);
167 color = FX_ARGBTOCOLORREF(argb);
151 168
152 return iColorType != COLORTYPE_TRANSPARENT; 169 return iColorType != COLORTYPE_TRANSPARENT;
153 } 170 }
154 171
155 FX_BOOL CPDFSDK_Widget::GetBorderColor(FX_COLORREF& color) const 172 return FALSE;
156 { 173 }
157 CPDF_FormControl* pFormCtrl = GetFormControl(); 174
158 ASSERT(pFormCtrl != NULL); 175 FX_FLOAT CPDFSDK_Widget::GetFontSize() const {
159 176 CPDF_FormControl* pFormCtrl = GetFormControl();
160 int iColorType = 0; 177 ASSERT(pFormCtrl != NULL);
161 color = FX_ARGBTOCOLORREF(pFormCtrl->GetBorderColor(iColorType)); 178
162 179 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance();
163 return iColorType != COLORTYPE_TRANSPARENT; 180 CFX_ByteString csFont = "";
164 } 181 FX_FLOAT fFontSize = 0.0f;
165 182 pDa.GetFont(csFont, fFontSize);
166 FX_BOOL CPDFSDK_Widget::GetTextColor(FX_COLORREF& color) const 183
167 { 184 return fFontSize;
168 CPDF_FormControl* pFormCtrl = GetFormControl(); 185 }
169 ASSERT(pFormCtrl != NULL); 186
170 187 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const {
171 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance(); 188 CPDF_FormField* pFormField = GetFormField();
172 if (da.HasColor()) 189 ASSERT(pFormField != NULL);
173 { 190
174 FX_ARGB argb; 191 return pFormField->GetSelectedIndex(nIndex);
175 int iColorType = COLORTYPE_TRANSPARENT; 192 }
176 da.GetColor(argb, iColorType); 193
177 color = FX_ARGBTOCOLORREF(argb); 194 CFX_WideString CPDFSDK_Widget::GetValue() const {
178 195 CPDF_FormField* pFormField = GetFormField();
179 return iColorType != COLORTYPE_TRANSPARENT; 196 ASSERT(pFormField != NULL);
180 } 197
181 198 return pFormField->GetValue();
182 return FALSE; 199 }
183 } 200
184 201 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const {
185 FX_FLOAT CPDFSDK_Widget::GetFontSize() const 202 CPDF_FormField* pFormField = GetFormField();
186 { 203 ASSERT(pFormField != NULL);
187 CPDF_FormControl* pFormCtrl = GetFormControl(); 204
188 ASSERT(pFormCtrl != NULL); 205 return pFormField->GetDefaultValue();
189 206 }
190 CPDF_DefaultAppearance pDa = pFormCtrl->GetDefaultAppearance(); 207
191 CFX_ByteString csFont = ""; 208 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const {
192 FX_FLOAT fFontSize = 0.0f; 209 CPDF_FormField* pFormField = GetFormField();
193 pDa.GetFont(csFont, fFontSize); 210 ASSERT(pFormField != NULL);
194 211
195 return fFontSize; 212 return pFormField->GetOptionLabel(nIndex);
196 } 213 }
197 214
198 int CPDFSDK_Widget::GetSelectedIndex(int nIndex) const 215 int CPDFSDK_Widget::CountOptions() const {
199 { 216 CPDF_FormField* pFormField = GetFormField();
200 CPDF_FormField* pFormField = GetFormField(); 217 ASSERT(pFormField != NULL);
201 ASSERT(pFormField != NULL); 218
202 219 return pFormField->CountOptions();
203 return pFormField->GetSelectedIndex(nIndex); 220 }
204 } 221
205 222 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const {
206 CFX_WideString CPDFSDK_Widget::GetValue() const 223 CPDF_FormField* pFormField = GetFormField();
207 { 224 ASSERT(pFormField != NULL);
208 CPDF_FormField* pFormField = GetFormField(); 225
209 ASSERT(pFormField != NULL); 226 return pFormField->IsItemSelected(nIndex);
210 227 }
211 return pFormField->GetValue(); 228
212 } 229 int CPDFSDK_Widget::GetTopVisibleIndex() const {
213 230 CPDF_FormField* pFormField = GetFormField();
214 CFX_WideString CPDFSDK_Widget::GetDefaultValue() const 231 ASSERT(pFormField != NULL);
215 { 232
216 CPDF_FormField* pFormField = GetFormField(); 233 return pFormField->GetTopVisibleIndex();
217 ASSERT(pFormField != NULL); 234 }
218 235
219 return pFormField->GetDefaultValue(); 236 FX_BOOL CPDFSDK_Widget::IsChecked() const {
220 } 237 CPDF_FormControl* pFormCtrl = GetFormControl();
221 238 ASSERT(pFormCtrl != NULL);
222 CFX_WideString CPDFSDK_Widget::GetOptionLabel(int nIndex) const 239
223 { 240 return pFormCtrl->IsChecked();
224 CPDF_FormField* pFormField = GetFormField(); 241 }
225 ASSERT(pFormField != NULL); 242
226 243 int CPDFSDK_Widget::GetAlignment() const {
227 return pFormField->GetOptionLabel(nIndex); 244 CPDF_FormControl* pFormCtrl = GetFormControl();
228 } 245 ASSERT(pFormCtrl != NULL);
229 246
230 int CPDFSDK_Widget::CountOptions() const 247 return pFormCtrl->GetControlAlignment();
231 { 248 }
232 CPDF_FormField* pFormField = GetFormField(); 249
233 ASSERT(pFormField != NULL); 250 int CPDFSDK_Widget::GetMaxLen() const {
234 251 CPDF_FormField* pFormField = GetFormField();
235 return pFormField->CountOptions(); 252 ASSERT(pFormField != NULL);
236 } 253
237 254 return pFormField->GetMaxLen();
238 FX_BOOL CPDFSDK_Widget::IsOptionSelected(int nIndex) const 255 }
239 { 256
240 CPDF_FormField* pFormField = GetFormField(); 257 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) {
241 ASSERT(pFormField != NULL); 258 CPDF_FormControl* pFormCtrl = GetFormControl();
242 259 ASSERT(pFormCtrl != NULL);
243 return pFormField->IsItemSelected(nIndex); 260
244 } 261 CPDF_FormField* pFormField = pFormCtrl->GetField();
245 262 ASSERT(pFormField != NULL);
246 int CPDFSDK_Widget::GetTopVisibleIndex() const 263
247 { 264 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked,
248 CPDF_FormField* pFormField = GetFormField(); 265 bNotify);
249 ASSERT(pFormField != NULL); 266 }
250 267
251 return pFormField->GetTopVisibleIndex(); 268 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) {
252 } 269 CPDF_FormField* pFormField = GetFormField();
253 270 ASSERT(pFormField != NULL);
254 FX_BOOL CPDFSDK_Widget::IsChecked() const 271
255 { 272 pFormField->SetValue(sValue, bNotify);
256 CPDF_FormControl* pFormCtrl = GetFormControl(); 273 }
257 ASSERT(pFormCtrl != NULL); 274
258 275 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) {}
259 return pFormCtrl->IsChecked(); 276 void CPDFSDK_Widget::SetOptionSelection(int index,
260 } 277 FX_BOOL bSelected,
261 278 FX_BOOL bNotify) {
262 int CPDFSDK_Widget::GetAlignment() const 279 CPDF_FormField* pFormField = GetFormField();
263 { 280 ASSERT(pFormField != NULL);
264 CPDF_FormControl* pFormCtrl = GetFormControl(); 281
265 ASSERT(pFormCtrl != NULL); 282 pFormField->SetItemSelection(index, bSelected, bNotify);
266 283 }
267 return pFormCtrl->GetControlAlignment(); 284
268 } 285 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify) {
269 286 CPDF_FormField* pFormField = GetFormField();
270 int CPDFSDK_Widget::GetMaxLen() const 287 ASSERT(pFormField != NULL);
271 { 288
272 CPDF_FormField* pFormField = GetFormField(); 289 pFormField->ClearSelection(bNotify);
273 ASSERT(pFormField != NULL); 290 }
274 291
275 return pFormField->GetMaxLen(); 292 void CPDFSDK_Widget::SetTopVisibleIndex(int index) {}
276 } 293
277 294 void CPDFSDK_Widget::SetAppModified() {
278 void CPDFSDK_Widget::SetCheck(FX_BOOL bChecked, FX_BOOL bNotify) 295 m_bAppModified = TRUE;
279 { 296 }
280 CPDF_FormControl* pFormCtrl = GetFormControl(); 297
281 ASSERT(pFormCtrl != NULL); 298 void CPDFSDK_Widget::ClearAppModified() {
282 299 m_bAppModified = FALSE;
283 CPDF_FormField* pFormField = pFormCtrl->GetField(); 300 }
284 ASSERT(pFormField != NULL); 301
285 302 FX_BOOL CPDFSDK_Widget::IsAppModified() const {
286 pFormField->CheckControl(pFormField->GetControlIndex(pFormCtrl), bChecked, b Notify); 303 return m_bAppModified;
287 } 304 }
288 305
289 void CPDFSDK_Widget::SetValue(const CFX_WideString& sValue, FX_BOOL bNotify) 306 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue,
290 { 307 FX_BOOL bValueChanged) {
291 CPDF_FormField* pFormField = GetFormField(); 308 SetAppModified();
292 ASSERT(pFormField != NULL); 309
293 310 m_nAppAge++;
294 pFormField->SetValue(sValue, bNotify); 311 if (m_nAppAge > 999999)
295 } 312 m_nAppAge = 0;
296 313 if (bValueChanged)
297 void CPDFSDK_Widget::SetDefaultValue(const CFX_WideString& sValue) 314 m_nValueAge++;
298 { 315
299 } 316 int nFieldType = GetFieldType();
300 void CPDFSDK_Widget::SetOptionSelection(int index, FX_BOOL bSelected, FX_BOOL bN otify) 317
301 { 318 switch (nFieldType) {
302 CPDF_FormField* pFormField = GetFormField();
303 ASSERT(pFormField != NULL);
304
305 pFormField->SetItemSelection(index, bSelected, bNotify);
306 }
307
308 void CPDFSDK_Widget::ClearSelection(FX_BOOL bNotify)
309 {
310 CPDF_FormField* pFormField = GetFormField();
311 ASSERT(pFormField != NULL);
312
313 pFormField->ClearSelection(bNotify);
314 }
315
316 void CPDFSDK_Widget::SetTopVisibleIndex(int index)
317 {
318 }
319
320 void CPDFSDK_Widget::SetAppModified()
321 {
322 m_bAppModified = TRUE;
323 }
324
325 void CPDFSDK_Widget::ClearAppModified()
326 {
327 m_bAppModified = FALSE;
328 }
329
330 FX_BOOL CPDFSDK_Widget::IsAppModified() const
331 {
332 return m_bAppModified;
333 }
334
335 void CPDFSDK_Widget::ResetAppearance(const FX_WCHAR* sValue, FX_BOOL bValueChang ed)
336 {
337 SetAppModified();
338
339 m_nAppAge++;
340 if (m_nAppAge > 999999)
341 m_nAppAge = 0;
342 if (bValueChanged)
343 m_nValueAge++;
344
345 int nFieldType = GetFieldType();
346
347 switch (nFieldType)
348 {
349 case FIELDTYPE_PUSHBUTTON: 319 case FIELDTYPE_PUSHBUTTON:
350 ResetAppearance_PushButton(); 320 ResetAppearance_PushButton();
321 break;
322 case FIELDTYPE_CHECKBOX:
323 ResetAppearance_CheckBox();
324 break;
325 case FIELDTYPE_RADIOBUTTON:
326 ResetAppearance_RadioButton();
327 break;
328 case FIELDTYPE_COMBOBOX:
329 ResetAppearance_ComboBox(sValue);
330 break;
331 case FIELDTYPE_LISTBOX:
332 ResetAppearance_ListBox();
333 break;
334 case FIELDTYPE_TEXTFIELD:
335 ResetAppearance_TextField(sValue);
336 break;
337 }
338
339 ASSERT(m_pAnnot != NULL);
340 m_pAnnot->ClearCachedAP();
341 }
342
343 CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormated) {
344 CPDF_FormField* pFormField = GetFormField();
345 ASSERT(pFormField != NULL);
346 return m_pInterForm->OnFormat(pFormField, bFormated);
347 }
348
349 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged) {
350 CPDF_FormField* pFormField = GetFormField();
351 ASSERT(pFormField != NULL);
352
353 ASSERT(m_pInterForm != NULL);
354
355 m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
356 }
357
358 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice,
359 const CPDF_Matrix* pUser2Device,
360 CPDF_Annot::AppearanceMode mode,
361 const CPDF_RenderOptions* pOptions) {
362 int nFieldType = GetFieldType();
363
364 if ((nFieldType == FIELDTYPE_CHECKBOX ||
365 nFieldType == FIELDTYPE_RADIOBUTTON) &&
366 mode == CPDF_Annot::Normal &&
367 !IsWidgetAppearanceValid(CPDF_Annot::Normal)) {
368 CFX_PathData pathData;
369
370 CPDF_Rect rcAnnot = GetRect();
371
372 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom, rcAnnot.right,
373 rcAnnot.top);
374
375 CFX_GraphStateData gsd;
376 gsd.m_LineWidth = 0.0f;
377
378 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA,
379 FXFILL_ALTERNATE);
380 } else {
381 CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
382 }
383 }
384
385 void CPDFSDK_Widget::UpdateField() {
386 CPDF_FormField* pFormField = GetFormField();
387 ASSERT(pFormField != NULL);
388
389 ASSERT(m_pInterForm != NULL);
390 m_pInterForm->UpdateField(pFormField);
391 }
392
393 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice,
394 CPDFSDK_PageView* pPageView) {
395 ASSERT(m_pInterForm != NULL);
396
397 int nFieldType = GetFieldType();
398 if (m_pInterForm->IsNeedHighLight(nFieldType)) {
399 // if (nFieldType != FIELDTYPE_PUSHBUTTON)
400 // {
401 CPDF_Rect rc = GetRect();
402 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
403 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
404
405 CFX_FloatRect rcDevice;
406 ASSERT(m_pInterForm->GetDocument());
407 CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
408 if (!pEnv)
409 return;
410 CFX_AffineMatrix page2device;
411 pPageView->GetCurrentMatrix(page2device);
412 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom),
413 rcDevice.left, rcDevice.bottom);
414 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left,
415 // rc.bottom, &rcDevice.left, &rcDevice.bottom);
416 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right,
417 // rc.top, &rcDevice.right, &rcDevice.top);
418 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top),
419 rcDevice.right, rcDevice.top);
420
421 rcDevice.Normalize();
422
423 FX_ARGB argb = ArgbEncode((int)alpha, color);
424 FX_RECT rcDev((int)rcDevice.left, (int)rcDevice.top, (int)rcDevice.right,
425 (int)rcDevice.bottom);
426 pDevice->FillRect(&rcDev, argb);
427 /* }*/
428 }
429 }
430
431 void CPDFSDK_Widget::ResetAppearance_PushButton() {
432 CPDF_FormControl* pControl = GetFormControl();
433 ASSERT(pControl != NULL);
434
435 CPDF_Rect rcWindow = GetRotatedRect();
436
437 int32_t nLayout = 0;
438
439 switch (pControl->GetTextPosition()) {
440 case TEXTPOS_ICON:
441 nLayout = PPBL_ICON;
442 break;
443 case TEXTPOS_BELOW:
444 nLayout = PPBL_ICONTOPLABELBOTTOM;
445 break;
446 case TEXTPOS_ABOVE:
447 nLayout = PPBL_LABELTOPICONBOTTOM;
448 break;
449 case TEXTPOS_RIGHT:
450 nLayout = PPBL_ICONLEFTLABELRIGHT;
451 break;
452 case TEXTPOS_LEFT:
453 nLayout = PPBL_LABELLEFTICONRIGHT;
454 break;
455 case TEXTPOS_OVERLAID:
456 nLayout = PPBL_LABELOVERICON;
457 break;
458 default:
459 nLayout = PPBL_LABEL;
460 break;
461 }
462
463 CPWL_Color crBackground, crBorder;
464
465 int iColorType;
466 FX_FLOAT fc[4];
467
468 pControl->GetOriginalBackgroundColor(iColorType, fc);
469 if (iColorType > 0)
470 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
471
472 pControl->GetOriginalBorderColor(iColorType, fc);
473 if (iColorType > 0)
474 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
475
476 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
477 int32_t nBorderStyle = 0;
478 CPWL_Dash dsBorder(3, 0, 0);
479 CPWL_Color crLeftTop, crRightBottom;
480
481 switch (GetBorderStyle()) {
482 case BBS_DASH:
483 nBorderStyle = PBS_DASH;
484 dsBorder = CPWL_Dash(3, 3, 0);
485 break;
486 case BBS_BEVELED:
487 nBorderStyle = PBS_BEVELED;
488 fBorderWidth *= 2;
489 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
490 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
491 break;
492 case BBS_INSET:
493 nBorderStyle = PBS_INSET;
494 fBorderWidth *= 2;
495 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
496 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
497 break;
498 case BBS_UNDERLINE:
499 nBorderStyle = PBS_UNDERLINED;
500 break;
501 default:
502 nBorderStyle = PBS_SOLID;
503 break;
504 }
505
506 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
507
508 CPWL_Color crText(COLORTYPE_GRAY, 0);
509
510 FX_FLOAT fFontSize = 12.0f;
511 CFX_ByteString csNameTag;
512
513 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
514 if (da.HasColor()) {
515 da.GetColor(iColorType, fc);
516 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
517 }
518
519 if (da.HasFont())
520 da.GetFont(csNameTag, fFontSize);
521
522 CFX_WideString csWCaption;
523 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption;
524
525 if (pControl->HasMKEntry("CA")) {
526 csNormalCaption = pControl->GetNormalCaption();
527 }
528 if (pControl->HasMKEntry("RC")) {
529 csRolloverCaption = pControl->GetRolloverCaption();
530 }
531 if (pControl->HasMKEntry("AC")) {
532 csDownCaption = pControl->GetDownCaption();
533 }
534
535 CPDF_Stream* pNormalIcon = NULL;
536 CPDF_Stream* pRolloverIcon = NULL;
537 CPDF_Stream* pDownIcon = NULL;
538
539 if (pControl->HasMKEntry("I")) {
540 pNormalIcon = pControl->GetNormalIcon();
541 }
542 if (pControl->HasMKEntry("RI")) {
543 pRolloverIcon = pControl->GetRolloverIcon();
544 }
545 if (pControl->HasMKEntry("IX")) {
546 pDownIcon = pControl->GetDownIcon();
547 }
548
549 if (pNormalIcon) {
550 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) {
551 if (pImageDict->GetString("Name").IsEmpty())
552 pImageDict->SetAtString("Name", "ImgA");
553 }
554 }
555
556 if (pRolloverIcon) {
557 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict()) {
558 if (pImageDict->GetString("Name").IsEmpty())
559 pImageDict->SetAtString("Name", "ImgB");
560 }
561 }
562
563 if (pDownIcon) {
564 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict()) {
565 if (pImageDict->GetString("Name").IsEmpty())
566 pImageDict->SetAtString("Name", "ImgC");
567 }
568 }
569
570 CPDF_IconFit iconFit = pControl->GetIconFit();
571
572 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
573 ASSERT(pDoc != NULL);
574 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
575
576 CBA_FontMap FontMap(
577 this,
578 pEnv->GetSysHandler()); //,
579 //ISystemHandle::GetSystemHandler(m_pBaseForm->Ge tEnv()));
580 FontMap.Initial();
581
582 FontMap.SetAPType("N");
583
584 CFX_ByteString csAP =
585 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
586 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
587 crLeftTop, crRightBottom, nBorderStyle,
588 dsBorder) +
589 CPWL_Utils::GetPushButtonAppStream(
590 iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap,
591 pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout);
592
593 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP);
594 if (pNormalIcon)
595 AddImageToAppearance("N", pNormalIcon);
596
597 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode();
598 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) {
599 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) {
600 csRolloverCaption = csNormalCaption;
601 pRolloverIcon = pNormalIcon;
602 }
603
604 FontMap.SetAPType("R");
605
606 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
607 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
608 crLeftTop, crRightBottom,
609 nBorderStyle, dsBorder) +
610 CPWL_Utils::GetPushButtonAppStream(
611 iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap,
612 pRolloverIcon, iconFit, csRolloverCaption, crText, fFontSize,
613 nLayout);
614
615 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP);
616 if (pRolloverIcon)
617 AddImageToAppearance("R", pRolloverIcon);
618
619 if (csDownCaption.IsEmpty() && !pDownIcon) {
620 csDownCaption = csNormalCaption;
621 pDownIcon = pNormalIcon;
622 }
623
624 switch (nBorderStyle) {
625 case PBS_BEVELED: {
626 CPWL_Color crTemp = crLeftTop;
627 crLeftTop = crRightBottom;
628 crRightBottom = crTemp;
629 } break;
630 case PBS_INSET:
631 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
632 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
351 break; 633 break;
352 case FIELDTYPE_CHECKBOX: 634 }
353 ResetAppearance_CheckBox(); 635
636 FontMap.SetAPType("D");
637
638 csAP = CPWL_Utils::GetRectFillAppStream(
639 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
640 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
641 crLeftTop, crRightBottom,
642 nBorderStyle, dsBorder) +
643 CPWL_Utils::GetPushButtonAppStream(
644 iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap,
645 pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout);
646
647 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP);
648 if (pDownIcon)
649 AddImageToAppearance("D", pDownIcon);
650 } else {
651 RemoveAppearance("D");
652 RemoveAppearance("R");
653 }
654 }
655
656 void CPDFSDK_Widget::ResetAppearance_CheckBox() {
657 CPDF_FormControl* pControl = GetFormControl();
658 ASSERT(pControl != NULL);
659
660 CPWL_Color crBackground, crBorder, crText;
661
662 int iColorType;
663 FX_FLOAT fc[4];
664
665 pControl->GetOriginalBackgroundColor(iColorType, fc);
666 if (iColorType > 0)
667 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
668
669 pControl->GetOriginalBorderColor(iColorType, fc);
670 if (iColorType > 0)
671 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
672
673 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
674 int32_t nBorderStyle = 0;
675 CPWL_Dash dsBorder(3, 0, 0);
676 CPWL_Color crLeftTop, crRightBottom;
677
678 switch (GetBorderStyle()) {
679 case BBS_DASH:
680 nBorderStyle = PBS_DASH;
681 dsBorder = CPWL_Dash(3, 3, 0);
682 break;
683 case BBS_BEVELED:
684 nBorderStyle = PBS_BEVELED;
685 fBorderWidth *= 2;
686 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
687 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
688 break;
689 case BBS_INSET:
690 nBorderStyle = PBS_INSET;
691 fBorderWidth *= 2;
692 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
693 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
694 break;
695 case BBS_UNDERLINE:
696 nBorderStyle = PBS_UNDERLINED;
697 break;
698 default:
699 nBorderStyle = PBS_SOLID;
700 break;
701 }
702
703 CPDF_Rect rcWindow = GetRotatedRect();
704 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
705
706 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
707 if (da.HasColor()) {
708 da.GetColor(iColorType, fc);
709 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
710 }
711
712 int32_t nStyle = 0;
713
714 CFX_WideString csWCaption = pControl->GetNormalCaption();
715 if (csWCaption.GetLength() > 0) {
716 switch (csWCaption[0]) {
717 case L'l':
718 nStyle = PCS_CIRCLE;
354 break; 719 break;
355 case FIELDTYPE_RADIOBUTTON: 720 case L'8':
356 ResetAppearance_RadioButton(); 721 nStyle = PCS_CROSS;
357 break; 722 break;
358 case FIELDTYPE_COMBOBOX: 723 case L'u':
359 ResetAppearance_ComboBox(sValue); 724 nStyle = PCS_DIAMOND;
360 break; 725 break;
361 case FIELDTYPE_LISTBOX: 726 case L'n':
362 ResetAppearance_ListBox(); 727 nStyle = PCS_SQUARE;
363 break; 728 break;
364 case FIELDTYPE_TEXTFIELD: 729 case L'H':
365 ResetAppearance_TextField(sValue); 730 nStyle = PCS_STAR;
366 break; 731 break;
367 } 732 default: // L'4'
368 733 nStyle = PCS_CHECK;
369 ASSERT(m_pAnnot != NULL);
370 m_pAnnot->ClearCachedAP();
371 }
372
373 CFX_WideString CPDFSDK_Widget::OnFormat(FX_BOOL& bFormated)
374 {
375 CPDF_FormField* pFormField = GetFormField();
376 ASSERT(pFormField != NULL);
377 return m_pInterForm->OnFormat(pFormField, bFormated);
378 }
379
380 void CPDFSDK_Widget::ResetFieldAppearance(FX_BOOL bValueChanged)
381 {
382 CPDF_FormField* pFormField = GetFormField();
383 ASSERT(pFormField != NULL);
384
385 ASSERT(m_pInterForm != NULL);
386
387 m_pInterForm->ResetFieldAppearance(pFormField, NULL, bValueChanged);
388 }
389
390 void CPDFSDK_Widget::DrawAppearance(CFX_RenderDevice* pDevice, const CPDF_Mat rix* pUser2Device,
391 CPDF_Annot::AppearanceMode mode, const CPDF_RenderOptions* pOptions)
392 {
393 int nFieldType = GetFieldType();
394
395 if ((nFieldType == FIELDTYPE_CHECKBOX || nFieldType == FIELDTYPE_RADIOBUTTON ) &&
396 mode == CPDF_Annot::Normal &&
397 !IsWidgetAppearanceValid(CPDF_Annot::Normal))
398 {
399 CFX_PathData pathData;
400
401 CPDF_Rect rcAnnot = GetRect();
402
403 pathData.AppendRect(rcAnnot.left, rcAnnot.bottom,
404 rcAnnot.right, rcAnnot.top);
405
406 CFX_GraphStateData gsd;
407 gsd.m_LineWidth = 0.0f;
408
409 pDevice->DrawPath(&pathData, pUser2Device, &gsd, 0, 0xFFAAAAAA, FXFILL_A LTERNATE);
410 }
411 else
412 {
413 CPDFSDK_Annot::DrawAppearance(pDevice, pUser2Device, mode, pOptions);
414 }
415 }
416
417 void CPDFSDK_Widget::UpdateField()
418 {
419 CPDF_FormField* pFormField = GetFormField();
420 ASSERT(pFormField != NULL);
421
422 ASSERT(m_pInterForm != NULL);
423 m_pInterForm->UpdateField(pFormField);
424 }
425
426 void CPDFSDK_Widget::DrawShadow(CFX_RenderDevice* pDevice, CPDFSDK_PageView* pPa geView)
427 {
428 ASSERT(m_pInterForm != NULL);
429
430 int nFieldType = GetFieldType();
431 if (m_pInterForm->IsNeedHighLight(nFieldType))
432 {
433
434 // if (nFieldType != FIELDTYPE_PUSHBUTTON)
435 // {
436 CPDF_Rect rc = GetRect();
437 FX_COLORREF color = m_pInterForm->GetHighlightColor(nFieldType);
438 uint8_t alpha = m_pInterForm->GetHighlightAlpha();
439
440 CFX_FloatRect rcDevice;
441 ASSERT(m_pInterForm->GetDocument());
442 CPDFDoc_Environment* pEnv = m_pInterForm->GetDocument()->GetEnv();
443 if(!pEnv)
444 return;
445 CFX_AffineMatrix page2device;
446 pPageView->GetCurrentMatrix(page2device);
447 page2device.Transform(((FX_FLOAT)rc.left), ((FX_FLOAT)rc.bottom), rc Device.left, rcDevice.bottom);
448 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.left, rc.bottom , &rcDevice.left, &rcDevice.bottom);
449 // pEnv->FFI_PageToDevice(m_pPageView->GetPDFPage(), rc.right, rc.top, &rcDevice.right, &rcDevice.top);
450 page2device.Transform(((FX_FLOAT)rc.right), ((FX_FLOAT)rc.top), rcDe vice.right, rcDevice.top);
451
452 rcDevice.Normalize();
453
454 FX_ARGB argb = ArgbEncode((int)alpha, color);
455 FX_RECT rcDev((int)rcDevice.left,(int)rcDevice.top,(int)rcDevice.rig ht,(int)rcDevice.bottom);
456 pDevice->FillRect(&rcDev, argb);
457 /* }*/
458 }
459 }
460
461 void CPDFSDK_Widget::ResetAppearance_PushButton()
462 {
463 CPDF_FormControl* pControl = GetFormControl();
464 ASSERT(pControl != NULL);
465
466
467
468 CPDF_Rect rcWindow = GetRotatedRect();
469
470 int32_t nLayout = 0;
471
472 switch (pControl->GetTextPosition())
473 {
474 case TEXTPOS_ICON:
475 nLayout = PPBL_ICON;
476 break; 734 break;
477 case TEXTPOS_BELOW: 735 }
478 nLayout = PPBL_ICONTOPLABELBOTTOM; 736 } else {
737 nStyle = PCS_CHECK;
738 }
739
740 CFX_ByteString csAP_N_ON =
741 CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
742 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
743 crLeftTop, crRightBottom, nBorderStyle,
744 dsBorder);
745
746 CFX_ByteString csAP_N_OFF = csAP_N_ON;
747
748 switch (nBorderStyle) {
749 case PBS_BEVELED: {
750 CPWL_Color crTemp = crLeftTop;
751 crLeftTop = crRightBottom;
752 crRightBottom = crTemp;
753 } break;
754 case PBS_INSET:
755 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
756 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
757 break;
758 }
759
760 CFX_ByteString csAP_D_ON =
761 CPWL_Utils::GetRectFillAppStream(
762 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
763 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
764 crLeftTop, crRightBottom, nBorderStyle,
765 dsBorder);
766
767 CFX_ByteString csAP_D_OFF = csAP_D_ON;
768
769 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
770 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient, nStyle, crText);
771
772 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
773 pControl->GetCheckedAPState());
774 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
775
776 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
777 pControl->GetCheckedAPState());
778 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
779
780 CFX_ByteString csAS = GetAppState();
781 if (csAS.IsEmpty())
782 SetAppState("Off");
783 }
784
785 void CPDFSDK_Widget::ResetAppearance_RadioButton() {
786 CPDF_FormControl* pControl = GetFormControl();
787 ASSERT(pControl != NULL);
788
789 CPWL_Color crBackground, crBorder, crText;
790
791 int iColorType;
792 FX_FLOAT fc[4];
793
794 pControl->GetOriginalBackgroundColor(iColorType, fc);
795 if (iColorType > 0)
796 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
797
798 pControl->GetOriginalBorderColor(iColorType, fc);
799 if (iColorType > 0)
800 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
801
802 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
803 int32_t nBorderStyle = 0;
804 CPWL_Dash dsBorder(3, 0, 0);
805 CPWL_Color crLeftTop, crRightBottom;
806
807 switch (GetBorderStyle()) {
808 case BBS_DASH:
809 nBorderStyle = PBS_DASH;
810 dsBorder = CPWL_Dash(3, 3, 0);
811 break;
812 case BBS_BEVELED:
813 nBorderStyle = PBS_BEVELED;
814 fBorderWidth *= 2;
815 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
816 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
817 break;
818 case BBS_INSET:
819 nBorderStyle = PBS_INSET;
820 fBorderWidth *= 2;
821 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
822 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
823 break;
824 case BBS_UNDERLINE:
825 nBorderStyle = PBS_UNDERLINED;
826 break;
827 default:
828 nBorderStyle = PBS_SOLID;
829 break;
830 }
831
832 CPDF_Rect rcWindow = GetRotatedRect();
833 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
834
835 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
836 if (da.HasColor()) {
837 da.GetColor(iColorType, fc);
838 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
839 }
840
841 int32_t nStyle = 0;
842
843 CFX_WideString csWCaption = pControl->GetNormalCaption();
844 if (csWCaption.GetLength() > 0) {
845 switch (csWCaption[0]) {
846 default: // L'l':
847 nStyle = PCS_CIRCLE;
479 break; 848 break;
480 case TEXTPOS_ABOVE: 849 case L'8':
481 nLayout = PPBL_LABELTOPICONBOTTOM; 850 nStyle = PCS_CROSS;
482 break; 851 break;
483 case TEXTPOS_RIGHT: 852 case L'u':
484 nLayout = PPBL_ICONLEFTLABELRIGHT; 853 nStyle = PCS_DIAMOND;
485 break; 854 break;
486 case TEXTPOS_LEFT: 855 case L'n':
487 nLayout = PPBL_LABELLEFTICONRIGHT; 856 nStyle = PCS_SQUARE;
488 break; 857 break;
489 case TEXTPOS_OVERLAID: 858 case L'H':
490 nLayout = PPBL_LABELOVERICON; 859 nStyle = PCS_STAR;
491 break; 860 break;
492 default: 861 case L'4':
493 nLayout = PPBL_LABEL; 862 nStyle = PCS_CHECK;
494 break; 863 break;
495 } 864 }
496 865 } else {
497 CPWL_Color crBackground, crBorder; 866 nStyle = PCS_CIRCLE;
498 867 }
499 int iColorType; 868
500 FX_FLOAT fc[4]; 869 CFX_ByteString csAP_N_ON;
501 870
502 pControl->GetOriginalBackgroundColor(iColorType, fc); 871 CPDF_Rect rcCenter =
503 if (iColorType > 0) 872 CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcWindow), 1.0f);
504 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); 873
505 874 if (nStyle == PCS_CIRCLE) {
506 pControl->GetOriginalBorderColor(iColorType, fc); 875 if (nBorderStyle == PBS_BEVELED) {
507 if (iColorType > 0) 876 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
508 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); 877 crRightBottom = CPWL_Utils::SubstractColor(crBackground, 0.25f);
509 878 } else if (nBorderStyle == PBS_INSET) {
510 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); 879 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5f);
511 int32_t nBorderStyle = 0; 880 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75f);
512 CPWL_Dash dsBorder(3,0,0); 881 }
513 CPWL_Color crLeftTop,crRightBottom; 882
514 883 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBackground) +
515 switch (GetBorderStyle()) 884 CPWL_Utils::GetCircleBorderAppStream(
516 { 885 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
517 case BBS_DASH: 886 nBorderStyle, dsBorder);
518 nBorderStyle = PBS_DASH; 887 } else {
519 dsBorder = CPWL_Dash(3, 3, 0); 888 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) +
520 break; 889 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
521 case BBS_BEVELED: 890 crLeftTop, crRightBottom,
522 nBorderStyle = PBS_BEVELED; 891 nBorderStyle, dsBorder);
523 fBorderWidth *= 2; 892 }
524 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1); 893
525 crRightBottom = CPWL_Utils::DevideColor(crBackground,2); 894 CFX_ByteString csAP_N_OFF = csAP_N_ON;
526 break; 895
527 case BBS_INSET: 896 switch (nBorderStyle) {
528 nBorderStyle = PBS_INSET; 897 case PBS_BEVELED: {
529 fBorderWidth *= 2; 898 CPWL_Color crTemp = crLeftTop;
530 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5); 899 crLeftTop = crRightBottom;
531 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75); 900 crRightBottom = crTemp;
532 break; 901 } break;
533 case BBS_UNDERLINE: 902 case PBS_INSET:
534 nBorderStyle = PBS_UNDERLINED; 903 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
535 break; 904 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
536 default: 905 break;
537 nBorderStyle = PBS_SOLID; 906 }
538 break; 907
539 } 908 CFX_ByteString csAP_D_ON;
540 909
541 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth); 910 if (nStyle == PCS_CIRCLE) {
542 911 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground, 0.25f);
543 CPWL_Color crText(COLORTYPE_GRAY,0); 912 if (nBorderStyle == PBS_BEVELED) {
544 913 crLeftTop = CPWL_Utils::SubstractColor(crBackground, 0.25f);
545 FX_FLOAT fFontSize = 12.0f; 914 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
546 CFX_ByteString csNameTag; 915 crBK = crBackground;
547 916 } else if (nBorderStyle == PBS_INSET) {
548 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance(); 917 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0);
549 if (da.HasColor()) 918 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
550 { 919 }
551 da.GetColor(iColorType, fc); 920
552 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); 921 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter, crBK) +
553 } 922 CPWL_Utils::GetCircleBorderAppStream(
554 923 rcCenter, fBorderWidth, crBorder, crLeftTop, crRightBottom,
555 if (da.HasFont()) 924 nBorderStyle, dsBorder);
556 da.GetFont(csNameTag, fFontSize); 925 } else {
557 926 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(
558 CFX_WideString csWCaption; 927 rcWindow, CPWL_Utils::SubstractColor(crBackground, 0.25f)) +
559 CFX_WideString csNormalCaption, csRolloverCaption, csDownCaption; 928 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
560 929 crLeftTop, crRightBottom,
561 if (pControl->HasMKEntry("CA")) 930 nBorderStyle, dsBorder);
562 { 931 }
563 csNormalCaption = pControl->GetNormalCaption(); 932
564 } 933 CFX_ByteString csAP_D_OFF = csAP_D_ON;
565 if (pControl->HasMKEntry("RC")) 934
566 { 935 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
567 csRolloverCaption = pControl->GetRolloverCaption(); 936 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient, nStyle, crText);
568 } 937
569 if (pControl->HasMKEntry("AC")) 938 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON,
570 { 939 pControl->GetCheckedAPState());
571 csDownCaption = pControl->GetDownCaption(); 940 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
572 } 941
573 942 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON,
574 CPDF_Stream* pNormalIcon = NULL; 943 pControl->GetCheckedAPState());
575 CPDF_Stream* pRolloverIcon = NULL; 944 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
576 CPDF_Stream* pDownIcon = NULL; 945
577 946 CFX_ByteString csAS = GetAppState();
578 if (pControl->HasMKEntry("I")) 947 if (csAS.IsEmpty())
579 { 948 SetAppState("Off");
580 pNormalIcon = pControl->GetNormalIcon(); 949 }
581 } 950
582 if (pControl->HasMKEntry("RI")) 951 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue) {
583 { 952 CPDF_FormControl* pControl = GetFormControl();
584 pRolloverIcon = pControl->GetRolloverIcon(); 953 ASSERT(pControl != NULL);
585 } 954 CPDF_FormField* pField = pControl->GetField();
586 if (pControl->HasMKEntry("IX")) 955 ASSERT(pField != NULL);
587 { 956
588 pDownIcon = pControl->GetDownIcon(); 957 CFX_ByteTextBuf sBody, sLines;
589 } 958
590 959 CPDF_Rect rcClient = GetClientRect();
591 if (pNormalIcon) 960 CPDF_Rect rcButton = rcClient;
592 { 961 rcButton.left = rcButton.right - 13;
593 if (CPDF_Dictionary* pImageDict = pNormalIcon->GetDict()) 962 rcButton.Normalize();
594 { 963
595 if (pImageDict->GetString("Name").IsEmpty()) 964 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
596 pImageDict->SetAtString("Name", "ImgA"); 965 pEdit->EnableRefresh(FALSE);
597 }
598 }
599
600 if (pRolloverIcon)
601 {
602 if (CPDF_Dictionary* pImageDict = pRolloverIcon->GetDict())
603 {
604 if (pImageDict->GetString("Name").IsEmpty())
605 pImageDict->SetAtString("Name", "ImgB");
606 }
607 }
608
609 if (pDownIcon)
610 {
611 if (CPDF_Dictionary* pImageDict = pDownIcon->GetDict())
612 {
613 if (pImageDict->GetString("Name").IsEmpty())
614 pImageDict->SetAtString("Name", "ImgC");
615 }
616 }
617
618 CPDF_IconFit iconFit = pControl->GetIconFit();
619 966
620 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument(); 967 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
621 ASSERT(pDoc != NULL); 968 ASSERT(pDoc != NULL);
622 CPDFDoc_Environment* pEnv = pDoc->GetEnv(); 969 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
623 970 CBA_FontMap FontMap(this, pEnv->GetSysHandler());
624 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSystem Handler(m_pBaseForm->GetEnv()));
625 FontMap.Initial(); 971 FontMap.Initial();
626 972 pEdit->SetFontMap(&FontMap);
627 FontMap.SetAPType("N"); 973
628 974 CPDF_Rect rcEdit = rcClient;
629 CFX_ByteString csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackgroun d) + 975 rcEdit.right = rcButton.left;
630 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftT op, crRightBottom, nBorderStyle, dsBorder) + 976 rcEdit.Normalize();
631 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pNormalIcon, iconFit, csNormalCaption, crText, fFontSize, nLayout); 977
632 978 pEdit->SetPlateRect(rcEdit);
633 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP); 979 pEdit->SetAlignmentV(1);
634 if (pNormalIcon) 980
635 AddImageToAppearance("N", pNormalIcon); 981 FX_FLOAT fFontSize = GetFontSize();
636 982 if (IsFloatZero(fFontSize))
637 CPDF_FormControl::HighlightingMode eHLM = pControl->GetHighlightingMode(); 983 pEdit->SetAutoFontSize(TRUE);
638 if (eHLM == CPDF_FormControl::Push || eHLM == CPDF_FormControl::Toggle) 984 else
639 { 985 pEdit->SetFontSize(fFontSize);
640 if (csRolloverCaption.IsEmpty() && !pRolloverIcon) 986
641 { 987 pEdit->Initialize();
642 csRolloverCaption = csNormalCaption; 988
643 pRolloverIcon = pNormalIcon; 989 if (sValue)
990 pEdit->SetText(sValue);
991 else {
992 int32_t nCurSel = pField->GetSelectedIndex(0);
993
994 if (nCurSel < 0)
995 pEdit->SetText(pField->GetValue().c_str());
996 else
997 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
998 }
999
1000 CPDF_Rect rcContent = pEdit->GetContentRect();
1001
1002 CFX_ByteString sEdit =
1003 CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f, 0.0f));
1004 if (sEdit.GetLength() > 0) {
1005 sBody << "/Tx BMC\n"
1006 << "q\n";
1007 if (rcContent.Width() > rcEdit.Width() ||
1008 rcContent.Height() > rcEdit.Height()) {
1009 sBody << rcEdit.left << " " << rcEdit.bottom << " " << rcEdit.Width()
1010 << " " << rcEdit.Height() << " re\nW\nn\n";
1011 }
1012
1013 CPWL_Color crText = GetTextPWLColor();
1014 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
1015 << "ET\n"
1016 << "Q\nEMC\n";
1017 }
1018
1019 IFX_Edit::DelEdit(pEdit);
1020 }
1021
1022 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton);
1023
1024 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1025 sLines.GetByteString() + sBody.GetByteString();
1026
1027 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1028 }
1029
1030 void CPDFSDK_Widget::ResetAppearance_ListBox() {
1031 CPDF_FormControl* pControl = GetFormControl();
1032 ASSERT(pControl != NULL);
1033 CPDF_FormField* pField = pControl->GetField();
1034 ASSERT(pField != NULL);
1035
1036 CPDF_Rect rcClient = GetClientRect();
1037
1038 CFX_ByteTextBuf sBody, sLines;
1039
1040 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
1041 pEdit->EnableRefresh(FALSE);
1042
1043 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1044 ASSERT(pDoc != NULL);
1045 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1046
1047 CBA_FontMap FontMap(this, pEnv->GetSysHandler());
1048 FontMap.Initial();
1049 pEdit->SetFontMap(&FontMap);
1050
1051 pEdit->SetPlateRect(CPDF_Rect(rcClient.left, 0.0f, rcClient.right, 0.0f));
1052
1053 FX_FLOAT fFontSize = GetFontSize();
1054
1055 if (IsFloatZero(fFontSize))
1056 pEdit->SetFontSize(12.0f);
1057 else
1058 pEdit->SetFontSize(fFontSize);
1059
1060 pEdit->Initialize();
1061
1062 CFX_ByteTextBuf sList;
1063 FX_FLOAT fy = rcClient.top;
1064
1065 int32_t nTop = pField->GetTopVisibleIndex();
1066 int32_t nCount = pField->CountOptions();
1067 int32_t nSelCount = pField->CountSelectedItems();
1068
1069 for (int32_t i = nTop; i < nCount; i++) {
1070 FX_BOOL bSelected = FALSE;
1071 for (int32_t j = 0; j < nSelCount; j++) {
1072 if (pField->GetSelectedIndex(j) == i) {
1073 bSelected = TRUE;
1074 break;
644 } 1075 }
645 1076 }
646 FontMap.SetAPType("R"); 1077
647 1078 pEdit->SetText(pField->GetOptionLabel(i).c_str());
648 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, crBackground) + 1079
649 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLeftTop, crRightBottom, nBorderStyle, dsBorder) + 1080 CPDF_Rect rcContent = pEdit->GetContentRect();
650 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWindow : rcClient, &FontMap, pRolloverIcon, iconFit, csRolloverCaption, crText , fFontSize, nLayout); 1081 FX_FLOAT fItemHeight = rcContent.Height();
651 1082
652 WriteAppearance("R", GetRotatedRect(), GetMatrix(), csAP); 1083 if (bSelected) {
653 if (pRolloverIcon) 1084 CPDF_Rect rcItem =
654 AddImageToAppearance("R", pRolloverIcon); 1085 CPDF_Rect(rcClient.left, fy - fItemHeight, rcClient.right, fy);
655 1086 sList << "q\n" << CPWL_Utils::GetColorAppStream(
656 if (csDownCaption.IsEmpty() && !pDownIcon) 1087 CPWL_Color(COLORTYPE_RGB, 0, 51.0f / 255.0f,
657 { 1088 113.0f / 255.0f),
658 csDownCaption = csNormalCaption; 1089 TRUE)
659 pDownIcon = pNormalIcon; 1090 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Width()
1091 << " " << rcItem.Height() << " re f\n"
1092 << "Q\n";
1093
1094 sList << "BT\n" << CPWL_Utils::GetColorAppStream(
1095 CPWL_Color(COLORTYPE_GRAY, 1), TRUE)
1096 << CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f, fy))
1097 << "ET\n";
1098 } else {
1099 CPWL_Color crText = GetTextPWLColor();
1100 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText, TRUE)
1101 << CPWL_Utils::GetEditAppStream(pEdit, CPDF_Point(0.0f, fy))
1102 << "ET\n";
1103 }
1104
1105 fy -= fItemHeight;
1106 }
1107
1108 if (sList.GetSize() > 0) {
1109 sBody << "/Tx BMC\n"
1110 << "q\n" << rcClient.left << " " << rcClient.bottom << " "
1111 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1112 sBody << sList << "Q\nEMC\n";
1113 }
1114
1115 IFX_Edit::DelEdit(pEdit);
1116 }
1117
1118 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1119 sLines.GetByteString() + sBody.GetByteString();
1120
1121 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1122 }
1123
1124 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue) {
1125 CPDF_FormControl* pControl = GetFormControl();
1126 ASSERT(pControl != NULL);
1127 CPDF_FormField* pField = pControl->GetField();
1128 ASSERT(pField != NULL);
1129
1130 CFX_ByteTextBuf sBody, sLines;
1131
1132 if (IFX_Edit* pEdit = IFX_Edit::NewEdit()) {
1133 pEdit->EnableRefresh(FALSE);
1134
1135 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1136 ASSERT(pDoc != NULL);
1137 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1138
1139 CBA_FontMap FontMap(
1140 this,
1141 pEnv->GetSysHandler()); //,
1142 //ISystemHandle::GetSystemHandler(m_pBaseForm-> GetEnv()));
1143 FontMap.Initial();
1144 pEdit->SetFontMap(&FontMap);
1145
1146 CPDF_Rect rcClient = GetClientRect();
1147 pEdit->SetPlateRect(rcClient);
1148 pEdit->SetAlignmentH(pControl->GetControlAlignment());
1149
1150 FX_DWORD dwFieldFlags = pField->GetFieldFlags();
1151 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
1152
1153 if (bMultiLine) {
1154 pEdit->SetMultiLine(TRUE);
1155 pEdit->SetAutoReturn(TRUE);
1156 } else {
1157 pEdit->SetAlignmentV(1);
1158 }
1159
1160 FX_WORD subWord = 0;
1161 if ((dwFieldFlags >> 13) & 1) {
1162 subWord = '*';
1163 pEdit->SetPasswordChar(subWord);
1164 }
1165
1166 int nMaxLen = pField->GetMaxLen();
1167 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1168 FX_FLOAT fFontSize = GetFontSize();
1169
1170 if (nMaxLen > 0) {
1171 if (bCharArray) {
1172 pEdit->SetCharArray(nMaxLen);
1173
1174 if (IsFloatZero(fFontSize)) {
1175 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetPDFFont(0),
1176 rcClient, nMaxLen);
660 } 1177 }
661 1178 } else {
662 switch (nBorderStyle) 1179 if (sValue)
663 { 1180 nMaxLen = wcslen((const wchar_t*)sValue);
664 case PBS_BEVELED: 1181 pEdit->SetLimitChar(nMaxLen);
665 { 1182 }
666 CPWL_Color crTemp = crLeftTop; 1183 }
667 crLeftTop = crRightBottom; 1184
668 crRightBottom = crTemp; 1185 if (IsFloatZero(fFontSize))
1186 pEdit->SetAutoFontSize(TRUE);
1187 else
1188 pEdit->SetFontSize(fFontSize);
1189
1190 pEdit->Initialize();
1191
1192 if (sValue)
1193 pEdit->SetText(sValue);
1194 else
1195 pEdit->SetText(pField->GetValue().c_str());
1196
1197 CPDF_Rect rcContent = pEdit->GetContentRect();
1198
1199 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(
1200 pEdit, CPDF_Point(0.0f, 0.0f), NULL, !bCharArray, subWord);
1201
1202 if (sEdit.GetLength() > 0) {
1203 sBody << "/Tx BMC\n"
1204 << "q\n";
1205 if (rcContent.Width() > rcClient.Width() ||
1206 rcContent.Height() > rcClient.Height()) {
1207 sBody << rcClient.left << " " << rcClient.bottom << " "
1208 << rcClient.Width() << " " << rcClient.Height() << " re\nW\nn\n";
1209 }
1210 CPWL_Color crText = GetTextPWLColor();
1211 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit
1212 << "ET\n"
1213 << "Q\nEMC\n";
1214 }
1215
1216 if (bCharArray) {
1217 switch (GetBorderStyle()) {
1218 case BBS_SOLID: {
1219 CFX_ByteString sColor =
1220 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
1221 if (sColor.GetLength() > 0) {
1222 sLines << "q\n" << GetBorderWidth() << " w\n"
1223 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
1224 << " 2 J 0 j\n";
1225
1226 for (int32_t i = 1; i < nMaxLen; i++) {
1227 sLines << rcClient.left +
1228 ((rcClient.right - rcClient.left) / nMaxLen) * i
1229 << " " << rcClient.bottom << " m\n"
1230 << rcClient.left +
1231 ((rcClient.right - rcClient.left) / nMaxLen) * i
1232 << " " << rcClient.top << " l S\n";
669 } 1233 }
670 break; 1234
671 case PBS_INSET: 1235 sLines << "Q\n";
672 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0); 1236 }
673 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1); 1237 } break;
674 break; 1238 case BBS_DASH: {
675 } 1239 CFX_ByteString sColor =
676 1240 CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE);
677 FontMap.SetAPType("D"); 1241 if (sColor.GetLength() > 0) {
678 1242 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
679 csAP = CPWL_Utils::GetRectFillAppStream(rcWindow, CPWL_Utils::SubstractC olor(crBackground,0.25f)) + 1243
680 CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crL eftTop, crRightBottom, nBorderStyle, dsBorder) + 1244 sLines << "q\n" << GetBorderWidth() << " w\n"
681 CPWL_Utils::GetPushButtonAppStream(iconFit.GetFittingBounds() ? rcWi ndow : rcClient, &FontMap, pDownIcon, iconFit, csDownCaption, crText, fFontSize, nLayout); 1245 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor(), FALSE)
682 1246 << "[" << dsBorder.nDash << " " << dsBorder.nGap << "] "
683 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP); 1247 << dsBorder.nPhase << " d\n";
684 if (pDownIcon) 1248
685 AddImageToAppearance("D", pDownIcon); 1249 for (int32_t i = 1; i < nMaxLen; i++) {
686 } 1250 sLines << rcClient.left +
687 else 1251 ((rcClient.right - rcClient.left) / nMaxLen) * i
688 { 1252 << " " << rcClient.bottom << " m\n"
689 RemoveAppearance("D"); 1253 << rcClient.left +
690 RemoveAppearance("R"); 1254 ((rcClient.right - rcClient.left) / nMaxLen) * i
691 } 1255 << " " << rcClient.top << " l S\n";
692 }
693
694 void CPDFSDK_Widget::ResetAppearance_CheckBox()
695 {
696 CPDF_FormControl* pControl = GetFormControl();
697 ASSERT(pControl != NULL);
698
699
700
701 CPWL_Color crBackground, crBorder, crText;
702
703 int iColorType;
704 FX_FLOAT fc[4];
705
706 pControl->GetOriginalBackgroundColor(iColorType, fc);
707 if (iColorType > 0)
708 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
709
710 pControl->GetOriginalBorderColor(iColorType, fc);
711 if (iColorType > 0)
712 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
713
714 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
715 int32_t nBorderStyle = 0;
716 CPWL_Dash dsBorder(3,0,0);
717 CPWL_Color crLeftTop,crRightBottom;
718
719 switch (GetBorderStyle())
720 {
721 case BBS_DASH:
722 nBorderStyle = PBS_DASH;
723 dsBorder = CPWL_Dash(3, 3, 0);
724 break;
725 case BBS_BEVELED:
726 nBorderStyle = PBS_BEVELED;
727 fBorderWidth *= 2;
728 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
729 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
730 break;
731 case BBS_INSET:
732 nBorderStyle = PBS_INSET;
733 fBorderWidth *= 2;
734 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
735 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
736 break;
737 case BBS_UNDERLINE:
738 nBorderStyle = PBS_UNDERLINED;
739 break;
740 default:
741 nBorderStyle = PBS_SOLID;
742 break;
743 }
744
745 CPDF_Rect rcWindow = GetRotatedRect();
746 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow,fBorderWidth);
747
748 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
749 if (da.HasColor())
750 {
751 da.GetColor(iColorType, fc);
752 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
753 }
754
755 int32_t nStyle = 0;
756
757 CFX_WideString csWCaption = pControl->GetNormalCaption();
758 if (csWCaption.GetLength() > 0)
759 {
760 switch (csWCaption[0])
761 {
762 case L'l':
763 nStyle = PCS_CIRCLE;
764 break;
765 case L'8':
766 nStyle = PCS_CROSS;
767 break;
768 case L'u':
769 nStyle = PCS_DIAMOND;
770 break;
771 case L'n':
772 nStyle = PCS_SQUARE;
773 break;
774 case L'H':
775 nStyle = PCS_STAR;
776 break;
777 default: //L'4'
778 nStyle = PCS_CHECK;
779 break;
780 }
781 }
782 else
783 {
784 nStyle = PCS_CHECK;
785 }
786
787 CFX_ByteString csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackg round) +
788 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop, crRightBottom,nBorderStyle,dsBorder);
789
790 CFX_ByteString csAP_N_OFF = csAP_N_ON;
791
792 switch (nBorderStyle)
793 {
794 case PBS_BEVELED:
795 {
796 CPWL_Color crTemp = crLeftTop;
797 crLeftTop = crRightBottom;
798 crRightBottom = crTemp;
799 }
800 break;
801 case PBS_INSET:
802 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
803 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
804 break;
805 }
806
807 CFX_ByteString csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Ut ils::SubstractColor(crBackground,0.25f)) +
808 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeftTop, crRightBottom,nBorderStyle,dsBorder);
809
810 CFX_ByteString csAP_D_OFF = csAP_D_ON;
811
812 csAP_N_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
813 csAP_D_ON += CPWL_Utils::GetCheckBoxAppStream(rcClient,nStyle,crText);
814
815 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->Get CheckedAPState());
816 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
817
818 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->Get CheckedAPState());
819 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
820
821 CFX_ByteString csAS = GetAppState();
822 if (csAS.IsEmpty())
823 SetAppState("Off");
824 }
825
826 void CPDFSDK_Widget::ResetAppearance_RadioButton()
827 {
828 CPDF_FormControl* pControl = GetFormControl();
829 ASSERT(pControl != NULL);
830
831
832
833 CPWL_Color crBackground, crBorder, crText;
834
835 int iColorType;
836 FX_FLOAT fc[4];
837
838 pControl->GetOriginalBackgroundColor(iColorType, fc);
839 if (iColorType > 0)
840 crBackground = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
841
842 pControl->GetOriginalBorderColor(iColorType, fc);
843 if (iColorType > 0)
844 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
845
846 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
847 int32_t nBorderStyle = 0;
848 CPWL_Dash dsBorder(3,0,0);
849 CPWL_Color crLeftTop,crRightBottom;
850
851 switch (GetBorderStyle())
852 {
853 case BBS_DASH:
854 nBorderStyle = PBS_DASH;
855 dsBorder = CPWL_Dash(3, 3, 0);
856 break;
857 case BBS_BEVELED:
858 nBorderStyle = PBS_BEVELED;
859 fBorderWidth *= 2;
860 crLeftTop = CPWL_Color(COLORTYPE_GRAY,1);
861 crRightBottom = CPWL_Utils::DevideColor(crBackground,2);
862 break;
863 case BBS_INSET:
864 nBorderStyle = PBS_INSET;
865 fBorderWidth *= 2;
866 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5);
867 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75);
868 break;
869 case BBS_UNDERLINE:
870 nBorderStyle = PBS_UNDERLINED;
871 break;
872 default:
873 nBorderStyle = PBS_SOLID;
874 break;
875 }
876
877 CPDF_Rect rcWindow = GetRotatedRect();
878 CPDF_Rect rcClient = CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
879
880 CPDF_DefaultAppearance da = pControl->GetDefaultAppearance();
881 if (da.HasColor())
882 {
883 da.GetColor(iColorType, fc);
884 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
885 }
886
887 int32_t nStyle = 0;
888
889 CFX_WideString csWCaption = pControl->GetNormalCaption();
890 if (csWCaption.GetLength() > 0)
891 {
892 switch (csWCaption[0])
893 {
894 default: //L'l':
895 nStyle = PCS_CIRCLE;
896 break;
897 case L'8':
898 nStyle = PCS_CROSS;
899 break;
900 case L'u':
901 nStyle = PCS_DIAMOND;
902 break;
903 case L'n':
904 nStyle = PCS_SQUARE;
905 break;
906 case L'H':
907 nStyle = PCS_STAR;
908 break;
909 case L'4':
910 nStyle = PCS_CHECK;
911 break;
912 }
913 }
914 else
915 {
916 nStyle = PCS_CIRCLE;
917 }
918
919 CFX_ByteString csAP_N_ON;
920
921 CPDF_Rect rcCenter = CPWL_Utils::DeflateRect(CPWL_Utils::GetCenterSquare(rcW indow), 1.0f);
922
923 if (nStyle == PCS_CIRCLE)
924 {
925 if (nBorderStyle == PBS_BEVELED)
926 {
927 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
928 crRightBottom = CPWL_Utils::SubstractColor(crBackground,0.25f);
929 }
930 else if (nBorderStyle == PBS_INSET)
931 {
932 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0.5f);
933 crRightBottom = CPWL_Color(COLORTYPE_GRAY,0.75f);
934 }
935
936 csAP_N_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBackground) +
937 CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorder, crLeftTop,crRightBottom,nBorderStyle,dsBorder);
938 }
939 else
940 {
941 csAP_N_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,crBackground) +
942 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeft Top,crRightBottom,nBorderStyle,dsBorder);
943 }
944
945 CFX_ByteString csAP_N_OFF = csAP_N_ON;
946
947 switch (nBorderStyle)
948 {
949 case PBS_BEVELED:
950 {
951 CPWL_Color crTemp = crLeftTop;
952 crLeftTop = crRightBottom;
953 crRightBottom = crTemp;
954 }
955 break;
956 case PBS_INSET:
957 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
958 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
959 break;
960 }
961
962 CFX_ByteString csAP_D_ON;
963
964 if (nStyle == PCS_CIRCLE)
965 {
966 CPWL_Color crBK = CPWL_Utils::SubstractColor(crBackground,0.25f);
967 if (nBorderStyle == PBS_BEVELED)
968 {
969 crLeftTop = CPWL_Utils::SubstractColor(crBackground,0.25f);
970 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 1);
971 crBK = crBackground;
972 }
973 else if (nBorderStyle == PBS_INSET)
974 {
975 crLeftTop = CPWL_Color(COLORTYPE_GRAY,0);
976 crRightBottom = CPWL_Color(COLORTYPE_GRAY,1);
977 }
978
979 csAP_D_ON = CPWL_Utils::GetCircleFillAppStream(rcCenter,crBK)
980 + CPWL_Utils::GetCircleBorderAppStream(rcCenter,fBorderWidth,crBorde r,crLeftTop,crRightBottom,nBorderStyle,dsBorder);
981 }
982 else
983 {
984 csAP_D_ON = CPWL_Utils::GetRectFillAppStream(rcWindow,CPWL_Utils::Substr actColor(crBackground,0.25f)) +
985 CPWL_Utils::GetBorderAppStream(rcWindow,fBorderWidth,crBorder,crLeft Top,crRightBottom,nBorderStyle,dsBorder);
986 }
987
988 CFX_ByteString csAP_D_OFF = csAP_D_ON;
989
990 csAP_N_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
991 csAP_D_ON += CPWL_Utils::GetRadioButtonAppStream(rcClient,nStyle,crText);
992
993 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_ON, pControl->Get CheckedAPState());
994 WriteAppearance("N", GetRotatedRect(), GetMatrix(), csAP_N_OFF, "Off");
995
996 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_ON, pControl->Get CheckedAPState());
997 WriteAppearance("D", GetRotatedRect(), GetMatrix(), csAP_D_OFF, "Off");
998
999 CFX_ByteString csAS = GetAppState();
1000 if (csAS.IsEmpty())
1001 SetAppState("Off");
1002 }
1003
1004 void CPDFSDK_Widget::ResetAppearance_ComboBox(const FX_WCHAR* sValue)
1005 {
1006 CPDF_FormControl* pControl = GetFormControl();
1007 ASSERT(pControl != NULL);
1008 CPDF_FormField* pField = pControl->GetField();
1009 ASSERT(pField != NULL);
1010
1011 CFX_ByteTextBuf sBody, sLines;
1012
1013 CPDF_Rect rcClient = GetClientRect();
1014 CPDF_Rect rcButton = rcClient;
1015 rcButton.left = rcButton.right - 13;
1016 rcButton.Normalize();
1017
1018 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1019 {
1020 pEdit->EnableRefresh(FALSE);
1021
1022 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1023 ASSERT(pDoc != NULL);
1024 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1025 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1026 FontMap.Initial();
1027 pEdit->SetFontMap(&FontMap);
1028
1029 CPDF_Rect rcEdit = rcClient;
1030 rcEdit.right = rcButton.left;
1031 rcEdit.Normalize();
1032
1033 pEdit->SetPlateRect(rcEdit);
1034 pEdit->SetAlignmentV(1);
1035
1036 FX_FLOAT fFontSize = GetFontSize();
1037 if (IsFloatZero(fFontSize))
1038 pEdit->SetAutoFontSize(TRUE);
1039 else
1040 pEdit->SetFontSize(fFontSize);
1041
1042 pEdit->Initialize();
1043
1044 if (sValue)
1045 pEdit->SetText(sValue);
1046 else
1047 {
1048 int32_t nCurSel = pField->GetSelectedIndex(0);
1049
1050 if (nCurSel < 0)
1051 pEdit->SetText(pField->GetValue().c_str());
1052 else
1053 pEdit->SetText(pField->GetOptionLabel(nCurSel).c_str());
1054 }
1055
1056 CPDF_Rect rcContent = pEdit->GetContentRect();
1057
1058 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0 f,0.0f));
1059 if (sEdit.GetLength() > 0)
1060 {
1061 sBody << "/Tx BMC\n" << "q\n";
1062 if (rcContent.Width() > rcEdit.Width() ||
1063 rcContent.Height() > rcEdit.Height())
1064 {
1065 sBody << rcEdit.left << " " << rcEdit.bottom << " "
1066 << rcEdit.Width() << " " << rcEdit.Height() << " re\nW\nn\n" ;
1067 } 1256 }
1068 1257
1069 CPWL_Color crText = GetTextPWLColor(); 1258 sLines << "Q\n";
1070 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n"; 1259 }
1071 } 1260 } break;
1072 1261 }
1073 IFX_Edit::DelEdit(pEdit); 1262 }
1074 } 1263
1075 1264 IFX_Edit::DelEdit(pEdit);
1076 sBody << CPWL_Utils::GetDropButtonAppStream(rcButton); 1265 }
1077 1266
1078 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLine s.GetByteString() + sBody.GetByteString(); 1267 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() +
1079 1268 sLines.GetByteString() + sBody.GetByteString();
1080 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP); 1269 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1081 } 1270 }
1082 1271
1083 void CPDFSDK_Widget::ResetAppearance_ListBox() 1272 CPDF_Rect CPDFSDK_Widget::GetClientRect() const {
1084 { 1273 CPDF_Rect rcWindow = GetRotatedRect();
1085 CPDF_FormControl* pControl = GetFormControl(); 1274 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1086 ASSERT(pControl != NULL); 1275 switch (GetBorderStyle()) {
1087 CPDF_FormField* pField = pControl->GetField();
1088 ASSERT(pField != NULL);
1089
1090 CPDF_Rect rcClient = GetClientRect();
1091
1092 CFX_ByteTextBuf sBody, sLines;
1093
1094 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1095 {
1096 pEdit->EnableRefresh(FALSE);
1097
1098 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1099 ASSERT(pDoc != NULL);
1100 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1101
1102 CBA_FontMap FontMap(this,pEnv->GetSysHandler());
1103 FontMap.Initial();
1104 pEdit->SetFontMap(&FontMap);
1105
1106 pEdit->SetPlateRect(CPDF_Rect(rcClient.left,0.0f,rcClient.right,0.0f));
1107
1108 FX_FLOAT fFontSize = GetFontSize();
1109
1110 if (IsFloatZero(fFontSize))
1111 pEdit->SetFontSize(12.0f);
1112 else
1113 pEdit->SetFontSize(fFontSize);
1114
1115 pEdit->Initialize();
1116
1117 CFX_ByteTextBuf sList;
1118 FX_FLOAT fy = rcClient.top;
1119
1120 int32_t nTop = pField->GetTopVisibleIndex();
1121 int32_t nCount = pField->CountOptions();
1122 int32_t nSelCount = pField->CountSelectedItems();
1123
1124 for (int32_t i=nTop; i<nCount; i++)
1125 {
1126 FX_BOOL bSelected = FALSE;
1127 for (int32_t j=0; j<nSelCount; j++)
1128 {
1129 if (pField->GetSelectedIndex(j) == i)
1130 {
1131 bSelected = TRUE;
1132 break;
1133 }
1134 }
1135
1136 pEdit->SetText(pField->GetOptionLabel(i).c_str());
1137
1138 CPDF_Rect rcContent = pEdit->GetContentRect();
1139 FX_FLOAT fItemHeight = rcContent.Height();
1140
1141 if (bSelected)
1142 {
1143 CPDF_Rect rcItem = CPDF_Rect(rcClient.left,fy-fItemHeight,rcClie nt.right,fy);
1144 sList << "q\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLOR TYPE_RGB,0,51.0f/255.0f,113.0f/255.0f),TRUE)
1145 << rcItem.left << " " << rcItem.bottom << " " << rcItem.Widt h() << " " << rcItem.Height() << " re f\n" << "Q\n";
1146
1147 sList << "BT\n" << CPWL_Utils::GetColorAppStream(CPWL_Color(COLO RTYPE_GRAY,1),TRUE) <<
1148 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << " ET\n";
1149 }
1150 else
1151 {
1152 CPWL_Color crText = GetTextPWLColor();
1153 sList << "BT\n" << CPWL_Utils::GetColorAppStream(crText,TRUE) <<
1154 CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0f,fy)) << "ET\n ";
1155 }
1156
1157 fy -= fItemHeight;
1158 }
1159
1160 if (sList.GetSize() > 0)
1161 {
1162 sBody << "/Tx BMC\n" << "q\n" << rcClient.left << " " << rcClient.bo ttom << " "
1163 << rcClient.Width() << " " << rcClient.Height() << " re\nW\n n\n";
1164 sBody << sList << "Q\nEMC\n";
1165 }
1166
1167 IFX_Edit::DelEdit(pEdit);
1168 }
1169
1170 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLine s.GetByteString() + sBody.GetByteString();
1171
1172 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1173 }
1174
1175 void CPDFSDK_Widget::ResetAppearance_TextField(const FX_WCHAR* sValue)
1176 {
1177 CPDF_FormControl* pControl = GetFormControl();
1178 ASSERT(pControl != NULL);
1179 CPDF_FormField* pField = pControl->GetField();
1180 ASSERT(pField != NULL);
1181
1182 CFX_ByteTextBuf sBody, sLines;
1183
1184 if (IFX_Edit * pEdit = IFX_Edit::NewEdit())
1185 {
1186 pEdit->EnableRefresh(FALSE);
1187
1188 CPDFSDK_Document* pDoc = m_pInterForm->GetDocument();
1189 ASSERT(pDoc != NULL);
1190 CPDFDoc_Environment* pEnv = pDoc->GetEnv();
1191
1192 CBA_FontMap FontMap(this,pEnv->GetSysHandler());//, ISystemHandle::GetSy stemHandler(m_pBaseForm->GetEnv()));
1193 FontMap.Initial();
1194 pEdit->SetFontMap(&FontMap);
1195
1196 CPDF_Rect rcClient = GetClientRect();
1197 pEdit->SetPlateRect(rcClient);
1198 pEdit->SetAlignmentH(pControl->GetControlAlignment());
1199
1200 FX_DWORD dwFieldFlags = pField->GetFieldFlags();
1201 FX_BOOL bMultiLine = (dwFieldFlags >> 12) & 1;
1202
1203 if (bMultiLine)
1204 {
1205 pEdit->SetMultiLine(TRUE);
1206 pEdit->SetAutoReturn(TRUE);
1207 }
1208 else
1209 {
1210 pEdit->SetAlignmentV(1);
1211 }
1212
1213 FX_WORD subWord = 0;
1214 if ((dwFieldFlags >> 13) & 1)
1215 {
1216 subWord = '*';
1217 pEdit->SetPasswordChar(subWord);
1218 }
1219
1220 int nMaxLen = pField->GetMaxLen();
1221 FX_BOOL bCharArray = (dwFieldFlags >> 24) & 1;
1222 FX_FLOAT fFontSize = GetFontSize();
1223
1224 if (nMaxLen > 0)
1225 {
1226 if (bCharArray)
1227 {
1228 pEdit->SetCharArray(nMaxLen);
1229
1230 if (IsFloatZero(fFontSize))
1231 {
1232 fFontSize = CPWL_Edit::GetCharArrayAutoFontSize(FontMap.GetP DFFont(0),rcClient,nMaxLen);
1233 }
1234 }
1235 else
1236 {
1237 if (sValue)
1238 nMaxLen = wcslen((const wchar_t*)sValue);
1239 pEdit->SetLimitChar(nMaxLen);
1240 }
1241 }
1242
1243 if (IsFloatZero(fFontSize))
1244 pEdit->SetAutoFontSize(TRUE);
1245 else
1246 pEdit->SetFontSize(fFontSize);
1247
1248 pEdit->Initialize();
1249
1250 if (sValue)
1251 pEdit->SetText(sValue);
1252 else
1253 pEdit->SetText(pField->GetValue().c_str());
1254
1255 CPDF_Rect rcContent = pEdit->GetContentRect();
1256
1257 CFX_ByteString sEdit = CPWL_Utils::GetEditAppStream(pEdit,CPDF_Point(0.0 f,0.0f),
1258 NULL,!bCharA rray,subWord);
1259
1260 if (sEdit.GetLength() > 0)
1261 {
1262 sBody << "/Tx BMC\n" << "q\n";
1263 if (rcContent.Width() > rcClient.Width() ||
1264 rcContent.Height() > rcClient.Height())
1265 {
1266 sBody << rcClient.left << " " << rcClient.bottom << " "
1267 << rcClient.Width() << " " << rcClient.Height() << " re\nW\n n\n";
1268 }
1269 CPWL_Color crText = GetTextPWLColor();
1270 sBody << "BT\n" << CPWL_Utils::GetColorAppStream(crText) << sEdit << "ET\n" << "Q\nEMC\n";
1271 }
1272
1273 if (bCharArray)
1274 {
1275 switch (GetBorderStyle())
1276 {
1277 case BBS_SOLID:
1278 {
1279 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBor derPWLColor(),FALSE);
1280 if (sColor.GetLength() > 0)
1281 {
1282 sLines << "q\n" << GetBorderWidth() << " w\n"
1283 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor() ,FALSE) << " 2 J 0 j\n";
1284
1285 for (int32_t i=1;i<nMaxLen;i++)
1286 {
1287 sLines << rcClient.left + ((rcClient.right - rcClien t.left)/nMaxLen)*i << " "
1288 << rcClient.bottom << " m\n"
1289 << rcClient.left + ((rcClient.right - rcClient.l eft)/nMaxLen)*i << " "
1290 << rcClient.top << " l S\n";
1291 }
1292
1293 sLines << "Q\n";
1294 }
1295 }
1296 break;
1297 case BBS_DASH:
1298 {
1299 CFX_ByteString sColor = CPWL_Utils::GetColorAppStream(GetBor derPWLColor(),FALSE);
1300 if (sColor.GetLength() > 0)
1301 {
1302 CPWL_Dash dsBorder = CPWL_Dash(3, 3, 0);
1303
1304 sLines << "q\n" << GetBorderWidth() << " w\n"
1305 << CPWL_Utils::GetColorAppStream(GetBorderPWLColor() ,FALSE)
1306 << "[" << dsBorder.nDash << " "
1307 << dsBorder.nGap << "] "
1308 << dsBorder.nPhase << " d\n";
1309
1310 for (int32_t i=1;i<nMaxLen;i++)
1311 {
1312 sLines << rcClient.left + ((rcClient.right - rcClien t.left)/nMaxLen)*i << " "
1313 << rcClient.bottom << " m\n"
1314 << rcClient.left + ((rcClient.right - rcClient.l eft)/nMaxLen)*i << " "
1315 << rcClient.top << " l S\n";
1316 }
1317
1318 sLines << "Q\n";
1319 }
1320 }
1321 break;
1322 }
1323 }
1324
1325 IFX_Edit::DelEdit(pEdit);
1326 }
1327
1328 CFX_ByteString sAP = GetBackgroundAppStream() + GetBorderAppStream() + sLine s.GetByteString() + sBody.GetByteString();
1329 WriteAppearance("N", GetRotatedRect(), GetMatrix(), sAP);
1330 }
1331
1332 CPDF_Rect CPDFSDK_Widget::GetClientRect() const
1333 {
1334 CPDF_Rect rcWindow = GetRotatedRect();
1335 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1336 switch (GetBorderStyle())
1337 {
1338 case BBS_BEVELED: 1276 case BBS_BEVELED:
1339 case BBS_INSET: 1277 case BBS_INSET:
1340 fBorderWidth *= 2.0f; 1278 fBorderWidth *= 2.0f;
1341 break; 1279 break;
1342 } 1280 }
1343 1281
1344 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth); 1282 return CPWL_Utils::DeflateRect(rcWindow, fBorderWidth);
1345 } 1283 }
1346 1284
1347 CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const 1285 CPDF_Rect CPDFSDK_Widget::GetRotatedRect() const {
1348 { 1286 CPDF_Rect rectAnnot = GetRect();
1349 CPDF_Rect rectAnnot = GetRect(); 1287 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left;
1350 FX_FLOAT fWidth = rectAnnot.right - rectAnnot.left; 1288 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom;
1351 FX_FLOAT fHeight = rectAnnot.top - rectAnnot.bottom; 1289
1352 1290 CPDF_FormControl* pControl = GetFormControl();
1353 CPDF_FormControl* pControl = GetFormControl(); 1291 CPDF_Rect rcPDFWindow;
1354 CPDF_Rect rcPDFWindow; 1292 switch (abs(pControl->GetRotation() % 360)) {
1355 switch(abs(pControl->GetRotation() % 360)) 1293 case 0:
1356 { 1294 case 180:
1357 case 0: 1295 default:
1358 case 180: 1296 rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight);
1359 default: 1297 break;
1360 rcPDFWindow = CPDF_Rect(0, 0, fWidth, fHeight); 1298 case 90:
1361 break; 1299 case 270:
1362 case 90: 1300 rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth);
1363 case 270: 1301 break;
1364 rcPDFWindow = CPDF_Rect(0, 0, fHeight, fWidth); 1302 }
1365 break; 1303
1366 } 1304 return rcPDFWindow;
1367 1305 }
1368 return rcPDFWindow; 1306
1369 } 1307 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const {
1370 1308 CPWL_Color crBackground = GetFillPWLColor();
1371 CFX_ByteString CPDFSDK_Widget::GetBackgroundAppStream() const 1309 if (crBackground.nColorType != COLORTYPE_TRANSPARENT) {
1372 { 1310 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground);
1373 CPWL_Color crBackground = GetFillPWLColor(); 1311 }
1374 if (crBackground.nColorType != COLORTYPE_TRANSPARENT) { 1312 return "";
1375 return CPWL_Utils::GetRectFillAppStream(GetRotatedRect(), crBackground); 1313 }
1376 } 1314
1377 return ""; 1315 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const {
1378 } 1316 CPDF_Rect rcWindow = GetRotatedRect();
1379 1317 CPWL_Color crBorder = GetBorderPWLColor();
1380 CFX_ByteString CPDFSDK_Widget::GetBorderAppStream() const 1318 CPWL_Color crBackground = GetFillPWLColor();
1381 { 1319 CPWL_Color crLeftTop, crRightBottom;
1382 CPDF_Rect rcWindow = GetRotatedRect(); 1320
1383 CPWL_Color crBorder = GetBorderPWLColor(); 1321 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth();
1384 CPWL_Color crBackground = GetFillPWLColor(); 1322 int32_t nBorderStyle = 0;
1385 CPWL_Color crLeftTop, crRightBottom; 1323 CPWL_Dash dsBorder(3, 0, 0);
1386 1324
1387 FX_FLOAT fBorderWidth = (FX_FLOAT)GetBorderWidth(); 1325 switch (GetBorderStyle()) {
1388 int32_t nBorderStyle = 0;
1389 CPWL_Dash dsBorder(3,0,0);
1390
1391 switch (GetBorderStyle())
1392 {
1393 case BBS_DASH: 1326 case BBS_DASH:
1394 nBorderStyle = PBS_DASH; 1327 nBorderStyle = PBS_DASH;
1395 dsBorder = CPWL_Dash(3, 3, 0); 1328 dsBorder = CPWL_Dash(3, 3, 0);
1396 break; 1329 break;
1397 case BBS_BEVELED: 1330 case BBS_BEVELED:
1398 nBorderStyle = PBS_BEVELED; 1331 nBorderStyle = PBS_BEVELED;
1399 fBorderWidth *= 2; 1332 fBorderWidth *= 2;
1400 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1); 1333 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 1);
1401 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2); 1334 crRightBottom = CPWL_Utils::DevideColor(crBackground, 2);
1402 break; 1335 break;
1403 case BBS_INSET: 1336 case BBS_INSET:
1404 nBorderStyle = PBS_INSET; 1337 nBorderStyle = PBS_INSET;
1405 fBorderWidth *= 2; 1338 fBorderWidth *= 2;
1406 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5); 1339 crLeftTop = CPWL_Color(COLORTYPE_GRAY, 0.5);
1407 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75); 1340 crRightBottom = CPWL_Color(COLORTYPE_GRAY, 0.75);
1408 break; 1341 break;
1409 case BBS_UNDERLINE: 1342 case BBS_UNDERLINE:
1410 nBorderStyle = PBS_UNDERLINED; 1343 nBorderStyle = PBS_UNDERLINED;
1411 break; 1344 break;
1412 default: 1345 default:
1413 nBorderStyle = PBS_SOLID; 1346 nBorderStyle = PBS_SOLID;
1414 break; 1347 break;
1415 } 1348 }
1416 1349
1417 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder, crLe ftTop, 1350 return CPWL_Utils::GetBorderAppStream(rcWindow, fBorderWidth, crBorder,
1418 crRightBottom, nBorderStyle, dsBorder); 1351 crLeftTop, crRightBottom, nBorderStyle,
1419 } 1352 dsBorder);
1420 1353 }
1421 CPDF_Matrix CPDFSDK_Widget::GetMatrix() const 1354
1422 { 1355 CPDF_Matrix CPDFSDK_Widget::GetMatrix() const {
1423 CPDF_Matrix mt; 1356 CPDF_Matrix mt;
1424 CPDF_FormControl* pControl = GetFormControl(); 1357 CPDF_FormControl* pControl = GetFormControl();
1425 ASSERT(pControl != NULL); 1358 ASSERT(pControl != NULL);
1426 1359
1427 CPDF_Rect rcAnnot = GetRect(); 1360 CPDF_Rect rcAnnot = GetRect();
1428 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left; 1361 FX_FLOAT fWidth = rcAnnot.right - rcAnnot.left;
1429 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom; 1362 FX_FLOAT fHeight = rcAnnot.top - rcAnnot.bottom;
1430 1363
1431 1364 switch (abs(pControl->GetRotation() % 360)) {
1432 1365 case 0:
1433 switch (abs(pControl->GetRotation() % 360)) 1366 default:
1434 { 1367 mt = CPDF_Matrix(1, 0, 0, 1, 0, 0);
1435 case 0: 1368 break;
1436 default: 1369 case 90:
1437 mt = CPDF_Matrix(1, 0, 0, 1, 0, 0); 1370 mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0);
1438 break; 1371 break;
1439 case 90: 1372 case 180:
1440 mt = CPDF_Matrix(0, 1, -1, 0, fWidth, 0); 1373 mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight);
1441 break; 1374 break;
1442 case 180: 1375 case 270:
1443 mt = CPDF_Matrix(-1, 0, 0, -1, fWidth, fHeight); 1376 mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight);
1444 break; 1377 break;
1445 case 270: 1378 }
1446 mt = CPDF_Matrix(0, -1, 1, 0, 0, fHeight); 1379
1447 break; 1380 return mt;
1448 } 1381 }
1449 1382
1450 return mt; 1383 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const {
1451 } 1384 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0);
1452 1385
1453 CPWL_Color CPDFSDK_Widget::GetTextPWLColor() const 1386 CPDF_FormControl* pFormCtrl = GetFormControl();
1454 { 1387 ASSERT(pFormCtrl != NULL);
1455 CPWL_Color crText = CPWL_Color(COLORTYPE_GRAY, 0); 1388
1456 1389 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1457 CPDF_FormControl* pFormCtrl = GetFormControl(); 1390 if (da.HasColor()) {
1458 ASSERT(pFormCtrl != NULL);
1459
1460 CPDF_DefaultAppearance da = pFormCtrl->GetDefaultAppearance();
1461 if (da.HasColor())
1462 {
1463 int32_t iColorType;
1464 FX_FLOAT fc[4];
1465 da.GetColor(iColorType, fc);
1466 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1467 }
1468
1469 return crText;
1470 }
1471
1472 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const
1473 {
1474 CPWL_Color crBorder;
1475
1476 CPDF_FormControl* pFormCtrl = GetFormControl();
1477 ASSERT(pFormCtrl != NULL);
1478
1479 int32_t iColorType; 1391 int32_t iColorType;
1480 FX_FLOAT fc[4]; 1392 FX_FLOAT fc[4];
1481 pFormCtrl->GetOriginalBorderColor(iColorType, fc); 1393 da.GetColor(iColorType, fc);
1482 if (iColorType > 0) 1394 crText = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1483 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); 1395 }
1484 1396
1485 return crBorder; 1397 return crText;
1486 } 1398 }
1487 1399
1488 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const 1400 CPWL_Color CPDFSDK_Widget::GetBorderPWLColor() const {
1489 { 1401 CPWL_Color crBorder;
1490 CPWL_Color crFill; 1402
1491 1403 CPDF_FormControl* pFormCtrl = GetFormControl();
1492 CPDF_FormControl* pFormCtrl = GetFormControl(); 1404 ASSERT(pFormCtrl != NULL);
1493 ASSERT(pFormCtrl != NULL); 1405
1494 1406 int32_t iColorType;
1495 int32_t iColorType; 1407 FX_FLOAT fc[4];
1496 FX_FLOAT fc[4]; 1408 pFormCtrl->GetOriginalBorderColor(iColorType, fc);
1497 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc); 1409 if (iColorType > 0)
1498 if (iColorType > 0) 1410 crBorder = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1499 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]); 1411
1500 1412 return crBorder;
1501 return crFill; 1413 }
1502 } 1414
1503 1415 CPWL_Color CPDFSDK_Widget::GetFillPWLColor() const {
1504 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType, CPDF_St ream* pImage) 1416 CPWL_Color crFill;
1505 { 1417
1506 ASSERT(pImage != NULL); 1418 CPDF_FormControl* pFormCtrl = GetFormControl();
1507 1419 ASSERT(pFormCtrl != NULL);
1508 CPDF_Document* pDoc = m_pPageView->GetPDFDocument();//pDocument->GetDocument (); 1420
1509 ASSERT(pDoc != NULL); 1421 int32_t iColorType;
1510 1422 FX_FLOAT fc[4];
1511 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP"); 1423 pFormCtrl->GetOriginalBackgroundColor(iColorType, fc);
1512 ASSERT(pAPDict != NULL); 1424 if (iColorType > 0)
1513 1425 crFill = CPWL_Color(iColorType, fc[0], fc[1], fc[2], fc[3]);
1514 CPDF_Stream* pStream = pAPDict->GetStream(sAPType); 1426
1515 ASSERT(pStream != NULL); 1427 return crFill;
1516 1428 }
1517 CPDF_Dictionary* pStreamDict = pStream->GetDict(); 1429
1518 ASSERT(pStreamDict != NULL); 1430 void CPDFSDK_Widget::AddImageToAppearance(const CFX_ByteString& sAPType,
1519 1431 CPDF_Stream* pImage) {
1520 CFX_ByteString sImageAlias = "IMG"; 1432 ASSERT(pImage != NULL);
1521 1433
1522 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) 1434 CPDF_Document* pDoc =
1523 { 1435 m_pPageView->GetPDFDocument(); // pDocument->GetDocument();
1524 sImageAlias = pImageDict->GetString("Name"); 1436 ASSERT(pDoc != NULL);
1525 if (sImageAlias.IsEmpty()) 1437
1526 sImageAlias = "IMG"; 1438 CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP");
1527 } 1439 ASSERT(pAPDict != NULL);
1528 1440
1529 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources"); 1441 CPDF_Stream* pStream = pAPDict->GetStream(sAPType);
1530 if (!pStreamResList) 1442 ASSERT(pStream != NULL);
1531 { 1443
1532 pStreamResList = new CPDF_Dictionary(); 1444 CPDF_Dictionary* pStreamDict = pStream->GetDict();
1533 pStreamDict->SetAt("Resources", pStreamResList); 1445 ASSERT(pStreamDict != NULL);
1534 } 1446
1535 1447 CFX_ByteString sImageAlias = "IMG";
1536 if (pStreamResList) 1448
1537 { 1449 if (CPDF_Dictionary* pImageDict = pImage->GetDict()) {
1538 CPDF_Dictionary* pXObject = new CPDF_Dictionary; 1450 sImageAlias = pImageDict->GetString("Name");
1539 pXObject->SetAtReference(sImageAlias, pDoc, pImage); 1451 if (sImageAlias.IsEmpty())
1540 pStreamResList->SetAt("XObject", pXObject); 1452 sImageAlias = "IMG";
1541 } 1453 }
1542 } 1454
1543 1455 CPDF_Dictionary* pStreamResList = pStreamDict->GetDict("Resources");
1544 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) 1456 if (!pStreamResList) {
1545 { 1457 pStreamResList = new CPDF_Dictionary();
1546 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) 1458 pStreamDict->SetAt("Resources", pStreamResList);
1547 { 1459 }
1548 pAPDict->RemoveAt(sAPType); 1460
1549 } 1461 if (pStreamResList) {
1550 } 1462 CPDF_Dictionary* pXObject = new CPDF_Dictionary;
1551 1463 pXObject->SetAtReference(sImageAlias, pDoc, pImage);
1552 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type, PDFSDK_FieldAc tion& data, CPDFSDK_PageView* pPageView) 1464 pStreamResList->SetAt("XObject", pXObject);
1553 { 1465 }
1554 CPDF_Action action = GetAAction(type); 1466 }
1555 1467
1556 if (action && action.GetType() != CPDF_Action::Unknown) 1468 void CPDFSDK_Widget::RemoveAppearance(const CFX_ByteString& sAPType) {
1557 { 1469 if (CPDF_Dictionary* pAPDict = m_pAnnot->GetAnnotDict()->GetDict("AP")) {
1558 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument(); 1470 pAPDict->RemoveAt(sAPType);
1559 ASSERT(pDocument != NULL); 1471 }
1560 1472 }
1561 CPDFDoc_Environment* pEnv = pDocument->GetEnv(); 1473
1562 ASSERT(pEnv != NULL); 1474 FX_BOOL CPDFSDK_Widget::OnAAction(CPDF_AAction::AActionType type,
1563 1475 PDFSDK_FieldAction& data,
1564 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();/*(CPDFS DK_ActionHandler*)pApp->GetActionHandler();*/ 1476 CPDFSDK_PageView* pPageView) {
1565 ASSERT(pActionHandler != NULL); 1477 CPDF_Action action = GetAAction(type);
1566 1478
1567 return pActionHandler->DoAction_Field(action, type, pDocument, GetFormFi eld(), data); 1479 if (action && action.GetType() != CPDF_Action::Unknown) {
1568 } 1480 CPDFSDK_Document* pDocument = pPageView->GetSDKDocument();
1569 1481 ASSERT(pDocument != NULL);
1570 return FALSE; 1482
1571 } 1483 CPDFDoc_Environment* pEnv = pDocument->GetEnv();
1572 1484 ASSERT(pEnv != NULL);
1573 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) 1485
1574 { 1486 CPDFSDK_ActionHandler* pActionHandler =
1575 switch (eAAT) 1487 pEnv->GetActionHander(); /*(CPDFSDK_ActionHandler*)pApp->GetActionHandle r();*/
1576 { 1488 ASSERT(pActionHandler != NULL);
1489
1490 return pActionHandler->DoAction_Field(action, type, pDocument,
1491 GetFormField(), data);
1492 }
1493
1494 return FALSE;
1495 }
1496
1497 CPDF_Action CPDFSDK_Widget::GetAAction(CPDF_AAction::AActionType eAAT) {
1498 switch (eAAT) {
1577 case CPDF_AAction::CursorEnter: 1499 case CPDF_AAction::CursorEnter:
1578 case CPDF_AAction::CursorExit: 1500 case CPDF_AAction::CursorExit:
1579 case CPDF_AAction::ButtonDown: 1501 case CPDF_AAction::ButtonDown:
1580 case CPDF_AAction::ButtonUp: 1502 case CPDF_AAction::ButtonUp:
1581 case CPDF_AAction::GetFocus: 1503 case CPDF_AAction::GetFocus:
1582 case CPDF_AAction::LoseFocus: 1504 case CPDF_AAction::LoseFocus:
1583 case CPDF_AAction::PageOpen: 1505 case CPDF_AAction::PageOpen:
1584 case CPDF_AAction::PageClose: 1506 case CPDF_AAction::PageClose:
1585 case CPDF_AAction::PageVisible: 1507 case CPDF_AAction::PageVisible:
1586 case CPDF_AAction::PageInvisible: 1508 case CPDF_AAction::PageInvisible:
1587 return CPDFSDK_Annot::GetAAction(eAAT); 1509 return CPDFSDK_Annot::GetAAction(eAAT);
1588 1510
1589 case CPDF_AAction::KeyStroke: 1511 case CPDF_AAction::KeyStroke:
1590 case CPDF_AAction::Format: 1512 case CPDF_AAction::Format:
1591 case CPDF_AAction::Validate: 1513 case CPDF_AAction::Validate:
1592 case CPDF_AAction::Calculate: 1514 case CPDF_AAction::Calculate: {
1593 { 1515 CPDF_FormField* pField = GetFormField();
1594 CPDF_FormField* pField = GetFormField(); 1516 if (CPDF_AAction aa = pField->GetAdditionalAction())
1595 if (CPDF_AAction aa = pField->GetAdditionalAction()) 1517 return aa.GetAction(eAAT);
1596 return aa.GetAction(eAAT); 1518
1597 1519 return CPDFSDK_Annot::GetAAction(eAAT);
1598 return CPDFSDK_Annot::GetAAction(eAAT); 1520 }
1521 default:
1522 break;
1523 }
1524
1525 return CPDF_Action();
1526 }
1527
1528 CFX_WideString CPDFSDK_Widget::GetAlternateName() const {
1529 CPDF_FormField* pFormField = GetFormField();
1530 ASSERT(pFormField != NULL);
1531
1532 return pFormField->GetAlternateName();
1533 }
1534
1535 int32_t CPDFSDK_Widget::GetAppearanceAge() const {
1536 return m_nAppAge;
1537 }
1538
1539 int32_t CPDFSDK_Widget::GetValueAge() const {
1540 return m_nValueAge;
1541 }
1542
1543 FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY) {
1544 CPDF_Annot* pAnnot = GetPDFAnnot();
1545 CFX_FloatRect annotRect;
1546 pAnnot->GetRect(annotRect);
1547 if (annotRect.Contains(pageX, pageY)) {
1548 if (!IsVisible())
1549 return FALSE;
1550
1551 int nFieldFlags = GetFieldFlags();
1552 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
1553 return FALSE;
1554
1555 return TRUE;
1556 }
1557 return FALSE;
1558 }
1559
1560 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
1561 : m_pDocument(pDocument),
1562 m_pInterForm(NULL),
1563 m_bCalculate(TRUE),
1564 m_bBusy(FALSE) {
1565 ASSERT(m_pDocument != NULL);
1566 m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
1567 ASSERT(m_pInterForm != NULL);
1568 m_pInterForm->SetFormNotify(this);
1569
1570 for (int i = 0; i < 6; i++)
1571 m_bNeedHightlight[i] = FALSE;
1572 m_iHighlightAlpha = 0;
1573 }
1574
1575 CPDFSDK_InterForm::~CPDFSDK_InterForm() {
1576 delete m_pInterForm;
1577 m_pInterForm = nullptr;
1578 m_Map.clear();
1579 }
1580
1581 FX_BOOL CPDFSDK_InterForm::HighlightWidgets() {
1582 return FALSE;
1583 }
1584
1585 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget,
1586 FX_BOOL bNext) const {
1587 nonstd::unique_ptr<CBA_AnnotIterator> pIterator(
1588 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
1589
1590 if (bNext) {
1591 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
1592 }
1593 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
1594 }
1595
1596 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const {
1597 if (!pControl || !m_pInterForm)
1598 return nullptr;
1599
1600 CPDFSDK_Widget* pWidget = nullptr;
1601 const auto it = m_Map.find(pControl);
1602 if (it != m_Map.end())
1603 pWidget = it->second;
1604
1605 if (pWidget)
1606 return pWidget;
1607
1608 CPDF_Dictionary* pControlDict = pControl->GetWidget();
1609 CPDF_Document* pDocument = m_pDocument->GetDocument();
1610 CPDFSDK_PageView* pPage = nullptr;
1611
1612 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) {
1613 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
1614 if (nPageIndex >= 0) {
1615 pPage = m_pDocument->GetPageView(nPageIndex);
1616 }
1617 }
1618
1619 if (!pPage) {
1620 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
1621 if (nPageIndex >= 0) {
1622 pPage = m_pDocument->GetPageView(nPageIndex);
1623 }
1624 }
1625
1626 if (!pPage)
1627 return nullptr;
1628 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
1629 }
1630
1631 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName,
1632 CFX_PtrArray& widgets) {
1633 ASSERT(m_pInterForm != NULL);
1634
1635 for (int i = 0, sz = m_pInterForm->CountFields(sFieldName); i < sz; i++) {
1636 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
1637 ASSERT(pFormField != NULL);
1638
1639 GetWidgets(pFormField, widgets);
1640 }
1641 }
1642
1643 void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField,
1644 CFX_PtrArray& widgets) {
1645 ASSERT(pField != NULL);
1646
1647 for (int i = 0, isz = pField->CountControls(); i < isz; i++) {
1648 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
1649 ASSERT(pFormCtrl != NULL);
1650
1651 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
1652
1653 if (pWidget)
1654 widgets.Add(pWidget);
1655 }
1656 }
1657
1658 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(
1659 CPDF_Document* pDocument,
1660 CPDF_Dictionary* pAnnotDict) const {
1661 ASSERT(pDocument != NULL);
1662 ASSERT(pAnnotDict != NULL);
1663
1664 for (int i = 0, sz = pDocument->GetPageCount(); i < sz; i++) {
1665 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i)) {
1666 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots")) {
1667 for (int j = 0, jsz = pAnnots->GetCount(); j < jsz; j++) {
1668 CPDF_Object* pDict = pAnnots->GetElementValue(j);
1669 if (pAnnotDict == pDict) {
1670 return i;
1671 }
1599 } 1672 }
1600 default: 1673 }
1601 break; 1674 }
1602 } 1675 }
1603 1676
1604 return CPDF_Action(); 1677 return -1;
1605 } 1678 }
1606 1679
1607 1680 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl,
1608 CFX_WideString CPDFSDK_Widget::GetAlternateName() const 1681 CPDFSDK_Widget* pWidget) {
1609 { 1682 m_Map[pControl] = pWidget;
1610 CPDF_FormField* pFormField = GetFormField(); 1683 }
1611 ASSERT(pFormField != NULL); 1684
1612 1685 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl) {
1613 return pFormField->GetAlternateName(); 1686 m_Map.erase(pControl);
1614 } 1687 }
1615 1688
1616 int32_t CPDFSDK_Widget::GetAppearanceAge() const 1689 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled) {
1617 { 1690 m_bCalculate = bEnabled;
1618 return m_nAppAge; 1691 }
1619 } 1692
1620 1693 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const {
1621 int32_t CPDFSDK_Widget::GetValueAge() const 1694 return m_bCalculate;
1622 {
1623 return m_nValueAge;
1624 }
1625
1626
1627 FX_BOOL CPDFSDK_Widget::HitTest(FX_FLOAT pageX, FX_FLOAT pageY)
1628 {
1629 CPDF_Annot* pAnnot = GetPDFAnnot();
1630 CFX_FloatRect annotRect;
1631 pAnnot->GetRect(annotRect);
1632 if(annotRect.Contains(pageX, pageY))
1633 {
1634 if (!IsVisible()) return FALSE;
1635
1636 int nFieldFlags = GetFieldFlags();
1637 if ((nFieldFlags & FIELDFLAG_READONLY) == FIELDFLAG_READONLY)
1638 return FALSE;
1639
1640 return TRUE;
1641 }
1642 return FALSE;
1643 }
1644
1645 CPDFSDK_InterForm::CPDFSDK_InterForm(CPDFSDK_Document* pDocument)
1646 :m_pDocument(pDocument),
1647 m_pInterForm(NULL),
1648 m_bCalculate(TRUE),
1649 m_bBusy(FALSE)
1650 {
1651 ASSERT(m_pDocument != NULL);
1652 m_pInterForm = new CPDF_InterForm(m_pDocument->GetDocument(), FALSE);
1653 ASSERT(m_pInterForm != NULL);
1654 m_pInterForm->SetFormNotify(this);
1655
1656 for(int i=0; i<6; i++)
1657 m_bNeedHightlight[i] = FALSE;
1658 m_iHighlightAlpha = 0;
1659 }
1660
1661 CPDFSDK_InterForm::~CPDFSDK_InterForm()
1662 {
1663 delete m_pInterForm;
1664 m_pInterForm = nullptr;
1665 m_Map.clear();
1666 }
1667
1668 FX_BOOL CPDFSDK_InterForm::HighlightWidgets()
1669 {
1670 return FALSE;
1671 }
1672
1673 CPDFSDK_Widget* CPDFSDK_InterForm::GetSibling(CPDFSDK_Widget* pWidget, FX_BOOL b Next) const
1674 {
1675 nonstd::unique_ptr<CBA_AnnotIterator> pIterator(
1676 new CBA_AnnotIterator(pWidget->GetPageView(), "Widget", ""));
1677
1678 if (bNext) {
1679 return (CPDFSDK_Widget*)pIterator->GetNextAnnot(pWidget);
1680 }
1681 return (CPDFSDK_Widget*)pIterator->GetPrevAnnot(pWidget);
1682 }
1683
1684 CPDFSDK_Widget* CPDFSDK_InterForm::GetWidget(CPDF_FormControl* pControl) const
1685 {
1686 if (!pControl || !m_pInterForm)
1687 return nullptr;
1688
1689 CPDFSDK_Widget* pWidget = nullptr;
1690 const auto it = m_Map.find(pControl);
1691 if (it != m_Map.end())
1692 pWidget = it->second;
1693
1694 if (pWidget)
1695 return pWidget;
1696
1697 CPDF_Dictionary* pControlDict = pControl->GetWidget();
1698 CPDF_Document* pDocument = m_pDocument->GetDocument();
1699 CPDFSDK_PageView* pPage = nullptr;
1700
1701 if (CPDF_Dictionary* pPageDict = pControlDict->GetDict("P")) {
1702 int nPageIndex = pDocument->GetPageIndex(pPageDict->GetObjNum());
1703 if (nPageIndex >= 0) {
1704 pPage = m_pDocument->GetPageView(nPageIndex);
1705 }
1706 }
1707
1708 if (!pPage) {
1709 int nPageIndex = GetPageIndexByAnnotDict(pDocument, pControlDict);
1710 if (nPageIndex >= 0) {
1711 pPage = m_pDocument->GetPageView(nPageIndex);
1712 }
1713 }
1714
1715 if (!pPage)
1716 return nullptr;
1717 return (CPDFSDK_Widget*)pPage->GetAnnotByDict(pControlDict);
1718 }
1719
1720 void CPDFSDK_InterForm::GetWidgets(const CFX_WideString& sFieldName, CFX_PtrArra y& widgets)
1721 {
1722 ASSERT(m_pInterForm != NULL);
1723
1724 for (int i=0,sz=m_pInterForm->CountFields(sFieldName); i<sz; i++)
1725 {
1726 CPDF_FormField* pFormField = m_pInterForm->GetField(i, sFieldName);
1727 ASSERT(pFormField != NULL);
1728
1729 GetWidgets(pFormField, widgets);
1730 }
1731 }
1732
1733 void CPDFSDK_InterForm::GetWidgets(CPDF_FormField* pField, CFX_PtrArray& widgets )
1734 {
1735 ASSERT(pField != NULL);
1736
1737 for (int i=0,isz=pField->CountControls(); i<isz; i++)
1738 {
1739 CPDF_FormControl* pFormCtrl = pField->GetControl(i);
1740 ASSERT(pFormCtrl != NULL);
1741
1742 CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl);
1743
1744 if (pWidget)
1745 widgets.Add(pWidget);
1746 }
1747 }
1748
1749 int CPDFSDK_InterForm::GetPageIndexByAnnotDict(CPDF_Document* pDocument, CPDF_Di ctionary* pAnnotDict) const
1750 {
1751 ASSERT(pDocument != NULL);
1752 ASSERT(pAnnotDict != NULL);
1753
1754 for (int i=0,sz=pDocument->GetPageCount(); i<sz; i++)
1755 {
1756 if (CPDF_Dictionary* pPageDict = pDocument->GetPage(i))
1757 {
1758 if (CPDF_Array* pAnnots = pPageDict->GetArray("Annots"))
1759 {
1760 for (int j=0,jsz=pAnnots->GetCount(); j<jsz; j++)
1761 {
1762 CPDF_Object* pDict = pAnnots->GetElementValue(j);
1763 if (pAnnotDict == pDict)
1764 {
1765 return i;
1766 }
1767 }
1768 }
1769 }
1770 }
1771
1772 return -1;
1773 }
1774
1775 void CPDFSDK_InterForm::AddMap(CPDF_FormControl* pControl, CPDFSDK_Widget* pWidg et)
1776 {
1777 m_Map[pControl] = pWidget;
1778 }
1779
1780 void CPDFSDK_InterForm::RemoveMap(CPDF_FormControl* pControl)
1781 {
1782 m_Map.erase(pControl);
1783 }
1784
1785 void CPDFSDK_InterForm::EnableCalculate(FX_BOOL bEnabled)
1786 {
1787 m_bCalculate = bEnabled;
1788 }
1789
1790 FX_BOOL CPDFSDK_InterForm::IsCalculateEnabled() const
1791 {
1792 return m_bCalculate;
1793 } 1695 }
1794 1696
1795 #ifdef _WIN32 1697 #ifdef _WIN32
1796 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) 1698 CPDF_Stream* CPDFSDK_InterForm::LoadImageFromFile(const CFX_WideString& sFile) {
1797 { 1699 ASSERT(m_pDocument != NULL);
1798 ASSERT(m_pDocument != NULL); 1700 CPDF_Document* pDocument = m_pDocument->GetDocument();
1799 CPDF_Document* pDocument = m_pDocument->GetDocument(); 1701 ASSERT(pDocument != NULL);
1800 ASSERT(pDocument != NULL); 1702
1801 1703 CPDF_Stream* pRetStream = NULL;
1802 CPDF_Stream* pRetStream = NULL; 1704
1803 1705 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile.c_str())) {
1804 if (CFX_DIBitmap* pBmp = CFX_WindowsDIB::LoadFromFile(sFile.c_str())) 1706 int nWidth = pBmp->GetWidth();
1805 { 1707 int nHeight = pBmp->GetHeight();
1806 int nWidth = pBmp->GetWidth(); 1708
1807 int nHeight = pBmp->GetHeight(); 1709 CPDF_Image Image(pDocument);
1808 1710 Image.SetImage(pBmp, FALSE);
1809 CPDF_Image Image(pDocument); 1711 CPDF_Stream* pImageStream = Image.GetStream();
1810 Image.SetImage(pBmp, FALSE); 1712 if (pImageStream) {
1811 CPDF_Stream* pImageStream = Image.GetStream(); 1713 if (pImageStream->GetObjNum() == 0)
1812 if (pImageStream) 1714 pDocument->AddIndirectObject(pImageStream);
1813 { 1715
1814 if (pImageStream->GetObjNum() == 0) 1716 CPDF_Dictionary* pStreamDict = new CPDF_Dictionary();
1815 pDocument->AddIndirectObject(pImageStream); 1717 pStreamDict->SetAtName("Subtype", "Form");
1816 1718 pStreamDict->SetAtName("Name", "IMG");
1817 CPDF_Dictionary* pStreamDict = new CPDF_Dictionary(); 1719 CPDF_Array* pMatrix = new CPDF_Array();
1818 pStreamDict->SetAtName("Subtype", "Form"); 1720 pStreamDict->SetAt("Matrix", pMatrix);
1819 pStreamDict->SetAtName("Name", "IMG"); 1721 pMatrix->AddInteger(1);
1820 CPDF_Array* pMatrix = new CPDF_Array(); 1722 pMatrix->AddInteger(0);
1821 pStreamDict->SetAt("Matrix", pMatrix); 1723 pMatrix->AddInteger(0);
1822 pMatrix->AddInteger(1); 1724 pMatrix->AddInteger(1);
1823 pMatrix->AddInteger(0); 1725 pMatrix->AddInteger(-nWidth / 2);
1824 pMatrix->AddInteger(0); 1726 pMatrix->AddInteger(-nHeight / 2);
1825 pMatrix->AddInteger(1); 1727 CPDF_Dictionary* pResource = new CPDF_Dictionary();
1826 pMatrix->AddInteger(-nWidth / 2); 1728 pStreamDict->SetAt("Resources", pResource);
1827 pMatrix->AddInteger(-nHeight / 2); 1729 CPDF_Dictionary* pXObject = new CPDF_Dictionary();
1828 CPDF_Dictionary* pResource = new CPDF_Dictionary(); 1730 pResource->SetAt("XObject", pXObject);
1829 pStreamDict->SetAt("Resources", pResource); 1731 pXObject->SetAtReference("Img", pDocument, pImageStream);
1830 CPDF_Dictionary* pXObject = new CPDF_Dictionary(); 1732 CPDF_Array* pProcSet = new CPDF_Array();
1831 pResource->SetAt("XObject", pXObject); 1733 pResource->SetAt("ProcSet", pProcSet);
1832 pXObject->SetAtReference("Img", pDocument, pImageStream); 1734 pProcSet->AddName("PDF");
1833 CPDF_Array* pProcSet = new CPDF_Array(); 1735 pProcSet->AddName("ImageC");
1834 pResource->SetAt("ProcSet", pProcSet); 1736 pStreamDict->SetAtName("Type", "XObject");
1835 pProcSet->AddName("PDF"); 1737 CPDF_Array* pBBox = new CPDF_Array();
1836 pProcSet->AddName("ImageC"); 1738 pStreamDict->SetAt("BBox", pBBox);
1837 pStreamDict->SetAtName("Type", "XObject"); 1739 pBBox->AddInteger(0);
1838 CPDF_Array* pBBox = new CPDF_Array(); 1740 pBBox->AddInteger(0);
1839 pStreamDict->SetAt("BBox", pBBox); 1741 pBBox->AddInteger(nWidth);
1840 pBBox->AddInteger(0); 1742 pBBox->AddInteger(nHeight);
1841 pBBox->AddInteger(0); 1743 pStreamDict->SetAtInteger("FormType", 1);
1842 pBBox->AddInteger(nWidth); 1744
1843 pBBox->AddInteger(nHeight); 1745 pRetStream = new CPDF_Stream(NULL, 0, NULL);
1844 pStreamDict->SetAtInteger("FormType", 1); 1746 CFX_ByteString csStream;
1845 1747 csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight);
1846 pRetStream = new CPDF_Stream(NULL, 0, NULL); 1748 pRetStream->InitStream((uint8_t*)csStream.c_str(), csStream.GetLength(),
1847 CFX_ByteString csStream; 1749 pStreamDict);
1848 csStream.Format("q\n%d 0 0 %d 0 0 cm\n/Img Do\nQ", nWidth, nHeight); 1750 pDocument->AddIndirectObject(pRetStream);
1849 pRetStream->InitStream((uint8_t*)csStream.c_str(), csStream.GetLengt h(), pStreamDict); 1751 }
1850 pDocument->AddIndirectObject(pRetStream); 1752
1851 } 1753 delete pBmp;
1852 1754 }
1853 delete pBmp; 1755
1854 } 1756 return pRetStream;
1855
1856 return pRetStream;
1857 } 1757 }
1858 #endif 1758 #endif
1859 1759
1860 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) 1760 void CPDFSDK_InterForm::OnCalculate(CPDF_FormField* pFormField) {
1861 { 1761 ASSERT(m_pDocument != NULL);
1862 ASSERT(m_pDocument != NULL); 1762 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1863 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 1763 ASSERT(pEnv);
1864 ASSERT(pEnv); 1764 if (!pEnv->IsJSInitiated())
1865 if(!pEnv->IsJSInitiated()) 1765 return;
1866 return; 1766
1867 1767 if (m_bBusy)
1868 if (m_bBusy) return; 1768 return;
1869 1769
1870 m_bBusy = TRUE; 1770 m_bBusy = TRUE;
1871 1771
1872 if (IsCalculateEnabled()) 1772 if (IsCalculateEnabled()) {
1873 {
1874 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
1875 ASSERT(pRuntime != NULL);
1876
1877 pRuntime->SetReaderDocument(m_pDocument);
1878
1879 int nSize = m_pInterForm->CountFieldsInCalculationOrder();
1880 for (int i=0; i<nSize; i++)
1881 {
1882 if(CPDF_FormField* pField = m_pInterForm->GetFieldInCalculationOrder (i))
1883 {
1884 // ASSERT(pField != NULL);
1885 int nType = pField->GetFieldType();
1886 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD)
1887 {
1888 CPDF_AAction aAction = pField->GetAdditionalAction();
1889 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate))
1890 {
1891 CPDF_Action action = aAction.GetAction(CPDF_AAction::Cal culate);
1892 if (action)
1893 {
1894 CFX_WideString csJS = action.GetJavaScript();
1895 if (!csJS.IsEmpty())
1896 {
1897 IFXJS_Context* pContext = pRuntime->NewContext() ;
1898 ASSERT(pContext != NULL);
1899
1900 CFX_WideString sOldValue = pField->GetValue();
1901 CFX_WideString sValue = sOldValue;
1902 FX_BOOL bRC = TRUE;
1903 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
1904
1905 CFX_WideString sInfo;
1906 FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
1907 pRuntime->ReleaseContext(pContext);
1908
1909 if (bRet)
1910 {
1911 if (bRC)
1912 {
1913 if (sValue.Compare(sOldValue) != 0)
1914 pField->SetValue(sValue, TRUE);
1915 }
1916 }
1917 }
1918 }
1919 }
1920 }
1921 }
1922 }
1923
1924
1925 }
1926
1927 m_bBusy = FALSE;
1928 }
1929
1930 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField, FX_BOOL& bFormated)
1931 {
1932 ASSERT(m_pDocument != NULL);
1933 ASSERT(pFormField != NULL);
1934
1935 CFX_WideString sValue = pFormField->GetValue();
1936 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1937 ASSERT(pEnv);
1938 if(!pEnv->IsJSInitiated())
1939 {
1940 bFormated = FALSE;
1941 return sValue;
1942 }
1943
1944 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime(); 1773 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
1945 ASSERT(pRuntime != NULL); 1774 ASSERT(pRuntime != NULL);
1946 1775
1947 pRuntime->SetReaderDocument(m_pDocument); 1776 pRuntime->SetReaderDocument(m_pDocument);
1948 1777
1949 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) 1778 int nSize = m_pInterForm->CountFieldsInCalculationOrder();
1950 { 1779 for (int i = 0; i < nSize; i++) {
1951 if (pFormField->CountSelectedItems() > 0) 1780 if (CPDF_FormField* pField =
1952 { 1781 m_pInterForm->GetFieldInCalculationOrder(i)) {
1953 int index = pFormField->GetSelectedIndex(0); 1782 // ASSERT(pField != NULL);
1954 if (index >= 0) 1783 int nType = pField->GetFieldType();
1955 sValue = pFormField->GetOptionLabel(index); 1784 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
1956 } 1785 CPDF_AAction aAction = pField->GetAdditionalAction();
1957 } 1786 if (aAction && aAction.ActionExist(CPDF_AAction::Calculate)) {
1958 1787 CPDF_Action action = aAction.GetAction(CPDF_AAction::Calculate);
1959 bFormated = FALSE; 1788 if (action) {
1960 1789 CFX_WideString csJS = action.GetJavaScript();
1961 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 1790 if (!csJS.IsEmpty()) {
1962 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format))
1963 {
1964 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
1965 if (action)
1966 {
1967 CFX_WideString script = action.GetJavaScript();
1968 if (!script.IsEmpty())
1969 {
1970 CFX_WideString Value = sValue;
1971
1972 IFXJS_Context* pContext = pRuntime->NewContext(); 1791 IFXJS_Context* pContext = pRuntime->NewContext();
1973 ASSERT(pContext != NULL); 1792 ASSERT(pContext != NULL);
1974 1793
1975 pContext->OnField_Format(pFormField, Value, TRUE); 1794 CFX_WideString sOldValue = pField->GetValue();
1795 CFX_WideString sValue = sOldValue;
1796 FX_BOOL bRC = TRUE;
1797 pContext->OnField_Calculate(pFormField, pField, sValue, bRC);
1976 1798
1977 CFX_WideString sInfo; 1799 CFX_WideString sInfo;
1978 FX_BOOL bRet = pContext->RunScript(script, sInfo); 1800 FX_BOOL bRet = pContext->RunScript(csJS, sInfo);
1979 pRuntime->ReleaseContext(pContext); 1801 pRuntime->ReleaseContext(pContext);
1980 1802
1981 if (bRet) 1803 if (bRet) {
1982 { 1804 if (bRC) {
1983 sValue = Value; 1805 if (sValue.Compare(sOldValue) != 0)
1984 bFormated = TRUE; 1806 pField->SetValue(sValue, TRUE);
1807 }
1985 } 1808 }
1809 }
1986 } 1810 }
1811 }
1987 } 1812 }
1988 } 1813 }
1989 1814 }
1815 }
1816
1817 m_bBusy = FALSE;
1818 }
1819
1820 CFX_WideString CPDFSDK_InterForm::OnFormat(CPDF_FormField* pFormField,
1821 FX_BOOL& bFormated) {
1822 ASSERT(m_pDocument != NULL);
1823 ASSERT(pFormField != NULL);
1824
1825 CFX_WideString sValue = pFormField->GetValue();
1826 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1827 ASSERT(pEnv);
1828 if (!pEnv->IsJSInitiated()) {
1829 bFormated = FALSE;
1990 return sValue; 1830 return sValue;
1991 } 1831 }
1992 1832
1993 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField, const F X_WCHAR* sValue, FX_BOOL bValueChanged) 1833 IFXJS_Runtime* pRuntime = m_pDocument->GetJsRuntime();
1994 { 1834 ASSERT(pRuntime != NULL);
1995 ASSERT(pFormField != NULL); 1835
1996 1836 pRuntime->SetReaderDocument(m_pDocument);
1997 for (int i=0,sz=pFormField->CountControls(); i<sz; i++) 1837
1998 { 1838 if (pFormField->GetFieldType() == FIELDTYPE_COMBOBOX) {
1999 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 1839 if (pFormField->CountSelectedItems() > 0) {
2000 ASSERT(pFormCtrl != NULL); 1840 int index = pFormField->GetSelectedIndex(0);
2001 1841 if (index >= 0)
2002 ASSERT(m_pInterForm != NULL); 1842 sValue = pFormField->GetOptionLabel(index);
2003 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) 1843 }
2004 pWidget->ResetAppearance(sValue, bValueChanged); 1844 }
2005 } 1845
2006 } 1846 bFormated = FALSE;
2007 1847
2008 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) 1848 CPDF_AAction aAction = pFormField->GetAdditionalAction();
2009 { 1849 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Format)) {
2010 ASSERT(pFormField != NULL); 1850 CPDF_Action action = aAction.GetAction(CPDF_AAction::Format);
2011 1851 if (action) {
2012 for (int i=0,sz=pFormField->CountControls(); i<sz; i++) 1852 CFX_WideString script = action.GetJavaScript();
2013 { 1853 if (!script.IsEmpty()) {
2014 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i); 1854 CFX_WideString Value = sValue;
2015 ASSERT(pFormCtrl != NULL); 1855
2016 1856 IFXJS_Context* pContext = pRuntime->NewContext();
2017 if(CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) 1857 ASSERT(pContext != NULL);
2018 { 1858
2019 CPDFDoc_Environment * pEnv = m_pDocument->GetEnv(); 1859 pContext->OnField_Format(pFormField, Value, TRUE);
2020 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller(); 1860
2021 1861 CFX_WideString sInfo;
2022 CPDF_Page * pPage = pWidget->GetPDFPage(); 1862 FX_BOOL bRet = pContext->RunScript(script, sInfo);
2023 CPDFSDK_PageView * pPageView = m_pDocument->GetPageView(pPage,FALSE) ; 1863 pRuntime->ReleaseContext(pContext);
2024 1864
2025 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget); 1865 if (bRet) {
2026 1866 sValue = Value;
2027 pEnv->FFI_Invalidate(pPage,rcBBox.left, rcBBox.top, rcBBox.right, rc BBox.bottom); 1867 bFormated = TRUE;
2028 } 1868 }
2029 } 1869 }
2030 } 1870 }
2031 1871 }
2032 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField, CFX_WideSt ring& csValue, FX_BOOL& bRC) 1872
2033 { 1873 return sValue;
2034 ASSERT(pFormField != NULL); 1874 }
2035 1875
2036 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 1876 void CPDFSDK_InterForm::ResetFieldAppearance(CPDF_FormField* pFormField,
2037 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) 1877 const FX_WCHAR* sValue,
2038 { 1878 FX_BOOL bValueChanged) {
2039 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke); 1879 ASSERT(pFormField != NULL);
2040 if (action) 1880
2041 { 1881 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2042 ASSERT(m_pDocument != NULL); 1882 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2043 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 1883 ASSERT(pFormCtrl != NULL);
2044 ASSERT(pEnv != NULL); 1884
2045 1885 ASSERT(m_pInterForm != NULL);
2046 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 1886 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl))
2047 ASSERT(pActionHandler != NULL); 1887 pWidget->ResetAppearance(sValue, bValueChanged);
2048 1888 }
2049 PDFSDK_FieldAction fa; 1889 }
2050 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); 1890
2051 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); 1891 void CPDFSDK_InterForm::UpdateField(CPDF_FormField* pFormField) {
2052 fa.sValue = csValue; 1892 ASSERT(pFormField != NULL);
2053 1893
2054 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeySt roke, 1894 for (int i = 0, sz = pFormField->CountControls(); i < sz; i++) {
2055 m_pDocument, pFormField, fa); 1895 CPDF_FormControl* pFormCtrl = pFormField->GetControl(i);
2056 bRC = fa.bRC; 1896 ASSERT(pFormCtrl != NULL);
1897
1898 if (CPDFSDK_Widget* pWidget = GetWidget(pFormCtrl)) {
1899 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1900 CFFL_IFormFiller* pIFormFiller = pEnv->GetIFormFiller();
1901
1902 CPDF_Page* pPage = pWidget->GetPDFPage();
1903 CPDFSDK_PageView* pPageView = m_pDocument->GetPageView(pPage, FALSE);
1904
1905 FX_RECT rcBBox = pIFormFiller->GetViewBBox(pPageView, pWidget);
1906
1907 pEnv->FFI_Invalidate(pPage, rcBBox.left, rcBBox.top, rcBBox.right,
1908 rcBBox.bottom);
1909 }
1910 }
1911 }
1912
1913 void CPDFSDK_InterForm::OnKeyStrokeCommit(CPDF_FormField* pFormField,
1914 CFX_WideString& csValue,
1915 FX_BOOL& bRC) {
1916 ASSERT(pFormField != NULL);
1917
1918 CPDF_AAction aAction = pFormField->GetAdditionalAction();
1919 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::KeyStroke)) {
1920 CPDF_Action action = aAction.GetAction(CPDF_AAction::KeyStroke);
1921 if (action) {
1922 ASSERT(m_pDocument != NULL);
1923 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1924 ASSERT(pEnv != NULL);
1925
1926 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1927 ASSERT(pActionHandler != NULL);
1928
1929 PDFSDK_FieldAction fa;
1930 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
1931 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
1932 fa.sValue = csValue;
1933
1934 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::KeyStroke,
1935 m_pDocument, pFormField, fa);
1936 bRC = fa.bRC;
1937 }
1938 }
1939 }
1940
1941 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField,
1942 CFX_WideString& csValue,
1943 FX_BOOL& bRC) {
1944 ASSERT(pFormField != NULL);
1945
1946 CPDF_AAction aAction = pFormField->GetAdditionalAction();
1947 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) {
1948 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate);
1949 if (action) {
1950 ASSERT(m_pDocument != NULL);
1951 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
1952 ASSERT(pEnv != NULL);
1953
1954 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander();
1955 ASSERT(pActionHandler != NULL);
1956
1957 PDFSDK_FieldAction fa;
1958 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0);
1959 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0);
1960 fa.sValue = csValue;
1961
1962 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Validate,
1963 m_pDocument, pFormField, fa);
1964 bRC = fa.bRC;
1965 }
1966 }
1967 }
1968
1969 /* ----------------------------- action ----------------------------- */
1970
1971 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action) {
1972 ASSERT(action);
1973
1974 CPDF_ActionFields af = action.GetWidgets();
1975 CFX_PtrArray fieldObjects;
1976 af.GetAllFields(fieldObjects);
1977 CFX_PtrArray widgetArray;
1978 CFX_PtrArray fields;
1979 GetFieldFromObjects(fieldObjects, fields);
1980
1981 FX_BOOL bHide = action.GetHideStatus();
1982
1983 FX_BOOL bChanged = FALSE;
1984
1985 for (int i = 0, sz = fields.GetSize(); i < sz; i++) {
1986 CPDF_FormField* pField = (CPDF_FormField*)fields[i];
1987 ASSERT(pField != NULL);
1988
1989 for (int j = 0, jsz = pField->CountControls(); j < jsz; j++) {
1990 CPDF_FormControl* pControl = pField->GetControl(j);
1991 ASSERT(pControl != NULL);
1992
1993 if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) {
1994 int nFlags = pWidget->GetFlags();
1995 if (bHide) {
1996 nFlags &= (~ANNOTFLAG_INVISIBLE);
1997 nFlags &= (~ANNOTFLAG_NOVIEW);
1998 nFlags |= (ANNOTFLAG_HIDDEN);
1999 } else {
2000 nFlags &= (~ANNOTFLAG_INVISIBLE);
2001 nFlags &= (~ANNOTFLAG_HIDDEN);
2002 nFlags &= (~ANNOTFLAG_NOVIEW);
2057 } 2003 }
2058 } 2004 pWidget->SetFlags(nFlags);
2059 } 2005
2060 2006 CPDFSDK_PageView* pPageView = pWidget->GetPageView();
2061 void CPDFSDK_InterForm::OnValidate(CPDF_FormField* pFormField, CFX_WideString& c sValue, FX_BOOL& bRC) 2007 ASSERT(pPageView != NULL);
2062 { 2008
2063 ASSERT(pFormField != NULL); 2009 pPageView->UpdateView(pWidget);
2064 2010
2065 CPDF_AAction aAction = pFormField->GetAdditionalAction(); 2011 bChanged = TRUE;
2066 if (aAction != NULL && aAction.ActionExist(CPDF_AAction::Validate)) 2012 }
2067 { 2013 }
2068 CPDF_Action action = aAction.GetAction(CPDF_AAction::Validate); 2014 }
2069 if (action) 2015
2070 { 2016 return bChanged;
2071 ASSERT(m_pDocument != NULL); 2017 }
2072 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 2018
2073 ASSERT(pEnv != NULL); 2019 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) {
2074 2020 ASSERT(m_pInterForm != NULL);
2075 CPDFSDK_ActionHandler* pActionHandler = pEnv->GetActionHander(); 2021 CFX_WideString sDestination = action.GetFilePath();
2076 ASSERT(pActionHandler != NULL); 2022 if (sDestination.IsEmpty())
2077 2023 return FALSE;
2078 PDFSDK_FieldAction fa; 2024
2079 fa.bModifier = pEnv->FFI_IsCTRLKeyDown(0); 2025 CPDF_Dictionary* pActionDict = action.GetDict();
2080 fa.bShift = pEnv->FFI_IsSHIFTKeyDown(0); 2026 if (pActionDict->KeyExist("Fields")) {
2081 fa.sValue = csValue;
2082
2083 pActionHandler->DoAction_FieldJavaScript(action, CPDF_AAction::Valid ate, m_pDocument, pFormField, fa);
2084 bRC = fa.bRC;
2085
2086 }
2087 }
2088 }
2089
2090 /* ----------------------------- action ----------------------------- */
2091
2092 FX_BOOL CPDFSDK_InterForm::DoAction_Hide(const CPDF_Action& action)
2093 {
2094 ASSERT(action);
2095
2096 CPDF_ActionFields af = action.GetWidgets(); 2027 CPDF_ActionFields af = action.GetWidgets();
2028 FX_DWORD dwFlags = action.GetFlags();
2097 CFX_PtrArray fieldObjects; 2029 CFX_PtrArray fieldObjects;
2098 af.GetAllFields(fieldObjects); 2030 af.GetAllFields(fieldObjects);
2099 CFX_PtrArray widgetArray; 2031
2100 CFX_PtrArray fields; 2032 CFX_PtrArray fields;
2101 GetFieldFromObjects(fieldObjects, fields); 2033 GetFieldFromObjects(fieldObjects, fields);
2102 2034 if (fields.GetSize() != 0) {
2103 FX_BOOL bHide = action.GetHideStatus(); 2035 FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01);
2104 2036 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude))
2105 FX_BOOL bChanged = FALSE; 2037 return FALSE;
2106 2038
2107 for (int i=0, sz=fields.GetSize(); i<sz; i++) 2039 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE);
2108 { 2040 }
2109 CPDF_FormField* pField = (CPDF_FormField*)fields[i]; 2041 }
2110 ASSERT(pField != NULL); 2042 if (m_pInterForm->CheckRequiredFields())
2111 2043 return FALSE;
2112 2044
2113 for (int j=0,jsz=pField->CountControls(); j<jsz; j++) 2045 return SubmitForm(sDestination, FALSE);
2114 { 2046 }
2115 CPDF_FormControl* pControl = pField->GetControl(j); 2047
2116 ASSERT(pControl != NULL); 2048 FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination,
2117 2049 const CFX_PtrArray& fields,
2118 if (CPDFSDK_Widget* pWidget = GetWidget(pControl)) 2050 FX_BOOL bIncludeOrExclude,
2119 { 2051 FX_BOOL bUrlEncoded) {
2120 int nFlags = pWidget->GetFlags(); 2052 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2121 if (bHide) 2053 ASSERT(pEnv != NULL);
2122 { 2054
2123 nFlags &= (~ANNOTFLAG_INVISIBLE); 2055 CFX_ByteTextBuf textBuf;
2124 nFlags &= (~ANNOTFLAG_NOVIEW); 2056 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf);
2125 nFlags |= (ANNOTFLAG_HIDDEN); 2057
2126 } 2058 uint8_t* pBuffer = textBuf.GetBuffer();
2127 else 2059 FX_STRSIZE nBufSize = textBuf.GetLength();
2128 { 2060
2129 nFlags &= (~ANNOTFLAG_INVISIBLE); 2061 if (bUrlEncoded) {
2130 nFlags &= (~ANNOTFLAG_HIDDEN); 2062 if (!FDFToURLEncodedData(pBuffer, nBufSize))
2131 nFlags &= (~ANNOTFLAG_NOVIEW); 2063 return FALSE;
2132 } 2064 }
2133 pWidget->SetFlags(nFlags); 2065
2134 2066 pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str());
2135 CPDFSDK_PageView* pPageView = pWidget->GetPageView(); 2067
2136 ASSERT(pPageView != NULL); 2068 return TRUE;
2137 2069 }
2138 pPageView->UpdateView(pWidget); 2070
2139 2071 void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer) {
2140 bChanged = TRUE; 2072 ASSERT(m_pDocument != NULL);
2141 } 2073
2074 if (CFDF_Document* pFDFDocument = CFDF_Document::ParseMemory(
2075 (const unsigned char*)sBuffer.GetBuffer(sBuffer.GetLength()),
2076 sBuffer.GetLength())) {
2077 CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
2078 if (pRootDic) {
2079 CPDF_Dictionary* pFDFDict = pRootDic->GetDict("FDF");
2080 if (pFDFDict) {
2081 CPDF_Dictionary* pJSDict = pFDFDict->GetDict("JavaScript");
2082 if (pJSDict) {
2083 CFX_WideString csJS;
2084
2085 CPDF_Object* pJS = pJSDict->GetElementValue("Before");
2086 if (pJS != NULL) {
2087 int iType = pJS->GetType();
2088 if (iType == PDFOBJ_STRING)
2089 csJS = pJSDict->GetUnicodeText("Before");
2090 else if (iType == PDFOBJ_STREAM)
2091 csJS = pJS->GetUnicodeText();
2092 }
2142 } 2093 }
2143 } 2094 }
2144 2095 }
2145 return bChanged; 2096 delete pFDFDocument;
2146 } 2097 }
2147 2098
2148 FX_BOOL CPDFSDK_InterForm::DoAction_SubmitForm(const CPDF_Action& action) 2099 sBuffer.ReleaseBuffer();
2149 { 2100 }
2150 ASSERT(m_pInterForm != NULL); 2101
2151 CFX_WideString sDestination = action.GetFilePath(); 2102 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile,
2152 if (sDestination.IsEmpty()) 2103 CFX_WideString csTxtFile) {
2153 return FALSE; 2104 return TRUE;
2154 2105 }
2155 CPDF_Dictionary* pActionDict = action.GetDict(); 2106
2156 if (pActionDict->KeyExist("Fields")) 2107 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf,
2157 { 2108 FX_STRSIZE& nBufSize) {
2158 CPDF_ActionFields af = action.GetWidgets(); 2109 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2159 FX_DWORD dwFlags = action.GetFlags(); 2110 if (pFDF) {
2160 CFX_PtrArray fieldObjects; 2111 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
2161 af.GetAllFields(fieldObjects); 2112 if (pMainDict == NULL)
2162 2113 return FALSE;
2163 CFX_PtrArray fields; 2114
2164 GetFieldFromObjects(fieldObjects, fields); 2115 // Get fields
2165 if (fields.GetSize() != 0) 2116 CPDF_Array* pFields = pMainDict->GetArray("Fields");
2166 { 2117 if (pFields == NULL)
2167 FX_BOOL bIncludeOrExclude = !(dwFlags & 0x01); 2118 return FALSE;
2168 if (m_pInterForm->CheckRequiredFields(&fields, bIncludeOrExclude)) 2119
2169 return FALSE; 2120 CFX_ByteTextBuf fdfEncodedData;
2170 2121
2171 return SubmitFields(sDestination, fields, bIncludeOrExclude, FALSE); 2122 for (FX_DWORD i = 0; i < pFields->GetCount(); i++) {
2172 } 2123 CPDF_Dictionary* pField = pFields->GetDict(i);
2173 } 2124 if (pField == NULL)
2174 if (m_pInterForm->CheckRequiredFields()) 2125 continue;
2175 return FALSE; 2126 CFX_WideString name;
2176 2127 name = pField->GetUnicodeText("T");
2177 return SubmitForm(sDestination, FALSE); 2128 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2178 } 2129 CFX_ByteString csBValue = pField->GetString("V");
2179 2130 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2180 FX_BOOL CPDFSDK_InterForm::SubmitFields(const CFX_WideString& csDestination, con st CFX_PtrArray& fields, 2131 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2181 FX_BOOL bIncludeOrExclude, FX_BOOL bUrlEncod ed) 2132
2182 { 2133 fdfEncodedData = fdfEncodedData << name_b.GetBuffer(name_b.GetLength());
2183 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv(); 2134 name_b.ReleaseBuffer();
2184 ASSERT(pEnv != NULL); 2135 fdfEncodedData = fdfEncodedData << "=";
2185 2136 fdfEncodedData = fdfEncodedData
2186 CFX_ByteTextBuf textBuf; 2137 << csValue_b.GetBuffer(csValue_b.GetLength());
2187 ExportFieldsToFDFTextBuf(fields, bIncludeOrExclude, textBuf); 2138 csValue_b.ReleaseBuffer();
2188 2139 if (i != pFields->GetCount() - 1)
2189 uint8_t* pBuffer = textBuf.GetBuffer(); 2140 fdfEncodedData = fdfEncodedData << "&";
2190 FX_STRSIZE nBufSize = textBuf.GetLength(); 2141 }
2191 2142
2192 if (bUrlEncoded) 2143 nBufSize = fdfEncodedData.GetLength();
2193 { 2144 pBuf = FX_Alloc(uint8_t, nBufSize);
2194 if(!FDFToURLEncodedData(pBuffer, nBufSize)) 2145 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
2195 return FALSE; 2146 }
2196 } 2147 return TRUE;
2197 2148 }
2198 pEnv->JS_docSubmitForm(pBuffer, nBufSize, csDestination.c_str()); 2149
2199 2150 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,
2200 return TRUE; 2151 FX_BOOL bIncludeOrExclude,
2201 } 2152 CFX_ByteTextBuf& textBuf) {
2202 2153 ASSERT(m_pDocument != NULL);
2203 void CPDFSDK_InterForm::DoFDFBuffer(CFX_ByteString sBuffer) 2154 ASSERT(m_pInterForm != NULL);
2204 { 2155
2205 ASSERT(m_pDocument != NULL); 2156 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(
2206 2157 m_pDocument->GetPath(), (CFX_PtrArray&)fields, bIncludeOrExclude);
2207 if (CFDF_Document *pFDFDocument = CFDF_Document::ParseMemory((const unsigned char *)sBuffer.GetBuffer(sBuffer.GetLength()), sBuffer.GetLength())) 2158 if (!pFDF)
2208 {
2209 CPDF_Dictionary* pRootDic = pFDFDocument->GetRoot();
2210 if(pRootDic)
2211 {
2212 CPDF_Dictionary * pFDFDict=pRootDic->GetDict("FDF");
2213 if(pFDFDict)
2214 {
2215 CPDF_Dictionary * pJSDict = pFDFDict->GetDict("JavaScript");
2216 if(pJSDict)
2217 {
2218 CFX_WideString csJS;
2219
2220 CPDF_Object* pJS = pJSDict->GetElementValue("Before");
2221 if (pJS != NULL)
2222 {
2223 int iType = pJS->GetType();
2224 if (iType == PDFOBJ_STRING)
2225 csJS = pJSDict->GetUnicodeText("Before");
2226 else if (iType == PDFOBJ_STREAM)
2227 csJS = pJS->GetUnicodeText();
2228 }
2229
2230 }
2231 }
2232 }
2233 delete pFDFDocument;
2234 }
2235
2236 sBuffer.ReleaseBuffer();
2237 }
2238
2239 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(CFX_WideString csFDFFile, CFX_Wid eString csTxtFile)
2240 {
2241 return TRUE;
2242 }
2243
2244 FX_BOOL CPDFSDK_InterForm::FDFToURLEncodedData(uint8_t*& pBuf, FX_STRSIZE& nBufS ize)
2245 {
2246 CFDF_Document* pFDF = CFDF_Document::ParseMemory(pBuf, nBufSize);
2247 if (pFDF)
2248 {
2249 CPDF_Dictionary* pMainDict = pFDF->GetRoot()->GetDict("FDF");
2250 if (pMainDict == NULL) return FALSE;
2251
2252 // Get fields
2253 CPDF_Array* pFields = pMainDict->GetArray("Fields");
2254 if (pFields == NULL) return FALSE;
2255
2256 CFX_ByteTextBuf fdfEncodedData;
2257
2258 for (FX_DWORD i = 0; i < pFields->GetCount(); i ++)
2259 {
2260 CPDF_Dictionary* pField = pFields->GetDict(i);
2261 if (pField == NULL) continue;
2262 CFX_WideString name;
2263 name = pField->GetUnicodeText("T");
2264 CFX_ByteString name_b = CFX_ByteString::FromUnicode(name);
2265 CFX_ByteString csBValue = pField->GetString("V");
2266 CFX_WideString csWValue = PDF_DecodeText(csBValue);
2267 CFX_ByteString csValue_b = CFX_ByteString::FromUnicode(csWValue);
2268
2269 fdfEncodedData = fdfEncodedData<<name_b.GetBuffer(name_b.GetLength() );
2270 name_b.ReleaseBuffer();
2271 fdfEncodedData = fdfEncodedData<<"=";
2272 fdfEncodedData = fdfEncodedData<<csValue_b.GetBuffer(csValue_b.GetLe ngth());
2273 csValue_b.ReleaseBuffer();
2274 if(i != pFields->GetCount()-1)
2275 fdfEncodedData = fdfEncodedData<<"&";
2276 }
2277
2278 nBufSize = fdfEncodedData.GetLength();
2279 pBuf = FX_Alloc(uint8_t, nBufSize);
2280 FXSYS_memcpy(pBuf, fdfEncodedData.GetBuffer(), nBufSize);
2281 }
2282 return TRUE;
2283 }
2284
2285 FX_BOOL CPDFSDK_InterForm::ExportFieldsToFDFTextBuf(const CFX_PtrArray& fields,F X_BOOL bIncludeOrExclude, CFX_ByteTextBuf& textBuf)
2286 {
2287 ASSERT(m_pDocument != NULL);
2288 ASSERT(m_pInterForm != NULL);
2289
2290 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath(),(CFX_ PtrArray&)fields, bIncludeOrExclude);
2291 if (!pFDF) return FALSE;
2292 FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
2293 delete pFDF;
2294
2295 return bRet;
2296 }
2297
2298 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(const CFX_WideString& sFi leExt)
2299 {
2300 CFX_WideString sFileName;
2301 return L"";
2302 }
2303
2304 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination, FX_BOO L bUrlEncoded)
2305 {
2306 if (sDestination.IsEmpty()) return FALSE;
2307
2308 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2309 ASSERT(pEnv != NULL);
2310
2311 if(NULL == m_pDocument) return FALSE;
2312 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2313
2314 if(NULL == m_pInterForm) return FALSE;
2315 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2316 if (NULL == pFDFDoc) return FALSE;
2317
2318 CFX_ByteTextBuf FdfBuffer;
2319 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2320 delete pFDFDoc;
2321 if (!bRet) return FALSE;
2322
2323 uint8_t* pBuffer = FdfBuffer.GetBuffer();
2324 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
2325
2326 if (bUrlEncoded)
2327 {
2328 if(!FDFToURLEncodedData(pBuffer, nBufSize))
2329 return FALSE;
2330 }
2331
2332 pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
2333
2334 if (bUrlEncoded && pBuffer)
2335 {
2336 FX_Free(pBuffer);
2337 pBuffer = NULL;
2338 }
2339
2340 return TRUE;
2341 }
2342
2343 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf)
2344 {
2345
2346 ASSERT(m_pInterForm != NULL);
2347 ASSERT(m_pDocument != NULL);
2348
2349 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2350 if (!pFDF) return FALSE;
2351
2352 FX_BOOL bRet = pFDF->WriteBuf(textBuf);
2353 delete pFDF;
2354
2355 return bRet;
2356 }
2357
2358
2359 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action)
2360 {
2361 ASSERT(action);
2362
2363 CPDF_Dictionary* pActionDict = action.GetDict();
2364 if (pActionDict->KeyExist("Fields"))
2365 {
2366 CPDF_ActionFields af = action.GetWidgets();
2367 FX_DWORD dwFlags = action.GetFlags();
2368
2369 CFX_PtrArray fieldObjects;
2370 af.GetAllFields(fieldObjects);
2371 CFX_PtrArray fields;
2372 GetFieldFromObjects(fieldObjects, fields);
2373 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
2374 }
2375
2376 return m_pInterForm->ResetForm(TRUE);
2377 }
2378
2379 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action)
2380 {
2381 return FALSE; 2159 return FALSE;
2382 } 2160 FX_BOOL bRet = pFDF->WriteBuf(textBuf); // = FALSE;//
2383 2161 delete pFDF;
2384 void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects, CFX_Ptr Array& fields) 2162
2385 { 2163 return bRet;
2386 ASSERT(m_pInterForm != NULL); 2164 }
2387 2165
2388 int iCount = objects.GetSize(); 2166 CFX_WideString CPDFSDK_InterForm::GetTemporaryFileName(
2389 for (int i = 0; i < iCount; i ++) 2167 const CFX_WideString& sFileExt) {
2390 { 2168 CFX_WideString sFileName;
2391 CPDF_Object* pObject = (CPDF_Object*)objects[i]; 2169 return L"";
2392 if (pObject == NULL) continue; 2170 }
2393 2171
2394 int iType = pObject->GetType(); 2172 FX_BOOL CPDFSDK_InterForm::SubmitForm(const CFX_WideString& sDestination,
2395 if (iType == PDFOBJ_STRING) 2173 FX_BOOL bUrlEncoded) {
2396 { 2174 if (sDestination.IsEmpty())
2397 CFX_WideString csName = pObject->GetUnicodeText(); 2175 return FALSE;
2398 CPDF_FormField* pField = m_pInterForm->GetField(0, csName); 2176
2399 if (pField != NULL) 2177 CPDFDoc_Environment* pEnv = m_pDocument->GetEnv();
2400 fields.Add(pField); 2178 ASSERT(pEnv != NULL);
2401 } 2179
2402 else if (iType == PDFOBJ_DICTIONARY) 2180 if (NULL == m_pDocument)
2403 { 2181 return FALSE;
2404 if (m_pInterForm->IsValidFormField(pObject)) 2182 CFX_WideString wsPDFFilePath = m_pDocument->GetPath();
2405 fields.Add(pObject); 2183
2406 } 2184 if (NULL == m_pInterForm)
2407 } 2185 return FALSE;
2408 } 2186 CFDF_Document* pFDFDoc = m_pInterForm->ExportToFDF(wsPDFFilePath);
2409 2187 if (NULL == pFDFDoc)
2410 /* ----------------------------- CPDF_FormNotify ----------------------------- * / 2188 return FALSE;
2411 2189
2412 int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField, CFX_WideS tring& csValue) 2190 CFX_ByteTextBuf FdfBuffer;
2413 { 2191 FX_BOOL bRet = pFDFDoc->WriteBuf(FdfBuffer);
2414 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2192 delete pFDFDoc;
2415 int nType = pFormField->GetFieldType(); 2193 if (!bRet)
2416 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) 2194 return FALSE;
2417 { 2195
2418 FX_BOOL bRC = TRUE; 2196 uint8_t* pBuffer = FdfBuffer.GetBuffer();
2419 OnKeyStrokeCommit(pFormField, csValue, bRC); 2197 FX_STRSIZE nBufSize = FdfBuffer.GetLength();
2420 if (bRC) 2198
2421 { 2199 if (bUrlEncoded) {
2422 OnValidate(pFormField, csValue, bRC); 2200 if (!FDFToURLEncodedData(pBuffer, nBufSize))
2423 return bRC ? 1 : -1; 2201 return FALSE;
2424 } 2202 }
2425 return -1; 2203
2426 } 2204 pEnv->JS_docSubmitForm(pBuffer, nBufSize, sDestination.c_str());
2427 return 0; 2205
2428 } 2206 if (bUrlEncoded && pBuffer) {
2429 2207 FX_Free(pBuffer);
2430 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) 2208 pBuffer = NULL;
2431 { 2209 }
2432 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2210
2433 int nType = pFormField->GetFieldType(); 2211 return TRUE;
2434 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) 2212 }
2435 { 2213
2436 OnCalculate(pFormField); 2214 FX_BOOL CPDFSDK_InterForm::ExportFormToFDFTextBuf(CFX_ByteTextBuf& textBuf) {
2437 FX_BOOL bFormated = FALSE; 2215 ASSERT(m_pInterForm != NULL);
2438 CFX_WideString sValue = OnFormat(pFormField, bFormated); 2216 ASSERT(m_pDocument != NULL);
2439 if (bFormated) 2217
2440 ResetFieldAppearance(pFormField, sValue.c_str(), TRUE); 2218 CFDF_Document* pFDF = m_pInterForm->ExportToFDF(m_pDocument->GetPath());
2441 else 2219 if (!pFDF)
2442 ResetFieldAppearance(pFormField, NULL, TRUE); 2220 return FALSE;
2443 UpdateField(pFormField); 2221
2444 } 2222 FX_BOOL bRet = pFDF->WriteBuf(textBuf);
2445 return 0; 2223 delete pFDF;
2446 } 2224
2447 2225 return bRet;
2448 int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField, CFX_W ideString& csValue) 2226 }
2449 { 2227
2450 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2228 FX_BOOL CPDFSDK_InterForm::DoAction_ResetForm(const CPDF_Action& action) {
2451 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX) 2229 ASSERT(action);
2452 return 0; 2230
2453 2231 CPDF_Dictionary* pActionDict = action.GetDict();
2232 if (pActionDict->KeyExist("Fields")) {
2233 CPDF_ActionFields af = action.GetWidgets();
2234 FX_DWORD dwFlags = action.GetFlags();
2235
2236 CFX_PtrArray fieldObjects;
2237 af.GetAllFields(fieldObjects);
2238 CFX_PtrArray fields;
2239 GetFieldFromObjects(fieldObjects, fields);
2240 return m_pInterForm->ResetForm(fields, !(dwFlags & 0x01), TRUE);
2241 }
2242
2243 return m_pInterForm->ResetForm(TRUE);
2244 }
2245
2246 FX_BOOL CPDFSDK_InterForm::DoAction_ImportData(const CPDF_Action& action) {
2247 return FALSE;
2248 }
2249
2250 void CPDFSDK_InterForm::GetFieldFromObjects(const CFX_PtrArray& objects,
2251 CFX_PtrArray& fields) {
2252 ASSERT(m_pInterForm != NULL);
2253
2254 int iCount = objects.GetSize();
2255 for (int i = 0; i < iCount; i++) {
2256 CPDF_Object* pObject = (CPDF_Object*)objects[i];
2257 if (pObject == NULL)
2258 continue;
2259
2260 int iType = pObject->GetType();
2261 if (iType == PDFOBJ_STRING) {
2262 CFX_WideString csName = pObject->GetUnicodeText();
2263 CPDF_FormField* pField = m_pInterForm->GetField(0, csName);
2264 if (pField != NULL)
2265 fields.Add(pField);
2266 } else if (iType == PDFOBJ_DICTIONARY) {
2267 if (m_pInterForm->IsValidFormField(pObject))
2268 fields.Add(pObject);
2269 }
2270 }
2271 }
2272
2273 /* ----------------------------- CPDF_FormNotify -----------------------------
2274 */
2275
2276 int CPDFSDK_InterForm::BeforeValueChange(const CPDF_FormField* pField,
2277 CFX_WideString& csValue) {
2278 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2279 int nType = pFormField->GetFieldType();
2280 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
2454 FX_BOOL bRC = TRUE; 2281 FX_BOOL bRC = TRUE;
2455 OnKeyStrokeCommit(pFormField, csValue, bRC); 2282 OnKeyStrokeCommit(pFormField, csValue, bRC);
2456 if (!bRC) 2283 if (bRC) {
2457 return -1; 2284 OnValidate(pFormField, csValue, bRC);
2458 2285 return bRC ? 1 : -1;
2459 OnValidate(pFormField, csValue, bRC); 2286 }
2460 if (!bRC) 2287 return -1;
2461 return -1; 2288 }
2462 2289 return 0;
2290 }
2291
2292 int CPDFSDK_InterForm::AfterValueChange(const CPDF_FormField* pField) {
2293 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2294 int nType = pFormField->GetFieldType();
2295 if (nType == FIELDTYPE_COMBOBOX || nType == FIELDTYPE_TEXTFIELD) {
2296 OnCalculate(pFormField);
2297 FX_BOOL bFormated = FALSE;
2298 CFX_WideString sValue = OnFormat(pFormField, bFormated);
2299 if (bFormated)
2300 ResetFieldAppearance(pFormField, sValue.c_str(), TRUE);
2301 else
2302 ResetFieldAppearance(pFormField, NULL, TRUE);
2303 UpdateField(pFormField);
2304 }
2305 return 0;
2306 }
2307
2308 int CPDFSDK_InterForm::BeforeSelectionChange(const CPDF_FormField* pField,
2309 CFX_WideString& csValue) {
2310 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2311 if (pFormField->GetFieldType() != FIELDTYPE_LISTBOX)
2312 return 0;
2313
2314 FX_BOOL bRC = TRUE;
2315 OnKeyStrokeCommit(pFormField, csValue, bRC);
2316 if (!bRC)
2317 return -1;
2318
2319 OnValidate(pFormField, csValue, bRC);
2320 if (!bRC)
2321 return -1;
2322
2323 return 1;
2324 }
2325
2326 int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField) {
2327 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2328 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX) {
2329 OnCalculate(pFormField);
2330 ResetFieldAppearance(pFormField, NULL, TRUE);
2331 UpdateField(pFormField);
2332 }
2333 return 0;
2334 }
2335
2336 int CPDFSDK_InterForm::AfterCheckedStatusChange(
2337 const CPDF_FormField* pField,
2338 const CFX_ByteArray& statusArray) {
2339 CPDF_FormField* pFormField = (CPDF_FormField*)pField;
2340 int nType = pFormField->GetFieldType();
2341 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) {
2342 OnCalculate(pFormField);
2343 UpdateField(pFormField);
2344 }
2345 return 0;
2346 }
2347
2348 int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm) {
2349 return 0;
2350 }
2351
2352 int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm) {
2353 OnCalculate(nullptr);
2354 return 0;
2355 }
2356
2357 int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm) {
2358 return 0;
2359 }
2360
2361 int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm) {
2362 OnCalculate(nullptr);
2363 return 0;
2364 }
2365
2366 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) {
2367 if (nFieldType < 1 || nFieldType > 6)
2368 return FALSE;
2369 return m_bNeedHightlight[nFieldType - 1];
2370 }
2371
2372 void CPDFSDK_InterForm::RemoveAllHighLight() {
2373 memset((void*)m_bNeedHightlight, 0, 6 * sizeof(FX_BOOL));
2374 }
2375 void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType) {
2376 if (nFieldType < 0 || nFieldType > 6)
2377 return;
2378 switch (nFieldType) {
2379 case 0: {
2380 for (int i = 0; i < 6; i++) {
2381 m_aHighlightColor[i] = clr;
2382 m_bNeedHightlight[i] = TRUE;
2383 }
2384 break;
2385 }
2386 default: {
2387 m_aHighlightColor[nFieldType - 1] = clr;
2388 m_bNeedHightlight[nFieldType - 1] = TRUE;
2389 break;
2390 }
2391 }
2392 }
2393
2394 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) {
2395 if (nFieldType < 0 || nFieldType > 6)
2396 return FXSYS_RGB(255, 255, 255);
2397 if (nFieldType == 0)
2398 return m_aHighlightColor[0];
2399 return m_aHighlightColor[nFieldType - 1];
2400 }
2401
2402 /* ------------------------- CBA_AnnotIterator ------------------------- */
2403
2404 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView,
2405 const CFX_ByteString& sType,
2406 const CFX_ByteString& sSubType)
2407 : m_pPageView(pPageView),
2408 m_sType(sType),
2409 m_sSubType(sSubType),
2410 m_nTabs(BAI_STRUCTURE) {
2411 ASSERT(m_pPageView != NULL);
2412
2413 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
2414 ASSERT(pPDFPage != NULL);
2415 ASSERT(pPDFPage->m_pFormDict != NULL);
2416
2417 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
2418
2419 if (sTabs == "R") {
2420 m_nTabs = BAI_ROW;
2421 } else if (sTabs == "C") {
2422 m_nTabs = BAI_COLUMN;
2423 } else {
2424 m_nTabs = BAI_STRUCTURE;
2425 }
2426
2427 GenerateResults();
2428 }
2429
2430 CBA_AnnotIterator::~CBA_AnnotIterator() {
2431 m_Annots.RemoveAll();
2432 }
2433
2434 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot() {
2435 if (m_Annots.GetSize() > 0)
2436 return m_Annots[0];
2437
2438 return NULL;
2439 }
2440
2441 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot() {
2442 if (m_Annots.GetSize() > 0)
2443 return m_Annots[m_Annots.GetSize() - 1];
2444
2445 return NULL;
2446 }
2447
2448 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot) {
2449 for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
2450 if (m_Annots[i] == pAnnot)
2451 return (i + 1 < sz) ? m_Annots[i + 1] : m_Annots[0];
2452 }
2453 return NULL;
2454 }
2455
2456 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot) {
2457 for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
2458 if (m_Annots[i] == pAnnot)
2459 return (i - 1 >= 0) ? m_Annots[i - 1] : m_Annots[sz - 1];
2460 }
2461 return NULL;
2462 }
2463
2464 int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
2465 ASSERT(p1);
2466 ASSERT(p2);
2467
2468 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2469 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2470
2471 if (rcAnnot1.left < rcAnnot2.left)
2472 return -1;
2473 if (rcAnnot1.left > rcAnnot2.left)
2463 return 1; 2474 return 1;
2464 } 2475 return 0;
2465 2476 }
2466 int CPDFSDK_InterForm::AfterSelectionChange(const CPDF_FormField* pField) 2477
2467 { 2478 int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2) {
2468 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2479 ASSERT(p1 != NULL);
2469 if (pFormField->GetFieldType() == FIELDTYPE_LISTBOX) 2480 ASSERT(p2 != NULL);
2470 { 2481
2471 OnCalculate(pFormField); 2482 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2472 ResetFieldAppearance(pFormField, NULL, TRUE); 2483 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2473 UpdateField(pFormField); 2484
2474 } 2485 if (rcAnnot1.top < rcAnnot2.top)
2475 return 0; 2486 return -1;
2476 } 2487 if (rcAnnot1.top > rcAnnot2.top)
2477 2488 return 1;
2478 int CPDFSDK_InterForm::AfterCheckedStatusChange(const CPDF_FormField* pField, co nst CFX_ByteArray& statusArray) 2489 return 0;
2479 { 2490 }
2480 CPDF_FormField* pFormField = (CPDF_FormField*)pField; 2491
2481 int nType = pFormField->GetFieldType(); 2492 void CBA_AnnotIterator::GenerateResults() {
2482 if (nType == FIELDTYPE_CHECKBOX || nType == FIELDTYPE_RADIOBUTTON) 2493 ASSERT(m_pPageView != NULL);
2483 { 2494
2484 OnCalculate(pFormField); 2495 switch (m_nTabs) {
2485 UpdateField(pFormField); 2496 case BAI_STRUCTURE: {
2486 } 2497 for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
2487 return 0; 2498 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2488 } 2499 ASSERT(pAnnot != NULL);
2489 2500
2490 int CPDFSDK_InterForm::BeforeFormReset(const CPDF_InterForm* pForm) 2501 if (pAnnot->GetType() == m_sType && pAnnot->GetSubType() == m_sSubType)
2491 { 2502 m_Annots.Add(pAnnot);
2492 return 0; 2503 }
2493 } 2504 } break;
2494 2505 case BAI_ROW: {
2495 int CPDFSDK_InterForm::AfterFormReset(const CPDF_InterForm* pForm) 2506 CPDFSDK_SortAnnots sa;
2496 { 2507
2497 OnCalculate(nullptr); 2508 {
2498 return 0; 2509 for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
2499 } 2510 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2500 2511 ASSERT(pAnnot != NULL);
2501 int CPDFSDK_InterForm::BeforeFormImportData(const CPDF_InterForm* pForm) 2512
2502 { 2513 if (pAnnot->GetType() == m_sType &&
2503 return 0; 2514 pAnnot->GetSubType() == m_sSubType)
2504 } 2515 sa.Add(pAnnot);
2505 2516 }
2506 int CPDFSDK_InterForm::AfterFormImportData(const CPDF_InterForm* pForm) 2517 }
2507 { 2518
2508 OnCalculate(nullptr); 2519 if (sa.GetSize() > 0) {
2509 return 0; 2520 sa.Sort(CBA_AnnotIterator::CompareByLeft);
2510 } 2521 }
2511 2522
2512 FX_BOOL CPDFSDK_InterForm::IsNeedHighLight(int nFieldType) 2523 while (sa.GetSize() > 0) {
2513 { 2524 int nLeftTopIndex = -1;
2514 if(nFieldType <1 || nFieldType > 6) 2525
2515 return FALSE;
2516 return m_bNeedHightlight[nFieldType-1];
2517 }
2518
2519 void CPDFSDK_InterForm::RemoveAllHighLight()
2520 {
2521 memset((void*)m_bNeedHightlight, 0, 6*sizeof(FX_BOOL));
2522 }
2523 void CPDFSDK_InterForm::SetHighlightColor(FX_COLORREF clr, int nFieldType)
2524 {
2525 if(nFieldType <0 || nFieldType > 6) return;
2526 switch(nFieldType)
2527 {
2528 case 0:
2529 { 2526 {
2530 for(int i=0; i<6; i++) 2527 FX_FLOAT fTop = 0.0f;
2531 { 2528
2532 m_aHighlightColor[i] = clr; 2529 for (int i = sa.GetSize() - 1; i >= 0; i--) {
2533 m_bNeedHightlight[i] = TRUE; 2530 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2531 ASSERT(pAnnot != NULL);
2532
2533 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2534
2535 if (rcAnnot.top > fTop) {
2536 nLeftTopIndex = i;
2537 fTop = rcAnnot.top;
2534 } 2538 }
2535 break; 2539 }
2536 } 2540 }
2537 default: 2541
2542 if (nLeftTopIndex >= 0) {
2543 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2544 ASSERT(pLeftTopAnnot != NULL);
2545
2546 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2547
2548 m_Annots.Add(pLeftTopAnnot);
2549 sa.RemoveAt(nLeftTopIndex);
2550
2551 CFX_ArrayTemplate<int> aSelect;
2552
2553 {
2554 for (int i = 0, sz = sa.GetSize(); i < sz; i++) {
2555 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2556 ASSERT(pAnnot != NULL);
2557
2558 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2559
2560 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
2561
2562 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeftTop.top)
2563 aSelect.Add(i);
2564 }
2565 }
2566
2567 {
2568 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) {
2569 m_Annots.Add(sa[aSelect[i]]);
2570 }
2571 }
2572
2573 {
2574 for (int i = aSelect.GetSize() - 1; i >= 0; i--) {
2575 sa.RemoveAt(aSelect[i]);
2576 }
2577 }
2578
2579 aSelect.RemoveAll();
2580 }
2581 }
2582 sa.RemoveAll();
2583 } break;
2584 case BAI_COLUMN: {
2585 CPDFSDK_SortAnnots sa;
2586
2587 {
2588 for (int i = 0, sz = m_pPageView->CountAnnots(); i < sz; i++) {
2589 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2590 ASSERT(pAnnot != NULL);
2591
2592 if (pAnnot->GetType() == m_sType &&
2593 pAnnot->GetSubType() == m_sSubType)
2594 sa.Add(pAnnot);
2595 }
2596 }
2597
2598 if (sa.GetSize() > 0) {
2599 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
2600 }
2601
2602 while (sa.GetSize() > 0) {
2603 int nLeftTopIndex = -1;
2604
2538 { 2605 {
2539 m_aHighlightColor[nFieldType-1] = clr; 2606 FX_FLOAT fLeft = -1.0f;
2540 m_bNeedHightlight[nFieldType-1] = TRUE; 2607
2541 break; 2608 for (int i = sa.GetSize() - 1; i >= 0; i--) {
2609 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2610 ASSERT(pAnnot != NULL);
2611
2612 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2613
2614 if (fLeft < 0) {
2615 nLeftTopIndex = 0;
2616 fLeft = rcAnnot.left;
2617 } else if (rcAnnot.left < fLeft) {
2618 nLeftTopIndex = i;
2619 fLeft = rcAnnot.left;
2620 }
2621 }
2542 } 2622 }
2543 } 2623
2544 2624 if (nLeftTopIndex >= 0) {
2545 } 2625 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2546 2626 ASSERT(pLeftTopAnnot != NULL);
2547 FX_COLORREF CPDFSDK_InterForm::GetHighlightColor(int nFieldType) 2627
2548 { 2628 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2549 if (nFieldType < 0 || nFieldType > 6) 2629
2550 return FXSYS_RGB(255,255,255); 2630 m_Annots.Add(pLeftTopAnnot);
2551 if (nFieldType == 0) 2631 sa.RemoveAt(nLeftTopIndex);
2552 return m_aHighlightColor[0]; 2632
2553 return m_aHighlightColor[nFieldType-1]; 2633 CFX_ArrayTemplate<int> aSelect;
2554 } 2634
2555 2635 {
2556 /* ------------------------- CBA_AnnotIterator ------------------------- */ 2636 for (int i = 0, sz = sa.GetSize(); i < sz; i++) {
2557 2637 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2558 CBA_AnnotIterator::CBA_AnnotIterator(CPDFSDK_PageView* pPageView, const CFX_Byte String& sType, const CFX_ByteString& sSubType) 2638 ASSERT(pAnnot != NULL);
2559 :m_pPageView(pPageView), 2639
2560 m_sType(sType), 2640 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2561 m_sSubType(sSubType), 2641
2562 m_nTabs(BAI_STRUCTURE) 2642 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
2563 { 2643
2564 ASSERT(m_pPageView != NULL); 2644 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTop.right)
2565 2645 aSelect.Add(i);
2566 CPDF_Page* pPDFPage = m_pPageView->GetPDFPage();
2567 ASSERT(pPDFPage != NULL);
2568 ASSERT(pPDFPage->m_pFormDict != NULL);
2569
2570 CFX_ByteString sTabs = pPDFPage->m_pFormDict->GetString("Tabs");
2571
2572 if (sTabs == "R")
2573 {
2574 m_nTabs = BAI_ROW;
2575 }
2576 else if (sTabs == "C")
2577 {
2578 m_nTabs = BAI_COLUMN;
2579 }
2580 else
2581 {
2582 m_nTabs = BAI_STRUCTURE;
2583 }
2584
2585 GenerateResults();
2586 }
2587
2588 CBA_AnnotIterator::~CBA_AnnotIterator()
2589 {
2590 m_Annots.RemoveAll();
2591 }
2592
2593 CPDFSDK_Annot* CBA_AnnotIterator::GetFirstAnnot()
2594 {
2595 if (m_Annots.GetSize() > 0)
2596 return m_Annots[0];
2597
2598 return NULL;
2599 }
2600
2601 CPDFSDK_Annot* CBA_AnnotIterator::GetLastAnnot()
2602 {
2603 if (m_Annots.GetSize() > 0)
2604 return m_Annots[m_Annots.GetSize() - 1];
2605
2606 return NULL;
2607 }
2608
2609 CPDFSDK_Annot* CBA_AnnotIterator::GetNextAnnot(CPDFSDK_Annot* pAnnot)
2610 {
2611 for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
2612 if (m_Annots[i] == pAnnot)
2613 return (i + 1 < sz) ? m_Annots[i+1] : m_Annots[0];
2614 }
2615 return NULL;
2616 }
2617
2618 CPDFSDK_Annot* CBA_AnnotIterator::GetPrevAnnot(CPDFSDK_Annot* pAnnot)
2619 {
2620 for (int i = 0, sz = m_Annots.GetSize(); i < sz; ++i) {
2621 if (m_Annots[i] == pAnnot)
2622 return (i - 1 >= 0) ? m_Annots[i-1] : m_Annots[sz-1];
2623 }
2624 return NULL;
2625 }
2626
2627 int CBA_AnnotIterator::CompareByLeft(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2628 {
2629 ASSERT(p1);
2630 ASSERT(p2);
2631
2632 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2633 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2634
2635 if (rcAnnot1.left < rcAnnot2.left)
2636 return -1;
2637 if (rcAnnot1.left > rcAnnot2.left)
2638 return 1;
2639 return 0;
2640 }
2641
2642
2643 int CBA_AnnotIterator::CompareByTop(CPDFSDK_Annot* p1, CPDFSDK_Annot* p2)
2644 {
2645 ASSERT(p1 != NULL);
2646 ASSERT(p2 != NULL);
2647
2648 CPDF_Rect rcAnnot1 = GetAnnotRect(p1);
2649 CPDF_Rect rcAnnot2 = GetAnnotRect(p2);
2650
2651 if (rcAnnot1.top < rcAnnot2.top)
2652 return -1;
2653 if (rcAnnot1.top > rcAnnot2.top)
2654 return 1;
2655 return 0;
2656 }
2657
2658 void CBA_AnnotIterator::GenerateResults()
2659 {
2660 ASSERT(m_pPageView != NULL);
2661
2662 switch (m_nTabs)
2663 {
2664 case BAI_STRUCTURE:
2665 {
2666 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2667 {
2668 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2669 ASSERT(pAnnot != NULL);
2670
2671 if (pAnnot->GetType() == m_sType
2672 && pAnnot->GetSubType() == m_sSubType)
2673 m_Annots.Add(pAnnot);
2674 } 2646 }
2647 }
2648
2649 {
2650 for (int i = 0, sz = aSelect.GetSize(); i < sz; i++) {
2651 m_Annots.Add(sa[aSelect[i]]);
2652 }
2653 }
2654
2655 {
2656 for (int i = aSelect.GetSize() - 1; i >= 0; i--) {
2657 sa.RemoveAt(aSelect[i]);
2658 }
2659 }
2660
2661 aSelect.RemoveAll();
2675 } 2662 }
2676 break; 2663 }
2677 case BAI_ROW: 2664 sa.RemoveAll();
2678 { 2665 } break;
2679 CPDFSDK_SortAnnots sa; 2666 }
2680 2667 }
2681 { 2668
2682 2669 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot) {
2683 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++) 2670 ASSERT(pAnnot != NULL);
2684 { 2671
2685 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i); 2672 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
2686 ASSERT(pAnnot != NULL); 2673 ASSERT(pPDFAnnot != NULL);
2687 2674
2688 if (pAnnot->GetType() == m_sType 2675 CPDF_Rect rcAnnot;
2689 && pAnnot->GetSubType() == m_sSubType) 2676 pPDFAnnot->GetRect(rcAnnot);
2690 sa.Add(pAnnot); 2677
2691 } 2678 return rcAnnot;
2692 } 2679 }
2693
2694 if (sa.GetSize() > 0)
2695 {
2696 sa.Sort(CBA_AnnotIterator::CompareByLeft);
2697 }
2698
2699 while (sa.GetSize() > 0)
2700 {
2701 int nLeftTopIndex = -1;
2702
2703 {
2704 FX_FLOAT fTop = 0.0f;
2705
2706 for (int i=sa.GetSize()-1; i>=0; i--)
2707 {
2708 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2709 ASSERT(pAnnot != NULL);
2710
2711 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2712
2713 if (rcAnnot.top > fTop)
2714 {
2715 nLeftTopIndex = i;
2716 fTop = rcAnnot.top;
2717 }
2718 }
2719 }
2720
2721 if (nLeftTopIndex >= 0)
2722 {
2723 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2724 ASSERT(pLeftTopAnnot != NULL);
2725
2726 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2727
2728 m_Annots.Add(pLeftTopAnnot);
2729 sa.RemoveAt(nLeftTopIndex);
2730
2731 CFX_ArrayTemplate<int> aSelect;
2732
2733 {
2734 for (int i=0,sz=sa.GetSize(); i<sz; i++)
2735 {
2736 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2737 ASSERT(pAnnot != NULL);
2738
2739 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2740
2741 FX_FLOAT fCenterY = (rcAnnot.top + rcAnnot.bottom) / 2.0f;
2742
2743 if (fCenterY > rcLeftTop.bottom && fCenterY < rcLeft Top.top)
2744 aSelect.Add(i);
2745 }
2746 }
2747
2748 {
2749 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
2750 {
2751 m_Annots.Add(sa[aSelect[i]]);
2752 }
2753 }
2754
2755 {
2756 for (int i=aSelect.GetSize()-1; i>=0; i--)
2757 {
2758 sa.RemoveAt(aSelect[i]);
2759 }
2760 }
2761
2762 aSelect.RemoveAll();
2763 }
2764 }
2765 sa.RemoveAll();
2766 }
2767 break;
2768 case BAI_COLUMN:
2769 {
2770 CPDFSDK_SortAnnots sa;
2771
2772 {
2773 for (int i=0,sz=m_pPageView->CountAnnots(); i<sz; i++)
2774 {
2775 CPDFSDK_Annot* pAnnot = m_pPageView->GetAnnot(i);
2776 ASSERT(pAnnot != NULL);
2777
2778 if (pAnnot->GetType() == m_sType
2779 && pAnnot->GetSubType() == m_sSubType)
2780 sa.Add(pAnnot);
2781 }
2782 }
2783
2784 if (sa.GetSize() > 0)
2785 {
2786 sa.Sort(CBA_AnnotIterator::CompareByTop, FALSE);
2787 }
2788
2789 while (sa.GetSize() > 0)
2790 {
2791 int nLeftTopIndex = -1;
2792
2793 {
2794 FX_FLOAT fLeft = -1.0f;
2795
2796 for (int i=sa.GetSize()-1; i>=0; i--)
2797 {
2798 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2799 ASSERT(pAnnot != NULL);
2800
2801 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2802
2803 if (fLeft < 0)
2804 {
2805 nLeftTopIndex = 0;
2806 fLeft = rcAnnot.left;
2807 }
2808 else if (rcAnnot.left < fLeft)
2809 {
2810 nLeftTopIndex = i;
2811 fLeft = rcAnnot.left;
2812 }
2813 }
2814 }
2815
2816 if (nLeftTopIndex >= 0)
2817 {
2818 CPDFSDK_Annot* pLeftTopAnnot = sa.GetAt(nLeftTopIndex);
2819 ASSERT(pLeftTopAnnot != NULL);
2820
2821 CPDF_Rect rcLeftTop = GetAnnotRect(pLeftTopAnnot);
2822
2823 m_Annots.Add(pLeftTopAnnot);
2824 sa.RemoveAt(nLeftTopIndex);
2825
2826 CFX_ArrayTemplate<int> aSelect;
2827
2828 {
2829 for (int i=0,sz=sa.GetSize(); i<sz; i++)
2830 {
2831 CPDFSDK_Annot* pAnnot = sa.GetAt(i);
2832 ASSERT(pAnnot != NULL);
2833
2834 CPDF_Rect rcAnnot = GetAnnotRect(pAnnot);
2835
2836 FX_FLOAT fCenterX = (rcAnnot.left + rcAnnot.right) / 2.0f;
2837
2838 if (fCenterX > rcLeftTop.left && fCenterX < rcLeftTo p.right)
2839 aSelect.Add(i);
2840 }
2841 }
2842
2843 {
2844 for (int i=0,sz=aSelect.GetSize(); i<sz; i++)
2845 {
2846 m_Annots.Add(sa[aSelect[i]]);
2847 }
2848 }
2849
2850 {
2851 for (int i=aSelect.GetSize()-1; i>=0; i--)
2852 {
2853 sa.RemoveAt(aSelect[i]);
2854 }
2855 }
2856
2857 aSelect.RemoveAll();
2858 }
2859 }
2860 sa.RemoveAll();
2861 }
2862 break;
2863 }
2864 }
2865
2866 CPDF_Rect CBA_AnnotIterator::GetAnnotRect(CPDFSDK_Annot* pAnnot)
2867 {
2868 ASSERT(pAnnot != NULL);
2869
2870 CPDF_Annot* pPDFAnnot = pAnnot->GetPDFAnnot();
2871 ASSERT(pPDFAnnot != NULL);
2872
2873 CPDF_Rect rcAnnot;
2874 pPDFAnnot->GetRect(rcAnnot);
2875
2876 return rcAnnot;
2877 }
2878
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698