/src/libreoffice/sd/source/ui/app/scalectrl.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 <scalectrl.hxx> |
21 | | |
22 | | #include <vcl/commandevent.hxx> |
23 | | #include <vcl/status.hxx> |
24 | | #include <vcl/svapp.hxx> |
25 | | #include <vcl/weld/Builder.hxx> |
26 | | #include <vcl/weld/Menu.hxx> |
27 | | #include <vcl/weld/Window.hxx> |
28 | | #include <vcl/weld/weldutils.hxx> |
29 | | #include <sfx2/bindings.hxx> |
30 | | #include <sfx2/viewfrm.hxx> |
31 | | #include <svl/stritem.hxx> |
32 | | #include <sfx2/sfxsids.hrc> |
33 | | |
34 | | #include <ViewShellBase.hxx> |
35 | | #include <drawdoc.hxx> |
36 | | #include <app.hrc> |
37 | | #include <sdresid.hxx> |
38 | | #include <strings.hrc> |
39 | | |
40 | 0 | #define TABLE_COUNT 9 |
41 | | |
42 | | SFX_IMPL_STATUSBAR_CONTROL(SdScaleControl, SfxStringItem); |
43 | | |
44 | | // class SdScaleControl ------------------------------------------ |
45 | | SdScaleControl::SdScaleControl(sal_uInt16 _nSlotId, sal_uInt16 _nId, StatusBar& rStb) |
46 | 0 | : SfxStatusBarControl(_nSlotId, _nId, rStb) |
47 | 0 | { |
48 | 0 | GetStatusBar().SetQuickHelpText(GetId(), SdResId(STR_SCALE_TOOLTIP)); |
49 | 0 | } |
50 | | |
51 | 0 | SdScaleControl::~SdScaleControl() {} |
52 | | |
53 | | void SdScaleControl::StateChangedAtStatusBarControl(sal_uInt16 /*nSID*/, SfxItemState eState, |
54 | | const SfxPoolItem* pState) |
55 | 0 | { |
56 | 0 | if (eState != SfxItemState::DEFAULT || SfxItemState::DISABLED == eState) |
57 | 0 | return; |
58 | | |
59 | 0 | auto pStringItem = dynamic_cast<const SfxStringItem*>(pState); |
60 | 0 | if (!pStringItem) |
61 | 0 | { |
62 | 0 | SAL_WARN("sd", "Item wasn't a SfxStringItem"); |
63 | 0 | return; |
64 | 0 | } |
65 | 0 | GetStatusBar().SetItemText(GetId(), pStringItem->GetValue()); |
66 | 0 | } |
67 | | |
68 | | void SdScaleControl::Command(const CommandEvent& rCEvt) |
69 | 0 | { |
70 | 0 | if (rCEvt.GetCommand() != CommandEventId::ContextMenu |
71 | 0 | || GetStatusBar().GetItemText(GetId()).isEmpty()) |
72 | 0 | return; |
73 | | |
74 | 0 | SfxViewFrame* pViewFrame = SfxViewFrame::Current(); |
75 | |
|
76 | 0 | sd::ViewShellBase* pViewShellBase = sd::ViewShellBase::GetViewShellBase(pViewFrame); |
77 | 0 | if (!pViewShellBase) |
78 | 0 | return; |
79 | | |
80 | 0 | SdDrawDocument* pDoc = pViewShellBase->GetDocument(); |
81 | 0 | if (!pDoc) |
82 | 0 | return; |
83 | | |
84 | 0 | std::unique_ptr<weld::Builder> xBuilder( |
85 | 0 | Application::CreateBuilder(nullptr, u"modules/simpress/ui/masterpagemenu.ui"_ustr)); |
86 | 0 | std::unique_ptr<weld::Menu> xPopup(xBuilder->weld_menu(u"menu"_ustr)); |
87 | |
|
88 | 0 | sal_uInt16 aTable[TABLE_COUNT] = { 1, 2, 5, 10, 12, 24, 48, 50, 100 }; |
89 | |
|
90 | 0 | for (sal_uInt16 i = TABLE_COUNT - 1; i > 0; i--) |
91 | 0 | xPopup->append(OUString::number(TABLE_COUNT - i), OUString::number(aTable[i]) + ":1"); |
92 | 0 | for (sal_uInt16 i = 0; i < TABLE_COUNT; i++) |
93 | 0 | xPopup->append(OUString::number(TABLE_COUNT + i), "1:" + OUString::number(aTable[i])); |
94 | |
|
95 | 0 | ::tools::Rectangle aRect(rCEvt.GetMousePosPixel(), Size(1, 1)); |
96 | 0 | weld::Window* pParent = weld::GetPopupParent(GetStatusBar(), aRect); |
97 | 0 | OUString sResult = xPopup->popup_at_rect(pParent, aRect); |
98 | 0 | if (sResult.isEmpty()) |
99 | 0 | return; |
100 | | |
101 | 0 | sal_Int32 i = sResult.toUInt32(); |
102 | 0 | sal_Int32 nX; |
103 | 0 | sal_Int32 nY; |
104 | 0 | if (i > TABLE_COUNT - 1) |
105 | 0 | nX = 1; |
106 | 0 | else |
107 | 0 | nX = aTable[(TABLE_COUNT - i) % TABLE_COUNT]; |
108 | 0 | if (i > TABLE_COUNT - 1) |
109 | 0 | nY = aTable[i % TABLE_COUNT]; |
110 | 0 | else |
111 | 0 | nY = 1; |
112 | 0 | pDoc->SetUIScale(double(nX) / nY); |
113 | |
|
114 | 0 | SfxBindings& pBindings = pViewFrame->GetBindings(); |
115 | 0 | pBindings.Invalidate(SID_SCALE); //update statusbar |
116 | 0 | pBindings.Invalidate(SID_ATTR_METRIC); //update sidebar |
117 | 0 | pViewShellBase->UpdateBorder(true); // update ruler |
118 | 0 | } |
119 | | |
120 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |