25#include <tools/datetime.hxx>
33#include <com/sun/star/style/XStyle.hpp>
34#include <com/sun/star/beans/XPropertySet.hpp>
35#include <com/sun/star/container/XNameContainer.hpp>
82 o_pNumberedParagraphContext =
93 "internal error: SetListItem: mListStack has no ListBlock");
95 "error: SetListItem: list item already exists");
104 const OUString& sListStyleName,
105 const OUString& sContinueListId,
106 const OUString& sListStyleDefaultListId )
111 "<XMLTextListsHelper::KeepListAsProcessed(..)> - list id already added" );
120 ::std::pair< OUString, OUString >
121 aListData( sListStyleName, sContinueListId );
122 (*mpProcessedLists)[ sListId ] = aListData;
132 (*mpStyleNameLastListIds)[sListStyleName] = sListId;
135 if ( sListStyleDefaultListId.isEmpty())
146 ::std::pair< OUString, OUString >
147 aListIdMapData( sListId, sListStyleDefaultListId );
148 (*mpMapListIdToListStyleDefaultListId)[ sListStyleName ] =
164 const OUString& sListId )
const
171 return (*aIter).second.first;
179 const OUString& sListId )
const
186 return (*aIter).second.second;
196 static bool bHack = (getenv(
"LIBO_ONEWAY_STABLE_ODF_EXPORT") !=
nullptr);
197 OUString sTmpStr(
"list" );
201 static sal_Int64 nIdCounter = SAL_CONST_INT64(5000000000);
202 sTmpStr += OUString::number(nIdCounter++);
212 sTmpStr += OUString::number(
n );
215 OUString sNewListId( sTmpStr );
222 sNewListId = sTmpStr + OUString::number( nHitCount );
233 if ( sListBlockListId.isEmpty() )
235 sListBlockListId = rListBlock.
GetListId();
240 if ( !sListBlockListId.isEmpty() )
242 const OUString sListStyleName =
245 tMapForLists::const_iterator aIter =
249 if ( (*aIter).second.first == sListBlockListId )
251 sListBlockListId = (*aIter).second.second;
257 return sListBlockListId;
261 const OUString& sContinuingListId )
268 (*mpContinuingLists)[ sListId ] = sContinuingListId;
272 const OUString& sListId )
const
276 tMapForContinuingLists::const_iterator aIter =
280 return (*aIter).second;
288 const OUString& sListStyleName )
294 ::std::pair< OUString, OUString >
295 aListData( sListId, sListStyleName );
314 const sal_uInt16 i_Level,
315 std::u16string_view i_StyleName)
317 if (i_StyleName.empty()) {
318 SAL_INFO(
"xmloff.text",
"invalid numbered-paragraph: no style-name");
320 if (!i_StyleName.empty()
325 "internal error: numbered-paragraph style-name but no list-id?");
333ClampLevel(uno::Reference<container::XIndexReplace>
const& i_xNumRules,
334 sal_Int16 & io_rLevel)
336 assert(i_xNumRules.is());
337 if (i_xNumRules.is()) {
338 const sal_Int32 nLevelCount( i_xNumRules->getCount() );
339 if ( io_rLevel >= nLevelCount ) {
340 io_rLevel = sal::static_int_cast< sal_Int16 >(nLevelCount-1);
345uno::Reference<container::XIndexReplace>
347 SvXMLImport & i_rImport,
348 const OUString& i_ListId,
349 sal_Int16 & io_rLevel,
const OUString& i_StyleName)
351 assert(!i_ListId.isEmpty());
352 assert(io_rLevel >= 0);
355 if ( rNPList.empty() ) {
358 rNPList.emplace_back(
none,
362 uno::Reference<container::XIndexReplace> xNumRules;
363 if ((0 == io_rLevel) || rNPList.empty() || !i_StyleName.isEmpty()) {
366 const size_t parent( std::min(
static_cast<size_t>(io_rLevel),
367 rNPList.size()) - 1 );
369 io_rLevel > 0 ? rNPList[parent].second :
nullptr,
370 io_rLevel > 0 ? rNPList[parent].
first :
none,
371 i_StyleName, io_rLevel);
376 if (
static_cast<sal_uInt16
>(io_rLevel) + 1U > rNPList.size()) {
378 for (
size_t i = rNPList.size();
381 NumParaList_t::value_type
const rule(rNPList.back());
382 rNPList.push_back(rule);
384 NumParaList_t::value_type
const rule(rNPList.back());
385 rNPList.push_back(xNumRules.is()
386 ? ::std::make_pair(i_StyleName, xNumRules)
390 if (xNumRules.is()) {
391 rNPList[io_rLevel] = std::make_pair(i_StyleName, xNumRules);
393 if (
static_cast<sal_uInt16
>(io_rLevel) + 1U < rNPList.size()) {
394 rNPList.erase(rNPList.begin() + io_rLevel + 1, rNPList.end());
402 return rNPList.back().second;
406uno::Reference<container::XIndexReplace>
408 SvXMLImport & i_rImport,
409 const uno::Reference<container::XIndexReplace>& i_rNumRule,
410 std::u16string_view i_ParentStyleName,
411 const OUString& i_StyleName,
412 sal_Int16 & io_rLevel,
413 bool* o_pRestartNumbering,
414 bool* io_pSetDefaults)
416 uno::Reference<container::XIndexReplace> xNumRules(i_rNumRule);
417 if ( !i_StyleName.isEmpty() && i_StyleName != i_ParentStyleName )
419 const OUString sDisplayStyleName(
422 const uno::Reference < container::XNameContainer >& rNumStyles(
423 i_rImport.GetTextImport()->GetNumberingStyles() );
424 if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
426 uno::Reference < style::XStyle > xStyle;
427 uno::Any any = rNumStyles->getByName( sDisplayStyleName );
430 uno::Reference< beans::XPropertySet > xPropSet( xStyle,
432 any = xPropSet->getPropertyValue(
"NumberingRules");
438 i_rImport.GetTextImport()->FindAutoListStyle( i_StyleName ) );
442 if( !xNumRules.is() )
451 bool bSetDefaults(io_pSetDefaults && *io_pSetDefaults);
452 if ( !xNumRules.is() )
460 SAL_INFO_IF(xNumRules.is(),
"xmloff.core",
"cannot create numrules");
461 if ( !xNumRules.is() )
465 if (o_pRestartNumbering) *o_pRestartNumbering =
false;
467 if (io_pSetDefaults) *io_pSetDefaults = bSetDefaults;
sal_uInt32 GetDateUnsigned() const
static css::uno::Reference< css::container::XIndexReplace > CreateNumRule(const css::uno::Reference< css::frame::XModel > &rModel)
static void SetDefaultStyle(const css::uno::Reference< css::container::XIndexReplace > &rNumRule, sal_Int16 nLevel, bool bOrdered)
const css::uno::Reference< css::container::XIndexReplace > & GetNumRules() const
void CreateAndInsertAuto() const
const OUString & GetContinueListId() const
const OUString & GetListId() const
void PopListContext()
pop the list context stack
OUString msListStyleOfLastProcessedList
bool EqualsToTopListStyleOnStack(std::u16string_view sListId) const
std::unique_ptr< tMapForLists > mpProcessedLists
void StoreLastContinuingList(const OUString &sListId, const OUString &sContinuingListId)
std::unique_ptr< std::map< OUString, OUString > > mpStyleNameLastListIds
void SetListItem(XMLTextListItemContext *pListItem)
set list item on top of the list context stack
::std::vector< ::std::pair< OUString, css::uno::Reference< css::container::XIndexReplace > > > NumParaList_t
numbered-paragraphs
void KeepListAsProcessed(const OUString &sListId, const OUString &sListStyleName, const OUString &sContinueListId, const OUString &sListStyleDefaultListId=OUString())
OUString GetNumberedParagraphListId(const sal_uInt16 i_Level, std::u16string_view i_StyleName)
get ID of the last numbered-paragraph iff it has given style-name
void PushListContext(XMLTextListBlockContext *i_pListBlock)
list stack for importing:
OUString GenerateNewListId() const
std::unique_ptr< tMapForLists > mpMapListIdToListStyleDefaultListId
static css::uno::Reference< css::container::XIndexReplace > MakeNumRule(SvXMLImport &i_rImport, const css::uno::Reference< css::container::XIndexReplace > &i_xNumRule, std::u16string_view i_ParentStyleName, const OUString &i_StyleName, sal_Int16 &io_rLevel, bool *o_pRestartNumbering=nullptr, bool *io_pSetDefaults=nullptr)
Creates a NumRule from given style-name.
std::unique_ptr< tMapForContinuingLists > mpContinuingLists
OUString GetListIdForListBlock(XMLTextListBlockContext const &rListBlock)
OUString msLastProcessedListId
::std::map< OUString, NumParaList_t > mNPLists
OUString GetListStyleOfProcessedList(const OUString &sListId) const
void ListContextTop(XMLTextListBlockContext *&o_pListBlockContext, XMLTextListItemContext *&o_pListItemContext, XMLNumberedParaContext *&o_pNumberedParagraphContext)
peek at the top of the list context stack
std::stack< ListStackFrame_t > mListStack
bool IsListProcessed(const OUString &sListId) const
std::unique_ptr< tStackForLists > mpListStack
LastNumberedParagraphs_t mLastNumberedParagraphs
OUString GetContinueListIdOfProcessedList(const OUString &sListId) const
void PushListOnStack(const OUString &sListId, const OUString &sListStyleName)
OUString GetLastContinuingListId(const OUString &sListId) const
css::uno::Reference< css::container::XIndexReplace > EnsureNumberedParagraph(SvXMLImport &i_rImport, const OUString &i_ListId, sal_Int16 &io_rLevel, const OUString &i_StyleName)
for importing numbered-paragraph note that the ID namespace for numbered-paragraph and regular list i...
OUString GetLastIdOfStyleName(const OUString &sListStyleName) const
Looks up the last list id of a given list style, by name.
#define SAL_INFO_IF(condition, area, stream)
#define SAL_INFO(area, stream)
int uniform_int_distribution(int a, int b)
constexpr OUStringLiteral first
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
static void ClampLevel(uno::Reference< container::XIndexReplace > const &i_xNumRules, sal_Int16 &io_rLevel)