1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
23 #include <rtl/ustrbuf.hxx>
24 #include <sal/log.hxx>
25 #include <unotools/useroptions.hxx>
26 #include <svx/svdocapt.hxx>
27 #include <svx/svdpage.hxx>
28 #include <editeng/outlobj.hxx>
29 #include <editeng/editobj.hxx>
30 #include <osl/diagnose.h>
31 #include <comphelper/lok.hxx>
33 #include <svx/sdsxyitm.hxx>
34 #include <svx/sdtagitm.hxx>
35 #include <svx/sdtmfitm.hxx>
36 #include <tools/gen.hxx>
38 #include <document.hxx>
39 #include <stlpool.hxx>
40 #include <stylehelper.hxx>
41 #include <drwlayer.hxx>
42 #include <userdat.hxx>
43 #include <editutil.hxx>
44 #include <globstr.hrc>
45 #include <scresid.hxx>
47 #include <strings.hrc>
48 #include <officecfg/Office/Calc.hxx>
50 #include <com/sun/star/text/XText.hpp>
51 #include <com/sun/star/text/XTextAppend.hpp>
52 #include <com/sun/star/awt/FontWeight.hpp>
53 #include <comphelper/propertyvalue.hxx>
55 using namespace com::sun::star
;
59 const tools::Long SC_NOTECAPTION_WIDTH
= 2900; /// Default width of note caption textbox.
60 const tools::Long SC_NOTECAPTION_MAXWIDTH_TEMP
= 12000; /// Maximum width of temporary note caption textbox.
61 const tools::Long SC_NOTECAPTION_HEIGHT
= 1800; /// Default height of note caption textbox.
62 const tools::Long SC_NOTECAPTION_CELLDIST
= 600; /// Default distance of note captions to border of anchor cell.
63 const tools::Long SC_NOTECAPTION_OFFSET_Y
= -1500; /// Default Y offset of note captions to top border of anchor cell.
64 const tools::Long SC_NOTECAPTION_OFFSET_X
= 1500; /// Default X offset of note captions to left border of anchor cell.
65 const tools::Long SC_NOTECAPTION_BORDERDIST_TEMP
= 100; /// Distance of temporary note captions to visible sheet area.
67 /** Static helper functions for caption objects. */
71 /** Moves the caption object to the correct layer according to passed visibility. */
72 static void SetCaptionLayer( SdrCaptionObj
& rCaption
, bool bShown
);
73 /** Sets basic caption settings required for note caption objects. */
74 static void SetBasicCaptionSettings( SdrCaptionObj
& rCaption
, bool bShown
);
75 /** Stores the cell position of the note in the user data area of the caption. */
76 static void SetCaptionUserData( SdrCaptionObj
& rCaption
, const ScAddress
& rPos
);
77 /** Sets all hard formatting attributes to the caption object. */
78 static void SetExtraItems( SdrCaptionObj
& rCaption
, const SfxItemSet
& rExtraItemSet
);
81 void ScCaptionUtil::SetCaptionLayer( SdrCaptionObj
& rCaption
, bool bShown
)
83 SdrLayerID nLayer
= bShown
? SC_LAYER_INTERN
: SC_LAYER_HIDDEN
;
84 if( nLayer
!= rCaption
.GetLayer() )
85 rCaption
.SetLayer( nLayer
);
88 void ScCaptionUtil::SetBasicCaptionSettings( SdrCaptionObj
& rCaption
, bool bShown
)
90 rCaption
.SetFixedTail();
91 rCaption
.SetSpecialTextBoxShadow();
92 SetCaptionLayer( rCaption
, bShown
);
95 void ScCaptionUtil::SetCaptionUserData( SdrCaptionObj
& rCaption
, const ScAddress
& rPos
)
97 // pass true to ScDrawLayer::GetObjData() to create the object data entry
98 ScDrawObjData
* pObjData
= ScDrawLayer::GetObjData( &rCaption
, true );
99 assert(pObjData
&& "ScCaptionUtil::SetCaptionUserData - missing drawing object user data");
100 pObjData
->maStart
= rPos
;
101 pObjData
->meType
= ScDrawObjData::CellNote
;
104 void ScCaptionUtil::SetExtraItems( SdrCaptionObj
& rCaption
, const SfxItemSet
& rExtraItemSet
)
106 SfxItemSet aItemSet
= rCaption
.GetMergedItemSet();
108 aItemSet
.Put(rExtraItemSet
);
109 // reset shadow visibility (see also ScNoteUtil::CreateNoteFromCaption)
110 aItemSet
.ClearItem(SDRATTR_SHADOW
);
111 // ... but not distance, as that will fallback to wrong values
112 // if the comment is shown and then opened in older versions:
113 aItemSet
.Put( makeSdrShadowXDistItem( 100 ) );
114 aItemSet
.Put( makeSdrShadowYDistItem( 100 ) );
116 rCaption
.SetMergedItemSet( aItemSet
, /*bClearAllItems*/false, /*bAdjustTextFrameWidthAndHeight*/false );
119 /** Helper for creation and manipulation of caption drawing objects independent
120 from cell annotations. */
121 class ScCaptionCreator
124 /** Create a new caption. The caption will not be inserted into the document. */
125 explicit ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, bool bTailFront
);
126 /** Manipulate an existing caption. */
127 explicit ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, const rtl::Reference
<SdrCaptionObj
>& xCaption
);
129 /** Returns the drawing layer page of the sheet contained in maPos. */
130 SdrPage
* GetDrawPage();
131 /** Returns the caption drawing object. */
132 rtl::Reference
<SdrCaptionObj
> & GetCaption() { return mxCaption
; }
134 /** Moves the caption inside the passed rectangle. Uses page area if 0 is passed. */
135 void FitCaptionToRect( const tools::Rectangle
* pVisRect
= nullptr );
136 /** Places the caption inside the passed rectangle, tries to keep the cell rectangle uncovered. Uses page area if 0 is passed. */
137 void AutoPlaceCaption( const tools::Rectangle
* pVisRect
= nullptr );
138 /** Updates caption tail and textbox according to current cell position. Uses page area if 0 is passed. */
139 void UpdateCaptionPos();
142 /** Helper constructor for derived classes. */
143 explicit ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
);
145 /** Calculates the caption tail position according to current cell position. */
146 Point
CalcTailPos( bool bTailFront
);
147 /** Implements creation of the caption object. The caption will not be inserted into the document. */
148 void CreateCaption( bool bShown
, bool bTailFront
);
151 /** Initializes all members. */
153 /** Returns the passed rectangle if existing, page rectangle otherwise. */
154 const tools::Rectangle
& GetVisRect( const tools::Rectangle
* pVisRect
) const { return pVisRect
? *pVisRect
: maPageRect
; }
159 rtl::Reference
<SdrCaptionObj
> mxCaption
;
160 tools::Rectangle maPageRect
;
161 tools::Rectangle maCellRect
;
165 ScCaptionCreator::ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, bool bTailFront
) :
170 CreateCaption( true/*bShown*/, bTailFront
);
173 ScCaptionCreator::ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, const rtl::Reference
<SdrCaptionObj
>& xCaption
) :
176 mxCaption( xCaption
)
181 ScCaptionCreator::ScCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
) :
188 SdrPage
* ScCaptionCreator::GetDrawPage()
190 ScDrawLayer
* pDrawLayer
= mrDoc
.GetDrawLayer();
191 return pDrawLayer
? pDrawLayer
->GetPage( static_cast< sal_uInt16
>( maPos
.Tab() ) ) : nullptr;
194 void ScCaptionCreator::FitCaptionToRect( const tools::Rectangle
* pVisRect
)
196 const tools::Rectangle
& rVisRect
= GetVisRect( pVisRect
);
199 Point aTailPos
= mxCaption
->GetTailPos();
200 aTailPos
.setX( ::std::clamp( aTailPos
.X(), rVisRect
.Left(), rVisRect
.Right() ) );
201 aTailPos
.setY( ::std::clamp( aTailPos
.Y(), rVisRect
.Top(), rVisRect
.Bottom() ) );
202 mxCaption
->SetTailPos( aTailPos
);
205 tools::Rectangle aCaptRect
= mxCaption
->GetLogicRect();
206 Point aCaptPos
= aCaptRect
.TopLeft();
207 // move textbox inside right border of visible area
208 aCaptPos
.setX( ::std::min
< tools::Long
>( aCaptPos
.X(), rVisRect
.Right() - aCaptRect
.GetWidth() ) );
209 // move textbox inside left border of visible area (this may move it outside on right side again)
210 aCaptPos
.setX( ::std::max
< tools::Long
>( aCaptPos
.X(), rVisRect
.Left() ) );
211 // move textbox inside bottom border of visible area
212 aCaptPos
.setY( ::std::min
< tools::Long
>( aCaptPos
.Y(), rVisRect
.Bottom() - aCaptRect
.GetHeight() ) );
213 // move textbox inside top border of visible area (this may move it outside on bottom side again)
214 aCaptPos
.setY( ::std::max
< tools::Long
>( aCaptPos
.Y(), rVisRect
.Top() ) );
216 aCaptRect
.SetPos( aCaptPos
);
217 mxCaption
->NbcSetLogicRect( aCaptRect
, /*bAdaptTextMinSize*/false );
220 void ScCaptionCreator::AutoPlaceCaption( const tools::Rectangle
* pVisRect
)
222 const tools::Rectangle
& rVisRect
= GetVisRect( pVisRect
);
225 tools::Rectangle aCaptRect
= mxCaption
->GetLogicRect();
226 tools::Long nWidth
= aCaptRect
.GetWidth();
227 tools::Long nHeight
= aCaptRect
.GetHeight();
229 // n***Space contains available space between border of visible area and cell
230 tools::Long nLeftSpace
= maCellRect
.Left() - rVisRect
.Left() + 1;
231 tools::Long nRightSpace
= rVisRect
.Right() - maCellRect
.Right() + 1;
232 tools::Long nTopSpace
= maCellRect
.Top() - rVisRect
.Top() + 1;
233 tools::Long nBottomSpace
= rVisRect
.Bottom() - maCellRect
.Bottom() + 1;
235 // nNeeded*** contains textbox dimensions plus needed distances to cell or border of visible area
236 tools::Long nNeededSpaceX
= nWidth
+ SC_NOTECAPTION_CELLDIST
;
237 tools::Long nNeededSpaceY
= nHeight
+ SC_NOTECAPTION_CELLDIST
;
239 // bFitsWidth*** == true means width of textbox fits into horizontal free space of visible area
240 bool bFitsWidthLeft
= nNeededSpaceX
<= nLeftSpace
; // text box width fits into the width left of cell
241 bool bFitsWidthRight
= nNeededSpaceX
<= nRightSpace
; // text box width fits into the width right of cell
242 bool bFitsWidth
= nWidth
<= rVisRect
.GetWidth(); // text box width fits into width of visible area
244 // bFitsHeight*** == true means height of textbox fits into vertical free space of visible area
245 bool bFitsHeightTop
= nNeededSpaceY
<= nTopSpace
; // text box height fits into the height above cell
246 bool bFitsHeightBottom
= nNeededSpaceY
<= nBottomSpace
; // text box height fits into the height below cell
247 bool bFitsHeight
= nHeight
<= rVisRect
.GetHeight(); // text box height fits into height of visible area
249 // bFits*** == true means the textbox fits completely into free space of visible area
250 bool bFitsLeft
= bFitsWidthLeft
&& bFitsHeight
;
251 bool bFitsRight
= bFitsWidthRight
&& bFitsHeight
;
252 bool bFitsTop
= bFitsWidth
&& bFitsHeightTop
;
253 bool bFitsBottom
= bFitsWidth
&& bFitsHeightBottom
;
256 // use left/right placement if possible, or if top/bottom placement not possible
257 if( bFitsLeft
|| bFitsRight
|| (!bFitsTop
&& !bFitsBottom
) )
259 // prefer left in RTL sheet and right in LTR sheets
260 bool bPreferLeft
= bFitsLeft
&& (mbNegPage
|| !bFitsRight
);
261 bool bPreferRight
= bFitsRight
&& (!mbNegPage
|| !bFitsLeft
);
262 // move to left, if left is preferred, or if neither left nor right fit and there is more space to the left
263 if( bPreferLeft
|| (!bPreferRight
&& (nLeftSpace
> nRightSpace
)) )
264 aCaptPos
.setX( maCellRect
.Left() - SC_NOTECAPTION_CELLDIST
- nWidth
);
266 aCaptPos
.setX( maCellRect
.Right() + SC_NOTECAPTION_CELLDIST
);
267 // Y position according to top cell border
268 aCaptPos
.setY( maCellRect
.Top() + SC_NOTECAPTION_OFFSET_Y
);
270 else // top or bottom placement
273 aCaptPos
.setX( maCellRect
.Left() + SC_NOTECAPTION_OFFSET_X
);
274 // top placement, if possible
276 aCaptPos
.setY( maCellRect
.Top() - SC_NOTECAPTION_CELLDIST
- nHeight
);
277 else // bottom placement
278 aCaptPos
.setY( maCellRect
.Bottom() + SC_NOTECAPTION_CELLDIST
);
281 // update textbox position in note caption object
282 aCaptRect
.SetPos( aCaptPos
);
283 mxCaption
->SetLogicRect( aCaptRect
);
284 FitCaptionToRect( pVisRect
);
287 void ScCaptionCreator::UpdateCaptionPos()
289 ScDrawLayer
* pDrawLayer
= mrDoc
.GetDrawLayer();
291 // update caption position
292 const Point
& rOldTailPos
= mxCaption
->GetTailPos();
293 Point aTailPos
= CalcTailPos( false );
294 if( rOldTailPos
!= aTailPos
)
296 // create drawing undo action
297 if( pDrawLayer
&& pDrawLayer
->IsRecording() )
298 pDrawLayer
->AddCalcUndo( std::make_unique
<SdrUndoGeoObj
>( *mxCaption
) );
299 // calculate new caption rectangle (#i98141# handle LTR<->RTL switch correctly)
300 tools::Rectangle aCaptRect
= mxCaption
->GetLogicRect();
301 tools::Long nDiffX
= (rOldTailPos
.X() >= 0) ? (aCaptRect
.Left() - rOldTailPos
.X()) : (rOldTailPos
.X() - aCaptRect
.Right());
302 if( mbNegPage
) nDiffX
= -nDiffX
- aCaptRect
.GetWidth();
303 tools::Long nDiffY
= aCaptRect
.Top() - rOldTailPos
.Y();
304 aCaptRect
.SetPos( aTailPos
+ Point( nDiffX
, nDiffY
) );
305 // set new tail position and caption rectangle
306 mxCaption
->SetTailPos( aTailPos
);
307 mxCaption
->SetLogicRect( aCaptRect
);
308 // fit caption into draw page
312 // update cell position in caption user data
313 ScDrawObjData
* pCaptData
= ScDrawLayer::GetNoteCaptionData( mxCaption
.get(), maPos
.Tab() );
314 if( pCaptData
&& (maPos
!= pCaptData
->maStart
) )
316 // create drawing undo action
317 if( pDrawLayer
&& pDrawLayer
->IsRecording() )
318 pDrawLayer
->AddCalcUndo( std::make_unique
<ScUndoObjData
>( mxCaption
.get(), pCaptData
->maStart
, pCaptData
->maEnd
, maPos
, pCaptData
->maEnd
) );
320 pCaptData
->maStart
= maPos
;
324 Point
ScCaptionCreator::CalcTailPos( bool bTailFront
)
327 bool bTailLeft
= bTailFront
!= mbNegPage
;
328 Point aTailPos
= bTailLeft
? maCellRect
.TopLeft() : maCellRect
.TopRight();
329 // move caption point 1/10 mm inside cell
330 if( bTailLeft
) aTailPos
.AdjustX(10 ); else aTailPos
.AdjustX( -10 );
331 aTailPos
.AdjustY(10);
335 void ScCaptionCreator::CreateCaption( bool bShown
, bool bTailFront
)
337 // create the caption drawing object
338 tools::Rectangle
aTextRect( Point( 0 , 0 ), Size( SC_NOTECAPTION_WIDTH
, SC_NOTECAPTION_HEIGHT
) );
339 Point aTailPos
= CalcTailPos( bTailFront
);
342 *mrDoc
.GetDrawLayer(), // TTTT should ret a ref?
345 // basic caption settings
346 ScCaptionUtil::SetBasicCaptionSettings( *mxCaption
, bShown
);
349 void ScCaptionCreator::Initialize()
351 maCellRect
= ScDrawLayer::GetCellRect( mrDoc
, maPos
, true );
352 mbNegPage
= mrDoc
.IsNegativePage( maPos
.Tab() );
353 if( SdrPage
* pDrawPage
= GetDrawPage() )
355 maPageRect
= tools::Rectangle( Point( 0, 0 ), pDrawPage
->GetSize() );
356 /* #i98141# SdrPage::GetSize() returns negative width in RTL mode.
357 The call to Rectangle::Adjust() orders left/right coordinate
359 maPageRect
.Normalize();
363 /** Helper for creation of permanent caption drawing objects for cell notes. */
364 class ScNoteCaptionCreator
: public ScCaptionCreator
367 /** Create a new caption object and inserts it into the document. */
368 explicit ScNoteCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, ScNoteData
& rNoteData
);
369 /** Manipulate an existing caption. */
370 explicit ScNoteCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, rtl::Reference
<SdrCaptionObj
>& xCaption
, bool bShown
);
373 ScNoteCaptionCreator::ScNoteCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, ScNoteData
& rNoteData
) :
374 ScCaptionCreator( rDoc
, rPos
) // use helper c'tor that does not create the caption yet
376 SdrPage
* pDrawPage
= GetDrawPage();
377 OSL_ENSURE( pDrawPage
, "ScNoteCaptionCreator::ScNoteCaptionCreator - no drawing page" );
381 // create the caption drawing object
382 CreateCaption( rNoteData
.mbShown
, false );
383 rNoteData
.mxCaption
= GetCaption();
384 OSL_ENSURE( rNoteData
.mxCaption
, "ScNoteCaptionCreator::ScNoteCaptionCreator - missing caption object" );
385 if( rNoteData
.mxCaption
)
387 // store note position in user data of caption object
388 ScCaptionUtil::SetCaptionUserData( *rNoteData
.mxCaption
, rPos
);
389 // insert object into draw page
390 pDrawPage
->InsertObject( rNoteData
.mxCaption
.get() );
394 ScNoteCaptionCreator::ScNoteCaptionCreator( ScDocument
& rDoc
, const ScAddress
& rPos
, rtl::Reference
<SdrCaptionObj
>& xCaption
, bool bShown
) :
395 ScCaptionCreator( rDoc
, rPos
, xCaption
)
397 SdrPage
* pDrawPage
= GetDrawPage();
398 OSL_ENSURE( pDrawPage
, "ScNoteCaptionCreator::ScNoteCaptionCreator - no drawing page" );
399 OSL_ENSURE( xCaption
->getSdrPageFromSdrObject() == pDrawPage
, "ScNoteCaptionCreator::ScNoteCaptionCreator - wrong drawing page in caption" );
400 if( pDrawPage
&& (xCaption
->getSdrPageFromSdrObject() == pDrawPage
) )
402 // store note position in user data of caption object
403 ScCaptionUtil::SetCaptionUserData( *xCaption
, rPos
);
404 // basic caption settings
405 ScCaptionUtil::SetBasicCaptionSettings( *xCaption
, bShown
);
406 // set correct tail position
407 xCaption
->SetTailPos( CalcTailPos( false ) );
413 struct ScCaptionInitData
415 std::optional
< SfxItemSet
> moItemSet
; /// Caption object formatting.
416 std::optional
< OutlinerParaObject
> mxOutlinerObj
; /// Text object with all text portion formatting.
417 std::unique_ptr
< GenerateNoteCaption
> mxGenerator
; /// Operator to generate Caption Object from import data
418 OUString maStyleName
; /// Drawing style associated with the caption object.
419 OUString maSimpleText
; /// Simple text without formatting.
420 Point maCaptionOffset
; /// Caption position relative to cell corner.
421 Size maCaptionSize
; /// Size of the caption object.
422 bool mbDefaultPosSize
; /// True = use default position and size for caption.
424 explicit ScCaptionInitData();
427 ScCaptionInitData::ScCaptionInitData() :
428 mbDefaultPosSize( true )
432 ScNoteData::ScNoteData( bool bShown
) :
437 sal_uInt32
ScPostIt::mnLastPostItId
= 1;
439 ScPostIt::ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, sal_uInt32 nPostItId
) :
443 mnPostItId
= nPostItId
== 0 ? mnLastPostItId
++ : nPostItId
;
445 CreateCaption( rPos
);
448 ScPostIt::ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, const ScPostIt
& rNote
, sal_uInt32 nPostItId
) :
450 maNoteData( rNote
.maNoteData
)
452 mnPostItId
= nPostItId
== 0 ? mnLastPostItId
++ : nPostItId
;
453 maNoteData
.mxCaption
.clear();
454 CreateCaption( rPos
, rNote
.maNoteData
.mxCaption
.get() );
457 ScPostIt::ScPostIt( ScDocument
& rDoc
, const ScAddress
& rPos
, ScNoteData aNoteData
, bool bAlwaysCreateCaption
, sal_uInt32 nPostItId
) :
459 maNoteData(std::move( aNoteData
))
461 mnPostItId
= nPostItId
== 0 ? mnLastPostItId
++ : nPostItId
;
462 if( bAlwaysCreateCaption
|| maNoteData
.mbShown
)
463 CreateCaptionFromInitData( rPos
);
466 ScPostIt::~ScPostIt()
471 std::unique_ptr
<ScPostIt
> ScPostIt::Clone( const ScAddress
& rOwnPos
, ScDocument
& rDestDoc
, const ScAddress
& rDestPos
, bool bCloneCaption
) const
473 // tdf#117307: Don't clone comment, if it is in the same position in the same document
474 const bool bIsSameDoc
= mrDoc
.GetPool() == rDestDoc
.GetPool();
475 if (bIsSameDoc
&& !mrDoc
.IsClipboard() && rOwnPos
== rDestPos
)
476 bCloneCaption
= false;
477 CreateCaptionFromInitData( rOwnPos
);
478 sal_uInt32 nPostItId
= comphelper::LibreOfficeKit::isActive() ? 0 : mnPostItId
;
479 return bCloneCaption
? std::make_unique
<ScPostIt
>( rDestDoc
, rDestPos
, *this, nPostItId
) : std::make_unique
<ScPostIt
>( rDestDoc
, rDestPos
, maNoteData
, false, mnPostItId
);
482 void ScPostIt::SetDate( const OUString
& rDate
)
484 maNoteData
.maDate
= rDate
;
487 void ScPostIt::SetAuthor( const OUString
& rAuthor
)
489 maNoteData
.maAuthor
= rAuthor
;
492 void ScPostIt::AutoStamp(bool bCreate
)
496 DateTime
aNow(DateTime::SYSTEM
);
497 auto const & rLocaleData
= ScGlobal::getLocaleData();
498 maNoteData
.maDate
= rLocaleData
.getDate(aNow
) + " " + rLocaleData
.getTime(aNow
, false);
500 if (!maNoteData
.maAuthor
.isEmpty())
502 const OUString aAuthor
= SvtUserOptions().GetFullName();
503 maNoteData
.maAuthor
= !aAuthor
.isEmpty() ? aAuthor
: ScResId(STR_CHG_UNKNOWN_AUTHOR
);
506 const OutlinerParaObject
* ScPostIt::GetOutlinerObject() const
508 if( maNoteData
.mxCaption
)
509 return maNoteData
.mxCaption
->GetOutlinerParaObject();
510 if( maNoteData
.mxInitData
&& maNoteData
.mxInitData
->mxOutlinerObj
)
511 return &*maNoteData
.mxInitData
->mxOutlinerObj
;
515 const EditTextObject
* ScPostIt::GetEditTextObject() const
517 const OutlinerParaObject
* pOPO
= GetOutlinerObject();
518 return pOPO
? &pOPO
->GetTextObject() : nullptr;
521 OUString
ScPostIt::GetText() const
523 if( const EditTextObject
* pEditObj
= GetEditTextObject() )
525 OUStringBuffer aBuffer
;
526 ScNoteEditEngine
& rEngine
= mrDoc
.GetNoteEngine();
527 rEngine
.SetTextCurrentDefaults(*pEditObj
);
528 sal_Int32 nParaCount
= rEngine
.GetParagraphCount();
529 for( sal_Int32 nPara
= 0; nPara
< nParaCount
; ++nPara
)
532 aBuffer
.append( '\n' );
533 aBuffer
.append(rEngine
.GetText(nPara
));
535 return aBuffer
.makeStringAndClear();
537 if( maNoteData
.mxInitData
)
538 return maNoteData
.mxInitData
->maSimpleText
;
542 void ScPostIt::SetText( const ScAddress
& rPos
, const OUString
& rText
)
544 CreateCaptionFromInitData( rPos
);
545 if( maNoteData
.mxCaption
)
546 maNoteData
.mxCaption
->SetText( rText
);
549 SdrCaptionObj
* ScPostIt::GetOrCreateCaption( const ScAddress
& rPos
) const
551 CreateCaptionFromInitData( rPos
);
552 return maNoteData
.mxCaption
.get();
555 void ScPostIt::ForgetCaption( bool bPreserveData
)
559 // Used in clipboard when the originating document is destructed to be
560 // able to paste into another document. Caption size and relative
561 // position are not preserved but default created when pasted. Also the
562 // MergedItemSet can not be carried over or it had to be adapted to
563 // defaults and pool. At least preserve the text and outline object if
565 ScCaptionInitData
* pInitData
= new ScCaptionInitData
;
566 const OutlinerParaObject
* pOPO
= GetOutlinerObject();
568 pInitData
->mxOutlinerObj
= *pOPO
;
569 pInitData
->maSimpleText
= GetText();
571 maNoteData
.mxInitData
.reset(pInitData
);
572 maNoteData
.mxCaption
.clear();
576 /* This function is used in undo actions to give up the responsibility for
577 the caption object which is handled by separate drawing undo actions. */
578 maNoteData
.mxCaption
.clear();
579 maNoteData
.mxInitData
.reset();
583 void ScPostIt::ShowCaption( const ScAddress
& rPos
, bool bShow
)
585 CreateCaptionFromInitData( rPos
);
586 // no separate drawing undo needed, handled completely inside ScUndoShowHideNote
587 maNoteData
.mbShown
= bShow
;
588 if( maNoteData
.mxCaption
)
589 ScCaptionUtil::SetCaptionLayer( *maNoteData
.mxCaption
, bShow
);
592 void ScPostIt::ShowCaptionTemp( const ScAddress
& rPos
, bool bShow
)
594 CreateCaptionFromInitData( rPos
);
595 if( maNoteData
.mxCaption
)
596 ScCaptionUtil::SetCaptionLayer( *maNoteData
.mxCaption
, maNoteData
.mbShown
|| bShow
);
599 void ScPostIt::UpdateCaptionPos( const ScAddress
& rPos
)
601 CreateCaptionFromInitData( rPos
);
602 if( maNoteData
.mxCaption
)
604 ScCaptionCreator
aCreator( mrDoc
, rPos
, maNoteData
.mxCaption
);
605 aCreator
.UpdateCaptionPos();
609 // private --------------------------------------------------------------------
611 void ScPostIt::CreateCaptionFromInitData( const ScAddress
& rPos
) const
613 // Captions are not created in Undo documents and only rarely in Clipboard,
614 // but otherwise we need caption or initial data.
615 assert((maNoteData
.mxCaption
|| maNoteData
.mxInitData
) || mrDoc
.IsUndo() || mrDoc
.IsClipboard());
616 if( !maNoteData
.mxInitData
)
620 /* This function is called from ScPostIt::Clone() when copying cells
621 to the clipboard/undo document, and when copying cells from the
622 clipboard/undo document. The former should always be called first,
623 so if called in a clipboard/undo document, the caption should have
624 been created already. However, for clipboard in case the
625 originating document was destructed a new caption has to be
627 OSL_ENSURE( !mrDoc
.IsUndo() && (!mrDoc
.IsClipboard() || !maNoteData
.mxCaption
),
628 "ScPostIt::CreateCaptionFromInitData - note caption should not be created in undo/clip documents" );
630 // going to forget the initial caption data struct when this method returns
631 auto xInitData
= std::move(maNoteData
.mxInitData
);
633 /* #i104915# Never try to create notes in Undo document, leads to
634 crash due to missing document members (e.g. row height array). */
635 if( maNoteData
.mxCaption
|| mrDoc
.IsUndo() )
638 if (mrDoc
.IsClipboard())
639 mrDoc
.InitDrawLayer(); // ensure there is a drawing layer
641 // ScNoteCaptionCreator c'tor creates the caption and inserts it into the document and maNoteData
642 ScNoteCaptionCreator
aCreator( mrDoc
, rPos
, maNoteData
);
643 if( !maNoteData
.mxCaption
)
646 // Prevent triple change broadcasts of the same object.
647 bool bWasLocked
= maNoteData
.mxCaption
->getSdrModelFromSdrObject().isLocked();
648 maNoteData
.mxCaption
->getSdrModelFromSdrObject().setLock(true);
650 if (xInitData
->mxGenerator
)
651 xInitData
->mxGenerator
->Generate(*maNoteData
.mxCaption
);
654 // transfer ownership of outliner object to caption, or set simple text
655 OSL_ENSURE( xInitData
->mxOutlinerObj
|| !xInitData
->maSimpleText
.isEmpty(),
656 "ScPostIt::CreateCaptionFromInitData - need either outliner para object or simple text" );
657 if (xInitData
->mxOutlinerObj
)
658 maNoteData
.mxCaption
->NbcSetOutlinerParaObjectForText(
659 std::move(xInitData
->mxOutlinerObj
),
660 maNoteData
.mxCaption
->getActiveText(),
661 /*bAdjustTextFrameWidthAndHeight*/false );
663 maNoteData
.mxCaption
->SetText( xInitData
->maSimpleText
);
666 if (!xInitData
->maStyleName
.isEmpty())
668 if (auto pStyleSheet
= mrDoc
.GetStyleSheetPool()->Find(xInitData
->maStyleName
, SfxStyleFamily::Frame
))
669 maNoteData
.mxCaption
->NbcSetStyleSheet(static_cast<SfxStyleSheet
*>(pStyleSheet
), true, /*bAdjustTextFrameWidthAndHeight*/false);
671 if (xInitData
->moItemSet
)
672 maNoteData
.mxCaption
->SetMergedItemSet(*xInitData
->moItemSet
,
673 /*bClearAllItems*/false, /*bAdjustTextFrameWidthAndHeight*/false);
677 if (auto pStyleSheet
= mrDoc
.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE
), SfxStyleFamily::Frame
))
678 maNoteData
.mxCaption
->NbcSetStyleSheet(static_cast<SfxStyleSheet
*>(pStyleSheet
), true, /*bAdjustTextFrameWidthAndHeight*/false);
680 // copy all items and reset shadow items
681 if (xInitData
->moItemSet
)
682 ScCaptionUtil::SetExtraItems(*maNoteData
.mxCaption
, *xInitData
->moItemSet
);
685 // set position and size of the caption object
686 if( xInitData
->mbDefaultPosSize
)
688 // set other items and fit caption size to text
689 maNoteData
.mxCaption
->SetMergedItem( makeSdrTextMinFrameWidthItem( SC_NOTECAPTION_WIDTH
) );
690 maNoteData
.mxCaption
->SetMergedItem( makeSdrTextMaxFrameWidthItem( SC_NOTECAPTION_MAXWIDTH_TEMP
) );
691 maNoteData
.mxCaption
->AdjustTextFrameWidthAndHeight();
692 aCreator
.AutoPlaceCaption();
696 tools::Rectangle aCellRect
= ScDrawLayer::GetCellRect( mrDoc
, rPos
, true );
697 bool bNegPage
= mrDoc
.IsNegativePage( rPos
.Tab() );
698 tools::Long nPosX
= bNegPage
? (aCellRect
.Left() - xInitData
->maCaptionOffset
.X()) : (aCellRect
.Right() + xInitData
->maCaptionOffset
.X());
699 tools::Long nPosY
= aCellRect
.Top() + xInitData
->maCaptionOffset
.Y();
700 tools::Rectangle
aCaptRect( Point( nPosX
, nPosY
), xInitData
->maCaptionSize
);
701 maNoteData
.mxCaption
->NbcSetLogicRect( aCaptRect
, /*bAdaptTextMinSize*/false );
702 aCreator
.FitCaptionToRect();
705 // End prevent triple change broadcasts of the same object.
706 maNoteData
.mxCaption
->getSdrModelFromSdrObject().setLock(bWasLocked
);
707 maNoteData
.mxCaption
->BroadcastObjectChange();
710 void ScPostIt::CreateCaption( const ScAddress
& rPos
, const SdrCaptionObj
* pCaption
)
712 OSL_ENSURE( !maNoteData
.mxCaption
, "ScPostIt::CreateCaption - unexpected caption object found" );
713 maNoteData
.mxCaption
.clear();
715 /* #i104915# Never try to create notes in Undo document, leads to
716 crash due to missing document members (e.g. row height array). */
717 OSL_ENSURE( !mrDoc
.IsUndo(), "ScPostIt::CreateCaption - note caption should not be created in undo documents" );
721 // drawing layer may be missing, if a note is copied into a clipboard document
722 if( mrDoc
.IsClipboard() )
723 mrDoc
.InitDrawLayer();
725 // ScNoteCaptionCreator c'tor creates the caption and inserts it into the document and maNoteData
726 ScNoteCaptionCreator
aCreator( mrDoc
, rPos
, maNoteData
);
727 if( !maNoteData
.mxCaption
)
730 // clone settings of passed caption
733 // copy edit text object (object must be inserted into page already)
734 if( OutlinerParaObject
* pOPO
= pCaption
->GetOutlinerParaObject() )
735 maNoteData
.mxCaption
->SetOutlinerParaObject( *pOPO
);
736 // copy formatting items (after text has been copied to apply font formatting)
737 if (auto pStyleSheet
= pCaption
->GetStyleSheet())
739 auto pPool
= mrDoc
.GetStyleSheetPool();
740 pPool
->CopyStyleFrom(pStyleSheet
->GetPool(), pStyleSheet
->GetName(), pStyleSheet
->GetFamily(), true);
742 if (auto pDestStyleSheet
= pPool
->Find(pStyleSheet
->GetName(), pStyleSheet
->GetFamily()))
743 maNoteData
.mxCaption
->SetStyleSheet(static_cast<SfxStyleSheet
*>(pDestStyleSheet
), true);
745 maNoteData
.mxCaption
->SetMergedItemSetAndBroadcast( pCaption
->GetMergedItemSet() );
746 // move textbox position relative to new cell, copy textbox size
747 tools::Rectangle aCaptRect
= pCaption
->GetLogicRect();
748 Point aDist
= maNoteData
.mxCaption
->GetTailPos() - pCaption
->GetTailPos();
749 aCaptRect
.Move( aDist
.X(), aDist
.Y() );
750 maNoteData
.mxCaption
->SetLogicRect( aCaptRect
);
751 aCreator
.FitCaptionToRect();
755 if (auto pStyleSheet
= mrDoc
.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE
), SfxStyleFamily::Frame
))
756 maNoteData
.mxCaption
->SetStyleSheet(static_cast<SfxStyleSheet
*>(pStyleSheet
), true);
757 // set default size, undoing sdr::TextProperties::SetStyleSheet's
758 // adjustment that use a wrong min height.
759 tools::Rectangle aCaptRect
= maNoteData
.mxCaption
->GetLogicRect();
760 aCaptRect
.SetSize({ SC_NOTECAPTION_WIDTH
, SC_NOTECAPTION_HEIGHT
});
761 maNoteData
.mxCaption
->SetLogicRect(aCaptRect
);
762 // set default position
763 aCreator
.AutoPlaceCaption();
766 // create undo action
767 if( ScDrawLayer
* pDrawLayer
= mrDoc
.GetDrawLayer() )
768 if( pDrawLayer
->IsRecording() )
769 pDrawLayer
->AddCalcUndo( std::make_unique
<SdrUndoNewObj
>( *maNoteData
.mxCaption
) );
772 void ScPostIt::RemoveCaption()
774 if (!maNoteData
.mxCaption
)
777 /* Remove caption object only, if this note is its owner (e.g. notes in
778 undo documents refer to captions in original document, do not remove
779 them from drawing layer here). */
780 // TTTT maybe no longer needed - can that still happen?
781 ScDrawLayer
* pDrawLayer
= mrDoc
.GetDrawLayer();
782 if (pDrawLayer
== &maNoteData
.mxCaption
->getSdrModelFromSdrObject())
784 SdrPage
* pDrawPage(maNoteData
.mxCaption
->getSdrPageFromSdrObject());
785 SAL_WARN_IF( !pDrawPage
, "sc.core", "ScCaptionPtr::removeFromDrawPageAndFree - object without drawing page");
788 pDrawPage
->RecalcObjOrdNums();
789 // create drawing undo action (before removing the object to have valid draw page in undo action)
790 if (pDrawLayer
->IsRecording())
791 pDrawLayer
->AddCalcUndo( std::make_unique
<SdrUndoDelObj
>( *maNoteData
.mxCaption
));
792 // remove the object from the drawing page
793 rtl::Reference
<SdrObject
> pRemovedObj
= pDrawPage
->RemoveObject( maNoteData
.mxCaption
->GetOrdNum() );
794 assert(pRemovedObj
.get() == maNoteData
.mxCaption
.get()); (void)pRemovedObj
;
798 SAL_INFO("sc.core","ScPostIt::RemoveCaption -"
799 " IsUndo: " << mrDoc
.IsUndo() << " IsClip: " << mrDoc
.IsClipboard() <<
800 " Dtor: " << mrDoc
.IsInDtorClear());
802 // Forget the caption object if removeFromDrawPageAndFree() did not free it.
803 if (maNoteData
.mxCaption
)
805 SAL_INFO("sc.core","ScPostIt::RemoveCaption - forgetting one ref");
806 maNoteData
.mxCaption
.clear();
810 static void lcl_FormatAndInsertAuthorAndDatepara(SdrCaptionObj
* pCaption
, OUStringBuffer
& aUserData
, bool bUserWithTrackText
)
812 uno::Reference
<drawing::XShape
> xShape
= pCaption
->getUnoShape();
813 uno::Reference
<text::XText
> xText(xShape
, uno::UNO_QUERY
);
814 uno::Reference
<text::XTextAppend
> xBodyTextAppend(xText
, uno::UNO_QUERY
);
816 if (xBodyTextAppend
.is())
818 uno::Sequence
< beans::PropertyValue
> aArgs
;
819 if (bUserWithTrackText
)
821 xBodyTextAppend
->insertTextPortion(aUserData
.makeStringAndClear(), aArgs
, xText
->getStart());
825 xBodyTextAppend
->insertTextPortion(u
"\n--------\n"_ustr
, aArgs
, xText
->getStart());
827 comphelper::makePropertyValue(u
"CharWeight"_ustr
, uno::Any(awt::FontWeight::BOLD
)),
829 xBodyTextAppend
->insertTextPortion(aUserData
.makeStringAndClear(), aArgs
, xText
->getStart());
834 rtl::Reference
<SdrCaptionObj
> ScNoteUtil::CreateTempCaption(
835 ScDocument
& rDoc
, const ScAddress
& rPos
, SdrPage
& rDrawPage
,
836 std::u16string_view rUserText
, const tools::Rectangle
& rVisRect
, bool bTailFront
)
838 bool bUserWithTrackText
= false;
839 OUStringBuffer
aBuffer( rUserText
);
840 // add plain text of invisible (!) cell note (no formatting etc.)
841 SdrCaptionObj
* pNoteCaption
= nullptr;
842 const ScPostIt
* pNote
= rDoc
.GetNote( rPos
);
843 if( pNote
&& !pNote
->IsCaptionShown() )
845 if (!aBuffer
.isEmpty())
847 bUserWithTrackText
= true;
848 aBuffer
.append("\n--------\n");
852 aBuffer
.append(pNote
->GetAuthor()
853 + (!pNote
->GetDate().isEmpty() ? ", " + pNote
->GetDate() : OUString()));
855 pNoteCaption
= pNote
->GetOrCreateCaption( rPos
);
858 // prepare visible rectangle (add default distance to all borders)
859 tools::Rectangle
aVisRect(
860 rVisRect
.Left() + SC_NOTECAPTION_BORDERDIST_TEMP
,
861 rVisRect
.Top() + SC_NOTECAPTION_BORDERDIST_TEMP
,
862 rVisRect
.Right() - SC_NOTECAPTION_BORDERDIST_TEMP
,
863 rVisRect
.Bottom() - SC_NOTECAPTION_BORDERDIST_TEMP
);
865 // create the caption object
866 ScCaptionCreator
aCreator( rDoc
, rPos
, bTailFront
);
868 // insert caption into page (needed to set caption text)
869 rtl::Reference
<SdrCaptionObj
> pCaption
= aCreator
.GetCaption(); // just for ease of use
870 rDrawPage
.InsertObject( pCaption
.get() );
872 // clone the edit text object, then seta and format the Author and date text
875 if( OutlinerParaObject
* pOPO
= pNoteCaption
->GetOutlinerParaObject() )
876 pCaption
->SetOutlinerParaObject( *pOPO
);
877 // Setting and formatting rUserText: Author name and date time
878 if (officecfg::Office::Calc::Content::Display::NoteAuthor::get())
879 lcl_FormatAndInsertAuthorAndDatepara(pCaption
.get(), aBuffer
, bUserWithTrackText
);
880 // set formatting (must be done after setting text) and resize the box to fit the text
881 if (auto pStyleSheet
= pNoteCaption
->GetStyleSheet())
882 pCaption
->SetStyleSheet(pStyleSheet
, true);
883 pCaption
->SetMergedItemSetAndBroadcast(pNoteCaption
->GetMergedItemSet());
887 pCaption
->SetText(aBuffer
.makeStringAndClear());
888 if (auto pStyleSheet
= rDoc
.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE
), SfxStyleFamily::Frame
))
889 pCaption
->SetStyleSheet(static_cast<SfxStyleSheet
*>(pStyleSheet
), true);
892 // adjust caption size to text size
893 tools::Long nMaxWidth
= ::std::min
< tools::Long
>( aVisRect
.GetWidth() * 2 / 3, SC_NOTECAPTION_MAXWIDTH_TEMP
);
894 pCaption
->SetMergedItem( makeSdrTextAutoGrowWidthItem( true ) );
895 pCaption
->SetMergedItem( makeSdrTextMinFrameWidthItem( SC_NOTECAPTION_WIDTH
) );
896 pCaption
->SetMergedItem( makeSdrTextMaxFrameWidthItem( nMaxWidth
) );
897 pCaption
->SetMergedItem( makeSdrTextAutoGrowHeightItem( true ) );
898 pCaption
->AdjustTextFrameWidthAndHeight();
900 // move caption into visible area
901 aCreator
.AutoPlaceCaption( &aVisRect
);
903 // XXX Note it is already inserted to the draw page.
904 return aCreator
.GetCaption();
907 ScPostIt
* ScNoteUtil::CreateNoteFromCaption(
908 ScDocument
& rDoc
, const ScAddress
& rPos
, SdrCaptionObj
* pCaption
, bool bHasStyle
)
910 ScNoteData
aNoteData( true/*bShown*/ );
911 aNoteData
.mxCaption
= pCaption
;
912 ScPostIt
* pNote
= new ScPostIt( rDoc
, rPos
, aNoteData
, false );
915 rDoc
.SetNote(rPos
, std::unique_ptr
<ScPostIt
>(pNote
));
917 // ScNoteCaptionCreator c'tor updates the caption object to be part of a note
918 ScNoteCaptionCreator
aCreator( rDoc
, rPos
, aNoteData
.mxCaption
, true/*bShown*/ );
922 if (auto pStyleSheet
= rDoc
.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE
), SfxStyleFamily::Frame
))
923 aNoteData
.mxCaption
->SetStyleSheet(static_cast<SfxStyleSheet
*>(pStyleSheet
), true);
925 /* We used to show a shadow despite of the shadow item being set to false.
926 Clear the existing item, so it inherits the true setting from the style.
927 Setting explicitly to true would corrupt the shadow when opened in older versions. */
928 aNoteData
.mxCaption
->ClearMergedItem(SDRATTR_SHADOW
);
934 ScNoteData
ScNoteUtil::CreateNoteData(ScDocument
& rDoc
, const ScAddress
& rPos
,
935 const tools::Rectangle
& rCaptionRect
, bool bShown
)
937 ScNoteData
aNoteData( bShown
);
938 aNoteData
.mxInitData
= std::make_shared
<ScCaptionInitData
>();
939 ScCaptionInitData
& rInitData
= *aNoteData
.mxInitData
;
941 // convert absolute caption position to relative position
942 rInitData
.mbDefaultPosSize
= rCaptionRect
.IsEmpty();
943 if( !rInitData
.mbDefaultPosSize
)
945 tools::Rectangle aCellRect
= ScDrawLayer::GetCellRect( rDoc
, rPos
, true );
946 bool bNegPage
= rDoc
.IsNegativePage( rPos
.Tab() );
947 rInitData
.maCaptionOffset
.setX( bNegPage
? (aCellRect
.Left() - rCaptionRect
.Right()) : (rCaptionRect
.Left() - aCellRect
.Right()) );
948 rInitData
.maCaptionOffset
.setY( rCaptionRect
.Top() - aCellRect
.Top() );
949 rInitData
.maCaptionSize
= rCaptionRect
.GetSize();
955 ScPostIt
* ScNoteUtil::CreateNoteFromObjectData(
956 ScDocument
& rDoc
, const ScAddress
& rPos
, const SfxItemSet
& rItemSet
, const OUString
& rStyleName
,
957 const OutlinerParaObject
& rOutlinerObj
, const tools::Rectangle
& rCaptionRect
,
960 ScNoteData
aNoteData(CreateNoteData(rDoc
, rPos
, rCaptionRect
, bShown
));
961 ScCaptionInitData
& rInitData
= *aNoteData
.mxInitData
;
962 rInitData
.mxOutlinerObj
= rOutlinerObj
;
963 rInitData
.moItemSet
.emplace(rItemSet
);
964 rInitData
.maStyleName
= ScStyleNameConversion::ProgrammaticToDisplayName(rStyleName
, SfxStyleFamily::Frame
);
966 return InsertNote(rDoc
, rPos
, std::move(aNoteData
), /*bAlwaysCreateCaption*/false, 0/*nPostItId*/);
969 ScPostIt
* ScNoteUtil::CreateNoteFromGenerator(
970 ScDocument
& rDoc
, const ScAddress
& rPos
,
971 std::unique_ptr
<GenerateNoteCaption
> xGenerator
,
972 const tools::Rectangle
& rCaptionRect
,
975 ScNoteData
aNoteData(CreateNoteData(rDoc
, rPos
, rCaptionRect
, bShown
));
976 ScCaptionInitData
& rInitData
= *aNoteData
.mxInitData
;
977 rInitData
.mxGenerator
= std::move(xGenerator
);
978 // because the Caption is generated on demand, we will need to create the
979 // simple text now to supply any queries for that which don't require
980 // creation of a full Caption
981 rInitData
.maSimpleText
= rInitData
.mxGenerator
->GetSimpleText();
982 aNoteData
.maAuthor
= rInitData
.mxGenerator
->GetAuthorName();
983 return InsertNote(rDoc
, rPos
, std::move(aNoteData
), /*bAlwaysCreateCaption*/ false,
984 0 /*nPostItId*/, false /*bShouldAutoStamp*/);
987 ScPostIt
* ScNoteUtil::InsertNote(ScDocument
& rDoc
, const ScAddress
& rPos
, ScNoteData
&& rNoteData
,
988 bool bAlwaysCreateCaption
, sal_uInt32 nPostItId
,
989 bool bShouldAutoStamp
)
991 /* Create the note and insert it into the document. If the note is
992 visible, the caption object will be created automatically. */
993 ScPostIt
* pNote
= new ScPostIt( rDoc
, rPos
, std::move(rNoteData
), bAlwaysCreateCaption
, nPostItId
);
994 pNote
->AutoStamp(bShouldAutoStamp
);
995 //insert takes ownership
996 rDoc
.SetNote(rPos
, std::unique_ptr
<ScPostIt
>(pNote
));
1000 ScPostIt
* ScNoteUtil::CreateNoteFromString(
1001 ScDocument
& rDoc
, const ScAddress
& rPos
, const OUString
& rNoteText
,
1002 bool bShown
, bool bAlwaysCreateCaption
, sal_uInt32 nPostItId
)
1004 ScPostIt
* pNote
= nullptr;
1005 if( !rNoteText
.isEmpty() )
1007 ScNoteData
aNoteData( bShown
);
1008 aNoteData
.mxInitData
= std::make_shared
<ScCaptionInitData
>();
1009 ScCaptionInitData
& rInitData
= *aNoteData
.mxInitData
;
1010 rInitData
.maSimpleText
= rNoteText
;
1011 rInitData
.maStyleName
= ScResId(STR_STYLENAME_NOTE
);
1012 rInitData
.mbDefaultPosSize
= true;
1014 pNote
= InsertNote(rDoc
, rPos
, std::move(aNoteData
), bAlwaysCreateCaption
, nPostItId
);
1021 NoteEntry::NoteEntry( const ScAddress
& rPos
, const ScPostIt
* pNote
) :
1022 maPos(rPos
), mpNote(pNote
) {}
1026 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */