1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <scalectrl.hxx>
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>
30 #include <ViewShellBase.hxx>
31 #include <drawdoc.hxx>
33 #include <sdresid.hxx>
34 #include <strings.hrc>
36 SFX_IMPL_STATUSBAR_CONTROL(SdScaleControl
, SfxStringItem
);
38 // class SdScaleControl ------------------------------------------
39 SdScaleControl::SdScaleControl(sal_uInt16 _nSlotId
, sal_uInt16 _nId
, StatusBar
& rStb
)
40 : SfxStatusBarControl(_nSlotId
, _nId
, rStb
)
42 GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_SCALE_TOOLTIP
));
45 SdScaleControl::~SdScaleControl() {}
47 void SdScaleControl::StateChangedAtStatusBarControl(sal_uInt16
/*nSID*/, SfxItemState eState
,
48 const SfxPoolItem
* pState
)
50 if (eState
!= SfxItemState::DEFAULT
|| pState
->IsVoidItem())
52 auto pStringItem
= dynamic_cast<const SfxStringItem
*>(pState
);
55 SAL_WARN("sd", "Item wasn't a SfxStringItem");
58 GetStatusBar().SetItemText(GetId(), pStringItem
->GetValue());
61 void SdScaleControl::Command(const CommandEvent
& rCEvt
)
63 if (rCEvt
.GetCommand() != CommandEventId::ContextMenu
64 || GetStatusBar().GetItemText(GetId()).isEmpty())
67 SfxViewFrame
* pViewFrame
= SfxViewFrame::Current();
69 sd::ViewShellBase
* pViewShellBase
= sd::ViewShellBase::GetViewShellBase(pViewFrame
);
73 SdDrawDocument
* pDoc
= pViewShellBase
->GetDocument();
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"));
81 sal_uInt16 aTable
[12] = { 1, 2, 4, 5, 8, 10, 16, 20, 30, 40, 50, 100 };
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
]));
88 ::tools::Rectangle
aRect(rCEvt
.GetMousePosPixel(), Size(1, 1));
89 weld::Window
* pParent
= weld::GetPopupParent(GetStatusBar(), aRect
);
90 OUString sResult
= xPopup
->popup_at_rect(pParent
, aRect
);
91 if (sResult
.isEmpty())
94 sal_Int32 i
= sResult
.toUInt32();
100 nX
= aTable
[(12 - i
) % 12];
105 pDoc
->SetUIScale(Fraction(nX
, nY
));
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
113 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */