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 .
20 #include <OutlineView.hxx>
21 #include <sfx2/progress.hxx>
22 #include <vcl/commandinfoprovider.hxx>
23 #include <vcl/svapp.hxx>
24 #include <svx/svxids.hrc>
25 #include <editeng/outliner.hxx>
26 #include <editeng/eeitem.hxx>
27 #include <editeng/editstat.hxx>
28 #include <editeng/lrspitem.hxx>
29 #include <svx/svdotext.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <svl/style.hxx>
32 #include <svx/svdundo.hxx>
33 #include <editeng/numitem.hxx>
34 #include <editeng/outlobj.hxx>
35 #include <editeng/editeng.hxx>
36 #include <xmloff/autolayout.hxx>
37 #include <tools/debug.hxx>
38 #include <officecfg/Office/Common.hxx>
40 #include <editeng/editobj.hxx>
41 #include <editeng/editund2.hxx>
43 #include <editeng/editview.hxx>
45 #include <com/sun/star/frame/XFrame.hpp>
47 #include <DrawDocShell.hxx>
48 #include <drawdoc.hxx>
52 #include <OutlineViewShell.hxx>
54 #include <strings.hrc>
56 #include <sdresid.hxx>
57 #include <Outliner.hxx>
58 #include <EventMultiplexer.hxx>
59 #include <ViewShellBase.hxx>
60 #include <ViewShellManager.hxx>
61 #include <undo/undomanager.hxx>
62 #include <stlsheet.hxx>
64 using namespace ::com::sun::star::uno
;
65 using namespace ::com::sun::star::frame
;
69 // a progress bar gets displayed when more than
70 // PROCESS_WITH_PROGRESS_THRESHOLD pages are concerned
71 #define PROCESS_WITH_PROGRESS_THRESHOLD 5
73 OutlineView::OutlineView(DrawDocShell
& rDocSh
, vcl::Window
* pWindow
,
74 OutlineViewShell
& rOutlineViewShell
)
75 : ::sd::SimpleOutlinerView(*rDocSh
.GetDoc(), pWindow
->GetOutDev(), &rOutlineViewShell
)
76 , mrOutlineViewShell(rOutlineViewShell
)
77 , mrOutliner(*mrDoc
.GetOutliner())
81 , maDocColor(COL_WHITE
)
82 , maLRSpaceItem(SvxIndentValue::twips(2000), SvxIndentValue::zero(), SvxIndentValue::zero(),
85 bool bInitOutliner
= false;
87 if (mrOutliner
.GetViewCount() == 0)
89 // initialize Outliner: set Reference Device
91 mrOutliner
.Init( OutlinerMode::OutlineView
);
92 mrOutliner
.SetRefDevice(SdModule::get()->GetVirtualRefDevice());
93 //viewsize without the width of the image and number in front
94 mnPaperWidth
= (mrOutlineViewShell
.GetActiveWindow()->GetViewSize().Width() - 4000);
95 mrOutliner
.SetPaperSize(Size(mnPaperWidth
, 400000000));
99 // width: DIN A4, two margins at 1 cm each
100 mnPaperWidth
= 19000;
103 mpOutlinerViews
[0].reset( new OutlinerView(&mrOutliner
, pWindow
) );
104 mpOutlinerViews
[0]->SetOutputArea(::tools::Rectangle());
105 mrOutliner
.SetUpdateLayout(false);
106 mrOutliner
.InsertView(mpOutlinerViews
[0].get(), EE_APPEND
);
108 onUpdateStyleSettings( true );
112 // fill Outliner with contents
116 Link
<tools::EventMultiplexerEvent
&,void> aLink( LINK(this,OutlineView
,EventMultiplexerListener
) );
117 mrOutlineViewShell
.GetViewShellBase().GetEventMultiplexer()->AddEventListener(aLink
);
119 Reference
<XFrame
> xFrame
;
120 if (SfxViewFrame
* pFrame
= mrOutlineViewShell
.GetViewShellBase().GetFrame())
121 xFrame
= pFrame
->GetFrame().GetFrameInterface();
122 maSlideImage
= vcl::CommandInfoProvider::GetImageForCommand(u
".uno:ShowSlide"_ustr
, xFrame
, vcl::ImageType::Size26
);
124 // Tell undo manager of the document about the undo manager of the
125 // outliner, so that the former can synchronize with the later.
126 sd::UndoManager
* pDocUndoMgr
= dynamic_cast<sd::UndoManager
*>(mpDocSh
->GetUndoManager());
127 if (pDocUndoMgr
!= nullptr)
128 pDocUndoMgr
->SetLinkedUndoManager(&mrOutliner
.GetUndoManager());
132 * Destructor, restore Links, clear Outliner
134 OutlineView::~OutlineView()
136 DBG_ASSERT(maDragAndDropModelGuard
== nullptr,
137 "sd::OutlineView::~OutlineView(), prior drag operation not finished correctly!");
139 Link
<tools::EventMultiplexerEvent
&,void> aLink( LINK(this,OutlineView
,EventMultiplexerListener
) );
140 mrOutlineViewShell
.GetViewShellBase().GetEventMultiplexer()->RemoveEventListener( aLink
);
141 DisconnectFromApplication();
145 // unregister OutlinerViews and destroy them
146 for (auto & rpView
: mpOutlinerViews
)
150 mrOutliner
.RemoveView( rpView
.get() );
155 if (mrOutliner
.GetViewCount() == 0)
157 // uninitialize Outliner: enable color display
159 EEControlBits nCntrl
= mrOutliner
.GetControlWord();
160 mrOutliner
.SetUpdateLayout(false); // otherwise there will be drawn on SetControlWord
161 mrOutliner
.SetControlWord(nCntrl
& ~EEControlBits::NOCOLORS
);
162 mrOutliner
.ForceAutoColor( officecfg::Office::Common::Accessibility::IsAutomaticFontColor::get() );
167 void OutlineView::ConnectToApplication()
169 // When the mode is switched to outline the main view shell grabs focus.
170 // This is done for getting cut/copy/paste commands on slides in the left
171 // pane (slide sorter view shell) to work properly.
172 SfxShell
* pTopViewShell
= mrOutlineViewShell
.GetViewShellBase().GetViewShellManager()->GetTopViewShell();
173 if (pTopViewShell
&& pTopViewShell
== &mrOutlineViewShell
)
175 mrOutlineViewShell
.GetActiveWindow()->GrabFocus();
178 Application::AddEventListener(LINK(this, OutlineView
, AppEventListenerHdl
));
181 void OutlineView::DisconnectFromApplication()
183 Application::RemoveEventListener(LINK(this, OutlineView
, AppEventListenerHdl
));
186 void OutlineView::Paint(const ::tools::Rectangle
& rRect
, ::sd::Window
const * pWin
)
188 OutlinerView
* pOlView
= GetViewByWindow(pWin
);
192 pOlView
->HideCursor();
193 pOlView
->Paint(rRect
);
195 pOlView
->ShowCursor(mbFirstPaint
);
197 mbFirstPaint
= false;
201 void OutlineView::AddDeviceToPaintView(OutputDevice
& rDev
, vcl::Window
* pWindow
)
204 bool bValidArea
= false;
205 ::tools::Rectangle aOutputArea
;
206 const Color
aWhiteColor( COL_WHITE
);
207 sal_uInt16 nView
= 0;
209 while (nView
< MAX_OUTLINERVIEWS
&& !bAdded
)
211 if (mpOutlinerViews
[nView
] == nullptr)
213 mpOutlinerViews
[nView
].reset( new OutlinerView(&mrOutliner
, dynamic_cast< ::sd::Window
* >(rDev
.GetOwnerWindow())) );
214 mpOutlinerViews
[nView
]->SetBackgroundColor( aWhiteColor
);
215 mrOutliner
.InsertView(mpOutlinerViews
[nView
].get(), EE_APPEND
);
220 mpOutlinerViews
[nView
]->SetOutputArea(aOutputArea
);
223 else if (!bValidArea
)
225 aOutputArea
= mpOutlinerViews
[nView
]->GetOutputArea();
232 // white background in Outliner
233 rDev
.SetBackground( Wallpaper( aWhiteColor
) );
235 ::sd::View::AddDeviceToPaintView(rDev
, pWindow
);
238 void OutlineView::DeleteDeviceFromPaintView(OutputDevice
& rDev
)
240 bool bRemoved
= false;
241 sal_uInt16 nView
= 0;
242 vcl::Window
* pWindow
;
244 while (nView
< MAX_OUTLINERVIEWS
&& !bRemoved
)
246 if (mpOutlinerViews
[nView
] != nullptr)
248 pWindow
= mpOutlinerViews
[nView
]->GetWindow();
250 if (pWindow
->GetOutDev() == &rDev
)
252 mrOutliner
.RemoveView( mpOutlinerViews
[nView
].get() );
253 mpOutlinerViews
[nView
].reset();
261 ::sd::View::DeleteDeviceFromPaintView(rDev
);
265 * Return a pointer to the OutlinerView corresponding to the window
267 OutlinerView
* OutlineView::GetViewByWindow (vcl::Window
const * pWin
) const
269 OutlinerView
* pOlView
= nullptr;
270 for (std::unique_ptr
<OutlinerView
> const & pView
: mpOutlinerViews
)
272 if (pView
!= nullptr)
274 if ( pWin
== pView
->GetWindow() )
276 pOlView
= pView
.get();
284 * Return the title before a random paragraph
286 Paragraph
* OutlineView::GetPrevTitle(const Paragraph
* pPara
)
288 sal_Int32 nPos
= mrOutliner
.GetAbsPos(pPara
);
294 pPara
= mrOutliner
.GetParagraph(--nPos
);
295 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
297 return const_cast< Paragraph
* >( pPara
);
306 * Return the title after a random paragraph
308 Paragraph
* OutlineView::GetNextTitle(const Paragraph
* pPara
)
310 Paragraph
* pResult
= const_cast< Paragraph
* >( pPara
);
312 sal_Int32 nPos
= mrOutliner
.GetAbsPos(pResult
);
316 pResult
= mrOutliner
.GetParagraph(++nPos
);
317 if( pResult
&& ::Outliner::HasParaFlag(pResult
, ParaFlag::ISPAGE
) )
326 * Handler for inserting pages (paragraphs)
328 IMPL_LINK( OutlineView
, ParagraphInsertedHdl
, Outliner::ParagraphHdlParam
, aParam
, void )
330 // we get calls to this handler during binary insert of drag and drop contents but
331 // we ignore it here and handle it later in OnEndPasteOrDrop()
332 if (maDragAndDropModelGuard
!= nullptr)
335 OutlineViewPageChangesGuard
aGuard(this);
337 sal_Int32 nAbsPos
= mrOutliner
.GetAbsPos( aParam
.pPara
);
339 UpdateParagraph( nAbsPos
);
341 if( (nAbsPos
== 0) ||
342 ::Outliner::HasParaFlag(aParam
.pPara
, ParaFlag::ISPAGE
) ||
343 ::Outliner::HasParaFlag(mrOutliner
.GetParagraph( nAbsPos
-1 ), ParaFlag::ISPAGE
) )
345 InsertSlideForParagraph( aParam
.pPara
);
349 /** creates and inserts an empty slide for the given paragraph */
350 SdPage
* OutlineView::InsertSlideForParagraph( Paragraph
* pPara
)
352 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::InsertSlideForParagraph(), model change without undo?!" );
354 OutlineViewPageChangesGuard
aGuard(this);
356 mrOutliner
.SetParaFlag( pPara
, ParaFlag::ISPAGE
);
357 // how many titles are there before the new title paragraph?
358 sal_uLong nExample
= 0; // position of the "example" page
359 sal_uLong nTarget
= 0; // position of insertion
362 pPara
= GetPrevTitle(pPara
);
367 // if a new paragraph is created via RETURN before the first paragraph, the
368 // Outliner reports the old paragraph (which was moved down) as a new
372 OUString aTest
= mrOutliner
.GetText(mrOutliner
.GetParagraph(0));
379 // the "example" page is the previous page - if it is available
382 nExample
= nTarget
- 1;
384 sal_uInt16 nPageCount
= mrDoc
.GetSdPageCount( PageKind::Standard
);
385 if( nExample
>= nPageCount
)
386 nExample
= nPageCount
- 1;
389 /**********************************************************************
390 * All the time, a standard page is created before a notes page.
391 * It is ensured that after each standard page the corresponding notes page
392 * follows. A handout page is exactly one handout page.
393 **********************************************************************/
395 // this page is exemplary
396 SdPage
* pExample
= mrDoc
.GetSdPage(static_cast<sal_uInt16
>(nExample
), PageKind::Standard
);
397 rtl::Reference
<SdPage
> pPage
= mrDoc
.AllocSdPage(false);
399 pPage
->SetLayoutName(pExample
->GetLayoutName());
402 mrDoc
.InsertPage(pPage
.get(), static_cast<sal_uInt16
>(nTarget
) * 2 + 1);
403 if( isRecordingUndo() )
404 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
406 // assign a master page to the standard page
407 pPage
->TRG_SetMasterPage(pExample
->TRG_GetMasterPage());
410 pPage
->SetSize(pExample
->GetSize());
411 pPage
->SetBorder( pExample
->GetLeftBorder(),
412 pExample
->GetUpperBorder(),
413 pExample
->GetRightBorder(),
414 pExample
->GetLowerBorder() );
416 // create new presentation objects (after <Title> or <Title with subtitle>
417 // follows <Title with outline>, otherwise apply the layout of the previous
419 AutoLayout eAutoLayout
= pExample
->GetAutoLayout();
420 if (eAutoLayout
== AUTOLAYOUT_TITLE
||
421 eAutoLayout
== AUTOLAYOUT_TITLE_ONLY
)
423 pPage
->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT
, true);
427 pPage
->SetAutoLayout(pExample
->GetAutoLayout(), true);
430 /**********************************************************************
431 |* now the notes page
432 \*********************************************************************/
433 pExample
= mrDoc
.GetSdPage(static_cast<sal_uInt16
>(nExample
), PageKind::Notes
);
434 rtl::Reference
<SdPage
> pNotesPage
= mrDoc
.AllocSdPage(false);
436 pNotesPage
->SetLayoutName(pExample
->GetLayoutName());
438 pNotesPage
->SetPageKind(PageKind::Notes
);
440 // insert (notes page)
441 mrDoc
.InsertPage(pNotesPage
.get(), static_cast<sal_uInt16
>(nTarget
) * 2 + 2);
442 if( isRecordingUndo() )
443 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
445 // assign a master page to the notes page
446 pNotesPage
->TRG_SetMasterPage(pExample
->TRG_GetMasterPage());
448 // set page size, there must be already one page available
449 pNotesPage
->SetSize(pExample
->GetSize());
450 pNotesPage
->SetBorder( pExample
->GetLeftBorder(),
451 pExample
->GetUpperBorder(),
452 pExample
->GetRightBorder(),
453 pExample
->GetLowerBorder() );
455 // create presentation objects
456 pNotesPage
->SetAutoLayout(pExample
->GetAutoLayout(), true);
458 mrOutliner
.UpdateFields();
464 * Handler for deleting pages (paragraphs)
466 IMPL_LINK( OutlineView
, ParagraphRemovingHdl
, ::Outliner::ParagraphHdlParam
, aParam
, void )
468 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::ParagraphRemovingHdl(), model change without undo?!" );
470 OutlineViewPageChangesGuard
aGuard(this);
472 Paragraph
* pPara
= aParam
.pPara
;
473 if( !::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) )
476 // how many titles are in front of the title paragraph in question?
480 pPara
= GetPrevTitle(pPara
);
484 // delete page and notes page
485 sal_uInt16 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
486 SdrPage
* pPage
= mrDoc
.GetPage(nAbsPos
);
487 if( isRecordingUndo() )
488 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
489 mrDoc
.RemovePage(nAbsPos
);
491 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
492 pPage
= mrDoc
.GetPage(nAbsPos
);
493 if( isRecordingUndo() )
494 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
495 mrDoc
.RemovePage(nAbsPos
);
497 // progress display if necessary
498 if (mnPagesToProcess
)
503 mpProgress
->SetState(mnPagesProcessed
);
505 if (mnPagesProcessed
== mnPagesToProcess
)
508 mnPagesToProcess
= 0;
509 mnPagesProcessed
= 0;
512 aParam
.pOutliner
->UpdateFields();
516 * Handler for changing the indentation depth of paragraphs (requires inserting
517 * or deleting of pages in some cases)
519 IMPL_LINK( OutlineView
, DepthChangedHdl
, ::Outliner::DepthChangeHdlParam
, aParam
, void )
521 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::DepthChangedHdl(), no undo for model change?!" );
523 OutlineViewPageChangesGuard
aGuard(this);
525 Paragraph
* pPara
= aParam
.pPara
;
526 ::Outliner
* pOutliner
= aParam
.pOutliner
;
527 if( ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) && ((aParam
.nPrevFlags
& ParaFlag::ISPAGE
) == ParaFlag::NONE
) )
529 // the current paragraph is transformed into a slide
531 mrOutliner
.SetDepth( pPara
, -1 );
533 // are multiple level 1 paragraphs being brought to level 0 and we
534 // should start a progress view or a timer and didn't already?
535 if (mnPagesToProcess
== 0)
537 Window
* pActWin
= mrOutlineViewShell
.GetActiveWindow();
538 OutlinerView
* pOlView
= GetViewByWindow(pActWin
);
540 std::vector
<Paragraph
*> aSelList
;
541 pOlView
->CreateSelectionList(aSelList
);
543 mnPagesToProcess
= std::count_if(aSelList
.begin(), aSelList
.end(),
544 [&pOutliner
](const Paragraph
*pParagraph
) {
545 return !Outliner::HasParaFlag(pParagraph
, ParaFlag::ISPAGE
) &&
546 (pOutliner
->GetDepth(pOutliner
->GetAbsPos(pParagraph
)) <= 0);
549 mnPagesToProcess
++; // the paragraph being in level 0 already
550 // should be included
551 mnPagesProcessed
= 0;
553 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
)
555 mpProgress
.reset( new SfxProgress( GetDocSh(), SdResId(STR_CREATE_PAGES
), mnPagesToProcess
) );
559 mpDocSh
->SetWaitCursor( true );
563 ParagraphInsertedHdl( { aParam
.pOutliner
, aParam
.pPara
} );
567 // should there be a progress display?
568 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
)
571 mpProgress
->SetState(mnPagesProcessed
);
574 // was this the last page?
575 if (mnPagesProcessed
== mnPagesToProcess
)
577 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
&& mpProgress
)
582 mpDocSh
->SetWaitCursor( false );
584 mnPagesToProcess
= 0;
585 mnPagesProcessed
= 0;
587 pOutliner
->UpdateFields();
589 else if( !::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) && ((aParam
.nPrevFlags
& ParaFlag::ISPAGE
) != ParaFlag::NONE
) )
591 // the paragraph was a page but now becomes a normal paragraph
593 // how many titles are before the title paragraph in question?
595 Paragraph
* pParagraph
= pPara
;
598 pParagraph
= GetPrevTitle(pParagraph
);
602 // delete page and notes page
604 sal_uInt16 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
605 SdrPage
* pPage
= mrDoc
.GetPage(nAbsPos
);
606 if( isRecordingUndo() )
607 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
608 mrDoc
.RemovePage(nAbsPos
);
610 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
611 pPage
= mrDoc
.GetPage(nAbsPos
);
612 if( isRecordingUndo() )
613 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
614 mrDoc
.RemovePage(nAbsPos
);
616 pPage
= GetPageForParagraph( pPara
);
618 mrOutliner
.SetDepth( pPara
, (pPage
&& (static_cast<SdPage
*>(pPage
)->GetAutoLayout() == AUTOLAYOUT_TITLE
)) ? -1 : 0 );
620 // progress display if necessary
621 if (mnPagesToProcess
)
625 mpProgress
->SetState(mnPagesProcessed
);
627 if (mnPagesProcessed
== mnPagesToProcess
)
630 mnPagesToProcess
= 0;
631 mnPagesProcessed
= 0;
634 pOutliner
->UpdateFields();
636 else if ( (pOutliner
->GetPrevDepth() == 1) && ( pOutliner
->GetDepth( pOutliner
->GetAbsPos( pPara
) ) == 2 ) )
638 // how many titles are in front of the title paragraph in question?
641 Paragraph
* pParagraph
= pPara
;
644 pParagraph
= GetPrevTitle(pParagraph
);
651 SdPage
*pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPos
), PageKind::Standard
);
653 if(pPage
&& pPage
->GetPresObj(PresObjKind::Text
))
654 pOutliner
->SetDepth( pPara
, 0 );
658 // how many titles are in front of the title paragraph in question?
661 Paragraph
* pTempPara
= pPara
;
664 pTempPara
= GetPrevTitle(pTempPara
);
672 SdPage
* pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPos
), PageKind::Standard
);
677 SfxStyleSheet
* pStyleSheet
= nullptr;
678 sal_Int32 nPara
= pOutliner
->GetAbsPos( pPara
);
679 sal_Int16 nDepth
= pOutliner
->GetDepth( nPara
);
680 bool bSubTitle
= pPage
->GetPresObj(PresObjKind::Text
) != nullptr;
682 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
684 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Title
);
688 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Text
);
692 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Outline
);
696 OUString aNewStyleSheetName
= pStyleSheet
->GetName();
697 if (!aNewStyleSheetName
.isEmpty())
698 aNewStyleSheetName
= aNewStyleSheetName
.copy(0, aNewStyleSheetName
.getLength() - 1);
699 aNewStyleSheetName
+= OUString::number( nDepth
+1 );
700 SfxStyleSheetBasePool
* pStylePool
= mrDoc
.GetStyleSheetPool();
701 pStyleSheet
= static_cast<SfxStyleSheet
*>( pStylePool
->Find( aNewStyleSheetName
, pStyleSheet
->GetFamily() ) );
705 // before we set the style sheet we need to preserve the bullet item
706 // since all items will be deleted while setting a new style sheet
707 SfxItemSet
aOldAttrs( pOutliner
->GetParaAttribs( nPara
) );
709 pOutliner
->SetStyleSheet( nPara
, pStyleSheet
);
711 // restore the old bullet item but not if the style changed
712 const SvxNumBulletItem
* pBulletItem
= nullptr;
713 if ( pOutliner
->GetPrevDepth() != -1 && nDepth
!= -1 &&
714 aOldAttrs
.GetItemState( EE_PARA_NUMBULLET
, true, &pBulletItem
) == SfxItemState::SET
)
716 SfxItemSet
aAttrs( pOutliner
->GetParaAttribs( nPara
) );
717 aAttrs
.Put( *pBulletItem
);
718 pOutliner
->SetParaAttribs( nPara
, aAttrs
);
723 * Handler for StatusEvents
725 IMPL_LINK_NOARG(OutlineView
, StatusEventHdl
, EditStatus
&, void)
727 ::sd::Window
* pWin
= mrOutlineViewShell
.GetActiveWindow();
728 OutlinerView
* pOutlinerView
= GetViewByWindow(pWin
);
729 ::tools::Rectangle aVis
= pOutlinerView
->GetVisArea();
730 ::tools::Rectangle
aText(Point(0,0),
732 mrOutliner
.GetTextHeight()));
733 ::tools::Rectangle
aWin(Point(0,0), pWin
->GetOutputSizePixel());
734 aWin
= pWin
->PixelToLogic(aWin
);
736 if (!aVis
.IsEmpty()) // not when opening
738 if (aWin
.GetHeight() > aText
.Bottom())
739 aText
.SetBottom( aWin
.GetHeight() );
741 mrOutlineViewShell
.InitWindows(Point(0,0), aText
.GetSize(), aVis
.TopLeft());
742 mrOutlineViewShell
.UpdateScrollBars();
746 IMPL_LINK_NOARG(OutlineView
, BeginDropHdl
, EditView
*, void)
748 DBG_ASSERT(maDragAndDropModelGuard
== nullptr,
749 "sd::OutlineView::BeginDropHdl(), prior drag operation not finished correctly!");
751 maDragAndDropModelGuard
.reset( new OutlineViewModelChangeGuard( *this ) );
754 IMPL_LINK_NOARG(OutlineView
, EndDropHdl
, EditView
*, void)
756 maDragAndDropModelGuard
.reset();
760 * Handler for the start of a paragraph movement
762 IMPL_LINK( OutlineView
, BeginMovingHdl
, ::Outliner
*, pOutliner
, void )
764 OutlineViewPageChangesGuard
aGuard(this);
766 // list of selected title paragraphs
767 mpOutlinerViews
[0]->CreateSelectionList(maSelectedParas
);
769 std::erase_if(maSelectedParas
,
770 [](const Paragraph
* pPara
) { return !Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
); });
772 // select the pages belonging to the paragraphs on level 0 to select
774 sal_Int32 nParaPos
= 0;
775 Paragraph
* pPara
= pOutliner
->GetParagraph( 0 );
776 std::vector
<Paragraph
*>::const_iterator fiter
;
780 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) ) // one page?
782 maOldParaOrder
.push_back(pPara
);
783 SdPage
* pPage
= mrDoc
.GetSdPage(nPos
, PageKind::Standard
);
785 fiter
= std::find(maSelectedParas
.begin(),maSelectedParas
.end(),pPara
);
787 pPage
->SetSelected(fiter
!= maSelectedParas
.end());
791 pPara
= pOutliner
->GetParagraph( ++nParaPos
);
796 * Handler for the end of a paragraph movement
798 IMPL_LINK( OutlineView
, EndMovingHdl
, ::Outliner
*, pOutliner
, void )
800 OutlineViewPageChangesGuard
aGuard(this);
802 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::EndMovingHdl(), model change without undo?!" );
804 // look for insertion position via the first paragraph
805 Paragraph
* pSearchIt
= maSelectedParas
.empty() ? nullptr : *(maSelectedParas
.begin());
807 // look for the first of the selected paragraphs in the new ordering
808 sal_uInt16 nPosNewOrder
= 0;
809 sal_Int32 nParaPos
= 0;
810 Paragraph
* pPara
= pOutliner
->GetParagraph( 0 );
811 Paragraph
* pPrev
= nullptr;
812 while (pPara
&& pPara
!= pSearchIt
)
814 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
819 pPara
= pOutliner
->GetParagraph( ++nParaPos
);
822 sal_uInt16 nPos
= nPosNewOrder
; // don't change nPosNewOrder
825 nPos
= sal_uInt16(-1); // insert before the first page
829 // look for the predecessor in the old ordering
830 std::vector
<Paragraph
*>::const_iterator it
= std::find(maOldParaOrder
.begin(),
831 maOldParaOrder
.end(),
834 if (it
!= maOldParaOrder
.end())
835 nPos
= static_cast<sal_uInt16
>(it
-maOldParaOrder
.begin());
839 DBG_ASSERT(nPos
!= 0xffff, "Paragraph not found");
842 mrDoc
.MovePages(nPos
);
844 // deselect the pages again
845 sal_uInt16 nPageCount
= static_cast<sal_uInt16
>(maSelectedParas
.size());
848 SdPage
* pPage
= mrDoc
.GetSdPage(nPosNewOrder
, PageKind::Standard
);
849 pPage
->SetSelected(false);
854 pOutliner
->UpdateFields();
856 maSelectedParas
.clear();
857 maOldParaOrder
.clear();
861 * Look for the title text object in one page of the model
863 SdrTextObj
* OutlineView::GetTitleTextObject(SdrPage
const * pPage
)
865 SdrTextObj
* pResult
= nullptr;
867 for (const rtl::Reference
<SdrObject
>& pObject
: *pPage
)
869 if (pObject
->GetObjInventor() == SdrInventor::Default
&&
870 pObject
->GetObjIdentifier() == SdrObjKind::TitleText
)
872 pResult
= static_cast<SdrTextObj
*>(pObject
.get());
880 * Look for the outline text object in one page of the model
882 SdrTextObj
* OutlineView::GetOutlineTextObject(SdrPage
const * pPage
)
884 SdrTextObj
* pResult
= nullptr;
886 for (const rtl::Reference
<SdrObject
>& pObject
: *pPage
)
888 if (pObject
->GetObjInventor() == SdrInventor::Default
&&
889 pObject
->GetObjIdentifier() == SdrObjKind::OutlineText
)
891 pResult
= static_cast<SdrTextObj
*>(pObject
.get());
898 SdrTextObj
* OutlineView::CreateTitleTextObject(SdPage
* pPage
)
900 DBG_ASSERT( GetTitleTextObject(pPage
) == nullptr, "sd::OutlineView::CreateTitleTextObject(), there is already a title text object!" );
902 if( pPage
->GetAutoLayout() == AUTOLAYOUT_NONE
)
905 pPage
->SetAutoLayout( AUTOLAYOUT_TITLE_ONLY
, true );
909 // we already have a layout with a title but the title
910 // object was deleted, create a new one
911 pPage
->InsertAutoLayoutShape( nullptr, PresObjKind::Title
, false, pPage
->GetTitleRect(), true );
914 return GetTitleTextObject(pPage
);
917 SdrTextObj
* OutlineView::CreateOutlineTextObject(SdPage
* pPage
)
919 DBG_ASSERT( GetOutlineTextObject(pPage
) == nullptr, "sd::OutlineView::CreateOutlineTextObject(), there is already a layout text object!" );
921 AutoLayout eNewLayout
= pPage
->GetAutoLayout();
924 case AUTOLAYOUT_NONE
:
925 case AUTOLAYOUT_TITLE_ONLY
:
926 case AUTOLAYOUT_TITLE
: eNewLayout
= AUTOLAYOUT_TITLE_CONTENT
; break;
928 case AUTOLAYOUT_CHART
: eNewLayout
= AUTOLAYOUT_CHARTTEXT
; break;
932 case AUTOLAYOUT_OBJ
: eNewLayout
= AUTOLAYOUT_OBJTEXT
; break;
937 if( eNewLayout
!= pPage
->GetAutoLayout() )
939 pPage
->SetAutoLayout( eNewLayout
, true );
943 // we already have a layout with a text but the text
944 // object was deleted, create a new one
945 pPage
->InsertAutoLayoutShape( nullptr,
946 PresObjKind::Outline
,
947 false, pPage
->GetLayoutRect(), true );
950 return GetOutlineTextObject(pPage
);
953 /** updates draw model with all changes from outliner model */
954 void OutlineView::PrepareClose()
956 ::sd::UndoManager
* pDocUndoMgr
= dynamic_cast<sd::UndoManager
*>(mpDocSh
->GetUndoManager());
957 if (pDocUndoMgr
!= nullptr)
958 pDocUndoMgr
->SetLinkedUndoManager(nullptr);
960 mrOutliner
.GetUndoManager().Clear();
962 BegUndo(SdResId(STR_UNDO_CHANGE_TITLE_AND_LAYOUT
));
965 mrDoc
.SetSelected(GetActualPage(), true);
969 * Set attributes of the selected text
971 bool OutlineView::SetAttributes(const SfxItemSet
& rSet
, bool /*bSlide*/, bool /*bReplaceAll*/, bool /*bMaster*/)
975 OutlinerView
* pOlView
= GetViewByWindow(mrOutlineViewShell
.GetActiveWindow());
979 pOlView
->SetAttribs(rSet
);
983 mrOutlineViewShell
.Invalidate (SID_PREVIEW_STATE
);
989 * Get attributes of the selected text
991 void OutlineView::GetAttributes( SfxItemSet
& rTargetSet
, bool ) const
993 OutlinerView
* pOlView
= GetViewByWindow(
994 mrOutlineViewShell
.GetActiveWindow());
995 assert(pOlView
&& "No OutlinerView found");
997 rTargetSet
.Put( pOlView
->GetAttribs(), false );
1000 /** creates outliner model from draw model */
1001 void OutlineView::FillOutliner()
1003 mrOutliner
.GetUndoManager().Clear();
1004 mrOutliner
.EnableUndo(false);
1006 const bool bPrevUpdateLayout
= mrOutliner
.SetUpdateLayout(false);
1008 Paragraph
* pTitleToSelect
= nullptr;
1009 sal_uInt16 nPageCount
= mrDoc
.GetSdPageCount(PageKind::Standard
);
1011 // fill outliner with paragraphs from slides title & (outlines|subtitles)
1012 for (sal_uInt16 nPage
= 0; nPage
< nPageCount
; nPage
++)
1014 SdPage
* pPage
= mrDoc
.GetSdPage(nPage
, PageKind::Standard
);
1015 Paragraph
* pPara
= nullptr;
1017 // take text from title shape
1018 SdrTextObj
* pTO
= GetTitleTextObject(pPage
);
1019 if(pTO
&& !(pTO
->IsEmptyPresObj()))
1021 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
1024 bool bVertical
= pOPO
->IsEffectivelyVertical();
1025 pOPO
->SetVertical( false );
1026 mrOutliner
.AddText(*pOPO
);
1027 pOPO
->SetVertical( bVertical
);
1028 pPara
= mrOutliner
.GetParagraph( mrOutliner
.GetParagraphCount()-1 );
1032 if( pPara
== nullptr ) // no title, insert an empty paragraph
1034 pPara
= mrOutliner
.Insert(OUString());
1035 mrOutliner
.SetDepth(pPara
, -1);
1037 // do not apply hard attributes from the previous paragraph
1038 mrOutliner
.SetParaAttribs( mrOutliner
.GetAbsPos(pPara
),
1039 mrOutliner
.GetEmptyItemSet() );
1041 mrOutliner
.SetStyleSheet( mrOutliner
.GetAbsPos( pPara
), pPage
->GetStyleSheetForPresObj( PresObjKind::Title
) );
1044 mrOutliner
.SetParaFlag( pPara
, ParaFlag::ISPAGE
);
1046 sal_Int32 nPara
= mrOutliner
.GetAbsPos( pPara
);
1048 UpdateParagraph( nPara
);
1050 // remember paragraph of currently selected page
1051 if (pPage
->IsSelected())
1052 pTitleToSelect
= pPara
;
1054 // take text from subtitle or outline
1055 pTO
= static_cast<SdrTextObj
*>(pPage
->GetPresObj(PresObjKind::Text
));
1056 const bool bSubTitle
= pTO
!= nullptr;
1058 if (!pTO
) // if no subtile found, try outline
1059 pTO
= GetOutlineTextObject(pPage
);
1061 if(pTO
&& !(pTO
->IsEmptyPresObj())) // found some text
1063 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
1066 sal_Int32 nParaCount1
= mrOutliner
.GetParagraphCount();
1067 bool bVertical
= pOPO
->IsEffectivelyVertical();
1068 pOPO
->SetVertical( false );
1069 mrOutliner
.AddText(*pOPO
);
1070 pOPO
->SetVertical( bVertical
);
1072 sal_Int32 nParaCount2
= mrOutliner
.GetParagraphCount();
1073 for (sal_Int32 n
= nParaCount1
; n
< nParaCount2
; n
++)
1077 Paragraph
* p
= mrOutliner
.GetParagraph(n
);
1078 if(p
&& mrOutliner
.GetDepth( n
) > 0 )
1079 mrOutliner
.SetDepth(p
, 0);
1082 UpdateParagraph( n
);
1088 // place cursor at the start
1089 Paragraph
* pFirstPara
= mrOutliner
.GetParagraph( 0 );
1090 mpOutlinerViews
[0]->Select( pFirstPara
);
1091 mpOutlinerViews
[0]->Select( pFirstPara
, false );
1093 // select title of slide that was selected
1095 mpOutlinerViews
[0]->Select(pTitleToSelect
);
1099 mrOutliner
.EnableUndo(true);
1101 mrOutliner
.SetUpdateLayout(bPrevUpdateLayout
);
1105 * Handler for deleting of level 0 paragraphs (pages): Warning
1107 IMPL_LINK_NOARG(OutlineView
, RemovingPagesHdl
, OutlinerView
*, bool)
1109 sal_Int32 nNumOfPages
= mrOutliner
.GetSelPageCount();
1111 if (nNumOfPages
> PROCESS_WITH_PROGRESS_THRESHOLD
)
1113 mnPagesToProcess
= nNumOfPages
;
1114 mnPagesProcessed
= 0;
1117 if (mnPagesToProcess
)
1119 mpProgress
.reset( new SfxProgress( GetDocSh(), SdResId(STR_DELETE_PAGES
), mnPagesToProcess
) );
1121 mrOutliner
.UpdateFields();
1127 * Handler for indenting level 0 paragraphs (pages): Warning
1129 IMPL_LINK( OutlineView
, IndentingPagesHdl
, OutlinerView
*, pOutlinerView
, bool )
1131 return RemovingPagesHdl(pOutlinerView
);
1134 /** returns the first slide that is selected in the outliner or where
1135 the cursor is located */
1136 SdPage
* OutlineView::GetActualPage()
1138 ::sd::Window
* pWin
= mrOutlineViewShell
.GetActiveWindow();
1139 OutlinerView
* pActiveView
= GetViewByWindow(pWin
);
1141 std::vector
<Paragraph
*> aSelList
;
1142 pActiveView
->CreateSelectionList(aSelList
);
1144 Paragraph
*pPar
= aSelList
.empty() ? nullptr : *(aSelList
.begin());
1145 SdPage
* pCurrent
= GetPageForParagraph(pPar
);
1147 DBG_ASSERT( pCurrent
||
1148 (mpDocSh
->GetUndoManager() && static_cast< sd::UndoManager
*>(mpDocSh
->GetUndoManager())->IsDoing()) ||
1149 maDragAndDropModelGuard
,
1150 "sd::OutlineView::GetActualPage(), no current page?" );
1155 return mrDoc
.GetSdPage( 0, PageKind::Standard
);
1158 SdPage
* OutlineView::GetPageForParagraph( Paragraph
* pPara
)
1160 if( !::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
) )
1161 pPara
= GetPrevTitle(pPara
);
1163 sal_uInt32 nPageToSelect
= 0;
1166 pPara
= GetPrevTitle(pPara
);
1171 if( nPageToSelect
< static_cast<sal_uInt32
>(mrDoc
.GetSdPageCount( PageKind::Standard
)) )
1172 return mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPageToSelect
), PageKind::Standard
);
1177 Paragraph
* OutlineView::GetParagraphForPage( ::Outliner
const & rOutl
, SdPage
const * pPage
)
1179 // get the number of paragraphs with ident 0 we need to skip before
1180 // we find the actual page
1181 sal_uInt16 nPageNum
= pPage
->GetPageNum();
1182 assert(nPageNum
> 0);
1183 sal_uInt32 nPagesToSkip
= (nPageNum
- 1) >> 1;
1185 sal_Int32 nParaPos
= 0;
1186 Paragraph
* pPara
= rOutl
.GetParagraph( 0 );
1189 // if this paragraph is a page...
1190 if( ::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
) )
1192 // see if we already skipped enough pages
1193 if( 0 == nPagesToSkip
)
1194 break; // and if so, end the loop
1196 // we skipped another page
1200 // get next paragraph
1201 pPara
= mrOutliner
.GetParagraph( ++nParaPos
);
1207 /** selects the paragraph for the given page at the outliner view*/
1208 void OutlineView::SetActualPage( SdPage
const * pActual
)
1210 if( pActual
&& mrOutliner
.GetIgnoreCurrentPageChangesLevel()==0 && !mbFirstPaint
)
1212 // if we found a paragraph, select its text at the outliner view
1213 Paragraph
* pPara
= GetParagraphForPage( mrOutliner
, pActual
);
1215 mpOutlinerViews
[0]->Select( pPara
);
1220 * Get StyleSheet from the selection
1222 SfxStyleSheet
* OutlineView::GetStyleSheet() const
1224 ::sd::Window
* pActWin
= mrOutlineViewShell
.GetActiveWindow();
1225 OutlinerView
* pOlView
= GetViewByWindow(pActWin
);
1226 SfxStyleSheet
* pResult
= pOlView
->GetStyleSheet();
1231 * Mark pages as selected / not selected
1233 void OutlineView::SetSelectedPages()
1235 // list of selected title paragraphs
1236 std::vector
<Paragraph
*> aSelParas
;
1237 mpOutlinerViews
[0]->CreateSelectionList(aSelParas
);
1239 std::erase_if(aSelParas
,
1240 [](const Paragraph
* pPara
) { return !Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
); });
1242 // select the pages belonging to the paragraphs on level 0 to select
1243 sal_uInt16 nPos
= 0;
1244 sal_Int32 nParaPos
= 0;
1245 Paragraph
*pPara
= mrOutliner
.GetParagraph( 0 );
1246 std::vector
<Paragraph
*>::const_iterator fiter
;
1250 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) ) // one page
1252 SdPage
* pPage
= mrDoc
.GetSdPage(nPos
, PageKind::Standard
);
1253 DBG_ASSERT(pPage
!=nullptr,
1254 "Trying to select non-existing page OutlineView::SetSelectedPages()");
1258 fiter
= std::find(aSelParas
.begin(),aSelParas
.end(),pPara
);
1259 pPage
->SetSelected(fiter
!= aSelParas
.end());
1265 pPara
= mrOutliner
.GetParagraph( ++nParaPos
);
1272 void OutlineView::SetLinks()
1274 // set notification links
1275 mrOutliner
.SetParaInsertedHdl(LINK(this, OutlineView
, ParagraphInsertedHdl
));
1276 mrOutliner
.SetParaRemovingHdl(LINK(this, OutlineView
, ParagraphRemovingHdl
));
1277 mrOutliner
.SetDepthChangedHdl(LINK(this, OutlineView
, DepthChangedHdl
));
1278 mrOutliner
.SetBeginMovingHdl(LINK(this, OutlineView
, BeginMovingHdl
));
1279 mrOutliner
.SetEndMovingHdl(LINK(this, OutlineView
, EndMovingHdl
));
1280 mrOutliner
.SetRemovingPagesHdl(LINK(this, OutlineView
, RemovingPagesHdl
));
1281 mrOutliner
.SetIndentingPagesHdl(LINK(this, OutlineView
, IndentingPagesHdl
));
1282 mrOutliner
.SetStatusEventHdl(LINK(this, OutlineView
, StatusEventHdl
));
1283 mrOutliner
.SetBeginDropHdl(LINK(this,OutlineView
, BeginDropHdl
));
1284 mrOutliner
.SetEndDropHdl(LINK(this,OutlineView
, EndDropHdl
));
1285 mrOutliner
.SetPaintFirstLineHdl(LINK(this,OutlineView
,PaintingFirstLineHdl
));
1286 mrOutliner
.SetBeginPasteOrDropHdl(LINK(this,OutlineView
, BeginPasteOrDropHdl
));
1287 mrOutliner
.SetEndPasteOrDropHdl(LINK(this,OutlineView
, EndPasteOrDropHdl
));
1293 void OutlineView::ResetLinks() const
1295 mrOutliner
.SetParaInsertedHdl(Link
<::Outliner::ParagraphHdlParam
,void>());
1296 mrOutliner
.SetParaRemovingHdl(Link
<::Outliner::ParagraphHdlParam
,void>());
1297 mrOutliner
.SetDepthChangedHdl(Link
<::Outliner::DepthChangeHdlParam
,void>());
1298 mrOutliner
.SetBeginMovingHdl(Link
<::Outliner
*,void>());
1299 mrOutliner
.SetEndMovingHdl(Link
<::Outliner
*,void>());
1300 mrOutliner
.SetStatusEventHdl(Link
<EditStatus
&,void>());
1301 mrOutliner
.SetRemovingPagesHdl(Link
<OutlinerView
*,bool>());
1302 mrOutliner
.SetIndentingPagesHdl(Link
<OutlinerView
*,bool>());
1303 mrOutliner
.SetDrawPortionHdl(Link
<DrawPortionInfo
*,void>());
1304 mrOutliner
.SetBeginPasteOrDropHdl(Link
<PasteOrDropInfos
*,void>());
1305 mrOutliner
.SetEndPasteOrDropHdl(Link
<PasteOrDropInfos
*,void>());
1308 sal_Int8
OutlineView::AcceptDrop( const AcceptDropEvent
&, DropTargetHelper
&, SdrLayerID
)
1310 return DND_ACTION_NONE
;
1313 sal_Int8
OutlineView::ExecuteDrop( const ExecuteDropEvent
&, ::sd::Window
*, sal_uInt16
, SdrLayerID
)
1315 return DND_ACTION_NONE
;
1318 // Re-implement GetScriptType for this view to get correct results
1319 SvtScriptType
OutlineView::GetScriptType() const
1321 SvtScriptType nScriptType
= ::sd::View::GetScriptType();
1323 std::optional
<OutlinerParaObject
> pTempOPObj
= mrOutliner
.CreateParaObject();
1326 nScriptType
= pTempOPObj
->GetTextObject().GetScriptType();
1332 void OutlineView::onUpdateStyleSettings( bool bForceUpdate
/* = false */ )
1334 svtools::ColorConfig aColorConfig
;
1335 const Color
aDocColor( aColorConfig
.GetColorValue( svtools::DOCCOLOR
).nColor
);
1336 if( !(bForceUpdate
|| (maDocColor
!= aDocColor
)) )
1340 for( nView
= 0; nView
< MAX_OUTLINERVIEWS
; nView
++ )
1342 if (mpOutlinerViews
[nView
] != nullptr)
1344 mpOutlinerViews
[nView
]->SetBackgroundColor( aDocColor
);
1346 vcl::Window
* pWindow
= mpOutlinerViews
[nView
]->GetWindow();
1349 pWindow
->SetBackground( Wallpaper( aDocColor
) );
1354 mrOutliner
.SetBackgroundColor( aDocColor
);
1356 maDocColor
= aDocColor
;
1359 IMPL_LINK_NOARG(OutlineView
, AppEventListenerHdl
, VclSimpleEvent
&, void)
1361 onUpdateStyleSettings(false);
1364 IMPL_LINK(OutlineView
, EventMultiplexerListener
, ::sd::tools::EventMultiplexerEvent
&, rEvent
, void)
1366 switch (rEvent
.meEventId
)
1368 case EventMultiplexerEventId::CurrentPageChanged
:
1369 SetActualPage(mrOutlineViewShell
.GetActualPage());
1372 case EventMultiplexerEventId::PageOrder
:
1373 if (mrOutliner
.GetIgnoreCurrentPageChangesLevel()==0)
1375 if (((mrDoc
.GetPageCount()-1)%2) == 0)
1379 ::sd::Window
* pWindow
= mrOutlineViewShell
.GetActiveWindow();
1380 if (pWindow
!= nullptr)
1381 pWindow
->Invalidate();
1390 void OutlineView::IgnoreCurrentPageChanges (bool bIgnoreChanges
)
1393 mrOutliner
.IncreIgnoreCurrentPageChangesLevel();
1395 mrOutliner
.DecreIgnoreCurrentPageChangesLevel();
1398 /** call this method before you do anything that can modify the outliner
1399 and or the drawing document model. It will create needed undo actions */
1400 void OutlineView::BeginModelChange()
1402 mrOutliner
.GetUndoManager().EnterListAction(u
""_ustr
, u
""_ustr
, 0, mrOutlineViewShell
.GetViewShellBase().GetViewShellId());
1403 BegUndo(SdResId(STR_UNDO_CHANGE_TITLE_AND_LAYOUT
));
1406 /** call this method after BeginModelChange(), when all possible model
1407 changes are done. */
1408 void OutlineView::EndModelChange()
1412 SfxUndoManager
* pDocUndoMgr
= mpDocSh
->GetUndoManager();
1414 bool bHasUndoActions
= pDocUndoMgr
->GetUndoActionCount() != 0;
1418 DBG_ASSERT( bHasUndoActions
== (mrOutliner
.GetUndoManager().GetUndoActionCount() != 0), "sd::OutlineView::EndModelChange(), undo actions not in sync!" );
1420 mrOutliner
.GetUndoManager().LeaveListAction();
1422 if( bHasUndoActions
&& mrOutliner
.GetEditEngine().HasTriedMergeOnLastAddUndo() )
1423 TryToMergeUndoActions();
1425 mrOutlineViewShell
.Invalidate( SID_UNDO
);
1426 mrOutlineViewShell
.Invalidate( SID_REDO
);
1429 /** updates all changes in the outliner model to the draw model */
1430 void OutlineView::UpdateDocument()
1432 OutlineViewPageChangesGuard
aGuard(this);
1434 const sal_uInt32 nPageCount
= mrDoc
.GetSdPageCount(PageKind::Standard
);
1435 Paragraph
* pPara
= mrOutliner
.GetParagraph( 0 );
1437 for (nPage
= 0; nPage
< nPageCount
; nPage
++)
1439 SdPage
* pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPage
), PageKind::Standard
);
1440 mrDoc
.SetSelected(pPage
, false);
1442 mrOutlineViewShell
.UpdateTitleObject( pPage
, pPara
);
1443 mrOutlineViewShell
.UpdateOutlineObject( pPage
, pPara
);
1446 pPara
= GetNextTitle(pPara
);
1449 DBG_ASSERT( pPara
== nullptr, "sd::OutlineView::UpdateDocument(), slides are out of sync, creating missing ones" );
1452 SdPage
* pPage
= InsertSlideForParagraph( pPara
);
1453 mrDoc
.SetSelected(pPage
, false);
1455 mrOutlineViewShell
.UpdateTitleObject( pPage
, pPara
);
1456 mrOutlineViewShell
.UpdateOutlineObject( pPage
, pPara
);
1458 pPara
= GetNextTitle(pPara
);
1462 /** merge edit engine undo actions if possible */
1463 void OutlineView::TryToMergeUndoActions()
1465 SfxUndoManager
& rOutlineUndo
= mrOutliner
.GetUndoManager();
1466 if( rOutlineUndo
.GetUndoActionCount() <= 1 )
1469 SfxListUndoAction
* pListAction
= dynamic_cast< SfxListUndoAction
* >( rOutlineUndo
.GetUndoAction() );
1470 SfxListUndoAction
* pPrevListAction
= dynamic_cast< SfxListUndoAction
* >( rOutlineUndo
.GetUndoAction(1) );
1471 if( !(pListAction
&& pPrevListAction
) )
1474 // find the top EditUndo action in the top undo action list
1475 size_t nAction
= pListAction
->maUndoActions
.size();
1476 EditUndo
* pEditUndo
= nullptr;
1477 while( !pEditUndo
&& nAction
)
1479 pEditUndo
= dynamic_cast< EditUndo
* >(pListAction
->GetUndoAction(--nAction
));
1482 sal_uInt16 nEditPos
= nAction
; // we need this later to remove the merged undo actions
1484 // make sure it is the only EditUndo action in the top undo list
1485 while( pEditUndo
&& nAction
)
1487 if( dynamic_cast< EditUndo
* >(pListAction
->GetUndoAction(--nAction
)) )
1488 pEditUndo
= nullptr;
1491 // do we have one and only one EditUndo action in the top undo list?
1495 // yes, see if we can merge it with the prev undo list
1497 nAction
= pPrevListAction
->maUndoActions
.size();
1498 EditUndo
* pPrevEditUndo
= nullptr;
1499 while( !pPrevEditUndo
&& nAction
)
1500 pPrevEditUndo
= dynamic_cast< EditUndo
* >(pPrevListAction
->GetUndoAction(--nAction
));
1502 if( !(pPrevEditUndo
&& pPrevEditUndo
->Merge( pEditUndo
)) )
1505 // ok we merged the only EditUndo of the top undo list with
1506 // the top EditUndo of the previous undo list
1508 // first remove the merged undo action
1509 assert( pListAction
->GetUndoAction(nEditPos
) == pEditUndo
&&
1510 "sd::OutlineView::TryToMergeUndoActions(), wrong edit pos!" );
1511 pListAction
->Remove(nEditPos
);
1513 if ( !pListAction
->maUndoActions
.empty() )
1515 // now we have to move all remaining doc undo actions from the top undo
1516 // list to the previous undo list and remove the top undo list
1518 size_t nCount
= pListAction
->maUndoActions
.size();
1519 size_t nDestAction
= pPrevListAction
->maUndoActions
.size();
1522 std::unique_ptr
<SfxUndoAction
> pTemp
= pListAction
->Remove(0);
1523 pPrevListAction
->Insert( std::move(pTemp
), nDestAction
++ );
1525 pPrevListAction
->nCurUndoAction
= pPrevListAction
->maUndoActions
.size();
1528 rOutlineUndo
.RemoveLastUndoAction();
1531 IMPL_LINK(OutlineView
, PaintingFirstLineHdl
, PaintFirstLineInfo
*, pInfo
, void)
1536 Paragraph
* pPara
= mrOutliner
.GetParagraph( pInfo
->mnPara
);
1537 EditEngine
& rEditEngine
= const_cast< EditEngine
& >( mrOutliner
.GetEditEngine() );
1539 Size
aImageSize( pInfo
->mpOutDev
->PixelToLogic( maSlideImage
.GetSizePixel() ) );
1540 Size
aOffset( 100, 100 );
1542 // paint slide number
1543 if( !(pPara
&& ::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
)) )
1546 ::tools::Long nPage
= 0; // todo, printing??
1547 for ( sal_Int32 n
= 0; n
<= pInfo
->mnPara
; n
++ )
1549 Paragraph
* p
= mrOutliner
.GetParagraph( n
);
1550 if ( ::Outliner::HasParaFlag(p
,ParaFlag::ISPAGE
) )
1554 ::tools::Long nBulletHeight
= static_cast<::tools::Long
>(mrOutliner
.GetLineHeight( pInfo
->mnPara
));
1555 ::tools::Long nFontHeight
= 0;
1556 if ( !rEditEngine
.IsFlatMode() )
1558 nFontHeight
= nBulletHeight
/ 5;
1562 nFontHeight
= (nBulletHeight
* 10) / 25;
1565 Size
aFontSz( 0, nFontHeight
);
1567 Size
aOutSize( 2000, nBulletHeight
);
1569 const float fImageHeight
= (static_cast<float>(aOutSize
.Height()) * float(4)) / float(7);
1570 if (aImageSize
.Width() != 0)
1572 const float fImageRatio
= static_cast<float>(aImageSize
.Height()) / static_cast<float>(aImageSize
.Width());
1573 aImageSize
.setWidth( static_cast<::tools::Long
>( fImageRatio
* fImageHeight
) );
1575 aImageSize
.setHeight( static_cast<::tools::Long
>(fImageHeight
) );
1577 Point
aImagePos( pInfo
->mrStartPos
);
1578 aImagePos
.AdjustX(aOutSize
.Width() - aImageSize
.Width() - aOffset
.Width() ) ;
1579 aImagePos
.AdjustY((aOutSize
.Height() - aImageSize
.Height()) / 2 );
1581 pInfo
->mpOutDev
->DrawImage( aImagePos
, aImageSize
, maSlideImage
);
1583 const bool bVertical
= mrOutliner
.IsVertical();
1584 const bool bRightToLeftPara
= rEditEngine
.IsRightToLeft( pInfo
->mnPara
);
1586 LanguageType eLang
= rEditEngine
.GetDefaultLanguage();
1588 Point
aTextPos( aImagePos
.X() - aOffset
.Width(), pInfo
->mrStartPos
.Y() );
1589 vcl::Font
aNewFont( OutputDevice::GetDefaultFont( DefaultFontType::SANS_UNICODE
, eLang
, GetDefaultFontFlags::NONE
) );
1590 aNewFont
.SetFontSize( aFontSz
);
1591 aNewFont
.SetVertical( bVertical
);
1592 aNewFont
.SetOrientation( Degree10(bVertical
? 2700 : 0) );
1593 aNewFont
.SetColor( COL_AUTO
);
1594 pInfo
->mpOutDev
->SetFont( aNewFont
);
1595 OUString aPageText
= OUString::number( nPage
);
1597 aTextSz
.setWidth( pInfo
->mpOutDev
->GetTextWidth( aPageText
) );
1598 aTextSz
.setHeight( pInfo
->mpOutDev
->GetTextHeight() );
1601 aTextPos
.AdjustY((aOutSize
.Height() - aTextSz
.Height()) / 2 );
1602 if ( !bRightToLeftPara
)
1604 aTextPos
.AdjustX( -(aTextSz
.Width()) );
1608 aTextPos
.AdjustX(aTextSz
.Width() );
1613 aTextPos
.AdjustY( -(aTextSz
.Width()) );
1614 aTextPos
.AdjustX(nBulletHeight
/ 2 );
1616 pInfo
->mpOutDev
->DrawText( aTextPos
, aPageText
);
1619 void OutlineView::UpdateParagraph( sal_Int32 nPara
)
1621 SfxItemSet
aNewAttrs2( mrOutliner
.GetParaAttribs( nPara
) );
1622 aNewAttrs2
.Put( maLRSpaceItem
);
1623 mrOutliner
.SetParaAttribs( nPara
, aNewAttrs2
);
1626 void OutlineView::OnBeginPasteOrDrop( PasteOrDropInfos
* /*pInfo*/ )
1630 /** this is called after a paste or drop operation, make sure that the newly inserted paragraphs
1631 get the correct style sheet and new slides are inserted. */
1632 void OutlineView::OnEndPasteOrDrop( PasteOrDropInfos
* pInfo
)
1634 SdPage
* pPage
= nullptr;
1635 SfxStyleSheetBasePool
* pStylePool
= GetDoc().GetStyleSheetPool();
1637 for( sal_Int32 nPara
= pInfo
->nStartPara
; nPara
<= pInfo
->nEndPara
; nPara
++ )
1639 Paragraph
* pPara
= mrOutliner
.GetParagraph( nPara
);
1641 bool bPage
= ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
);
1645 SdStyleSheet
* pStyleSheet
= dynamic_cast< SdStyleSheet
* >( mrOutliner
.GetStyleSheet( nPara
) );
1648 if ( pStyleSheet
->GetApiName() == "title" )
1654 continue; // fatality!?
1656 if( bPage
&& (nPara
!= pInfo
->nStartPara
) )
1658 // insert new slide for this paragraph
1659 pPage
= InsertSlideForParagraph( pPara
);
1663 // newly inserted non page paragraphs get the outline style
1665 pPage
= GetPageForParagraph( pPara
);
1669 SfxStyleSheet
* pStyle
= pPage
->GetStyleSheetForPresObj( bPage
? PresObjKind::Title
: PresObjKind::Outline
);
1673 const sal_Int16 nDepth
= mrOutliner
.GetDepth( nPara
);
1676 OUString aStyleSheetName
= pStyle
->GetName();
1677 if (!aStyleSheetName
.isEmpty())
1678 aStyleSheetName
= aStyleSheetName
.copy(0, aStyleSheetName
.getLength() - 1);
1679 aStyleSheetName
+= OUString::number( nDepth
);
1680 pStyle
= static_cast<SfxStyleSheet
*>( pStylePool
->Find( aStyleSheetName
, pStyle
->GetFamily() ) );
1681 DBG_ASSERT( pStyle
, "sd::OutlineView::OnEndPasteOrDrop(), Style not found!" );
1685 mrOutliner
.SetStyleSheet( nPara
, pStyle
);
1688 UpdateParagraph( nPara
);
1694 OutlineViewModelChangeGuard::OutlineViewModelChangeGuard( OutlineView
& rView
)
1697 mrView
.BeginModelChange();
1700 OutlineViewModelChangeGuard::~OutlineViewModelChangeGuard() COVERITY_NOEXCEPT_FALSE
1702 mrView
.EndModelChange();
1706 OutlineViewPageChangesGuard::OutlineViewPageChangesGuard( OutlineView
* pView
)
1710 mpView
->IgnoreCurrentPageChanges( true );
1713 OutlineViewPageChangesGuard::~OutlineViewPageChangesGuard()
1716 mpView
->IgnoreCurrentPageChanges( false );
1719 } // end of namespace sd
1721 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */