1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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/.
10 #include <watermarkdialog.hxx>
11 #include <comphelper/propertysequence.hxx>
12 #include <comphelper/dispatchcommand.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>
20 #include <sfx2/watermarkitem.hxx>
21 #include <svtools/ctrltool.hxx>
22 #include <comphelper/lok.hxx>
23 #include <sfx2/viewsh.hxx>
25 #define IS_MOBILE (comphelper::LibreOfficeKit::isActive() && SfxViewShell::Current() && SfxViewShell::Current()->isLOKMobilePhone())
27 SwWatermarkDialog::SwWatermarkDialog(weld::Window
* pParent
, SfxBindings
& rBindings
)
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(); }))
41 m_xBuilder
->weld_label("ColorLabel")->hide();
43 m_xBuilder
->weld_button("cancel")->hide();
44 m_xBuilder
->weld_button("help")->hide();
48 SwWatermarkDialog::~SwWatermarkDialog()
52 void SwWatermarkDialog::InitFields()
55 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
56 const SfxPoolItem
* pFontItem
;
57 const FontList
* pFontList
= nullptr;
58 std::unique_ptr
<FontList
> xFontList
;
60 if ( pDocSh
&& ( ( pFontItem
= pDocSh
->GetItem( SID_ATTR_CHAR_FONTLIST
) ) != nullptr ) )
61 pFontList
= static_cast<const SvxFontListItem
*>( pFontItem
)->GetFontList();
65 xFontList
.reset(new FontList(Application::GetDefaultDevice(), nullptr));
66 pFontList
= xFontList
.get();
70 sal_uInt16 nFontCount
= pFontList
->GetFontNameCount();
71 for (sal_uInt16 i
= 0; i
< nFontCount
; ++i
)
73 const FontMetric
& rFontMetric
= pFontList
->GetFontName(i
);
74 m_xFont
->append_text(rFontMetric
.GetFamilyName());
78 m_xOKButton
->connect_clicked(LINK(this, SwWatermarkDialog
, OKButtonHdl
));
80 // Get watermark properties
81 const SfxWatermarkItem
* pWatermark
;
82 SfxItemState eState
= m_rBindings
.GetDispatcher()->QueryState( SID_WATERMARK
, pWatermark
);
84 if( !(eState
>= SfxItemState::DEFAULT
&& pWatermark
&& pWatermark
->Which() == SID_WATERMARK
))
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
);
92 m_xFont
->set_active(nFontIndex
);
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
);
100 IMPL_LINK_NOARG(SwWatermarkDialog
, OKButtonHdl
, weld::Button
&, void)
102 OUString sText
= m_xTextInput
->get_text();
104 css::uno::Sequence
<css::beans::PropertyValue
> aPropertyValues( comphelper::InitPropertySequence(
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() ) ) }
112 comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues
);
114 m_xDialog
->response(RET_OK
);
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */