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 OUString ToString( ) const override;
94  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
95 
96  void Swap()
97  {
98  if(m_pPos2)
99  m_pPos1.swap(m_pPos2);
100  }
101 
102  virtual void InitDoc(SwDoc* const, sw::mark::InsertMode)
103  {
104  }
105 
106  virtual ~MarkBase() override;
107 
108  const css::uno::WeakReference< css::text::XTextContent> & GetXBookmark() const
109  { return m_wXBookmark; }
110  void SetXBookmark(css::uno::Reference< css::text::XTextContent> const& xBkmk)
111  { m_wXBookmark = xBkmk; }
112 
113  protected:
114  // SwClient
115  virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) override;
116 
117  MarkBase(const SwPaM& rPaM, const OUString& rName);
118  std::unique_ptr<SwPosition> m_pPos1;
119  std::unique_ptr<SwPosition> m_pPos2;
120  OUString m_aName;
121  static OUString GenerateNewName(const OUString& rPrefix);
122 
123  css::uno::WeakReference< css::text::XTextContent> m_wXBookmark;
124  };
125 
127  : public MarkBase
128  {
129  public:
130  NavigatorReminder(const SwPaM& rPaM);
131  };
132 
133  class UnoMark
134  : public MarkBase
135  {
136  public:
137  UnoMark(const SwPaM& rPaM);
138  };
139 
141  : public MarkBase
142  {
143  public:
144  DdeBookmark(const SwPaM& rPaM);
145 
146  const SwServerObject* GetRefObject() const { return m_aRefObj.get(); }
148 
149  bool IsServer() const { return m_aRefObj.is(); }
150 
151  void SetRefObject( SwServerObject* pObj );
152 
153  virtual void DeregisterFromDoc(SwDoc* const pDoc);
154  virtual ~DdeBookmark() override;
155 
156  private:
158  };
159 
160  class Bookmark
161  : virtual public IBookmark
162  , public DdeBookmark
163  , public ::sfx2::Metadatable
164  {
165  public:
166  Bookmark(const SwPaM& rPaM,
167  const vcl::KeyCode& rCode,
168  const OUString& rName);
169  virtual void InitDoc(SwDoc* const io_Doc, sw::mark::InsertMode eMode) override;
170 
171  virtual void DeregisterFromDoc(SwDoc* const io_pDoc) override;
172 
173  virtual const OUString& GetShortName() const override
174  { return m_sShortName; }
175  virtual const vcl::KeyCode& GetKeyCode() const override
176  { return m_aCode; }
177  virtual void SetShortName(const OUString& rShortName) override
178  { m_sShortName = rShortName; }
179  virtual void SetKeyCode(const vcl::KeyCode& rCode) override
180  { m_aCode = rCode; }
181  virtual bool IsHidden() const override
182  { return m_bHidden; }
183  virtual const OUString& GetHideCondition() const override
184  { return m_sHideCondition; }
185  virtual void Hide(bool rHide) override
186  { m_bHidden = rHide; }
187  virtual void SetHideCondition(const OUString& rHideCondition) override
188  { m_sHideCondition = rHideCondition; }
189 
190  // ::sfx2::Metadatable
191  virtual ::sfx2::IXmlIdRegistry& GetRegistry() override;
192  virtual bool IsInClipboard() const override;
193  virtual bool IsInUndo() const override;
194  virtual bool IsInContent() const override;
195  virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override;
196 
197  private:
199  OUString m_sShortName;
200  bool m_bHidden;
202  };
203 
204  class Fieldmark
205  : virtual public IFieldmark
206  , public MarkBase
207  {
208  public:
209  Fieldmark(const SwPaM& rPaM);
210 
211  virtual OUString GetFieldname() const override
212  { return m_aFieldname; }
213  virtual OUString GetFieldHelptext() const override
214  { return m_aFieldHelptext; }
215 
217  { return &m_vParams; }
218 
219  virtual const IFieldmark::parameter_map_t* GetParameters() const override
220  { return &m_vParams; }
221 
222  virtual void SetFieldname(const OUString& aFieldname) override
223  { m_aFieldname = aFieldname; }
224  virtual void SetFieldHelptext(const OUString& aFieldHelptext) override
225  { m_aFieldHelptext = aFieldHelptext; }
226 
227  virtual void ReleaseDoc(SwDoc* const) = 0;
228 
229  void SetMarkStartPos( const SwPosition& rNewStartPos );
230  void SetMarkEndPos( const SwPosition& rNewEndPos );
231 
232  virtual void Invalidate() override;
233  virtual OUString ToString() const override;
234  virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override;
235 
236  private:
237  OUString m_aFieldname;
240  };
241 
243  : public Fieldmark
244  {
245  public:
246  TextFieldmark(const SwPaM& rPaM, const OUString& rName);
247  virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override;
248  virtual void ReleaseDoc(SwDoc* const pDoc) override;
249  };
250 
251  // Non text fieldmarks have no content between the start and end marks.
253  : public Fieldmark
254  {
255  public:
256  NonTextFieldmark(const SwPaM& rPaM);
257  virtual void InitDoc(SwDoc* const io_pDoc, sw::mark::InsertMode eMode) override;
258  virtual void ReleaseDoc(SwDoc* const pDoc) override;
259  };
260 
263  : virtual public ICheckboxFieldmark
264  , public NonTextFieldmark
265  {
266  public:
267  CheckboxFieldmark(const SwPaM& rPaM);
268  bool IsChecked() const override;
269  void SetChecked(bool checked) override;
270  };
271 
274  : public NonTextFieldmark
275  {
276  public:
277  FieldmarkWithDropDownButton(const SwPaM& rPaM);
278  virtual ~FieldmarkWithDropDownButton() override;
279 
280  virtual void ShowButton(SwEditWin* pEditWin) = 0;
281  void HideButton();
282  void RemoveButton();
283 
284  protected:
286  };
287 
291  {
292  public:
293  DropDownFieldmark(const SwPaM& rPaM);
294  virtual ~DropDownFieldmark() override;
295 
296  virtual void ShowButton(SwEditWin* pEditWin) override;
297 
298  // This method should be called only by the portion so we can now the portion's painting area
299  void SetPortionPaintArea(const SwRect& rPortionPaintArea);
300 
301  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* const io_pDoc, sw::mark::InsertMode eMode) override;
315  virtual void ReleaseDoc(SwDoc* const pDoc) 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  }
340 }
341 #endif
342 
343 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void SetMarkStartPos(const SwPosition &rNewStartPos)
Definition: bookmrk.cxx:360
OUString m_aName
Definition: bookmrk.hxx:120
static OUString GenerateNewName(const OUString &rPrefix)
Definition: bookmrk.cxx:213
virtual std::pair< bool, double > GetCurrentDate() const override
Definition: bookmrk.cxx:655
bool is() const
Fieldmark representing a date form field.
Definition: bookmrk.hxx:306
DateFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:547
virtual void ShowButton(SwEditWin *pEditWin)=0
virtual void Modify(const SfxPoolItem *pOld, const SfxPoolItem *pNew) override
Definition: bookmrk.cxx:239
std::map< OUString, css::uno::Any > parameter_map_t
Definition: IMark.hxx:94
vcl::KeyCode m_aCode
Definition: bookmrk.hxx:198
Marks a position in the document model.
Definition: pam.hxx:35
OUString m_aFieldHelptext
Definition: bookmrk.hxx:238
virtual void SetHideCondition(const OUString &rHideCondition) override
Definition: bookmrk.hxx:187
virtual OUString GetFieldHelptext() const override
Definition: bookmrk.hxx:213
bool IsChecked() const override
Definition: bookmrk.cxx:480
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:521
virtual bool IsInUndo() const override
Definition: bookmrk.cxx:332
virtual void ReplaceContent(const OUString &sNewContent) override
Definition: bookmrk.cxx:631
virtual void Hide(bool rHide) override
Definition: bookmrk.hxx:185
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:457
OUString m_sHideCondition
Definition: bookmrk.hxx:201
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: bookmrk.cxx:393
Definition: doc.hxx:185
virtual SwPosition & GetMarkStart() const override
Definition: bookmrk.hxx:65
sw::DocumentContentOperationsManager * m_pDocumentContentOperationsManager
Definition: bookmrk.hxx:335
OUString m_aFieldname
Definition: bookmrk.hxx:237
void SetChecked(bool checked) override
Definition: bookmrk.cxx:468
virtual OUString ToString() const override
Definition: bookmrk.cxx:187
Fieldmark representing a checkbox form field.
Definition: bookmrk.hxx:262
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:430
UnoMark(const SwPaM &rPaM)
Definition: bookmrk.cxx:253
virtual ::sfx2::IXmlIdRegistry & GetRegistry() override
Definition: bookmrk.cxx:318
virtual void ReleaseDoc(SwDoc *const pDoc) override
Definition: bookmrk.cxx:572
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:38
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
void SetPortionPaintAreaEnd(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:598
virtual bool IsCoveringPosition(const SwPosition &rPos) const override
Definition: bookmrk.cxx:170
virtual ~DdeBookmark() override
Definition: bookmrk.cxx:272
TextFieldmark(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:411
Fieldmark with a drop down button (e.g. this button opens the date picker for a date field) ...
Definition: bookmrk.hxx:273
std::unique_ptr< SwPosition > m_pPos1
Definition: bookmrk.hxx:118
virtual bool IsExpanded() const override
Definition: bookmrk.hxx:83
virtual SwPosition & GetMarkEnd() const override
Definition: bookmrk.hxx:73
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode) override
Definition: bookmrk.cxx:418
virtual const OUString & GetName() const override
Definition: bookmrk.hxx:58
std::unique_ptr< SwPosition > m_pPos2
Definition: bookmrk.hxx:119
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode) override
Definition: bookmrk.cxx:439
virtual ~DropDownFieldmark() override
Definition: bookmrk.cxx:517
std::pair< bool, double > ParseCurrentDateParam() const
Definition: bookmrk.cxx:735
OUString GetDateInCurrentDateFormat(double fDate) const
Definition: bookmrk.cxx:771
void InvalidateCurrentDateParam()
Definition: bookmrk.cxx:812
Bookmark(const SwPaM &rPaM, const vcl::KeyCode &rCode, const OUString &rName)
Definition: bookmrk.cxx:285
virtual void ShowButton(SwEditWin *pEditWin) override
Definition: bookmrk.cxx:577
void SetRefObject(SwServerObject *pObj)
Definition: bookmrk.cxx:261
virtual void SetFieldname(const OUString &aFieldname) override
Definition: bookmrk.hxx:222
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:181
void SetName(const OUString &rName)
Definition: bookmrk.hxx:86
css::uno::WeakReference< css::text::XTextContent > m_wXBookmark
Definition: bookmrk.hxx:123
void SetMarkEndPos(const SwPosition &rNewEndPos)
Definition: bookmrk.cxx:368
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:194
virtual void InitDoc(SwDoc *const, sw::mark::InsertMode)
Definition: bookmrk.hxx:102
virtual void SetShortName(const OUString &rShortName) override
Definition: bookmrk.hxx:177
virtual ~MarkBase() override
Definition: bookmrk.cxx:210
virtual const vcl::KeyCode & GetKeyCode() const override
Definition: bookmrk.hxx:175
virtual const OUString & GetHideCondition() const override
Definition: bookmrk.hxx:183
SvNumberFormatter * m_pNumberFormatter
Definition: bookmrk.hxx:334
virtual void SetKeyCode(const vcl::KeyCode &rCode) override
Definition: bookmrk.hxx:179
DdeBookmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:257
virtual css::uno::Reference< css::rdf::XMetadatable > MakeUnoObject() override
Definition: bookmrk.cxx:344
void SetPortionPaintAreaStart(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:589
DropDownFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:512
virtual void InitDoc(SwDoc *const io_pDoc, sw::mark::InsertMode eMode) override
Definition: bookmrk.cxx:558
CheckboxFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:464
virtual OUString ToString() const override
Definition: bookmrk.cxx:376
virtual void DeregisterFromDoc(SwDoc *const io_pDoc) override
Definition: bookmrk.cxx:306
NavigatorReminder(const SwPaM &rPaM)
Definition: bookmrk.cxx:249
NonTextFieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:435
virtual SwPosition & GetOtherMarkPos() const override
Definition: bookmrk.hxx:60
FieldmarkWithDropDownButton(const SwPaM &rPaM)
Definition: bookmrk.cxx:489
MarkBase(const SwPaM &rPaM, const OUString &rName)
Definition: bookmrk.cxx:153
virtual const OUString & GetShortName() const override
Definition: bookmrk.hxx:173
void SetXBookmark(css::uno::Reference< css::text::XTextContent > const &xBkmk)
Definition: bookmrk.hxx:110
virtual bool IsInContent() const override
Definition: bookmrk.cxx:337
virtual bool IsInClipboard() const override
Definition: bookmrk.cxx:325
virtual const IFieldmark::parameter_map_t * GetParameters() const override
Definition: bookmrk.hxx:219
OUString m_sShortName
Definition: bookmrk.hxx:199
virtual SwPosition & GetMarkPos() const override
Definition: bookmrk.hxx:56
virtual void SetFieldHelptext(const OUString &aFieldHelptext) override
Definition: bookmrk.hxx:224
virtual void SetMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:175
void SetPortionPaintArea(const SwRect &rPortionPaintArea)
Definition: bookmrk.cxx:532
IFieldmark::parameter_map_t m_vParams
Definition: bookmrk.hxx:239
virtual ~DateFieldmark() override
Definition: bookmrk.cxx:554
virtual void SetCurrentDate(double fDate) override
Definition: bookmrk.cxx:701
virtual OUString GetContent() const override
Definition: bookmrk.cxx:618
Fieldmark(const SwPaM &rPaM)
Definition: bookmrk.cxx:353
def text(shape, st)
virtual void InitDoc(SwDoc *const io_Doc, sw::mark::InsertMode eMode) override
Definition: bookmrk.cxx:296
virtual void DeregisterFromDoc(SwDoc *const pDoc)
Definition: bookmrk.cxx:266
tools::SvRef< SwServerObject > m_aRefObj
Definition: bookmrk.hxx:157
const css::uno::WeakReference< css::text::XTextContent > & GetXBookmark() const
Definition: bookmrk.hxx:108
InsertMode
Definition: IMark.hxx:31
virtual void SetOtherMarkPos(const SwPosition &rNewPos)
Definition: bookmrk.cxx:181
virtual ~FieldmarkWithDropDownButton() override
Definition: bookmrk.cxx:495
virtual void ClearOtherMarkPos()
Definition: bookmrk.hxx:90
Fieldmark representing a drop-down form field.
Definition: bookmrk.hxx:289
SwServerObject * GetRefObject()
Definition: bookmrk.hxx:147
const SwServerObject * GetRefObject() const
Definition: bookmrk.hxx:146
virtual void Invalidate() override
Definition: bookmrk.cxx:385
virtual OUString GetFieldname() const override
Definition: bookmrk.hxx:211
VclPtr< FormFieldButton > m_pButton
Definition: bookmrk.hxx:285
virtual IFieldmark::parameter_map_t * GetParameters() override
Definition: bookmrk.hxx:216
bool IsServer() const
Definition: bookmrk.hxx:149
virtual OUString GetDateInStandardDateFormat(double fDate) const override
Definition: bookmrk.cxx:711