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 .
20 #ifndef INCLUDED_SW_SOURCE_CORE_INC_BOOKMRK_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_BOOKMRK_HXX
23 #include <cppuhelper/weakref.hxx>
24 #include <sfx2/Metadatable.hxx>
25 #include <vcl/keycod.hxx>
27 #include <rtl/ustring.hxx>
28 #include <osl/diagnose.h>
29 #include <tools/ref.hxx>
32 #include "FormFieldButton.hxx"
34 namespace com::sun::star::text
{ class XTextContent
; }
39 class SvNumberFormatter
;
43 : virtual public IMark
47 virtual SwPosition
& GetMarkPos() const override
49 virtual const OUString
& GetName() const override
51 virtual SwPosition
& GetOtherMarkPos() const override
53 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
56 virtual SwPosition
& GetMarkStart() const override
58 if( !IsExpanded() ) return GetMarkPos( );
59 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
62 return GetOtherMarkPos( );
64 virtual SwPosition
& GetMarkEnd() const override
66 if( !IsExpanded() ) return GetMarkPos();
67 if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
70 return GetOtherMarkPos( );
73 virtual bool IsCoveringPosition(const SwPosition
& rPos
) const override
;
74 virtual bool IsExpanded() const override
75 { return static_cast< bool >(m_pPos2
); }
77 void SetName(const OUString
& rName
)
79 virtual void SetMarkPos(const SwPosition
& rNewPos
);
80 virtual void SetOtherMarkPos(const SwPosition
& rNewPos
);
81 virtual void ClearOtherMarkPos()
84 virtual auto InvalidateFrames() -> void;
86 virtual OUString
ToString( ) const override
;
87 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
92 m_pPos1
.swap(m_pPos2
);
95 virtual void InitDoc(SwDoc
&, sw::mark::InsertMode
, SwPosition
const*)
99 virtual ~MarkBase() override
;
101 const css::uno::WeakReference
< css::text::XTextContent
> & GetXBookmark() const
102 { return m_wXBookmark
; }
103 void SetXBookmark(css::uno::Reference
< css::text::XTextContent
> const& xBkmk
)
104 { m_wXBookmark
= xBkmk
; }
108 virtual void SwClientNotify(const SwModify
&, const SfxHint
&) override
;
110 MarkBase(const SwPaM
& rPaM
, const OUString
& rName
);
111 std::unique_ptr
<SwPosition
> m_pPos1
;
112 std::unique_ptr
<SwPosition
> m_pPos2
;
114 static OUString
GenerateNewName(const OUString
& rPrefix
);
116 css::uno::WeakReference
< css::text::XTextContent
> m_wXBookmark
;
119 class NavigatorReminder
123 NavigatorReminder(const SwPaM
& rPaM
);
130 UnoMark(const SwPaM
& rPaM
);
137 DdeBookmark(const SwPaM
& rPaM
);
139 const SwServerObject
* GetRefObject() const { return m_aRefObj
.get(); }
140 SwServerObject
* GetRefObject() { return m_aRefObj
.get(); }
142 bool IsServer() const { return m_aRefObj
.is(); }
144 void SetRefObject( SwServerObject
* pObj
);
146 virtual void DeregisterFromDoc(SwDoc
& rDoc
);
147 virtual ~DdeBookmark() override
;
150 tools::SvRef
<SwServerObject
> m_aRefObj
;
154 : virtual public IBookmark
156 , public ::sfx2::Metadatable
159 Bookmark(const SwPaM
& rPaM
,
160 const vcl::KeyCode
& rCode
,
161 const OUString
& rName
);
162 virtual void InitDoc(SwDoc
& io_Doc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
164 virtual void DeregisterFromDoc(SwDoc
& io_rDoc
) override
;
166 virtual auto InvalidateFrames() -> void override
;
168 virtual const OUString
& GetShortName() const override
169 { return m_sShortName
; }
170 virtual const vcl::KeyCode
& GetKeyCode() const override
172 virtual void SetShortName(const OUString
& rShortName
) override
173 { m_sShortName
= rShortName
; }
174 virtual void SetKeyCode(const vcl::KeyCode
& rCode
) override
176 virtual bool IsHidden() const override
177 { return m_bHidden
; }
178 virtual const OUString
& GetHideCondition() const override
179 { return m_sHideCondition
; }
180 virtual void Hide(bool rHide
) override
;
181 virtual void SetHideCondition(const OUString
& rHideCondition
) override
;
183 // ::sfx2::Metadatable
184 virtual ::sfx2::IXmlIdRegistry
& GetRegistry() override
;
185 virtual bool IsInClipboard() const override
;
186 virtual bool IsInUndo() const override
;
187 virtual bool IsInContent() const override
;
188 virtual css::uno::Reference
< css::rdf::XMetadatable
> MakeUnoObject() override
;
191 vcl::KeyCode m_aCode
;
192 OUString m_sShortName
;
194 OUString m_sHideCondition
;
198 : virtual public IFieldmark
202 Fieldmark(const SwPaM
& rPaM
);
204 virtual OUString
GetFieldname() const override
205 { return m_aFieldname
; }
206 virtual OUString
GetFieldHelptext() const override
207 { return m_aFieldHelptext
; }
209 virtual IFieldmark::parameter_map_t
* GetParameters() override
210 { return &m_vParams
; }
212 virtual const IFieldmark::parameter_map_t
* GetParameters() const override
213 { return &m_vParams
; }
215 virtual void SetFieldname(const OUString
& aFieldname
) override
216 { m_aFieldname
= aFieldname
; }
217 virtual void SetFieldHelptext(const OUString
& aFieldHelptext
) override
218 { m_aFieldHelptext
= aFieldHelptext
; }
220 virtual void ReleaseDoc(SwDoc
&) = 0;
222 void SetMarkStartPos( const SwPosition
& rNewStartPos
);
223 void SetMarkEndPos( const SwPosition
& rNewEndPos
);
225 virtual void Invalidate() override
;
226 virtual OUString
ToString() const override
;
227 virtual void dumpAsXml(xmlTextWriterPtr pWriter
) const override
;
230 OUString m_aFieldname
;
231 OUString m_aFieldHelptext
;
232 IFieldmark::parameter_map_t m_vParams
;
239 TextFieldmark(const SwPaM
& rPaM
, const OUString
& rName
);
240 virtual void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
241 virtual void ReleaseDoc(SwDoc
& rDoc
) override
;
244 // Non text fieldmarks have no content between the start and end marks.
245 class NonTextFieldmark
249 NonTextFieldmark(const SwPaM
& rPaM
);
250 virtual void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
251 virtual void ReleaseDoc(SwDoc
& rDoc
) override
;
254 /// Fieldmark representing a checkbox form field.
255 class CheckboxFieldmark
256 : virtual public ICheckboxFieldmark
257 , public NonTextFieldmark
260 CheckboxFieldmark(const SwPaM
& rPaM
);
261 bool IsChecked() const override
;
262 void SetChecked(bool checked
) override
;
265 /// Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
266 class FieldmarkWithDropDownButton
267 : public NonTextFieldmark
270 FieldmarkWithDropDownButton(const SwPaM
& rPaM
);
271 virtual ~FieldmarkWithDropDownButton() override
;
273 virtual void ShowButton(SwEditWin
* pEditWin
) = 0;
274 virtual void HideButton();
275 virtual void RemoveButton();
278 VclPtr
<FormFieldButton
> m_pButton
;
281 /// Fieldmark representing a drop-down form field.
282 class DropDownFieldmark
283 : public FieldmarkWithDropDownButton
286 DropDownFieldmark(const SwPaM
& rPaM
);
287 virtual ~DropDownFieldmark() override
;
289 virtual void ShowButton(SwEditWin
* pEditWin
) override
;
290 virtual void HideButton() override
;
291 virtual void RemoveButton() override
;
293 // This method should be called only by the portion so we can now the portion's painting area
294 void SetPortionPaintArea(const SwRect
& rPortionPaintArea
);
296 void SendLOKMessage(const OString
& sAction
);
299 SwRect m_aPortionPaintArea
;
300 OString m_sLastSentLOKMsg
;
303 /// Fieldmark representing a date form field.
305 : virtual public IDateFieldmark
306 , public FieldmarkWithDropDownButton
309 DateFieldmark(const SwPaM
& rPaM
);
310 virtual ~DateFieldmark() override
;
312 virtual void InitDoc(SwDoc
& io_rDoc
, sw::mark::InsertMode eMode
, SwPosition
const* pSepPos
) override
;
313 virtual void ReleaseDoc(SwDoc
& rDoc
) override
;
315 virtual void ShowButton(SwEditWin
* pEditWin
) override
;
317 void SetPortionPaintAreaStart(const SwRect
& rPortionPaintArea
);
318 void SetPortionPaintAreaEnd(const SwRect
& rPortionPaintArea
);
320 virtual OUString
GetContent() const override
;
321 virtual void ReplaceContent(const OUString
& sNewContent
) override
;
323 virtual std::pair
<bool, double> GetCurrentDate() const override
;
324 virtual void SetCurrentDate(double fDate
) override
;
325 virtual OUString
GetDateInStandardDateFormat(double fDate
) const override
;
328 OUString
GetDateInCurrentDateFormat(double fDate
) const;
329 std::pair
<bool, double> ParseCurrentDateParam() const;
330 void InvalidateCurrentDateParam();
332 SvNumberFormatter
* m_pNumberFormatter
;
333 sw::DocumentContentOperationsManager
* m_pDocumentContentOperationsManager
;
334 SwRect m_aPaintAreaStart
;
335 SwRect m_aPaintAreaEnd
;
338 /// return position of the CH_TXT_ATR_FIELDSEP for rMark
339 SwPosition
FindFieldSep(IFieldmark
const& rMark
);
341 /// check if rPaM is valid range of new fieldmark
342 bool IsFieldmarkOverlap(SwPaM
const& rPaM
);
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */