/src/libreoffice/sw/source/uibase/dialog/watermarkdialog.cxx
Line | Count | Source |
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> |
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 <tools/fldunit.hxx> |
20 | | #include <vcl/metric.hxx> |
21 | | #include <vcl/svapp.hxx> |
22 | | #include <vcl/weld/Dialog.hxx> |
23 | | #include <vcl/weld/Label.hxx> |
24 | | #include <sfx2/watermarkitem.hxx> |
25 | | #include <svtools/ctrltool.hxx> |
26 | | #include <comphelper/lok.hxx> |
27 | | #include <sfx2/viewsh.hxx> |
28 | | #include <svl/itemset.hxx> |
29 | | #include <vcl/weld/Builder.hxx> |
30 | | |
31 | | SwWatermarkDialog::SwWatermarkDialog(weld::Window* pParent, SfxBindings& rBindings) |
32 | 0 | : SfxDialogController(pParent, u"modules/swriter/ui/watermarkdialog.ui"_ustr, u"WatermarkDialog"_ustr) |
33 | 0 | , m_rBindings(rBindings) |
34 | 0 | , m_xTextInput(m_xBuilder->weld_entry(u"TextInput"_ustr)) |
35 | 0 | , m_xOKButton(m_xBuilder->weld_button(u"ok"_ustr)) |
36 | 0 | , m_xFont(m_xBuilder->weld_combo_box(u"FontBox"_ustr)) |
37 | 0 | , m_xAngle(m_xBuilder->weld_metric_spin_button(u"Angle"_ustr, FieldUnit::DEGREE)) |
38 | 0 | , m_xTransparency(m_xBuilder->weld_metric_spin_button(u"Transparency"_ustr, FieldUnit::PERCENT)) |
39 | 0 | , m_xColor(new ColorListBox(m_xBuilder->weld_menu_button(u"Color"_ustr), [this]{ return m_xDialog.get(); })) |
40 | 0 | { |
41 | 0 | InitFields(); |
42 | 0 | } |
43 | | |
44 | | SwWatermarkDialog::~SwWatermarkDialog() |
45 | 0 | { |
46 | 0 | } |
47 | | |
48 | | void SwWatermarkDialog::InitFields() |
49 | 0 | { |
50 | | // Update font list |
51 | 0 | SfxObjectShell* pDocSh = SfxObjectShell::Current(); |
52 | 0 | const SvxFontListItem* pFontItem; |
53 | 0 | const FontList* pFontList = nullptr; |
54 | 0 | std::unique_ptr<FontList> xFontList; |
55 | |
|
56 | 0 | if ( pDocSh && ( ( pFontItem = pDocSh->GetItem( SID_ATTR_CHAR_FONTLIST ) ) != nullptr ) ) |
57 | 0 | pFontList = pFontItem->GetFontList(); |
58 | |
|
59 | 0 | if (!pFontList) |
60 | 0 | { |
61 | 0 | xFontList.reset(new FontList(Application::GetDefaultDevice(), nullptr)); |
62 | 0 | pFontList = xFontList.get(); |
63 | 0 | } |
64 | |
|
65 | 0 | m_xFont->freeze(); |
66 | 0 | sal_uInt16 nFontCount = pFontList->GetFontNameCount(); |
67 | 0 | for (sal_uInt16 i = 0; i < nFontCount; ++i) |
68 | 0 | { |
69 | 0 | const FontMetric& rFontMetric = pFontList->GetFontName(i); |
70 | 0 | m_xFont->append_text(rFontMetric.GetFamilyName()); |
71 | 0 | } |
72 | 0 | m_xFont->thaw(); |
73 | |
|
74 | 0 | m_xOKButton->connect_clicked(LINK(this, SwWatermarkDialog, OKButtonHdl)); |
75 | | |
76 | | // Get watermark properties |
77 | 0 | SfxPoolItemHolder aResult; |
78 | 0 | const SfxItemState eState(m_rBindings.GetDispatcher()->QueryState(SID_WATERMARK, aResult)); |
79 | 0 | const SfxWatermarkItem* pWatermark(static_cast<const SfxWatermarkItem*>(aResult.getItem())); |
80 | |
|
81 | 0 | if( !(eState >= SfxItemState::DEFAULT && pWatermark && pWatermark->Which() == SID_WATERMARK)) |
82 | 0 | return; |
83 | | |
84 | 0 | const OUString& sText = pWatermark->GetText(); |
85 | 0 | m_xTextInput->set_text(sText); |
86 | 0 | OUString sFontName = pWatermark->GetFont(); |
87 | 0 | int nFontIndex = m_xFont->find_text(sFontName); |
88 | 0 | if (nFontIndex != -1) |
89 | 0 | m_xFont->set_active(nFontIndex); |
90 | 0 | else |
91 | 0 | m_xFont->set_entry_text(sFontName); |
92 | 0 | m_xAngle->set_value(pWatermark->GetAngle(), FieldUnit::DEGREE); |
93 | 0 | m_xColor->SelectEntry( pWatermark->GetColor() ); |
94 | 0 | m_xTransparency->set_value(pWatermark->GetTransparency(), FieldUnit::PERCENT); |
95 | 0 | } |
96 | | |
97 | | IMPL_LINK_NOARG(SwWatermarkDialog, OKButtonHdl, weld::Button&, void) |
98 | 0 | { |
99 | 0 | OUString sText = m_xTextInput->get_text(); |
100 | |
|
101 | 0 | css::uno::Sequence<css::beans::PropertyValue> aPropertyValues( comphelper::InitPropertySequence( |
102 | 0 | { |
103 | 0 | { "Text", css::uno::Any( sText ) }, |
104 | 0 | { "Font", css::uno::Any( m_xFont->get_active_text() ) }, |
105 | 0 | { "Angle", css::uno::Any( static_cast<sal_Int16>( m_xAngle->get_value(FieldUnit::DEGREE) ) ) }, |
106 | 0 | { "Transparency", css::uno::Any( static_cast<sal_Int16>( m_xTransparency->get_value(FieldUnit::PERCENT) ) ) }, |
107 | 0 | { "Color", css::uno::Any( static_cast<sal_uInt32>( m_xColor->GetSelectEntryColor().GetRGBColor() ) ) } |
108 | 0 | } ) ); |
109 | 0 | comphelper::dispatchCommand( u".uno:Watermark"_ustr, aPropertyValues ); |
110 | |
|
111 | 0 | m_xDialog->response(RET_OK); |
112 | 0 | } |
113 | | |
114 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ |