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;
192 css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
193
194 private:
196 OUString m_sShortName;
199 };
200
202 : virtual public IFieldmark
203 , public MarkBase
204 {
205 public:
206 Fieldmark(const SwPaM& rPaM);
207
208 OUString GetFieldname() const override
209 { return m_aFieldname; }
210 OUString GetFieldHelptext() const override
211 { return m_aFieldHelptext; }
212
213 IFieldmark::parameter_map_t* GetParameters() override
214 { return &m_vParams; }
215
216 const IFieldmark::parameter_map_t* GetParameters() const override
217 { return &m_vParams; }
218
219 void SetFieldname(const OUString& aFieldname) override
220 { m_aFieldname = aFieldname; }
221 void SetFieldHelptext(const OUString& aFieldHelptext) override
222 { m_aFieldHelptext = aFieldHelptext; }
223
224 virtual void ReleaseDoc(SwDoc&) = 0;
225
226 void SetMarkStartPos( const SwPosition& rNewStartPos );
227
228 void Invalidate() override;
229 OUString ToString() const override;
230 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
231
232 private:
233 OUString m_aFieldname;
235 IFieldmark::parameter_map_t m_vParams;
236 };
237
238 class TextFieldmark final
239 : public Fieldmark
240 {
241 public:
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;
246
247 OUString GetContent() const override;
248 void ReplaceContent(const OUString& sNewContent) override;
249
250 private:
252 };
253
254 // Non text fieldmarks have no content between the start and end marks.
256 : public Fieldmark
257 {
258 public:
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;
262 };
263
266 : virtual public ICheckboxFieldmark
267 , public NonTextFieldmark
268 {
269 public:
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;
275 };
276
279 : public NonTextFieldmark
280 {
281 public:
284
285 virtual void ShowButton(SwEditWin* pEditWin) = 0;
286 virtual void RemoveButton();
287 void LaunchPopup();
288
289 protected:
291 };
292
295 : virtual public IDropdownFieldmark
297 {
298 public:
299 DropDownFieldmark(const SwPaM& rPaM, const OUString& rName);
300 ~DropDownFieldmark() override;
301
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;
310
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);
313
314 void SendLOKShowMessage(const SfxViewShell* pViewShell);
315 static void SendLOKHideMessage(const SfxViewShell* pViewShell);
316
317 private:
319 };
320
326 class DateFieldmark final
327 : virtual public IDateFieldmark
329 {
330 public:
331 DateFieldmark(const SwPaM& rPaM);
332 ~DateFieldmark() override;
333
334 void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
335 void ReleaseDoc(SwDoc& rDoc) override;
336
337 void ShowButton(SwEditWin* pEditWin) override;
338
339 void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
340 void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
341
342 OUString GetContent() const override;
343 void ReplaceContent(const OUString& sNewContent) override;
344
345 std::pair<bool, double> GetCurrentDate() const override;
346 void SetCurrentDate(double fDate) override;
347 OUString GetDateInStandardDateFormat(double fDate) const override;
348
349 private:
350 OUString GetDateInCurrentDateFormat(double fDate) const;
351 std::pair<bool, double> ParseCurrentDateParam() const;
353
358 };
359
361 SwPosition FindFieldSep(IFieldmark const& rMark);
362
364 bool IsFieldmarkOverlap(SwPaM const& rPaM);
365}
366
367/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Definition: doc.hxx:197
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:188
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
UNO API wrapper around an internal sw::mark::IMark.
Definition: unobookmark.hxx:51
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
struct _xmlTextWriter * xmlTextWriterPtr
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:38