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/preview.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 <scitems.hxx>
21
#include <editeng/eeitem.hxx>
22
23
#include <officecfg/Office/Common.hxx>
24
#include <svtools/colorcfg.hxx>
25
#include <svx/fmview.hxx>
26
#include <editeng/sizeitem.hxx>
27
#include <svx/svdpagv.hxx>
28
#include <sfx2/bindings.hxx>
29
#include <sfx2/viewfrm.hxx>
30
#include <sfx2/dispatch.hxx>
31
#include <svl/itemset.hxx>
32
#include <tools/multisel.hxx>
33
#include <vcl/commandevent.hxx>
34
#include <vcl/settings.hxx>
35
#include <o3tl/deleter.hxx>
36
#include <o3tl/unit_conversion.hxx>
37
38
#include <preview.hxx>
39
#include <prevwsh.hxx>
40
#include <prevloc.hxx>
41
#include <docsh.hxx>
42
#include <docfunc.hxx>
43
#include <printfun.hxx>
44
#include <printopt.hxx>
45
#include <stlpool.hxx>
46
#include <undostyl.hxx>
47
#include <drwlayer.hxx>
48
#include <scmod.hxx>
49
#include <markdata.hxx>
50
#include <globstr.hrc>
51
#include <scresid.hxx>
52
#include <sc.hrc>
53
#include <helpids.h>
54
#include <AccessibleDocumentPagePreview.hxx>
55
#include <editeng/lrspitem.hxx>
56
#include <editeng/ulspitem.hxx>
57
#include <editeng/colritem.hxx>
58
#include <editeng/fhgtitem.hxx>
59
#include <com/sun/star/accessibility/XAccessible.hpp>
60
#include <AccessibilityHints.hxx>
61
#include <vcl/svapp.hxx>
62
#include <viewutil.hxx>
63
#include <patattr.hxx>
64
#include <columnspanset.hxx>
65
66
#include <memory>
67
68
0
#define SC_PREVIEW_SHADOWSIZE   2
69
70
static tools::Long lcl_GetDisplayStart( SCTAB nTab, const ScDocument* pDoc, std::vector<tools::Long>& nPages )
71
0
{
72
0
    tools::Long nDisplayStart = 0;
73
0
    for (SCTAB i=0; i<nTab; i++)
74
0
    {
75
0
        if ( pDoc->NeedPageResetAfterTab(i) )
76
0
            nDisplayStart = 0;
77
0
        else
78
0
            nDisplayStart += nPages[i];
79
0
    }
80
0
    return nDisplayStart;
81
0
}
82
83
ScPreview::ScPreview( vcl::Window* pParent, ScDocShell* pDocSh, ScPreviewShell* pViewSh ) :
84
0
    Window( pParent ),
85
0
    nPageNo( 0 ),
86
0
    nZoom( 100 ),
87
0
    nTabCount( 0 ),
88
0
    nTabsTested( 0 ),
89
0
    nTab( 0 ),
90
0
    nTabPage( 0 ),
91
0
    nTabStart( 0 ),
92
0
    nDisplayStart( 0 ),
93
0
    aDateTime( DateTime::SYSTEM ),
94
0
    nTotalPages( 0 ),
95
0
    pDocShell( pDocSh ),
96
0
    pViewShell( pViewSh ),
97
0
    bInGetState( false ),
98
0
    bValid( false ),
99
0
    bStateValid( false ),
100
0
    bLocationValid( false ),
101
0
    bInPaint( false ),
102
0
    bInSetZoom( false ),
103
0
    bLeftRulerMove( false ),
104
0
    bRightRulerMove( false ),
105
0
    bTopRulerMove( false ),
106
0
    bBottomRulerMove( false ),
107
0
    bHeaderRulerMove( false ),
108
0
    bFooterRulerMove( false ),
109
0
    bLeftRulerChange( false ),
110
0
    bRightRulerChange( false ),
111
0
    bTopRulerChange( false ),
112
0
    bBottomRulerChange( false ),
113
0
    bHeaderRulerChange( false ),
114
0
    bFooterRulerChange( false ),
115
0
    bPageMargin ( false ),
116
0
    bColRulerMove( false ),
117
0
    mbHasEmptyRangeTable(false),
118
0
    nLeftPosition( 0 ),
119
0
    mnScale( 0 ),
120
0
    nColNumberButtonDown( 0 ),
121
0
    nHeaderHeight ( 0 ),
122
0
    nFooterHeight ( 0 )
