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 <sfx2/watermarkitem.hxx>
21 #include <svtools/ctrltool.hxx>
22 #include <comphelper/lok.hxx>
23 #include <sfx2/lokhelper.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"), 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 SfxPoolItem* pItem;
82  SfxItemState eState = m_rBindings.GetDispatcher()->QueryState( SID_WATERMARK, pItem );
83 
84  if( !(eState >= SfxItemState::DEFAULT && pItem && pItem->Which() == SID_WATERMARK))
85  return;
86 
87  const SfxWatermarkItem* pWatermark = static_cast<const SfxWatermarkItem*>( pItem );
88  const OUString& sText = pWatermark->GetText();
89  m_xTextInput->set_text(sText);
90  OUString sFontName = pWatermark->GetFont();
91  int nFontIndex = m_xFont->find_text(sFontName);
92  if (nFontIndex != -1)
93  m_xFont->set_active(nFontIndex);
94  else
95  m_xFont->set_entry_text(sFontName);
96  m_xAngle->set_value(pWatermark->GetAngle(), FieldUnit::DEGREE);
97  m_xColor->SelectEntry( pWatermark->GetColor() );
98  m_xTransparency->set_value(pWatermark->GetTransparency(), FieldUnit::PERCENT);
99 }
100 
102 {
103  OUString sText = m_xTextInput->get_text();
104 
105  css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence(
106  {
107  { "Text", css::uno::makeAny( sText ) },
108  { "Font", css::uno::makeAny( m_xFont->get_active_text() ) },
109  { "Angle", css::uno::makeAny( static_cast<sal_Int16>( m_xAngle->get_value(FieldUnit::DEGREE) ) ) },
110  { "Transparency", css::uno::makeAny( static_cast<sal_Int16>( m_xTransparency->get_value(FieldUnit::PERCENT) ) ) },
111  { "Color", css::uno::makeAny( static_cast<sal_uInt32>( m_xColor->GetSelectEntryColor().GetRGBColor() ) ) }
112  } ) );
113  comphelper::dispatchCommand( ".uno:Watermark", aPropertyValues );
114 
115  m_xDialog->response(RET_OK);
116 }
117 
118 /* 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)
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
constexpr OUStringLiteral PERCENT(u"Percent")
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
int i
SfxBindings & m_rBindings
std::unique_ptr< weld::ComboBox > m_xFont
PropertyValueVector_t aPropertyValues
SfxItemState QueryState(sal_uInt16 nSID, const SfxPoolItem *&rpState)
size_t GetFontNameCount() const
OUString const & GetFont() const
SfxItemState
RET_OK
#define IS_MOBILE
Reference< XExecutableDialog > m_xDialog
Color GetColor() const
SfxDispatcher * GetDispatcher() const
sal_uInt16 Which() const
sal_Int16 GetAngle() const