tdf#126268: Add support for negative decimal
[LibreOffice.git] / sfx2 / inc / SfxRedactionHelper.hxx
blob737357505e5d6588b95918dbba750f963d1e4607
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.
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 */
10 #ifndef INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX
11 #define INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX
13 #include <com/sun/star/uno/Reference.hxx>
14 #include <com/sun/star/lang/XComponent.hpp>
15 #include <com/sun/star/frame/XModel.hpp>
16 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <com/sun/star/drawing/XDrawPage.hpp>
19 #include <sal/types.h>
20 #include <rtl/ustring.hxx>
21 #include <tools/gen.hxx>
23 #include <vector>
25 using namespace ::com::sun::star;
26 using namespace ::com::sun::star::lang;
27 using namespace ::com::sun::star::uno;
29 class SfxRequest;
30 class SfxStringItem;
31 class GDIMetaFile;
32 class DocumentToGraphicRenderer;
33 class SfxViewFrame;
34 struct RedactionTarget;
36 namespace i18nutil
38 struct SearchOptions2;
41 struct PageMargins
43 // Page margins in mm100th
44 sal_Int32 nTop;
45 sal_Int32 nBottom;
46 sal_Int32 nLeft;
47 sal_Int32 nRight;
51 * Mostly a bunch of static methods to handle the redaction functionality at
52 * different points of the process.
53 **/
54 class SfxRedactionHelper
56 public:
57 /// Checks to see if the request has a parameter of IsRedactMode:bool=true
58 static bool isRedactMode(const SfxRequest& rReq);
60 * Returns the value of the given string param as an OUString
61 * Returns empty OUString if no param
62 * */
63 static OUString getStringParam(const SfxRequest& rReq, sal_uInt16 nParamId);
65 * Creates metafiles from the pages of the given document,
66 * and pushes into the given vector.
67 * */
68 static void getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMetaFiles,
69 std::vector<::Size>& aPageSizes, sal_Int32 nPages,
70 DocumentToGraphicRenderer& aRenderer);
72 * Creates one shape and one draw page for each gdimetafile,
73 * and inserts the shapes into the newly created draw pages.
74 * */
75 static void
76 addPagesToDraw(uno::Reference<XComponent>& xComponent, sal_Int32 nPages,
77 const std::vector<GDIMetaFile>& aMetaFiles,
78 const std::vector<::Size>& aPageSizes, const PageMargins& aPageMargins,
79 const std::vector<std::pair<RedactionTarget*, OUString>>& r_aTableTargets,
80 bool bIsAutoRedact);
82 * Makes the Redaction toolbar visible to the user.
83 * Meant to be called after converting a document to a Draw doc
84 * for redaction purposes.
85 * */
86 static void showRedactionToolbar(SfxViewFrame* pViewFrame);
89 * Used to get the page margins from the original/source Writer document. Then we apply these values to the
90 * pages inserted into Draw for redaction.
91 * */
92 static PageMargins getPageMarginsForWriter(css::uno::Reference<css::frame::XModel>& xModel);
95 * Used to get the page margins from the original/source Calc document. Then we apply these values to the
96 * pages inserted into Draw for redaction.
97 * */
98 static PageMargins getPageMarginsForCalc(css::uno::Reference<css::frame::XModel>& xModel);
100 static void searchInMetaFile(const RedactionTarget* pRedactionTarget, const GDIMetaFile& rMtf,
101 std::vector<tools::Rectangle>& aRedactionRectangles,
102 uno::Reference<XComponent>& xComponent);
105 * Draws a redaction rectangle on the draw page referenced with its page number (0-based)
106 * */
107 static void addRedactionRectToPage(uno::Reference<XComponent>& xComponent,
108 uno::Reference<drawing::XDrawPage>& xPage,
109 const std::vector<tools::Rectangle>& aNewRectangles);
112 * Search for the given term through the gdimetafile, which has the whole content of a draw page,
113 * and draw redaction rectangles to the appropriate positions with suitable sizes.
114 * */
115 static void autoRedactPage(const RedactionTarget* pRedactionTarget,
116 const GDIMetaFile& rGDIMetaFile,
117 uno::Reference<drawing::XDrawPage>& xPage,
118 uno::Reference<XComponent>& xComponent);
120 /// Fill the search options based on the given redaction target
121 static void fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt,
122 const RedactionTarget* pTarget);
124 private:
125 static constexpr OUStringLiteral m_aPredefinedTargets[6] = {
126 "\\b(?:\\d[ -]*?){13,16}\\b", //Credit card numbers
127 "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b", //Email addresses
128 "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
129 "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)"
130 "\\b", //IP addresses
131 "([12]\\d{3}[./-](0[1-9]|1[0-2])[./"
132 "-](0[1-9]|[12]\\d|3[01]))|((0[1-9]|[12]\\d|3[01])[./-](0[1-9]|1[0-2])[./"
133 "-][12]\\d{3})", //Dates (numerical)
134 "\\s*[a-zA-Z]{2}(?:\\s*\\d\\s*){6}[a-zA-Z]?\\s*", //National Insurance Number (UK)
135 "([1-9])(?!\\1{2}-\\1{2}-\\1{4})[1-9]{2}-[1-9]{2}-[1-9]{4}" //Social Security Number (US)
139 #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */