Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / uibase / utlui / uitool.cxx
blob079b5f9fdb1fea8f4430ff13b2ddf775f74d7323
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <hintids.hxx>
22 #include <osl/diagnose.h>
23 #include <tools/datetime.hxx>
24 #include <vcl/weld.hxx>
25 #include <unotools/collatorwrapper.hxx>
26 #include <svl/stritem.hxx>
27 #include <svl/grabbagitem.hxx>
28 #include <unotools/syslocale.hxx>
29 #include <IDocumentStylePoolAccess.hxx>
30 #include <editeng/pmdlitem.hxx>
31 #include <editeng/tstpitem.hxx>
32 #include <editeng/boxitem.hxx>
33 #include <editeng/sizeitem.hxx>
34 #include <editeng/brushitem.hxx>
35 #include <svx/pageitem.hxx>
36 #include <editeng/lrspitem.hxx>
37 #include <svl/style.hxx>
38 #include <unotools/localedatawrapper.hxx>
39 #include <com/sun/star/awt/XPopupMenu.hpp>
40 #include <com/sun/star/frame/XDispatch.hpp>
41 #include <com/sun/star/frame/XDispatchProvider.hpp>
42 #include <com/sun/star/frame/XFrame.hpp>
43 #include <com/sun/star/util/URLTransformer.hpp>
44 #include <com/sun/star/util/XURLTransformer.hpp>
45 #include <comphelper/processfactory.hxx>
46 #include <sfx2/viewfrm.hxx>
47 #include <sfx2/docfile.hxx>
48 #include <sfx2/docfilt.hxx>
49 #include <fmtornt.hxx>
50 #include <tabcol.hxx>
51 #include <fmtfsize.hxx>
52 #include <fmthdft.hxx>
53 #include <fmtpdsc.hxx>
54 #include <uiitems.hxx>
55 #include <docsh.hxx>
56 #include <wrtsh.hxx>
57 #include <swmodule.hxx>
58 #include <view.hxx>
59 #include <uitool.hxx>
60 #include <frmatr.hxx>
61 #include <paratr.hxx>
62 #include <fmtcol.hxx>
63 #include <usrpref.hxx>
65 #include <cmdid.h>
66 #include <doc.hxx>
67 #include <charfmt.hxx>
68 #include <SwStyleNameMapper.hxx>
69 #include <strings.hrc>
70 #include <docmodel/color/ComplexColor.hxx>
72 // 50 cm 28350
73 #define MAXHEIGHT 28350
74 #define MAXWIDTH 28350
76 using namespace ::com::sun::star;
78 // General list of string pointer
80 // Set boxinfo attribute
82 void PrepareBoxInfo(SfxItemSet& rSet, const SwWrtShell& rSh)
84 std::shared_ptr<SvxBoxInfoItem> aBoxInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER));
86 if ( const SvxBoxInfoItem *pBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER ))
88 aBoxInfo.reset(pBoxInfo->Clone());
91 // Table variant: If more than one table cells are selected
92 rSh.GetCursor(); //So that GetCursorCnt() returns the right thing
93 aBoxInfo->SetTable (rSh.IsTableMode() && rSh.GetCursorCnt() > 1);
94 // Always show the distance field
95 aBoxInfo->SetDist (true);
96 // Set minimal size in tables and paragraphs
97 aBoxInfo->SetMinDist (rSh.IsTableMode() || rSh.GetSelectionType() & (SelectionType::Text | SelectionType::Table));
98 // Set always the default distance
99 aBoxInfo->SetDefDist (MIN_BORDER_DIST);
100 // Single lines can have only in tables DontCare-Status
101 aBoxInfo->SetValid(SvxBoxInfoItemValidFlags::DISABLE, !rSh.IsTableMode());
103 rSet.Put(*aBoxInfo);
106 void ConvertAttrCharToGen(SfxItemSet& rSet, bool bIsPara)
108 // Background / highlight
110 // Always use the visible background
111 if( const SvxBrushItem *pTmpBrush = rSet.GetItemIfSet( RES_CHRATR_HIGHLIGHT ) )
113 SvxBrushItem aTmpBrush( *pTmpBrush );
114 if( aTmpBrush.GetColor() != COL_TRANSPARENT )
116 aTmpBrush.SetWhich( RES_CHRATR_BACKGROUND );
117 rSet.Put( aTmpBrush );
122 if ( bIsPara )
123 return;
125 // Tell dialogs to use character-specific slots/whichIds
126 // tdf#126684: We use RES_PARATR_GRABBAG, because RES_CHRATR_GRABBAG may be overwritten later in
127 // SwDocStyleSheet::GetItemSet when applying attributes from char format
128 assert(SfxItemState::SET != rSet.GetItemState(RES_PARATR_GRABBAG, false));
129 SfxGrabBagItem aGrabBag(RES_PARATR_GRABBAG);
130 aGrabBag.GetGrabBag()["DialogUseCharAttr"] <<= true;
131 // Store initial ranges to allow restoring later
132 uno::Sequence<sal_uInt16> aOrigRanges(rSet.GetRanges().size() * 2 + 1);
133 int i = 0;
134 for (const auto& rPair : rSet.GetRanges())
136 aOrigRanges.getArray()[i++] = rPair.first;
137 aOrigRanges.getArray()[i++] = rPair.second;
139 aOrigRanges.getArray()[i++] = 0;
140 aGrabBag.GetGrabBag()["OrigItemSetRanges"] <<= aOrigRanges;
141 rSet.MergeRange(RES_PARATR_GRABBAG, RES_PARATR_GRABBAG);
142 rSet.Put(aGrabBag);
145 void ConvertAttrGenToChar(SfxItemSet& rSet, const SfxItemSet& rOrigSet, bool bIsPara)
147 // Background / highlighting
148 if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_BACKGROUND, false ) )
150 // Highlight is an MS specific thing, so remove it at the first time when LO modifies
151 // this part of the imported document.
152 rSet.Put( SvxBrushItem(RES_CHRATR_HIGHLIGHT) );
154 // Remove shading marker
155 if (const SfxGrabBagItem* pGrabBagItem = rOrigSet.GetItemIfSet(RES_CHRATR_GRABBAG, false))
157 SfxGrabBagItem aGrabBag(*pGrabBagItem);
158 std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
159 auto aIterator = rMap.find("CharShadingMarker");
160 if( aIterator != rMap.end() )
162 aIterator->second <<= false;
164 rSet.Put( aGrabBag );
168 if ( bIsPara )
169 return;
171 rSet.ClearItem( RES_BACKGROUND );
173 if (const SfxGrabBagItem* pGrabBagItem = rOrigSet.GetItemIfSet(RES_PARATR_GRABBAG, false))
175 SfxGrabBagItem aGrabBag(*pGrabBagItem);
176 std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
177 auto aIterator = rMap.find("OrigItemSetRanges");
178 if (aIterator != rMap.end())
180 uno::Sequence<sal_uInt16> aOrigRanges;
181 if ( aIterator->second >>= aOrigRanges )
183 assert(aOrigRanges.getLength() % 2 == 1);
184 int numPairs = (aOrigRanges.getLength()-1)/2;
185 std::unique_ptr<WhichPair[]> xPairs(new WhichPair[numPairs]);
186 for(int i=0; i<aOrigRanges.getLength()-1; i += 2)
188 xPairs[i/2] = { aOrigRanges[i], aOrigRanges[i+1] };
190 rSet.SetRanges(WhichRangesContainer(std::move(xPairs), numPairs));
194 assert(SfxItemState::SET != rSet.GetItemState(RES_PARATR_GRABBAG, false));
197 void ApplyCharBackground(Color const& rBackgroundColor, model::ComplexColor const& rComplexColor, SwWrtShell& rShell)
199 rShell.StartUndo(SwUndoId::INSATTR);
201 SfxItemSetFixed<RES_CHRATR_GRABBAG, RES_CHRATR_GRABBAG> aCoreSet(rShell.GetView().GetPool());
203 rShell.GetCurAttr(aCoreSet);
205 // Set char background
206 rShell.SetAttrItem(SvxBrushItem(rBackgroundColor, rComplexColor, RES_CHRATR_BACKGROUND));
208 // Highlight is an MS specific thing, so remove it at the first time when LO modifies
209 // this part of the imported document.
210 rShell.SetAttrItem(SvxBrushItem(RES_CHRATR_HIGHLIGHT));
212 // Remove shading marker
213 if (const SfxGrabBagItem* pGrabBagItem = aCoreSet.GetItemIfSet(RES_CHRATR_GRABBAG, false))
215 SfxGrabBagItem aGrabBag(*pGrabBagItem);
216 std::map<OUString, css::uno::Any>& rMap = aGrabBag.GetGrabBag();
217 auto aIterator = rMap.find("CharShadingMarker");
218 if (aIterator != rMap.end())
220 aIterator->second <<= false;
222 rShell.SetAttrItem(aGrabBag);
225 rShell.EndUndo(SwUndoId::INSATTR);
228 // Fill header footer
230 static void FillHdFt(SwFrameFormat* pFormat, const SfxItemSet& rSet)
232 SwAttrSet aSet(pFormat->GetAttrSet());
233 aSet.Put(rSet);
235 const SvxSizeItem& rSize = rSet.Get(SID_ATTR_PAGE_SIZE);
236 const SfxBoolItem& rDynamic = rSet.Get(SID_ATTR_PAGE_DYNAMIC);
238 // Convert size
239 SwFormatFrameSize aFrameSize(rDynamic.GetValue() ? SwFrameSize::Minimum : SwFrameSize::Fixed,
240 rSize.GetSize().Width(),
241 rSize.GetSize().Height());
242 aSet.Put(aFrameSize);
243 pFormat->SetFormatAttr(aSet);
246 /// Convert from UseOnPage to SvxPageUsage.
247 static SvxPageUsage lcl_convertUseToSvx(UseOnPage nUse)
249 SvxPageUsage nRet = SvxPageUsage::NONE;
250 if (nUse & UseOnPage::Left)
251 nRet = SvxPageUsage::Left;
252 if (nUse & UseOnPage::Right)
253 nRet = SvxPageUsage::Right;
254 if ((nUse & UseOnPage::All) == UseOnPage::All)
255 nRet = SvxPageUsage::All;
256 if ((nUse & UseOnPage::Mirror) == UseOnPage::Mirror)
257 nRet = SvxPageUsage::Mirror;
258 return nRet;
261 /// Convert from SvxPageUsage to UseOnPage.
262 static UseOnPage lcl_convertUseFromSvx(SvxPageUsage nUse)
264 UseOnPage nRet = UseOnPage::NONE;
265 if (nUse == SvxPageUsage::Left)
266 nRet = UseOnPage::Left;
267 else if (nUse == SvxPageUsage::Right)
268 nRet = UseOnPage::Right;
269 else if (nUse == SvxPageUsage::All)
270 nRet = UseOnPage::All;
271 else if (nUse == SvxPageUsage::Mirror)
272 nRet = UseOnPage::Mirror;
273 return nRet;
276 // PageDesc <-> convert into sets and back
278 void ItemSetToPageDesc( const SfxItemSet& rSet, SwPageDesc& rPageDesc )
280 SwFrameFormat& rMaster = rPageDesc.GetMaster();
281 bool bFirstShare = false;
283 // before SetFormatAttr() in case it contains RES_BACKGROUND_FULL_SIZE
284 // itself, as it does when called from SwXPageStyle
285 if (const SfxGrabBagItem* pGrabBag = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
287 bool bValue;
288 if (pGrabBag->GetGrabBag().find("BackgroundFullSize")->second >>= bValue)
290 rMaster.SetFormatAttr(SfxBoolItem(RES_BACKGROUND_FULL_SIZE, bValue));
292 auto it = pGrabBag->GetGrabBag().find("RtlGutter");
293 if (it != pGrabBag->GetGrabBag().end() && (it->second >>= bValue))
295 rMaster.SetFormatAttr(SfxBoolItem(RES_RTL_GUTTER, bValue));
299 // Transfer all general frame attributes
300 rMaster.SetFormatAttr(rSet);
302 // PageData
303 if(rSet.GetItemState(SID_ATTR_PAGE) == SfxItemState::SET)
305 const SvxPageItem& rPageItem = rSet.Get(SID_ATTR_PAGE);
307 const SvxPageUsage nUse = rPageItem.GetPageUsage();
308 if(nUse != SvxPageUsage::NONE)
309 rPageDesc.SetUseOn( lcl_convertUseFromSvx(nUse) );
310 rPageDesc.SetLandscape(rPageItem.IsLandscape());
311 SvxNumberType aNumType;
312 aNumType.SetNumberingType( rPageItem.GetNumType() );
313 rPageDesc.SetNumType(aNumType);
315 // Size
316 if(rSet.GetItemState(SID_ATTR_PAGE_SIZE) == SfxItemState::SET)
318 const SvxSizeItem& rSizeItem = rSet.Get(SID_ATTR_PAGE_SIZE);
319 SwFormatFrameSize aSize(SwFrameSize::Fixed);
320 aSize.SetSize(rSizeItem.GetSize());
321 rMaster.SetFormatAttr(aSize);
323 // Evaluate header attributes
324 if( const SvxSetItem* pHeaderSetItem = rSet.GetItemIfSet( SID_ATTR_PAGE_HEADERSET,
325 false ) )
327 const SfxItemSet& rHeaderSet = pHeaderSetItem->GetItemSet();
328 const SfxBoolItem& rHeaderOn = rHeaderSet.Get(SID_ATTR_PAGE_ON);
330 if(rHeaderOn.GetValue())
332 // Take over values
333 if(!rMaster.GetHeader().IsActive())
334 rMaster.SetFormatAttr(SwFormatHeader(true));
336 // Pick out everything and adapt the header format
337 SwFormatHeader aHeaderFormat(rMaster.GetHeader());
338 SwFrameFormat *pHeaderFormat = aHeaderFormat.GetHeaderFormat();
339 OSL_ENSURE(pHeaderFormat != nullptr, "no header format");
341 ::FillHdFt(pHeaderFormat, rHeaderSet);
343 rPageDesc.ChgHeaderShare(rHeaderSet.Get(SID_ATTR_PAGE_SHARED).GetValue());
344 rPageDesc.ChgFirstShare(static_cast<const SfxBoolItem&>(
345 rHeaderSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
346 bFirstShare = true;
348 else
350 // Disable header
351 if(rMaster.GetHeader().IsActive())
353 rMaster.SetFormatAttr(SwFormatHeader(false));
354 rPageDesc.ChgHeaderShare(false);
359 // Evaluate footer attributes
360 if( const SvxSetItem* pFooterSetItem = rSet.GetItemIfSet( SID_ATTR_PAGE_FOOTERSET,
361 false ) )
363 const SfxItemSet& rFooterSet = pFooterSetItem->GetItemSet();
364 const SfxBoolItem& rFooterOn = rFooterSet.Get(SID_ATTR_PAGE_ON);
366 if(rFooterOn.GetValue())
368 // Take over values
369 if(!rMaster.GetFooter().IsActive())
370 rMaster.SetFormatAttr(SwFormatFooter(true));
372 // Pick out everything and adapt the footer format
373 SwFormatFooter aFooterFormat(rMaster.GetFooter());
374 SwFrameFormat *pFooterFormat = aFooterFormat.GetFooterFormat();
375 OSL_ENSURE(pFooterFormat != nullptr, "no footer format");
377 ::FillHdFt(pFooterFormat, rFooterSet);
379 rPageDesc.ChgFooterShare(rFooterSet.Get(SID_ATTR_PAGE_SHARED).GetValue());
380 if (!bFirstShare)
382 rPageDesc.ChgFirstShare(static_cast<const SfxBoolItem&>(
383 rFooterSet.Get(SID_ATTR_PAGE_SHARED_FIRST)).GetValue());
386 else
388 // Disable footer
389 if(rMaster.GetFooter().IsActive())
391 rMaster.SetFormatAttr(SwFormatFooter(false));
392 rPageDesc.ChgFooterShare(false);
397 // Footnotes
399 if( const SwPageFootnoteInfoItem* pFootnoteItem = rSet.GetItemIfSet( FN_PARAM_FTN_INFO,
400 false ) )
401 rPageDesc.SetFootnoteInfo( pFootnoteItem->GetPageFootnoteInfo() );
403 // Columns
405 // Register compliant
407 const SfxBoolItem* pRegisterModeItem = rSet.GetItemIfSet(
408 SID_SWREGISTER_MODE, false);
409 if(!pRegisterModeItem)
410 return;
412 bool bSet = pRegisterModeItem->GetValue();
413 if(!bSet)
414 rPageDesc.SetRegisterFormatColl(nullptr);
415 else if(const SfxStringItem* pCollectionItem = rSet.GetItemIfSet(
416 SID_SWREGISTER_COLLECTION, false))
418 const OUString& rColl = pCollectionItem->GetValue();
419 SwDoc& rDoc = *rMaster.GetDoc();
420 SwTextFormatColl* pColl = rDoc.FindTextFormatCollByName( rColl );
421 if( !pColl )
423 const sal_uInt16 nId = SwStyleNameMapper::GetPoolIdFromUIName(
424 rColl, SwGetPoolIdFromName::TxtColl );
425 if( USHRT_MAX != nId )
426 pColl = rDoc.getIDocumentStylePoolAccess().GetTextCollFromPool( nId );
427 else
428 pColl = rDoc.MakeTextFormatColl( rColl,
429 rDoc.GetDfltTextFormatColl() );
431 if( pColl )
432 pColl->SetFormatAttr( SwRegisterItem ( true ));
433 rPageDesc.SetRegisterFormatColl( pColl );
437 namespace
439 bool IsOwnFormat(const SwDoc& rDoc)
441 const SwDocShell* pDocShell = rDoc.GetDocShell();
442 SfxMedium* pMedium = pDocShell->GetMedium();
443 if (!pMedium)
445 return false;
448 std::shared_ptr<const SfxFilter> pFilter = pMedium->GetFilter();
449 if (!pFilter)
451 return false;
454 return pFilter->IsOwnFormat();
458 void PageDescToItemSet( const SwPageDesc& rPageDesc, SfxItemSet& rSet)
460 const SwFrameFormat& rMaster = rPageDesc.GetMaster();
462 // Page data
463 SvxPageItem aPageItem(SID_ATTR_PAGE);
464 aPageItem.SetDescName(rPageDesc.GetName());
465 aPageItem.SetPageUsage(lcl_convertUseToSvx(rPageDesc.GetUseOn()));
466 aPageItem.SetLandscape(rPageDesc.GetLandscape());
467 aPageItem.SetNumType(rPageDesc.GetNumType().GetNumberingType());
468 rSet.Put(aPageItem);
470 // Size
471 SvxSizeItem aSizeItem(SID_ATTR_PAGE_SIZE, rMaster.GetFrameSize().GetSize());
472 rSet.Put(aSizeItem);
474 // Maximum size
475 SvxSizeItem aMaxSizeItem(SID_ATTR_PAGE_MAXSIZE, Size(MAXWIDTH, MAXHEIGHT));
476 rSet.Put(aMaxSizeItem);
478 // Margins, border and the other stuff.
479 rSet.Put(rMaster.GetAttrSet());
481 std::shared_ptr<SvxBoxInfoItem> aBoxInfo(std::make_shared<SvxBoxInfoItem>(SID_ATTR_BORDER_INNER));
483 if ( const SvxBoxInfoItem *pBoxInfo = rSet.GetItemIfSet( SID_ATTR_BORDER_INNER ) )
485 aBoxInfo.reset(pBoxInfo->Clone());
488 aBoxInfo->SetTable( false );
489 // Show always the distance field
490 aBoxInfo->SetDist( true);
491 // Set minimal size in tables and paragraphs
492 aBoxInfo->SetMinDist( false );
493 // Set always the default distance
494 aBoxInfo->SetDefDist( MIN_BORDER_DIST );
495 // Single lines can have only in tables DontCare-Status
496 aBoxInfo->SetValid( SvxBoxInfoItemValidFlags::DISABLE );
497 rSet.Put( *aBoxInfo );
499 SfxStringItem aFollow(SID_ATTR_PAGE_EXT1, OUString());
500 if(rPageDesc.GetFollow())
501 aFollow.SetValue(rPageDesc.GetFollow()->GetName());
502 rSet.Put(aFollow);
504 // Header
505 if(rMaster.GetHeader().IsActive())
507 const SwFormatHeader &rHeaderFormat = rMaster.GetHeader();
508 const SwFrameFormat *pHeaderFormat = rHeaderFormat.GetHeaderFormat();
509 OSL_ENSURE(pHeaderFormat != nullptr, "no header format");
511 // HeaderInfo, margins, background, border
512 SfxItemSetFixed<RES_FRMATR_BEGIN,RES_FRMATR_END - 1, // [82
514 // FillAttribute support
515 XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014
517 SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023
518 SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051
519 SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060
520 SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST> aHeaderSet(*rSet.GetPool());
522 // set correct parent to get the XFILL_NONE FillStyle as needed
523 aHeaderSet.SetParent(&rMaster.GetDoc()->GetDfltFrameFormat()->GetAttrSet());
525 // Dynamic or fixed height
526 SfxBoolItem aOn(SID_ATTR_PAGE_ON, true);
527 aHeaderSet.Put(aOn);
529 const SwFormatFrameSize &rFrameSize = pHeaderFormat->GetFrameSize();
530 const SwFrameSize eSizeType = rFrameSize.GetHeightSizeType();
531 SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != SwFrameSize::Fixed);
532 aHeaderSet.Put(aDynamic);
534 // Left equal right
535 SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsHeaderShared());
536 aHeaderSet.Put(aShared);
537 SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
538 aHeaderSet.Put(aFirstShared);
540 // Size
541 SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, rFrameSize.GetSize());
542 aHeaderSet.Put(aSize);
544 // Shifting frame attributes
545 aHeaderSet.Put(pHeaderFormat->GetAttrSet());
546 aHeaderSet.Put( *aBoxInfo );
548 // Create SetItem
549 SvxSetItem aSetItem(SID_ATTR_PAGE_HEADERSET, aHeaderSet);
550 rSet.Put(aSetItem);
553 // Footer
554 if(rMaster.GetFooter().IsActive())
556 const SwFormatFooter &rFooterFormat = rMaster.GetFooter();
557 const SwFrameFormat *pFooterFormat = rFooterFormat.GetFooterFormat();
558 OSL_ENSURE(pFooterFormat != nullptr, "no footer format");
560 // FooterInfo, margins, background, border
561 SfxItemSetFixed<RES_FRMATR_BEGIN,RES_FRMATR_END - 1, // [82
563 // FillAttribute support
564 XATTR_FILL_FIRST, XATTR_FILL_LAST, // [1014
566 SID_ATTR_BORDER_INNER,SID_ATTR_BORDER_INNER, // [10023
567 SID_ATTR_PAGE_SIZE,SID_ATTR_PAGE_SIZE, // [10051
568 SID_ATTR_PAGE_ON,SID_ATTR_PAGE_SHARED, // [10060
569 SID_ATTR_PAGE_SHARED_FIRST,SID_ATTR_PAGE_SHARED_FIRST> aFooterSet(*rSet.GetPool());
571 // set correct parent to get the XFILL_NONE FillStyle as needed
572 aFooterSet.SetParent(&rMaster.GetDoc()->GetDfltFrameFormat()->GetAttrSet());
574 // Dynamic or fixed height
575 SfxBoolItem aOn(SID_ATTR_PAGE_ON, true);
576 aFooterSet.Put(aOn);
578 const SwFormatFrameSize &rFrameSize = pFooterFormat->GetFrameSize();
579 const SwFrameSize eSizeType = rFrameSize.GetHeightSizeType();
580 SfxBoolItem aDynamic(SID_ATTR_PAGE_DYNAMIC, eSizeType != SwFrameSize::Fixed);
581 aFooterSet.Put(aDynamic);
583 // Left equal right
584 SfxBoolItem aShared(SID_ATTR_PAGE_SHARED, rPageDesc.IsFooterShared());
585 aFooterSet.Put(aShared);
586 SfxBoolItem aFirstShared(SID_ATTR_PAGE_SHARED_FIRST, rPageDesc.IsFirstShared());
587 aFooterSet.Put(aFirstShared);
589 // Size
590 SvxSizeItem aSize(SID_ATTR_PAGE_SIZE, rFrameSize.GetSize());
591 aFooterSet.Put(aSize);
593 // Shifting Frame attributes
594 aFooterSet.Put(pFooterFormat->GetAttrSet());
595 aFooterSet.Put( *aBoxInfo );
597 // Create SetItem
598 SvxSetItem aSetItem(SID_ATTR_PAGE_FOOTERSET, aFooterSet);
599 rSet.Put(aSetItem);
602 // Integrate footnotes
603 SwPageFootnoteInfo& rInfo = const_cast<SwPageFootnoteInfo&>(rPageDesc.GetFootnoteInfo());
604 SwPageFootnoteInfoItem aFootnoteItem(rInfo);
605 rSet.Put(aFootnoteItem);
607 // Register compliant
608 const SwTextFormatColl* pCol = rPageDesc.GetRegisterFormatColl();
609 SwRegisterItem aReg(pCol != nullptr);
610 aReg.SetWhich(SID_SWREGISTER_MODE);
611 rSet.Put(aReg);
612 if(pCol)
613 rSet.Put(SfxStringItem(SID_SWREGISTER_COLLECTION, pCol->GetName()));
615 std::optional<SfxGrabBagItem> oGrabBag;
616 if (SfxGrabBagItem const* pItem = rSet.GetItemIfSet(SID_ATTR_CHAR_GRABBAG))
618 oGrabBag.emplace(*pItem);
620 else
622 oGrabBag.emplace(SID_ATTR_CHAR_GRABBAG);
624 oGrabBag->GetGrabBag()["BackgroundFullSize"] <<=
625 rMaster.GetAttrSet().GetItem<SfxBoolItem>(RES_BACKGROUND_FULL_SIZE)->GetValue();
627 if (IsOwnFormat(*rMaster.GetDoc()))
629 oGrabBag->GetGrabBag()["RtlGutter"]
630 <<= rMaster.GetAttrSet().GetItem<SfxBoolItem>(RES_RTL_GUTTER)->GetValue();
633 rSet.Put(*oGrabBag);
636 // Set DefaultTabs
638 void MakeDefTabs(SwTwips nDefDist, SvxTabStopItem& rTabs)
640 if( rTabs.Count() )
641 return;
643 SvxTabStop aSwTabStop( nDefDist, SvxTabAdjust::Default );
644 rTabs.Insert( aSwTabStop );
648 // Distance between two tabs
650 SwTwips GetTabDist(const SvxTabStopItem& rTabs)
652 return rTabs.Count() ? rTabs[0].GetTabPos() : 1134; // 1134 = 2 cm
655 // Inquire if in the set is a Sfx-PageDesc combination present and return it.
656 void SfxToSwPageDescAttr( const SwWrtShell& rShell, SfxItemSet& rSet )
658 const SfxPoolItem* pItem;
659 SwFormatPageDesc aPgDesc;
661 bool bChanged = false;
662 // Page number
663 switch (rSet.GetItemState(SID_ATTR_PARA_PAGENUM, false, &pItem))
665 case SfxItemState::SET:
667 aPgDesc.SetNumOffset(static_cast<const SfxUInt16Item*>(pItem)->GetValue());
668 bChanged = true;
669 break;
671 case SfxItemState::DISABLED:
673 bChanged = true; // default initialised aPgDesc clears the number
674 break;
676 case SfxItemState::UNKNOWN:
677 case SfxItemState::DEFAULT:
678 break;
679 default:
680 assert(false); // unexpected
681 break;
683 if( const SvxPageModelItem* pModelItem = rSet.GetItemIfSet( SID_ATTR_PARA_MODEL, false ))
685 const OUString& rDescName = pModelItem->GetValue();
686 if( !rDescName.isEmpty() ) // No name -> disable PageDesc!
688 // Delete only, if PageDesc will be enabled!
689 rSet.ClearItem( RES_BREAK );
690 SwPageDesc* pDesc = const_cast<SwWrtShell&>(rShell).FindPageDescByName(
691 rDescName, true );
692 if( pDesc )
693 aPgDesc.RegisterToPageDesc( *pDesc );
695 rSet.ClearItem( SID_ATTR_PARA_MODEL );
696 bChanged = true;
698 else
700 SfxItemSetFixed<RES_PAGEDESC, RES_PAGEDESC> aCoreSet(rShell.GetView().GetPool());
701 rShell.GetCurAttr( aCoreSet );
702 if(const SwFormatPageDesc* pPageDescItem = aCoreSet.GetItemIfSet( RES_PAGEDESC ) )
704 const SwPageDesc* pPageDesc = pPageDescItem->GetPageDesc();
705 if( pPageDesc )
707 aPgDesc.RegisterToPageDesc( *const_cast<SwPageDesc*>(pPageDesc) );
712 if(bChanged)
713 rSet.Put( aPgDesc );
716 // Inquire if in the set is a Sfx-PageDesc combination present and return it.
717 void SwToSfxPageDescAttr( SfxItemSet& rCoreSet )
719 const SwFormatPageDesc* pPageDescItem = nullptr;
720 OUString aName;
721 ::std::optional<sal_uInt16> oNumOffset;
722 bool bPut = true;
723 switch( rCoreSet.GetItemState( RES_PAGEDESC, true, &pPageDescItem ) )
725 case SfxItemState::SET:
727 if( pPageDescItem->GetPageDesc() )
729 aName = pPageDescItem->GetPageDesc()->GetName();
730 oNumOffset = pPageDescItem->GetNumOffset();
732 rCoreSet.ClearItem( RES_PAGEDESC );
733 // Page number
735 break;
737 case SfxItemState::DEFAULT:
738 break;
740 default:
741 bPut = false;
744 if (oNumOffset)
746 SfxUInt16Item aPageNum( SID_ATTR_PARA_PAGENUM, *oNumOffset );
747 rCoreSet.Put( aPageNum );
750 if(bPut)
751 rCoreSet.Put( SvxPageModelItem( aName, true, SID_ATTR_PARA_MODEL ) );
754 // Determine metric
756 FieldUnit GetDfltMetric(bool bWeb)
758 return SW_MOD()->GetUsrPref(bWeb)->GetMetric();
761 // Determine metric
763 void SetDfltMetric( FieldUnit eMetric, bool bWeb )
765 SW_MOD()->ApplyUserMetric(eMetric, bWeb);
768 void InsertStringSorted(const OUString& rId, const OUString& rEntry, weld::ComboBox& rToFill, int nOffset)
770 CollatorWrapper& rCaseColl = ::GetAppCaseCollator();
771 const int nCount = rToFill.get_count();
772 while (nOffset < nCount)
774 if (0 < rCaseColl.compareString(rToFill.get_text(nOffset), rEntry))
775 break;
776 ++nOffset;
778 rToFill.insert(nOffset, rEntry, &rId, nullptr, nullptr);
781 void FillCharStyleListBox(weld::ComboBox& rToFill, SwDocShell* pDocSh, bool bSorted, bool bWithDefault)
783 const int nOffset = rToFill.get_count() > 0 ? 1 : 0;
784 rToFill.freeze();
785 SfxStyleSheetBasePool* pPool = pDocSh->GetStyleSheetPool();
786 SwDoc* pDoc = pDocSh->GetDoc();
787 const SfxStyleSheetBase* pBase = pPool->First(SfxStyleFamily::Char);
788 const OUString sStandard(SwResId(STR_POOLCHR_STANDARD));
789 while(pBase)
791 if(bWithDefault || pBase->GetName() != sStandard)
793 sal_IntPtr nPoolId = SwStyleNameMapper::GetPoolIdFromUIName( pBase->GetName(), SwGetPoolIdFromName::ChrFmt );
794 OUString sId(OUString::number(nPoolId));
795 if (bSorted)
796 InsertStringSorted(sId, pBase->GetName(), rToFill, nOffset);
797 else
798 rToFill.append(sId, pBase->GetName());
800 pBase = pPool->Next();
802 // non-pool styles
803 const SwCharFormats* pFormats = pDoc->GetCharFormats();
804 for(size_t i = 0; i < pFormats->size(); ++i)
806 const SwCharFormat* pFormat = (*pFormats)[i];
807 if(pFormat->IsDefault())
808 continue;
809 const OUString& rName = pFormat->GetName();
810 if (rToFill.find_text(rName) == -1)
812 OUString sId(OUString::number(USHRT_MAX));
813 if (bSorted)
814 InsertStringSorted(sId, rName, rToFill, nOffset);
815 else
816 rToFill.append(sId, rName);
819 rToFill.thaw();
822 SwTwips GetTableWidth( SwFrameFormat const * pFormat, SwTabCols const & rCols, sal_uInt16 *pPercent,
823 SwWrtShell* pSh )
825 // To get the width is slightly more complicated.
826 SwTwips nWidth = 0;
827 const sal_Int16 eOri = pFormat->GetHoriOrient().GetHoriOrient();
828 switch(eOri)
830 case text::HoriOrientation::FULL: nWidth = rCols.GetRight(); break;
831 case text::HoriOrientation::LEFT_AND_WIDTH:
832 case text::HoriOrientation::LEFT:
833 case text::HoriOrientation::RIGHT:
834 case text::HoriOrientation::CENTER:
835 nWidth = pFormat->GetFrameSize().GetWidth();
836 break;
837 default:
839 if(pSh)
841 if ( nullptr == pSh->GetFlyFrameFormat() )
843 nWidth = pSh->GetAnyCurRect(CurRectType::PagePrt).Width();
845 else
847 nWidth = pSh->GetAnyCurRect(CurRectType::FlyEmbeddedPrt).Width();
850 else
852 OSL_FAIL("where to get the actual width from?");
854 const SvxLRSpaceItem& rLRSpace = pFormat->GetLRSpace();
855 nWidth -= (rLRSpace.GetRight() + rLRSpace.GetLeft());
858 if (pPercent)
859 *pPercent = pFormat->GetFrameSize().GetWidthPercent();
860 return nWidth;
863 OUString GetAppLangDateTimeString( const DateTime& rDT )
865 const SvtSysLocale aSysLocale;
866 const LocaleDataWrapper& rAppLclData = aSysLocale.GetLocaleData();
867 OUString sRet = rAppLclData.getDate( rDT ) + " " + rAppLclData.getTime( rDT );
868 return sRet;
871 // Add a new function which can get and set the current "SID_ATTR_APPLYCHARUNIT" value
873 bool HasCharUnit( bool bWeb)
875 return SW_MOD()->GetUsrPref(bWeb)->IsApplyCharUnit();
878 void SetApplyCharUnit(bool bApplyChar, bool bWeb)
880 SW_MOD()->ApplyUserCharUnit(bApplyChar, bWeb);
883 bool ExecuteMenuCommand(const css::uno::Reference<css::awt::XPopupMenu>& rMenu, const SfxViewFrame& rViewFrame, sal_uInt16 nId)
885 bool bRet = false;
886 const sal_uInt16 nItemCount = rMenu->getItemCount();
887 OUString sCommand;
888 for (sal_uInt16 nItem = 0; nItem < nItemCount; ++nItem)
890 sal_Int16 nItemId = rMenu->getItemId(nItem);
891 css::uno::Reference<css::awt::XPopupMenu> xPopup = rMenu->getPopupMenu(nItemId);
892 if (xPopup.is())
894 sCommand = xPopup->getCommand(nId);
895 if(!sCommand.isEmpty())
896 break;
899 if(!sCommand.isEmpty())
901 uno::Reference< frame::XFrame > xFrame = rViewFrame.GetFrame().GetFrameInterface();
902 uno::Reference < frame::XDispatchProvider > xProv( xFrame, uno::UNO_QUERY );
903 util::URL aURL;
904 aURL.Complete = sCommand;
905 uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create(::comphelper::getProcessComponentContext() ) );
906 xTrans->parseStrict( aURL );
907 uno::Reference< frame::XDispatch > xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
908 if( xDisp.is() )
910 uno::Sequence< beans::PropertyValue > aSeq;
911 xDisp->dispatch( aURL, aSeq );
912 bRet = true;
915 return bRet;
918 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */