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