diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2009-11-25 13:27:22 +0100 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2009-11-25 13:27:22 +0100 |
commit | 33f21809ca208713191cca2d35a7879163e75909 (patch) | |
tree | f256b381afb8c1796e1e96d4af6f4884b18955df /svx | |
parent | 27107b0d9f88117373b50fef948a8919ea49288e (diff) | |
parent | fcac7b7672113ec68f90ab4443bc8a920a59ab34 (diff) |
CWS-TOOLING: integrate CWS controltextrendering
Diffstat (limited to 'svx')
-rw-r--r-- | svx/inc/svx/fmmodel.hxx | 10 | ||||
-rw-r--r-- | svx/source/form/fmcontrollayout.cxx | 205 | ||||
-rw-r--r-- | svx/source/form/fmmodel.cxx | 39 | ||||
-rw-r--r-- | svx/source/form/fmobj.cxx | 86 | ||||
-rw-r--r-- | svx/source/form/formcontrolfactory.cxx | 107 | ||||
-rw-r--r-- | svx/source/inc/fmcontrollayout.hxx | 16 | ||||
-rw-r--r-- | svx/source/inc/fmobj.hxx | 8 |
7 files changed, 314 insertions, 157 deletions
diff --git a/svx/inc/svx/fmmodel.hxx b/svx/inc/svx/fmmodel.hxx index 2f61967bc3ac..f831729b5006 100644 --- a/svx/inc/svx/fmmodel.hxx +++ b/svx/inc/svx/fmmodel.hxx @@ -89,14 +89,16 @@ public: /** check whether the OpenInDesignMode has been set explicitly or been loaded (<FALSE/>) or if it still has the default value from construction (<TRUE/>) */ - sal_Bool OpenInDesignModeIsDefaulted( ); + sal_Bool OpenInDesignModeIsDefaulted(); -//#if 0 // _SOLAR__PRIVATE - void implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce ); + /** determines whether form controls should use the SdrModel's reference device for text rendering + */ + sal_Bool ControlsUseRefDevice() const; FmXUndoEnvironment& GetUndoEnv(); -//#endif +private: + void implSetOpenInDesignMode( sal_Bool _bOpenDesignMode, sal_Bool _bForce ); }; #endif // _FM_FMMODEL_HXX diff --git a/svx/source/form/fmcontrollayout.cxx b/svx/source/form/fmcontrollayout.cxx index 92e987db796c..9748426c0b26 100644 --- a/svx/source/form/fmcontrollayout.cxx +++ b/svx/source/form/fmcontrollayout.cxx @@ -30,17 +30,28 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svx.hxx" + #include "fmcontrollayout.hxx" -#ifndef _SVX_FMPROP_HRC #include "fmprop.hrc" -#endif /** === begin UNO includes === **/ #include <com/sun/star/form/FormComponentType.hpp> #include <com/sun/star/awt/VisualEffect.hpp> +#include <com/sun/star/i18n/ScriptType.hpp> +#include <com/sun/star/lang/Locale.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> +#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/container/XChild.hpp> /** === end UNO includes === **/ -#include <tools/debug.hxx> + #include <comphelper/processfactory.hxx> +#include <i18npool/mslangid.hxx> +#include <svtools/syslocale.hxx> +#include <toolkit/helper/vclunohelper.hxx> +#include <tools/debug.hxx> +#include <tools/diagnose_ex.h> +#include <vcl/outdev.hxx> //........................................................................ namespace svxform @@ -48,15 +59,171 @@ namespace svxform //........................................................................ using namespace ::utl; - using namespace ::com::sun::star::uno; - using namespace ::com::sun::star::awt; - using namespace ::com::sun::star::beans; - using namespace ::com::sun::star::form; + /** === begin UNO using === **/ + using ::com::sun::star::uno::Reference; + using ::com::sun::star::uno::XInterface; + using ::com::sun::star::uno::UNO_QUERY; + using ::com::sun::star::uno::UNO_QUERY_THROW; + using ::com::sun::star::uno::UNO_SET_THROW; + using ::com::sun::star::uno::Exception; + using ::com::sun::star::uno::RuntimeException; + using ::com::sun::star::uno::Any; + using ::com::sun::star::uno::makeAny; + using ::com::sun::star::uno::Sequence; + using ::com::sun::star::uno::Type; + using ::com::sun::star::beans::XPropertySet; + using ::com::sun::star::beans::XPropertySetInfo; + using ::com::sun::star::lang::Locale; + using ::com::sun::star::awt::FontDescriptor; + using ::com::sun::star::style::XStyleFamiliesSupplier; + using ::com::sun::star::lang::XServiceInfo; + using ::com::sun::star::container::XNameAccess; + using ::com::sun::star::container::XChild; + /** === end UNO using === **/ + namespace FormComponentType = ::com::sun::star::form::FormComponentType; + namespace VisualEffect = ::com::sun::star::awt::VisualEffect; + namespace ScriptType = ::com::sun::star::i18n::ScriptType; + + //-------------------------------------------------------------------- + namespace + { + //.................................................................... + template< class INTERFACE_TYPE > + Reference< INTERFACE_TYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode ) + { + Reference< INTERFACE_TYPE > xTypedNode( _rxModelNode, UNO_QUERY ); + if ( xTypedNode.is() ) + return xTypedNode; + else + { + Reference< XChild > xChild( _rxModelNode, UNO_QUERY ); + if ( xChild.is() ) + return getTypedModelNode< INTERFACE_TYPE >( xChild->getParent() ); + else + return NULL; + } + } + + //.................................................................... + static bool lcl_getDocumentDefaultStyleAndFamily( const Reference< XInterface >& _rxDocument, ::rtl::OUString& _rFamilyName, ::rtl::OUString& _rStyleName ) SAL_THROW(( Exception )) + { + bool bSuccess = true; + Reference< XServiceInfo > xDocumentSI( _rxDocument, UNO_QUERY ); + if ( xDocumentSI.is() ) + { + if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ) ) + || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.WebDocument" ) ) ) + ) + { + _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ); + _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); + } + else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" ) ) ) ) + { + _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ); + _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ); + } + else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) + || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) + ) + { + _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) ); + _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ); + } + else + bSuccess = false; + } + return bSuccess; + } + + //.................................................................... + static void lcl_initializeControlFont( const Reference< XPropertySet >& _rxModel ) + { + try + { + Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW ); + Reference< XPropertySetInfo > xStylePSI( xStyle->getPropertySetInfo(), UNO_SET_THROW ); + + // determine the script type associated with the system locale + const LocaleDataWrapper& rSysLocaleData = SvtSysLocale().GetLocaleData(); + const sal_Int16 eSysLocaleScriptType = MsLangId::getScriptType( MsLangId::convertLocaleToLanguage( rSysLocaleData.getLocale() ) ); + + // depending on this script type, use the right property from the document's style which controls the + // default locale for document content + const sal_Char* pCharLocalePropertyName = "CharLocale"; + switch ( eSysLocaleScriptType ) + { + case ScriptType::LATIN: + // already defaulted above + break; + case ScriptType::ASIAN: + pCharLocalePropertyName = "CharLocaleAsian"; + break; + case ScriptType::COMPLEX: + pCharLocalePropertyName = "CharLocaleComplex"; + break; + default: + OSL_ENSURE( false, "lcl_initializeControlFont: unexpected script type for system locale!" ); + break; + } + + ::rtl::OUString sCharLocalePropertyName = ::rtl::OUString::createFromAscii( pCharLocalePropertyName ); + Locale aDocumentCharLocale; + if ( xStylePSI->hasPropertyByName( sCharLocalePropertyName ) ) + { + OSL_VERIFY( xStyle->getPropertyValue( sCharLocalePropertyName ) >>= aDocumentCharLocale ); + } + // fall back to CharLocale property at the style + if ( !aDocumentCharLocale.Language.getLength() ) + { + sCharLocalePropertyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CharLocale" ) ); + if ( xStylePSI->hasPropertyByName( sCharLocalePropertyName ) ) + { + OSL_VERIFY( xStyle->getPropertyValue( sCharLocalePropertyName ) >>= aDocumentCharLocale ); + } + } + // fall back to the system locale + if ( !aDocumentCharLocale.Language.getLength() ) + { + aDocumentCharLocale = rSysLocaleData.getLocale(); + } + + // retrieve a default font for this locale, and set it at the control + Font aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_SANS, MsLangId::convertLocaleToLanguage( aDocumentCharLocale ), DEFAULTFONT_FLAGS_ONLYONE ); + FontDescriptor aFontDesc = VCLUnoHelper::CreateFontDescriptor( aFont ); + _rxModel->setPropertyValue( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "FontDescriptor" ) ), + makeAny( aFontDesc ) + ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + } //==================================================================== //= ControlLayouter //==================================================================== //-------------------------------------------------------------------- + Reference< XPropertySet > ControlLayouter::getDefaultDocumentTextStyle( const Reference< XPropertySet >& _rxModel ) + { + // the style family collection + Reference< XStyleFamiliesSupplier > xSuppStyleFamilies( getTypedModelNode< XStyleFamiliesSupplier >( _rxModel.get() ), UNO_SET_THROW ); + Reference< XNameAccess > xStyleFamilies( xSuppStyleFamilies->getStyleFamilies(), UNO_SET_THROW ); + + // the names of the family, and the style - depends on the document type we live in + ::rtl::OUString sFamilyName, sStyleName; + if ( !lcl_getDocumentDefaultStyleAndFamily( xSuppStyleFamilies.get(), sFamilyName, sStyleName ) ) + throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "unknown document type!" ) ), NULL ); + + // the concrete style + Reference< XNameAccess > xStyleFamily( xStyleFamilies->getByName( sFamilyName ), UNO_QUERY_THROW ); + return Reference< XPropertySet >( xStyleFamily->getByName( sStyleName ), UNO_QUERY_THROW ); + } + + //-------------------------------------------------------------------- void ControlLayouter::initializeControlLayout( const Reference< XPropertySet >& _rxControlModel, DocumentType _eDocType ) { DBG_ASSERT( _rxControlModel.is(), "ControlLayouter::initializeControlLayout: invalid model!" ); @@ -65,10 +232,7 @@ namespace svxform try { - Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo() ); - if ( !xPSI.is() ) - // can't do anything - return; + Reference< XPropertySetInfo > xPSI( _rxControlModel->getPropertySetInfo(), UNO_SET_THROW ); // the control type sal_Int16 nClassId = FormComponentType::CONTROL; @@ -114,6 +278,13 @@ namespace svxform if ( xPSI->hasPropertyByName( FM_PROP_VISUALEFFECT ) ) _rxControlModel->setPropertyValue( FM_PROP_VISUALEFFECT, makeAny( nVisualEffect ) ); } + + // the font (only if we use the document's ref devices for rendering control text, otherwise, the + // default font of VCL controls is assumed to be fine) + if ( useDocumentReferenceDevice( _eDocType ) + && xPSI->hasPropertyByName( FM_PROP_FONT ) + ) + lcl_initializeControlFont( _rxControlModel ); } catch( const Exception& ) { @@ -141,6 +312,18 @@ namespace svxform return bDynamicBorderColor; } + //-------------------------------------------------------------------- + bool ControlLayouter::useDocumentReferenceDevice( DocumentType _eDocType ) + { + if ( _eDocType == eUnknownDocumentType ) + return false; + OConfigurationNode aConfig = getLayoutSettings( _eDocType ); + Any aUseRefDevice = aConfig.getNodeValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseDocumentTextMetrics" ) ) ); + bool bUseRefDevice = false; + OSL_VERIFY( aUseRefDevice >>= bUseRefDevice ); + return bUseRefDevice; + } + //........................................................................ } // namespace svxform //........................................................................ diff --git a/svx/source/form/fmmodel.cxx b/svx/source/form/fmmodel.cxx index 09008ae220b9..a09d0f78173a 100644 --- a/svx/source/form/fmmodel.cxx +++ b/svx/source/form/fmmodel.cxx @@ -30,30 +30,27 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_svx.hxx" + +#include "fmundo.hxx" +#include "fmdocumentclassification.hxx" +#include "fmcontrollayout.hxx" + +#include <svx/fmmodel.hxx> +#include <svx/fmpage.hxx> +#include <svx/svdobj.hxx> #include <tools/debug.hxx> #ifndef SVX_LIGHT -#ifndef _SFX_OBJSH_HXX //autogen #include <sfx2/objsh.hxx> -#endif #else class SfxObjectShell; #endif -#ifndef _FM_FMMODEL_HXX -#include <svx/fmmodel.hxx> -#endif - -#ifndef _FM_PAGE_HXX -#include <svx/fmpage.hxx> -#endif -#include "fmundo.hxx" -#ifndef _SVX_SVDOBJ_HXX -#include <svx/svdobj.hxx> -#endif +#include <boost/optional.hpp> using ::com::sun::star::uno::Reference; using ::com::sun::star::container::XNameContainer; +using namespace svxform; TYPEINIT1(FmFormModel, SdrModel); @@ -62,11 +59,14 @@ struct FmFormModelImplData FmXUndoEnvironment* pUndoEnv; sal_Bool bOpenInDesignIsDefaulted; sal_Bool bMovingPage; + ::boost::optional< sal_Bool > + aControlsUseRefDevice; FmFormModelImplData() :pUndoEnv( NULL ) ,bOpenInDesignIsDefaulted( sal_True ) ,bMovingPage( sal_False ) + ,aControlsUseRefDevice() { } }; @@ -314,6 +314,19 @@ sal_Bool FmFormModel::OpenInDesignModeIsDefaulted( ) #endif //------------------------------------------------------------------------ +sal_Bool FmFormModel::ControlsUseRefDevice() const +{ + if ( !m_pImpl->aControlsUseRefDevice ) + { + DocumentType eDocType = eUnknownDocumentType; + if ( m_pObjShell ) + eDocType = DocumentClassification::classifyHostDocument( m_pObjShell->GetModel() ); + m_pImpl->aControlsUseRefDevice.reset( ControlLayouter::useDocumentReferenceDevice( eDocType ) ); + } + return *m_pImpl->aControlsUseRefDevice; +} + +//------------------------------------------------------------------------ void FmFormModel::SetAutoControlFocus( sal_Bool _bAutoControlFocus ) { #ifndef SVX_LIGHT diff --git a/svx/source/form/fmobj.cxx b/svx/source/form/fmobj.cxx index f2773b7350fa..b5a055730f71 100644 --- a/svx/source/form/fmobj.cxx +++ b/svx/source/form/fmobj.cxx @@ -81,6 +81,10 @@ FmFormObj::FmFormObj(const ::rtl::OUString& rModelName,sal_Int32 _nType) ,m_pLastKnownRefDevice ( NULL ) { DBG_CTOR(FmFormObj, NULL); + + // normally, this is done in SetUnoControlModel, but if the call happened in the base class ctor, + // then our incarnation of it was not called (since we were not constructed at this time). + impl_checkRefDevice_nothrow( true ); } //------------------------------------------------------------------ @@ -124,6 +128,45 @@ void FmFormObj::ClearObjEnv() } //------------------------------------------------------------------ +void FmFormObj::impl_checkRefDevice_nothrow( bool _force ) +{ + const FmFormModel* pFormModel = PTR_CAST( FmFormModel, GetModel() ); + if ( !pFormModel || !pFormModel->ControlsUseRefDevice() ) + return; + + OutputDevice* pCurrentRefDevice = pFormModel ? pFormModel->GetRefDevice() : NULL; + if ( ( m_pLastKnownRefDevice == pCurrentRefDevice ) && !_force ) + return; + + Reference< XControlModel > xControlModel( GetUnoControlModel() ); + if ( !xControlModel.is() ) + return; + + m_pLastKnownRefDevice = pCurrentRefDevice; + if ( m_pLastKnownRefDevice == NULL ) + return; + + try + { + Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY_THROW ); + Reference< XPropertySetInfo > xPropertyInfo( xModelProps->getPropertySetInfo(), UNO_SET_THROW ); + + static const ::rtl::OUString sRefDevicePropName( RTL_CONSTASCII_USTRINGPARAM( "ReferenceDevice" ) ); + if ( xPropertyInfo->hasPropertyByName( sRefDevicePropName ) ) + { + VCLXDevice* pUnoRefDevice = new VCLXDevice; + pUnoRefDevice->SetOutputDevice( m_pLastKnownRefDevice ); + Reference< XDevice > xRefDevice( pUnoRefDevice ); + xModelProps->setPropertyValue( sRefDevicePropName, makeAny( xRefDevice ) ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } +} + +//------------------------------------------------------------------ void FmFormObj::impl_isolateControlModel_nothrow() { try @@ -360,38 +403,10 @@ SdrObject* FmFormObj::Clone() const } //------------------------------------------------------------------ -void FmFormObj::ReformatText() +void FmFormObj::NbcReformatText() { - const FmFormModel* pFormModel = PTR_CAST( FmFormModel, GetModel() ); - OutputDevice* pCurrentRefDevice = pFormModel ? pFormModel->GetRefDevice() : NULL; - - if ( m_pLastKnownRefDevice != pCurrentRefDevice ) - { - m_pLastKnownRefDevice = pCurrentRefDevice; - - try - { - Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY ); - Reference< XPropertySetInfo > xPropertyInfo; - if ( xModelProps.is() ) - xPropertyInfo = xModelProps->getPropertySetInfo(); - - const ::rtl::OUString sRefDevicePropName( RTL_CONSTASCII_USTRINGPARAM( "ReferenceDevice" ) ); - if ( xPropertyInfo.is() && xPropertyInfo->hasPropertyByName( sRefDevicePropName ) ) - { - VCLXDevice* pUnoRefDevice = new VCLXDevice; - pUnoRefDevice->SetOutputDevice( m_pLastKnownRefDevice ); - Reference< XDevice > xRefDevice( pUnoRefDevice ); - xModelProps->setPropertyValue( sRefDevicePropName, makeAny( xRefDevice ) ); - } - } - catch( const Exception& ) - { - OSL_ENSURE( sal_False, "FmFormObj::ReformatText: caught an exception!" ); - } - } - - SdrUnoObj::ReformatText(); + impl_checkRefDevice_nothrow( false ); + SdrUnoObj::NbcReformatText(); } //------------------------------------------------------------------ @@ -564,6 +579,13 @@ Reference< XInterface > FmFormObj::ensureModelEnv(const Reference< XInterface > } //------------------------------------------------------------------ +void FmFormObj::SetModel( SdrModel* _pNewModel ) +{ + SdrUnoObj::SetModel( _pNewModel ); + impl_checkRefDevice_nothrow(); +} + +//------------------------------------------------------------------ FmFormObj* FmFormObj::GetFormObject( SdrObject* _pSdrObject ) { FmFormObj* pFormObject = dynamic_cast< FmFormObj* >( _pSdrObject ); @@ -595,6 +617,8 @@ void FmFormObj::SetUnoControlModel( const Reference< com::sun::star::awt::XContr SdrUnoObj::SetUnoControlModel( _rxModel ); // TODO: call something like formObjectInserted at the form page, to tell it the new model + + impl_checkRefDevice_nothrow( true ); } //------------------------------------------------------------------ diff --git a/svx/source/form/formcontrolfactory.cxx b/svx/source/form/formcontrolfactory.cxx index de1a7d76b526..da3c2634b63c 100644 --- a/svx/source/form/formcontrolfactory.cxx +++ b/svx/source/form/formcontrolfactory.cxx @@ -44,8 +44,6 @@ #include <com/sun/star/form/FormComponentType.hpp> #include <com/sun/star/awt/ScrollBarOrientation.hpp> #include <com/sun/star/form/XGridColumnFactory.hpp> -#include <com/sun/star/lang/XServiceInfo.hpp> -#include <com/sun/star/style/XStyleFamiliesSupplier.hpp> #include <com/sun/star/style/VerticalAlignment.hpp> #include <com/sun/star/awt/LineEndFormat.hpp> #include <com/sun/star/awt/ImageScaleMode.hpp> @@ -53,6 +51,7 @@ #include <com/sun/star/util/XNumberFormatTypes.hpp> #include <com/sun/star/sdbc/ColumnValue.hpp> #include <com/sun/star/text/WritingMode2.hpp> +#include <com/sun/star/awt/FontDescriptor.hpp> /** === end UNO includes === **/ #include <comphelper/componentcontext.hxx> @@ -88,15 +87,16 @@ namespace svxform using ::com::sun::star::beans::PropertyValue; using ::com::sun::star::container::XChild; using ::com::sun::star::form::XGridColumnFactory; - using ::com::sun::star::lang::XServiceInfo; - using ::com::sun::star::style::XStyleFamiliesSupplier; - using ::com::sun::star::container::XNameAccess; using ::com::sun::star::style::VerticalAlignment_MIDDLE; using ::com::sun::star::beans::Property; using ::com::sun::star::uno::TypeClass_DOUBLE; using ::com::sun::star::uno::TypeClass_LONG; using ::com::sun::star::util::XNumberFormats; using ::com::sun::star::util::XNumberFormatTypes; + using ::com::sun::star::awt::FontDescriptor; + using ::com::sun::star::lang::Locale; + using ::com::sun::star::lang::XServiceInfo; + using ::com::sun::star::container::XNameAccess; /** === end UNO using === **/ namespace FormComponentType = ::com::sun::star::form::FormComponentType; namespace ScrollBarOrientation = ::com::sun::star::awt::ScrollBarOrientation; @@ -236,65 +236,6 @@ namespace svxform } return aInfo; } - /* - ATTENTION! - Broken for solaris? It seems that the old used template argument TYPE was already - defined as a macro ... which expand to ... "TYPE "!? - All platforms are OK - excepting Solaris. There the line "template< class TYPE >" - was expanded to "template < class TYPE " where the closing ">" was missing. - */ - #ifdef MYTYPE - #error "Who defines the macro MYTYPE, which is used as template argument here?" - #endif - - //.................................................................... - template< class MYTYPE > - Reference< MYTYPE > getTypedModelNode( const Reference< XInterface >& _rxModelNode ) - { - Reference< MYTYPE > xTypedNode( _rxModelNode, UNO_QUERY ); - if ( xTypedNode.is() ) - return xTypedNode; - else - { - Reference< XChild > xChild( _rxModelNode, UNO_QUERY ); - if ( xChild.is() ) - return getTypedModelNode< MYTYPE >( xChild->getParent() ); - else - return NULL; - } - } - - //.................................................................... - static bool lcl_getDocumentDefaultStyleAndFamily( const Reference< XInterface >& _rxDocument, ::rtl::OUString& _rFamilyName, ::rtl::OUString& _rStyleName ) SAL_THROW(( Exception )) - { - bool bSuccess = true; - Reference< XServiceInfo > xDocumentSI( _rxDocument, UNO_QUERY ); - if ( xDocumentSI.is() ) - { - if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.TextDocument" ) ) ) - || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.text.WebDocument" ) ) ) - ) - { - _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ParagraphStyles" ) ); - _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Standard" ) ); - } - else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.sheet.SpreadsheetDocument" ) ) ) ) - { - _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CellStyles" ) ); - _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ); - } - else if ( xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.DrawingDocument" ) ) ) - || xDocumentSI->supportsService( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.presentation.PresentationDocument" ) ) ) - ) - { - _rFamilyName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "graphics" ) ); - _rStyleName = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ); - } - else - bSuccess = false; - } - return bSuccess; - } //.................................................................... static const sal_Char* aCharacterAndParagraphProperties[] = @@ -430,41 +371,13 @@ namespace svxform //.................................................................... static void lcl_initializeCharacterAttributes( const Reference< XPropertySet >& _rxModel ) { - // need to initialize the attributes from the "Default" style of the document we live in - try { - // the style family collection - Reference< XStyleFamiliesSupplier > xSuppStyleFamilies = getTypedModelNode< XStyleFamiliesSupplier >( _rxModel.get() ); - Reference< XNameAccess > xStyleFamilies; - if ( xSuppStyleFamilies.is() ) - xStyleFamilies = xSuppStyleFamilies->getStyleFamilies(); - OSL_ENSURE( xStyleFamilies.is(), "lcl_initializeCharacterAttributes: could not obtain the style families!" ); - if ( !xStyleFamilies.is() ) - return; - - // the names of the family, and the style - depends on the document type we live in - ::rtl::OUString sFamilyName, sStyleName; - bool bKnownDocumentType = lcl_getDocumentDefaultStyleAndFamily( xSuppStyleFamilies.get(), sFamilyName, sStyleName ); - OSL_ENSURE( bKnownDocumentType, "lcl_initializeCharacterAttributes: Huh? What document type is this?" ); - if ( !bKnownDocumentType ) - return; - - // the concrete style - Reference< XNameAccess > xStyleFamily( xStyleFamilies->getByName( sFamilyName ), UNO_QUERY ); - Reference< XPropertySet > xStyle; - if ( xStyleFamily.is() ) - xStyleFamily->getByName( sStyleName ) >>= xStyle; - OSL_ENSURE( xStyle.is(), "lcl_initializeCharacterAttributes: could not retrieve the style!" ); - if ( !xStyle.is() ) - return; - - // transfer all properties which are described by the com.sun.star.style. - Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo() ); - Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo() ); - OSL_ENSURE( xSourcePropInfo.is() && xDestPropInfo.is(), "lcl_initializeCharacterAttributes: no property set info!" ); - if ( !xSourcePropInfo.is() || !xDestPropInfo.is() ) - return; + Reference< XPropertySet > xStyle( ControlLayouter::getDefaultDocumentTextStyle( _rxModel ), UNO_SET_THROW ); + + // transfer all properties which are described by the style + Reference< XPropertySetInfo > xSourcePropInfo( xStyle->getPropertySetInfo(), UNO_SET_THROW ); + Reference< XPropertySetInfo > xDestPropInfo( _rxModel->getPropertySetInfo(), UNO_SET_THROW ); ::rtl::OUString sPropertyName; const sal_Char** pCharacterProperty = aCharacterAndParagraphProperties; diff --git a/svx/source/inc/fmcontrollayout.hxx b/svx/source/inc/fmcontrollayout.hxx index 1110c274b9f8..c5abe43f3228 100644 --- a/svx/source/inc/fmcontrollayout.hxx +++ b/svx/source/inc/fmcontrollayout.hxx @@ -62,6 +62,22 @@ namespace svxform */ static bool useDynamicBorderColor( DocumentType _eDocType ); + /** determines whether for the given document type, form controls should use the document's reference device + for text rendering + */ + static bool useDocumentReferenceDevice( DocumentType _eDocType ); + + /** gets the "default" style in a document which can be used if some default text format is needed + + It depends on the type document type which concrete kind of style is returned, but it is expected to support + the css.style.CharacterProperties service. + + @param _rxModel + a form component. + */ + static ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > + getDefaultDocumentTextStyle( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& _rxModel ); + private: ControlLayouter(); // never implemented diff --git a/svx/source/inc/fmobj.hxx b/svx/source/inc/fmobj.hxx index 4099f241b72a..25f792ed7417 100644 --- a/svx/source/inc/fmobj.hxx +++ b/svx/source/inc/fmobj.hxx @@ -86,12 +86,14 @@ public: virtual sal_uInt32 GetObjInventor() const; virtual sal_uInt16 GetObjIdentifier() const; - virtual void ReformatText(); + virtual void NbcReformatText(); virtual SdrObject* Clone() const; // #116235# virtual SdrObject* Clone(SdrPage* pPage, SdrModel* pModel) const; virtual void operator= (const SdrObject& rObj); + virtual void SetModel(SdrModel* pNewModel); + virtual void clonedFrom(const FmFormObj* _pSource); static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface> ensureModelEnv(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface>& _rSourceContainer, const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer> _rTopLevelDestContainer); @@ -124,6 +126,10 @@ private: its parent. */ void impl_isolateControlModel_nothrow(); + + /** forwards the reference device of our SdrModel to the control model + */ + void impl_checkRefDevice_nothrow( bool _force = false ); }; |