LibreOffice Module sw (master)  1
edattr.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <memory>
21 #include <hintids.hxx>
22 #include <editeng/tstpitem.hxx>
23 #include <editeng/lrspitem.hxx>
24 #include <com/sun/star/i18n/ScriptType.hpp>
25 #include <com/sun/star/i18n/XBreakIterator.hpp>
26 #include <osl/diagnose.h>
27 #include <txatbase.hxx>
28 #include <txtftn.hxx>
29 #include <fmtftn.hxx>
30 #include <editsh.hxx>
31 #include <edimp.hxx>
32 #include <doc.hxx>
33 #include <swundo.hxx>
34 #include <ndtxt.hxx>
35 #include <ftnidx.hxx>
36 #include <expfld.hxx>
37 #include <rootfrm.hxx>
38 #include <cntfrm.hxx>
39 #include <breakit.hxx>
40 #include <fmtfld.hxx>
41 #include <txtfrm.hxx>
42 #include <scriptinfo.hxx>
43 #include <svl/itemiter.hxx>
44 #include <svl/languageoptions.hxx>
45 #include <charfmt.hxx>
46 #include <numrule.hxx>
47 
48 /*
49  * hard Formatting (Attributes)
50  */
51 
52 // if selection is bigger as max nodes or more than max selections
53 // => no attributes
54 static sal_uInt16 getMaxLookup()
55 {
56  return 10000;
57 }
58 
60  const bool bMergeIndentValuesOfNumRule ) const
61 {
62  // ??? pPaM can be different from the Cursor ???
63  if( GetCursorCnt() > getMaxLookup() )
64  {
65  rSet.InvalidateAllItems();
66  return false;
67  }
68 
69  SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() );
70  SfxItemSet *pSet = &rSet;
71 
72  for(SwPaM& rCurrentPaM : pPaM->GetRingContainer())
73  {
74  // #i27615# if the cursor is in front of the numbering label
75  // the attributes to get are those from the numbering format.
76  if (rCurrentPaM.IsInFrontOfLabel())
77  {
78  SwTextNode const*const pTextNd = sw::GetParaPropsNode(*GetLayout(),
79  rCurrentPaM.GetPoint()->nNode);
80 
81  if (pTextNd)
82  {
83  SwNumRule * pNumRule = pTextNd->GetNumRule();
84 
85  if (pNumRule)
86  {
87  int nListLevel = pTextNd->GetActualListLevel();
88 
89  if (nListLevel < 0)
90  nListLevel = 0;
91 
92  if (nListLevel >= MAXLEVEL)
93  nListLevel = MAXLEVEL - 1;
94 
95  const OUString & aCharFormatName =
96  pNumRule->Get(o3tl::narrowing<sal_uInt16>(nListLevel)).GetCharFormatName();
97  SwCharFormat * pCharFormat =
98  GetDoc()->FindCharFormatByName(aCharFormatName);
99 
100  if (pCharFormat)
101  rSet.Put(pCharFormat->GetAttrSet());
102  }
103  }
104 
105  continue;
106  }
107 
108  sal_uLong nSttNd = rCurrentPaM.GetMark()->nNode.GetIndex(),
109  nEndNd = rCurrentPaM.GetPoint()->nNode.GetIndex();
110  sal_Int32 nSttCnt = rCurrentPaM.GetMark()->nContent.GetIndex();
111  sal_Int32 nEndCnt = rCurrentPaM.GetPoint()->nContent.GetIndex();
112 
113  if( nSttNd > nEndNd || ( nSttNd == nEndNd && nSttCnt > nEndCnt ))
114  {
115  std::swap(nSttNd, nEndNd);
116  std::swap(nSttCnt, nEndCnt);
117  }
118 
119  if( nEndNd - nSttNd >= getMaxLookup() )
120  {
121  rSet.ClearItem();
122  rSet.InvalidateAllItems();
123  return false;
124  }
125 
126  // at first node the node enter his values into the GetSet (Initial)
127  // all additional nodes are additional merged to GetSet
128  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
129  {
130  SwNode* pNd = GetDoc()->GetNodes()[ n ];
131  switch( pNd->GetNodeType() )
132  {
133  case SwNodeType::Text:
134  {
135  const sal_Int32 nStt = (n == nSttNd) ? nSttCnt : 0;
136  const sal_Int32 nEnd = (n == nEndNd)
137  ? nEndCnt
138  : pNd->GetTextNode()->GetText().getLength();
139 
140  static_cast<SwTextNode*>(pNd)->GetParaAttr(*pSet, nStt, nEnd,
141  false, true,
142  bMergeIndentValuesOfNumRule,
143  GetLayout());
144  }
145  break;
146  case SwNodeType::Grf:
147  case SwNodeType::Ole:
148  static_cast<SwContentNode*>(pNd)->GetAttr( *pSet );
149  break;
150 
151  default:
152  pNd = nullptr;
153  }
154 
155  if( pNd )
156  {
157  if( pSet != &rSet )
158  {
159  if (!GetLayout()->HasMergedParas()
161  {
162  rSet.MergeValues( aSet );
163  }
164  }
165 
166  if( aSet.Count() )
167  aSet.ClearItem();
168  }
169  pSet = &aSet;
170  }
171 
172  }
173 
174  return true;
175 }
176 
178  const bool bMergeIndentValuesOfNumRule ) const
179 {
180  return GetPaMAttr( GetCursor(), rSet, bMergeIndentValuesOfNumRule );
181 }
182 
184 {
185  GetPaMParAttr( GetCursor(), rSet );
186 }
187 
188 void SwEditShell::GetPaMParAttr( SwPaM* pPaM, SfxItemSet& rSet ) const
189 {
190  // number of nodes the function has explored so far
191  sal_uInt16 numberOfLookup = 0;
192 
193  SfxItemSet aSet( *rSet.GetPool(), rSet.GetRanges() );
194  SfxItemSet* pSet = &rSet;
195 
196  for(SwPaM& rCurrentPaM : pPaM->GetRingContainer())
197  { // for all the point and mark (selections)
198 
199  // get the start and the end node of the current selection
200  sal_uLong nSttNd = rCurrentPaM.GetMark()->nNode.GetIndex(),
201  nEndNd = rCurrentPaM.GetPoint()->nNode.GetIndex();
202 
203  // reverse start and end if there number aren't sorted correctly
204  if( nSttNd > nEndNd )
205  std::swap(nSttNd, nEndNd);
206 
207  // for all the nodes in the current selection
208  // get the node (paragraph) attributes
209  // and merge them in rSet
210  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
211  {
212  // get the node
213  SwNode* pNd = GetDoc()->GetNodes()[ n ];
214 
215  if (GetLayout()->HasMergedParas()
217  {
218  continue;
219  }
220 
221  if( pNd->IsTextNode() )
222  {
223  // get the node (paragraph) attributes
224  sw::GetAttrMerged(*pSet, *pNd->GetTextNode(), GetLayout());
225 
226  if( pSet != &rSet && aSet.Count() )
227  {
228  rSet.MergeValues( aSet );
229  aSet.ClearItem();
230  }
231 
232  pSet = &aSet;
233  }
234 
235  ++numberOfLookup;
236 
237  // if the maximum number of node that can be inspected has been reached
238  if (numberOfLookup >= getMaxLookup())
239  return;
240  }
241  }
242 }
243 
245 {
246  return GetPaMTextFormatColl( GetCursor() );
247 }
248 
250 {
251  // number of nodes the function have explored so far
252  sal_uInt16 numberOfLookup = 0;
253 
254  for(SwPaM& rCurrentPaM : pPaM->GetRingContainer())
255  { // for all the point and mark (selections)
256 
257  // get the start and the end node of the current selection
258  sal_uLong nSttNd = rCurrentPaM.GetMark()->nNode.GetIndex(),
259  nEndNd = rCurrentPaM.GetPoint()->nNode.GetIndex();
260 
261  // reverse start and end if they aren't sorted correctly
262  if( nSttNd > nEndNd )
263  std::swap(nSttNd, nEndNd);
264 
265  // for all the nodes in the current Point and Mark
266  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
267  {
268  // get the node
269  SwNode* pNd = GetDoc()->GetNodes()[ n ];
270 
271  ++numberOfLookup;
272 
273  // if the maximum number of node that can be inspected has been reached
274  if (numberOfLookup >= getMaxLookup())
275  return nullptr;
276 
277  if( pNd->IsTextNode() )
278  {
279  SwTextNode *const pTextNode(sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pNd)));
280  // if it's a text node get its named paragraph format
281  SwTextFormatColl *const pFormat = pTextNode->GetTextColl();
282 
283  // if the paragraph format exist stop here and return it
284  if( pFormat != nullptr )
285  return pFormat;
286  }
287  }
288  }
289 
290  // if none of the selected node contain a named paragraph format
291  return nullptr;
292 }
293 
294 std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> SwEditShell::GetItemWithPaM( sal_uInt16 nWhich )
295 {
296  assert(isCHRATR(nWhich)); // sw_redlinehide: only thing that works
297  std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> vItem;
298  for(SwPaM& rCurrentPaM : GetCursor()->GetRingContainer())
299  { // for all the point and mark (selections)
300 
301  // get the start and the end node of the current selection
302  sal_uLong nSttNd = rCurrentPaM.Start()->nNode.GetIndex(),
303  nEndNd = rCurrentPaM.End()->nNode.GetIndex();
304  sal_Int32 nSttCnt = rCurrentPaM.Start()->nContent.GetIndex();
305  sal_Int32 nEndCnt = rCurrentPaM.End()->nContent.GetIndex();
306 
307  SwPaM* pNewPaM = nullptr;
308  const SfxPoolItem* pItem = nullptr;
309 
310  // for all the nodes in the current selection
311  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
312  {
313  SwNode* pNd = GetDoc()->GetNodes()[ n ];
314  if( pNd->IsTextNode() )
315  {
316  SwTextNode* pTextNd = static_cast< SwTextNode* >( pNd );
317  const sal_Int32 nStt = (n == nSttNd) ? nSttCnt : 0;
318  const sal_Int32 nEnd = (n == nEndNd)
319  ? nEndCnt : pTextNd->GetText().getLength();
320  SwTextFrame const* pFrame;
321  const SwScriptInfo *const pScriptInfo =
322  SwScriptInfo::GetScriptInfo(*pTextNd, &pFrame);
323  TextFrameIndex const iStt(pScriptInfo
324  ? pFrame->MapModelToView(pTextNd, nStt)
325  : TextFrameIndex(-1/*invalid, do not use*/));
326  sal_uInt8 nScript = pScriptInfo
327  ? pScriptInfo->ScriptType(iStt)
328  : css::i18n::ScriptType::WEAK;
329  nWhich = GetWhichOfScript( nWhich, nScript );
330 
331  // item from attribute set
332  if( pTextNd->HasSwAttrSet() )
333  {
334  pNewPaM = new SwPaM(*pNd, nStt, *pNd, nEnd);
335  pItem = pTextNd->GetSwAttrSet().GetItem( nWhich );
336  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
337  }
338 
339  if( !pTextNd->HasHints() )
340  continue;
341 
342  // items with limited range
343  const size_t nSize = pTextNd->GetpSwpHints()->Count();
344  for( size_t m = 0; m < nSize; m++ )
345  {
346  const SwTextAttr* pHt = pTextNd->GetpSwpHints()->Get(m);
347  if( pHt->Which() == RES_TXTATR_AUTOFMT ||
348  pHt->Which() == RES_TXTATR_CHARFMT ||
349  pHt->Which() == RES_TXTATR_INETFMT )
350  {
351  const sal_Int32 nAttrStart = pHt->GetStart();
352  const sal_Int32* pAttrEnd = pHt->End();
353 
354  // Ignore items not in selection
355  if( nAttrStart > nEnd )
356  break;
357  if( *pAttrEnd <= nStt )
358  continue;
359 
360  nScript = pScriptInfo
361  ? pScriptInfo->ScriptType(iStt)
362  : css::i18n::ScriptType::WEAK;
363  nWhich = GetWhichOfScript( nWhich, nScript );
364  const SfxItemSet* pAutoSet = CharFormat::GetItemSet( pHt->GetAttr() );
365  if( pAutoSet )
366  {
367  SfxItemIter aItemIter( *pAutoSet );
368  pItem = aItemIter.GetCurItem();
369  while( pItem )
370  {
371  if( pItem->Which() == nWhich )
372  {
373  sal_Int32 nStart = 0, nStop = 0;
374  if( nAttrStart < nStt ) // Attribute starts before selection
375  nStart = nStt;
376  else
377  nStart = nAttrStart;
378  if( *pAttrEnd > nEnd ) // Attribute ends after selection
379  nStop = nEnd;
380  else
381  nStop = *pAttrEnd;
382  pNewPaM = new SwPaM(*pNd, nStart, *pNd, nStop);
383  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
384  break;
385  }
386  pItem = aItemIter.NextItem();
387  }
388  // default item
389  if( !pItem && !pTextNd->HasSwAttrSet() )
390  {
391  pNewPaM = new SwPaM(*pNd, nStt, *pNd, nEnd);
392  pItem = pAutoSet->GetPool()->GetPoolDefaultItem( nWhich );
393  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
394  }
395  }
396  }
397  }
398  }
399  }
400  }
401  return vItem;
402 }
403 
405 {
406  // The cursor must be positioned on the current footnotes anchor:
407  SwPaM* pCursor = GetCursor();
408  SwTextNode* pTextNd = pCursor->GetNode().GetTextNode();
409  if( !pTextNd )
410  return false;
411 
412  SwTextAttr *const pFootnote = pTextNd->GetTextAttrForCharAt(
413  pCursor->GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN);
414  if( pFootnote && pFillFootnote )
415  {
416  // Transfer data from the attribute
417  const SwFormatFootnote &rFootnote = static_cast<SwTextFootnote*>(pFootnote)->GetFootnote();
418  pFillFootnote->SetNumber( rFootnote );
419  pFillFootnote->SetEndNote( rFootnote.IsEndNote() );
420  }
421  return nullptr != pFootnote;
422 }
423 
424 bool SwEditShell::SetCurFootnote( const SwFormatFootnote& rFillFootnote )
425 {
426  bool bChgd = false;
427  StartAllAction();
428 
429  for(const SwPaM& rCursor : GetCursor()->GetRingContainer())
430  {
431  bChgd |=
432  mxDoc->SetCurFootnote(rCursor, rFillFootnote.GetNumStr(), rFillFootnote.IsEndNote());
433 
434  }
435 
436  EndAllAction();
437  return bChgd;
438 }
439 
440 bool SwEditShell::HasFootnotes( bool bEndNotes ) const
441 {
442  const SwFootnoteIdxs &rIdxs = mxDoc->GetFootnoteIdxs();
443  for ( auto pIdx : rIdxs )
444  {
445  const SwFormatFootnote &rFootnote = pIdx->GetFootnote();
446  if ( bEndNotes == rFootnote.IsEndNote() )
447  return true;
448  }
449  return false;
450 }
451 
453 size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes )
454 {
455  rList.Clear();
456 
457  IDocumentRedlineAccess & rIDRA(mxDoc->getIDocumentRedlineAccess());
458 
459  const size_t nFootnoteCnt = mxDoc->GetFootnoteIdxs().size();
460  SwTextFootnote* pTextFootnote;
461  for( size_t n = 0; n < nFootnoteCnt; ++n )
462  {
463  pTextFootnote = mxDoc->GetFootnoteIdxs()[ n ];
464  const SwFormatFootnote& rFootnote = pTextFootnote->GetFootnote();
465  if ( rFootnote.IsEndNote() != bEndNotes )
466  continue;
467 
468  SwNodeIndex* pIdx = pTextFootnote->GetStartNode();
469  if( pIdx )
470  {
471  SwNodeIndex aIdx( *pIdx, 1 );
472  SwTextNode* pTextNd = aIdx.GetNode().GetTextNode();
473  if( !pTextNd )
474  pTextNd = static_cast<SwTextNode*>(mxDoc->GetNodes().GoNext( &aIdx ));
475 
476  if( pTextNd )
477  {
478  if (GetLayout()->IsHideRedlines()
479  && sw::IsFootnoteDeleted(rIDRA, *pTextFootnote))
480  {
481  continue;
482  }
483 
484  OUString sText(rFootnote.GetViewNumStr(*mxDoc, GetLayout()));
485  if( !sText.isEmpty() )
486  sText += " ";
487  sText += pTextNd->GetExpandText(GetLayout());
488 
489  SeqFieldLstElem aNew( sText, pTextFootnote->GetSeqRefNo() );
490  while( rList.InsertSort( aNew ) )
491  aNew.sDlgEntry += " ";
492  }
493  }
494  }
495 
496  return rList.Count();
497 }
498 
500 bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const
501 {
502  bool bRet = true;
503 
504  const SvxTabStopItem& rTabItem = GetDoc()->GetDefault( RES_PARATR_TABSTOP );
505  sal_uInt16 nDefDist = o3tl::narrowing<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134);
506  if( !nDefDist )
507  return false;
508 
509  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
510  {
511  sal_uLong nSttNd = rPaM.GetMark()->nNode.GetIndex(),
512  nEndNd = rPaM.GetPoint()->nNode.GetIndex();
513 
514  if( nSttNd > nEndNd )
515  std::swap(nSttNd, nEndNd);
516 
517  SwContentNode* pCNd;
518  for( sal_uLong n = nSttNd; bRet && n <= nEndNd; ++n )
519  {
520  pCNd = GetDoc()->GetNodes()[ n ]->GetTextNode();
521  if( nullptr != pCNd )
522  {
523  pCNd = sw::GetParaPropsNode(*GetLayout(), *pCNd);
524  const SvxLRSpaceItem& rLS = static_cast<const SvxLRSpaceItem&>(
525  pCNd->GetAttr( RES_LR_SPACE ));
526  if( bRight )
527  {
528  tools::Long nNext = rLS.GetTextLeft() + nDefDist;
529  if( bModulus )
530  nNext = ( nNext / nDefDist ) * nDefDist;
531  SwFrame* pFrame = pCNd->getLayoutFrame( GetLayout() );
532  if ( pFrame )
533  {
534  const sal_uInt32 nFrameWidth = o3tl::narrowing<sal_uInt32>( pFrame->IsVertical() ?
535  pFrame->getFrameArea().Height() :
536  pFrame->getFrameArea().Width() );
537  bRet = o3tl::narrowing<SwTwips>(nFrameWidth) > ( nNext + MM50 );
538  }
539  else
540  bRet = false;
541  }
542  }
543  }
544 
545  if( !bRet )
546  break;
547 
548  }
549  return bRet;
550 }
551 
552 void SwEditShell::MoveLeftMargin( bool bRight, bool bModulus )
553 {
554  StartAllAction();
556 
557  SwPaM* pCursor = GetCursor();
558  if( pCursor->GetNext() != pCursor ) // Multiple selection ?
559  {
560  SwPamRanges aRangeArr( *pCursor );
561  SwPaM aPam( *pCursor->GetPoint() );
562  for( size_t n = 0; n < aRangeArr.Count(); ++n )
563  GetDoc()->MoveLeftMargin( aRangeArr.SetPam( n, aPam ),
564  bRight, bModulus, GetLayout() );
565  }
566  else
567  GetDoc()->MoveLeftMargin( *pCursor, bRight, bModulus, GetLayout() );
568 
570  EndAllAction();
571 }
572 
573 static SvtScriptType lcl_SetScriptFlags( sal_uInt16 nType )
574 {
575  switch( nType )
576  {
577  case css::i18n::ScriptType::LATIN:
578  return SvtScriptType::LATIN;
579  case css::i18n::ScriptType::ASIAN:
580  return SvtScriptType::ASIAN;
581  case css::i18n::ScriptType::COMPLEX:
582  return SvtScriptType::COMPLEX;
583  default:
584  return SvtScriptType::NONE;
585  }
586 }
587 
588 static bool lcl_IsNoEndTextAttrAtPos(SwRootFrame const& rLayout,
589  const SwTextNode& rTNd, sal_Int32 const nPos,
590  SvtScriptType &rScrpt, bool bInSelection, bool bNum )
591 {
592  bool bRet = false;
593  OUString sExp;
594 
595  // consider numbering
596  if ( bNum )
597  {
598  bRet = false;
599  SwTextNode const*const pPropsNode(sw::GetParaPropsNode(rLayout, rTNd));
600  if (pPropsNode->IsInList())
601  {
602  OSL_ENSURE( pPropsNode->GetNumRule(),
603  "<lcl_IsNoEndTextAttrAtPos(..)> - no list style found at text node. Serious defect." );
604  const SwNumRule* pNumRule = pPropsNode->GetNumRule();
605  if(pNumRule)
606  {
607  int nListLevel = pPropsNode->GetActualListLevel();
608 
609  if (nListLevel < 0)
610  nListLevel = 0;
611 
612  if (nListLevel >= MAXLEVEL)
613  nListLevel = MAXLEVEL - 1;
614 
615  const SwNumFormat &rNumFormat = pNumRule->Get( o3tl::narrowing<sal_uInt16>(nListLevel) );
616  if( SVX_NUM_BITMAP != rNumFormat.GetNumberingType() )
617  {
618  if ( SVX_NUM_CHAR_SPECIAL == rNumFormat.GetNumberingType() )
619  {
620  sal_UCS4 cBullet = rNumFormat.GetBulletChar();
621  sExp = OUString(&cBullet, 1);
622  }
623  else
624  sExp = pPropsNode->GetNumString(true, MAXLEVEL, &rLayout);
625  }
626  }
627  }
628  }
629 
630  // and fields
631  if (nPos < rTNd.GetText().getLength() && CH_TXTATR_BREAKWORD == rTNd.GetText()[nPos])
632  {
633  const SwTextAttr* const pAttr = rTNd.GetTextAttrForCharAt( nPos );
634  if (pAttr)
635  {
636  bRet = true; // all other than fields can be
637  // defined as weak-script ?
638  if ( RES_TXTATR_FIELD == pAttr->Which() )
639  {
640  const SwField* const pField = pAttr->GetFormatField().GetField();
641  if (pField)
642  {
643  sExp += pField->ExpandField(true, &rLayout);
644  }
645  }
646  }
647  }
648 
649  const sal_Int32 nEnd = sExp.getLength();
650  if ( nEnd )
651  {
652  if( bInSelection )
653  {
654  sal_uInt16 nScript;
655  for( sal_Int32 n = 0; n < nEnd;
656  n = g_pBreakIt->GetBreakIter()->endOfScript( sExp, n, nScript ))
657  {
658  nScript = g_pBreakIt->GetBreakIter()->getScriptType( sExp, n );
659  rScrpt |= lcl_SetScriptFlags( nScript );
660  }
661  }
662  else
664  getScriptType( sExp, nEnd-1 ));
665  }
666 
667  return bRet;
668 }
669 
672 {
673  SvtScriptType nRet = SvtScriptType::NONE;
674 
675  {
676  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
677  {
678  const SwPosition *pStt = rPaM.Start(),
679  *pEnd = pStt == rPaM.GetMark()
680  ? rPaM.GetPoint()
681  : rPaM.GetMark();
682  if( pStt == pEnd || *pStt == *pEnd )
683  {
684  const SwTextNode* pTNd = pStt->nNode.GetNode().GetTextNode();
685  if( pTNd )
686  {
687  // try to get SwScriptInfo
688  SwTextFrame const* pFrame;
689  const SwScriptInfo *const pScriptInfo =
690  SwScriptInfo::GetScriptInfo(*pTNd, &pFrame);
691 
692  sal_Int32 nPos = pStt->nContent.GetIndex();
693  //Task 90448: we need the scripttype of the previous
694  // position, if no selection exist!
695  if( nPos )
696  {
697  SwIndex aIdx( pStt->nContent );
698  if( pTNd->GoPrevious( &aIdx, CRSR_SKIP_CHARS ) )
699  nPos = aIdx.GetIndex();
700  }
701 
702  sal_uInt16 nScript;
703 
704  if (!pTNd->GetText().isEmpty())
705  {
706  nScript = pScriptInfo
707  ? pScriptInfo->ScriptType(pFrame->MapModelToView(pTNd, nPos))
708  : g_pBreakIt->GetBreakIter()->getScriptType( pTNd->GetText(), nPos );
709  }
710  else
712 
713  if (!lcl_IsNoEndTextAttrAtPos(*GetLayout(), *pTNd, nPos, nRet, false, false))
714  nRet |= lcl_SetScriptFlags( nScript );
715  }
716  }
717  else
718  {
719  sal_uLong nEndIdx = pEnd->nNode.GetIndex();
720  SwNodeIndex aIdx( pStt->nNode );
721  for( ; aIdx.GetIndex() <= nEndIdx; ++aIdx )
722  if( aIdx.GetNode().IsTextNode() )
723  {
724  const SwTextNode* pTNd = aIdx.GetNode().GetTextNode();
725  const OUString& rText = pTNd->GetText();
726 
727  // try to get SwScriptInfo
728  SwTextFrame const* pFrame;
729  const SwScriptInfo *const pScriptInfo =
730  SwScriptInfo::GetScriptInfo(*pTNd, &pFrame);
731 
732  sal_Int32 nChg = aIdx == pStt->nNode
733  ? pStt->nContent.GetIndex()
734  : 0;
735  sal_Int32 nEndPos = aIdx == nEndIdx
736  ? pEnd->nContent.GetIndex()
737  : rText.getLength();
738 
739  OSL_ENSURE( nEndPos <= rText.getLength(),
740  "Index outside the range - endless loop!" );
741  if (nEndPos > rText.getLength())
742  nEndPos = rText.getLength();
743 
744  bool const isUntilEnd(pScriptInfo
745  ? pFrame->MapViewToModelPos(TextFrameIndex(pFrame->GetText().getLength())) <= *pEnd
746  : rText.getLength() == nEndPos);
747  sal_uInt16 nScript;
748  while( nChg < nEndPos )
749  {
750  TextFrameIndex iChg(pScriptInfo
751  ? pFrame->MapModelToView(pTNd, nChg)
752  : TextFrameIndex(-1/*invalid, do not use*/));
753  nScript = pScriptInfo ?
754  pScriptInfo->ScriptType( iChg ) :
755  g_pBreakIt->GetBreakIter()->getScriptType(
756  rText, nChg );
757 
758  if (!lcl_IsNoEndTextAttrAtPos(*GetLayout(), *pTNd, nChg, nRet, true,
759  TextFrameIndex(0) == iChg && isUntilEnd))
760  {
761  nRet |= lcl_SetScriptFlags( nScript );
762  }
763 
764  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
765  SvtScriptType::COMPLEX) == nRet )
766  break;
767 
768  sal_Int32 nFieldPos = nChg+1;
769 
770  if (pScriptInfo)
771  {
772  iChg = pScriptInfo->NextScriptChg(iChg);
773  if (iChg == TextFrameIndex(COMPLETE_STRING))
774  {
775  nChg = pTNd->Len();
776  }
777  else
778  {
779  std::pair<SwTextNode*, sal_Int32> const tmp(
780  pFrame->MapViewToModel(iChg));
781  nChg = (tmp.first == pTNd)
782  ? tmp.second
783  : pTNd->Len();
784  }
785  }
786  else
787  {
788  nChg = g_pBreakIt->GetBreakIter()->endOfScript(
789  rText, nChg, nScript );
790  }
791 
792  nFieldPos = rText.indexOf(
793  CH_TXTATR_BREAKWORD, nFieldPos);
794  if ((-1 != nFieldPos) && (nFieldPos < nChg))
795  nChg = nFieldPos;
796  }
797  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
798  SvtScriptType::COMPLEX) == nRet )
799  break;
800  }
801  }
802  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
803  SvtScriptType::COMPLEX) == nRet )
804  break;
805 
806  }
807  }
808  if( nRet == SvtScriptType::NONE )
810  return nRet;
811 }
812 
814 {
815  const SwPaM* pCursor = GetCursor();
816  const SwPosition& rPos = *pCursor->GetPoint();
817  const SwTextNode* pTNd = rPos.nNode.GetNode().GetTextNode();
819  if( pTNd )
820  {
821  //JP 24.9.2001: if exist no selection, then get the language before
822  // the current character!
823  sal_Int32 nPos = rPos.nContent.GetIndex();
824  if( nPos && !pCursor->HasMark() )
825  --nPos;
826  nLang = pTNd->GetLang( nPos );
827  }
828  else
829  nLang = LANGUAGE_DONTKNOW;
830  return nLang;
831 }
832 
834 {
835  const SwPaM* pCursor = GetCursor();
836  const SwPosition* pStt = pCursor->Start();
837  const SwTextNode* pTNd = pStt->nNode.GetNode().GetTextNode();
838  OSL_ENSURE( pTNd, "no textnode available" );
839 
840  sal_uInt16 nScaleWidth;
841  if( pTNd )
842  {
843  SwTextFrame *const pFrame(static_cast<SwTextFrame *>(
844  pTNd->getLayoutFrame(GetLayout(), pStt)));
845  assert(pFrame); // shell cursor must be positioned in node with frame
846  TextFrameIndex const nStart(pFrame->MapModelToViewPos(*pStt));
847  TextFrameIndex const nEnd(
848  sw::FrameContainsNode(*pFrame, pCursor->End()->nNode.GetIndex())
849  ? pFrame->MapModelToViewPos(*pCursor->End())
850  : TextFrameIndex(pFrame->GetText().getLength()));
851  nScaleWidth = pFrame->GetScalingOfSelectedText(nStart, nEnd);
852  }
853  else
854  nScaleWidth = 100; // default are no scaling -> 100%
855  return nScaleWidth;
856 }
857 
858 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxNumType GetNumberingType() const
Base class of the Writer layout elements.
Definition: frame.hxx:313
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:158
void SetEndNote(bool b)
Definition: atrftn.cxx:173
SwNode & GetNode(bool bPoint=true) const
Definition: pam.hxx:223
SwTextFormatColl * GetCurTextFormatColl() const
Get the named paragraph format of the current selection.
Definition: edattr.cxx:244
Represents the style of a paragraph.
Definition: fmtcol.hxx:56
sal_uInt16 Count() const
Marks a position in the document model.
Definition: pam.hxx:35
constexpr TypedWhichId< SvxTabStopItem > RES_PARATR_TABSTOP(68)
SwTextNode const & GetAttrMerged(SfxItemSet &rFormatSet, SwTextNode const &rNode, SwRootFrame const *pLayout)
Definition: txtfrm.cxx:371
TextFrameIndex NextScriptChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1715
const SwField * GetField() const
Definition: fmtfld.hxx:110
sal_UCS4 GetBulletChar() const
SwPaM * GetCursor(bool bMakeTableCursor=true) const
Return pointer to the current shell cursor.
Definition: crsrsh.cxx:195
sal_uInt32 sal_UCS4
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:472
const OUString & GetText() const
Definition: ndtxt.hxx:215
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:223
SwNodeIndex nNode
Definition: pam.hxx:37
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:276
sal_uIntPtr sal_uLong
long Long
Base class of all fields.
Definition: fldbas.hxx:289
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1213
sal_Int64 n
const WhichRangesContainer & GetRanges() const
static SwScriptInfo * GetScriptInfo(const SwTextNode &rNode, SwTextFrame const **o_pFrame=nullptr, bool bAllowInvalid=false)
return a frame for the node, ScriptInfo is its member...
Definition: porlay.cxx:2442
OUString sDlgEntry
Definition: expfld.hxx:49
SwUndoId EndUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Closes parenthesis of nUndoId, not used by UI.
Definition: edws.cxx:234
bool IsFootnoteDeleted(IDocumentRedlineAccess const &rIDRA, SwTextFootnote const &rTextFootnote)
Definition: ftnidx.cxx:37
SwNode & GetNode() const
Definition: ndindex.hxx:119
static SvtScriptType lcl_SetScriptFlags(sal_uInt16 nType)
Definition: edattr.cxx:573
bool InsertSort(SeqFieldLstElem aNew)
Definition: expfld.cxx:730
bool IsEndNote() const
Definition: fmtftn.hxx:71
sal_uInt16 Which() const
Definition: txatbase.hxx:114
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1295
void GetCurParAttr(SfxItemSet &rSet) const
Get the paragraph format attribute(s) of the current selection.
Definition: edattr.cxx:183
void EndAllAction()
Definition: edws.cxx:97
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
int GetActualListLevel() const
Returns the actual list level of this text node, when it is a list item.
Definition: ndtxt.cxx:4087
OUString GetViewNumStr(const SwDoc &rDoc, SwRootFrame const *pLayout, bool bInclStrings=false) const
Returns string to be displayed of footnote / endnote.
Definition: atrftn.cxx:217
static LanguageType nLang
Definition: srtdlg.cxx:51
LanguageType GetCurLang() const
Definition: edattr.cxx:813
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3035
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:170
const SfxPoolItem * NextItem()
size_t Count()
Definition: expfld.hxx:64
SwNodeType GetNodeType() const
Definition: node.hxx:145
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:171
SwIndex nContent
Definition: pam.hxx:38
const SwRect & getFrameArea() const
Definition: frame.hxx:178
A wrapper around SfxPoolItem to store the start position of (usually) a text portion, with an optional end.
Definition: txatbase.hxx:41
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
const SfxPoolItem & GetDefault(sal_uInt16 nFormatHint) const
Get the default attribute in this document.
Definition: docfmt.cxx:653
sal_uLong GetIndex() const
Definition: ndindex.hxx:152
sal_Int32 GetStart() const
Definition: txatbase.hxx:86
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:91
void Width(tools::Long nNew)
Definition: swrect.hxx:187
static bool lcl_IsNoEndTextAttrAtPos(SwRootFrame const &rLayout, const SwTextNode &rTNd, sal_Int32 const nPos, SvtScriptType &rScrpt, bool bInSelection, bool bNum)
Definition: edattr.cxx:588
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:195
const OUString & GetNumStr() const
Definition: fmtftn.hxx:68
static SvtScriptType GetScriptTypeOfLanguage(LanguageType nLang)
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatFootnote > RES_TXTATR_FTN(58)
sal_uInt16 GetSeqRefNo() const
Definition: txtftn.hxx:64
SwPaM * GetNext()
Definition: pam.hxx:264
SwPaM & SetPam(size_t nArrPos, SwPaM &rPam)
Definition: ednumber.cxx:101
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
SVX_NUM_BITMAP
SVX_NUM_CHAR_SPECIAL
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
bool FrameContainsNode(SwContentFrame const &rFrame, sal_uLong nNodeIndex)
Definition: txtfrm.cxx:288
size_t Count() const
Definition: edimp.hxx:49
constexpr TypedWhichId< SwFormatField > RES_TXTATR_FIELD(RES_TXTATR_NOEND_BEGIN)
tools::Long GetTextLeft() const
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SvtScriptType
size_t Count() const
Definition: ndhints.hxx:142
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1269
SvtScriptType GetScriptType() const
returns the script type of the selection
Definition: edattr.cxx:671
SwTextAttr * Get(size_t nPos) const
Definition: ndhints.hxx:144
const SwPosition * GetPoint() const
Definition: pam.hxx:207
#define LANGUAGE_SYSTEM
sal_uInt16 Count() const
bool HasMark() const
A PaM marks a selection if Point and Mark are distinct positions.
Definition: pam.hxx:205
void MoveLeftMargin(bool bRight, bool bModulus=true)
Definition: edattr.cxx:552
SwUndoId StartUndo(SwUndoId eUndoId=SwUndoId::EMPTY, const SwRewriter *pRewriter=nullptr)
Undo: set up Undo parenthesis, return nUndoId of this parenthesis.
Definition: edws.cxx:223
static sal_Int16 GetI18NScriptTypeOfLanguage(LanguageType nLang)
Marks a character position inside a document model node.
Definition: index.hxx:33
const SfxItemSet * GetItemSet(const SfxPoolItem &rAttr)
Returns the item set associated with a character/inet/auto style.
Definition: atrstck.cxx:132
sal_uInt16 GetWhichOfScript(sal_uInt16 nWhich, sal_uInt16 nScript)
Definition: hints.cxx:190
SwNumRule * GetNumRule(bool bInParent=true) const
Returns numbering rule of this text node.
Definition: ndtxt.cxx:2798
#define LANGUAGE_DONTKNOW
sal_uInt16 GetCursorCnt(bool bAll=true) const
Get the number of elements in the ring of cursors.
Definition: crsrsh.cxx:2738
Marks a node in the document model.
Definition: ndindex.hxx:31
size_t GetSeqFootnoteList(SwSeqFieldList &rList, bool bEndNotes=false)
Give a List of all footnotes and their beginning texts.
Definition: edattr.cxx:453
bool HasSwAttrSet() const
Definition: node.hxx:451
ring_container GetRingContainer()
Definition: ring.hxx:240
void MergeValues(const SfxItemSet &rSet)
SfxItemPool * GetPool() const
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:204
std::pair< SwTextNode *, sal_Int32 > MapViewToModel(TextFrameIndex nIndex) const
map position in potentially merged text frame to SwPosition
Definition: txtfrm.cxx:1233
const SwPosition * Start() const
Definition: pam.hxx:212
std::vector< std::pair< const SfxPoolItem *, std::unique_ptr< SwPaM > > > GetItemWithPaM(sal_uInt16 nWhich)
Get RES_CHRATR_* items of one type in the current selection.
Definition: edattr.cxx:294
bool GetPaMAttr(SwPaM *pPaM, SfxItemSet &, const bool bMergeIndentValuesOfNumRule=false) const
Apply / remove attributes.
Definition: edattr.cxx:59
SwTextNode * GetParaPropsNode(SwRootFrame const &rLayout, SwNodeIndex const &rNode)
Definition: txtfrm.cxx:328
sal_uInt16 GetScalingOfSelectedText(TextFrameIndex nStt, TextFrameIndex nEnd)
Calculates the width of the text part specified by nStart and nEnd, the height of the line containing...
Definition: itratr.cxx:1254
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:62
const SwNumFormat & Get(sal_uInt16 i) const
Definition: number.cxx:79
SwCharFormat * FindCharFormatByName(const OUString &rName) const
Definition: doc.hxx:771
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool SetCurFootnote(const SwFormatFootnote &rFillFootnote)
Definition: edattr.cxx:424
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:79
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:465
void MoveLeftMargin(const SwPaM &rPam, bool bRight, bool bModulus, SwRootFrame const *pLayout=nullptr)
Adjust left margin via object bar (similar to adjustment of numerations).
Definition: docfmt.cxx:1629
sal_Int16 ScriptType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1728
OUString GetExpandText(SwRootFrame const *pLayout, const sal_Int32 nIdx=0, const sal_Int32 nLen=-1, const bool bWithNum=false, const bool bAddSpaceAfterListLabelStr=false, const bool bWithSpacesForLevel=false, const ExpandMode eAdditionalMode=ExpandMode::ExpandFootnote) const
add 4th optional parameter indicating, when that a spa...
Definition: ndtxt.cxx:3359
#define MM50
Definition: swtypes.hxx:55
bool IsMoveLeftMargin(bool bRight, bool bModulus=true) const
Adjust left margin via object bar (similar to adjustment of numerations).
Definition: edattr.cxx:500
unsigned char sal_uInt8
bool HasFootnotes(bool bEndNotes=false) const
Definition: edattr.cxx:440
TextFrameIndex MapModelToView(SwTextNode const *pNode, sal_Int32 nIndex) const
Definition: txtfrm.cxx:1254
sal_Int32 GetIndex() const
Definition: index.hxx:91
LanguageType GetAppLanguage()
Definition: init.cxx:722
SwNodes & GetNodes()
Definition: doc.hxx:409
const SwPosition * End() const
Definition: pam.hxx:217
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3364
const sal_Int32 * End() const
Definition: txatbase.hxx:152
bool GetCurFootnote(SwFormatFootnote *pToFillFootnote=nullptr)
Query and set footnote-text/number. Set... to current SSelection!
Definition: edattr.cxx:404
void SetNumber(const SwFormatFootnote &rFootnote)
Definition: fmtftn.hxx:76
constexpr TypedWhichId< SvxLRSpaceItem > RES_LR_SPACE(91)
bool IsHideRedlines() const
Replacement for sw::DocumentRedlineManager::GetRedlineFlags() (this is layout-level redline hiding)...
Definition: rootfrm.hxx:422
bool GetCurAttr(SfxItemSet &, const bool bMergeIndentValuesOfNumRule=false) const
Definition: edattr.cxx:177
SwTextFormatColl * GetPaMTextFormatColl(SwPaM *pPaM) const
Get the named paragraph format of the selection(s) described by a SwPaM.
Definition: edattr.cxx:249
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:715
OUString GetNumString(const bool _bInclPrefixAndSuffixStrings=true, const unsigned int _nRestrictToThisLevel=MAXLEVEL, SwRootFrame const *pLayout=nullptr) const
Returns outline of numbering string.
Definition: ndtxt.cxx:3106
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:163
void GetPaMParAttr(SwPaM *pPaM, SfxItemSet &rSet) const
Get the paragraph format attribute(s) of the selection(s) described by a SwPaM.
Definition: edattr.cxx:188
static sal_uInt16 getMaxLookup()
Definition: edattr.cxx:54
bool IsVertical() const
Definition: frame.hxx:970
const sal_uInt16 CRSR_SKIP_CHARS
Definition: swcrsr.hxx:65
SwNodeIndex * GetStartNode() const
Definition: txtftn.hxx:41
void InvalidateAllItems()
bool IsInList() const
Definition: ndtxt.cxx:4329
bool HasMergedParas() const
Definition: rootfrm.hxx:426
tuple m
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:120
const SfxPoolItem & GetAttr(sal_uInt16 nWhich, bool bInParent=true) const
SS for PoolItems: hard attributation.
Definition: node.hxx:722
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
sal_uInt16 GetScalingOfSelectedText() const
Definition: edattr.cxx:833
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2067
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
bool IsTextNode() const
Definition: node.hxx:637
void Height(tools::Long nNew)
Definition: swrect.hxx:191
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1248
Merge GetRedlineMergeFlag() const
Definition: node.hxx:98
virtual OUString GetCharFormatName() const override
Definition: number.cxx:303
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
sal_uInt16 Which() const
bool GoPrevious(SwIndex *, sal_uInt16 nMode) const
Definition: node.cxx:1315
void Clear()
Definition: expfld.hxx:67
sal_uInt16 nPos
const SfxPoolItem * GetCurItem() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:850
bool HasHints() const
Definition: ndtxt.hxx:225
Base class of the Writer document model elements.
Definition: node.hxx:80
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:844