123
0
{
124
0
    GetOutDev()->SetOutDevViewType( OutDevViewType::PrintPreview );
125
0
    SetBackground();
126
127
0
    SetHelpId( HID_SC_WIN_PREVIEW );
128
129
0
    GetOutDev()->SetDigitLanguage( ScModule::GetOptDigitLanguage() );
130
0
}
Unexecuted instantiation: ScPreview::ScPreview(vcl::Window*, ScDocShell*, ScPreviewShell*)
Unexecuted instantiation: ScPreview::ScPreview(vcl::Window*, ScDocShell*, ScPreviewShell*)
131
132
ScPreview::~ScPreview()
133
0
{
134
0
    disposeOnce();
135
0
}
136
137
void ScPreview::dispose()
138
0
{
139
0
    pDrawView.reset();
140
0
    pLocationData.reset();
141
0
    vcl::Window::dispose();
142
0
}
143
144
void ScPreview::UpdateDrawView()        // nTab must be right
145
0
{
146
0
    ScDocument& rDoc = pDocShell->GetDocument();
147
0
    ScDrawLayer* pModel = rDoc.GetDrawLayer();     // is not 0
148
149
0
    if ( pModel )
150
0
    {
151
0
        SdrPage* pPage = pModel->GetPage(nTab);
152
0
        if ( pDrawView && ( !pDrawView->GetSdrPageView() || pDrawView->GetSdrPageView()->GetPage() != pPage ) )
153
0
        {
154
            // convert the displayed Page of drawView (see below) does not work?!?
155
0
            pDrawView.reset();
156
0
        }
157
158
0
        if ( !pDrawView )                                   // New Drawing?
159
0
        {
160
0
            pDrawView.reset( new FmFormView( *pModel, GetOutDev()) );
161
162
            // The DrawView takes over the Design-Mode from the Model
163
            // (Settings "In opening Draftmode"), therefore to restore here
164
0
            pDrawView->SetDesignMode();
165
0
            pDrawView->SetPrintPreview();
166
0
            pDrawView->ShowSdrPage(pPage);
167
0
        }
168
0
    }
169
0
    else if ( pDrawView )
170
0
    {
171
0
        pDrawView.reset();   // for this Chart is not needed
172
0
    }
173
0
}
174
175
void ScPreview::TestLastPage()
176
0
{
177
0
    if (nPageNo < nTotalPages)
178
0
        return;
179
180
0
    if (nTotalPages)
181
0
    {
182
0
        nPageNo = nTotalPages - 1;
183
0
        nTab = static_cast<SCTAB>(nPages.size()) -1;
184
0
        while (nTab > 0 && !nPages[nTab])       // not the last empty Table
185
0
            --nTab;
186
0
        OSL_ENSURE(0 < static_cast<SCTAB>(nPages.size()),"are all tables empty?");
187
0
        nTabPage = nPages[nTab] - 1;
188
0
        nTabStart = 0;
189
0
        for (sal_uInt16 i=0; i<nTab; i++)
190
0
            nTabStart += nPages[i];
191
192
0
        ScDocument& rDoc = pDocShell->GetDocument();
193
0
        nDisplayStart = lcl_GetDisplayStart( nTab, &rDoc, nPages );
194
0
    }
195
0
    else        // empty Document
196
0
    {
197
0
        nTab = 0;
198
0
        nPageNo = nTabPage = nTabStart = nDisplayStart = 0;
199
0
        aState = ScPrintState();
200
0
    }
201
0
}
202
203
void ScPreview::CalcPages()
204
0
{
205
0
    weld::WaitObject aWait(GetFrameWeld());
206
207
0
    ScDocument& rDoc = pDocShell->GetDocument();
208
0
    nTabCount = rDoc.GetTableCount();
209
210
0
    if (maSelectedTabs.empty())
211
0
    {
212
0
        SCTAB nCurrentTab = ScDocShell::GetCurTab();
213
0
        maSelectedTabs.insert(nCurrentTab);
214
0
    }
215
216
0
    SCTAB nStart = nTabsTested;
217
0
    if (!bValid)
218
0
    {
219
0
        nStart = 0;
220
0
        nTotalPages = 0;
221
0
        nTabsTested = 0;
222
0
    }
223
224
    // update all pending row heights with a single progress bar,
225
    // instead of a separate progress for each sheet from ScPrintFunc
226
0
    pDocShell->UpdatePendingRowHeights( nTabCount-1, true );
227
228
    //  PrintOptions is passed to PrintFunc for SkipEmpty flag,
229
    //  but always all sheets are used (there is no selected sheet)
230
0
    ScPrintOptions aOptions = ScModule::get()->GetPrintOptions();
231
232
0
    while (nStart > static_cast<SCTAB>(nPages.size()))
233
0
        nPages.push_back(0);
234
0
    while (nStart > static_cast<SCTAB>(nFirstAttr.size()))
235
0
        nFirstAttr.push_back(1);
236
237
0
    for (SCTAB i=nStart; i<nTabCount; i++)
238
0
    {
239
0
        if ( i == static_cast<SCTAB>(nPages.size()))
240
0
            nPages.push_back(0);
241
0
        if ( i == static_cast<SCTAB>(nFirstAttr.size()))
242
0
            nFirstAttr.push_back(1);
243
0
        if (!aOptions.GetAllSheets() && maSelectedTabs.count(i) == 0)
244
0
        {
245
0
            nPages[i] = 0;
246
0
            nFirstAttr[i] = 1;
247
0
            continue;
248
0
        }
249
250
0
        tools::Long nAttrPage = i > 0 ? nFirstAttr[i-1] : 1;
251
252
0
        tools::Long nThisStart = nTotalPages;
253
0
        ScPrintFunc aPrintFunc( GetOutDev(), *pDocShell, i, nAttrPage, 0, nullptr, &aOptions );
254
0
        tools::Long nThisTab = aPrintFunc.GetTotalPages();
255
0
        if (!aPrintFunc.HasPrintRange())
256
0
            mbHasEmptyRangeTable = true;
257
258
0
        nPages[i] = nThisTab;
259
0
        nTotalPages += nThisTab;
260
0
        nFirstAttr[i] = aPrintFunc.GetFirstPageNo();    // to keep or from template
261
262
0
        if (nPageNo>=nThisStart && nPageNo<nTotalPages)
263
0
        {
264
0
            nTab = i;
265
0
            nTabPage = nPageNo - nThisStart;
266
0
            nTabStart = nThisStart;
267
268
0
            aPrintFunc.GetPrintState( aState );
269
0
        }
270
0
    }
271
272
0
    nDisplayStart = lcl_GetDisplayStart( nTab, &rDoc, nPages );
273
274
0
    if (nTabCount > nTabsTested)
275
0
        nTabsTested = nTabCount;
276
277
0
    TestLastPage();
278
279
0
    aState.nDocPages = nTotalPages;
280
281
0
    bValid = true;
282
0
    bStateValid = true;
283
0
    DoInvalidate();
284
0
}
285
286
void ScPreview::RecalcPages()           // only nPageNo is changed
287
0
{
288
0
    if (!bValid)
289
0
        return;                         // then CalcPages is called
290
291
0
    SCTAB nOldTab = nTab;
292
293
0
    bool bDone = false;
294
0
    while (nPageNo >= nTotalPages && nTabsTested < nTabCount)
295
0
    {
296
0
        CalcPages();
297
0
        bDone = true;
298
0
    }
299
300
0
    if (!bDone)
301
0
    {
302
0
        tools::Long nPartPages = 0;
303
0
        for (SCTAB i=0; i<nTabsTested && nTab < static_cast<SCTAB>(nPages.size()); i++)
304
0
        {
305
0
            tools::Long nThisStart = nPartPages;
306
0
            nPartPages += nPages[i];
307
308
0
            if (nPageNo>=nThisStart && nPageNo<nPartPages)
309
0
            {
310
0
                nTab = i;
311
0
                nTabPage = nPageNo - nThisStart;
312
0
                nTabStart = nThisStart;
313
0
            }
314
0
        }
315
316
0
        ScDocument& rDoc = pDocShell->GetDocument();
317
0
        nDisplayStart = lcl_GetDisplayStart( nTab, &rDoc, nPages );
318
0
    }
319
320
0
    TestLastPage();         // to test, if after last page
321
322
0
    if ( nTab != nOldTab )
323
0
        bStateValid = false;
324
325
0
    DoInvalidate();
326
0
}
327
328
void ScPreview::DoPrint( ScPreviewLocationData* pFillLocation )
329
0
{
330
0
    if (!bValid)
331
0
    {
332
0
        CalcPages();
333
0
        RecalcPages();
334
0
        UpdateDrawView();       // Spreadsheet eventually changes
335
0
    }
336
337
0
    Fraction aPreviewZoom( nZoom, 100 );
338
0
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
339
0
    MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
340
341
0
    bool bDoPrint = ( pFillLocation == nullptr );
342
0
    bool bValidPage = ( nPageNo < nTotalPages );
343
344
0
    ScModule* pScMod = ScModule::get();
345
0
    const svtools::ColorConfig& rColorCfg = pScMod->GetColorConfig();
346
0
    Color aBackColor( rColorCfg.GetColorValue(svtools::APPBACKGROUND).nColor );
347
348
0
    if ( bDoPrint && ( aOffset.X() < 0 || aOffset.Y() < 0 ) && bValidPage )
349
0
    {
350
0
        SetMapMode( aMMMode );
351
0
        GetOutDev()->SetLineColor();
352
0
        GetOutDev()->SetFillColor(aBackColor);
353
354
0
        Size aWinSize = GetOutDev()->GetOutputSize();
355
0
        if ( aOffset.X() < 0 )
356
0
            GetOutDev()->DrawRect(tools::Rectangle( 0, 0, -aOffset.X(), aWinSize.Height() ));
357
0
        if ( aOffset.Y() < 0 )
358
0
            GetOutDev()->DrawRect(tools::Rectangle( 0, 0, aWinSize.Width(), -aOffset.Y() ));
359
0
    }
360
361
0
    tools::Long   nLeftMargin = 0;
362
0
    tools::Long   nRightMargin = 0;
363
0
    tools::Long   nTopMargin = 0;
364
0
    tools::Long   nBottomMargin = 0;
365
0
    bool   bHeaderOn = false;
366
0
    bool   bFooterOn = false;
367
368
0
    ScDocument& rDoc = pDocShell->GetDocument();
369
0
    bool   bLayoutRTL = rDoc.IsLayoutRTL( nTab );
370
371
0
    Size aLocalPageSize;
372
0
    if ( bValidPage )
373
0
    {
374
0
        ScPrintOptions aOptions = pScMod->GetPrintOptions();
375
376
0
        std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
377
0
        if (bStateValid)
378
0
            pPrintFunc.reset(new ScPrintFunc(GetOutDev(), *pDocShell, aState, &aOptions));
379
0
        else
380
0
            pPrintFunc.reset(new ScPrintFunc(GetOutDev(), *pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions));
381
382
0
        pPrintFunc->SetOffset(aOffset);
383
0
        pPrintFunc->SetManualZoom(nZoom);
384
0
        pPrintFunc->SetDateTime(aDateTime);
385
0
        pPrintFunc->SetClearFlag(true);
386
0
        pPrintFunc->SetUseStyleColor(false); // tdf#101142 print preview should use a white background
387
388
0
        pPrintFunc->SetDrawView( pDrawView.get() );
389
390
        // MultiSelection for the one Page must produce something inconvenient
391
0
        Range aPageRange( nPageNo+1, nPageNo+1 );
392
0
        MultiSelection aPage( aPageRange );
393
0
        aPage.SetTotalRange( Range(0,RANGE_MAX) );
394
0
        aPage.Select( aPageRange );
395
396
0
        tools::Long nPrinted = pPrintFunc->DoPrint( aPage, nTabStart, nDisplayStart, bDoPrint, pFillLocation );
397
0
        OSL_ENSURE(nPrinted<=1, "What is happening?");
398
399
0
        SetMapMode(aMMMode);
400
401
        //init nLeftMargin ... in the ScPrintFunc::InitParam!!!
402
0
        nLeftMargin = pPrintFunc->GetLeftMargin();
403
0
        nRightMargin = pPrintFunc->GetRightMargin();
404
0
        nTopMargin = pPrintFunc->GetTopMargin();
405
0
        nBottomMargin = pPrintFunc->GetBottomMargin();
406
0
        nHeaderHeight = pPrintFunc->GetHeader().nHeight;
407
0
        nFooterHeight = pPrintFunc->GetFooter().nHeight;
408
0
        bHeaderOn = pPrintFunc->GetHeader().bEnable;
409
0
        bFooterOn = pPrintFunc->GetFooter().bEnable;
410
0
        mnScale = pPrintFunc->GetZoom();
411
412
0
        if ( bDoPrint && bPageMargin && pLocationData )     // don't make use of pLocationData while filling it
413
0
        {
414
0
            tools::Rectangle aPixRect;
415
0
            tools::Rectangle aRectCellPosition;
416
0
            tools::Rectangle aRectPosition;
417
0
            pLocationData->GetMainCellRange( aPageArea, aPixRect );
418
0
            mvRight.resize(aPageArea.aEnd.Col()+1);
419
0
            if( !bLayoutRTL )
420
0
            {
421
0
                aRectPosition = pLocationData->GetCellPosition(aPageArea.aStart);
422
0
                nLeftPosition = aRectPosition.Left();
423
0
                for( SCCOL i = aPageArea.aStart.Col(); i <= aPageArea.aEnd.Col(); i++ )
424
0
                {
425
0
                    aRectCellPosition = pLocationData->GetCellPosition(
426
0
                        ScAddress(i, aPageArea.aStart.Row(), aPageArea.aStart.Tab()));
427
0
                    mvRight[i] = aRectCellPosition.Right();
428
0
                }
429
0
            }
430
0
            else
431
0
            {
432
0
                aRectPosition = pLocationData->GetCellPosition(aPageArea.aEnd);
433
0
                nLeftPosition = aRectPosition.Right()+1;
434
435
0
                aRectCellPosition = pLocationData->GetCellPosition(aPageArea.aStart);
436
0
                mvRight[ aPageArea.aEnd.Col() ] = aRectCellPosition.Left();
437
0
                for( SCCOL i = aPageArea.aEnd.Col(); i > aPageArea.aStart.Col(); i-- )
438
0
                {
439
0
                    aRectCellPosition = pLocationData->GetCellPosition(
440
0
                        ScAddress(i, aPageArea.aEnd.Row(), aPageArea.aEnd.Tab()));
441
0
                    mvRight[ i-1 ] = mvRight[ i ] + aRectCellPosition.Right() - aRectCellPosition.Left() + 1;
442
0
                }
443
0
            }
444
0
        }
445
446
0
        if (nPrinted)   // if not, draw everything grey
447
0
        {
448
0
            aLocalPageSize = pPrintFunc->GetPageSize();
449
0
            aLocalPageSize.setWidth(
450
0
                o3tl::convert(aLocalPageSize.Width(), o3tl::Length::twip, o3tl::Length::mm100));
451
0
            aLocalPageSize.setHeight(
452
0
                o3tl::convert(aLocalPageSize.Height(), o3tl::Length::twip, o3tl::Length::mm100));
453
454
0
            nLeftMargin = o3tl::convert(nLeftMargin, o3tl::Length::twip, o3tl::Length::mm100);
455
0
            nRightMargin = o3tl::convert(nRightMargin, o3tl::Length::twip, o3tl::Length::mm100);
456
0
            nTopMargin = o3tl::convert(nTopMargin, o3tl::Length::twip, o3tl::Length::mm100);
457
0
            nBottomMargin = o3tl::convert(nBottomMargin, o3tl::Length::twip, o3tl::Length::mm100);
458
0
            constexpr auto md = o3tl::getConversionMulDiv(o3tl::Length::twip, o3tl::Length::mm10);
459
0
            const auto m = md.first * mnScale, d = md.second * 100;
460
0
            nHeaderHeight = o3tl::convert(nHeaderHeight, m, d) + nTopMargin;
461
0
            nFooterHeight = o3tl::convert(nFooterHeight, m, d) + nBottomMargin;
462
0
        }
463
464
0
        if (!bStateValid)
465
0
        {
466
0
            pPrintFunc->GetPrintState( aState );
467
0
            aState.nDocPages = nTotalPages;
468
0
            bStateValid = true;
469
0
        }
470
0
    }
471
472
0
    if ( !bDoPrint )
473
0
        return;
474
475
0
    tools::Long nPageEndX = aLocalPageSize.Width()  - aOffset.X();
476
0
    tools::Long nPageEndY = aLocalPageSize.Height() - aOffset.Y();
477
0
    if ( !bValidPage )
478
0
        nPageEndX = nPageEndY = 0;
479
480
0
    Size aWinSize = GetOutDev()->GetOutputSize();
481
0
    Point aWinEnd( aWinSize.Width(), aWinSize.Height() );
482
0
    bool bRight  = nPageEndX <= aWinEnd.X();
483
0
    bool bBottom = nPageEndY <= aWinEnd.Y();
484
485
0
    if (!nTotalPages)
486
0
    {
487
        // There is no data to print. Print a friendly warning message and
488
        // bail out.
489
490
0
        SetMapMode(aMMMode);
491
492
        // Draw background first.
493
0
        GetOutDev()->SetLineColor();
494
0
        GetOutDev()->SetFillColor(aBackColor);
495
0
        GetOutDev()->DrawRect(tools::Rectangle(0, 0, aWinEnd.X(), aWinEnd.Y()));
496
497
0
        const ScPatternAttr& rDefPattern(rDoc.getCellAttributeHelper().getDefaultCellAttribute());
498
499
0
        std::unique_ptr<ScEditEngineDefaulter> pEditEng(
500
0
            new ScEditEngineDefaulter(EditEngine::CreatePool().get(), true));
501
502
0
        pEditEng->SetRefMapMode(aMMMode);
503
0
        SfxItemSet aEditDefaults( pEditEng->GetEmptyItemSet() );
504
0
        rDefPattern.FillEditItemSet(&aEditDefaults);
505
0
        aEditDefaults.Put(SvxColorItem(COL_LIGHTGRAY, EE_CHAR_COLOR));
506
0
        pEditEng->SetDefaults(std::move(aEditDefaults));
507
508
0
        OUString aEmptyMsg;
509
0
        if (mbHasEmptyRangeTable)
510
0
            aEmptyMsg = ScResId(STR_PRINT_PREVIEW_EMPTY_RANGE);
511
0
        else
512
0
            aEmptyMsg = ScResId(STR_PRINT_PREVIEW_NODATA);
513
514
0
        tools::Long nHeight = 3000;
515
0
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT));
516
0
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CJK));
517
0
        pEditEng->SetDefaultItem(SvxFontHeightItem(nHeight, 100, EE_CHAR_FONTHEIGHT_CTL));
518
519
0
        pEditEng->SetTextCurrentDefaults(aEmptyMsg);
520
521
0
        Point aCenter(
522
0
            (aWinEnd.X() - pEditEng->CalcTextWidth())/2,
523
0
            (aWinEnd.Y() - pEditEng->GetTextHeight())/2);
524
525
0
        pEditEng->DrawText_ToPosition(*GetOutDev(), aCenter);
526
527
0
        return;
528
0
    }
529
530
0
    if( bPageMargin && bValidPage )
531
0
    {
532
0
        SetMapMode(aMMMode);
533
0
        GetOutDev()->SetLineColor( COL_BLACK );
534
0
        DrawInvert( static_cast<tools::Long>( nTopMargin - aOffset.Y() ), PointerStyle::VSizeBar );
535
0
        DrawInvert( static_cast<tools::Long>(nPageEndY - nBottomMargin ), PointerStyle::VSizeBar );
536
0
        DrawInvert( static_cast<tools::Long>( nLeftMargin - aOffset.X() ), PointerStyle::HSizeBar );
537
0
        DrawInvert( static_cast<tools::Long>( nPageEndX - nRightMargin ) , PointerStyle::HSizeBar );
538
0
        if( bHeaderOn )
539
0
        {
540
0
            DrawInvert( nHeaderHeight - aOffset.Y(), PointerStyle::VSizeBar );
541
0
        }
542
0
        if( bFooterOn )
543
0
        {
544
0
            DrawInvert( nPageEndY - nFooterHeight, PointerStyle::VSizeBar );
545
0
        }
546
547
0
        SetMapMode( MapMode( MapUnit::MapPixel ) );
548
0
        for( int i= aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
549
0
        {
550
0
            Point aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
551
0
            GetOutDev()->SetLineColor( COL_BLACK );
552
0
            GetOutDev()->SetFillColor( COL_BLACK );
553
0
            GetOutDev()->DrawRect( tools::Rectangle( Point( mvRight[i] - 2, aColumnTop.Y() ),Point( mvRight[i] + 2 , 4 + aColumnTop.Y()) ));
554
0
            GetOutDev()->DrawLine( Point( mvRight[i], aColumnTop.Y() ), Point( mvRight[i],  10 + aColumnTop.Y()) );
555
0
        }
556
0
        SetMapMode( aMMMode );
557
0
    }
558
559
0
    if (bRight || bBottom)
560
0
    {
561
0
        SetMapMode(aMMMode);
562
0
        GetOutDev()->SetLineColor();
563
0
        GetOutDev()->SetFillColor(aBackColor);
564
0
        if (bRight)
565
0
            GetOutDev()->DrawRect(tools::Rectangle(nPageEndX,0, aWinEnd.X(),aWinEnd.Y()));
566
0
        if (bBottom)
567
0
        {
568
0
            if (bRight)
569
0
                GetOutDev()->DrawRect(tools::Rectangle(0,nPageEndY, nPageEndX,aWinEnd.Y()));    // Corner not duplicated
570
0
            else
571
0
                GetOutDev()->DrawRect(tools::Rectangle(0,nPageEndY, aWinEnd.X(),aWinEnd.Y()));
572
0
        }
573
0
    }
574
575
0
    if ( !bValidPage )
576
0
        return;
577
578
0
    Color aBorderColor(ScModule::get()->GetColorConfig().GetColorValue(svtools::FONTCOLOR).nColor);
579
580
    //  draw border
581
582
0
    if ( aOffset.X() <= 0 || aOffset.Y() <= 0 || bRight || bBottom )
583
0
    {
584
0
        GetOutDev()->SetLineColor( aBorderColor );
585
0
        GetOutDev()->SetFillColor();
586
587
0
        tools::Rectangle aPixel( LogicToPixel( tools::Rectangle( -aOffset.X(), -aOffset.Y(), nPageEndX, nPageEndY ) ) );
588
0
        aPixel.AdjustRight( -1 );
589
0
        aPixel.AdjustBottom( -1 );
590
0
        GetOutDev()->DrawRect( PixelToLogic( aPixel ) );
591
0
    }
592
593
    //  draw shadow
594
595
0
    GetOutDev()->SetLineColor();
596
0
    GetOutDev()->SetFillColor( aBorderColor );
597
598
0
    tools::Rectangle aPixel;
599
600
0
    aPixel = LogicToPixel( tools::Rectangle( nPageEndX, -aOffset.Y(), nPageEndX, nPageEndY ) );
601
0
    aPixel.AdjustTop(SC_PREVIEW_SHADOWSIZE );
602
0
    aPixel.AdjustRight(SC_PREVIEW_SHADOWSIZE - 1 );
603
0
    aPixel.AdjustBottom(SC_PREVIEW_SHADOWSIZE - 1 );
604
0
    GetOutDev()->DrawRect( PixelToLogic( aPixel ) );
605
606
0
    aPixel = LogicToPixel( tools::Rectangle( -aOffset.X(), nPageEndY, nPageEndX, nPageEndY ) );
607
0
    aPixel.AdjustLeft(SC_PREVIEW_SHADOWSIZE );
608
0
    aPixel.AdjustRight(SC_PREVIEW_SHADOWSIZE - 1 );
609
0
    aPixel.AdjustBottom(SC_PREVIEW_SHADOWSIZE - 1 );
610
0
    GetOutDev()->DrawRect( PixelToLogic( aPixel ) );
611
0
}
612
613
void ScPreview::Paint( vcl::RenderContext& /*rRenderContext*/, const tools::Rectangle& /* rRect */ )
614
0
{
615
0
    bool bWasInPaint = bInPaint;        // nested calls shouldn't be necessary, but allow for now
616
0
    bInPaint = true;
617
618
0
    if (bPageMargin)
619
0
        GetLocationData();              // fill location data for column positions
620
0
    DoPrint( nullptr );
621
0
    pViewShell->UpdateScrollBars();
622
623
0
    bInPaint = bWasInPaint;
624
0
}
625
626
void ScPreview::Command( const CommandEvent& rCEvt )
627
0
{
628
0
    CommandEventId nCmd = rCEvt.GetCommand();
629
0
    if ( nCmd == CommandEventId::Wheel || nCmd == CommandEventId::StartAutoScroll || nCmd == CommandEventId::AutoScroll )
630
0
    {
631
0
        bool bDone = pViewShell->ScrollCommand( rCEvt );
632
0
        if (!bDone)
633
0
            Window::Command(rCEvt);
634
0
    }
635
0
    else if ( nCmd == CommandEventId::ContextMenu )
636
0
        SfxDispatcher::ExecutePopup();
637
0
    else
638
0
        Window::Command( rCEvt );
639
0
}
640
641
void ScPreview::KeyInput( const KeyEvent& rKEvt )
642
0
{
643
    //  The + and - keys can't be configured as accelerator entries, so they must be handled directly
644
    //  (in ScPreview, not ScPreviewShell -> only if the preview window has the focus)
645
646
0
    const vcl::KeyCode& rKeyCode = rKEvt.GetKeyCode();
647
0
    sal_uInt16 nKey = rKeyCode.GetCode();
648
0
    bool bHandled = false;
649
0
    if(!rKeyCode.GetModifier())
650
0
    {
651
0
        sal_uInt16 nSlot = 0;
652
0
        switch(nKey)
653
0
        {
654
0
            case KEY_ADD:      nSlot = SID_ZOOM_IN;  break;
655
0
            case KEY_ESCAPE:   nSlot = ScViewUtil::IsFullScreen( *pViewShell ) ? SID_CANCEL : SID_PREVIEW_CLOSE; break;
656
0
            case KEY_SUBTRACT: nSlot = SID_ZOOM_OUT; break;
657
0
        }
658
0
        if(nSlot)
659
0
        {
660
0
            bHandled = true;
661
0
            pViewShell->GetViewFrame().GetDispatcher()->Execute( nSlot, SfxCallMode::ASYNCHRON );
662
0
        }
663
0
    }
664
665
0
    if ( !bHandled && !pViewShell->KeyInput(rKEvt) )
666
0
        Window::KeyInput(rKEvt);
667
0
}
668
669
const ScPreviewLocationData& ScPreview::GetLocationData()
670
0
{
671
0
    if ( !pLocationData )
672
0
    {
673
0
        pLocationData.reset( new ScPreviewLocationData( &pDocShell->GetDocument(), GetOutDev() ) );
674
0
        bLocationValid = false;
675
0
    }
676
0
    if ( !bLocationValid )
677
0
    {
678
0
        pLocationData->Clear();
679
0
        DoPrint( pLocationData.get() );
680
0
        bLocationValid = true;
681
0
    }
682
0
    return *pLocationData;
683
0
}
684
685
void ScPreview::DataChanged(bool bNewTime)
686
0
{
687
0
    if (bNewTime)
688
0
        aDateTime = DateTime( DateTime::SYSTEM );
689
690
0
    bValid = false;
691
0
    InvalidateLocationData( SfxHintId::ScDataChanged );
692
0
    Invalidate();
693
0
}
694
695
OUString ScPreview::GetPosString()
696
0
{
697
0
    if (!bValid)
698
0
    {
699
0
        CalcPages();
700
0
        UpdateDrawView();       // The table eventually changes
701
0
    }
702
703
0
    OUString aString = ScResId( STR_PAGE ) +
704
0
                       " " + OUString::number(nPageNo+1);
705
706
0
    if (nTabsTested >= nTabCount)
707
0
        aString += " / " + OUString::number(nTotalPages);
708
709
0
    return aString;
710
0
}
711
712
void ScPreview::SetZoom(sal_uInt16 nNewZoom)
713
0
{
714
0
    if (nNewZoom < 20)
715
0
        nNewZoom = 20;
716
0
    if (nNewZoom > 400)
717
0
        nNewZoom = 400;
718
0
    if (nNewZoom == nZoom)
719
0
        return;
720
721
0
    nZoom = nNewZoom;
722
723
    //  apply new MapMode and call UpdateScrollBars to update aOffset
724
725
0
    Fraction aPreviewZoom( nZoom, 100 );
726
0
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
727
0
    MapMode aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
728
0
    SetMapMode( aMMMode );
729
730
0
    bInSetZoom = true;              // don't scroll during SetYOffset in UpdateScrollBars
731
0
    pViewShell->UpdateNeededScrollBars(true);
732
0
    bInSetZoom = false;
733
734
0
    InvalidateLocationData( SfxHintId::ScAccVisAreaChanged );
735
0
    DoInvalidate();
736
0
    Invalidate();
737
0
}
738
739
void ScPreview::SetPageNo( tools::Long nPage )
740
0
{
741
0
    nPageNo = nPage;
742
0
    RecalcPages();
743
0
    UpdateDrawView();       // The table eventually changes
744
0
    InvalidateLocationData( SfxHintId::ScDataChanged );
745
0
    Invalidate();
746
0
}
747
748
tools::Long ScPreview::GetFirstPage(SCTAB nTabP)
749
0
{
750
0
    SCTAB nDocTabCount = pDocShell->GetDocument().GetTableCount();
751
0
    if (nTabP >= nDocTabCount)
752
0
        nTabP = nDocTabCount-1;
753
754
0
    tools::Long nPage = 0;
755
0
    if (nTabP>0)
756
0
    {
757
0
        CalcPages();
758
0
        if (nTabP >= static_cast<SCTAB>(nPages.size()) )
759
0
            OSL_FAIL("nPages out of bounds, FIX IT");
760
0
        UpdateDrawView();       // The table eventually changes
761
762
0
        for (SCTAB i=0; i<nTabP; i++)
763
0
            nPage += nPages[i];
764
765
        // An empty Table on the previous Page
766
767
0
        if ( nPages[nTabP]==0 && nPage > 0 )
768
0
            --nPage;
769
0
    }
770
771
0
    return nPage;
772
0
}
773
774
static Size lcl_GetDocPageSize( const ScDocument* pDoc, SCTAB nTab )
775
0
{
776
0
    OUString aName = pDoc->GetPageStyle( nTab );
777
0
    ScStyleSheetPool* pStylePool = pDoc->GetStyleSheetPool();
778
0
    SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aName, SfxStyleFamily::Page );
