tdf#151548 vba FormFields: Add basic word::XTextInput support
[LibreOffice.git] / sw / source / core / inc / bookmark.hxx
blob14c176c96a3653c74e74839e03d7b5997bd37481
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #pragma once
22 #include <cppuhelper/weakref.hxx>
23 #include <sfx2/Metadatable.hxx>
24 #include <vcl/keycod.hxx>
25 #include <unotools/weakref.hxx>
26 #include <memory>
27 #include <optional>
28 #include <string_view>
29 #include <com/sun/star/text/XTextContent.hpp>
31 #include <rtl/ustring.hxx>
32 #include <osl/diagnose.h>
33 #include <tools/ref.hxx>
34 #include <IMark.hxx>
35 #include <swrect.hxx>
36 #include "FormFieldButton.hxx"
38 class SwDoc;
39 class SwEditWin;
40 class SwServerObject;
41 class SvNumberFormatter;
42 class SfxViewShell;
43 class SwXBookmark;
45 namespace sw::mark {
46 class MarkBase
47 : virtual public IMark
49 public:
50 //getters
51 virtual SwPosition& GetMarkPos() const override
52 { return const_cast<SwPosition&>(*m_oPos1); }
53 virtual const OUString& GetName() const override
54 { return m_aName; }
55 virtual SwPosition& GetOtherMarkPos() const override
57 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
58 return const_cast<SwPosition&>(*m_oPos2);
60 virtual SwPosition& GetMarkStart() const override
62 if( !IsExpanded() ) return GetMarkPos( );
63 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
64 return GetMarkPos();
65 else
66 return GetOtherMarkPos( );
68 virtual SwPosition& GetMarkEnd() const override
70 if( !IsExpanded() ) return GetMarkPos();
71 if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
72 return GetMarkPos( );
73 else
74 return GetOtherMarkPos( );
77 virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
78 virtual bool IsExpanded() const override
79 { return m_oPos2.has_value(); }
81 void SetName(const OUString& rName)
82 { m_aName = rName; }
83 virtual void SetMarkPos(const SwPosition& rNewPos);
84 virtual void SetOtherMarkPos(const SwPosition& rNewPos);
85 virtual void ClearOtherMarkPos()
86 { m_oPos2.reset(); }
88 virtual auto InvalidateFrames() -> void;
90 virtual OUString ToString( ) const override;
91 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
93 void Swap()
95 if(m_oPos2)
96 m_oPos1.swap(m_oPos2);
99 virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
103 virtual ~MarkBase() override;
105 const unotools::WeakReference<SwXBookmark> & GetXBookmark() const
106 { return m_wXBookmark; }
107 void SetXBookmark(rtl::Reference<SwXBookmark> const& xBkmk);
109 protected:
110 // SwClient
111 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
113 MarkBase(const SwPaM& rPaM, OUString aName);
114 std::optional<SwPosition> m_oPos1;
115 std::optional<SwPosition> m_oPos2;
116 OUString m_aName;
117 static OUString GenerateNewName(std::u16string_view rPrefix);
119 unotools::WeakReference<SwXBookmark> m_wXBookmark;
122 class NavigatorReminder final
123 : public MarkBase
125 public:
126 NavigatorReminder(const SwPaM& rPaM);
129 class UnoMark final
130 : public MarkBase
132 public:
133 UnoMark(const SwPaM& rPaM);
136 class DdeBookmark
137 : public MarkBase
139 public:
140 DdeBookmark(const SwPaM& rPaM);
142 const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
143 SwServerObject* GetRefObject() { return m_aRefObj.get(); }
145 bool IsServer() const { return m_aRefObj.is(); }
147 void SetRefObject( SwServerObject* pObj );
149 virtual void DeregisterFromDoc(SwDoc& rDoc);
150 virtual ~DdeBookmark() override;
152 private:
153 tools::SvRef<SwServerObject> m_aRefObj;
156 class Bookmark
157 : virtual public IBookmark
158 , public DdeBookmark
159 , public ::sfx2::Metadatable
161 public:
162 Bookmark(const SwPaM& rPaM,
163 const vcl::KeyCode& rCode,
164 const OUString& rName);
165 virtual void InitDoc(SwDoc& io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
167 virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;
169 virtual auto InvalidateFrames() -> void override;
171 virtual const OUString& GetShortName() const override
172 { return m_sShortName; }
173 virtual const vcl::KeyCode& GetKeyCode() const override
174 { return m_aCode; }
175 virtual void SetShortName(const OUString& rShortName) override
176 { m_sShortName = rShortName; }
177 virtual void SetKeyCode(const vcl::KeyCode& rCode) override
178 { m_aCode = rCode; }
179 virtual bool IsHidden() const override
180 { return m_bHidden; }
181 virtual const OUString& GetHideCondition() const override
182 { return m_sHideCondition; }
183 virtual void Hide(bool rHide) override;
184 virtual void SetHideCondition(const OUString& rHideCondition) override;
186 // ::sfx2::Metadatable
187 virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
188 virtual bool IsInClipboard() const override;
189 virtual bool IsInUndo() const override;
190 virtual bool IsInContent() const override;
191 virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
193 private:
194 vcl::KeyCode m_aCode;
195 OUString m_sShortName;
196 bool m_bHidden;
197 OUString m_sHideCondition;
200 class Fieldmark
201 : virtual public IFieldmark
202 , public MarkBase
204 public:
205 Fieldmark(const SwPaM& rPaM);
207 virtual OUString GetFieldname() const override
208 { return m_aFieldname; }
209 virtual OUString GetFieldHelptext() const override
210 { return m_aFieldHelptext; }
212 virtual IFieldmark::parameter_map_t* GetParameters() override
213 { return &m_vParams; }
215 virtual const IFieldmark::parameter_map_t* GetParameters() const override
216 { return &m_vParams; }
218 virtual void SetFieldname(const OUString& aFieldname) override
219 { m_aFieldname = aFieldname; }
220 virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
221 { m_aFieldHelptext = aFieldHelptext; }
223 virtual void ReleaseDoc(SwDoc&) = 0;
225 void SetMarkStartPos( const SwPosition& rNewStartPos );
227 virtual void Invalidate() override;
228 virtual OUString ToString() const override;
229 virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
231 private:
232 OUString m_aFieldname;
233 OUString m_aFieldHelptext;
234 IFieldmark::parameter_map_t m_vParams;
237 class TextFieldmark final
238 : public Fieldmark
240 public:
241 TextFieldmark(const SwPaM& rPaM, const OUString& rName);
242 virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
243 virtual void ReleaseDoc(SwDoc& rDoc) override;
245 OUString GetContent() const override;
246 void ReplaceContent(const OUString& sNewContent) override;
248 private:
249 sw::DocumentContentOperationsManager* m_pDocumentContentOperationsManager;
252 // Non text fieldmarks have no content between the start and end marks.
253 class NonTextFieldmark
254 : public Fieldmark
256 public:
257 NonTextFieldmark(const SwPaM& rPaM);
258 virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
259 virtual void ReleaseDoc(SwDoc& rDoc) override;
262 /// Fieldmark representing a checkbox form field.
263 class CheckboxFieldmark final
264 : virtual public ICheckboxFieldmark
265 , public NonTextFieldmark
267 public:
268 CheckboxFieldmark(const SwPaM& rPaM, const OUString& rName);
269 bool IsChecked() const override;
270 void SetChecked(bool checked) override;
271 virtual OUString GetContent() const override;
272 virtual void ReplaceContent(const OUString& sNewContent) override;
275 /// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
276 class FieldmarkWithDropDownButton
277 : public NonTextFieldmark
279 public:
280 FieldmarkWithDropDownButton(const SwPaM& rPaM);
281 virtual ~FieldmarkWithDropDownButton() override;
283 virtual void ShowButton(SwEditWin* pEditWin) = 0;
284 virtual void RemoveButton();
285 void LaunchPopup();
287 protected:
288 VclPtr<FormFieldButton> m_pButton;
291 /// Fieldmark representing a drop-down form field.
292 class DropDownFieldmark final
293 : public FieldmarkWithDropDownButton
295 public:
296 DropDownFieldmark(const SwPaM& rPaM, const OUString& rName);
297 virtual ~DropDownFieldmark() override;
299 virtual void ShowButton(SwEditWin* pEditWin) override;
300 virtual void RemoveButton() override;
302 // This method should be called only by the portion so we can now the portion's painting area
303 void SetPortionPaintArea(const SwRect& rPortionPaintArea);
305 void SendLOKShowMessage(const SfxViewShell* pViewShell);
306 static void SendLOKHideMessage(const SfxViewShell* pViewShell);
308 private:
309 SwRect m_aPortionPaintArea;
312 /// Fieldmark representing a date form field.
313 /// TODO: this was an SDT in DOCX, which is modelled suboptimally here
314 /// as a fieldmark; as it cannot contain paragraph breaks, must be
315 /// well-formed XML element, and does not have field separator, it
316 /// should be a nesting text attribute similar to SwTextMeta.
317 class DateFieldmark final
318 : virtual public IDateFieldmark
319 , public FieldmarkWithDropDownButton
321 public:
322 DateFieldmark(const SwPaM& rPaM);
323 virtual ~DateFieldmark() override;
325 virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
326 virtual void ReleaseDoc(SwDoc& rDoc) override;
328 virtual void ShowButton(SwEditWin* pEditWin) override;
330 void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
331 void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
333 virtual OUString GetContent() const override;
334 virtual void ReplaceContent(const OUString& sNewContent) override;
336 virtual std::pair<bool, double> GetCurrentDate() const override;
337 virtual void SetCurrentDate(double fDate) override;
338 virtual OUString GetDateInStandardDateFormat(double fDate) const override;
340 private:
341 OUString GetDateInCurrentDateFormat(double fDate) const;
342 std::pair<bool, double> ParseCurrentDateParam() const;
343 void InvalidateCurrentDateParam();
345 SvNumberFormatter* m_pNumberFormatter;
346 sw::DocumentContentOperationsManager* m_pDocumentContentOperationsManager;
347 SwRect m_aPaintAreaStart;
348 SwRect m_aPaintAreaEnd;
351 /// return position of the CH_TXT_ATR_FIELDSEP for rMark
352 SwPosition FindFieldSep(IFieldmark const& rMark);
354 /// check if rPaM is valid range of new fieldmark
355 bool IsFieldmarkOverlap(SwPaM const& rPaM);
358 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */