LibreOffice Module sd (master) 1
scalectrl.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <scalectrl.hxx>
21
22#include <vcl/commandevent.hxx>
23#include <vcl/status.hxx>
24#include <vcl/weldutils.hxx>
25#include <sfx2/bindings.hxx>
26#include <sfx2/viewfrm.hxx>
27#include <svl/stritem.hxx>
28#include <sfx2/sfxsids.hrc>
29
30#include <ViewShellBase.hxx>
31#include <drawdoc.hxx>
32#include <app.hrc>
33#include <sdresid.hxx>
34#include <strings.hrc>
35
37
38// class SdScaleControl ------------------------------------------
39SdScaleControl::SdScaleControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb)
40 : SfxStatusBarControl(_nSlotId, _nId, rStb)
41{
42 GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_SCALE_TOOLTIP));
43}
44
46
48 const SfxPoolItem* pState)
49{
50 if (eState != SfxItemState::DEFAULT || pState->IsVoidItem())
51 return;
52 auto pStringItem = dynamic_cast<const SfxStringItem*>(pState);
53 if (!pStringItem)
54 {
55 SAL_WARN("sd", "Item wasn't a SfxStringItem");
56 return;
57 }
58 GetStatusBar().SetItemText(GetId(), pStringItem->GetValue());
59}
60
62{
63 if (rCEvt.GetCommand() != CommandEventId::ContextMenu
64 || GetStatusBar().GetItemText(GetId()).isEmpty())
65 return;
66
67 SfxViewFrame* pViewFrame = SfxViewFrame::Current();
68
69 sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase(pViewFrame);
70 if (!pViewShellBase)
71 return;
72
73 SdDrawDocument* pDoc = pViewShellBase->GetDocument();
74 if (!pDoc)
75 return;
76
77 std::unique_ptr<weld::Builder> xBuilder(
78 Application::CreateBuilder(nullptr, "modules/simpress/ui/masterpagemenu.ui"));
79 std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu("menu"));
80
81 sal_uInt16 aTable[12] = { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
82
83 for (sal_uInt16 i = 11; i > 0; i--)
84 xPopup->append(OUString::number(12 - i), OUString::number(aTable[i]) + ":1");
85 for (sal_uInt16 i = 0; i < 12; i++)
86 xPopup->append(OUString::number(12 + i), "1:" + OUString::number(aTable[i]));
87
88 ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1));
90 OUString sResult = xPopup->popup_at_rect(pParent, aRect);
91 if (sResult.isEmpty())
92 return;
93
94 sal_Int32 i = sResult.toUInt32();
95 sal_Int32 nX;
96 sal_Int32 nY;
97 if (i > 11)
98 nX = 1;
99 else
100 nX = aTable[(12 - i) % 12];
101 if (i > 11)
102 nY = aTable[i % 12];
103 else
104 nY = 1;
105 pDoc->SetUIScale(Fraction(nX, nY));
106
107 SfxBindings& pBindings = pViewFrame->GetBindings();
108 pBindings.Invalidate(SID_SCALE); //update statusbar
109 pBindings.Invalidate(SID_ATTR_METRIC); //update sidebar
110 pViewShellBase->UpdateBorder(true); // update ruler
111}
112
113/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static std::unique_ptr< weld::Builder > CreateBuilder(weld::Widget *pParent, const OUString &rUIFile, bool bMobile=false, sal_uInt64 nLOKWindowId=0)
CommandEventId GetCommand() const
const Point & GetMousePosPixel() const
virtual void StateChangedAtStatusBarControl(sal_uInt16 nSID, SfxItemState eState, const SfxPoolItem *pState) override
Definition: scalectrl.cxx:47
virtual ~SdScaleControl() override
Definition: scalectrl.cxx:45
virtual void Command(const CommandEvent &rCEvt) override
Definition: scalectrl.cxx:61
SdScaleControl(sal_uInt16 nSlotId, sal_uInt16 nId, StatusBar &rStb)
Definition: scalectrl.cxx:39
void SetUIScale(const Fraction &rScale)
void Invalidate(sal_uInt16 nId)
virtual bool IsVoidItem() const
StatusBar & GetStatusBar() const
sal_uInt16 GetId() const
static SAL_WARN_UNUSED_RESULT SfxViewFrame * Current()
SfxBindings & GetBindings()
void SetItemText(sal_uInt16 nItemId, const OUString &rText, int nCharsWidth=-1)
void SetQuickHelpText(sal_uInt16 nItemId, const OUString &rText)
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
static ViewShellBase * GetViewShellBase(SfxViewFrame const *pFrame)
When given a view frame this static method returns the corresponding sd::ViewShellBase object.
void UpdateBorder(bool bForce=false)
Update the border that is set with SfxViewShell::SetBorderPixel().
SdDrawDocument * GetDocument() const
#define SAL_WARN(area, stream)
int i
weld::Window * GetPopupParent(vcl::Window &rOutWin, tools::Rectangle &rRect)
SfxItemState
SFX_IMPL_STATUSBAR_CONTROL(SdScaleControl, SfxStringItem)
OUString SdResId(TranslateId aId)
Definition: sdmod.cxx:83