Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sc/source/ui/view/tabview3.cxx
Line
Count
Source
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 <officecfg/Office/Calc.hxx>
21
#include <rangelst.hxx>
22
#include <scitems.hxx>
23
24
#include <editeng/editview.hxx>
25
#include <editeng/StripPortionsHelper.hxx>
26
#include <svx/fmshell.hxx>
27
#include <svx/sdr/overlay/overlaymanager.hxx>
28
#include <svx/svdoole2.hxx>
29
#include <sfx2/bindings.hxx>
30
#include <sfx2/lokhelper.hxx>
31
#include <sfx2/viewfrm.hxx>
32
#include <vcl/cursor.hxx>
33
#include <vcl/dndlistenercontainer.hxx>
34
#include <vcl/uitest/logger.hxx>
35
#include <vcl/uitest/eventdescription.hxx>
36
#include <sal/log.hxx>
37
#include <osl/diagnose.h>
38
39
#include <basegfx/polygon/b2dpolygontools.hxx>
40
#include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
41
#include <drawinglayer/primitive2d/transformprimitive2d.hxx>
42
#include <svx/sdr/overlay/overlayselection.hxx>
43
#include <svtools/optionsdrawinglayer.hxx>
44
45
#include <IAnyRefDialog.hxx>
46
#include <tabview.hxx>
47
#include <tabvwsh.hxx>
48
#include <docsh.hxx>
49
#include <gridwin.hxx>
50
#include <olinewin.hxx>
51
#include <overlayobject.hxx>
52
#include <colrowba.hxx>
53
#include <tabcont.hxx>
54
#include <scmod.hxx>
55
#include <sc.hrc>
56
#include <viewutil.hxx>
57
#include <editutil.hxx>
58
#include <inputhdl.hxx>
59
#include <inputwin.hxx>
60
#include <validat.hxx>
61
#include <inputopt.hxx>
62
#include <rfindlst.hxx>
63
#include <hiranges.hxx>
64
#include <viewuno.hxx>
65
#include <dpobject.hxx>
66
#include <seltrans.hxx>
67
#include <fillinfo.hxx>
68
#include <rangeutl.hxx>
69
#include <client.hxx>
70
#include <tabprotection.hxx>
71
#include <spellcheckcontext.hxx>
72
#include <markdata.hxx>
73
#include <formula/FormulaCompiler.hxx>
74
#include <comphelper/lok.hxx>
75
#include <comphelper/scopeguard.hxx>
76
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
77
#include <output.hxx>
78
79
#include <utility>
80
81
#include <com/sun/star/chart2/data/HighlightedRange.hpp>
82
83
namespace
84
{
85
86
ScRange lcl_getSubRangeByIndex( const ScRange& rRange, sal_Int32 nIndex )
87
0
{
88
0
    ScAddress aResult( rRange.aStart );
89
90
0
    SCCOL nWidth = rRange.aEnd.Col() - rRange.aStart.Col() + 1;
91
0
    SCROW nHeight = rRange.aEnd.Row() - rRange.aStart.Row() + 1;
92
0
    SCTAB nDepth = rRange.aEnd.Tab() - rRange.aStart.Tab() + 1;
93
0
    if( (nWidth > 0) && (nHeight > 0) && (nDepth > 0) )
94
0
    {
95
        // row by row from first to last sheet
96
0
        sal_Int32 nArea = nWidth * nHeight;
97
0
        aResult.IncCol( static_cast< SCCOL >( nIndex % nWidth ) );
98
0
        aResult.IncRow( static_cast< SCROW >( (nIndex % nArea) / nWidth ) );
99
0
        aResult.IncTab( static_cast< SCTAB >( nIndex / nArea ) );
100
0
        if( !rRange.Contains( aResult ) )
101
0
            aResult = rRange.aStart;
102
0
    }
103
104
0
    return ScRange( aResult );
105
0
}
106
107
} // anonymous namespace
108
109
using namespace com::sun::star;
110
111
ScExtraEditViewManager::~ScExtraEditViewManager()
112
0
{
113
0
    DBG_ASSERT(nTotalWindows == 0, "ScExtraEditViewManager dtor: some out window has not yet been removed!");
114
0
}
115
116
inline void ScExtraEditViewManager::Add(SfxViewShell* pViewShell, ScSplitPos eWhich)
117
0
{
118
0
    Apply<Adder>(pViewShell, eWhich);
119
0
}
120
121
inline void ScExtraEditViewManager::Remove(SfxViewShell* pViewShell, ScSplitPos eWhich)
122
0
{
123
0
    Apply<Remover>(pViewShell, eWhich);
124
0
}
125
126
127
template<ScExtraEditViewManager::ModifierTagType ModifierTag>
128
void ScExtraEditViewManager::Apply(SfxViewShell* pViewShell, ScSplitPos eWhich)
129
0
{
130
0
    ScTabViewShell* pOtherViewShell = dynamic_cast<ScTabViewShell*>(pViewShell);
131
0
    if (pOtherViewShell == nullptr || pOtherViewShell == mpThisViewShell)
132
0
        return;
133
134
0
    mpOtherEditView = pOtherViewShell->GetViewData().GetEditView(eWhich);
135
0
    if (mpOtherEditView != nullptr)
136
0
    {
137
0
        for (int i = 0; i < 4; ++i)
138
0
        {
139
0
            ScGridWindow* pWin = mpGridWin[i].get();
140
0
            if (pWin != nullptr)
141
0
            {
142
0
                Modifier<ModifierTag>(pWin);
143
0
            }
144
0
        }
145
0
    }
146
0
}
Unexecuted instantiation: void ScExtraEditViewManager::Apply<(ScExtraEditViewManager::ModifierTagType)0>(SfxViewShell*, ScSplitPos)
Unexecuted instantiation: void ScExtraEditViewManager::Apply<(ScExtraEditViewManager::ModifierTagType)1>(SfxViewShell*, ScSplitPos)
147
148
template<ScExtraEditViewManager::ModifierTagType ModifierTag>
149
void ScExtraEditViewManager::Modifier(ScGridWindow* /*pWin*/)
150
{
151
    (void)this;
152
    SAL_WARN("sc", "ScExtraEditViewManager::Modifier<ModifierTag>: non-specialized version should not be invoked.");
153
}
154
155
template<>
156
void ScExtraEditViewManager::Modifier<ScExtraEditViewManager::Adder>(ScGridWindow* pWin)
157
0
{
158
0
    if (mpOtherEditView->AddOtherViewWindow(pWin))
159
0
        ++nTotalWindows;
160
0
}
161
162
template<>
163
void ScExtraEditViewManager::Modifier<ScExtraEditViewManager::Remover>(ScGridWindow* pWin)
164
0
{
165
0
    if (mpOtherEditView->RemoveOtherViewWindow(pWin))
166
0
        --nTotalWindows;
167
0
}
168
169
// ---  public functions
170
171
void ScTabView::ClickCursor( SCCOL nPosX, SCROW nPosY, bool bControl )
172
0
{
173
0
    ScDocument& rDoc = aViewData.GetDocument();
174
0
    SCTAB nTab = aViewData.CurrentTabForData();
175
0
    rDoc.SkipOverlapped(nPosX, nPosY, nTab);
176
177
0
    ScModule* mod = ScModule::get();
178
0
    bool bRefMode = mod->IsFormulaMode();
179
180
0
    if ( bRefMode )
181
0
    {
182
0
        DoneRefMode();
183
184
0
        if (bControl)
185
0
            mod->AddRefEntry();
186
187
0
        InitRefMode( nPosX, nPosY, nTab, SC_REFTYPE_REF );
188
0
    }
189
0
    else
190
0
    {
191
0
        DoneBlockMode( bControl );
192
0
        aViewData.ResetOldCursor();
193
0
        SetCursor( nPosX, nPosY );
194
0
    }
195
0
}
196
197
void ScTabView::UpdateAutoFillMark(bool bFromPaste)
198
0
{
199
    // single selection or cursor
200
0
    ScRange aMarkRange;
201
0
    ScMarkType eMarkType = aViewData.GetSimpleArea(aMarkRange);
202
0
    bool bMarked = eMarkType == SC_MARK_SIMPLE || eMarkType == SC_MARK_SIMPLE_FILTERED;
203
204
0
    for (sal_uInt16 i = 0; i < 4; i++)
205
0
    {
206
0
        if (pGridWin[i] && pGridWin[i]->IsVisible())
207
0
            pGridWin[i]->UpdateAutoFillMark( bMarked, aMarkRange );
208
0
    }
209
210
0
    for (sal_uInt16 i = 0; i < 2; i++)
211
0
    {
212
0
        if (pColBar[i] && pColBar[i]->IsVisible())
213
0
            pColBar[i]->SetMark( bMarked, aMarkRange.aStart.Col(), aMarkRange.aEnd.Col() );
214
0
        if (pRowBar[i] && pRowBar[i]->IsVisible())
215
0
            pRowBar[i]->SetMark( bMarked, aMarkRange.aStart.Row(), aMarkRange.aEnd.Row() );
216
0
    }
217
218
    //  selection transfer object is checked together with AutoFill marks,
219
    //  because it has the same requirement of a single continuous block.
220
0
    if (!bFromPaste)
221
0
        CheckSelectionTransfer();   // update selection transfer object
222
0
}
223
224
void ScTabView::FakeButtonUp( ScSplitPos eWhich )
225
0
{
226
0
    if (pGridWin[eWhich])
227
0
        pGridWin[eWhich]->FakeButtonUp();
228
0
}
229
230
void ScTabView::HideAllCursors()
231
0
{
232
0
    for (VclPtr<ScGridWindow> & pWin : pGridWin)
233
0
    {
234
0
        if (pWin && pWin->IsVisible())
235
0
        {
236
0
            vcl::Cursor* pCur = pWin->GetCursor();
237
0
            if (pCur && pCur->IsVisible())
238
0
                pCur->Hide();
239
0
            pWin->HideCursor();
240
0
        }
241
0
    }
242
0
}
243
244
void ScTabView::ShowAllCursors()
245
0
{
246
0
    for (VclPtr<ScGridWindow> & pWin : pGridWin)
247
0
    {
248
0
        if (pWin && pWin->IsVisible())
249
0
        {
250
0
            pWin->ShowCursor();
251
0
            pWin->CursorChanged();
252
0
        }
253
0
    }
254
0
}
255
256
void ScTabView::ShowCursor()
257
0
{
258
0
    pGridWin[aViewData.GetActivePart()]->ShowCursor();
259
0
    pGridWin[aViewData.GetActivePart()]->CursorChanged();
260
0
}
261
262
void ScTabView::InvalidateAttribs()
263
0
{
264
0
    SfxBindings& rBindings = aViewData.GetBindings();
265
266
0
    rBindings.Invalidate( SID_STYLE_APPLY );
267
0
    rBindings.Invalidate( SID_STYLE_FAMILY2 );
268
0
    rBindings.Invalidate( SID_STYLE_FAMILY3 );
269
270
0
    rBindings.Invalidate( SID_ATTR_CHAR_FONT );
271
0
    rBindings.Invalidate( SID_ATTR_CHAR_FONTHEIGHT );
272
0
    rBindings.Invalidate( SID_ATTR_CHAR_COLOR );
273
274
0
    rBindings.Invalidate( SID_ATTR_CHAR_WEIGHT );
275
0
    rBindings.Invalidate( SID_ATTR_CHAR_POSTURE );
276
0
    rBindings.Invalidate( SID_ATTR_CHAR_UNDERLINE );
277
0
    rBindings.Invalidate( SID_ULINE_VAL_NONE );
278
0
    rBindings.Invalidate( SID_ULINE_VAL_SINGLE );
279
0
    rBindings.Invalidate( SID_ULINE_VAL_DOUBLE );
280
0
    rBindings.Invalidate( SID_ULINE_VAL_DOTTED );
281
282
0
    rBindings.Invalidate( SID_ATTR_CHAR_OVERLINE );
283
284
0
    rBindings.Invalidate( SID_ATTR_CHAR_KERNING );
285
0
    rBindings.Invalidate( SID_SET_SUPER_SCRIPT );
286
0
    rBindings.Invalidate( SID_SET_SUB_SCRIPT );
287
0
    rBindings.Invalidate( SID_ATTR_CHAR_STRIKEOUT );
288
0
    rBindings.Invalidate( SID_ATTR_CHAR_SHADOWED );
289
290
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_LEFT );
291
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_RIGHT );
292
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_BLOCK );
293
0
    rBindings.Invalidate( SID_ATTR_PARA_ADJUST_CENTER);
294
0
    rBindings.Invalidate( SID_NUMBER_TYPE_FORMAT);
295
296
0
    rBindings.Invalidate( SID_ALIGNLEFT );
297
0
    rBindings.Invalidate( SID_ALIGNRIGHT );
298
0
    rBindings.Invalidate( SID_ALIGNBLOCK );
299
0
    rBindings.Invalidate( SID_ALIGNCENTERHOR );
300
301
0
    rBindings.Invalidate( SID_ALIGNTOP );
302
0
    rBindings.Invalidate( SID_ALIGNBOTTOM );
303
0
    rBindings.Invalidate( SID_ALIGNCENTERVER );
304
305
0
    rBindings.Invalidate( SID_SCATTR_CELLPROTECTION );
306
307
    // stuff for sidebar panels
308
0
    {
309
0
        rBindings.Invalidate( SID_H_ALIGNCELL );
310
0
        rBindings.Invalidate( SID_V_ALIGNCELL );
311
0
        rBindings.Invalidate( SID_ATTR_ALIGN_INDENT );
312
0
        rBindings.Invalidate( SID_FRAME_LINECOLOR );
313
0
        rBindings.Invalidate( SID_FRAME_LINESTYLE );
314
0
        rBindings.Invalidate( SID_ATTR_BORDER_OUTER );
315
0
        rBindings.Invalidate( SID_ATTR_BORDER_INNER );
316
0
        rBindings.Invalidate( SID_ATTR_BORDER_DIAG_TLBR );
317
0
        rBindings.Invalidate( SID_ATTR_BORDER_DIAG_BLTR );
318
0
        rBindings.Invalidate( SID_NUMBER_TYPE_FORMAT );
319
0
    }
320
321
0
    rBindings.Invalidate( SID_BACKGROUND_COLOR );
322
323
0
    rBindings.Invalidate( SID_ATTR_ALIGN_LINEBREAK );
324
0
    rBindings.Invalidate( SID_NUMBER_FORMAT );
325
326
0
    rBindings.Invalidate( SID_TEXTDIRECTION_LEFT_TO_RIGHT );
327
0
    rBindings.Invalidate( SID_TEXTDIRECTION_TOP_TO_BOTTOM );
328
0
    rBindings.Invalidate( SID_ATTR_PARA_LEFT_TO_RIGHT );
329
0
    rBindings.Invalidate( SID_ATTR_PARA_RIGHT_TO_LEFT );
330
331
    // pseudo slots for Format menu
332
0
    rBindings.Invalidate( SID_ALIGN_ANY_HDEFAULT );
333
0
    rBindings.Invalidate( SID_ALIGN_ANY_LEFT );
334
0
    rBindings.Invalidate( SID_ALIGN_ANY_HCENTER );
335
0
    rBindings.Invalidate( SID_ALIGN_ANY_RIGHT );
336
0
    rBindings.Invalidate( SID_ALIGN_ANY_JUSTIFIED );
337
0
    rBindings.Invalidate( SID_ALIGN_ANY_VDEFAULT );
338
0
    rBindings.Invalidate( SID_ALIGN_ANY_TOP );
339
0
    rBindings.Invalidate( SID_ALIGN_ANY_VCENTER );
340
0
    rBindings.Invalidate( SID_ALIGN_ANY_BOTTOM );
341
342
0
    rBindings.Invalidate( SID_NUMBER_CURRENCY );
343
0
    rBindings.Invalidate( SID_NUMBER_SCIENTIFIC );
344
0
    rBindings.Invalidate( SID_NUMBER_DATE );
345
0
    rBindings.Invalidate( SID_NUMBER_CURRENCY );
346
0
    rBindings.Invalidate( SID_NUMBER_PERCENT );
347
0
    rBindings.Invalidate( SID_NUMBER_TWODEC );
348
0
    rBindings.Invalidate( SID_NUMBER_TIME );
349
0
    rBindings.Invalidate( SID_NUMBER_STANDARD );
350
0
    rBindings.Invalidate( SID_NUMBER_THOUSANDS );
351
0
}
352
353
namespace {
354
355
void collectUIInformation(std::map<OUString, OUString>&& aParameters)
356
0
{
357
0
    EventDescription aDescription;
358
0
    aDescription.aID = "grid_window";
359
0
    aDescription.aAction = "SELECT";
360
0
    aDescription.aParameters = std::move(aParameters);
361
0
    aDescription.aParent = "MainWindow";
362
0
    aDescription.aKeyWord = "ScGridWinUIObject";
363
364
0
    UITestLogger::getInstance().logEvent(aDescription);
365
0
}
366
367
}
368
369
// SetCursor - Cursor, set, draw, update InputWin
370
// or send reference
371
// Optimising breaks the functionality
372
373
void ScTabView::SetCursor( SCCOL nPosX, SCROW nPosY, bool bNew )
374
0
{
375
0
    SCCOL nOldX = aViewData.GetCurX();
376
0
    SCROW nOldY = aViewData.GetCurY();
377
378
    //  DeactivateIP only for MarkListHasChanged
379
380
    // FIXME: this is to limit the number of rows handled in the Online
381
    // to 1000; this will be removed again when the performance
382
    // bottlenecks are sorted out
383
0
    if (comphelper::LibreOfficeKit::isActive())
384
0
        nPosY = std::min(nPosY, MAXTILEDROW);
385
386
0
    if ( !(nPosX != nOldX || nPosY != nOldY || bNew) )
387
0
    {
388
0
        HighlightOverlay();
389
0
        return;
390
0
    }
391
392
0
    ScTabViewShell* pViewShell = aViewData.GetViewShell();
393
0
    bool bRefMode = pViewShell && pViewShell->IsRefInputMode();
394
0
    if ( aViewData.HasEditView( aViewData.GetActivePart() ) && !bRefMode ) // 23259 or so
395
0
    {
396
0
        UpdateInputLine();
397
0
    }
398
399
0
    HideAllCursors();
400
401
0
    aViewData.SetCurX( nPosX );
402
0
    aViewData.SetCurY( nPosY );
403
404
0
    ShowAllCursors();
405
406
0
    HighlightOverlay();
407
408
0
    CursorPosChanged();
409
410
0
    OUString aCurrAddress = ScAddress(nPosX,nPosY,0).GetColRowString();
411
0
    collectUIInformation({{"CELL", aCurrAddress}});
412
413
0
    if (!comphelper::LibreOfficeKit::isActive())
414
0
        return;
415
416
0
    if (nPosX <= aViewData.GetMaxTiledCol() - 10 && nPosY <= aViewData.GetMaxTiledRow() - 25)
417
0
        return;
418
419
0
    ScDocument& rDoc = aViewData.GetDocument();
420
0
    ScDocShell& rDocSh = aViewData.GetDocShell();
421
0
    ScModelObj* pModelObj = rDocSh.GetModel();
422
0
    Size aOldSize(0, 0);
423
0
    if (pModelObj)
424
0
        aOldSize = pModelObj->getDocumentSize();
425
426
0
    if (nPosX > aViewData.GetMaxTiledCol() - 10)
427
0
        aViewData.SetMaxTiledCol(std::min<SCCOL>(std::max(nPosX, aViewData.GetMaxTiledCol()) + 10, rDoc.MaxCol()));
428
429
0
    if (nPosY > aViewData.GetMaxTiledRow() - 25)
430
0
        aViewData.SetMaxTiledRow(std::min<SCROW>(std::max(nPosY, aViewData.GetMaxTiledRow()) + 25,  MAXTILEDROW));
431
432
0
    Size aNewSize(0, 0);
433
0
    if (pModelObj)
434
0
        aNewSize = pModelObj->getDocumentSize();
435
436
0
    if (pModelObj)
437
0
    {
438
0
        ScGridWindow* pGridWindow = aViewData.GetActiveWin();
439
0
        if (pGridWindow)
440
0
        {
441
0
            Size aNewSizePx(aNewSize.Width() * aViewData.GetPPTX(), aNewSize.Height() * aViewData.GetPPTY());
442
0
            if (aNewSizePx != pGridWindow->GetOutputSizePixel())
443
0
                pGridWindow->SetOutputSizePixel(aNewSizePx);
444
0
        }
445
0
    }
446
447
0
    if (aOldSize == aNewSize)
448
0
        return;
449
450
    // New area extended to the right of the sheet after last column
451
    // including overlapping area with aNewRowArea
452
0
    tools::Rectangle aNewColArea(aOldSize.getWidth(), 0, aNewSize.getWidth(), aNewSize.getHeight());
453
    // New area extended to the bottom of the sheet after last row
454
    // excluding overlapping area with aNewColArea
455
0
    tools::Rectangle aNewRowArea(0, aOldSize.getHeight(), aOldSize.getWidth(), aNewSize.getHeight());
456
457
    // Only invalidate if spreadsheet extended to the right
458
0
    if (aNewColArea.getOpenWidth())
459
0
    {
460
0
        SfxLokHelper::notifyInvalidation(aViewData.GetViewShell(), &aNewColArea);
461
0
    }
462
463
    // Only invalidate if spreadsheet extended to the bottom
464
0
    if (aNewRowArea.getOpenHeight())
465
0
    {
466
0
        SfxLokHelper::notifyInvalidation(aViewData.GetViewShell(), &aNewRowArea);
467
0
    }
468
469
    // Provide size in the payload, so clients don't have to
470
    // call lok::Document::getDocumentSize().
471
0
    std::stringstream ss;
472
0
    ss << aNewSize.Width() << ", " << aNewSize.Height();
473
0
    OString sSize( ss.str() );
474
0
    ScModelObj* pModel = comphelper::getFromUnoTunnel<ScModelObj>(aViewData.GetViewShell()->GetCurrentDocument());
475
0
    SfxLokHelper::notifyDocumentSizeChanged(aViewData.GetViewShell(), sSize, pModel, false);
476
0
}
477
478
static bool lcl_IsRefDlgActive(SfxViewFrame& rViewFrm)
479
0
{
480
0
    ScModule* pScMod = ScModule::get();
481
0
    if (!pScMod->IsRefDialogOpen())
482
0
       return false;
483
484
0
    auto nDlgId = pScMod->GetCurRefDlgId();
485
0
    if (!rViewFrm.HasChildWindow(nDlgId))
486
0
        return false;
487
488
0
    SfxChildWindow* pChild = rViewFrm.GetChildWindow(nDlgId);
489
0
    if (!pChild)
490
0
        return false;
491
492
0
    auto xDlgController = pChild->GetController();
493
0
    if (!xDlgController || !xDlgController->getDialog()->get_visible())
494
0
        return false;
495
496
0
    IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(xDlgController.get());
497
0
    return pRefDlg && pRefDlg->IsRefInputMode();
498
0
}
499
500
void ScTabView::CheckSelectionTransfer()
501
0
{
502
0
    if ( !aViewData.IsActive() )     // only for active view
503
0
        return;
504
505
0
    ScModule* pScMod = ScModule::get();
506
0
    ScSelectionTransferObj* pOld = pScMod->GetSelectionTransfer();
507
0
    rtl::Reference<ScSelectionTransferObj> pNew = ScSelectionTransferObj::CreateFromView( this );
508
0
    if ( !pNew )
509
0
        return;
510
511
    //  create new selection
512
513
0
    if (pOld)
514
0
        pOld->ForgetView();
515
516
0
    pScMod->SetSelectionTransfer( pNew.get() );
517
518
    // tdf#124975/tdf#136242 changing the calc selection can trigger removal of the
519
    // selection of an open RefDlg dialog, so don't inform the
520
    // desktop clipboard of the changed selection if that dialog is open
521
0
    if (!lcl_IsRefDlgActive(aViewData.GetViewShell()->GetViewFrame()))
522
0
        pNew->CopyToPrimarySelection();                    // may delete pOld
523
524
    // Log the selection change
525
0
    ScMarkData& rMark = aViewData.GetMarkData();
526
0
    if (rMark.IsMarked())
527
0
    {
528
0
        const ScRange& aMarkRange = rMark.GetMarkArea();
529
0
        OUString aStartAddress =  aMarkRange.aStart.GetColRowString();
530
0
        OUString aEndAddress = aMarkRange.aEnd.GetColRowString();
531
0
        collectUIInformation({{"RANGE", aStartAddress + ":" + aEndAddress}});
532
0
    }
533
0
}
534
535
// update input row / menus
536
// CursorPosChanged calls SelectionChanged
537
// SelectionChanged calls CellContentChanged
538
539
void ScTabView::CellContentChanged()
540
0
{
541
0
    SfxBindings& rBindings = aViewData.GetBindings();
542
543
0
    rBindings.Invalidate( SID_ATTR_SIZE );      // -> show error message
544
0
    rBindings.Invalidate( SID_THESAURUS );
545
0
    rBindings.Invalidate( SID_HYPERLINK_GETLINK );
546
0
    rBindings.Invalidate( SID_ROWCOL_SELCOUNT );
547
548
0
    InvalidateAttribs();                    // attributes updates
549
550
0
    aViewData.GetViewShell()->UpdateInputHandler();
551
0
}
552
553
void ScTabView::SetTabProtectionSymbol( SCTAB nTab, const bool bProtect )
554
0
{
555
0
    pTabControl->SetProtectionSymbol( static_cast<sal_uInt16>(nTab)+1, bProtect);
556
0
}
557
558
void ScTabView::SelectionChanged(bool bFromPaste)
559
0
{
560
0
    SfxViewFrame& rViewFrame = aViewData.GetViewShell()->GetViewFrame();
561
0
    uno::Reference<frame::XController> xController = rViewFrame.GetFrame().GetController();
562
0
    if (xController.is())
563
0
    {
564
0
        ScTabViewObj* pImp = dynamic_cast<ScTabViewObj*>( xController.get() );
565
0
        if (pImp)
566
0
            pImp->SelectionChanged();
567
0
    }
568
569
0
    UpdateAutoFillMark(bFromPaste);   // also calls CheckSelectionTransfer
570
571
0
    SfxBindings& rBindings = aViewData.GetBindings();
572
573
0
    rBindings.Invalidate( SID_CURRENTCELL );    // -> Navigator
574
0
    rBindings.Invalidate( SID_AUTO_FILTER );    // -> Menu
575
0
    rBindings.Invalidate( FID_NOTE_VISIBLE );
576
0
    rBindings.Invalidate( FID_SHOW_NOTE );
577
0
    rBindings.Invalidate( FID_HIDE_NOTE );
578
0
    rBindings.Invalidate( FID_SHOW_ALL_NOTES );
579
0
    rBindings.Invalidate( FID_HIDE_ALL_NOTES );
580
0
    rBindings.Invalidate( SID_TOGGLE_NOTES );
581
0
    rBindings.Invalidate( SID_DELETE_NOTE );
582
0
    rBindings.Invalidate( SID_ROWCOL_SELCOUNT );
583
584
        //  functions than may need to be disabled
585
586
0
    rBindings.Invalidate( FID_INS_ROWBRK );
587
0
    rBindings.Invalidate( FID_INS_COLBRK );
588
0
    rBindings.Invalidate( FID_DEL_ROWBRK );
589
0
    rBindings.Invalidate( FID_DEL_COLBRK );
590
0
    rBindings.Invalidate( FID_MERGE_ON );
591
0
    rBindings.Invalidate( FID_MERGE_OFF );
592
0
    rBindings.Invalidate( FID_MERGE_TOGGLE );
593
0
    rBindings.Invalidate( SID_AUTOFILTER_HIDE );
594
0
    rBindings.Invalidate( SID_UNFILTER );
595
0
    rBindings.Invalidate( SID_REIMPORT_DATA );
596
0
    rBindings.Invalidate( SID_REFRESH_DBAREA );
597
0
    rBindings.Invalidate( SID_OUTLINE_SHOW );
598
0
    rBindings.Invalidate( SID_OUTLINE_HIDE );
599
0
    rBindings.Invalidate( SID_OUTLINE_REMOVE );
600
0
    rBindings.Invalidate( FID_FILL_TO_BOTTOM );
601
0
    rBindings.Invalidate( FID_FILL_TO_RIGHT );
602
0
    rBindings.Invalidate( FID_FILL_TO_TOP );
603
0
    rBindings.Invalidate( FID_FILL_TO_LEFT );
604
0
    rBindings.Invalidate( FID_FILL_SERIES );
605
0
    rBindings.Invalidate( SID_SCENARIOS );
606
0
    rBindings.Invalidate( SID_AUTOFORMAT );
607
0
    rBindings.Invalidate( SID_OPENDLG_TABOP );
608
0
    rBindings.Invalidate( SID_DATA_SELECT );
609
610
0
    rBindings.Invalidate( SID_CUT );
611
0
    rBindings.Invalidate( SID_COPY );
612
0
    rBindings.Invalidate( SID_PASTE );
613
0
    rBindings.Invalidate( SID_PASTE_SPECIAL );
614
0
    rBindings.Invalidate( SID_PASTE_UNFORMATTED );
615
0
    rBindings.Invalidate( SID_COPYDELETE );
616
617
0
    rBindings.Invalidate( FID_INS_ROW );
618
0
    rBindings.Invalidate( FID_INS_COLUMN );
619
0
    rBindings.Invalidate( FID_INS_ROWS_BEFORE );
620
0
    rBindings.Invalidate( FID_INS_COLUMNS_BEFORE );
621
0
    rBindings.Invalidate( FID_INS_ROWS_AFTER );
622
0
    rBindings.Invalidate( FID_INS_COLUMNS_AFTER );
623
0
    rBindings.Invalidate( FID_INS_CELL );
624
0
    rBindings.Invalidate( FID_INS_CELLSDOWN );
625
0
    rBindings.Invalidate( FID_INS_CELLSRIGHT );
626
627
0
    rBindings.Invalidate( FID_CHG_COMMENT );
628
629
        // only due to  protect cell:
630
631
0
    rBindings.Invalidate( SID_CELL_FORMAT_RESET );
632
0
    rBindings.Invalidate( SID_DELETE );
633
0
    rBindings.Invalidate( SID_DELETE_CONTENTS );
634
0
    rBindings.Invalidate( FID_DELETE_CELL );
635
0
    rBindings.Invalidate( FID_CELL_FORMAT );
636
0
    rBindings.Invalidate( SID_ENABLE_HYPHENATION );
637
0
    rBindings.Invalidate( SID_INSERT_POSTIT );
638
0
    rBindings.Invalidate( SID_CHARMAP );
639
0
    rBindings.Invalidate( SID_OPENDLG_FUNCTION );
640
0
    rBindings.Invalidate( FID_VALIDATION );
641
0
    rBindings.Invalidate( SID_EXTERNAL_SOURCE );
642
0
    rBindings.Invalidate( SID_TEXT_TO_COLUMNS );
643
0
    rBindings.Invalidate( SID_SORT_ASCENDING );
644
0
    rBindings.Invalidate( SID_SORT_DESCENDING );
645
0
    rBindings.Invalidate( SID_SELECT_UNPROTECTED_CELLS );
646
0
    rBindings.Invalidate( SID_CLEAR_AUTO_FILTER );
647
0
    if (!comphelper::LibreOfficeKit::isActive())
648
0
        rBindings.Invalidate( SID_LANGUAGE_STATUS );
649
650
0
    if (aViewData.GetViewShell()->HasAccessibilityObjects())
651
0
        aViewData.GetViewShell()->BroadcastAccessibility(SfxHint(SfxHintId::ScAccCursorChanged));
652
653
0
    CellContentChanged();
654
0
}
655
656
void ScTabView::CursorPosChanged()
657
0
{
658
0
    bool bRefMode = ScModule::get()->IsFormulaMode();
659
0
    if ( !bRefMode ) // check that RefMode works when switching sheets
660
0
        aViewData.GetDocShell().Broadcast( SfxHint( SfxHintId::ScKillEditView ) );
661
662
    //  Broadcast, so that other Views of the document also switch
663
664
0
    ScDocument& rDocument = aViewData.GetDocument();
665
0
    bool bDataPilot = rDocument.HasDataPilotAtPosition(aViewData.GetCurPos());
666
0
    aViewData.GetViewShell()->SetPivotShell(bDataPilot);
667
668
0
    if (!bDataPilot)
669
0
    {
670
0
        bool bSparkline = rDocument.HasSparkline(aViewData.GetCurPos());
671
0
        aViewData.GetViewShell()->SetSparklineShell(bSparkline);
672
0
    }
673
674
    //  UpdateInputHandler now in CellContentChanged
675
676
0
    SelectionChanged();
677
678
0
    aViewData.SetTabStartCol( SC_TABSTART_NONE );
679
0
}
680
681
namespace {
682
683
Point calcHintWindowPosition(
684
    const Point& rCellPos, const Size& rCellSize, const Size& rFrameWndSize, const Size& rHintWndSize)
685
0
{
686
0
    const tools::Long nMargin = 20;
687
688
0
    tools::Long nMLeft = rCellPos.X();
689
0
    tools::Long nMRight = rFrameWndSize.Width() - rCellPos.X() - rCellSize.Width();
690
0
    tools::Long nMTop = rCellPos.Y();
691
0
    tools::Long nMBottom = rFrameWndSize.Height() - rCellPos.Y() - rCellSize.Height();
692
693
    // First, see if we can fit the entire hint window in the visible region.
694
695
0
    if (nMRight - nMargin >= rHintWndSize.Width())
696
0
    {
697
        // Right margin is wide enough.
698
0
        if (rFrameWndSize.Height() >= rHintWndSize.Height())
699
0
        {
700
            // The frame has enough height.  Take it.
701
0
            Point aPos = rCellPos;
702
0
            aPos.AdjustX(rCellSize.Width() + nMargin );
703
0
            if (aPos.Y() + rHintWndSize.Height() > rFrameWndSize.Height())
704
0
            {
705
                // Push the hint window up a bit to make it fit.
706
0
                aPos.setY( rFrameWndSize.Height() - rHintWndSize.Height() );
707
0
            }
708
0
            return aPos;
709
0
        }
710
0
    }
711
712
0
    if (nMBottom - nMargin >= rHintWndSize.Height())
713
0
    {
714
        // Bottom margin is high enough.
715
0
        if (rFrameWndSize.Width() >= rHintWndSize.Width())
716
0
        {
717
            // The frame has enough width.  Take it.
718
0
            Point aPos = rCellPos;
719
0
            aPos.AdjustY(rCellSize.Height() + nMargin );
720
0
            if (aPos.X() + rHintWndSize.Width() > rFrameWndSize.Width())
721
0
            {
722
                // Move the hint window to the left to make it fit.
723
0
                aPos.setX( rFrameWndSize.Width() - rHintWndSize.Width() );
724
0
            }
725
0
            return aPos;
726
0
        }
727
0
    }
728
729
0
    if (nMLeft - nMargin >= rHintWndSize.Width())
730
0
    {
731
        // Left margin is wide enough.
732
0
        if (rFrameWndSize.Height() >= rHintWndSize.Height())
733
0
        {
734
            // The frame is high enough.  Take it.
735
0
            Point aPos = rCellPos;
736
0
            aPos.AdjustX( -(rHintWndSize.Width() + nMargin) );
737
0
            if (aPos.Y() + rHintWndSize.Height() > rFrameWndSize.Height())
738
0
            {
739
                // Push the hint window up a bit to make it fit.
740
0
                aPos.setY( rFrameWndSize.Height() - rHintWndSize.Height() );
741
0
            }
742
0
            return aPos;
743
0
        }
744
0
    }
745
746
0
    if (nMTop - nMargin >= rHintWndSize.Height())
747
0
    {
748
        // Top margin is high enough.
749
0
        if (rFrameWndSize.Width() >= rHintWndSize.Width())
750
0
        {
751
            // The frame is wide enough.  Take it.
752
0
            Point aPos = rCellPos;
753
0
            aPos.AdjustY( -(rHintWndSize.Height() + nMargin) );
754
0
            if (aPos.X() + rHintWndSize.Width() > rFrameWndSize.Width())
755
0
            {
756
                // Move the hint window to the left to make it fit.
757
0
                aPos.setX( rFrameWndSize.Width() - rHintWndSize.Width() );
758
0
            }
759
0
            return aPos;
760
0
        }
761
0
    }
762
763
    // The popup doesn't fit in any direction in its entirety.  Do our best.
764
765
0
    if (nMRight - nMargin >= rHintWndSize.Width())
766
0
    {
767
        // Right margin is good enough.
768
0
        Point aPos = rCellPos;
769
0
        aPos.AdjustX(nMargin + rCellSize.Width() );
770
0
        aPos.setY( 0 );
771
0
        return aPos;
772
0
    }
773
774
0
    if (nMBottom - nMargin >= rHintWndSize.Height())
775
0
    {
776
        // Bottom margin is good enough.
777
0
        Point aPos = rCellPos;
778
0
        aPos.AdjustY(nMargin + rCellSize.Height() );
779
0
        aPos.setX( 0 );
780
0
        return aPos;
781
0
    }
782
783
0
    if (nMLeft - nMargin >= rHintWndSize.Width())
784
0
    {
785
        // Left margin is good enough.
786
0
        Point aPos = rCellPos;
787
0
        aPos.AdjustX( -(rHintWndSize.Width() + nMargin) );
788
0
        aPos.setY( 0 );
789
0
        return aPos;
790
0
    }
791
792
0
    if (nMTop - nMargin >= rHintWndSize.Height())
793
0
    {
794
        // Top margin is good enough.
795
0
        Point aPos = rCellPos;
796
0
        aPos.AdjustY( -(rHintWndSize.Height() + nMargin) );
797
0
        aPos.setX( 0 );
798
0
        return aPos;
799
0
    }
800
801
    // None of the above.  Hopeless.  At least try not to cover the current
802
    // cell.
803
0
    Point aPos = rCellPos;
804
0
    aPos.AdjustX(rCellSize.Width() );
805
0
    return aPos;
806
0
}
807
808
}
809
810
void ScTabView::TestHintWindow()
811
0
{
812
    //  show input help window and list drop-down button for validity
813
814
0
    mxInputHintOO.reset();
815
816
0
    bool bListValButton = false;
817
0
    ScAddress aListValPos;
818
819
0
    ScDocument& rDoc = aViewData.GetDocument();
820
0
    const SfxUInt32Item* pItem = rDoc.GetAttr( aViewData.GetCurX(),
821
0
                                               aViewData.GetCurY(),
822
0
                                               aViewData.CurrentTabForData(),
823
0
                                               ATTR_VALIDDATA );
824
0
    if ( pItem->GetValue() )
825
0
    {
826
0
        const ScValidationData* pData = rDoc.GetValidationEntry( pItem->GetValue() );
827
0
        OSL_ENSURE(pData,"ValidationData not found");
828
0
        OUString aTitle, aMessage;
829
830
0
        if ( pData && pData->GetInput( aTitle, aMessage ) && !aMessage.isEmpty() )
831
0
        {
832
0
            ScSplitPos eWhich = aViewData.GetActivePart();
833
0
            ScGridWindow* pWin = pGridWin[eWhich].get();
834
0
            SCCOL nCol = aViewData.GetCurX();
835
0
            SCROW nRow = aViewData.GetCurY();
836
0
            Point aPos = aViewData.GetScrPos( nCol, nRow, eWhich );
837
0
            Size aWinSize = pWin->GetOutputSizePixel();
838
            // cursor visible?
839
0
            if ( nCol >= aViewData.GetPosX(WhichH(eWhich)) &&
840
0
                 nRow >= aViewData.GetPosY(WhichV(eWhich)) &&
841
0
                 aPos.X() < aWinSize.Width() && aPos.Y() < aWinSize.Height() )
842
0
            {
843
0
                const svtools::ColorConfig& rColorCfg = ScModule::get()->GetColorConfig();
844
                // tdf#156398 use same color combination as used in XclDefaultPalette
845
0
                Color aCommentText = rColorCfg.GetColorValue(svtools::FONTCOLOR).nColor;
846
0
                Color aCommentBack = rColorCfg.GetColorValue(svtools::CALCNOTESBACKGROUND).nColor;
847
                // create HintWindow, determines its size by itself
848
0
                ScOverlayHint* pOverlay = new ScOverlayHint(aTitle, aMessage,
849
0
                                                            aCommentBack, aCommentText,
850
0
                                                            pFrameWin->GetFont());
851
852
0
                mxInputHintOO.reset(new sdr::overlay::OverlayObjectList);
853
0
                mxInputHintOO->append(std::unique_ptr<sdr::overlay::OverlayObject>(pOverlay));
854
855
0
                Size aHintWndSize = pOverlay->GetSizePixel();
856
0
                tools::Long nCellSizeX = 0;
857
0
                tools::Long nCellSizeY = 0;
858
0
                aViewData.GetMergeSizePixel(nCol, nRow, nCellSizeX, nCellSizeY);
859
860
0
                Point aHintPos = calcHintWindowPosition(
861
0
                    aPos, Size(nCellSizeX,nCellSizeY), aWinSize, aHintWndSize);
862
863
0
                pOverlay->SetPos(pWin->PixelToLogic(aHintPos, pWin->GetDrawMapMode()), pWin->GetDrawMapMode());
864
0
                for (VclPtr<ScGridWindow> & pWindow : pGridWin)
865
0
                {
866
0
                    if (!pWindow)
867
0
                        continue;
868
0
                    if (!pWindow->IsVisible())
869
0
                        continue;
870
0
                    rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = pWindow->getOverlayManager();
871
0
                    if (!xOverlayManager.is())
872
0
                        continue;
873
0
                    if (pWindow == pWin)
874
0
                    {
875
0
                        xOverlayManager->add(*pOverlay);
876
0
                        pWindow->updateLOKInputHelp(aTitle, aMessage);
877
0
                    }
878
0
                    else
879
0
                    {
880
                        //tdf#92530 if the help tip doesn't fit into its allocated area in a split window
881
                        //scenario, then because here we place it into the other split windows as well the
882
                        //missing portions will be displayed in the other split windows to form an apparent
883
                        //single tip, albeit "under" the split lines
884
0
                        Point aOtherPos(pWindow->ScreenToOutputPixel(pWin->OutputToScreenPixel(aHintPos)));
885
0
                        std::unique_ptr<ScOverlayHint> pOtherOverlay(new ScOverlayHint(aTitle, aMessage,
886
0
                                                                                       aCommentBack,
887
0
                                                                                       aCommentText,
888
0
                                                                                       pFrameWin->GetFont()));
889
0
                        Point aFooPos(pWindow->PixelToLogic(aOtherPos, pWindow->GetDrawMapMode()));
890
0
                        pOtherOverlay->SetPos(aFooPos, pWindow->GetDrawMapMode());
891
0
                        xOverlayManager->add(*pOtherOverlay);
892
0
                        mxInputHintOO->append(std::move(pOtherOverlay));
893
0
                    }
894
0
                }
895
0
            }
896
0
        }
897
898
        // list drop-down button
899
0
        if ( pData && pData->HasSelectionList() )
900
0
        {
901
0
            aListValPos.Set( aViewData.GetCurX(), aViewData.GetCurY(), aViewData.CurrentTabForData() );
902
0
            bListValButton = true;
903
0
        }
904
0
    }
905
906
0
    for (VclPtr<ScGridWindow> const & pWin : pGridWin)
907
0
    {
908
0
        if (pWin && pWin->IsVisible())
909
0
            pWin->UpdateListValPos(bListValButton, aListValPos);
910
0
    }
911
0
}
912
913
0
bool ScTabView::HasHintWindow() const { return mxInputHintOO != nullptr; }
914
915
void ScTabView::RemoveHintWindow()
916
0
{
917
0
    mxInputHintOO.reset();
918
0
}
919
920
// find window that should not be over the cursor
921
static weld::Window* lcl_GetCareWin(SfxViewFrame& rViewFrm)
922
0
{
923
    //! also spelling ??? (then set the member variables when calling)
924
925
    // search & replace
926
0
    if (rViewFrm.HasChildWindow(SID_SEARCH_DLG))
927
0
    {
928
0
        SfxChildWindow* pChild = rViewFrm.GetChildWindow(SID_SEARCH_DLG);
929
0
        if (pChild)
930
0
        {
931
0
            auto xDlgController = pChild->GetController();
932
0
            if (xDlgController && xDlgController->getDialog()->get_visible())
933
0
                return xDlgController->getDialog();
934
0
        }
935
0
    }
936
937
    // apply changes
938
0
    if ( rViewFrm.HasChildWindow(FID_CHG_ACCEPT) )
939
0
    {
940
0
        SfxChildWindow* pChild = rViewFrm.GetChildWindow(FID_CHG_ACCEPT);
941
0
        if (pChild)
942
0
        {
943
0
            auto xDlgController = pChild->GetController();
944
0
            if (xDlgController && xDlgController->getDialog()->get_visible())
945
0
                return xDlgController->getDialog();
946
0
        }
947
0
    }
948
949
0
    return nullptr;
950
0
}
951
952
    // adjust screen with respect to cursor position
953
954
void ScTabView::AlignToCursor( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
955
                                const ScSplitPos* pWhich )
956
0
{
957
    // now switch active part here
958
959
0
    ScSplitPos eActive = aViewData.GetActivePart();
960
0
    ScHSplitPos eActiveX = WhichH(eActive);
961
0
    ScVSplitPos eActiveY = WhichV(eActive);
962
0
    bool bHFix = (aViewData.GetHSplitMode() == SC_SPLIT_FIX);
963
0
    bool bVFix = (aViewData.GetVSplitMode() == SC_SPLIT_FIX);
964
0
    if (bHFix && eActiveX == SC_SPLIT_LEFT && nCurX >= aViewData.GetFixPosX())
965
0
    {
966
0
        ActivatePart( (eActiveY==SC_SPLIT_TOP) ? SC_SPLIT_TOPRIGHT : SC_SPLIT_BOTTOMRIGHT );
967
0
        eActiveX = SC_SPLIT_RIGHT;
968
0
    }
969
0
    if (bVFix && eActiveY == SC_SPLIT_TOP && nCurY >= aViewData.GetFixPosY())
970
0
    {
971
0
        ActivatePart( (eActiveX==SC_SPLIT_LEFT) ? SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT );
972
0
        eActiveY = SC_SPLIT_BOTTOM;
973
0
    }
974
975
    // actual align
976
977
0
    if ( eMode != SC_FOLLOW_NONE )
978
0
    {
979
0
        ScSplitPos eAlign;
980
0
        if (pWhich)
981
0
            eAlign = *pWhich;
982
0
        else
983
0
            eAlign = aViewData.GetActivePart();
984
0
        ScHSplitPos eAlignX = WhichH(eAlign);
985
0
        ScVSplitPos eAlignY = WhichV(eAlign);
986
987
0
        SCCOL nDeltaX = aViewData.GetPosX(eAlignX);
988
0
        SCROW nDeltaY = aViewData.GetPosY(eAlignY);
989
0
        SCCOL nSizeX = aViewData.VisibleCellsX(eAlignX);
990
0
        SCROW nSizeY = aViewData.VisibleCellsY(eAlignY);
991
992
0
        tools::Long nCellSizeX;
993
0
        tools::Long nCellSizeY;
994
0
        if ( nCurX >= 0 && nCurY >= 0 )
995
0
            aViewData.GetMergeSizePixel( nCurX, nCurY, nCellSizeX, nCellSizeY );
996
0
        else
997
0
            nCellSizeX = nCellSizeY = 0;
998
0
        Size aScrSize = aViewData.GetScrSize();
999
1000
0
        tools::Long nDenom;
1001
0
        if ( eMode == SC_FOLLOW_JUMP_END && nCurX > aViewData.GetRefStartX()
1002
0
            && nCurY > aViewData.GetRefStartY() )
1003
0
            nDenom = 1; // tdf#154271 Selected cell will be at the bottom corner
1004
                        // to maximize the visible/usable area
1005
0
        else
1006
0
            nDenom = 2; // Selected cell will be at the center of the screen, so that
1007
                        // it will be visible. This is useful for search results, etc.
1008
0
        tools::Long nSpaceX = ( aScrSize.Width()  - nCellSizeX ) / nDenom;
1009
0
        tools::Long nSpaceY = ( aScrSize.Height() - nCellSizeY ) / nDenom;
1010
        //  nSpaceY: desired start position of cell for FOLLOW_JUMP, modified if dialog interferes
1011
1012
0
        bool bForceNew = false;     // force new calculation of JUMP position (vertical only)
1013
1014
        // VisibleCellsY == CellsAtY( GetPosY( eWhichY ), 1, eWhichY )
1015
1016
        // when for instance a search dialog is open, don't put the cursor behind the dialog
1017
        // if possible, put the row with the cursor above or below the dialog
1018
        //! not if already completely visible
1019
1020
0
        if ( eMode == SC_FOLLOW_JUMP || eMode == SC_FOLLOW_JUMP_END )
1021
0
        {
1022
0
            weld::Window* pCare = lcl_GetCareWin( aViewData.GetViewShell()->GetViewFrame() );
1023
0
            if (pCare)
1024
0
            {
1025
0
                bool bLimit = false;
1026
0
                tools::Rectangle aDlgPixel;
1027
0
                Size aWinSize;
1028
0
                vcl::Window* pWin = GetActiveWin();
1029
0
                weld::Window* pFrame = pWin ? pWin->GetFrameWeld() : nullptr;
1030
0
                int x, y, width, height;
1031
0
                if (pFrame && pCare->get_extents_relative_to(*pFrame, x, y, width, height))
1032
0
                {
1033
0
                    aDlgPixel = tools::Rectangle(Point(x, y), Size(width, height));
1034
0
                    aWinSize = pWin->GetOutputSizePixel();
1035
                    // dos the dialog cover the GridWin?
1036
0
                    if ( aDlgPixel.Right() >= 0 && aDlgPixel.Left() < aWinSize.Width() )
1037
0
                    {
1038
0
                        if ( nCurX < nDeltaX || nCurX >= nDeltaX+nSizeX ||
1039
0
                             nCurY < nDeltaY || nCurY >= nDeltaY+nSizeY )
1040
0
                            bLimit = true;          // scroll anyway
1041
0
                        else
1042
0
                        {
1043
                            // cursor is on the screen
1044
0
                            Point aStart = aViewData.GetScrPos( nCurX, nCurY, eAlign );
1045
0
                            tools::Long nCSX, nCSY;
1046
0
                            aViewData.GetMergeSizePixel( nCurX, nCurY, nCSX, nCSY );
1047
0
                            tools::Rectangle aCursor( aStart, Size( nCSX, nCSY ) );
1048
0
                            if ( aCursor.Overlaps( aDlgPixel ) )
1049
0
                                bLimit = true;      // cell is covered by the dialog
1050
0
                        }
1051
0
                    }
1052
0
                }
1053
1054
0
                if (bLimit)
1055
0
                {
1056
0
                    bool bBottom = false;
1057
0
                    tools::Long nTopSpace = aDlgPixel.Top();
1058
0
                    tools::Long nBotSpace = aWinSize.Height() - aDlgPixel.Bottom();
1059
0
                    if ( nBotSpace > 0 && nBotSpace > nTopSpace )
1060
0
                    {
1061
0
                        tools::Long nDlgBot = aDlgPixel.Bottom();
1062
0
                        SCCOL nWPosX;
1063
0
                        SCROW nWPosY;
1064
0
                        aViewData.GetPosFromPixel( 0,nDlgBot, eAlign, nWPosX, nWPosY );
1065
0
                        ++nWPosY;   // below the last affected cell
1066
1067
0
                        SCROW nDiff = nWPosY - nDeltaY;
1068
0
                        if ( nCurY >= nDiff )           // position can not be negative
1069
0
                        {
1070
0
                            nSpaceY = nDlgBot + ( nBotSpace - nCellSizeY ) / 2;
1071
0
                            bBottom = true;
1072
0
                            bForceNew = true;
1073
0
                        }
1074
0
                    }
1075
0
                    if ( !bBottom && nTopSpace > 0 )
1076
0
                    {
1077
0
                        nSpaceY = ( nTopSpace - nCellSizeY ) / 2;
1078
0
                        bForceNew = true;
1079
0
                    }
1080
0
                }
1081
0
            }
1082
0
        }
1083
1084
0
        SCCOL nNewDeltaX = nDeltaX;
1085
0
        SCROW nNewDeltaY = nDeltaY;
1086
0
        bool bDoLine = false;
1087
1088
0
        switch (eMode)
1089
0
        {
1090
0
            case SC_FOLLOW_JUMP:
1091
0
            case SC_FOLLOW_JUMP_END:
1092
0
                if ( nCurX < nDeltaX || nCurX >= nDeltaX+nSizeX )
1093
0
                {
1094
0
                    nNewDeltaX = nCurX - aViewData.CellsAtX( nCurX, -1, eAlignX, nSpaceX );
1095
0
                    if (nNewDeltaX < 0)
1096
0
                        nNewDeltaX = 0;
1097
0
                    nSizeX = aViewData.CellsAtX( nNewDeltaX, 1, eAlignX );
1098
0
                }
1099
0
                if ( nCurY < nDeltaY || nCurY >= nDeltaY+nSizeY || bForceNew )
1100
0
                {
1101
0
                    nNewDeltaY = nCurY - aViewData.CellsAtY( nCurY, -1, eAlignY, nSpaceY );
1102
0
                    if (nNewDeltaY < 0)
1103
0
                        nNewDeltaY = 0;
1104
0
                    nSizeY = aViewData.CellsAtY( nNewDeltaY, 1, eAlignY );
1105
0
                }
1106
0
                bDoLine = true;
1107
0
                break;
1108
1109
0
            case SC_FOLLOW_LINE:
1110
0
                bDoLine = true;
1111
0
                break;
1112
1113
0
            case SC_FOLLOW_FIX:
1114
0
                if ( nCurX < nDeltaX || nCurX >= nDeltaX+nSizeX )
1115
0
                {
1116
0
                    nNewDeltaX = nDeltaX + nCurX - aViewData.GetCurX();
1117
0
                    if (nNewDeltaX < 0)
1118
0
                        nNewDeltaX = 0;
1119
0
                    nSizeX = aViewData.CellsAtX( nNewDeltaX, 1, eAlignX );
1120
0
                }
1121
0
                if ( nCurY < nDeltaY || nCurY >= nDeltaY+nSizeY )
1122
0
                {
1123
0
                    nNewDeltaY = nDeltaY + nCurY - aViewData.GetCurY();
1124
0
                    if (nNewDeltaY < 0)
1125
0
                        nNewDeltaY = 0;
1126
0
                    nSizeY = aViewData.CellsAtY( nNewDeltaY, 1, eAlignY );
1127
0
                }
1128
1129
                //  like old version of SC_FOLLOW_JUMP:
1130
1131
0
                if ( nCurX < nNewDeltaX || nCurX >= nNewDeltaX+nSizeX )
1132
0
                {
1133
0
                    nNewDeltaX = nCurX - (nSizeX / 2);
1134
0
                    if (nNewDeltaX < 0)
1135
0
                        nNewDeltaX = 0;
1136
0
                    nSizeX = aViewData.CellsAtX( nNewDeltaX, 1, eAlignX );
1137
0
                }
1138
0
                if ( nCurY < nNewDeltaY || nCurY >= nNewDeltaY+nSizeY )
1139
0
                {
1140
0
                    nNewDeltaY = nCurY - (nSizeY / 2);
1141
0
                    if (nNewDeltaY < 0)
1142
0
                        nNewDeltaY = 0;
1143
0
                    nSizeY = aViewData.CellsAtY( nNewDeltaY, 1, eAlignY );
1144
0
                }
1145
1146
0
                bDoLine = true;
1147
0
                break;
1148
1149
0
            case SC_FOLLOW_NONE:
1150
0
                break;
1151
0
            default:
1152
0
                OSL_FAIL("Wrong cursor mode");
1153
0
                break;
1154
0
        }
1155
1156
0
        ScDocument& rDoc = aViewData.GetDocument();
1157
0
        if (bDoLine)
1158
0
        {
1159
0
            while ( nCurX >= nNewDeltaX+nSizeX )
1160
0
            {
1161
0
                nNewDeltaX = nCurX-nSizeX+1;
1162
0
                SCTAB nTab = aViewData.CurrentTabForData();
1163
0
                while ( nNewDeltaX < rDoc.MaxCol() && !rDoc.GetColWidth( nNewDeltaX, nTab ) )
1164
0
                    ++nNewDeltaX;
1165
0
                nSizeX = aViewData.CellsAtX( nNewDeltaX, 1, eAlignX );
1166
0
            }
1167
0
            while ( nCurY >= nNewDeltaY+nSizeY )
1168
0
            {
1169
0
                nNewDeltaY = nCurY-nSizeY+1;
1170
0
                SCTAB nTab = aViewData.CurrentTabForData();
1171
0
                while ( nNewDeltaY < rDoc.MaxRow() && !rDoc.GetRowHeight( nNewDeltaY, nTab ) )
1172
0
                    ++nNewDeltaY;
1173
0
                nSizeY = aViewData.CellsAtY( nNewDeltaY, 1, eAlignY );
1174
0
            }
1175
0
            if ( nCurX < nNewDeltaX )
1176
0
                nNewDeltaX = nCurX;
1177
0
            if ( nCurY < nNewDeltaY )
1178
0
                nNewDeltaY = nCurY;
1179
0
        }
1180
1181
0
        if ( nNewDeltaX != nDeltaX )
1182
0
            nSizeX = aViewData.CellsAtX( nNewDeltaX, 1, eAlignX );
1183
0
        if (nNewDeltaX+nSizeX-1 > rDoc.MaxCol())
1184
0
            nNewDeltaX = rDoc.MaxCol()-nSizeX+1;
1185
0
        if (nNewDeltaX < 0)
1186
0
            nNewDeltaX = 0;
1187
1188
0
        if ( nNewDeltaY != nDeltaY )
1189
0
            nSizeY = aViewData.CellsAtY( nNewDeltaY, 1, eAlignY );
1190
0
        if (nNewDeltaY+nSizeY-1 > rDoc.MaxRow())
1191
0
            nNewDeltaY = rDoc.MaxRow()-nSizeY+1;
1192
0
        if (nNewDeltaY < 0)
1193
0
            nNewDeltaY = 0;
1194
1195
0
        if ( nNewDeltaX != nDeltaX )
1196
0
            ScrollX( nNewDeltaX - nDeltaX, eAlignX );
1197
0
        if ( nNewDeltaY != nDeltaY )
1198
0
            ScrollY( nNewDeltaY - nDeltaY, eAlignY );
1199
0
    }
1200
1201
    // switch active part again
1202
1203
0
    if (bHFix)
1204
0
        if (eActiveX == SC_SPLIT_RIGHT && nCurX < aViewData.GetFixPosX())
1205
0
        {
1206
0
            ActivatePart( (eActiveY==SC_SPLIT_TOP) ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT );
1207
0
            eActiveX = SC_SPLIT_LEFT;
1208
0
        }
1209
0
    if (bVFix)
1210
0
        if (eActiveY == SC_SPLIT_BOTTOM && nCurY < aViewData.GetFixPosY())
1211
0
        {
1212
0
            ActivatePart( (eActiveX==SC_SPLIT_LEFT) ? SC_SPLIT_TOPLEFT : SC_SPLIT_TOPRIGHT );
1213
0
        }
1214
0
}
1215
1216
bool ScTabView::SelMouseButtonDown( const MouseEvent& rMEvt )
1217
0
{
1218
0
    bool bRet = false;
1219
1220
    // #i3875# *Hack*
1221
0
    bool bMod1Locked = (aViewData.GetViewShell()->GetLockedModifiers() & KEY_MOD1) != 0;
1222
0
    aViewData.SetSelCtrlMouseClick( rMEvt.IsMod1() || bMod1Locked );
1223
1224
0
    if ( pSelEngine )
1225
0
    {
1226
0
        bMoveIsShift = rMEvt.IsShift();
1227
0
        bRet = pSelEngine->SelMouseButtonDown( rMEvt );
1228
0
        bMoveIsShift = false;
1229
0
    }
1230
1231
0
    aViewData.SetSelCtrlMouseClick( false ); // #i3875# *Hack*
1232
1233
0
    return bRet;
1234
0
}
1235
1236
    //  MoveCursor - with adjustment of the view section
1237
1238
void ScTabView::MoveCursorAbs( SCCOL nCurX, SCROW nCurY, ScFollowMode eMode,
1239
                               bool bShift, bool bControl, bool bKeepOld, bool bKeepSel )
1240
0
{
1241
0
    if (!bKeepOld)
1242
0
        aViewData.ResetOldCursor();
1243
1244
0
    ScDocument& rDoc = aViewData.GetDocument();
1245
    // #i123629#
1246
0
    if( aViewData.GetViewShell()->GetForceFocusOnCurCell() )
1247
0
        aViewData.GetViewShell()->SetForceFocusOnCurCell( !rDoc.ValidColRow(nCurX, nCurY) );
1248
1249
0
    if (nCurX < 0) nCurX = 0;
1250
0
    if (nCurY < 0) nCurY = 0;
1251
0
    if (nCurX > rDoc.MaxCol()) nCurX = rDoc.MaxCol();
1252
0
    if (nCurY > rDoc.MaxRow()) nCurY = rDoc.MaxRow();
1253
1254
    // FIXME: this is to limit the number of rows handled in the Online
1255
    // to 1000; this will be removed again when the performance
1256
    // bottlenecks are sorted out
1257
0
    if (comphelper::LibreOfficeKit::isActive())
1258
0
        nCurY = std::min(nCurY, MAXTILEDROW);
1259
1260
0
    HideAllCursors();
1261
1262
    // switch of active now in AlignToCursor
1263
1264
0
    AlignToCursor( nCurX, nCurY, eMode );
1265
1266
0
    if (bKeepSel)
1267
0
    {
1268
0
        SetCursor( nCurX, nCurY );      // keep selection
1269
1270
        // If the cursor is in existing selection, it's a cursor movement by
1271
        // ENTER or TAB.  If not, then it's a new selection during ADD
1272
        // selection mode.
1273
1274
0
        const ScMarkData& rMark = aViewData.GetMarkData();
1275
0
        ScRangeList aSelList;
1276
0
        rMark.FillRangeListWithMarks(&aSelList, false);
1277
0
        if (!aSelList.Contains(ScRange(nCurX, nCurY, aViewData.CurrentTabForData())))
1278
            // Cursor not in existing selection.  Start a new selection.
1279
0
            DoneBlockMode(true);
1280
0
    }
1281
0
    else
1282
0
    {
1283
0
        if (!bShift)
1284
0
        {
1285
            // Remove all marked data on cursor movement unless the Shift is
1286
            // locked or while editing a formula. It is cheaper to check for
1287
            // marks first and then formula mode.
1288
0
            ScMarkData& rMark = aViewData.GetMarkData();
1289
0
            bool bMarked = rMark.IsMarked() || rMark.IsMultiMarked();
1290
0
            if (bMarked && !ScModule::get()->IsFormulaMode())
1291
0
            {
1292
0
                rMark.ResetMark();
1293
0
                DoneBlockMode();
1294
0
                InitOwnBlockMode( ScRange( nCurX, nCurY, aViewData.CurrentTabForData()));
1295
0
                MarkDataChanged();
1296
0
            }
1297
0
        }
1298
1299
0
        bool bSame = ( nCurX == aViewData.GetCurX() && nCurY == aViewData.GetCurY() );
1300
0
        bMoveIsShift = bShift;
1301
0
        pSelEngine->CursorPosChanging( bShift, bControl );
1302
0
        bMoveIsShift = false;
1303
0
        aFunctionSet.SetCursorAtCell( nCurX, nCurY, false );
1304
1305
        // If the cursor has not been moved, the SelectionChanged for canceling the
1306
        // selection has to happen here individually:
1307
0
        if (bSame)
1308
0
            SelectionChanged();
1309
0
    }
1310
1311
0
    ShowAllCursors();
1312
0
    TestHintWindow();
1313
0
}
1314
1315
void ScTabView::MoveCursorRel( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode,
1316
                               bool bShift, bool bKeepSel )
1317
0
{
1318
0
    ScDocument& rDoc = aViewData.GetDocument();
1319
0
    SCTAB nTab = aViewData.CurrentTabForData();
1320
1321
0
    bool bSkipProtected = false, bSkipUnprotected = false;
1322
0
    const ScTableProtection* pProtect = rDoc.GetTabProtection(nTab);
1323
0
    if ( pProtect && pProtect->isProtected() )
1324
0
    {
1325
0
        bSkipProtected   = !pProtect->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS);
1326
0
        bSkipUnprotected = !pProtect->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS);
1327
0
    }
1328
1329
0
    if ( bSkipProtected && bSkipUnprotected )
1330
0
        return;
1331
1332
0
    SCCOL nOldX;
1333
0
    SCROW nOldY;
1334
0
    SCCOL nCurX;
1335
0
    SCROW nCurY;
1336
0
    if ( aViewData.IsRefMode() )
1337
0
    {
1338
0
        nOldX = aViewData.GetRefEndX();
1339
0
        nOldY = aViewData.GetRefEndY();
1340
0
        nCurX = nOldX + nMovX;
1341
0
        nCurY = nOldY + nMovY;
1342
0
    }
1343
0
    else
1344
0
    {
1345
0
        nOldX = aViewData.GetCurX();
1346
0
        nOldY = aViewData.GetCurY();
1347
0
        nCurX = (nMovX != 0) ? nOldX+nMovX : aViewData.GetOldCurX();
1348
0
        nCurY = (nMovY != 0) ? nOldY+nMovY : aViewData.GetOldCurY();
1349
0
    }
1350
1351
0
    if (nMovX < 0 && nOldX == 0)
1352
0
    { // trying to go left from 1st column
1353
0
        if (nMovY == 0) // done, because no vertical move is requested
1354
0
            return;
1355
0
    }
1356
0
    if (nMovY < 0 && nOldY == 0)
1357
0
    { // trying to go up from 1st row
1358
0
        if (nMovX == 0) // done, because no horizontal move is requested
1359
0
            return;
1360
0
    }
1361
1362
0
    aViewData.ResetOldCursor();
1363
1364
0
    if (nMovX != 0 && rDoc.ValidColRow(nCurX,nCurY))
1365
0
        SkipCursorHorizontal(nCurX, nCurY, nOldX, nMovX);
1366
1367
0
    if (nMovY != 0 && rDoc.ValidColRow(nCurX,nCurY))
1368
0
        SkipCursorVertical(nCurX, nCurY, nOldY, nMovY);
1369
1370
0
    MoveCursorAbs( nCurX, nCurY, eMode, bShift, false, true, bKeepSel );
1371
0
}
1372
1373
void ScTabView::MoveCursorPage( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift, bool bKeepSel )
1374
0
{
1375
0
    SCCOL nPageX;
1376
0
    SCROW nPageY;
1377
0
    GetPageMoveEndPosition(nMovX, nMovY, nPageX, nPageY);
1378
0
    MoveCursorRel( nPageX, nPageY, eMode, bShift, bKeepSel );
1379
0
}
1380
1381
void ScTabView::MoveCursorArea( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift, bool bKeepSel, bool bInteractiveByUser )
1382
0
{
1383
0
    SCCOL nNewX;
1384
0
    SCROW nNewY;
1385
0
    GetAreaMoveEndPosition(nMovX, nMovY, eMode, nNewX, nNewY, eMode, bInteractiveByUser);
1386
0
    MoveCursorRel(nNewX, nNewY, eMode, bShift, bKeepSel);
1387
0
}
1388
1389
void ScTabView::MoveCursorEnd( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift, bool bKeepSel )
1390
0
{
1391
0
    ScDocument& rDoc = aViewData.GetDocument();
1392
0
    SCTAB nTab = aViewData.CurrentTabForData();
1393
1394
0
    SCCOL nCurX;
1395
0
    SCROW nCurY;
1396
0
    aViewData.GetMoveCursor( nCurX,nCurY );
1397
0
    SCCOL nNewX = nCurX;
1398
0
    SCROW nNewY = nCurY;
1399
1400
0
    SCCOL nUsedX = 0;
1401
0
    SCROW nUsedY = 0;
1402
0
    if ( nMovX > 0 || nMovY > 0 )
1403
0
        rDoc.GetPrintArea( nTab, nUsedX, nUsedY );     // get end
1404
1405
0
    if (nMovX<0)
1406
0
        nNewX=0;
1407
0
    else if (nMovX>0)
1408
0
        nNewX=nUsedX;                                   // last used range
1409
1410
0
    if (nMovY<0)
1411
0
        nNewY=0;
1412
0
    else if (nMovY>0)
1413
0
        nNewY=nUsedY;
1414
1415
0
    aViewData.ResetOldCursor();
1416
0
    MoveCursorRel( nNewX-nCurX, nNewY-nCurY, eMode, bShift, bKeepSel );
1417
0
}
1418
1419
void ScTabView::MoveCursorScreen( SCCOL nMovX, SCROW nMovY, ScFollowMode eMode, bool bShift )
1420
0
{
1421
0
    ScDocument& rDoc = aViewData.GetDocument();
1422
0
    SCTAB nTab = aViewData.CurrentTabForData();
1423
1424
0
    SCCOL nCurX;
1425
0
    SCROW nCurY;
1426
0
    aViewData.GetMoveCursor( nCurX,nCurY );
1427
0
    SCCOL nNewX = nCurX;
1428
0
    SCROW nNewY = nCurY;
1429
1430
0
    ScSplitPos eWhich = aViewData.GetActivePart();
1431
0
    SCCOL nPosX = aViewData.GetPosX( WhichH(eWhich) );
1432
0
    SCROW nPosY = aViewData.GetPosY( WhichV(eWhich) );
1433
1434
0
    SCCOL nAddX = aViewData.VisibleCellsX( WhichH(eWhich) );
1435
0
    if (nAddX != 0)
1436
0
        --nAddX;
1437
0
    SCROW nAddY = aViewData.VisibleCellsY( WhichV(eWhich) );
1438
0
    if (nAddY != 0)
1439
0
        --nAddY;
1440
1441
0
    if (nMovX<0)
1442
0
        nNewX=nPosX;
1443
0
    else if (nMovX>0)
1444
0
        nNewX=nPosX+nAddX;
1445
1446
0
    if (nMovY<0)
1447
0
        nNewY=nPosY;
1448
0
    else if (nMovY>0)
1449
0
        nNewY=nPosY+nAddY;
1450
1451
0
    aViewData.SetOldCursor( nNewX,nNewY );
1452
0
    rDoc.SkipOverlapped(nNewX, nNewY, nTab);
1453
0
    MoveCursorAbs( nNewX, nNewY, eMode, bShift, false, true );
1454
0
}
1455
1456
void ScTabView::MoveCursorEnter( bool bShift )          // bShift -> up/down
1457
0
{
1458
0
    const ScInputOptions& rOpt = ScModule::get()->GetInputOptions();
1459
0
    if (!rOpt.GetMoveSelection())
1460
0
    {
1461
0
        aViewData.UpdateInputHandler(true);
1462
0
        return;
1463
0
    }
1464
1465
0
    SCCOL nMoveX = 0;
1466
0
    SCROW nMoveY = 0;
1467
0
    switch (static_cast<ScDirection>(rOpt.GetMoveDir()))
1468
0
    {
1469
0
        case DIR_BOTTOM:
1470
0
            nMoveY = bShift ? -1 : 1;
1471
0
            break;
1472
0
        case DIR_RIGHT:
1473
0
            nMoveX = bShift ? -1 : 1;
1474
0
            break;
1475
0
        case DIR_TOP:
1476
0
            nMoveY = bShift ? 1 : -1;
1477
0
            break;
1478
0
        case DIR_LEFT:
1479
0
            nMoveX = bShift ? 1 : -1;
1480
0
            break;
1481
0
    }
1482
1483
0
    SCCOL nCurX;
1484
0
    SCROW nCurY;
1485
0
    aViewData.GetMoveCursor( nCurX,nCurY );
1486
0
    SCCOL nNewX = nCurX;
1487
0
    SCROW nNewY = nCurY;
1488
0
    SCTAB nTab  = aViewData.CurrentTabForData();
1489
1490
0
    ScMarkData& rMark = aViewData.GetMarkData();
1491
0
    ScDocument& rDoc  = aViewData.GetDocument();
1492
1493
0
    if (rMark.IsMarked() || rMark.IsMultiMarked())
1494
0
    {
1495
0
        rDoc.GetNextPos( nNewX, nNewY, nTab, nMoveX, nMoveY, true, false, rMark );
1496
1497
0
        MoveCursorRel( nNewX - nCurX, nNewY - nCurY, SC_FOLLOW_LINE, false, true );
1498
1499
        //  update input line even if cursor was not moved
1500
0
        if ( nNewX == nCurX && nNewY == nCurY )
1501
0
            aViewData.UpdateInputHandler(true);
1502
0
    }
1503
0
    else
1504
0
    {
1505
        // After Tab and Enter back to the starting column again.
1506
0
        const SCCOL nTabStartCol = ((nMoveY != 0 && !nMoveX) ? aViewData.GetTabStartCol() : SC_TABSTART_NONE);
1507
0
        rDoc.GetNextPos( nNewX, nNewY, nTab, nMoveX, nMoveY, false, true, rMark, nTabStartCol );
1508
1509
0
        MoveCursorRel( nNewX - nCurX, nNewY - nCurY, SC_FOLLOW_LINE, false);
1510
0
    }
1511
0
}
1512
1513
bool ScTabView::MoveCursorKeyInput( const KeyEvent& rKeyEvent )
1514
0
{
1515
0
    const vcl::KeyCode& rKCode = rKeyEvent.GetKeyCode();
1516
1517
0
    enum { MOD_NONE, MOD_CTRL, MOD_ALT, MOD_BOTH } eModifier =
1518
0
        rKCode.IsMod1() ?
1519
0
            (rKCode.IsMod2() ? MOD_BOTH : MOD_CTRL) :
1520
0
            (rKCode.IsMod2() ? MOD_ALT : MOD_NONE);
1521
1522
0
    bool bSel = rKCode.IsShift();
1523
0
    sal_uInt16 nCode = rKCode.GetCode();
1524
1525
    // CURSOR keys
1526
0
    SCCOL nDX = 0;
1527
0
    SCROW nDY = 0;
1528
0
    switch( nCode )
1529
0
    {
1530
0
        case KEY_LEFT:  nDX = -1;   break;
1531
0
        case KEY_RIGHT: nDX = 1;    break;
1532
0
        case KEY_UP:    nDY = -1;   break;
1533
0
        case KEY_DOWN:  nDY = 1;    break;
1534
0
    }
1535
0
    if( nDX != 0 || nDY != 0 )
1536
0
    {
1537
0
        switch( eModifier )
1538
0
        {
1539
0
            case MOD_NONE:  MoveCursorRel( nDX, nDY, SC_FOLLOW_LINE, bSel );    break;
1540
0
            case MOD_CTRL:  MoveCursorArea( nDX, nDY, SC_FOLLOW_JUMP, bSel );   break;
1541
0
            default:
1542
0
            {
1543
                // added to avoid warnings
1544
0
            }
1545
0
        }
1546
        // always true to suppress changes of col/row size (ALT+CURSOR)
1547
0
        return true;
1548
0
    }
1549
1550
    // PAGEUP/PAGEDOWN
1551
0
    if( (nCode == KEY_PAGEUP) || (nCode == KEY_PAGEDOWN) )
1552
0
    {
1553
0
        nDX = (nCode == KEY_PAGEUP) ? -1 : 1;
1554
0
        switch( eModifier )
1555
0
        {
1556
0
            case MOD_NONE:  MoveCursorPage( 0, static_cast<SCCOLROW>(nDX), SC_FOLLOW_FIX, bSel );  break;
1557
0
            case MOD_ALT:   MoveCursorPage( nDX, 0, SC_FOLLOW_FIX, bSel );  break;
1558
0
            case MOD_CTRL:  SelectNextTab( nDX, false );                    break;
1559
0
            default:
1560
0
            {
1561
                // added to avoid warnings
1562
0
            }
1563
0
        }
1564
0
        return true;
1565
0
    }
1566
1567
    // HOME/END
1568
0
    if( (nCode == KEY_HOME) || (nCode == KEY_END) )
1569
0
    {
1570
0
        nDX = (nCode == KEY_HOME) ? -1 : 1;
1571
0
        ScFollowMode eMode = (nCode == KEY_HOME) ? SC_FOLLOW_LINE : SC_FOLLOW_JUMP_END;
1572
0
        switch( eModifier )
1573
0
        {
1574
0
            case MOD_NONE:  MoveCursorEnd( nDX, 0, eMode, bSel );   break;
1575
0
            case MOD_CTRL:  MoveCursorEnd( nDX, static_cast<SCCOLROW>(nDX), eMode, bSel ); break;
1576
0
            default:
1577
0
            {
1578
                // added to avoid warnings
1579
0
            }
1580
0
        }
1581
0
        return true;
1582
0
    }
1583
1584
0
    return false;
1585
0
}
1586
1587
        // next/previous unprotected cell
1588
void ScTabView::FindNextUnprot( bool bShift, bool bInSelection )
1589
0
{
1590
0
    short nMove = bShift ? -1 : 1;
1591
1592
0
    ScMarkData& rMark = aViewData.GetMarkData();
1593
0
    bool bMarked = bInSelection && (rMark.IsMarked() || rMark.IsMultiMarked());
1594
1595
0
    SCCOL nCurX;
1596
0
    SCROW nCurY;
1597
0
    aViewData.GetMoveCursor( nCurX,nCurY );
1598
0
    SCCOL nNewX = nCurX;
1599
0
    SCROW nNewY = nCurY;
1600
0
    SCTAB nTab = aViewData.CurrentTabForData();
1601
1602
0
    ScDocument& rDoc = aViewData.GetDocument();
1603
0
    rDoc.GetNextPos( nNewX,nNewY, nTab, nMove,0, bMarked, true, rMark );
1604
1605
0
    SCCOL nTabCol = aViewData.GetTabStartCol();
1606
0
    if ( nTabCol == SC_TABSTART_NONE )
1607
0
        nTabCol = nCurX;                    // back to this column after Enter
1608
1609
0
    MoveCursorRel( nNewX-nCurX, nNewY-nCurY, SC_FOLLOW_LINE, false, true );
1610
1611
    // TabCol is reset in MoveCursorRel...
1612
0
    aViewData.SetTabStartCol( nTabCol );
1613
0
}
1614
1615
void ScTabView::MarkColumns()
1616
0
{
1617
0
    SCCOL nStartCol;
1618
0
    SCCOL nEndCol;
1619
1620
0
    ScMarkData& rMark = aViewData.GetMarkData();
1621
0
    if (rMark.IsMarked())
1622
0
    {
1623
0
        const ScRange& aMarkRange = rMark.GetMarkArea();
1624
0
        nStartCol = aMarkRange.aStart.Col();
1625
0
        nEndCol = aMarkRange.aEnd.Col();
1626
0
    }
1627
0
    else
1628
0
    {
1629
0
        SCROW nDummy;
1630
0
        aViewData.GetMoveCursor( nStartCol, nDummy );
1631
0
        nEndCol=nStartCol;
1632
0
    }
1633
1634
0
    SCTAB nTab = aViewData.CurrentTabForData();
1635
0
    ScDocument& rDoc = aViewData.GetDocument();
1636
0
    DoneBlockMode();
1637
0
    InitBlockMode( nStartCol,0, nTab );
1638
0
    MarkCursor( nEndCol, rDoc.MaxRow(), nTab );
1639
0
    SelectionChanged();
1640
0
}
1641
1642
void ScTabView::MarkRows()
1643
0
{
1644
0
    SCROW nStartRow;
1645
0
    SCROW nEndRow;
1646
1647
0
    ScMarkData& rMark = aViewData.GetMarkData();
1648
0
    if (rMark.IsMarked())
1649
0
    {
1650
0
        const ScRange& aMarkRange = rMark.GetMarkArea();
1651
0
        nStartRow = aMarkRange.aStart.Row();
1652
0
        nEndRow = aMarkRange.aEnd.Row();
1653
0
    }
1654
0
    else
1655
0
    {
1656
0
        SCCOL nDummy;
1657
0
        aViewData.GetMoveCursor( nDummy, nStartRow );
1658
0
        nEndRow=nStartRow;
1659
0
    }
1660
1661
0
    SCTAB nTab = aViewData.CurrentTabForData();
1662
0
    ScDocument& rDoc = aViewData.GetDocument();
1663
0
    DoneBlockMode();
1664
0
    InitBlockMode( 0,nStartRow, nTab );
1665
0
    MarkCursor( rDoc.MaxCol(), nEndRow, nTab );
1666
0
    SelectionChanged();
1667
0
}
1668
1669
1670
void ScTabView::MarkColumns(SCCOL nCol, sal_Int16 nModifier)
1671
0
{
1672
0
    ScDocument& rDoc = aViewData.GetDocument();
1673
0
    SCCOL nStartCol = nCol;
1674
0
    SCTAB nTab = aViewData.CurrentTabForData();
1675
1676
0
    if ((nModifier & KEY_SHIFT) == KEY_SHIFT)
1677
0
        bMoveIsShift = true;
1678
1679
0
    if (ScModule::get()->IsFormulaMode())
1680
0
    {
1681
0
        DoneRefMode( nModifier != 0 );
1682
0
        InitRefMode( nCol, 0, nTab, SC_REFTYPE_REF );
1683
0
        UpdateRef( nCol, rDoc.MaxRow(), nTab );
1684
0
        bMoveIsShift = false;
1685
0
    }
1686
0
    else
1687
0
    {
1688
0
        DoneBlockMode( nModifier != 0 );
1689
0
        InitBlockMode( nStartCol, 0, nTab, true, true);
1690
0
        MarkCursor( nCol, rDoc.MaxRow(), nTab );
1691
0
        bMoveIsShift = false;
1692
0
        SetCursor( nCol, 0 );
1693
0
        SelectionChanged();
1694
0
    }
1695
0
}
1696
1697
void ScTabView::MarkRows(SCROW nRow, sal_Int16 nModifier)
1698
0
{
1699
0
    ScDocument& rDoc = aViewData.GetDocument();
1700
0
    SCROW nStartRow = nRow;
1701
0
    SCTAB nTab = aViewData.CurrentTabForData();
1702
1703
0
    if ((nModifier & KEY_SHIFT) == KEY_SHIFT)
1704
0
        bMoveIsShift = true;
1705
1706
0
    if (ScModule::get()->IsFormulaMode())
1707
0
    {
1708
0
        DoneRefMode( nModifier != 0 );
1709
0
        InitRefMode( 0, nRow, nTab, SC_REFTYPE_REF );
1710
0
        UpdateRef( rDoc.MaxCol(), nRow, nTab );
1711
0
        bMoveIsShift = false;
1712
0
    }
1713
0
    else
1714
0
    {
1715
0
        DoneBlockMode( nModifier != 0 );
1716
0
        InitBlockMode( 0, nStartRow, nTab, true, false, true );
1717
0
        MarkCursor( rDoc.MaxCol(), nRow, nTab );
1718
0
        bMoveIsShift = false;
1719
0
        SetCursor( 0, nRow );
1720
0
        SelectionChanged();
1721
0
    }
1722
0
}
1723
1724
void ScTabView::HighlightOverlay()
1725
0
{
1726
0
    if (!officecfg::Office::Calc::Content::Display::ColumnRowHighlighting::get())
1727
0
    {
1728
0
        aViewData.GetHighlightData().ResetMark();
1729
0
        UpdateHighlightOverlay();
1730
0
        return;
1731
0
    }
1732
1733
0
    ScAddress aCell = GetViewData().GetCurPos();
1734
0
    SCROW nRow = aCell.Row();
1735
0
    SCCOL nCol = aCell.Col();
1736
1737
0
    bool nModifier = false;         // modifier key pressed?
1738
0
    DoneBlockModeHighlight( nModifier );
1739
0
    InitBlockModeHighlight( nCol, 0, aCell.Tab(), true, false);
1740
0
    nModifier = true;
1741
0
    DoneBlockModeHighlight( nModifier );
1742
0
    InitBlockModeHighlight( 0, nRow, aCell.Tab(), false, true );
1743
0
}
1744
1745
void ScTabView::MarkDataArea( bool bIncludeCursor )
1746
0
{
1747
0
    ScDocument& rDoc = aViewData.GetDocument();
1748
0
    SCTAB nTab = aViewData.CurrentTabForData();
1749
0
    SCCOL nStartCol = aViewData.GetCurX();
1750
0
    SCROW nStartRow = aViewData.GetCurY();
1751
0
    SCCOL nEndCol = nStartCol;
1752
0
    SCROW nEndRow = nStartRow;
1753
1754
0
    rDoc.GetDataArea( nTab, nStartCol, nStartRow, nEndCol, nEndRow, bIncludeCursor, false );
1755
1756
0
    HideAllCursors();
1757
0
    DoneBlockMode();
1758
0
    InitBlockMode( nStartCol, nStartRow, nTab );
1759
0
    MarkCursor( nEndCol, nEndRow, nTab );
1760
0
    ShowAllCursors();
1761
1762
0
    SelectionChanged();
1763
0
}
1764
1765
void ScTabView::MarkMatrixFormula()
1766
0
{
1767
0
    ScDocument& rDoc = aViewData.GetDocument();
1768
0
    ScAddress aCursor( aViewData.GetCurX(), aViewData.GetCurY(), aViewData.CurrentTabForData() );
1769
0
    ScRange aMatrix;
1770
0
    if ( rDoc.GetMatrixFormulaRange( aCursor, aMatrix ) )
1771
0
    {
1772
0
        MarkRange( aMatrix, false );        // cursor is already within the range
1773
0
    }
1774
0
}
1775
1776
void ScTabView::MarkRange( const ScRange& rRange, bool bSetCursor, bool bContinue )
1777
0
{
1778
0
    ScDocument& rDoc = aViewData.GetDocument();
1779
0
    SCTAB nTab = rRange.aStart.Tab();
1780
0
    SetTabNo( nTab );
1781
1782
0
    HideAllCursors();
1783
0
    DoneBlockMode( bContinue ); // bContinue==true -> clear old mark
1784
0
    if (bSetCursor)             // if Cursor is set, also always align
1785
0
    {
1786
0
        SCCOL nAlignX = rRange.aStart.Col();
1787
0
        SCROW nAlignY = rRange.aStart.Row();
1788
0
        bool bCol = ( rRange.aStart.Col() == 0 && rRange.aEnd.Col() == rDoc.MaxCol() ) && !aViewData.GetDocument().IsInVBAMode();
1789
0
        bool bRow = ( rRange.aStart.Row() == 0 && rRange.aEnd.Row() == rDoc.MaxRow() );
1790
0
        if ( bCol )
1791
0
            nAlignX = aViewData.GetPosX(WhichH(aViewData.GetActivePart()));
1792
0
        if ( bRow )
1793
0
            nAlignY = aViewData.GetPosY(WhichV(aViewData.GetActivePart()));
1794
0
        AlignToCursor( nAlignX, nAlignY, SC_FOLLOW_JUMP );
1795
0
    }
1796
0
    InitBlockMode( rRange.aStart.Col(), rRange.aStart.Row(), nTab );
1797
0
    MarkCursor( rRange.aEnd.Col(), rRange.aEnd.Row(), nTab );
1798
0
    if (bSetCursor)
1799
0
    {
1800
0
        SCCOL nPosX = rRange.aStart.Col();
1801
0
        SCROW nPosY = rRange.aStart.Row();
1802
0
        rDoc.SkipOverlapped(nPosX, nPosY, nTab);
1803
1804
0
        aViewData.ResetOldCursor();
1805
0
        SetCursor( nPosX, nPosY );
1806
0
    }
1807
0
    ShowAllCursors();
1808
1809
0
    SelectionChanged();
1810
0
}
1811
1812
void ScTabView::Unmark()
1813
0
{
1814
0
    ScMarkData& rMark = aViewData.GetMarkData();
1815
0
    if ( rMark.IsMarked() || rMark.IsMultiMarked() )
1816
0
    {
1817
0
        SCCOL nCurX;
1818
0
        SCROW nCurY;
1819
0
        aViewData.GetMoveCursor( nCurX,nCurY );
1820
0
        MoveCursorAbs( nCurX, nCurY, SC_FOLLOW_NONE, false, false );
1821
1822
0
        SelectionChanged();
1823
0
    }
1824
0
}
1825
1826
void ScTabView::SetMarkData( const ScMarkData& rNew )
1827
0
{
1828
0
    DoneBlockMode();
1829
0
    InitOwnBlockMode( rNew.GetMarkArea());
1830
0
    aViewData.GetMarkData() = rNew;
1831
1832
0
    MarkDataChanged();
1833
0
}
1834
1835
void ScTabView::MarkDataChanged()
1836
0
{
1837
    // has to be called after making direct changes to mark data (not via MarkCursor etc)
1838
1839
0
    UpdateSelectionOverlay();
1840
0
}
1841
1842
void ScTabView::SelectNextTab( short nDir, bool bExtendSelection )
1843
0
{
1844
0
    if (!nDir)
1845
0
        return;
1846
0
    OSL_ENSURE( nDir==-1 || nDir==1, "SelectNextTab: invalid value");
1847
1848
0
    ScDocument& rDoc = aViewData.GetDocument();
1849
0
    SCTAB nTab = aViewData.CurrentTabForData();
1850
0
    SCTAB nNextTab = nTab;
1851
0
    SCTAB nCount = rDoc.GetTableCount();
1852
0
    if (nDir < 0)
1853
0
    {
1854
0
        do
1855
0
        {
1856
0
            --nNextTab;
1857
0
            if (nNextTab < 0)
1858
0
            {
1859
0
                if (officecfg::Office::Calc::Input::WrapNextPrevSheetTab::get())
1860
0
                    nNextTab = nCount;
1861
0
                else
1862
0
                    return;
1863
0
            }
1864
0
            if (rDoc.IsVisible(nNextTab))
1865
0
                break;
1866
0
        } while (nNextTab != nTab);
1867
0
    }
1868
0
    else // nDir > 0
1869
0
    {
1870
0
        do
1871
0
        {
1872
0
            ++nNextTab;
1873
0
            if (nNextTab >= nCount)
1874
0
            {
1875
0
                if (officecfg::Office::Calc::Input::WrapNextPrevSheetTab::get())
1876
0
                    nNextTab = 0;
1877
0
                else
1878
0
                    return;
1879
0
            }
1880
0
            if (rDoc.IsVisible(nNextTab))
1881
0
                break;
1882
0
        } while (nNextTab != nTab);
1883
0
    }
1884
0
    if (nNextTab == nTab)
1885
0
        return;
1886
1887
0
    SetTabNo(nNextTab, false, bExtendSelection);
1888
0
    PaintExtras();
1889
0
}
1890
1891
void ScTabView::SelectTabPage( const sal_uInt16 nTab )
1892
0
{
1893
0
    pTabControl->SwitchToPageId( nTab );
1894
0
}
1895
1896
//  SetTabNo - set the displayed sheet
1897
1898
void ScTabView::SetTabNo( SCTAB nTab, bool bNew, bool bExtendSelection, bool bSameTabButMoved )
1899
0
{
1900
0
    ScTabViewShell* pViewShell = aViewData.GetViewShell();
1901
0
    pViewShell->SetTabChangeInProgress(true);
1902
1903
0
    if ( !ValidTab(nTab) )
1904
0
    {
1905
0
        OSL_FAIL("SetTabNo: invalid sheet");
1906
0
        return;
1907
0
    }
1908
1909
0
    if (!bNew && nTab == aViewData.CurrentTabForData())
1910
0
        return;
1911
1912
    // FormShell would like to be informed before the switch
1913
0
    FmFormShell* pFormSh = aViewData.GetViewShell()->GetFormShell();
1914
0
    if (pFormSh)
1915
0
    {
1916
0
        bool bAllowed = pFormSh->PrepareClose();
1917
0
        if (!bAllowed)
1918
0
        {
1919
            //! error message? or does FormShell do it?
1920
            //! return error flag and cancel actions
1921
1922
0
            return;     // FormShell says that it can not be switched
1923
0
        }
1924
0
    }
1925
1926
                                    // not InputEnterHandler due to reference input
1927
1928
0
    ScDocument& rDoc = aViewData.GetDocument();
1929
1930
0
    rDoc.MakeTable( nTab );
1931
1932
    // Update pending row heights before switching the sheet, so Reschedule from the progress bar
1933
    // doesn't paint the new sheet with old heights
1934
0
    aViewData.GetDocShell().UpdatePendingRowHeights( nTab );
1935
1936
0
    SCTAB nTabCount = rDoc.GetTableCount();
1937
0
    SCTAB nOldPos = nTab;
1938
0
    while (!rDoc.IsVisible(nTab))              // search for next visible
1939
0
    {
1940
0
        bool bUp = (nTab>=nOldPos);
1941
0
        if (bUp)
1942
0
        {
1943
0
            ++nTab;
1944
0
            if (nTab>=nTabCount)
1945
0
            {
1946
0
                nTab = nOldPos;
1947
0
                bUp = false;
1948
0
            }
1949
0
        }
1950
1951
0
        if (!bUp)
1952
0
        {
1953
0
            if (nTab != 0)
1954
0
                --nTab;
1955
0
            else
1956
0
            {
1957
0
                OSL_FAIL("no visible sheets");
1958
0
                rDoc.SetVisible( 0, true );
1959
0
            }
1960
0
        }
1961
0
    }
1962
1963
    // #i71490# Deselect drawing objects before changing the sheet number in view data,
1964
    // so the handling of notes still has the sheet selected on which the notes are.
1965
0
    DrawDeselectAll();
1966
1967
0
    ScModule* pScMod = ScModule::get();
1968
0
    bool bRefMode = pScMod->IsFormulaMode();
1969
0
    if ( !bRefMode ) // query, so that RefMode works when switching sheet
1970
0
    {
1971
0
        DoneBlockMode();
1972
0
        pSelEngine->Reset();                // reset all flags, including locked modifiers
1973
0
        aViewData.SetRefTabNo( nTab );
1974
0
    }
1975
1976
0
    ScSplitPos eOldActive = aViewData.GetActivePart();      // before switching
1977
0
    bool bFocus = pGridWin[eOldActive] && pGridWin[eOldActive]->HasFocus();
1978
1979
0
    aViewData.SetTabNo( nTab );
1980
0
    if (mpSpellCheckCxt)
1981
0
        mpSpellCheckCxt->setTabNo( nTab );
1982
    // UpdateShow before SetCursor, so that UpdateAutoFillMark finds the correct
1983
    // window  (is called from SetCursor)
1984
0
    UpdateShow();
1985
0
    aViewData.GetView()->TestHintWindow();
1986
1987
0
    SfxBindings& rBindings = aViewData.GetBindings();
1988
0
    ScMarkData& rMark = aViewData.GetMarkData();
1989
1990
0
    bool bAllSelected = true;
1991
0
    for (SCTAB nSelTab = 0; nSelTab < nTabCount; ++nSelTab)
1992
0
    {
1993
0
        if (!rDoc.IsVisible(nSelTab) || rMark.GetTableSelect(nSelTab))
1994
0
        {
1995
0
            if (nTab == nSelTab)
1996
                // This tab is already in selection.  Keep the current
1997
                // selection.
1998
0
                bExtendSelection = true;
1999
0
        }
2000
0
        else
2001
0
        {
2002
0
            bAllSelected = false;
2003
0
            if (bExtendSelection)
2004
                // We got what we need.  No need to stay in the loop.
2005
0
                break;
2006
0
        }
2007
0
    }
2008
0
    if (bAllSelected && !bNew)
2009
        // #i6327# if all tables are selected, a selection event (#i6330#) will deselect all
2010
        // (not if called with bNew to update settings)
2011
0
        bExtendSelection = false;
2012
2013
0
    if (bExtendSelection)
2014
0
        rMark.SelectTable( nTab, true );
2015
0
    else
2016
0
    {
2017
0
        rMark.SelectOneTable( nTab );
2018
0
        rBindings.Invalidate( FID_FILL_TAB );
2019
0
        rBindings.Invalidate( FID_TAB_DESELECTALL );
2020
0
    }
2021
2022
0
    bool bUnoRefDialog = pScMod->IsRefDialogOpen() && pScMod->GetCurRefDlgId() == WID_SIMPLE_REF;
2023
2024
    // recalc zoom-dependent values (before TabChanged, before UpdateEditViewPos)
2025
0
    RefreshZoom(/*bRecalcScale*/false); // no need to call RecalcScale() here, because we will do it in TabChanged()
2026
0
    UpdateVarZoom();
2027
2028
0
    if ( bRefMode )     // hide EditView if necessary (after aViewData.SetTabNo !)
2029
0
    {
2030
0
        for (VclPtr<ScGridWindow> & pWin : pGridWin)
2031
0
        {
2032
0
            if (pWin && pWin->IsVisible())
2033
0
                pWin->UpdateEditViewPos();
2034
0
        }
2035
0
    }
2036
2037
0
    TabChanged(bSameTabButMoved);                                       // DrawView
2038
0
    collectUIInformation({{"TABLE", OUString::number(nTab)}});
2039
0
    UpdateVisibleRange();
2040
2041
0
    aViewData.GetViewShell()->WindowChanged();          // if the active window has changed
2042
0
    aViewData.ResetOldCursor();
2043
0
    SetCursor( aViewData.GetCurX(), aViewData.GetCurY(), true );
2044
2045
0
    if ( !bUnoRefDialog )
2046
0
        aViewData.GetViewShell()->DisconnectAllClients();   // important for floating frames
2047
0
    else
2048
0
    {
2049
        // hide / show inplace client
2050
0
        ScClient* pClient = static_cast<ScClient*>(aViewData.GetViewShell()->GetIPClient());
2051
0
        if ( pClient && pClient->IsObjectInPlaceActive() )
2052
0
        {
2053
0
            tools::Rectangle aObjArea = pClient->GetObjArea();
2054
0
            if ( nTab == aViewData.GetRefTabNo() )
2055
0
            {
2056
                // move to its original position
2057
2058
0
                SdrOle2Obj* pDrawObj = pClient->GetDrawObj();
2059
0
                if ( pDrawObj )
2060
0
                {
2061
0
                    tools::Rectangle aRect = pDrawObj->GetLogicRect();
2062
0
                    MapMode aMapMode( MapUnit::Map100thMM );
2063
0
                    Size aOleSize = pDrawObj->GetOrigObjSize( &aMapMode );
2064
0
                    aRect.SetSize( aOleSize );
2065
0
                    aObjArea = aRect;
2066
0
                }
2067
0
            }
2068
0
            else
2069
0
            {
2070
                // move to an invisible position
2071
2072
0
                aObjArea.SetPos( Point( 0, -2*aObjArea.GetHeight() ) );
2073
0
            }
2074
0
            pClient->SetObjArea( aObjArea );
2075
0
        }
2076
0
    }
2077
2078
0
    if ( bFocus && aViewData.GetActivePart() != eOldActive && !bRefMode )
2079
0
        ActiveGrabFocus();      // grab focus to the pane that's active now
2080
2081
        // freeze
2082
2083
0
    bool bResize = false;
2084
0
    if ( aViewData.GetHSplitMode() == SC_SPLIT_FIX )
2085
0
        if (aViewData.UpdateFixX())
2086
0
            bResize = true;
2087
0
    if ( aViewData.GetVSplitMode() == SC_SPLIT_FIX )
2088
0
        if (aViewData.UpdateFixY())
2089
0
            bResize = true;
2090
0
    if (bResize)
2091
0
        RepeatResize();
2092
0
    InvalidateSplit();
2093
2094
0
    if ( aViewData.IsPagebreakMode() )
2095
0
        UpdatePageBreakData();              //! asynchronously ??
2096
2097
    // Form Layer must know the visible area of the new sheet
2098
    // that is why MapMode must already be correct here
2099
0
    SyncGridWindowMapModeFromDrawMapMode();
2100
0
    SetNewVisArea();
2101
2102
    // disable invalidations for kit during tab switching
2103
0
    {
2104
0
        SfxLokCallbackInterface* pCallback = pViewShell->getLibreOfficeKitViewCallback();
2105
0
        pViewShell->setLibreOfficeKitViewCallback(nullptr);
2106
0
        comphelper::ScopeGuard aOutputGuard(
2107
0
            [pViewShell, pCallback] {
2108
0
                pViewShell->setLibreOfficeKitViewCallback(pCallback);
2109
0
            });
2110
0
        PaintGrid();
2111
0
    }
2112
2113
0
    PaintTop();
2114
0
    PaintLeft();
2115
0
    PaintExtras();
2116
2117
0
    DoResize( aBorderPos, aFrameSize );
2118
0
    rBindings.Invalidate( SID_DELETE_PRINTAREA );   // Menu
2119
0
    rBindings.Invalidate( FID_DEL_MANUALBREAKS );
2120
0
    rBindings.Invalidate( FID_RESET_PRINTZOOM );
2121
0
    rBindings.Invalidate( SID_STATUS_DOCPOS );      // Status bar
2122
0
    rBindings.Invalidate( SID_ROWCOL_SELCOUNT );    // Status bar
2123
0
    rBindings.Invalidate( SID_STATUS_PAGESTYLE );   // Status bar
2124
0
    rBindings.Invalidate( SID_CURRENTTAB );         // Navigator
2125
0
    rBindings.Invalidate( SID_STYLE_FAMILY2 );      // Designer
2126
0
    rBindings.Invalidate( SID_STYLE_FAMILY4 );      // Designer
2127
0
    rBindings.Invalidate( SID_TABLES_COUNT );
2128
2129
0
    rBindings.Invalidate(FID_CURRENT_SHEET_VIEW);
2130
2131
0
    if (pScMod->IsRefDialogOpen())
2132
0
    {
2133
0
        sal_uInt16 nCurRefDlgId=pScMod->GetCurRefDlgId();
2134
0
        SfxViewFrame& rViewFrm = aViewData.GetViewShell()->GetViewFrame();
2135
0
        SfxChildWindow* pChildWnd = rViewFrm.GetChildWindow( nCurRefDlgId );
2136
0
        if (pChildWnd)
2137
0
        {
2138
0
            if (pChildWnd->GetController())
2139
0
            {
2140
0
                IAnyRefDialog* pRefDlg = dynamic_cast<IAnyRefDialog*>(pChildWnd->GetController().get());
2141
0
                if (pRefDlg)
2142
0
                    pRefDlg->ViewShellChanged();
2143
0
            }
2144
0
        }
2145
0
    }
2146
2147
0
    OnLibreOfficeKitTabChanged();
2148
0
    pViewShell->SetTabChangeInProgress(false);
2149
0
}
2150
2151
void ScTabView::AddWindowToForeignEditView(SfxViewShell* pViewShell, ScSplitPos eWhich)
2152
0
{
2153
0
    aExtraEditViewManager.Add(pViewShell, eWhich);
2154
0
}
2155
2156
void ScTabView::RemoveWindowFromForeignEditView(SfxViewShell* pViewShell, ScSplitPos eWhich)
2157
0
{
2158
0
    aExtraEditViewManager.Remove(pViewShell, eWhich);
2159
0
}
2160
2161
void ScTabView::OnLibreOfficeKitTabChanged()
2162
0
{
2163
0
    if (!comphelper::LibreOfficeKit::isActive())
2164
0
        return;
2165
2166
0
    ScTabViewShell* pThisViewShell = aViewData.GetViewShell();
2167
0
    SCTAB nThisTabNo = pThisViewShell->GetViewData().CurrentTabForData();
2168
0
    auto lTabSwitch = [pThisViewShell, nThisTabNo] (ScTabViewShell* pOtherViewShell)
2169
0
    {
2170
0
        ScViewData& rOtherViewData = pOtherViewShell->GetViewData();
2171
0
        SCTAB nOtherTabNo = rOtherViewData.CurrentTabForData();
2172
0
        if (nThisTabNo == nOtherTabNo)
2173
0
        {
2174
0
            for (int i = 0; i < 4; ++i)
2175
0
            {
2176
0
                if (rOtherViewData.HasEditView(ScSplitPos(i)))
2177
0
                {
2178
0
                    pThisViewShell->AddWindowToForeignEditView(pOtherViewShell, ScSplitPos(i));
2179
0
                }
2180
0
            }
2181
0
        }
2182
0
        else
2183
0
        {
2184
0
            for (int i = 0; i < 4; ++i)
2185
0
            {
2186
0
                if (rOtherViewData.HasEditView(ScSplitPos(i)))
2187
0
                {
2188
0
                    pThisViewShell->RemoveWindowFromForeignEditView(pOtherViewShell, ScSplitPos(i));
2189
0
                }
2190
0
            }
2191
0
        }
2192
0
    };
2193
2194
0
    SfxLokHelper::forEachOtherView(pThisViewShell, lTabSwitch);
2195
2196
0
    pThisViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_INVALIDATE_HEADER, "all"_ostr);
2197
2198
0
    if (pThisViewShell->GetInputHandler())
2199
0
        pThisViewShell->GetInputHandler()->UpdateLokReferenceMarks();
