LibreOffice Module sc (master)  1
tabvwsha.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 <com/sun/star/table/BorderLineStyle.hpp>
21 
22 #include <comphelper/lok.hxx>
23 #include <editeng/boxitem.hxx>
24 #include <o3tl/temporary.hxx>
25 #include <sfx2/bindings.hxx>
26 #include <sfx2/request.hxx>
27 #include <sfx2/sfxdlg.hxx>
28 #include <sfx2/sidebar/Sidebar.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <svl/ilstitem.hxx>
31 #include <svl/numformat.hxx>
32 #include <svl/zformat.hxx>
33 #include <svl/int64item.hxx>
34 #include <svl/srchitem.hxx>
35 #include <svl/srchdefs.hxx>
36 #include <svl/stritem.hxx>
37 #include <svl/whiter.hxx>
38 #include <svx/numinf.hxx>
39 #include <svx/zoomslideritem.hxx>
40 
41 #include <global.hxx>
42 #include <appoptio.hxx>
43 #include <attrib.hxx>
44 #include <cellform.hxx>
45 #include <cellvalue.hxx>
46 #include <compiler.hxx>
47 #include <docsh.hxx>
48 #include <document.hxx>
49 #include <formulacell.hxx>
50 #include <globstr.hrc>
51 #include <inputhdl.hxx>
52 #include <inputwin.hxx>
53 #include <markdata.hxx>
54 #include <patattr.hxx>
55 #include <sc.hrc>
56 #include <scabstdlg.hxx>
57 #include <scitems.hxx>
58 #include <scmod.hxx>
59 #include <scresid.hxx>
60 #include <stlpool.hxx>
61 #include <tabvwsh.hxx>
62 #include <tokenarray.hxx>
63 #include <viewdata.hxx>
64 
65 #include <memory>
66 
67 using namespace com::sun::star;
68 
69 bool ScTabViewShell::GetFunction( OUString& rFuncStr, FormulaError nErrCode )
70 {
71  sal_uInt32 nFuncs = SC_MOD()->GetAppOptions().GetStatusFunc();
72  ScViewData& rViewData = GetViewData();
73  ScMarkData& rMark = rViewData.GetMarkData();
74  bool bIgnoreError = (rMark.IsMarked() || rMark.IsMultiMarked());
75  bool bFirst = true;
76  for ( sal_uInt16 nFunc = 0; nFunc < 32; nFunc++ )
77  {
78  if ( !(nFuncs & (1U << nFunc)) )
79  continue;
80  ScSubTotalFunc eFunc = static_cast<ScSubTotalFunc>(nFunc);
81 
82  if (bIgnoreError && (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2))
83  nErrCode = FormulaError::NONE;
84 
85  if (nErrCode != FormulaError::NONE)
86  {
87  rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
88  return true;
89  }
90 
91  TranslateId pGlobStrId;
92  switch (eFunc)
93  {
94  case SUBTOTAL_FUNC_AVE: pGlobStrId = STR_FUN_TEXT_AVG; break;
95  case SUBTOTAL_FUNC_CNT: pGlobStrId = STR_FUN_TEXT_COUNT; break;
96  case SUBTOTAL_FUNC_CNT2: pGlobStrId = STR_FUN_TEXT_COUNT2; break;
97  case SUBTOTAL_FUNC_MAX: pGlobStrId = STR_FUN_TEXT_MAX; break;
98  case SUBTOTAL_FUNC_MIN: pGlobStrId = STR_FUN_TEXT_MIN; break;
99  case SUBTOTAL_FUNC_SUM: pGlobStrId = STR_FUN_TEXT_SUM; break;
100  case SUBTOTAL_FUNC_SELECTION_COUNT: pGlobStrId = STR_FUN_TEXT_SELECTION_COUNT; break;
101 
102  default:
103  {
104  // added to avoid warnings
105  }
106  }
107  if (pGlobStrId)
108  {
109  ScDocument& rDoc = rViewData.GetDocument();
110  SCCOL nPosX = rViewData.GetCurX();
111  SCROW nPosY = rViewData.GetCurY();
112  SCTAB nTab = rViewData.GetTabNo();
113 
114  OUString aStr = ScResId(pGlobStrId) + ": ";
115 
116  ScAddress aCursor( nPosX, nPosY, nTab );
117  double nVal;
118  if ( rDoc.GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
119  {
120  if ( nVal == 0.0 )
121  aStr += "0";
122  else
123  {
124  // Number in the standard format, the other on the cursor position
125  SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
126  sal_uInt32 nNumFmt = 0;
127  if ( eFunc != SUBTOTAL_FUNC_CNT && eFunc != SUBTOTAL_FUNC_CNT2 && eFunc != SUBTOTAL_FUNC_SELECTION_COUNT)
128  {
129  // number format from attributes or formula
130  nNumFmt = rDoc.GetNumberFormat( nPosX, nPosY, nTab );
131  // If the number format is time (without date) and the
132  // result is not within 24 hours, use a duration
133  // format. Summing date+time doesn't make much sense
134  // otherwise but we also don't want to display duration
135  // for a single date+time value.
136  if (nVal < 0.0 || nVal >= 1.0)
137  {
138  const SvNumberformat* pFormat = pFormatter->GetEntry(nNumFmt);
139  if (pFormat && (pFormat->GetType() == SvNumFormatType::TIME))
140  nNumFmt = pFormatter->GetTimeFormat( nVal, pFormat->GetLanguage(), true);
141  }
142  }
143 
144  OUString aValStr;
145  const Color* pDummy;
146  pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
147  aStr += aValStr;
148  }
149  }
150  if ( bFirst )
151  {
152  rFuncStr += aStr;
153  bFirst = false;
154  }
155  else
156  rFuncStr += "; " + aStr;
157  }
158  }
159 
160  return !rFuncStr.isEmpty();
161 }
162 
163 // Functions that are disabled, depending on the selection
164 // Default:
165 // SID_DELETE,
166 // SID_DELETE_CONTENTS,
167 // FID_DELETE_CELL
168 // FID_VALIDATION
169 
171 {
172  ScViewData& rViewData = GetViewData();
173  ScDocument& rDoc = rViewData.GetDocument();
174  ScDocShell* pDocShell = rViewData.GetDocShell();
175  ScMarkData& rMark = rViewData.GetMarkData();
176  SCCOL nPosX = rViewData.GetCurX();
177  SCROW nPosY = rViewData.GetCurY();
178  SCTAB nTab = rViewData.GetTabNo();
179 
180  SfxViewFrame* pThisFrame = GetViewFrame();
181  bool bOle = GetViewFrame()->GetFrame().IsInPlace();
182 
183  SCTAB nTabSelCount = rMark.GetSelectCount();
184 
185  SfxWhichIter aIter(rSet);
186  sal_uInt16 nWhich = aIter.FirstWhich();
187 
188  while ( nWhich )
189  {
190  switch ( nWhich )
191  {
192  case FID_CHG_COMMENT:
193  {
194  ScDocShell* pDocSh = GetViewData().GetDocShell();
195  ScAddress aPos( nPosX, nPosY, nTab );
196  if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
197  rSet.DisableItem( nWhich );
198  }
199  break;
200 
201  case SID_OPENDLG_EDIT_PRINTAREA:
202  case SID_ADD_PRINTAREA:
203  case SID_DEFINE_PRINTAREA:
204  {
205  if ( pDocShell && pDocShell->IsDocShared() )
206  {
207  rSet.DisableItem( nWhich );
208  }
209  }
210  break;
211 
212  case SID_DELETE_PRINTAREA:
213  if ( pDocShell && pDocShell->IsDocShared() )
214  {
215  rSet.DisableItem( nWhich );
216  }
217  else if (rDoc.IsPrintEntireSheet(nTab))
218  rSet.DisableItem(nWhich);
219  break;
220 
221  case SID_STATUS_PAGESTYLE:
222  case SID_HFEDIT:
223  GetViewData().GetDocShell()->GetStatePageStyle( rSet, nTab );
224  break;
225 
226  case SID_SEARCH_ITEM:
227  {
228  SvxSearchItem aItem(ScGlobal::GetSearchItem()); // make a copy.
229  // Search on current selection if a range is marked.
230  aItem.SetSelection(rMark.IsMarked());
231  rSet.Put(aItem);
232  break;
233  }
234 
235  case SID_SEARCH_OPTIONS:
236  {
237  // Anything goes
238  SearchOptionFlags nOptions = SearchOptionFlags::ALL;
239 
240  // No replacement if ReadOnly
241  if (GetViewData().GetDocShell()->IsReadOnly())
242  nOptions &= ~SearchOptionFlags( SearchOptionFlags::REPLACE | SearchOptionFlags::REPLACE_ALL );
243  rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(nOptions) ) );
244  }
245  break;
246 
247  case SID_CURRENTCELL:
248  {
249  ScAddress aScAddress( GetViewData().GetCurX(), GetViewData().GetCurY(), 0 );
250  OUString aAddr(aScAddress.Format(ScRefFlags::ADDR_ABS, nullptr, rDoc.GetAddressConvention()));
251  SfxStringItem aPosItem( SID_CURRENTCELL, aAddr );
252 
253  rSet.Put( aPosItem );
254  }
255  break;
256 
257  case SID_CURRENTTAB:
258  // Table for Basic is 1-based
259  rSet.Put( SfxUInt16Item( nWhich, static_cast<sal_uInt16>(GetViewData().GetTabNo()) + 1 ) );
260  break;
261 
262  case SID_CURRENTDOC:
263  rSet.Put( SfxStringItem( nWhich, GetViewData().GetDocShell()->GetTitle() ) );
264  break;
265 
266  case FID_TOGGLEINPUTLINE:
267  {
268  sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
269 
270  if ( pThisFrame->KnowsChildWindow( nId ) )
271  {
272  SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
273  rSet.Put( SfxBoolItem( nWhich, pWnd != nullptr ) );
274  }
275  else
276  rSet.DisableItem( nWhich );
277  }
278  break;
279 
280  case FID_DEL_MANUALBREAKS:
281  if (!rDoc.HasManualBreaks(nTab))
282  rSet.DisableItem( nWhich );
283  break;
284 
285  case FID_RESET_PRINTZOOM:
286  {
287  // disable if already set to default
288 
289  OUString aStyleName = rDoc.GetPageStyle( nTab );
290  ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
291  SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aStyleName,
292  SfxStyleFamily::Page );
293  OSL_ENSURE( pStyleSheet, "PageStyle not found" );
294  if ( pStyleSheet )
295  {
296  SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
297  sal_uInt16 nScale = rStyleSet.Get(ATTR_PAGE_SCALE).GetValue();
298  sal_uInt16 nPages = rStyleSet.Get(ATTR_PAGE_SCALETOPAGES).GetValue();
299  if ( nScale == 100 && nPages == 0 )
300  rSet.DisableItem( nWhich );
301  }
302  }
303  break;
304 
305  case SID_ZOOM_IN:
306  {
307  const Fraction& rZoomY = GetViewData().GetZoomY();
308  tools::Long nZoom = tools::Long(rZoomY * 100);
309  if (nZoom >= tools::Long(MAXZOOM))
310  rSet.DisableItem(nWhich);
311  }
312  break;
313  case SID_ZOOM_OUT:
314  {
315  const Fraction& rZoomY = GetViewData().GetZoomY();
316  tools::Long nZoom = tools::Long(rZoomY * 100);
317  if (nZoom <= tools::Long(MINZOOM))
318  rSet.DisableItem(nWhich);
319  }
320  break;
321 
322  case FID_SCALE:
323  case SID_ATTR_ZOOM:
324  if ( bOle )
325  rSet.DisableItem( nWhich );
326  else
327  {
328  const Fraction& rOldY = GetViewData().GetZoomY();
329  sal_uInt16 nZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
330  rSet.Put( SvxZoomItem( SvxZoomType::PERCENT, nZoom, nWhich ) );
331  }
332  break;
333 
334  case SID_ATTR_ZOOMSLIDER:
335  {
336  if ( bOle )
337  rSet.DisableItem( nWhich );
338  else
339  {
340  const Fraction& rOldY = GetViewData().GetZoomY();
341  sal_uInt16 nCurrentZoom = static_cast<sal_uInt16>(tools::Long( rOldY * 100 ));
342 
343  if( nCurrentZoom )
344  {
345  SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
346  aZoomSliderItem.AddSnappingPoint( 100 );
347  rSet.Put( aZoomSliderItem );
348  }
349  }
350  }
351  break;
352 
353  case FID_FUNCTION_BOX:
354  {
355  const bool bBoxOpen = ::sfx2::sidebar::Sidebar::IsPanelVisible(u"ScFunctionsPanel",
356  pThisFrame->GetFrame().GetFrameInterface());
357  rSet.Put(SfxBoolItem(nWhich, bBoxOpen));
358  break;
359  }
360 
361  case FID_TOGGLESYNTAX:
362  rSet.Put(SfxBoolItem(nWhich, GetViewData().IsSyntaxMode()));
363  break;
364 
365  case FID_TOGGLEHEADERS:
366  rSet.Put(SfxBoolItem(nWhich, GetViewData().IsHeaderMode()));
367  break;
368 
369  case FID_TOGGLEFORMULA:
370  {
371  const ScViewOptions& rOpts = rViewData.GetOptions();
372  bool bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
373  rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
374  }
375  break;
376 
377  case FID_NORMALVIEWMODE:
378  case FID_PAGEBREAKMODE:
379  // always handle both slots - they exclude each other
380  if ( bOle )
381  {
382  rSet.DisableItem( FID_NORMALVIEWMODE );
383  rSet.DisableItem( FID_PAGEBREAKMODE );
384  }
385  else
386  {
387  rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData().IsPagebreakMode()));
388  rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData().IsPagebreakMode()));
389  }
390  break;
391 
392  case FID_PROTECT_DOC:
393  {
394  if ( pDocShell && pDocShell->IsDocShared() )
395  {
396  rSet.DisableItem( nWhich );
397  }
398  else
399  {
400  rSet.Put( SfxBoolItem( nWhich, rDoc.IsDocProtected() ) );
401  }
402  }
403  break;
404 
405  case FID_PROTECT_TABLE:
406  {
407  if ( pDocShell && pDocShell->IsDocShared() )
408  {
409  rSet.DisableItem( nWhich );
410  }
411  else
412  {
413  rSet.Put( SfxBoolItem( nWhich, rDoc.IsTabProtected( nTab ) ) );
414  }
415  }
416  break;
417 
418  case SID_AUTO_OUTLINE:
419  {
420  if (rDoc.GetChangeTrack()!=nullptr || GetViewData().IsMultiMarked())
421  {
422  rSet.DisableItem( nWhich );
423  }
424  }
425  break;
426 
427  case SID_OUTLINE_DELETEALL:
428  {
429  SCTAB nOlTab = GetViewData().GetTabNo();
430  ScOutlineTable* pOlTable = rDoc.GetOutlineTable( nOlTab );
431  if (pOlTable == nullptr)
432  rSet.DisableItem( nWhich );
433  }
434  break;
435 
436  case SID_WINDOW_SPLIT:
437  rSet.Put(SfxBoolItem(nWhich,
438  rViewData.GetHSplitMode() == SC_SPLIT_NORMAL ||
439  rViewData.GetVSplitMode() == SC_SPLIT_NORMAL ));
440  break;
441 
442  case SID_WINDOW_FIX:
444  {
445  rSet.Put(SfxBoolItem(nWhich,
446  rViewData.GetHSplitMode() == SC_SPLIT_FIX ||
447  rViewData.GetVSplitMode() == SC_SPLIT_FIX ));
448  }
449  else
450  {
451  rSet.Put(SfxBoolItem(nWhich,
452  rViewData.GetLOKSheetFreezeIndex(true) > 0 ||
453  rViewData.GetLOKSheetFreezeIndex(false) > 0 ));
454  }
455  break;
456 
457  case SID_WINDOW_FIX_COL:
458  case SID_WINDOW_FIX_ROW:
459  {
460  bool bIsCol = (nWhich == SID_WINDOW_FIX_COL);
461  sal_Int32 nFreezeIndex = rViewData.GetLOKSheetFreezeIndex(bIsCol);
462  rSet.Put(SfxInt32Item(nWhich, nFreezeIndex));
463  }
464  break;
465 
466  case FID_CHG_SHOW:
467  {
468  if ( rDoc.GetChangeTrack() == nullptr || ( pDocShell && pDocShell->IsDocShared() ) )
469  rSet.DisableItem( nWhich );
470  }
471  break;
472  case FID_CHG_ACCEPT:
473  {
474  if(
475  ( !rDoc.GetChangeTrack() && !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
476  ||
477  ( pDocShell && pDocShell->IsDocShared() )
478  )
479  {
480  rSet.DisableItem( nWhich);
481  }
482  else
483  {
484  rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
485  pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
486  }
487  }
488  break;
489 
490  case SID_FORMATPAGE:
491  // in protected tables
492  if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
493  rSet.DisableItem( nWhich );
494  break;
495 
496  case SID_PRINTPREVIEW:
497  // Toggle slot needs a State
498  rSet.Put( SfxBoolItem( nWhich, false ) );
499  break;
500 
501  case SID_READONLY_MODE:
502  rSet.Put( SfxBoolItem( nWhich, GetViewData().GetDocShell()->IsReadOnly() ) );
503  break;
504 
505  case FID_TAB_DESELECTALL:
506  if ( nTabSelCount == 1 )
507  rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
508  break;
509 
510  case FID_TOGGLEHIDDENCOLROW:
511  const svtools::ColorConfig& rColorCfg = SC_MOD()->GetColorConfig();
513  break;
514 
515  } // switch ( nWitch )
516  nWhich = aIter.NextWhich();
517  } // while ( nWitch )
518 }
519 
520 void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OString &rName)
521 {
522  ScDocument& rDoc = GetViewData().GetDocument();
523 
524  std::shared_ptr<SvxBoxItem> aLineOuter(std::make_shared<SvxBoxItem>(ATTR_BORDER));
525  std::shared_ptr<SvxBoxInfoItem> aLineInner(std::make_shared<SvxBoxInfoItem>(ATTR_BORDER_INNER));
526 
527  const ScPatternAttr* pOldAttrs = GetSelectionPattern();
528 
529  auto pOldSet = std::make_shared<SfxItemSet>(pOldAttrs->GetItemSet());
530  std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem;
531 
532  pOldSet->MergeRange(XATTR_FILLSTYLE, XATTR_FILLCOLOR);
533 
534  pOldSet->MergeRange(SID_ATTR_BORDER_STYLES, SID_ATTR_BORDER_DEFAULT_WIDTH);
535 
536  // We only allow these border line types.
537  std::vector<sal_Int32> aBorderStyles{
538  table::BorderLineStyle::SOLID,
539  table::BorderLineStyle::DOTTED,
540  table::BorderLineStyle::DASHED,
541  table::BorderLineStyle::FINE_DASHED,
542  table::BorderLineStyle::DASH_DOT,
543  table::BorderLineStyle::DASH_DOT_DOT,
544  table::BorderLineStyle::DOUBLE_THIN };
545 
546  pOldSet->Put(SfxIntegerListItem(SID_ATTR_BORDER_STYLES, std::move(aBorderStyles)));
547 
548  // Set the default border width to 0.75 points.
549  SfxInt64Item aBorderWidthItem(SID_ATTR_BORDER_DEFAULT_WIDTH, 75);
550  pOldSet->Put(aBorderWidthItem);
551 
552  // Get border items and put them in the set:
553  GetSelectionFrame( aLineOuter, aLineInner );
554 
555  //Fix border incorrect for RTL fdo#62399
556  if( rDoc.IsLayoutRTL( GetViewData().GetTabNo() ) )
557  {
558  std::unique_ptr<SvxBoxItem> aNewFrame(aLineOuter->Clone());
559  std::unique_ptr<SvxBoxInfoItem> aTempInfo(aLineInner->Clone());
560 
561  if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::LEFT) )
562  aNewFrame->SetLine( aLineOuter->GetLeft(), SvxBoxItemLine::RIGHT );
563  if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::RIGHT) )
564  aNewFrame->SetLine( aLineOuter->GetRight(), SvxBoxItemLine::LEFT );
565 
566  aLineInner->SetValid( SvxBoxInfoItemValidFlags::LEFT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::RIGHT));
567  aLineInner->SetValid( SvxBoxInfoItemValidFlags::RIGHT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::LEFT));
568 
569  pOldSet->Put( *aNewFrame );
570  }
571  else
572  {
573  pOldSet->Put( *aLineOuter );
574  }
575 
576  pOldSet->Put( *aLineInner );
577 
578  // Generate NumberFormat Value from Value and Language and box it.
579  pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
580  pOldAttrs->GetNumberFormat( rDoc.GetFormatTable() ) ) );
581 
582  pNumberInfoItem = MakeNumberInfoItem(rDoc, GetViewData());
583 
584  pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
585  pOldSet->Put(*pNumberInfoItem );
586 
587  bInFormatDialog = true;
589 
590  VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScAttrDlg(GetFrameWeld(), pOldSet.get()));
591 
592  if (!rName.isEmpty())
593  pDlg->SetCurPageId(rName);
594 
595  auto pRequest = std::make_shared<SfxRequest>(rReq);
596  rReq.Ignore(); // the 'old' request is not relevant any more
597 
598  pDlg->StartExecuteAsync([pDlg, pOldSet, pRequest, this](sal_Int32 nResult){
599  bInFormatDialog = false;
600 
601  if ( nResult == RET_OK )
602  {
603  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
604  if(const SvxNumberInfoItem* pItem = pOutSet->GetItemIfSet(SID_ATTR_NUMBERFORMAT_INFO))
605  {
606  UpdateNumberFormatter(*pItem);
607  }
608 
609  ApplyAttributes(pOutSet, pOldSet.get());
610 
611  pRequest->Done(*pOutSet);
612  }
613 
614  pDlg->disposeOnce();
615  });
616 }
617 
619 {
620  ScModule* pScMod = SC_MOD();
621  if ( pScMod )
622  {
623  if( pScMod->IsRefDialogOpen() )
624  return pScMod->IsFormulaMode();
625  if( pScMod->IsFormulaMode() )
626  {
627  ScInputHandler* pHdl = pScMod->GetInputHdl();
628  if ( pHdl )
629  {
630  OUString aString = pHdl->GetEditString();
631  if ( !pHdl->GetSelIsRef() && aString.getLength() > 1 &&
632  ( aString[0] == '+' || aString[0] == '-' ) )
633  {
634  const ScViewData& rViewData = GetViewData();
635  ScDocument& rDoc = rViewData.GetDocument();
636  const ScAddress aPos( rViewData.GetCurPos() );
637  ScCompiler aComp( rDoc, aPos, rDoc.GetGrammar() );
638  aComp.SetCloseBrackets( false );
639  std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aString));
640  if ( pArr && pArr->MayReferenceFollow() )
641  {
642  return true;
643  }
644  }
645  else
646  {
647  return true;
648  }
649  }
650  }
651  }
652 
653  return false;
654 }
655 
657 {
658  if ( !IsRefInputMode() )
659  {
660  ScModule* pScMod = SC_MOD();
661  if ( pScMod )
662  {
663  pScMod->InputEnterHandler();
664  }
665  }
666 }
667 
668 void ScTabViewShell::UpdateInputHandler( bool bForce /* = sal_False */, bool bStopEditing /* = sal_True */ )
669 {
670  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
671 
672  if ( pHdl )
673  {
674  OUString aString;
675  const EditTextObject* pObject = nullptr;
676  ScViewData& rViewData = GetViewData();
677  ScDocument& rDoc = rViewData.GetDocument();
678  SCCOL nPosX = rViewData.GetCurX();
679  SCROW nPosY = rViewData.GetCurY();
680  SCTAB nTab = rViewData.GetTabNo();
681  SCTAB nStartTab = 0;
682  SCTAB nEndTab = 0;
683  SCCOL nStartCol = 0;
684  SCROW nStartRow = 0;
685  SCCOL nEndCol = 0;
686  SCROW nEndRow = 0;
687  ScAddress aPos = rViewData.GetCurPos();
688 
689  rViewData.GetSimpleArea( nStartCol, nStartRow, nStartTab,
690  nEndCol, nEndRow, nEndTab );
691 
692  PutInOrder( nStartCol, nEndCol );
693  PutInOrder( nStartRow, nEndRow );
694  PutInOrder( nStartTab, nEndTab );
695 
696  bool bHideFormula = false;
697  bool bHideAll = false;
698 
699  if (rDoc.IsTabProtected(nTab))
700  {
701  const ScProtectionAttr* pProt = rDoc.GetAttr( nPosX,nPosY,nTab,
703  bHideFormula = pProt->GetHideFormula();
704  bHideAll = pProt->GetHideCell();
705  }
706 
707  if (!bHideAll)
708  {
709  ScRefCellValue rCell(rDoc, aPos);
710  if (rCell.meType == CELLTYPE_FORMULA)
711  {
712  if (!bHideFormula)
713  aString = rCell.mpFormula->GetFormula();
714  }
715  else if (rCell.meType == CELLTYPE_EDIT)
716  {
717  pObject = rCell.mpEditText;
718  }
719  else
720  {
721  SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
722  sal_uInt32 nNumFmt = rDoc.GetNumberFormat( aPos );
723 
724  aString = ScCellFormat::GetInputString( rCell, nNumFmt, *pFormatter, rDoc );
725  if (rCell.meType == CELLTYPE_STRING)
726  {
727  // Put a ' in front if necessary, so that the string is not
728  // unintentionally interpreted as a number, and to show the
729  // user that it is a string (#35060#).
731  if ( pFormatter->IsNumberFormat(aString, nNumFmt, o3tl::temporary(double())) )
732  aString = "'" + aString;
733  }
734  }
735  }
736 
737  ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
738  ScAddress( nStartCol, nStartRow, nTab ),
739  ScAddress( nEndCol, nEndRow, nTab ),
740  aString,
741  pObject );
742 
743  // if using the view's local input handler, this view can always be set
744  // as current view inside NotifyChange.
745  ScTabViewShell* pSourceSh = mpInputHandler ? this : nullptr;
746 
747  pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
748  }
749 
750  SfxBindings& rBindings = GetViewFrame()->GetBindings();
751  rBindings.Invalidate( SID_STATUS_SUM ); // always together with the input row
752  rBindings.Invalidate( SID_ATTR_SIZE );
753  rBindings.Invalidate( SID_TABLE_CELL );
754 }
755 
757 {
758  if( ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl() )
759  pHdl->UpdateCellAdjust( eJust );
760 }
761 
763 {
764  // only SID_SAVEDOC / SID_SAVEASDOC
765  bool bCommitChanges = true;
766  const SfxItemSet* pReqArgs = rReq.GetArgs();
767  const SfxPoolItem* pItem;
768 
769  if (pReqArgs && pReqArgs->HasItem(FN_PARAM_1, &pItem))
770  bCommitChanges = !static_cast<const SfxBoolItem*>(pItem)->GetValue();
771 
772  // Finish entering unless 'DontTerminateEdit' is specified, even if a formula is being processed
773  if (bCommitChanges)
774  {
775  bool bLOKActive = comphelper::LibreOfficeKit::isActive();
776 
777  // Disable error dialog box when about to save in lok mode as
778  // this ultimately invokes SvpSalInstance::DoYield() when we want
779  // to save immediately without committing any erroneous input in possibly
780  // a cell with validation rules. After save is complete the user
781  // can continue editing.
782  SC_MOD()->InputEnterHandler(ScEnterMode::NORMAL, bLOKActive /* bBeforeSavingInLOK */);
783 
784  if (bLOKActive)
785  {
786  // Normally this isn't needed, but in Calc when editing a cell formula
787  // and manually saving (without changing cells or hitting enter), while
788  // InputEnterHandler will mark the doc as modified (when it is), because
789  // we will save the doc immediately afterwards, the modified state event
790  // is clobbered. To avoid that, we need to update SID_DOC_MODIFIED so that
791  // a possible state of "true" after "InputEnterHandler" will be sent
792  // as a notification. It is important that the notification goes through
793  // normal process (cache) rather than directly notifying the views.
794  // Otherwise, because there is a previous state of "false" in cache, the
795  // "false" state after saving will be ignored.
796  // This will work only if .uno:ModifiedStatus message will be removed from
797  // the mechanism that keeps in the message queue only last message of
798  // a particular status even if the values are different.
799  GetViewData().GetDocShell()->GetViewBindings()->Update(SID_DOC_MODIFIED);
800  }
801  }
802 
803  if ( GetViewData().GetDocShell()->IsDocShared() )
804  {
805  GetViewData().GetDocShell()->SetDocumentModified();
806  }
807 
808  // otherwise as normal
809  GetViewData().GetDocShell()->ExecuteSlot( rReq );
810 }
811 
813 {
814  SfxShell* pDocSh = GetViewData().GetDocShell();
815 
816  SfxWhichIter aIter(rSet);
817  sal_uInt16 nWhich = aIter.FirstWhich();
818  while( nWhich )
819  {
820  if ( nWhich != SID_SAVEDOC || !GetViewData().GetDocShell()->IsDocShared() )
821  {
822  // get state from DocShell
823  pDocSh->GetSlotState( nWhich, nullptr, &rSet );
824  }
825  nWhich = aIter.NextWhich();
826  }
827 }
828 
830 {
831  ScViewOptions aViewOptions = GetViewData().GetOptions();
832  ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
833 
834  SfxBindings& rBindings = GetViewFrame()->GetBindings();
835  const SfxItemSet* pArgs = rReq.GetArgs();
836  const SfxPoolItem* pItem;
837  sal_uInt16 nSlotId = rReq.GetSlot();
838  switch (nSlotId)
839  {
840  case SID_GRID_VISIBLE:
841  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
842  {
843  aGridOptions.SetGridVisible( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
844  aViewOptions.SetGridOptions(aGridOptions);
845  rBindings.Invalidate(SID_GRID_VISIBLE);
846  }
847  break;
848 
849  case SID_GRID_USE:
850  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
851  {
852  aGridOptions.SetUseGridSnap( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
853  aViewOptions.SetGridOptions(aGridOptions);
854  rBindings.Invalidate(SID_GRID_USE);
855  }
856  break;
857 
858  case SID_HELPLINES_MOVE:
859  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
860  {
861  aViewOptions.SetOption( VOPT_HELPLINES, static_cast<const SfxBoolItem*>(pItem)->GetValue() );
862  rBindings.Invalidate(SID_HELPLINES_MOVE);
863  }
864  break;
865  }
866 
867  GetViewData().SetOptions(aViewOptions);
868 }
869 
871 {
872  SfxBoolItem aBool;
873 
874  const ScViewOptions& rViewOptions = GetViewData().GetOptions();
875  const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
876 
877  aBool.SetValue(rGridOptions.GetGridVisible());
878  aBool.SetWhich( SID_GRID_VISIBLE );
879  rSet.Put( aBool );
880 
881  aBool.SetValue(rGridOptions.GetUseGridSnap());
882  aBool.SetWhich( SID_GRID_USE );
883  rSet.Put( aBool );
884 
885  aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
886  aBool.SetWhich( SID_HELPLINES_MOVE );
887  rSet.Put( aBool );
888 }
889 
890 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1902
#define MAXZOOM
Definition: global.hxx:79
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3135
void SetOption(ScViewOption eOpt, bool bNew)
Definition: viewopti.hxx:87
SvxCellHorJustify
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1913
todo: It should be possible to have MarkArrays for each table, in order to enable "search all" across...
Definition: markdata.hxx:42
SfxChildWindow * GetChildWindow(sal_uInt16)
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
const OUString & GetEditString()
Definition: inputhdl.cxx:4417
OUString GetFormula(const formula::FormulaGrammar::Grammar=formula::FormulaGrammar::GRAM_DEFAULT, const ScInterpreterContext *pContext=nullptr) const
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
void GetState(SfxItemSet &rSet)
Definition: tabvwsha.cxx:170
void UpdateInputHandlerCellAdjust(SvxCellHorJustify eJust)
Definition: tabvwsha.cxx:756
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALE(175)
long Long
constexpr TypedWhichId< XFillStyleItem > XATTR_FILLSTYLE(XATTR_FILL_FIRST)
SCROW GetCurY() const
Definition: viewdata.hxx:402
SCCOLROW GetLOKSheetFreezeIndex(bool bIsCol) const
Definition: viewdata.cxx:4218
sal_Int16 nId
sal_uInt16 FirstWhich()
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
static OUString GetLongErrorString(FormulaError nErrNumber)
Definition: global.cxx:343
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
virtual SfxItemSet & GetItemSet()
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:103
constexpr TypedWhichId< ScProtectionAttr > ATTR_PROTECTION(149)
SC_DLLPUBLIC formula::FormulaGrammar::Grammar GetGrammar() const
Definition: document.hxx:1007
const SfxItemSet * GetArgs() const
void Invalidate(sal_uInt16 nId)
EmbeddedObjectRef * pObject
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:494
sal_uInt16 NextWhich()
void AddSnappingPoint(sal_Int32 nNew)
UNOTOOLS_DLLPUBLIC bool GetTitle(OUString const &url, OUString *title)
const EditTextObject * mpEditText
Definition: cellvalue.hxx:109
bool IsFormulaMode()
Definition: scmod.cxx:1678
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
SCTAB GetSelectCount() const
Definition: markdata.cxx:180
bool IsMultiMarked() const
Definition: markdata.hxx:81
SC_DLLPUBLIC void InputEnterHandler(ScEnterMode nBlockMode=ScEnterMode::NORMAL, bool bBeforeSavingInLOK=false)
Definition: scmod.cxx:1408
SfxFrame & GetFrame() const
bool IsDocShared() const
void UpdateInputHandler(bool bForce=false, bool bStopEditing=true)
Definition: tabvwsha.cxx:668
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:110
void ExecDrawOpt(const SfxRequest &rReq)
Definition: tabvwsha.cxx:829
bool GetFunction(OUString &rFuncStr, FormulaError nErrCode)
Definition: tabvwsha.cxx:69
ScSplitMode GetHSplitMode() const
Definition: viewdata.hxx:416
void SetCloseBrackets(bool bVal)
Definition: compiler.hxx:433
bool IsPrintEntireSheet(SCTAB nTab) const
Returns true, if the specified sheet is always printed.
Definition: document.cxx:6368
ScChangeTrack * GetChangeTrack() const
Definition: document.hxx:2485
SC_DLLPUBLIC const SfxPoolItem * GetAttr(SCCOL nCol, SCROW nRow, SCTAB nTab, sal_uInt16 nWhich) const
Definition: document.cxx:4764
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:150
void ExecuteInputDirect()
Definition: tabvwsha.cxx:656
bool GetHideCell() const
Definition: attrib.hxx:147
void ExecuteSave(SfxRequest &rReq)
Definition: tabvwsha.cxx:762
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:459
void SetGridVisible(bool bSet)
SvNumFormatType GetType() const
bool GetUseGridSnap() const
bool IsMarked() const
Definition: markdata.hxx:80
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * GetSlotState(sal_uInt16 nSlotId, const SfxInterface *pIF=nullptr, SfxItemSet *pStateSet=nullptr)
sal_Int16 SCCOL
Definition: types.hxx:21
virtual VclPtr< SfxAbstractTabDialog > CreateScAttrDlg(weld::Window *pParent, const SfxItemSet *pCellAttrs)=0
#define SC_MOD()
Definition: scmod.hxx:249
bool GetHideFormula() const
Definition: attrib.hxx:145
void GetDrawOptState(SfxItemSet &rSet)
Definition: tabvwsha.cxx:870
void ExecuteCellFormatDlg(SfxRequest &rReq, const OString &rTabPage)
Definition: tabvwsha.cxx:520
ScChangeAction * GetChangeAction(const ScAddress &rPos)
Definition: docsh3.cxx:572
float u
SfxItemSet & GetItemSet()
Definition: patattr.hxx:155
bool HasManualBreaks(SCTAB nTab) const
Definition: document.cxx:6335
ScMarkType GetSimpleArea(SCCOL &rStartCol, SCROW &rStartRow, SCTAB &rStartTab, SCCOL &rEndCol, SCROW &rEndRow, SCTAB &rEndTab) const
Definition: viewdata.cxx:1181
virtual void SetCurPageId(const OString &rName)=0
bool IsNumberFormat(const OUString &sString, sal_uInt32 &F_Index, double &fOutNumber, SvNumInputOptions eInputOptions=SvNumInputOptions::NONE)
bool GetOption(ScViewOption eOpt) const
Definition: viewopti.hxx:88
constexpr TypedWhichId< SfxUInt32Item > ATTR_VALUE_FORMAT(146)
SC_DLLPUBLIC OUString GetPageStyle(SCTAB nTab) const
Definition: document.cxx:6288
void SetGridOptions(const ScGridOptions &rNew)
Definition: viewopti.hxx:97
sal_uInt32 GetNumberFormat(SvNumberFormatter *) const
Definition: patattr.cxx:1301
const ScGridOptions & GetGridOptions() const
Definition: viewopti.hxx:96
void SetValue(bool const bTheValue)
FormulaError
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
bool IsReadOnly() const
constexpr T & temporary(T &&x)
ScAddress GetCurPos() const
Definition: viewdata.cxx:4121
CellType meType
Definition: cellvalue.hxx:105
constexpr TypedWhichId< XFillColorItem > XATTR_FILLCOLOR(XATTR_FILL_FIRST+1)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
sal_Int32 SCROW
Definition: types.hxx:17
sal_uInt16 GetSlot() const
bool HasChildWindow(sal_uInt16)
void DisableItem(sal_uInt16 nWhich)
ColorConfigValue GetColorValue(ColorConfigEntry eEntry, bool bSmart=true) const
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
static OUString GetInputString(const ScRefCellValue &rCell, sal_uInt32 nFormat, SvNumberFormatter &rFormatter, const ScDocument &rDoc, const svl::SharedString **pShared=nullptr, bool bFiltering=false, bool bForceSystemLocale=false)
Definition: cellform.cxx:129
void SetUseGridSnap(bool bSet)
void SetWhich(sal_uInt16 nId)
static SC_DLLPUBLIC ScAbstractDialogFactory * Create()
Definition: scabstdlg.cxx:37
RET_OK
bool KnowsChildWindow(sal_uInt16)
SC_DLLPUBLIC ScOutlineTable * GetOutlineTable(SCTAB nTab, bool bCreate=false)
Definition: documen3.cxx:739
void NotifyChange(const ScInputHdlState *pState, bool bForce=false, ScTabViewShell *pSourceSh=nullptr, bool bStopEditing=true)
Definition: inputhdl.cxx:4118
bool HasItem(sal_uInt16 nWhich, const SfxPoolItem **ppItem=nullptr) const
const ScViewOptions & GetOptions() const
Definition: viewdata.hxx:554
void SetSelection(bool bNewSelection)
bool GetSelectionFunction(ScSubTotalFunc eFunc, const ScAddress &rCursor, const ScMarkData &rMark, double &rResult)
Definition: documen4.cxx:616
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6161
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(176)
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:989
bool GetSelIsRef() const
Definition: inputhdl.hxx:247
#define MINZOOM
Definition: global.hxx:78
bool IsRefInputMode() const
Definition: tabvwsha.cxx:618
ScInputHandler * GetInputHdl(ScTabViewShell *pViewSh=nullptr, bool bUseRef=true)
Input-Handler.
Definition: scmod.cxx:1352
ScSubTotalFunc
Definition: global.hxx:843
bool IsRefDialogOpen()
Definition: scmod.cxx:1662
void GetSaveState(SfxItemSet &rSet)
Definition: tabvwsha.cxx:812
bool GetGridVisible() const
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
void Ignore()
static bool IsPanelVisible(std::u16string_view rsPanelId, const css::uno::Reference< css::frame::XFrame > &rxFrame)
SearchOptionFlags
weld::Window * GetFrameWeld(const SfxFrame *pFrame)
aStr
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
ScSplitMode GetVSplitMode() const
Definition: viewdata.hxx:417
sal_uInt32 GetTimeFormat(double fNumber, LanguageType eLnge, bool bForceDuration)
LanguageType GetLanguage() const
sal_Int16 SCTAB
Definition: types.hxx:22
SCCOL GetCurX() const
Definition: viewdata.hxx:401
SC_DLLPUBLIC sal_uInt32 GetNumberFormat(SCCOL nCol, SCROW nRow, SCTAB nTab) const
Definition: document.cxx:3677
static SC_DLLPUBLIC const SvxSearchItem & GetSearchItem()
Definition: global.cxx:223