Files
libreoffice/xmloff/source/text/txtlists.cxx

479 lines
16 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by: Armin Le Grand. #118558# Correcting OLE attributes of LO3.4 at load time by loading as OOo3.3, details see task. http://svn.apache.org/viewvc?view=revision&revision=1195906 #118485# - Styles for OLEs are not saved. http://svn.apache.org/viewvc?view=revision&revision=1182166 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles http://svn.apache.org/viewvc?view=revision&revision=1293316 #119337# Solves the wrong get/setPropertyValue calls in SvxShapeText (and thus in SvxOle2Shape) http://svn.apache.org/viewvc?view=revision&revision=1344156 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i117717#: remove wrong assertion http://svn.apache.org/viewvc?view=revision&revision=1172349 Patch contributed by Herbert Duerr goodbye Registration and License dialogs, don't let the door hit you http://svn.apache.org/viewvc?view=revision&revision=1172613 help gcc 4.6.0 on 32bit ubuntu 11.10" http://svn.apache.org/viewvc?view=revision&revision=1245357 Do not add targets for junit tests when junit is disabled. Patch contributed by Andre Fischer http://svn.apache.org/viewvc?view=revision&revision=1241508 Revert "sb140: #i117082# avoid unncessary static class data members commit 21d97438e2944861e26e4984195f959a0cce1e41. remove obsolete FreeBSD visibility special case. retain consolidated BSD bridge code, remove OS/2 pieces.
2012-11-12 17:21:24 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <txtlists.hxx>
#include <comphelper/random.hxx>
#include <o3tl/make_unique.hxx>
#include <tools/date.hxx>
#include <tools/time.hxx>
2008-10-01 06:34:11 +00:00
#include <xmloff/txtimp.hxx>
#include <xmloff/xmlimp.hxx>
#include <xmloff/xmlnumi.hxx>
#include <com/sun/star/style/XStyle.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include "XMLTextListItemContext.hxx"
#include "XMLTextListBlockContext.hxx"
2008-10-01 06:34:11 +00:00
#include "txtparai.hxx"
using namespace ::com::sun::star;
XMLTextListsHelper::XMLTextListsHelper()
: msLastProcessedListId(),
msListStyleOfLastProcessedList()
// Inconsistent behavior regarding lists (#i92811#)
{
}
2008-10-01 06:34:11 +00:00
void XMLTextListsHelper::PushListContext(
XMLTextListBlockContext *i_pListBlock)
{
mListStack.emplace(i_pListBlock,
static_cast<XMLTextListItemContext*>(nullptr),
static_cast<XMLNumberedParaContext*>(nullptr));
2008-10-01 06:34:11 +00:00
}
void XMLTextListsHelper::PushListContext(
XMLNumberedParaContext *i_pNumberedParagraph)
{
mListStack.emplace(
static_cast<XMLTextListBlockContext*>(nullptr),
static_cast<XMLTextListItemContext*>(nullptr), i_pNumberedParagraph);
2008-10-01 06:34:11 +00:00
}
void XMLTextListsHelper::PopListContext()
{
assert(mListStack.size());
CWS-TOOLING: integrate CWS dbaperf1 2009-04-02 09:12:25 +0200 oj r270372 : CWS-TOOLING: rebase CWS dbaperf1 to trunk@270033 (milestone: DEV300:m45) 2009-03-17 10:20:34 +0100 oj r269577 : add parameter 2009-03-17 10:20:05 +0100 oj r269576 : add parameter 2009-03-12 12:32:24 +0100 oj r269387 : add missing ++ 2009-03-11 12:53:35 +0100 oj r269315 : compile error 2009-03-06 08:52:11 +0100 oj r268968 : #i99264# remove duplicate code 2009-03-06 08:20:08 +0100 oj r268966 : add missingheader 2009-03-06 08:17:41 +0100 oj r268965 : add header 2009-03-06 08:15:07 +0100 oj r268964 : #i99708# remove duplicate code 2009-03-06 07:24:11 +0100 oj r268963 : #i99708# remove duplicate code 2009-03-06 07:22:24 +0100 oj r268962 : #i99708# use tenary operator 2009-03-06 07:19:21 +0100 oj r268961 : remove unused rtl_logs 2009-03-06 07:15:55 +0100 oj r268960 : #i99708# extract getLength from for loop 2009-03-06 07:15:35 +0100 oj r268959 : #i99708# extract getLength from for loop 2009-03-06 07:14:57 +0100 oj r268958 : remove unused rtl_logs 2009-03-06 07:13:01 +0100 oj r268957 : insert DBG_ helper 2009-03-06 07:12:17 +0100 oj r268956 : remove unused rtl_logs 2009-03-06 07:10:26 +0100 oj r268955 : remove unused rtl_logs 2009-03-06 07:04:51 +0100 oj r268954 : #i99708# use tenary operator 2009-03-05 12:04:46 +0100 oj r268895 : comment RTL_LOG out 2009-03-05 09:05:07 +0100 oj r268874 : add rtl logfile 2009-03-04 14:21:18 +0100 oj r268828 : #i99708# make static inplace and some method calls in for loop removed 2009-03-04 14:20:34 +0100 oj r268827 : #i99708# impl double check pattern for getInfohelper 2009-03-02 09:31:42 +0100 oj r268636 : add rtl logfile 2009-03-02 08:18:37 +0100 oj r268633 : add rtl logfile 2009-02-27 11:22:16 +0100 oj r268570 : #i99709# change algorithm for marking objects 2009-02-27 11:17:04 +0100 oj r268568 : #i99708# some improvements to load forms, controls faster and replacement of size() call with !empty() which is much faster 2009-02-24 10:09:35 +0100 sb r268383 : #i99290# no longer care to set a sensible context class loader for native threads attached to the VM 2009-02-23 13:44:04 +0100 oj r268354 : #i76606# seekrow changes 2009-02-23 12:27:30 +0100 oj r268349 : deleted 2009-02-20 15:14:23 +0100 oj r268325 : #i76606# some code changes 2009-02-19 14:15:25 +0100 oj r268284 : #i76606# use of simple prep stmt instead of full blown rowset, when source and dest connection are the same use insert into ... ( select ... ) 2009-02-19 11:27:55 +0100 oj r268265 : #i76606# insert some RTL_LOG and setObject impl 2009-02-18 14:45:37 +0100 oj r268222 : #i99363# insert RTL_LOG 2009-02-18 14:45:18 +0100 oj r268221 : #i99363# insert RTL_LOG 2009-02-18 11:14:54 +0100 oj r268207 : #i99363# call some impl_ methods to avoid duplicate cechCache calls 2009-02-18 11:10:47 +0100 oj r268206 : #i99363# make isCount inline 2009-02-18 10:33:22 +0100 oj r268203 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-18 10:32:57 +0100 oj r268202 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-17 07:29:05 +0100 oj r267843 : #i96897# remove some dll public 2009-02-16 15:01:04 +0100 oj r267816 : #i96897# remove some dll public 2009-02-16 14:25:53 +0100 oj r267810 : #i99264# remove duplicate code 2009-02-16 14:25:33 +0100 oj r267809 : #i99264# remove duplicate code 2009-02-16 14:24:59 +0100 oj r267808 : #i99264# remove duplicate code 2009-02-13 10:56:17 +0100 oj r267703 : #i99191# comment the contextclassloader 2009-02-13 10:32:40 +0100 oj r267700 : reduce call to resultset meta data 2009-02-13 10:27:31 +0100 oj r267699 : reduce call to resultset meta data 2009-02-13 10:27:08 +0100 oj r267698 : reduce call to resultset meta data
2009-04-23 10:42:05 +00:00
if ( !mListStack.empty())
mListStack.pop();
2008-10-01 06:34:11 +00:00
}
void XMLTextListsHelper::ListContextTop(
XMLTextListBlockContext*& o_pListBlockContext,
XMLTextListItemContext*& o_pListItemContext,
XMLNumberedParaContext*& o_pNumberedParagraphContext )
{
CWS-TOOLING: integrate CWS dbaperf1 2009-04-02 09:12:25 +0200 oj r270372 : CWS-TOOLING: rebase CWS dbaperf1 to trunk@270033 (milestone: DEV300:m45) 2009-03-17 10:20:34 +0100 oj r269577 : add parameter 2009-03-17 10:20:05 +0100 oj r269576 : add parameter 2009-03-12 12:32:24 +0100 oj r269387 : add missing ++ 2009-03-11 12:53:35 +0100 oj r269315 : compile error 2009-03-06 08:52:11 +0100 oj r268968 : #i99264# remove duplicate code 2009-03-06 08:20:08 +0100 oj r268966 : add missingheader 2009-03-06 08:17:41 +0100 oj r268965 : add header 2009-03-06 08:15:07 +0100 oj r268964 : #i99708# remove duplicate code 2009-03-06 07:24:11 +0100 oj r268963 : #i99708# remove duplicate code 2009-03-06 07:22:24 +0100 oj r268962 : #i99708# use tenary operator 2009-03-06 07:19:21 +0100 oj r268961 : remove unused rtl_logs 2009-03-06 07:15:55 +0100 oj r268960 : #i99708# extract getLength from for loop 2009-03-06 07:15:35 +0100 oj r268959 : #i99708# extract getLength from for loop 2009-03-06 07:14:57 +0100 oj r268958 : remove unused rtl_logs 2009-03-06 07:13:01 +0100 oj r268957 : insert DBG_ helper 2009-03-06 07:12:17 +0100 oj r268956 : remove unused rtl_logs 2009-03-06 07:10:26 +0100 oj r268955 : remove unused rtl_logs 2009-03-06 07:04:51 +0100 oj r268954 : #i99708# use tenary operator 2009-03-05 12:04:46 +0100 oj r268895 : comment RTL_LOG out 2009-03-05 09:05:07 +0100 oj r268874 : add rtl logfile 2009-03-04 14:21:18 +0100 oj r268828 : #i99708# make static inplace and some method calls in for loop removed 2009-03-04 14:20:34 +0100 oj r268827 : #i99708# impl double check pattern for getInfohelper 2009-03-02 09:31:42 +0100 oj r268636 : add rtl logfile 2009-03-02 08:18:37 +0100 oj r268633 : add rtl logfile 2009-02-27 11:22:16 +0100 oj r268570 : #i99709# change algorithm for marking objects 2009-02-27 11:17:04 +0100 oj r268568 : #i99708# some improvements to load forms, controls faster and replacement of size() call with !empty() which is much faster 2009-02-24 10:09:35 +0100 sb r268383 : #i99290# no longer care to set a sensible context class loader for native threads attached to the VM 2009-02-23 13:44:04 +0100 oj r268354 : #i76606# seekrow changes 2009-02-23 12:27:30 +0100 oj r268349 : deleted 2009-02-20 15:14:23 +0100 oj r268325 : #i76606# some code changes 2009-02-19 14:15:25 +0100 oj r268284 : #i76606# use of simple prep stmt instead of full blown rowset, when source and dest connection are the same use insert into ... ( select ... ) 2009-02-19 11:27:55 +0100 oj r268265 : #i76606# insert some RTL_LOG and setObject impl 2009-02-18 14:45:37 +0100 oj r268222 : #i99363# insert RTL_LOG 2009-02-18 14:45:18 +0100 oj r268221 : #i99363# insert RTL_LOG 2009-02-18 11:14:54 +0100 oj r268207 : #i99363# call some impl_ methods to avoid duplicate cechCache calls 2009-02-18 11:10:47 +0100 oj r268206 : #i99363# make isCount inline 2009-02-18 10:33:22 +0100 oj r268203 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-18 10:32:57 +0100 oj r268202 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-17 07:29:05 +0100 oj r267843 : #i96897# remove some dll public 2009-02-16 15:01:04 +0100 oj r267816 : #i96897# remove some dll public 2009-02-16 14:25:53 +0100 oj r267810 : #i99264# remove duplicate code 2009-02-16 14:25:33 +0100 oj r267809 : #i99264# remove duplicate code 2009-02-16 14:24:59 +0100 oj r267808 : #i99264# remove duplicate code 2009-02-13 10:56:17 +0100 oj r267703 : #i99191# comment the contextclassloader 2009-02-13 10:32:40 +0100 oj r267700 : reduce call to resultset meta data 2009-02-13 10:27:31 +0100 oj r267699 : reduce call to resultset meta data 2009-02-13 10:27:08 +0100 oj r267698 : reduce call to resultset meta data
2009-04-23 10:42:05 +00:00
if ( !mListStack.empty() ) {
2008-10-01 06:34:11 +00:00
o_pListBlockContext =
static_cast<XMLTextListBlockContext*>(std::get<0>(mListStack.top()).get());
2008-10-01 06:34:11 +00:00
o_pListItemContext =
static_cast<XMLTextListItemContext *>(std::get<1>(mListStack.top()).get());
2008-10-01 06:34:11 +00:00
o_pNumberedParagraphContext =
static_cast<XMLNumberedParaContext *>(std::get<2>(mListStack.top()).get());
2008-10-01 06:34:11 +00:00
}
}
void XMLTextListsHelper::SetListItem( XMLTextListItemContext *i_pListItem )
{
// may be cleared by ListBlockContext for upper list...
if (i_pListItem) {
assert(mListStack.size());
assert(std::get<0>(mListStack.top()).is() &&
2008-10-01 06:34:11 +00:00
"internal error: SetListItem: mListStack has no ListBlock");
assert(!std::get<1>(mListStack.top()).is() &&
2008-10-01 06:34:11 +00:00
"error: SetListItem: list item already exists");
}
CWS-TOOLING: integrate CWS dbaperf1 2009-04-02 09:12:25 +0200 oj r270372 : CWS-TOOLING: rebase CWS dbaperf1 to trunk@270033 (milestone: DEV300:m45) 2009-03-17 10:20:34 +0100 oj r269577 : add parameter 2009-03-17 10:20:05 +0100 oj r269576 : add parameter 2009-03-12 12:32:24 +0100 oj r269387 : add missing ++ 2009-03-11 12:53:35 +0100 oj r269315 : compile error 2009-03-06 08:52:11 +0100 oj r268968 : #i99264# remove duplicate code 2009-03-06 08:20:08 +0100 oj r268966 : add missingheader 2009-03-06 08:17:41 +0100 oj r268965 : add header 2009-03-06 08:15:07 +0100 oj r268964 : #i99708# remove duplicate code 2009-03-06 07:24:11 +0100 oj r268963 : #i99708# remove duplicate code 2009-03-06 07:22:24 +0100 oj r268962 : #i99708# use tenary operator 2009-03-06 07:19:21 +0100 oj r268961 : remove unused rtl_logs 2009-03-06 07:15:55 +0100 oj r268960 : #i99708# extract getLength from for loop 2009-03-06 07:15:35 +0100 oj r268959 : #i99708# extract getLength from for loop 2009-03-06 07:14:57 +0100 oj r268958 : remove unused rtl_logs 2009-03-06 07:13:01 +0100 oj r268957 : insert DBG_ helper 2009-03-06 07:12:17 +0100 oj r268956 : remove unused rtl_logs 2009-03-06 07:10:26 +0100 oj r268955 : remove unused rtl_logs 2009-03-06 07:04:51 +0100 oj r268954 : #i99708# use tenary operator 2009-03-05 12:04:46 +0100 oj r268895 : comment RTL_LOG out 2009-03-05 09:05:07 +0100 oj r268874 : add rtl logfile 2009-03-04 14:21:18 +0100 oj r268828 : #i99708# make static inplace and some method calls in for loop removed 2009-03-04 14:20:34 +0100 oj r268827 : #i99708# impl double check pattern for getInfohelper 2009-03-02 09:31:42 +0100 oj r268636 : add rtl logfile 2009-03-02 08:18:37 +0100 oj r268633 : add rtl logfile 2009-02-27 11:22:16 +0100 oj r268570 : #i99709# change algorithm for marking objects 2009-02-27 11:17:04 +0100 oj r268568 : #i99708# some improvements to load forms, controls faster and replacement of size() call with !empty() which is much faster 2009-02-24 10:09:35 +0100 sb r268383 : #i99290# no longer care to set a sensible context class loader for native threads attached to the VM 2009-02-23 13:44:04 +0100 oj r268354 : #i76606# seekrow changes 2009-02-23 12:27:30 +0100 oj r268349 : deleted 2009-02-20 15:14:23 +0100 oj r268325 : #i76606# some code changes 2009-02-19 14:15:25 +0100 oj r268284 : #i76606# use of simple prep stmt instead of full blown rowset, when source and dest connection are the same use insert into ... ( select ... ) 2009-02-19 11:27:55 +0100 oj r268265 : #i76606# insert some RTL_LOG and setObject impl 2009-02-18 14:45:37 +0100 oj r268222 : #i99363# insert RTL_LOG 2009-02-18 14:45:18 +0100 oj r268221 : #i99363# insert RTL_LOG 2009-02-18 11:14:54 +0100 oj r268207 : #i99363# call some impl_ methods to avoid duplicate cechCache calls 2009-02-18 11:10:47 +0100 oj r268206 : #i99363# make isCount inline 2009-02-18 10:33:22 +0100 oj r268203 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-18 10:32:57 +0100 oj r268202 : #i99363# use bookmarkable if available and inserted some RTL_LOG 2009-02-17 07:29:05 +0100 oj r267843 : #i96897# remove some dll public 2009-02-16 15:01:04 +0100 oj r267816 : #i96897# remove some dll public 2009-02-16 14:25:53 +0100 oj r267810 : #i99264# remove duplicate code 2009-02-16 14:25:33 +0100 oj r267809 : #i99264# remove duplicate code 2009-02-16 14:24:59 +0100 oj r267808 : #i99264# remove duplicate code 2009-02-13 10:56:17 +0100 oj r267703 : #i99191# comment the contextclassloader 2009-02-13 10:32:40 +0100 oj r267700 : reduce call to resultset meta data 2009-02-13 10:27:31 +0100 oj r267699 : reduce call to resultset meta data 2009-02-13 10:27:08 +0100 oj r267698 : reduce call to resultset meta data
2009-04-23 10:42:05 +00:00
if ( !mListStack.empty() ) {
std::get<1>(mListStack.top()) = i_pListItem;
2008-10-01 06:34:11 +00:00
}
}
// Handling for parameter <sListStyleDefaultListId> (#i92811#)
void XMLTextListsHelper::KeepListAsProcessed( const OUString& sListId,
const OUString& sListStyleName,
const OUString& sContinueListId,
const OUString& sListStyleDefaultListId )
{
if ( IsListProcessed( sListId ) )
{
assert(false &&
"<XMLTextListsHelper::KeepListAsProcessed(..)> - list id already added" );
return;
}
if ( !mpProcessedLists )
{
mpProcessedLists = o3tl::make_unique<tMapForLists>();
}
::std::pair< OUString, OUString >
aListData( sListStyleName, sContinueListId );
(*mpProcessedLists)[ sListId ] = aListData;
msLastProcessedListId = sListId;
msListStyleOfLastProcessedList = sListStyleName;
// Inconsistent behavior regarding lists (#i92811#)
if ( !sListStyleDefaultListId.isEmpty())
{
if ( !mpMapListIdToListStyleDefaultListId )
{
mpMapListIdToListStyleDefaultListId = o3tl::make_unique<tMapForLists>();
}
if ( mpMapListIdToListStyleDefaultListId->find( sListStyleName ) ==
mpMapListIdToListStyleDefaultListId->end() )
{
::std::pair< OUString, OUString >
aListIdMapData( sListId, sListStyleDefaultListId );
(*mpMapListIdToListStyleDefaultListId)[ sListStyleName ] =
aListIdMapData;
}
}
}
bool XMLTextListsHelper::IsListProcessed( const OUString& sListId ) const
{
if ( !mpProcessedLists )
{
return false;
}
return mpProcessedLists->find( sListId ) != mpProcessedLists->end();
}
OUString XMLTextListsHelper::GetListStyleOfProcessedList(
const OUString& sListId ) const
{
if ( mpProcessedLists )
{
tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId );
if ( aIter != mpProcessedLists->end() )
{
return (*aIter).second.first;
}
}
return OUString();
}
OUString XMLTextListsHelper::GetContinueListIdOfProcessedList(
const OUString& sListId ) const
{
if ( mpProcessedLists )
{
tMapForLists::const_iterator aIter = mpProcessedLists->find( sListId );
if ( aIter != mpProcessedLists->end() )
{
return (*aIter).second.second;
}
}
return OUString();
}
OUString XMLTextListsHelper::GenerateNewListId() const
{
static bool bHack = (getenv("LIBO_ONEWAY_STABLE_ODF_EXPORT") != nullptr);
Add hack to optionally get stable ODF output from the same input To be used in regression testing and similar scenarios, where the output ODF is *not* intended to be further manipulated in LibreOffice. An environment variable LIBO_ONEWAY_STABLE_ODF_EXPORT is used to toggle this behaviour. I am not 100% sure whether the generated ODF with the hack toggled on is even fully correct, but correctness is not the purpose of the hack anyway. Two classes of issues handled: 1) Automatic style names and 2) use of randomness. For class 1), when the hack toggle is in effect, we generate the names at first as strings based on all the properties of the style, and sort them based on those, and then rename them (for brevity in the output) to the "normal" form of a short prefix plus a number (like "P12"). Sure, it would have been better to just figure out *why* the automatic style naming currently is not stable in the first place, but outputs the styles in different order (with some styles being assigned different numbers) in separate invokations of LibreOffice), but I was unable to understand that. Possibly this code could be used in all cases, except that it does break some unit test (can't recall which right now). I don't know whether that is simply because the unit test assumes too much knowledge of the internal workings of the automatic style name generation, or whether the generated ODF is actually invalid. For 2), I found a handful of places where randomness was used to generated various kinds of identifiers in ODF output. I changed those to just use large (64-bit) non-overlapping integers instead. I assume there *is* a point in the original code in each case that explains why randomness is needed, so the hack definitely needs to be optional and used only for the above mentioned scenarios. Change-Id: I17b657197e38bcf24abdfe61ad4a277f4339eeae
2013-09-30 15:23:35 +03:00
OUString sTmpStr( "list" );
if (bHack)
{
static sal_Int64 nIdCounter = SAL_CONST_INT64(5000000000);
sTmpStr += OUString::number(nIdCounter++);
}
else
{
// Value of xml:id in element <text:list> has to be a valid ID type (#i92478#)
sal_Int64 n = ::tools::Time( ::tools::Time::SYSTEM ).GetTime();
n += Date( Date::SYSTEM ).GetDateUnsigned();
n += comphelper::rng::uniform_int_distribution(0, std::numeric_limits<int>::max());
Add hack to optionally get stable ODF output from the same input To be used in regression testing and similar scenarios, where the output ODF is *not* intended to be further manipulated in LibreOffice. An environment variable LIBO_ONEWAY_STABLE_ODF_EXPORT is used to toggle this behaviour. I am not 100% sure whether the generated ODF with the hack toggled on is even fully correct, but correctness is not the purpose of the hack anyway. Two classes of issues handled: 1) Automatic style names and 2) use of randomness. For class 1), when the hack toggle is in effect, we generate the names at first as strings based on all the properties of the style, and sort them based on those, and then rename them (for brevity in the output) to the "normal" form of a short prefix plus a number (like "P12"). Sure, it would have been better to just figure out *why* the automatic style naming currently is not stable in the first place, but outputs the styles in different order (with some styles being assigned different numbers) in separate invokations of LibreOffice), but I was unable to understand that. Possibly this code could be used in all cases, except that it does break some unit test (can't recall which right now). I don't know whether that is simply because the unit test assumes too much knowledge of the internal workings of the automatic style name generation, or whether the generated ODF is actually invalid. For 2), I found a handful of places where randomness was used to generated various kinds of identifiers in ODF output. I changed those to just use large (64-bit) non-overlapping integers instead. I assume there *is* a point in the original code in each case that explains why randomness is needed, so the hack definitely needs to be optional and used only for the above mentioned scenarios. Change-Id: I17b657197e38bcf24abdfe61ad4a277f4339eeae
2013-09-30 15:23:35 +03:00
// Value of xml:id in element <text:list> has to be a valid ID type (#i92478#)
sTmpStr += OUString::number( n );
}
OUString sNewListId( sTmpStr );
if ( mpProcessedLists )
{
2011-07-30 23:51:40 +02:00
long nHitCount = 0;
while ( mpProcessedLists->find( sNewListId ) != mpProcessedLists->end() )
{
++nHitCount;
sNewListId = sTmpStr;
sNewListId += OUString::number( nHitCount );
}
}
return sNewListId;
}
// Provide list id for a certain list block for import (#i92811#)
OUString XMLTextListsHelper::GetListIdForListBlock( XMLTextListBlockContext& rListBlock )
{
OUString sListBlockListId( rListBlock.GetContinueListId() );
if ( sListBlockListId.isEmpty() )
{
sListBlockListId = rListBlock.GetListId();
}
if ( mpMapListIdToListStyleDefaultListId )
{
if ( !sListBlockListId.isEmpty() )
{
const OUString sListStyleName =
GetListStyleOfProcessedList( sListBlockListId );
tMapForLists::const_iterator aIter =
mpMapListIdToListStyleDefaultListId->find( sListStyleName );
if ( aIter != mpMapListIdToListStyleDefaultListId->end() )
{
if ( (*aIter).second.first == sListBlockListId )
{
sListBlockListId = (*aIter).second.second;
}
}
}
}
return sListBlockListId;
}
void XMLTextListsHelper::StoreLastContinuingList( const OUString& sListId,
const OUString& sContinuingListId )
{
if ( !mpContinuingLists )
{
mpContinuingLists = o3tl::make_unique<tMapForContinuingLists>();
}
(*mpContinuingLists)[ sListId ] = sContinuingListId;
}
OUString XMLTextListsHelper::GetLastContinuingListId(
const OUString& sListId ) const
{
if ( mpContinuingLists )
{
tMapForContinuingLists::const_iterator aIter =
mpContinuingLists->find( sListId );
if ( aIter != mpContinuingLists->end() )
{
return (*aIter).second;
}
}
return sListId;
}
void XMLTextListsHelper::PushListOnStack( const OUString& sListId,
const OUString& sListStyleName )
{
if ( !mpListStack )
{
mpListStack = o3tl::make_unique<tStackForLists>();
}
::std::pair< OUString, OUString >
aListData( sListId, sListStyleName );
mpListStack->push_back( aListData );
}
void XMLTextListsHelper::PopListFromStack()
{
if ( mpListStack &&
mpListStack->size() > 0 )
{
mpListStack->pop_back();
}
}
bool XMLTextListsHelper::EqualsToTopListStyleOnStack( const OUString& sListId ) const
{
return mpListStack && sListId == mpListStack->back().second;
}
2008-10-01 06:34:11 +00:00
OUString
2008-10-01 06:34:11 +00:00
XMLTextListsHelper::GetNumberedParagraphListId(
const sal_uInt16 i_Level,
const OUString& i_StyleName)
2008-10-01 06:34:11 +00:00
{
if (i_StyleName.isEmpty()) {
SAL_INFO("xmloff.text", "invalid numbered-paragraph: no style-name");
2008-10-01 06:34:11 +00:00
}
if (!i_StyleName.isEmpty()
2008-10-01 06:34:11 +00:00
&& (i_Level < mLastNumberedParagraphs.size())
&& (mLastNumberedParagraphs[i_Level].first == i_StyleName) )
{
assert(!mLastNumberedParagraphs[i_Level].second.isEmpty() &&
2008-10-01 06:34:11 +00:00
"internal error: numbered-paragraph style-name but no list-id?");
return mLastNumberedParagraphs[i_Level].second;
} else {
return GenerateNewListId();
}
}
static void
ClampLevel(uno::Reference<container::XIndexReplace> const& i_xNumRules,
sal_Int16 & io_rLevel)
{
assert(i_xNumRules.is());
2008-10-01 06:34:11 +00:00
if (i_xNumRules.is()) {
const sal_Int32 nLevelCount( i_xNumRules->getCount() );
if ( io_rLevel >= nLevelCount ) {
io_rLevel = sal::static_int_cast< sal_Int16 >(nLevelCount-1);
}
}
}
uno::Reference<container::XIndexReplace>
XMLTextListsHelper::EnsureNumberedParagraph(
SvXMLImport & i_rImport,
const OUString& i_ListId,
sal_Int16 & io_rLevel, const OUString& i_StyleName)
2008-10-01 06:34:11 +00:00
{
assert(!i_ListId.isEmpty());
assert(io_rLevel >= 0);
2008-10-01 06:34:11 +00:00
NumParaList_t & rNPList( mNPLists[i_ListId] );
const OUString none; // default
if ( rNPList.empty() ) {
2008-10-01 06:34:11 +00:00
// create default list style for top level
sal_Int16 lev(0);
rNPList.push_back(::std::make_pair(none,
MakeNumRule(i_rImport, nullptr, none, none, lev) ));
2008-10-01 06:34:11 +00:00
}
// create num rule first because this might clamp the level...
uno::Reference<container::XIndexReplace> xNumRules;
if ((0 == io_rLevel) || rNPList.empty() || !i_StyleName.isEmpty()) {
2008-10-01 06:34:11 +00:00
// no parent to inherit from, or explicit style given => new numrules!
// index of parent: level - 1, but maybe that does not exist
const size_t parent( std::min(static_cast<size_t>(io_rLevel),
rNPList.size()) - 1 );
xNumRules = MakeNumRule(i_rImport,
io_rLevel > 0 ? rNPList[parent].second : nullptr,
2008-10-01 06:34:11 +00:00
io_rLevel > 0 ? rNPList[parent].first : none,
i_StyleName, io_rLevel);
} else {
// no style given, but has a parent => reuse parent numrules!
ClampLevel(rNPList.back().second, io_rLevel);
}
if (static_cast<sal_uInt16>(io_rLevel) + 1U > rNPList.size()) {
// new level: need to enlarge
for (size_t i = rNPList.size();
i < static_cast<size_t>(io_rLevel); ++i)
{
NumParaList_t::value_type const rule(rNPList.back());
rNPList.push_back(rule);
2008-10-01 06:34:11 +00:00
}
NumParaList_t::value_type const rule(rNPList.back());
2008-10-01 06:34:11 +00:00
rNPList.push_back(xNumRules.is()
? ::std::make_pair(i_StyleName, xNumRules)
: rule);
2008-10-01 06:34:11 +00:00
} else {
// old level: no need to enlarge; possibly shrink
if (xNumRules.is()) {
rNPList[io_rLevel] = std::make_pair(i_StyleName, xNumRules);
}
if (static_cast<sal_uInt16>(io_rLevel) + 1U < rNPList.size()) {
rNPList.erase(rNPList.begin() + io_rLevel + 1, rNPList.end());
}
}
// remember the list id
if (mLastNumberedParagraphs.size() <= static_cast<size_t>(io_rLevel)) {
mLastNumberedParagraphs.resize(io_rLevel+1);
}
mLastNumberedParagraphs[io_rLevel] = std::make_pair(i_StyleName, i_ListId);
return rNPList.back().second;
}
/** extracted from the XMLTextListBlockContext constructor */
uno::Reference<container::XIndexReplace>
XMLTextListsHelper::MakeNumRule(
SvXMLImport & i_rImport,
const uno::Reference<container::XIndexReplace>& i_rNumRule,
const OUString& i_ParentStyleName,
const OUString& i_StyleName,
2008-10-01 06:34:11 +00:00
sal_Int16 & io_rLevel,
bool* o_pRestartNumbering,
bool* io_pSetDefaults)
2008-10-01 06:34:11 +00:00
{
static const char s_NumberingRules[] = "NumberingRules";
2008-10-01 06:34:11 +00:00
uno::Reference<container::XIndexReplace> xNumRules(i_rNumRule);
if ( !i_StyleName.isEmpty() && i_StyleName != i_ParentStyleName )
2008-10-01 06:34:11 +00:00
{
const OUString sDisplayStyleName(
2008-10-01 06:34:11 +00:00
i_rImport.GetStyleDisplayName( XML_STYLE_FAMILY_TEXT_LIST,
i_StyleName) );
const uno::Reference < container::XNameContainer >& rNumStyles(
i_rImport.GetTextImport()->GetNumberingStyles() );
if( rNumStyles.is() && rNumStyles->hasByName( sDisplayStyleName ) )
{
uno::Reference < style::XStyle > xStyle;
uno::Any any = rNumStyles->getByName( sDisplayStyleName );
any >>= xStyle;
uno::Reference< beans::XPropertySet > xPropSet( xStyle,
uno::UNO_QUERY );
any = xPropSet->getPropertyValue(s_NumberingRules);
2008-10-01 06:34:11 +00:00
any >>= xNumRules;
}
else
{
const SvxXMLListStyleContext *pListStyle(
i_rImport.GetTextImport()->FindAutoListStyle( i_StyleName ) );
if( pListStyle )
{
xNumRules = pListStyle->GetNumRules();
if( !xNumRules.is() )
{
pListStyle->CreateAndInsertAuto();
xNumRules = pListStyle->GetNumRules();
}
}
}
}
bool bSetDefaults(io_pSetDefaults && *io_pSetDefaults);
2008-10-01 06:34:11 +00:00
if ( !xNumRules.is() )
{
// If no style name has been specified for this style and for any
// parent or if no num rule with the specified name exists,
// create a new one.
xNumRules =
SvxXMLListStyleContext::CreateNumRule( i_rImport.GetModel() );
assert(xNumRules.is());
2008-10-01 06:34:11 +00:00
if ( !xNumRules.is() )
return xNumRules;
// Because it is a new num rule, numbering must not be restarted.
if (o_pRestartNumbering) *o_pRestartNumbering = false;
bSetDefaults = true;
2008-10-01 06:34:11 +00:00
if (io_pSetDefaults) *io_pSetDefaults = bSetDefaults;
}
ClampLevel(xNumRules, io_rLevel);
if ( bSetDefaults )
{
// Because there is no list style sheet for this style, a default
// format must be set for any level of this num rule.
SvxXMLListStyleContext::SetDefaultStyle( xNumRules, io_rLevel,
false );
2008-10-01 06:34:11 +00:00
}
return xNumRules;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */