LibreOffice Module sc (master)  1
postit.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_SC_INC_POSTIT_HXX
21 #define INCLUDED_SC_INC_POSTIT_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include "address.hxx"
25 #include "scdllapi.h"
26 
27 #include <memory>
28 
29 class EditTextObject;
30 class OutlinerParaObject;
31 class SdrCaptionObj;
32 class SdrPage;
33 
34 class SfxItemSet;
35 class ScDocument;
36 namespace tools { class Rectangle; }
37 struct ScCaptionInitData;
38 
43 {
44 public:
45  ScCaptionPtr();
46  explicit ScCaptionPtr( SdrCaptionObj* p );
47  ScCaptionPtr( const ScCaptionPtr& r );
48  ScCaptionPtr(ScCaptionPtr&& r) noexcept;
49  ~ScCaptionPtr();
50 
51  ScCaptionPtr& operator=( const ScCaptionPtr& r );
52  ScCaptionPtr& operator=(ScCaptionPtr&& r) noexcept;
53  explicit operator bool() const { return mpCaption != nullptr; }
54  const SdrCaptionObj* get() const { return mpCaption; }
55  SdrCaptionObj* get() { return mpCaption; }
56  const SdrCaptionObj* operator->() const { return mpCaption; }
58  const SdrCaptionObj& operator*() const { return *mpCaption; }
60 
61  // Does not default to nullptr to make it visually obvious where such is used.
62  void reset( SdrCaptionObj* p );
63 
66  void insertToDrawPage( SdrPage& rDrawPage );
67 
71  void removeFromDrawPage( SdrPage& rDrawPage );
72 
75  void removeFromDrawPageAndFree( bool bIgnoreUndo = false );
76 
82 
87  void forget();
88 
90  void setNotOwner();
91 
92  oslInterlockedCount getRefs() const;
93 
94 private:
95 
96  struct Head
97  {
99  oslInterlockedCount mnRefs;
100 
101  Head() = delete;
102  explicit Head( ScCaptionPtr* );
103  };
104 
106  mutable ScCaptionPtr* mpNext;
108  bool mbNotOwner;
109  /* TODO: can that be moved to Head?
110  * It's unclear when to reset, so
111  * each instance has its own flag.
112  * The last reference count
113  * decrement automatically has the
114  * then current state available.
115  * */
116 
117  void newHead(); //< Allocate a new Head and init.
118  void incRef() const;
119  bool decRef() const; //< @returns <TRUE/> if the last reference was decremented.
120  void decRefAndDestroy(); //< Destroys caption object if the last reference was decremented.
121 
128  void removeFromList();
129 
134  void replaceInList(ScCaptionPtr* pNew) noexcept;
135 
137  void dissolve();
138 
140  void clear();
141 };
142 
145 {
146  typedef std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef;
147 
148  OUString maDate;
149  OUString maAuthor;
150  ScCaptionInitDataRef mxInitData;
152  bool mbShown;
153 
154  explicit ScNoteData( bool bShown = false );
155 };
156 
161 {
162 public:
163  static sal_uInt32 mnLastPostItId;
164 
167  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 );
168 
170  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 );
171 
182  explicit ScPostIt(
183  ScDocument& rDoc, const ScAddress& rPos,
184  const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
185 
187  ~ScPostIt();
188 
197  std::unique_ptr<ScPostIt> Clone(
198  const ScAddress& rOwnPos,
199  ScDocument& rDestDoc, const ScAddress& rDestPos,
200  bool bCloneCaption ) const;
201 
203  sal_uInt32 GetId() const { return mnPostItId; }
204 
206  const ScNoteData& GetNoteData() const { return maNoteData;}
207 
209  const OUString& GetDate() const { return maNoteData.maDate;}
211  void SetDate( const OUString& rDate );
212 
214  const OUString& GetAuthor() const { return maNoteData.maAuthor;}
216  void SetAuthor( const OUString& rAuthor );
217 
219  void AutoStamp();
220 
222  const OutlinerParaObject* GetOutlinerObject() const;
224  const EditTextObject* GetEditTextObject() const;
225 
227  OUString GetText() const;
229  bool HasMultiLineText() const;
231  void SetText( const ScAddress& rPos, const OUString& rText );
232 
237  SdrCaptionObj* GetCaption() const { return maNoteData.mxCaption.get();}
242  SdrCaptionObj* GetOrCreateCaption( const ScAddress& rPos ) const;
243 
250  void ForgetCaption( bool bPreserveData = false );
251 
253  void ShowCaption( const ScAddress& rPos, bool bShow );
255  bool IsCaptionShown() const { return maNoteData.mbShown;}
256 
258  void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true );
259 
261  void UpdateCaptionPos( const ScAddress& rPos );
262 
263 private:
264  ScPostIt( const ScPostIt& ) = delete;
265  ScPostIt& operator=( const ScPostIt& ) = delete;
266 
268  void CreateCaptionFromInitData( const ScAddress& rPos ) const;
270  void CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption = nullptr );
272  void RemoveCaption();
273 
274 private:
277  sal_uInt32 mnPostItId;
278 };
279 
281 {
282 public:
283 
285  static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
286  SdrPage& rDrawPage, const OUString& rUserText,
287  const tools::Rectangle& rVisRect, bool bTailFront );
288 
305  static ScPostIt* CreateNoteFromCaption(
306  ScDocument& rDoc, const ScAddress& rPos,
307  SdrCaptionObj* pCaption );
308 
334  static ScPostIt* CreateNoteFromObjectData(
335  ScDocument& rDoc, const ScAddress& rPos,
336  std::unique_ptr<SfxItemSet> pItemSet, OutlinerParaObject* pOutlinerObj,
337  const tools::Rectangle& rCaptionRect, bool bShown );
338 
355  static ScPostIt* CreateNoteFromString(
356  ScDocument& rDoc, const ScAddress& rPos,
357  const OUString& rNoteText, bool bShown,
358  bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
359 
360 };
361 
362 namespace sc {
363 
364 struct NoteEntry
365 {
367  const ScPostIt* mpNote;
368 
369  NoteEntry( const ScAddress& rPos, const ScPostIt* pNote );
370 };
371 
372 }
373 
374 #endif
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCaptionInitDataRef mxInitData
Author of the note.
Definition: postit.hxx:150
void decRefAndDestroy()
Definition: postit.cxx:698
SdrCaptionObj & operator*()
Definition: postit.hxx:59
bool mbNotOwner
whether this caption object is owned by something else, e.g. held in Undo
Definition: postit.hxx:108
oslInterlockedCount mnRefs
use count
Definition: postit.hxx:99
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:214
ScCaptionPtr * mpNext
next in list
Definition: postit.hxx:106
void removeFromDrawPage(SdrPage &rDrawPage)
Remove from draw page.
Definition: postit.cxx:744
void forget()
Forget the SdrCaptionObj pointer in this one instance.
Definition: postit.cxx:788
SdrCaptionObj * operator->()
Definition: postit.hxx:57
ScAddress maPos
Definition: postit.hxx:366
Additional class containing cell annotation data.
Definition: postit.hxx:160
void insertToDrawPage(SdrPage &rDrawPage)
Insert to draw page.
Definition: postit.cxx:737
void setNotOwner()
Flag that this instance is in Undo, so drawing layer owns it.
Definition: postit.cxx:547
ScNoteData maNoteData
Parent document containing the note.
Definition: postit.hxx:276
NoteEntry(const ScAddress &rPos, const ScPostIt *pNote)
Definition: postit.cxx:1299
std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef
Definition: postit.hxx:146
bool mbShown
Drawing object representing the cell note.
Definition: postit.hxx:152
void replaceInList(ScCaptionPtr *pNew) noexcept
Replace this instance with pNew in a list, if any.
Definition: postit.cxx:563
SdrCaptionObj * mpCaption
the caption object, managed by head master
Definition: postit.hxx:107
const SdrCaptionObj * operator->() const
Definition: postit.hxx:56
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
static sal_uInt32 mnLastPostItId
Definition: postit.hxx:163
ScCaptionPtr * mpFirst
first in list
Definition: postit.hxx:98
Head * mpHead
points to the "master" entry
Definition: postit.hxx:105
void removeFromList()
Remove from current list and close gap.
Definition: postit.cxx:589
void clear()
Just clear everything, while dissolving the list.
Definition: postit.cxx:812
OUString maAuthor
Creation date of the note.
Definition: postit.hxx:149
const ScPostIt * mpNote
Definition: postit.hxx:367
void incRef() const
Definition: postit.cxx:687
SdrCaptionObj * GetCaption() const
Returns an existing note caption object.
Definition: postit.hxx:237
ScCaptionPtr mxCaption
Initial data for invisible notes without SdrObject.
Definition: postit.hxx:151
const ScNoteData & GetNoteData() const
Returns the data struct containing all note settings.
Definition: postit.hxx:206
Some desperate attempt to fight against the caption object ownership mess, to which none of shared/we...
Definition: postit.hxx:42
Internal data for a cell annotation.
Definition: postit.hxx:144
sal_uInt32 mnPostItId
Note data with pointer to caption object.
Definition: postit.hxx:277
bool decRef() const
Definition: postit.cxx:693
oslInterlockedCount getRefs() const
Definition: postit.cxx:682
sal_uInt32 GetId() const
Returns the note id.
Definition: postit.hxx:203
OUString maDate
Definition: postit.hxx:148
SdrCaptionObj * release()
Release all management of the SdrCaptionObj* in all instances of this list and dissolve.
Definition: postit.cxx:781
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:209
void * p
const SdrCaptionObj & operator*() const
Definition: postit.hxx:58
ScCaptionPtr & operator=(const ScCaptionPtr &r)
Definition: postit.cxx:509
void removeFromDrawPageAndFree(bool bIgnoreUndo=false)
Remove from draw page and free caption object if no Undo recording.
Definition: postit.cxx:751
void dissolve()
Dissolve list when the caption object is released or gone.
Definition: postit.cxx:796
void newHead()
Definition: postit.cxx:557
ScDocument & mrDoc
Definition: postit.hxx:275
void reset(SdrCaptionObj *p)
Definition: postit.cxx:651
#define SC_DLLPUBLIC
Definition: scdllapi.h:28
ScNoteData(bool bShown=false)
True = note is visible.
Definition: postit.cxx:837
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:255