summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2013-01-31 18:30:31 +0100
committerLuboš Luňák <l.lunak@suse.cz>2013-02-01 14:20:34 +0100
commit4a4c5f331b495d758aaad4e7253b13883dc863a9 (patch)
treea96768381725a7abe1bc6d54f7c5556bb5f61bc3
parent805fc4bf039e011591d29f8a75e53c0b1b3a3c6b (diff)
consolidate the ugly code for getting SwDoc* to a function
I'm not quite sure why the code has to do it this complicated way, but at least it's just in one (ok, two) places. Additionally, it seems all those checks are needless paranoia, so just assert. Change-Id: I9f0d4ecc5aec6995eb66ae553a4bd92cc5450b86
-rw-r--r--sw/source/filter/xml/xmlexp.cxx93
-rw-r--r--sw/source/filter/xml/xmlexp.hxx6
-rw-r--r--sw/source/filter/xml/xmlfonte.cxx15
-rw-r--r--sw/source/filter/xml/xmlimp.cxx85
-rw-r--r--sw/source/filter/xml/xmlimp.hxx5
5 files changed, 83 insertions, 121 deletions
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 7148709f854d..2d2d90388eb0 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -88,6 +88,7 @@ SwXMLExport::SwXMLExport(
pTableLines( 0 ),
bBlock( sal_False ),
bShowProgress( sal_True ),
+ doc( NULL ),
sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")),
sCell(RTL_CONSTASCII_USTRINGPARAM("Cell"))
@@ -108,13 +109,6 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
SwPauseThreadStarting aPauseThreadStarting; // #i73788#
- Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
- Reference < XText > xText = xTextDoc->getText();
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( !xTextTunnel.is() )
- return ERR_SWG_WRITE_ERROR;
-
// from here, we use core interfaces -> lock Solar-Mutex
SolarMutexGuard aGuard;
@@ -135,13 +129,7 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
}
}
- SwXText *pText = reinterpret_cast< SwXText * >(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
- OSL_ENSURE( pText, "SwXText missing" );
- if( !pText )
- return ERR_SWG_WRITE_ERROR;
-
- SwDoc *pDoc = pText->GetDoc();
+ SwDoc *pDoc = getDoc();
sal_Bool bExtended = sal_False;
if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
@@ -377,30 +365,7 @@ void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "Views") );
pValue[nIndex++].Value <<= Reference < XIndexAccess > ( xBox, UNO_QUERY );
- Reference < XText > xText;
- SwXText *pText = 0;
-
- if( GetModel().is() )
- {
- Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
- xText = xTextDoc->getText();
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( xTextTunnel.is() )
- {
- pText = reinterpret_cast< SwXText * >(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId()) ));
- OSL_ENSURE( pText, "SwXText missing" );
- }
- }
-
- if( !pText )
- {
- aProps.realloc(nIndex);
- return;
- }
-
- SwDoc *pDoc = pText->GetDoc();
+ SwDoc *pDoc = getDoc();
const Rectangle rRect =
pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
@@ -476,31 +441,16 @@ sal_Int32 SwXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >
void SwXMLExport::SetBodyAttributes()
{
- Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
- Reference < XText > xText = xTextDoc->getText();
// export use of soft page breaks
+ SwDoc *pDoc = getDoc();
+ if( pDoc->GetCurrentViewShell() &&
+ pDoc->GetCurrentViewShell()->GetPageCount() > 1 )
{
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( xTextTunnel.is() )
- {
- SwXText *pText = reinterpret_cast< SwXText * >(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
- OSL_ENSURE( pText, "SwXText missing" );
- if( pText )
- {
- SwDoc *pDoc = pText->GetDoc();
- if( pDoc && pDoc->GetCurrentViewShell() &&
- pDoc->GetCurrentViewShell()->GetPageCount() > 1 )
- {
- sal_Bool bValue = sal_True;
- rtl::OUStringBuffer sBuffer;
- ::sax::Converter::convertBool(sBuffer, bValue);
- AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS,
- sBuffer.makeStringAndClear());
- }
- }
- }
+ sal_Bool bValue = sal_True;
+ rtl::OUStringBuffer sBuffer;
+ ::sax::Converter::convertBool(sBuffer, bValue);
+ AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS,
+ sBuffer.makeStringAndClear());
}
}
@@ -836,4 +786,25 @@ OUString SAL_CALL SwXMLExport::getImplementationName()
}
}
+SwDoc* SwXMLExport::getDoc()
+{
+ if( doc != NULL )
+ return doc;
+ Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
+ Reference < XText > xText = xTextDoc->getText();
+ Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
+ assert( xTextTunnel.is());
+ SwXText *pText = reinterpret_cast< SwXText *>(
+ sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
+ assert( pText != NULL );
+ doc = pText->GetDoc();
+ assert( doc != NULL );
+ return doc;
+}
+
+const SwDoc* SwXMLExport::getDoc() const
+{
+ return const_cast< SwXMLExport* >( this )->getDoc();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmlexp.hxx b/sw/source/filter/xml/xmlexp.hxx
index d5c9ea26a3e2..9015bc6e152d 100644
--- a/sw/source/filter/xml/xmlexp.hxx
+++ b/sw/source/filter/xml/xmlexp.hxx
@@ -26,6 +26,7 @@
#include <xmloff/xmltoken.hxx>
#include <vector>
+class SwDoc;
class SwFmt;
class SwFrmFmt;
class SvXMLUnitConverter;
@@ -60,6 +61,8 @@ class SwXMLExport : public SvXMLExport
sal_Bool bShowProgress : 1;
sal_Bool bSavedShowChanges : 1;
+ SwDoc* doc; // cached for getDoc()
+
void _InitItemExport();
void _FinitItemExport();
void ExportTableLinesAutoStyles( const SwTableLines& rLines,
@@ -144,6 +147,9 @@ public:
// XServiceInfo (override parent method)
::rtl::OUString SAL_CALL getImplementationName()
throw( ::com::sun::star::uno::RuntimeException );
+
+ const SwDoc* getDoc() const;
+ SwDoc* getDoc();
};
inline const SvXMLUnitConverter& SwXMLExport::GetTwipUnitConverter() const
diff --git a/sw/source/filter/xml/xmlfonte.cxx b/sw/source/filter/xml/xmlfonte.cxx
index bf9563b391e2..4b4e48cd33c7 100644
--- a/sw/source/filter/xml/xmlfonte.cxx
+++ b/sw/source/filter/xml/xmlfonte.cxx
@@ -46,20 +46,7 @@ SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(
sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
RES_CHRATR_CTL_FONT };
- Reference < XTextDocument > xTextDoc( _rExport.GetModel(), UNO_QUERY );
- Reference < XText > xText = xTextDoc->getText();
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( !xTextTunnel.is() )
- return;
-
- SwXText *pText = reinterpret_cast< SwXText *>(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
- OSL_ENSURE( pText, "SwXText missing" );
- if( !pText )
- return;
-
- const SfxItemPool& rPool = pText->GetDoc()->GetAttrPool();
+ const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
const SfxPoolItem* pItem;
for( sal_uInt16 i=0; i<3; i++ )
{
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index a86364b4d50e..67fa1efdcb6f 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -425,7 +425,8 @@ SwXMLImport::SwXMLImport(
bShowProgress( true ),
bOrganizerMode( false ),
bInititedXForms( false ),
- bPreserveRedlineMode( sal_True )
+ bPreserveRedlineMode( sal_True ),
+ doc( NULL )
{
_InitItemImport();
@@ -1016,20 +1017,7 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
// this method will modify the document directly -> lock SolarMutex
SolarMutexGuard aGuard;
- Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
- Reference < XText > xText = xTextDoc->getText();
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( !xTextTunnel.is() )
- return;
-
- SwXText *pText = reinterpret_cast< SwXText *>(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
- OSL_ENSURE( pText, "SwXText missing" );
- if( !pText )
- return;
-
- SwDoc *pDoc = pText->GetDoc();
+ SwDoc *pDoc = getDoc();
Rectangle aRect;
if( pDoc->GetDocShell() )
aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
@@ -1463,39 +1451,23 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
if ( !bTabOverMargin )
xProps->setPropertyValue("TabOverMargin", makeAny( false ) );
- Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
- Reference < XText > xText = xTextDoc->getText();
- Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
- OSL_ENSURE( xTextTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( xTextTunnel.is() )
+ SwDoc *pDoc = getDoc();
+ SfxPrinter *pPrinter = pDoc->getPrinter( false );
+ if( pPrinter )
{
- SwXText *pText = reinterpret_cast< SwXText *>(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
- OSL_ENSURE( pText, "SwXText missing" );
- if( pText )
+ // If the printer is known, then the OLE objects will
+ // already have correct sizes, and we don't have to call
+ // PrtOLENotify again. Otherwise we have to call it.
+ // The flag might be set from setting the printer, so it
+ // it is required to clear it.
+ pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
+
+ // old printer metrics compatibility
+ if ( pDoc->get(IDocumentSettingAccess::USE_OLD_PRINTER_METRICS ) &&
+ !pDoc->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
{
- SwDoc *pDoc = pText->GetDoc();
- if( pDoc )
- {
- SfxPrinter *pPrinter = pDoc->getPrinter( false );
- if( pPrinter )
- {
- // If the printer is known, then the OLE objects will
- // already have correct sizes, and we don't have to call
- // PrtOLENotify again. Otherwise we have to call it.
- // The flag might be set from setting the printer, so it
- // it is required to clear it.
- pDoc->SetOLEPrtNotifyPending( !pPrinter->IsKnown() );
-
- // old printer metrics compatibility
- if ( pDoc->get(IDocumentSettingAccess::USE_OLD_PRINTER_METRICS ) &&
- !pDoc->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE ) )
- {
- pPrinter->Compat_OldPrinterMetrics( true );
- pDoc->GetDocShell()->UpdateFontList();
- }
- }
- }
+ pPrinter->Compat_OldPrinterMetrics( true );
+ pDoc->GetDocShell()->UpdateFontList();
}
}
}
@@ -1740,4 +1712,25 @@ void SwXMLImport::initXForms()
bInititedXForms = true;
}
+SwDoc* SwXMLImport::getDoc()
+{
+ if( doc != NULL )
+ return doc;
+ Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
+ Reference < XText > xText = xTextDoc->getText();
+ Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
+ assert( xTextTunnel.is());
+ SwXText *pText = reinterpret_cast< SwXText *>(
+ sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
+ assert( pText != NULL );
+ doc = pText->GetDoc();
+ assert( doc != NULL );
+ return doc;
+}
+
+const SwDoc* SwXMLImport::getDoc() const
+{
+ return const_cast< SwXMLImport* >( this )->getDoc();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/xml/xmlimp.hxx b/sw/source/filter/xml/xmlimp.hxx
index e77ceddcaf4d..093aea3bd394 100644
--- a/sw/source/filter/xml/xmlimp.hxx
+++ b/sw/source/filter/xml/xmlimp.hxx
@@ -79,6 +79,8 @@ class SwXMLImport: public SvXMLImport
bool bInititedXForms : 1;
sal_Bool bPreserveRedlineMode;
+ SwDoc* doc; // cached for getDoc()
+
void _InitItemImport();
void _FinitItemImport();
void UpdateTxtCollConditions( SwDoc *pDoc );
@@ -194,6 +196,9 @@ public:
::com::sun::star::uno::Reference<
::com::sun::star::document::XDocumentProperties>
GetDocumentProperties() const;
+
+ const SwDoc* getDoc() const;
+ SwDoc* getDoc();
};
inline const SvXMLUnitConverter& SwXMLImport::GetTwipUnitConverter() const