/*
Copyright 2008 Stefano Chizzolini. http://clown.stefanochizzolini.it
Contributors:
* Stefano Chizzolini (original code developer, http://www.stefanochizzolini.it)
This file should be part of the source code distribution of "PDF Clown library"
(the Program): see the accompanying README files for more info.
This Program is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation; either version 2 of the License, or (at your option) any later version.
This Program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY, either expressed or implied; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License for more details.
You should have received a copy of the GNU General Public License along with this
Program (see README files); if not, go to the GNU website (http://www.gnu.org/).
Redistribution and use, with or without modification, are permitted provided that such
redistributions retain the above copyright notice, license and disclaimer, along with
this list of conditions.
*/
using it.stefanochizzolini.clown.bytes;
using it.stefanochizzolini.clown.documents;
using it.stefanochizzolini.clown.documents.interaction.annotations;
using it.stefanochizzolini.clown.files;
using it.stefanochizzolini.clown.objects;
using System;
using System.Collections;
using System.Collections.Generic;
namespace it.stefanochizzolini.clown.documents.interaction.forms{
/**
<summary>Interactive form fields [PDF:1.6:8.6.1].</summary>
*/
public class Fields
: PdfObjectWrapper<PdfArray>,
IDictionary<string,Field>
{
#region dynamic
#region constructors
public Fields(
Document context
) : base(
context.File,
new PdfArray()
)
{}
internal Fields(
PdfDirectObject baseObject,
PdfIndirectObject container
) : base(baseObject,container)
{}
#endregion
#region interface
#region public
public bool Add(
Field value
)
{
BaseDataObject.Add(value.BaseObject);
return true;
}
public override object Clone(
Document context
)
{throw new NotImplementedException();}
#region IDictionary
public void Add(
string key,
Field value
)
{throw new NotImplementedException();}
public bool ContainsKey(
string key
)
{throw new NotImplementedException();}
public ICollection<string> Keys
{
get
{
throw new NotImplementedException();
//TODO: retrieve all the full names (keys)!!!
// return getBaseDataObject().keySet();
}
}
public bool Remove(
string key
)
{
throw new NotImplementedException();
/*
TODO:search through the full name (key)!
return Field.wrap(
getBaseDataObject().remove(key)
);*/
}
public Field this[
string key
]
{
//TODO!!!
get
{throw new NotImplementedException();}
set
{
throw new NotImplementedException();
/*
TODO:put the field into the correct position, based on the full name (key)!!!
return Field.wrap(
getBaseDataObject().put(key,value.getBaseObject())
);*/
}
}
public bool TryGetValue(
string key,
out Field value
)
{
value = this[key];
if(value == null)
return ContainsKey(key);
return true;
}
public ICollection<Field> Values
{
get
{
IList<Field> values = new List<Field>();
RetrieveValues(BaseDataObject, values);
return values;
}
}
#region ICollection
void ICollection<KeyValuePair<string,Field>>.Add(
KeyValuePair<string,Field> entry
)
{Add(entry.Key,entry.Value);}
public void Clear(
)
{
//TODO:verify whether to recursively unregister the fields!!!
BaseDataObject.Clear();
}
bool ICollection<KeyValuePair<string,Field>>.Contains(
KeyValuePair<string,Field> entry
)
{throw new NotImplementedException();}
public void CopyTo(
KeyValuePair<string,Field>[] entries,
int index
)
{throw new NotImplementedException();}
public int Count
{get{return BaseDataObject.Count;}}
public bool IsReadOnly
{get{return false;}}
public bool Remove(
KeyValuePair<string,Field> entry
)
{throw new NotImplementedException();}
#region IEnumerable<KeyValuePair<string,Field>>
IEnumerator<KeyValuePair<string,Field>> IEnumerable<KeyValuePair<string,Field>>.GetEnumerator(
)
{throw new NotImplementedException();}
#region IEnumerable
IEnumerator IEnumerable.GetEnumerator(
)
{return ((IEnumerable<KeyValuePair<string,Field>>)this).GetEnumerator();}
#endregion
#endregion
#endregion
#endregion
#endregion
#region private
private void RetrieveValues(
PdfArray fieldObjects,
IList<Field> values
)
{
foreach(
PdfDirectObject fieldObject in fieldObjects
)
{
PdfReference fieldReference = (PdfReference)fieldObject;
PdfArray kidReferences = (PdfArray)File.Resolve(
((PdfDictionary)fieldReference.DataObject)[PdfName.Kids]
);
PdfDictionary kidObject;
if(kidReferences == null)
{kidObject = null;}
else
{kidObject = (PdfDictionary)((PdfReference)kidReferences[0]).DataObject;}
// Terminal field?
if(kidObject == null // Merged single widget annotation.
|| (!kidObject.ContainsKey(PdfName.FT) // Multiple widget annotations.
&& kidObject.ContainsKey(PdfName.Subtype)
&& kidObject[PdfName.Subtype].Equals(PdfName.Widget)))
{values.Add(Field.Wrap(fieldReference));}
else // Non-terminal field.
{RetrieveValues(kidReferences, values);}
}
}
#endregion
#endregion
#endregion
}
}
|