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 <tools/gen.hxx>
35 #include "address.hxx"
44 // ============================================================================
46 struct SC_DLLPUBLIC ScNoteData
48 String maDate
; /// Creation date of the note.
49 String maAuthor
; /// Author of the note.
50 SdrCaptionObj
* mpCaption
; /// Drawing object representing the cell note.
51 bool mbShown
; /// True = note is visible.
53 explicit ScNoteData( bool bShown
= false );
56 // ============================================================================
58 class SC_DLLPUBLIC ScPostIt
61 /** Creates an empty note and its caption object and places it according to
62 the passed cell position. */
63 explicit ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, bool bShown
);
65 /** Copy constructor. Clones the note and its caption to a new document. */
66 explicit ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, const ScPostIt
& rNote
);
68 /** Creates a note from the passed note data with existing caption object. */
69 explicit ScPostIt( ScDocument
& rDoc
, const ScNoteData
& rNoteData
);
71 /** Removes the caption object from drawing layer, if this note is its owner. */
74 /** Returns the data struct containing note settings. */
75 inline const ScNoteData
& GetNoteData() const { return maNoteData
; }
77 /** Returns the creation date of this note. */
78 inline const String
& GetDate() const { return maNoteData
.maDate
; }
79 /** Sets a new creation date for this note. */
80 inline void SetDate( const String
& rDate
) { maNoteData
.maDate
= rDate
; }
82 /** Returns the author date of this note. */
83 inline const String
& GetAuthor() const { return maNoteData
.maAuthor
; }
84 /** Sets a new author date for this note. */
85 inline void SetAuthor( const String
& rAuthor
) { maNoteData
.maAuthor
= rAuthor
; }
87 /** Sets date and author from system settings. */
90 /** Returns the pointer to the current edit text object, or null. */
91 const EditTextObject
* GetEditTextObject() const;
92 /** Returns the caption text of this note. */
93 String
GetText() const;
94 /** Returns true, if the caption text of this note contains line breaks. */
95 bool HasMultiLineText() const;
96 /** Changes the caption text of this note. All text formatting will be lost. */
97 void SetText( const String
& rText
);
99 /** Returns the note caption object. */
100 inline SdrCaptionObj
* GetCaption() const { return maNoteData
.mpCaption
; }
101 /** Returns and forgets the note caption object. */
102 inline SdrCaptionObj
* ForgetCaption() { SdrCaptionObj
* pCapt
= maNoteData
.mpCaption
; maNoteData
.mpCaption
= 0; return pCapt
; }
104 /** Shows or hides the note caption object. */
105 void ShowCaption( bool bShow
= true );
106 /** Hides the note caption object. */
107 inline void HideCaption() { ShowCaption( false ); }
108 /** Returns true, if the caption object is visible. */
109 inline bool IsCaptionShown() const { return maNoteData
.mbShown
; }
111 /** Shows or hides the caption temporarily (does not change internal visibility state). */
112 void ShowCaptionTemp( bool bShow
= true );
113 /** Hides caption if it has been shown temporarily (does not change internal visibility state). */
114 inline void HideCaptionTemp() { ShowCaptionTemp( false ); }
116 /** Updates caption position according to position of the passed cell. */
117 void UpdateCaptionPos( const ScAddress
& rPos
);
119 /** Sets caption itemset to default items. */
120 void SetCaptionDefaultItems();
121 /** Updates caption itemset according to the passed item set while removing shadow items. */
122 void SetCaptionItems( const SfxItemSet
& rItemSet
);
125 ScPostIt( const ScPostIt
& );
126 ScPostIt
& operator=( const ScPostIt
& );
128 /** Creates a new caption object at the passed cell position, clones passed existing caption. */
129 void CreateCaption( const ScAddress
& rPos
, const SdrCaptionObj
* pCaption
= 0 );
130 /** Removes the caption object from the drawing layer, if this note is its owner. */
131 void RemoveCaption();
132 /** Updates caption visibility. */
133 void UpdateCaptionLayer( bool bShow
);
136 ScDocument
& mrDoc
; /// Parent document containing the note.
137 ScNoteData maNoteData
; /// Note data with pointer to caption object.
140 // ============================================================================
142 class SC_DLLPUBLIC ScNoteUtil
145 /** Clones the note and its caption object, if specified.
146 @param bCloneCaption True = clones the caption object and inserts it
147 into the drawing layer of the destination document. False = the
148 cloned note will refer to the old caption object. */
149 static ScPostIt
* CloneNote( ScDocument
& rDoc
, const ScAddress
& rPos
,
150 const ScPostIt
& rNote
, bool bCloneCaption
);
152 /** Tries to update the position of note caption objects in the specified range. */
153 static void UpdateCaptionPositions( ScDocument
& rDoc
, const ScRange
& rRange
);
155 /** Creates and returns a caption object for a temporary caption. */
156 static SdrCaptionObj
* CreateTempCaption( ScDocument
& rDoc
, const ScAddress
& rPos
,
157 SdrPage
& rPage
, const String
& rUserText
,
158 const Rectangle
& rVisRect
, bool bTailFront
);
160 /** Creates a cell note based on the passed string and inserts it into the document. */
161 static ScPostIt
* CreateNoteFromString( ScDocument
& rDoc
, const ScAddress
& rPos
,
162 const String
& rNoteText
, bool bShown
);
165 // ============================================================================