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 SwPosition
& GetMarkPos() const override
52 { return const_cast<SwPosition
&>(*m_oPos1
); }
53 const OUString
& GetName() const override
55 SwPosition
& GetOtherMarkPos() const override
57 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
58 return const_cast<SwPosition
&>(*m_oPos2
);
60 SwPosition
& GetMarkStart() const override
62 if( !IsExpanded() ) return GetMarkPos( );
63 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
66 return GetOtherMarkPos( );
68 SwPosition
& GetMarkEnd() const override
70 if( !IsExpanded() ) return GetMarkPos();
71 if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
74 return GetOtherMarkPos( );
77 bool IsCoveringPosition(const SwPosition
& rPos
) const override
;
78 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 OUString
ToString( ) const override
;
91 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
96 m_oPos1
.swap(m_oPos2
);
99 virtual void InitDoc(SwDoc
&, sw::mark::InsertMode
, SwPosition
const*)
103 ~MarkBase() override
;
105 const unotools::WeakReference
<SwXBookmark
> & GetXBookmark() const
106 { return m_wXBookmark
; }
107 void SetXBookmark(rtl::Reference
<SwXBookmark
> const& xBkmk
);
111 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 ~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 void InitDoc(SwDoc
& io_Doc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
167 void DeregisterFromDoc(SwDoc
& io_rDoc
) override
;
169 auto InvalidateFrames() -> void override
;
171 const OUString
& GetShortName() const override
172 { return m_sShortName
; }
173 const vcl::KeyCode
& GetKeyCode() const override
175 void SetShortName(const OUString
& rShortName
) override
176 { m_sShortName
= rShortName
; }
177 void SetKeyCode(const vcl::KeyCode
& rCode
) override
179 bool IsHidden() const override
180 { return m_bHidden
; }
181 const OUString
& GetHideCondition() const override
182 { return m_sHideCondition
; }
183 void Hide(bool rHide
) override
;
184 void SetHideCondition(const OUString
& rHideCondition
) override
;
186 // ::sfx2::Metadatable
187 ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
188 bool IsInClipboard() const override
;
189 bool IsInUndo() const override
;
190 bool IsInContent() const override
;
191 void sendLOKDeleteCallback();
192 css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
195 vcl::KeyCode m_aCode
;
196 OUString m_sShortName
;
198 OUString m_sHideCondition
;
202 : virtual public IFieldmark
206 Fieldmark(const SwPaM
& rPaM
);
208 OUString
GetFieldname() const override
209 { return m_aFieldname
; }
210 OUString
GetFieldHelptext() const override
211 { return m_aFieldHelptext
; }
213 IFieldmark::parameter_map_t
* GetParameters() override
214 { return &m_vParams
; }
216 const IFieldmark::parameter_map_t
* GetParameters() const override
217 { return &m_vParams
; }
219 void SetFieldname(const OUString
& aFieldname
) override
220 { m_aFieldname
= aFieldname
; }
221 void SetFieldHelptext(const OUString
& aFieldHelptext
) override
222 { m_aFieldHelptext
= aFieldHelptext
; }
224 virtual void ReleaseDoc(SwDoc
&) = 0;
226 void SetMarkStartPos( const SwPosition
& rNewStartPos
);
228 void Invalidate() override
;
229 OUString
ToString() const override
;
230 void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
233 OUString m_aFieldname
;
234 OUString m_aFieldHelptext
;
235 IFieldmark::parameter_map_t m_vParams
;
238 class TextFieldmark final
242 TextFieldmark(const SwPaM
& rPaM
, const OUString
& rName
);
244 void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
245 void ReleaseDoc(SwDoc
& rDoc
) override
;
247 OUString
GetContent() const override
;
248 void ReplaceContent(const OUString
& sNewContent
) override
;
251 sw::DocumentContentOperationsManager
* m_pDocumentContentOperationsManager
;
254 // Non text fieldmarks have no content between the start and end marks.
255 class NonTextFieldmark
259 NonTextFieldmark(const SwPaM
& rPaM
);
260 void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
261 void ReleaseDoc(SwDoc
& rDoc
) override
;
264 /// Fieldmark representing a checkbox form field.
265 class CheckboxFieldmark final
266 : virtual public ICheckboxFieldmark
267 , public NonTextFieldmark
270 CheckboxFieldmark(const SwPaM
& rPaM
, const OUString
& rName
);
271 bool IsChecked() const override
;
272 void SetChecked(bool checked
) override
;
273 OUString
GetContent() const override
;
274 void ReplaceContent(const OUString
& sNewContent
) override
;
277 /// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
278 class FieldmarkWithDropDownButton
279 : public NonTextFieldmark
282 FieldmarkWithDropDownButton(const SwPaM
& rPaM
);
283 ~FieldmarkWithDropDownButton() override
;
285 virtual void ShowButton(SwEditWin
* pEditWin
) = 0;
286 virtual void RemoveButton();
290 VclPtr
<FormFieldButton
> m_pButton
;
293 /// Fieldmark representing a drop-down form field.
294 class DropDownFieldmark final
295 : virtual public IDropdownFieldmark
296 , public FieldmarkWithDropDownButton
299 DropDownFieldmark(const SwPaM
& rPaM
, const OUString
& rName
);
300 ~DropDownFieldmark() override
;
302 void ShowButton(SwEditWin
* pEditWin
) override
;
303 void RemoveButton() override
;
304 OUString
GetContent(sal_Int32
* pIndex
) const override
;
305 OUString
GetContent() const override
;
306 void AddContent(const OUString
& rText
, sal_Int32
* pIndex
= nullptr) override
;
307 void DelContent(sal_Int32 nDelIndex
= -1) override
;
308 void ReplaceContent(const OUString
* pText
, sal_Int32
* pIndex
) override
;
309 void ReplaceContent(const OUString
& sNewContent
) override
;
311 // This method should be called only by the portion so we can now the portion's painting area
312 void SetPortionPaintArea(const SwRect
& rPortionPaintArea
);
314 void SendLOKShowMessage(const SfxViewShell
* pViewShell
);
315 static void SendLOKHideMessage(const SfxViewShell
* pViewShell
);
318 SwRect m_aPortionPaintArea
;
321 /// Fieldmark representing a date form field.
322 /// TODO: this was an SDT in DOCX, which is modelled suboptimally here
323 /// as a fieldmark; as it cannot contain paragraph breaks, must be
324 /// well-formed XML element, and does not have field separator, it
325 /// should be a nesting text attribute similar to SwTextMeta.
326 class DateFieldmark final
327 : virtual public IDateFieldmark
328 , public FieldmarkWithDropDownButton
331 DateFieldmark(const SwPaM
& rPaM
);
332 ~DateFieldmark() override
;
334 void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
335 void ReleaseDoc(SwDoc
& rDoc
) override
;
337 void ShowButton(SwEditWin
* pEditWin
) override
;
339 void SetPortionPaintAreaStart(const SwRect
& rPortionPaintArea
);
340 void SetPortionPaintAreaEnd(const SwRect
& rPortionPaintArea
);
342 OUString
GetContent() const override
;
343 void ReplaceContent(const OUString
& sNewContent
) override
;
345 std::pair
<bool, double> GetCurrentDate() const override
;
346 void SetCurrentDate(double fDate
) override
;
347 OUString
GetDateInStandardDateFormat(double fDate
) const override
;
350 OUString
GetDateInCurrentDateFormat(double fDate
) const;
351 std::pair
<bool, double> ParseCurrentDateParam() const;
352 void InvalidateCurrentDateParam();
354 SvNumberFormatter
* m_pNumberFormatter
;
355 sw::DocumentContentOperationsManager
* m_pDocumentContentOperationsManager
;
356 SwRect m_aPaintAreaStart
;
357 SwRect m_aPaintAreaEnd
;
360 /// return position of the CH_TXT_ATR_FIELDSEP for rMark
361 SwPosition
FindFieldSep(IFieldmark
const& rMark
);
363 /// check if rPaM is valid range of new fieldmark
364 bool IsFieldmarkOverlap(SwPaM
const& rPaM
);
367 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */