diff options
author | Vitaliy Anderson <vanderson@smartru.com> | 2017-01-19 02:09:04 -0800 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-01-27 07:35:47 +0000 |
commit | 91ccb4dbf7cbe7e684c7a8183863e597d7205e57 (patch) | |
tree | 6e6a942e91e2c12fe30a9a7222324493ba9a75e3 /include/unotools/compatibility.hxx | |
parent | 78f5923e7cec0f6a0b3dbcbe29bad1980593454c (diff) |
Compatibility options refactoring. Part 1
It relate to reduce the nubmer of copy-paste the same code
and simplify adding compability options.
Also using enum class instead enum can eliminate to occurrence
an error relate to access to out of range an array.
Change-Id: I07b862aac5f88da4a98e2273cb14daa09e70eacb
Reviewed-on: https://gerrit.libreoffice.org/33543
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include/unotools/compatibility.hxx')
-rw-r--r-- | include/unotools/compatibility.hxx | 243 |
1 files changed, 152 insertions, 91 deletions
diff --git a/include/unotools/compatibility.hxx b/include/unotools/compatibility.hxx index 551627b251a1..8d18092b3bd9 100644 --- a/include/unotools/compatibility.hxx +++ b/include/unotools/compatibility.hxx @@ -19,54 +19,152 @@ #ifndef INCLUDED_UNOTOOLS_COMPATIBILITY_HXX #define INCLUDED_UNOTOOLS_COMPATIBILITY_HXX -#include <unotools/unotoolsdllapi.h> #include <sal/types.h> #include <osl/mutex.hxx> #include <com/sun/star/uno/Sequence.h> #include <com/sun/star/beans/PropertyValue.hpp> #include <unotools/options.hxx> +#include <unotools/unotoolsdllapi.h> +#include <rtl/ustring.hxx> #include <memory> -enum CompatibilityOptions -{ - COPT_USE_PRINTERDEVICE = 0, - COPT_ADD_SPACING, - COPT_ADD_SPACING_AT_PAGES, - COPT_USE_OUR_TABSTOPS, - COPT_NO_EXTLEADING, - COPT_USE_LINESPACING, - COPT_ADD_TABLESPACING, - COPT_USE_OBJECTPOSITIONING, - COPT_USE_OUR_TEXTWRAPPING, - COPT_CONSIDER_WRAPPINGSTYLE, - COPT_EXPAND_WORDSPACE, - COPT_PROTECT_FORM, - COPT_MS_WORD_COMP_TRAILING_BLANKS -}; - /*-************************************************************************************************************ - @descr The method GetList() returns a list of property values. - Use follow defines to separate values by names. + @descr Struct to hold information about one compatibility entry *//*-*************************************************************************************************************/ -#define COMPATIBILITY_PROPERTYNAME_NAME "Name" -#define COMPATIBILITY_PROPERTYNAME_MODULE "Module" -#define COMPATIBILITY_PROPERTYNAME_USEPRTMETRICS "UsePrinterMetrics" -#define COMPATIBILITY_PROPERTYNAME_ADDSPACING "AddSpacing" -#define COMPATIBILITY_PROPERTYNAME_ADDSPACINGATPAGES "AddSpacingAtPages" -#define COMPATIBILITY_PROPERTYNAME_USEOURTABSTOPS "UseOurTabStopFormat" -#define COMPATIBILITY_PROPERTYNAME_NOEXTLEADING "NoExternalLeading" -#define COMPATIBILITY_PROPERTYNAME_USELINESPACING "UseLineSpacing" -#define COMPATIBILITY_PROPERTYNAME_ADDTABLESPACING "AddTableSpacing" -#define COMPATIBILITY_PROPERTYNAME_USEOBJECTPOSITIONING "UseObjectPositioning" -#define COMPATIBILITY_PROPERTYNAME_USEOURTEXTWRAPPING "UseOurTextWrapping" -#define COMPATIBILITY_PROPERTYNAME_CONSIDERWRAPPINGSTYLE "ConsiderWrappingStyle" -#define COMPATIBILITY_PROPERTYNAME_EXPANDWORDSPACE "ExpandWordSpace" -#define COMPATIBILITY_PROPERTYNAME_PROTECTFORM "ProtectForm" -#define COMPATIBILITY_PROPERTYNAME_MSWORDTRAILINGBLANKS "MsWordCompTrailingBlanks" - -#define COMPATIBILITY_DEFAULT_NAME "_default" - -// forward declarations +class UNOTOOLS_DLLPUBLIC SvtCompatibilityEntry +{ + public: + /*-************************************************************************************************************ + @descr The method SvtCompatibilityOptions::GetList() returns a list of property values. + Use follow enum class to separate values by names. + Sync it with sPropertyName in SvtCompatibilityEntry::getName() + *//*-*************************************************************************************************************/ + enum class Index + { + /* Should be in the start. Do not remove it. */ + Name, + Module, + + /* Editable list of compatibility options. */ + UsePrtMetrics, + AddSpacing, + AddSpacingAtPages, + UseOurTabStops, + NoExtLeading, + UseLineSpacing, + AddTableSpacing, + UseObjectPositioning, + UseOurTextWrapping, + ConsiderWrappingStyle, + ExpandWordSpace, + ProtectForm, + MsWordTrailingBlanks, + + /* Should be at the end. Do not remove it. */ + INVALID + }; + + SvtCompatibilityEntry(); + ~SvtCompatibilityEntry(); + + static OUString getName( const Index rIdx ); + + static inline OUString getUserEntryName() + { + return OUString( "_user" ); + } + + static inline OUString getDefaultEntryName() + { + return OUString( "_default" ); + } + + static inline Index getIndex( const OUString& rName ) + { + for ( int i = static_cast<int>(Index::Name); i < static_cast<int>(Index::INVALID); ++i ) + if ( getName( Index(i) ) == rName ) + return Index(i); + + /* SvtCompatibilityEntry::getIndex() Undeclared compatibility property name */ + assert(false); + + return Index::INVALID; + } + + static inline size_t getElementCount() + { + return static_cast<size_t>(Index::INVALID); + } + + inline css::uno::Any getValue( const Index rIdx ) const + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + return m_aPropertyValue[ static_cast<int>(rIdx) ]; + } else + { + /* Wrong index. */ + assert( false ); + return css::uno::Any(); + } + } + + template<typename T> + inline T getValue( const Index rIdx ) const + { + T aValue = T(); + + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] >>= aValue; + } else + { + /* Wrong index. */ + assert( false ); + } + + return aValue; + } + + inline void setValue( const Index rIdx, css::uno::Any& rValue ) + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] = rValue; + } else + { + /* Wrong index. */ + assert( false ); + } + } + + template<typename T> + inline void setValue( const Index rIdx, T rValue ) + { + if ( static_cast<size_t>(rIdx) < getElementCount() ) + { + m_aPropertyValue[ static_cast<int>(rIdx) ] = css::uno::Any(rValue); + } else + { + /* Wrong index. */ + assert( false ); + } + } + + inline bool isDefaultEntry() const + { + return m_bDefaultEntry; + } + + inline void setDefaultEntry( bool rValue ) + { + m_bDefaultEntry = rValue; + } + + private: + std::vector<css::uno::Any> m_aPropertyValue; + bool m_bDefaultEntry; +}; /*-************************************************************************************************************ @short forward declaration to our private date container implementation @@ -74,7 +172,6 @@ enum CompatibilityOptions You can create the container if it is necessary. The class which use these mechanism is faster and smaller then a complete implementation! *//*-*************************************************************************************************************/ - class SvtCompatibilityOptions_Impl; /*-************************************************************************************************************ @@ -82,23 +179,30 @@ class SvtCompatibilityOptions_Impl; @descr Make it possible to configure dynamic menu structures of menus like "new" or "wizard". @devstatus ready to use *//*-*************************************************************************************************************/ - class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options { public: - SvtCompatibilityOptions(); + SvtCompatibilityOptions(); virtual ~SvtCompatibilityOptions() override; - // interface + /*-**************************************************************************************************** + @short append a new item + @descr + + @seealso method Clear() + + @param "aItem" SvtCompatibilityEntry + *//*-*****************************************************************************************************/ + void AppendItem( const SvtCompatibilityEntry& aItem ); /*-**************************************************************************************************** @short clear complete specified list @descr Call this methods to clear the whole list. *//*-*****************************************************************************************************/ - void Clear(); - void SetDefault( const OUString & sName, bool bValue ); + void SetDefault( SvtCompatibilityEntry::Index rIdx, bool rValue ); + bool GetDefault( SvtCompatibilityEntry::Index rIdx ) const; /*-**************************************************************************************************** @short return complete specified list @@ -108,49 +212,10 @@ class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options @onerror We return an empty list. *//*-*****************************************************************************************************/ - css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > GetList() const; - /*-**************************************************************************************************** - @short append a new item - @descr - - @seealso method Clear() - - @param "sName" Name - @param "sModule" Module - *//*-*****************************************************************************************************/ - - void AppendItem( const OUString& sName, - const OUString& sModule, - bool bUsePrtMetrics, - bool bAddSpacing, - bool bAddSpacingAtPages, - bool bUseOurTabStops, - bool bNoExtLeading, - bool bUseLineSpacing, - bool bAddTableSpacing, - bool bUseObjectPositioning, - bool bUseOurTextWrapping, - bool bConsiderWrappingStyle, - bool bExpandWordSpace, - bool bProtectForm, - bool bMsWordCompTrailingBlanks ); - - bool IsUsePrtDevice() const; - bool IsAddSpacing() const; - bool IsAddSpacingAtPages() const; - bool IsUseOurTabStops() const; - bool IsNoExtLeading() const; - bool IsUseLineSpacing() const; - bool IsAddTableSpacing() const; - bool IsUseObjectPositioning() const; - bool IsUseOurTextWrapping() const; - bool IsConsiderWrappingStyle() const; - bool IsExpandWordSpace() const; - bool IsMsWordCompTrailingBlanks() const; - private: + std::shared_ptr<SvtCompatibilityOptions_Impl> m_pImpl; /*-**************************************************************************************************** @short return a reference to a static mutex @@ -159,12 +224,8 @@ class UNOTOOLS_DLLPUBLIC SvtCompatibilityOptions: public utl::detail::Options We create a static mutex only for one ime and use at different times. @return A reference to a static mutex member. *//*-*****************************************************************************************************/ - - UNOTOOLS_DLLPRIVATE static ::osl::Mutex& GetOwnStaticMutex(); - - std::shared_ptr<SvtCompatibilityOptions_Impl> m_pImpl; - -}; // class SvtCompatibilityOptions + UNOTOOLS_DLLPRIVATE static osl::Mutex& GetOwnStaticMutex(); +}; #endif // INCLUDED_UNOTOOLS_COMPATIBILITY_HXX |