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 <svl/itemset.hxx>
24 #include "address.hxx"
25 #include "scdllapi.h"
26 
27 #include <memory>
28 #include <optional>
29 #include <string_view>
30 
31 class EditTextObject;
32 class OutlinerParaObject;
33 class SdrCaptionObj;
34 class SdrPage;
35 
36 class ScDocument;
37 namespace tools { class Rectangle; }
38 struct ScCaptionInitData;
39 
44 {
45 public:
46  ScCaptionPtr();
47  explicit ScCaptionPtr( SdrCaptionObj* p );
48  ScCaptionPtr( const ScCaptionPtr& r );
49  ScCaptionPtr(ScCaptionPtr&& r) noexcept;
50  ~ScCaptionPtr();
51 
52  ScCaptionPtr& operator=( const ScCaptionPtr& r );
53  ScCaptionPtr& operator=(ScCaptionPtr&& r) noexcept;
54  explicit operator bool() const { return mpCaption != nullptr; }
55  const SdrCaptionObj* get() const { return mpCaption; }
56  SdrCaptionObj* get() { return mpCaption; }
57  const SdrCaptionObj* operator->() const { return mpCaption; }
59  const SdrCaptionObj& operator*() const { return *mpCaption; }
61 
62  // Does not default to nullptr to make it visually obvious where such is used.
63  void reset( SdrCaptionObj* p );
64 
67  void insertToDrawPage( SdrPage& rDrawPage );
68 
72  void removeFromDrawPage( SdrPage& rDrawPage );
73 
76  void removeFromDrawPageAndFree( bool bIgnoreUndo = false );
77 
83 
88  void forget();
89 
91  void setNotOwner();
92 
93  oslInterlockedCount getRefs() const;
94 
95 private:
96 
97  struct Head
98  {
100  oslInterlockedCount mnRefs;
101 
102  Head() = delete;
103  explicit Head( ScCaptionPtr* );
104  };
105 
107  mutable ScCaptionPtr* mpNext;
109  bool mbNotOwner;
110  /* TODO: can that be moved to Head?
111  * It's unclear when to reset, so
112  * each instance has its own flag.
113  * The last reference count
114  * decrement automatically has the
115  * then current state available.
116  * */
117 
118  void newHead(); //< Allocate a new Head and init.
119  void incRef() const;
120  bool decRef() const; //< @returns <TRUE/> if the last reference was decremented.
121  void decRefAndDestroy(); //< Destroys caption object if the last reference was decremented.
122 
129  void removeFromList();
130 
135  void replaceInList(ScCaptionPtr* pNew) noexcept;
136 
138  void dissolve();
139 
141  void clear();
142 };
143 
146 {
147  typedef std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef;
148 
149  OUString maDate;
150  OUString maAuthor;
151  ScCaptionInitDataRef mxInitData;
153  bool mbShown;
154 
155  explicit ScNoteData( bool bShown = false );
156 };
157 
162 {
163 public:
164  static sal_uInt32 mnLastPostItId;
165 
168  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 );
169 
171  explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 );
172 
183  explicit ScPostIt(
184  ScDocument& rDoc, const ScAddress& rPos,
185  const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
186 
188  ~ScPostIt();
189 
198  std::unique_ptr<ScPostIt> Clone(
199  const ScAddress& rOwnPos,
200  ScDocument& rDestDoc, const ScAddress& rDestPos,
201  bool bCloneCaption ) const;
202 
204  sal_uInt32 GetId() const { return mnPostItId; }
205 
207  const ScNoteData& GetNoteData() const { return maNoteData;}
208 
210  const OUString& GetDate() const { return maNoteData.maDate;}
212  void SetDate( const OUString& rDate );
213 
215  const OUString& GetAuthor() const { return maNoteData.maAuthor;}
217  void SetAuthor( const OUString& rAuthor );
218 
220  void AutoStamp();
221 
223  const OutlinerParaObject* GetOutlinerObject() const;
225  const EditTextObject* GetEditTextObject() const;
226 
228  OUString GetText() const;
230  bool HasMultiLineText() const;
232  void SetText( const ScAddress& rPos, const OUString& rText );
233 
238  SdrCaptionObj* GetCaption() const { return maNoteData.mxCaption.get();}
243  SdrCaptionObj* GetOrCreateCaption( const ScAddress& rPos ) const;
244 
251  void ForgetCaption( bool bPreserveData = false );
252 
254  void ShowCaption( const ScAddress& rPos, bool bShow );
256  bool IsCaptionShown() const { return maNoteData.mbShown;}
257 
259  void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true );
260 
262  void UpdateCaptionPos( const ScAddress& rPos );
263 
264 private:
265  ScPostIt( const ScPostIt& ) = delete;
266  ScPostIt& operator=( const ScPostIt& ) = delete;
267 
269  void CreateCaptionFromInitData( const ScAddress& rPos ) const;
271  void CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption = nullptr );
273  void RemoveCaption();
274 
275 private:
278  sal_uInt32 mnPostItId;
279 };
280 
282 {
283 public:
284 
286  static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
287  SdrPage& rDrawPage, std::u16string_view rUserText,
288  const tools::Rectangle& rVisRect, bool bTailFront );
289 
306  static ScPostIt* CreateNoteFromCaption(
307  ScDocument& rDoc, const ScAddress& rPos,
308  SdrCaptionObj* pCaption );
309 
334  static ScPostIt* CreateNoteFromObjectData(
335  ScDocument& rDoc, const ScAddress& rPos,
336  SfxItemSet&& oItemSet,
337  const OutlinerParaObject& rOutlinerObj,
338  const tools::Rectangle& rCaptionRect, bool bShown );
339 
356  static ScPostIt* CreateNoteFromString(
357  ScDocument& rDoc, const ScAddress& rPos,
358  const OUString& rNoteText, bool bShown,
359  bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
360 
361 };
362 
363 namespace sc {
364 
365 struct NoteEntry
366 {
368  const ScPostIt* mpNote;
369 
370  NoteEntry( const ScAddress& rPos, const ScPostIt* pNote );
371 };
372 
373 }
374 
375 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ScCaptionInitDataRef mxInitData
Author of the note.
Definition: postit.hxx:151
void decRefAndDestroy()
Definition: postit.cxx:699
SdrCaptionObj & operator*()
Definition: postit.hxx:60
bool mbNotOwner
whether this caption object is owned by something else, e.g. held in Undo
Definition: postit.hxx:109
oslInterlockedCount mnRefs
use count
Definition: postit.hxx:100
virtual void SetText(const OUString &rStr) override
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:215
ScCaptionPtr * mpNext
next in list
Definition: postit.hxx:107
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:58
ScAddress maPos
Definition: postit.hxx:367
Additional class containing cell annotation data.
Definition: postit.hxx:161
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:277
NoteEntry(const ScAddress &rPos, const ScPostIt *pNote)
Definition: postit.cxx:1299
std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef
Definition: postit.hxx:147
bool mbShown
Drawing object representing the cell note.
Definition: postit.hxx:153
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:108
const SdrCaptionObj * operator->() const
Definition: postit.hxx:57
Reference< XAnimationNode > Clone(const Reference< XAnimationNode > &xSourceNode, const SdPage *pSource, const SdPage *pTarget)
static sal_uInt32 mnLastPostItId
Definition: postit.hxx:164
ScCaptionPtr * mpFirst
first in list
Definition: postit.hxx:99
Head * mpHead
points to the "master" entry
Definition: postit.hxx:106
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:150
const ScPostIt * mpNote
Definition: postit.hxx:368
void incRef() const
Definition: postit.cxx:688
SdrCaptionObj * GetCaption() const
Returns an existing note caption object.
Definition: postit.hxx:238
ScCaptionPtr mxCaption
Initial data for invisible notes without SdrObject.
Definition: postit.hxx:152
const ScNoteData & GetNoteData() const
Returns the data struct containing all note settings.
Definition: postit.hxx:207
Some desperate attempt to fight against the caption object ownership mess, to which none of shared/we...
Definition: postit.hxx:43
Internal data for a cell annotation.
Definition: postit.hxx:145
sal_uInt32 mnPostItId
Note data with pointer to caption object.
Definition: postit.hxx:278
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:204
OUString maDate
Definition: postit.hxx:149
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:210
void * p
const SdrCaptionObj & operator*() const
Definition: postit.hxx:59
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:276
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:256