LibreOffice Module cui (master) 1
SignatureLineDialog.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
11
13#include <utility>
14#include <vcl/weld.hxx>
16
17#include <com/sun/star/beans/XPropertySet.hpp>
18#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
19#include <com/sun/star/drawing/XShape.hpp>
20#include <com/sun/star/graphic/XGraphic.hpp>
21#include <com/sun/star/lang/XMultiServiceFactory.hpp>
22#include <com/sun/star/sheet/XSpreadsheet.hpp>
23#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
24#include <com/sun/star/sheet/XSpreadsheetView.hpp>
25#include <com/sun/star/text/TextContentAnchorType.hpp>
26#include <com/sun/star/text/XTextContent.hpp>
27#include <com/sun/star/text/XTextDocument.hpp>
28#include <com/sun/star/text/XTextViewCursor.hpp>
29#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
30
31using namespace css;
32using namespace css::uno;
33using namespace css::beans;
34using namespace css::container;
35using namespace css::frame;
36using namespace css::lang;
37using namespace css::frame;
38using namespace css::sheet;
39using namespace css::text;
40using namespace css::drawing;
41using namespace css::graphic;
42
43SignatureLineDialog::SignatureLineDialog(weld::Widget* pParent, Reference<XModel> xModel,
44 bool bEditExisting)
45 : SignatureLineDialogBase(pParent, std::move(xModel), "cui/ui/signatureline.ui",
46 "SignatureLineDialog")
47 , m_xEditName(m_xBuilder->weld_entry("edit_name"))
48 , m_xEditTitle(m_xBuilder->weld_entry("edit_title"))
49 , m_xEditEmail(m_xBuilder->weld_entry("edit_email"))
50 , m_xEditInstructions(m_xBuilder->weld_text_view("edit_instructions"))
51 , m_xCheckboxCanAddComments(m_xBuilder->weld_check_button("checkbox_can_add_comments"))
52 , m_xCheckboxShowSignDate(m_xBuilder->weld_check_button("checkbox_show_sign_date"))
53{
54 m_xEditInstructions->set_size_request(m_xEditInstructions->get_approximate_digit_width() * 48,
55 m_xEditInstructions->get_text_height() * 5);
56
57 // No signature line selected - start with empty dialog and set some default values
58 if (!bEditExisting)
59 {
60 m_xCheckboxCanAddComments->set_active(true);
61 m_xCheckboxShowSignDate->set_active(true);
62 return;
63 }
64
65 Reference<container::XIndexAccess> xIndexAccess(m_xModel->getCurrentSelection(),
66 UNO_QUERY_THROW);
67 Reference<XPropertySet> xProps(xIndexAccess->getByIndex(0), UNO_QUERY_THROW);
68
69 // Read properties from selected signature line
70 xProps->getPropertyValue("SignatureLineId") >>= m_aSignatureLineId;
71 OUString aSuggestedSignerName;
72 xProps->getPropertyValue("SignatureLineSuggestedSignerName") >>= aSuggestedSignerName;
73 m_xEditName->set_text(aSuggestedSignerName);
74 OUString aSuggestedSignerTitle;
75 xProps->getPropertyValue("SignatureLineSuggestedSignerTitle") >>= aSuggestedSignerTitle;
76 m_xEditTitle->set_text(aSuggestedSignerTitle);
77 OUString aSuggestedSignerEmail;
78 xProps->getPropertyValue("SignatureLineSuggestedSignerEmail") >>= aSuggestedSignerEmail;
79 m_xEditEmail->set_text(aSuggestedSignerEmail);
80 OUString aSigningInstructions;
81 xProps->getPropertyValue("SignatureLineSigningInstructions") >>= aSigningInstructions;
82 m_xEditInstructions->set_text(aSigningInstructions);
83 bool bCanAddComments = false;
84 xProps->getPropertyValue("SignatureLineCanAddComment") >>= bCanAddComments;
85 m_xCheckboxCanAddComments->set_active(bCanAddComments);
86 bool bShowSignDate = false;
87 xProps->getPropertyValue("SignatureLineShowSignDate") >>= bShowSignDate;
88 m_xCheckboxShowSignDate->set_active(bShowSignDate);
89
90 // Mark this as existing shape
92}
93
95{
96 if (m_aSignatureLineId.isEmpty())
98 = OStringToOUString(comphelper::xml::generateGUIDString(), RTL_TEXTENCODING_ASCII_US);
99 OUString aSignerName(m_xEditName->get_text());
100 OUString aSignerTitle(m_xEditTitle->get_text());
101 OUString aSignerEmail(m_xEditEmail->get_text());
102 OUString aSigningInstructions(m_xEditInstructions->get_text());
103 bool bCanAddComments(m_xCheckboxCanAddComments->get_active());
104 bool bShowSignDate(m_xCheckboxShowSignDate->get_active());
105
106 // Read svg and replace placeholder texts
108 aSvgImage = aSvgImage.replaceAll("[SIGNER_NAME]", getCDataString(aSignerName));
109 aSvgImage = aSvgImage.replaceAll("[SIGNER_TITLE]", getCDataString(aSignerTitle));
110
111 // These are only filled if the signature line is signed.
112 aSvgImage = aSvgImage.replaceAll("[SIGNATURE]", "");
113 aSvgImage = aSvgImage.replaceAll("[SIGNED_BY]", "");
114 aSvgImage = aSvgImage.replaceAll("[INVALID_SIGNATURE]", "");
115 aSvgImage = aSvgImage.replaceAll("[DATE]", "");
116
117 // Insert/Update graphic
118 Reference<XGraphic> xGraphic = svx::SignatureLineHelper::importSVG(aSvgImage);
119
120 bool bIsExistingSignatureLine = m_xExistingShapeProperties.is();
121 Reference<XPropertySet> xShapeProps;
122 if (bIsExistingSignatureLine)
123 xShapeProps = m_xExistingShapeProperties;
124 else
125 xShapeProps.set(Reference<lang::XMultiServiceFactory>(m_xModel, UNO_QUERY_THROW)
126 ->createInstance("com.sun.star.drawing.GraphicObjectShape"),
127 UNO_QUERY);
128
129 xShapeProps->setPropertyValue("Graphic", Any(xGraphic));
130 xShapeProps->setPropertyValue("SignatureLineUnsignedImage", Any(xGraphic));
131
132 // Set signature line properties
133 xShapeProps->setPropertyValue("IsSignatureLine", Any(true));
134 xShapeProps->setPropertyValue("SignatureLineId", Any(m_aSignatureLineId));
135 if (!aSignerName.isEmpty())
136 xShapeProps->setPropertyValue("SignatureLineSuggestedSignerName", Any(aSignerName));
137 if (!aSignerTitle.isEmpty())
138 xShapeProps->setPropertyValue("SignatureLineSuggestedSignerTitle", Any(aSignerTitle));
139 if (!aSignerEmail.isEmpty())
140 xShapeProps->setPropertyValue("SignatureLineSuggestedSignerEmail", Any(aSignerEmail));
141 if (!aSigningInstructions.isEmpty())
142 xShapeProps->setPropertyValue("SignatureLineSigningInstructions",
143 Any(aSigningInstructions));
144 xShapeProps->setPropertyValue("SignatureLineShowSignDate", Any(bShowSignDate));
145 xShapeProps->setPropertyValue("SignatureLineCanAddComment", Any(bCanAddComments));
146
147 if (bIsExistingSignatureLine)
148 return;
149
150 // Default size
151 Reference<XShape> xShape(xShapeProps, UNO_QUERY);
152 awt::Size aShapeSize;
153 aShapeSize.Height = 3000;
154 aShapeSize.Width = 6000;
155 xShape->setSize(aShapeSize);
156
157 // Default anchoring
158 xShapeProps->setPropertyValue("AnchorType", Any(TextContentAnchorType_AT_PARAGRAPH));
159
160 // Writer
161 const Reference<XTextDocument> xTextDocument(m_xModel, UNO_QUERY);
162 if (xTextDocument.is())
163 {
164 Reference<XTextContent> xTextContent(xShape, UNO_QUERY_THROW);
165 Reference<XTextViewCursorSupplier> xViewCursorSupplier(m_xModel->getCurrentController(),
166 UNO_QUERY_THROW);
167 Reference<XTextViewCursor> xCursor = xViewCursorSupplier->getViewCursor();
168 // use cursor's XText - it might be in table cell, frame, ...
169 Reference<XText> const xText(xCursor->getText());
170 assert(xText.is());
171 xText->insertTextContent(xCursor, xTextContent, true);
172 return;
173 }
174
175 // Calc
176 const Reference<XSpreadsheetDocument> xSpreadsheetDocument(m_xModel, UNO_QUERY);
177 if (!xSpreadsheetDocument.is())
178 return;
179
180 Reference<XPropertySet> xSheetCell(m_xModel->getCurrentSelection(), UNO_QUERY_THROW);
181 awt::Point aCellPosition;
182 xSheetCell->getPropertyValue("Position") >>= aCellPosition;
183 xShape->setPosition(aCellPosition);
184
185 Reference<XSpreadsheetView> xView(m_xModel->getCurrentController(), UNO_QUERY_THROW);
186 Reference<XSpreadsheet> xSheet(xView->getActiveSheet(), UNO_SET_THROW);
187 Reference<XDrawPageSupplier> xDrawPageSupplier(xSheet, UNO_QUERY_THROW);
188 Reference<XDrawPage> xDrawPage(xDrawPageSupplier->getDrawPage(), UNO_SET_THROW);
189 Reference<XShapes> xShapes(xDrawPage, UNO_QUERY_THROW);
190
191 xShapes->add(xShape);
192}
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
HRESULT createInstance(REFIID iid, Ifc **ppIfc)
static OUString getCDataString(std::u16string_view rString)
css::uno::Reference< css::frame::XModel > m_xModel
std::unique_ptr< weld::Entry > m_xEditName
css::uno::Reference< css::beans::XPropertySet > m_xExistingShapeProperties
std::unique_ptr< weld::Entry > m_xEditTitle
std::unique_ptr< weld::CheckButton > m_xCheckboxShowSignDate
std::unique_ptr< weld::Entry > m_xEditEmail
std::unique_ptr< weld::TextView > m_xEditInstructions
std::unique_ptr< weld::CheckButton > m_xCheckboxCanAddComments
SignatureLineDialog(weld::Widget *pParent, css::uno::Reference< css::frame::XModel > xModel, bool bEditExisting)
virtual void Apply() override
OString generateGUIDString()
uno::Reference< graphic::XGraphic > importSVG(std::u16string_view rSVG)
OUString getSignatureImage(const OUString &rType=OUString())
Reference< XModel > xModel