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 <rtl/ustring.hxx>
28 #include <osl/diagnose.h>
29 #include <tools/ref.hxx>
30 #include <IMark.hxx>
31 #include <swrect.hxx>
32 #include "FormFieldButton.hxx"
33 
34 namespace com::sun::star::text { class XTextContent; }
35 
36 class SwDoc;
37 class SwEditWin;
38 class SwServerObject;
39 class SvNumberFormatter;
40 
41 namespace sw::mark {
42  class MarkBase
43  : virtual public IMark
44  {
45  public:
46  //getters
47  virtual SwPosition& GetMarkPos() const override
48  { return *m_pPos1; }
49  virtual const OUString& GetName() const override
50  { return m_aName; }
51  virtual SwPosition& GetOtherMarkPos() const override
52  {
53  OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
54  return *m_pPos2;
55  }
56  virtual SwPosition& GetMarkStart() const override
57  {
58  if( !IsExpanded() ) return GetMarkPos( );
59  if ( GetMarkPos( ) < GetOtherMarkPos( ) )
60  return GetMarkPos();
61  else
62  return GetOtherMarkPos( );
63  }
64  virtual SwPosition& GetMarkEnd() const override
65  {
66  if( !IsExpanded() ) return GetMarkPos();
67  if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
68  return GetMarkPos( );
69  else
70  return GetOtherMarkPos( );
71  }
72 
73  virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
74  virtual bool IsExpanded() const override
75  { return static_cast< bool >(m_pPos2); }
76 
77  void SetName(const OUString& rName)
78  { m_aName = rName; }
79  virtual void SetMarkPos(const SwPosition& rNewPos);
80  virtual void SetOtherMarkPos(const SwPosition& rNewPos);
81  virtual void ClearOtherMarkPos()
82  { m_pPos2.reset(); }
83 
84  virtual auto InvalidateFrames() -> void;
85 
86  virtual OUString ToString( ) const override;
87  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
88 
89  void Swap()
90  {
91  if(m_pPos2)
92  m_pPos1.swap(m_pPos2);
93  }
94 
95  virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
96  {
97  }
98 
99  virtual ~MarkBase() override;
100 
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; }
105 
106  protected:
107  // SwClient
108  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
109 
110  MarkBase(const SwPaM& rPaM, const OUString& rName);
111  std::unique_ptr<SwPosition> m_pPos1;
112  std::unique_ptr<SwPosition> m_pPos2;
113  OUString m_aName;
114  static OUString GenerateNewName(const OUString& rPrefix);
115 
116  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
117  };
118 
120  : public MarkBase
121  {
122  public:
123  NavigatorReminder(const SwPaM& rPaM);
124  };
125 
126  class UnoMark
127  : public MarkBase
128  {
129  public:
130  UnoMark(const SwPaM& rPaM);
131  };
132 
134  : public MarkBase
135  {
136  public:
137  DdeBookmark(const SwPaM& rPaM);
138 
139  const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
141 
142  bool IsServer() const { return m_aRefObj.is(); }
143 
144  void SetRefObject( SwServerObject* pObj );
145 
146  virtual void DeregisterFromDoc(SwDoc& rDoc);
147  virtual ~DdeBookmark() override;
148 
149  private:
151  };
152 
153  class Bookmark
154  : virtual public IBookmark
155  , public DdeBookmark
156  , public ::sfx2::Metadatable
157  {
158  public:
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;
163 
164  virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;
165 
166  virtual auto InvalidateFrames() -> void override;
167 
168  virtual const OUString& GetShortName() const override
169  { return m_sShortName; }
170  virtual const vcl::KeyCode& GetKeyCode() const override
171  { return m_aCode; }
172  virtual void SetShortName(const OUString& rShortName) override
173  { m_sShortName = rShortName; }
174  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
175  { m_aCode = rCode; }
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;
182 
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;
189 
190  private:
192  OUString m_sShortName;
193  bool m_bHidden;
195  };
196 
197  class Fieldmark
198  : virtual public IFieldmark
199  , public MarkBase
200  {
201  public:
202  Fieldmark(const SwPaM& rPaM);
203 
204  virtual OUString GetFieldname() const override
205  { return m_aFieldname; }
206  virtual OUString GetFieldHelptext() const override
207  { return m_aFieldHelptext; }
208 
210  { return &m_vParams; }
211 
212  virtual const IFieldmark::parameter_map_t* GetParameters() const override
213  { return &m_vParams; }
214 
215  virtual void SetFieldname(const OUString& aFieldname) override
216  { m_aFieldname = aFieldname; }
217  virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
218  { m_aFieldHelptext = aFieldHelptext; }
219 
220  virtual void ReleaseDoc(SwDoc&) = 0;
221 
222  void SetMarkStartPos( const SwPosition& rNewStartPos );
223  void SetMarkEndPos( const SwPosition& rNewEndPos );
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 
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 
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 HideButton();
275  virtual void RemoveButton();
276 
277  protected:
279  };
280 
284  {
285  public:
286  DropDownFieldmark(const SwPaM& rPaM);
287  virtual ~DropDownFieldmark() override;
288 
289  virtual void ShowButton(SwEditWin* pEditWin) override;
290  virtual void HideButton() override;
291  virtual void RemoveButton() override;
292 
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);
295 
296  void SendLOKMessage(const OString& sAction);
297 
298  private:
301  };
302 
305  : virtual public IDateFieldmark
307  {
308  public:
309  DateFieldmark(const SwPaM& rPaM);
310  virtual ~DateFieldmark() override;
311 
312  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
313  virtual void ReleaseDoc(SwDoc& rDoc) override;
314 
315  virtual void ShowButton(SwEditWin* pEditWin) override;
316 
317  void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
318  void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
319 
320  virtual OUString GetContent() const override;
321  virtual void ReplaceContent(const OUString& sNewContent) override;
322 
323  virtual std::pair<bool, double> GetCurrentDate() const override;
324  virtual void SetCurrentDate(double fDate) override;
325  virtual OUString GetDateInStandardDateFormat(double fDate) const override;
326 
327  private:
328  OUString GetDateInCurrentDateFormat(double fDate) const;
329  std::pair<bool, double> ParseCurrentDateParam() const;
331 
336  };
337 
339  SwPosition FindFieldSep(IFieldmark const& rMark);
340 
342  bool IsFieldmarkOverlap(SwPaM const& rPaM);
343 }
344 
345 #endif
346 
347 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
Definition: bookmrk.cxx:495
OUString m_aName
Definition: bookmrk.hxx:113
static OUString GenerateNewName(const OUString &rPrefix)
Definition: bookmrk.cxx:318
virtual void Hide(bool rHide) override
Definition: bookmrk.cxx:439
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:891
bool is() const
Fieldmark representing a date form field.
Definition: bookmrk.hxx:304
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:191
Marks a position in the document model.
Definition: pam.hxx:35
OUString m_aFieldHelptext
Definition: bookmrk.hxx:231
virtual OUString GetFieldHelptext() const override
Definition: bookmrk.hxx:206
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:469
virtual void ReplaceContent(const OUString &sNewContent) override
Definition: bookmrk.cxx:866
OUString m_sHideCondition
Definition: bookmrk.hxx:194
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:528
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:553
Definition: doc.hxx:184
virtual SwPosition & GetMarkStart() const override
Definition: bookmrk.hxx:56
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
Definition: bookmrk.hxx:333
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: bookmrk.cxx:343
virtual auto InvalidateFrames() -> void override
Definition: bookmrk.cxx:430
OUString m_aFieldname
Definition: bookmrk.hxx:230
SwPosition FindFieldSep(IFieldmark const &rMark)
return position of the CH_TXT_ATR_FIELDSEP for rMark
Definition: bookmrk.cxx:57
void SetChecked(bool checked) override
Definition: bookmrk.cxx:620
virtual OUString ToString() const override
Definition: bookmrk.cxx:292
virtual void InitDoc(SwDoc &, sw::mark::InsertMode, SwPosition const *)
Definition: bookmrk.hxx:95
Fieldmark representing a checkbox form field.
Definition: bookmrk.hxx:255
UnoMark(const SwPaM &rPaM)
Definition: bookmrk.cxx:361
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Definition: bookmrk.cxx:457
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:832
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
Definition: bookmrk.cxx:275
virtual ~DdeBookmark() override
Definition: bookmrk.cxx:380
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:546
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:266
std::unique_ptr< SwPosition > m_pPos1
Definition: bookmrk.hxx:111
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:74
virtual void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:404
virtual SwPosition & GetMarkEnd() const override
Definition: bookmrk.hxx:64
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:49
std::unique_ptr< SwPosition > m_pPos2
Definition: bookmrk.hxx:112
virtual void ReleaseDoc(SwDoc &)=0
virtual ~DropDownFieldmark() override
Definition: bookmrk.cxx:668
std::pair< bool, double > ParseCurrentDateParam() const
Definition: bookmrk.cxx:971
Mode eMode
OUString GetDateInCurrentDateFormat(double fDate) const
Definition: bookmrk.cxx:1007
void InvalidateCurrentDateParam()
Definition: bookmrk.cxx:1048
virtual void DeregisterFromDoc(SwDoc &rDoc)
Definition: bookmrk.cxx:374
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
Definition: bookmrk.cxx:393
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:811
void SetRefObject(SwServerObject *pObj)
Definition: bookmrk.cxx:369
virtual void SetFieldname(const OUString &aFieldname) override
Definition: bookmrk.hxx:215
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:176
void SetName(const OUString &rName)
Definition: bookmrk.hxx:77
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
Definition: bookmrk.hxx:116
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:568
void SetMarkEndPos(const SwPosition &rNewEndPos)
Definition: bookmrk.cxx:503
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:299
virtual void DeregisterFromDoc(SwDoc &io_rDoc) override
Definition: bookmrk.cxx:416
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:172
virtual auto InvalidateFrames() -> void
Definition: bookmrk.cxx:353
virtual ~MarkBase() override
Definition: bookmrk.cxx:315
virtual const vcl::KeyCode & GetKeyCode() const override
Definition: bookmrk.hxx:170
virtual const OUString & GetHideCondition() const override
Definition: bookmrk.hxx:178
SvNumberFormatter * m_pNumberFormatter
Definition: bookmrk.hxx:332
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
Definition: bookmrk.hxx:174
virtual void HideButton() override
Definition: bookmrk.cxx:685
DdeBookmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:365
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: bookmrk.cxx:480
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:823
DropDownFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:663
void SendLOKMessage(const OString &sAction)
Definition: bookmrk.cxx:708
CheckboxFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:616
virtual OUString ToString() const override
Definition: bookmrk.cxx:511
NavigatorReminder(const SwPaM &rPaM)
Definition: bookmrk.cxx:357
NonTextFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:579
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:51
FieldmarkWithDropDownButton(const SwPaM &rPaM)
Definition: bookmrk.cxx:640
MarkBase(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:258
virtual const OUString & GetShortName() const override
Definition: bookmrk.hxx:168
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
Definition: bookmrk.hxx:103
virtual bool IsInContent() const override
Definition: bookmrk.cxx:474
virtual bool IsInClipboard() const override
Definition: bookmrk.cxx:463
virtual const IFieldmark::parameter_map_t * GetParameters() const override
Definition: bookmrk.hxx:212
virtual void RemoveButton() override
Definition: bookmrk.cxx:691
OUString m_sShortName
Definition: bookmrk.hxx:192
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:47
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
Definition: bookmrk.hxx:217
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:280
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:232
virtual ~DateFieldmark() override
Definition: bookmrk.cxx:780
virtual void SetCurrentDate(double fDate) override
Definition: bookmrk.cxx:937
virtual OUString GetContent() const override
Definition: bookmrk.cxx:852
Fieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:488
virtual void SetHideCondition(const OUString &rHideCondition) override
Definition: bookmrk.cxx:448
tools::SvRef< SwServerObject > m_aRefObj
Definition: bookmrk.hxx:150
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
Definition: bookmrk.hxx:101
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:286
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:81
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:282
SwServerObject * GetRefObject()
Definition: bookmrk.hxx:140
const SwServerObject * GetRefObject() const
Definition: bookmrk.hxx:139
virtual void Invalidate() override
Definition: bookmrk.cxx:520
virtual OUString GetFieldname() const override
Definition: bookmrk.hxx:204
VclPtr< FormFieldButton > m_pButton
Definition: bookmrk.hxx:278
virtual IFieldmark::parameter_map_t * GetParameters() override
Definition: bookmrk.hxx:209
bool IsServer() const
Definition: bookmrk.hxx:142
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
virtual OUString GetDateInStandardDateFormat(double fDate) const override
Definition: bookmrk.cxx:947