Coverage Report

Created: 2025-11-16 09:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/sd/source/ui/func/fuscale.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 <fuscale.hxx>
21
22
#include <svx/svxids.hrc>
23
24
#include <app.hrc>
25
#include <View.hxx>
26
#include <Window.hxx>
27
#include <OutlineViewShell.hxx>
28
#include <drawdoc.hxx>
29
#include <DrawViewShell.hxx>
30
#include <ViewShell.hxx>
31
#include <fuzoom.hxx>
32
33
#include <svx/svdpagv.hxx>
34
#include <sfx2/viewfrm.hxx>
35
#include <sfx2/dispatch.hxx>
36
#include <sfx2/zoomitem.hxx>
37
#include <sfx2/request.hxx>
38
#include <svx/svxdlg.hxx>
39
#include <memory>
40
41
namespace sd {
42
43
44
FuScale::FuScale (
45
    ViewShell& rViewSh,
46
    ::sd::Window* pWin,
47
    ::sd::View* pView,
48
    SdDrawDocument& rDoc,
49
    SfxRequest& rReq)
50
0
    : FuPoor(rViewSh, pWin, pView, rDoc, rReq)
51
0
{
52
0
}
53
54
rtl::Reference<FuPoor> FuScale::Create( ViewShell& rViewSh, ::sd::Window* pWin, ::sd::View* pView, SdDrawDocument& rDoc, SfxRequest& rReq )
55
0
{
56
0
    rtl::Reference<FuPoor> xFunc( new FuScale( rViewSh, pWin, pView, rDoc, rReq ) );
57
0
    xFunc->DoExecute(rReq);
58
0
    return xFunc;
59
0
}
60
61
void FuScale::DoExecute( SfxRequest& rReq )
62
0
{
63
0
    sal_Int16 nValue;
64
65
0
    const SfxItemSet* pArgs = rReq.GetArgs();
66
67
0
    if( !pArgs )
68
0
    {
69
0
        SfxItemSetFixed<SID_ATTR_ZOOM, SID_ATTR_ZOOM> aNewAttr( mrDoc.GetPool() );
70
0
        std::unique_ptr<SvxZoomItem> pZoomItem;
71
0
        SvxZoomEnableFlags nZoomValues = SvxZoomEnableFlags::ALL;
72
73
0
        nValue = static_cast<sal_Int16>(mpWindow->GetZoom());
74
75
        // zoom on page size?
76
0
        if( dynamic_cast< DrawViewShell *>( &mrViewShell ) &&
77
0
            static_cast<DrawViewShell*>(&mrViewShell)->IsZoomOnPage() )
78
0
        {
79
0
            pZoomItem.reset(new SvxZoomItem( SvxZoomType::WHOLEPAGE, nValue ));
80
0
        }
81
0
        else
82
0
        {
83
0
            pZoomItem.reset(new SvxZoomItem( SvxZoomType::PERCENT, nValue ));
84
0
        }
85
86
        // limit range
87
0
        if( dynamic_cast< DrawViewShell *>( &mrViewShell ) !=  nullptr )
88
0
        {
89
0
            SdrPageView* pPageView = mpView->GetSdrPageView();
90
0
            if( pPageView && pPageView->GetObjList()->GetObjCount() == 0 )
91
0
            {
92
0
                nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
93
0
            }
94
0
        }
95
0
        else if( dynamic_cast< OutlineViewShell *>( &mrViewShell ) !=  nullptr )
96
0
        {
97
0
            nZoomValues &= ~SvxZoomEnableFlags::OPTIMAL;
98
0
            nZoomValues &= ~SvxZoomEnableFlags::WHOLEPAGE;
99
0
            nZoomValues &= ~SvxZoomEnableFlags::PAGEWIDTH;
100
0
        }
101
102
0
        pZoomItem->SetValueSet( nZoomValues );
103
0
        aNewAttr.Put( std::move(pZoomItem) );
104
105
0
        SvxAbstractDialogFactory* pFact = SvxAbstractDialogFactory::Create();
106
0
        ScopedVclPtr<AbstractSvxZoomDialog> pDlg(pFact->CreateSvxZoomDialog(rReq.GetFrameWeld(), aNewAttr));
107
0
        pDlg->SetLimits( static_cast<sal_uInt16>(mpWindow->GetMinZoom()), static_cast<sal_uInt16>(mpWindow->GetMaxZoom()) );
108
0
        sal_uInt16 nResult = pDlg->Execute();
109
0
        switch( nResult )
110
0
        {
111
0
            case RET_CANCEL:
112
0
            {
113
0
                rReq.Ignore ();
114
0
                return; // Cancel
115
0
            }
116
0
            default:
117
0
            {
118
0
                rReq.Ignore ();
119
0
            }
120
0
            break;
121
0
        }
122
123
0
        const SfxItemSet aArgs (*(pDlg->GetOutputItemSet ()));
124
125
0
        pDlg.disposeAndClear();
126
127
0
        switch ( aArgs.Get (SID_ATTR_ZOOM).GetType ())
128
0
        {
129
0
            case SvxZoomType::PERCENT:
130
0
            {
131
0
                nValue = aArgs.Get (SID_ATTR_ZOOM).GetValue ();
132
133
0
                mrViewShell.SetZoom( nValue );
134
135
0
                mrViewShell.GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
136
0
            }
137
0
            break;
138
139
0
            case SvxZoomType::OPTIMAL:
140
0
            {
141
0
                if( dynamic_cast< DrawViewShell *>( &mrViewShell ) !=  nullptr )
142
0
                {
143
                    // name confusion: SID_SIZE_ALL -> zoom onto all objects
144
                    // --> the program offers it as optimal
145
0
                    mrViewShell.GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_ALL, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
146
0
                }
147
0
            }
148
0
            break;
149
150
0
            case SvxZoomType::PAGEWIDTH:
151
0
                mrViewShell.GetViewFrame()->GetDispatcher()->Execute( SID_SIZE_PAGE_WIDTH, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
152
0
                break;
153
154
0
            case SvxZoomType::WHOLEPAGE:
155
0
                mrViewShell.GetViewFrame()->GetDispatcher()->Execute(SID_SIZE_PAGE, SfxCallMode::ASYNCHRON | SfxCallMode::RECORD);
156
0
                break;
157
0
            default:
158
0
                break;
159
0
        }
160
0
    }
161
0
    else if(pArgs->Count () == 1)
162
0
    {
163
0
        const SfxUInt32Item* pScale = rReq.GetArg<SfxUInt32Item>(ID_VAL_ZOOM);
164
0
        mrViewShell.SetZoom (pScale->GetValue ());
165
166
0
        mrViewShell.GetViewFrame()->GetBindings().Invalidate( SidArrayZoom );
167
0
    }
168
169
0
}
170
171
} // end of namespace sd
172
173
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */