1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <watermarkdialog.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/dispatchcommand.hxx>
#include <editeng/editids.hrc>
#include <editeng/flstitem.hxx>
#include <sfx2/sfxsids.hrc>
#include <sfx2/bindings.hxx>
#include <sfx2/dispatch.hxx>
#include <svl/eitem.hxx>
#include <sfx2/watermarkitem.hxx>
#include <svtools/ctrltool.hxx>
SwWatermarkDialog::SwWatermarkDialog( vcl::Window* pParent, SfxBindings& rBindings )
: ModelessDialog( pParent, "WatermarkDialog", "modules/swriter/ui/watermarkdialog.ui" )
, m_rBindings( rBindings )
{
get( m_pTextGrid, "TextGrid" );
get( m_pEnableWatermarkCB, "EnableWatermarkCB" );
get( m_pTextInput, "TextInput" );
get( m_pOKButton, "ok" );
get( m_pFont, "FontBox" );
get( m_pAngle, "Angle" );
get( m_pTransparency, "Transparency" );
get( m_pColor, "Color" );
InitFields();
Update();
}
SwWatermarkDialog::~SwWatermarkDialog()
{
disposeOnce();
}
void SwWatermarkDialog::dispose()
{
m_pFont.clear();
m_pAngle.clear();
m_pTransparency.clear();
m_pColor.clear();
m_pTextGrid.clear();
m_pEnableWatermarkCB.clear();
m_pTextInput.clear();
m_pOKButton.clear();
ModelessDialog::dispose();
}
void SwWatermarkDialog::InitFields()
{
// Update font list
SfxObjectShell* pDocSh = SfxObjectShell::Current();
const SfxPoolItem* pFontItem;
const FontList* pFontList = nullptr;
if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) )
pFontList = static_cast<const SvxFontListItem*>( pFontItem )->GetFontList();
if(!pFontList)
pFontList = new FontList(Application::GetDefaultDevice(), nullptr);
m_pFont->Fill( pFontList );
m_pEnableWatermarkCB->SetClickHdl( LINK( this, SwWatermarkDialog, CheckBoxHdl ) );
m_pOKButton->SetClickHdl( LINK( this, SwWatermarkDialog, OKButtonHdl ) );
// Get watermark properties
const SfxPoolItem* pItem;
SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pItem );
if( eState >= SfxItemState::DEFAULT && pItem && pItem->Which() == SID_WATERMARK)
{
const SfxWatermarkItem* pWatermark = static_cast<const SfxWatermarkItem*>( pItem );
OUString sText = pWatermark->GetText();
m_pEnableWatermarkCB->Check( !sText.isEmpty() );
m_pTextInput->SetText( sText );
m_pFont->SelectEntryPos( m_pFont->GetEntryPos( pWatermark->GetFont() ) );
m_pAngle->SetValue( pWatermark->GetAngle() );
m_pColor->SelectEntry( pWatermark->GetColor() );
m_pTransparency->SetValue( pWatermark->GetTransparency() );
}
}
void SwWatermarkDialog::Update()
{
if( m_pEnableWatermarkCB->IsChecked() )
m_pTextGrid->Enable();
else
m_pTextGrid->Disable();
}
IMPL_LINK_NOARG( SwWatermarkDialog, CheckBoxHdl, Button*, void )
{
Update();
}
IMPL_LINK_NOARG( SwWatermarkDialog, OKButtonHdl, Button*, void )
{
OUString sText = "";
if( m_pEnableWatermarkCB->IsChecked() )
sText = m_pTextInput->GetText();
css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence(
{
{ "Text", css::uno::makeAny( sText ) },
{ "Font", css::uno::makeAny( m_pFont->GetSelectEntry() ) },
{ "Angle", css::uno::makeAny( static_cast<sal_Int16>( m_pAngle->GetValue() ) ) },
{ "Transparency", css::uno::makeAny( static_cast<sal_Int16>( m_pTransparency->GetValue() ) ) },
{ "Color", css::uno::makeAny( static_cast<sal_uInt32>( m_pColor->GetSelectEntryColor().GetRGBColor() ) ) }
} ) );
comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
Close();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
|