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