779
0
    if ( pStyleSheet )
780
0
    {
781
0
        SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
782
0
        return rStyleSet.Get(ATTR_PAGE_SIZE).GetSize();
783
0
    }
784
0
    else
785
0
    {
786
0
        OSL_FAIL( "PageStyle not found" );
787
0
        return Size();
788
0
    }
789
0
}
790
791
sal_uInt16 ScPreview::GetOptimalZoom(bool bWidthOnly)
792
0
{
793
0
    double nWinScaleX = ScGlobal::nScreenPPTX / pDocShell->GetOutputFactor();
794
0
    double nWinScaleY = ScGlobal::nScreenPPTY;
795
0
    Size aWinSize = GetOutputSizePixel();
796
797
    //  desired margin is 0.25cm in default MapMode (like Writer),
798
    //  but some additional margin is introduced by integer scale values
799
    //  -> add only 0.10cm, so there is some margin in all cases.
800
0
    Size aMarginSize( LogicToPixel(Size(100, 100), MapMode(MapUnit::Map100thMM)) );
801
0
    aWinSize.AdjustWidth( -(2 * aMarginSize.Width()) );
802
0
    aWinSize.AdjustHeight( -(2 * aMarginSize.Height()) );
803
804
0
    Size aLocalPageSize = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab );
805
0
    if ( aLocalPageSize.Width() && aLocalPageSize.Height() )
806
0
    {
807
0
        tools::Long nZoomX = static_cast<tools::Long>( aWinSize.Width() * 100  / ( aLocalPageSize.Width() * nWinScaleX ));
808
0
        tools::Long nZoomY = static_cast<tools::Long>( aWinSize.Height() * 100 / ( aLocalPageSize.Height() * nWinScaleY ));
809
810
0
        tools::Long nOptimal = nZoomX;
811
0
        if (!bWidthOnly && nZoomY<nOptimal)
812
0
            nOptimal = nZoomY;
813
814
0
        if (nOptimal<20)
815
0
            nOptimal = 20;
816
0
        if (nOptimal>400)
817
0
            nOptimal = 400;
818
819
0
        return static_cast<sal_uInt16>(nOptimal);
820
0
    }
821
0
    else
822
0
        return nZoom;
823
0
}
824
825
void ScPreview::SetXOffset( tools::Long nX )
826
0
{
827
0
    if ( aOffset.X() == nX )
828
0
        return;
829
830
0
    if (bValid)
831
0
    {
832
0
        tools::Long nDif = LogicToPixel(aOffset).X() - LogicToPixel(Point(nX,0)).X();
833
0
        aOffset.setX( nX );
834
0
        if (nDif && !bInSetZoom)
835
0
        {
836
0
            MapMode aOldMode = GetMapMode();
837
0
            SetMapMode(MapMode(MapUnit::MapPixel));
838
0
            Scroll( nDif, 0 );
839
0
            SetMapMode(aOldMode);
840
0
        }
841
0
    }
842
0
    else
843
0
    {
844
0
        aOffset.setX( nX );
845
0
        if (!bInSetZoom)
846
0
            Invalidate();
847
0
    }
848
0
    InvalidateLocationData( SfxHintId::ScAccVisAreaChanged );
849
0
    Invalidate();
850
0
}
851
852
void ScPreview::SetYOffset( tools::Long nY )
853
0
{
854
0
    if ( aOffset.Y() == nY )
855
0
        return;
856
857
0
    if (bValid)
858
0
    {
859
0
        tools::Long nDif = LogicToPixel(aOffset).Y() - LogicToPixel(Point(0,nY)).Y();
860
0
        aOffset.setY( nY );
861
0
        if (nDif && !bInSetZoom)
862
0
        {
863
0
            MapMode aOldMode = GetMapMode();
864
0
            SetMapMode(MapMode(MapUnit::MapPixel));
865
0
            Scroll( 0, nDif );
866
0
            SetMapMode(aOldMode);
867
0
        }
868
0
    }
869
0
    else
870
0
    {
871
0
        aOffset.setY( nY );
872
0
        if (!bInSetZoom)
873
0
            Invalidate();
874
0
    }
875
0
    InvalidateLocationData( SfxHintId::ScAccVisAreaChanged );
876
0
    Invalidate();
877
0
}
878
879
void ScPreview::DoInvalidate()
880
0
{
881
    //  If the whole GetState of the shell is called
882
    //  The Invalidate must come behind asynchronously
883
884
0
    if (bInGetState)
885
0
        Application::PostUserEvent( LINK( this, ScPreview, InvalidateHdl ), nullptr, true );
886
0
    else
887
0
        StaticInvalidate();     // Immediately
888
0
}
889
890
void ScPreview::StaticInvalidate()
891
0
{
892
    //  static method, because it's called asynchronously
893
    //  -> must use current viewframe
894
895
0
    SfxViewFrame* pViewFrm = SfxViewFrame::Current();
896
0
    if (!pViewFrm)
897
0
        return;
898
899
0
    SfxBindings& rBindings = pViewFrm->GetBindings();
900
0
    rBindings.Invalidate(SID_STATUS_DOCPOS);
901
0
    rBindings.Invalidate(FID_AUTO_CALC);
902
0
    rBindings.Invalidate(SID_ROWCOL_SELCOUNT);
903
0
    rBindings.Invalidate(SID_STATUS_PAGESTYLE);
904
0
    rBindings.Invalidate(SID_PREVIEW_PREVIOUS);
905
0
    rBindings.Invalidate(SID_PREVIEW_NEXT);
906
0
    rBindings.Invalidate(SID_PREVIEW_FIRST);
907
0
    rBindings.Invalidate(SID_PREVIEW_LAST);
908
0
    rBindings.Invalidate(SID_ATTR_ZOOM);
909
0
    rBindings.Invalidate(SID_ZOOM_IN);
910
0
    rBindings.Invalidate(SID_ZOOM_OUT);
911
0
    rBindings.Invalidate(SID_PREVIEW_SCALINGFACTOR);
912
0
    rBindings.Invalidate(SID_ATTR_ZOOMSLIDER);
913
0
}
914
915
IMPL_STATIC_LINK_NOARG( ScPreview, InvalidateHdl, void*, void )
916
0
{
917
0
    StaticInvalidate();
918
0
}
919
920
void ScPreview::DataChanged( const DataChangedEvent& rDCEvt )
921
0
{
922
0
    Window::DataChanged(rDCEvt);
923
924
0
    if ( !((rDCEvt.GetType() == DataChangedEventType::PRINTER) ||
925
0
         (rDCEvt.GetType() == DataChangedEventType::DISPLAY) ||
926
0
         (rDCEvt.GetType() == DataChangedEventType::FONTS) ||
927
0
         (rDCEvt.GetType() == DataChangedEventType::FONTSUBSTITUTION) ||
928
0
         ((rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
929
0
          (rDCEvt.GetFlags() & AllSettingsFlags::STYLE))) )
930
0
        return;
931
932
0
    if ( rDCEvt.GetType() == DataChangedEventType::FONTS )
933
0
        pDocShell->UpdateFontList();
934
935
    // #i114518# Paint of form controls may modify the window's settings.
936
    // Ignore the event if it is called from within Paint.
937
0
    if ( !bInPaint )
938
0
    {
939
0
        if ( rDCEvt.GetType() == DataChangedEventType::SETTINGS &&
940
0
              (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
941
0
        {
942
            //  scroll bar size may have changed
943
0
            pViewShell->InvalidateBorder();     // calls OuterResizePixel
944
0
        }
945
0
        Invalidate();
946
0
        InvalidateLocationData( SfxHintId::ScDataChanged );
947
0
    }
948
0
}
949
950
void ScPreview::MouseButtonDown( const MouseEvent& rMEvt )
951
0
{
952
0
    Fraction  aPreviewZoom( nZoom, 100 );
953
0
    Fraction  aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
954
0
    MapMode   aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
955
956
0
    aButtonDownChangePoint = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
957
0
    aButtonDownPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
958
959
0
    CaptureMouse();
960
961
0
    if( rMEvt.IsLeft() && GetPointer() == PointerStyle::HSizeBar )
962
0
    {
963
0
        SetMapMode( aMMMode );
964
0
        if( bLeftRulerChange )
965
0
        {
966
0
           DrawInvert( aButtonDownChangePoint.X(), PointerStyle::HSizeBar );
967
0
           bLeftRulerMove = true;
968
0
           bRightRulerMove = false;
969
0
        }
970
0
        else if( bRightRulerChange )
971
0
        {
972
0
           DrawInvert( aButtonDownChangePoint.X(), PointerStyle::HSizeBar );
973
0
           bLeftRulerMove = false;
974
0
           bRightRulerMove = true;
975
0
        }
976
0
    }
977
978
0
    if( rMEvt.IsLeft() && GetPointer() == PointerStyle::VSizeBar )
979
0
    {
980
0
        SetMapMode( aMMMode );
981
0
        if( bTopRulerChange )
982
0
        {
983
0
            DrawInvert( aButtonDownChangePoint.Y(), PointerStyle::VSizeBar );
984
0
            bTopRulerMove = true;
985
0
            bBottomRulerMove = false;
986
0
        }
987
0
        else if( bBottomRulerChange )
988
0
        {
989
0
            DrawInvert( aButtonDownChangePoint.Y(), PointerStyle::VSizeBar );
990
0
            bTopRulerMove = false;
991
0
            bBottomRulerMove = true;
992
0
        }
993
0
        else if( bHeaderRulerChange )
994
0
        {
995
0
            DrawInvert( aButtonDownChangePoint.Y(), PointerStyle::VSizeBar );
996
0
            bHeaderRulerMove = true;
997
0
            bFooterRulerMove = false;
998
0
        }
999
0
        else if( bFooterRulerChange )
1000
0
        {
1001
0
            DrawInvert( aButtonDownChangePoint.Y(), PointerStyle::VSizeBar );
1002
0
            bHeaderRulerMove = false;
1003
0
            bFooterRulerMove = true;
1004
0
        }
1005
0
    }
1006
1007
0
    if( !(rMEvt.IsLeft() && GetPointer() == PointerStyle::HSplit) )
1008
0
        return;
1009
1010
0
    Point  aNowPt = rMEvt.GetPosPixel();
1011
0
    SCCOL i = 0;
1012
0
    for( i = aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
1013
0
    {
1014
0
        if( aNowPt.X() < mvRight[i] + 2 && aNowPt.X() > mvRight[i] - 2 )
1015
0
        {
1016
0
            nColNumberButtonDown = i;
1017
0
            break;
1018
0
        }
1019
0
    }
1020
0
    if( i == aPageArea.aEnd.Col()+1 )
1021
0
        return;
1022
1023
0
    SetMapMode( aMMMode );
1024
0
    if( nColNumberButtonDown == aPageArea.aStart.Col() )
1025
0
        DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,PointerStyle::HSplit );
1026
0
    else
1027
0
        DrawInvert( PixelToLogic( Point( mvRight[ nColNumberButtonDown-1 ], 0 ),aMMMode ).X() ,PointerStyle::HSplit );
1028
1029
0
    DrawInvert( aButtonDownChangePoint.X(), PointerStyle::HSplit );
1030
0
    bColRulerMove = true;
1031
0
}
1032
1033
void ScPreview::MouseButtonUp( const MouseEvent& rMEvt )
1034
0
{
1035
0
        Fraction  aPreviewZoom( nZoom, 100 );
1036
0
        Fraction  aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1037
0
        MapMode   aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
1038
1039
0
        aButtonUpPt = PixelToLogic( rMEvt.GetPosPixel(),aMMMode );
1040
1041
0
        tools::Long  nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
1042
0
        tools::Long  nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();
1043
1044
0
        if( rMEvt.IsLeft() && GetPointer() == PointerStyle::HSizeBar )
1045
0
        {
1046
0
            SetPointer( PointerStyle::Arrow );
1047
1048
0
            ScDocument& rDoc = pDocShell->GetDocument();
1049
0
            OUString aOldName = rDoc.GetPageStyle( nTab );
1050
0
            bool bUndo = rDoc.IsUndoEnabled();
1051
0
            ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
1052
0
            SfxStyleSheetBase* pStyleSheet = pStylePool->Find( aOldName, SfxStyleFamily::Page );
1053
1054
0
            if ( pStyleSheet )
1055
0
            {
1056
0
                bool bMoveRulerAction= true;
1057
0
                ScStyleSaveData aOldData;
1058
0
                if( bUndo )
1059
0
                    aOldData.InitFromStyle( pStyleSheet );
1060
1061
0
                SfxItemSet&  rStyleSet = pStyleSheet->GetItemSet();
1062
1063
0
                SvxLRSpaceItem aLRItem = rStyleSet.Get( ATTR_LRSPACE );
1064
1065
0
                if(( bLeftRulerChange || bRightRulerChange ) && ( aButtonUpPt.X() <= ( 0 - aOffset.X() ) || aButtonUpPt.X() > o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X() ) )
1066
0
                {
1067
0
                    bMoveRulerAction = false;
1068
0
                    Invalidate(tools::Rectangle(0, 0, 10000, 10000));
1069
0
                }
1070
0
                else if (bLeftRulerChange
1071
0
                         && (o3tl::convert(aButtonUpPt.X(), o3tl::Length::mm100, o3tl::Length::twip)
1072
0
                             > nWidth - aLRItem.ResolveRight({})
1073
0
                                   - o3tl::convert(aOffset.X(), o3tl::Length::mm100,
1074
0
                                                   o3tl::Length::twip)))
1075
0
                {
1076
0
                    bMoveRulerAction = false;
1077
0
                    Invalidate(tools::Rectangle(0, 0, 10000, 10000));
1078
0
                }
1079
0
                else if (bRightRulerChange
1080
0
                         && (o3tl::convert(aButtonUpPt.X(), o3tl::Length::mm100, o3tl::Length::twip)
1081
0
                             < aLRItem.ResolveLeft({})
1082
0
                                   - o3tl::convert(aOffset.X(), o3tl::Length::mm100,
1083
0
                                                   o3tl::Length::twip)))
1084
0
                {
1085
0
                    bMoveRulerAction = false;
1086
0
                    Invalidate(tools::Rectangle(0, 0, 10000, 10000));
1087
0
                }
1088
0
                else if( aButtonDownPt.X() == aButtonUpPt.X() )
1089
0
                {
1090
0
                    bMoveRulerAction = false;
1091
0
                    DrawInvert( aButtonUpPt.X(), PointerStyle::HSizeBar );
1092
0
                }
1093
0
                if( bMoveRulerAction )
1094
0
                {
1095
0
                    ScDocShellModificator aModificator( *pDocShell );
1096
0
                    if( bLeftRulerChange && bLeftRulerMove )
1097
0
                    {
1098
0
                        aLRItem.SetLeft(SvxIndentValue::twips(
1099
0
                            o3tl::convert(aButtonUpPt.X(), o3tl::Length::mm100, o3tl::Length::twip)
1100
0
                            + o3tl::convert(aOffset.X(), o3tl::Length::mm100, o3tl::Length::twip)));
1101
0
                        rStyleSet.Put(aLRItem);
1102
0
                        pDocShell->SetModified();
1103
0
                    }
1104
0
                    else if( bRightRulerChange && bRightRulerMove )
1105
0
                    {
1106
0
                        aLRItem.SetRight(SvxIndentValue::twips(
1107
0
                            nWidth
1108
0
                            - o3tl::convert(aButtonUpPt.X(), o3tl::Length::mm100,
1109
0
                                            o3tl::Length::twip)
1110
0
                            - o3tl::convert(aOffset.X(), o3tl::Length::mm100, o3tl::Length::twip)));
1111
0
                        rStyleSet.Put( aLRItem );
1112
0
                        pDocShell->SetModified();
1113
0
                    }
1114
1115
0
                    ScStyleSaveData aNewData;
1116
0
                    aNewData.InitFromStyle( pStyleSheet );
1117
0
                    if( bUndo )
1118
0
                    {
1119
0
                        pDocShell->GetUndoManager()->AddUndoAction(
1120
0
                            std::make_unique<ScUndoModifyStyle>( *pDocShell, SfxStyleFamily::Page,
1121
0
                            aOldData, aNewData ) );
1122
0
                    }
1123
1124
0
                    if ( ValidTab( nTab ) )
1125
0
                    {
1126
0
                        ScPrintFunc aPrintFunc( GetOutDev(), *pDocShell, nTab );
1127
0
                        aPrintFunc.UpdatePages();
1128
0
                    }
1129
1130
0
                    tools::Rectangle aRect(0,0,10000,10000);
1131
0
                    Invalidate(aRect);
1132
0
                    aModificator.SetDocumentModified();
1133
0
                    bLeftRulerChange = false;
1134
0
                    bRightRulerChange = false;
1135
0
                }
1136
0
            }
1137
0
            bLeftRulerMove = false;
1138
0
            bRightRulerMove = false;
1139
0
        }
1140
1141
0
        if( rMEvt.IsLeft() && GetPointer() == PointerStyle::VSizeBar )
1142
0
        {
1143
0
            SetPointer( PointerStyle::Arrow );
1144
1145
0
            bool bMoveRulerAction = true;
1146
0
            if( ( bTopRulerChange || bBottomRulerChange || bHeaderRulerChange || bFooterRulerChange ) && ( aButtonUpPt.Y() <= ( 0 - aOffset.Y() ) || aButtonUpPt.Y() > o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) -aOffset.Y() ) )
1147
0
            {
1148
0
                bMoveRulerAction = false;
1149
0
                Invalidate(tools::Rectangle(0, 0, 10000, 10000));
1150
0
            }
1151
0
            else if( aButtonDownPt.Y() == aButtonUpPt.Y() )
1152
0
            {
1153
0
                bMoveRulerAction = false;
1154
0
                DrawInvert( aButtonUpPt.Y(), PointerStyle::VSizeBar );
1155
0
            }
1156
0
            if( bMoveRulerAction )
1157
0
            {
1158
0
                ScDocument& rDoc = pDocShell->GetDocument();
1159
0
                bool bUndo = rDoc.IsUndoEnabled();
1160
0
                ScStyleSheetPool* pStylePool = rDoc.GetStyleSheetPool();
1161
0
                SfxStyleSheetBase* pStyleSheet = pStylePool->Find( rDoc.GetPageStyle( nTab ), SfxStyleFamily::Page );
1162
0
                OSL_ENSURE( pStyleSheet, "PageStyle not found" );
1163
0
                if ( pStyleSheet )
1164
0
                {
1165
0
                    ScDocShellModificator aModificator( *pDocShell );
1166
0
                    ScStyleSaveData aOldData;
1167
0
                    if( bUndo )
1168
0
                        aOldData.InitFromStyle( pStyleSheet );
1169
1170
0
                    SfxItemSet& rStyleSet = pStyleSheet->GetItemSet();
1171
1172
0
                    SvxULSpaceItem aULItem = rStyleSet.Get( ATTR_ULSPACE );
1173
1174
0
                    if( bTopRulerMove && bTopRulerChange )
1175
0
                    {
1176
0
                        aULItem.SetUpperValue(o3tl::convert(aButtonUpPt.Y(), o3tl::Length::mm100, o3tl::Length::twip) + o3tl::convert(aOffset.Y(), o3tl::Length::mm100, o3tl::Length::twip));
1177
0
                        rStyleSet.Put( aULItem );
1178
0
                        pDocShell->SetModified();
1179
0
                    }
1180
0
                    else if( bBottomRulerMove && bBottomRulerChange )
1181
0
                    {
1182
0
                        aULItem.SetLowerValue(nHeight - o3tl::convert(aButtonUpPt.Y(), o3tl::Length::mm100, o3tl::Length::twip) - o3tl::convert(aOffset.Y(), o3tl::Length::mm100, o3tl::Length::twip));
1183
0
                        rStyleSet.Put( aULItem );
1184
0
                        pDocShell->SetModified();
1185
0
                    }
1186
0
                    else if( bHeaderRulerMove && bHeaderRulerChange )
1187
0
                    {
1188
0
                        if ( const SvxSetItem* pSetItem = rStyleSet.GetItemIfSet( ATTR_PAGE_HEADERSET, false ) )
1189
0
                        {
1190
0
                            const SfxItemSet& rHeaderSet = pSetItem->GetItemSet();
1191
0
                            Size  aHeaderSize = rHeaderSet.Get(ATTR_PAGE_SIZE).GetSize();
1192
0
                            aHeaderSize.setHeight(o3tl::convert( aButtonUpPt.Y(), o3tl::Length::mm100, o3tl::Length::twip) + o3tl::convert(aOffset.Y(), o3tl::Length::mm100, o3tl::Length::twip) - aULItem.GetUpper());
1193
0
                            aHeaderSize.setHeight( aHeaderSize.Height() * 100 / mnScale );
1194
0
                            SvxSetItem  aNewHeader( rStyleSet.Get(ATTR_PAGE_HEADERSET) );
1195
0
                            aNewHeader.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aHeaderSize ) );
1196
0
                            rStyleSet.Put( aNewHeader );
1197
0
                            pDocShell->SetModified();
1198
0
                        }
1199
0
                    }
1200
0
                    else if( bFooterRulerMove && bFooterRulerChange )
1201
0
                    {
1202
0
                        if( const SvxSetItem* pSetItem = rStyleSet.GetItemIfSet( ATTR_PAGE_FOOTERSET, false ) )
1203
0
                        {
1204
0
                            const SfxItemSet& rFooterSet = pSetItem->GetItemSet();
1205
0
                            Size aFooterSize = rFooterSet.Get(ATTR_PAGE_SIZE).GetSize();
1206
0
                            aFooterSize.setHeight(nHeight - o3tl::convert(aButtonUpPt.Y(), o3tl::Length::mm100, o3tl::Length::twip) - o3tl::convert(aOffset.Y(), o3tl::Length::mm100, o3tl::Length::twip) - aULItem.GetLower());
1207
0
                            aFooterSize.setHeight( aFooterSize.Height() * 100 / mnScale );
1208
0
                            SvxSetItem  aNewFooter( rStyleSet.Get(ATTR_PAGE_FOOTERSET) );
1209
0
                            aNewFooter.GetItemSet().Put( SvxSizeItem( ATTR_PAGE_SIZE, aFooterSize ) );
1210
0
                            rStyleSet.Put( aNewFooter );
1211
0
                            pDocShell->SetModified();
1212
0
                        }
1213
0
                    }
1214
1215
0
                    ScStyleSaveData aNewData;
1216
0
                    aNewData.InitFromStyle( pStyleSheet );
1217
0
                    if( bUndo )
1218
0
                    {
1219
0
                        pDocShell->GetUndoManager()->AddUndoAction(
1220
0
                            std::make_unique<ScUndoModifyStyle>( *pDocShell, SfxStyleFamily::Page,
1221
0
                            aOldData, aNewData ) );
1222
0
                    }
1223
1224
0
                    if ( ValidTab( nTab ) )
1225
0
                    {
1226
0
                        ScPrintFunc aPrintFunc( GetOutDev(), *pDocShell, nTab );
1227
0
                        aPrintFunc.UpdatePages();
1228
0
                    }
1229
1230
0
                    tools::Rectangle aRect(0, 0, 10000, 10000);
1231
0
                    Invalidate(aRect);
1232
0
                    aModificator.SetDocumentModified();
1233
0
                    bTopRulerChange = false;
1234
0
                    bBottomRulerChange = false;
1235
0
                    bHeaderRulerChange = false;
1236
0
                    bFooterRulerChange = false;
1237
0
                }
1238
0
            }
1239
0
            bTopRulerMove = false;
1240
0
            bBottomRulerMove = false;
1241
0
            bHeaderRulerMove = false;
1242
0
            bFooterRulerMove = false;
1243
0
        }
1244
0
        if( rMEvt.IsLeft() && GetPointer() == PointerStyle::HSplit )
1245
0
        {
1246
0
            SetPointer(PointerStyle::Arrow);
1247
0
            ScDocument& rDoc = pDocShell->GetDocument();
1248
0
            bool bLayoutRTL = rDoc.IsLayoutRTL( nTab );
1249
0
            bool bMoveRulerAction = true;
1250
0
            if( aButtonDownPt.X() == aButtonUpPt.X() )
1251
0
            {
1252
0
                bMoveRulerAction = false;
1253
0
                if( nColNumberButtonDown == aPageArea.aStart.Col() )
1254
0
                    DrawInvert( PixelToLogic( Point( nLeftPosition, 0 ),aMMMode ).X() ,PointerStyle::HSplit );
1255
0
                else
1256
0
                    DrawInvert( PixelToLogic( Point( mvRight[ nColNumberButtonDown-1 ], 0 ),aMMMode ).X() ,PointerStyle::HSplit );
1257
0
                DrawInvert( aButtonUpPt.X(), PointerStyle::HSplit );
1258
0
            }
1259
0
            if( bMoveRulerAction )
1260
0
            {
1261
0
                tools::Long  nNewColWidth = 0;
1262
0
                std::vector<sc::ColRowSpan> aCols(1, sc::ColRowSpan(nColNumberButtonDown,nColNumberButtonDown));
1263
1264
0
                constexpr auto md = o3tl::getConversionMulDiv(o3tl::Length::mm100, o3tl::Length::twip);
1265
0
                const auto m = md.first * 100, d = md.second * mnScale;
1266
0
                if( !bLayoutRTL )
1267
0
                {
1268
0
                    nNewColWidth = o3tl::convert(PixelToLogic( Point( rMEvt.GetPosPixel().X() - mvRight[ nColNumberButtonDown ], 0), aMMMode ).X(), m, d);
1269
0
                    nNewColWidth += pDocShell->GetDocument().GetColWidth( nColNumberButtonDown, nTab );
1270
0
                }
1271
0
                else
1272
0
                {
1273
1274
0
                    nNewColWidth = o3tl::convert(PixelToLogic( Point( mvRight[ nColNumberButtonDown ] - rMEvt.GetPosPixel().X(), 0), aMMMode ).X(), m, d);
1275
0
                    nNewColWidth += pDocShell->GetDocument().GetColWidth( nColNumberButtonDown, nTab );
1276
0
                }
1277
1278
0
                if( nNewColWidth >= 0 )
1279
0
                {
1280
0
                    pDocShell->GetDocFunc().SetWidthOrHeight(
1281
0
                        true, aCols, nTab, SC_SIZE_DIRECT, static_cast<sal_uInt16>(nNewColWidth), true, true);
1282
0
                    pDocShell->SetModified();
1283
0
                }
1284
0
                if ( ValidTab( nTab ) )
1285
0
                {
1286
0
                    ScPrintFunc aPrintFunc( GetOutDev(), *pDocShell, nTab );
1287
0
                    aPrintFunc.UpdatePages();
1288
0
                }
1289
0
                tools::Rectangle aRect(0, 0, 10000, 10000);
1290
0
                Invalidate(aRect);
1291
0
            }
1292
0
            bColRulerMove = false;
1293
0
        }
1294
0
        ReleaseMouse();
1295
0
}
1296
1297
void ScPreview::MouseMove( const MouseEvent& rMEvt )
1298
0
{
1299
0
    Fraction aPreviewZoom( nZoom, 100 );
1300
0
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1301
0
    MapMode  aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
1302
0
    Point    aMouseMovePoint = PixelToLogic( rMEvt.GetPosPixel(), aMMMode );
1303
1304
0
    tools::Long    nLeftMargin = 0;
1305
0
    tools::Long    nRightMargin = 0;
1306
0
    tools::Long    nTopMargin = 0;
1307
0
    tools::Long    nBottomMargin = 0;
1308
1309
0
    tools::Long    nWidth = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Width();
1310
0
    tools::Long    nHeight = lcl_GetDocPageSize(&pDocShell->GetDocument(), nTab).Height();
1311
1312
0
    if ( nPageNo < nTotalPages )
1313
0
    {
1314
0
        ScPrintOptions aOptions = ScModule::get()->GetPrintOptions();
1315
1316
0
        std::unique_ptr<ScPrintFunc, o3tl::default_delete<ScPrintFunc>> pPrintFunc;
1317
0
        if (bStateValid)
1318
0
            pPrintFunc.reset(new ScPrintFunc( GetOutDev(), *pDocShell, aState, &aOptions ));
1319
0
        else
1320
0
            pPrintFunc.reset(new ScPrintFunc( GetOutDev(), *pDocShell, nTab, nFirstAttr[nTab], nTotalPages, nullptr, &aOptions ));
1321
1322
0
        nLeftMargin = o3tl::convert(pPrintFunc->GetLeftMargin(), o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X();
1323
0
        nRightMargin = o3tl::convert(pPrintFunc->GetRightMargin(), o3tl::Length::twip, o3tl::Length::mm100);
1324
0
        nRightMargin = o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - nRightMargin - aOffset.X();
1325
0
        nTopMargin = o3tl::convert(pPrintFunc->GetTopMargin(), o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y();
1326
0
        nBottomMargin = o3tl::convert(pPrintFunc->GetBottomMargin(), o3tl::Length::twip, o3tl::Length::mm100);
1327
0
        nBottomMargin = o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - nBottomMargin - aOffset.Y();
1328
0
        if( mnScale > 0 )
1329
0
        {
1330
0
            constexpr auto md = o3tl::getConversionMulDiv(o3tl::Length::twip, o3tl::Length::mm100);
1331
0
            const auto m = md.first * mnScale, d = md.second * 100;
1332
0
            nHeaderHeight = nTopMargin + o3tl::convert(pPrintFunc->GetHeader().nHeight, m, d);
1333
0
            nFooterHeight = nBottomMargin - o3tl::convert(pPrintFunc->GetFooter().nHeight, m, d);
1334
0
        }
1335
0
        else
1336
0
        {
1337
0
            nHeaderHeight = nTopMargin + o3tl::convert(pPrintFunc->GetHeader().nHeight, o3tl::Length::twip, o3tl::Length::mm100);
1338
0
            nFooterHeight = nBottomMargin - o3tl::convert(pPrintFunc->GetFooter().nHeight, o3tl::Length::twip, o3tl::Length::mm100);
1339
0
        }
1340
0
    }
1341
1342
0
    Point   aPixPt( rMEvt.GetPosPixel() );
1343
0
    Point   aLeftTop = LogicToPixel( Point( nLeftMargin, -aOffset.Y() ) , aMMMode );
1344
0
    Point   aLeftBottom = LogicToPixel( Point( nLeftMargin, o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y()), aMMMode );
1345
0
    Point   aRightTop = LogicToPixel( Point( nRightMargin, -aOffset.Y() ), aMMMode );
1346
0
    Point   aTopLeft = LogicToPixel( Point( -aOffset.X(), nTopMargin ), aMMMode );
1347
0
    Point   aTopRight = LogicToPixel( Point( o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X(), nTopMargin ), aMMMode );
1348
0
    Point   aBottomLeft = LogicToPixel( Point( -aOffset.X(), nBottomMargin ), aMMMode );
1349
0
    Point   aHeaderLeft = LogicToPixel( Point(  -aOffset.X(), nHeaderHeight ), aMMMode );
1350
0
    Point   aFooderLeft = LogicToPixel( Point( -aOffset.X(), nFooterHeight ), aMMMode );
1351
1352
0
    bool bOnColRulerChange = false;
1353
1354
0
    for( SCCOL i=aPageArea.aStart.Col(); i<= aPageArea.aEnd.Col(); i++ )
1355
0
    {
1356
0
        Point   aColumnTop = LogicToPixel( Point( 0, -aOffset.Y() ) ,aMMMode );
1357
0
        Point   aColumnBottom = LogicToPixel( Point( 0, o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y()), aMMMode );
1358
0
        tools::Long nRight = i < static_cast<SCCOL>(mvRight.size()) ? mvRight[i] : 0;
1359
0
        if( aPixPt.X() < ( nRight + 2 ) && ( aPixPt.X() > ( nRight - 2 ) ) && ( aPixPt.X() < aRightTop.X() ) && ( aPixPt.X() > aLeftTop.X() )
1360
0
            && ( aPixPt.Y() > aColumnTop.Y() ) && ( aPixPt.Y() < aColumnBottom.Y() ) && !bLeftRulerMove && !bRightRulerMove
1361
0
            && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1362
0
        {
1363
0
            bOnColRulerChange = true;
1364
0
            if( !rMEvt.GetButtons() && GetPointer() == PointerStyle::HSplit )
1365
0
                nColNumberButtonDown = i;
1366
0
            break;
1367
0
        }
1368
0
    }
1369
1370
0
    if( aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 ) && !bRightRulerMove )
1371
0
    {
1372
0
        bLeftRulerChange = true;
1373
0
        bRightRulerChange = false;
1374
0
    }
1375
0
    else if( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) && !bLeftRulerMove )
1376
0
    {
1377
0
        bLeftRulerChange = false;
1378
0
        bRightRulerChange = true;
1379
0
    }
1380
0
    else if( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1381
0
    {
1382
0
        bTopRulerChange = true;
1383
0
        bBottomRulerChange = false;
1384
0
        bHeaderRulerChange = false;
1385
0
        bFooterRulerChange = false;
1386
0
    }
1387
0
    else if( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) && !bTopRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1388
0
    {
1389
0
        bTopRulerChange = false;
1390
0
        bBottomRulerChange = true;
1391
0
        bHeaderRulerChange = false;
1392
0
        bFooterRulerChange = false;
1393
0
    }
1394
0
    else if( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bFooterRulerMove )
1395
0
    {
1396
0
        bTopRulerChange = false;
1397
0
        bBottomRulerChange = false;
1398
0
        bHeaderRulerChange = true;
1399
0
        bFooterRulerChange = false;
1400
0
    }
1401
0
    else if( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove )
1402
0
    {
1403
0
        bTopRulerChange = false;
1404
0
        bBottomRulerChange = false;
1405
0
        bHeaderRulerChange = false;
1406
0
        bFooterRulerChange = true;
1407
0
    }
1408
1409
0
    if( !bPageMargin )
1410
0
        return;
1411
1412
0
    if(( (aPixPt.X() < ( aLeftTop.X() + 2 ) && aPixPt.X() > ( aLeftTop.X() - 2 )) || bLeftRulerMove ||
1413
0
        ( aPixPt.X() < ( aRightTop.X() + 2 ) && aPixPt.X() > ( aRightTop.X() - 2 ) ) || bRightRulerMove || bOnColRulerChange || bColRulerMove )
1414
0
        && aPixPt.Y() > aLeftTop.Y() && aPixPt.Y() < aLeftBottom.Y() )
1415
0
    {
1416
0
        if( bOnColRulerChange || bColRulerMove )
1417
0
        {
1418
0
            SetPointer( PointerStyle::HSplit );
1419
0
            if( bColRulerMove )
1420
0
            {
1421
0
                if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X() )
1422
0
                   DragMove( aMouseMovePoint.X(), PointerStyle::HSplit );
1423
0
            }
1424
0
        }
1425
0
        else
1426
0
        {
1427
0
            if( bLeftRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1428
0
            {
1429
0
                SetPointer( PointerStyle::HSizeBar );
1430
0
                if( bLeftRulerMove )
1431
0
                {
1432
0
                   if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X() )
1433
0
                       DragMove( aMouseMovePoint.X(), PointerStyle::HSizeBar );
1434
0
                }
1435
0
            }
1436
0
            else if( bRightRulerChange && !bTopRulerMove && !bBottomRulerMove && !bHeaderRulerMove && !bFooterRulerMove )
1437
0
            {
1438
0
                SetPointer( PointerStyle::HSizeBar );
1439
0
                if( bRightRulerMove )
1440
0
                {
1441
0
                   if( aMouseMovePoint.X() > -aOffset.X() && aMouseMovePoint.X() < o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X() )
1442
0
                       DragMove( aMouseMovePoint.X(), PointerStyle::HSizeBar );
1443
0
                }
1444
0
            }
1445
0
        }
1446
0
    }
1447
0
    else
1448
0
    {
1449
0
        if( ( ( aPixPt.Y() < ( aTopLeft.Y() + 2 ) && aPixPt.Y() > ( aTopLeft.Y() - 2 ) ) || bTopRulerMove ||
1450
0
            ( aPixPt.Y() < ( aBottomLeft.Y() + 2 ) && aPixPt.Y() > ( aBottomLeft.Y() - 2 ) ) || bBottomRulerMove ||
1451
0
            ( aPixPt.Y() < ( aHeaderLeft.Y() + 2 ) && aPixPt.Y() > ( aHeaderLeft.Y() - 2 ) ) || bHeaderRulerMove ||
1452
0
            ( aPixPt.Y() < ( aFooderLeft.Y() + 2 ) && aPixPt.Y() > ( aFooderLeft.Y() - 2 ) ) || bFooterRulerMove )
1453
0
            && aPixPt.X() > aTopLeft.X() && aPixPt.X() < aTopRight.X() )
1454
0
        {
1455
0
            if( bTopRulerChange )
1456
0
            {
1457
0
                SetPointer( PointerStyle::VSizeBar );
1458
0
                if( bTopRulerMove )
1459
0
                {
1460
0
                    if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y() )
1461
0
                        DragMove( aMouseMovePoint.Y(), PointerStyle::VSizeBar );
1462
0
                }
1463
0
            }
1464
0
            else if( bBottomRulerChange )
1465
0
            {
1466
0
                SetPointer( PointerStyle::VSizeBar );
1467
0
                if( bBottomRulerMove )
1468
0
                {
1469
0
                    if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y() )
1470
0
                        DragMove( aMouseMovePoint.Y(), PointerStyle::VSizeBar );
1471
0
                }
1472
0
            }
1473
0
            else if( bHeaderRulerChange )
1474
0
            {
1475
0
                SetPointer( PointerStyle::VSizeBar );
1476
0
                if( bHeaderRulerMove )
1477
0
                {
1478
0
                    if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y() )
1479
0
                        DragMove( aMouseMovePoint.Y(), PointerStyle::VSizeBar );
1480
0
                }
1481
0
            }
1482
0
            else if( bFooterRulerChange )
1483
0
            {
1484
0
                SetPointer( PointerStyle::VSizeBar );
1485
0
                if( bFooterRulerMove )
1486
0
                {
1487
0
                    if( aMouseMovePoint.Y() > -aOffset.Y() && aMouseMovePoint.Y() < o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y() )
1488
0
                        DragMove( aMouseMovePoint.Y(), PointerStyle::VSizeBar );
1489
0
                }
1490
0
            }
1491
0
        }
