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 .
19 #include <SectionView.hxx>
20 #include <DesignView.hxx>
21 #include <RptPage.hxx>
22 #include <RptObject.hxx>
24 #include <svx/svddrgmt.hxx>
25 #include <ReportSection.hxx>
26 #include <ReportWindow.hxx>
27 #include <strings.hxx>
28 #include <tools/diagnose_ex.h>
32 using namespace ::com::sun::star
;
34 OSectionView::OSectionView(
36 OReportSection
* _pSectionWindow
,
37 OReportWindow
* pEditor
)
38 : SdrView(rSdrModel
, _pSectionWindow
->GetOutDev())
39 ,m_pReportWindow( pEditor
)
40 ,m_pSectionWindow(_pSectionWindow
)
42 // SetPagePaintingAllowed(false);
43 SetBufferedOutputAllowed(true);
44 SetBufferedOverlayAllowed(true);
45 SetPageBorderVisible(false);
47 SetQuickTextEditMode(false);
51 OSectionView::~OSectionView()
56 void OSectionView::MarkListHasChanged()
58 SdrView::MarkListHasChanged();
60 if ( m_pReportWindow
&& m_pSectionWindow
&& !m_pSectionWindow
->getPage()->getSpecialMode() )
62 DlgEdHint
aHint( RPTUI_HINT_SELECTIONCHANGED
);
63 m_pReportWindow
->getReportView()->Broadcast( aHint
);
64 m_pReportWindow
->getReportView()->UpdatePropertyBrowserDelayed(*this);
69 void OSectionView::MakeVisible( const tools::Rectangle
& rRect
, vcl::Window
& rWin
)
72 MapMode
aMap( rWin
.GetMapMode() );
73 const Point
aOrg( aMap
.GetOrigin() );
74 const Size
aVisSize( rWin
.GetOutDev()->GetOutputSize() );
75 const tools::Rectangle
aVisRect( Point(-aOrg
.X(),-aOrg
.Y()), aVisSize
);
77 // check, if rectangle is inside visible area
78 if ( !aVisRect
.Contains( rRect
) )
80 // calculate scroll distance; the rectangle must be inside the visible area
81 sal_Int32 nScrollX
= 0, nScrollY
= 0;
83 const sal_Int32 nVisLeft
= aVisRect
.Left();
84 const sal_Int32 nVisRight
= aVisRect
.Right();
85 const sal_Int32 nVisTop
= aVisRect
.Top();
86 const sal_Int32 nVisBottom
= aVisRect
.Bottom();
88 // don't scroll beyond the page size
89 Size aPageSize
= m_pSectionWindow
->getPage()->GetSize();
90 const sal_Int32 nPageWidth
= aPageSize
.Width();
91 const sal_Int32 nPageHeight
= aPageSize
.Height();
93 if ( nVisRight
+ nScrollX
> nPageWidth
)
94 nScrollX
= nPageWidth
- nVisRight
;
96 if ( nVisLeft
+ nScrollX
< 0 )
99 if ( nVisBottom
+ nScrollY
> nPageHeight
)
100 nScrollY
= nPageHeight
- nVisBottom
;
102 if ( nVisTop
+ nScrollY
< 0 )
106 rWin
.PaintImmediately();
107 rWin
.Scroll( -nScrollX
, -nScrollY
);
108 aMap
.SetOrigin( Point( aOrg
.X() - nScrollX
, aOrg
.Y() - nScrollY
) );
109 rWin
.SetMapMode( aMap
);
112 if ( m_pReportWindow
)
114 const DlgEdHint
aHint( RPTUI_HINT_WINDOWSCROLLED
);
115 m_pReportWindow
->getReportView()->Broadcast( aHint
);
120 rWin
.Invalidate(InvalidateFlags::NoErase
);
124 void OSectionView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
126 SdrView::Notify(rBC
,rHint
);
127 if (rHint
.GetId() != SfxHintId::ThisIsAnSdrHint
)
129 const SdrHint
* pSdrHint
= static_cast<const SdrHint
*>(&rHint
);
130 const SdrObject
* pObj
= pSdrHint
->GetObject();
131 const SdrHintKind eKind
= pSdrHint
->GetKind();
132 // check for change of selected object
133 if(SdrHintKind::ObjectChange
== eKind
&& pObj
&& IsObjMarked(pObj
))
135 else if ( eKind
== SdrHintKind::ObjectRemoved
)
136 ObjectRemovedInAliveMode(pObj
);
140 void OSectionView::ObjectRemovedInAliveMode( const SdrObject
* _pObject
)
142 const SdrMarkList
& rMarkedList
= GetMarkedObjectList();
143 const size_t nMark
= rMarkedList
.GetMarkCount();
145 for( size_t i
= 0; i
< nMark
; ++i
)
147 SdrObject
* pSdrObj
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
148 if (_pObject
== pSdrObj
)
150 SdrPageView
* pPgView
= GetSdrPageView();
152 MarkObj( pSdrObj
, pPgView
, true );
159 void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo
)
161 if (!AreObjectsMarked())
164 // #i11702# use SdrUndoObjectLayerChange for undo
165 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
168 const SdrMarkList
& rMark
= GetMarkedObjectList();
169 const size_t nCount
= rMark
.GetMarkCount();
170 for (size_t i
= 0; i
<nCount
; ++i
)
172 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
173 if ( dynamic_cast< const OCustomShape
*>( pObj
) != nullptr )
175 AddUndo( std::make_unique
<SdrUndoObjectLayerChange
>( *pObj
, pObj
->GetLayer(), _nLayerNo
) );
176 pObj
->SetLayer( _nLayerNo
);
177 OObjectBase
& rBaseObj
= dynamic_cast<OObjectBase
&>(*pObj
);
180 rBaseObj
.getReportComponent()->setPropertyValue(PROPERTY_OPAQUE
,uno::makeAny(_nLayerNo
== RPT_LAYER_FRONT
));
182 catch(const uno::Exception
&)
184 DBG_UNHANDLED_EXCEPTION("reportdesign");
191 // check mark list now instead of later in a timer
193 MarkListHasChanged();
196 bool OSectionView::OnlyShapesMarked() const
198 const SdrMarkList
& rMark
= GetMarkedObjectList();
199 const size_t nCount
= rMark
.GetMarkCount();
202 for (size_t i
= 0; i
<nCount
; ++i
)
204 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
205 if ( dynamic_cast< const OCustomShape
*>( pObj
) == nullptr )
213 bool OSectionView::IsDragResize() const
215 const SdrDragMethod
* pDragMethod
= GetDragMethod();
218 bool bMoveOnly
= pDragMethod
->getMoveOnly();
221 // current marked components will be resized
229 SdrLayerID
OSectionView::GetLayerIdOfMarkedObjects() const
231 SdrLayerID nRet
= SDRLAYER_NOTFOUND
;
232 const SdrMarkList
&rMrkList
= GetMarkedObjectList();
233 for ( size_t i
= 0; i
< rMrkList
.GetMarkCount(); ++i
)
235 const SdrObject
*pObj
= rMrkList
.GetMark( i
)->GetMarkedSdrObj();
236 if ( nRet
== SDRLAYER_NOTFOUND
)
237 nRet
= pObj
->GetLayer();
238 else if ( nRet
!= pObj
->GetLayer() )
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */