1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 #include <boost/shared_ptr.hpp>
32 #include <rtl/ustring.hxx>
33 #include <tools/gen.hxx>
34 #include "address.hxx"
38 class OutlinerParaObject
;
43 struct ScCaptionInitData
;
45 // ============================================================================
47 /** Internal data for a cell annotation. */
48 struct SC_DLLPUBLIC ScNoteData
50 typedef ::boost::shared_ptr
< ScCaptionInitData
> ScCaptionInitDataRef
;
52 ::rtl::OUString maDate
; /// Creation date of the note.
53 ::rtl::OUString maAuthor
; /// Author of the note.
54 ScCaptionInitDataRef mxInitData
; /// Initial data for invisible notes without SdrObject.
55 SdrCaptionObj
* mpCaption
; /// Drawing object representing the cell note.
56 bool mbShown
; /// True = note is visible.
58 explicit ScNoteData( bool bShown
= false );
62 // ============================================================================
64 /** An additional class held by an ScBaseCell instance containing all
65 information for a cell annotation.
67 class SC_DLLPUBLIC ScPostIt
70 /** Creates an empty note and its caption object and places it according to
71 the passed cell position. */
72 explicit ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, bool bShown
);
74 /** Copy constructor. Clones the note and its caption to a new document. */
75 explicit ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, const ScPostIt
& rNote
);
77 /** Creates a note from the passed note data with existing caption object.
79 @param bAlwaysCreateCaption Instead of a pointer to an existing
80 caption object, the passed note data structure may contain a
81 reference to an ScCaptionInitData structure containing information
82 about how to construct a missing caption object. If TRUE is passed,
83 the caption drawing object will be created immediately from that
84 data. If FALSE is passed and the note is not visible, it will
85 continue to cache that data until the caption object is requested.
88 ScDocument
& rDoc
, const ScAddress
& rPos
,
89 const ScNoteData
& rNoteData
, bool bAlwaysCreateCaption
);
91 /** Removes the caption object from drawing layer, if this note is its owner. */
94 /** Clones this note and its caption object, if specified.
96 @param bCloneCaption If TRUE is passed, clones the caption object and
97 inserts it into the drawing layer of the destination document. If
98 FALSE is passed, the cloned note will refer to the old caption
99 object (used e.g. in Undo documents to restore the pointer to the
100 existing caption object).
103 const ScAddress
& rOwnPos
,
104 ScDocument
& rDestDoc
, const ScAddress
& rDestPos
,
105 bool bCloneCaption
) const;
107 /** Returns the data struct containing all note settings. */
108 inline const ScNoteData
& GetNoteData() const { return maNoteData
; }
110 /** Returns the creation date of this note. */
111 inline const ::rtl::OUString
& GetDate() const { return maNoteData
.maDate
; }
112 /** Sets a new creation date for this note. */
113 inline void SetDate( const ::rtl::OUString
& rDate
) { maNoteData
.maDate
= rDate
; }
115 /** Returns the author date of this note. */
116 inline const ::rtl::OUString
& GetAuthor() const { return maNoteData
.maAuthor
; }
117 /** Sets a new author date for this note. */
118 inline void SetAuthor( const ::rtl::OUString
& rAuthor
) { maNoteData
.maAuthor
= rAuthor
; }
120 /** Sets date and author from system settings. */
123 /** Returns the pointer to the current outliner object, or null. */
124 const OutlinerParaObject
* GetOutlinerObject() const;
125 /** Returns the pointer to the current edit text object, or null. */
126 const EditTextObject
* GetEditTextObject() const;
128 /** Returns the caption text of this note. */
129 ::rtl::OUString
GetText() const;
130 /** Returns true, if the caption text of this note contains line breaks. */
131 bool HasMultiLineText() const;
132 /** Changes the caption text of this note. All text formatting will be lost. */
133 void SetText( const ScAddress
& rPos
, const ::rtl::OUString
& rText
);
135 /** Returns an existing note caption object. returns null, if the note
136 contains initial caption data needed to construct a caption object. */
137 inline SdrCaptionObj
* GetCaption() const { return maNoteData
.mpCaption
; }
138 /** Returns the caption object of this note. Creates the caption object, if
139 the note contains initial caption data instead of the caption. */
140 SdrCaptionObj
* GetOrCreateCaption( const ScAddress
& rPos
) const;
141 /** Forgets the pointer to the note caption object. */
142 void ForgetCaption();
144 /** Shows or hides the note caption object. */
145 void ShowCaption( const ScAddress
& rPos
, bool bShow
= true );
146 /** Returns true, if the caption object is visible. */
147 inline bool IsCaptionShown() const { return maNoteData
.mbShown
; }
149 /** Shows or hides the caption temporarily (does not change internal visibility state). */
150 void ShowCaptionTemp( const ScAddress
& rPos
, bool bShow
= true );
152 /** Updates caption position according to position of the passed cell. */
153 void UpdateCaptionPos( const ScAddress
& rPos
);
156 ScPostIt( const ScPostIt
& );
157 ScPostIt
& operator=( const ScPostIt
& );
159 /** Creates the caption object from initial caption data if existing. */
160 void CreateCaptionFromInitData( const ScAddress
& rPos
) const;
161 /** Creates a new caption object at the passed cell position, clones passed existing caption. */
162 void CreateCaption( const ScAddress
& rPos
, const SdrCaptionObj
* pCaption
= 0 );
163 /** Removes the caption object from the drawing layer, if this note is its owner. */
164 void RemoveCaption();
167 ScDocument
& mrDoc
; /// Parent document containing the note.
168 mutable ScNoteData maNoteData
; /// Note data with pointer to caption object.
171 // ============================================================================
173 class SC_DLLPUBLIC ScNoteUtil
176 /** Tries to update the position of note caption objects in the specified range. */
177 static void UpdateCaptionPositions( ScDocument
& rDoc
, const ScRange
& rRange
);
179 /** Creates and returns a caption object for a temporary caption. */
180 static SdrCaptionObj
* CreateTempCaption( ScDocument
& rDoc
, const ScAddress
& rPos
,
181 SdrPage
& rDrawPage
, const ::rtl::OUString
& rUserText
,
182 const Rectangle
& rVisRect
, bool bTailFront
);
184 /** Creates a cell note using the passed caption drawing object.
186 This function is used in import filters to reuse the imported drawing
187 object as note caption object.
189 @param rCaption The drawing object for the cell note. This object MUST
190 be inserted into the document at the correct drawing page already.
192 @return Pointer to the new cell note object if insertion was
193 successful (i.e. the passed cell position was valid), null
194 otherwise. The Calc document is the owner of the note object. The
195 passed item set and outliner object are deleted automatically if
196 creation of the note was not successful.
198 static ScPostIt
* CreateNoteFromCaption(
199 ScDocument
& rDoc
, const ScAddress
& rPos
,
200 SdrCaptionObj
& rCaption
, bool bShown
);
202 /** Creates a cell note based on the passed caption object data.
204 This function is used in import filters to use an existing imported
205 item set and outliner object to create a note caption object. For
206 performance reasons, it is possible to specify that the caption drawing
207 object for the cell note is not created yet but the note caches the
208 passed data needed to create the caption object on demand (see
209 parameter bAlwaysCreateCaption).
211 @param pItemSet Pointer to an item set on heap memory containing all
212 formatting attributes of the caption object. This function takes
213 ownership of the passed item set.
215 @param pOutlinerObj Pointer to an outliner object on heap memory
216 containing (formatted) text for the caption object. This function
217 takes ownership of the passed outliner object.
219 @param rCaptionRect The absolute position and size of the caption
220 object. The rectangle may be empty, in this case the default
221 position and size is used.
223 @param bAlwaysCreateCaption If TRUE is passed, the caption drawing
224 object will be created immediately. If FALSE is passed, the caption
225 drawing object will not be created if the note is not visible
226 (bShown = FALSE), but the cell note will cache the passed data.
227 MUST be set to FALSE outside of import filter implementations!
229 @return Pointer to the new cell note object if insertion was
230 successful (i.e. the passed cell position was valid), null
231 otherwise. The Calc document is the owner of the note object.
233 static ScPostIt
* CreateNoteFromObjectData(
234 ScDocument
& rDoc
, const ScAddress
& rPos
,
235 SfxItemSet
* pItemSet
, OutlinerParaObject
* pOutlinerObj
,
236 const Rectangle
& rCaptionRect
, bool bShown
,
237 bool bAlwaysCreateCaption
);
239 /** Creates a cell note based on the passed string and inserts it into the
242 @param rNoteText The text used to create the note caption object. Must
245 @param bAlwaysCreateCaption If TRUE is passed, the caption drawing
246 object will be created immediately. If FALSE is passed, the caption
247 drawing object will not be created if the note is not visible
248 (bShown = FALSE), but the cell note will cache the passed data.
249 MUST be set to FALSE outside of import filter implementations!
251 @return Pointer to the new cell note object if insertion was
252 successful (i.e. the passed cell position was valid), null
253 otherwise. The Calc document is the owner of the note object.
255 static ScPostIt
* CreateNoteFromString(
256 ScDocument
& rDoc
, const ScAddress
& rPos
,
257 const ::rtl::OUString
& rNoteText
, bool bShown
,
258 bool bAlwaysCreateCaption
);
261 // ============================================================================