OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include "../../include/fpdfdoc/fpdf_doc.h" | 7 #include "../../include/fpdfdoc/fpdf_doc.h" |
8 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWid
getDict) | 8 CPDF_FormControl::CPDF_FormControl(CPDF_FormField* pField, CPDF_Dictionary* pWid
getDict) |
9 { | 9 { |
10 m_pField = pField; | 10 m_pField = pField; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 int iIndex = m_pField->GetControlIndex(this); | 106 int iIndex = m_pField->GetControlIndex(this); |
107 csOn = ((CPDF_Array*)pOpt)->GetString(iIndex); | 107 csOn = ((CPDF_Array*)pOpt)->GetString(iIndex); |
108 } | 108 } |
109 } | 109 } |
110 if (csOn.IsEmpty()) { | 110 if (csOn.IsEmpty()) { |
111 csOn = "Yes"; | 111 csOn = "Yes"; |
112 } | 112 } |
113 CFX_WideString csWOn = PDF_DecodeText(csOn); | 113 CFX_WideString csWOn = PDF_DecodeText(csOn); |
114 return csWOn; | 114 return csWOn; |
115 } | 115 } |
116 FX_BOOL CPDF_FormControl::IsChecked() | 116 bool CPDF_FormControl::IsChecked() |
117 { | 117 { |
118 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); | 118 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); |
119 CFX_ByteString csOn = GetOnStateName(); | 119 CFX_ByteString csOn = GetOnStateName(); |
120 CFX_ByteString csAS = m_pWidgetDict->GetString("AS"); | 120 CFX_ByteString csAS = m_pWidgetDict->GetString("AS"); |
121 return csAS == csOn; | 121 return csAS == csOn; |
122 } | 122 } |
123 FX_BOOL CPDF_FormControl::IsDefaultChecked() | 123 bool CPDF_FormControl::IsDefaultChecked() |
124 { | 124 { |
125 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); | 125 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); |
126 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); | 126 CPDF_Object* pDV = FPDF_GetFieldAttr(m_pField->m_pDict, "DV"); |
127 if (pDV == NULL) { | 127 if (pDV == NULL) { |
128 return FALSE; | 128 return false; |
129 } | 129 } |
130 CFX_ByteString csDV = pDV->GetString(); | 130 CFX_ByteString csDV = pDV->GetString(); |
131 CFX_ByteString csOn = GetOnStateName(); | 131 CFX_ByteString csOn = GetOnStateName(); |
132 return (csDV == csOn); | 132 return (csDV == csOn); |
133 } | 133 } |
134 void CPDF_FormControl::CheckControl(FX_BOOL bChecked) | 134 void CPDF_FormControl::CheckControl(bool bChecked) |
135 { | 135 { |
136 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); | 136 ASSERT(GetType() == CPDF_FormField::CheckBox || GetType() == CPDF_FormField:
:RadioButton); |
137 CFX_ByteString csOn = GetOnStateName(); | 137 CFX_ByteString csOn = GetOnStateName(); |
138 CFX_ByteString csOldAS = m_pWidgetDict->GetString("AS", "Off"); | 138 CFX_ByteString csOldAS = m_pWidgetDict->GetString("AS", "Off"); |
139 CFX_ByteString csAS = "Off"; | 139 CFX_ByteString csAS = "Off"; |
140 if (bChecked) { | 140 if (bChecked) { |
141 csAS = csOn; | 141 csAS = csOn; |
142 } | 142 } |
143 if (csOldAS == csAS) { | 143 if (csOldAS == csAS) { |
144 return; | 144 return; |
145 } | 145 } |
146 m_pWidgetDict->SetAtName("AS", csAS); | 146 m_pWidgetDict->SetAtName("AS", csAS); |
147 m_pForm->m_bUpdated = TRUE; | 147 m_pForm->m_bUpdated = true; |
148 } | 148 } |
149 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::Appeara
nceMode mode); | 149 CPDF_Stream* FPDFDOC_GetAnnotAP(CPDF_Dictionary* pAnnotDict, CPDF_Annot::Appeara
nceMode mode); |
150 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CFX_AffineMatrix*
pMatrix, CPDF_Page* pPage, | 150 void CPDF_FormControl::DrawControl(CFX_RenderDevice* pDevice, CFX_AffineMatrix*
pMatrix, CPDF_Page* pPage, |
151 CPDF_Annot::AppearanceMode mode, const CPDF_R
enderOptions* pOptions) | 151 CPDF_Annot::AppearanceMode mode, const CPDF_R
enderOptions* pOptions) |
152 { | 152 { |
153 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) { | 153 if (m_pWidgetDict->GetInteger("F") & ANNOTFLAG_HIDDEN) { |
154 return; | 154 return; |
155 } | 155 } |
156 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); | 156 CPDF_Stream* pStream = FPDFDOC_GetAnnotAP(m_pWidgetDict, mode); |
157 if (pStream == NULL) { | 157 if (pStream == NULL) { |
(...skipping 21 matching lines...) Expand all Loading... |
179 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); | 179 CFX_ByteString csH = m_pWidgetDict->GetString("H", "I"); |
180 int i = 0; | 180 int i = 0; |
181 while (g_sHighlightingMode[i][0] != '\0') { | 181 while (g_sHighlightingMode[i][0] != '\0') { |
182 if (csH.Equal(g_sHighlightingMode[i])) { | 182 if (csH.Equal(g_sHighlightingMode[i])) { |
183 return (HighlightingMode)i; | 183 return (HighlightingMode)i; |
184 } | 184 } |
185 i ++; | 185 i ++; |
186 } | 186 } |
187 return Invert; | 187 return Invert; |
188 } | 188 } |
189 CPDF_ApSettings CPDF_FormControl::GetMK(FX_BOOL bCreate) | 189 CPDF_ApSettings CPDF_FormControl::GetMK(bool bCreate) |
190 { | 190 { |
191 if (!m_pWidgetDict) { | 191 if (!m_pWidgetDict) { |
192 return NULL; | 192 return NULL; |
193 } | 193 } |
194 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK")); | 194 CPDF_ApSettings mk = m_pWidgetDict->GetDict(FX_BSTRC("MK")); |
195 if (!mk && bCreate) { | 195 if (!mk && bCreate) { |
196 mk = CPDF_Dictionary::Create(); | 196 mk = CPDF_Dictionary::Create(); |
197 if (mk == NULL) { | 197 if (mk == NULL) { |
198 return NULL; | 198 return NULL; |
199 } | 199 } |
200 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk); | 200 m_pWidgetDict->SetAt(FX_BSTRC("MK"), mk); |
201 } | 201 } |
202 return mk; | 202 return mk; |
203 } | 203 } |
204 FX_BOOL CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) | 204 bool CPDF_FormControl::HasMKEntry(CFX_ByteString csEntry) |
205 { | 205 { |
206 CPDF_ApSettings mk = GetMK(FALSE); | 206 CPDF_ApSettings mk = GetMK(false); |
207 return mk.HasMKEntry(csEntry); | 207 return mk.HasMKEntry(csEntry); |
208 } | 208 } |
209 int CPDF_FormControl::GetRotation() | 209 int CPDF_FormControl::GetRotation() |
210 { | 210 { |
211 CPDF_ApSettings mk = GetMK(FALSE); | 211 CPDF_ApSettings mk = GetMK(false); |
212 return mk.GetRotation(); | 212 return mk.GetRotation(); |
213 } | 213 } |
214 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) | 214 FX_ARGB CPDF_FormControl::GetColor(int& iColorType, CFX_ByteString csEntry) |
215 { | 215 { |
216 CPDF_ApSettings mk = GetMK(FALSE); | 216 CPDF_ApSettings mk = GetMK(false); |
217 return mk.GetColor(iColorType, csEntry); | 217 return mk.GetColor(iColorType, csEntry); |
218 } | 218 } |
219 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) | 219 FX_FLOAT CPDF_FormControl::GetOriginalColor(int index, CFX_ByteString csEntry) |
220 { | 220 { |
221 CPDF_ApSettings mk = GetMK(FALSE); | 221 CPDF_ApSettings mk = GetMK(false); |
222 return mk.GetOriginalColor(index, csEntry); | 222 return mk.GetOriginalColor(index, csEntry); |
223 } | 223 } |
224 void CPDF_FormControl::GetOriginalColor(int& iColorType, FX_FLOAT fc[4], CFX_Byt
eString csEntry) | 224 void CPDF_FormControl::GetOriginalColor(int& iColorType, FX_FLOAT fc[4], CFX_Byt
eString csEntry) |
225 { | 225 { |
226 CPDF_ApSettings mk = GetMK(FALSE); | 226 CPDF_ApSettings mk = GetMK(false); |
227 mk.GetOriginalColor(iColorType, fc, csEntry); | 227 mk.GetOriginalColor(iColorType, fc, csEntry); |
228 } | 228 } |
229 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) | 229 CFX_WideString CPDF_FormControl::GetCaption(CFX_ByteString csEntry) |
230 { | 230 { |
231 CPDF_ApSettings mk = GetMK(FALSE); | 231 CPDF_ApSettings mk = GetMK(false); |
232 return mk.GetCaption(csEntry); | 232 return mk.GetCaption(csEntry); |
233 } | 233 } |
234 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) | 234 CPDF_Stream* CPDF_FormControl::GetIcon(CFX_ByteString csEntry) |
235 { | 235 { |
236 CPDF_ApSettings mk = GetMK(FALSE); | 236 CPDF_ApSettings mk = GetMK(false); |
237 return mk.GetIcon(csEntry); | 237 return mk.GetIcon(csEntry); |
238 } | 238 } |
239 CPDF_IconFit CPDF_FormControl::GetIconFit() | 239 CPDF_IconFit CPDF_FormControl::GetIconFit() |
240 { | 240 { |
241 CPDF_ApSettings mk = GetMK(FALSE); | 241 CPDF_ApSettings mk = GetMK(false); |
242 return mk.GetIconFit(); | 242 return mk.GetIconFit(); |
243 } | 243 } |
244 int CPDF_FormControl::GetTextPosition() | 244 int CPDF_FormControl::GetTextPosition() |
245 { | 245 { |
246 CPDF_ApSettings mk = GetMK(FALSE); | 246 CPDF_ApSettings mk = GetMK(false); |
247 return mk.GetTextPosition(); | 247 return mk.GetTextPosition(); |
248 } | 248 } |
249 CPDF_Action CPDF_FormControl::GetAction() | 249 CPDF_Action CPDF_FormControl::GetAction() |
250 { | 250 { |
251 if (!m_pWidgetDict) { | 251 if (!m_pWidgetDict) { |
252 return CPDF_Action(); | 252 return CPDF_Action(); |
253 } | 253 } |
254 if (m_pWidgetDict->KeyExist("A")) { | 254 if (m_pWidgetDict->KeyExist("A")) { |
255 return CPDF_Action(m_pWidgetDict->GetDict("A")); | 255 return CPDF_Action(m_pWidgetDict->GetDict("A")); |
256 } | 256 } |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
339 if (m_pWidgetDict->KeyExist("Q")) { | 339 if (m_pWidgetDict->KeyExist("Q")) { |
340 return m_pWidgetDict->GetInteger("Q", 0); | 340 return m_pWidgetDict->GetInteger("Q", 0); |
341 } else { | 341 } else { |
342 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); | 342 CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q"); |
343 if (pObj == NULL) { | 343 if (pObj == NULL) { |
344 return m_pField->m_pForm->GetFormAlignment(); | 344 return m_pField->m_pForm->GetFormAlignment(); |
345 } | 345 } |
346 return pObj->GetInteger(); | 346 return pObj->GetInteger(); |
347 } | 347 } |
348 } | 348 } |
349 FX_BOOL CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) | 349 bool CPDF_ApSettings::HasMKEntry(const CFX_ByteStringC& csEntry) |
350 { | 350 { |
351 if (m_pDict == NULL) { | 351 if (m_pDict == NULL) { |
352 return FALSE; | 352 return false; |
353 } | 353 } |
354 return m_pDict->KeyExist(csEntry); | 354 return m_pDict->KeyExist(csEntry); |
355 } | 355 } |
356 int CPDF_ApSettings::GetRotation() | 356 int CPDF_ApSettings::GetRotation() |
357 { | 357 { |
358 if (m_pDict == NULL) { | 358 if (m_pDict == NULL) { |
359 return 0; | 359 return 0; |
360 } | 360 } |
361 return m_pDict->GetInteger(FX_BSTRC("R")); | 361 return m_pDict->GetInteger(FX_BSTRC("R")); |
362 } | 362 } |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
458 } | 458 } |
459 return m_pDict->GetDict(FX_BSTRC("IF")); | 459 return m_pDict->GetDict(FX_BSTRC("IF")); |
460 } | 460 } |
461 int CPDF_ApSettings::GetTextPosition() | 461 int CPDF_ApSettings::GetTextPosition() |
462 { | 462 { |
463 if (m_pDict == NULL) { | 463 if (m_pDict == NULL) { |
464 return TEXTPOS_CAPTION; | 464 return TEXTPOS_CAPTION; |
465 } | 465 } |
466 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION); | 466 return m_pDict->GetInteger(FX_BSTRC("TP"), TEXTPOS_CAPTION); |
467 } | 467 } |
OLD | NEW |