1492
0
        else
1493
0
            SetPointer( PointerStyle::Arrow );
1494
0
    }
1495
0
}
1496
1497
void ScPreview::InvalidateLocationData(SfxHintId nId)
1498
0
{
1499
0
    bLocationValid = false;
1500
0
    if (pViewShell->HasAccessibilityObjects())
1501
0
        pViewShell->BroadcastAccessibility( SfxHint( nId ) );
1502
0
}
1503
1504
void ScPreview::GetFocus()
1505
0
{
1506
0
    Window::GetFocus();
1507
0
    if (pViewShell && pViewShell->HasAccessibilityObjects())
1508
0
        pViewShell->BroadcastAccessibility( ScAccWinFocusGotHint() );
1509
0
}
1510
1511
void ScPreview::LoseFocus()
1512
0
{
1513
0
    if (pViewShell && pViewShell->HasAccessibilityObjects())
1514
0
        pViewShell->BroadcastAccessibility( ScAccWinFocusLostHint() );
1515
0
    Window::LoseFocus();
1516
0
}
1517
1518
rtl::Reference<comphelper::OAccessible> ScPreview::CreateAccessible()
1519
0
{
1520
0
    rtl::Reference<ScAccessibleDocumentPagePreview> pAccessible =
1521
0
        new ScAccessibleDocumentPagePreview(GetAccessibleParent(), pViewShell );
1522
0
    SetAccessible(pAccessible);
1523
0
    pAccessible->Init();
1524
0
    return pAccessible;
1525
0
}
1526
1527
void ScPreview::DragMove( tools::Long nDragMovePos, PointerStyle nFlags )
1528
0
{
1529
0
    Fraction aPreviewZoom( nZoom, 100 );
1530
0
    Fraction aHorPrevZoom( static_cast<tools::Long>( 100 * nZoom / pDocShell->GetOutputFactor() ), 10000 );
1531
0
    MapMode  aMMMode( MapUnit::Map100thMM, Point(), aHorPrevZoom, aPreviewZoom );
1532
0
    SetMapMode( aMMMode );
1533
0
    tools::Long  nPos = nDragMovePos;
1534
0
    if( nFlags == PointerStyle::HSizeBar || nFlags == PointerStyle::HSplit )
1535
0
    {
1536
0
        if( nDragMovePos != aButtonDownChangePoint.X() )
1537
0
        {
1538
0
            DrawInvert( aButtonDownChangePoint.X(), nFlags );
1539
0
            aButtonDownChangePoint.setX( nPos );
1540
0
            DrawInvert( aButtonDownChangePoint.X(), nFlags );
1541
0
        }
1542
0
    }
1543
0
    else if( nFlags == PointerStyle::VSizeBar )
1544
0
    {
1545
0
        if( nDragMovePos != aButtonDownChangePoint.Y() )
1546
0
        {
1547
0
            DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1548
0
            aButtonDownChangePoint.setY( nPos );
1549
0
            DrawInvert( aButtonDownChangePoint.Y(), nFlags );
1550
0
        }
1551
0
    }
1552
0
}
1553
1554
void ScPreview::DrawInvert( tools::Long nDragPos, PointerStyle nFlags )
1555
0
{
1556
0
    tools::Long  nHeight = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Height();
1557
0
    tools::Long  nWidth = lcl_GetDocPageSize( &pDocShell->GetDocument(), nTab ).Width();
1558
0
    if( nFlags == PointerStyle::HSizeBar || nFlags == PointerStyle::HSplit )
1559
0
    {
1560
0
        tools::Rectangle aRect( nDragPos, -aOffset.Y(), nDragPos + 1, o3tl::convert(nHeight, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.Y());
1561
0
        GetOutDev()->Invert( aRect, InvertFlags::N50 );
1562
0
    }
1563
0
    else if( nFlags == PointerStyle::VSizeBar )
1564
0
    {
1565
0
        tools::Rectangle aRect( -aOffset.X(), nDragPos, o3tl::convert(nWidth, o3tl::Length::twip, o3tl::Length::mm100) - aOffset.X(), nDragPos + 1 );
1566
0
        GetOutDev()->Invert( aRect, InvertFlags::N50 );
1567
0
    }
1568
0
}
1569
1570
void ScPreview::SetSelectedTabs(const ScMarkData& rMark)
1571
0
{
1572
0
    maSelectedTabs = rMark.GetSelectedTabs();
1573
0
}
1574
1575
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */