LibreOffice Module sc (master)  1
documen8.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 <scitems.hxx>
21 #include <comphelper/fileformat.h>
24 #include <officecfg/Office/Common.hxx>
25 #include <tools/urlobj.hxx>
26 #include <editeng/editobj.hxx>
27 #include <editeng/frmdiritem.hxx>
28 #include <editeng/langitem.hxx>
29 #include <sfx2/linkmgr.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/objsh.hxx>
32 #include <sfx2/printer.hxx>
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/viewsh.hxx>
35 #include <svl/flagitem.hxx>
36 #include <svl/intitem.hxx>
37 #include <svl/zforlist.hxx>
38 #include <svl/zformat.hxx>
40 #include <sal/log.hxx>
41 
42 #include <vcl/svapp.hxx>
43 #include <vcl/virdev.hxx>
44 #include <vcl/weld.hxx>
45 #include <vcl/TaskStopwatch.hxx>
46 
47 #include <inputopt.hxx>
48 #include <global.hxx>
49 #include <table.hxx>
50 #include <column.hxx>
51 #include <poolhelp.hxx>
52 #include <docpool.hxx>
53 #include <stlpool.hxx>
54 #include <stlsheet.hxx>
55 #include <docoptio.hxx>
56 #include <viewopti.hxx>
57 #include <scextopt.hxx>
58 #include <rechead.hxx>
59 #include <ddelink.hxx>
60 #include <scmatrix.hxx>
61 #include <arealink.hxx>
62 #include <patattr.hxx>
63 #include <editutil.hxx>
64 #include <progress.hxx>
65 #include <document.hxx>
66 #include <chartlis.hxx>
67 #include <chartlock.hxx>
68 #include <refupdat.hxx>
69 #include <markdata.hxx>
70 #include <scmod.hxx>
71 #include <externalrefmgr.hxx>
72 #include <globstr.hrc>
73 #include <strings.hrc>
74 #include <sc.hrc>
75 #include <charthelper.hxx>
76 #include <macromgr.hxx>
77 #include <docuno.hxx>
78 #include <scresid.hxx>
79 #include <columniterator.hxx>
80 #include <globalnames.hxx>
81 #include <stringutil.hxx>
82 #include <documentlinkmgr.hxx>
83 #include <scopetools.hxx>
84 #include <tokenarray.hxx>
85 
86 #include <memory>
87 #include <utility>
88 
89 using namespace com::sun::star;
90 
91 namespace {
92 
93 sal_uInt16 getScaleValue(SfxStyleSheetBase& rStyle, sal_uInt16 nWhich)
94 {
95  return static_cast<const SfxUInt16Item&>(rStyle.GetItemSet().Get(nWhich)).GetValue();
96 }
97 
98 }
99 
101 {
102  pDocOptions.reset( new ScDocOptions() );
103  pViewOptions.reset( new ScViewOptions() );
104 }
105 
107 {
108  pDocOptions.reset();
109  pViewOptions.reset();
110  pExtDocOptions.reset();
111 }
112 
113 SfxPrinter* ScDocument::GetPrinter(bool bCreateIfNotExist)
114 {
115  if ( !mpPrinter && bCreateIfNotExist )
116  {
117  auto pSet =
118  std::make_unique<SfxItemSet>( *mxPoolHelper->GetDocPool(),
119  svl::Items<SID_PRINTER_NOTFOUND_WARN, SID_PRINTER_NOTFOUND_WARN,
120  SID_PRINTER_CHANGESTODOC, SID_PRINTER_CHANGESTODOC,
121  SID_PRINT_SELECTEDSHEET, SID_PRINT_SELECTEDSHEET,
122  SID_SCPRINTOPTIONS, SID_SCPRINTOPTIONS>{} );
123 
124  SfxPrinterChangeFlags nFlags = SfxPrinterChangeFlags::NONE;
125  if (officecfg::Office::Common::Print::Warning::PaperOrientation::get())
126  nFlags |= SfxPrinterChangeFlags::CHG_ORIENTATION;
127  if (officecfg::Office::Common::Print::Warning::PaperSize::get())
128  nFlags |= SfxPrinterChangeFlags::CHG_SIZE;
129  pSet->Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, static_cast<int>(nFlags) ) );
130  pSet->Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, officecfg::Office::Common::Print::Warning::NotFound::get() ) );
131 
132  mpPrinter = VclPtr<SfxPrinter>::Create( std::move(pSet) );
133  mpPrinter->SetMapMode(MapMode(MapUnit::Map100thMM));
134  UpdateDrawPrinter();
135  mpPrinter->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
136  }
137 
138  return mpPrinter;
139 }
140 
141 void ScDocument::SetPrinter( VclPtr<SfxPrinter> const & pNewPrinter )
142 {
143  if ( pNewPrinter == mpPrinter.get() )
144  {
145  // #i6706# SetPrinter is called with the same printer again if
146  // the JobSetup has changed. In that case just call UpdateDrawPrinter
147  // (SetRefDevice for drawing layer) because of changed text sizes.
148  UpdateDrawPrinter();
149  }
150  else
151  {
152  ScopedVclPtr<SfxPrinter> xKeepAlive( mpPrinter );
153  mpPrinter = pNewPrinter;
154  UpdateDrawPrinter();
155  mpPrinter->SetDigitLanguage( SC_MOD()->GetOptDigitLanguage() );
156  }
157  InvalidateTextWidth(nullptr, nullptr, false); // in both cases
158 }
159 
161 {
162  if ( !mpPrinter ) GetPrinter(); // this sets mpPrinter
163  OSL_ENSURE( mpPrinter, "Error in printer creation :-/" );
164 
165  if ( !mpPrinter )
166  return;
167 
168  SfxItemSet aOptSet( mpPrinter->GetOptions() );
169 
170  SfxPrinterChangeFlags nFlags = SfxPrinterChangeFlags::NONE;
171  if (officecfg::Office::Common::Print::Warning::PaperOrientation::get())
172  nFlags |= SfxPrinterChangeFlags::CHG_ORIENTATION;
173  if (officecfg::Office::Common::Print::Warning::PaperSize::get())
174  nFlags |= SfxPrinterChangeFlags::CHG_SIZE;
175  aOptSet.Put( SfxFlagItem( SID_PRINTER_CHANGESTODOC, static_cast<int>(nFlags) ) );
176  aOptSet.Put( SfxBoolItem( SID_PRINTER_NOTFOUND_WARN, officecfg::Office::Common::Print::Warning::NotFound::get() ) );
177 
178  mpPrinter->SetOptions( aOptSet );
179 }
180 
182 {
183  if (!mpVirtualDevice_100th_mm)
184  {
185 #ifdef IOS
186  mpVirtualDevice_100th_mm = VclPtr<VirtualDevice>::Create(DeviceFormat::GRAYSCALE);
187 #else
188  mpVirtualDevice_100th_mm = VclPtr<VirtualDevice>::Create(DeviceFormat::BITMASK);
189 #endif
190  mpVirtualDevice_100th_mm->SetReferenceDevice(VirtualDevice::RefDevMode::MSO1);
191  MapMode aMapMode( mpVirtualDevice_100th_mm->GetMapMode() );
192  aMapMode.SetMapUnit( MapUnit::Map100thMM );
193  mpVirtualDevice_100th_mm->SetMapMode( aMapMode );
194  }
195  return mpVirtualDevice_100th_mm;
196 }
197 
199 {
200  // Create printer like ref device, see Writer...
201  OutputDevice* pRefDevice = nullptr;
202  if ( SC_MOD()->GetInputOptions().GetTextWysiwyg() )
203  pRefDevice = GetPrinter();
204  else
205  pRefDevice = GetVirtualDevice_100th_mm();
206  return pRefDevice;
207 }
208 
210  const SfxItemSet& rChanges )
211 {
212  SfxItemSet& rSet = rStyleSheet.GetItemSet();
213 
214  switch ( rStyleSheet.GetFamily() )
215  {
216  case SfxStyleFamily::Page:
217  {
218  const sal_uInt16 nOldScale = getScaleValue(rStyleSheet, ATTR_PAGE_SCALE);
219  const sal_uInt16 nOldScaleToPages = getScaleValue(rStyleSheet, ATTR_PAGE_SCALETOPAGES);
220  rSet.Put( rChanges );
221  const sal_uInt16 nNewScale = getScaleValue(rStyleSheet, ATTR_PAGE_SCALE);
222  const sal_uInt16 nNewScaleToPages = getScaleValue(rStyleSheet, ATTR_PAGE_SCALETOPAGES);
223 
224  if ( (nOldScale != nNewScale) || (nOldScaleToPages != nNewScaleToPages) )
225  InvalidateTextWidth( rStyleSheet.GetName() );
226 
228  {
229  const SfxPoolItem *pItem = nullptr;
230  if( rChanges.GetItemState(ATTR_WRITINGDIR, true, &pItem ) == SfxItemState::SET )
232  }
233  }
234  break;
235 
236  case SfxStyleFamily::Para:
237  {
238  bool bNumFormatChanged;
239  if ( ScGlobal::CheckWidthInvalidate( bNumFormatChanged,
240  rSet, rChanges ) )
241  InvalidateTextWidth( nullptr, nullptr, bNumFormatChanged );
242 
243  for (SCTAB nTab=0; nTab<=MAXTAB; ++nTab)
244  if (maTabs[nTab])
245  maTabs[nTab]->SetStreamValid( false );
246 
247  sal_uLong nOldFormat =
248  rSet.Get( ATTR_VALUE_FORMAT ).GetValue();
249  sal_uLong nNewFormat =
250  rChanges.Get( ATTR_VALUE_FORMAT ).GetValue();
251  LanguageType eNewLang, eOldLang;
252  eNewLang = eOldLang = LANGUAGE_DONTKNOW;
253  if ( nNewFormat != nOldFormat )
254  {
255  SvNumberFormatter* pFormatter = GetFormatTable();
256  eOldLang = pFormatter->GetEntry( nOldFormat )->GetLanguage();
257  eNewLang = pFormatter->GetEntry( nNewFormat )->GetLanguage();
258  }
259 
260  // Explanation to Items in rChanges:
261  // Set Item - take over change
262  // Dontcare - Set Default
263  // Default - No change
264  // ("no change" is not possible with PutExtended, thus the loop)
265  for (sal_uInt16 nWhich = ATTR_PATTERN_START; nWhich <= ATTR_PATTERN_END; nWhich++)
266  {
267  const SfxPoolItem* pItem;
268  SfxItemState eState = rChanges.GetItemState( nWhich, false, &pItem );
269  if ( eState == SfxItemState::SET )
270  rSet.Put( *pItem );
271  else if ( eState == SfxItemState::DONTCARE )
272  rSet.ClearItem( nWhich );
273  // when Default nothing
274  }
275 
276  if ( eNewLang != eOldLang )
277  rSet.Put(
278  SvxLanguageItem( eNewLang, ATTR_LANGUAGE_FORMAT ) );
279  }
280  break;
281  default:
282  {
283  // added to avoid warnings
284  }
285  }
286 }
287 
289 {
290  // number format exchange list has to be handled here, too
291  NumFmtMergeHandler aNumFmtMergeHdl(*this, rSrcDoc);
292  mxPoolHelper->GetStylePool()->CopyStdStylesFrom( rSrcDoc.mxPoolHelper->GetStylePool() );
293 }
294 
295 void ScDocument::InvalidateTextWidth( const OUString& rStyleName )
296 {
297  const SCTAB nCount = GetTableCount();
298  for ( SCTAB i=0; i<nCount && maTabs[i]; i++ )
299  if ( maTabs[i]->GetPageStyle() == rStyleName )
300  InvalidateTextWidth( i );
301 }
302 
304 {
305  ScAddress aAdrFrom( 0, 0, nTab );
306  ScAddress aAdrTo ( MaxCol(), MaxRow(), nTab );
307  InvalidateTextWidth( &aAdrFrom, &aAdrTo, false );
308 }
309 
310 bool ScDocument::IsPageStyleInUse( const OUString& rStrPageStyle, SCTAB* pInTab )
311 {
312  bool bInUse = false;
313  const SCTAB nCount = GetTableCount();
314  SCTAB i;
315 
316  for ( i = 0; !bInUse && i < nCount && maTabs[i]; i++ )
317  bInUse = ( maTabs[i]->GetPageStyle() == rStrPageStyle );
318 
319  if ( pInTab )
320  *pInTab = i-1;
321 
322  return bInUse;
323 }
324 
325 bool ScDocument::RemovePageStyleInUse( const OUString& rStyle )
326 {
327  bool bWasInUse = false;
328  const SCTAB nCount = GetTableCount();
329 
330  for ( SCTAB i=0; i<nCount && maTabs[i]; i++ )
331  if ( maTabs[i]->GetPageStyle() == rStyle )
332  {
333  bWasInUse = true;
334  maTabs[i]->SetPageStyle( ScResId(STR_STYLENAME_STANDARD_PAGE) );
335  }
336 
337  return bWasInUse;
338 }
339 
340 bool ScDocument::RenamePageStyleInUse( const OUString& rOld, const OUString& rNew )
341 {
342  bool bWasInUse = false;
343  const SCTAB nCount = GetTableCount();
344 
345  for ( SCTAB i=0; i<nCount && maTabs[i]; i++ )
346  if ( maTabs[i]->GetPageStyle() == rOld )
347  {
348  bWasInUse = true;
349  maTabs[i]->SetPageStyle( rNew );
350  }
351 
352  return bWasInUse;
353 }
354 
356 {
357  EEHorizontalTextDirection eRet = EEHorizontalTextDirection::Default;
358 
359  OUString aStyleName = GetPageStyle( nTab );
360  SfxStyleSheetBase* pStyle = mxPoolHelper->GetStylePool()->Find( aStyleName, SfxStyleFamily::Page );
361  if ( pStyle )
362  {
363  SfxItemSet& rStyleSet = pStyle->GetItemSet();
364  SvxFrameDirection eDirection =
365  rStyleSet.Get( ATTR_WRITINGDIR ).GetValue();
366 
367  if ( eDirection == SvxFrameDirection::Horizontal_LR_TB )
368  eRet = EEHorizontalTextDirection::L2R;
369  else if ( eDirection == SvxFrameDirection::Horizontal_RL_TB )
370  eRet = EEHorizontalTextDirection::R2L;
371  // else (invalid for EditEngine): keep "default"
372  }
373 
374  return eRet;
375 }
376 
378 {
379  if (!mpMacroMgr)
380  mpMacroMgr.reset(new ScMacroManager(*this));
381  return mpMacroMgr.get();
382 }
383 
385  ScMatrix& rMat, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, svl::SharedStringPool* pPool ) const
386 {
387  const ScTable* pTab = FetchTable(nTab);
388  if (!pTab)
389  return;
390 
391  if (nCol1 > nCol2 || nRow1 > nRow2)
392  return;
393 
394  SCSIZE nC, nR;
395  rMat.GetDimensions(nC, nR);
396  if (static_cast<SCROW>(nR) != nRow2 - nRow1 + 1 || static_cast<SCCOL>(nC) != nCol2 - nCol1 + 1)
397  return;
398 
399  pTab->FillMatrix(rMat, nCol1, nRow1, nCol2, nRow2, pPool);
400 }
401 
402 void ScDocument::SetFormulaResults( const ScAddress& rTopPos, const double* pResults, size_t nLen )
403 {
404  ScTable* pTab = FetchTable(rTopPos.Tab());
405  if (!pTab)
406  return;
407 
408  pTab->SetFormulaResults(rTopPos.Col(), rTopPos.Row(), pResults, nLen);
409 }
410 
411 const ScDocumentThreadSpecific& ScDocument::CalculateInColumnInThread( ScInterpreterContext& rContext, const ScRange& rCalcRange, unsigned nThisThread, unsigned nThreadsTotal)
412 {
413  ScTable* pTab = FetchTable(rCalcRange.aStart.Tab());
414  if (!pTab)
415  return maNonThreaded;
416 
417  assert(IsThreadedGroupCalcInProgress());
418 
419  maThreadSpecific.pContext = &rContext;
421  pTab->CalculateInColumnInThread(rContext, rCalcRange.aStart.Col(), rCalcRange.aEnd.Col(), rCalcRange.aStart.Row(), rCalcRange.aEnd.Row(), nThisThread, nThreadsTotal);
422 
423  assert(IsThreadedGroupCalcInProgress());
424  maThreadSpecific.pContext = nullptr;
425 
426  return maThreadSpecific;
427 }
428 
429 void ScDocument::HandleStuffAfterParallelCalculation( SCCOL nColStart, SCCOL nColEnd, SCROW nRow, size_t nLen, SCTAB nTab, ScInterpreter* pInterpreter )
430 {
431  assert(!IsThreadedGroupCalcInProgress());
432  for( const DelayedSetNumberFormat& data : GetNonThreadedContext().maDelayedSetNumberFormat)
433  SetNumberFormat( ScAddress( data.mCol, data.mRow, nTab ), data.mnNumberFormat );
434  GetNonThreadedContext().maDelayedSetNumberFormat.clear();
435 
436  ScTable* pTab = FetchTable(nTab);
437  if (!pTab)
438  return;
439 
440  pTab->HandleStuffAfterParallelCalculation(nColStart, nColEnd, nRow, nLen, pInterpreter);
441 }
442 
443 void ScDocument::InvalidateTextWidth( const ScAddress* pAdrFrom, const ScAddress* pAdrTo,
444  bool bNumFormatChanged )
445 {
446  bool bBroadcast = (bNumFormatChanged && GetDocOptions().IsCalcAsShown() && !IsImportingXML() && !IsClipboard());
447  if ( pAdrFrom && !pAdrTo )
448  {
449  const SCTAB nTab = pAdrFrom->Tab();
450 
451  if (nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
452  maTabs[nTab]->InvalidateTextWidth( pAdrFrom, nullptr, bNumFormatChanged, bBroadcast );
453  }
454  else
455  {
456  const SCTAB nTabStart = pAdrFrom ? pAdrFrom->Tab() : 0;
457  const SCTAB nTabEnd = pAdrTo ? pAdrTo->Tab() : MAXTAB;
458 
459  for ( SCTAB nTab=nTabStart; nTab<=nTabEnd && nTab < static_cast<SCTAB>(maTabs.size()); nTab++ )
460  if ( maTabs[nTab] )
461  maTabs[nTab]->InvalidateTextWidth( pAdrFrom, pAdrTo, bNumFormatChanged, bBroadcast );
462  }
463 }
464 
465 #define CALCMAX 1000 // Calculations
466 
467 namespace {
468 
469 class IdleCalcTextWidthScope : public TaskStopwatch
470 {
471  ScDocument& mrDoc;
472  ScAddress& mrCalcPos;
473  MapMode maOldMapMode;
474  ScStyleSheetPool* mpStylePool;
475  bool mbNeedMore;
476  bool mbProgress;
477 
478 public:
479  IdleCalcTextWidthScope(ScDocument& rDoc, ScAddress& rCalcPos) :
480  mrDoc(rDoc),
481  mrCalcPos(rCalcPos),
482  mpStylePool(rDoc.GetStyleSheetPool()),
483  mbNeedMore(false),
484  mbProgress(false)
485  {
486  mrDoc.EnableIdle(false);
487  }
488 
489  ~IdleCalcTextWidthScope() COVERITY_NOEXCEPT_FALSE
490  {
491  SfxPrinter* pDev = mrDoc.GetPrinter();
492  if (pDev)
493  pDev->SetMapMode(maOldMapMode);
494 
495  if (mbProgress)
497 
498  mrDoc.EnableIdle(true);
499  }
500 
501  SCTAB Tab() const { return mrCalcPos.Tab(); }
502  SCCOL Col() const { return mrCalcPos.Col(); }
503  SCROW Row() const { return mrCalcPos.Row(); }
504 
505  void setTab(SCTAB nTab) { mrCalcPos.SetTab(nTab); }
506  void setCol(SCCOL nCol) { mrCalcPos.SetCol(nCol); }
507  void setRow(SCROW nRow) { mrCalcPos.SetRow(nRow); }
508 
509  void incTab() { mrCalcPos.IncTab(); }
510  void incCol(SCCOL nInc) { mrCalcPos.IncCol(nInc); }
511 
512  void setOldMapMode(const MapMode& rOldMapMode) { maOldMapMode = rOldMapMode; }
513 
514  void setNeedMore(bool b) { mbNeedMore = b; }
515  bool getNeedMore() const { return mbNeedMore; }
516 
517  void createProgressBar()
518  {
520  mbProgress = true;
521  }
522 
523  bool hasProgressBar() const { return mbProgress; }
524 
525  ScStyleSheetPool* getStylePool() { return mpStylePool; }
526 };
527 
528 }
529 
530 bool ScDocument::IdleCalcTextWidth() // true = try next again
531 {
532  // #i75610# if a printer hasn't been set or created yet, don't create one for this
533  if (!mbIdleEnabled || IsInLinkUpdate() || GetPrinter(false) == nullptr)
534  return false;
535 
536  IdleCalcTextWidthScope aScope(*this, aCurTextWidthCalcPos);
537 
538  if (!ValidRow(aScope.Row()))
539  {
540  aScope.setRow(0);
541  aScope.incCol(-1);
542  }
543 
544  if (aScope.Col() < 0)
545  {
546  aScope.setCol(MaxCol());
547  aScope.incTab();
548  }
549 
550  if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()])
551  aScope.setTab(0);
552 
553  ScTable* pTab = maTabs[aScope.Tab()].get();
554  ScStyleSheet* pStyle = static_cast<ScStyleSheet*>(aScope.getStylePool()->Find(pTab->aPageStyle, SfxStyleFamily::Page));
555  OSL_ENSURE( pStyle, "Missing StyleSheet :-/" );
556 
557  if (!pStyle || getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
558  {
559  // Move to the next sheet as the current one has scale-to-pages set,
560  // and bail out.
561  aScope.incTab();
562  return false;
563  }
564 
565  sal_uInt16 nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
566  Fraction aZoomFract(nZoom, 100);
567 
568  aScope.setCol(pTab->ClampToAllocatedColumns(aScope.Col()));
569  // Start at specified cell position (nCol, nRow, nTab).
570  ScColumn* pCol = &pTab->aCol[aScope.Col()];
571  std::unique_ptr<ScColumnTextWidthIterator> pColIter(new ScColumnTextWidthIterator(*this, *pCol, aScope.Row(), MaxRow()));
572 
573  OutputDevice* pDev = nullptr;
574  sal_uInt16 nRestart = 0;
575  sal_uInt16 nCount = 0;
576  while ( (nZoom > 0) && (nCount < CALCMAX) && (nRestart < 2) )
577  {
578  if (pColIter->hasCell())
579  {
580  // More cell in this column.
581  SCROW nRow = pColIter->getPos();
582  aScope.setRow(nRow);
583 
584  if (pColIter->getValue() == TEXTWIDTH_DIRTY)
585  {
586  // Calculate text width for this cell.
587  double nPPTX = 0.0;
588  double nPPTY = 0.0;
589  if (!pDev)
590  {
591  pDev = GetPrinter();
592  aScope.setOldMapMode(pDev->GetMapMode());
593  pDev->SetMapMode(MapMode(MapUnit::MapPixel)); // Important for GetNeededSize
594 
595  Point aPix1000 = pDev->LogicToPixel(Point(1000,1000), MapMode(MapUnit::MapTwip));
596  nPPTX = aPix1000.X() / 1000.0;
597  nPPTY = aPix1000.Y() / 1000.0;
598  }
599 
600  if (!aScope.hasProgressBar() && pCol->IsFormulaDirty(nRow))
601  aScope.createProgressBar();
602 
603  sal_uInt16 nNewWidth = static_cast<sal_uInt16>(GetNeededSize(
604  aScope.Col(), aScope.Row(), aScope.Tab(),
605  pDev, nPPTX, nPPTY, aZoomFract,aZoomFract, true, true)); // bTotalSize
606 
607  pColIter->setValue(nNewWidth);
608  aScope.setNeedMore(true);
609  }
610  pColIter->next();
611  }
612  else
613  {
614  // No more cell in this column. Move to the left column and start at row 0.
615 
616  bool bNewTab = false;
617 
618  aScope.setRow(0);
619  aScope.incCol(-1);
620 
621  if (aScope.Col() < 0)
622  {
623  // No more column to the left. Move to the right-most column of the next sheet.
624  aScope.setCol(MaxCol());
625  aScope.incTab();
626  bNewTab = true;
627  }
628 
629  if (!ValidTab(aScope.Tab()) || aScope.Tab() >= static_cast<SCTAB>(maTabs.size()) || !maTabs[aScope.Tab()] )
630  {
631  // Sheet doesn't exist at specified sheet position. Restart at sheet 0.
632  aScope.setTab(0);
633  nRestart++;
634  bNewTab = true;
635  }
636 
637  if ( nRestart < 2 )
638  {
639  if ( bNewTab )
640  {
641  pTab = maTabs[aScope.Tab()].get();
642  aScope.setCol(pTab->ClampToAllocatedColumns(aScope.Col()));
643  pStyle = static_cast<ScStyleSheet*>(aScope.getStylePool()->Find(
644  pTab->aPageStyle, SfxStyleFamily::Page));
645 
646  if ( pStyle )
647  {
648  // Check if the scale-to-pages setting is set. If
649  // set, we exit the loop. If not, get the page
650  // scale factor of the new sheet.
651  if (getScaleValue(*pStyle, ATTR_PAGE_SCALETOPAGES) == 0)
652  {
653  nZoom = getScaleValue(*pStyle, ATTR_PAGE_SCALE);
654  aZoomFract = Fraction(nZoom, 100);
655  }
656  else
657  nZoom = 0;
658  }
659  else
660  {
661  OSL_FAIL( "Missing StyleSheet :-/" );
662  }
663  }
664 
665  if ( nZoom > 0 )
666  {
667  pCol = &pTab->aCol[aScope.Col()];
668  pColIter.reset(new ScColumnTextWidthIterator(*this, *pCol, aScope.Row(), MaxRow()));
669  }
670  else
671  {
672  aScope.incTab(); // Move to the next sheet as the current one has scale-to-pages set.
673  return false;
674  }
675  }
676  }
677 
678  ++nCount;
679 
680  if (!aScope.continueIter())
681  break;
682  }
683 
684  return aScope.getNeedMore();
685 }
686 
687 void ScDocument::RepaintRange( const ScRange& rRange )
688 {
689  if ( bIsVisible && mpShell )
690  {
691  ScModelObj* pModel = comphelper::getUnoTunnelImplementation<ScModelObj>( mpShell->GetModel() );
692  if ( pModel )
693  pModel->RepaintRange( rRange ); // locked repaints are checked there
694  }
695 }
696 
698 {
699  if ( bIsVisible && mpShell )
700  {
701  ScModelObj* pModel = comphelper::getUnoTunnelImplementation<ScModelObj>( mpShell->GetModel() );
702  if ( pModel )
703  pModel->RepaintRange( rRange ); // locked repaints are checked there
704  }
705 }
706 
707 void ScDocument::SaveDdeLinks(SvStream& rStream) const
708 {
709  // when 4.0-Export, remove all with mode != DEFAULT
710  bool bExport40 = ( rStream.GetVersion() <= SOFFICE_FILEFORMAT_40 );
711 
712  const ::sfx2::SvBaseLinks& rLinks = GetLinkManager()->GetLinks();
713  sal_uInt16 nCount = rLinks.size();
714 
715  // Count them first
716 
717  sal_uInt16 nDdeCount = 0;
718  sal_uInt16 i;
719  for (i=0; i<nCount; i++)
720  {
721  ::sfx2::SvBaseLink* pBase = rLinks[i].get();
722  if (ScDdeLink* pLink = dynamic_cast<ScDdeLink*>(pBase))
723  if ( !bExport40 || pLink->GetMode() == SC_DDE_DEFAULT )
724  ++nDdeCount;
725  }
726 
727  // Header
728 
729  ScMultipleWriteHeader aHdr( rStream );
730  rStream.WriteUInt16( nDdeCount );
731 
732  // Save links
733 
734  for (i=0; i<nCount; i++)
735  {
736  ::sfx2::SvBaseLink* pBase = rLinks[i].get();
737  if (ScDdeLink* pLink = dynamic_cast<ScDdeLink*>(pBase))
738  {
739  if ( !bExport40 || pLink->GetMode() == SC_DDE_DEFAULT )
740  pLink->Store( rStream, aHdr );
741  }
742  }
743 }
744 
746 {
747  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
748  if (!pMgr)
749  return;
750 
751  ScMultipleReadHeader aHdr( rStream );
752 
753  sal_uInt16 nCount(0);
754  rStream.ReadUInt16( nCount );
755 
756  const rtl_TextEncoding eCharSet = rStream.GetStreamCharSet();
757  const size_t nMinStringSize = eCharSet == RTL_TEXTENCODING_UNICODE ? sizeof(sal_uInt32) : sizeof(sal_uInt16);
758  const size_t nMinRecordSize = 1 + nMinStringSize*3;
759  const size_t nMaxRecords = rStream.remainingSize() / nMinRecordSize;
760  if (nCount > nMaxRecords)
761  {
762  SAL_WARN("sc", "Parsing error: " << nMaxRecords <<
763  " max possible entries, but " << nCount << " claimed, truncating");
764  nCount = nMaxRecords;
765  }
766 
767  for (sal_uInt16 i=0; i<nCount; ++i)
768  {
769  ScDdeLink* pLink = new ScDdeLink( *this, rStream, aHdr );
770  pMgr->InsertDDELink(pLink, pLink->GetAppl(), pLink->GetTopic(), pLink->GetItem());
771  }
772 }
773 
775 {
776  // called from TableLink and AreaLink
777 
778  OSL_ENSURE( bInLinkUpdate != bSet, "SetInLinkUpdate twice" );
779  bInLinkUpdate = bSet;
780 }
781 
783 {
784  return bInLinkUpdate || IsInDdeLinkUpdate();
785 }
786 
788 {
789  if (!pExternalRefMgr)
790  return;
791 
792  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
793  if (!pMgr)
794  return;
795 
796  const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
797  sal_uInt16 nCount = rLinks.size();
798 
799  bool bAny = false;
800 
801  // Collect all the external ref links first.
802  std::vector<ScExternalRefLink*> aRefLinks;
803  for (sal_uInt16 i = 0; i < nCount; ++i)
804  {
805  ::sfx2::SvBaseLink* pBase = rLinks[i].get();
806  ScExternalRefLink* pRefLink = dynamic_cast<ScExternalRefLink*>(pBase);
807  if (pRefLink)
808  aRefLinks.push_back(pRefLink);
809  }
810 
811  weld::WaitObject aWaitSwitch(pWin);
812 
813  pExternalRefMgr->enableDocTimer(false);
814  ScProgress aProgress(GetDocumentShell(), ScResId(SCSTR_UPDATE_EXTDOCS), aRefLinks.size(), true);
815  for (size_t i = 0, n = aRefLinks.size(); i < n; ++i)
816  {
817  aProgress.SetState(i+1);
818 
819  ScExternalRefLink* pRefLink = aRefLinks[i];
820  if (pRefLink->Update())
821  {
822  bAny = true;
823  continue;
824  }
825 
826  // Update failed. Notify the user.
827 
828  OUString aFile;
829  sfx2::LinkManager::GetDisplayNames(pRefLink, nullptr, &aFile);
830  // Decode encoded URL for display friendliness.
833 
834  OUString sMessage = ScResId(SCSTR_EXTDOC_NOT_LOADED) +
835  "\n\n" +
836  aFile;
837  std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(pWin,
838  VclMessageType::Warning, VclButtonsType::Ok,
839  sMessage));
840  xBox->run();
841  }
842 
843  pExternalRefMgr->enableDocTimer(true);
844 
845  if (!bAny)
846  return;
847 
848  TrackFormulas();
849  mpShell->Broadcast( SfxHint(SfxHintId::ScDataChanged) );
850 
851  // #i101960# set document modified, as in TrackTimeHdl for DDE links
852  if (!mpShell->IsModified())
853  {
854  mpShell->SetModified();
855  SfxBindings* pBindings = GetViewBindings();
856  if (pBindings)
857  {
858  pBindings->Invalidate( SID_SAVEDOC );
859  pBindings->Invalidate( SID_DOC_MODIFIED );
860  }
861  }
862 }
863 
864 void ScDocument::CopyDdeLinks( ScDocument& rDestDoc ) const
865 {
866  if (bIsClip) // Create from Stream
867  {
868  if (pClipData)
869  {
870  pClipData->Seek(0);
871  rDestDoc.LoadDdeLinks(*pClipData);
872  }
873 
874  return;
875  }
876 
877  const sfx2::LinkManager* pMgr = GetDocLinkManager().getExistingLinkManager();
878  if (!pMgr)
879  return;
880 
881  sfx2::LinkManager* pDestMgr = rDestDoc.GetDocLinkManager().getLinkManager(rDestDoc.bAutoCalc);
882  if (!pDestMgr)
883  return;
884 
885  const sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
886  for (const auto & rLink : rLinks)
887  {
888  const sfx2::SvBaseLink* pBase = rLink.get();
889  if (const ScDdeLink* p = dynamic_cast<const ScDdeLink*>(pBase))
890  {
891  ScDdeLink* pNew = new ScDdeLink(rDestDoc, *p);
892  pDestMgr->InsertDDELink(
893  pNew, pNew->GetAppl(), pNew->GetTopic(), pNew->GetItem());
894  }
895  }
896 }
897 
898 namespace {
899 
904 ScDdeLink* lclGetDdeLink(
905  const sfx2::LinkManager* pLinkManager,
906  const OUString& rAppl, const OUString& rTopic, const OUString& rItem, sal_uInt8 nMode,
907  size_t* pnDdePos = nullptr )
908 {
909  if( pLinkManager )
910  {
911  const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
912  size_t nCount = rLinks.size();
913  if( pnDdePos ) *pnDdePos = 0;
914  for( size_t nIndex = 0; nIndex < nCount; ++nIndex )
915  {
916  ::sfx2::SvBaseLink* pLink = rLinks[ nIndex ].get();
917  if( ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>( pLink ) )
918  {
919  if( (pDdeLink->GetAppl() == rAppl) &&
920  (pDdeLink->GetTopic() == rTopic) &&
921  (pDdeLink->GetItem() == rItem) &&
922  ((nMode == SC_DDE_IGNOREMODE) || (nMode == pDdeLink->GetMode())) )
923  return pDdeLink;
924  if( pnDdePos ) ++*pnDdePos;
925  }
926  }
927  }
928  return nullptr;
929 }
930 
934 ScDdeLink* lclGetDdeLink( const sfx2::LinkManager* pLinkManager, size_t nDdePos )
935 {
936  if( pLinkManager )
937  {
938  const ::sfx2::SvBaseLinks& rLinks = pLinkManager->GetLinks();
939  size_t nCount = rLinks.size();
940  size_t nDdeIndex = 0; // counts only the DDE links
941  for( size_t nIndex = 0; nIndex < nCount; ++nIndex )
942  {
943  ::sfx2::SvBaseLink* pLink = rLinks[ nIndex ].get();
944  if( ScDdeLink* pDdeLink = dynamic_cast<ScDdeLink*>( pLink ) )
945  {
946  if( nDdeIndex == nDdePos )
947  return pDdeLink;
948  ++nDdeIndex;
949  }
950  }
951  }
952  return nullptr;
953 }
954 
955 } // namespace
956 
957 bool ScDocument::FindDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem,
958  sal_uInt8 nMode, size_t& rnDdePos )
959 {
960  return lclGetDdeLink( GetLinkManager(), rAppl, rTopic, rItem, nMode, &rnDdePos ) != nullptr;
961 }
962 
963 bool ScDocument::GetDdeLinkData( size_t nDdePos, OUString& rAppl, OUString& rTopic, OUString& rItem ) const
964 {
965  if( const ScDdeLink* pDdeLink = lclGetDdeLink( GetLinkManager(), nDdePos ) )
966  {
967  rAppl = pDdeLink->GetAppl();
968  rTopic = pDdeLink->GetTopic();
969  rItem = pDdeLink->GetItem();
970  return true;
971  }
972  return false;
973 }
974 
975 bool ScDocument::GetDdeLinkMode( size_t nDdePos, sal_uInt8& rnMode ) const
976 {
977  if( const ScDdeLink* pDdeLink = lclGetDdeLink( GetLinkManager(), nDdePos ) )
978  {
979  rnMode = pDdeLink->GetMode();
980  return true;
981  }
982  return false;
983 }
984 
985 const ScMatrix* ScDocument::GetDdeLinkResultMatrix( size_t nDdePos ) const
986 {
987  const ScDdeLink* pDdeLink = lclGetDdeLink( GetLinkManager(), nDdePos );
988  return pDdeLink ? pDdeLink->GetResult() : nullptr;
989 }
990 
991 bool ScDocument::CreateDdeLink( const OUString& rAppl, const OUString& rTopic, const OUString& rItem, sal_uInt8 nMode, const ScMatrixRef& pResults )
992 {
993  /* Create a DDE link without updating it (i.e. for Excel import), to prevent
994  unwanted connections. First try to find existing link. Set result array
995  on existing and new links. */
996  //TODO: store DDE links additionally at document (for efficiency)?
997  OSL_ENSURE( nMode != SC_DDE_IGNOREMODE, "ScDocument::CreateDdeLink - SC_DDE_IGNOREMODE not allowed here" );
998 
999  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(bAutoCalc);
1000  if (!pMgr)
1001  return false;
1002 
1003  if (nMode != SC_DDE_IGNOREMODE)
1004  {
1005  ScDdeLink* pDdeLink = lclGetDdeLink(pMgr, rAppl, rTopic, rItem, nMode);
1006  if( !pDdeLink )
1007  {
1008  // create a new DDE link, but without TryUpdate
1009  pDdeLink = new ScDdeLink( *this, rAppl, rTopic, rItem, nMode );
1010  pMgr->InsertDDELink(pDdeLink, rAppl, rTopic, rItem);
1011  }
1012 
1013  // insert link results
1014  if( pResults )
1015  pDdeLink->SetResult( pResults );
1016 
1017  return true;
1018  }
1019  return false;
1020 }
1021 
1022 bool ScDocument::SetDdeLinkResultMatrix( size_t nDdePos, const ScMatrixRef& pResults )
1023 {
1024  if( ScDdeLink* pDdeLink = lclGetDdeLink( GetLinkManager(), nDdePos ) )
1025  {
1026  pDdeLink->SetResult( pResults );
1027  return true;
1028  }
1029  return false;
1030 }
1031 
1033 {
1034  const sfx2::LinkManager* pMgr = GetDocLinkManager().getExistingLinkManager();
1035  if (!pMgr)
1036  return false;
1037 
1038  const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
1039  sal_uInt16 nCount = rLinks.size();
1040  for (sal_uInt16 i=0; i<nCount; i++)
1041  if (nullptr != dynamic_cast<const ScAreaLink* >(rLinks[i].get()))
1042  return true;
1043 
1044  return false;
1045 }
1046 
1048 {
1049  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(false);
1050  if (!pMgr)
1051  return;
1052 
1053  const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
1054  for (const auto & rLink : rLinks)
1055  {
1056  ::sfx2::SvBaseLink* pBase = rLink.get();
1057  if (dynamic_cast<const ScAreaLink*>( pBase) != nullptr)
1058  pBase->Update();
1059  }
1060 }
1061 
1063 {
1064  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(false);
1065  if (!pMgr)
1066  return;
1067 
1068  const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
1069  sfx2::SvBaseLinks::size_type nPos = 0;
1070  while ( nPos < rLinks.size() )
1071  {
1072  const ::sfx2::SvBaseLink* pBase = rLinks[nPos].get();
1073  const ScAreaLink* pLink = dynamic_cast<const ScAreaLink*>(pBase);
1074  if (pLink && pLink->GetDestArea().aStart.Tab() == nTab)
1075  pMgr->Remove(nPos);
1076  else
1077  ++nPos;
1078  }
1079 }
1080 
1082  const ScRange& rRange, SCCOL nDx, SCROW nDy, SCTAB nDz )
1083 {
1084  sfx2::LinkManager* pMgr = GetDocLinkManager().getLinkManager(false);
1085  if (!pMgr)
1086  return;
1087 
1088  bool bAnyUpdate = false;
1089 
1090  const ::sfx2::SvBaseLinks& rLinks = pMgr->GetLinks();
1091  sal_uInt16 nCount = rLinks.size();
1092  for (sal_uInt16 i=0; i<nCount; i++)
1093  {
1094  ::sfx2::SvBaseLink* pBase = rLinks[i].get();
1095  if (ScAreaLink* pLink = dynamic_cast<ScAreaLink*>(pBase))
1096  {
1097  ScRange aOutRange = pLink->GetDestArea();
1098 
1099  SCCOL nCol1 = aOutRange.aStart.Col();
1100  SCROW nRow1 = aOutRange.aStart.Row();
1101  SCTAB nTab1 = aOutRange.aStart.Tab();
1102  SCCOL nCol2 = aOutRange.aEnd.Col();
1103  SCROW nRow2 = aOutRange.aEnd.Row();
1104  SCTAB nTab2 = aOutRange.aEnd.Tab();
1105 
1106  ScRefUpdateRes eRes =
1107  ScRefUpdate::Update( this, eUpdateRefMode,
1108  rRange.aStart.Col(), rRange.aStart.Row(), rRange.aStart.Tab(),
1109  rRange.aEnd.Col(), rRange.aEnd.Row(), rRange.aEnd.Tab(), nDx, nDy, nDz,
1110  nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 );
1111  if ( eRes != UR_NOTHING )
1112  {
1113  pLink->SetDestArea( ScRange( nCol1, nRow1, nTab1, nCol2, nRow2, nTab2 ) );
1114  bAnyUpdate = true;
1115  }
1116  }
1117  }
1118 
1119  if ( !bAnyUpdate )
1120  return;
1121 
1122  // #i52120# Look for duplicates (after updating all positions).
1123  // If several links start at the same cell, the one with the lower index is removed
1124  // (file format specifies only one link definition for a cell).
1125 
1126  sal_uInt16 nFirstIndex = 0;
1127  while ( nFirstIndex < nCount )
1128  {
1129  bool bFound = false;
1130  ::sfx2::SvBaseLink* pFirst = rLinks[nFirstIndex].get();
1131  if (ScAreaLink* pFirstLink = dynamic_cast<ScAreaLink*>(pFirst))
1132  {
1133  ScAddress aFirstPos = pFirstLink->GetDestArea().aStart;
1134  for ( sal_uInt16 nSecondIndex = nFirstIndex + 1; nSecondIndex < nCount && !bFound; ++nSecondIndex )
1135  {
1136  ::sfx2::SvBaseLink* pSecond = rLinks[nSecondIndex].get();
1137  ScAreaLink* pSecondLink = dynamic_cast<ScAreaLink*>(pSecond);
1138  if (pSecondLink && pSecondLink->GetDestArea().aStart == aFirstPos)
1139  {
1140  // remove the first link, exit the inner loop, don't increment nFirstIndex
1141  pMgr->Remove(pFirst);
1142  nCount = rLinks.size();
1143  bFound = true;
1144  }
1145  }
1146  }
1147  if (!bFound)
1148  ++nFirstIndex;
1149  }
1150 }
1151 
1153 {
1154  if (HasLinkFormulaNeedingCheck())
1155  return;
1156 
1157  // Prefer RPN over tokenized formula if available.
1158  if (rCode.GetCodeLen())
1159  {
1160  if (rCode.HasOpCodeRPN(ocDde) || rCode.HasOpCodeRPN(ocWebservice))
1161  SetLinkFormulaNeedingCheck(true);
1162  }
1163  else if (rCode.GetLen())
1164  {
1165  if (rCode.HasOpCode(ocDde) || rCode.HasOpCode(ocWebservice))
1166  SetLinkFormulaNeedingCheck(true);
1167  }
1168  else
1169  {
1170  // Possible with named expression without expression like Excel
1171  // internal print ranges, obscure user define names, ... formula error
1172  // cells without formula ...
1173  SAL_WARN("sc.core","ScDocument::CheckLinkFormulaNeedingCheck - called with empty ScTokenArray");
1174  }
1175 }
1176 
1177 // TimerDelays etc.
1179 {
1180  if ( pChartListenerCollection->hasListeners() )
1181  pChartListenerCollection->StartTimer();
1182  if (apTemporaryChartLock)
1183  apTemporaryChartLock->StartOrContinueLocking();
1184 }
1185 
1187 {
1188  // used to invalidate slots after changes to this document
1189 
1190  if ( !mpShell )
1191  return nullptr; // no ObjShell -> no view
1192 
1193  // first check current view
1194  SfxViewFrame* pViewFrame = SfxViewFrame::Current();
1195  if ( pViewFrame && pViewFrame->GetObjectShell() != mpShell ) // wrong document?
1196  pViewFrame = nullptr;
1197 
1198  // otherwise use first view for this doc
1199  if ( !pViewFrame )
1200  pViewFrame = SfxViewFrame::GetFirst( mpShell );
1201 
1202  if (pViewFrame)
1203  return &pViewFrame->GetBindings();
1204  else
1205  return nullptr;
1206 }
1207 
1209 {
1210  OSL_ENSURE( rMultiMark.IsMultiMarked(), "TransliterateText: no selection" );
1211 
1212  utl::TransliterationWrapper aTransliterationWrapper( comphelper::getProcessComponentContext(), nType );
1213  bool bConsiderLanguage = aTransliterationWrapper.needLanguageForTheMode();
1214  LanguageType nLanguage = LANGUAGE_SYSTEM;
1215 
1216  std::unique_ptr<ScEditEngineDefaulter> pEngine; // not using mpEditEngine member because of defaults
1217 
1218  SCTAB nCount = GetTableCount();
1219  for (const SCTAB& nTab : rMultiMark)
1220  {
1221  if (nTab >= nCount)
1222  break;
1223 
1224  if ( maTabs[nTab] )
1225  {
1226  SCCOL nCol = 0;
1227  SCROW nRow = 0;
1228 
1229  bool bFound = rMultiMark.IsCellMarked( nCol, nRow );
1230  if (!bFound)
1231  bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark );
1232 
1233  while (bFound)
1234  {
1235  ScRefCellValue aCell(*this, ScAddress(nCol, nRow, nTab));
1236 
1237  // fdo#32786 TITLE_CASE/SENTENCE_CASE need the extra handling in EditEngine (loop over words/sentences).
1238  // Still use TransliterationWrapper directly for text cells with other transliteration types,
1239  // for performance reasons.
1240  if (aCell.meType == CELLTYPE_EDIT ||
1241  (aCell.meType == CELLTYPE_STRING &&
1242  ( nType == TransliterationFlags::SENTENCE_CASE || nType == TransliterationFlags::TITLE_CASE)))
1243  {
1244  if (!pEngine)
1245  pEngine.reset(new ScFieldEditEngine(this, GetEnginePool(), GetEditPool()));
1246 
1247  // defaults from cell attributes must be set so right language is used
1248  const ScPatternAttr* pPattern = GetPattern( nCol, nRow, nTab );
1249  std::unique_ptr<SfxItemSet> pDefaults(new SfxItemSet( pEngine->GetEmptyItemSet() ));
1250  if ( ScStyleSheet* pPreviewStyle = GetPreviewCellStyle( nCol, nRow, nTab ) )
1251  {
1252  std::unique_ptr<ScPatternAttr> pPreviewPattern(new ScPatternAttr( *pPattern ));
1253  pPreviewPattern->SetStyleSheet(pPreviewStyle);
1254  pPreviewPattern->FillEditItemSet( pDefaults.get() );
1255  }
1256  else
1257  {
1258  SfxItemSet* pFontSet = GetPreviewFont( nCol, nRow, nTab );
1259  pPattern->FillEditItemSet( pDefaults.get(), pFontSet );
1260  }
1261  pEngine->SetDefaults( std::move(pDefaults) );
1262  if (aCell.meType == CELLTYPE_STRING)
1263  pEngine->SetTextCurrentDefaults(aCell.mpString->getString());
1264  else if (aCell.mpEditText)
1265  pEngine->SetTextCurrentDefaults(*aCell.mpEditText);
1266 
1267  pEngine->ClearModifyFlag();
1268 
1269  sal_Int32 nLastPar = pEngine->GetParagraphCount();
1270  if (nLastPar)
1271  --nLastPar;
1272  sal_Int32 nTxtLen = pEngine->GetTextLen(nLastPar);
1273  ESelection aSelAll( 0, 0, nLastPar, nTxtLen );
1274 
1275  pEngine->TransliterateText( aSelAll, nType );
1276 
1277  if ( pEngine->IsModified() )
1278  {
1279  ScEditAttrTester aTester( pEngine.get() );
1280  if ( aTester.NeedsObject() )
1281  {
1282  // remove defaults (paragraph attributes) before creating text object
1283  pEngine->SetDefaults( std::make_unique<SfxItemSet>( pEngine->GetEmptyItemSet() ) );
1284 
1285  // The cell will take ownership of the text object instance.
1286  SetEditText(ScAddress(nCol,nRow,nTab), pEngine->CreateTextObject());
1287  }
1288  else
1289  {
1290  ScSetStringParam aParam;
1291  aParam.setTextInput();
1292  SetString(ScAddress(nCol,nRow,nTab), pEngine->GetText(), &aParam);
1293  }
1294  }
1295  }
1296 
1297  else if (aCell.meType == CELLTYPE_STRING)
1298  {
1299  OUString aOldStr = aCell.mpString->getString();
1300  sal_Int32 nOldLen = aOldStr.getLength();
1301 
1302  if ( bConsiderLanguage )
1303  {
1304  SvtScriptType nScript = GetStringScriptType( aOldStr ); //TODO: cell script type?
1305  sal_uInt16 nWhich = ( nScript == SvtScriptType::ASIAN ) ? ATTR_CJK_FONT_LANGUAGE :
1306  ( ( nScript == SvtScriptType::COMPLEX ) ? ATTR_CTL_FONT_LANGUAGE :
1308  nLanguage = static_cast<const SvxLanguageItem*>(GetAttr( nCol, nRow, nTab, nWhich ))->GetValue();
1309  }
1310 
1311  uno::Sequence<sal_Int32> aOffsets;
1312  OUString aNewStr = aTransliterationWrapper.transliterate( aOldStr, nLanguage, 0, nOldLen, &aOffsets );
1313 
1314  if ( aNewStr != aOldStr )
1315  {
1316  ScSetStringParam aParam;
1317  aParam.setTextInput();
1318  SetString(ScAddress(nCol,nRow,nTab), aNewStr, &aParam);
1319  }
1320  }
1321  bFound = GetNextMarkedCell( nCol, nRow, nTab, rMultiMark );
1322  }
1323  }
1324  }
1325 }
1326 
1327 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Matrix data type that can store values of mixed types.
Definition: scmatrix.hxx:113
constexpr double nPPTY
void EnableIdle(bool bDo)
Definition: document.hxx:2118
OUString sMessage
static ScRefUpdateRes Update(const ScDocument *pDoc, UpdateRefMode eUpdateRefMode, SCCOL nCol1, SCROW nRow1, SCTAB nTab1, SCCOL nCol2, SCROW nRow2, SCTAB nTab2, SCCOL nDx, SCROW nDy, SCTAB nDz, SCCOL &theCol1, SCROW &theRow1, SCTAB &theTab1, SCCOL &theCol2, SCROW &theRow2, SCTAB &theTab2)
Definition: refupdat.cxx:189
sal_Int32 nIndex
OUString getString() const
ScAddress aStart
Definition: address.hxx:500
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:43
void InvalidateTextWidth(const OUString &rStyleName)
Definition: documen8.cxx:295
Store parameters used in the ScDocument::SetString() method.
Definition: stringutil.hxx:35
constexpr TypedWhichId< SvxLanguageItem > ATTR_LANGUAGE_FORMAT(147)
void HandleStuffAfterParallelCalculation(SCCOL nColStart, SCCOL nColEnd, SCROW nRow, size_t nLen, SCTAB nTab, ScInterpreter *pInterpreter)
Definition: documen8.cxx:429
void LoadDdeLinks(SvStream &rStream)
Definition: documen8.cxx:745
SvStream & WriteUInt16(sal_uInt16 nUInt16)
void IncTab(SCTAB nDelta=1)
Definition: address.hxx:308
void SC_DLLPUBLIC SetFormulaResults(const ScAddress &rTopPos, const double *pResults, size_t nLen)
Set an array of numerical formula results to a group of contiguous formula cells. ...
Definition: documen8.cxx:402
SCROW Row() const
Definition: address.hxx:262
void setTextInput()
Call this whenever you need to unconditionally set input as text, no matter what the input is...
Definition: stringutil.cxx:38
constexpr TypedWhichId< SvxLanguageItem > ATTR_CJK_FONT_LANGUAGE(115)
constexpr sal_uInt16 ATTR_PATTERN_START(100)
SvStream & ReadUInt16(sal_uInt16 &rUInt16)
std::string GetValue
sal_Int32 GetVersion() const
void SetInLinkUpdate(bool bSet)
Definition: documen8.cxx:774
SC_DLLPUBLIC void CopyStdStylesFrom(const ScDocument &rSrcDoc)
Definition: documen8.cxx:288
void FillMatrix(ScMatrix &rMat, SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, svl::SharedStringPool *pPool=nullptr) const
Definition: documen8.cxx:384
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(175)
sal_uIntPtr sal_uLong
constexpr TypedWhichId< SvxLanguageItem > ATTR_FONT_LANGUAGE(110)
const sal_uInt8 SC_DDE_DEFAULT
Definition: document.hxx:291
sal_Int64 n
bool HasOpCode(OpCode) const
#define CALCMAX
Definition: documen8.cxx:465
SC_DLLPUBLIC bool CreateDdeLink(const OUString &rAppl, const OUString &rTopic, const OUString &rItem, sal_uInt8 nMode, const ScMatrixRef &pResults)
Tries to find a DDE link or creates a new, if not extant.
Definition: documen8.cxx:991
void ModifyStyleSheet(SfxStyleSheetBase &rPageStyle, const SfxItemSet &rChanges)
Definition: documen8.cxx:209
void SetFormulaResults(SCCOL nCol, SCROW nRow, const double *pResults, size_t nLen)
Definition: table1.cxx:2510
const MapMode & GetMapMode() const
sal_uInt16 GetCodeLen() const
ScAddress aEnd
Definition: address.hxx:501
SvxFrameDirection
VirtualDevice * GetVirtualDevice_100th_mm()
Definition: documen8.cxx:181
virtual SfxItemSet & GetItemSet()
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
void RepaintRange(const ScRange &rRange)
Definition: docuno.cxx:492
void Invalidate(sal_uInt16 nId)
sc::DocumentLinkManager & GetDocLinkManager()
Definition: documen2.cxx:225
SfxStyleFamily GetFamily() const
virtual SfxObjectShell * GetObjectShell() override
void SetPrinter(VclPtr< SfxPrinter > const &pNewPrinter)
Definition: documen8.cxx:141
void SetMapMode()
sfx2::LinkManager * getLinkManager(bool bCreate=true)
void SetString(SwCursor &rCursor, const OUString &rString)
void TransliterateText(const ScMarkData &rMultiMark, TransliterationFlags nType)
Definition: documen8.cxx:1208
SfxPrinter * GetPrinter(bool bCreateIfNotExist=true)
Definition: documen8.cxx:113
void CalculateInColumnInThread(ScInterpreterContext &rContext, SCCOL nColStart, SCCOL nColEnd, SCROW nRowStart, SCROW nRowEnd, unsigned nThisThread, unsigned nThreadsTotal)
Definition: table1.cxx:2518
void RepaintRange(const ScRange &rRange)
Definition: documen8.cxx:687
static void SetupFromNonThreadedData(const ScDocumentThreadSpecific &rNonThreadedData)
Definition: document.cxx:6822
SC_DLLPUBLIC void CheckLinkFormulaNeedingCheck(const ScTokenArray &rCode)
Check token array and set link check if ocDde/ocWebservice is contained.
Definition: documen8.cxx:1152
const OUString & GetName() const
SfxPrinterChangeFlags
const EditTextObject * mpEditText
Definition: cellvalue.hxx:110
size_t SCSIZE
size_t typedef to be able to find places where code was changed from USHORT to size_t and is used to ...
Definition: address.hxx:45
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
void FillMatrix(ScMatrix &rMat, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, svl::SharedStringPool *pPool) const
Definition: table1.cxx:2496
bool IsMultiMarked() const
Definition: markdata.hxx:83
bool SetDdeLinkResultMatrix(size_t nDdePos, const ScMatrixRef &pResults)
Sets a result matrix for the specified DDE link.
Definition: documen8.cxx:1022
int nCount
const ScDocumentThreadSpecific & CalculateInColumnInThread(ScInterpreterContext &rContext, const ScRange &rCalcRange, unsigned nThisThread, unsigned nThreadsTotal)
Definition: documen8.cxx:411
::boost::intrusive_ptr< ScMatrix > ScMatrixRef
Definition: types.hxx:26
void HandleStuffAfterParallelCalculation(SCCOL nColStart, SCCOL nColEnd, SCROW nRow, size_t nLen, ScInterpreter *pInterpreter)
Definition: table1.cxx:2535
SCTAB Tab() const
Definition: address.hxx:271
void SetRow(SCROW nRowP)
Definition: address.hxx:275
bool RenamePageStyleInUse(const OUString &rOld, const OUString &rNew)
Definition: documen8.cxx:340
const sal_uInt8 SC_DDE_IGNOREMODE
Definition: document.hxx:294
sal_uInt64 remainingSize()
void SetCol(SCCOL nColP)
Definition: address.hxx:279
TransliterationFlags
sal_uInt16 GetLen() const
void ImplCreateOptions()
Definition: documen8.cxx:100
constexpr double nPPTX
ocDde
void SetTab(SCTAB nTabP)
Definition: address.hxx:283
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SvtScriptType
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SvBaseLinks & GetLinks() const
int i
void Remove(SvBaseLink const *pLink)
void IncCol(SCCOL nDelta=1)
Definition: address.hxx:304
void GetDimensions(SCSIZE &rC, SCSIZE &rR) const
Definition: scmatrix.cxx:2984
#define LANGUAGE_SYSTEM
const svl::SharedString * mpString
Definition: cellvalue.hxx:109
sal_Int16 SCCOL
Definition: types.hxx:22
SC_DLLPUBLIC const ScMatrix * GetDdeLinkResultMatrix(size_t nDdePos) const
Returns the result matrix of the specified DDE link.
Definition: documen8.cxx:985
bool GetDdeLinkData(size_t nDdePos, OUString &rAppl, OUString &rTopic, OUString &rItem) const
Returns the connection data of the specified DDE link.
Definition: documen8.cxx:963
#define SC_MOD()
Definition: scmod.hxx:253
bool HasAreaLinks() const
Definition: documen8.cxx:1032
SfxBindings & GetBindings()
bool GetDdeLinkMode(size_t nDdePos, sal_uInt8 &rnMode) const
Returns the link mode of the specified DDE link.
Definition: documen8.cxx:975
EEHorizontalTextDirection
OUString ScResId(const char *pId)
Definition: scdll.cxx:95
#define LANGUAGE_DONTKNOW
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
static void DeleteInterpretProgress()
Definition: progress.cxx:155
ScColContainer aCol
Definition: table.hxx:156
void SaveDdeLinks(SvStream &rStream) const
Definition: documen8.cxx:707
static void CreateInterpretProgress(ScDocument *pDoc, bool bWait=true)
Definition: progress.cxx:135
const SCTAB MAXTAB
Definition: address.hxx:71
Use this class as a locale variable to merge number formatter from another document, and set NULL pointer to pFormatExchangeList when done.
Definition: document.hxx:2556
void UpdateRefAreaLinks(UpdateRefMode eUpdateRefMode, const ScRange &r, SCCOL nDx, SCROW nDy, SCTAB nDz)
Definition: documen8.cxx:1081
Reference not affected, no change at all.
Definition: refupdat.hxx:32
SCCOL Col() const
Definition: address.hxx:267
exports com.sun.star.chart2. data
void InsertDDELink(SvBaseLink *, const OUString &rServer, const OUString &rTopic, const OUString &rItem)
SC_DLLPUBLIC ScMacroManager * GetMacroManager()
Definition: documen8.cxx:377
ocWebservice
Point LogicToPixel(const Point &rLogicPt) const
bool IdleCalcTextWidth()
Definition: documen8.cxx:530
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
constexpr TypedWhichId< SvxLanguageItem > ATTR_CTL_FONT_LANGUAGE(120)
CellType meType
Definition: cellvalue.hxx:106
void SetState(sal_uLong nVal, sal_uLong nNewRange=0)
Definition: progress.hxx:79
static bool GetDisplayNames(const SvBaseLink *, OUString *pType, OUString *pFile=nullptr, OUString *pLink=nullptr, OUString *pFilter=nullptr)
constexpr TypedWhichId< SvxFrameDirectionItem > ATTR_WRITINGDIR(138)
UpdateRefMode
Definition: global.hxx:311
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:18
void UpdateExternalRefLinks(weld::Window *pWin)
Definition: documen8.cxx:787
EEHorizontalTextDirection GetEditTextDirection(SCTAB nTab) const
Definition: documen8.cxx:355
OUString aPageStyle
Definition: table.hxx:170
SC_DLLPUBLIC OutputDevice * GetRefDevice()
Definition: documen8.cxx:198
std::vector< tools::SvRef< SvBaseLink > > SvBaseLinks
static SfxViewFrame * Current()
SfxItemState
void SetPrintOptions()
Definition: documen8.cxx:160
SC_DLLPUBLIC bool FindDdeLink(const OUString &rAppl, const OUString &rTopic, const OUString &rItem, sal_uInt8 nMode, size_t &rnDdePos)
Tries to find a DDE link with the specified connection data.
Definition: documen8.cxx:957
#define SOFFICE_FILEFORMAT_40
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
SvBaseLink * pLink
unsigned char sal_uInt8
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
bool IsCTLFontEnabled() const
SfxBindings * GetViewBindings()
Definition: documen8.cxx:1186
static VclPtr< reference_type > Create(Arg &&...arg)
static bool CheckWidthInvalidate(bool &bNumFormatChanged, const SfxItemSet &rNewAttrs, const SfxItemSet &rOldAttrs)
Definition: global.cxx:178
rtl_TextEncoding GetStreamCharSet() const
void * p
Reference< XComponentContext > getProcessComponentContext()
QPRO_FUNC_TYPE nType
Definition: qproform.cxx:401
constexpr sal_uInt16 ATTR_PATTERN_END(155)
ScRefUpdateRes
Definition: refupdat.hxx:31
void DeleteAreaLinksOnTab(SCTAB nTab)
Definition: documen8.cxx:1062
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6066
bool IsInLinkUpdate() const
Definition: documen8.cxx:782
bool bAutoCalc
Definition: document.hxx:491
bool ValidRow(SCROW nRow, SCROW nMaxRow)
Definition: address.hxx:99
reference_type * get() const
rtl::Reference< ScPoolHelper > mxPoolHelper
Definition: document.hxx:363
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
#define SAL_WARN(area, stream)
SC_DLLPUBLIC void CopyDdeLinks(ScDocument &rDestDoc) const
Definition: documen8.cxx:864
SCCOL ClampToAllocatedColumns(SCCOL nCol) const
Definition: table.hxx:1084
bool IsFormulaDirty(SCROW nRow) const
Definition: column.cxx:3219
void UpdateAreaLinks()
Definition: documen8.cxx:1047
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALE(174)
bool IsPageStyleInUse(const OUString &rStrPageStyle, SCTAB *pInTab)
Definition: documen8.cxx:310
For usage in FindDdeLink() only!
Definition: document.hxx:297
bool ValidTab(SCTAB nTab)
Definition: address.hxx:105
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
static sal_uInt16 DoUpdateAllCharts(ScDocument &rDoc)
void ImplDeleteOptions()
Definition: documen8.cxx:106
LanguageType GetLanguage() const
sal_uInt16 nPos
sal_Int16 SCTAB
Definition: types.hxx:23
bool RemovePageStyleInUse(const OUString &rStrPageStyle)
Definition: documen8.cxx:325
#define TEXTWIDTH_DIRTY
Definition: globalnames.hxx:18
void FillEditItemSet(SfxItemSet *pEditSet, const SfxItemSet *pCondSet=nullptr) const
Converts all Calc items contained in the own item set to edit engine items and puts them into pEditSe...
Definition: patattr.cxx:776
void KeyInput()
Definition: documen8.cxx:1178
bool HasOpCodeRPN(OpCode) const