Coverage Report

Created: 2026-07-10 11:04

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