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 class SfxViewShell;
43 
44 namespace sw::mark {
45  class MarkBase
46  : virtual public IMark
47  {
48  public:
49  //getters
50  virtual SwPosition& GetMarkPos() const override
51  { return *m_pPos1; }
52  virtual const OUString& GetName() const override
53  { return m_aName; }
54  virtual SwPosition& GetOtherMarkPos() const override
55  {
56  OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
57  return *m_pPos2;
58  }
59  virtual SwPosition& GetMarkStart() const override
60  {
61  if( !IsExpanded() ) return GetMarkPos( );
62  if ( GetMarkPos( ) < GetOtherMarkPos( ) )
63  return GetMarkPos();
64  else
65  return GetOtherMarkPos( );
66  }
67  virtual SwPosition& GetMarkEnd() const override
68  {
69  if( !IsExpanded() ) return GetMarkPos();
70  if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
71  return GetMarkPos( );
72  else
73  return GetOtherMarkPos( );
74  }
75 
76  virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
77  virtual bool IsExpanded() const override
78  { return static_cast< bool >(m_pPos2); }
79 
80  void SetName(const OUString& rName)
81  { m_aName = rName; }
82  virtual void SetMarkPos(const SwPosition& rNewPos);
83  virtual void SetOtherMarkPos(const SwPosition& rNewPos);
84  virtual void ClearOtherMarkPos()
85  { m_pPos2.reset(); }
86 
87  virtual auto InvalidateFrames() -> void;
88 
89  virtual OUString ToString( ) const override;
90  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
91 
92  void Swap()
93  {
94  if(m_pPos2)
95  m_pPos1.swap(m_pPos2);
96  }
97 
98  virtual void InitDoc(SwDoc&, sw::mark::InsertMode, SwPosition const*)
99  {
100  }
101 
102  virtual ~MarkBase() override;
103 
104  const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
105  { return m_wXBookmark; }
106  void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
107  { m_wXBookmark = xBkmk; }
108 
109  protected:
110  // SwClient
111  virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
112 
113  MarkBase(const SwPaM& rPaM, const OUString& rName);
114  std::unique_ptr<SwPosition> m_pPos1;
115  std::unique_ptr<SwPosition> m_pPos2;
116  OUString m_aName;
117  static OUString GenerateNewName(std::u16string_view rPrefix);
118 
119  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
120  };
121 
122  class NavigatorReminder final
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  virtual ~DdeBookmark() override;
151 
152  private:
154  };
155 
156  class Bookmark
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  virtual void InitDoc(SwDoc& io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
166 
167  virtual void DeregisterFromDoc(SwDoc& io_rDoc) override;
168 
169  virtual auto InvalidateFrames() -> void override;
170 
171  virtual const OUString& GetShortName() const override
172  { return m_sShortName; }
173  virtual const vcl::KeyCode& GetKeyCode() const override
174  { return m_aCode; }
175  virtual void SetShortName(const OUString& rShortName) override
176  { m_sShortName = rShortName; }
177  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
178  { m_aCode = rCode; }
179  virtual bool IsHidden() const override
180  { return m_bHidden; }
181  virtual const OUString& GetHideCondition() const override
182  { return m_sHideCondition; }
183  virtual void Hide(bool rHide) override;
184  virtual void SetHideCondition(const OUString& rHideCondition) override;
185 
186  // ::sfx2::Metadatable
187  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
188  virtual bool IsInClipboard() const override;
189  virtual bool IsInUndo() const override;
190  virtual bool IsInContent() const override;
191  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
192 
193  private:
195  OUString m_sShortName;
196  bool m_bHidden;
198  };
199 
200  class Fieldmark
201  : virtual public IFieldmark
202  , public MarkBase
203  {
204  public:
205  Fieldmark(const SwPaM& rPaM);
206 
207  virtual OUString GetFieldname() const override
208  { return m_aFieldname; }
209  virtual OUString GetFieldHelptext() const override
210  { return m_aFieldHelptext; }
211 
213  { return &m_vParams; }
214 
215  virtual const IFieldmark::parameter_map_t* GetParameters() const override
216  { return &m_vParams; }
217 
218  virtual void SetFieldname(const OUString& aFieldname) override
219  { m_aFieldname = aFieldname; }
220  virtual 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  void SetMarkEndPos( const SwPosition& rNewEndPos );
227 
228  virtual void Invalidate() override;
229  virtual OUString ToString() const override;
230  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
231 
232  private:
233  OUString m_aFieldname;
236  };
237 
238  class TextFieldmark final
239  : public Fieldmark
240  {
241  public:
242  TextFieldmark(const SwPaM& rPaM, const OUString& rName);
243  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
244  virtual void ReleaseDoc(SwDoc& rDoc) override;
245  };
246 
247  // Non text fieldmarks have no content between the start and end marks.
249  : public Fieldmark
250  {
251  public:
252  NonTextFieldmark(const SwPaM& rPaM);
253  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
254  virtual void ReleaseDoc(SwDoc& rDoc) override;
255  };
256 
258  class CheckboxFieldmark final
259  : virtual public ICheckboxFieldmark
260  , public NonTextFieldmark
261  {
262  public:
263  CheckboxFieldmark(const SwPaM& rPaM);
264  bool IsChecked() const override;
265  void SetChecked(bool checked) override;
266  };
267 
270  : public NonTextFieldmark
271  {
272  public:
273  FieldmarkWithDropDownButton(const SwPaM& rPaM);
274  virtual ~FieldmarkWithDropDownButton() override;
275 
276  virtual void ShowButton(SwEditWin* pEditWin) = 0;
277  virtual void RemoveButton();
278 
279  protected:
281  };
282 
284  class DropDownFieldmark final
286  {
287  public:
288  DropDownFieldmark(const SwPaM& rPaM);
289  virtual ~DropDownFieldmark() override;
290 
291  virtual void ShowButton(SwEditWin* pEditWin) override;
292  virtual void RemoveButton() override;
293 
294  // This method should be called only by the portion so we can now the portion's painting area
295  void SetPortionPaintArea(const SwRect& rPortionPaintArea);
296 
297  void SendLOKShowMessage(const SfxViewShell* pViewShell);
298  static void SendLOKHideMessage(const SfxViewShell* pViewShell);
299 
300  private:
302  };
303 
305  class DateFieldmark final
306  : virtual public IDateFieldmark
308  {
309  public:
310  DateFieldmark(const SwPaM& rPaM);
311  virtual ~DateFieldmark() override;
312 
313  virtual void InitDoc(SwDoc& io_rDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
314  virtual void ReleaseDoc(SwDoc& rDoc) override;
315 
316  virtual void ShowButton(SwEditWin* pEditWin) override;
317 
318  void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
319  void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
320 
321  virtual OUString GetContent() const override;
322  virtual void ReplaceContent(const OUString& sNewContent) override;
323 
324  virtual std::pair<bool, double> GetCurrentDate() const override;
325  virtual void SetCurrentDate(double fDate) override;
326  virtual OUString GetDateInStandardDateFormat(double fDate) const override;
327 
328  private:
329  OUString GetDateInCurrentDateFormat(double fDate) const;
330  std::pair<bool, double> ParseCurrentDateParam() const;
332 
337  };
338 
340  SwPosition FindFieldSep(IFieldmark const& rMark);
341 
343  bool IsFieldmarkOverlap(SwPaM const& rPaM);
344 }
345 
346 #endif
347 
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
Definition: bookmrk.cxx:497
OUString m_aName
Definition: bookmrk.hxx:116
virtual void Hide(bool rHide) override
Definition: bookmrk.cxx:440
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:867
bool is() const
Fieldmark representing a date form field.
Definition: bookmrk.hxx:305
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:586
DateFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:746
virtual void ShowButton(SwEditWin *pEditWin)=0
static void SendLOKHideMessage(const SfxViewShell *pViewShell)
Definition: bookmrk.cxx:740
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
vcl::KeyCode m_aCode
Definition: bookmrk.hxx:194
Marks a position in the document model.
Definition: pam.hxx:35
OUString m_aFieldHelptext
Definition: bookmrk.hxx:234
virtual OUString GetFieldHelptext() const override
Definition: bookmrk.hxx:209
bool IsChecked() const override
Definition: bookmrk.cxx:634
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:669
virtual bool IsInUndo() const override
Definition: bookmrk.cxx:471
virtual void ReplaceContent(const OUString &sNewContent) override
Definition: bookmrk.cxx:842
OUString m_sHideCondition
Definition: bookmrk.hxx:197
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:530
virtual void InitDoc(SwDoc &io_rDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:555
Definition: doc.hxx:188
virtual SwPosition & GetMarkStart() const override
Definition: bookmrk.hxx:59
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
Definition: bookmrk.hxx:334
virtual void SwClientNotify(const SwModify &, const SfxHint &) override
Definition: bookmrk.cxx:343
virtual auto InvalidateFrames() -> void override
Definition: bookmrk.cxx:431
OUString m_aFieldname
Definition: bookmrk.hxx:233
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:623
virtual OUString ToString() const override
Definition: bookmrk.cxx:292
virtual void InitDoc(SwDoc &, sw::mark::InsertMode, SwPosition const *)
Definition: bookmrk.hxx:98
Fieldmark representing a checkbox form field.
Definition: bookmrk.hxx:258
UnoMark(const SwPaM &rPaM)
Definition: bookmrk.cxx:363
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Definition: bookmrk.cxx:459
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:808
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
Definition: bookmrk.cxx:275
virtual ~DdeBookmark() override
Definition: bookmrk.cxx:382
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:548
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:269
std::unique_ptr< SwPosition > m_pPos1
Definition: bookmrk.hxx:114
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:77
virtual void InitDoc(SwDoc &io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:405
virtual SwPosition & GetMarkEnd() const override
Definition: bookmrk.hxx:67
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:52
std::unique_ptr< SwPosition > m_pPos2
Definition: bookmrk.hxx:115
virtual void ReleaseDoc(SwDoc &)=0
virtual ~DropDownFieldmark() override
Definition: bookmrk.cxx:665
std::pair< bool, double > ParseCurrentDateParam() const
Definition: bookmrk.cxx:947
Mode eMode
OUString GetDateInCurrentDateFormat(double fDate) const
Definition: bookmrk.cxx:983
void InvalidateCurrentDateParam()
Definition: bookmrk.cxx:1024
virtual void DeregisterFromDoc(SwDoc &rDoc)
Definition: bookmrk.cxx:376
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
Definition: bookmrk.cxx:395
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:787
void SetRefObject(SwServerObject *pObj)
Definition: bookmrk.cxx:371
virtual void SetFieldname(const OUString &aFieldname) override
Definition: bookmrk.hxx:218
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:179
void SetName(const OUString &rName)
Definition: bookmrk.hxx:80
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
Definition: bookmrk.hxx:119
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:568
void SetMarkEndPos(const SwPosition &rNewEndPos)
Definition: bookmrk.cxx:505
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:417
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:606
virtual void ReleaseDoc(SwDoc &rDoc) override
Definition: bookmrk.cxx:772
virtual void SetShortName(const OUString &rShortName) override
Definition: bookmrk.hxx:175
virtual auto InvalidateFrames() -> void
Definition: bookmrk.cxx:355
virtual ~MarkBase() override
Definition: bookmrk.cxx:315
virtual const vcl::KeyCode & GetKeyCode() const override
Definition: bookmrk.hxx:173
virtual const OUString & GetHideCondition() const override
Definition: bookmrk.hxx:181
SvNumberFormatter * m_pNumberFormatter
Definition: bookmrk.hxx:333
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
Definition: bookmrk.hxx:177
DdeBookmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:367
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: bookmrk.cxx:482
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:799
static OUString GenerateNewName(std::u16string_view rPrefix)
Definition: bookmrk.cxx:318
DropDownFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:660
CheckboxFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:619
virtual OUString ToString() const override
Definition: bookmrk.cxx:513
NavigatorReminder(const SwPaM &rPaM)
Definition: bookmrk.cxx:359
NonTextFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:582
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:54
FieldmarkWithDropDownButton(const SwPaM &rPaM)
Definition: bookmrk.cxx:643
MarkBase(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:258
void SendLOKShowMessage(const SfxViewShell *pViewShell)
Definition: bookmrk.cxx:695
virtual const OUString & GetShortName() const override
Definition: bookmrk.hxx:171
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
Definition: bookmrk.hxx:106
virtual bool IsInContent() const override
Definition: bookmrk.cxx:476
virtual bool IsInClipboard() const override
Definition: bookmrk.cxx:465
virtual const IFieldmark::parameter_map_t * GetParameters() const override
Definition: bookmrk.hxx:215
virtual void RemoveButton() override
Definition: bookmrk.cxx:680
OUString m_sShortName
Definition: bookmrk.hxx:195
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:50
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
Definition: bookmrk.hxx:220
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:757
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:685
IFieldmark::parameter_map_t m_vParams
Definition: bookmrk.hxx:235
virtual ~DateFieldmark() override
Definition: bookmrk.cxx:753
virtual void SetCurrentDate(double fDate) override
Definition: bookmrk.cxx:913
virtual OUString GetContent() const override
Definition: bookmrk.cxx:828
Fieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:490
virtual void SetHideCondition(const OUString &rHideCondition) override
Definition: bookmrk.cxx:449
tools::SvRef< SwServerObject > m_aRefObj
Definition: bookmrk.hxx:153
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
Definition: bookmrk.hxx:104
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:649
virtual void ClearOtherMarkPos()
Definition: bookmrk.hxx:84
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:284
SwServerObject * GetRefObject()
Definition: bookmrk.hxx:143
const SwServerObject * GetRefObject() const
Definition: bookmrk.hxx:142
virtual void Invalidate() override
Definition: bookmrk.cxx:522
virtual OUString GetFieldname() const override
Definition: bookmrk.hxx:207
VclPtr< FormFieldButton > m_pButton
Definition: bookmrk.hxx:280
virtual IFieldmark::parameter_map_t * GetParameters() override
Definition: bookmrk.hxx:212
bool IsServer() const
Definition: bookmrk.hxx:145
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
virtual OUString GetDateInStandardDateFormat(double fDate) const override
Definition: bookmrk.cxx:923