LibreOffice Module sw (master)  1
bookmrk.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 #ifndef INCLUDED_SW_SOURCE_CORE_INC_BOOKMRK_HXX
21 #define INCLUDED_SW_SOURCE_CORE_INC_BOOKMRK_HXX
22 
23 #include <cppuhelper/weakref.hxx>
24 #include <sfx2/Metadatable.hxx>
25 #include <vcl/keycod.hxx>
26 #include <memory>
27 #include <string_view>
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 namespace com::sun::star::text { class XTextContent; }
37 
38 class SwDoc;
39 class SwEditWin;
40 class SwServerObject;
41 class SvNumberFormatter;
42 
43 namespace sw::mark {
44  class MarkBase
45  : virtual public IMark
46  {
47  public:
48  //getters
49  virtual SwPosition& GetMarkPos() const override
50  { return *m_pPos1; }
51  virtual const OUString& GetName() const override
52  { return m_aName; }
53  virtual SwPosition& GetOtherMarkPos() const override
54  {
55  OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
56  return *m_pPos2;
57  }
58  virtual SwPosition& GetMarkStart() const override
59  {
60  if( !IsExpanded() ) return GetMarkPos( );
61  if ( GetMarkPos( ) < GetOtherMarkPos( ) )
62  return GetMarkPos();
63  else
64  return GetOtherMarkPos( );
65  }
66  virtual SwPosition& GetMarkEnd() const override
67  {
68  if( !IsExpanded() ) return GetMarkPos();
69  if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
70  return GetMarkPos( );
71  else
72  return GetOtherMarkPos( );
73  }
74 
75  virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
76  virtual bool IsExpanded() const override
77  { return static_cast< bool >(m_pPos2); }
78 
79  void SetName(const OUString& rName)
80  { m_aName = rName; }
81  virtual void SetMarkPos(const SwPosition& rNewPos);
82  virtual void SetOtherMarkPos(const SwPosition& rNewPos);
83  virtual void ClearOtherMarkPos()
84  { m_pPos2.reset(); }
85 
86  virtual auto InvalidateFrames() -> void;
87 
88  virtual OUString ToString( ) const override;
89  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
90 
91  void Swap()
92  {
93  if(m_pPos2)
94  m_pPos1.swap(m_pPos2);
95  }
96 
97  virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
98  {
99  }
100 
101  virtual ~MarkBase() override;
102 
103  const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
104  { return m_wXBookmark; }
105  void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
106  { m_wXBookmark = xBkmk; }
107 
108  protected:
109  // SwClient
110  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
111 
112  MarkBase(const SwPaM& rPaM, const OUString& rName);
113  std::unique_ptr<SwPosition> m_pPos1;
114  std::unique_ptr<SwPosition> m_pPos2;
115  OUString m_aName;
116  static OUString GenerateNewName(std::u16string_view rPrefix);
117 
118  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
119  };
120 
122  : public MarkBase
123  {
124  public:
125  NavigatorReminder(const SwPaM& rPaM);
126  };
127 
128  class UnoMark
129  : public MarkBase
130  {
131  public:
132  UnoMark(const SwPaM& rPaM);
133  };
134 
136  : public MarkBase
137  {
138  public:
139  DdeBookmark(const SwPaM& rPaM);
140 
141  const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
143 
144  bool IsServer() const { return m_aRefObj.is(); }
145 
146  void SetRefObject( SwServerObject* pObj );
147 
148  virtual void DeregisterFromDoc(SwDoc& rDoc);
149  virtual ~DdeBookmark() override;
150 
151  private:
153  };
154 
155  class Bookmark
156  : virtual public IBookmark
157  , public DdeBookmark
158  , public ::sfx2::Metadatable
159  {
160  public:
161  Bookmark(const SwPaM& rPaM,
162  const vcl::KeyCode& rCode,
163  const OUString& rName);
164  virtual void InitDoc(SwDoc& io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
165 
166  virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;
167 
168  virtual auto InvalidateFrames() -> void override;
169 
170  virtual const OUString& GetShortName() const override
171  { return m_sShortName; }
172  virtual const vcl::KeyCode& GetKeyCode() const override
173  { return m_aCode; }
174  virtual void SetShortName(const OUString& rShortName) override
175  { m_sShortName = rShortName; }
176  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
177  { m_aCode = rCode; }
178  virtual bool IsHidden() const override
179  { return m_bHidden; }
180  virtual const OUString& GetHideCondition() const override
181  { return m_sHideCondition; }
182  virtual void Hide(bool rHide) override;
183  virtual void SetHideCondition(const OUString& rHideCondition) override;
184 
185  // ::sfx2::Metadatable
186  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
187  virtual bool IsInClipboard() const override;
188  virtual bool IsInUndo() const override;
189  virtual bool IsInContent() const override;
190  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
191 
192  private:
194  OUString m_sShortName;
195  bool m_bHidden;
197  };
198 
199  class Fieldmark
200  : virtual public IFieldmark
201  , public MarkBase
202  {
203  public:
204  Fieldmark(const SwPaM& rPaM);
205 
206  virtual OUString GetFieldname() const override
207  { return m_aFieldname; }
208  virtual OUString GetFieldHelptext() const override
209  { return m_aFieldHelptext; }
210 
212  { return &m_vParams; }
213 
214  virtual const IFieldmark::parameter_map_t* GetParameters() const override
215  { return &m_vParams; }
216 
217  virtual void SetFieldname(const OUString& aFieldname) override
218  { m_aFieldname = aFieldname; }
219  virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
220  { m_aFieldHelptext = aFieldHelptext; }
221 
222  virtual void ReleaseDoc(SwDoc&) = 0;
223 
224  void SetMarkStartPos( const SwPosition& rNewStartPos );
225  void SetMarkEndPos( const SwPosition& rNewEndPos );
226 
227  virtual void Invalidate() override;
228  virtual OUString ToString() const override;
229  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
230 
231  private:
232  OUString m_aFieldname;
235  };
236 
238  : public Fieldmark
239  {
240  public:
241  TextFieldmark(const SwPaM& rPaM, const OUString& rName);
242  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
243  virtual void ReleaseDoc(SwDoc& rDoc) override;
244  };
245 
246  // Non text fieldmarks have no content between the start and end marks.
248  : public Fieldmark
249  {
250  public:
251  NonTextFieldmark(const SwPaM& rPaM);
252  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
253  virtual void ReleaseDoc(SwDoc& rDoc) override;
254  };
255 
258  : virtual public ICheckboxFieldmark
259  , public NonTextFieldmark
260  {
261  public:
262  CheckboxFieldmark(const SwPaM& rPaM);
263  bool IsChecked() const override;
264  void SetChecked(bool checked) override;
265  };
266 
269  : public NonTextFieldmark
270  {
271  public:
272  FieldmarkWithDropDownButton(const SwPaM& rPaM);
273  virtual ~FieldmarkWithDropDownButton() override;
274 
275  virtual void ShowButton(SwEditWin* pEditWin) = 0;
276  virtual void HideButton();
277  virtual void RemoveButton();
278 
279  protected:
281  };
282 
286  {
287  public:
288  DropDownFieldmark(const SwPaM& rPaM);
289  virtual ~DropDownFieldmark() override;
290 
291  virtual void ShowButton(SwEditWin* pEditWin) override;
292  virtual void HideButton() override;
293  virtual void RemoveButton() override;
294 
295  // This method should be called only by the portion so we can now the portion's painting area
296  void SetPortionPaintArea(const SwRect& rPortionPaintArea);
297 
298  void SendLOKMessage(std::string_view sAction);
299 
300  private:
303  };
304 
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 #endif
348 
349 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
Definition: bookmrk.cxx:494
OUString m_aName
Definition: bookmrk.hxx:115
virtual void Hide(bool rHide) override
Definition: bookmrk.cxx:438
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:894
bool is() const
Fieldmark representing a date form field.
Definition: bookmrk.hxx:306
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:583
DateFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:773
virtual void ShowButton(SwEditWin *pEditWin)=0
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
vcl::KeyCode m_aCode
Definition: bookmrk.hxx:193
Marks a position in the document model.
Definition: pam.hxx:35
OUString m_aFieldHelptext
Definition: bookmrk.hxx:233
virtual OUString GetFieldHelptext() const override
Definition: bookmrk.hxx:208
bool IsChecked() const override
Definition: bookmrk.cxx:631
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:673
virtual bool IsInUndo() const override
Definition: bookmrk.cxx:468
virtual void ReplaceContent(const OUString &sNewContent) override
Definition: bookmrk.cxx:869
OUString m_sHideCondition
Definition: bookmrk.hxx:196
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:527
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:552
Definition: doc.hxx:186
virtual SwPosition & GetMarkStart() const override
Definition: bookmrk.hxx:58
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
Definition: bookmrk.hxx:335
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: bookmrk.cxx:342
virtual auto InvalidateFrames() -> void override
Definition: bookmrk.cxx:429
OUString m_aFieldname
Definition: bookmrk.hxx:232
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
Definition: bookmrk.cxx:56
void SetChecked(bool checked) override
Definition: bookmrk.cxx:620
virtual OUString ToString() const override
Definition: bookmrk.cxx:291
virtual void InitDoc(SwDoc &, sw::mark::InsertMode, SwPosition const *)
Definition: bookmrk.hxx:97
Fieldmark representing a checkbox form field.
Definition: bookmrk.hxx:257
UnoMark(const SwPaM &rPaM)
Definition: bookmrk.cxx:360
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Definition: bookmrk.cxx:456
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:835
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
Definition: bookmrk.cxx:274
virtual ~DdeBookmark() override
Definition: bookmrk.cxx:379
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:545
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:268
std::unique_ptr< SwPosition > m_pPos1
Definition: bookmrk.hxx:113
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:76
virtual void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:403
virtual SwPosition & GetMarkEnd() const override
Definition: bookmrk.hxx:66
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:51
std::unique_ptr< SwPosition > m_pPos2
Definition: bookmrk.hxx:114
virtual void ReleaseDoc(SwDoc &)=0
virtual ~DropDownFieldmark() override
Definition: bookmrk.cxx:668
std::pair< bool, double > ParseCurrentDateParam() const
Definition: bookmrk.cxx:974
Mode eMode
OUString GetDateInCurrentDateFormat(double fDate) const
Definition: bookmrk.cxx:1010
void InvalidateCurrentDateParam()
Definition: bookmrk.cxx:1051
virtual void DeregisterFromDoc(SwDoc &rDoc)
Definition: bookmrk.cxx:373
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
Definition: bookmrk.cxx:392
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:814
void SetRefObject(SwServerObject *pObj)
Definition: bookmrk.cxx:368
virtual void SetFieldname(const OUString &aFieldname) override
Definition: bookmrk.hxx:217
void SendLOKMessage(std::string_view sAction)
Definition: bookmrk.cxx:708
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:136
struct _xmlTextWriter * xmlTextWriterPtr
T * get() const
virtual bool IsHidden() const override
Definition: bookmrk.hxx:178
void SetName(const OUString &rName)
Definition: bookmrk.hxx:79
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
Definition: bookmrk.hxx:118
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:565
void SetMarkEndPos(const SwPosition &rNewEndPos)
Definition: bookmrk.cxx:502
Window class for the Writer edit area, this is the one handling mouse and keyboard events and doing t...
Definition: edtwin.hxx:58
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:298
virtual void DeregisterFromDoc(SwDoc &io_rDoc) override
Definition: bookmrk.cxx:415
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:603
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:799
virtual void SetShortName(const OUString &rShortName) override
Definition: bookmrk.hxx:174
virtual auto InvalidateFrames() -> void
Definition: bookmrk.cxx:352
virtual ~MarkBase() override
Definition: bookmrk.cxx:314
virtual const vcl::KeyCode & GetKeyCode() const override
Definition: bookmrk.hxx:172
virtual const OUString & GetHideCondition() const override
Definition: bookmrk.hxx:180
SvNumberFormatter * m_pNumberFormatter
Definition: bookmrk.hxx:334
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
Definition: bookmrk.hxx:176
virtual void HideButton() override
Definition: bookmrk.cxx:685
DdeBookmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:364
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: bookmrk.cxx:479
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:826
static OUString GenerateNewName(std::u16string_view rPrefix)
Definition: bookmrk.cxx:317
DropDownFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:663
CheckboxFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:616
virtual OUString ToString() const override
Definition: bookmrk.cxx:510
NavigatorReminder(const SwPaM &rPaM)
Definition: bookmrk.cxx:356
NonTextFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:579
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:53
FieldmarkWithDropDownButton(const SwPaM &rPaM)
Definition: bookmrk.cxx:640
MarkBase(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:257
virtual const OUString & GetShortName() const override
Definition: bookmrk.hxx:170
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
Definition: bookmrk.hxx:105
virtual bool IsInContent() const override
Definition: bookmrk.cxx:473
virtual bool IsInClipboard() const override
Definition: bookmrk.cxx:462
virtual const IFieldmark::parameter_map_t * GetParameters() const override
Definition: bookmrk.hxx:214
virtual void RemoveButton() override
Definition: bookmrk.cxx:691
OUString m_sShortName
Definition: bookmrk.hxx:194
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:49
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
Definition: bookmrk.hxx:219
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:279
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:784
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:697
IFieldmark::parameter_map_t m_vParams
Definition: bookmrk.hxx:234
virtual ~DateFieldmark() override
Definition: bookmrk.cxx:780
virtual void SetCurrentDate(double fDate) override
Definition: bookmrk.cxx:940
virtual OUString GetContent() const override
Definition: bookmrk.cxx:855
Fieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:487
virtual void SetHideCondition(const OUString &rHideCondition) override
Definition: bookmrk.cxx:447
tools::SvRef< SwServerObject > m_aRefObj
Definition: bookmrk.hxx:152
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
Definition: bookmrk.hxx:103
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:285
bool IsFieldmarkOverlap(SwPaM const &rPaM)
check if rPaM is valid range of new fieldmark
virtual ~FieldmarkWithDropDownButton() override
Definition: bookmrk.cxx:646
virtual void ClearOtherMarkPos()
Definition: bookmrk.hxx:83
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:284
SwServerObject * GetRefObject()
Definition: bookmrk.hxx:142
const SwServerObject * GetRefObject() const
Definition: bookmrk.hxx:141
virtual void Invalidate() override
Definition: bookmrk.cxx:519
virtual OUString GetFieldname() const override
Definition: bookmrk.hxx:206
VclPtr< FormFieldButton > m_pButton
Definition: bookmrk.hxx:280
virtual IFieldmark::parameter_map_t * GetParameters() override
Definition: bookmrk.hxx:211
bool IsServer() const
Definition: bookmrk.hxx:144
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
virtual OUString GetDateInStandardDateFormat(double fDate) const override
Definition: bookmrk.cxx:950