LibreOffice Module sw (master) 1
core/inc/bookmark.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
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>
30
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"
37
38class SwDoc;
39class SwEditWin;
40class SwServerObject;
42class SfxViewShell;
43class SwXBookmark;
44
45namespace sw::mark {
47 : virtual public IMark
48 {
49 public:
50 //getters
51 SwPosition& GetMarkPos() const override
52 { return const_cast<SwPosition&>(*m_oPos1); }
53 const OUString& GetName() const override
54 { return m_aName; }
55 SwPosition& GetOtherMarkPos() const override
56 {
57 OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
58 return const_cast<SwPosition&>(*m_oPos2);
59 }
60 SwPosition& GetMarkStart() const override
61 {
62 if( !IsExpanded() ) return GetMarkPos( );
63 if ( GetMarkPos( ) < GetOtherMarkPos( ) )
64 return GetMarkPos();
65 else
66 return GetOtherMarkPos( );
67 }
68 SwPosition& GetMarkEnd() const override
69 {
70 if( !IsExpanded() ) return GetMarkPos();
71 if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
72 return GetMarkPos( );
73 else
74 return GetOtherMarkPos( );
75 }
76
77 bool IsCoveringPosition(const SwPosition& rPos) const override;
78 bool IsExpanded() const override
79 { return m_oPos2.has_value(); }
80
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(); }
87
88 virtual auto InvalidateFrames() -> void;
89
90 OUString ToString( ) const override;
91 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
92
93 void Swap()
94 {
95 if(m_oPos2)
96 m_oPos1.swap(m_oPos2);
97 }
98
100 {
101 }
102
103 ~MarkBase() override;
104
106 { return m_wXBookmark; }
107 void SetXBookmark(rtl::Reference<SwXBookmark> const& xBkmk);
108
109 protected:
110 // SwClient
111 void SwClientNotify(const SwModify&, const SfxHint&) override;
112
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);
118
120 };
121
123 : public MarkBase
124 {
125 public:
126 NavigatorReminder(const SwPaM& rPaM);
127 };
128
129 class UnoMark final
130 : public MarkBase
131 {
132 public:
133 UnoMark(const SwPaM& rPaM);
134 };
135
137 : public MarkBase
138 {
139 public:
140 DdeBookmark(const SwPaM& rPaM);
141
142 const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
144
145 bool IsServer() const { return m_aRefObj.is(); }
146
147 void SetRefObject( SwServerObject* pObj );
148
149 virtual void DeregisterFromDoc(SwDoc& rDoc);
150 ~DdeBookmark() override;
151
152 private:
154 };
155
157 : virtual public IBookmark
158 , public DdeBookmark
159 , public ::sfx2::Metadatable
160 {
161 public:
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;
166
167 void DeregisterFromDoc(SwDoc& io_rDoc) override;
168
169 auto InvalidateFrames() -> void override;
170
171 const OUString& GetShortName() const override
172 { return m_sShortName; }
173 const vcl::KeyCode& GetKeyCode() const override
174 { return m_aCode; }
175 void SetShortName(const OUString& rShortName) override
176 { m_sShortName = rShortName; }
177 void SetKeyCode(const vcl::KeyCode& rCode) override
178 { m_aCode = rCode; }
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;
185
186 // ::sfx2::Metadatable
188 bool IsInClipboard() const override;
189 bool IsInUndo() const override;
190 bool IsInContent() const override;
191 css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
192
193 private:
195 OUString m_sShortName;
198 };
199
201 : virtual public IFieldmark
202 , public MarkBase
203 {
204 public:
205 Fieldmark(const SwPaM& rPaM);
206
207 OUString GetFieldname() const override
208 { return m_aFieldname; }
209 OUString GetFieldHelptext() const override
210 { return m_aFieldHelptext; }
211
212 IFieldmark::parameter_map_t* GetParameters() override
213 { return &m_vParams; }
214
215 const IFieldmark::parameter_map_t* GetParameters() const override
216 { return &m_vParams; }
217
218 void SetFieldname(const OUString& aFieldname) override
219 { m_aFieldname = aFieldname; }
220 void SetFieldHelptext(const OUString& aFieldHelptext) override
221 { m_aFieldHelptext = aFieldHelptext; }
222
223 virtual void ReleaseDoc(SwDoc&) = 0;
224
225 void SetMarkStartPos( const SwPosition& rNewStartPos );
226
227 void Invalidate() override;
228 OUString ToString() const override;
229 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
230
231 private:
232 OUString m_aFieldname;
234 IFieldmark::parameter_map_t m_vParams;
235 };
236
237 class TextFieldmark final
238 : public Fieldmark
239 {
240 public:
241 TextFieldmark(const SwPaM& rPaM, const OUString& rName);
242 void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
243 void ReleaseDoc(SwDoc& rDoc) override;
244
245 OUString GetContent() const override;
246 void ReplaceContent(const OUString& sNewContent) override;
247
248 private:
250 };
251
252 // Non text fieldmarks have no content between the start and end marks.
254 : public Fieldmark
255 {
256 public:
257 NonTextFieldmark(const SwPaM& rPaM);
258 void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
259 void ReleaseDoc(SwDoc& rDoc) override;
260 };
261
264 : virtual public ICheckboxFieldmark
265 , public NonTextFieldmark
266 {
267 public:
268 CheckboxFieldmark(const SwPaM& rPaM, const OUString& rName);
269 bool IsChecked() const override;
270 void SetChecked(bool checked) override;
271 OUString GetContent() const override;
272 void ReplaceContent(const OUString& sNewContent) override;
273 };
274
277 : public NonTextFieldmark
278 {
279 public:
282
283 virtual void ShowButton(SwEditWin* pEditWin) = 0;
284 virtual void RemoveButton();
285 void LaunchPopup();
286
287 protected:
289 };
290
293 : virtual public IDropdownFieldmark
295 {
296 public:
297 DropDownFieldmark(const SwPaM& rPaM, const OUString& rName);
298 ~DropDownFieldmark() override;
299
300 void ShowButton(SwEditWin* pEditWin) override;
301 void RemoveButton() override;
302 OUString GetContent(sal_Int32* pIndex) const override;
303 OUString GetContent() const override;
304 void AddContent(const OUString& rText, sal_Int32* pIndex = nullptr) override;
305 void DelContent(sal_Int32 nDelIndex = -1) override;
306 void ReplaceContent(const OUString* pText, sal_Int32* pIndex) override;
307 void ReplaceContent(const OUString& sNewContent) override;
308
309 // This method should be called only by the portion so we can now the portion's painting area
310 void SetPortionPaintArea(const SwRect& rPortionPaintArea);
311
312 void SendLOKShowMessage(const SfxViewShell* pViewShell);
313 static void SendLOKHideMessage(const SfxViewShell* pViewShell);
314
315 private:
317 };
318
324 class DateFieldmark final
325 : virtual public IDateFieldmark
327 {
328 public:
329 DateFieldmark(const SwPaM& rPaM);
330 ~DateFieldmark() override;
331
332 void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
333 void ReleaseDoc(SwDoc& rDoc) override;
334
335 void ShowButton(SwEditWin* pEditWin) override;
336
337 void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
338 void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
339
340 OUString GetContent() const override;
341 void ReplaceContent(const OUString& sNewContent) override;
342
343 std::pair<bool, double> GetCurrentDate() const override;
344 void SetCurrentDate(double fDate) override;
345 OUString GetDateInStandardDateFormat(double fDate) const override;
346
347 private:
348 OUString GetDateInCurrentDateFormat(double fDate) const;
349 std::pair<bool, double> ParseCurrentDateParam() const;
351
356 };
357
359 SwPosition FindFieldSep(IFieldmark const& rMark);
360
362 bool IsFieldmarkOverlap(SwPaM const& rPaM);
363}
364
365/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
struct _xmlTextWriter * xmlTextWriterPtr
Definition: doc.hxx:194
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:61
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
UNO API wrapper around an internal sw::mark::IMark.
Definition: unobookmark.hxx:53
void SetHideCondition(const OUString &rHideCondition) override
css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
void SetShortName(const OUString &rShortName) override
const OUString & GetHideCondition() const override
bool IsHidden() const override
auto InvalidateFrames() -> void override
bool IsInClipboard() const override
void DeregisterFromDoc(SwDoc &io_rDoc) override
bool IsInUndo() const override
void Hide(bool rHide) override
const OUString & GetShortName() const override
::sfx2::IXmlIdRegistry & GetRegistry() override
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
bool IsInContent() const override
const vcl::KeyCode & GetKeyCode() const override
void SetKeyCode(const vcl::KeyCode &rCode) override
void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Fieldmark representing a checkbox form field.
bool IsChecked() const override
void SetChecked(bool checked) override
void ReplaceContent(const OUString &sNewContent) override
OUString GetContent() const override
CheckboxFieldmark(const SwPaM &rPaM, const OUString &rName)
Fieldmark representing a date form field.
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
std::pair< bool, double > ParseCurrentDateParam() const
std::pair< bool, double > GetCurrentDate() const override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void SetCurrentDate(double fDate) override
DateFieldmark(const SwPaM &rPaM)
SvNumberFormatter * m_pNumberFormatter
void ReleaseDoc(SwDoc &rDoc) override
OUString GetDateInStandardDateFormat(double fDate) const override
OUString GetContent() const override
void ReplaceContent(const OUString &sNewContent) override
void ShowButton(SwEditWin *pEditWin) override
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
OUString GetDateInCurrentDateFormat(double fDate) const
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
const SwServerObject * GetRefObject() const
SwServerObject * GetRefObject()
void SetRefObject(SwServerObject *pObj)
DdeBookmark(const SwPaM &rPaM)
tools::SvRef< SwServerObject > m_aRefObj
virtual void DeregisterFromDoc(SwDoc &rDoc)
Fieldmark representing a drop-down form field.
void SendLOKShowMessage(const SfxViewShell *pViewShell)
void DelContent(sal_Int32 nDelIndex=-1) override
Remove everything if the given index is negative, else remove the given index (if valid).
void ShowButton(SwEditWin *pEditWin) override
void AddContent(const OUString &rText, sal_Int32 *pIndex=nullptr) override
AddContent : INSERTS a new choice.
DropDownFieldmark(const SwPaM &rPaM, const OUString &rName)
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
OUString GetContent() const override
void ReplaceContent(const OUString *pText, sal_Int32 *pIndex) override
ReplaceContent : changes the list result index or renames the existing choices.
static void SendLOKHideMessage(const SfxViewShell *pViewShell)
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field)
virtual void ShowButton(SwEditWin *pEditWin)=0
void dumpAsXml(xmlTextWriterPtr pWriter) const override
void SetFieldHelptext(const OUString &aFieldHelptext) override
OUString GetFieldHelptext() const override
void Invalidate() override
IFieldmark::parameter_map_t m_vParams
virtual void ReleaseDoc(SwDoc &)=0
void SetMarkStartPos(const SwPosition &rNewStartPos)
Fieldmark(const SwPaM &rPaM)
const IFieldmark::parameter_map_t * GetParameters() const override
void SetFieldname(const OUString &aFieldname) override
OUString ToString() const override
IFieldmark::parameter_map_t * GetParameters() override
OUString GetFieldname() const override
void SwClientNotify(const SwModify &, const SfxHint &) override
const unotools::WeakReference< SwXBookmark > & GetXBookmark() const
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
const OUString & GetName() const override
std::optional< SwPosition > m_oPos1
OUString ToString() const override
void SetXBookmark(rtl::Reference< SwXBookmark > const &xBkmk)
void dumpAsXml(xmlTextWriterPtr pWriter) const override
std::optional< SwPosition > m_oPos2
SwPosition & GetMarkEnd() const override
unotools::WeakReference< SwXBookmark > m_wXBookmark
virtual auto InvalidateFrames() -> void
virtual void InitDoc(SwDoc &, sw::mark::InsertMode, SwPosition const *)
bool IsCoveringPosition(const SwPosition &rPos) const override
bool IsExpanded() const override
virtual void SetMarkPos(const SwPosition &rNewPos)
virtual void ClearOtherMarkPos()
MarkBase(const SwPaM &rPaM, OUString aName)
void SetName(const OUString &rName)
SwPosition & GetMarkPos() const override
SwPosition & GetMarkStart() const override
SwPosition & GetOtherMarkPos() const override
static OUString GenerateNewName(std::u16string_view rPrefix)
NavigatorReminder(const SwPaM &rPaM)
NonTextFieldmark(const SwPaM &rPaM)
void ReleaseDoc(SwDoc &rDoc) override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void ReplaceContent(const OUString &sNewContent) override
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
void ReleaseDoc(SwDoc &rDoc) override
OUString GetContent() const override
UnoMark(const SwPaM &rPaM)
T * get() const
bool is() const
Mode eMode
bool IsFieldmarkOverlap(SwPaM const &rPaM)
check if rPaM is valid range of new fieldmark
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
InsertMode
Definition: IMark.hxx:32
Marks a position in the document model.
Definition: pam.hxx:37