Avoid potential negative array index access to cached text.
[LibreOffice.git] / sfx2 / inc / autoredactdialog.hxx
blob52a03cfd8a8fdf2add9bb08125a818e835dc77d7
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_SFX2_INC_AUTOREDACTDIALOG_HXX
11 #define INCLUDED_SFX2_INC_AUTOREDACTDIALOG_HXX
13 #include <memory>
14 #include <sal/config.h>
15 #include <sfx2/basedlgs.hxx>
16 #include <sfx2/objsh.hxx>
18 namespace weld
20 class Button;
22 namespace weld
24 class ComboBox;
26 namespace weld
28 class Label;
30 namespace weld
32 class Window;
34 namespace weld
36 class TreeView;
39 enum RedactionTargetType
41 REDACTION_TARGET_TEXT,
42 REDACTION_TARGET_REGEX,
43 REDACTION_TARGET_PREDEFINED,
44 REDACTION_TARGET_UNKNOWN
47 /// Keeps information for a single redaction target
48 struct RedactionTarget
50 OUString sName;
51 RedactionTargetType sType;
52 OUString sContent;
53 bool bCaseSensitive;
54 bool bWholeWords;
55 sal_uInt32 nID;
58 /// Used to display the targets list
59 class TargetsTable
61 std::unique_ptr<weld::TreeView> m_xControl;
62 int GetRowByTargetName(std::u16string_view sName);
64 public:
65 TargetsTable(std::unique_ptr<weld::TreeView> xControl);
66 void InsertTarget(RedactionTarget* pTarget);
67 RedactionTarget* GetTargetByName(std::u16string_view sName);
68 OUString GetNameProposal() const;
70 int get_selected_index() const { return m_xControl->get_selected_index(); }
71 std::vector<int> get_selected_rows() const { return m_xControl->get_selected_rows(); }
72 void clear() { m_xControl->clear(); }
73 void remove(int nRow) { m_xControl->remove(nRow); }
74 void select(int nRow) { m_xControl->select(nRow); }
75 OUString get_id(int nRow) const { return m_xControl->get_id(nRow); }
77 // Sync data on the targets box with the data on the target
78 void setRowData(int nRowIndex, const RedactionTarget* pTarget);
80 void connect_row_activated(const Link<weld::TreeView&, bool>& rLink)
82 m_xControl->connect_row_activated(rLink);
86 namespace sfx2
88 class FileDialogHelper;
91 enum class StartFileDialogType
93 Open,
94 SaveAs
97 class SfxAutoRedactDialog final : public SfxDialogController
99 SfxObjectShellLock m_xDocShell;
100 std::vector<std::pair<std::unique_ptr<RedactionTarget>, OUString>> m_aTableTargets;
101 std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
102 bool m_bIsValidState;
103 bool m_bTargetsCopied;
105 TargetsTable m_aTargetsBox;
106 std::unique_ptr<weld::Button> m_xLoadBtn;
107 std::unique_ptr<weld::Button> m_xSaveBtn;
108 std::unique_ptr<weld::Button> m_xAddBtn;
109 std::unique_ptr<weld::Button> m_xEditBtn;
110 std::unique_ptr<weld::Button> m_xDeleteBtn;
112 DECL_LINK(Load, weld::Button&, void);
113 DECL_LINK(Save, weld::Button&, void);
114 DECL_LINK(AddHdl, weld::Button&, void);
115 DECL_LINK(EditHdl, weld::Button&, void);
116 DECL_LINK(DeleteHdl, weld::Button&, void);
117 DECL_LINK(DoubleClickEditHdl, weld::TreeView&, bool);
118 DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void);
119 DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void);
121 void StartFileDialog(StartFileDialogType nType, const OUString& rTitle);
122 /// Carry out proper addition both to the targets box, and to the tabletargets vector.
123 void addTarget(std::unique_ptr<RedactionTarget> pTarget);
124 /// Clear all targets both visually and from the targets vector
125 void clearTargets();
127 public:
128 SfxAutoRedactDialog(weld::Window* pParent);
129 virtual ~SfxAutoRedactDialog() override;
131 /// Check if the dialog has any valid redaction targets.
132 bool hasTargets() const;
133 /// Check if the dialog is in a valid state.
134 bool isValidState() const { return m_bIsValidState; }
135 /** Copies targets vector
136 * Does a shallow copy.
137 * Returns true if successful.
139 bool getTargets(std::vector<std::pair<RedactionTarget, OUString>>& r_aTargets);
142 class SfxAddTargetDialog final : public weld::GenericDialogController
144 private:
145 std::unique_ptr<weld::Entry> m_xName;
146 std::unique_ptr<weld::ComboBox> m_xType;
147 std::unique_ptr<weld::Label> m_xLabelContent;
148 std::unique_ptr<weld::Entry> m_xContent;
149 std::unique_ptr<weld::Label> m_xLabelPredefContent;
150 std::unique_ptr<weld::ComboBox> m_xPredefContent;
151 std::unique_ptr<weld::CheckButton> m_xCaseSensitive;
152 std::unique_ptr<weld::CheckButton> m_xWholeWords;
154 DECL_LINK(SelectTypeHdl, weld::ComboBox&, void);
156 public:
157 SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName);
158 SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName,
159 const RedactionTargetType& eTargetType, const OUString& sContent,
160 bool bCaseSensitive, bool bWholeWords);
162 OUString getName() const { return m_xName->get_text(); }
163 RedactionTargetType getType() const;
164 OUString getContent() const;
165 bool isCaseSensitive() const
167 return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE;
169 bool isWholeWords() const { return m_xWholeWords->get_state() == TriState::TRISTATE_TRUE; }
172 #endif
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */