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>
32 #include <o3tl/make_unique.hxx>
36 using namespace ::com::sun::star
;
38 OSectionView::OSectionView(
40 OReportSection
* _pSectionWindow
,
41 OReportWindow
* pEditor
)
42 : SdrView(rSdrModel
, _pSectionWindow
)
43 ,m_pReportWindow( pEditor
)
44 ,m_pSectionWindow(_pSectionWindow
)
46 // SetPagePaintingAllowed(false);
47 SetBufferedOutputAllowed(true);
48 SetBufferedOverlayAllowed(true);
49 SetPageBorderVisible(false);
51 SetQuickTextEditMode(false);
55 OSectionView::~OSectionView()
60 void OSectionView::MarkListHasChanged()
62 SdrView::MarkListHasChanged();
64 if ( m_pReportWindow
&& m_pSectionWindow
&& !m_pSectionWindow
->getPage()->getSpecialMode() )
66 DlgEdHint
aHint( RPTUI_HINT_SELECTIONCHANGED
);
67 m_pReportWindow
->getReportView()->Broadcast( aHint
);
68 m_pReportWindow
->getReportView()->UpdatePropertyBrowserDelayed(*this);
73 void OSectionView::MakeVisible( const tools::Rectangle
& rRect
, vcl::Window
& rWin
)
76 MapMode
aMap( rWin
.GetMapMode() );
77 const Point
aOrg( aMap
.GetOrigin() );
78 const Size
aVisSize( rWin
.GetOutputSize() );
79 const tools::Rectangle
aVisRect( Point(-aOrg
.X(),-aOrg
.Y()), aVisSize
);
81 // check, if rectangle is inside visible area
82 if ( !aVisRect
.IsInside( rRect
) )
84 // calculate scroll distance; the rectangle must be inside the visible area
85 sal_Int32 nScrollX
= 0, nScrollY
= 0;
87 const sal_Int32 nVisLeft
= aVisRect
.Left();
88 const sal_Int32 nVisRight
= aVisRect
.Right();
89 const sal_Int32 nVisTop
= aVisRect
.Top();
90 const sal_Int32 nVisBottom
= aVisRect
.Bottom();
92 // don't scroll beyond the page size
93 Size aPageSize
= m_pSectionWindow
->getPage()->GetSize();
94 const sal_Int32 nPageWidth
= aPageSize
.Width();
95 const sal_Int32 nPageHeight
= aPageSize
.Height();
97 if ( nVisRight
+ nScrollX
> nPageWidth
)
98 nScrollX
= nPageWidth
- nVisRight
;
100 if ( nVisLeft
+ nScrollX
< 0 )
101 nScrollX
= -nVisLeft
;
103 if ( nVisBottom
+ nScrollY
> nPageHeight
)
104 nScrollY
= nPageHeight
- nVisBottom
;
106 if ( nVisTop
+ nScrollY
< 0 )
111 rWin
.Scroll( -nScrollX
, -nScrollY
);
112 aMap
.SetOrigin( Point( aOrg
.X() - nScrollX
, aOrg
.Y() - nScrollY
) );
113 rWin
.SetMapMode( aMap
);
117 if ( m_pReportWindow
)
119 const DlgEdHint
aHint( RPTUI_HINT_WINDOWSCROLLED
);
120 m_pReportWindow
->getReportView()->Broadcast( aHint
);
125 rWin
.Invalidate(InvalidateFlags::NoErase
);
129 void OSectionView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
131 SdrView::Notify(rBC
,rHint
);
132 const SdrHint
* pSdrHint
= dynamic_cast<const SdrHint
*>(&rHint
);
135 const SdrObject
* pObj
= pSdrHint
->GetObject();
136 const SdrHintKind eKind
= pSdrHint
->GetKind();
137 // check for change of selected object
138 if(SdrHintKind::ObjectChange
== eKind
&& pObj
&& IsObjMarked(pObj
))
140 else if ( eKind
== SdrHintKind::ObjectRemoved
)
141 ObjectRemovedInAliveMode(pObj
);
146 void OSectionView::ObjectRemovedInAliveMode( const SdrObject
* _pObject
)
148 const SdrMarkList
& rMarkedList
= GetMarkedObjectList();
149 const size_t nMark
= rMarkedList
.GetMarkCount();
151 for( size_t i
= 0; i
< nMark
; ++i
)
153 SdrObject
* pSdrObj
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
154 if (_pObject
== pSdrObj
)
156 SdrPageView
* pPgView
= GetSdrPageView();
158 MarkObj( pSdrObj
, pPgView
, true );
165 void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo
)
167 if (AreObjectsMarked())
169 // #i11702# use SdrUndoObjectLayerChange for undo
170 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
173 const SdrMarkList
& rMark
= GetMarkedObjectList();
174 const size_t nCount
= rMark
.GetMarkCount();
175 for (size_t i
= 0; i
<nCount
; ++i
)
177 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
178 if ( dynamic_cast< const OCustomShape
*>( pObj
) != nullptr )
180 AddUndo( o3tl::make_unique
<SdrUndoObjectLayerChange
>( *pObj
, pObj
->GetLayer(), _nLayerNo
) );
181 pObj
->SetLayer( _nLayerNo
);
182 OObjectBase
& rBaseObj
= dynamic_cast<OObjectBase
&>(*pObj
);
185 rBaseObj
.getReportComponent()->setPropertyValue(PROPERTY_OPAQUE
,uno::makeAny(_nLayerNo
== RPT_LAYER_FRONT
));
187 catch(const uno::Exception
&)
189 DBG_UNHANDLED_EXCEPTION("reportdesign");
196 // check mark list now instead of later in a timer
198 MarkListHasChanged();
202 bool OSectionView::OnlyShapesMarked() const
204 const SdrMarkList
& rMark
= GetMarkedObjectList();
205 const size_t nCount
= rMark
.GetMarkCount();
208 for (size_t i
= 0; i
<nCount
; ++i
)
210 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
211 if ( dynamic_cast< const OCustomShape
*>( pObj
) == nullptr )
219 bool OSectionView::IsDragResize() const
221 const SdrDragMethod
* pDragMethod
= GetDragMethod();
224 bool bMoveOnly
= pDragMethod
->getMoveOnly();
227 // current marked components will be resized
235 SdrLayerID
OSectionView::GetLayerIdOfMarkedObjects() const
237 SdrLayerID nRet
= SDRLAYER_NOTFOUND
;
238 const SdrMarkList
&rMrkList
= GetMarkedObjectList();
239 for ( size_t i
= 0; i
< rMrkList
.GetMarkCount(); ++i
)
241 const SdrObject
*pObj
= rMrkList
.GetMark( i
)->GetMarkedSdrObj();
242 if ( nRet
== SDRLAYER_NOTFOUND
)
243 nRet
= pObj
->GetLayer();
244 else if ( nRet
!= pObj
->GetLayer() )
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */