/* 
  ==========================================================================
  Basic infrastructure providing
    CollectionOf_xFormFields
    CollectionOf_xFormWidgets

  Nov 2020 - A.Buratti fecit
  ==========================================================================
*/

#ifndef __XPDF_FORM_INCLUDED
#define __XPDF_FORM_INCLUDED

#include <mupdf/pdf.h>
#include "xCollection.h"

/*
** ----------------------------------------------------------------------------
** xFormField section:
**  * Declare xFormField structure
**  * Declare xFormField's New/Destroy
**  * Declare CollectionOf_xFormFields (set of all the fields of a given pdf_document)
**  * Declare Build_CollectionOf_xFormFields()
** ----------------------------------------------------------------------------
*/

typedef struct {
    fz_context* ctx;    // ref to document's context.
	char *fieldname;     // (owned)   full field name.
	pdf_obj *fieldObj;  // reference to the terminal-field element.
} xFormField;

xFormField* xFormField_New(fz_context* ctx, char* fullname, pdf_obj* fieldObj);
void        xFormField_Destroy(xFormField* rec);

DECLARE_COLLECTION_OF(xFormField *,xFormFields)

int Build_CollectionOf_xFormFields(fz_context *ctx, pdf_document* doc, CollectionOf_xFormFields* map);

/*
** ----------------------------------------------------------------------------
** xFormWidgets section:
**  * Declare xFormWidget structure
**  * Declare xFormWidget's New/Destroy
**  * Declare CollectionOf_xFormWidgets   (set of all the fields' widgets of a given pdf_document)
**  * Declare Build_CollectionOf_xFormWidgets()
** ----------------------------------------------------------------------------
*/

 // note that a field may have more than one widget on the same page
 // (and other widgets in other pages)  
typedef struct {
    fz_context* ctx;     // ref to document's context
    pdf_obj *widgetObj;  // ref to the widget's obj                        
	int pageNumber;
	pdf_obj *fieldObj;   // ref to the terminal-field element
} xFormWidget;

xFormWidget* xFormWidget_New(fz_context* ctx, pdf_obj* fieldObj, pdf_obj* widget, int pageNumber);
void         xFormWidget_Destroy(xFormWidget* rec);

DECLARE_COLLECTION_OF(xFormWidget *,xFormWidgets)

extern int Build_CollectionOf_xFormWidgets(fz_context *ctx, pdf_document* doc, CollectionOf_xFormWidgets* map);

#endif  // __XPDF_FORM_INCLUDED
