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 <svx/numfmtsh.hxx>
23#include <svx/numinf.hxx>
24#include <svx/svxids.hrc>
25#include <sfx2/dispatch.hxx>
26#include <sfx2/objsh.hxx>
27#include <sfx2/viewfrm.hxx>
28#include <osl/diagnose.h>
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/numformat.hxx>
40#include <svl/sharedstring.hxx>
41
43{
44 if (const ScPaintHint* pPaintHint = dynamic_cast<const ScPaintHint*>(&rHint)) // draw new
45 {
46 PaintPartFlags nParts = pPaintHint->GetParts();
47 SCTAB nTab = GetViewData().GetTabNo();
48 if (pPaintHint->GetStartTab() <= nTab && pPaintHint->GetEndTab() >= nTab)
49 {
50 if (nParts & PaintPartFlags::Extras) // first if table vanished !!!
51 if (PaintExtras())
52 nParts = PaintPartFlags::All;
53
54 // if the current sheet has pending row height updates (sheet links refreshed),
55 // execute them before invalidating the window
57
58 if (nParts & PaintPartFlags::Size)
59 RepeatResize();
60 if (nParts & PaintPartFlags::Grid)
61 PaintArea( pPaintHint->GetStartCol(), pPaintHint->GetStartRow(),
62 pPaintHint->GetEndCol(), pPaintHint->GetEndRow() );
63 if (nParts & PaintPartFlags::Marks)
64 PaintArea( pPaintHint->GetStartCol(), pPaintHint->GetStartRow(),
65 pPaintHint->GetEndCol(), pPaintHint->GetEndRow(), ScUpdateMode::Marks );
66 if (nParts & PaintPartFlags::Left)
67 PaintLeftArea( pPaintHint->GetStartRow(), pPaintHint->GetEndRow() );
68 if (nParts & PaintPartFlags::Top)
69 PaintTopArea( pPaintHint->GetStartCol(), pPaintHint->GetEndCol() );
70
71 // #i84689# call UpdateAllOverlays here instead of in ScTabView::PaintArea
72 if (nParts & ( PaintPartFlags::Left | PaintPartFlags::Top )) // only if widths or heights changed
74
76 }
77 }
78 else if (auto pEditViewHint = dynamic_cast<const ScEditViewHint*>(&rHint)) // create Edit-View
79 {
80 // ScEditViewHint is only received at active view
81
82 SCTAB nTab = GetViewData().GetTabNo();
83 if ( pEditViewHint->GetTab() == nTab )
84 {
85 SCCOL nCol = pEditViewHint->GetCol();
86 SCROW nRow = pEditViewHint->GetRow();
87 {
89
90 MakeEditView( pEditViewHint->GetEngine(), nCol, nRow );
91
92 StopEditShell(); // shouldn't be set
93
95 if ( GetViewData().HasEditView(eActive) )
96 {
97 // MakeEditView will fail, if the cursor is outside the screen.
98 // Then GetEditView will return a none-active view, therefore
99 // calling HasEditView.
100
101 EditView* pView = GetViewData().GetEditView(eActive); // isn't zero
102
103 SetEditShell(pView, true);
104 }
105 }
106 }
107 }
108 else if (auto pTablesHint = dynamic_cast<const ScTablesHint*>(&rHint)) // table insert / deleted
109 {
110 // first fetch current table (can be changed during DeleteTab on ViewData)
111 SCTAB nActiveTab = GetViewData().GetTabNo();
112
113 SCTAB nTab1 = pTablesHint->GetTab1();
114 SCTAB nTab2 = pTablesHint->GetTab2();
115 sal_uInt16 nId = pTablesHint->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
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:
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:
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()
234 || bInDispose)
235 {
237 KillEditView( nSlot == SfxHintId::ScKillEditViewNoPaint );
238 }
239 break;
240
241 case SfxHintId::DocChanged:
242 {
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:
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
313std::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.getType())
325 {
326 case CELLTYPE_VALUE:
327 {
328 nCellValue = aCell.getDouble();
329 eValType = SvxNumberValueType::Number;
330 }
331 break;
332
333 case CELLTYPE_STRING:
334 {
335 aCellString = aCell.getSharedString()->getString();
336 eValType = SvxNumberValueType::String;
337 }
338 break;
339
340 case CELLTYPE_FORMULA:
341 {
342 if (aCell.getFormula()->IsValue())
343 {
344 nCellValue = aCell.getFormula()->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(), 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: */
void UpdatePendingRowHeights(SCTAB nUpdateTab, bool bBefore=false)
Definition: docsh5.cxx:442
SC_DLLPUBLIC SvNumberFormatter * GetFormatTable() const
Definition: documen2.cxx:467
SC_DLLPUBLIC bool HasTable(SCTAB nTab) const
Definition: document.cxx:2502
SC_DLLPUBLIC SCTAB GetTableCount() const
Definition: document.cxx:297
double GetValue()
static void UpdateNumberFormatter(const SvxNumberInfoItem &rInfoItem)
Definition: tabvwsh5.cxx:383
bool bInPrepareClose
Definition: tabvwsh.hxx:157
void SetEditShell(EditView *pView, bool bActive)
Definition: tabvwsh4.cxx:771
static std::unique_ptr< SvxNumberInfoItem > MakeNumberInfoItem(ScDocument &rDoc, const ScViewData &rViewData)
Definition: tabvwsh5.cxx:313
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: tabvwsh5.cxx:42
void StopEditShell()
Definition: tabvwsh4.cxx:1106
void UpdateLayerLocks()
Definition: tabview5.cxx:351
void PaintTopArea(SCCOL nStartCol, SCCOL nEndCol)
Definition: tabview3.cxx:2687
bool PaintExtras()
Definition: tabview3.cxx:2787
void MakeDrawView(TriState nForceDesignMode)
Definition: tabview5.cxx:227
void MakeEditView(ScEditEngineDefaulter *pEngine, SCCOL nCol, SCROW nRow)
Definition: tabview3.cxx:2113
ScViewSelectionEngine * GetSelEngine()
Definition: tabview.hxx:348
void PaintArea(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow, ScUpdateMode eMode=ScUpdateMode::All)
Definition: tabview3.cxx:2331
void StopRefMode()
Definition: tabview4.cxx:113
ScViewData & GetViewData()
Definition: tabview.hxx:344
ScGridWindow * GetActiveWin()
Definition: tabview.cxx:878
void UpdateFormulas(SCCOL nStartCol=-1, SCROW nStartRow=-1, SCCOL nEndCol=-1, SCROW nEndRow=-1)
Definition: tabview3.cxx:2308
void HideNoteMarker()
Definition: tabview2.cxx:1522
void KillEditView(bool bNoPaint)
Definition: tabview3.cxx:2196
SC_DLLPUBLIC void SetTabNo(SCTAB nTab, bool bNew=false, bool bExtendSelection=false, bool bSameTabButMoved=false)
Definition: tabview3.cxx:1819
void PaintRangeFinder(tools::Long nNumber)
Definition: tabview3.cxx:2521
void UpdateAllOverlays()
Definition: tabview2.cxx:1137
void RepeatResize(bool bUpdateFix=true)
Definition: tabview.cxx:763
void PaintLeftArea(SCROW nStartRow, SCROW nEndRow)
Definition: tabview3.cxx:2745
void UpdateInputContext()
Definition: tabview3.cxx:3005
SfxDispatcher & GetDispatcher()
Definition: viewdata.cxx:3140
void DeleteTabs(SCTAB nTab, SCTAB nSheets)
Definition: viewdata.cxx:929
void DeleteTab(SCTAB nTab)
Definition: viewdata.cxx:915
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
void InsertTab(SCTAB nTab)
Definition: viewdata.cxx:882
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
ScDocShell * GetDocShell() const
Definition: viewdata.hxx:354
void InsertTabs(SCTAB nTab, SCTAB nNewSheets)
Definition: viewdata.cxx:896
ScSplitPos GetActivePart() const
Definition: viewdata.hxx:398
void GetEditView(ScSplitPos eWhich, EditView *&rViewPtr, SCCOL &rCol, SCROW &rRow)
Definition: viewdata.cxx:2284
void CopyTab(SCTAB nSrcTab, SCTAB nDestTab)
Definition: viewdata.cxx:944
SfxObjectShell * GetSfxDocShell() const
Definition: viewdata.hxx:358
ScAddress GetCurPos() const
Definition: viewdata.cxx:4119
void MoveTab(SCTAB nSrcTab, SCTAB nDestTab)
Definition: viewdata.cxx:969
void Invalidate(sal_uInt16 nId)
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 GetId() const
bool IsReadOnly() const
SfxBindings & GetBindings()
SfxViewFrame & GetViewFrame() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
static SAL_WARN_UNUSED_RESULT SfxViewShell * Current()
void DeleteEntry(sal_uInt32 nKey)
SvNumberFormatter * GetNumberFormatter() const
const std::vector< sal_uInt32 > & GetDelFormats() const
const OUString & getString() const
constexpr OUStringLiteral IsReadOnly(u"IsReadOnly")
TRISTATE_INDET
@ CELLTYPE_STRING
Definition: global.hxx:275
@ CELLTYPE_FORMULA
Definition: global.hxx:276
@ CELLTYPE_VALUE
Definition: global.hxx:274
PaintPartFlags
Definition: global.hxx:109
SfxHintId
sal_Int32 nIndex
SvxNumberValueType
sal_Int16 nId
#define SC_MOD()
Definition: scmod.hxx:247
This is very similar to ScCellValue, except that it references the original value instead of copying ...
Definition: cellvalue.hxx:108
ScFormulaCell * getFormula() const
Definition: cellvalue.hxx:137
double getDouble() const
Definition: cellvalue.hxx:134
const svl::SharedString * getSharedString() const
Definition: cellvalue.hxx:135
CellType getType() const
Definition: cellvalue.hxx:133
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
#define SC_TAB_MOVED
Definition: uiitems.hxx:77
#define SC_TAB_COPIED
Definition: uiitems.hxx:78
#define SC_TABS_INSERTED
Definition: uiitems.hxx:80
#define SC_TAB_INSERTED
Definition: uiitems.hxx:75
#define SC_TAB_HIDDEN
Definition: uiitems.hxx:79
#define SC_TABS_DELETED
Definition: uiitems.hxx:81
#define SC_TAB_DELETED
Definition: uiitems.hxx:76
ScSplitPos
Definition: viewdata.hxx:44