Version 6.1.0.2, tag libreoffice-6.1.0.2
[LibreOffice.git] / sc / inc / postit.hxx
blobde77e208b8290da3acd307d9884ddab9a97c74cc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_SC_INC_POSTIT_HXX
21 #define INCLUDED_SC_INC_POSTIT_HXX
23 #include <rtl/ustring.hxx>
24 #include "address.hxx"
25 #include "scdllapi.h"
27 #include <memory>
29 class EditTextObject;
30 class OutlinerParaObject;
31 class SdrCaptionObj;
32 class SdrPage;
34 class SfxItemSet;
35 class ScDocument;
36 namespace tools { class Rectangle; }
37 struct ScCaptionInitData;
39 /** Internal data for a cell annotation. */
40 struct SC_DLLPUBLIC ScNoteData
42 typedef std::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef;
44 OUString maDate; /// Creation date of the note.
45 OUString maAuthor; /// Author of the note.
46 ScCaptionInitDataRef mxInitData; /// Initial data for invisible notes without SdrObject.
47 std::shared_ptr< SdrCaptionObj > m_pCaption; /// Drawing object representing the cell note.
48 bool mbShown; /// True = note is visible.
50 explicit ScNoteData( bool bShown = false );
51 ~ScNoteData();
54 /**
55 * Additional class containing cell annotation data.
57 class SC_DLLPUBLIC ScPostIt
59 public:
60 static sal_uInt32 mnLastPostItId;
62 /** Creates an empty note and its caption object and places it according to
63 the passed cell position. */
64 explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId = 0 );
66 /** Copy constructor. Clones the note and its caption to a new document. */
67 explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId = 0 );
69 /** Creates a note from the passed note data with existing caption object.
71 @param bAlwaysCreateCaption Instead of a pointer to an existing
72 caption object, the passed note data structure may contain a
73 reference to an ScCaptionInitData structure containing information
74 about how to construct a missing caption object. If sal_True is passed,
75 the caption drawing object will be created immediately from that
76 data. If sal_False is passed and the note is not visible, it will
77 continue to cache that data until the caption object is requested.
79 explicit ScPostIt(
80 ScDocument& rDoc, const ScAddress& rPos,
81 const ScNoteData& rNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
83 /** Removes the caption object from drawing layer, if this note is its owner. */
84 ~ScPostIt();
86 /** Clones this note and its caption object, if specified.
88 @param bCloneCaption If sal_True is passed, clones the caption object and
89 inserts it into the drawing layer of the destination document. If
90 sal_False is passed, the cloned note will refer to the old caption
91 object (used e.g. in Undo documents to restore the pointer to the
92 existing caption object).
94 ScPostIt* Clone(
95 const ScAddress& rOwnPos,
96 ScDocument& rDestDoc, const ScAddress& rDestPos,
97 bool bCloneCaption ) const;
99 /** Returns the note id. */
100 sal_uInt32 GetId() const { return mnPostItId; }
102 /** Returns the data struct containing all note settings. */
103 const ScNoteData& GetNoteData() const { return maNoteData;}
105 /** Returns the creation date of this note. */
106 const OUString& GetDate() const { return maNoteData.maDate;}
107 /** Sets a new creation date for this note. */
108 void SetDate( const OUString& rDate );
110 /** Returns the author date of this note. */
111 const OUString& GetAuthor() const { return maNoteData.maAuthor;}
112 /** Sets a new author date for this note. */
113 void SetAuthor( const OUString& rAuthor );
115 /** Sets date and author from system settings. */
116 void AutoStamp();
118 /** Returns the pointer to the current outliner object, or null. */
119 const OutlinerParaObject* GetOutlinerObject() const;
120 /** Returns the pointer to the current edit text object, or null. */
121 const EditTextObject* GetEditTextObject() const;
123 /** Returns the caption text of this note. */
124 OUString GetText() const;
125 /** Returns true, if the caption text of this note contains line breaks. */
126 bool HasMultiLineText() const;
127 /** Changes the caption text of this note. All text formatting will be lost. */
128 void SetText( const ScAddress& rPos, const OUString& rText );
130 /** Returns an existing note caption object. returns null, if the note
131 contains initial caption data needed to construct a caption object.
132 The SdrCaptionObj* returned is still managed by the underlying
133 ScNoteData::ScCaptionPtr and must not be stored elsewhere. */
134 const std::shared_ptr< SdrCaptionObj>& GetCaption() const { return maNoteData.m_pCaption; }
135 /** Returns the caption object of this note. Creates the caption object, if
136 the note contains initial caption data instead of the caption.
137 The SdrCaptionObj* returned is still managed by the underlying
138 ScNoteData::ScCaptionPtr and must not be stored elsewhere. */
139 const std::shared_ptr< SdrCaptionObj>& GetOrCreateCaption( const ScAddress& rPos ) const;
141 /** Forgets the pointer to the note caption object.
143 @param bPreserveData
144 If true then the note text is remembered in maNoteData to be able
145 to later reconstruct a caption from it.
147 void ForgetCaption( bool bPreserveData = false );
149 /** Shows or hides the note caption object. */
150 void ShowCaption( const ScAddress& rPos, bool bShow );
151 /** Returns true, if the caption object is visible. */
152 bool IsCaptionShown() const { return maNoteData.mbShown;}
154 /** Shows or hides the caption temporarily (does not change internal visibility state). */
155 void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true );
157 /** Updates caption position according to position of the passed cell. */
158 void UpdateCaptionPos( const ScAddress& rPos );
160 private:
161 ScPostIt( const ScPostIt& ) = delete;
162 ScPostIt& operator=( const ScPostIt& ) = delete;
164 /** Creates the caption object from initial caption data if existing. */
165 void CreateCaptionFromInitData( const ScAddress& rPos ) const;
166 /** Creates a new caption object at the passed cell position, clones passed existing caption. */
167 void CreateCaption( const ScAddress& rPos, const std::shared_ptr< SdrCaptionObj >& pCaption );
168 /** Removes the caption object from the drawing layer, if this note is its owner. */
169 void RemoveCaption();
171 private:
172 ScDocument& mrDoc; /// Parent document containing the note.
173 mutable ScNoteData maNoteData; /// Note data with pointer to caption object.
174 sal_uInt32 mnPostItId;
177 class SC_DLLPUBLIC ScNoteUtil
179 public:
181 /** Creates and returns a caption object for a temporary caption. */
182 static std::shared_ptr< SdrCaptionObj > CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
183 SdrPage& rDrawPage, const OUString& rUserText,
184 const tools::Rectangle& rVisRect, bool bTailFront );
186 /** Creates a cell note using the passed caption drawing object.
188 This function is used in import filters to reuse the imported drawing
189 object as note caption object.
191 @param pCaption The drawing object for the cell note. This object MUST
192 be inserted into the document at the correct drawing page already.
193 The underlying ScPostIt::ScNoteData::ScCaptionPtr takes managing
194 ownership of the pointer.
196 @return Pointer to the new cell note object if insertion was
197 successful (i.e. the passed cell position was valid), null
198 otherwise. The Calc document is the owner of the note object. The
199 passed item set and outliner object are deleted automatically if
200 creation of the note was not successful.
202 static ScPostIt* CreateNoteFromCaption(
203 ScDocument& rDoc, const ScAddress& rPos,
204 SdrCaptionObj* pCaption );
206 /** Creates a cell note based on the passed caption object data.
208 This function is used in import filters to use an existing imported
209 item set and outliner object to create a note caption object. For
210 performance reasons, it is possible to specify that the caption drawing
211 object for the cell note is not created yet but the note caches the
212 passed data needed to create the caption object on demand (see
213 parameter bAlwaysCreateCaption).
215 @param pItemSet Pointer to an item set on heap memory containing all
216 formatting attributes of the caption object. This function takes
217 ownership of the passed item set.
219 @param pOutlinerObj Pointer to an outliner object on heap memory
220 containing (formatted) text for the caption object. This function
221 takes ownership of the passed outliner object.
223 @param rCaptionRect The absolute position and size of the caption
224 object. The rectangle may be empty, in this case the default
225 position and size is used.
227 @return Pointer to the new cell note object if insertion was
228 successful (i.e. the passed cell position was valid), null
229 otherwise. The Calc document is the owner of the note object.
231 static ScPostIt* CreateNoteFromObjectData(
232 ScDocument& rDoc, const ScAddress& rPos,
233 std::unique_ptr<SfxItemSet> pItemSet, OutlinerParaObject* pOutlinerObj,
234 const tools::Rectangle& rCaptionRect, bool bShown );
236 /** Creates a cell note based on the passed string and inserts it into the
237 document.
239 @param rNoteText The text used to create the note caption object. Must
240 not be empty.
242 @param bAlwaysCreateCaption If sal_True is passed, the caption drawing
243 object will be created immediately. If sal_False is passed, the caption
244 drawing object will not be created if the note is not visible
245 (bShown = sal_False), but the cell note will cache the passed data.
246 MUST be set to sal_False outside of import filter implementations!
248 @return Pointer to the new cell note object if insertion was
249 successful (i.e. the passed cell position was valid), null
250 otherwise. The Calc document is the owner of the note object.
252 static ScPostIt* CreateNoteFromString(
253 ScDocument& rDoc, const ScAddress& rPos,
254 const OUString& rNoteText, bool bShown,
255 bool bAlwaysCreateCaption, sal_uInt32 nPostItId = 0 );
259 namespace sc {
261 struct NoteEntry
263 ScAddress maPos;
264 const ScPostIt* mpNote;
266 NoteEntry( const ScAddress& rPos, const ScPostIt* pNote );
271 #endif
272 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */