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 <svl/eitem.hxx>
19 #include <sfx2/watermarkitem.hxx>
20 #include <svtools/ctrltool.hxx>
22 SwWatermarkDialog::SwWatermarkDialog( vcl::Window
* pParent
, SfxBindings
& rBindings
)
23 : ModelessDialog( pParent
, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" )
24 , m_rBindings( rBindings
)
26 get( m_pTextInput
, "TextInput" );
27 get( m_pOKButton
, "ok" );
28 get( m_pFont
, "FontBox" );
29 get( m_pAngle
, "Angle" );
30 get( m_pTransparency
, "Transparency" );
31 get( m_pColor
, "Color" );
37 SwWatermarkDialog::~SwWatermarkDialog()
42 void SwWatermarkDialog::dispose()
46 m_pTransparency
.clear();
51 ModelessDialog::dispose();
54 void SwWatermarkDialog::InitFields()
57 SfxObjectShell
* pDocSh
= SfxObjectShell::Current();
58 const SfxPoolItem
* pFontItem
;
59 const FontList
* pFontList
= nullptr;
60 std::unique_ptr
<FontList
> xFontList
;
62 if ( pDocSh
&& ( ( pFontItem
= pDocSh
->GetItem( SID_ATTR_CHAR_FONTLIST
) ) != nullptr ) )
63 pFontList
= static_cast<const SvxFontListItem
*>( pFontItem
)->GetFontList();
67 xFontList
.reset(new FontList(Application::GetDefaultDevice(), nullptr));
68 pFontList
= xFontList
.get();
71 m_pFont
->Fill( pFontList
);
73 m_pOKButton
->SetClickHdl( LINK( this, SwWatermarkDialog
, OKButtonHdl
) );
75 // Get watermark properties
76 const SfxPoolItem
* pItem
;
77 SfxItemState eState
= m_rBindings
.GetDispatcher()->QueryState( SID_WATERMARK
, pItem
);
79 if( eState
>= SfxItemState::DEFAULT
&& pItem
&& pItem
->Which() == SID_WATERMARK
)
81 const SfxWatermarkItem
* pWatermark
= static_cast<const SfxWatermarkItem
*>( pItem
);
82 OUString sText
= pWatermark
->GetText();
83 m_pTextInput
->SetText( sText
);
84 m_pFont
->SelectEntryPos( m_pFont
->GetEntryPos( pWatermark
->GetFont() ) );
85 m_pAngle
->SetValue( pWatermark
->GetAngle() );
86 m_pColor
->SelectEntry( pWatermark
->GetColor() );
87 m_pTransparency
->SetValue( pWatermark
->GetTransparency() );
91 IMPL_LINK_NOARG( SwWatermarkDialog
, OKButtonHdl
, Button
*, void )
93 OUString sText
= m_pTextInput
->GetText();
95 css::uno::Sequence
<css::beans::PropertyValue
> aPropertyValues( comphelper::InitPropertySequence(
97 { "Text", css::uno::makeAny( sText
) },
98 { "Font", css::uno::makeAny( m_pFont
->GetSelectEntry() ) },
99 { "Angle", css::uno::makeAny( static_cast<sal_Int16
>( m_pAngle
->GetValue() ) ) },
100 { "Transparency", css::uno::makeAny( static_cast<sal_Int16
>( m_pTransparency
->GetValue() ) ) },
101 { "Color", css::uno::makeAny( static_cast<sal_uInt32
>( m_pColor
->GetSelectEntryColor().GetRGBColor() ) ) }
103 comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues
);
108 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */