1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <cppuhelper/weakref.hxx>
23 #include <sfx2/Metadatable.hxx>
24 #include <vcl/keycod.hxx>
25 #include <unotools/weakref.hxx>
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>
36 #include "FormFieldButton.hxx"
41 class SvNumberFormatter
;
47 : virtual public IMark
51 virtual SwPosition
& GetMarkPos() const override
52 { return const_cast<SwPosition
&>(*m_oPos1
); }
53 virtual const OUString
& GetName() const override
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( ) )
66 return GetOtherMarkPos( );
68 virtual SwPosition
& GetMarkEnd() const override
70 if( !IsExpanded() ) return GetMarkPos();
71 if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
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
)
83 virtual void SetMarkPos(const SwPosition
& rNewPos
);
84 virtual void SetOtherMarkPos(const SwPosition
& rNewPos
);
85 virtual void ClearOtherMarkPos()
88 virtual auto InvalidateFrames() -> void;
90 virtual OUString
ToString( ) const override
;
91 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
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
);
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
;
117 static OUString
GenerateNewName(std::u16string_view rPrefix
);
119 unotools::WeakReference
<SwXBookmark
> m_wXBookmark
;
122 class NavigatorReminder final
126 NavigatorReminder(const SwPaM
& rPaM
);
133 UnoMark(const SwPaM
& rPaM
);
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
;
153 tools::SvRef
<SwServerObject
> m_aRefObj
;
157 : virtual public IBookmark
159 , public ::sfx2::Metadatable
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
175 virtual void SetShortName(const OUString
& rShortName
) override
176 { m_sShortName
= rShortName
; }
177 virtual void SetKeyCode(const vcl::KeyCode
& rCode
) override
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
;
194 vcl::KeyCode m_aCode
;
195 OUString m_sShortName
;
197 OUString m_sHideCondition
;
201 : virtual public IFieldmark
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
;
232 OUString m_aFieldname
;
233 OUString m_aFieldHelptext
;
234 IFieldmark::parameter_map_t m_vParams
;
237 class TextFieldmark final
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
;
249 sw::DocumentContentOperationsManager
* m_pDocumentContentOperationsManager
;
252 // Non text fieldmarks have no content between the start and end marks.
253 class NonTextFieldmark
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
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
280 FieldmarkWithDropDownButton(const SwPaM
& rPaM
);
281 virtual ~FieldmarkWithDropDownButton() override
;
283 virtual void ShowButton(SwEditWin
* pEditWin
) = 0;
284 virtual void RemoveButton();
288 VclPtr
<FormFieldButton
> m_pButton
;
291 /// Fieldmark representing a drop-down form field.
292 class DropDownFieldmark final
293 : public FieldmarkWithDropDownButton
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
);
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
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
;
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: */