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