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