LibreOffice Module sc (master)  1
tabvwsh5.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 <svl/hint.hxx>
21 #include <comphelper/lok.hxx>
22 #include <svl/zforlist.hxx>
23 #include <svx/numfmtsh.hxx>
24 #include <svx/numinf.hxx>
25 #include <svx/svxids.hrc>
26 #include <sfx2/dispatch.hxx>
27 #include <sfx2/objsh.hxx>
28 #include <sfx2/viewfrm.hxx>
29 
30 #include <tabvwsh.hxx>
31 #include <global.hxx>
32 #include <docsh.hxx>
33 #include <document.hxx>
34 #include <formulacell.hxx>
35 #include <scmod.hxx>
36 #include <uiitems.hxx>
37 #include <hints.hxx>
38 #include <cellvalue.hxx>
39 #include <svl/sharedstring.hxx>
40 
41 void ScTabViewShell::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
42 {
43  if (const ScPaintHint* pPaintHint = dynamic_cast<const ScPaintHint*>(&rHint)) // draw new
44  {
45  PaintPartFlags nParts = pPaintHint->GetParts();
46  SCTAB nTab = GetViewData().GetTabNo();
47  if (pPaintHint->GetStartTab() <= nTab && pPaintHint->GetEndTab() >= nTab)
48  {
49  if (nParts & PaintPartFlags::Extras) // first if table vanished !!!
50  if (PaintExtras())
51  nParts = PaintPartFlags::All;
52 
53  // if the current sheet has pending row height updates (sheet links refreshed),
54  // execute them before invalidating the window
56 
57  if (nParts & PaintPartFlags::Size)
58  RepeatResize();
59  if (nParts & PaintPartFlags::Grid)
60  PaintArea( pPaintHint->GetStartCol(), pPaintHint->GetStartRow(),
61  pPaintHint->GetEndCol(), pPaintHint->GetEndRow() );
62  if (nParts & PaintPartFlags::Marks)
63  PaintArea( pPaintHint->GetStartCol(), pPaintHint->GetStartRow(),
64  pPaintHint->GetEndCol(), pPaintHint->GetEndRow(), ScUpdateMode::Marks );
65  if (nParts & PaintPartFlags::Left)
66  PaintLeftArea( pPaintHint->GetStartRow(), pPaintHint->GetEndRow() );
67  if (nParts & PaintPartFlags::Top)
68  PaintTopArea( pPaintHint->GetStartCol(), pPaintHint->GetEndCol() );
69 
70  // #i84689# call UpdateAllOverlays here instead of in ScTabView::PaintArea
71  if (nParts & ( PaintPartFlags::Left | PaintPartFlags::Top )) // only if widths or heights changed
73 
75  }
76  }
77  else if (auto pEditViewHint = dynamic_cast<const ScEditViewHint*>(&rHint)) // create Edit-View
78  {
79  // ScEditViewHint is only received at active view
80 
81  SCTAB nTab = GetViewData().GetTabNo();
82  if ( pEditViewHint->GetTab() == nTab )
83  {
84  SCCOL nCol = pEditViewHint->GetCol();
85  SCROW nRow = pEditViewHint->GetRow();
86  {
88 
89  MakeEditView( pEditViewHint->GetEngine(), nCol, nRow );
90 
91  StopEditShell(); // shouldn't be set
92 
93  ScSplitPos eActive = GetViewData().GetActivePart();
94  if ( GetViewData().HasEditView(eActive) )
95  {
96  // MakeEditView will fail, if the cursor is outside the screen.
97  // Then GetEditView will return a none-active view, therefore
98  // calling HasEditView.
99 
100  EditView* pView = GetViewData().GetEditView(eActive); // isn't zero
101 
102  SetEditShell(pView, true);
103  }
104  }
105  }
106  }
107  else if (dynamic_cast<const ScTablesHint*>(&rHint)) // table insert / deleted
108  {
109  // first fetch current table (can be changed during DeleteTab on ViewData)
110  SCTAB nActiveTab = GetViewData().GetTabNo();
111 
112  const ScTablesHint& rTabHint = static_cast<const ScTablesHint&>(rHint);
113  SCTAB nTab1 = rTabHint.GetTab1();
114  SCTAB nTab2 = rTabHint.GetTab2();
115  sal_uInt16 nId = rTabHint.GetTablesHintId();
116  switch (nId)
117  {
118  case SC_TAB_INSERTED:
119  GetViewData().InsertTab( nTab1 );
120  break;
121  case SC_TAB_DELETED:
122  GetViewData().DeleteTab( nTab1 );
123  break;
124  case SC_TAB_MOVED:
125  GetViewData().MoveTab( nTab1, nTab2 );
126  break;
127  case SC_TAB_COPIED:
128  GetViewData().CopyTab( nTab1, nTab2 );
129  break;
130  case SC_TAB_HIDDEN:
131  break;
132  case SC_TABS_INSERTED:
133  GetViewData().InsertTabs( nTab1, nTab2 );
134  break;
135  case SC_TABS_DELETED:
136  GetViewData().DeleteTabs( nTab1, nTab2 );
137  break;
138  default:
139  OSL_FAIL("unknown ScTablesHint");
140  }
141 
142  // No calling of IsActive() here, because the actions can be coming from Basic
143  // and then also the active view has to be switched.
144 
145  SCTAB nNewTab = nActiveTab;
146  bool bStayOnActiveTab = true;
147  switch (nId)
148  {
149  case SC_TAB_INSERTED:
150  if ( nTab1 <= nNewTab ) // insert before
151  ++nNewTab;
152  break;
153  case SC_TAB_DELETED:
154  if ( nTab1 < nNewTab ) // deleted before
155  --nNewTab;
156  else if ( nTab1 == nNewTab ) // deleted current
157  bStayOnActiveTab = false;
158  break;
159  case SC_TAB_MOVED:
160  if ( nNewTab == nTab1 ) // moved table
161  nNewTab = nTab2;
162  else if ( nTab1 < nTab2 ) // moved back
163  {
164  if ( nNewTab > nTab1 && nNewTab <= nTab2 ) // succeeding area
165  --nNewTab;
166  }
167  else // move in front
168  {
169  if ( nNewTab >= nTab2 && nNewTab < nTab1 ) // succeeding area
170  ++nNewTab;
171  }
172  break;
173  case SC_TAB_COPIED:
174  if ( nNewTab >= nTab2 ) // insert before
175  ++nNewTab;
176  break;
177  case SC_TAB_HIDDEN:
178  if ( nTab1 == nNewTab ) // current is hidden
179  bStayOnActiveTab = false;
180  break;
181  case SC_TABS_INSERTED:
182  if ( nTab1 <= nNewTab )
183  nNewTab += nTab2;
184  break;
185  case SC_TABS_DELETED:
186  if ( nTab1 < nNewTab )
187  nNewTab -= nTab2;
188  break;
189  }
190 
191  ScDocument& rDoc = GetViewData().GetDocument();
192  if ( nNewTab >= rDoc.GetTableCount() )
193  nNewTab = rDoc.GetTableCount() - 1;
194 
195  bool bForce = !bStayOnActiveTab;
196  SetTabNo( nNewTab, bForce, false, bStayOnActiveTab );
197  }
198  else if (const ScIndexHint* pIndexHint = dynamic_cast<const ScIndexHint*>(&rHint))
199  {
200  SfxHintId nId = pIndexHint->GetId();
201  sal_uInt16 nIndex = pIndexHint->GetIndex();
202  switch (nId)
203  {
204  case SfxHintId::ScShowRangeFinder:
205  PaintRangeFinder( nIndex );
206  break;
207  default: break;
208  }
209  }
210  else // without parameter
211  {
212  const SfxHintId nSlot = rHint.GetId();
213  switch ( nSlot )
214  {
215  case SfxHintId::ScDataChanged:
216  UpdateFormulas();
217  break;
218 
219  case SfxHintId::ScRefModeChanged:
220  {
221  bool bRefMode = SC_MOD()->IsFormulaMode();
222  if (!bRefMode)
223  StopRefMode();
224  else
225  GetSelEngine()->Reset();
226  }
227  break;
228 
229  case SfxHintId::ScKillEditView:
230  case SfxHintId::ScKillEditViewNoPaint:
232  || this == SfxViewShell::Current()
233  || bInPrepareClose
234  || bInDispose)
235  {
236  StopEditShell();
237  KillEditView( nSlot == SfxHintId::ScKillEditViewNoPaint );
238  }
239  break;
240 
241  case SfxHintId::DocChanged:
242  {
243  ScDocument& rDoc = GetViewData().GetDocument();
244  if (!rDoc.HasTable( GetViewData().GetTabNo() ))
245  {
246  SetTabNo(0);
247  }
248  }
249  break;
250 
251  case SfxHintId::ScDrawLayerNew:
253  break;
254 
255  case SfxHintId::ScDocSaved:
256  {
257  // "Save as" can make a write-protected document writable,
258  // therefore the Layer-Locks anew (#39884#)
259  // (Invalidate etc. is happening already from Sfx)
260  // by SID_EDITDOC no SfxHintId::TitleChanged will occur, that
261  // is why the own hint from DoSaveCompleted
263 
265 
266  // Would be too much to change Design-Mode with every save
267  // (when saving under the name, it should remain unchanged)
268  // Therefore only by SfxHintId::ModeChanged (from ViewFrame)
269  }
270  break;
271 
272  case SfxHintId::ModeChanged:
273  // Since you can no longer rely on it where this hint was coming
274  // from, always switch the design mode when the ReadOnly state
275  // really was changed:
276 
277  if ( GetViewData().GetSfxDocShell()->IsReadOnly() != bReadOnly )
278  {
280 
281  SfxBoolItem aItem( SID_FM_DESIGN_MODE, !bReadOnly);
282  GetViewData().GetDispatcher().ExecuteList(SID_FM_DESIGN_MODE,
283  SfxCallMode::ASYNCHRON, { &aItem });
284 
286  }
287  break;
288 
289  case SfxHintId::ScShowRangeFinder:
290  PaintRangeFinder(-1);
291  break;
292 
293  case SfxHintId::ScForceSetTab:
294  SetTabNo( GetViewData().GetTabNo(), true );
295  break;
296 
297  case SfxHintId::LanguageChanged:
298  {
299  GetViewFrame()->GetBindings().Invalidate(SID_LANGUAGE_STATUS);
300  if ( ScGridWindow* pWin = GetViewData().GetActiveWin() )
301  pWin->ResetAutoSpell();
302  }
303  break;
304 
305  default:
306  break;
307  }
308  }
309 
310  SfxViewShell::Notify( rBC, rHint );
311 }
312 
313 std::unique_ptr<SvxNumberInfoItem> ScTabViewShell::MakeNumberInfoItem( ScDocument& rDoc, const ScViewData& rViewData )
314 {
315 
316  // construct NumberInfo item
317 
318  SvxNumberValueType eValType = SvxNumberValueType::Undefined;
319  double nCellValue = 0;
320  OUString aCellString;
321 
322  ScRefCellValue aCell(rDoc, rViewData.GetCurPos());
323 
324  switch (aCell.meType)
325  {
326  case CELLTYPE_VALUE:
327  {
328  nCellValue = aCell.mfValue;
329  eValType = SvxNumberValueType::Number;
330  }
331  break;
332 
333  case CELLTYPE_STRING:
334  {
335  aCellString = aCell.mpString->getString();
336  eValType = SvxNumberValueType::String;
337  }
338  break;
339 
340  case CELLTYPE_FORMULA:
341  {
342  if (aCell.mpFormula->IsValue())
343  {
344  nCellValue = aCell.mpFormula->GetValue();
345  eValType = SvxNumberValueType::Number;
346  }
347  else
348  {
349  nCellValue = 0;
350  eValType = SvxNumberValueType::Undefined;
351  }
352  }
353  break;
354 
355  default:
356  nCellValue = 0;
357  eValType = SvxNumberValueType::Undefined;
358  }
359 
360  switch ( eValType )
361  {
362  case SvxNumberValueType::String:
363  return std::make_unique<SvxNumberInfoItem>(
364  rDoc.GetFormatTable(),
365  aCellString,
366  SID_ATTR_NUMBERFORMAT_INFO );
367 
368  case SvxNumberValueType::Number:
369  return std::make_unique<SvxNumberInfoItem>(
370  rDoc.GetFormatTable(),
371  nCellValue,
372  SID_ATTR_NUMBERFORMAT_INFO );
373 
374  case SvxNumberValueType::Undefined:
375  default:
376  ;
377  }
378 
379  return std::make_unique<SvxNumberInfoItem>(
380  rDoc.GetFormatTable(), static_cast<sal_uInt16>(SID_ATTR_NUMBERFORMAT_INFO));
381 }
382 
384  const SvxNumberInfoItem& rInfoItem )
385 {
386  for ( sal_uInt32 key : rInfoItem.GetDelFormats() )
387  rInfoItem.GetNumberFormatter()->DeleteEntry( key );
388 }
389 
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewFrame * GetViewFrame() const
SCTAB GetTab2() const
Definition: uiitems.hxx:96
const SfxPoolItem * ExecuteList(sal_uInt16 nSlot, SfxCallMode nCall, std::initializer_list< SfxPoolItem const * > args, std::initializer_list< SfxPoolItem const * > internalargs=std::initializer_list< SfxPoolItem const * >())
SfxHintId
sal_Int32 nIndex
static void UpdateNumberFormatter(const SvxNumberInfoItem &rInfoItem)
Definition: tabvwsh5.cxx:383
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
void UpdatePendingRowHeights(SCTAB nUpdateTab, bool bBefore=false)
Definition: docsh5.cxx:432
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
#define SC_TAB_MOVED
Definition: uiitems.hxx:78
void UpdateInputContext()
Definition: tabview3.cxx:2969
bool PaintExtras()
Definition: tabview3.cxx:2751
void InsertTabs(SCTAB nTab, SCTAB nNewSheets)
Definition: viewdata.cxx:884
void RepeatResize(bool bUpdateFix=true)
Definition: tabview.cxx:770
void HideNoteMarker()
Definition: tabview2.cxx:1386
bool bInPrepareClose
Definition: tabvwsh.hxx:153
sal_Int16 nId
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
SvxNumberValueType
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
void UpdateAllOverlays()
Definition: tabview2.cxx:999
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:104
#define SC_TAB_INSERTED
Definition: uiitems.hxx:76
void Invalidate(sal_uInt16 nId)
const std::vector< sal_uInt32 > & GetDelFormats() const
static std::unique_ptr< SvxNumberInfoItem > MakeNumberInfoItem(ScDocument &rDoc, const ScViewData &rViewData)
Definition: tabvwsh5.cxx:313
SfxHintId GetId() const
ScSplitPos
Definition: viewdata.hxx:45
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2167
void PaintLeftArea(SCROW nStartRow, SCROW nEndRow)
Definition: tabview3.cxx:2711
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:312
void PaintRangeFinder(tools::Long nNumber)
Definition: tabview3.cxx:2491
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: tabvwsh5.cxx:41
static SfxViewShell * Current()
void UpdateFormulas(SCCOL nStartCol=-1, SCROW nStartRow=-1, SCCOL nEndCol=-1, SCROW nEndRow=-1)
Definition: tabview3.cxx:2279
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:189
#define SC_TAB_DELETED
Definition: uiitems.hxx:77
TRISTATE_INDET
ScViewData & GetViewData()
Definition: tabview.hxx:334
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:885
void PaintArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScUpdateMode eMode=ScUpdateMode::All)
Definition: tabview3.cxx:2302
void InsertTab(SCTAB nTab)
Definition: viewdata.cxx:870
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:438
void DeleteTab(SCTAB nTab)
Definition: viewdata.cxx:903
sal_Int16 SCCOL
Definition: types.hxx:22
#define SC_TAB_HIDDEN
Definition: uiitems.hxx:80
#define SC_MOD()
Definition: scmod.hxx:250
SfxBindings & GetBindings()
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1794
void StopEditShell()
Definition: tabvwsh4.cxx:1050
void DeleteTabs(SCTAB nTab, SCTAB nSheets)
Definition: viewdata.cxx:917
void DeleteEntry(sal_uInt32 nKey)
void MakeEditView(ScEditEngineDefaulter *pEngine, SCCOL nCol, SCROW nRow)
Definition: tabview3.cxx:2087
void MoveTab(SCTAB nSrcTab, SCTAB nDestTab)
Definition: viewdata.cxx:957
bool IsReadOnly() const
void StopRefMode()
Definition: tabview4.cxx:113
ScAddress GetCurPos() const
Definition: viewdata.cxx:4007
SvNumberFormatter * GetNumberFormatter() const
#define SC_TABS_DELETED
Definition: uiitems.hxx:82
sal_Int32 SCROW
Definition: types.hxx:18
sal_uInt16 GetTablesHintId() const
Definition: uiitems.hxx:94
#define SC_TABS_INSERTED
Definition: uiitems.hxx:81
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3040
ScViewSelectionEngine * GetSelEngine()
Definition: tabview.hxx:338
SfxObjectShell * GetSfxDocShell() const
Definition: viewdata.hxx:358
#define SC_TAB_COPIED
Definition: uiitems.hxx:79
void PaintTopArea(SCCOL nStartCol, SCCOL nEndCol)
Definition: tabview3.cxx:2655
void CopyTab(SCTAB nSrcTab, SCTAB nDestTab)
Definition: viewdata.cxx:932
PaintPartFlags
Definition: global.hxx:121
void UpdateLayerLocks()
Definition: tabview5.cxx:346
void SetEditShell(EditView *pView, bool bActive)
Definition: tabvwsh4.cxx:732
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2219
sal_Int16 SCTAB
Definition: types.hxx:23
void MakeDrawView(TriState nForceDesignMode)
Definition: tabview5.cxx:228
SCTAB GetTab1() const
Definition: uiitems.hxx:95