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 {
35  namespace sun {
36  namespace star {
37  namespace text {
38  class XTextContent;
39  }
40  }
41  }
42 }
43 
44 class SwDoc;
45 class SwEditWin;
46 class SwServerObject;
47 class SvNumberFormatter;
48 
49 namespace sw {
50  namespace mark {
51  class MarkBase
52  : virtual public IMark
53  {
54  public:
55  //getters
56  virtual SwPosition& GetMarkPos() const override
57  { return *m_pPos1; }
58  virtual const OUString& GetName() const override
59  { return m_aName; }
60  virtual SwPosition& GetOtherMarkPos() const override
61  {
62  OSL_PRECOND(IsExpanded(), "<SwPosition::GetOtherMarkPos(..)> - I have no other Pos set." );
63  return *m_pPos2;
64  }
65  virtual SwPosition& GetMarkStart() const override
66  {
67  if( !IsExpanded() ) return GetMarkPos( );
68  if ( GetMarkPos( ) < GetOtherMarkPos( ) )
69  return GetMarkPos();
70  else
71  return GetOtherMarkPos( );
72  }
73  virtual SwPosition& GetMarkEnd() const override
74  {
75  if( !IsExpanded() ) return GetMarkPos();
76  if ( GetMarkPos( ) >= GetOtherMarkPos( ) )
77  return GetMarkPos( );
78  else
79  return GetOtherMarkPos( );
80  }
81 
82  virtual bool IsCoveringPosition(const SwPosition& rPos) const override;
83  virtual bool IsExpanded() const override
84  { return static_cast< bool >(m_pPos2); }
85 
86  void SetName(const OUString& rName)
87  { m_aName = rName; }
88  virtual void SetMarkPos(const SwPosition& rNewPos);
89  virtual void SetOtherMarkPos(const SwPosition& rNewPos);
90  virtual void ClearOtherMarkPos()
91  { m_pPos2.reset(); }
92 
93  virtual auto InvalidateFrames() -> void;
94 
95  virtual OUString ToString( ) const override;
96  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
97 
98  void Swap()
99  {
100  if(m_pPos2)
101  m_pPos1.swap(m_pPos2);
102  }
103 
104  virtual void InitDoc(SwDoc* const, sw::mark::InsertMode, SwPosition const*)
105  {
106  }
107 
108  virtual ~MarkBase() override;
109 
110  const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
111  { return m_wXBookmark; }
112  void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
113  { m_wXBookmark = xBkmk; }
114 
115  protected:
116  // SwClient
117  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
118 
119  MarkBase(const SwPaM& rPaM, const OUString& rName);
120  std::unique_ptr<SwPosition> m_pPos1;
121  std::unique_ptr<SwPosition> m_pPos2;
122  OUString m_aName;
123  static OUString GenerateNewName(const OUString& rPrefix);
124 
125  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
126  };
127 
129  : public MarkBase
130  {
131  public:
132  NavigatorReminder(const SwPaM& rPaM);
133  };
134 
135  class UnoMark
136  : public MarkBase
137  {
138  public:
139  UnoMark(const SwPaM& rPaM);
140  };
141 
143  : public MarkBase
144  {
145  public:
146  DdeBookmark(const SwPaM& rPaM);
147 
148  const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
150 
151  bool IsServer() const { return m_aRefObj.is(); }
152 
153  void SetRefObject( SwServerObject* pObj );
154 
155  virtual void DeregisterFromDoc(SwDoc* const pDoc);
156  virtual ~DdeBookmark() override;
157 
158  private:
160  };
161 
162  class Bookmark
163  : virtual public IBookmark
164  , public DdeBookmark
165  , public ::sfx2::Metadatable
166  {
167  public:
168  Bookmark(const SwPaM& rPaM,
169  const vcl::KeyCode& rCode,
170  const OUString& rName);
171  virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
172 
173  virtual void DeregisterFromDoc(SwDoc* const io_pDoc) override;
174 
175  virtual auto InvalidateFrames() -> void override;
176 
177  virtual const OUString& GetShortName() const override
178  { return m_sShortName; }
179  virtual const vcl::KeyCode& GetKeyCode() const override
180  { return m_aCode; }
181  virtual void SetShortName(const OUString& rShortName) override
182  { m_sShortName = rShortName; }
183  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
184  { m_aCode = rCode; }
185  virtual bool IsHidden() const override
186  { return m_bHidden; }
187  virtual const OUString& GetHideCondition() const override
188  { return m_sHideCondition; }
189  virtual void Hide(bool rHide) override;
190  virtual void SetHideCondition(const OUString& rHideCondition) override;
191 
192  // ::sfx2::Metadatable
193  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
194  virtual bool IsInClipboard() const override;
195  virtual bool IsInUndo() const override;
196  virtual bool IsInContent() const override;
197  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
198 
199  private:
201  OUString m_sShortName;
202  bool m_bHidden;
204  };
205 
206  class Fieldmark
207  : virtual public IFieldmark
208  , public MarkBase
209  {
210  public:
211  Fieldmark(const SwPaM& rPaM);
212 
213  virtual OUString GetFieldname() const override
214  { return m_aFieldname; }
215  virtual OUString GetFieldHelptext() const override
216  { return m_aFieldHelptext; }
217 
219  { return &m_vParams; }
220 
221  virtual const IFieldmark::parameter_map_t* GetParameters() const override
222  { return &m_vParams; }
223 
224  virtual void SetFieldname(const OUString& aFieldname) override
225  { m_aFieldname = aFieldname; }
226  virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
227  { m_aFieldHelptext = aFieldHelptext; }
228 
229  virtual void ReleaseDoc(SwDoc* const) = 0;
230 
231  void SetMarkStartPos( const SwPosition& rNewStartPos );
232  void SetMarkEndPos( const SwPosition& rNewEndPos );
233 
234  virtual void Invalidate() override;
235  virtual OUString ToString() const override;
236  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
237 
238  private:
239  OUString m_aFieldname;
242  };
243 
245  : public Fieldmark
246  {
247  public:
248  TextFieldmark(const SwPaM& rPaM, const OUString& rName);
249  virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
250  virtual void ReleaseDoc(SwDoc* const pDoc) override;
251  };
252 
253  // Non text fieldmarks have no content between the start and end marks.
255  : public Fieldmark
256  {
257  public:
258  NonTextFieldmark(const SwPaM& rPaM);
259  virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
260  virtual void ReleaseDoc(SwDoc* const pDoc) override;
261  };
262 
265  : virtual public ICheckboxFieldmark
266  , public NonTextFieldmark
267  {
268  public:
269  CheckboxFieldmark(const SwPaM& rPaM);
270  bool IsChecked() const override;
271  void SetChecked(bool checked) override;
272  };
273 
276  : public NonTextFieldmark
277  {
278  public:
279  FieldmarkWithDropDownButton(const SwPaM& rPaM);
280  virtual ~FieldmarkWithDropDownButton() override;
281 
282  virtual void ShowButton(SwEditWin* pEditWin) = 0;
283  virtual void HideButton();
284  virtual void RemoveButton();
285 
286  protected:
288  };
289 
293  {
294  public:
295  DropDownFieldmark(const SwPaM& rPaM);
296  virtual ~DropDownFieldmark() override;
297 
298  virtual void ShowButton(SwEditWin* pEditWin) override;
299  virtual void HideButton() override;
300  virtual void RemoveButton() override;
301 
302  // This method should be called only by the portion so we can now the portion's painting area
303  void SetPortionPaintArea(const SwRect& rPortionPaintArea);
304 
305  void SendLOKMessage(const OString& sAction);
306 
307  private:
310  };
311 
314  : virtual public IDateFieldmark
316  {
317  public:
318  DateFieldmark(const SwPaM& rPaM);
319  virtual ~DateFieldmark() override;
320 
321  virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode, SwPosition const* pSepPos) override;
322  virtual void ReleaseDoc(SwDoc* const pDoc) override;
323 
324  virtual void ShowButton(SwEditWin* pEditWin) override;
325 
326  void SetPortionPaintAreaStart(const SwRect& rPortionPaintArea);
327  void SetPortionPaintAreaEnd(const SwRect& rPortionPaintArea);
328 
329  virtual OUString GetContent() const override;
330  virtual void ReplaceContent(const OUString& sNewContent) override;
331 
332  virtual std::pair<bool, double> GetCurrentDate() const override;
333  virtual void SetCurrentDate(double fDate) override;
334  virtual OUString GetDateInStandardDateFormat(double fDate) const override;
335 
336  private:
337  OUString GetDateInCurrentDateFormat(double fDate) const;
338  std::pair<bool, double> ParseCurrentDateParam() const;
340 
345  };
346 
348  SwPosition FindFieldSep(IFieldmark const& rMark);
349 
351  bool IsFieldmarkOverlap(SwPaM const& rPaM);
352  }
353 }
354 #endif
355 
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
Definition: bookmrk.cxx:498
OUString m_aName
Definition: bookmrk.hxx:122
static OUString GenerateNewName(const OUString &rPrefix)
Definition: bookmrk.cxx:318
virtual void Hide(bool rHide) override
Definition: bookmrk.cxx:438
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:895
bool is() const
Fieldmark representing a date form field.
Definition: bookmrk.hxx:313
DateFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:777
virtual void ShowButton(SwEditWin *pEditWin)=0
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: bookmrk.cxx:343
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
vcl::KeyCode m_aCode
Definition: bookmrk.hxx:200
Marks a position in the document model.
Definition: pam.hxx:35
OUString m_aFieldHelptext
Definition: bookmrk.hxx:240
virtual OUString GetFieldHelptext() const override
Definition: bookmrk.hxx:215
bool IsChecked() const override
Definition: bookmrk.cxx:635
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:677
virtual bool IsInUndo() const override
Definition: bookmrk.cxx:470
virtual void ReplaceContent(const OUString &sNewContent) override
Definition: bookmrk.cxx:870
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:606
OUString m_sHideCondition
Definition: bookmrk.hxx:203
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:531
Definition: doc.hxx:184
virtual SwPosition & GetMarkStart() const override
Definition: bookmrk.hxx:65
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:788
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
Definition: bookmrk.hxx:342
virtual auto InvalidateFrames() -> void override
Definition: bookmrk.cxx:429
OUString m_aFieldname
Definition: bookmrk.hxx:239
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
Fieldmark representing a checkbox form field.
Definition: bookmrk.hxx:264
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:571
UnoMark(const SwPaM &rPaM)
Definition: bookmrk.cxx:360
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Definition: bookmrk.cxx:456
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:803
Dialog to specify the properties of date form field.
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:836
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
Definition: bookmrk.cxx:275
virtual ~DdeBookmark() override
Definition: bookmrk.cxx:379
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:549
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:275
std::unique_ptr< SwPosition > m_pPos1
Definition: bookmrk.hxx:120
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:83
virtual SwPosition & GetMarkEnd() const override
Definition: bookmrk.hxx:73
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:58
std::unique_ptr< SwPosition > m_pPos2
Definition: bookmrk.hxx:121
virtual ~DropDownFieldmark() override
Definition: bookmrk.cxx:672
std::pair< bool, double > ParseCurrentDateParam() const
Definition: bookmrk.cxx:975
Mode eMode
OUString GetDateInCurrentDateFormat(double fDate) const
Definition: bookmrk.cxx:1011
void InvalidateCurrentDateParam()
Definition: bookmrk.cxx:1052
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
Definition: bookmrk.cxx:392
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:815
void SetRefObject(SwServerObject *pObj)
Definition: bookmrk.cxx:368
exports com.sun.star. text
virtual void SetFieldname(const OUString &aFieldname) override
Definition: bookmrk.hxx:224
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:185
void SetName(const OUString &rName)
Definition: bookmrk.hxx:86
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
Definition: bookmrk.hxx:125
void SetMarkEndPos(const SwPosition &rNewEndPos)
Definition: bookmrk.cxx:506
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 ReleaseDoc(SwDoc *const)=0
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:299
virtual void InitDoc(SwDoc *const io_Doc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:403
virtual void SetShortName(const OUString &rShortName) override
Definition: bookmrk.hxx:181
virtual auto InvalidateFrames() -> void
Definition: bookmrk.cxx:352
virtual ~MarkBase() override
Definition: bookmrk.cxx:315
virtual const vcl::KeyCode & GetKeyCode() const override
Definition: bookmrk.hxx:179
virtual const OUString & GetHideCondition() const override
Definition: bookmrk.hxx:187
SvNumberFormatter * m_pNumberFormatter
Definition: bookmrk.hxx:341
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
Definition: bookmrk.hxx:183
virtual void HideButton() override
Definition: bookmrk.cxx:689
DdeBookmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:364
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: bookmrk.cxx:482
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:827
DropDownFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:667
void SendLOKMessage(const OString &sAction)
Definition: bookmrk.cxx:712
CheckboxFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:619
virtual OUString ToString() const override
Definition: bookmrk.cxx:514
virtual void DeregisterFromDoc(SwDoc *const io_pDoc) override
Definition: bookmrk.cxx:415
virtual void InitDoc(SwDoc *const, sw::mark::InsertMode, SwPosition const *)
Definition: bookmrk.hxx:104
NavigatorReminder(const SwPaM &rPaM)
Definition: bookmrk.cxx:356
NonTextFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:582
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:556
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:60
FieldmarkWithDropDownButton(const SwPaM &rPaM)
Definition: bookmrk.cxx:644
MarkBase(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:258
virtual const OUString & GetShortName() const override
Definition: bookmrk.hxx:177
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
Definition: bookmrk.hxx:112
virtual bool IsInContent() const override
Definition: bookmrk.cxx:475
virtual bool IsInClipboard() const override
Definition: bookmrk.cxx:463
virtual const IFieldmark::parameter_map_t * GetParameters() const override
Definition: bookmrk.hxx:221
virtual void RemoveButton() override
Definition: bookmrk.cxx:695
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode, SwPosition const *pSepPos) override
Definition: bookmrk.cxx:586
OUString m_sShortName
Definition: bookmrk.hxx:201
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:56
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
Definition: bookmrk.hxx:226
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:280
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:701
IFieldmark::parameter_map_t m_vParams
Definition: bookmrk.hxx:241
virtual ~DateFieldmark() override
Definition: bookmrk.cxx:784
virtual void SetCurrentDate(double fDate) override
Definition: bookmrk.cxx:941
virtual OUString GetContent() const override
Definition: bookmrk.cxx:856
Fieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:491
virtual void SetHideCondition(const OUString &rHideCondition) override
Definition: bookmrk.cxx:447
virtual void DeregisterFromDoc(SwDoc *const pDoc)
Definition: bookmrk.cxx:373
tools::SvRef< SwServerObject > m_aRefObj
Definition: bookmrk.hxx:159
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
Definition: bookmrk.hxx:110
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:650
virtual void ClearOtherMarkPos()
Definition: bookmrk.hxx:90
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:291
SwServerObject * GetRefObject()
Definition: bookmrk.hxx:149
const SwServerObject * GetRefObject() const
Definition: bookmrk.hxx:148
virtual void Invalidate() override
Definition: bookmrk.cxx:523
virtual OUString GetFieldname() const override
Definition: bookmrk.hxx:213
VclPtr< FormFieldButton > m_pButton
Definition: bookmrk.hxx:287
virtual IFieldmark::parameter_map_t * GetParameters() override
Definition: bookmrk.hxx:218
bool IsServer() const
Definition: bookmrk.hxx:151
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo
virtual OUString GetDateInStandardDateFormat(double fDate) const override
Definition: bookmrk.cxx:951