Version 5.2.6.1, tag libreoffice-5.2.6.1
[LibreOffice.git] / sc / source / ui / view / tabvwsha.cxx
blobef0d1ced18431588b6a643b7a045d3b1d79e1e9e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "scitems.hxx"
21 #include <svl/stritem.hxx>
22 #include <svl/whiter.hxx>
23 #include <svl/zformat.hxx>
24 #include <editeng/boxitem.hxx>
25 #include <svx/numinf.hxx>
26 #include <svl/srchitem.hxx>
27 #include <svl/ilstitem.hxx>
28 #include <svl/int64item.hxx>
29 #include <svx/zoomslideritem.hxx>
30 #include <sfx2/bindings.hxx>
31 #include <sfx2/sidebar/Sidebar.hxx>
32 #include <sfx2/viewfrm.hxx>
33 #include <sfx2/dispatch.hxx>
34 #include <sfx2/request.hxx>
35 #include <vcl/msgbox.hxx>
37 #include "global.hxx"
38 #include "attrib.hxx"
39 #include "patattr.hxx"
40 #include "cellform.hxx"
41 #include "document.hxx"
42 #include "formulacell.hxx"
43 #include "globstr.hrc"
44 #include "scmod.hxx"
45 #include "inputhdl.hxx"
46 #include "inputwin.hxx"
47 #include "docsh.hxx"
48 #include "viewdata.hxx"
49 #include "appoptio.hxx"
50 #include "sc.hrc"
51 #include "stlpool.hxx"
52 #include "tabvwsh.hxx"
53 #include "dwfunctr.hxx"
54 #include "scabstdlg.hxx"
55 #include "compiler.hxx"
56 #include "markdata.hxx"
57 #include "cellvalue.hxx"
58 #include "tokenarray.hxx"
60 #include <com/sun/star/table/BorderLineStyle.hpp>
62 #include <memory>
64 using namespace com::sun::star;
66 bool ScTabViewShell::GetFunction( OUString& rFuncStr, sal_uInt16 nErrCode )
68 OUString aStr;
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++ )
77 if ( !(nFuncs & (1 << nFunc)) )
78 continue;
79 ScSubTotalFunc eFunc = (ScSubTotalFunc)nFunc;
81 if (bIgnoreError && (eFunc == SUBTOTAL_FUNC_CNT || eFunc == SUBTOTAL_FUNC_CNT2))
82 nErrCode = 0;
84 if (nErrCode)
86 rFuncStr = ScGlobal::GetLongErrorString(nErrCode);
87 return true;
90 sal_uInt16 nGlobStrId = 0;
91 switch (eFunc)
93 case SUBTOTAL_FUNC_AVE: nGlobStrId = STR_FUN_TEXT_AVG; break;
94 case SUBTOTAL_FUNC_CNT: nGlobStrId = STR_FUN_TEXT_COUNT; break;
95 case SUBTOTAL_FUNC_CNT2: nGlobStrId = STR_FUN_TEXT_COUNT2; break;
96 case SUBTOTAL_FUNC_MAX: nGlobStrId = STR_FUN_TEXT_MAX; break;
97 case SUBTOTAL_FUNC_MIN: nGlobStrId = STR_FUN_TEXT_MIN; break;
98 case SUBTOTAL_FUNC_SUM: nGlobStrId = STR_FUN_TEXT_SUM; break;
99 case SUBTOTAL_FUNC_SELECTION_COUNT: nGlobStrId = STR_FUN_TEXT_SELECTION_COUNT; break;
101 default:
103 // added to avoid warnings
106 if (nGlobStrId)
108 ScDocument* pDoc = rViewData.GetDocument();
109 SCCOL nPosX = rViewData.GetCurX();
110 SCROW nPosY = rViewData.GetCurY();
111 SCTAB nTab = rViewData.GetTabNo();
113 aStr = ScGlobal::GetRscString(nGlobStrId);
114 aStr += ": ";
116 ScAddress aCursor( nPosX, nPosY, nTab );
117 double nVal;
118 if ( pDoc->GetSelectionFunction( eFunc, aCursor, rMark, nVal ) )
120 if ( nVal == 0.0 )
121 aStr += "0";
122 else
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)
129 // number format from attributes or formula
130 pDoc->GetNumberFormat( nPosX, nPosY, nTab, nNumFmt );
133 OUString aValStr;
134 Color* pDummy;
135 pFormatter->GetOutputString( nVal, nNumFmt, aValStr, &pDummy );
136 aStr += aValStr;
139 if ( bFirst )
141 rFuncStr += aStr;
142 bFirst = false;
144 else
145 rFuncStr += ("; " + aStr);
149 return !rFuncStr.isEmpty();
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
159 void ScTabViewShell::GetState( SfxItemSet& rSet )
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();
169 SfxViewFrame* pThisFrame = GetViewFrame();
170 bool bOle = GetViewFrame()->GetFrame().IsInPlace();
172 SCTAB nTabSelCount = rMark.GetSelectCount();
174 SfxWhichIter aIter(rSet);
175 sal_uInt16 nWhich = aIter.FirstWhich();
177 while ( nWhich )
179 switch ( nWhich )
181 case FID_CHG_COMMENT:
183 ScDocShell* pDocSh = GetViewData().GetDocShell();
184 ScAddress aPos( nPosX, nPosY, nTab );
185 if ( pDocSh->IsReadOnly() || !pDocSh->GetChangeAction(aPos) || pDocSh->IsDocShared() )
186 rSet.DisableItem( nWhich );
188 break;
190 case SID_OPENDLG_EDIT_PRINTAREA:
191 case SID_ADD_PRINTAREA:
192 case SID_DEFINE_PRINTAREA:
194 if ( pDocShell && pDocShell->IsDocShared() )
196 rSet.DisableItem( nWhich );
199 break;
201 case SID_DELETE_PRINTAREA:
202 if ( pDocShell && pDocShell->IsDocShared() )
204 rSet.DisableItem( nWhich );
206 else if (pDoc->IsPrintEntireSheet(nTab))
207 rSet.DisableItem(nWhich);
208 break;
210 case SID_STATUS_PAGESTYLE:
211 case SID_HFEDIT:
212 GetViewData().GetDocShell()->GetStatePageStyle( *this, rSet, nTab );
213 break;
215 case SID_SEARCH_ITEM:
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;
224 case SID_SEARCH_OPTIONS:
226 // Anything goes
227 SearchOptionFlags nOptions = SearchOptionFlags::ALL;
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) ) );
234 break;
236 case SID_CURRENTCELL:
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 );
242 rSet.Put( aPosItem );
244 break;
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;
251 case SID_CURRENTDOC:
252 rSet.Put( SfxStringItem( nWhich, GetViewData().GetDocShell()->GetTitle() ) );
253 break;
255 case FID_TOGGLEINPUTLINE:
257 sal_uInt16 nId = ScInputWindowWrapper::GetChildWindowId();
259 if ( pThisFrame->KnowsChildWindow( nId ) )
261 SfxChildWindow* pWnd = pThisFrame->GetChildWindow( nId );
262 rSet.Put( SfxBoolItem( nWhich, pWnd != nullptr ) );
264 else
265 rSet.DisableItem( nWhich );
267 break;
269 case FID_DEL_MANUALBREAKS:
270 if (!pDoc->HasManualBreaks(nTab))
271 rSet.DisableItem( nWhich );
272 break;
274 case FID_RESET_PRINTZOOM:
276 // disable if already set to default
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 )
285 SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
286 sal_uInt16 nScale = static_cast<const SfxUInt16Item&>(
287 rStyleSet.Get(ATTR_PAGE_SCALE)).GetValue();
288 sal_uInt16 nPages = static_cast<const SfxUInt16Item&>(
289 rStyleSet.Get(ATTR_PAGE_SCALETOPAGES)).GetValue();
290 if ( nScale == 100 && nPages == 0 )
291 rSet.DisableItem( nWhich );
294 break;
296 case FID_SCALE:
297 case SID_ATTR_ZOOM:
298 if ( bOle )
299 rSet.DisableItem( nWhich );
300 else
302 const Fraction& rOldY = GetViewData().GetZoomY();
303 sal_uInt16 nZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 )
304 / rOldY.GetDenominator());
305 rSet.Put( SvxZoomItem( SvxZoomType::PERCENT, nZoom, nWhich ) );
307 break;
309 case SID_ATTR_ZOOMSLIDER:
311 if ( bOle )
312 rSet.DisableItem( nWhich );
313 else
315 const Fraction& rOldY = GetViewData().GetZoomY();
316 sal_uInt16 nCurrentZoom = (sal_uInt16)(( rOldY.GetNumerator() * 100 ) / rOldY.GetDenominator());
318 if( nCurrentZoom )
320 SvxZoomSliderItem aZoomSliderItem( nCurrentZoom, MINZOOM, MAXZOOM, SID_ATTR_ZOOMSLIDER );
321 aZoomSliderItem.AddSnappingPoint( 100 );
322 rSet.Put( aZoomSliderItem );
326 break;
328 case FID_FUNCTION_BOX:
330 const bool bBoxOpen = ::sfx2::sidebar::Sidebar::IsPanelVisible("ScFunctionsPanel",
331 pThisFrame->GetFrame().GetFrameInterface());
332 rSet.Put(SfxBoolItem(nWhich, bBoxOpen));
333 break;
336 case FID_TOGGLESYNTAX:
337 rSet.Put(SfxBoolItem(nWhich, GetViewData().IsSyntaxMode()));
338 break;
340 case FID_TOGGLEHEADERS:
341 rSet.Put(SfxBoolItem(nWhich, GetViewData().IsHeaderMode()));
342 break;
344 case FID_TOGGLEFORMULA:
346 const ScViewOptions& rOpts = rViewData.GetOptions();
347 bool bFormulaMode = rOpts.GetOption( VOPT_FORMULAS );
348 rSet.Put(SfxBoolItem(nWhich, bFormulaMode ));
350 break;
352 case FID_NORMALVIEWMODE:
353 case FID_PAGEBREAKMODE:
354 // always handle both slots - they exclude each other
355 if ( bOle )
357 rSet.DisableItem( FID_NORMALVIEWMODE );
358 rSet.DisableItem( FID_PAGEBREAKMODE );
360 else
362 rSet.Put(SfxBoolItem(FID_NORMALVIEWMODE, !GetViewData().IsPagebreakMode()));
363 rSet.Put(SfxBoolItem(FID_PAGEBREAKMODE, GetViewData().IsPagebreakMode()));
365 break;
367 case FID_PROTECT_DOC:
369 if ( pDocShell && pDocShell->IsDocShared() )
371 rSet.DisableItem( nWhich );
373 else
375 rSet.Put( SfxBoolItem( nWhich, pDoc->IsDocProtected() ) );
378 break;
380 case FID_PROTECT_TABLE:
382 if ( pDocShell && pDocShell->IsDocShared() )
384 rSet.DisableItem( nWhich );
386 else
388 rSet.Put( SfxBoolItem( nWhich, pDoc->IsTabProtected( nTab ) ) );
391 break;
393 case SID_AUTO_OUTLINE:
395 if (pDoc->GetChangeTrack()!=nullptr || GetViewData().IsMultiMarked())
397 rSet.DisableItem( nWhich );
400 break;
402 case SID_OUTLINE_DELETEALL:
404 SCTAB nOlTab = GetViewData().GetTabNo();
405 ScOutlineTable* pOlTable = pDoc->GetOutlineTable( nOlTab );
406 if (pOlTable == nullptr)
407 rSet.DisableItem( nWhich );
409 break;
411 case SID_WINDOW_SPLIT:
412 rSet.Put(SfxBoolItem(nWhich,
413 rViewData.GetHSplitMode() == SC_SPLIT_NORMAL ||
414 rViewData.GetVSplitMode() == SC_SPLIT_NORMAL ));
415 break;
417 case SID_WINDOW_FIX:
418 rSet.Put(SfxBoolItem(nWhich,
419 rViewData.GetHSplitMode() == SC_SPLIT_FIX ||
420 rViewData.GetVSplitMode() == SC_SPLIT_FIX ));
421 break;
423 case FID_CHG_SHOW:
425 if ( pDoc->GetChangeTrack() == nullptr || ( pDocShell && pDocShell->IsDocShared() ) )
426 rSet.DisableItem( nWhich );
428 break;
429 case FID_CHG_ACCEPT:
431 rSet.Put(SfxBoolItem(FID_CHG_ACCEPT,
432 pThisFrame->HasChildWindow(FID_CHG_ACCEPT)));
433 if(pDoc->GetChangeTrack()==nullptr)
435 if ( !pThisFrame->HasChildWindow(FID_CHG_ACCEPT) )
437 rSet.DisableItem( nWhich);
440 if ( pDocShell && pDocShell->IsDocShared() )
442 rSet.DisableItem( nWhich );
445 break;
447 case SID_FORMATPAGE:
448 // in protected tables
449 if ( pDocShell && ( pDocShell->IsReadOnly() || pDocShell->IsDocShared() ) )
450 rSet.DisableItem( nWhich );
451 break;
453 case SID_PRINTPREVIEW:
454 // Toggle slot needs a State
455 rSet.Put( SfxBoolItem( nWhich, false ) );
456 break;
458 case SID_READONLY_MODE:
459 rSet.Put( SfxBoolItem( nWhich, GetViewData().GetDocShell()->IsReadOnly() ) );
460 break;
462 case FID_TAB_DESELECTALL:
463 if ( nTabSelCount == 1 )
464 rSet.DisableItem( nWhich ); // enabled only if several sheets are selected
465 break;
467 } // switch ( nWitch )
468 nWhich = aIter.NextWhich();
469 } // while ( nWitch )
472 void ScTabViewShell::ExecuteCellFormatDlg(SfxRequest& rReq, const OString &rName)
474 ScDocument* pDoc = GetViewData().GetDocument();
476 SvxBoxItem aLineOuter( ATTR_BORDER );
477 SvxBoxInfoItem aLineInner( ATTR_BORDER_INNER );
479 const ScPatternAttr* pOldAttrs = GetSelectionPattern();
481 std::unique_ptr<SfxAbstractTabDialog> pDlg;
482 std::unique_ptr<SfxItemSet> pOldSet(new SfxItemSet(pOldAttrs->GetItemSet()));
483 std::unique_ptr<SvxNumberInfoItem> pNumberInfoItem;
485 pOldSet->MergeRange(SID_ATTR_BORDER_STYLES, SID_ATTR_BORDER_DEFAULT_WIDTH);
487 // We only allow these border line types.
488 std::vector<sal_Int32> aBorderStyles;
489 aBorderStyles.reserve(5);
490 aBorderStyles.push_back(table::BorderLineStyle::SOLID);
491 aBorderStyles.push_back(table::BorderLineStyle::DOTTED);
492 aBorderStyles.push_back(table::BorderLineStyle::DASHED);
493 aBorderStyles.push_back(table::BorderLineStyle::FINE_DASHED);
494 aBorderStyles.push_back(table::BorderLineStyle::DASH_DOT);
495 aBorderStyles.push_back(table::BorderLineStyle::DASH_DOT_DOT);
496 aBorderStyles.push_back(table::BorderLineStyle::DOUBLE_THIN);
498 SfxIntegerListItem aBorderStylesItem(SID_ATTR_BORDER_STYLES, aBorderStyles);
499 pOldSet->Put(aBorderStylesItem);
501 // Set the default border width to 0.75 points.
502 SfxInt64Item aBorderWidthItem(SID_ATTR_BORDER_DEFAULT_WIDTH, 75);
503 pOldSet->Put(aBorderWidthItem);
505 // Get border items and put them in the set:
506 GetSelectionFrame( aLineOuter, aLineInner );
507 //Fix border incorrect for RTL fdo#62399
508 if( pDoc->IsLayoutRTL( GetViewData().GetTabNo() ) )
510 SvxBoxItem aNewFrame( aLineOuter );
511 SvxBoxInfoItem aTempInfo( aLineInner );
513 if ( aLineInner.IsValid(SvxBoxInfoItemValidFlags::LEFT) )
514 aNewFrame.SetLine( aLineOuter.GetLeft(), SvxBoxItemLine::RIGHT );
515 if ( aLineInner.IsValid(SvxBoxInfoItemValidFlags::RIGHT) )
516 aNewFrame.SetLine( aLineOuter.GetRight(), SvxBoxItemLine::LEFT );
518 aLineInner.SetValid( SvxBoxInfoItemValidFlags::LEFT, aTempInfo.IsValid(SvxBoxInfoItemValidFlags::RIGHT));
519 aLineInner.SetValid( SvxBoxInfoItemValidFlags::RIGHT, aTempInfo.IsValid(SvxBoxInfoItemValidFlags::LEFT));
521 pOldSet->Put( aNewFrame );
523 else
524 pOldSet->Put( aLineOuter );
526 pOldSet->Put( aLineInner );
528 // Generate NumberFormat Value from Value and Language and box it.
529 pOldSet->Put( SfxUInt32Item( ATTR_VALUE_FORMAT,
530 pOldAttrs->GetNumberFormat( pDoc->GetFormatTable() ) ) );
532 pNumberInfoItem.reset(MakeNumberInfoItem(pDoc, &GetViewData()));
534 pOldSet->MergeRange( SID_ATTR_NUMBERFORMAT_INFO, SID_ATTR_NUMBERFORMAT_INFO );
535 pOldSet->Put(*pNumberInfoItem );
537 bInFormatDialog = true;
538 ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
539 OSL_ENSURE(pFact, "ScAbstractFactory create fail!");
541 pDlg.reset(pFact->CreateScAttrDlg(GetDialogParent(), pOldSet.get()));
543 if (!rName.isEmpty())
544 pDlg->SetCurPageId(rName);
545 short nResult = pDlg->Execute();
546 bInFormatDialog = false;
548 if ( nResult == RET_OK )
550 const SfxItemSet* pOutSet = pDlg->GetOutputItemSet();
552 const SfxPoolItem* pItem=nullptr;
553 if(pOutSet->GetItemState(SID_ATTR_NUMBERFORMAT_INFO,true,&pItem)==SfxItemState::SET)
556 UpdateNumberFormatter(static_cast<const SvxNumberInfoItem&>(*pItem));
559 ApplyAttributes(pOutSet, pOldSet.get());
561 rReq.Done( *pOutSet );
565 bool ScTabViewShell::IsRefInputMode() const
567 ScModule* pScMod = SC_MOD();
568 if ( pScMod )
570 if( pScMod->IsRefDialogOpen() )
571 return pScMod->IsFormulaMode();
572 if( pScMod->IsFormulaMode() )
574 ScInputHandler* pHdl = pScMod->GetInputHdl();
575 if ( pHdl )
577 OUString aString = pHdl->GetEditString();
578 if ( !pHdl->GetSelIsRef() && aString.getLength() > 1 &&
579 ( aString[0] == '+' || aString[0] == '-' ) )
581 const ScViewData& rViewData = GetViewData();
582 ScDocument* pDoc = rViewData.GetDocument();
583 if ( pDoc )
585 const ScAddress aPos( rViewData.GetCurPos() );
586 ScCompiler aComp( pDoc, aPos );
587 aComp.SetGrammar(pDoc->GetGrammar());
588 aComp.SetCloseBrackets( false );
589 std::unique_ptr<ScTokenArray> pArr(aComp.CompileString(aString));
590 if ( pArr && pArr->MayReferenceFollow() )
592 return true;
596 else
598 return true;
604 return false;
607 void ScTabViewShell::ExecuteInputDirect()
609 if ( !IsRefInputMode() )
611 ScModule* pScMod = SC_MOD();
612 if ( pScMod )
614 pScMod->InputEnterHandler();
619 void ScTabViewShell::UpdateInputHandler( bool bForce /* = sal_False */, bool bStopEditing /* = sal_True */ )
621 ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl();
623 if ( pHdl )
625 OUString aString;
626 const EditTextObject* pObject = nullptr;
627 ScViewData& rViewData = GetViewData();
628 ScDocument* pDoc = rViewData.GetDocument();
629 SCCOL nPosX = rViewData.GetCurX();
630 SCROW nPosY = rViewData.GetCurY();
631 SCTAB nTab = rViewData.GetTabNo();
632 SCTAB nStartTab = 0;
633 SCTAB nEndTab = 0;
634 SCCOL nStartCol = 0;
635 SCROW nStartRow = 0;
636 SCCOL nEndCol = 0;
637 SCROW nEndRow = 0;
638 ScAddress aPos = rViewData.GetCurPos();
640 rViewData.GetSimpleArea( nStartCol, nStartRow, nStartTab,
641 nEndCol, nEndRow, nEndTab );
643 PutInOrder( nStartCol, nEndCol );
644 PutInOrder( nStartRow, nEndRow );
645 PutInOrder( nStartTab, nEndTab );
647 bool bHideFormula = false;
648 bool bHideAll = false;
650 if (pDoc->IsTabProtected(nTab))
652 const ScProtectionAttr* pProt = static_cast<const ScProtectionAttr*>(
653 pDoc->GetAttr( nPosX,nPosY,nTab,
654 ATTR_PROTECTION));
655 bHideFormula = pProt->GetHideFormula();
656 bHideAll = pProt->GetHideCell();
659 if (!bHideAll)
661 ScRefCellValue rCell(*pDoc, aPos);
662 if (rCell.meType == CELLTYPE_FORMULA)
664 if (!bHideFormula)
665 rCell.mpFormula->GetFormula(aString);
667 else if (rCell.meType == CELLTYPE_EDIT)
669 pObject = rCell.mpEditText;
671 else
673 SvNumberFormatter* pFormatter = pDoc->GetFormatTable();
674 sal_uInt32 nNumFmt = pDoc->GetNumberFormat( aPos );
676 ScCellFormat::GetInputString( rCell, nNumFmt, aString, *pFormatter, pDoc );
677 if (rCell.meType == CELLTYPE_STRING)
679 // Put a ' in front if necessary, so that the string is not
680 // unintentionally interpreted as a number, and to show the
681 // user that it is a string (#35060#).
682 //! also for numberformat "Text"? -> then remove when editing
683 double fDummy;
684 if ( pFormatter->IsNumberFormat(aString, nNumFmt, fDummy) )
685 aString = "'" + aString;
690 ScInputHdlState aState( ScAddress( nPosX, nPosY, nTab ),
691 ScAddress( nStartCol, nStartRow, nTab ),
692 ScAddress( nEndCol, nEndRow, nTab ),
693 aString,
694 pObject );
696 // if using the view's local input handler, this view can always be set
697 // as current view inside NotifyChange.
698 ScTabViewShell* pSourceSh = pInputHandler ? this : nullptr;
700 pHdl->NotifyChange( &aState, bForce, pSourceSh, bStopEditing );
703 SfxBindings& rBindings = GetViewFrame()->GetBindings();
704 rBindings.Invalidate( SID_STATUS_SUM ); // always together with the input row
705 rBindings.Invalidate( SID_ATTR_SIZE );
706 rBindings.Invalidate( SID_TABLE_CELL );
709 void ScTabViewShell::UpdateInputHandlerCellAdjust( SvxCellHorJustify eJust )
711 if( ScInputHandler* pHdl = pInputHandler ? pInputHandler : SC_MOD()->GetInputHdl() )
712 pHdl->UpdateCellAdjust( eJust );
715 void ScTabViewShell::ExecuteSave( SfxRequest& rReq )
717 // only SID_SAVEDOC / SID_SAVEASDOC
718 bool bCommitChanges = true;
719 const SfxItemSet* pReqArgs = rReq.GetArgs();
720 const SfxPoolItem* pItem;
722 if (pReqArgs && pReqArgs->HasItem(FN_PARAM_1, &pItem))
723 bCommitChanges = !static_cast<const SfxBoolItem*>(pItem)->GetValue();
725 // Finish entering unless 'DontTerminateEdit' is specified, even if a formula is being processed
726 if (bCommitChanges)
727 SC_MOD()->InputEnterHandler();
729 if ( GetViewData().GetDocShell()->IsDocShared() )
731 GetViewData().GetDocShell()->SetDocumentModified();
734 // otherwise as normal
735 GetViewData().GetDocShell()->ExecuteSlot( rReq );
738 void ScTabViewShell::GetSaveState( SfxItemSet& rSet )
740 SfxShell* pDocSh = GetViewData().GetDocShell();
742 SfxWhichIter aIter(rSet);
743 sal_uInt16 nWhich = aIter.FirstWhich();
744 while( nWhich )
746 if ( nWhich != SID_SAVEDOC || !GetViewData().GetDocShell()->IsDocShared() )
748 // get state from DocShell
749 pDocSh->GetSlotState( nWhich, nullptr, &rSet );
751 nWhich = aIter.NextWhich();
755 void ScTabViewShell::ExecDrawOpt( SfxRequest& rReq )
757 ScViewOptions aViewOptions = GetViewData().GetOptions();
758 ScGridOptions aGridOptions = aViewOptions.GetGridOptions();
760 SfxBindings& rBindings = GetViewFrame()->GetBindings();
761 const SfxItemSet* pArgs = rReq.GetArgs();
762 const SfxPoolItem* pItem;
763 sal_uInt16 nSlotId = rReq.GetSlot();
764 switch (nSlotId)
766 case SID_GRID_VISIBLE:
767 if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
769 aGridOptions.SetGridVisible( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
770 aViewOptions.SetGridOptions(aGridOptions);
771 rBindings.Invalidate(SID_GRID_VISIBLE);
773 break;
775 case SID_GRID_USE:
776 if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
778 aGridOptions.SetUseGridSnap( static_cast<const SfxBoolItem*>(pItem)->GetValue() );
779 aViewOptions.SetGridOptions(aGridOptions);
780 rBindings.Invalidate(SID_GRID_USE);
782 break;
784 case SID_HELPLINES_MOVE:
785 if ( pArgs && pArgs->GetItemState(nSlotId,true,&pItem) == SfxItemState::SET )
787 aViewOptions.SetOption( VOPT_HELPLINES, static_cast<const SfxBoolItem*>(pItem)->GetValue() );
788 rBindings.Invalidate(SID_HELPLINES_MOVE);
790 break;
793 GetViewData().SetOptions(aViewOptions);
796 void ScTabViewShell::GetDrawOptState( SfxItemSet& rSet )
798 SfxBoolItem aBool;
800 const ScViewOptions& rViewOptions = GetViewData().GetOptions();
801 const ScGridOptions& rGridOptions = rViewOptions.GetGridOptions();
803 aBool.SetValue(rGridOptions.GetGridVisible());
804 aBool.SetWhich( SID_GRID_VISIBLE );
805 rSet.Put( aBool );
807 aBool.SetValue(rGridOptions.GetUseGridSnap());
808 aBool.SetWhich( SID_GRID_USE );
809 rSet.Put( aBool );
811 aBool.SetValue(rViewOptions.GetOption( VOPT_HELPLINES ));
812 aBool.SetWhich( SID_HELPLINES_MOVE );
813 rSet.Put( aBool );
816 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */