Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef SC_POSTIT_HXX
30 : : #define SC_POSTIT_HXX
31 : :
32 : : #include <boost/shared_ptr.hpp>
33 : : #include <rtl/ustring.hxx>
34 : : #include <tools/gen.hxx>
35 : : #include "address.hxx"
36 : : #include "scdllapi.h"
37 : :
38 : : #include <map>
39 : :
40 : : class EditTextObject;
41 : : class OutlinerParaObject;
42 : : class SdrCaptionObj;
43 : : class SdrPage;
44 : : class SfxItemSet;
45 : : class ScDocument;
46 : : struct ScCaptionInitData;
47 : :
48 : : // ============================================================================
49 : :
50 : : /** Internal data for a cell annotation. */
51 [ + - ]: 28 : struct SC_DLLPUBLIC ScNoteData
52 : : {
53 : : typedef ::boost::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef;
54 : :
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.
60 : :
61 : : explicit ScNoteData( bool bShown = false );
62 : : ~ScNoteData();
63 : : };
64 : :
65 : : // ============================================================================
66 : :
67 : : /** An additional class held by an ScBaseCell instance containing all
68 : : information for a cell annotation.
69 : : */
70 : : class SC_DLLPUBLIC ScPostIt
71 : : {
72 : : public:
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 );
76 : :
77 : : /** Copy constructor. Clones the note and its caption to a new document. */
78 : : explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote );
79 : :
80 : : /** Creates a note from the passed note data with existing caption object.
81 : :
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 sal_True is passed,
86 : : the caption drawing object will be created immediately from that
87 : : data. If sal_False is passed and the note is not visible, it will
88 : : continue to cache that data until the caption object is requested.
89 : : */
90 : : explicit ScPostIt(
91 : : ScDocument& rDoc, const ScAddress& rPos,
92 : : const ScNoteData& rNoteData, bool bAlwaysCreateCaption );
93 : :
94 : : /** Removes the caption object from drawing layer, if this note is its owner. */
95 : : ~ScPostIt();
96 : :
97 : : /** Clones this note and its caption object, if specified.
98 : :
99 : : @param bCloneCaption If sal_True is passed, clones the caption object and
100 : : inserts it into the drawing layer of the destination document. If
101 : : sal_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).
104 : : */
105 : : ScPostIt* Clone(
106 : : const ScAddress& rOwnPos,
107 : : ScDocument& rDestDoc, const ScAddress& rDestPos,
108 : : bool bCloneCaption ) const;
109 : :
110 : : /** Returns the data struct containing all note settings. */
111 : 5 : inline const ScNoteData& GetNoteData() const { return maNoteData; }
112 : :
113 : : /** Returns the creation date of this note. */
114 : 0 : inline const ::rtl::OUString& GetDate() const { return maNoteData.maDate; }
115 : : /** Sets a new creation date for this note. */
116 : 8 : inline void SetDate( const ::rtl::OUString& rDate ) { maNoteData.maDate = rDate; }
117 : :
118 : : /** Returns the author date of this note. */
119 : 0 : inline const ::rtl::OUString& GetAuthor() const { return maNoteData.maAuthor; }
120 : : /** Sets a new author date for this note. */
121 : 11 : inline void SetAuthor( const ::rtl::OUString& rAuthor ) { maNoteData.maAuthor = rAuthor; }
122 : :
123 : : /** Sets date and author from system settings. */
124 : : void AutoStamp();
125 : :
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;
130 : :
131 : : /** Returns the caption text of this note. */
132 : : ::rtl::OUString GetText() const;
133 : : /** Changes the caption text of this note. All text formatting will be lost. */
134 : : void SetText( const ScAddress& rPos, const ::rtl::OUString& rText );
135 : :
136 : : /** Returns an existing note caption object. returns null, if the note
137 : : contains initial caption data needed to construct a caption object. */
138 : 0 : inline SdrCaptionObj* GetCaption() const { return maNoteData.mpCaption; }
139 : : /** Returns the caption object of this note. Creates the caption object, if
140 : : the note contains initial caption data instead of the caption. */
141 : : SdrCaptionObj* GetOrCreateCaption( const ScAddress& rPos ) const;
142 : : /** Forgets the pointer to the note caption object. */
143 : : void ForgetCaption();
144 : :
145 : : /** Shows or hides the note caption object. */
146 : : void ShowCaption( const ScAddress& rPos, bool bShow = true );
147 : : /** Returns true, if the caption object is visible. */
148 : 3 : inline bool IsCaptionShown() const { return maNoteData.mbShown; }
149 : :
150 : : /** Shows or hides the caption temporarily (does not change internal visibility state). */
151 : : void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true );
152 : :
153 : : /** Updates caption position according to position of the passed cell. */
154 : : void UpdateCaptionPos( const ScAddress& rPos );
155 : :
156 : : private:
157 : : ScPostIt( const ScPostIt& );
158 : : ScPostIt& operator=( const ScPostIt& );
159 : :
160 : : /** Creates the caption object from initial caption data if existing. */
161 : : void CreateCaptionFromInitData( const ScAddress& rPos ) const;
162 : : /** Creates a new caption object at the passed cell position, clones passed existing caption. */
163 : : void CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption = 0 );
164 : : /** Removes the caption object from the drawing layer, if this note is its owner. */
165 : : void RemoveCaption();
166 : :
167 : : private:
168 : : ScDocument& mrDoc; /// Parent document containing the note.
169 : : mutable ScNoteData maNoteData; /// Note data with pointer to caption object.
170 : : };
171 : :
172 : : // ============================================================================
173 : :
174 : : class SC_DLLPUBLIC ScNoteUtil
175 : : {
176 : : public:
177 : : /** Tries to update the position of note caption objects in the specified range. */
178 : : static void UpdateCaptionPositions( ScDocument& rDoc, const ScRange& rRange );
179 : :
180 : : /** Creates and returns a caption object for a temporary caption. */
181 : : static SdrCaptionObj* CreateTempCaption( ScDocument& rDoc, const ScAddress& rPos,
182 : : SdrPage& rDrawPage, const ::rtl::OUString& rUserText,
183 : : const Rectangle& rVisRect, bool bTailFront );
184 : :
185 : : /** Creates a cell note using the passed caption drawing object.
186 : :
187 : : This function is used in import filters to reuse the imported drawing
188 : : object as note caption object.
189 : :
190 : : @param rCaption The drawing object for the cell note. This object MUST
191 : : be inserted into the document at the correct drawing page already.
192 : :
193 : : @return Pointer to the new cell note object if insertion was
194 : : successful (i.e. the passed cell position was valid), null
195 : : otherwise. The Calc document is the owner of the note object. The
196 : : passed item set and outliner object are deleted automatically if
197 : : creation of the note was not successful.
198 : : */
199 : : static ScPostIt* CreateNoteFromCaption(
200 : : ScDocument& rDoc, const ScAddress& rPos,
201 : : SdrCaptionObj& rCaption, bool bShown );
202 : :
203 : : /** Creates a cell note based on the passed caption object data.
204 : :
205 : : This function is used in import filters to use an existing imported
206 : : item set and outliner object to create a note caption object. For
207 : : performance reasons, it is possible to specify that the caption drawing
208 : : object for the cell note is not created yet but the note caches the
209 : : passed data needed to create the caption object on demand (see
210 : : parameter bAlwaysCreateCaption).
211 : :
212 : : @param pItemSet Pointer to an item set on heap memory containing all
213 : : formatting attributes of the caption object. This function takes
214 : : ownership of the passed item set.
215 : :
216 : : @param pOutlinerObj Pointer to an outliner object on heap memory
217 : : containing (formatted) text for the caption object. This function
218 : : takes ownership of the passed outliner object.
219 : :
220 : : @param rCaptionRect The absolute position and size of the caption
221 : : object. The rectangle may be empty, in this case the default
222 : : position and size is used.
223 : :
224 : : @param bAlwaysCreateCaption If sal_True is passed, the caption drawing
225 : : object will be created immediately. If sal_False is passed, the caption
226 : : drawing object will not be created if the note is not visible
227 : : (bShown = sal_False), but the cell note will cache the passed data.
228 : : MUST be set to sal_False outside of import filter implementations!
229 : :
230 : : @return Pointer to the new cell note object if insertion was
231 : : successful (i.e. the passed cell position was valid), null
232 : : otherwise. The Calc document is the owner of the note object.
233 : : */
234 : : static ScPostIt* CreateNoteFromObjectData(
235 : : ScDocument& rDoc, const ScAddress& rPos,
236 : : SfxItemSet* pItemSet, OutlinerParaObject* pOutlinerObj,
237 : : const Rectangle& rCaptionRect, bool bShown,
238 : : bool bAlwaysCreateCaption );
239 : :
240 : : /** Creates a cell note based on the passed string and inserts it into the
241 : : document.
242 : :
243 : : @param rNoteText The text used to create the note caption object. Must
244 : : not be empty.
245 : :
246 : : @param bAlwaysCreateCaption If sal_True is passed, the caption drawing
247 : : object will be created immediately. If sal_False is passed, the caption
248 : : drawing object will not be created if the note is not visible
249 : : (bShown = sal_False), but the cell note will cache the passed data.
250 : : MUST be set to sal_False outside of import filter implementations!
251 : :
252 : : @return Pointer to the new cell note object if insertion was
253 : : successful (i.e. the passed cell position was valid), null
254 : : otherwise. The Calc document is the owner of the note object.
255 : : */
256 : : static ScPostIt* CreateNoteFromString(
257 : : ScDocument& rDoc, const ScAddress& rPos,
258 : : const ::rtl::OUString& rNoteText, bool bShown,
259 : : bool bAlwaysCreateCaption );
260 : : };
261 : :
262 : 12 : class SC_DLLPUBLIC ScNotes
263 : : {
264 : : private:
265 : : typedef std::pair<SCCOL, SCROW> ScAddress2D;
266 : : typedef std::map<ScAddress2D, ScPostIt*> ScNoteMap;
267 : : ScNoteMap maNoteMap;
268 : :
269 : : ScDocument* mpDoc;
270 : : public:
271 : : ScNotes(ScDocument* pDoc);
272 : : ScNotes(const ScNotes& rNotes);
273 : : ~ScNotes();
274 : :
275 : : typedef ScNoteMap::iterator iterator;
276 : : typedef ScNoteMap::const_iterator const_iterator;
277 : :
278 : : iterator begin();
279 : : iterator end();
280 : :
281 : : const_iterator begin() const;
282 : : const_iterator end() const;
283 : :
284 : : size_t size() const;
285 : : bool empty() const;
286 : :
287 : : ScPostIt* findByAddress(SCCOL nCol, SCROW nRow);
288 : : const ScPostIt* findByAddress(SCCOL nCol, SCROW nRow) const;
289 : :
290 : : ScPostIt* findByAddress(const ScAddress& rAddress);
291 : : const ScPostIt* findByAddress(const ScAddress& rAddress) const;
292 : : /**
293 : : * takes ownership of the
294 : : */
295 : : bool insert( SCCOL nCol, SCROW nRow, ScPostIt* );
296 : : bool insert( const ScAddress& rPos, ScPostIt* );
297 : :
298 : : void erase(SCCOL, SCROW, bool bForgetCaption = false);
299 : : void erase(const ScAddress& rPos);
300 : :
301 : : /** Returns and forgets the cell note object at the passed cell address. */
302 : : ScPostIt* ReleaseNote( const ScAddress& rPos );
303 : : ScPostIt* ReleaseNote( SCCOL nCol, SCROW nRow );
304 : : /** Returns the pointer to an existing or created cell note object at the passed cell address. */
305 : : ScPostIt* GetOrCreateNote( const ScAddress& rPos );
306 : :
307 : : void clear();
308 : :
309 : : ScNotes* clone(ScDocument* pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bCloneNoteCaption, SCTAB nTab);
310 : : void CopyFromClip(const ScNotes& maNotes, ScDocument* pDoc, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, SCsCOL nDx, SCsROW nDy, SCTAB nTab, bool bCloneCaption);
311 : :
312 : : void erase(SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2, bool bForgetCaption = false);
313 : :
314 : : void CreateAllNoteCaptions(SCTAB nTab);
315 : : };
316 : :
317 : : // ============================================================================
318 : :
319 : : #endif
320 : :
321 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|