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(static_cast<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 bool 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 false;
240  }
241  }
242 
243  return true;
244 }
245 
247 {
248  return GetPaMTextFormatColl( GetCursor() );
249 }
250 
252 {
253  // number of nodes the function have explored so far
254  sal_uInt16 numberOfLookup = 0;
255 
256  for(SwPaM& rCurrentPaM : pPaM->GetRingContainer())
257  { // for all the point and mark (selections)
258 
259  // get the start and the end node of the current selection
260  sal_uLong nSttNd = rCurrentPaM.GetMark()->nNode.GetIndex(),
261  nEndNd = rCurrentPaM.GetPoint()->nNode.GetIndex();
262 
263  // reverse start and end if they aren't sorted correctly
264  if( nSttNd > nEndNd )
265  std::swap(nSttNd, nEndNd);
266 
267  // for all the nodes in the current Point and Mark
268  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
269  {
270  // get the node
271  SwNode* pNd = GetDoc()->GetNodes()[ n ];
272 
273  ++numberOfLookup;
274 
275  // if the maximum number of node that can be inspected has been reached
276  if (numberOfLookup >= getMaxLookup())
277  return nullptr;
278 
279  if( pNd->IsTextNode() )
280  {
281  SwTextNode *const pTextNode(sw::GetParaPropsNode(*GetLayout(), SwNodeIndex(*pNd)));
282  // if it's a text node get its named paragraph format
283  SwTextFormatColl *const pFormat = pTextNode->GetTextColl();
284 
285  // if the paragraph format exist stop here and return it
286  if( pFormat != nullptr )
287  return pFormat;
288  }
289  }
290  }
291 
292  // if none of the selected node contain a named paragraph format
293  return nullptr;
294 }
295 
296 std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> SwEditShell::GetItemWithPaM( sal_uInt16 nWhich )
297 {
298  assert(isCHRATR(nWhich)); // sw_redlinehide: only thing that works
299  std::vector<std::pair< const SfxPoolItem*, std::unique_ptr<SwPaM> >> vItem;
300  for(SwPaM& rCurrentPaM : GetCursor()->GetRingContainer())
301  { // for all the point and mark (selections)
302 
303  // get the start and the end node of the current selection
304  sal_uLong nSttNd = rCurrentPaM.Start()->nNode.GetIndex(),
305  nEndNd = rCurrentPaM.End()->nNode.GetIndex();
306  sal_Int32 nSttCnt = rCurrentPaM.Start()->nContent.GetIndex();
307  sal_Int32 nEndCnt = rCurrentPaM.End()->nContent.GetIndex();
308 
309  SwPaM* pNewPaM = nullptr;
310  const SfxPoolItem* pItem = nullptr;
311 
312  // for all the nodes in the current selection
313  for( sal_uLong n = nSttNd; n <= nEndNd; ++n )
314  {
315  SwNode* pNd = GetDoc()->GetNodes()[ n ];
316  if( pNd->IsTextNode() )
317  {
318  SwTextNode* pTextNd = static_cast< SwTextNode* >( pNd );
319  const sal_Int32 nStt = (n == nSttNd) ? nSttCnt : 0;
320  const sal_Int32 nEnd = (n == nEndNd)
321  ? nEndCnt : pTextNd->GetText().getLength();
322  SwTextFrame const* pFrame;
323  const SwScriptInfo *const pScriptInfo =
324  SwScriptInfo::GetScriptInfo(*pTextNd, &pFrame);
325  TextFrameIndex const iStt(pScriptInfo
326  ? pFrame->MapModelToView(pTextNd, nStt)
327  : TextFrameIndex(-1/*invalid, do not use*/));
328  sal_uInt8 nScript = pScriptInfo
329  ? pScriptInfo->ScriptType(iStt)
330  : css::i18n::ScriptType::WEAK;
331  nWhich = GetWhichOfScript( nWhich, nScript );
332 
333  // item from attribute set
334  if( pTextNd->HasSwAttrSet() )
335  {
336  pNewPaM = new SwPaM(*pNd, nStt, *pNd, nEnd);
337  pItem = pTextNd->GetSwAttrSet().GetItem( nWhich );
338  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
339  }
340 
341  if( !pTextNd->HasHints() )
342  continue;
343 
344  // items with limited range
345  const size_t nSize = pTextNd->GetpSwpHints()->Count();
346  for( size_t m = 0; m < nSize; m++ )
347  {
348  const SwTextAttr* pHt = pTextNd->GetpSwpHints()->Get(m);
349  if( pHt->Which() == RES_TXTATR_AUTOFMT ||
350  pHt->Which() == RES_TXTATR_CHARFMT ||
351  pHt->Which() == RES_TXTATR_INETFMT )
352  {
353  const sal_Int32 nAttrStart = pHt->GetStart();
354  const sal_Int32* pAttrEnd = pHt->End();
355 
356  // Ignore items not in selection
357  if( nAttrStart > nEnd )
358  break;
359  if( *pAttrEnd <= nStt )
360  continue;
361 
362  nScript = pScriptInfo
363  ? pScriptInfo->ScriptType(iStt)
364  : css::i18n::ScriptType::WEAK;
365  nWhich = GetWhichOfScript( nWhich, nScript );
366  const SfxItemSet* pAutoSet = CharFormat::GetItemSet( pHt->GetAttr() );
367  if( pAutoSet )
368  {
369  SfxItemIter aItemIter( *pAutoSet );
370  pItem = aItemIter.GetCurItem();
371  while( pItem )
372  {
373  if( pItem->Which() == nWhich )
374  {
375  sal_Int32 nStart = 0, nStop = 0;
376  if( nAttrStart < nStt ) // Attribute starts before selection
377  nStart = nStt;
378  else
379  nStart = nAttrStart;
380  if( *pAttrEnd > nEnd ) // Attribute ends after selection
381  nStop = nEnd;
382  else
383  nStop = *pAttrEnd;
384  pNewPaM = new SwPaM(*pNd, nStart, *pNd, nStop);
385  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
386  break;
387  }
388  pItem = aItemIter.NextItem();
389  }
390  // default item
391  if( !pItem && !pTextNd->HasSwAttrSet() )
392  {
393  pNewPaM = new SwPaM(*pNd, nStt, *pNd, nEnd);
394  pItem = pAutoSet->GetPool()->GetPoolDefaultItem( nWhich );
395  vItem.emplace_back( pItem, std::unique_ptr<SwPaM>(pNewPaM) );
396  }
397  }
398  }
399  }
400  }
401  }
402  }
403  return vItem;
404 }
405 
407 {
408  // The cursor must be positioned on the current footnotes anchor:
409  SwPaM* pCursor = GetCursor();
410  SwTextNode* pTextNd = pCursor->GetNode().GetTextNode();
411  if( !pTextNd )
412  return false;
413 
414  SwTextAttr *const pFootnote = pTextNd->GetTextAttrForCharAt(
415  pCursor->GetPoint()->nContent.GetIndex(), RES_TXTATR_FTN);
416  if( pFootnote && pFillFootnote )
417  {
418  // Transfer data from the attribute
419  const SwFormatFootnote &rFootnote = static_cast<SwTextFootnote*>(pFootnote)->GetFootnote();
420  pFillFootnote->SetNumber( rFootnote );
421  pFillFootnote->SetEndNote( rFootnote.IsEndNote() );
422  }
423  return nullptr != pFootnote;
424 }
425 
426 bool SwEditShell::SetCurFootnote( const SwFormatFootnote& rFillFootnote )
427 {
428  bool bChgd = false;
429  StartAllAction();
430 
431  for(const SwPaM& rCursor : GetCursor()->GetRingContainer())
432  {
433  bChgd |=
434  mxDoc->SetCurFootnote(rCursor, rFillFootnote.GetNumStr(), rFillFootnote.IsEndNote());
435 
436  }
437 
438  EndAllAction();
439  return bChgd;
440 }
441 
442 bool SwEditShell::HasFootnotes( bool bEndNotes ) const
443 {
444  const SwFootnoteIdxs &rIdxs = mxDoc->GetFootnoteIdxs();
445  for ( auto pIdx : rIdxs )
446  {
447  const SwFormatFootnote &rFootnote = pIdx->GetFootnote();
448  if ( bEndNotes == rFootnote.IsEndNote() )
449  return true;
450  }
451  return false;
452 }
453 
455 size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes )
456 {
457  rList.Clear();
458 
459  IDocumentRedlineAccess & rIDRA(mxDoc->getIDocumentRedlineAccess());
460 
461  const size_t nFootnoteCnt = mxDoc->GetFootnoteIdxs().size();
462  SwTextFootnote* pTextFootnote;
463  for( size_t n = 0; n < nFootnoteCnt; ++n )
464  {
465  pTextFootnote = mxDoc->GetFootnoteIdxs()[ n ];
466  const SwFormatFootnote& rFootnote = pTextFootnote->GetFootnote();
467  if ( rFootnote.IsEndNote() != bEndNotes )
468  continue;
469 
470  SwNodeIndex* pIdx = pTextFootnote->GetStartNode();
471  if( pIdx )
472  {
473  SwNodeIndex aIdx( *pIdx, 1 );
474  SwTextNode* pTextNd = aIdx.GetNode().GetTextNode();
475  if( !pTextNd )
476  pTextNd = static_cast<SwTextNode*>(mxDoc->GetNodes().GoNext( &aIdx ));
477 
478  if( pTextNd )
479  {
480  if (GetLayout()->IsHideRedlines()
481  && sw::IsFootnoteDeleted(rIDRA, *pTextFootnote))
482  {
483  continue;
484  }
485 
486  OUString sText(rFootnote.GetViewNumStr(*mxDoc, GetLayout()));
487  if( !sText.isEmpty() )
488  sText += " ";
489  sText += pTextNd->GetExpandText(GetLayout());
490 
491  SeqFieldLstElem aNew( sText, pTextFootnote->GetSeqRefNo() );
492  while( rList.InsertSort( aNew ) )
493  aNew.sDlgEntry += " ";
494  }
495  }
496  }
497 
498  return rList.Count();
499 }
500 
502 bool SwEditShell::IsMoveLeftMargin( bool bRight, bool bModulus ) const
503 {
504  bool bRet = true;
505 
506  const SvxTabStopItem& rTabItem = GetDoc()->GetDefault( RES_PARATR_TABSTOP );
507  sal_uInt16 nDefDist = static_cast<sal_uInt16>(rTabItem.Count() ? rTabItem[0].GetTabPos() : 1134);
508  if( !nDefDist )
509  return false;
510 
511  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
512  {
513  sal_uLong nSttNd = rPaM.GetMark()->nNode.GetIndex(),
514  nEndNd = rPaM.GetPoint()->nNode.GetIndex();
515 
516  if( nSttNd > nEndNd )
517  std::swap(nSttNd, nEndNd);
518 
519  SwContentNode* pCNd;
520  for( sal_uLong n = nSttNd; bRet && n <= nEndNd; ++n )
521  {
522  pCNd = GetDoc()->GetNodes()[ n ]->GetTextNode();
523  if( nullptr != pCNd )
524  {
525  pCNd = sw::GetParaPropsNode(*GetLayout(), *pCNd);
526  const SvxLRSpaceItem& rLS = static_cast<const SvxLRSpaceItem&>(
527  pCNd->GetAttr( RES_LR_SPACE ));
528  if( bRight )
529  {
530  tools::Long nNext = rLS.GetTextLeft() + nDefDist;
531  if( bModulus )
532  nNext = ( nNext / nDefDist ) * nDefDist;
533  SwFrame* pFrame = pCNd->getLayoutFrame( GetLayout() );
534  if ( pFrame )
535  {
536  const sal_uInt16 nFrameWidth = static_cast<sal_uInt16>( pFrame->IsVertical() ?
537  pFrame->getFrameArea().Height() :
538  pFrame->getFrameArea().Width() );
539  bRet = nFrameWidth > ( nNext + MM50 );
540  }
541  else
542  bRet = false;
543  }
544  }
545  }
546 
547  if( !bRet )
548  break;
549 
550  }
551  return bRet;
552 }
553 
554 void SwEditShell::MoveLeftMargin( bool bRight, bool bModulus )
555 {
556  StartAllAction();
558 
559  SwPaM* pCursor = GetCursor();
560  if( pCursor->GetNext() != pCursor ) // Multiple selection ?
561  {
562  SwPamRanges aRangeArr( *pCursor );
563  SwPaM aPam( *pCursor->GetPoint() );
564  for( size_t n = 0; n < aRangeArr.Count(); ++n )
565  GetDoc()->MoveLeftMargin( aRangeArr.SetPam( n, aPam ),
566  bRight, bModulus, GetLayout() );
567  }
568  else
569  GetDoc()->MoveLeftMargin( *pCursor, bRight, bModulus, GetLayout() );
570 
572  EndAllAction();
573 }
574 
575 static SvtScriptType lcl_SetScriptFlags( sal_uInt16 nType )
576 {
577  switch( nType )
578  {
579  case css::i18n::ScriptType::LATIN:
580  return SvtScriptType::LATIN;
581  case css::i18n::ScriptType::ASIAN:
582  return SvtScriptType::ASIAN;
583  case css::i18n::ScriptType::COMPLEX:
584  return SvtScriptType::COMPLEX;
585  default:
586  return SvtScriptType::NONE;
587  }
588 }
589 
590 static bool lcl_IsNoEndTextAttrAtPos(SwRootFrame const& rLayout,
591  const SwTextNode& rTNd, sal_Int32 const nPos,
592  SvtScriptType &rScrpt, bool bInSelection, bool bNum )
593 {
594  bool bRet = false;
595  OUString sExp;
596 
597  // consider numbering
598  if ( bNum )
599  {
600  bRet = false;
601  SwTextNode const*const pPropsNode(sw::GetParaPropsNode(rLayout, rTNd));
602  if (pPropsNode->IsInList())
603  {
604  OSL_ENSURE( pPropsNode->GetNumRule(),
605  "<lcl_IsNoEndTextAttrAtPos(..)> - no list style found at text node. Serious defect." );
606  const SwNumRule* pNumRule = pPropsNode->GetNumRule();
607  if(pNumRule)
608  {
609  int nListLevel = pPropsNode->GetActualListLevel();
610 
611  if (nListLevel < 0)
612  nListLevel = 0;
613 
614  if (nListLevel >= MAXLEVEL)
615  nListLevel = MAXLEVEL - 1;
616 
617  const SwNumFormat &rNumFormat = pNumRule->Get( static_cast<sal_uInt16>(nListLevel) );
618  if( SVX_NUM_BITMAP != rNumFormat.GetNumberingType() )
619  {
620  if ( SVX_NUM_CHAR_SPECIAL == rNumFormat.GetNumberingType() )
621  {
622  sal_UCS4 cBullet = rNumFormat.GetBulletChar();
623  sExp = OUString(&cBullet, 1);
624  }
625  else
626  sExp = pPropsNode->GetNumString(true, MAXLEVEL, &rLayout);
627  }
628  }
629  }
630  }
631 
632  // and fields
633  if (nPos < rTNd.GetText().getLength() && CH_TXTATR_BREAKWORD == rTNd.GetText()[nPos])
634  {
635  const SwTextAttr* const pAttr = rTNd.GetTextAttrForCharAt( nPos );
636  if (pAttr)
637  {
638  bRet = true; // all other than fields can be
639  // defined as weak-script ?
640  if ( RES_TXTATR_FIELD == pAttr->Which() )
641  {
642  const SwField* const pField = pAttr->GetFormatField().GetField();
643  if (pField)
644  {
645  sExp += pField->ExpandField(true, &rLayout);
646  }
647  }
648  }
649  }
650 
651  const sal_Int32 nEnd = sExp.getLength();
652  if ( nEnd )
653  {
654  if( bInSelection )
655  {
656  sal_uInt16 nScript;
657  for( sal_Int32 n = 0; n < nEnd;
658  n = g_pBreakIt->GetBreakIter()->endOfScript( sExp, n, nScript ))
659  {
660  nScript = g_pBreakIt->GetBreakIter()->getScriptType( sExp, n );
661  rScrpt |= lcl_SetScriptFlags( nScript );
662  }
663  }
664  else
666  getScriptType( sExp, nEnd-1 ));
667  }
668 
669  return bRet;
670 }
671 
674 {
675  SvtScriptType nRet = SvtScriptType::NONE;
676 
677  {
678  for(SwPaM& rPaM : GetCursor()->GetRingContainer())
679  {
680  const SwPosition *pStt = rPaM.Start(),
681  *pEnd = pStt == rPaM.GetMark()
682  ? rPaM.GetPoint()
683  : rPaM.GetMark();
684  if( pStt == pEnd || *pStt == *pEnd )
685  {
686  const SwTextNode* pTNd = pStt->nNode.GetNode().GetTextNode();
687  if( pTNd )
688  {
689  // try to get SwScriptInfo
690  SwTextFrame const* pFrame;
691  const SwScriptInfo *const pScriptInfo =
692  SwScriptInfo::GetScriptInfo(*pTNd, &pFrame);
693 
694  sal_Int32 nPos = pStt->nContent.GetIndex();
695  //Task 90448: we need the scripttype of the previous
696  // position, if no selection exist!
697  if( nPos )
698  {
699  SwIndex aIdx( pStt->nContent );
700  if( pTNd->GoPrevious( &aIdx, CRSR_SKIP_CHARS ) )
701  nPos = aIdx.GetIndex();
702  }
703 
704  sal_uInt16 nScript;
705 
706  if (!pTNd->GetText().isEmpty())
707  {
708  nScript = pScriptInfo
709  ? pScriptInfo->ScriptType(pFrame->MapModelToView(pTNd, nPos))
710  : g_pBreakIt->GetBreakIter()->getScriptType( pTNd->GetText(), nPos );
711  }
712  else
714 
715  if (!lcl_IsNoEndTextAttrAtPos(*GetLayout(), *pTNd, nPos, nRet, false, false))
716  nRet |= lcl_SetScriptFlags( nScript );
717  }
718  }
719  else
720  {
721  sal_uLong nEndIdx = pEnd->nNode.GetIndex();
722  SwNodeIndex aIdx( pStt->nNode );
723  for( ; aIdx.GetIndex() <= nEndIdx; ++aIdx )
724  if( aIdx.GetNode().IsTextNode() )
725  {
726  const SwTextNode* pTNd = aIdx.GetNode().GetTextNode();
727  const OUString& rText = pTNd->GetText();
728 
729  // try to get SwScriptInfo
730  SwTextFrame const* pFrame;
731  const SwScriptInfo *const pScriptInfo =
732  SwScriptInfo::GetScriptInfo(*pTNd, &pFrame);
733 
734  sal_Int32 nChg = aIdx == pStt->nNode
735  ? pStt->nContent.GetIndex()
736  : 0;
737  sal_Int32 nEndPos = aIdx == nEndIdx
738  ? pEnd->nContent.GetIndex()
739  : rText.getLength();
740 
741  OSL_ENSURE( nEndPos <= rText.getLength(),
742  "Index outside the range - endless loop!" );
743  if (nEndPos > rText.getLength())
744  nEndPos = rText.getLength();
745 
746  bool const isUntilEnd(pScriptInfo
747  ? pFrame->MapViewToModelPos(TextFrameIndex(pFrame->GetText().getLength())) <= *pEnd
748  : rText.getLength() == nEndPos);
749  sal_uInt16 nScript;
750  while( nChg < nEndPos )
751  {
752  TextFrameIndex iChg(pScriptInfo
753  ? pFrame->MapModelToView(pTNd, nChg)
754  : TextFrameIndex(-1/*invalid, do not use*/));
755  nScript = pScriptInfo ?
756  pScriptInfo->ScriptType( iChg ) :
757  g_pBreakIt->GetBreakIter()->getScriptType(
758  rText, nChg );
759 
760  if (!lcl_IsNoEndTextAttrAtPos(*GetLayout(), *pTNd, nChg, nRet, true,
761  TextFrameIndex(0) == iChg && isUntilEnd))
762  {
763  nRet |= lcl_SetScriptFlags( nScript );
764  }
765 
766  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
767  SvtScriptType::COMPLEX) == nRet )
768  break;
769 
770  sal_Int32 nFieldPos = nChg+1;
771 
772  if (pScriptInfo)
773  {
774  iChg = pScriptInfo->NextScriptChg(iChg);
775  if (iChg == TextFrameIndex(COMPLETE_STRING))
776  {
777  nChg = pTNd->Len();
778  }
779  else
780  {
781  std::pair<SwTextNode*, sal_Int32> const tmp(
782  pFrame->MapViewToModel(iChg));
783  nChg = (tmp.first == pTNd)
784  ? tmp.second
785  : pTNd->Len();
786  }
787  }
788  else
789  {
790  nChg = g_pBreakIt->GetBreakIter()->endOfScript(
791  rText, nChg, nScript );
792  }
793 
794  nFieldPos = rText.indexOf(
795  CH_TXTATR_BREAKWORD, nFieldPos);
796  if ((-1 != nFieldPos) && (nFieldPos < nChg))
797  nChg = nFieldPos;
798  }
799  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
800  SvtScriptType::COMPLEX) == nRet )
801  break;
802  }
803  }
804  if( (SvtScriptType::LATIN | SvtScriptType::ASIAN |
805  SvtScriptType::COMPLEX) == nRet )
806  break;
807 
808  }
809  }
810  if( nRet == SvtScriptType::NONE )
812  return nRet;
813 }
814 
816 {
817  const SwPaM* pCursor = GetCursor();
818  const SwPosition& rPos = *pCursor->GetPoint();
819  const SwTextNode* pTNd = rPos.nNode.GetNode().GetTextNode();
821  if( pTNd )
822  {
823  //JP 24.9.2001: if exist no selection, then get the language before
824  // the current character!
825  sal_Int32 nPos = rPos.nContent.GetIndex();
826  if( nPos && !pCursor->HasMark() )
827  --nPos;
828  nLang = pTNd->GetLang( nPos );
829  }
830  else
831  nLang = LANGUAGE_DONTKNOW;
832  return nLang;
833 }
834 
836 {
837  const SwPaM* pCursor = GetCursor();
838  const SwPosition* pStt = pCursor->Start();
839  const SwTextNode* pTNd = pStt->nNode.GetNode().GetTextNode();
840  OSL_ENSURE( pTNd, "no textnode available" );
841 
842  sal_uInt16 nScaleWidth;
843  if( pTNd )
844  {
845  SwTextFrame *const pFrame(static_cast<SwTextFrame *>(
846  pTNd->getLayoutFrame(GetLayout(), pStt)));
847  assert(pFrame); // shell cursor must be positioned in node with frame
848  TextFrameIndex const nStart(pFrame->MapModelToViewPos(*pStt));
849  TextFrameIndex const nEnd(
850  sw::FrameContainsNode(*pFrame, pCursor->End()->nNode.GetIndex())
851  ? pFrame->MapModelToViewPos(*pCursor->End())
852  : TextFrameIndex(pFrame->GetText().getLength()));
853  nScaleWidth = pFrame->GetScalingOfSelectedText(nStart, nEnd);
854  }
855  else
856  nScaleWidth = 100; // default are no scaling -> 100%
857  return nScaleWidth;
858 }
859 
860 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SvxNumType GetNumberingType() const
Base class of the Writer layout elements.
Definition: frame.hxx:298
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
void SetEndNote(bool b)
Definition: atrftn.cxx:171
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:246
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:367
TextFrameIndex NextScriptChg(TextFrameIndex nPos) const
Definition: porlay.cxx:1643
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:194
SwCharFormat * FindCharFormatByName(std::u16string_view rName) const
Definition: doc.hxx:772
sal_uInt32 sal_UCS4
bool isCHRATR(const sal_uInt16 nWhich)
Definition: hintids.hxx:469
const OUString & GetText() const
Definition: ndtxt.hxx:211
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:219
SwNodeIndex nNode
Definition: pam.hxx:37
const SfxPoolItem * GetPoolDefaultItem(sal_uInt16 nWhich) const
virtual sal_Int32 Len() const override
Definition: ndtxt.cxx:274
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:1208
sal_Int64 n
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:2370
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:575
bool InsertSort(SeqFieldLstElem aNew)
Definition: expfld.cxx:728
bool IsEndNote() const
Definition: fmtftn.hxx:71
sal_uInt16 Which() const
Definition: txatbase.hxx:110
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1285
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:4076
OUString GetViewNumStr(const SwDoc &rDoc, SwRootFrame const *pLayout, bool bInclStrings=false) const
Returns string to be displayed of footnote / endnote.
Definition: atrftn.cxx:215
static LanguageType nLang
Definition: srtdlg.cxx:51
LanguageType GetCurLang() const
Definition: edattr.cxx:815
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:3020
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:169
const SfxPoolItem * NextItem()
size_t Count()
Definition: expfld.hxx:64
SwNodeType GetNodeType() const
Definition: node.hxx:144
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
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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:82
const sal_uInt8 MAXLEVEL
Definition: swtypes.hxx:95
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:590
constexpr TypedWhichId< SwFormatCharFormat > RES_TXTATR_CHARFMT(52)
SwDoc * GetDoc() const
Definition: viewsh.hxx:281
const SwFormatField & GetFormatField() const
Definition: txatbase.hxx:191
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:284
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:1259
SvtScriptType GetScriptType() const
returns the script type of the selection
Definition: edattr.cxx:673
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:554
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:2775
#define LANGUAGE_DONTKNOW
sal_uInt16 GetCursorCnt(bool bAll=true) const
Get the number of elements in the ring of cursors.
Definition: crsrsh.cxx:2736
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:455
bool HasSwAttrSet() const
Definition: node.hxx:452
ring_container GetRingContainer()
Definition: ring.hxx:240
void MergeValues(const SfxItemSet &rSet)
SfxItemPool * GetPool() const
const SwFormatFootnote & GetFootnote() const
Definition: txatbase.hxx:200
std::pair< SwTextNode *, sal_Int32 > MapViewToModel(TextFrameIndex nIndex) const
map position in potentially merged text frame to SwPosition
Definition: txtfrm.cxx:1223
const SwPosition * Start() const
Definition: pam.hxx:212
bool GetPaMParAttr(SwPaM *pPaM, SfxItemSet &rSet) const
Get the paragraph format attribute(s) of the selection(s) described by a SwPaM.
Definition: edattr.cxx:188
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:296
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:324
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:1243
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:62
const SwNumFormat & Get(sal_uInt16 i) const
Definition: number.cxx:79
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
bool SetCurFootnote(const SwFormatFootnote &rFillFootnote)
Definition: edattr.cxx:426
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:455
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:1626
sal_Int16 ScriptType(const TextFrameIndex nPos) const
Definition: porlay.cxx:1656
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:3344
#define MM50
Definition: swtypes.hxx:59
bool IsMoveLeftMargin(bool bRight, bool bModulus=true) const
Adjust left margin via object bar (similar to adjustment of numerations).
Definition: edattr.cxx:502
unsigned char sal_uInt8
bool HasFootnotes(bool bEndNotes=false) const
Definition: edattr.cxx:442
TextFrameIndex MapModelToView(SwTextNode const *pNode, sal_Int32 nIndex) const
Definition: txtfrm.cxx:1244
sal_Int32 GetIndex() const
Definition: index.hxx:91
LanguageType GetAppLanguage()
Definition: init.cxx:728
SwNodes & GetNodes()
Definition: doc.hxx:407
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:3418
const sal_Int32 * End() const
Definition: txatbase.hxx:148
bool GetCurFootnote(SwFormatFootnote *pToFillFootnote=nullptr)
Query and set footnote-text/number. Set... to current SSelection!
Definition: edattr.cxx:406
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:420
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:251
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:717
OUString GetNumString(const bool _bInclPrefixAndSuffixStrings=true, const unsigned int _nRestrictToThisLevel=MAXLEVEL, SwRootFrame const *pLayout=nullptr) const
Returns outline of numbering string.
Definition: ndtxt.cxx:3091
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:159
static sal_uInt16 getMaxLookup()
Definition: edattr.cxx:54
const sal_uInt16 * GetRanges() const
bool IsVertical() const
Definition: frame.hxx:954
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:4318
bool HasMergedParas() const
Definition: rootfrm.hxx:424
tuple m
const SwAttrSet & GetAttrSet() const
For querying the attribute array.
Definition: format.hxx:137
const SfxPoolItem & GetAttr(sal_uInt16 nWhich, bool bInParent=true) const
SS for PoolItems: hard attributation.
Definition: node.hxx:724
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:835
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2064
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:639
void Height(tools::Long nNew)
Definition: swrect.hxx:191
SwPosition MapViewToModelPos(TextFrameIndex nIndex) const
Definition: txtfrm.cxx:1238
Merge GetRedlineMergeFlag() const
Definition: node.hxx:97
virtual OUString GetCharFormatName() const override
Definition: number.cxx:303
const sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:61
sal_uInt16 Which() const
bool GoPrevious(SwIndex *, sal_uInt16 nMode) const
Definition: node.cxx:1314
void Clear()
Definition: expfld.hxx:67
sal_uInt16 nPos
const SfxPoolItem * GetCurItem() const
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:846
bool HasHints() const
Definition: ndtxt.hxx:221
Base class of the Writer document model elements.
Definition: node.hxx:79
SwTextFormatColl * GetTextColl() const
Definition: ndtxt.hxx:840