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& 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  rDoc.GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
131  }
132 
133  OUString aValStr;
134  const 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& rDoc = 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 (rDoc.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, rDoc.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 (!rDoc.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 = rDoc.GetPageStyle( nTab );
279  ScStyleSheetPool* pStylePool = rDoc.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>(tools::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>(tools::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, rDoc.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, rDoc.IsTabProtected( nTab ) ) );
386  }
387  }
388  break;
389 
390  case SID_AUTO_OUTLINE:
391  {
392  if (rDoc.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 = rDoc.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:
416  {
417  rSet.Put(SfxBoolItem(nWhich,
418  rViewData.GetHSplitMode() == SC_SPLIT_FIX ||
419  rViewData.GetVSplitMode() == SC_SPLIT_FIX ));
420  }
421  else
422  {
423  rSet.Put(SfxBoolItem(nWhich,
424  rViewData.GetLOKSheetFreezeIndex(true) > 0 ||
425  rViewData.GetLOKSheetFreezeIndex(false) > 0 ));
426  }
427  break;
428 
429  case SID_WINDOW_FIX_COL:
430  case SID_WINDOW_FIX_ROW:
431  {
432  bool bIsCol = (nWhich == SID_WINDOW_FIX_COL);
433  sal_Int32 nFreezeIndex = rViewData.GetLOKSheetFreezeIndex(bIsCol);
434  rSet.Put(SfxInt32Item(nWhich, nFreezeIndex));
435  }
436  break;
437 
438  case FID_CHG_SHOW:
439  {
440  if ( rDoc.GetChangeTrack() == nullptr || ( pDocShell && pDocShell->IsDocShared() ) )
441  rSet.DisableItem( nWhich );
442  }
443  break;
444  case FID_CHG_ACCEPT:
445  {
446  if(
447  ( !rDoc.GetChangeTrack() && !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
448  ||
449  ( pDocShell && pDocShell->IsDocShared() )
450  )
451  {
452  rSet.DisableItem( nWhich);
453  }
454  else
455  {
456  rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
457  pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
458  }
459  }
460  break;
461 
462  case SID_FORMATPAGE:
463  // in protected tables
464  if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
465  rSet.DisableItem( nWhich );
466  break;
467 
468  case SID_PRINTPREVIEW:
469  // Toggle slot needs a State
470  rSet.Put( SfxBoolItem( nWhich, false ) );
471  break;
472 
473  case SID_READONLY_MODE:
474  rSet.Put( SfxBoolItem( nWhich, GetViewData().GetDocShell()->IsReadOnly() ) );
475  break;
476 
477  case FID_TAB_DESELECTALL:
478  if ( nTabSelCount == 1 )
479  rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
480  break;
481 
482  } // switch ( nWitch )
483  nWhich = aIter.NextWhich();
484  } // while ( nWitch )
485 }
486 
487 void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OString &rName)
488 {
489  ScDocument& rDoc = GetViewData().GetDocument();
490 
491  std::shared_ptr<SvxBoxItem> aLineOuter(std::make_shared<SvxBoxItem>(ATTR_BORDER));
492  std::shared_ptr<SvxBoxInfoItem> aLineInner(std::make_shared<SvxBoxInfoItem>(ATTR_BORDER_INNER));
493 
494  const ScPatternAttr* pOldAttrs = GetSelectionPattern();
495 
496  auto pOldSet = std::make_shared<SfxItemSet>(pOldAttrs->GetItemSet());
497  std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem;
498 
499  pOldSet->MergeRange(XATTR_FILLSTYLE, XATTR_FILLCOLOR);
500 
501  pOldSet->MergeRange(SID_ATTR_BORDER_STYLES, SID_ATTR_BORDER_DEFAULT_WIDTH);
502 
503  // We only allow these border line types.
504  const std::vector<sal_Int32> aBorderStyles{
505  table::BorderLineStyle::SOLID,
506  table::BorderLineStyle::DOTTED,
507  table::BorderLineStyle::DASHED,
508  table::BorderLineStyle::FINE_DASHED,
509  table::BorderLineStyle::DASH_DOT,
510  table::BorderLineStyle::DASH_DOT_DOT,
511  table::BorderLineStyle::DOUBLE_THIN };
512 
513  SfxIntegerListItem aBorderStylesItem(SID_ATTR_BORDER_STYLES, aBorderStyles);
514  pOldSet->Put(aBorderStylesItem);
515 
516  // Set the default border width to 0.75 points.
517  SfxInt64Item aBorderWidthItem(SID_ATTR_BORDER_DEFAULT_WIDTH, 75);
518  pOldSet->Put(aBorderWidthItem);
519 
520  // Get border items and put them in the set:
521  GetSelectionFrame( aLineOuter, aLineInner );
522 
523  //Fix border incorrect for RTL fdo#62399
524  if( rDoc.IsLayoutRTL( GetViewData().GetTabNo() ) )
525  {
526  std::unique_ptr<SvxBoxItem> aNewFrame(aLineOuter->Clone());
527  std::unique_ptr<SvxBoxInfoItem> aTempInfo(aLineInner->Clone());
528 
529  if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::LEFT) )
530  aNewFrame->SetLine( aLineOuter->GetLeft(), SvxBoxItemLine::RIGHT );
531  if ( aLineInner->IsValid(SvxBoxInfoItemValidFlags::RIGHT) )
532  aNewFrame->SetLine( aLineOuter->GetRight(), SvxBoxItemLine::LEFT );
533 
534  aLineInner->SetValid( SvxBoxInfoItemValidFlags::LEFT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::RIGHT));
535  aLineInner->SetValid( SvxBoxInfoItemValidFlags::RIGHT, aTempInfo->IsValid(SvxBoxInfoItemValidFlags::LEFT));
536 
537  pOldSet->Put( *aNewFrame );
538  }
539  else
540  {
541  pOldSet->Put( *aLineOuter );
542  }
543 
544  pOldSet->Put( *aLineInner );
545 
546  // Generate NumberFormat Value from Value and Language and box it.
547  pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
548  pOldAttrs->GetNumberFormat( rDoc.GetFormatTable() ) ) );
549 
550  pNumberInfoItem = MakeNumberInfoItem(rDoc, &GetViewData());
551 
552  pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
553  pOldSet->Put(*pNumberInfoItem );
554 
555  bInFormatDialog = true;
557 
558  VclPtr<SfxAbstractTabDialog> pDlg(pFact->CreateScAttrDlg(GetFrameWeld(), pOldSet.get()));
559 
560  if (!rName.isEmpty())
561  pDlg->SetCurPageId(rName);
562 
563  auto pRequest = std::make_shared<SfxRequest>(rReq);
564  rReq.Ignore(); // the 'old' request is not relevant any more
565 
566  pDlg->StartExecuteAsync([pDlg, pOldSet, pRequest, this](sal_Int32 nResult){
567  bInFormatDialog = false;
568 
569  if ( nResult == RET_OK )
570  {
571  const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
572 
573  const SfxPoolItem* pItem=nullptr;
574  if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,true,&pItem)==SfxItemState::SET)
575  {
576  UpdateNumberFormatter(static_cast<const SvxNumberInfoItem&>(*pItem));
577  }
578 
579  ApplyAttributes(pOutSet, pOldSet.get());
580 
581  pRequest->Done(*pOutSet);
582  }
583 
584  pDlg->disposeOnce();
585  });
586 }
587 
589 {
590  ScModule* pScMod = SC_MOD();
591  if ( pScMod )
592  {
593  if( pScMod->IsRefDialogOpen() )
594  return pScMod->IsFormulaMode();
595  if( pScMod->IsFormulaMode() )
596  {
597  ScInputHandler* pHdl = pScMod->GetInputHdl();
598  if ( pHdl )
599  {
600  OUString aString = pHdl->GetEditString();
601  if ( !pHdl->GetSelIsRef() && aString.getLength() > 1 &&
602  ( aString[0] == '+' || aString[0] == '-' ) )
603  {
604  const ScViewData& rViewData = GetViewData();
605  ScDocument& rDoc = rViewData.GetDocument();
606  const ScAddress aPos( rViewData.GetCurPos() );
607  ScCompiler aComp( rDoc, aPos, rDoc.GetGrammar() );
608  aComp.SetCloseBrackets( false );
609  std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aString));
610  if ( pArr && pArr->MayReferenceFollow() )
611  {
612  return true;
613  }
614  }
615  else
616  {
617  return true;
618  }
619  }
620  }
621  }
622 
623  return false;
624 }
625 
627 {
628  if ( !IsRefInputMode() )
629  {
630  ScModule* pScMod = SC_MOD();
631  if ( pScMod )
632  {
633  pScMod->InputEnterHandler();
634  }
635  }
636 }
637 
638 void ScTabViewShell::UpdateInputHandler( bool bForce /* = sal_False */, bool bStopEditing /* = sal_True */ )
639 {
640  ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl();
641 
642  if ( pHdl )
643  {
644  OUString aString;
645  const EditTextObject* pObject = nullptr;
646  ScViewData& rViewData = GetViewData();
647  ScDocument& rDoc = rViewData.GetDocument();
648  SCCOL nPosX = rViewData.GetCurX();
649  SCROW nPosY = rViewData.GetCurY();
650  SCTAB nTab = rViewData.GetTabNo();
651  SCTAB nStartTab = 0;
652  SCTAB nEndTab = 0;
653  SCCOL nStartCol = 0;
654  SCROW nStartRow = 0;
655  SCCOL nEndCol = 0;
656  SCROW nEndRow = 0;
657  ScAddress aPos = rViewData.GetCurPos();
658 
659  rViewData.GetSimpleArea( nStartCol, nStartRow, nStartTab,
660  nEndCol, nEndRow, nEndTab );
661 
662  PutInOrder( nStartCol, nEndCol );
663  PutInOrder( nStartRow, nEndRow );
664  PutInOrder( nStartTab, nEndTab );
665 
666  bool bHideFormula = false;
667  bool bHideAll = false;
668 
669  if (rDoc.IsTabProtected(nTab))
670  {
671  const ScProtectionAttr* pProt = rDoc.GetAttr( nPosX,nPosY,nTab,
673  bHideFormula = pProt->GetHideFormula();
674  bHideAll = pProt->GetHideCell();
675  }
676 
677  if (!bHideAll)
678  {
679  ScRefCellValue rCell(rDoc, aPos);
680  if (rCell.meType == CELLTYPE_FORMULA)
681  {
682  if (!bHideFormula)
683  rCell.mpFormula->GetFormula(aString);
684  }
685  else if (rCell.meType == CELLTYPE_EDIT)
686  {
687  pObject = rCell.mpEditText;
688  }
689  else
690  {
691  SvNumberFormatter* pFormatter = rDoc.GetFormatTable();
692  sal_uInt32 nNumFmt = rDoc.GetNumberFormat( aPos );
693 
694  ScCellFormat::GetInputString( rCell, nNumFmt, aString, *pFormatter, rDoc );
695  if (rCell.meType == CELLTYPE_STRING)
696  {
697  // Put a ' in front if necessary, so that the string is not
698  // unintentionally interpreted as a number, and to show the
699  // user that it is a string (#35060#).
701  if ( pFormatter->IsNumberFormat(aString, nNumFmt, o3tl::temporary(double())) )
702  aString = "'" + aString;
703  }
704  }
705  }
706 
707  ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
708  ScAddress( nStartCol, nStartRow, nTab ),
709  ScAddress( nEndCol, nEndRow, nTab ),
710  aString,
711  pObject );
712 
713  // if using the view's local input handler, this view can always be set
714  // as current view inside NotifyChange.
715  ScTabViewShell* pSourceSh = mpInputHandler ? this : nullptr;
716 
717  pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
718  }
719 
720  SfxBindings& rBindings = GetViewFrame()->GetBindings();
721  rBindings.Invalidate( SID_STATUS_SUM ); // always together with the input row
722  rBindings.Invalidate( SID_ATTR_SIZE );
723  rBindings.Invalidate( SID_TABLE_CELL );
724 }
725 
727 {
728  if( ScInputHandler* pHdl = mpInputHandler ? mpInputHandler.get() : SC_MOD()->GetInputHdl() )
729  pHdl->UpdateCellAdjust( eJust );
730 }
731 
733 {
734  // only SID_SAVEDOC / SID_SAVEASDOC
735  bool bCommitChanges = true;
736  const SfxItemSet* pReqArgs = rReq.GetArgs();
737  const SfxPoolItem* pItem;
738 
739  if (pReqArgs && pReqArgs->HasItem(FN_PARAM_1, &pItem))
740  bCommitChanges = !static_cast<const SfxBoolItem*>(pItem)->GetValue();
741 
742  // Finish entering unless 'DontTerminateEdit' is specified, even if a formula is being processed
743  if (bCommitChanges)
744  {
745  SC_MOD()->InputEnterHandler();
746 
748  {
749  // Normally this isn't needed, but in Calc when editing a cell formula
750  // and manually saving (without changing cells or hitting enter), while
751  // InputEnterHandler will mark the doc as modified (when it is), because
752  // we will save the doc immediately afterwards, the modified state event
753  // is clobbered. To avoid that, we need to update SID_DOC_MODIFIED so that
754  // a possible state of "true" after "InputEnterHandler" will be sent
755  // as a notification. It is important that the notification goes through
756  // normal process (cache) rather than directly notifying the views.
757  // Otherwise, because there is a previous state of "false" in cache, the
758  // "false" state after saving will be ignored.
759  // This will work only if .uno:ModifiedStatus message will be removed from
760  // the mechanism that keeps in the message queue only last message of
761  // a particular status even if the values are different.
762  GetViewData().GetDocShell()->GetViewBindings()->Update(SID_DOC_MODIFIED);
763  }
764  }
765 
766  if ( GetViewData().GetDocShell()->IsDocShared() )
767  {
768  GetViewData().GetDocShell()->SetDocumentModified();
769  }
770 
771  // otherwise as normal
772  GetViewData().GetDocShell()->ExecuteSlot( rReq );
773 }
774 
776 {
777  SfxShell* pDocSh = GetViewData().GetDocShell();
778 
779  SfxWhichIter aIter(rSet);
780  sal_uInt16 nWhich = aIter.FirstWhich();
781  while( nWhich )
782  {
783  if ( nWhich != SID_SAVEDOC || !GetViewData().GetDocShell()->IsDocShared() )
784  {
785  // get state from DocShell
786  pDocSh->GetSlotState( nWhich, nullptr, &rSet );
787  }
788  nWhich = aIter.NextWhich();
789  }
790 }
791 
793 {
794  ScViewOptions aViewOptions = GetViewData().GetOptions();
795  ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
796 
797  SfxBindings& rBindings = GetViewFrame()->GetBindings();
798  const SfxItemSet* pArgs = rReq.GetArgs();
799  const SfxPoolItem* pItem;
800  sal_uInt16 nSlotId = rReq.GetSlot();
801  switch (nSlotId)
802  {
803  case SID_GRID_VISIBLE:
804  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
805  {
806  aGridOptions.SetGridVisible( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
807  aViewOptions.SetGridOptions(aGridOptions);
808  rBindings.Invalidate(SID_GRID_VISIBLE);
809  }
810  break;
811 
812  case SID_GRID_USE:
813  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
814  {
815  aGridOptions.SetUseGridSnap( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
816  aViewOptions.SetGridOptions(aGridOptions);
817  rBindings.Invalidate(SID_GRID_USE);
818  }
819  break;
820 
821  case SID_HELPLINES_MOVE:
822  if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
823  {
824  aViewOptions.SetOption( VOPT_HELPLINES, static_cast<const SfxBoolItem*>(pItem)->GetValue() );
825  rBindings.Invalidate(SID_HELPLINES_MOVE);
826  }
827  break;
828  }
829 
830  GetViewData().SetOptions(aViewOptions);
831 }
832 
834 {
835  SfxBoolItem aBool;
836 
837  const ScViewOptions& rViewOptions = GetViewData().GetOptions();
838  const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
839 
840  aBool.SetValue(rGridOptions.GetGridVisible());
841  aBool.SetWhich( SID_GRID_VISIBLE );
842  rSet.Put( aBool );
843 
844  aBool.SetValue(rGridOptions.GetUseGridSnap());
845  aBool.SetWhich( SID_GRID_USE );
846  rSet.Put( aBool );
847 
848  aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
849  aBool.SetWhich( SID_HELPLINES_MOVE );
850  rSet.Put( aBool );
851 }
852 
853 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SC_DLLPUBLIC bool IsDocProtected() const
Definition: documen3.cxx:1879
#define MAXZOOM
Definition: global.hxx:77
ScMarkData & GetMarkData()
Definition: viewdata.cxx:3046
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:2107
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
SC_DLLPUBLIC bool IsTabProtected(SCTAB nTab) const
Definition: documen3.cxx:1890
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)
constexpr TypedWhichId< SvxBoxItem > ATTR_BORDER(150)
const OUString & GetEditString()
Definition: inputhdl.cxx:4220
virtual const SfxItemSet * GetOutputItemSet() const =0
std::string GetValue
void GetState(SfxItemSet &rSet)
Definition: tabvwsha.cxx:159
void UpdateInputHandlerCellAdjust(SvxCellHorJustify eJust)
Definition: tabvwsha.cxx:726
void GetFormula(OUString &rFormula, const formula::FormulaGrammar::Grammar=formula::FormulaGrammar::GRAM_DEFAULT, const ScInterpreterContext *pContext=nullptr) const
constexpr TypedWhichId< SfxUInt16Item > ATTR_PAGE_SCALETOPAGES(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:4099
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:3641
constexpr TypedWhichId< SvxBoxInfoItem > ATTR_BORDER_INNER(151)
static OUString GetLongErrorString(FormulaError nErrNumber)
Definition: global.cxx:333
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: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:489
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
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
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:638
ScFormulaCell * mpFormula
Definition: cellvalue.hxx:111
void ExecDrawOpt(const SfxRequest &rReq)
Definition: tabvwsha.cxx:792
bool GetFunction(OUString &rFuncStr, FormulaError nErrCode)
Definition: tabvwsha.cxx:69
ScSplitMode GetHSplitMode() const
Definition: viewdata.hxx:416
void SetCloseBrackets(bool bVal)
Definition: compiler.hxx:412
bool IsPrintEntireSheet(SCTAB nTab) const
Returns true, if the specified sheet is always printed.
Definition: document.cxx:6266
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:4714
void PutInOrder(T &nStart, T &nEnd)
Definition: address.hxx:954
void ExecuteInputDirect()
Definition: tabvwsha.cxx:626
bool GetHideCell() const
Definition: attrib.hxx:148
void ExecuteSave(SfxRequest &rReq)
Definition: tabvwsha.cxx:732
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:833
void ExecuteCellFormatDlg(SfxRequest &rReq, const OString &rTabPage)
Definition: tabvwsha.cxx:487
ScChangeAction * GetChangeAction(const ScAddress &rPos)
Definition: docsh3.cxx:571
bool HasManualBreaks(SCTAB nTab) const
Definition: document.cxx:6233
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:1170
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:6186
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:4007
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:731
void NotifyChange(const ScInputHdlState *pState, bool bForce=false, ScTabViewShell *pSourceSh=nullptr, bool bStopEditing=true)
Definition: inputhdl.cxx:3942
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:6066
SC_DLLPUBLIC bool IsLayoutRTL(SCTAB nTab) const
Definition: document.cxx:994
bool GetSelIsRef() const
Definition: inputhdl.hxx:243
#define MINZOOM
Definition: global.hxx:76
bool IsRefInputMode() const
Definition: tabvwsha.cxx:588
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:775
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)
static void GetInputString(const ScRefCellValue &rCell, sal_uInt32 nFormat, OUString &rString, SvNumberFormatter &rFormatter, const ScDocument &rDoc)
Definition: cellform.cxx:120
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_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 SC_DLLPUBLIC const SvxSearchItem & GetSearchItem()
Definition: global.cxx:213