summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Vogelheim <dvo@openoffice.org>2001-03-09 13:10:57 +0000
committerDaniel Vogelheim <dvo@openoffice.org>2001-03-09 13:10:57 +0000
commitedddc03962aa2f229eee28911b20463253fcc1d6 (patch)
tree4a6bd586582a72f37080794aeaa68985bdc6a93d
parent68e3c99207c3229dbe802f3fdcc265696d210a55 (diff)
- added: local text fields
-rw-r--r--xmloff/inc/txtflde.hxx50
-rw-r--r--xmloff/source/text/txtflde.cxx107
2 files changed, 134 insertions, 23 deletions
diff --git a/xmloff/inc/txtflde.hxx b/xmloff/inc/txtflde.hxx
index 4eeaf174fcd3..dfbfaba8d483 100644
--- a/xmloff/inc/txtflde.hxx
+++ b/xmloff/inc/txtflde.hxx
@@ -2,9 +2,9 @@
*
* $RCSfile: txtflde.hxx,v $
*
- * $Revision: 1.14 $
+ * $Revision: 1.15 $
*
- * last change: $Author: cl $ $Date: 2001-02-01 19:10:54 $
+ * last change: $Author: dvo $ $Date: 2001-03-09 14:10:57 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -78,14 +78,24 @@
#include <rtl/ustring>
#endif
+#include <map>
+#include <set>
+
+
class SvXMLExport;
class SvXMLNumFmtExport;
struct XMLPropertyState;
-namespace com { namespace sun { namespace star { namespace util {
- struct DateTime;
- struct Date;
-}}}}
+namespace com { namespace sun { namespace star {
+ namespace util { struct DateTime; }
+ namespace util { struct Date; }
+ namespace text { class XTextField; }
+ namespace text { class XText; }
+ namespace beans { class XPropertySet; }
+ namespace frame { class XModel; }
+} } }
+namespace rtl { class OUString; }
+
/// field IDs,
// including translation between UNO speak and XML speak if appropriate
@@ -179,20 +189,18 @@ enum FieldIdEnum {
FIELD_ID_UNKNOWN // invalid or unknown field type!
};
-namespace com { namespace sun { namespace star{
- namespace text { class XTextField; }
- namespace beans { class XPropertySet; }
- namespace frame { class XModel; }
-} } }
-
-namespace rtl { class OUString; }
-
class XMLTextFieldExport
{
SvXMLExport& rExport;
+ /// store used text field master names (NULL means: don't collect)
+ ::std::map<
+ ::com::sun::star::uno::Reference< ::com::sun::star::text::XText >,
+ ::std::set< ::rtl::OUString > > *
+ pUsedMasters;
+
public:
XMLTextFieldExport( SvXMLExport& rExp,
@@ -207,6 +215,7 @@ public:
/// collect styles (character styles, data styles, ...) for this field
/// (if appropriate).
+ /// Also collect used field masters (if pUsedMasters is set)
/// to be called for every field during style export.
void ExportFieldAutoStyle(const ::com::sun::star::uno::Reference <
::com::sun::star::text::XTextField > & rTextField );
@@ -215,6 +224,18 @@ public:
/// to be called once at beginning of document body.
void ExportFieldDeclarations();
+ /// export field declarations for fields used in the the particular XText.
+ /// (Requires that a list of used field declarations has previously been
+ /// built-up in ExportFieldAutoStyle() )
+ void ExportFieldDeclarations(
+ const ::com::sun::star::uno::Reference <
+ ::com::sun::star::text::XText > & rText);
+
+ /// export all field declarations, or only those that have been used?
+ /// Calling this method will reset the list of used field declataions.
+ void SetExportOnlyUsedFieldDeclarations(
+ sal_Bool bExportOnlyUsed = sal_True);
+
// determine element or attribute names
// (public, because they may be useful in related XML export classes)
static const sal_Char* MapPlaceholderType(sal_uInt16 nType);
@@ -478,6 +499,7 @@ private:
const ::rtl::OUString sPropertyAuthor;
const ::rtl::OUString sPropertyDate;
const ::rtl::OUString sPropertyMeasureKind;
+ const ::rtl::OUString sPropertyInstanceName;
const ::rtl::OUString sEmpty;
diff --git a/xmloff/source/text/txtflde.cxx b/xmloff/source/text/txtflde.cxx
index f86a1d57c76f..b8077b0ea799 100644
--- a/xmloff/source/text/txtflde.cxx
+++ b/xmloff/source/text/txtflde.cxx
@@ -2,9 +2,9 @@
*
* $RCSfile: txtflde.cxx,v $
*
- * $Revision: 1.20 $
+ * $Revision: 1.21 $
*
- * last change: $Author: mtg $ $Date: 2001-02-28 11:36:41 $
+ * last change: $Author: dvo $ $Date: 2001-03-09 14:10:33 $
*
* The Contents of this file are made available subject to the terms of
* either of the following licenses
@@ -385,6 +385,7 @@ inline Date const GetDateProperty( const OUString& sPropName,
XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp,
XMLPropertyState* pCombinedCharState)
: rExport(rExp),
+ pUsedMasters(NULL),
sServicePrefix(
RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextField.")),
sFieldMasterPrefix(
@@ -457,13 +458,16 @@ XMLTextFieldExport::XMLTextFieldExport( SvXMLExport& rExp,
sPropertyAuthor(RTL_CONSTASCII_USTRINGPARAM("Author")),
sPropertyDate(RTL_CONSTASCII_USTRINGPARAM("Date")),
sPropertyMeasureKind(RTL_CONSTASCII_USTRINGPARAM("Kind")),
+ sPropertyInstanceName(RTL_CONSTASCII_USTRINGPARAM("InstanceName")),
pCombinedCharactersPropertyState(pCombinedCharState)
{
+ SetExportOnlyUsedFieldDeclarations();
}
XMLTextFieldExport::~XMLTextFieldExport()
{
delete pCombinedCharactersPropertyState;
+ delete pUsedMasters;
}
/// get the field ID (as in FieldIDEnum) from XTextField
@@ -820,6 +824,33 @@ void XMLTextFieldExport::ExportFieldAutoStyle(
// get property set
Reference<XPropertySet> xPropSet(rTextField, UNO_QUERY);
+ // add field master to list of used field masters (if desired)
+ if (NULL != pUsedMasters)
+ {
+ Reference<XDependentTextField> xDepField(rTextField, UNO_QUERY);
+ if (xDepField.is())
+ {
+ Reference<XText> xOurText = rTextField->getAnchor()->getText();
+
+ map<Reference<XText>, set<OUString> >::iterator aMapIter =
+ pUsedMasters->find(xOurText);
+
+ // insert a list for our XText (if necessary)
+ if (aMapIter == pUsedMasters->end())
+ {
+ set<OUString> * pSet = new set<OUString> ;
+ (*pUsedMasters)[xOurText] = *pSet;
+ aMapIter = pUsedMasters->find(xOurText);
+ }
+
+ // insert this text field master
+ OUString sFieldMasterName = GetStringProperty(
+ sPropertyInstanceName, xDepField->getTextFieldMaster());
+ aMapIter->second.insert( sFieldMasterName );
+ }
+ // else: no dependent field -> no master -> ignore
+ }
+
// get Field ID
sal_uInt16 nToken = GetFieldID(rTextField, xPropSet);
@@ -1663,28 +1694,75 @@ void XMLTextFieldExport::ExportFieldHelper(
}
}
+
/// export field declarations / field masters
void XMLTextFieldExport::ExportFieldDeclarations()
{
+ Reference<XText> xEmptyText;
+ ExportFieldDeclarations(xEmptyText);
+}
+
+/// export field declarations / field masters
+void XMLTextFieldExport::ExportFieldDeclarations(
+ const Reference<XText> & rText )
+{
// store lists for decl elements
vector<OUString> aVarName;
vector<OUString> aUserName;
vector<OUString> aSeqName;
vector<OUString> aDdeName;
- // get text fields supplier
+ // get text fields supplier and field master name access
Reference<XTextFieldsSupplier> xTextFieldsSupp(GetExport().GetModel(),
UNO_QUERY);
-
- // iterate over field masters
Reference<container::XNameAccess> xFieldMasterNameAccess(
xTextFieldsSupp->getTextFieldMasters(), UNO_QUERY);
- Sequence<OUString> fieldMasters =
- xFieldMasterNameAccess->getElementNames();
- for(sal_Int32 i=0; i<fieldMasters.getLength(); i++) {
+
+ // where to get the text field masters from?
+ // a) we get a specific XText: then use pUsedMasters
+ // b) the XText is empty: then export all text fields
+ Sequence<OUString> aFieldMasters;
+ if (rText.is())
+ {
+ // export only used masters
+ DBG_ASSERT(NULL != pUsedMasters,
+ "field masters must be recorded in order to be "
+ "written out separatly" );
+ if (NULL != pUsedMasters)
+ {
+ map<Reference<XText>, set<OUString> > ::iterator aMapIter =
+ pUsedMasters->find(rText);
+ if (aMapIter != pUsedMasters->end())
+ {
+ // found the set of used field masters
+ set<OUString> & rOurMasters = aMapIter->second;
+
+ // copy set to sequence
+ aFieldMasters.realloc( rOurMasters.size() );
+ sal_Int32 i = 0;
+ for( set<OUString>::iterator aSetIter = rOurMasters.begin();
+ aSetIter != rOurMasters.end();
+ aSetIter++, i++ )
+ {
+ aFieldMasters[i] = *aSetIter;
+ }
+
+ pUsedMasters->erase(rText);
+ }
+ // else: XText not found -> ignore
+ }
+ // else: no field masters have been recorded -> ignore
+ }
+ else
+ {
+ // no XText: export all!
+ aFieldMasters = xFieldMasterNameAccess->getElementNames();
+ }
+
+ for(sal_Int32 i=0; i<aFieldMasters.getLength(); i++) {
// get field master name
- OUString sFieldMaster = fieldMasters[i];
+ OUString sFieldMaster = aFieldMasters[i];
// workaround for #no-bug#
static const sal_Char sDB[] =
@@ -1943,6 +2021,17 @@ void XMLTextFieldExport::ExportFieldDeclarations()
// else: no declarations element
}
+void XMLTextFieldExport::SetExportOnlyUsedFieldDeclarations(
+ sal_Bool bExportOnlyUsed)
+{
+ delete pUsedMasters;
+ pUsedMasters = NULL;
+
+ // create used masters set (if none is used)
+ if (bExportOnlyUsed)
+ pUsedMasters = new map<Reference<XText>, set<OUString> > ;
+}
+
void XMLTextFieldExport::ExportElement(const sal_Char* pElementName,
sal_Bool bAddSpace)
{