2200
0
}
2201
2202
// TextEditOverlayObject for TextOnOverlay TextEdit. It directly
2203
// implements needed EditViewCallbacks and also hosts the
2204
// OverlaySelection
2205
namespace
2206
{
2207
class ScTextEditOverlayObject : public sdr::overlay::OverlayObject, public EditViewCallbacks
2208
{
2209
    // the ScTabView the TextEdit is running at and the ScSplitPos to
2210
    // identify the associated data
2211
    ScTabView& mrScTabView;
2212
    ScSplitPos maScSplitPos;
2213
2214
    // this separate OverlayObject holds and creates the selection
2215
    // visualization, so it can be changed/refreshed without changing
2216
    // the Text or TextEditBackground
2217
    std::unique_ptr<sdr::overlay::OverlaySelection> mxOverlayTransparentSelection;
2218
2219
    // geometry creation for OverlayObject, in this case the extraction
2220
    // of edited Text from the setup EditEngine
2221
    virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override;
2222
2223
    // EditView overrides
2224
    virtual void EditViewInvalidate(const tools::Rectangle& rRect) override;
2225
    virtual void EditViewSelectionChange() override;
2226
    virtual OutputDevice& EditViewOutputDevice() const override;
2227
    virtual Point EditViewPointerPosPixel() const override;
2228
    virtual css::uno::Reference<css::datatransfer::clipboard::XClipboard> GetClipboard() const override;
2229
    virtual css::uno::Reference<css::datatransfer::dnd::XDropTarget> GetDropTarget() override;
2230
    virtual void EditViewInputContext(const InputContext& rInputContext) override;
2231
    virtual void EditViewCursorRect(const tools::Rectangle& rRect, int nExtTextInputWidth) override;
2232
2233
public:
2234
    // create using system selection color & ScTabView
2235
    ScTextEditOverlayObject(
2236
        const Color& rColor,
2237
        ScTabView& rScTabView,
2238
        ScSplitPos aScSplitPos);
2239
    virtual ~ScTextEditOverlayObject() override;
2240
2241
    // override to mix in TextEditBackground and the Text transformed
2242
    // as needed
2243
    virtual drawinglayer::primitive2d::Primitive2DContainer getOverlayObjectPrimitive2DSequence() const override;
2244
2245
    // access to OverlaySelection to add to OverlayManager
2246
    sdr::overlay::OverlayObject* getOverlaySelection()
2247
0
    {
2248
0
        return mxOverlayTransparentSelection.get();
2249
0
    }
2250
2251
    void RefeshTextEditOverlay()
2252
0
    {
2253
        // currently just deletes all created stuff, this may
2254
        // be fine-tuned later if needed
2255
0
        objectChange();
2256
0
    }
2257
};
2258
2259
ScTextEditOverlayObject::ScTextEditOverlayObject(
2260
    const Color& rColor,
2261
    ScTabView& rScTabView,
2262
    ScSplitPos aScSplitPos)
2263
0
: OverlayObject(rColor)
2264
0
, mrScTabView(rScTabView)
2265
0
, maScSplitPos(aScSplitPos)
2266
0
{
2267
    // no AA for TextEdit overlay
2268
0
    allowAntiAliase(false);
2269
2270
    // establish EditViewCallbacks
2271
0
    const ScViewData& rScViewData(mrScTabView.GetViewData());
2272
0
    EditView* pEditView(rScViewData.GetEditView(maScSplitPos));
2273
0
    DBG_ASSERT(nullptr != pEditView, "NO access to EditView in ScTextEditOverlayObject!");
2274
0
    pEditView->setEditViewCallbacks(this);
2275
2276
    // initialize empty OverlaySelection
2277
0
    std::vector<basegfx::B2DRange> aEmptySelection{};
2278
0
    mxOverlayTransparentSelection.reset(new sdr::overlay::OverlaySelection(
2279
0
        sdr::overlay::OverlayType::Transparent, rColor, std::move(aEmptySelection), true));
2280
0
}
2281
2282
ScTextEditOverlayObject::~ScTextEditOverlayObject()
2283
0
{
2284
    // delete OverlaySelection - this will also remove itself from
2285
    // OverlayManager already
2286
0
    mxOverlayTransparentSelection.reset();
2287
2288
    // shutdown EditViewCallbacks
2289
0
    const ScViewData& rScViewData(mrScTabView.GetViewData());
2290
0
    EditView* pEditView(rScViewData.GetEditView(maScSplitPos));
2291
0
    DBG_ASSERT(nullptr != pEditView, "NO access to EditView in ScTextEditOverlayObject!");
2292
0
    pEditView->setEditViewCallbacks(nullptr);
2293
2294
    // remove myself
2295
0
    if (getOverlayManager())
2296
0
        getOverlayManager()->remove(*this);
2297
0
}
2298
2299
drawinglayer::primitive2d::Primitive2DContainer ScTextEditOverlayObject::createOverlayObjectPrimitive2DSequence()
2300
0
{
2301
    // extract primitive representation from active EditEngine
2302
0
    drawinglayer::primitive2d::Primitive2DContainer aRetval;
2303
2304
0
    ScViewData& rScViewData(mrScTabView.GetViewData());
2305
0
    const EditView* pEditView(rScViewData.GetEditView(maScSplitPos));
2306
0
    assert(pEditView && "NO access to EditView in ScTextEditOverlayObject!");
2307
2308
    // get text data in LogicMode
2309
0
    OutputDevice& rOutDev(pEditView->GetOutputDevice());
2310
0
    const MapMode aOrig(rOutDev.GetMapMode());
2311
0
    rOutDev.SetMapMode(rScViewData.GetLogicMode());
2312
2313
    // StripPortions from EditEngine.
2314
    // use no transformations. The result will be in logic coordinates
2315
    // based on aEditRectangle and the EditEngine setup, see
2316
    // ScViewData::SetEditEngine
2317
0
    TextHierarchyBreakup aBreakup;
2318
0
    pEditView->getEditEngine().StripPortions(aBreakup);
2319
0
    aRetval = aBreakup.getTextPortionPrimitives();
2320
2321
0
    rOutDev.SetMapMode(aOrig);
2322
0
    return aRetval;
2323
0
}
2324
2325
void ScTextEditOverlayObject::EditViewInvalidate(const tools::Rectangle& rRect)
2326
0
{
2327
0
    if (comphelper::LibreOfficeKit::isActive())
2328
0
    {
2329
        // UT testPageDownInvalidation from CppunitTest_sc_tiledrendering
2330
        // *needs* the direct invalidates formerly done in
2331
        // EditView::InvalidateWindow when no EditViewCallbacks are set
2332
0
        ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2333
0
        pActiveWin->Invalidate(rRect);
2334
0
    }
2335
2336
0
    RefeshTextEditOverlay();
2337
0
}
2338
2339
void ScTextEditOverlayObject::EditViewSelectionChange()
2340
0
{
2341
0
    ScViewData& rScViewData(mrScTabView.GetViewData());
2342
0
    EditView* pEditView(rScViewData.GetEditView(maScSplitPos));
2343
0
    assert(pEditView && "NO access to EditView in ScTextEditOverlayObject!");
2344
2345
    // get the selection rectangles
2346
0
    std::vector<tools::Rectangle> aRects;
2347
0
    pEditView->GetSelectionRectangles(aRects);
2348
0
    std::vector<basegfx::B2DRange> aLogicRanges;
2349
2350
0
    if (aRects.empty())
2351
0
    {
2352
        // if none, reset selection at OverlayObject and we are done
2353
0
        mxOverlayTransparentSelection->setRanges(std::move(aLogicRanges));
2354
0
        return;
2355
0
    }
2356
2357
    // create needed transformations
2358
    // LogicMode -> DiscreteViewCoordinates (Pixels)
2359
0
    basegfx::B2DHomMatrix aTransformToPixels;
2360
0
    OutputDevice& rOutDev(pEditView->GetOutputDevice());
2361
0
    const MapMode aOrig(rOutDev.GetMapMode());
2362
0
    rOutDev.SetMapMode(rScViewData.GetLogicMode());
2363
0
    aTransformToPixels = rOutDev.GetViewTransformation();
2364
2365
    // DiscreteViewCoordinates (Pixels) -> LogicDrawCoordinates
2366
0
    basegfx::B2DHomMatrix aTransformToDrawCoordinates;
2367
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2368
0
    rOutDev.SetMapMode(pActiveWin->GetDrawMapMode());
2369
0
    aTransformToDrawCoordinates = rOutDev.GetInverseViewTransformation();
2370
0
    rOutDev.SetMapMode(aOrig);
2371
2372
0
    for (const auto& aRect : aRects)
2373
0
    {
2374
0
        basegfx::B2DRange aRange(aRect.Left(), aRect.Top(), aRect.Right(), aRect.Bottom());
2375
2376
        // range to pixels
2377
0
        aRange.transform(aTransformToPixels);
2378
2379
        // grow by 1px for slight distance/overlap
2380
0
        aRange.grow(1.0);
2381
2382
        // to drawinglayer coordinates & add
2383
0
        aRange.transform(aTransformToDrawCoordinates);
2384
0
        aLogicRanges.emplace_back(aRange);
2385
0
    }
2386
2387
0
    mxOverlayTransparentSelection->setRanges(std::move(aLogicRanges));
2388
0
}
2389
2390
OutputDevice& ScTextEditOverlayObject::EditViewOutputDevice() const
2391
0
{
2392
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2393
0
    return *pActiveWin->GetOutDev();
2394
0
}
2395
2396
Point ScTextEditOverlayObject::EditViewPointerPosPixel() const
2397
0
{
2398
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2399
0
    return pActiveWin->GetPointerPosPixel();
2400
0
}
2401
2402
css::uno::Reference<css::datatransfer::clipboard::XClipboard> ScTextEditOverlayObject::GetClipboard() const
2403
0
{
2404
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2405
0
    return pActiveWin->GetClipboard();
2406
0
}
2407
2408
css::uno::Reference<css::datatransfer::dnd::XDropTarget> ScTextEditOverlayObject::GetDropTarget()
2409
0
{
2410
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2411
0
    return pActiveWin->GetDropTarget();
2412
0
}
2413
2414
void ScTextEditOverlayObject::EditViewInputContext(const InputContext& rInputContext)
2415
0
{
2416
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2417
0
    pActiveWin->SetInputContext(rInputContext);
2418
0
}
2419
2420
void ScTextEditOverlayObject::EditViewCursorRect(const tools::Rectangle& rRect, int nExtTextInputWidth)
2421
0
{
2422
0
    ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2423
0
    pActiveWin->SetCursorRect(&rRect, nExtTextInputWidth);
2424
0
}
2425
2426
drawinglayer::primitive2d::Primitive2DContainer ScTextEditOverlayObject::getOverlayObjectPrimitive2DSequence() const
2427
0
{
2428
0
    drawinglayer::primitive2d::Primitive2DContainer aRetval;
2429
2430
2431
0
    ScViewData& rScViewData(mrScTabView.GetViewData());
2432
0
    EditView* pEditView(rScViewData.GetEditView(maScSplitPos));
2433
0
    assert(pEditView && "NO access to EditView in ScTextEditOverlayObject!");
2434
2435
    // call base implementation to get TextPrimitives in logic coordinates
2436
    // directly from the setup EditEngine
2437
0
    drawinglayer::primitive2d::Primitive2DContainer aText(
2438
0
        OverlayObject::getOverlayObjectPrimitive2DSequence());
2439
2440
0
    if (aText.empty())
2441
        // no Text, done, return result
2442
0
        return aRetval;
2443
2444
    // remember MapMode and restore at exit - we do not want
2445
    // to change it outside this method
2446
0
    OutputDevice& rOutDev(pEditView->GetOutputDevice());
2447
0
    const MapMode aOrig(rOutDev.GetMapMode());
2448
2449
    // create text edit background based on pixel coordinates
2450
    // of involved Cells and append
2451
0
    {
2452
0
        const SCCOL nCol1(rScViewData.GetEditStartCol());
2453
0
        const SCROW nRow1(rScViewData.GetEditStartRow());
2454
0
        const SCCOL nCol2(rScViewData.GetEditEndCol());
2455
0
        const SCROW nRow2(rScViewData.GetEditEndRow());
2456
0
        const Point aStart(rScViewData.GetScrPos(nCol1, nRow1, maScSplitPos));
2457
0
        const Point aEnd(rScViewData.GetScrPos(nCol2+1, nRow2+1, maScSplitPos));
2458
2459
0
        if (aStart != aEnd)
2460
0
        {
2461
            // create outline polygon. Shrink by 1px due to working
2462
            // with pixel positions one cell right and below. We are
2463
            // in discrete (pixel) coordinates with start/end here,
2464
            // so just subtract '1' from x and y to do that
2465
0
            basegfx::B2DPolyPolygon aOutline(basegfx::utils::createPolygonFromRect(
2466
0
                basegfx::B2DRange(
2467
0
                    aStart.X(), aStart.Y(),
2468
0
                    aEnd.X() - 1, aEnd.Y() - 1)));
2469
2470
            // transform from Pixels to LogicDrawCoordinates
2471
0
            ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2472
0
            rOutDev.SetMapMode(pActiveWin->GetDrawMapMode());
2473
0
            aOutline.transform(rOutDev.GetInverseViewTransformation());
2474
2475
0
            aRetval.push_back(
2476
0
                rtl::Reference<drawinglayer::primitive2d::PolyPolygonColorPrimitive2D>(
2477
0
                    new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
2478
0
                        std::move(aOutline),
2479
0
                        pEditView->GetBackgroundColor().getBColor())));
2480
0
        }
2481
0
    }
2482
2483
    // create embedding transformation for Text itself and
2484
    // append Text
2485
0
    {
2486
0
        basegfx::B2DHomMatrix aTransform;
2487
2488
        // transform by TextPaint StartPosition (Top-Left). This corresponds
2489
        // to aEditRectangle and the EditEngine setup, see
2490
        // ScViewData::SetEditEngine. Offset is in LogicCoordinates/LogicMode
2491
0
        const Point aStartPosition(pEditView->CalculateTextPaintStartPosition());
2492
0
        aTransform.translate(aStartPosition.X(), aStartPosition.Y());
2493
2494
        // LogicMode -> DiscreteViewCoordinates (Pixels)
2495
0
        rOutDev.SetMapMode(rScViewData.GetLogicMode());
2496
0
        aTransform *= rOutDev.GetViewTransformation();
2497
2498
        // DiscreteViewCoordinates (Pixels) -> LogicDrawCoordinates
2499
0
        ScGridWindow* pActiveWin(static_cast<ScGridWindow*>(mrScTabView.GetWindowByPos(maScSplitPos)));
2500
0
        rOutDev.SetMapMode(pActiveWin->GetDrawMapMode());
2501
0
        aTransform *= rOutDev.GetInverseViewTransformation();
2502
2503
        // add text embedded to created transformation
2504
0
        aRetval.push_back(rtl::Reference<drawinglayer::primitive2d::TransformPrimitive2D>(
2505
0
            new drawinglayer::primitive2d::TransformPrimitive2D(
2506
0
                aTransform, std::move(aText))));
2507
0
    }
2508
2509
0
    rOutDev.SetMapMode(aOrig);
2510
0
    return aRetval;
2511
0
}
2512
} // end of anonymous namespace
2513
2514
void ScTabView::RefeshTextEditOverlay()
2515
0
{
2516
    // find the ScTextEditOverlayObject in the OverlayGroup and
2517
    // call refresh there. It is also possible to have separate
2518
    // holders of that data, so no find/identification would be
2519
    // needed, but having all associated OverlayObjects in one
2520
    // group makes handling simple(r). It may also be that the
2521
    // cursor visualization will be added to that group later
2522
0
    for (sal_uInt32 a(0); a < maTextEditOverlayGroup.count(); a++)
2523
0
    {
2524
0
        sdr::overlay::OverlayObject& rOverlayObject(maTextEditOverlayGroup.getOverlayObject(a));
2525
0
        ScTextEditOverlayObject* pScTextEditOverlayObject(dynamic_cast<ScTextEditOverlayObject*>(&rOverlayObject));
2526
2527
0
        if (nullptr != pScTextEditOverlayObject)
2528
0
        {
2529
0
            pScTextEditOverlayObject->RefeshTextEditOverlay();
2530
0
        }
2531
0
    }
2532
0
}
2533
2534
void ScTabView::MakeEditView( ScEditEngineDefaulter& rEngine, SCCOL nCol, SCROW nRow )
2535
0
{
2536
0
    DrawDeselectAll();
2537
2538
0
    if (pDrawView)
2539
0
        DrawEnableAnim( false );
2540
2541
0
    EditView* pSpellingView = aViewData.GetSpellingView();
2542
2543
0
    for (sal_uInt16 i = 0; i < 4; i++)
2544
0
    {
2545
0
        if (pGridWin[i] && pGridWin[i]->IsVisible() && !aViewData.HasEditView(ScSplitPos(i)))
2546
0
        {
2547
0
            const ScSplitPos aScSplitPos(static_cast<ScSplitPos>(i));
2548
0
            ScHSplitPos eHWhich = WhichH(aScSplitPos);
2549
0
            ScVSplitPos eVWhich = WhichV(aScSplitPos);
2550
0
            SCCOL nScrX = aViewData.GetPosX( eHWhich );
2551
0
            SCROW nScrY = aViewData.GetPosY( eVWhich );
2552
2553
0
            bool bPosVisible =
2554
0
                 ( nCol >= nScrX && nCol <= nScrX + aViewData.VisibleCellsX(eHWhich) - 1 &&
2555
0
                   nRow >= nScrY && nRow <= nScrY + aViewData.VisibleCellsY(eVWhich) - 1 );
2556
2557
            //  for the active part, create edit view even if outside the visible area,
2558
            //  so input isn't lost (and the edit view may be scrolled into the visible area)
2559
2560
            //  #i26433# during spelling, the spelling view must be active
2561
0
            if ( bPosVisible || aViewData.GetActivePart() == aScSplitPos ||
2562
0
                 ( pSpellingView && aViewData.GetEditView(aScSplitPos) == pSpellingView ) )
2563
0
            {
2564
0
                VclPtr<ScGridWindow> pScGridWindow(pGridWin[aScSplitPos]);
2565
0
                pScGridWindow->HideCursor();
2566
0
                pScGridWindow->DeleteCursorOverlay();
2567
0
                pScGridWindow->DeleteAutoFillOverlay();
2568
0
                pScGridWindow->DeleteCopySourceOverlay();
2569
2570
                // MapMode must be set after HideCursor
2571
0
                pScGridWindow->SetMapMode(aViewData.GetLogicMode());
2572
2573
0
                if ( !bPosVisible )
2574
0
                {
2575
                    //  move the edit view area to the real (possibly negative) position,
2576
                    //  or hide if completely above or left of the window
2577
0
                    pScGridWindow->UpdateEditViewPos();
2578
0
                }
2579
2580
0
                aViewData.SetEditEngine(aScSplitPos, rEngine, pScGridWindow, nCol,
2581
0
                                        nRow);
2582
2583
                // get OverlayManager and initialize TextEditOnOverlay for it
2584
0
                rtl::Reference<sdr::overlay::OverlayManager> xOverlayManager = pScGridWindow->getOverlayManager();
2585
2586
0
                if (xOverlayManager.is() && aViewData.HasEditView(aScSplitPos))
2587
0
                {
2588
0
                    const Color aHilightColor(SvtOptionsDrawinglayer::getHilightColor());
2589
0
                    std::unique_ptr<ScTextEditOverlayObject> pNewScTextEditOverlayObject(
2590
0
                        new ScTextEditOverlayObject(
2591
0
                            aHilightColor,
2592
0
                            *this,
2593
0
                            aScSplitPos));
2594
2595
                    // add TextEditOverlayObject and the OverlaySelection hosted by it
2596
                    // to the OverlayManager (to make visible) and to the local
2597
                    // reference TextEditOverlayGroup (to access if needed)
2598
0
                    xOverlayManager->add(*pNewScTextEditOverlayObject);
2599
0
                    xOverlayManager->add(*pNewScTextEditOverlayObject->getOverlaySelection());
2600
0
                    maTextEditOverlayGroup.append(std::move(pNewScTextEditOverlayObject));
2601
0
                }
2602
0
            }
2603
0
        }
2604
0
    }
2605
2606
0
    if (aViewData.GetViewShell()->HasAccessibilityObjects())
2607
0
        aViewData.GetViewShell()->BroadcastAccessibility(SfxHint(SfxHintId::ScAccEnterEditMode));
2608
0
}
2609
2610
void ScTabView::UpdateEditView()
2611
0
{
2612
0
    if (aViewData.CurrentTabForData() != aViewData.GetRefTabNo() && ScModule::get()->IsFormulaMode())
2613
0
        return;
2614
2615
0
    ScSplitPos eActive = aViewData.GetActivePart();
2616
0
    for (sal_uInt16 i = 0; i < 4; i++)
2617
0
    {
2618
0
        ScSplitPos eCurrent = ScSplitPos(i);
2619
0
        if (aViewData.HasEditView(eCurrent))
2620
0
        {
2621
0
            EditView* pEditView = aViewData.GetEditView(eCurrent);
2622
2623
0
            tools::Long nRefTabNo = GetViewData().GetRefTabNo();
2624
0
            tools::Long nX = GetViewData().GetCurXForTab(nRefTabNo);
2625
0
            tools::Long nY = GetViewData().GetCurYForTab(nRefTabNo);
2626
2627
0
            aViewData.SetEditEngine(eCurrent,
2628
0
                static_cast<ScEditEngineDefaulter&>(pEditView->getEditEngine()),
2629
0
                pGridWin[i], nX, nY );
2630
0
            if (eCurrent == eActive)
2631
0
                pEditView->ShowCursor( false );
2632
0
        }
2633
0
    }
2634
2635
0
    RefeshTextEditOverlay();
2636
0
}
2637
2638
void ScTabView::KillEditView( bool bNoPaint )
2639
0
{
2640
0
    SCCOL nCol1 = aViewData.GetEditStartCol();
2641
0
    SCROW nRow1 = aViewData.GetEditStartRow();
2642
0
    SCCOL nCol2 = aViewData.GetEditEndCol();
2643
0
    SCROW nRow2 = aViewData.GetEditEndRow();
2644
0
    SCTAB nTab = aViewData.CurrentTabForData();
2645
0
    bool bPaint[4];
2646
0
    bool bNotifyAcc = false;
2647
0
    tools::Rectangle aRectangle[4];
2648
2649
0
    bool bExtended = nRow1 != nRow2;                    // column is painted to the end anyway
2650
2651
0
    bool bAtCursor = nCol1 <= aViewData.GetCurX() &&
2652
0
                     nCol2 >= aViewData.GetCurX() &&
2653
0
                     nRow1 == aViewData.GetCurY();
2654
0
    for (sal_uInt16 i = 0; i < 4; i++)
2655
0
    {
2656
0
        bPaint[i] = aViewData.HasEditView( static_cast<ScSplitPos>(i) );
2657
0
        if (bPaint[i])
2658
0
        {
2659
0
            bNotifyAcc = true;
2660
2661
0
            EditView* pView = aViewData.GetEditView( static_cast<ScSplitPos>(i) );
2662
0
            aRectangle[i] = pView->GetInvalidateRect();
2663
0
        }
2664
0
    }
2665
2666
    // this cleans up all used OverlayObjects for TextEdit, they get deleted
2667
    // and removed from the OverlayManager what makes them optically disappear
2668
0
    maTextEditOverlayGroup.clear();
2669
2670
    // notify accessibility before all things happen
2671
0
    if (bNotifyAcc && aViewData.GetViewShell()->HasAccessibilityObjects())
2672
0
        aViewData.GetViewShell()->BroadcastAccessibility(SfxHint(SfxHintId::ScAccLeaveEditMode));
2673
2674
0
    aViewData.ResetEditView();
2675
0
    for (sal_uInt16 i = 0; i < 4; i++)
2676
0
    {
2677
0
        if (pGridWin[i] && bPaint[i] && pGridWin[i]->IsVisible())
2678
0
        {
2679
0
            pGridWin[i]->ShowCursor();
2680
2681
0
            pGridWin[i]->SetMapMode(pGridWin[i]->GetDrawMapMode());
2682
2683
0
            const tools::Rectangle& rInvRect = aRectangle[i];
2684
2685
0
            if (comphelper::LibreOfficeKit::isActive())
2686
0
            {
2687
0
                pGridWin[i]->LogicInvalidatePart(&rInvRect, nTab);
2688
2689
                // invalidate other views
2690
0
                auto lInvalidateWindows =
2691
0
                        [nTab, &rInvRect] (ScTabView* pTabView)
2692
0
                        {
2693
0
                            for (VclPtr<ScGridWindow> const & pWin: pTabView->pGridWin)
2694
0
                            {
2695
0
                                if (pWin)
2696
0
                                    pWin->LogicInvalidatePart(&rInvRect, nTab);
2697
0
                            }
2698
0
                        };
2699
2700
0
                SfxLokHelper::forEachOtherView(GetViewData().GetViewShell(), lInvalidateWindows);
2701
0
            }
2702
            // #i73567# the cell still has to be repainted
2703
0
            else
2704
0
            {
2705
0
                const bool bDoPaint = bExtended || (bAtCursor && !bNoPaint);
2706
0
                const bool bDoInvalidate = !bDoPaint && bAtCursor;
2707
0
                if (bDoPaint)
2708
0
                {
2709
0
                    pGridWin[i]->Draw( nCol1, nRow1, nCol2, nRow2, ScUpdateMode::All );
2710
0
                    pGridWin[i]->UpdateSelectionOverlay();
2711
0
                }
2712
0
                else if (bDoInvalidate)
2713
0
                {
2714
                    // tdf#162651 even if !bNoPaint is set, and there will be a
2715
                    // follow up Draw of the next content, the area blanked out
2716
                    // by the editview which is being removed still needs to be
2717
                    // invalidated. The follow-up Draw of the content may be
2718
                    // optimized to only redraw the area of cells where content
2719
                    // has changed and will be unaware of what bounds this
2720
                    // editview grew to during its editing cycle.
2721
0
                    pGridWin[i]->Invalidate(rInvRect);
2722
0
                }
2723
0
            }
2724
0
        }
2725
0
    }
2726
2727
0
    if (pDrawView)
2728
0
        DrawEnableAnim( true );
2729
2730
        // GrabFocus always when this View is active and
2731
        // when the input row has the focus
2732
2733
0
    bool bGrabFocus = false;
2734
0
    if (aViewData.IsActive())
2735
0
    {
2736
0
        ScInputHandler* pInputHdl = ScModule::get()->GetInputHdl();
2737
0
        if ( pInputHdl )
2738
0
        {
2739
0
            ScInputWindow* pInputWin = pInputHdl->GetInputWindow();
2740
0
            if (pInputWin && pInputWin->IsInputActive())
2741
0
                bGrabFocus = true;
2742
0
        }
2743
0
    }
2744
2745
0
    if (bGrabFocus)
2746
0
    {
2747
//      should be done like this, so that Sfx notice it, but it does not work:
2748
//!     aViewData.CurrentTabForData()->GetViewFrame().GetWindow().GrabFocus();
2749
//      therefore first like this:
2750
0
        GetActiveWin()->GrabFocus();
2751
0
    }
2752
2753
    // cursor query only after GrabFocus
2754
2755
0
    for (sal_uInt16 i = 0; i < 4; i++)
2756
0
    {
2757
0
        if (pGridWin[i] && pGridWin[i]->IsVisible())
2758
0
        {
2759
0
            vcl::Cursor* pCur = pGridWin[i]->GetCursor();
2760
0
            if (pCur && pCur->IsVisible())
2761
0
                pCur->Hide();
2762
2763
0
            if (bPaint[i])
2764
0
            {
2765
0
                pGridWin[i]->UpdateCursorOverlay();
2766
0
                pGridWin[i]->UpdateAutoFillOverlay();
2767
0
            }
2768
0
        }
2769
0
    }
2770
0
}
2771
2772
void ScTabView::UpdateFormulas(SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow)
2773
0
{
2774
0
    if ( aViewData.GetDocument().IsAutoCalcShellDisabled() )
2775
0
        return;
2776
2777
0
    for (sal_uInt16 i = 0; i < 4; i++)
2778
0
    {
2779
0
        if (pGridWin[i] && pGridWin[i]->IsVisible())
2780
0
            pGridWin[i]->UpdateFormulas(nStartCol, nStartRow, nEndCol, nEndRow);
2781
0
    }
2782
2783
0
    if ( aViewData.IsPagebreakMode() )
2784
0
        UpdatePageBreakData();              //! asynchronous
2785
2786
0
    bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
2787
    // UpdateHeaderWidth can fit the GridWindow widths to the frame, something
2788
    // we don't want in kit-mode where we try and match the GridWindow width
2789
    // to the tiled area separately
2790
0
    if (!bIsTiledRendering)
2791
0
        UpdateHeaderWidth();
2792
2793
    //  if in edit mode, adjust edit view area because widths/heights may have changed
2794
0
    if ( aViewData.HasEditView( aViewData.GetActivePart() ) )
2795
0
        UpdateEditView();
2796
0
}
2797
2798
//  PaintArea - repaint block
2799
2800
void ScTabView::PaintArea( SCCOL nStartCol, SCROW nStartRow, SCCOL nEndCol, SCROW nEndRow,
2801
                            ScUpdateMode eMode, tools::Long nMaxWidthAffectedHintTwip )
2802
0
{
2803
0
    SCCOL nCol1;
2804
0
    SCROW nRow1;
2805
0
    SCCOL nCol2;
2806
0
    SCROW nRow2;
2807
0
    bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
2808
0
    ScDocument& rDoc = aViewData.GetDocument();
2809
2810
0
    PutInOrder( nStartCol, nEndCol );
2811
0
    PutInOrder( nStartRow, nEndRow );
2812
2813
0
    for (size_t i = 0; i < 4; ++i)
2814
0
    {
2815
0
        if (!pGridWin[i] || !pGridWin[i]->IsVisible())
2816
0
            continue;
2817
2818
0
        ScHSplitPos eHWhich = WhichH( static_cast<ScSplitPos>(i) );
2819
0
        ScVSplitPos eVWhich = WhichV( static_cast<ScSplitPos>(i) );
2820
0
        bool bOut = false;
2821
2822
0
        nCol1 = nStartCol;
2823
0
        nRow1 = nStartRow;
2824
0
        nCol2 = nEndCol;
2825
0
        nRow2 = nEndRow;
2826
2827
0
        SCCOL nLastX = 0;
2828
0
        SCROW nLastY = 0;
2829
2830
0
        if (bIsTiledRendering)
2831
0
        {
2832
0
            nLastX = aViewData.GetMaxTiledCol();
2833
0
            nLastY = aViewData.GetMaxTiledRow();
2834
0
        }
2835
0
        else
2836
0
        {
2837
2838
0
            SCCOL nScrX = aViewData.GetPosX( eHWhich );
2839
0
            SCROW nScrY = aViewData.GetPosY( eVWhich );
2840
2841
0
            if (nCol1 < nScrX)
2842
0
                nCol1 = nScrX;
2843
0
            if (nCol2 < nScrX)
2844
0
            {
2845
0
                if ( eMode == ScUpdateMode::All )   // for UPDATE_ALL, paint anyway
2846
0
                    nCol2 = nScrX;              // (because of extending strings to the right)
2847
0
                else
2848
0
                    bOut = true;                // completely outside the window
2849
0
            }
2850
0
            if (nRow1 < nScrY)
2851
0
                nRow1 = nScrY;
2852
0
            if (nRow2 < nScrY)
2853
0
                bOut = true;
2854
2855
0
            nLastX = nScrX + aViewData.VisibleCellsX( eHWhich ) + 1;
2856
0
            nLastY = nScrY + aViewData.VisibleCellsY( eVWhich ) + 1;
2857
0
        }
2858
2859
0
        if (nCol1 > nLastX)
2860
0
            bOut = true;
2861
0
        if (nCol2 > nLastX)
2862
0
            nCol2 = nLastX;
2863
0
        if (nRow1 > nLastY)
2864
0
            bOut = true;
2865
0
        if (nRow2 > nLastY)
2866
0
            nRow2 = nLastY;
2867
2868
0
        if (bOut)
2869
0
            continue;
2870
2871
0
        bool bLayoutRTL = aViewData.GetDocument().IsLayoutRTL( aViewData.CurrentTabForData() );
2872
0
        tools::Long nLayoutSign = (!bIsTiledRendering && bLayoutRTL) ? -1 : 1;
2873
2874
0
        Point aStart = aViewData.GetScrPos( nCol1, nRow1, static_cast<ScSplitPos>(i) );
2875
0
        Point aEnd   = aViewData.GetScrPos( nCol2+1, nRow2+1, static_cast<ScSplitPos>(i) );
2876
2877
0
        if ( eMode == ScUpdateMode::All )
2878
0
        {
2879
0
            if (nMaxWidthAffectedHintTwip != -1)
2880
0
            {
2881
0
                tools::Long nMaxWidthAffectedHint = ScViewData::ToPixel(nMaxWidthAffectedHintTwip, aViewData.GetPPTX());
2882
2883
                // If we know the max text width affected then just invalidate
2884
                // the max of the cell width and hint of affected cell width
2885
                // (where affected with is in terms of max width of optimal cell
2886
                // width for before/after change)
2887
0
                tools::Long nCellWidth = std::abs(aEnd.X() - aStart.X());
2888
0
                aEnd.setX(aStart.getX() + std::max(nCellWidth, nMaxWidthAffectedHint) * nLayoutSign);
2889
0
            }
2890
0
            else
2891
0
            {
2892
0
                if (bIsTiledRendering)
2893
0
                {
2894
                    // When a cell content is deleted we have no clue about
2895
                    // the width of the embedded text.
2896
                    // Anyway, clients will ask only for tiles that overlaps
2897
                    // the visible area.
2898
                    // Remember that wsd expects int and that aEnd.X() is
2899
                    // in pixels and will be converted in twips, before performing
2900
                    // the lok callback, so we need to avoid that an overflow occurs.
2901
0
                    aEnd.setX( std::numeric_limits<int>::max() / 1000 );
2902
0
                }
2903
0
                else
2904
0
                {
2905
0
                    aEnd.setX( bLayoutRTL ? 0 : pGridWin[i]->GetOutputSizePixel().Width() );
2906
0
                }
2907
0
            }
2908
0
        }
2909
0
        aEnd.AdjustX( -nLayoutSign );
2910
0
        aEnd.AdjustY( -1 );
2911
2912
        // #i85232# include area below cells (could be done in GetScrPos?)
2913
0
        if ( eMode == ScUpdateMode::All && nRow2 >= rDoc.MaxRow() && !bIsTiledRendering )
2914
0
            aEnd.setY( pGridWin[i]->GetOutputSizePixel().Height() );
2915
2916
0
        aStart.AdjustX( -nLayoutSign );      // include change marks
2917
0
        aStart.AdjustY( -1 );
2918
2919
0
        bool bMarkClipped = ScModule::get()->GetColorConfig().GetColorValue(svtools::CALCTEXTOVERFLOW).bIsVisible;
2920
0
        if (bMarkClipped)
2921
0
        {
2922
            // ScColumn::IsEmptyData has to be optimized for this
2923
            //  (switch to Search() )
2924
            //!if ( nCol1 > 0 && !aViewData.GetDocument()->IsBlockEmpty(
2925
            //!                     0, nRow1, nCol1-1, nRow2.
2926
            //!                     aViewData.CurrentTabForData() ) )
2927
0
            tools::Long nMarkPixel = static_cast<tools::Long>( SC_CLIPMARK_SIZE * aViewData.GetPPTX() );
2928
0
            aStart.AdjustX( -(nMarkPixel * nLayoutSign) );
2929
0
        }
2930
2931
0
        pGridWin[i]->Invalidate( pGridWin[i]->PixelToLogic( tools::Rectangle( aStart,aEnd ) ) );
2932
0
    }
2933
2934
    // #i79909# Calling UpdateAllOverlays here isn't necessary and would lead to overlay calls from a timer,
2935
    // with a wrong MapMode if editing in a cell (reference input).
2936
    // #i80499# Overlays need updates in a lot of cases, e.g. changing row/column size,
2937
    // or showing/hiding outlines. TODO: selections in inactive windows are vanishing.
2938
    // #i84689# With relative conditional formats, PaintArea may be called often (for each changed cell),
2939
    // so UpdateAllOverlays was moved to ScTabViewShell::Notify and is called only if PaintPartFlags::Left/PaintPartFlags::Top
2940
    // is set (width or height changed).
2941
0
}
2942
2943
void ScTabView::PaintRangeFinderEntry (const ScRangeFindData* pData, const SCTAB nTab)
2944
0
{
2945
0
    ScRange aRef = pData->aRef;
2946
0
    aRef.PutInOrder();                 // PutInOrder for the queries below
2947
2948
0
    if ( aRef.aStart == aRef.aEnd )     //! ignore sheet?
2949
0
        aViewData.GetDocument().ExtendMerge(aRef);
2950
2951
0
    if (aRef.aStart.Tab() < nTab || aRef.aEnd.Tab() > nTab)
2952
0
        return;
2953
2954
0
    SCCOL nCol1 = aRef.aStart.Col();
2955
0
    SCROW nRow1 = aRef.aStart.Row();
2956
0
    SCCOL nCol2 = aRef.aEnd.Col();
2957
0
    SCROW nRow2 = aRef.aEnd.Row();
2958
2959
    //  remove -> repaint
2960
    //  ScUpdateMode::Marks: Invalidate, nothing until end of row
2961
2962
0
    bool bHiddenEdge = false;
2963
0
    SCROW nTmp;
2964
0
    ScDocument& rDoc = aViewData.GetDocument();
2965
0
    while ( nCol1 > 0 && rDoc.ColHidden(nCol1, nTab) )
2966
0
    {
2967
0
        --nCol1;
2968
0
        bHiddenEdge = true;
2969
0
    }
2970
0
    while ( nCol2 < rDoc.MaxCol() && rDoc.ColHidden(nCol2, nTab) )
2971
0
    {
2972
0
        ++nCol2;
2973
0
        bHiddenEdge = true;
2974
0
    }
2975
0
    nTmp = rDoc.LastVisibleRow(0, nRow1, nTab);
2976
0
    if (!rDoc.ValidRow(nTmp))
2977
0
        nTmp = 0;
2978
0
    if (nTmp < nRow1)
2979
0
    {
2980
0
        nRow1 = nTmp;
2981
0
        bHiddenEdge = true;
2982
0
    }
2983
0
    nTmp = rDoc.FirstVisibleRow(nRow2, rDoc.MaxRow(), nTab);
2984
0
    if (!rDoc.ValidRow(nTmp))
2985
0
        nTmp = rDoc.MaxRow();
2986
0
    if (nTmp > nRow2)
2987
0
    {
2988
0
        nRow2 = nTmp;
2989
0
        bHiddenEdge = true;
2990
0
    }
2991
2992
0
    if ( nCol2 - nCol1 > 1 && nRow2 - nRow1 > 1 && !bHiddenEdge )
2993
0
    {
2994
        // only along the edges
2995
0
        PaintArea( nCol1, nRow1, nCol2, nRow1, ScUpdateMode::Marks );
2996
0
        PaintArea( nCol1, nRow1+1, nCol1, nRow2-1, ScUpdateMode::Marks );
2997
0
        PaintArea( nCol2, nRow1+1, nCol2, nRow2-1, ScUpdateMode::Marks );
2998
0
        PaintArea( nCol1, nRow2, nCol2, nRow2, ScUpdateMode::Marks );
2999
0
    }
3000
0
    else    // all in one
3001
0
        PaintArea( nCol1, nRow1, nCol2, nRow2, ScUpdateMode::Marks );
3002
0
}
3003
3004
void ScTabView::PaintRangeFinder( tools::Long nNumber )
3005
0
{
3006
0
    ScInputHandler* pHdl = ScModule::get()->GetInputHdl(aViewData.GetViewShell());
3007
0
    if (!pHdl)
3008
0
        return;
3009
3010
0
    ScRangeFindList* pRangeFinder = pHdl->GetRangeFindList();
3011
0
    if ( !(pRangeFinder && pRangeFinder->GetDocName() == aViewData.GetDocShell().GetTitle()) )
3012
0
        return;
3013
3014
0
    SCTAB nTab = aViewData.CurrentTabForData();
3015
0
    sal_uInt16 nCount = static_cast<sal_uInt16>(pRangeFinder->Count());
3016
3017
0
    if (nNumber < 0)
3018
0
    {
3019
0
        for (sal_uInt16 i=0; i<nCount; i++)
3020
0
            PaintRangeFinderEntry(&pRangeFinder->GetObject(i),nTab);
3021
0
    }
3022
0
    else
3023
0
    {
3024
0
        sal_uInt16 idx = nNumber;
3025
0
        if (idx < nCount)
3026
0
            PaintRangeFinderEntry(&pRangeFinder->GetObject(idx),nTab);
3027
0
    }
3028
0
}
3029
3030
// for chart data selection
3031
3032
void ScTabView::AddHighlightRange( const ScRange& rRange, const Color& rColor )
3033
0
{
3034
0
    maHighlightRanges.emplace_back( rRange, rColor );
3035
3036
0
    SCTAB nTab = aViewData.CurrentTabForData();
3037
0
    if ( nTab >= rRange.aStart.Tab() && nTab <= rRange.aEnd.Tab() )
3038
0
        PaintArea( rRange.aStart.Col(), rRange.aStart.Row(),
3039
0
                    rRange.aEnd.Col(), rRange.aEnd.Row(), ScUpdateMode::Marks );
3040
0
}
3041
3042
void ScTabView::ClearHighlightRanges()
3043
0
{
3044
0
    SCTAB nTab = aViewData.CurrentTabForData();
3045
0
    for (ScHighlightEntry const & rEntry : maHighlightRanges)
3046
0
    {
3047
0
        ScRange aRange = rEntry.aRef;
3048
0
        if ( nTab >= aRange.aStart.Tab() && nTab <= aRange.aEnd.Tab() )
3049
0
            PaintArea( aRange.aStart.Col(), aRange.aStart.Row(),
3050
0
                       aRange.aEnd.Col(), aRange.aEnd.Row(), ScUpdateMode::Marks );
3051
0
    }
3052
3053
0
    maHighlightRanges.clear();
3054
0
}
3055
3056
void ScTabView::DoChartSelection(
3057
    const uno::Sequence< chart2::data::HighlightedRange > & rHilightRanges )
