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