|
|
|
|
@ -22,11 +22,15 @@ |
|
|
|
|
#include "../document_p.h" |
|
|
|
|
#include "../form.h" |
|
|
|
|
#include "../page.h" |
|
|
|
|
#include "../page_p.h" |
|
|
|
|
|
|
|
|
|
using namespace Okular; |
|
|
|
|
|
|
|
|
|
static KJSPrototype *g_fieldProto; |
|
|
|
|
|
|
|
|
|
typedef QHash< FormField *, Page * > FormCache; |
|
|
|
|
Q_GLOBAL_STATIC( FormCache, g_fieldCache ) |
|
|
|
|
|
|
|
|
|
// Field.doc
|
|
|
|
|
static KJSObject fieldGetDoc( KJSContext *context, void * ) |
|
|
|
|
{ |
|
|
|
|
@ -109,7 +113,7 @@ static KJSObject fieldGetType( KJSContext *, void *object ) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Field.value (getter)
|
|
|
|
|
static KJSObject fieldGetValue( KJSContext *context, void *object ) |
|
|
|
|
static KJSObject fieldGetValue( KJSContext */*context*/, void *object ) |
|
|
|
|
{ |
|
|
|
|
FormField *field = reinterpret_cast< FormField * >( object ); |
|
|
|
|
|
|
|
|
|
@ -156,8 +160,23 @@ static void fieldSetValue( KJSContext *context, void *object, KJSObject value ) |
|
|
|
|
} |
|
|
|
|
case FormField::FormText: |
|
|
|
|
{ |
|
|
|
|
FormFieldText *text = static_cast< FormFieldText * >( field ); |
|
|
|
|
text->setText( value.toString( context ) ); |
|
|
|
|
FormFieldText *textField = static_cast< FormFieldText * >( field ); |
|
|
|
|
const QString text = value.toString( context ); |
|
|
|
|
if ( text != textField->text() ) |
|
|
|
|
{ |
|
|
|
|
textField->setText( text ); |
|
|
|
|
|
|
|
|
|
Page *page = g_fieldCache->value( field ); |
|
|
|
|
if (page) |
|
|
|
|
{ |
|
|
|
|
Document *doc = PagePrivate::get( page )->m_doc->m_parent; |
|
|
|
|
QMetaObject::invokeMethod( doc, "refreshPixmaps", Qt::QueuedConnection, Q_ARG( int, page->number() ) ); |
|
|
|
|
} |
|
|
|
|
else |
|
|
|
|
{ |
|
|
|
|
qWarning() << "Could not get page of field" << field; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
case FormField::FormChoice: |
|
|
|
|
@ -196,5 +215,14 @@ KJSObject JSField::wrapField( KJSContext *ctx, FormField *field, Page *page ) |
|
|
|
|
// ### cache unique wrapper
|
|
|
|
|
KJSObject f = g_fieldProto->constructObject( ctx, field ); |
|
|
|
|
f.setProperty( ctx, QStringLiteral("page"), page->number() ); |
|
|
|
|
g_fieldCache->insert( field, page ); |
|
|
|
|
return f; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void JSField::clearCachedFields() |
|
|
|
|
{ |
|
|
|
|
if ( g_fieldCache.exists() ) |
|
|
|
|
{ |
|
|
|
|
g_fieldCache->clear(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|