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>
20 #include <svl/eitem.hxx>
21 #include <sfx2/watermarkitem.hxx>
22 #include <svtools/ctrltool.hxx>
23 
25  : SfxDialogController(pParent, "modules/swriter/ui/watermarkdialog.ui", "WatermarkDialog")
26  , m_rBindings(rBindings)
27  , m_xTextInput(m_xBuilder->weld_entry("TextInput"))
28  , m_xOKButton(m_xBuilder->weld_button("ok"))
29  , m_xFont(m_xBuilder->weld_combo_box("FontBox"))
30  , m_xAngle(m_xBuilder->weld_metric_spin_button("Angle", FieldUnit::DEGREE))
31  , m_xTransparency(m_xBuilder->weld_metric_spin_button("Transparency", FieldUnit::PERCENT))
32  , m_xColor(new ColorListBox(m_xBuilder->weld_menu_button("Color"), m_xDialog.get()))
33 {
34  InitFields();
35 }
36 
38 {
39 }
40 
42 {
43  // Update font list
45  const SfxPoolItem* pFontItem;
46  const FontList* pFontList = nullptr;
47  std::unique_ptr<FontList> xFontList;
48 
49  if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) )
50  pFontList = static_cast<const SvxFontListItem*>( pFontItem )->GetFontList();
51 
52  if (!pFontList)
53  {
54  xFontList.reset(new FontList(Application::GetDefaultDevice(), nullptr));
55  pFontList = xFontList.get();
56  }
57 
58  sal_uInt16 nFontCount = pFontList->GetFontNameCount();
59  for (sal_uInt16 i = 0; i < nFontCount; ++i)
60  {
61  const FontMetric& rFontMetric = pFontList->GetFontName(i);
62  m_xFont->append_text(rFontMetric.GetFamilyName());
63  }
64 
65  m_xOKButton->connect_clicked(LINK(this, SwWatermarkDialog, OKButtonHdl));
66 
67  // Get watermark properties
68  const SfxPoolItem* pItem;
69  SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pItem );
70 
71  if( eState >= SfxItemState::DEFAULT && pItem && pItem->Which() == SID_WATERMARK)
72  {
73  const SfxWatermarkItem* pWatermark = static_cast<const SfxWatermarkItem*>( pItem );
74  const OUString& sText = pWatermark->GetText();
75  m_xTextInput->set_text(sText);
76  m_xFont->set_entry_text(pWatermark->GetFont());
77  m_xAngle->set_value(pWatermark->GetAngle(), FieldUnit::DEGREE);
78  m_xColor->SelectEntry( pWatermark->GetColor() );
79  m_xTransparency->set_value(pWatermark->GetTransparency(), FieldUnit::PERCENT);
80  }
81 }
82 
84 {
85  OUString sText = m_xTextInput->get_text();
86 
87  css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence(
88  {
89  { "Text", css::uno::makeAny( sText ) },
90  { "Font", css::uno::makeAny( m_xFont->get_active_text() ) },
91  { "Angle", css::uno::makeAny( static_cast<sal_Int16>( m_xAngle->get_value(FieldUnit::DEGREE) ) ) },
92  { "Transparency", css::uno::makeAny( static_cast<sal_Int16>( m_xTransparency->get_value(FieldUnit::PERCENT) ) ) },
93  { "Color", css::uno::makeAny( static_cast<sal_uInt32>( m_xColor->GetSelectEntryColor().GetRGBColor() ) ) }
94  } ) );
95  comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
96 
97  m_xDialog->response(RET_OK);
98 }
99 
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
PropertyValueVector_t const aPropertyValues
FieldUnit
std::unique_ptr< weld::Entry > m_xTextInput
const OUString & GetFamilyName() const
std::unique_ptr< weld::MetricSpinButton > m_xAngle
IMPL_LINK_NOARG(SwWatermarkDialog, OKButtonHdl, weld::Button &, void)
std::unique_ptr< weld::Button > m_xOKButton
sal_Int16 GetTransparency() const
static SfxObjectShell * Current()
virtual ~SwWatermarkDialog() override
static OutputDevice * GetDefaultDevice()
std::unique_ptr< weld::Button > m_xOKButton
std::unique_ptr< ColorListBox > m_xColor
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)
SwWatermarkDialog(weld::Window *pParent, SfxBindings &rBindings)
css::uno::Sequence< css::beans::PropertyValue > InitPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
const FontMetric & GetFontName(size_t nFont) const
const SfxPoolItem * GetItem(sal_uInt16 nSlotId) const
OUString const & GetText() const
std::unique_ptr< weld::MetricSpinButton > m_xTransparency
SfxBindings & m_rBindings
int i
std::unique_ptr< weld::ComboBox > m_xFont
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
size_t GetFontNameCount() const
OUString const & GetFont() const
SfxItemState
RET_OK
Reference< XExecutableDialog > m_xDialog
const OUString PERCENT("Percent")
Color GetColor() const
SfxDispatcher * GetDispatcher() const
sal_uInt16 Which() const
sal_Int16 GetAngle() const