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 <sal/config.h>
22 #include <comphelper/propertyvalue.hxx>
23 #include <i18nutil/unicode.hxx>
24 #include <vcl/commandevent.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/svapp.hxx>
27 #include <vcl/status.hxx>
28 #include <vcl/weldutils.hxx>
29 #include <vcl/settings.hxx>
30 #include <tools/urlobj.hxx>
31 #include <sal/log.hxx>
33 #include <svx/strings.hrc>
35 #include <svx/zoomctrl.hxx>
36 #include <sfx2/zoomitem.hxx>
37 #include <svx/dialmgr.hxx>
38 #include "modctrl_internal.hxx"
39 #include <bitmaps.hlst>
41 #include <com/sun/star/beans/PropertyValue.hpp>
43 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomStatusBarControl
,SvxZoomItem
);
50 ZoomPopup_Impl(weld::Window
* pPopupParent
, sal_uInt16 nZ
, SvxZoomEnableFlags nValueSet
);
52 sal_uInt16
GetZoom(std::string_view ident
) const;
54 OString
popup_at_rect(const tools::Rectangle
& rRect
)
56 return m_xMenu
->popup_at_rect(m_pPopupParent
, rRect
);
60 weld::Window
* m_pPopupParent
;
61 std::unique_ptr
<weld::Builder
> m_xBuilder
;
62 std::unique_ptr
<weld::Menu
> m_xMenu
;
68 ZoomPopup_Impl::ZoomPopup_Impl(weld::Window
* pPopupParent
, sal_uInt16 nZ
, SvxZoomEnableFlags nValueSet
)
69 : m_pPopupParent(pPopupParent
)
70 , m_xBuilder(Application::CreateBuilder(m_pPopupParent
, "svx/ui/zoommenu.ui"))
71 , m_xMenu(m_xBuilder
->weld_menu("menu"))
74 if ( !(SvxZoomEnableFlags::N50
& nValueSet
) )
75 m_xMenu
->set_sensitive("50", false);
76 if ( !(SvxZoomEnableFlags::N100
& nValueSet
) )
77 m_xMenu
->set_sensitive("100", false);
78 if ( !(SvxZoomEnableFlags::N150
& nValueSet
) )
79 m_xMenu
->set_sensitive("150", false);
80 if ( !(SvxZoomEnableFlags::N200
& nValueSet
) )
81 m_xMenu
->set_sensitive("200", false);
82 if ( !(SvxZoomEnableFlags::OPTIMAL
& nValueSet
) )
83 m_xMenu
->set_sensitive("optimal", false);
84 if ( !(SvxZoomEnableFlags::WHOLEPAGE
& nValueSet
) )
85 m_xMenu
->set_sensitive("page", false);
86 if ( !(SvxZoomEnableFlags::PAGEWIDTH
& nValueSet
) )
87 m_xMenu
->set_sensitive("width", false);
90 sal_uInt16
ZoomPopup_Impl::GetZoom(std::string_view ident
) const
92 sal_uInt16 nRet
= nZoom
;
96 else if (ident
== "150")
98 else if (ident
== "100")
100 else if (ident
== "75")
102 else if (ident
== "50")
104 else if (ident
== "optimal" || ident
== "width" || ident
== "page")
110 SvxZoomStatusBarControl::SvxZoomStatusBarControl( sal_uInt16 _nSlotId
,
114 SfxStatusBarControl( _nSlotId
, _nId
, rStb
),
116 nValueSet( SvxZoomEnableFlags::ALL
)
118 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_ZOOMTOOL_HINT
));
119 ImplUpdateItemText();
122 void SvxZoomStatusBarControl::StateChangedAtStatusBarControl( sal_uInt16
, SfxItemState eState
,
123 const SfxPoolItem
* pState
)
125 if( SfxItemState::DEFAULT
!= eState
)
127 GetStatusBar().SetItemText( GetId(), "" );
128 nValueSet
= SvxZoomEnableFlags::NONE
;
130 else if ( auto pItem
= dynamic_cast< const SfxUInt16Item
* >(pState
) )
132 nZoom
= pItem
->GetValue();
133 ImplUpdateItemText();
135 if ( auto pZoomItem
= dynamic_cast<const SvxZoomItem
*>(pState
) )
137 nValueSet
= pZoomItem
->GetValueSet();
141 SAL_INFO( "svx", "use SfxZoomItem for SID_ATTR_ZOOM" );
142 nValueSet
= SvxZoomEnableFlags::ALL
;
147 void SvxZoomStatusBarControl::ImplUpdateItemText()
149 // workaround - don't bother updating when we don't have a real zoom value
152 OUString
aStr(unicode::formatPercent(nZoom
, Application::GetSettings().GetUILanguageTag()));
153 GetStatusBar().SetItemText( GetId(), aStr
);
157 void SvxZoomStatusBarControl::Paint( const UserDrawEvent
& )
161 void SvxZoomStatusBarControl::Command( const CommandEvent
& rCEvt
)
163 if ( CommandEventId::ContextMenu
== rCEvt
.GetCommand() && bool(nValueSet
) )
165 ::tools::Rectangle
aRect(rCEvt
.GetMousePosPixel(), Size(1, 1));
166 weld::Window
* pPopupParent
= weld::GetPopupParent(GetStatusBar(), aRect
);
167 ZoomPopup_Impl
aPop(pPopupParent
, nZoom
, nValueSet
);
169 OString sIdent
= aPop
.popup_at_rect(aRect
);
170 if (!sIdent
.isEmpty() && (nZoom
!= aPop
.GetZoom(sIdent
) || !nZoom
))
172 nZoom
= aPop
.GetZoom(sIdent
);
173 ImplUpdateItemText();
174 SvxZoomItem
aZoom(SvxZoomType::PERCENT
, nZoom
, GetId());
176 if (sIdent
== "optimal")
177 aZoom
.SetType(SvxZoomType::OPTIMAL
);
178 else if (sIdent
== "width")
179 aZoom
.SetType(SvxZoomType::PAGEWIDTH
);
180 else if (sIdent
== "page")
181 aZoom
.SetType(SvxZoomType::WHOLEPAGE
);
184 aZoom
.QueryValue( a
);
185 INetURLObject
aObj( m_aCommandURL
);
187 css::uno::Sequence
< css::beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue(
188 aObj
.GetURLPath(), a
) };
193 SfxStatusBarControl::Command( rCEvt
);
196 SFX_IMPL_STATUSBAR_CONTROL(SvxZoomPageStatusBarControl
,SfxVoidItem
);
198 SvxZoomPageStatusBarControl::SvxZoomPageStatusBarControl(sal_uInt16 _nSlotId
,
199 sal_uInt16 _nId
, StatusBar
& rStb
)
200 : SfxStatusBarControl(_nSlotId
, _nId
, rStb
)
201 , maImage(StockImage::Yes
, RID_SVXBMP_ZOOM_PAGE
)
203 GetStatusBar().SetQuickHelpText(GetId(), SvxResId(RID_SVXSTR_FIT_SLIDE
));
206 void SvxZoomPageStatusBarControl::Paint(const UserDrawEvent
& rUsrEvt
)
208 vcl::RenderContext
* pDev
= rUsrEvt
.GetRenderContext();
209 tools::Rectangle aRect
= rUsrEvt
.GetRect();
210 Point aPt
= centerImage(aRect
, maImage
);
211 pDev
->DrawImage(aPt
, maImage
);
214 bool SvxZoomPageStatusBarControl::MouseButtonDown(const MouseEvent
&)
216 SvxZoomItem
aZoom( SvxZoomType::WHOLEPAGE
, 0, GetId() );
219 aZoom
.QueryValue( a
);
220 INetURLObject
aObj( m_aCommandURL
);
222 css::uno::Sequence
< css::beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue(
223 aObj
.GetURLPath(), a
) };
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */