Kaydet (Commit) 4a4c5f33 authored tarafından Luboš Luňák's avatar Luboš Luňák

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
üst 805fc4bf
...@@ -88,6 +88,7 @@ SwXMLExport::SwXMLExport( ...@@ -88,6 +88,7 @@ SwXMLExport::SwXMLExport(
pTableLines( 0 ), pTableLines( 0 ),
bBlock( sal_False ), bBlock( sal_False ),
bShowProgress( sal_True ), bShowProgress( sal_True ),
doc( NULL ),
sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")), sNumberFormat(RTL_CONSTASCII_USTRINGPARAM("NumberFormat")),
sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")), sIsProtected(RTL_CONSTASCII_USTRINGPARAM("IsProtected")),
sCell(RTL_CONSTASCII_USTRINGPARAM("Cell")) sCell(RTL_CONSTASCII_USTRINGPARAM("Cell"))
...@@ -108,13 +109,6 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass ) ...@@ -108,13 +109,6 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
SwPauseThreadStarting aPauseThreadStarting; // #i73788# 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 // from here, we use core interfaces -> lock Solar-Mutex
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
...@@ -135,13 +129,7 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass ) ...@@ -135,13 +129,7 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
} }
} }
SwXText *pText = reinterpret_cast< SwXText * >( SwDoc *pDoc = getDoc();
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();
sal_Bool bExtended = sal_False; sal_Bool bExtended = sal_False;
if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES| if( (getExportFlags() & (EXPORT_FONTDECLS|EXPORT_STYLES|
...@@ -377,30 +365,7 @@ void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps) ...@@ -377,30 +365,7 @@ void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps)
pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "Views") ); pValue[nIndex].Name = OUString( RTL_CONSTASCII_USTRINGPARAM ( "Views") );
pValue[nIndex++].Value <<= Reference < XIndexAccess > ( xBox, UNO_QUERY ); pValue[nIndex++].Value <<= Reference < XIndexAccess > ( xBox, UNO_QUERY );
Reference < XText > xText; SwDoc *pDoc = getDoc();
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();
const Rectangle rRect = const Rectangle rRect =
pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT ); pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP; sal_Bool bTwip = pDoc->GetDocShell()->GetMapUnit ( ) == MAP_TWIP;
...@@ -476,21 +441,9 @@ sal_Int32 SwXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup > ...@@ -476,21 +441,9 @@ sal_Int32 SwXMLExport::GetDocumentSpecificSettings( ::std::list< SettingsGroup >
void SwXMLExport::SetBodyAttributes() void SwXMLExport::SetBodyAttributes()
{ {
Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY );
Reference < XText > xText = xTextDoc->getText();
// export use of soft page breaks // export use of soft page breaks
{ SwDoc *pDoc = getDoc();
Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY); if( pDoc->GetCurrentViewShell() &&
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 ) pDoc->GetCurrentViewShell()->GetPageCount() > 1 )
{ {
sal_Bool bValue = sal_True; sal_Bool bValue = sal_True;
...@@ -499,9 +452,6 @@ void SwXMLExport::SetBodyAttributes() ...@@ -499,9 +452,6 @@ void SwXMLExport::SetBodyAttributes()
AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS, AddAttribute(XML_NAMESPACE_TEXT, XML_USE_SOFT_PAGE_BREAKS,
sBuffer.makeStringAndClear()); sBuffer.makeStringAndClear());
} }
}
}
}
} }
...@@ -836,4 +786,25 @@ OUString SAL_CALL SwXMLExport::getImplementationName() ...@@ -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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <xmloff/xmltoken.hxx> #include <xmloff/xmltoken.hxx>
#include <vector> #include <vector>
class SwDoc;
class SwFmt; class SwFmt;
class SwFrmFmt; class SwFrmFmt;
class SvXMLUnitConverter; class SvXMLUnitConverter;
...@@ -60,6 +61,8 @@ class SwXMLExport : public SvXMLExport ...@@ -60,6 +61,8 @@ class SwXMLExport : public SvXMLExport
sal_Bool bShowProgress : 1; sal_Bool bShowProgress : 1;
sal_Bool bSavedShowChanges : 1; sal_Bool bSavedShowChanges : 1;
SwDoc* doc; // cached for getDoc()
void _InitItemExport(); void _InitItemExport();
void _FinitItemExport(); void _FinitItemExport();
void ExportTableLinesAutoStyles( const SwTableLines& rLines, void ExportTableLinesAutoStyles( const SwTableLines& rLines,
...@@ -144,6 +147,9 @@ public: ...@@ -144,6 +147,9 @@ public:
// XServiceInfo (override parent method) // XServiceInfo (override parent method)
::rtl::OUString SAL_CALL getImplementationName() ::rtl::OUString SAL_CALL getImplementationName()
throw( ::com::sun::star::uno::RuntimeException ); throw( ::com::sun::star::uno::RuntimeException );
const SwDoc* getDoc() const;
SwDoc* getDoc();
}; };
inline const SvXMLUnitConverter& SwXMLExport::GetTwipUnitConverter() const inline const SvXMLUnitConverter& SwXMLExport::GetTwipUnitConverter() const
......
...@@ -46,20 +46,7 @@ SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl( ...@@ -46,20 +46,7 @@ SwXMLFontAutoStylePool_Impl::SwXMLFontAutoStylePool_Impl(
sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT, sal_uInt16 aWhichIds[3] = { RES_CHRATR_FONT, RES_CHRATR_CJK_FONT,
RES_CHRATR_CTL_FONT }; RES_CHRATR_CTL_FONT };
Reference < XTextDocument > xTextDoc( _rExport.GetModel(), UNO_QUERY ); const SfxItemPool& rPool = _rExport.getDoc()->GetAttrPool();
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 SfxPoolItem* pItem; const SfxPoolItem* pItem;
for( sal_uInt16 i=0; i<3; i++ ) for( sal_uInt16 i=0; i<3; i++ )
{ {
......
...@@ -425,7 +425,8 @@ SwXMLImport::SwXMLImport( ...@@ -425,7 +425,8 @@ SwXMLImport::SwXMLImport(
bShowProgress( true ), bShowProgress( true ),
bOrganizerMode( false ), bOrganizerMode( false ),
bInititedXForms( false ), bInititedXForms( false ),
bPreserveRedlineMode( sal_True ) bPreserveRedlineMode( sal_True ),
doc( NULL )
{ {
_InitItemImport(); _InitItemImport();
...@@ -1016,20 +1017,7 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps) ...@@ -1016,20 +1017,7 @@ void SwXMLImport::SetViewSettings(const Sequence < PropertyValue > & aViewProps)
// this method will modify the document directly -> lock SolarMutex // this method will modify the document directly -> lock SolarMutex
SolarMutexGuard aGuard; SolarMutexGuard aGuard;
Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY ); SwDoc *pDoc = getDoc();
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();
Rectangle aRect; Rectangle aRect;
if( pDoc->GetDocShell() ) if( pDoc->GetDocShell() )
aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT ); aRect = pDoc->GetDocShell()->GetVisArea( ASPECT_CONTENT );
...@@ -1463,20 +1451,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1463,20 +1451,7 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
if ( !bTabOverMargin ) if ( !bTabOverMargin )
xProps->setPropertyValue("TabOverMargin", makeAny( false ) ); xProps->setPropertyValue("TabOverMargin", makeAny( false ) );
Reference < XTextDocument > xTextDoc( GetModel(), UNO_QUERY ); SwDoc *pDoc = getDoc();
Reference < XText > xText = xTextDoc->getText();
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 )
{
SfxPrinter *pPrinter = pDoc->getPrinter( false ); SfxPrinter *pPrinter = pDoc->getPrinter( false );
if( pPrinter ) if( pPrinter )
{ {
...@@ -1495,9 +1470,6 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC ...@@ -1495,9 +1470,6 @@ void SwXMLImport::SetConfigurationSettings(const Sequence < PropertyValue > & aC
pDoc->GetDocShell()->UpdateFontList(); pDoc->GetDocShell()->UpdateFontList();
} }
} }
}
}
}
} }
...@@ -1740,4 +1712,25 @@ void SwXMLImport::initXForms() ...@@ -1740,4 +1712,25 @@ void SwXMLImport::initXForms()
bInititedXForms = true; 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -79,6 +79,8 @@ class SwXMLImport: public SvXMLImport ...@@ -79,6 +79,8 @@ class SwXMLImport: public SvXMLImport
bool bInititedXForms : 1; bool bInititedXForms : 1;
sal_Bool bPreserveRedlineMode; sal_Bool bPreserveRedlineMode;
SwDoc* doc; // cached for getDoc()
void _InitItemImport(); void _InitItemImport();
void _FinitItemImport(); void _FinitItemImport();
void UpdateTxtCollConditions( SwDoc *pDoc ); void UpdateTxtCollConditions( SwDoc *pDoc );
...@@ -194,6 +196,9 @@ public: ...@@ -194,6 +196,9 @@ public:
::com::sun::star::uno::Reference< ::com::sun::star::uno::Reference<
::com::sun::star::document::XDocumentProperties> ::com::sun::star::document::XDocumentProperties>
GetDocumentProperties() const; GetDocumentProperties() const;
const SwDoc* getDoc() const;
SwDoc* getDoc();
}; };
inline const SvXMLUnitConverter& SwXMLImport::GetTwipUnitConverter() const inline const SvXMLUnitConverter& SwXMLImport::GetTwipUnitConverter() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment