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 
22 #include <cppuhelper/weakref.hxx>
23 #include <sfx2/Metadatable.hxx>
24 #include <vcl/keycod.hxx>
25 #include <memory>
26 #include <string_view>
27 #include <com/sun/star/text/XTextContent.hpp>
28 
29 #include <rtl/ustring.hxx>
30 #include <osl/diagnose.h>
31 #include <tools/ref.hxx>
32 #include <IMark.hxx>
33 #include <swrect.hxx>
34 #include "FormFieldButton.hxx"
35 
36 class SwDoc;
37 class SwEditWin;
38 class SwServerObject;
39 class SvNumberFormatter;
40 class SfxViewShell;
41 
42 namespace sw::mark {
43  class MarkBase
44  : virtual public IMark
45  {
46  public:
47  //getters
48  virtual SwPosition& GetMarkPos() const override
49  { return *m_pPos1; }
50  virtual const OUString& GetName() const override
51  { return m_aName; }
52  virtual SwPosition& GetOtherMarkPos() const override
53  {
54  OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
55  return *m_pPos2;
56  }
57  virtual SwPosition& GetMarkStart() const override
58  {
59  if( !IsExpanded() ) return GetMarkPos( );
60  if ( GetMarkPos( ) < GetOtherMarkPos( ) )
61  return GetMarkPos();
62  else
63  return GetOtherMarkPos( );
64  }
65  virtual SwPosition& GetMarkEnd() const override
66  {
67  if( !IsExpanded() ) return GetMarkPos();
68  if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
69  return GetMarkPos( );
70  else
71  return GetOtherMarkPos( );
72  }
73 
74  virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
75  virtual bool IsExpanded() const override
76  { return static_cast< bool >(m_pPos2); }
77 
78  void SetName(const OUString& rName)
79  { m_aName = rName; }
80  virtual void SetMarkPos(const SwPosition& rNewPos);
81  virtual void SetOtherMarkPos(const SwPosition& rNewPos);
82  virtual void ClearOtherMarkPos()
83  { m_pPos2.reset(); }
84 
85  virtual auto InvalidateFrames() -> void;
86 
87  virtual OUString ToString( ) const override;
88  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
89 
90  void Swap()
91  {
92  if(m_pPos2)
93  m_pPos1.swap(m_pPos2);
94  }
95 
96  virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
97  {
98  }
99 
100  virtual ~MarkBase() override;
101 
102  const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
103  { return m_wXBookmark; }
104  void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
105  { m_wXBookmark = xBkmk; }
106 
107  protected:
108  // SwClient
109  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
110 
111  MarkBase(const SwPaM& rPaM, const OUString& rName);
112  std::unique_ptr<SwPosition> m_pPos1;
113  std::unique_ptr<SwPosition> m_pPos2;
114  OUString m_aName;
115  static OUString GenerateNewName(std::u16string_view rPrefix);
116 
117  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
118  };
119 
120  class NavigatorReminder final
121  : public MarkBase
122  {
123  public:
124  NavigatorReminder(const SwPaM& rPaM);
125  };
126 
127  class UnoMark final
128  : public MarkBase
129  {
130  public:
131  UnoMark(const SwPaM& rPaM);
132  };
133 
135  : public MarkBase
136  {
137  public:
138  DdeBookmark(const SwPaM& rPaM);
139 
140  const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
142 
143  bool IsServer() const { return m_aRefObj.is(); }
144 
145  void SetRefObject( SwServerObject* pObj );
146 
147  virtual void DeregisterFromDoc(SwDoc& rDoc);
148  virtual ~DdeBookmark() override;
149 
150  private:
152  };
153 
154  class Bookmark
155  : virtual public IBookmark
156  , public DdeBookmark
157  , public ::sfx2::Metadatable
158  {
159  public:
160  Bookmark(const SwPaM& rPaM,
161  const vcl::KeyCode& rCode,
162  const OUString& rName);
163  virtual void InitDoc(SwDoc& io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
164 
165  virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;
166 
167  virtual auto InvalidateFrames() -> void override;
168 
169  virtual const OUString& GetShortName() const override
170  { return m_sShortName; }
171  virtual const vcl::KeyCode& GetKeyCode() const override
172  { return m_aCode; }
173  virtual void SetShortName(const OUString& rShortName) override
174  { m_sShortName = rShortName; }
175  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
176  { m_aCode = rCode; }
177  virtual bool IsHidden() const override
178  { return m_bHidden; }
179  virtual const OUString& GetHideCondition() const override
180  { return m_sHideCondition; }
181  virtual void Hide(bool rHide) override;
182  virtual void SetHideCondition(const OUString& rHideCondition) override;
183 
184  // ::sfx2::Metadatable
185  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
186  virtual bool IsInClipboard() const override;
187  virtual bool IsInUndo() const override;
188  virtual bool IsInContent() const override;
189  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
190 
191  private:
193  OUString m_sShortName;
194  bool m_bHidden;
196  };
197 
198  class Fieldmark
199  : virtual public IFieldmark
200  , public MarkBase
201  {
202  public:
203  Fieldmark(const SwPaM& rPaM);
204 
205  virtual OUString GetFieldname() const override
206  { return m_aFieldname; }
207  virtual OUString GetFieldHelptext() const override
208  { return m_aFieldHelptext; }
209 
211  { return &m_vParams; }
212 
213  virtual const IFieldmark::parameter_map_t* GetParameters() const override
214  { return &m_vParams; }
215 
216  virtual void SetFieldname(const OUString& aFieldname) override
217  { m_aFieldname = aFieldname; }
218  virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
219  { m_aFieldHelptext = aFieldHelptext; }
220 
221  virtual void ReleaseDoc(SwDoc&) = 0;
222 
223  void SetMarkStartPos( const SwPosition& rNewStartPos );
224 
225  virtual void Invalidate() override;
226  virtual OUString ToString() const override;
227  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
228 
229  private:
230  OUString m_aFieldname;
233  };
234 
235  class TextFieldmark final
236  : public Fieldmark
237  {
238  public:
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;
242  };
243 
244  // Non text fieldmarks have no content between the start and end marks.
246  : public Fieldmark
247  {
248  public:
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;
252  };
253 
255  class CheckboxFieldmark final
256  : virtual public ICheckboxFieldmark
257  , public NonTextFieldmark
258  {
259  public:
260  CheckboxFieldmark(const SwPaM& rPaM);
261  bool IsChecked() const override;
262  void SetChecked(bool checked) override;
263  };
264 
267  : public NonTextFieldmark
268  {
269  public:
270  FieldmarkWithDropDownButton(const SwPaM& rPaM);
271  virtual ~FieldmarkWithDropDownButton() override;
272 
273  virtual void ShowButton(SwEditWin* pEditWin) = 0;
274  virtual void RemoveButton();
275 
276  protected:
278  };
279 
281  class DropDownFieldmark final
283  {
284  public:
285  DropDownFieldmark(const SwPaM& rPaM);
286  virtual ~DropDownFieldmark() override;
287 
288  virtual void ShowButton(SwEditWin* pEditWin) override;
289  virtual void RemoveButton() override;
290 
291  // This method should be called only by the portion so we can now the portion's painting area
292  void SetPortionPaintArea(const SwRect& rPortionPaintArea);
293 
294  void SendLOKShowMessage(const SfxViewShell* pViewShell);
295  static void SendLOKHideMessage(const SfxViewShell* pViewShell);
296 
297  private:
299  };
300 
306  class DateFieldmark final
307  : virtual public IDateFieldmark
309  {
310  public:
311  DateFieldmark(const SwPaM& rPaM);
312  virtual ~DateFieldmark() override;
313 
314  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
315  virtual void ReleaseDoc(SwDoc& rDoc) override;
316 
317  virtual void ShowButton(SwEditWin* pEditWin) override;
318 
319  void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
320  void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
321 
322  virtual OUString GetContent() const override;
323  virtual void ReplaceContent(const OUString& sNewContent) override;
324 
325  virtual std::pair<bool, double> GetCurrentDate() const override;
326  virtual void SetCurrentDate(double fDate) override;
327  virtual OUString GetDateInStandardDateFormat(double fDate) const override;
328 
329  private:
330  OUString GetDateInCurrentDateFormat(double fDate) const;
331  std::pair<bool, double> ParseCurrentDateParam() const;
333 
338  };
339 
341  SwPosition FindFieldSep(IFieldmark const& rMark);
342 
344  bool IsFieldmarkOverlap(SwPaM const& rPaM);
345 }
346 
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
virtual void Hide(bool rHide) override
virtual std::pair< bool, double > GetCurrentDate() const override
bool is() const
Fieldmark representing a date form field.
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
DateFieldmark(const SwPaM &rPaM)
virtual void ShowButton(SwEditWin *pEditWin)=0
static void SendLOKHideMessage(const SfxViewShell *pViewShell)
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
Marks a position in the document model.
Definition: pam.hxx:36
virtual OUString GetFieldHelptext() const override
bool IsChecked() const override
virtual void ShowButton(SwEditWin *pEditWin) override
virtual bool IsInUndo() const override
virtual void ReplaceContent(const OUString &sNewContent) override
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: doc.hxx:187
virtual SwPosition & GetMarkStart() const override
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
virtual auto InvalidateFrames() -> void override
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
void SetChecked(bool checked) override
virtual OUString ToString() const override
virtual void InitDoc(SwDoc &, sw::mark::InsertMode, SwPosition const *)
Fieldmark representing a checkbox form field.
UnoMark(const SwPaM &rPaM)
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
virtual ~DdeBookmark() override
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
std::unique_ptr< SwPosition > m_pPos1
virtual bool IsExpanded() const override
virtual void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
virtual SwPosition & GetMarkEnd() const override
virtual const OUString & GetName() const override
std::unique_ptr< SwPosition > m_pPos2
virtual void ReleaseDoc(SwDoc &)=0
virtual ~DropDownFieldmark() override
std::pair< bool, double > ParseCurrentDateParam() const
Mode eMode
OUString GetDateInCurrentDateFormat(double fDate) const
virtual void DeregisterFromDoc(SwDoc &rDoc)
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
virtual void ShowButton(SwEditWin *pEditWin) override
void SetRefObject(SwServerObject *pObj)
virtual void SetFieldname(const OUString &aFieldname) override
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:137
T * get() const
virtual bool IsHidden() const override
void SetName(const OUString &rName)
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
virtual void ReleaseDoc(SwDoc &rDoc) override
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:59
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
virtual void DeregisterFromDoc(SwDoc &io_rDoc) override
virtual void ReleaseDoc(SwDoc &rDoc) override
virtual void ReleaseDoc(SwDoc &rDoc) override
virtual void SetShortName(const OUString &rShortName) override
virtual auto InvalidateFrames() -> void
virtual ~MarkBase() override
virtual const vcl::KeyCode & GetKeyCode() const override
virtual const OUString & GetHideCondition() const override
SvNumberFormatter * m_pNumberFormatter
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
DdeBookmark(const SwPaM &rPaM)
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
static OUString GenerateNewName(std::u16string_view rPrefix)
DropDownFieldmark(const SwPaM &rPaM)
CheckboxFieldmark(const SwPaM &rPaM)
virtual OUString ToString() const override
NavigatorReminder(const SwPaM &rPaM)
NonTextFieldmark(const SwPaM &rPaM)
virtual SwPosition & GetOtherMarkPos() const override
MarkBase(const SwPaM &rPaM, const OUString &rName)
void SendLOKShowMessage(const SfxViewShell *pViewShell)
virtual const OUString & GetShortName() const override
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
virtual bool IsInContent() const override
virtual bool IsInClipboard() const override
virtual const IFieldmark::parameter_map_t * GetParameters() const override
virtual void RemoveButton() override
virtual SwPosition & GetMarkPos() const override
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
virtual void SetMarkPos(const SwPosition &rNewPos)
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
IFieldmark::parameter_map_t m_vParams
virtual ~DateFieldmark() override
virtual void SetCurrentDate(double fDate) override
virtual OUString GetContent() const override
Fieldmark(const SwPaM &rPaM)
virtual void SetHideCondition(const OUString &rHideCondition) override
struct _xmlTextWriter * xmlTextWriterPtr
tools::SvRef< SwServerObject > m_aRefObj
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
bool IsFieldmarkOverlap(SwPaM const &rPaM)
check if rPaM is valid range of new fieldmark
virtual void ClearOtherMarkPos()
Fieldmark representing a drop-down form field.
SwServerObject * GetRefObject()
const SwServerObject * GetRefObject() const
virtual void Invalidate() override
virtual OUString GetFieldname() const override
virtual IFieldmark::parameter_map_t * GetParameters() override
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
virtual OUString GetDateInStandardDateFormat(double fDate) const override