20 #include <com/sun/star/text/XDocumentIndexesSupplier.hpp>
21 #include <com/sun/star/text/XTextSectionsSupplier.hpp>
22 #include <com/sun/star/text/XDependentTextField.hpp>
23 #include <com/sun/star/text/XDocumentIndex.hpp>
24 #include <com/sun/star/text/ChapterFormat.hpp>
25 #include <com/sun/star/text/XTextSection.hpp>
26 #include <com/sun/star/beans/PropertyValues.hpp>
27 #include <com/sun/star/ucb/XCommandEnvironment.hpp>
34 #include <unoprnms.hxx>
51 static void lcl_SetProp( uno::Reference< XPropertySetInfo >
const & xInfo,
52 uno::Reference< XPropertySet >
const & xProps,
53 OUString
const & aPropName,
const OUString& rValue)
55 if(xInfo->hasPropertyByName(aPropName))
59 xProps->setPropertyValue(aPropName, aValue);
63 static void lcl_SetProp( uno::Reference< XPropertySetInfo >
const & xInfo,
64 uno::Reference< XPropertySet >
const & xProps,
65 OUString
const & aPropName, sal_Int16 nValue )
67 if(xInfo->hasPropertyByName(aPropName))
71 xProps->setPropertyValue(aPropName, aValue);
76 uno::Reference< beans::XPropertySetInfo >
const & xInfo,
77 uno::Reference< beans::XPropertySet >
const & xProps,
78 OUString
const & aPropName,
bool bValue )
80 if(xInfo->hasPropertyByName(aPropName))
82 xProps->setPropertyValue(aPropName,
makeAny(bValue));
90 uno::Reference< frame::XModel > &
xModel = m_xExampleFrame->GetModel();
91 auto pDoc = comphelper::getUnoTunnelImplementation<SwXTextDocument>(xModel);
94 pDoc->GetDocShell()->LoadStyles_( *m_rWrtShell.GetView().GetDocShell(), true );
96 uno::Reference< text::XTextSectionsSupplier > xSectionSupplier(
97 xModel, uno::UNO_QUERY);
98 uno::Reference< container::XNameAccess > xSections =
99 xSectionSupplier->getTextSections();
101 for(
int i = 0;
i < 7; ++
i )
103 OUString sTmp =
"IndexSection_" + OUString::number(
i);
104 uno::Any aSection = xSections->getByName( sTmp );
105 aSection >>= m_vTypeData[
i].m_pxIndexSections->xContainerSection;
107 uno::Reference< text::XDocumentIndexesSupplier > xIdxSupp(xModel, uno::UNO_QUERY);
108 uno::Reference< container::XIndexAccess > xIdxs = xIdxSupp->getDocumentIndexes();
109 int n = xIdxs->getCount();
113 uno::Any aIdx = xIdxs->getByIndex(n);
114 uno::Reference< text::XDocumentIndex > xIdx;
118 CreateOrUpdateExample(m_eCurrentTOXType.eType);
127 TOXTypes nTOXIndex, sal_uInt16 nPage, sal_uInt16 nCurrentLevel)
129 if(!m_xExampleFrame || !m_xExampleFrame->IsInitialized())
134 static const char* IndexServiceNames[] =
136 "com.sun.star.text.DocumentIndex",
137 "com.sun.star.text.UserIndex",
138 "com.sun.star.text.ContentIndex",
139 "com.sun.star.text.IllustrationsIndex",
140 "com.sun.star.text.ObjectIndex",
141 "com.sun.star.text.TableIndex",
142 "com.sun.star.text.Bibliography"
145 OSL_ENSURE(m_vTypeData[nTOXIndex].m_pxIndexSections &&
146 m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection.is(),
147 "Section not created");
148 uno::Reference< frame::XModel > &
xModel = m_xExampleFrame->GetModel();
149 bool bInitialCreate =
true;
150 if(!m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex.is())
152 bInitialCreate =
true;
153 if(!m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection.is())
154 throw uno::RuntimeException();
155 uno::Reference< text::XTextRange > xAnchor = m_vTypeData[nTOXIndex].m_pxIndexSections->xContainerSection->getAnchor();
156 xAnchor = xAnchor->getStart();
157 uno::Reference< text::XTextCursor > xCursor = xAnchor->getText()->createTextCursorByRange(xAnchor);
159 uno::Reference< lang::XMultiServiceFactory > xFact(xModel, uno::UNO_QUERY);
161 OUString sIndexTypeName(OUString::createFromAscii( IndexServiceNames[
163 m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex.set(xFact->createInstance(sIndexTypeName), uno::UNO_QUERY);
164 uno::Reference< text::XTextContent >
xContent = m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex;
165 xCursor->getText()->insertTextContent(xCursor, xContent,
false);
169 uno::Reference< beans::XPropertySet > xSectPr(m_vTypeData[
i].m_pxIndexSections->xContainerSection, uno::UNO_QUERY);
176 uno::Reference< beans::XPropertySet > xIdxProps(m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex, uno::UNO_QUERY);
177 uno::Reference< beans::XPropertySetInfo > xInfo = xIdxProps->getPropertySetInfo();
192 uno::Reference< container::XIndexReplace > xAcc;
193 aStyleNames >>= xAcc;
200 const sal_Int32 nStyles =
202 uno::Sequence<OUString> aStyles(nStyles);
203 OUString* pArr = aStyles.getArray();
205 for(sal_Int32 nStyle = 0; nStyle < nStyles; ++nStyle)
208 xAcc->replaceByIndex(
i, aAny);
239 sal_Int16 nSet = text::ChapterFormat::NAME_NUMBER;
255 const SwForm* pForm = GetForm(m_eCurrentTOXType);
260 const bool bUseCurrent = nCurrentLevel < pForm->
GetFormMax();
261 const sal_uInt16 nStartLevel = bUseCurrent ? nCurrentLevel : 0;
262 const sal_uInt16 nEndLevel = bUseCurrent ? nCurrentLevel : pForm->
GetFormMax() - 1;
265 for(sal_uInt16 nCurrLevel = nStartLevel; nCurrLevel <= nEndLevel; nCurrLevel++)
268 uno::Sequence< beans::PropertyValues> aSequPropVals(10);
275 for(
const auto& aToken : aPattern)
277 if( aSequPropVals.getLength() <= nTokenIndex)
278 aSequPropVals.realloc(nTokenIndex + 10);
280 switch(aToken.eTokenType)
283 sTokenType =
"TokenEntryNumber";
288 sTokenType =
"TokenEntryText";
292 sTokenType =
"TokenTabStop";
295 sTokenType =
"TokenText";
299 sTokenType =
"TokenPageNumber";
302 sTokenType =
"TokenChapterInfo";
305 sTokenType =
"TokenHyperlinkStart";
308 sTokenType =
"TokenHyperlinkEnd";
312 sTokenType =
"TokenBibliographyDataField";
317 beans::PropertyValues aPropVals(nParamCount);
318 beans::PropertyValue* pPropValArr = aPropVals.getArray();
319 pPropValArr[0].Name =
"TokenType";
320 pPropValArr[0].Value <<= sTokenType;
321 pPropValArr[1].Name =
"CharacterStyleName";
322 pPropValArr[1].Value <<= aToken.sCharStyleName;
325 pPropValArr[2].Name =
"TabStopRightAligned";
326 pPropValArr[2].Value <<= SvxTabAdjust::End == aToken.eTabAlign;
327 pPropValArr[3].Name =
"TabStopFillCharacter";
328 pPropValArr[3].Value <<= OUString(aToken.cTabFillChar);
329 pPropValArr[4].Name =
"TabStopPosition";
330 SwTwips nTempPos = aToken.nTabStopPosition >= 0 ?
331 aToken.nTabStopPosition : 0;
333 pPropValArr[4].Value <<=
static_cast<sal_Int32
>(nTempPos);
337 pPropValArr[2].Name =
"Text";
338 pPropValArr[2].Value <<= aToken.sText;
340 beans::PropertyValues*
pValues = aSequPropVals.getArray();
341 pValues[nTokenIndex] = aPropVals;
344 aSequPropVals.realloc(nTokenIndex);
348 "wrong property type");
350 uno::Reference< container::XIndexReplace > xFormatAccess;
351 aFormatAccess >>= xFormatAccess;
353 xFormatAccess->replaceByIndex(nCurrLevel, aLevelProp);
360 sal_uInt16 nOffset = 0;
361 sal_uInt16 nEndLevel = 2;
362 switch(m_eCurrentTOXType.eType)
376 for(sal_uInt16
i = 1;
i < nEndLevel;
i++)
380 "ParaStyleLevel" + OUString::number(
i ),
384 m_vTypeData[nTOXIndex].m_pxIndexSections->xDocumentIndex->update();
391 m_xExampleFrame->Invalidate();
std::vector< SwFormToken > SwFormTokens
Vector of tokens.
#define UNO_NAME_USE_KEY_AS_ENTRY
#define UNO_NAME_CREATE_FROM_STAR_MATH
SwTOXElement GetContentOptions() const
#define UNO_NAME_LABEL_DISPLAY_TYPE
#define UNO_NAME_CREATE_FROM_STAR_CALC
const OUString & GetSequenceName() const
#define UNO_NAME_IS_VISIBLE
#define TOX_STYLE_DELIMITER
void CreateOrUpdateExample(TOXTypes nTOXIndex, sal_uInt16 nPage=0, sal_uInt16 nCurLevel=USHRT_MAX)
#define UNO_NAME_IS_COMMA_SEPARATED
sal_Int32 getTokenCount(const OString &rIn, char cTok)
#define UNO_NAME_CREATE_FROM_STAR_CHART
constexpr auto convertTwipToMm100(N n)
SwCaptionDisplay GetCaptionDisplay() const
#define UNO_NAME_LEVEL_FORMAT
#define UNO_NAME_USE_UPPER_CASE
SwTOIOptions GetIndexOptions() const
#define UNO_NAME_CREATE_FROM_CHAPTER
bool IsCreateFromObjectNames() const
#define UNO_NAME_IS_PROTECTED
#define UNO_NAME_CREATE_FROM_TEXT_FRAMES
#define UNO_NAME_TOC_NEWLINE
#define UNO_NAME_HIDE_TAB_LEADER_AND_PAGE_NUMBERS
bool IsFromChapter() const
static SW_DLLPUBLIC const OUString & GetSpecialExtraProgName(const OUString &rExtraUIName)
static void lcl_SetBOOLProp(uno::Reference< beans::XPropertySetInfo > const &xInfo, uno::Reference< beans::XPropertySet > const &xProps, OUString const &aPropName, bool bValue)
#define UNO_NAME_LEVEL_PARAGRAPH_STYLES
#define TOOLS_WARN_EXCEPTION(area, stream)
sal_uInt8 GetLevel() const
SwTOOElements GetOLEOptions() const
#define UNO_NAME_LABEL_CATEGORY
#define UNO_NAME_CREATE_FROM_MARKS
#define UNO_NAME_TOC_PARAGRAPH_OUTLINE_LEVEL
#define UNO_NAME_CREATE_FROM_LABELS
css::uno::Type const & get()
#define UNO_NAME_TAB_IN_TOC
#define UNO_NAME_CREATE_FROM_TABLES
#define UNO_NAME_CREATE_FROM_OTHER_EMBEDDED_OBJECTS
static void lcl_SetProp(uno::Reference< XPropertySetInfo > const &xInfo, uno::Reference< XPropertySet > const &xProps, OUString const &aPropName, const OUString &rValue)
#define UNO_NAME_USE_DASH
#define UNO_NAME_CREATE_FROM_STAR_DRAW
const PropertyValue * pValues
#define UNO_NAME_CREATE_FROM_EMBEDDED_OBJECTS
std::optional< OUString > const & GetTitle() const
#define UNO_NAME_CREATE_FROM_OUTLINE
uno::Reference< ucb::XContent > xContent
Reference< XModel > xModel
const OUString & GetStyleNames(sal_uInt16 nLvl) const
#define UNO_NAME_IS_CASE_SENSITIVE
#define UNO_NAME_USE_COMBINED_ENTRIES
#define UNO_NAME_CREATE_FROM_GRAPHIC_OBJECTS
IMPL_LINK_NOARG(SwMultiTOXTabDialog, CreateExample_Hdl, SwOneExampleFrame &, void)
#define UNO_NAME_USE_ALPHABETICAL_SEPARATORS
css::uno::Any SAL_CALL makeAny(const SharedUNOComponent< INTERFACE, COMPONENT > &value)