1
/* poppler-form.h: qt4 interface to poppler
2
* Copyright (C) 2007-2008, Pino Toscano <pino@kde.org>
3
* Copyright (C) 2008, Albert Astals Cid <aacid@kde.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2, or (at your option)
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
20
#include "poppler-qt4.h"
22
#include <QtCore/QSizeF>
28
#include "poppler-form.h"
29
#include "poppler-page-private.h"
30
#include "poppler-private.h"
31
#include "poppler-annotation-helper.h"
37
FormField::FormField(FormFieldData &dd)
40
const int rotation = m_formData->page->getRotate();
42
double left, top, right, bottom;
43
m_formData->fm->getRect(&left, &bottom, &right, &top);
44
// build a normalized transform matrix for this page at 100% scale
45
GfxState gfxState( 72.0, 72.0, m_formData->page->getCropBox(), rotation, gTrue );
46
double * gfxCTM = gfxState.getCTM();
48
double pageWidth = m_formData->page->getCropWidth();
49
double pageHeight = m_formData->page->getCropHeight();
50
// landscape and seascape page rotation: be sure to use the correct (== rotated) page size
51
if (((rotation / 90) % 2) == 1)
52
qSwap(pageWidth, pageHeight);
53
for ( int i = 0; i < 6; i+=2 )
55
MTX[i] = gfxCTM[i] / pageWidth;
56
MTX[i+1] = gfxCTM[i+1] / pageHeight;
59
XPDFReader::transform( MTX, qMin( left, right ), qMax( top, bottom ), topLeft );
61
XPDFReader::transform( MTX, qMax( left, right ), qMin( top, bottom ), bottomRight );
62
m_formData->box = QRectF(topLeft, QSizeF(bottomRight.x() - topLeft.x(), bottomRight.y() - topLeft.y()));
64
Object *obj = m_formData->fm->getObj();
68
if (obj->isDict() && obj->dictLookup("Ff", &tmp)->isInt())
70
m_formData->flags = tmp.getInt();
73
// reading the widget annotation flags
74
if (obj->isDict() && obj->dictLookup("F", &tmp)->isInt())
76
m_formData->annoflags = tmp.getInt();
81
FormField::~FormField()
87
QRectF FormField::rect() const
89
return m_formData->box;
92
int FormField::id() const
94
return m_formData->fm->getID();
97
QString FormField::name() const
100
Object *obj = m_formData->fm->getObj();
102
if (obj->dictLookup("T", &tmp)->isString())
104
GooString *goo = tmp.getString();
106
name = goo->getCString();
112
QString FormField::uiName() const
115
Object *obj = m_formData->fm->getObj();
117
if (obj->dictLookup("TU", &tmp)->isString())
119
GooString *goo = tmp.getString();
121
name = goo->getCString();
127
bool FormField::isReadOnly() const
129
return m_formData->fm->isReadOnly();
132
bool FormField::isVisible() const
134
return !(m_formData->annoflags & (1 << 1));
137
Link* FormField::activationAction() const
140
Object *obj = m_formData->fm->getObj();
142
if (obj->dictLookup("A", &tmp)->isDict())
144
::LinkAction *act = ::LinkAction::parseAction(&tmp, m_formData->doc->doc->getCatalog()->getBaseURI());
147
action = PageData::convertLinkActionToLink(act, m_formData->doc, QRectF());
156
FormFieldButton::FormFieldButton(DocumentData *doc, ::Page *p, ::FormWidgetButton *w)
157
: FormField(*new FormFieldData(doc, p, w))
161
FormFieldButton::~FormFieldButton()
165
FormFieldButton::FormType FormFieldButton::type() const
167
return FormField::FormButton;
170
FormFieldButton::ButtonType FormFieldButton::buttonType() const
172
FormWidgetButton* fwb = static_cast<FormWidgetButton*>(m_formData->fm);
173
switch (fwb->getButtonType())
175
case formButtonCheck:
176
return FormFieldButton::CheckBox;
179
return FormFieldButton::Push;
181
case formButtonRadio:
182
return FormFieldButton::Radio;
185
return FormFieldButton::CheckBox;
188
QString FormFieldButton::caption() const
190
FormWidgetButton* fwb = static_cast<FormWidgetButton*>(m_formData->fm);
191
// HACK push buttons seems to have a null GooString for the caption
192
if (fwb->getButtonType() == formButtonPush)
195
return fwb->getOnStr() ? QString::fromUtf8(fwb->getOnStr()) : QString();
198
bool FormFieldButton::state() const
200
FormWidgetButton* fwb = static_cast<FormWidgetButton*>(m_formData->fm);
201
return fwb->getState();
204
void FormFieldButton::setState( bool state )
206
FormWidgetButton* fwb = static_cast<FormWidgetButton*>(m_formData->fm);
207
fwb->setState((GBool)state);
210
QList<int> FormFieldButton::siblings() const
212
FormWidgetButton* fwb = static_cast<FormWidgetButton*>(m_formData->fm);
213
if (fwb->getButtonType() == formButtonPush)
217
unsigned *sibls = fwb->getSiblingsID();
218
for (int i = 0; i < fwb->getNumSiblingsID(); ++i)
219
ret.append(sibls[i]);
225
FormFieldText::FormFieldText(DocumentData *doc, ::Page *p, ::FormWidgetText *w)
226
: FormField(*new FormFieldData(doc, p, w))
230
FormFieldText::~FormFieldText()
234
FormField::FormType FormFieldText::type() const
236
return FormField::FormText;
239
FormFieldText::TextType FormFieldText::textType() const
241
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
242
if (fwt->isFileSelect())
243
return FormFieldText::FileSelect;
244
else if (fwt->isMultiline())
245
return FormFieldText::Multiline;
246
return FormFieldText::Normal;
249
QString FormFieldText::text() const
251
GooString *goo = static_cast<FormWidgetText*>(m_formData->fm)->getContent();
252
return UnicodeParsedString(goo);
255
void FormFieldText::setText( const QString& text )
257
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
258
GooString * goo = QStringToUnicodeGooString( text );
259
fwt->setContent( goo );
263
bool FormFieldText::isPassword() const
265
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
266
return fwt->isPassword();
269
bool FormFieldText::isRichText() const
271
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
272
return fwt->isRichText();
275
int FormFieldText::maximumLength() const
277
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
278
const int maxlen = fwt->getMaxLen();
279
return maxlen > 0 ? maxlen : -1;
282
Qt::Alignment FormFieldText::textAlignment() const
284
return m_formData->textAlignment(m_formData->fm->getObj());
287
bool FormFieldText::canBeSpellChecked() const
289
FormWidgetText* fwt = static_cast<FormWidgetText*>(m_formData->fm);
290
return !fwt->noSpellCheck();
294
FormFieldChoice::FormFieldChoice(DocumentData *doc, ::Page *p, ::FormWidgetChoice *w)
295
: FormField(*new FormFieldData(doc, p, w))
299
FormFieldChoice::~FormFieldChoice()
303
FormFieldChoice::FormType FormFieldChoice::type() const
305
return FormField::FormChoice;
308
FormFieldChoice::ChoiceType FormFieldChoice::choiceType() const
310
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
312
return FormFieldChoice::ComboBox;
313
return FormFieldChoice::ListBox;
316
QStringList FormFieldChoice::choices() const
318
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
320
int num = fwc->getNumChoices();
321
for (int i = 0; i < num; ++i)
323
ret.append(UnicodeParsedString(fwc->getChoice(i)));
328
bool FormFieldChoice::isEditable() const
330
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
331
return fwc->isCombo() ? fwc->hasEdit() : false;
334
bool FormFieldChoice::multiSelect() const
336
// return m_formData->flags & (1 << 21);
337
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
338
return !fwc->isCombo() ? fwc->isMultiSelect() : false;
341
QList<int> FormFieldChoice::currentChoices() const
343
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
344
int num = fwc->getNumChoices();
346
for ( int i = 0; i < num; ++i )
347
if ( fwc->isSelected( i ) )
352
void FormFieldChoice::setCurrentChoices( const QList<int> &choice )
354
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
356
for ( int i = 0; i < choice.count(); ++i )
357
fwc->select( choice.at( i ) );
360
Qt::Alignment FormFieldChoice::textAlignment() const
362
return m_formData->textAlignment(m_formData->fm->getObj());
365
bool FormFieldChoice::canBeSpellChecked() const
367
FormWidgetChoice* fwc = static_cast<FormWidgetChoice*>(m_formData->fm);
368
return !fwc->noSpellCheck();