LibreOffice Module sw (master) 1
watermarkdialog.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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
10#include <watermarkdialog.hxx>
13#include <editeng/editids.hrc>
14#include <editeng/flstitem.hxx>
15#include <sfx2/sfxsids.hrc>
16#include <sfx2/bindings.hxx>
17#include <sfx2/dispatch.hxx>
18#include <sfx2/objsh.hxx>
19#include <vcl/svapp.hxx>
21#include <svtools/ctrltool.hxx>
22#include <comphelper/lok.hxx>
23#include <sfx2/viewsh.hxx>
24
25#define IS_MOBILE (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())
26
28 : SfxDialogController(pParent, "modules/swriter/ui/watermarkdialog.ui", "WatermarkDialog")
29 , m_rBindings(rBindings)
30 , m_xTextInput(m_xBuilder->weld_entry("TextInput"))
31 , m_xOKButton(m_xBuilder->weld_button("ok"))
32 , m_xFont(m_xBuilder->weld_combo_box("FontBox"))
33 , m_xAngle(m_xBuilder->weld_metric_spin_button("Angle", FieldUnit::DEGREE))
34 , m_xTransparency(m_xBuilder->weld_metric_spin_button("Transparency", FieldUnit::PERCENT))
35 , m_xColor(new ColorListBox(m_xBuilder->weld_menu_button("Color"), [this]{ return m_xDialog.get(); }))
36{
37 InitFields();
38
39 if (IS_MOBILE)
40 {
41 m_xBuilder->weld_label("ColorLabel")->hide();
42 m_xColor->hide();
43 m_xBuilder->weld_button("cancel")->hide();
44 m_xBuilder->weld_button("help")->hide();
45 }
46}
47
49{
50}
51
53{
54 // Update font list
56 const SfxPoolItem* pFontItem;
57 const FontList* pFontList = nullptr;
58 std::unique_ptr<FontList> xFontList;
59
60 if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) )
61 pFontList = static_cast<const SvxFontListItem*>( pFontItem )->GetFontList();
62
63 if (!pFontList)
64 {
65 xFontList.reset(new FontList(Application::GetDefaultDevice(), nullptr));
66 pFontList = xFontList.get();
67 }
68
69 m_xFont->freeze();
70 sal_uInt16 nFontCount = pFontList->GetFontNameCount();
71 for (sal_uInt16 i = 0; i < nFontCount; ++i)
72 {
73 const FontMetric& rFontMetric = pFontList->GetFontName(i);
74 m_xFont->append_text(rFontMetric.GetFamilyName());
75 }
76 m_xFont->thaw();
77
78 m_xOKButton->connect_clicked(LINK(this, SwWatermarkDialog, OKButtonHdl));
79
80 // Get watermark properties
81 const SfxWatermarkItem* pWatermark;
82 SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pWatermark );
83
84 if( !(eState >= SfxItemState::DEFAULT && pWatermark && pWatermark->Which() == SID_WATERMARK))
85 return;
86
87 const OUString& sText = pWatermark->GetText();
88 m_xTextInput->set_text(sText);
89 OUString sFontName = pWatermark->GetFont();
90 int nFontIndex = m_xFont->find_text(sFontName);
91 if (nFontIndex != -1)
92 m_xFont->set_active(nFontIndex);
93 else
94 m_xFont->set_entry_text(sFontName);
95 m_xAngle->set_value(pWatermark->GetAngle(), FieldUnit::DEGREE);
96 m_xColor->SelectEntry( pWatermark->GetColor() );
97 m_xTransparency->set_value(pWatermark->GetTransparency(), FieldUnit::PERCENT);
98}
99
101{
102 OUString sText = m_xTextInput->get_text();
103
104 css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence(
105 {
106 { "Text", css::uno::Any( sText ) },
107 { "Font", css::uno::Any( m_xFont->get_active_text() ) },
108 { "Angle", css::uno::Any( static_cast<sal_Int16>( m_xAngle->get_value(FieldUnit::DEGREE) ) ) },
109 { "Transparency", css::uno::Any( static_cast<sal_Int16>( m_xTransparency->get_value(FieldUnit::PERCENT) ) ) },
110 { "Color", css::uno::Any( static_cast<sal_uInt32>( m_xColor->GetSelectEntryColor().GetRGBColor() ) ) }
111 } ) );
112 comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
113
114 m_xDialog->response(RET_OK);
115}
116
117/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
PropertyValueVector_t aPropertyValues
Reference< XExecutableDialog > m_xDialog
static OutputDevice * GetDefaultDevice()
size_t GetFontNameCount() const
const FontMetric & GetFontName(size_t nFont) const
SfxDispatcher * GetDispatcher() const
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
sal_Int16 GetTransparency() const
OUString const & GetFont() const
OUString const & GetText() const
sal_Int16 GetAngle() const
Color GetColor() const
virtual ~SwWatermarkDialog() override
std::unique_ptr< weld::Button > m_xOKButton
SfxBindings & m_rBindings
SwWatermarkDialog(weld::Window *pParent, SfxBindings &rBindings)
std::unique_ptr< ColorListBox > m_xColor
std::unique_ptr< weld::MetricSpinButton > m_xTransparency
std::unique_ptr< weld::ComboBox > m_xFont
std::unique_ptr< weld::Entry > m_xTextInput
std::unique_ptr< weld::MetricSpinButton > m_xAngle
const OUString & GetFamilyName() const
FieldUnit
std::unique_ptr< weld::Button > m_xOKButton
bool dispatchCommand(const OUString &rCommand, const uno::Reference< css::frame::XFrame > &rFrame, const css::uno::Sequence< css::beans::PropertyValue > &rArguments, const uno::Reference< css::frame::XDispatchResultListener > &rListener)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
int i
SfxItemState
constexpr OUStringLiteral PERCENT(u"Percent")
RET_OK
#define IS_MOBILE
IMPL_LINK_NOARG(SwWatermarkDialog, OKButtonHdl, weld::Button &, void)