Kaydet (Commit) 45a6fdad authored tarafından Jakub Trzebiatowski's avatar Jakub Trzebiatowski Kaydeden (comit) Miklos Vajna

sw UNO Cell Style family, SwXTextCellStyle

Cell Family :: getByName
Cell Family :: getElementNames
Cell Family :: getCount

Change-Id: I37d567ee284054f847c704d9fce370d174a0c48c
Reviewed-on: https://gerrit.libreoffice.org/25896Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst 93490816
......@@ -38,6 +38,7 @@ enum class SfxStyleFamily {
Page = 0x08,
Pseudo = 0x10,
Table = 0x20,
Cell = 0x40,
All = 0x7fff
};
......
......@@ -32,6 +32,7 @@ namespace nsSwGetPoolIdFromName
const SwGetPoolIdFromName GET_POOLID_PAGEDESC = 0x08;
const SwGetPoolIdFromName GET_POOLID_NUMRULE = 0x10;
const SwGetPoolIdFromName GET_POOLID_TABSTYLE = 0x20;
const SwGetPoolIdFromName GET_POOLID_CELLSTYLE= 0x40;
}
#endif
......
......@@ -94,6 +94,7 @@ protected:
*m_pPageDescUINameArray,
*m_pNumRuleUINameArray,
*m_pTableStyleUINameArray,
*m_pCellStyleUINameArray,
// Programmatic Name tables
*m_pTextProgNameArray,
*m_pListsProgNameArray,
......@@ -106,7 +107,8 @@ protected:
*m_pHTMLChrFormatProgNameArray,
*m_pPageDescProgNameArray,
*m_pNumRuleProgNameArray,
*m_pTableStyleProgNameArray;
*m_pTableStyleProgNameArray,
*m_pCellStyleProgNameArray;
static NameToIdHash *m_pParaUIMap,
*m_pCharUIMap,
......@@ -114,13 +116,15 @@ protected:
*m_pFrameUIMap,
*m_pNumRuleUIMap,
*m_pTableStyleUIMap,
*m_pCellStyleUIMap,
*m_pParaProgMap,
*m_pCharProgMap,
*m_pPageProgMap,
*m_pFrameProgMap,
*m_pNumRuleProgMap,
*m_pTableStyleProgMap;
*m_pTableStyleProgMap,
*m_pCellStyleProgMap;
static void fillNameFromId(sal_uInt16 nId, OUString &rName, bool bProgName);
static const OUString& getNameFromId(sal_uInt16 nId, const OUString &rName,
......@@ -181,6 +185,7 @@ public:
static const ::std::vector<OUString>& GetPageDescUINameArray();
static const ::std::vector<OUString>& GetNumRuleUINameArray();
static const ::std::vector<OUString>& GetTableStyleUINameArray();
static const ::std::vector<OUString>& GetCellStyleUINameArray();
static const ::std::vector<OUString>& GetTextProgNameArray();
static const ::std::vector<OUString>& GetListsProgNameArray();
......@@ -194,6 +199,7 @@ public:
static const ::std::vector<OUString>& GetPageDescProgNameArray();
static const ::std::vector<OUString>& GetNumRuleProgNameArray();
static const ::std::vector<OUString>& GetTableStyleProgNameArray();
static const ::std::vector<OUString>& GetCellStyleProgNameArray();
};
#endif // _NAME_MAPPER_HXX
......
......@@ -37,6 +37,7 @@ class SwTextFormatColl;
class SwFrameFormat;
class SwNumRule;
class SwTableAutoFormat;
class SwBoxAutoFormat;
// Temporary StyleSheet.
class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
......@@ -50,6 +51,7 @@ class SW_DLLPUBLIC SwDocStyleSheet : public SfxStyleSheetBase
const SwPageDesc* pDesc;
const SwNumRule* pNumRule;
const SwTableAutoFormat* pTableFormat;
const SwBoxAutoFormat* pBoxFormat;
SwDoc& rDoc;
SfxItemSet aCoreSet;
......
......@@ -78,6 +78,7 @@ const sal_uInt16 POOLGRP_FRAMEFMT = (1 << 11) + POOLGRP_NOCOLLID;
const sal_uInt16 POOLGRP_PAGEDESC = (2 << 11) + POOLGRP_NOCOLLID;
const sal_uInt16 POOLGRP_NUMRULE = (3 << 11) + POOLGRP_NOCOLLID;
const sal_uInt16 POOLGRP_TABSTYLE = (4 << 11) + POOLGRP_NOCOLLID;
const sal_uInt16 POOLGRP_CELLSTYLE = (5 << 11) + POOLGRP_NOCOLLID;
/// Recognize whether it's a user defined style or not:
const sal_uInt16 POOL_IDUSER_FMT =
......@@ -222,6 +223,12 @@ RES_POOLTABLESTYLE_YELLOW,
RES_POOLTABSTYLE_END
};
enum RES_POOL_CELLSTYLE_TYPE
{
RES_POOLCELLSTYLE_BEGIN = POOLGRP_CELLSTYLE,
RES_POOLCELLSTYLE_END = RES_POOLCELLSTYLE_BEGIN
};
// IDs for paragraph styles.
enum RES_POOL_COLLFMT_TYPE
{
......
......@@ -110,6 +110,8 @@ class SwBoxAutoFormat
OUString m_sNumFormatString;
LanguageType m_eSysLanguage, m_eNumFormatLanguage;
css::uno::WeakReference<css::uno::XInterface> m_wXObject;
public:
SwBoxAutoFormat();
SwBoxAutoFormat( const SwBoxAutoFormat& rNew );
......@@ -176,6 +178,11 @@ public:
void SetValueFormat( const OUString& rFormat, LanguageType eLng, LanguageType eSys )
{ m_sNumFormatString = rFormat; m_eNumFormatLanguage = eLng; m_eSysLanguage = eSys; }
css::uno::WeakReference<css::uno::XInterface> const& GetXObject() const
{ return m_wXObject; }
void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
{ m_wXObject = xObject; }
bool Load( SvStream& rStream, const SwAfVersions& rVersions, sal_uInt16 nVer );
bool Save( SvStream& rStream, sal_uInt16 fileVersion ) const;
bool SaveVersionNo( SvStream& rStream, sal_uInt16 fileVersion ) const;
......@@ -300,6 +307,11 @@ public:
{ return m_wXObject; }
void SetXObject(css::uno::Reference<css::uno::XInterface> const& xObject)
{ m_wXObject = xObject; }
/// Returns the cell's name postfix. eg. ".1"
OUString GetTableTemplateCellSubName(const SwBoxAutoFormat& rBoxFormat) const;
/// Returns a vector of indexes in aBoxAutoFormat array. Returned indexes points to cells which are mapped to a table-template.
static const std::vector<sal_Int32>& GetTableTemplateMap();
};
class SW_DLLPUBLIC SwTableAutoFormatTable
......
......@@ -30,8 +30,9 @@
#define STR_STYLE_FAMILY_PAGE (RC_UNOCORE_BEGIN + 6)
#define STR_STYLE_FAMILY_NUMBERING (RC_UNOCORE_BEGIN + 7)
#define STR_STYLE_FAMILY_TABLE (RC_UNOCORE_BEGIN + 8)
#define STR_STYLE_FAMILY_CELL (RC_UNOCORE_BEGIN + 9)
#define UNOCORE_ACT_END STR_STYLE_FAMILY_TABLE
#define UNOCORE_ACT_END STR_STYLE_FAMILY_CELL
#if UNOCORE_ACT_END > RC_UNOCORE_END
#error Resource-Id Ueberlauf in #file, #line
......
......@@ -312,12 +312,15 @@ class SwBoxAutoFormat;
class SwXTextCellStyle : public cppu::WeakImplHelper
<
css::style::XStyle,
css::beans::XPropertySet
css::beans::XPropertySet,
css::lang::XServiceInfo
>
{
SwDocShell* m_pDocShell;
SwBoxAutoFormat& m_rBoxAutoFormat;
OUString m_sParentStyle;
public:
SwXTextCellStyle(SwBoxAutoFormat& rBoxAutoFormat);
SwXTextCellStyle(SwDocShell* pDocShell, SwBoxAutoFormat& rBoxAutoFormat, const OUString& sParentStyle);
//XStyle
virtual sal_Bool SAL_CALL isUserDefined() throw (css::uno::RuntimeException, std::exception) override;
......@@ -338,6 +341,12 @@ public:
virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName, const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) throw(css::beans::UnknownPropertyException, css::lang::WrappedTargetException, css::uno::RuntimeException, std::exception) override;
//XServiceInfo
virtual OUString SAL_CALL getImplementationName() throw(css::uno::RuntimeException, std::exception) override;
virtual sal_Bool SAL_CALL supportsService(const OUString& rServiceName) throw(css::uno::RuntimeException, std::exception) override;
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw(css::uno::RuntimeException, std::exception) override;
static css::uno::Reference<css::style::XStyle> CreateXTextCellStyle(SwDocShell* pDocShell, const OUString& sName);
};
#endif
......
......@@ -39,11 +39,11 @@ class CheckStyle(unittest.TestCase):
self.assertFalse(xStyleFamilies.supportsService("foobarbaz"))
self.assertTrue(xStyleFamilies.hasElements())
self.assertRegex(str(xStyleFamilies.ElementType), "com\.sun\.star\.container\.XNameContainer")
self.assertEqual(len(xStyleFamilies.ElementNames), 6)
self.assertEqual(len(xStyleFamilies.ElementNames), 7)
for sFamilyname in xStyleFamilies.ElementNames:
self.assertIn(sFamilyname,
["CharacterStyles", "ParagraphStyles", "PageStyles", "FrameStyles", "NumberingStyles", "TableStyles"])
["CharacterStyles", "ParagraphStyles", "PageStyles", "FrameStyles", "NumberingStyles", "TableStyles", "CellStyles"])
with self.assertRaises(NoSuchElementException):
xStyleFamilies.getByName("foobarbaz")
......@@ -183,6 +183,14 @@ class CheckStyle(unittest.TestCase):
xCellStyle.getPropertyValue("foobarbaz")
xDoc.dispose()
def test_CellFamily(self):
xDoc = CheckStyle._uno.openEmptyWriterDoc()
xCellStyles = xDoc.StyleFamilies["CellStyles"]
vEmptyDocStyles = ['Default Style.1', 'Default Style.2', 'Default Style.3', 'Default Style.4', 'Default Style.5', 'Default Style.6', 'Default Style.7', 'Default Style.8', 'Default Style.9', 'Default Style.10']
self.__test_StyleFamily(xCellStyles, vEmptyDocStyles, "SwXTextCellStyle")
#possibly more depth tests could be added, to test properties of a cell style... yet to come
xDoc.dispose()
if __name__ == '__main__':
unittest.main()
......
......@@ -43,6 +43,7 @@ extern ResMgr* pSwResMgr;
*SwStyleNameMapper::m_pPageDescUINameArray = nullptr,
*SwStyleNameMapper::m_pNumRuleUINameArray = nullptr,
*SwStyleNameMapper::m_pTableStyleUINameArray = nullptr,
*SwStyleNameMapper::m_pCellStyleUINameArray = nullptr,
// Initialise programmatic names to 0
*SwStyleNameMapper::m_pTextProgNameArray = nullptr,
......@@ -56,7 +57,8 @@ extern ResMgr* pSwResMgr;
*SwStyleNameMapper::m_pHTMLChrFormatProgNameArray = nullptr,
*SwStyleNameMapper::m_pPageDescProgNameArray = nullptr,
*SwStyleNameMapper::m_pNumRuleProgNameArray = nullptr,
*SwStyleNameMapper::m_pTableStyleProgNameArray = nullptr;
*SwStyleNameMapper::m_pTableStyleProgNameArray = nullptr,
*SwStyleNameMapper::m_pCellStyleProgNameArray = nullptr;
NameToIdHash *SwStyleNameMapper::m_pParaUIMap = nullptr,
*SwStyleNameMapper::m_pCharUIMap = nullptr,
......@@ -64,13 +66,15 @@ NameToIdHash *SwStyleNameMapper::m_pParaUIMap = nullptr,
*SwStyleNameMapper::m_pFrameUIMap = nullptr,
*SwStyleNameMapper::m_pNumRuleUIMap = nullptr,
*SwStyleNameMapper::m_pTableStyleUIMap = nullptr,
*SwStyleNameMapper::m_pCellStyleUIMap = nullptr,
*SwStyleNameMapper::m_pParaProgMap = nullptr,
*SwStyleNameMapper::m_pCharProgMap = nullptr,
*SwStyleNameMapper::m_pPageProgMap = nullptr,
*SwStyleNameMapper::m_pFrameProgMap = nullptr,
*SwStyleNameMapper::m_pNumRuleProgMap = nullptr,
*SwStyleNameMapper::m_pTableStyleProgMap = nullptr;
*SwStyleNameMapper::m_pTableStyleProgMap = nullptr,
*SwStyleNameMapper::m_pCellStyleProgMap = nullptr;
// SwTableEntry so we can pass the length to the String CTOR
struct SwTableEntry
......@@ -498,6 +502,12 @@ const NameToIdHash & SwStyleNameMapper::getHashTable ( SwGetPoolIdFromName eFlag
vIndexes.push_back( std::make_tuple(RES_POOLTABSTYLE_BEGIN, RES_POOLTABSTYLE_END, bProgName ? &GetTableStyleProgNameArray : &GetTableStyleUINameArray) );
}
break;
case nsSwGetPoolIdFromName::GET_POOLID_CELLSTYLE:
{
pHashPointer = bProgName ? &m_pCellStyleProgMap : &m_pCellStyleUIMap;
vIndexes.push_back( std::make_tuple(RES_POOLCELLSTYLE_BEGIN, RES_POOLCELLSTYLE_END, bProgName ? &GetCellStyleProgNameArray : &GetCellStyleUINameArray) );
}
break;
default:
assert(false && "unknown pool family");
}
......@@ -855,6 +865,14 @@ const ::std::vector<OUString>& SwStyleNameMapper::GetTableStyleUINameArray()
return *m_pTableStyleUINameArray;
}
/// retuns an empty array because Cell Names aren't translated
const ::std::vector<OUString>& SwStyleNameMapper::GetCellStyleUINameArray()
{
if (!m_pCellStyleUINameArray)
m_pCellStyleUINameArray = new std::vector<OUString>();
return *m_pCellStyleUINameArray;
}
const ::std::vector<OUString>& SwStyleNameMapper::GetTextProgNameArray()
{
if (!m_pTextProgNameArray)
......@@ -951,6 +969,14 @@ const ::std::vector<OUString>& SwStyleNameMapper::GetTableStyleProgNameArray()
return *m_pTableStyleProgNameArray;
}
/// retuns an empty array because Cell Names aren't translated
const ::std::vector<OUString>& SwStyleNameMapper::GetCellStyleProgNameArray()
{
if (!m_pCellStyleProgNameArray)
m_pCellStyleProgNameArray = new std::vector<OUString>();
return *m_pCellStyleProgNameArray;
}
const OUString
SwStyleNameMapper::GetSpecialExtraProgName(const OUString& rExtraUIName)
{
......
......@@ -1029,6 +1029,47 @@ bool SwTableAutoFormat::Save( SvStream& rStream, sal_uInt16 fileVersion ) const
return bRet;
}
OUString SwTableAutoFormat::GetTableTemplateCellSubName(const SwBoxAutoFormat& rBoxFormat) const
{
sal_Int32 nIndex = 0;
for (; nIndex < 16; ++nIndex)
if (aBoxAutoFormat[nIndex] == &rBoxFormat) break;
// box format doesn't belong to this table format
if (16 <= nIndex)
return OUString();
const std::vector<sal_Int32> aTableTemplateMap = GetTableTemplateMap();
for (size_t i=0; i < aTableTemplateMap.size(); ++i)
{
if (aTableTemplateMap[i] == nIndex)
return "." + OUString::number(i + 1);
}
// box format doesn't belong to a table template
return OUString();
}
const std::vector<sal_Int32>& SwTableAutoFormat::GetTableTemplateMap()
{
static std::vector<sal_Int32>* pTableTemplateMap;
if (!pTableTemplateMap)
{
pTableTemplateMap = new std::vector<sal_Int32>;
pTableTemplateMap->push_back(0); // FIRST_ROW
pTableTemplateMap->push_back(1); // LAST_ROW
pTableTemplateMap->push_back(2); // FIRST_COLUMN
pTableTemplateMap->push_back(3); // LAST_COLUMN
pTableTemplateMap->push_back(4); // EVEN_ROWS
pTableTemplateMap->push_back(5); // ODD_ROWS
pTableTemplateMap->push_back(6); // EVEN_COLUMNS
pTableTemplateMap->push_back(7); // ODD_COLUMNS
pTableTemplateMap->push_back(8); // BODY
pTableTemplateMap->push_back(9); // BACKGROUND
}
return *pTableTemplateMap;
}
struct SwTableAutoFormatTable::Impl
{
std::vector<std::unique_ptr<SwTableAutoFormat>> m_AutoFormats;
......
......@@ -59,4 +59,9 @@ String STR_STYLE_FAMILY_TABLE
Text [ en-US ] = "Table" ;
};
String STR_STYLE_FAMILY_CELL
{
Text [ en-US ] = "Cell" ;
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -77,6 +77,7 @@
#define cPAGE (sal_Unicode)'g'
#define cNUMRULE (sal_Unicode)'n'
#define cTABSTYLE (sal_Unicode)'t'
#define cCELLSTYLE (sal_Unicode)'b'
using namespace com::sun::star;
......@@ -320,6 +321,40 @@ static const SwTableAutoFormat* lcl_FindTableStyle(SwDoc& rDoc, const OUString&
return pFormat;
}
static const SwBoxAutoFormat* lcl_FindCellStyle(SwDoc& rDoc, const OUString& rName, SwDocStyleSheet *pStyle = nullptr)
{
const SwBoxAutoFormat* pFormat = nullptr;
auto aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
for (size_t i=0; i < rTableStyles.size() && !pFormat; ++i)
{
const SwTableAutoFormat& rTableStyle = rTableStyles[i];
for (size_t nBoxFormat=0; nBoxFormat < aTableTemplateMap.size() && !pFormat; ++nBoxFormat)
{
const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat];
const SwBoxAutoFormat& rBoxFormat = rTableStyle.GetBoxFormat(nBoxIndex);
OUString sBoxFormatName;
SwStyleNameMapper::FillProgName(rTableStyle.GetName(), sBoxFormatName, nsSwGetPoolIdFromName::GET_POOLID_CELLSTYLE, true);
sBoxFormatName += rTableStyle.GetTableTemplateCellSubName(rBoxFormat);
if (rName == sBoxFormatName)
pFormat = &rBoxFormat;
}
}
if(pStyle)
{
if(pFormat)
{
pStyle->SetPhysical(true);
pStyle->PresetParent(OUString());
}
else
pStyle->SetPhysical(false);
}
return pFormat;
}
sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
const OUString &rName)
{
......@@ -346,6 +381,9 @@ sal_uInt32 SwStyleSheetIterator::SwPoolFormatList::FindName(SfxStyleFamily eFam,
case SfxStyleFamily::Table:
cStyle = cTABSTYLE;
break;
case SfxStyleFamily::Cell:
cStyle = cCELLSTYLE;
break;
default:
cStyle = ' ';
break;
......@@ -1945,6 +1983,11 @@ bool SwDocStyleSheet::FillStyleSheet(
pTableFormat = lcl_FindTableStyle(rDoc, aName, this);
bRet = bPhysical = (nullptr != pTableFormat);
break;
case SfxStyleFamily::Cell:
pBoxFormat = lcl_FindCellStyle(rDoc, aName, this);
bRet = bPhysical = (nullptr != pBoxFormat);
break;
default:; //prevent warning
}
......@@ -2529,6 +2572,9 @@ SfxStyleSheetBase* SwDocStyleSheetPool::Find( const OUString& rName,
}
break;
case SfxStyleFamily::Table:
case SfxStyleFamily::Cell:
break;
default:
OSL_ENSURE(false, "unknown style family");
}
......@@ -2941,6 +2987,26 @@ SfxStyleSheetBase* SwStyleSheetIterator::First()
}
}
if( nSearchFamily == SfxStyleFamily::Cell ||
nSearchFamily == SfxStyleFamily::All )
{
const std::vector<sal_Int32> aTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
const SwTableAutoFormatTable& rTableStyles = rDoc.GetTableStyles();
for(size_t i = 0; i < rTableStyles.size(); ++i)
{
const SwTableAutoFormat& rTableStyle = rTableStyles[i];
for(size_t nBoxFormat = 0; nBoxFormat < aTableTemplateMap.size(); ++nBoxFormat)
{
const sal_uInt32 nBoxIndex = aTableTemplateMap[nBoxFormat];
const SwBoxAutoFormat& rBoxFormat = rTableStyle.GetBoxFormat(nBoxIndex);
OUString sBoxFormatName;
SwStyleNameMapper::FillProgName(rTableStyle.GetName(), sBoxFormatName, nsSwGetPoolIdFromName::GET_POOLID_CELLSTYLE, true);
sBoxFormatName += rTableStyle.GetTableTemplateCellSubName(rBoxFormat);
aLst.Append( cCELLSTYLE, sBoxFormatName );
}
}
}
if(!aLst.empty())
{
nLastPos = SAL_MAX_UINT32;
......
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