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