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 <string_view>
29
30class EditTextObject;
32class SdrCaptionObj;
33class SdrPage;
34
35class ScDocument;
36namespace tools { class Rectangle; }
38
43{
44public:
46 explicit ScCaptionPtr( SdrCaptionObj* p );
47 ScCaptionPtr( const ScCaptionPtr& r );
48 ScCaptionPtr(ScCaptionPtr&& r) noexcept;
50
52 ScCaptionPtr& operator=(ScCaptionPtr&& r) noexcept;
53 explicit operator bool() const { return mpCaption != nullptr; }
54 const SdrCaptionObj* get() const { 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
94private:
95
96 struct Head
97 {
99 oslInterlockedCount mnRefs;
100
101 Head() = delete;
102 explicit Head( ScCaptionPtr* );
103 };
104
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;
152 bool mbShown;
153
154 explicit ScNoteData( bool bShown = false );
155};
156
161{
162public:
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
263private:
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
274private:
277 sal_uInt32 mnPostItId;
278};
279
281{
282public:
283
285 static ScCaptionPtr CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
286 SdrPage& rDrawPage, std::u16string_view rUserText,
287 const tools::Rectangle& rVisRect, bool bTailFront );
288
305 static ScPostIt* CreateNoteFromCaption(
306 ScDocument& rDoc, const ScAddress& rPos,
307 SdrCaptionObj* pCaption );
308
333 static ScPostIt* CreateNoteFromObjectData(
334 ScDocument& rDoc, const ScAddress& rPos,
335 SfxItemSet&& oItemSet,
336 const OutlinerParaObject& rOutlinerObj,
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
362namespace sc {
363
365{
368
369 NoteEntry( const ScAddress& rPos, const ScPostIt* pNote );
370};
371
372}
373
374/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Some desperate attempt to fight against the caption object ownership mess, to which none of shared/we...
Definition: postit.hxx:43
const SdrCaptionObj * get() const
Definition: postit.hxx:54
SdrCaptionObj * mpCaption
the caption object, managed by head master
Definition: postit.hxx:107
SdrCaptionObj & operator*()
Definition: postit.hxx:59
void clear()
Just clear everything, while dissolving the list.
Definition: postit.cxx:814
SdrCaptionObj * release()
Release all management of the SdrCaptionObj* in all instances of this list and dissolve.
Definition: postit.cxx:783
void incRef() const
Definition: postit.cxx:689
void removeFromList()
Remove from current list and close gap.
Definition: postit.cxx:591
void reset(SdrCaptionObj *p)
Definition: postit.cxx:653
void insertToDrawPage(SdrPage &rDrawPage)
Insert to draw page.
Definition: postit.cxx:739
const SdrCaptionObj * operator->() const
Definition: postit.hxx:56
void forget()
Forget the SdrCaptionObj pointer in this one instance.
Definition: postit.cxx:790
ScCaptionPtr & operator=(const ScCaptionPtr &r)
Definition: postit.cxx:511
SdrCaptionObj * get()
Definition: postit.hxx:55
bool decRef() const
Definition: postit.cxx:695
void replaceInList(ScCaptionPtr *pNew) noexcept
Replace this instance with pNew in a list, if any.
Definition: postit.cxx:565
void decRefAndDestroy()
Definition: postit.cxx:700
const SdrCaptionObj & operator*() const
Definition: postit.hxx:58
void newHead()
Definition: postit.cxx:559
void removeFromDrawPageAndFree(bool bIgnoreUndo=false)
Remove from draw page and free caption object if no Undo recording.
Definition: postit.cxx:753
void removeFromDrawPage(SdrPage &rDrawPage)
Remove from draw page.
Definition: postit.cxx:746
ScCaptionPtr * mpNext
next in list
Definition: postit.hxx:106
oslInterlockedCount getRefs() const
Definition: postit.cxx:684
bool mbNotOwner
whether this caption object is owned by something else, e.g. held in Undo
Definition: postit.hxx:108
Head * mpHead
points to the "master" entry
Definition: postit.hxx:105
SdrCaptionObj * operator->()
Definition: postit.hxx:57
void setNotOwner()
Flag that this instance is in Undo, so drawing layer owns it.
Definition: postit.cxx:549
void dissolve()
Dissolve list when the caption object is released or gone.
Definition: postit.cxx:798
Additional class containing cell annotation data.
Definition: postit.hxx:161
const ScNoteData & GetNoteData() const
Returns the data struct containing all note settings.
Definition: postit.hxx:206
sal_uInt32 GetId() const
Returns the note id.
Definition: postit.hxx:203
ScNoteData maNoteData
Parent document containing the note.
Definition: postit.hxx:276
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:209
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:214
ScPostIt(const ScPostIt &)=delete
static sal_uInt32 mnLastPostItId
Definition: postit.hxx:163
sal_uInt32 mnPostItId
Note data with pointer to caption object.
Definition: postit.hxx:277
ScDocument & mrDoc
Definition: postit.hxx:275
ScPostIt & operator=(const ScPostIt &)=delete
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:255
SdrCaptionObj * GetCaption() const
Returns an existing note caption object.
Definition: postit.hxx:237
virtual void SetText(const OUString &rStr) override
void * p
CAUTION! The following defines must be in the same namespace as the respective type.
css::uno::Reference< css::animations::XAnimationNode > Clone(const css::uno::Reference< css::animations::XAnimationNode > &xSourceNode, const SdPage *pSource=nullptr, const SdPage *pTarget=nullptr)
#define SC_DLLPUBLIC
Definition: scdllapi.h:27
oslInterlockedCount mnRefs
use count
Definition: postit.hxx:99
ScCaptionPtr * mpFirst
first in list
Definition: postit.hxx:98
Internal data for a cell annotation.
Definition: postit.hxx:145
ScCaptionPtr mxCaption
Initial data for invisible notes without SdrObject.
Definition: postit.hxx:151
ScCaptionInitDataRef mxInitData
Author of the note.
Definition: postit.hxx:150
OUString maDate
Definition: postit.hxx:148
OUString maAuthor
Creation date of the note.
Definition: postit.hxx:149
bool mbShown
Drawing object representing the cell note.
Definition: postit.hxx:152
ScNoteData(bool bShown=false)
True = note is visible.
Definition: postit.cxx:839
std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef
Definition: postit.hxx:146
ScAddress maPos
Definition: postit.hxx:366
const ScPostIt * mpNote
Definition: postit.hxx:367
NoteEntry(const ScAddress &rPos, const ScPostIt *pNote)
Definition: postit.cxx:1301