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>
39 #include <editeng/editobj.hxx>
40 #include <editeng/editund2.hxx>
42 #include <editeng/editview.hxx>
44 #include <com/sun/star/frame/XFrame.hpp>
46 #include <DrawDocShell.hxx>
47 #include <drawdoc.hxx>
51 #include <OutlineViewShell.hxx>
53 #include <strings.hrc>
55 #include <sdresid.hxx>
56 #include <Outliner.hxx>
57 #include <EventMultiplexer.hxx>
58 #include <ViewShellBase.hxx>
59 #include <ViewShellManager.hxx>
60 #include <undo/undomanager.hxx>
61 #include <stlsheet.hxx>
63 using namespace ::com::sun::star::uno
;
64 using namespace ::com::sun::star::frame
;
68 // a progress bar gets displayed when more than
69 // PROCESS_WITH_PROGRESS_THRESHOLD pages are concerned
70 #define PROCESS_WITH_PROGRESS_THRESHOLD 5
72 OutlineView::OutlineView( DrawDocShell
& rDocSh
, vcl::Window
* pWindow
, OutlineViewShell
& rOutlineViewShell
)
73 : ::sd::View(*rDocSh
.GetDoc(), pWindow
->GetOutDev(), &rOutlineViewShell
)
74 , mrOutlineViewShell(rOutlineViewShell
)
75 , mrOutliner(*mrDoc
.GetOutliner())
79 , maDocColor( COL_WHITE
)
80 , maLRSpaceItem(2000, 0, 0, EE_PARA_OUTLLRSPACE
)
82 bool bInitOutliner
= false;
84 if (mrOutliner
.GetViewCount() == 0)
86 // initialize Outliner: set Reference Device
88 mrOutliner
.Init( OutlinerMode::OutlineView
);
89 mrOutliner
.SetRefDevice( SD_MOD()->GetVirtualRefDevice() );
90 //viewsize without the width of the image and number in front
91 mnPaperWidth
= (mrOutlineViewShell
.GetActiveWindow()->GetViewSize().Width() - 4000);
92 mrOutliner
.SetPaperSize(Size(mnPaperWidth
, 400000000));
96 // width: DIN A4, two margins at 1 cm each
100 mpOutlinerViews
[0].reset( new OutlinerView(&mrOutliner
, pWindow
) );
101 mpOutlinerViews
[0]->SetOutputArea(::tools::Rectangle());
102 mrOutliner
.SetUpdateLayout(false);
103 mrOutliner
.InsertView(mpOutlinerViews
[0].get(), EE_APPEND
);
105 onUpdateStyleSettings( true );
109 // fill Outliner with contents
113 Link
<tools::EventMultiplexerEvent
&,void> aLink( LINK(this,OutlineView
,EventMultiplexerListener
) );
114 mrOutlineViewShell
.GetViewShellBase().GetEventMultiplexer()->AddEventListener(aLink
);
116 Reference
<XFrame
> xFrame
= mrOutlineViewShell
.GetViewShellBase().GetFrame()->GetFrame().GetFrameInterface();
117 maSlideImage
= vcl::CommandInfoProvider::GetImageForCommand(".uno:ShowSlide", xFrame
, vcl::ImageType::Size26
);
119 // Tell undo manager of the document about the undo manager of the
120 // outliner, so that the former can synchronize with the later.
121 sd::UndoManager
* pDocUndoMgr
= dynamic_cast<sd::UndoManager
*>(mpDocSh
->GetUndoManager());
122 if (pDocUndoMgr
!= nullptr)
123 pDocUndoMgr
->SetLinkedUndoManager(&mrOutliner
.GetUndoManager());
127 * Destructor, restore Links, clear Outliner
129 OutlineView::~OutlineView()
131 DBG_ASSERT(maDragAndDropModelGuard
== nullptr,
132 "sd::OutlineView::~OutlineView(), prior drag operation not finished correctly!");
134 Link
<tools::EventMultiplexerEvent
&,void> aLink( LINK(this,OutlineView
,EventMultiplexerListener
) );
135 mrOutlineViewShell
.GetViewShellBase().GetEventMultiplexer()->RemoveEventListener( aLink
);
136 DisconnectFromApplication();
140 // unregister OutlinerViews and destroy them
141 for (auto & rpView
: mpOutlinerViews
)
145 mrOutliner
.RemoveView( rpView
.get() );
150 if (mrOutliner
.GetViewCount() == 0)
152 // uninitialize Outliner: enable color display
154 EEControlBits nCntrl
= mrOutliner
.GetControlWord();
155 mrOutliner
.SetUpdateLayout(false); // otherwise there will be drawn on SetControlWord
156 mrOutliner
.SetControlWord(nCntrl
& ~EEControlBits::NOCOLORS
);
157 mrOutliner
.ForceAutoColor( SvtAccessibilityOptions::GetIsAutomaticFontColor() );
162 void OutlineView::ConnectToApplication()
164 // When the mode is switched to outline the main view shell grabs focus.
165 // This is done for getting cut/copy/paste commands on slides in the left
166 // pane (slide sorter view shell) to work properly.
167 SfxShell
* pTopViewShell
= mrOutlineViewShell
.GetViewShellBase().GetViewShellManager()->GetTopViewShell();
168 if (pTopViewShell
&& pTopViewShell
== &mrOutlineViewShell
)
170 mrOutlineViewShell
.GetActiveWindow()->GrabFocus();
173 Application::AddEventListener(LINK(this, OutlineView
, AppEventListenerHdl
));
176 void OutlineView::DisconnectFromApplication()
178 Application::RemoveEventListener(LINK(this, OutlineView
, AppEventListenerHdl
));
181 void OutlineView::Paint(const ::tools::Rectangle
& rRect
, ::sd::Window
const * pWin
)
183 OutlinerView
* pOlView
= GetViewByWindow(pWin
);
187 pOlView
->HideCursor();
188 pOlView
->Paint(rRect
);
190 pOlView
->ShowCursor(mbFirstPaint
);
192 mbFirstPaint
= false;
196 void OutlineView::AddDeviceToPaintView(OutputDevice
& rDev
, vcl::Window
* pWindow
)
199 bool bValidArea
= false;
200 ::tools::Rectangle aOutputArea
;
201 const Color
aWhiteColor( COL_WHITE
);
202 sal_uInt16 nView
= 0;
204 while (nView
< MAX_OUTLINERVIEWS
&& !bAdded
)
206 if (mpOutlinerViews
[nView
] == nullptr)
208 mpOutlinerViews
[nView
].reset( new OutlinerView(&mrOutliner
, dynamic_cast< ::sd::Window
* >(rDev
.GetOwnerWindow())) );
209 mpOutlinerViews
[nView
]->SetBackgroundColor( aWhiteColor
);
210 mrOutliner
.InsertView(mpOutlinerViews
[nView
].get(), EE_APPEND
);
215 mpOutlinerViews
[nView
]->SetOutputArea(aOutputArea
);
218 else if (!bValidArea
)
220 aOutputArea
= mpOutlinerViews
[nView
]->GetOutputArea();
227 // white background in Outliner
228 rDev
.SetBackground( Wallpaper( aWhiteColor
) );
230 ::sd::View::AddDeviceToPaintView(rDev
, pWindow
);
233 void OutlineView::DeleteDeviceFromPaintView(OutputDevice
& rDev
)
235 bool bRemoved
= false;
236 sal_uInt16 nView
= 0;
237 vcl::Window
* pWindow
;
239 while (nView
< MAX_OUTLINERVIEWS
&& !bRemoved
)
241 if (mpOutlinerViews
[nView
] != nullptr)
243 pWindow
= mpOutlinerViews
[nView
]->GetWindow();
245 if (pWindow
->GetOutDev() == &rDev
)
247 mrOutliner
.RemoveView( mpOutlinerViews
[nView
].get() );
248 mpOutlinerViews
[nView
].reset();
256 ::sd::View::DeleteDeviceFromPaintView(rDev
);
260 * Return a pointer to the OutlinerView corresponding to the window
262 OutlinerView
* OutlineView::GetViewByWindow (vcl::Window
const * pWin
) const
264 OutlinerView
* pOlView
= nullptr;
265 for (std::unique_ptr
<OutlinerView
> const & pView
: mpOutlinerViews
)
267 if (pView
!= nullptr)
269 if ( pWin
== pView
->GetWindow() )
271 pOlView
= pView
.get();
279 * Return the title before a random paragraph
281 Paragraph
* OutlineView::GetPrevTitle(const Paragraph
* pPara
)
283 sal_Int32 nPos
= mrOutliner
.GetAbsPos(pPara
);
289 pPara
= mrOutliner
.GetParagraph(--nPos
);
290 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
292 return const_cast< Paragraph
* >( pPara
);
301 * Return the title after a random paragraph
303 Paragraph
* OutlineView::GetNextTitle(const Paragraph
* pPara
)
305 Paragraph
* pResult
= const_cast< Paragraph
* >( pPara
);
307 sal_Int32 nPos
= mrOutliner
.GetAbsPos(pResult
);
311 pResult
= mrOutliner
.GetParagraph(++nPos
);
312 if( pResult
&& ::Outliner::HasParaFlag(pResult
, ParaFlag::ISPAGE
) )
321 * Handler for inserting pages (paragraphs)
323 IMPL_LINK( OutlineView
, ParagraphInsertedHdl
, Outliner::ParagraphHdlParam
, aParam
, void )
325 // we get calls to this handler during binary insert of drag and drop contents but
326 // we ignore it here and handle it later in OnEndPasteOrDrop()
327 if (maDragAndDropModelGuard
!= nullptr)
330 OutlineViewPageChangesGuard
aGuard(this);
332 sal_Int32 nAbsPos
= mrOutliner
.GetAbsPos( aParam
.pPara
);
334 UpdateParagraph( nAbsPos
);
336 if( (nAbsPos
== 0) ||
337 ::Outliner::HasParaFlag(aParam
.pPara
, ParaFlag::ISPAGE
) ||
338 ::Outliner::HasParaFlag(mrOutliner
.GetParagraph( nAbsPos
-1 ), ParaFlag::ISPAGE
) )
340 InsertSlideForParagraph( aParam
.pPara
);
344 /** creates and inserts an empty slide for the given paragraph */
345 SdPage
* OutlineView::InsertSlideForParagraph( Paragraph
* pPara
)
347 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::InsertSlideForParagraph(), model change without undo?!" );
349 OutlineViewPageChangesGuard
aGuard(this);
351 mrOutliner
.SetParaFlag( pPara
, ParaFlag::ISPAGE
);
352 // how many titles are there before the new title paragraph?
353 sal_uLong nExample
= 0; // position of the "example" page
354 sal_uLong nTarget
= 0; // position of insertion
357 pPara
= GetPrevTitle(pPara
);
362 // if a new paragraph is created via RETURN before the first paragraph, the
363 // Outliner reports the old paragraph (which was moved down) as a new
367 OUString aTest
= mrOutliner
.GetText(mrOutliner
.GetParagraph(0));
374 // the "example" page is the previous page - if it is available
377 nExample
= nTarget
- 1;
379 sal_uInt16 nPageCount
= mrDoc
.GetSdPageCount( PageKind::Standard
);
380 if( nExample
>= nPageCount
)
381 nExample
= nPageCount
- 1;
384 /**********************************************************************
385 * All the time, a standard page is created before a notes page.
386 * It is ensured that after each standard page the corresponding notes page
387 * follows. A handout page is exactly one handout page.
388 **********************************************************************/
390 // this page is exemplary
391 SdPage
* pExample
= mrDoc
.GetSdPage(static_cast<sal_uInt16
>(nExample
), PageKind::Standard
);
392 rtl::Reference
<SdPage
> pPage
= mrDoc
.AllocSdPage(false);
394 pPage
->SetLayoutName(pExample
->GetLayoutName());
397 mrDoc
.InsertPage(pPage
.get(), static_cast<sal_uInt16
>(nTarget
) * 2 + 1);
398 if( isRecordingUndo() )
399 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoNewPage(*pPage
));
401 // assign a master page to the standard page
402 pPage
->TRG_SetMasterPage(pExample
->TRG_GetMasterPage());
405 pPage
->SetSize(pExample
->GetSize());
406 pPage
->SetBorder( pExample
->GetLeftBorder(),
407 pExample
->GetUpperBorder(),
408 pExample
->GetRightBorder(),
409 pExample
->GetLowerBorder() );
411 // create new presentation objects (after <Title> or <Title with subtitle>
412 // follows <Title with outline>, otherwise apply the layout of the previous
414 AutoLayout eAutoLayout
= pExample
->GetAutoLayout();
415 if (eAutoLayout
== AUTOLAYOUT_TITLE
||
416 eAutoLayout
== AUTOLAYOUT_TITLE_ONLY
)
418 pPage
->SetAutoLayout(AUTOLAYOUT_TITLE_CONTENT
, true);
422 pPage
->SetAutoLayout(pExample
->GetAutoLayout(), true);
425 /**********************************************************************
426 |* now the notes page
427 \*********************************************************************/
428 pExample
= mrDoc
.GetSdPage(static_cast<sal_uInt16
>(nExample
), PageKind::Notes
);
429 rtl::Reference
<SdPage
> pNotesPage
= mrDoc
.AllocSdPage(false);
431 pNotesPage
->SetLayoutName(pExample
->GetLayoutName());
433 pNotesPage
->SetPageKind(PageKind::Notes
);
435 // insert (notes page)
436 mrDoc
.InsertPage(pNotesPage
.get(), static_cast<sal_uInt16
>(nTarget
) * 2 + 2);
437 if( isRecordingUndo() )
438 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoNewPage(*pNotesPage
));
440 // assign a master page to the notes page
441 pNotesPage
->TRG_SetMasterPage(pExample
->TRG_GetMasterPage());
443 // set page size, there must be already one page available
444 pNotesPage
->SetSize(pExample
->GetSize());
445 pNotesPage
->SetBorder( pExample
->GetLeftBorder(),
446 pExample
->GetUpperBorder(),
447 pExample
->GetRightBorder(),
448 pExample
->GetLowerBorder() );
450 // create presentation objects
451 pNotesPage
->SetAutoLayout(pExample
->GetAutoLayout(), true);
453 mrOutliner
.UpdateFields();
459 * Handler for deleting pages (paragraphs)
461 IMPL_LINK( OutlineView
, ParagraphRemovingHdl
, ::Outliner::ParagraphHdlParam
, aParam
, void )
463 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::ParagraphRemovingHdl(), model change without undo?!" );
465 OutlineViewPageChangesGuard
aGuard(this);
467 Paragraph
* pPara
= aParam
.pPara
;
468 if( !::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) )
471 // how many titles are in front of the title paragraph in question?
475 pPara
= GetPrevTitle(pPara
);
479 // delete page and notes page
480 sal_uInt16 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
481 SdrPage
* pPage
= mrDoc
.GetPage(nAbsPos
);
482 if( isRecordingUndo() )
483 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
484 mrDoc
.RemovePage(nAbsPos
);
486 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
487 pPage
= mrDoc
.GetPage(nAbsPos
);
488 if( isRecordingUndo() )
489 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
490 mrDoc
.RemovePage(nAbsPos
);
492 // progress display if necessary
493 if (mnPagesToProcess
)
498 mpProgress
->SetState(mnPagesProcessed
);
500 if (mnPagesProcessed
== mnPagesToProcess
)
503 mnPagesToProcess
= 0;
504 mnPagesProcessed
= 0;
507 aParam
.pOutliner
->UpdateFields();
511 * Handler for changing the indentation depth of paragraphs (requires inserting
512 * or deleting of pages in some cases)
514 IMPL_LINK( OutlineView
, DepthChangedHdl
, ::Outliner::DepthChangeHdlParam
, aParam
, void )
516 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::DepthChangedHdl(), no undo for model change?!" );
518 OutlineViewPageChangesGuard
aGuard(this);
520 Paragraph
* pPara
= aParam
.pPara
;
521 ::Outliner
* pOutliner
= aParam
.pOutliner
;
522 if( ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) && ((aParam
.nPrevFlags
& ParaFlag::ISPAGE
) == ParaFlag::NONE
) )
524 // the current paragraph is transformed into a slide
526 mrOutliner
.SetDepth( pPara
, -1 );
528 // are multiple level 1 paragraphs being brought to level 0 and we
529 // should start a progress view or a timer and didn't already?
530 if (mnPagesToProcess
== 0)
532 Window
* pActWin
= mrOutlineViewShell
.GetActiveWindow();
533 OutlinerView
* pOlView
= GetViewByWindow(pActWin
);
535 std::vector
<Paragraph
*> aSelList
;
536 pOlView
->CreateSelectionList(aSelList
);
538 mnPagesToProcess
= std::count_if(aSelList
.begin(), aSelList
.end(),
539 [&pOutliner
](const Paragraph
*pParagraph
) {
540 return !Outliner::HasParaFlag(pParagraph
, ParaFlag::ISPAGE
) &&
541 (pOutliner
->GetDepth(pOutliner
->GetAbsPos(pParagraph
)) <= 0);
544 mnPagesToProcess
++; // the paragraph being in level 0 already
545 // should be included
546 mnPagesProcessed
= 0;
548 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
)
550 mpProgress
.reset( new SfxProgress( GetDocSh(), SdResId(STR_CREATE_PAGES
), mnPagesToProcess
) );
554 mpDocSh
->SetWaitCursor( true );
558 ParagraphInsertedHdl( { aParam
.pOutliner
, aParam
.pPara
} );
562 // should there be a progress display?
563 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
)
566 mpProgress
->SetState(mnPagesProcessed
);
569 // was this the last page?
570 if (mnPagesProcessed
== mnPagesToProcess
)
572 if (mnPagesToProcess
> PROCESS_WITH_PROGRESS_THRESHOLD
&& mpProgress
)
577 mpDocSh
->SetWaitCursor( false );
579 mnPagesToProcess
= 0;
580 mnPagesProcessed
= 0;
582 pOutliner
->UpdateFields();
584 else if( !::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
) && ((aParam
.nPrevFlags
& ParaFlag::ISPAGE
) != ParaFlag::NONE
) )
586 // the paragraph was a page but now becomes a normal paragraph
588 // how many titles are before the title paragraph in question?
590 Paragraph
* pParagraph
= pPara
;
593 pParagraph
= GetPrevTitle(pParagraph
);
597 // delete page and notes page
599 sal_uInt16 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
600 SdrPage
* pPage
= mrDoc
.GetPage(nAbsPos
);
601 if( isRecordingUndo() )
602 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
603 mrDoc
.RemovePage(nAbsPos
);
605 nAbsPos
= static_cast<sal_uInt16
>(nPos
) * 2 + 1;
606 pPage
= mrDoc
.GetPage(nAbsPos
);
607 if( isRecordingUndo() )
608 AddUndo(mrDoc
.GetSdrUndoFactory().CreateUndoDeletePage(*pPage
));
609 mrDoc
.RemovePage(nAbsPos
);
611 pPage
= GetPageForParagraph( pPara
);
613 mrOutliner
.SetDepth( pPara
, (pPage
&& (static_cast<SdPage
*>(pPage
)->GetAutoLayout() == AUTOLAYOUT_TITLE
)) ? -1 : 0 );
615 // progress display if necessary
616 if (mnPagesToProcess
)
620 mpProgress
->SetState(mnPagesProcessed
);
622 if (mnPagesProcessed
== mnPagesToProcess
)
625 mnPagesToProcess
= 0;
626 mnPagesProcessed
= 0;
629 pOutliner
->UpdateFields();
631 else if ( (pOutliner
->GetPrevDepth() == 1) && ( pOutliner
->GetDepth( pOutliner
->GetAbsPos( pPara
) ) == 2 ) )
633 // how many titles are in front of the title paragraph in question?
636 Paragraph
* pParagraph
= pPara
;
639 pParagraph
= GetPrevTitle(pParagraph
);
646 SdPage
*pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPos
), PageKind::Standard
);
648 if(pPage
&& pPage
->GetPresObj(PresObjKind::Text
))
649 pOutliner
->SetDepth( pPara
, 0 );
653 // how many titles are in front of the title paragraph in question?
656 Paragraph
* pTempPara
= pPara
;
659 pTempPara
= GetPrevTitle(pTempPara
);
667 SdPage
* pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPos
), PageKind::Standard
);
672 SfxStyleSheet
* pStyleSheet
= nullptr;
673 sal_Int32 nPara
= pOutliner
->GetAbsPos( pPara
);
674 sal_Int16 nDepth
= pOutliner
->GetDepth( nPara
);
675 bool bSubTitle
= pPage
->GetPresObj(PresObjKind::Text
) != nullptr;
677 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
679 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Title
);
683 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Text
);
687 pStyleSheet
= pPage
->GetStyleSheetForPresObj( PresObjKind::Outline
);
691 OUString aNewStyleSheetName
= pStyleSheet
->GetName();
692 if (!aNewStyleSheetName
.isEmpty())
693 aNewStyleSheetName
= aNewStyleSheetName
.copy(0, aNewStyleSheetName
.getLength() - 1);
694 aNewStyleSheetName
+= OUString::number( nDepth
+1 );
695 SfxStyleSheetBasePool
* pStylePool
= mrDoc
.GetStyleSheetPool();
696 pStyleSheet
= static_cast<SfxStyleSheet
*>( pStylePool
->Find( aNewStyleSheetName
, pStyleSheet
->GetFamily() ) );
700 // before we set the style sheet we need to preserve the bullet item
701 // since all items will be deleted while setting a new style sheet
702 SfxItemSet
aOldAttrs( pOutliner
->GetParaAttribs( nPara
) );
704 pOutliner
->SetStyleSheet( nPara
, pStyleSheet
);
706 // restore the old bullet item but not if the style changed
707 if ( pOutliner
->GetPrevDepth() != -1 && nDepth
!= -1 &&
708 aOldAttrs
.GetItemState( EE_PARA_NUMBULLET
) == SfxItemState::SET
)
710 SfxItemSet
aAttrs( pOutliner
->GetParaAttribs( nPara
) );
711 aAttrs
.Put( *aOldAttrs
.GetItem( EE_PARA_NUMBULLET
) );
712 pOutliner
->SetParaAttribs( nPara
, aAttrs
);
717 * Handler for StatusEvents
719 IMPL_LINK_NOARG(OutlineView
, StatusEventHdl
, EditStatus
&, void)
721 ::sd::Window
* pWin
= mrOutlineViewShell
.GetActiveWindow();
722 OutlinerView
* pOutlinerView
= GetViewByWindow(pWin
);
723 ::tools::Rectangle aVis
= pOutlinerView
->GetVisArea();
724 ::tools::Rectangle
aText(Point(0,0),
726 mrOutliner
.GetTextHeight()));
727 ::tools::Rectangle
aWin(Point(0,0), pWin
->GetOutputSizePixel());
728 aWin
= pWin
->PixelToLogic(aWin
);
730 if (!aVis
.IsEmpty()) // not when opening
732 if (aWin
.GetHeight() > aText
.Bottom())
733 aText
.SetBottom( aWin
.GetHeight() );
735 mrOutlineViewShell
.InitWindows(Point(0,0), aText
.GetSize(), aVis
.TopLeft());
736 mrOutlineViewShell
.UpdateScrollBars();
740 IMPL_LINK_NOARG(OutlineView
, BeginDropHdl
, EditView
*, void)
742 DBG_ASSERT(maDragAndDropModelGuard
== nullptr,
743 "sd::OutlineView::BeginDropHdl(), prior drag operation not finished correctly!");
745 maDragAndDropModelGuard
.reset( new OutlineViewModelChangeGuard( *this ) );
748 IMPL_LINK_NOARG(OutlineView
, EndDropHdl
, EditView
*, void)
750 maDragAndDropModelGuard
.reset();
754 * Handler for the start of a paragraph movement
756 IMPL_LINK( OutlineView
, BeginMovingHdl
, ::Outliner
*, pOutliner
, void )
758 OutlineViewPageChangesGuard
aGuard(this);
760 // list of selected title paragraphs
761 mpOutlinerViews
[0]->CreateSelectionList(maSelectedParas
);
763 maSelectedParas
.erase(std::remove_if(maSelectedParas
.begin(), maSelectedParas
.end(),
764 [](const Paragraph
* pPara
) { return !Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
); }),
765 maSelectedParas
.end());
767 // select the pages belonging to the paragraphs on level 0 to select
769 sal_Int32 nParaPos
= 0;
770 Paragraph
* pPara
= pOutliner
->GetParagraph( 0 );
771 std::vector
<Paragraph
*>::const_iterator fiter
;
775 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) ) // one page?
777 maOldParaOrder
.push_back(pPara
);
778 SdPage
* pPage
= mrDoc
.GetSdPage(nPos
, PageKind::Standard
);
780 fiter
= std::find(maSelectedParas
.begin(),maSelectedParas
.end(),pPara
);
782 pPage
->SetSelected(fiter
!= maSelectedParas
.end());
786 pPara
= pOutliner
->GetParagraph( ++nParaPos
);
791 * Handler for the end of a paragraph movement
793 IMPL_LINK( OutlineView
, EndMovingHdl
, ::Outliner
*, pOutliner
, void )
795 OutlineViewPageChangesGuard
aGuard(this);
797 DBG_ASSERT( isRecordingUndo(), "sd::OutlineView::EndMovingHdl(), model change without undo?!" );
799 // look for insertion position via the first paragraph
800 Paragraph
* pSearchIt
= maSelectedParas
.empty() ? nullptr : *(maSelectedParas
.begin());
802 // look for the first of the selected paragraphs in the new ordering
803 sal_uInt16 nPosNewOrder
= 0;
804 sal_Int32 nParaPos
= 0;
805 Paragraph
* pPara
= pOutliner
->GetParagraph( 0 );
806 Paragraph
* pPrev
= nullptr;
807 while (pPara
&& pPara
!= pSearchIt
)
809 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) )
814 pPara
= pOutliner
->GetParagraph( ++nParaPos
);
817 sal_uInt16 nPos
= nPosNewOrder
; // don't change nPosNewOrder
820 nPos
= sal_uInt16(-1); // insert before the first page
824 // look for the predecessor in the old ordering
825 std::vector
<Paragraph
*>::const_iterator it
= std::find(maOldParaOrder
.begin(),
826 maOldParaOrder
.end(),
829 if (it
!= maOldParaOrder
.end())
830 nPos
= static_cast<sal_uInt16
>(it
-maOldParaOrder
.begin());
834 DBG_ASSERT(nPos
!= 0xffff, "Paragraph not found");
837 mrDoc
.MovePages(nPos
);
839 // deselect the pages again
840 sal_uInt16 nPageCount
= static_cast<sal_uInt16
>(maSelectedParas
.size());
843 SdPage
* pPage
= mrDoc
.GetSdPage(nPosNewOrder
, PageKind::Standard
);
844 pPage
->SetSelected(false);
849 pOutliner
->UpdateFields();
851 maSelectedParas
.clear();
852 maOldParaOrder
.clear();
856 * Look for the title text object in one page of the model
858 SdrTextObj
* OutlineView::GetTitleTextObject(SdrPage
const * pPage
)
860 const size_t nObjectCount
= pPage
->GetObjCount();
861 SdrTextObj
* pResult
= nullptr;
863 for (size_t nObject
= 0; nObject
< nObjectCount
; ++nObject
)
865 SdrObject
* pObject
= pPage
->GetObj(nObject
);
866 if (pObject
->GetObjInventor() == SdrInventor::Default
&&
867 pObject
->GetObjIdentifier() == SdrObjKind::TitleText
)
869 pResult
= static_cast<SdrTextObj
*>(pObject
);
877 * Look for the outline text object in one page of the model
879 SdrTextObj
* OutlineView::GetOutlineTextObject(SdrPage
const * pPage
)
881 const size_t nObjectCount
= pPage
->GetObjCount();
882 SdrTextObj
* pResult
= nullptr;
884 for (size_t nObject
= 0; nObject
< nObjectCount
; ++nObject
)
886 SdrObject
* pObject
= pPage
->GetObj(nObject
);
887 if (pObject
->GetObjInventor() == SdrInventor::Default
&&
888 pObject
->GetObjIdentifier() == SdrObjKind::OutlineText
)
890 pResult
= static_cast<SdrTextObj
*>(pObject
);
897 SdrTextObj
* OutlineView::CreateTitleTextObject(SdPage
* pPage
)
899 DBG_ASSERT( GetTitleTextObject(pPage
) == nullptr, "sd::OutlineView::CreateTitleTextObject(), there is already a title text object!" );
901 if( pPage
->GetAutoLayout() == AUTOLAYOUT_NONE
)
904 pPage
->SetAutoLayout( AUTOLAYOUT_TITLE_ONLY
, true );
908 // we already have a layout with a title but the title
909 // object was deleted, create a new one
910 pPage
->InsertAutoLayoutShape( nullptr, PresObjKind::Title
, false, pPage
->GetTitleRect(), true );
913 return GetTitleTextObject(pPage
);
916 SdrTextObj
* OutlineView::CreateOutlineTextObject(SdPage
* pPage
)
918 DBG_ASSERT( GetOutlineTextObject(pPage
) == nullptr, "sd::OutlineView::CreateOutlineTextObject(), there is already a layout text object!" );
920 AutoLayout eNewLayout
= pPage
->GetAutoLayout();
923 case AUTOLAYOUT_NONE
:
924 case AUTOLAYOUT_TITLE_ONLY
:
925 case AUTOLAYOUT_TITLE
: eNewLayout
= AUTOLAYOUT_TITLE_CONTENT
; break;
927 case AUTOLAYOUT_CHART
: eNewLayout
= AUTOLAYOUT_CHARTTEXT
; break;
931 case AUTOLAYOUT_OBJ
: eNewLayout
= AUTOLAYOUT_OBJTEXT
; break;
936 if( eNewLayout
!= pPage
->GetAutoLayout() )
938 pPage
->SetAutoLayout( eNewLayout
, true );
942 // we already have a layout with a text but the text
943 // object was deleted, create a new one
944 pPage
->InsertAutoLayoutShape( nullptr,
945 PresObjKind::Outline
,
946 false, pPage
->GetLayoutRect(), true );
949 return GetOutlineTextObject(pPage
);
952 /** updates draw model with all changes from outliner model */
953 void OutlineView::PrepareClose()
955 ::sd::UndoManager
* pDocUndoMgr
= dynamic_cast<sd::UndoManager
*>(mpDocSh
->GetUndoManager());
956 if (pDocUndoMgr
!= nullptr)
957 pDocUndoMgr
->SetLinkedUndoManager(nullptr);
959 mrOutliner
.GetUndoManager().Clear();
961 BegUndo(SdResId(STR_UNDO_CHANGE_TITLE_AND_LAYOUT
));
964 mrDoc
.SetSelected(GetActualPage(), true);
968 * Set attributes of the selected text
970 bool OutlineView::SetAttributes(const SfxItemSet
& rSet
, bool /*bSlide*/, bool /*bReplaceAll*/, bool /*bMaster*/)
974 OutlinerView
* pOlView
= GetViewByWindow(mrOutlineViewShell
.GetActiveWindow());
978 pOlView
->SetAttribs(rSet
);
982 mrOutlineViewShell
.Invalidate (SID_PREVIEW_STATE
);
988 * Get attributes of the selected text
990 void OutlineView::GetAttributes( SfxItemSet
& rTargetSet
, bool ) const
992 OutlinerView
* pOlView
= GetViewByWindow(
993 mrOutlineViewShell
.GetActiveWindow());
994 assert(pOlView
&& "No OutlinerView found");
996 rTargetSet
.Put( pOlView
->GetAttribs(), false );
999 /** creates outliner model from draw model */
1000 void OutlineView::FillOutliner()
1002 mrOutliner
.GetUndoManager().Clear();
1003 mrOutliner
.EnableUndo(false);
1005 const bool bPrevUpdateLayout
= mrOutliner
.SetUpdateLayout(false);
1007 Paragraph
* pTitleToSelect
= nullptr;
1008 sal_uInt16 nPageCount
= mrDoc
.GetSdPageCount(PageKind::Standard
);
1010 // fill outliner with paragraphs from slides title & (outlines|subtitles)
1011 for (sal_uInt16 nPage
= 0; nPage
< nPageCount
; nPage
++)
1013 SdPage
* pPage
= mrDoc
.GetSdPage(nPage
, PageKind::Standard
);
1014 Paragraph
* pPara
= nullptr;
1016 // take text from title shape
1017 SdrTextObj
* pTO
= GetTitleTextObject(pPage
);
1018 if(pTO
&& !(pTO
->IsEmptyPresObj()))
1020 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
1023 bool bVertical
= pOPO
->IsEffectivelyVertical();
1024 pOPO
->SetVertical( false );
1025 mrOutliner
.AddText(*pOPO
);
1026 pOPO
->SetVertical( bVertical
);
1027 pPara
= mrOutliner
.GetParagraph( mrOutliner
.GetParagraphCount()-1 );
1031 if( pPara
== nullptr ) // no title, insert an empty paragraph
1033 pPara
= mrOutliner
.Insert(OUString());
1034 mrOutliner
.SetDepth(pPara
, -1);
1036 // do not apply hard attributes from the previous paragraph
1037 mrOutliner
.SetParaAttribs( mrOutliner
.GetAbsPos(pPara
),
1038 mrOutliner
.GetEmptyItemSet() );
1040 mrOutliner
.SetStyleSheet( mrOutliner
.GetAbsPos( pPara
), pPage
->GetStyleSheetForPresObj( PresObjKind::Title
) );
1043 mrOutliner
.SetParaFlag( pPara
, ParaFlag::ISPAGE
);
1045 sal_Int32 nPara
= mrOutliner
.GetAbsPos( pPara
);
1047 UpdateParagraph( nPara
);
1049 // remember paragraph of currently selected page
1050 if (pPage
->IsSelected())
1051 pTitleToSelect
= pPara
;
1053 // take text from subtitle or outline
1054 pTO
= static_cast<SdrTextObj
*>(pPage
->GetPresObj(PresObjKind::Text
));
1055 const bool bSubTitle
= pTO
!= nullptr;
1057 if (!pTO
) // if no subtile found, try outline
1058 pTO
= GetOutlineTextObject(pPage
);
1060 if(pTO
&& !(pTO
->IsEmptyPresObj())) // found some text
1062 OutlinerParaObject
* pOPO
= pTO
->GetOutlinerParaObject();
1065 sal_Int32 nParaCount1
= mrOutliner
.GetParagraphCount();
1066 bool bVertical
= pOPO
->IsEffectivelyVertical();
1067 pOPO
->SetVertical( false );
1068 mrOutliner
.AddText(*pOPO
);
1069 pOPO
->SetVertical( bVertical
);
1071 sal_Int32 nParaCount2
= mrOutliner
.GetParagraphCount();
1072 for (sal_Int32 n
= nParaCount1
; n
< nParaCount2
; n
++)
1076 Paragraph
* p
= mrOutliner
.GetParagraph(n
);
1077 if(p
&& mrOutliner
.GetDepth( n
) > 0 )
1078 mrOutliner
.SetDepth(p
, 0);
1081 UpdateParagraph( n
);
1087 // place cursor at the start
1088 Paragraph
* pFirstPara
= mrOutliner
.GetParagraph( 0 );
1089 mpOutlinerViews
[0]->Select( pFirstPara
);
1090 mpOutlinerViews
[0]->Select( pFirstPara
, false );
1092 // select title of slide that was selected
1094 mpOutlinerViews
[0]->Select(pTitleToSelect
);
1098 mrOutliner
.EnableUndo(true);
1100 mrOutliner
.SetUpdateLayout(bPrevUpdateLayout
);
1104 * Handler for deleting of level 0 paragraphs (pages): Warning
1106 IMPL_LINK_NOARG(OutlineView
, RemovingPagesHdl
, OutlinerView
*, bool)
1108 sal_Int32 nNumOfPages
= mrOutliner
.GetSelPageCount();
1110 if (nNumOfPages
> PROCESS_WITH_PROGRESS_THRESHOLD
)
1112 mnPagesToProcess
= nNumOfPages
;
1113 mnPagesProcessed
= 0;
1116 if (mnPagesToProcess
)
1118 mpProgress
.reset( new SfxProgress( GetDocSh(), SdResId(STR_DELETE_PAGES
), mnPagesToProcess
) );
1120 mrOutliner
.UpdateFields();
1126 * Handler for indenting level 0 paragraphs (pages): Warning
1128 IMPL_LINK( OutlineView
, IndentingPagesHdl
, OutlinerView
*, pOutlinerView
, bool )
1130 return RemovingPagesHdl(pOutlinerView
);
1133 /** returns the first slide that is selected in the outliner or where
1134 the cursor is located */
1135 SdPage
* OutlineView::GetActualPage()
1137 ::sd::Window
* pWin
= mrOutlineViewShell
.GetActiveWindow();
1138 OutlinerView
* pActiveView
= GetViewByWindow(pWin
);
1140 std::vector
<Paragraph
*> aSelList
;
1141 pActiveView
->CreateSelectionList(aSelList
);
1143 Paragraph
*pPar
= aSelList
.empty() ? nullptr : *(aSelList
.begin());
1144 SdPage
* pCurrent
= GetPageForParagraph(pPar
);
1146 DBG_ASSERT( pCurrent
||
1147 (mpDocSh
->GetUndoManager() && static_cast< sd::UndoManager
*>(mpDocSh
->GetUndoManager())->IsDoing()) ||
1148 maDragAndDropModelGuard
,
1149 "sd::OutlineView::GetActualPage(), no current page?" );
1154 return mrDoc
.GetSdPage( 0, PageKind::Standard
);
1157 SdPage
* OutlineView::GetPageForParagraph( Paragraph
* pPara
)
1159 if( !::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
) )
1160 pPara
= GetPrevTitle(pPara
);
1162 sal_uInt32 nPageToSelect
= 0;
1165 pPara
= GetPrevTitle(pPara
);
1170 if( nPageToSelect
< static_cast<sal_uInt32
>(mrDoc
.GetSdPageCount( PageKind::Standard
)) )
1171 return mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPageToSelect
), PageKind::Standard
);
1176 Paragraph
* OutlineView::GetParagraphForPage( ::Outliner
const & rOutl
, SdPage
const * pPage
)
1178 // get the number of paragraphs with ident 0 we need to skip before
1179 // we find the actual page
1180 sal_uInt32 nPagesToSkip
= (pPage
->GetPageNum() - 1) >> 1;
1182 sal_Int32 nParaPos
= 0;
1183 Paragraph
* pPara
= rOutl
.GetParagraph( 0 );
1186 // if this paragraph is a page...
1187 if( ::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
) )
1189 // see if we already skipped enough pages
1190 if( 0 == nPagesToSkip
)
1191 break; // and if so, end the loop
1193 // we skipped another page
1197 // get next paragraph
1198 pPara
= mrOutliner
.GetParagraph( ++nParaPos
);
1204 /** selects the paragraph for the given page at the outliner view*/
1205 void OutlineView::SetActualPage( SdPage
const * pActual
)
1207 if( pActual
&& dynamic_cast<SdOutliner
&>(mrOutliner
).GetIgnoreCurrentPageChangesLevel()==0 && !mbFirstPaint
)
1209 // if we found a paragraph, select its text at the outliner view
1210 Paragraph
* pPara
= GetParagraphForPage( mrOutliner
, pActual
);
1212 mpOutlinerViews
[0]->Select( pPara
);
1217 * Get StyleSheet from the selection
1219 SfxStyleSheet
* OutlineView::GetStyleSheet() const
1221 ::sd::Window
* pActWin
= mrOutlineViewShell
.GetActiveWindow();
1222 OutlinerView
* pOlView
= GetViewByWindow(pActWin
);
1223 SfxStyleSheet
* pResult
= pOlView
->GetStyleSheet();
1228 * Mark pages as selected / not selected
1230 void OutlineView::SetSelectedPages()
1232 // list of selected title paragraphs
1233 std::vector
<Paragraph
*> aSelParas
;
1234 mpOutlinerViews
[0]->CreateSelectionList(aSelParas
);
1236 aSelParas
.erase(std::remove_if(aSelParas
.begin(), aSelParas
.end(),
1237 [](const Paragraph
* pPara
) { return !Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
); }),
1240 // select the pages belonging to the paragraphs on level 0 to select
1241 sal_uInt16 nPos
= 0;
1242 sal_Int32 nParaPos
= 0;
1243 Paragraph
*pPara
= mrOutliner
.GetParagraph( 0 );
1244 std::vector
<Paragraph
*>::const_iterator fiter
;
1248 if( ::Outliner::HasParaFlag(pPara
, ParaFlag::ISPAGE
) ) // one page
1250 SdPage
* pPage
= mrDoc
.GetSdPage(nPos
, PageKind::Standard
);
1251 DBG_ASSERT(pPage
!=nullptr,
1252 "Trying to select non-existing page OutlineView::SetSelectedPages()");
1256 fiter
= std::find(aSelParas
.begin(),aSelParas
.end(),pPara
);
1257 pPage
->SetSelected(fiter
!= aSelParas
.end());
1263 pPara
= mrOutliner
.GetParagraph( ++nParaPos
);
1270 void OutlineView::SetLinks()
1272 // set notification links
1273 mrOutliner
.SetParaInsertedHdl(LINK(this, OutlineView
, ParagraphInsertedHdl
));
1274 mrOutliner
.SetParaRemovingHdl(LINK(this, OutlineView
, ParagraphRemovingHdl
));
1275 mrOutliner
.SetDepthChangedHdl(LINK(this, OutlineView
, DepthChangedHdl
));
1276 mrOutliner
.SetBeginMovingHdl(LINK(this, OutlineView
, BeginMovingHdl
));
1277 mrOutliner
.SetEndMovingHdl(LINK(this, OutlineView
, EndMovingHdl
));
1278 mrOutliner
.SetRemovingPagesHdl(LINK(this, OutlineView
, RemovingPagesHdl
));
1279 mrOutliner
.SetIndentingPagesHdl(LINK(this, OutlineView
, IndentingPagesHdl
));
1280 mrOutliner
.SetStatusEventHdl(LINK(this, OutlineView
, StatusEventHdl
));
1281 mrOutliner
.SetBeginDropHdl(LINK(this,OutlineView
, BeginDropHdl
));
1282 mrOutliner
.SetEndDropHdl(LINK(this,OutlineView
, EndDropHdl
));
1283 mrOutliner
.SetPaintFirstLineHdl(LINK(this,OutlineView
,PaintingFirstLineHdl
));
1284 mrOutliner
.SetBeginPasteOrDropHdl(LINK(this,OutlineView
, BeginPasteOrDropHdl
));
1285 mrOutliner
.SetEndPasteOrDropHdl(LINK(this,OutlineView
, EndPasteOrDropHdl
));
1291 void OutlineView::ResetLinks() const
1293 mrOutliner
.SetParaInsertedHdl(Link
<::Outliner::ParagraphHdlParam
,void>());
1294 mrOutliner
.SetParaRemovingHdl(Link
<::Outliner::ParagraphHdlParam
,void>());
1295 mrOutliner
.SetDepthChangedHdl(Link
<::Outliner::DepthChangeHdlParam
,void>());
1296 mrOutliner
.SetBeginMovingHdl(Link
<::Outliner
*,void>());
1297 mrOutliner
.SetEndMovingHdl(Link
<::Outliner
*,void>());
1298 mrOutliner
.SetStatusEventHdl(Link
<EditStatus
&,void>());
1299 mrOutliner
.SetRemovingPagesHdl(Link
<OutlinerView
*,bool>());
1300 mrOutliner
.SetIndentingPagesHdl(Link
<OutlinerView
*,bool>());
1301 mrOutliner
.SetDrawPortionHdl(Link
<DrawPortionInfo
*,void>());
1302 mrOutliner
.SetBeginPasteOrDropHdl(Link
<PasteOrDropInfos
*,void>());
1303 mrOutliner
.SetEndPasteOrDropHdl(Link
<PasteOrDropInfos
*,void>());
1306 sal_Int8
OutlineView::AcceptDrop( const AcceptDropEvent
&, DropTargetHelper
&, SdrLayerID
)
1308 return DND_ACTION_NONE
;
1311 sal_Int8
OutlineView::ExecuteDrop( const ExecuteDropEvent
&, ::sd::Window
*, sal_uInt16
, SdrLayerID
)
1313 return DND_ACTION_NONE
;
1316 // Re-implement GetScriptType for this view to get correct results
1317 SvtScriptType
OutlineView::GetScriptType() const
1319 SvtScriptType nScriptType
= ::sd::View::GetScriptType();
1321 std::optional
<OutlinerParaObject
> pTempOPObj
= mrOutliner
.CreateParaObject();
1324 nScriptType
= pTempOPObj
->GetTextObject().GetScriptType();
1330 void OutlineView::onUpdateStyleSettings( bool bForceUpdate
/* = false */ )
1332 svtools::ColorConfig aColorConfig
;
1333 const Color
aDocColor( aColorConfig
.GetColorValue( svtools::DOCCOLOR
).nColor
);
1334 if( !(bForceUpdate
|| (maDocColor
!= aDocColor
)) )
1338 for( nView
= 0; nView
< MAX_OUTLINERVIEWS
; nView
++ )
1340 if (mpOutlinerViews
[nView
] != nullptr)
1342 mpOutlinerViews
[nView
]->SetBackgroundColor( aDocColor
);
1344 vcl::Window
* pWindow
= mpOutlinerViews
[nView
]->GetWindow();
1347 pWindow
->SetBackground( Wallpaper( aDocColor
) );
1352 mrOutliner
.SetBackgroundColor( aDocColor
);
1354 maDocColor
= aDocColor
;
1357 IMPL_LINK_NOARG(OutlineView
, AppEventListenerHdl
, VclSimpleEvent
&, void)
1359 onUpdateStyleSettings(false);
1362 IMPL_LINK(OutlineView
, EventMultiplexerListener
, ::sd::tools::EventMultiplexerEvent
&, rEvent
, void)
1364 switch (rEvent
.meEventId
)
1366 case EventMultiplexerEventId::CurrentPageChanged
:
1367 SetActualPage(mrOutlineViewShell
.GetActualPage());
1370 case EventMultiplexerEventId::PageOrder
:
1371 if (dynamic_cast<SdOutliner
&>(mrOutliner
).GetIgnoreCurrentPageChangesLevel()==0)
1373 if (((mrDoc
.GetPageCount()-1)%2) == 0)
1377 ::sd::Window
* pWindow
= mrOutlineViewShell
.GetActiveWindow();
1378 if (pWindow
!= nullptr)
1379 pWindow
->Invalidate();
1388 void OutlineView::IgnoreCurrentPageChanges (bool bIgnoreChanges
)
1391 dynamic_cast<SdOutliner
&>(mrOutliner
).IncreIgnoreCurrentPageChangesLevel();
1393 dynamic_cast<SdOutliner
&>(mrOutliner
).DecreIgnoreCurrentPageChangesLevel();
1396 /** call this method before you do anything that can modify the outliner
1397 and or the drawing document model. It will create needed undo actions */
1398 void OutlineView::BeginModelChange()
1400 mrOutliner
.GetUndoManager().EnterListAction("", "", 0, mrOutlineViewShell
.GetViewShellBase().GetViewShellId());
1401 BegUndo(SdResId(STR_UNDO_CHANGE_TITLE_AND_LAYOUT
));
1404 /** call this method after BeginModelChange(), when all possible model
1405 changes are done. */
1406 void OutlineView::EndModelChange()
1410 SfxUndoManager
* pDocUndoMgr
= mpDocSh
->GetUndoManager();
1412 bool bHasUndoActions
= pDocUndoMgr
->GetUndoActionCount() != 0;
1416 DBG_ASSERT( bHasUndoActions
== (mrOutliner
.GetUndoManager().GetUndoActionCount() != 0), "sd::OutlineView::EndModelChange(), undo actions not in sync!" );
1418 mrOutliner
.GetUndoManager().LeaveListAction();
1420 if( bHasUndoActions
&& mrOutliner
.GetEditEngine().HasTriedMergeOnLastAddUndo() )
1421 TryToMergeUndoActions();
1423 mrOutlineViewShell
.Invalidate( SID_UNDO
);
1424 mrOutlineViewShell
.Invalidate( SID_REDO
);
1427 /** updates all changes in the outliner model to the draw model */
1428 void OutlineView::UpdateDocument()
1430 OutlineViewPageChangesGuard
aGuard(this);
1432 const sal_uInt32 nPageCount
= mrDoc
.GetSdPageCount(PageKind::Standard
);
1433 Paragraph
* pPara
= mrOutliner
.GetParagraph( 0 );
1435 for (nPage
= 0; nPage
< nPageCount
; nPage
++)
1437 SdPage
* pPage
= mrDoc
.GetSdPage( static_cast<sal_uInt16
>(nPage
), PageKind::Standard
);
1438 mrDoc
.SetSelected(pPage
, false);
1440 mrOutlineViewShell
.UpdateTitleObject( pPage
, pPara
);
1441 mrOutlineViewShell
.UpdateOutlineObject( pPage
, pPara
);
1444 pPara
= GetNextTitle(pPara
);
1447 DBG_ASSERT( pPara
== nullptr, "sd::OutlineView::UpdateDocument(), slides are out of sync, creating missing ones" );
1450 SdPage
* pPage
= InsertSlideForParagraph( pPara
);
1451 mrDoc
.SetSelected(pPage
, false);
1453 mrOutlineViewShell
.UpdateTitleObject( pPage
, pPara
);
1454 mrOutlineViewShell
.UpdateOutlineObject( pPage
, pPara
);
1456 pPara
= GetNextTitle(pPara
);
1460 /** merge edit engine undo actions if possible */
1461 void OutlineView::TryToMergeUndoActions()
1463 SfxUndoManager
& rOutlineUndo
= mrOutliner
.GetUndoManager();
1464 if( rOutlineUndo
.GetUndoActionCount() <= 1 )
1467 SfxListUndoAction
* pListAction
= dynamic_cast< SfxListUndoAction
* >( rOutlineUndo
.GetUndoAction() );
1468 SfxListUndoAction
* pPrevListAction
= dynamic_cast< SfxListUndoAction
* >( rOutlineUndo
.GetUndoAction(1) );
1469 if( !(pListAction
&& pPrevListAction
) )
1472 // find the top EditUndo action in the top undo action list
1473 size_t nAction
= pListAction
->maUndoActions
.size();
1474 EditUndo
* pEditUndo
= nullptr;
1475 while( !pEditUndo
&& nAction
)
1477 pEditUndo
= dynamic_cast< EditUndo
* >(pListAction
->GetUndoAction(--nAction
));
1480 sal_uInt16 nEditPos
= nAction
; // we need this later to remove the merged undo actions
1482 // make sure it is the only EditUndo action in the top undo list
1483 while( pEditUndo
&& nAction
)
1485 if( dynamic_cast< EditUndo
* >(pListAction
->GetUndoAction(--nAction
)) )
1486 pEditUndo
= nullptr;
1489 // do we have one and only one EditUndo action in the top undo list?
1493 // yes, see if we can merge it with the prev undo list
1495 nAction
= pPrevListAction
->maUndoActions
.size();
1496 EditUndo
* pPrevEditUndo
= nullptr;
1497 while( !pPrevEditUndo
&& nAction
)
1498 pPrevEditUndo
= dynamic_cast< EditUndo
* >(pPrevListAction
->GetUndoAction(--nAction
));
1500 if( !(pPrevEditUndo
&& pPrevEditUndo
->Merge( pEditUndo
)) )
1503 // ok we merged the only EditUndo of the top undo list with
1504 // the top EditUndo of the previous undo list
1506 // first remove the merged undo action
1507 assert( pListAction
->GetUndoAction(nEditPos
) == pEditUndo
&&
1508 "sd::OutlineView::TryToMergeUndoActions(), wrong edit pos!" );
1509 pListAction
->Remove(nEditPos
);
1511 if ( !pListAction
->maUndoActions
.empty() )
1513 // now we have to move all remaining doc undo actions from the top undo
1514 // list to the previous undo list and remove the top undo list
1516 size_t nCount
= pListAction
->maUndoActions
.size();
1517 size_t nDestAction
= pPrevListAction
->maUndoActions
.size();
1520 std::unique_ptr
<SfxUndoAction
> pTemp
= pListAction
->Remove(0);
1521 pPrevListAction
->Insert( std::move(pTemp
), nDestAction
++ );
1523 pPrevListAction
->nCurUndoAction
= pPrevListAction
->maUndoActions
.size();
1526 rOutlineUndo
.RemoveLastUndoAction();
1529 IMPL_LINK(OutlineView
, PaintingFirstLineHdl
, PaintFirstLineInfo
*, pInfo
, void)
1534 Paragraph
* pPara
= mrOutliner
.GetParagraph( pInfo
->mnPara
);
1535 EditEngine
& rEditEngine
= const_cast< EditEngine
& >( mrOutliner
.GetEditEngine() );
1537 Size
aImageSize( pInfo
->mpOutDev
->PixelToLogic( maSlideImage
.GetSizePixel() ) );
1538 Size
aOffset( 100, 100 );
1540 // paint slide number
1541 if( !(pPara
&& ::Outliner::HasParaFlag(pPara
,ParaFlag::ISPAGE
)) )
1544 ::tools::Long nPage
= 0; // todo, printing??
1545 for ( sal_Int32 n
= 0; n
<= pInfo
->mnPara
; n
++ )
1547 Paragraph
* p
= mrOutliner
.GetParagraph( n
);
1548 if ( ::Outliner::HasParaFlag(p
,ParaFlag::ISPAGE
) )
1552 ::tools::Long nBulletHeight
= static_cast<::tools::Long
>(mrOutliner
.GetLineHeight( pInfo
->mnPara
));
1553 ::tools::Long nFontHeight
= 0;
1554 if ( !rEditEngine
.IsFlatMode() )
1556 nFontHeight
= nBulletHeight
/ 5;
1560 nFontHeight
= (nBulletHeight
* 10) / 25;
1563 Size
aFontSz( 0, nFontHeight
);
1565 Size
aOutSize( 2000, nBulletHeight
);
1567 const float fImageHeight
= (static_cast<float>(aOutSize
.Height()) * float(4)) / float(7);
1568 if (aImageSize
.Width() != 0)
1570 const float fImageRatio
= static_cast<float>(aImageSize
.Height()) / static_cast<float>(aImageSize
.Width());
1571 aImageSize
.setWidth( static_cast<::tools::Long
>( fImageRatio
* fImageHeight
) );
1573 aImageSize
.setHeight( static_cast<::tools::Long
>(fImageHeight
) );
1575 Point
aImagePos( pInfo
->mrStartPos
);
1576 aImagePos
.AdjustX(aOutSize
.Width() - aImageSize
.Width() - aOffset
.Width() ) ;
1577 aImagePos
.AdjustY((aOutSize
.Height() - aImageSize
.Height()) / 2 );
1579 pInfo
->mpOutDev
->DrawImage( aImagePos
, aImageSize
, maSlideImage
);
1581 const bool bVertical
= mrOutliner
.IsVertical();
1582 const bool bRightToLeftPara
= rEditEngine
.IsRightToLeft( pInfo
->mnPara
);
1584 LanguageType eLang
= rEditEngine
.GetDefaultLanguage();
1586 Point
aTextPos( aImagePos
.X() - aOffset
.Width(), pInfo
->mrStartPos
.Y() );
1587 vcl::Font
aNewFont( OutputDevice::GetDefaultFont( DefaultFontType::SANS_UNICODE
, eLang
, GetDefaultFontFlags::NONE
) );
1588 aNewFont
.SetFontSize( aFontSz
);
1589 aNewFont
.SetVertical( bVertical
);
1590 aNewFont
.SetOrientation( Degree10(bVertical
? 2700 : 0) );
1591 aNewFont
.SetColor( COL_AUTO
);
1592 pInfo
->mpOutDev
->SetFont( aNewFont
);
1593 OUString aPageText
= OUString::number( nPage
);
1595 aTextSz
.setWidth( pInfo
->mpOutDev
->GetTextWidth( aPageText
) );
1596 aTextSz
.setHeight( pInfo
->mpOutDev
->GetTextHeight() );
1599 aTextPos
.AdjustY((aOutSize
.Height() - aTextSz
.Height()) / 2 );
1600 if ( !bRightToLeftPara
)
1602 aTextPos
.AdjustX( -(aTextSz
.Width()) );
1606 aTextPos
.AdjustX(aTextSz
.Width() );
1611 aTextPos
.AdjustY( -(aTextSz
.Width()) );
1612 aTextPos
.AdjustX(nBulletHeight
/ 2 );
1614 pInfo
->mpOutDev
->DrawText( aTextPos
, aPageText
);
1617 void OutlineView::UpdateParagraph( sal_Int32 nPara
)
1619 SfxItemSet
aNewAttrs2( mrOutliner
.GetParaAttribs( nPara
) );
1620 aNewAttrs2
.Put( maLRSpaceItem
);
1621 mrOutliner
.SetParaAttribs( nPara
, aNewAttrs2
);
1624 void OutlineView::OnBeginPasteOrDrop( PasteOrDropInfos
* /*pInfo*/ )
1628 /** this is called after a paste or drop operation, make sure that the newly inserted paragraphs
1629 get the correct style sheet and new slides are inserted. */
1630 void OutlineView::OnEndPasteOrDrop( PasteOrDropInfos
* pInfo
)
1632 SdPage
* pPage
= nullptr;
1633 SfxStyleSheetBasePool
* pStylePool
= GetDoc().GetStyleSheetPool();
1635 for( sal_Int32 nPara
= pInfo
->nStartPara
; nPara
<= pInfo
->nEndPara
; nPara
++ )
1637 Paragraph
* pPara
= mrOutliner
.GetParagraph( nPara
);
1639 bool bPage
= ::Outliner::HasParaFlag( pPara
, ParaFlag::ISPAGE
);
1643 SdStyleSheet
* pStyleSheet
= dynamic_cast< SdStyleSheet
* >( mrOutliner
.GetStyleSheet( nPara
) );
1646 if ( pStyleSheet
->GetApiName() == "title" )
1652 continue; // fatality!?
1654 if( bPage
&& (nPara
!= pInfo
->nStartPara
) )
1656 // insert new slide for this paragraph
1657 pPage
= InsertSlideForParagraph( pPara
);
1661 // newly inserted non page paragraphs get the outline style
1663 pPage
= GetPageForParagraph( pPara
);
1667 SfxStyleSheet
* pStyle
= pPage
->GetStyleSheetForPresObj( bPage
? PresObjKind::Title
: PresObjKind::Outline
);
1671 const sal_Int16 nDepth
= mrOutliner
.GetDepth( nPara
);
1674 OUString aStyleSheetName
= pStyle
->GetName();
1675 if (!aStyleSheetName
.isEmpty())
1676 aStyleSheetName
= aStyleSheetName
.copy(0, aStyleSheetName
.getLength() - 1);
1677 aStyleSheetName
+= OUString::number( nDepth
);
1678 pStyle
= static_cast<SfxStyleSheet
*>( pStylePool
->Find( aStyleSheetName
, pStyle
->GetFamily() ) );
1679 DBG_ASSERT( pStyle
, "sd::OutlineView::OnEndPasteOrDrop(), Style not found!" );
1683 mrOutliner
.SetStyleSheet( nPara
, pStyle
);
1686 UpdateParagraph( nPara
);
1692 OutlineViewModelChangeGuard::OutlineViewModelChangeGuard( OutlineView
& rView
)
1695 mrView
.BeginModelChange();
1698 OutlineViewModelChangeGuard::~OutlineViewModelChangeGuard() COVERITY_NOEXCEPT_FALSE
1700 mrView
.EndModelChange();
1704 OutlineViewPageChangesGuard::OutlineViewPageChangesGuard( OutlineView
* pView
)
1708 mpView
->IgnoreCurrentPageChanges( true );
1711 OutlineViewPageChangesGuard::~OutlineViewPageChangesGuard()
1714 mpView
->IgnoreCurrentPageChanges( false );
1717 } // end of namespace sd
1719 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */