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 #pragma once
21 
22 #include <rtl/ustring.hxx>
23 #include "address.hxx"
24 #include "scdllapi.h"
25 
26 #include <memory>
27 
28 class EditTextObject;
29 class OutlinerParaObject;
30 class SdrCaptionObj;
31 class SdrPage;
32 
33 class SfxItemSet;
34 class ScDocument;
35 namespace tools { class Rectangle; }
36 struct ScCaptionInitData;
37 
42 {
43 public:
44  ScCaptionPtr();
45  explicit ScCaptionPtr( SdrCaptionObj* p );
46  ScCaptionPtr( const ScCaptionPtr& r );
47  ScCaptionPtr(ScCaptionPtr&& r) noexcept;
48  ~ScCaptionPtr();
49 
50  ScCaptionPtr& operator=( const ScCaptionPtr& r );
51  ScCaptionPtr& operator=(ScCaptionPtr&& r) noexcept;
52  explicit operator bool() const { return mpCaption != nullptr; }
53  const SdrCaptionObj* get() const { return mpCaption; }
54  SdrCaptionObj* get() { return mpCaption; }
55  const SdrCaptionObj* operator->() const { return mpCaption; }
57  const SdrCaptionObj& operator*() const { return *mpCaption; }
59 
60  // Does not default to nullptr to make it visually obvious where such is used.
61  void reset( SdrCaptionObj* p );
62 
65  void insertToDrawPage( SdrPage& rDrawPage );
66 
70  void removeFromDrawPage( SdrPage& rDrawPage );
71 
74  void removeFromDrawPageAndFree( bool bIgnoreUndo = false );
75 
81 
86  void forget();
87 
89  void setNotOwner();
90 
91  oslInterlockedCount getRefs() const;
92 
93 private:
94 
95  struct Head
96  {
98  oslInterlockedCount mnRefs;
99 
100  Head() = delete;
101  explicit Head( ScCaptionPtr* );
102  };
103 
105  mutable ScCaptionPtr* mpNext;
107  bool mbNotOwner;
108  /* TODO: can that be moved to Head?
109  * It's unclear when to reset, so
110  * each instance has its own flag.
111  * The last reference count
112  * decrement automatically has the
113  * then current state available.
114  * */
115 
116  void newHead(); //< Allocate a new Head and init.
117  void incRef() const;
118  bool decRef() const; //< @returns <TRUE/> if the last reference was decremented.
119  void decRefAndDestroy(); //< Destroys caption object if the last reference was decremented.
120 
127  void removeFromList();
128 
133  void replaceInList(ScCaptionPtr* pNew) noexcept;
134 
136  void dissolve();
137 
139  void clear();
140 };
141 
144 {
145  typedef std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef;
146 
147  OUString maDate;
148  OUString maAuthor;
149  ScCaptionInitDataRef mxInitData;
151  bool mbShown;
152 
153  explicit ScNoteData( bool bShown = false );
154 };
155 
160 {
161 public:
162  static sal_uInt32 mnLastPostItId;
163 
166  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 );
167 
169  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 );
170 
181  explicit ScPostIt(
182  ScDocument& rDoc, const ScAddress& rPos,
183  const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
184 
186  ~ScPostIt();
187 
196  std::unique_ptr<ScPostIt> Clone(
197  const ScAddress& rOwnPos,
198  ScDocument& rDestDoc, const ScAddress& rDestPos,
199  bool bCloneCaption ) const;
200 
202  sal_uInt32 GetId() const { return mnPostItId; }
203 
205  const ScNoteData& GetNoteData() const { return maNoteData;}
206 
208  const OUString& GetDate() const { return maNoteData.maDate;}
210  void SetDate( const OUString& rDate );
211 
213  const OUString& GetAuthor() const { return maNoteData.maAuthor;}
215  void SetAuthor( const OUString& rAuthor );
216 
218  void AutoStamp();
219 
221  const OutlinerParaObject* GetOutlinerObject() const;
223  const EditTextObject* GetEditTextObject() const;
224 
226  OUString GetText() const;
228  bool HasMultiLineText() const;
230  void SetText( const ScAddress& rPos, const OUString& rText );
231 
236  SdrCaptionObj* GetCaption() const { return maNoteData.mxCaption.get();}
241  SdrCaptionObj* GetOrCreateCaption( const ScAddress& rPos ) const;
242 
249  void ForgetCaption( bool bPreserveData = false );
250 
252  void ShowCaption( const ScAddress& rPos, bool bShow );
254  bool IsCaptionShown() const { return maNoteData.mbShown;}
255 
257  void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true );
258 
260  void UpdateCaptionPos( const ScAddress& rPos );
261 
262 private:
263  ScPostIt( const ScPostIt& ) = delete;
264  ScPostIt& operator=( const ScPostIt& ) = delete;
265 
267  void CreateCaptionFromInitData( const ScAddress& rPos ) const;
269  void CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption = nullptr );
271  void RemoveCaption();
272 
273 private:
276  sal_uInt32 mnPostItId;
277 };
278 
280 {
281 public:
282 
284  static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
285  SdrPage& rDrawPage, const OUString& rUserText,
286  const tools::Rectangle& rVisRect, bool bTailFront );
287 
304  static ScPostIt* CreateNoteFromCaption(
305  ScDocument& rDoc, const ScAddress& rPos,
306  SdrCaptionObj* pCaption );
307 
333  static ScPostIt* CreateNoteFromObjectData(
334  ScDocument& rDoc, const ScAddress& rPos,
335  std::unique_ptr<SfxItemSet> pItemSet, OutlinerParaObject* pOutlinerObj,
336  const tools::Rectangle& rCaptionRect, bool bShown );
337 
354  static ScPostIt* CreateNoteFromString(
355  ScDocument& rDoc, const ScAddress& rPos,
356  const OUString& rNoteText, bool bShown,
357  bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
358 
359 };
360 
361 namespace sc {
362 
363 struct NoteEntry
364 {
366  const ScPostIt* mpNote;
367 
368  NoteEntry( const ScAddress& rPos, const ScPostIt* pNote );
369 };
370 
371 }
372 
373 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCaptionInitDataRef mxInitData
Author of the note.
Definition: postit.hxx:149
void decRefAndDestroy()
Definition: postit.cxx:699
SdrCaptionObj & operator*()
Definition: postit.hxx:58
bool mbNotOwner
whether this caption object is owned by something else, e.g. held in Undo
Definition: postit.hxx:107
oslInterlockedCount mnRefs
use count
Definition: postit.hxx:98
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:213
ScCaptionPtr * mpNext
next in list
Definition: postit.hxx:105
void removeFromDrawPage(SdrPage &rDrawPage)
Remove from draw page.
Definition: postit.cxx:745
void forget()
Forget the SdrCaptionObj pointer in this one instance.
Definition: postit.cxx:789
SdrCaptionObj * operator->()
Definition: postit.hxx:56
ScAddress maPos
Definition: postit.hxx:365
Additional class containing cell annotation data.
Definition: postit.hxx:159
void insertToDrawPage(SdrPage &rDrawPage)
Insert to draw page.
Definition: postit.cxx:738
void setNotOwner()
Flag that this instance is in Undo, so drawing layer owns it.
Definition: postit.cxx:548
ScNoteData maNoteData
Parent document containing the note.
Definition: postit.hxx:275
NoteEntry(const ScAddress &rPos, const ScPostIt *pNote)
Definition: postit.cxx:1300
std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef
Definition: postit.hxx:145
bool mbShown
Drawing object representing the cell note.
Definition: postit.hxx:151
void replaceInList(ScCaptionPtr *pNew) noexcept
Replace this instance with pNew in a list, if any.
Definition: postit.cxx:564
SdrCaptionObj * mpCaption
the caption object, managed by head master
Definition: postit.hxx:106
const SdrCaptionObj * operator->() const
Definition: postit.hxx:55
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
static sal_uInt32 mnLastPostItId
Definition: postit.hxx:162
ScCaptionPtr * mpFirst
first in list
Definition: postit.hxx:97
Head * mpHead
points to the "master" entry
Definition: postit.hxx:104
void removeFromList()
Remove from current list and close gap.
Definition: postit.cxx:590
void clear()
Just clear everything, while dissolving the list.
Definition: postit.cxx:813
OUString maAuthor
Creation date of the note.
Definition: postit.hxx:148
const ScPostIt * mpNote
Definition: postit.hxx:366
void incRef() const
Definition: postit.cxx:688
SdrCaptionObj * GetCaption() const
Returns an existing note caption object.
Definition: postit.hxx:236
ScCaptionPtr mxCaption
Initial data for invisible notes without SdrObject.
Definition: postit.hxx:150
const ScNoteData & GetNoteData() const
Returns the data struct containing all note settings.
Definition: postit.hxx:205
Some desperate attempt to fight against the caption object ownership mess, to which none of shared/we...
Definition: postit.hxx:41
Internal data for a cell annotation.
Definition: postit.hxx:143
sal_uInt32 mnPostItId
Note data with pointer to caption object.
Definition: postit.hxx:276
bool decRef() const
Definition: postit.cxx:694
oslInterlockedCount getRefs() const
Definition: postit.cxx:683
sal_uInt32 GetId() const
Returns the note id.
Definition: postit.hxx:202
OUString maDate
Definition: postit.hxx:147
SdrCaptionObj * release()
Release all management of the SdrCaptionObj* in all instances of this list and dissolve.
Definition: postit.cxx:782
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:208
void * p
const SdrCaptionObj & operator*() const
Definition: postit.hxx:57
ScCaptionPtr & operator=(const ScCaptionPtr &r)
Definition: postit.cxx:510
void removeFromDrawPageAndFree(bool bIgnoreUndo=false)
Remove from draw page and free caption object if no Undo recording.
Definition: postit.cxx:752
void dissolve()
Dissolve list when the caption object is released or gone.
Definition: postit.cxx:797
void newHead()
Definition: postit.cxx:558
ScDocument & mrDoc
Definition: postit.hxx:274
void reset(SdrCaptionObj *p)
Definition: postit.cxx:652
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
ScNoteData(bool bShown=false)
True = note is visible.
Definition: postit.cxx:838
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:254