LibreOffice Module sc (master) 1
postit.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <memory>
21#include <postit.hxx>
22
23#include <rtl/ustrbuf.hxx>
24#include <sal/log.hxx>
26#include <svx/svdpage.hxx>
27#include <svx/svdocapt.hxx>
28#include <editeng/outlobj.hxx>
29#include <editeng/editobj.hxx>
31#include <osl/diagnose.h>
32#include <comphelper/lok.hxx>
33
34#include <scitems.hxx>
35#include <svx/xfillit0.hxx>
36#include <svx/xlnstit.hxx>
37#include <svx/xlnstwit.hxx>
38#include <svx/xlnstcit.hxx>
39#include <svx/sxcecitm.hxx>
40#include <svx/xflclit.hxx>
41#include <svx/sdshitm.hxx>
42#include <svx/sdsxyitm.hxx>
43#include <svx/sdtditm.hxx>
44#include <svx/sdtagitm.hxx>
45#include <svx/sdtmfitm.hxx>
46#include <tools/gen.hxx>
47
48#include <document.hxx>
49#include <docpool.hxx>
50#include <stlpool.hxx>
51#include <stylehelper.hxx>
52#include <patattr.hxx>
53#include <drwlayer.hxx>
54#include <userdat.hxx>
55#include <detfunc.hxx>
56#include <editutil.hxx>
57#include <globstr.hrc>
58#include <scresid.hxx>
59#include <utility>
60#include <strings.hrc>
61
62#include <com/sun/star/text/XText.hpp>
63#include <com/sun/star/text/XTextAppend.hpp>
64#include <com/sun/star/beans/XPropertySet.hpp>
65#include <com/sun/star/awt/FontWeight.hpp>
67
68using namespace com::sun::star;
69
70namespace {
71
72const tools::Long SC_NOTECAPTION_WIDTH = 2900;
73const tools::Long SC_NOTECAPTION_MAXWIDTH_TEMP = 12000;
74const tools::Long SC_NOTECAPTION_HEIGHT = 1800;
75const tools::Long SC_NOTECAPTION_CELLDIST = 600;
76const tools::Long SC_NOTECAPTION_OFFSET_Y = -1500;
77const tools::Long SC_NOTECAPTION_OFFSET_X = 1500;
78const tools::Long SC_NOTECAPTION_BORDERDIST_TEMP = 100;
79
81class ScCaptionUtil
82{
83public:
85 static void SetCaptionLayer( SdrCaptionObj& rCaption, bool bShown );
87 static void SetBasicCaptionSettings( SdrCaptionObj& rCaption, bool bShown );
89 static void SetCaptionUserData( SdrCaptionObj& rCaption, const ScAddress& rPos );
91 static void SetExtraItems( SdrCaptionObj& rCaption, const SfxItemSet& rExtraItemSet );
92};
93
94void ScCaptionUtil::SetCaptionLayer( SdrCaptionObj& rCaption, bool bShown )
95{
96 SdrLayerID nLayer = bShown ? SC_LAYER_INTERN : SC_LAYER_HIDDEN;
97 if( nLayer != rCaption.GetLayer() )
98 rCaption.SetLayer( nLayer );
99}
100
101void ScCaptionUtil::SetBasicCaptionSettings( SdrCaptionObj& rCaption, bool bShown )
102{
103 rCaption.SetFixedTail();
104 rCaption.SetSpecialTextBoxShadow();
105 SetCaptionLayer( rCaption, bShown );
106}
107
108void ScCaptionUtil::SetCaptionUserData( SdrCaptionObj& rCaption, const ScAddress& rPos )
109{
110 // pass true to ScDrawLayer::GetObjData() to create the object data entry
111 ScDrawObjData* pObjData = ScDrawLayer::GetObjData( &rCaption, true );
112 OSL_ENSURE( pObjData, "ScCaptionUtil::SetCaptionUserData - missing drawing object user data" );
113 pObjData->maStart = rPos;
115}
116
117void ScCaptionUtil::SetExtraItems( SdrCaptionObj& rCaption, const SfxItemSet& rExtraItemSet )
118{
119 SfxItemSet aItemSet = rCaption.GetMergedItemSet();
120
121 aItemSet.Put(rExtraItemSet);
122 // reset shadow visibility (see also ScNoteUtil::CreateNoteFromCaption)
123 aItemSet.ClearItem(SDRATTR_SHADOW);
124 // ... but not distance, as that will fallback to wrong values
125 // if the comment is shown and then opened in older versions:
126 aItemSet.Put( makeSdrShadowXDistItem( 100 ) );
127 aItemSet.Put( makeSdrShadowYDistItem( 100 ) );
128
129 rCaption.SetMergedItemSet( aItemSet );
130}
131
134class ScCaptionCreator
135{
136public:
138 explicit ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, bool bTailFront );
140 explicit ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, const rtl::Reference<SdrCaptionObj>& xCaption );
141
143 SdrPage* GetDrawPage();
145 rtl::Reference<SdrCaptionObj> & GetCaption() { return mxCaption; }
146
148 void FitCaptionToRect( const tools::Rectangle* pVisRect = nullptr );
150 void AutoPlaceCaption( const tools::Rectangle* pVisRect = nullptr );
152 void UpdateCaptionPos();
153
154protected:
156 explicit ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos );
157
159 Point CalcTailPos( bool bTailFront );
161 void CreateCaption( bool bShown, bool bTailFront );
162
163private:
165 void Initialize();
167 const tools::Rectangle& GetVisRect( const tools::Rectangle* pVisRect ) const { return pVisRect ? *pVisRect : maPageRect; }
168
169private:
170 ScDocument& mrDoc;
171 ScAddress maPos;
173 tools::Rectangle maPageRect;
174 tools::Rectangle maCellRect;
175 bool mbNegPage;
176};
177
178ScCaptionCreator::ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, bool bTailFront ) :
179 mrDoc( rDoc ),
180 maPos( rPos )
181{
182 Initialize();
183 CreateCaption( true/*bShown*/, bTailFront );
184}
185
186ScCaptionCreator::ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, const rtl::Reference<SdrCaptionObj>& xCaption ) :
187 mrDoc( rDoc ),
188 maPos( rPos ),
189 mxCaption( xCaption )
190{
191 Initialize();
192}
193
194ScCaptionCreator::ScCaptionCreator( ScDocument& rDoc, const ScAddress& rPos ) :
195 mrDoc( rDoc ),
196 maPos( rPos )
197{
198 Initialize();
199}
200
201SdrPage* ScCaptionCreator::GetDrawPage()
202{
203 ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer();
204 return pDrawLayer ? pDrawLayer->GetPage( static_cast< sal_uInt16 >( maPos.Tab() ) ) : nullptr;
205}
206
207void ScCaptionCreator::FitCaptionToRect( const tools::Rectangle* pVisRect )
208{
209 const tools::Rectangle& rVisRect = GetVisRect( pVisRect );
210
211 // tail position
212 Point aTailPos = mxCaption->GetTailPos();
213 aTailPos.setX( ::std::clamp( aTailPos.X(), rVisRect.Left(), rVisRect.Right() ) );
214 aTailPos.setY( ::std::clamp( aTailPos.Y(), rVisRect.Top(), rVisRect.Bottom() ) );
215 mxCaption->SetTailPos( aTailPos );
216
217 // caption rectangle
218 tools::Rectangle aCaptRect = mxCaption->GetLogicRect();
219 Point aCaptPos = aCaptRect.TopLeft();
220 // move textbox inside right border of visible area
221 aCaptPos.setX( ::std::min< tools::Long >( aCaptPos.X(), rVisRect.Right() - aCaptRect.GetWidth() ) );
222 // move textbox inside left border of visible area (this may move it outside on right side again)
223 aCaptPos.setX( ::std::max< tools::Long >( aCaptPos.X(), rVisRect.Left() ) );
224 // move textbox inside bottom border of visible area
225 aCaptPos.setY( ::std::min< tools::Long >( aCaptPos.Y(), rVisRect.Bottom() - aCaptRect.GetHeight() ) );
226 // move textbox inside top border of visible area (this may move it outside on bottom side again)
227 aCaptPos.setY( ::std::max< tools::Long >( aCaptPos.Y(), rVisRect.Top() ) );
228 // update caption
229 aCaptRect.SetPos( aCaptPos );
230 mxCaption->SetLogicRect( aCaptRect );
231}
232
233void ScCaptionCreator::AutoPlaceCaption( const tools::Rectangle* pVisRect )
234{
235 const tools::Rectangle& rVisRect = GetVisRect( pVisRect );
236
237 // caption rectangle
238 tools::Rectangle aCaptRect = mxCaption->GetLogicRect();
239 tools::Long nWidth = aCaptRect.GetWidth();
240 tools::Long nHeight = aCaptRect.GetHeight();
241
242 // n***Space contains available space between border of visible area and cell
243 tools::Long nLeftSpace = maCellRect.Left() - rVisRect.Left() + 1;
244 tools::Long nRightSpace = rVisRect.Right() - maCellRect.Right() + 1;
245 tools::Long nTopSpace = maCellRect.Top() - rVisRect.Top() + 1;
246 tools::Long nBottomSpace = rVisRect.Bottom() - maCellRect.Bottom() + 1;
247
248 // nNeeded*** contains textbox dimensions plus needed distances to cell or border of visible area
249 tools::Long nNeededSpaceX = nWidth + SC_NOTECAPTION_CELLDIST;
250 tools::Long nNeededSpaceY = nHeight + SC_NOTECAPTION_CELLDIST;
251
252 // bFitsWidth*** == true means width of textbox fits into horizontal free space of visible area
253 bool bFitsWidthLeft = nNeededSpaceX <= nLeftSpace; // text box width fits into the width left of cell
254 bool bFitsWidthRight = nNeededSpaceX <= nRightSpace; // text box width fits into the width right of cell
255 bool bFitsWidth = nWidth <= rVisRect.GetWidth(); // text box width fits into width of visible area
256
257 // bFitsHeight*** == true means height of textbox fits into vertical free space of visible area
258 bool bFitsHeightTop = nNeededSpaceY <= nTopSpace; // text box height fits into the height above cell
259 bool bFitsHeightBottom = nNeededSpaceY <= nBottomSpace; // text box height fits into the height below cell
260 bool bFitsHeight = nHeight <= rVisRect.GetHeight(); // text box height fits into height of visible area
261
262 // bFits*** == true means the textbox fits completely into free space of visible area
263 bool bFitsLeft = bFitsWidthLeft && bFitsHeight;
264 bool bFitsRight = bFitsWidthRight && bFitsHeight;
265 bool bFitsTop = bFitsWidth && bFitsHeightTop;
266 bool bFitsBottom = bFitsWidth && bFitsHeightBottom;
267
268 Point aCaptPos;
269 // use left/right placement if possible, or if top/bottom placement not possible
270 if( bFitsLeft || bFitsRight || (!bFitsTop && !bFitsBottom) )
271 {
272 // prefer left in RTL sheet and right in LTR sheets
273 bool bPreferLeft = bFitsLeft && (mbNegPage || !bFitsRight);
274 bool bPreferRight = bFitsRight && (!mbNegPage || !bFitsLeft);
275 // move to left, if left is preferred, or if neither left nor right fit and there is more space to the left
276 if( bPreferLeft || (!bPreferRight && (nLeftSpace > nRightSpace)) )
277 aCaptPos.setX( maCellRect.Left() - SC_NOTECAPTION_CELLDIST - nWidth );
278 else // to right
279 aCaptPos.setX( maCellRect.Right() + SC_NOTECAPTION_CELLDIST );
280 // Y position according to top cell border
281 aCaptPos.setY( maCellRect.Top() + SC_NOTECAPTION_OFFSET_Y );
282 }
283 else // top or bottom placement
284 {
285 // X position
286 aCaptPos.setX( maCellRect.Left() + SC_NOTECAPTION_OFFSET_X );
287 // top placement, if possible
288 if( bFitsTop )
289 aCaptPos.setY( maCellRect.Top() - SC_NOTECAPTION_CELLDIST - nHeight );
290 else // bottom placement
291 aCaptPos.setY( maCellRect.Bottom() + SC_NOTECAPTION_CELLDIST );
292 }
293
294 // update textbox position in note caption object
295 aCaptRect.SetPos( aCaptPos );
296 mxCaption->SetLogicRect( aCaptRect );
297 FitCaptionToRect( pVisRect );
298}
299
300void ScCaptionCreator::UpdateCaptionPos()
301{
302 ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer();
303
304 // update caption position
305 const Point& rOldTailPos = mxCaption->GetTailPos();
306 Point aTailPos = CalcTailPos( false );
307 if( rOldTailPos != aTailPos )
308 {
309 // create drawing undo action
310 if( pDrawLayer && pDrawLayer->IsRecording() )
311 pDrawLayer->AddCalcUndo( std::make_unique<SdrUndoGeoObj>( *mxCaption ) );
312 // calculate new caption rectangle (#i98141# handle LTR<->RTL switch correctly)
313 tools::Rectangle aCaptRect = mxCaption->GetLogicRect();
314 tools::Long nDiffX = (rOldTailPos.X() >= 0) ? (aCaptRect.Left() - rOldTailPos.X()) : (rOldTailPos.X() - aCaptRect.Right());
315 if( mbNegPage ) nDiffX = -nDiffX - aCaptRect.GetWidth();
316 tools::Long nDiffY = aCaptRect.Top() - rOldTailPos.Y();
317 aCaptRect.SetPos( aTailPos + Point( nDiffX, nDiffY ) );
318 // set new tail position and caption rectangle
319 mxCaption->SetTailPos( aTailPos );
320 mxCaption->SetLogicRect( aCaptRect );
321 // fit caption into draw page
322 FitCaptionToRect();
323 }
324
325 // update cell position in caption user data
326 ScDrawObjData* pCaptData = ScDrawLayer::GetNoteCaptionData( mxCaption.get(), maPos.Tab() );
327 if( pCaptData && (maPos != pCaptData->maStart) )
328 {
329 // create drawing undo action
330 if( pDrawLayer && pDrawLayer->IsRecording() )
331 pDrawLayer->AddCalcUndo( std::make_unique<ScUndoObjData>( mxCaption.get(), pCaptData->maStart, pCaptData->maEnd, maPos, pCaptData->maEnd ) );
332 // set new position
333 pCaptData->maStart = maPos;
334 }
335}
336
337Point ScCaptionCreator::CalcTailPos( bool bTailFront )
338{
339 // tail position
340 bool bTailLeft = bTailFront != mbNegPage;
341 Point aTailPos = bTailLeft ? maCellRect.TopLeft() : maCellRect.TopRight();
342 // move caption point 1/10 mm inside cell
343 if( bTailLeft ) aTailPos.AdjustX(10 ); else aTailPos.AdjustX( -10 );
344 aTailPos.AdjustY(10);
345 return aTailPos;
346}
347
348void ScCaptionCreator::CreateCaption( bool bShown, bool bTailFront )
349{
350 // create the caption drawing object
351 tools::Rectangle aTextRect( Point( 0 , 0 ), Size( SC_NOTECAPTION_WIDTH, SC_NOTECAPTION_HEIGHT ) );
352 Point aTailPos = CalcTailPos( bTailFront );
353 mxCaption =
354 new SdrCaptionObj(
355 *mrDoc.GetDrawLayer(), // TTTT should ret a ref?
356 aTextRect,
357 aTailPos);
358 // basic caption settings
359 ScCaptionUtil::SetBasicCaptionSettings( *mxCaption, bShown );
360}
361
362void ScCaptionCreator::Initialize()
363{
364 maCellRect = ScDrawLayer::GetCellRect( mrDoc, maPos, true );
365 mbNegPage = mrDoc.IsNegativePage( maPos.Tab() );
366 if( SdrPage* pDrawPage = GetDrawPage() )
367 {
368 maPageRect = tools::Rectangle( Point( 0, 0 ), pDrawPage->GetSize() );
369 /* #i98141# SdrPage::GetSize() returns negative width in RTL mode.
370 The call to Rectangle::Adjust() orders left/right coordinate
371 accordingly. */
372 maPageRect.Normalize();
373 }
374}
375
377class ScNoteCaptionCreator : public ScCaptionCreator
378{
379public:
381 explicit ScNoteCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, ScNoteData& rNoteData );
383 explicit ScNoteCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, rtl::Reference<SdrCaptionObj>& xCaption, bool bShown );
384};
385
386ScNoteCaptionCreator::ScNoteCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, ScNoteData& rNoteData ) :
387 ScCaptionCreator( rDoc, rPos ) // use helper c'tor that does not create the caption yet
388{
389 SdrPage* pDrawPage = GetDrawPage();
390 OSL_ENSURE( pDrawPage, "ScNoteCaptionCreator::ScNoteCaptionCreator - no drawing page" );
391 if( !pDrawPage )
392 return;
393
394 // create the caption drawing object
395 CreateCaption( rNoteData.mbShown, false );
396 rNoteData.mxCaption = GetCaption();
397 OSL_ENSURE( rNoteData.mxCaption, "ScNoteCaptionCreator::ScNoteCaptionCreator - missing caption object" );
398 if( rNoteData.mxCaption )
399 {
400 // store note position in user data of caption object
401 ScCaptionUtil::SetCaptionUserData( *rNoteData.mxCaption, rPos );
402 // insert object into draw page
403 pDrawPage->InsertObject( rNoteData.mxCaption.get() );
404 }
405}
406
407ScNoteCaptionCreator::ScNoteCaptionCreator( ScDocument& rDoc, const ScAddress& rPos, rtl::Reference<SdrCaptionObj>& xCaption, bool bShown ) :
408 ScCaptionCreator( rDoc, rPos, xCaption )
409{
410 SdrPage* pDrawPage = GetDrawPage();
411 OSL_ENSURE( pDrawPage, "ScNoteCaptionCreator::ScNoteCaptionCreator - no drawing page" );
412 OSL_ENSURE( xCaption->getSdrPageFromSdrObject() == pDrawPage, "ScNoteCaptionCreator::ScNoteCaptionCreator - wrong drawing page in caption" );
413 if( pDrawPage && (xCaption->getSdrPageFromSdrObject() == pDrawPage) )
414 {
415 // store note position in user data of caption object
416 ScCaptionUtil::SetCaptionUserData( *xCaption, rPos );
417 // basic caption settings
418 ScCaptionUtil::SetBasicCaptionSettings( *xCaption, bShown );
419 // set correct tail position
420 xCaption->SetTailPos( CalcTailPos( false ) );
421 }
422}
423
424} // namespace
425
426
428{
429 std::optional< SfxItemSet > moItemSet;
431 OUString maStyleName;
432 OUString maSimpleText;
436
437 explicit ScCaptionInitData();
438};
439
441 mbDefaultPosSize( true )
442{
443}
444
446 mbShown( bShown )
447{
448}
449
450sal_uInt32 ScPostIt::mnLastPostItId = 1;
451
452ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, sal_uInt32 nPostItId ) :
453 mrDoc( rDoc ),
454 maNoteData( false )
455{
456 mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
457 AutoStamp();
458 CreateCaption( rPos );
459}
460
461ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, const ScPostIt& rNote, sal_uInt32 nPostItId ) :
462 mrDoc( rDoc ),
463 maNoteData( rNote.maNoteData )
464{
465 mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
466 maNoteData.mxCaption.clear();
467 CreateCaption( rPos, rNote.maNoteData.mxCaption.get() );
468}
469
470ScPostIt::ScPostIt( ScDocument& rDoc, const ScAddress& rPos, ScNoteData aNoteData, bool bAlwaysCreateCaption, sal_uInt32 nPostItId ) :
471 mrDoc( rDoc ),
472 maNoteData(std::move( aNoteData ))
473{
474 mnPostItId = nPostItId == 0 ? mnLastPostItId++ : nPostItId;
475 if( bAlwaysCreateCaption || maNoteData.mbShown )
477}
478
480{
482}
483
484std::unique_ptr<ScPostIt> ScPostIt::Clone( const ScAddress& rOwnPos, ScDocument& rDestDoc, const ScAddress& rDestPos, bool bCloneCaption ) const
485{
486 // tdf#117307: Don't clone comment, if it is in the same position
487 if ( (rOwnPos == rDestPos) && !mrDoc.IsClipboard() )
488 bCloneCaption = false;
489 CreateCaptionFromInitData( rOwnPos );
490 sal_uInt32 nPostItId = comphelper::LibreOfficeKit::isActive() ? 0 : mnPostItId;
491 return bCloneCaption ? std::make_unique<ScPostIt>( rDestDoc, rDestPos, *this, nPostItId ) : std::make_unique<ScPostIt>( rDestDoc, rDestPos, maNoteData, false, mnPostItId );
492}
493
494void ScPostIt::SetDate( const OUString& rDate )
495{
496 maNoteData.maDate = rDate;
497}
498
499void ScPostIt::SetAuthor( const OUString& rAuthor )
500{
501 maNoteData.maAuthor = rAuthor;
502}
503
505{
508 const OUString aAuthor = SvtUserOptions().GetFullName();
509 maNoteData.maAuthor = !aAuthor.isEmpty() ? aAuthor : ScResId(STR_CHG_UNKNOWN_AUTHOR);
510}
511
513{
515 return maNoteData.mxCaption->GetOutlinerParaObject();
516 if( maNoteData.mxInitData && maNoteData.mxInitData->mxOutlinerObj )
517 return &*maNoteData.mxInitData->mxOutlinerObj;
518 return nullptr;
519}
520
522{
524 return pOPO ? &pOPO->GetTextObject() : nullptr;
525}
526
527OUString ScPostIt::GetText() const
528{
529 if( const EditTextObject* pEditObj = GetEditTextObject() )
530 {
531 OUStringBuffer aBuffer;
533 rEngine.SetTextCurrentDefaults(*pEditObj);
534 sal_Int32 nParaCount = rEngine.GetParagraphCount();
535 for( sal_Int32 nPara = 0; nPara < nParaCount; ++nPara )
536 {
537 if( nPara > 0 )
538 aBuffer.append( '\n' );
539 aBuffer.append(rEngine.GetText(nPara));
540 }
541 return aBuffer.makeStringAndClear();
542 }
544 return maNoteData.mxInitData->maSimpleText;
545 return OUString();
546}
547
548void ScPostIt::SetText( const ScAddress& rPos, const OUString& rText )
549{
552 maNoteData.mxCaption->SetText( rText );
553}
554
556{
558 return maNoteData.mxCaption.get();
559}
560
561void ScPostIt::ForgetCaption( bool bPreserveData )
562{
563 if (bPreserveData)
564 {
565 // Used in clipboard when the originating document is destructed to be
566 // able to paste into another document. Caption size and relative
567 // position are not preserved but default created when pasted. Also the
568 // MergedItemSet can not be carried over or it had to be adapted to
569 // defaults and pool. At least preserve the text and outline object if
570 // possible.
571 ScCaptionInitData* pInitData = new ScCaptionInitData;
573 if (pOPO)
574 pInitData->mxOutlinerObj = *pOPO;
575 pInitData->maSimpleText = GetText();
576
577 maNoteData.mxInitData.reset(pInitData);
578 maNoteData.mxCaption.clear();
579 }
580 else
581 {
582 /* This function is used in undo actions to give up the responsibility for
583 the caption object which is handled by separate drawing undo actions. */
584 maNoteData.mxCaption.clear();
585 maNoteData.mxInitData.reset();
586 }
587}
588
589void ScPostIt::ShowCaption( const ScAddress& rPos, bool bShow )
590{
592 // no separate drawing undo needed, handled completely inside ScUndoShowHideNote
593 maNoteData.mbShown = bShow;
595 ScCaptionUtil::SetCaptionLayer( *maNoteData.mxCaption, bShow );
596}
597
598void ScPostIt::ShowCaptionTemp( const ScAddress& rPos, bool bShow )
599{
602 ScCaptionUtil::SetCaptionLayer( *maNoteData.mxCaption, maNoteData.mbShown || bShow );
603}
604
606{
609 {
610 ScCaptionCreator aCreator( mrDoc, rPos, maNoteData.mxCaption );
611 aCreator.UpdateCaptionPos();
612 }
613}
614
615// private --------------------------------------------------------------------
616
618{
619 // Captions are not created in Undo documents and only rarely in Clipboard,
620 // but otherwise we need caption or initial data.
623 return;
624
625
626 /* This function is called from ScPostIt::Clone() when copying cells
627 to the clipboard/undo document, and when copying cells from the
628 clipboard/undo document. The former should always be called first,
629 so if called in a clipboard/undo document, the caption should have
630 been created already. However, for clipboard in case the
631 originating document was destructed a new caption has to be
632 created. */
633 OSL_ENSURE( !mrDoc.IsUndo() && (!mrDoc.IsClipboard() || !maNoteData.mxCaption),
634 "ScPostIt::CreateCaptionFromInitData - note caption should not be created in undo/clip documents" );
635
636 // going to forget the initial caption data struct when this method returns
637 auto xInitData = std::move(maNoteData.mxInitData);
638
639 /* #i104915# Never try to create notes in Undo document, leads to
640 crash due to missing document members (e.g. row height array). */
642 return;
643
644 if (mrDoc.IsClipboard())
645 mrDoc.InitDrawLayer(); // ensure there is a drawing layer
646
647 // ScNoteCaptionCreator c'tor creates the caption and inserts it into the document and maNoteData
648 ScNoteCaptionCreator aCreator( mrDoc, rPos, maNoteData );
649 if( !maNoteData.mxCaption )
650 return;
651
652 // Prevent triple change broadcasts of the same object.
653 bool bWasLocked = maNoteData.mxCaption->getSdrModelFromSdrObject().isLocked();
654 maNoteData.mxCaption->getSdrModelFromSdrObject().setLock(true);
655
656 // transfer ownership of outliner object to caption, or set simple text
657 OSL_ENSURE( xInitData->mxOutlinerObj || !xInitData->maSimpleText.isEmpty(),
658 "ScPostIt::CreateCaptionFromInitData - need either outliner para object or simple text" );
659 if (xInitData->mxOutlinerObj)
660 maNoteData.mxCaption->SetOutlinerParaObject( std::move(xInitData->mxOutlinerObj) );
661 else
662 maNoteData.mxCaption->SetText( xInitData->maSimpleText );
663
664 if (!xInitData->maStyleName.isEmpty())
665 {
666 if (auto pStyleSheet = mrDoc.GetStyleSheetPool()->Find(xInitData->maStyleName, SfxStyleFamily::Frame))
667 maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true);
668
669 if (xInitData->moItemSet)
670 maNoteData.mxCaption->SetMergedItemSet(*xInitData->moItemSet);
671 }
672 else
673 {
674 if (auto pStyleSheet = mrDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame))
675 maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true);
676
677 // copy all items and reset shadow items
678 if (xInitData->moItemSet)
679 ScCaptionUtil::SetExtraItems(*maNoteData.mxCaption, *xInitData->moItemSet);
680 }
681
682 // set position and size of the caption object
683 if( xInitData->mbDefaultPosSize )
684 {
685 // set other items and fit caption size to text
686 maNoteData.mxCaption->SetMergedItem( makeSdrTextMinFrameWidthItem( SC_NOTECAPTION_WIDTH ) );
687 maNoteData.mxCaption->SetMergedItem( makeSdrTextMaxFrameWidthItem( SC_NOTECAPTION_MAXWIDTH_TEMP ) );
688 maNoteData.mxCaption->AdjustTextFrameWidthAndHeight();
689 aCreator.AutoPlaceCaption();
690 }
691 else
692 {
693 tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( mrDoc, rPos, true );
694 bool bNegPage = mrDoc.IsNegativePage( rPos.Tab() );
695 tools::Long nPosX = bNegPage ? (aCellRect.Left() - xInitData->maCaptionOffset.X()) : (aCellRect.Right() + xInitData->maCaptionOffset.X());
696 tools::Long nPosY = aCellRect.Top() + xInitData->maCaptionOffset.Y();
697 tools::Rectangle aCaptRect( Point( nPosX, nPosY ), xInitData->maCaptionSize );
698 maNoteData.mxCaption->SetLogicRect( aCaptRect );
699 aCreator.FitCaptionToRect();
700 }
701
702 // End prevent triple change broadcasts of the same object.
703 maNoteData.mxCaption->getSdrModelFromSdrObject().setLock(bWasLocked);
704 maNoteData.mxCaption->BroadcastObjectChange();
705}
706
707void ScPostIt::CreateCaption( const ScAddress& rPos, const SdrCaptionObj* pCaption )
708{
709 OSL_ENSURE( !maNoteData.mxCaption, "ScPostIt::CreateCaption - unexpected caption object found" );
710 maNoteData.mxCaption.clear();
711
712 /* #i104915# Never try to create notes in Undo document, leads to
713 crash due to missing document members (e.g. row height array). */
714 OSL_ENSURE( !mrDoc.IsUndo(), "ScPostIt::CreateCaption - note caption should not be created in undo documents" );
715 if( mrDoc.IsUndo() )
716 return;
717
718 // drawing layer may be missing, if a note is copied into a clipboard document
719 if( mrDoc.IsClipboard() )
721
722 // ScNoteCaptionCreator c'tor creates the caption and inserts it into the document and maNoteData
723 ScNoteCaptionCreator aCreator( mrDoc, rPos, maNoteData );
724 if( !maNoteData.mxCaption )
725 return;
726
727 // clone settings of passed caption
728 if( pCaption )
729 {
730 // copy edit text object (object must be inserted into page already)
731 if( OutlinerParaObject* pOPO = pCaption->GetOutlinerParaObject() )
732 maNoteData.mxCaption->SetOutlinerParaObject( *pOPO );
733 // copy formatting items (after text has been copied to apply font formatting)
734 if (auto pStyleSheet = pCaption->GetStyleSheet())
735 {
736 auto pPool = mrDoc.GetStyleSheetPool();
737 pPool->CopyStyleFrom(pStyleSheet->GetPool(), pStyleSheet->GetName(), pStyleSheet->GetFamily(), true);
738
739 if (auto pDestStyleSheet = pPool->Find(pStyleSheet->GetName(), pStyleSheet->GetFamily()))
740 maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pDestStyleSheet), true);
741 }
742 maNoteData.mxCaption->SetMergedItemSetAndBroadcast( pCaption->GetMergedItemSet() );
743 // move textbox position relative to new cell, copy textbox size
744 tools::Rectangle aCaptRect = pCaption->GetLogicRect();
745 Point aDist = maNoteData.mxCaption->GetTailPos() - pCaption->GetTailPos();
746 aCaptRect.Move( aDist.X(), aDist.Y() );
747 maNoteData.mxCaption->SetLogicRect( aCaptRect );
748 aCreator.FitCaptionToRect();
749 }
750 else
751 {
752 if (auto pStyleSheet = mrDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame))
753 maNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true);
754 // set default size, undoing sdr::TextProperties::SetStyleSheet's
755 // adjustment that use a wrong min height.
756 tools::Rectangle aCaptRect = maNoteData.mxCaption->GetLogicRect();
757 aCaptRect.SetSize({ SC_NOTECAPTION_WIDTH, SC_NOTECAPTION_HEIGHT });
758 maNoteData.mxCaption->SetLogicRect(aCaptRect);
759 // set default position
760 aCreator.AutoPlaceCaption();
761 }
762
763 // create undo action
764 if( ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer() )
765 if( pDrawLayer->IsRecording() )
766 pDrawLayer->AddCalcUndo( std::make_unique<SdrUndoNewObj>( *maNoteData.mxCaption ) );
767}
768
770{
772 return;
773
774 /* Remove caption object only, if this note is its owner (e.g. notes in
775 undo documents refer to captions in original document, do not remove
776 them from drawing layer here). */
777 // TTTT maybe no longer needed - can that still happen?
778 ScDrawLayer* pDrawLayer = mrDoc.GetDrawLayer();
779 if (pDrawLayer == &maNoteData.mxCaption->getSdrModelFromSdrObject())
780 {
781 SdrPage* pDrawPage(maNoteData.mxCaption->getSdrPageFromSdrObject());
782 SAL_WARN_IF( !pDrawPage, "sc.core", "ScCaptionPtr::removeFromDrawPageAndFree - object without drawing page");
783 if (pDrawPage)
784 {
785 pDrawPage->RecalcObjOrdNums();
786 // create drawing undo action (before removing the object to have valid draw page in undo action)
787 bool bRecording = (pDrawLayer && pDrawLayer->IsRecording());
788 if (bRecording)
789 pDrawLayer->AddCalcUndo( std::make_unique<SdrUndoDelObj>( *maNoteData.mxCaption ));
790 // remove the object from the drawing page
791 rtl::Reference<SdrObject> pRemovedObj = pDrawPage->RemoveObject( maNoteData.mxCaption->GetOrdNum() );
792 assert(pRemovedObj.get() == maNoteData.mxCaption.get()); (void)pRemovedObj;
793 }
794 }
795
796 SAL_INFO("sc.core","ScPostIt::RemoveCaption -"
797 " IsUndo: " << mrDoc.IsUndo() << " IsClip: " << mrDoc.IsClipboard() <<
798 " Dtor: " << mrDoc.IsInDtorClear());
799
800 // Forget the caption object if removeFromDrawPageAndFree() did not free it.
802 {
803 SAL_INFO("sc.core","ScPostIt::RemoveCaption - forgetting one ref");
804 maNoteData.mxCaption.clear();
805 }
806}
807
808static void lcl_FormatAndInsertAuthorAndDatepara(SdrCaptionObj* pCaption, OUStringBuffer& aUserData, bool bUserWithTrackText)
809{
810 uno::Reference<drawing::XShape> xShape = pCaption->getUnoShape();
811 uno::Reference<text::XText> xText(xShape, uno::UNO_QUERY);
812 uno::Reference<text::XTextAppend> xBodyTextAppend(xText, uno::UNO_QUERY);
813
814 if (xBodyTextAppend.is())
815 {
816 uno::Sequence< beans::PropertyValue > aArgs;
817 if (bUserWithTrackText)
818 {
819 xBodyTextAppend->insertTextPortion(aUserData.makeStringAndClear(), aArgs, xText->getStart());
820 }
821 else
822 {
823 xBodyTextAppend->insertTextPortion("\n--------\n", aArgs, xText->getStart());
824 aArgs = {
825 comphelper::makePropertyValue("CharWeight", uno::Any(awt::FontWeight::BOLD)),
826 };
827 xBodyTextAppend->insertTextPortion(aUserData.makeStringAndClear(), aArgs, xText->getStart());
828 }
829 }
830}
831
833 ScDocument& rDoc, const ScAddress& rPos, SdrPage& rDrawPage,
834 std::u16string_view rUserText, const tools::Rectangle& rVisRect, bool bTailFront )
835{
836 bool bUserWithTrackText = false;
837 OUStringBuffer aBuffer( rUserText );
838 // add plain text of invisible (!) cell note (no formatting etc.)
839 SdrCaptionObj* pNoteCaption = nullptr;
840 const ScPostIt* pNote = rDoc.GetNote( rPos );
841 if( pNote && !pNote->IsCaptionShown() )
842 {
843 if (!aBuffer.isEmpty())
844 {
845 bUserWithTrackText = true;
846 aBuffer.append("\n--------\n");
847 }
848 else
849 {
850 aBuffer.append(pNote->GetAuthor()
851 + ", "
852 + pNote->GetDate());
853 }
854 pNoteCaption = pNote->GetOrCreateCaption( rPos );
855 }
856
857 // prepare visible rectangle (add default distance to all borders)
858 tools::Rectangle aVisRect(
859 rVisRect.Left() + SC_NOTECAPTION_BORDERDIST_TEMP,
860 rVisRect.Top() + SC_NOTECAPTION_BORDERDIST_TEMP,
861 rVisRect.Right() - SC_NOTECAPTION_BORDERDIST_TEMP,
862 rVisRect.Bottom() - SC_NOTECAPTION_BORDERDIST_TEMP );
863
864 // create the caption object
865 ScCaptionCreator aCreator( rDoc, rPos, bTailFront );
866
867 // insert caption into page (needed to set caption text)
868 rtl::Reference<SdrCaptionObj> pCaption = aCreator.GetCaption(); // just for ease of use
869 rDrawPage.InsertObject( pCaption.get() );
870
871 // clone the edit text object, then seta and format the Author and date text
872 if (pNoteCaption)
873 {
874 if( OutlinerParaObject* pOPO = pNoteCaption->GetOutlinerParaObject() )
875 pCaption->SetOutlinerParaObject( *pOPO );
876 // Setting and formatting rUserText: Author name and date time
877 lcl_FormatAndInsertAuthorAndDatepara(pCaption.get(), aBuffer, bUserWithTrackText);
878 // set formatting (must be done after setting text) and resize the box to fit the text
879 if (auto pStyleSheet = pNoteCaption->GetStyleSheet())
880 pCaption->SetStyleSheet(pStyleSheet, true);
881 pCaption->SetMergedItemSetAndBroadcast(pNoteCaption->GetMergedItemSet());
882 }
883 else
884 {
885 pCaption->SetText(aBuffer.makeStringAndClear());
886 if (auto pStyleSheet = rDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame))
887 pCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true);
888 }
889
890 // adjust caption size to text size
891 tools::Long nMaxWidth = ::std::min< tools::Long >( aVisRect.GetWidth() * 2 / 3, SC_NOTECAPTION_MAXWIDTH_TEMP );
892 pCaption->SetMergedItem( makeSdrTextAutoGrowWidthItem( true ) );
893 pCaption->SetMergedItem( makeSdrTextMinFrameWidthItem( SC_NOTECAPTION_WIDTH ) );
894 pCaption->SetMergedItem( makeSdrTextMaxFrameWidthItem( nMaxWidth ) );
895 pCaption->SetMergedItem( makeSdrTextAutoGrowHeightItem( true ) );
896 pCaption->AdjustTextFrameWidthAndHeight();
897
898 // move caption into visible area
899 aCreator.AutoPlaceCaption( &aVisRect );
900
901 // XXX Note it is already inserted to the draw page.
902 return aCreator.GetCaption();
903}
904
906 ScDocument& rDoc, const ScAddress& rPos, SdrCaptionObj* pCaption, bool bHasStyle )
907{
908 ScNoteData aNoteData( true/*bShown*/ );
909 aNoteData.mxCaption = pCaption;
910 ScPostIt* pNote = new ScPostIt( rDoc, rPos, aNoteData, false );
911 pNote->AutoStamp();
912
913 rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
914
915 // ScNoteCaptionCreator c'tor updates the caption object to be part of a note
916 ScNoteCaptionCreator aCreator( rDoc, rPos, aNoteData.mxCaption, true/*bShown*/ );
917
918 if (!bHasStyle)
919 {
920 if (auto pStyleSheet = rDoc.GetStyleSheetPool()->Find(ScResId(STR_STYLENAME_NOTE), SfxStyleFamily::Frame))
921 aNoteData.mxCaption->SetStyleSheet(static_cast<SfxStyleSheet*>(pStyleSheet), true);
922
923 /* We used to show a shadow despite of the shadow item being set to false.
924 Clear the existing item, so it inherits the true setting from the style.
925 Setting explicitly to true would corrupt the shadow when opened in older versions. */
926 aNoteData.mxCaption->ClearMergedItem(SDRATTR_SHADOW);
927 }
928
929 return pNote;
930}
931
933 ScDocument& rDoc, const ScAddress& rPos, SfxItemSet&& rItemSet, const OUString& rStyleName,
934 const OutlinerParaObject& rOutlinerObj, const tools::Rectangle& rCaptionRect,
935 bool bShown )
936{
937 ScNoteData aNoteData( bShown );
938 aNoteData.mxInitData = std::make_shared<ScCaptionInitData>();
939 ScCaptionInitData& rInitData = *aNoteData.mxInitData;
940 rInitData.moItemSet.emplace(std::move(rItemSet));
941 rInitData.mxOutlinerObj = rOutlinerObj;
942 rInitData.maStyleName = ScStyleNameConversion::ProgrammaticToDisplayName(rStyleName, SfxStyleFamily::Frame);
943
944 // convert absolute caption position to relative position
945 rInitData.mbDefaultPosSize = rCaptionRect.IsEmpty();
946 if( !rInitData.mbDefaultPosSize )
947 {
948 tools::Rectangle aCellRect = ScDrawLayer::GetCellRect( rDoc, rPos, true );
949 bool bNegPage = rDoc.IsNegativePage( rPos.Tab() );
950 rInitData.maCaptionOffset.setX( bNegPage ? (aCellRect.Left() - rCaptionRect.Right()) : (rCaptionRect.Left() - aCellRect.Right()) );
951 rInitData.maCaptionOffset.setY( rCaptionRect.Top() - aCellRect.Top() );
952 rInitData.maCaptionSize = rCaptionRect.GetSize();
953 }
954
955 /* Create the note and insert it into the document. If the note is
956 visible, the caption object will be created automatically. */
957 ScPostIt* pNote = new ScPostIt( rDoc, rPos, std::move(aNoteData), /*bAlwaysCreateCaption*/false, 0/*nPostItId*/ );
958 pNote->AutoStamp();
959
960 rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
961
962 return pNote;
963}
964
966 ScDocument& rDoc, const ScAddress& rPos, const OUString& rNoteText,
967 bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId )
968{
969 ScPostIt* pNote = nullptr;
970 if( !rNoteText.isEmpty() )
971 {
972 ScNoteData aNoteData( bShown );
973 aNoteData.mxInitData = std::make_shared<ScCaptionInitData>();
974 ScCaptionInitData& rInitData = *aNoteData.mxInitData;
975 rInitData.maSimpleText = rNoteText;
976 rInitData.maStyleName = ScResId(STR_STYLENAME_NOTE);
977 rInitData.mbDefaultPosSize = true;
978
979 /* Create the note and insert it into the document. If the note is
980 visible, the caption object will be created automatically. */
981 pNote = new ScPostIt( rDoc, rPos, std::move(aNoteData), bAlwaysCreateCaption, nPostItId );
982 pNote->AutoStamp();
983 //insert takes ownership
984 rDoc.SetNote(rPos, std::unique_ptr<ScPostIt>(pNote));
985 }
986 return pNote;
987}
988
989namespace sc {
990
991NoteEntry::NoteEntry( const ScAddress& rPos, const ScPostIt* pNote ) :
992 maPos(rPos), mpNote(pNote) {}
993
994}
995
996/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetText(LineEnd eEnd=LINEEND_LF) const
sal_Int32 GetParagraphCount() const
OUString getDate(const Date &rDate) const
OUString getTime(const tools::Time &rTime, bool bSec=true, bool b100Sec=false) const
const EditTextObject & GetTextObject() const
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
SCTAB Tab() const
Definition: address.hxx:283
bool IsUndo() const
Definition: document.hxx:1593
void SetNote(const ScAddress &rPos, std::unique_ptr< ScPostIt > pNote)
Definition: document.cxx:6599
SC_DLLPUBLIC void InitDrawLayer(SfxObjectShell *pDocShell=nullptr)
Definition: documen9.cxx:105
bool IsClipboard() const
Definition: document.hxx:1594
SC_DLLPUBLIC ScPostIt * GetNote(const ScAddress &rPos)
Definition: document.cxx:6587
SC_DLLPUBLIC bool IsNegativePage(SCTAB nTab) const
Definition: document.cxx:982
SC_DLLPUBLIC ScDrawLayer * GetDrawLayer()
Definition: document.hxx:1084
SC_DLLPUBLIC ScNoteEditEngine & GetNoteEngine()
Definition: documen2.cxx:496
SC_DLLPUBLIC ScStyleSheetPool * GetStyleSheetPool() const
Definition: document.cxx:6055
bool IsInDtorClear() const
Definition: document.hxx:2455
static tools::Rectangle GetCellRect(const ScDocument &rDoc, const ScAddress &rPos, bool bMergedCell)
Returns the rectangle for the passed cell address in 1/100 mm.
Definition: drwlayer.cxx:2385
static ScDrawObjData * GetObjData(SdrObject *pObj, bool bCreate=false)
Definition: drwlayer.cxx:2874
bool IsRecording() const
Definition: drwlayer.hxx:143
static ScDrawObjData * GetNoteCaptionData(SdrObject *pObj, SCTAB nTab)
Returns the object data, if the passed object is a cell note caption.
Definition: drwlayer.cxx:2907
void AddCalcUndo(std::unique_ptr< SdrUndoAction > pUndo)
Definition: drwlayer.cxx:1503
ScAddress maStart
Definition: userdat.hxx:36
ScAddress maEnd
Definition: userdat.hxx:37
void SetTextCurrentDefaults(const EditTextObject &rTextObject)
SetText and apply defaults already set.
Definition: editutil.cxx:619
static SC_DLLPUBLIC const LocaleDataWrapper & getLocaleData()
Definition: global.cxx:1055
static ScPostIt * CreateNoteFromCaption(ScDocument &rDoc, const ScAddress &rPos, SdrCaptionObj *pCaption, bool bHasStyle)
Creates a cell note using the passed caption drawing object.
Definition: postit.cxx:905
static ScPostIt * CreateNoteFromString(ScDocument &rDoc, const ScAddress &rPos, const OUString &rNoteText, bool bShown, bool bAlwaysCreateCaption, sal_uInt32 nPostItId=0)
Creates a cell note based on the passed string and inserts it into the document.
Definition: postit.cxx:965
static ScPostIt * CreateNoteFromObjectData(ScDocument &rDoc, const ScAddress &rPos, SfxItemSet &&oItemSet, const OUString &rStyleName, const OutlinerParaObject &rOutlinerObj, const tools::Rectangle &rCaptionRect, bool bShown)
Creates a cell note based on the passed caption object data.
Definition: postit.cxx:932
static rtl::Reference< SdrCaptionObj > CreateTempCaption(ScDocument &rDoc, const ScAddress &rPos, SdrPage &rDrawPage, std::u16string_view rUserText, const tools::Rectangle &rVisRect, bool bTailFront)
Creates and returns a caption object for a temporary caption.
Definition: postit.cxx:832
Additional class containing cell annotation data.
Definition: postit.hxx:58
void SetAuthor(const OUString &rAuthor)
Sets a new author date for this note.
Definition: postit.cxx:499
void ShowCaptionTemp(const ScAddress &rPos, bool bShow=true)
Shows or hides the caption temporarily (does not change internal visibility state).
Definition: postit.cxx:598
~ScPostIt()
Removes the caption object from drawing layer, if this note is its owner.
Definition: postit.cxx:479
ScNoteData maNoteData
Parent document containing the note.
Definition: postit.hxx:171
void AutoStamp()
Sets date and author from system settings.
Definition: postit.cxx:504
const OUString & GetDate() const
Returns the creation date of this note.
Definition: postit.hxx:106
const OUString & GetAuthor() const
Returns the author date of this note.
Definition: postit.hxx:111
void SetText(const ScAddress &rPos, const OUString &rText)
Changes the caption text of this note.
Definition: postit.cxx:548
void UpdateCaptionPos(const ScAddress &rPos)
Updates caption position according to position of the passed cell.
Definition: postit.cxx:605
static sal_uInt32 mnLastPostItId
Definition: postit.hxx:60
std::unique_ptr< ScPostIt > Clone(const ScAddress &rOwnPos, ScDocument &rDestDoc, const ScAddress &rDestPos, bool bCloneCaption) const
Clones this note and its caption object, if specified.
Definition: postit.cxx:484
sal_uInt32 mnPostItId
Note data with pointer to caption object.
Definition: postit.hxx:172
ScDocument & mrDoc
Definition: postit.hxx:170
void ShowCaption(const ScAddress &rPos, bool bShow)
Shows or hides the note caption object.
Definition: postit.cxx:589
const EditTextObject * GetEditTextObject() const
Returns the pointer to the current edit text object, or null.
Definition: postit.cxx:521
SdrCaptionObj * GetOrCreateCaption(const ScAddress &rPos) const
Returns the caption object of this note.
Definition: postit.cxx:555
void CreateCaptionFromInitData(const ScAddress &rPos) const
Creates the caption object from initial caption data if existing.
Definition: postit.cxx:617
void ForgetCaption(bool bPreserveData=false)
Forgets the pointer to the note caption object.
Definition: postit.cxx:561
ScPostIt(ScDocument &rDoc, const ScAddress &rPos, sal_uInt32 nPostItId=0)
Creates an empty note and its caption object and places it according to the passed cell position.
Definition: postit.cxx:452
void SetDate(const OUString &rDate)
Sets a new creation date for this note.
Definition: postit.cxx:494
const OutlinerParaObject * GetOutlinerObject() const
Returns the pointer to the current outliner object, or null.
Definition: postit.cxx:512
bool IsCaptionShown() const
Returns true, if the caption object is visible.
Definition: postit.hxx:150
OUString GetText() const
Returns the caption text of this note.
Definition: postit.cxx:527
void RemoveCaption()
Removes the caption object from the drawing layer, if this note is its owner.
Definition: postit.cxx:769
void CreateCaption(const ScAddress &rPos, const SdrCaptionObj *pCaption=nullptr)
Creates a new caption object at the passed cell position, clones passed existing caption.
Definition: postit.cxx:707
static SC_DLLPUBLIC OUString ProgrammaticToDisplayName(const OUString &rProgName, SfxStyleFamily nType)
void CopyStyleFrom(SfxStyleSheetBasePool *pSrcPool, const OUString &rName, SfxStyleFamily eFamily, bool bNewStyleHierarchy=false)
Definition: stlpool.cxx:128
void SetSpecialTextBoxShadow()
const Point & GetTailPos() const
virtual const tools::Rectangle & GetLogicRect() const override
void SetFixedTail()
const SdrPage * GetPage(sal_uInt16 nPgNum) const
virtual void InsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
void RecalcObjOrdNums()
virtual rtl::Reference< SdrObject > RemoveObject(size_t nObjNum)
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
SfxStyleSheet * GetStyleSheet() const
const SfxItemSet & GetMergedItemSet() const
virtual SdrLayerID GetLayer() const
virtual void SetLayer(SdrLayerID nLayer)
virtual OutlinerParaObject * GetOutlinerParaObject() const override
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
virtual SfxStyleSheetBase * Find(const OUString &, SfxStyleFamily eFam, SfxStyleSearchBits n=SfxStyleSearchBits::All)
constexpr tools::Long GetWidth() const
constexpr tools::Long Top() const
void SetSize(const Size &)
constexpr Point TopLeft() const
void SetPos(const Point &rPoint)
constexpr Size GetSize() const
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
constexpr tools::Long Right() const
constexpr tools::Long GetHeight() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
constexpr bool IsEmpty() const
constexpr SdrLayerID SC_LAYER_HIDDEN(4)
constexpr SdrLayerID SC_LAYER_INTERN(2)
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
CAUTION! The following defines must be in the same namespace as the respective type.
Definition: broadcast.cxx:15
long Long
static void lcl_FormatAndInsertAuthorAndDatepara(SdrCaptionObj *pCaption, OUStringBuffer &aUserData, bool bUserWithTrackText)
Definition: postit.cxx:808
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
SdrMetricItem makeSdrShadowXDistItem(tools::Long nDist)
SdrMetricItem makeSdrShadowYDistItem(tools::Long nDist)
SdrOnOffItem makeSdrTextAutoGrowHeightItem(bool bAuto)
SdrOnOffItem makeSdrTextAutoGrowWidthItem(bool bAuto)
SdrMetricItem makeSdrTextMaxFrameWidthItem(tools::Long mnWidth)
SdrMetricItem makeSdrTextMinFrameWidthItem(tools::Long mnWidth)
Point maCaptionOffset
Simple text without formatting.
Definition: postit.cxx:433
Size maCaptionSize
Caption position relative to cell corner.
Definition: postit.cxx:434
OUString maSimpleText
Drawing style associated with the caption object.
Definition: postit.cxx:432
bool mbDefaultPosSize
Size of the caption object.
Definition: postit.cxx:435
OUString maStyleName
Text object with all text portion formatting.
Definition: postit.cxx:431
std::optional< OutlinerParaObject > mxOutlinerObj
Caption object formatting.
Definition: postit.cxx:430
ScCaptionInitData()
True = use default position and size for caption.
Definition: postit.cxx:440
std::optional< SfxItemSet > moItemSet
Definition: postit.cxx:429
Internal data for a cell annotation.
Definition: postit.hxx:42
rtl::Reference< SdrCaptionObj > mxCaption
Initial data for invisible notes without SdrObject.
Definition: postit.hxx:48
ScCaptionInitDataRef mxInitData
Author of the note.
Definition: postit.hxx:47
OUString maDate
Definition: postit.hxx:45
OUString maAuthor
Creation date of the note.
Definition: postit.hxx:46
bool mbShown
Drawing object representing the cell note.
Definition: postit.hxx:49
ScNoteData(bool bShown=false)
True = note is visible.
Definition: postit.cxx:445
NoteEntry(const ScAddress &rPos, const ScPostIt *pNote)
Definition: postit.cxx:991
constexpr TypedWhichId< SdrOnOffItem > SDRATTR_SHADOW(SDRATTR_SHADOW_FIRST+0)
std::unique_ptr< char[]> aBuffer