3058
0
{
3059
0
    ClearHighlightRanges();
3060
0
    const sal_Unicode sep = ::formula::FormulaCompiler::GetNativeSymbolChar(ocSep);
3061
0
    size_t nSize = 0;
3062
0
    size_t nIndex = 0;
3063
0
    std::vector<ReferenceMark> aReferenceMarks( nSize );
3064
3065
0
    for (chart2::data::HighlightedRange const & rHighlightedRange : rHilightRanges)
3066
0
    {
3067
0
        Color aSelColor(ColorTransparency, rHighlightedRange.PreferredColor);
3068
0
        ScRangeList aRangeList;
3069
0
        ScDocument& rDoc = aViewData.GetDocShell().GetDocument();
3070
0
        if( ScRangeStringConverter::GetRangeListFromString(
3071
0
                aRangeList, rHighlightedRange.RangeRepresentation, rDoc, rDoc.GetAddressConvention(), sep ))
3072
0
        {
3073
0
            size_t nListSize = aRangeList.size();
3074
0
            nSize += nListSize;
3075
0
            aReferenceMarks.resize(nSize);
3076
3077
0
            for ( size_t j = 0; j < nListSize; ++j )
3078
0
            {
3079
0
                ScRange& p = aRangeList[j];
3080
0
                ScRange aTargetRange;
3081
0
                if( rHighlightedRange.Index == - 1 )
3082
0
                {
3083
0
                    aTargetRange = p;
3084
0
                    AddHighlightRange( aTargetRange, aSelColor );
3085
0
                }
3086
0
                else
3087
0
                {
3088
0
                    aTargetRange = lcl_getSubRangeByIndex( p, rHighlightedRange.Index );
3089
0
                    AddHighlightRange( aTargetRange, aSelColor );
3090
0
                }
3091
3092
0
                if ( comphelper::LibreOfficeKit::isActive() && aViewData.GetViewShell() )
3093
0
                {
3094
0
                    aTargetRange.PutInOrder();
3095
3096
0
                    tools::Long nX1 = aTargetRange.aStart.Col();
3097
0
                    tools::Long nX2 = aTargetRange.aEnd.Col();
3098
0
                    tools::Long nY1 = aTargetRange.aStart.Row();
3099
0
                    tools::Long nY2 = aTargetRange.aEnd.Row();
3100
0
                    tools::Long nTab = aTargetRange.aStart.Tab();
3101
3102
0
                    aReferenceMarks[nIndex++] = ScInputHandler::GetReferenceMark( aViewData, aViewData.GetDocShell(),
3103
0
                                                                            nX1, nX2, nY1, nY2,
3104
0
                                                                            nTab, aSelColor );
3105
0
                }
3106
0
            }
3107
0
        }
3108
0
    }
3109
3110
0
    if ( comphelper::LibreOfficeKit::isActive() && aViewData.GetViewShell() )
3111
0
        ScInputHandler::SendReferenceMarks( aViewData.GetViewShell(), aReferenceMarks );
3112
0
}
3113
3114
void ScTabView::DoDPFieldPopup(std::u16string_view rPivotTableName, sal_Int32 nDimensionIndex, Point aPoint, Size aSize)
3115
0
{
3116
0
    ScDocument& rDocument = aViewData.GetDocShell().GetDocument();
3117
0
    ScGridWindow* pWin = pGridWin[aViewData.GetActivePart()].get();
3118
3119
0
    if (!pWin)
3120
0
        return;
3121
3122
0
    ScDPCollection* pDPCollection = rDocument.GetDPCollection();
3123
0
    ScDPObject* pDPObject = pDPCollection->GetByName(rPivotTableName);
3124
0
    if (!pDPObject)
3125
0
        return;
3126
3127
0
    pDPObject->BuildAllDimensionMembers();
3128
3129
0
    Point aPos = pWin->LogicToPixel(aPoint);
3130
0
    bool bLOK = comphelper::LibreOfficeKit::isActive();
3131
0
    Point aScreenPoint = bLOK ? aPos : pWin->OutputToScreenPixel(aPos);
3132
0
    Size aScreenSize = pWin->LogicToPixel(aSize);
3133
3134
0
    pWin->DPLaunchFieldPopupMenu(aScreenPoint, aScreenSize, nDimensionIndex, pDPObject);
3135
0
}
3136
3137
//  PaintGrid - repaint data range
3138
3139
void ScTabView::PaintGrid()
3140
0
{
3141
0
    for (sal_uInt16 i = 0; i < 4; i++)
3142
0
    {
3143
0
        if (pGridWin[i] && pGridWin[i]->IsVisible())
3144
0
            pGridWin[i]->Invalidate();
3145
0
    }
3146
0
}
3147
3148
//  PaintTop - repaint top control elements
3149
3150
void ScTabView::PaintTop()
3151
0
{
3152
0
    for (sal_uInt16 i = 0; i < 2; i++)
3153
0
    {
3154
0
        if (pColBar[i])
3155
0
            pColBar[i]->Invalidate();
3156
0
        if (pColOutline[i])
3157
0
            pColOutline[i]->Invalidate();
3158
0
    }
3159
0
}
3160
3161
void ScTabView::CreateAnchorHandles(SdrHdlList& rHdl, const ScAddress& rAddress)
3162
0
{
3163
0
    for (sal_uInt16 i = 0; i < 4; i++)
3164
0
    {
3165
0
        if(pGridWin[i] && pGridWin[i]->IsVisible())
3166
0
            pGridWin[i]->CreateAnchorHandle(rHdl, rAddress);
3167
0
    }
3168
0
}
3169
3170
void ScTabView::PaintTopArea( SCCOL nStartCol, SCCOL nEndCol )
3171
0
{
3172
        // pixel position of the left edge
3173
3174
0
    if ( nStartCol < aViewData.GetPosX(SC_SPLIT_LEFT) ||
3175
0
         nStartCol < aViewData.GetPosX(SC_SPLIT_RIGHT) )
3176
0
        aViewData.RecalcPixPos();
3177
3178
        // adjust freeze (UpdateFixX resets HSplitPos)
3179
3180
0
    if ( aViewData.GetHSplitMode() == SC_SPLIT_FIX && nStartCol < aViewData.GetFixPosX() )
3181
0
        if (aViewData.UpdateFixX())
3182
0
            RepeatResize();
3183
3184
        // paint
3185
3186
0
    if (nStartCol>0)
3187
0
        --nStartCol;                //! general ?
3188
3189
0
    ScDocument& rDoc = aViewData.GetDocument();
3190
0
    bool bLayoutRTL = rDoc.IsLayoutRTL( aViewData.CurrentTabForData() );
3191
0
    tools::Long nLayoutSign = bLayoutRTL ? -1 : 1;
3192
3193
0
    for (sal_uInt16 i = 0; i < 2; i++)
3194
0
    {
3195
0
        ScHSplitPos eWhich = ScHSplitPos(i);
3196
0
        if (pColBar[eWhich])
3197
0
        {
3198
0
            Size aWinSize = pColBar[eWhich]->GetSizePixel();
3199
0
            tools::Long nStartX = aViewData.GetScrPos( nStartCol, 0, eWhich ).X();
3200
0
            tools::Long nEndX;
3201
0
            if (nEndCol >= rDoc.MaxCol())
3202
0
                nEndX = bLayoutRTL ? 0 : ( aWinSize.Width()-1 );
3203
0
            else
3204
0
                nEndX = aViewData.GetScrPos( nEndCol+1, 0, eWhich ).X() - nLayoutSign;
3205
0
            if (nStartX > nEndX)
3206
0
                std::swap(nStartX, nEndX);
3207
0
            pColBar[eWhich]->Invalidate(
3208
0
                    tools::Rectangle( nStartX, 0, nEndX, aWinSize.Height()-1 ) );
3209
0
        }
3210
0
        if (pColOutline[eWhich])
3211
0
            pColOutline[eWhich]->Invalidate();
3212
0
    }
3213
0
}
3214
3215
//  PaintLeft - repaint left control elements
3216
3217
void ScTabView::PaintLeft()
3218
0
{
3219
0
    for (sal_uInt16 i = 0; i < 2; i++)
3220
0
    {
3221
0
        if (pRowBar[i])
3222
0
            pRowBar[i]->Invalidate();
3223
0
        if (pRowOutline[i])
3224
0
            pRowOutline[i]->Invalidate();
3225
0
    }
3226
0
}
3227
3228
void ScTabView::PaintLeftArea( SCROW nStartRow, SCROW nEndRow )
3229
0
{
3230
        // pixel position of the upper edge
3231
3232
0
    if ( nStartRow < aViewData.GetPosY(SC_SPLIT_TOP) ||
3233
0
         nStartRow < aViewData.GetPosY(SC_SPLIT_BOTTOM) )
3234
0
        aViewData.RecalcPixPos();
3235
3236
        // adjust freeze (UpdateFixY reset VSplitPos)
3237
3238
0
    if ( aViewData.GetVSplitMode() == SC_SPLIT_FIX && nStartRow < aViewData.GetFixPosY() )
3239
0
        if (aViewData.UpdateFixY())
3240
0
            RepeatResize();
3241
3242
        // paint
3243
3244
0
    if (nStartRow>0)
3245
0
        --nStartRow;
3246
3247
0
    ScDocument& rDoc = aViewData.GetDocument();
3248
0
    for (sal_uInt16 i = 0; i < 2; i++)
3249
0
    {
3250
0
        ScVSplitPos eWhich = ScVSplitPos(i);
3251
0
        if (pRowBar[eWhich])
3252
0
        {
3253
0
            Size aWinSize = pRowBar[eWhich]->GetSizePixel();
3254
0
            tools::Long nStartY = aViewData.GetScrPos( 0, nStartRow, eWhich ).Y();
3255
0
            tools::Long nEndY;
3256
0
            if (nEndRow >= rDoc.MaxRow())
3257
0
                nEndY = aWinSize.Height() - 1;
3258
0
            else
3259
0
                nEndY = aViewData.GetScrPos( 0, nEndRow+1, eWhich ).Y() - 1;
3260
0
            if (nStartY > nEndY)
3261
0
                std::swap(nStartY, nEndY);
3262
0
            pRowBar[eWhich]->Invalidate(
3263
0
                    tools::Rectangle( 0, nStartY, aWinSize.Width()-1, nEndY ) );
3264
0
        }
3265
0
        if (pRowOutline[eWhich])
3266
0
            pRowOutline[eWhich]->Invalidate();
3267
0
    }
3268
0
}
3269
3270
bool ScTabView::PaintExtras()
3271
0
{
3272
0
    bool bRet = false;
3273
0
    ScDocument& rDoc = aViewData.GetDocument();
3274
0
    SCTAB nTab = aViewData.CurrentTabForData();
3275
0
    if (!rDoc.HasTable(nTab))                  // sheet is deleted?
3276
0
    {
3277
0
        SCTAB nCount = rDoc.GetTableCount();
3278
0
        aViewData.SetTabNo(nCount-1);
3279
0
        bRet = true;
3280
0
    }
3281
0
    pTabControl->UpdateStatus();                        // true = active
3282
0
    return bRet;
3283
0
}
3284
3285
void ScTabView::RecalcPPT()
3286
0
{
3287
    //  called after changes that require the PPT values to be recalculated
3288
    //  (currently from detective operations)
3289
3290
0
    double nOldX = aViewData.GetPPTX();
3291
0
    double nOldY = aViewData.GetPPTY();
3292
3293
0
    aViewData.RefreshZoom();                            // pre-calculate new PPT values
3294
3295
0
    bool bChangedX = ( aViewData.GetPPTX() != nOldX );
3296
0
    bool bChangedY = ( aViewData.GetPPTY() != nOldY );
3297
0
    if ( !(bChangedX || bChangedY) )
3298
0
        return;
3299
3300
    //  call view SetZoom (including draw scale, split update etc)
3301
    //  and paint only if values changed
3302
3303
0
    Fraction aZoomX = aViewData.GetZoomX();
3304
0
    Fraction aZoomY = aViewData.GetZoomY();
3305
0
    SetZoom( aZoomX, aZoomY, false );
3306
3307
0
    PaintGrid();
3308
0
    if (bChangedX)
3309
0
        PaintTop();
3310
0
    if (bChangedY)
3311
0
        PaintLeft();
3312
0
}
3313
3314
void ScTabView::ActivateView( bool bActivate, bool bFirst )
3315
0
{
3316
0
    if ( bActivate == aViewData.IsActive() && !bFirst )
3317
0
    {
3318
        // no assertion anymore - occurs when previously in Drag&Drop switching over
3319
        // to another document
3320
0
        return;
3321
0
    }
3322
3323
    // is only called for MDI-(De)Activate
3324
    // aViewData.Activate behind due to cursor show for KillEditView
3325
    // don't delete selection - if Activate(false) is set in ViewData,
3326
    // then the selection is not displayed
3327
3328
0
    if (!bActivate)
3329
0
    {
3330
0
        ScModule* pScMod = ScModule::get();
3331
0
        bool bRefMode = pScMod->IsFormulaMode();
3332
3333
            // don't cancel reference input, to allow reference
3334
            // to other document
3335
3336
0
        if (!bRefMode)
3337
0
        {
3338
            // pass view to GetInputHdl, this view may not be current anymore
3339
0
            ScInputHandler* pHdl = pScMod->GetInputHdl(aViewData.GetViewShell());
3340
0
            if (pHdl)
3341
0
                pHdl->EnterHandler();
3342
0
        }
3343
0
    }
3344
3345
0
    PaintExtras();
3346
3347
0
    aViewData.Activate(bActivate);
3348
3349
0
    PaintBlock(false);                  // repaint, selection after active status
3350
3351
0
    if (!bActivate)
3352
0
        HideAllCursors();               // Cursor
3353
0
    else if (!bFirst)
3354
0
        ShowAllCursors();
3355
3356
0
    if (bActivate)
3357
0
    {
3358
0
        if ( bFirst )
3359
0
        {
3360
0
            ScSplitPos eWin = aViewData.GetActivePart();
3361
0
            OSL_ENSURE( pGridWin[eWin], "Corrupted document, not all SplitPos in GridWin" );
3362
0
            if ( !pGridWin[eWin] )
3363
0
            {
3364
0
                eWin = SC_SPLIT_BOTTOMLEFT;
3365
0
                if ( !pGridWin[eWin] )
3366
0
                {
3367
0
                    short i;
3368
0
                    for ( i=0; i<4; i++ )
3369
0
                    {
3370
0
                        if ( pGridWin[i] )
3371
0
                        {
3372
0
                            eWin = static_cast<ScSplitPos>(i);
3373
0
                            break;  // for
3374
0
                        }
3375
0
                    }
3376
0
                    OSL_ENSURE( i<4, "and BOOM" );
3377
0
                }
3378
0
                aViewData.SetActivePart( eWin );
3379
0
            }
3380
0
        }
3381
        // do not call GrabFocus from here!
3382
        // if the document is processed, then Sfx calls GrabFocus in the window of the shell.
3383
        // if it is a mail body for instance, then it can't get the focus
3384
0
        UpdateInputContext();
3385
0
    }
3386
0
    else
3387
0
        pGridWin[aViewData.GetActivePart()]->ClickExtern();
3388
0
}
3389
3390
void ScTabView::ActivatePart( ScSplitPos eWhich )
3391
0
{
3392
0
    ScSplitPos eOld = aViewData.GetActivePart();
3393
0
    if ( eOld == eWhich )
3394
0
        return;
3395
3396
0
    bInActivatePart = true;
3397
3398
0
    bool bRefMode = ScModule::get()->IsFormulaMode();
3399
3400
    //  the HasEditView call during SetCursor would fail otherwise
3401
0
    if ( aViewData.HasEditView(eOld) && !bRefMode )
3402
0
        UpdateInputLine();
3403
3404
0
    ScHSplitPos eOldH = WhichH(eOld);
3405
0
    ScVSplitPos eOldV = WhichV(eOld);
3406
0
    ScHSplitPos eNewH = WhichH(eWhich);
3407
0
    ScVSplitPos eNewV = WhichV(eWhich);
3408
0
    bool bTopCap  = pColBar[eOldH] && pColBar[eOldH]->IsMouseCaptured();
3409
0
    bool bLeftCap = pRowBar[eOldV] && pRowBar[eOldV]->IsMouseCaptured();
3410
3411
0
    bool bFocus = pGridWin[eOld]->HasFocus();
3412
0
    bool bCapture = pGridWin[eOld]->IsMouseCaptured();
3413
0
    if (bCapture)
3414
0
        pGridWin[eOld]->ReleaseMouse();
3415
0
    pGridWin[eOld]->ClickExtern();
3416
0
    pGridWin[eOld]->HideCursor();
3417
0
    pGridWin[eWhich]->HideCursor();
3418
0
    aViewData.SetActivePart( eWhich );
3419
3420
0
    ScTabViewShell* pShell = aViewData.GetViewShell();
3421
0
    pShell->WindowChanged();
3422
3423
0
    pSelEngine->SetWindow(pGridWin[eWhich]);
3424
0
    pSelEngine->SetWhich(eWhich);
3425
0
    pSelEngine->SetVisibleArea( tools::Rectangle(Point(), pGridWin[eWhich]->GetOutputSizePixel()) );
3426
3427
0
    pGridWin[eOld]->MoveMouseStatus(*pGridWin[eWhich]);
3428
3429
0
    if ( bCapture || pGridWin[eWhich]->IsMouseCaptured() )
3430
0
    {
3431
        // tracking instead of CaptureMouse, so it can be cancelled cleanly
3432
        // (SelectionEngine calls CaptureMouse for SetWindow)
3433
        //! someday SelectionEngine itself should call StartTracking!?!
3434
0
        pGridWin[eWhich]->ReleaseMouse();
3435
0
        pGridWin[eWhich]->StartTracking();
3436
0
    }
3437
3438
0
    if ( bTopCap && pColBar[eNewH] )
3439
0
    {
3440
0
        pColBar[eOldH]->SetIgnoreMove(true);
3441
0
        pColBar[eNewH]->SetIgnoreMove(false);
3442
0
        pHdrSelEng->SetWindow( pColBar[eNewH] );
3443
0
        tools::Long nWidth = pColBar[eNewH]->GetOutputSizePixel().Width();
3444
0
        pHdrSelEng->SetVisibleArea( tools::Rectangle( 0, LONG_MIN, nWidth-1, LONG_MAX ) );
3445
0
        pColBar[eNewH]->CaptureMouse();
3446
0
    }
3447
0
    if ( bLeftCap && pRowBar[eNewV] )
3448
0
    {
3449
0
        pRowBar[eOldV]->SetIgnoreMove(true);
3450
0
        pRowBar[eNewV]->SetIgnoreMove(false);
3451
0
        pHdrSelEng->SetWindow( pRowBar[eNewV] );
3452
0
        tools::Long nHeight = pRowBar[eNewV]->GetOutputSizePixel().Height();
3453
0
        pHdrSelEng->SetVisibleArea( tools::Rectangle( LONG_MIN, 0, LONG_MAX, nHeight-1 ) );
3454
0
        pRowBar[eNewV]->CaptureMouse();
3455
0
    }
3456
0
    aHdrFunc.SetWhich(eWhich);
3457
3458
0
    pGridWin[eOld]->ShowCursor();
3459
0
    pGridWin[eWhich]->ShowCursor();
3460
3461
0
    SfxInPlaceClient* pClient = aViewData.GetViewShell()->GetIPClient();
3462
0
    bool bOleActive = ( pClient && pClient->IsObjectInPlaceActive() );
3463
3464
    // don't switch ViewShell's active window during RefInput, because the focus
3465
    // might change, and subsequent SetReference calls wouldn't find the right EditView
3466
0
    if ( !bRefMode && !bOleActive )
3467
0
        aViewData.GetViewShell()->SetWindow( pGridWin[eWhich] );
3468
3469
0
    if ( bFocus && !aViewData.IsAnyFillMode() && !bRefMode )
3470
0
    {
3471
        // GrabFocus only if previously the other GridWindow had the focus
3472
        // (for instance due to search and replace)
3473
0
        pGridWin[eWhich]->GrabFocus();
3474
0
    }
3475
3476
0
    bInActivatePart = false;
3477
0
}
3478
3479
void ScTabView::HideListBox()
3480
0
{
3481
0
    for (VclPtr<ScGridWindow> & pWin : pGridWin)
3482
0
    {
3483
0
        if (pWin)
3484
0
            pWin->ClickExtern();
3485
0
    }
3486
0
}
3487
3488
void ScTabView::UpdateInputContext()
3489
0
{
3490
0
    ScGridWindow* pWin = pGridWin[aViewData.GetActivePart()].get();
3491
0
    if (pWin)
3492
0
        pWin->UpdateInputContext();
3493
3494
0
    if (pTabControl)
3495
0
        pTabControl->UpdateInputContext();
3496
0
}
3497
3498
// GetGridWidth - width of an output range (for ViewData)
3499
3500
tools::Long ScTabView::GetGridWidth( ScHSplitPos eWhich )
3501
0
{
3502
    // at present only the size of the current pane is synchronized with
3503
    // the size of the visible area in Online;
3504
    // as a workaround we use the same width for all panes independently
3505
    // from the eWhich value
3506
0
    if (comphelper::LibreOfficeKit::isActive())
3507
0
    {
3508
0
        ScGridWindow* pGridWindow = aViewData.GetActiveWin();
3509
0
        if (pGridWindow)
3510
0
            return pGridWindow->GetSizePixel().Width();
3511
0
    }
3512
3513
0
    ScSplitPos eGridWhich = ( eWhich == SC_SPLIT_LEFT ) ? SC_SPLIT_BOTTOMLEFT : SC_SPLIT_BOTTOMRIGHT;
3514
0
    if (pGridWin[eGridWhich])
3515
0
        return pGridWin[eGridWhich]->GetSizePixel().Width();
3516
0
    else
3517
0
        return 0;
3518
0
}
3519
3520
// GetGridHeight - height of an output range (for ViewData)
3521
3522
tools::Long ScTabView::GetGridHeight( ScVSplitPos eWhich )
3523
0
{
3524
    // at present only the size of the current pane is synchronized with
3525
    // the size of the visible area in Online;
3526
    // as a workaround we use the same height for all panes independently
3527
    // from the eWhich value
3528
0
    if (comphelper::LibreOfficeKit::isActive())
3529
0
    {
3530
0
        ScGridWindow* pGridWindow = aViewData.GetActiveWin();
3531
0
        if (pGridWindow)
3532
0
            return pGridWindow->GetSizePixel().Height();
3533
0
    }
3534
3535
0
    ScSplitPos eGridWhich = ( eWhich == SC_SPLIT_TOP ) ? SC_SPLIT_TOPLEFT : SC_SPLIT_BOTTOMLEFT;
3536
0
    if (pGridWin[eGridWhich])
3537
0
        return pGridWin[eGridWhich]->GetSizePixel().Height();
3538
0
    else
3539
0
        return 0;
3540
0
}
3541
3542
void ScTabView::UpdateInputLine()
3543
0
{
3544
0
    ScModule::get()->InputEnterHandler();
3545
0
}
3546
3547
void ScTabView::SyncGridWindowMapModeFromDrawMapMode()
3548
0
{
3549
    // AW: Discussed with NN if there is a reason that new map mode was only set for one window,
3550
    // but is not. Setting only on one window causes the first repaint to have the old mapMode
3551
    // in three of four views, so the overlay will save the wrong content e.g. when zooming out.
3552
    // Changing to setting map mode at all windows.
3553
0
    for (VclPtr<ScGridWindow> & pWin : pGridWin)
3554
0
    {
3555
0
        if (!pWin)
3556
0
            continue;
3557
0
        pWin->SetMapMode(pWin->GetDrawMapMode());
3558
0
    }
3559
0
}
3560
3561
void ScTabView::ZoomChanged()
3562
0
{
3563
0
    ScInputHandler* pHdl = ScModule::get()->GetInputHdl(aViewData.GetViewShell());
3564
0
    if (pHdl)
3565
0
        pHdl->SetRefScale( aViewData.GetZoomX(), aViewData.GetZoomY() );
3566
3567
0
    UpdateFixPos();
3568
3569
0
    UpdateScrollBars();
3570
3571
0
    SyncGridWindowMapModeFromDrawMapMode();
3572
3573
    // VisArea...
3574
0
    SetNewVisArea();
3575
3576
0
    InterpretVisible();     // have everything calculated before painting
3577
3578
0
    SfxBindings& rBindings = aViewData.GetBindings();
3579
0
    rBindings.Invalidate( SID_ATTR_ZOOM );
3580
0
    rBindings.Invalidate( SID_ATTR_ZOOMSLIDER );
3581
0
    rBindings.Invalidate(SID_ZOOM_IN);
3582
0
    rBindings.Invalidate(SID_ZOOM_OUT);
3583
3584
0
    HideNoteOverlay();
3585
3586
    // To not change too much, use pWin here
3587
0
    ScGridWindow* pWin = pGridWin[aViewData.GetActivePart()].get();
3588
3589
0
    if ( pWin && aViewData.HasEditView( aViewData.GetActivePart() ) )
3590
0
    {
3591
        // make sure the EditView's position and size are updated
3592
        // with the right (logic, not drawing) MapMode
3593
0
        pWin->SetMapMode( aViewData.GetLogicMode() );
3594
0
        UpdateEditView();
3595
0
    }
3596
0
}
3597
3598
void ScTabView::CheckNeedsRepaint()
3599
0
{
3600
0
    for (sal_uInt16 i = 0; i < 4; i++)
3601
0
    {
3602
0
        if (pGridWin[i] && pGridWin[i]->IsVisible())
3603
0
            pGridWin[i]->CheckNeedsRepaint();
3604
0
    }
3605
0
}
3606
3607
bool ScTabView::NeedsRepaint()
3608
0
{
3609
0
    for (VclPtr<ScGridWindow> & pWin : pGridWin)
3610
0
    {
3611
0
        if (pWin && pWin->IsVisible() && pWin->NeedsRepaint())
3612
0
            return true;
3613
0
    }
3614
0
    return false;
3615
0
}
3616
3617
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */