1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 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. 14 * 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). 20 * 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. 25 * 26 ************************************************************************/ 27 28 #ifndef SC_POSTIT_HXX 29 #define SC_POSTIT_HXX 30 31 #include <boost/shared_ptr.hpp> 32 #include <rtl/ustring.hxx> 33 #include <tools/gen.hxx> 34 #include "address.hxx" 35 #include "scdllapi.h" 36 37 class EditTextObject; 38 class OutlinerParaObject; 39 class SdrCaptionObj; 40 class SdrPage; 41 class SfxItemSet; 42 class ScDocument; 43 struct ScCaptionInitData; 44 45 // ============================================================================ 46 47 /** Internal data for a cell annotation. */ 48 struct SC_DLLPUBLIC ScNoteData 49 { 50 typedef ::boost::shared_ptr< ScCaptionInitData > ScCaptionInitDataRef; 51 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. 57 58 explicit ScNoteData( bool bShown = false ); 59 ~ScNoteData(); 60 }; 61 62 // ============================================================================ 63 64 /** An additional class held by an ScBaseCell instance containing all 65 information for a cell annotation. 66 */ 67 class SC_DLLPUBLIC ScPostIt 68 { 69 public: 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 ); 73 74 /** Copy constructor. Clones the note and its caption to a new document. */ 75 explicit ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote ); 76 77 /** Creates a note from the passed note data with existing caption object. 78 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 sal_True is passed, 83 the caption drawing object will be created immediately from that 84 data. If sal_False is passed and the note is not visible, it will 85 continue to cache that data until the caption object is requested. 86 */ 87 explicit ScPostIt( 88 ScDocument& rDoc, const ScAddress& rPos, 89 const ScNoteData& rNoteData, bool bAlwaysCreateCaption ); 90 91 /** Removes the caption object from drawing layer, if this note is its owner. */ 92 ~ScPostIt(); 93 94 /** Clones this note and its caption object, if specified. 95 96 @param bCloneCaption If sal_True is passed, clones the caption object and 97 inserts it into the drawing layer of the destination document. If 98 sal_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). 101 */ 102 ScPostIt* Clone( 103 const ScAddress& rOwnPos, 104 ScDocument& rDestDoc, const ScAddress& rDestPos, 105 bool bCloneCaption ) const; 106 107 /** Returns the data struct containing all note settings. */ 108 inline const ScNoteData& GetNoteData() const { return maNoteData; } 109 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; } 114 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; } 119 120 /** Sets date and author from system settings. */ 121 void AutoStamp(); 122 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; 127 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 ); 134 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(); 143 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; } 148 149 /** Shows or hides the caption temporarily (does not change internal visibility state). */ 150 void ShowCaptionTemp( const ScAddress& rPos, bool bShow = true ); 151 152 /** Updates caption position according to position of the passed cell. */ 153 void UpdateCaptionPos( const ScAddress& rPos ); 154 155 private: 156 ScPostIt( const ScPostIt& ); 157 ScPostIt& operator=( const ScPostIt& ); 158 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(); 165 166 private: 167 ScDocument& mrDoc; /// Parent document containing the note. 168 mutable ScNoteData maNoteData; /// Note data with pointer to caption object. 169 }; 170 171 // ============================================================================ 172 173 class SC_DLLPUBLIC ScNoteUtil 174 { 175 public: 176 /** Tries to update the position of note caption objects in the specified range. */ 177 static void UpdateCaptionPositions( ScDocument& rDoc, const ScRange& rRange ); 178 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 ); 183 184 /** Creates a cell note using the passed caption drawing object. 185 186 This function is used in import filters to reuse the imported drawing 187 object as note caption object. 188 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. 191 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. 197 */ 198 static ScPostIt* CreateNoteFromCaption( 199 ScDocument& rDoc, const ScAddress& rPos, 200 SdrCaptionObj& rCaption, bool bShown ); 201 202 /** Creates a cell note based on the passed caption object data. 203 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). 210 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. 214 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. 218 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. 222 223 @param bAlwaysCreateCaption If sal_True is passed, the caption drawing 224 object will be created immediately. If sal_False is passed, the caption 225 drawing object will not be created if the note is not visible 226 (bShown = sal_False), but the cell note will cache the passed data. 227 MUST be set to sal_False outside of import filter implementations! 228 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. 232 */ 233 static ScPostIt* CreateNoteFromObjectData( 234 ScDocument& rDoc, const ScAddress& rPos, 235 SfxItemSet* pItemSet, OutlinerParaObject* pOutlinerObj, 236 const Rectangle& rCaptionRect, bool bShown, 237 bool bAlwaysCreateCaption ); 238 239 /** Creates a cell note based on the passed string and inserts it into the 240 document. 241 242 @param rNoteText The text used to create the note caption object. Must 243 not be empty. 244 245 @param bAlwaysCreateCaption If sal_True is passed, the caption drawing 246 object will be created immediately. If sal_False is passed, the caption 247 drawing object will not be created if the note is not visible 248 (bShown = sal_False), but the cell note will cache the passed data. 249 MUST be set to sal_False outside of import filter implementations! 250 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. 254 */ 255 static ScPostIt* CreateNoteFromString( 256 ScDocument& rDoc, const ScAddress& rPos, 257 const ::rtl::OUString& rNoteText, bool bShown, 258 bool bAlwaysCreateCaption ); 259 }; 260 261 // ============================================================================ 262 263 #endif 264