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/svxids.hrc>
25 #include <svx/svddrgmt.hxx>
26 #include <vcl/scrbar.hxx>
27 #include <ReportSection.hxx>
28 #include <ReportWindow.hxx>
29 #include <strings.hxx>
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
35 using namespace ::com::sun::star
;
37 OSectionView::OSectionView(
39 OReportSection
* _pSectionWindow
,
40 OReportWindow
* pEditor
)
41 : SdrView(rSdrModel
, _pSectionWindow
)
42 ,m_pReportWindow( pEditor
)
43 ,m_pSectionWindow(_pSectionWindow
)
45 // SetPagePaintingAllowed(false);
46 SetBufferedOutputAllowed(true);
47 SetBufferedOverlayAllowed(true);
48 SetPageBorderVisible(false);
50 SetQuickTextEditMode(false);
54 OSectionView::~OSectionView()
59 void OSectionView::MarkListHasChanged()
61 SdrView::MarkListHasChanged();
63 if ( m_pReportWindow
&& m_pSectionWindow
&& !m_pSectionWindow
->getPage()->getSpecialMode() )
65 DlgEdHint
aHint( RPTUI_HINT_SELECTIONCHANGED
);
66 m_pReportWindow
->getReportView()->Broadcast( aHint
);
67 m_pReportWindow
->getReportView()->UpdatePropertyBrowserDelayed(*this);
72 void OSectionView::MakeVisible( const tools::Rectangle
& rRect
, vcl::Window
& rWin
)
75 MapMode
aMap( rWin
.GetMapMode() );
76 const Point
aOrg( aMap
.GetOrigin() );
77 const Size
aVisSize( rWin
.GetOutputSize() );
78 const tools::Rectangle
aVisRect( Point(-aOrg
.X(),-aOrg
.Y()), aVisSize
);
80 // check, if rectangle is inside visible area
81 if ( !aVisRect
.IsInside( rRect
) )
83 // calculate scroll distance; the rectangle must be inside the visible area
84 sal_Int32 nScrollX
= 0, nScrollY
= 0;
86 const sal_Int32 nVisLeft
= aVisRect
.Left();
87 const sal_Int32 nVisRight
= aVisRect
.Right();
88 const sal_Int32 nVisTop
= aVisRect
.Top();
89 const sal_Int32 nVisBottom
= aVisRect
.Bottom();
91 // don't scroll beyond the page size
92 Size aPageSize
= m_pSectionWindow
->getPage()->GetSize();
93 const sal_Int32 nPageWidth
= aPageSize
.Width();
94 const sal_Int32 nPageHeight
= aPageSize
.Height();
96 if ( nVisRight
+ nScrollX
> nPageWidth
)
97 nScrollX
= nPageWidth
- nVisRight
;
99 if ( nVisLeft
+ nScrollX
< 0 )
100 nScrollX
= -nVisLeft
;
102 if ( nVisBottom
+ nScrollY
> nPageHeight
)
103 nScrollY
= nPageHeight
- nVisBottom
;
105 if ( nVisTop
+ nScrollY
< 0 )
110 rWin
.Scroll( -nScrollX
, -nScrollY
);
111 aMap
.SetOrigin( Point( aOrg
.X() - nScrollX
, aOrg
.Y() - nScrollY
) );
112 rWin
.SetMapMode( aMap
);
116 if ( m_pReportWindow
)
118 const DlgEdHint
aHint( RPTUI_HINT_WINDOWSCROLLED
);
119 m_pReportWindow
->getReportView()->Broadcast( aHint
);
124 rWin
.Invalidate(InvalidateFlags::NoErase
);
128 void OSectionView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
130 SdrView::Notify(rBC
,rHint
);
131 if (rHint
.GetId() != SfxHintId::ThisIsAnSdrHint
)
133 const SdrHint
* pSdrHint
= static_cast<const SdrHint
*>(&rHint
);
134 const SdrObject
* pObj
= pSdrHint
->GetObject();
135 const SdrHintKind eKind
= pSdrHint
->GetKind();
136 // check for change of selected object
137 if(SdrHintKind::ObjectChange
== eKind
&& pObj
&& IsObjMarked(pObj
))
139 else if ( eKind
== SdrHintKind::ObjectRemoved
)
140 ObjectRemovedInAliveMode(pObj
);
144 void OSectionView::ObjectRemovedInAliveMode( const SdrObject
* _pObject
)
146 const SdrMarkList
& rMarkedList
= GetMarkedObjectList();
147 const size_t nMark
= rMarkedList
.GetMarkCount();
149 for( size_t i
= 0; i
< nMark
; ++i
)
151 SdrObject
* pSdrObj
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
152 if (_pObject
== pSdrObj
)
154 SdrPageView
* pPgView
= GetSdrPageView();
156 MarkObj( pSdrObj
, pPgView
, true );
163 void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo
)
165 if (AreObjectsMarked())
167 // #i11702# use SdrUndoObjectLayerChange for undo
168 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
171 const SdrMarkList
& rMark
= GetMarkedObjectList();
172 const size_t nCount
= rMark
.GetMarkCount();
173 for (size_t i
= 0; i
<nCount
; ++i
)
175 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
176 if ( dynamic_cast< const OCustomShape
*>( pObj
) != nullptr )
178 AddUndo( std::make_unique
<SdrUndoObjectLayerChange
>( *pObj
, pObj
->GetLayer(), _nLayerNo
) );
179 pObj
->SetLayer( _nLayerNo
);
180 OObjectBase
& rBaseObj
= dynamic_cast<OObjectBase
&>(*pObj
);
183 rBaseObj
.getReportComponent()->setPropertyValue(PROPERTY_OPAQUE
,uno::makeAny(_nLayerNo
== RPT_LAYER_FRONT
));
185 catch(const uno::Exception
&)
187 DBG_UNHANDLED_EXCEPTION("reportdesign");
194 // check mark list now instead of later in a timer
196 MarkListHasChanged();
200 bool OSectionView::OnlyShapesMarked() const
202 const SdrMarkList
& rMark
= GetMarkedObjectList();
203 const size_t nCount
= rMark
.GetMarkCount();
206 for (size_t i
= 0; i
<nCount
; ++i
)
208 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
209 if ( dynamic_cast< const OCustomShape
*>( pObj
) == nullptr )
217 bool OSectionView::IsDragResize() const
219 const SdrDragMethod
* pDragMethod
= GetDragMethod();
222 bool bMoveOnly
= pDragMethod
->getMoveOnly();
225 // current marked components will be resized
233 SdrLayerID
OSectionView::GetLayerIdOfMarkedObjects() const
235 SdrLayerID nRet
= SDRLAYER_NOTFOUND
;
236 const SdrMarkList
&rMrkList
= GetMarkedObjectList();
237 for ( size_t i
= 0; i
< rMrkList
.GetMarkCount(); ++i
)
239 const SdrObject
*pObj
= rMrkList
.GetMark( i
)->GetMarkedSdrObj();
240 if ( nRet
== SDRLAYER_NOTFOUND
)
241 nRet
= pObj
->GetLayer();
242 else if ( nRet
!= pObj
->GetLayer() )
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */