bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / ui / report / SectionView.cxx
blob9a23632da48aa4b6d0e96c8d285e809fa7b8fe7d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
23 #include <RptDef.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>
33 namespace rptui
35 using namespace ::com::sun::star;
37 OSectionView::OSectionView(
38 SdrModel& rSdrModel,
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);
49 SetBordVisible();
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 )
74 // visible area
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 )
106 nScrollY = -nVisTop;
108 // scroll window
109 rWin.Update();
110 rWin.Scroll( -nScrollX, -nScrollY );
111 aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
112 rWin.SetMapMode( aMap );
113 rWin.Update();
114 rWin.Invalidate();
116 if ( m_pReportWindow )
118 const DlgEdHint aHint( RPTUI_HINT_WINDOWSCROLLED );
119 m_pReportWindow->getReportView()->Broadcast( aHint );
122 else
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)
132 return;
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))
138 AdjustMarkHdl();
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();
155 BrkAction();
156 MarkObj( pSdrObj, pPgView, true );
157 break;
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
169 BegUndo( );
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");
192 EndUndo();
194 // check mark list now instead of later in a timer
195 CheckMarked();
196 MarkListHasChanged();
200 bool OSectionView::OnlyShapesMarked() const
202 const SdrMarkList& rMark = GetMarkedObjectList();
203 const size_t nCount = rMark.GetMarkCount();
204 if ( !nCount )
205 return false;
206 for (size_t i = 0; i<nCount; ++i)
208 SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
209 if ( dynamic_cast< const OCustomShape *>( pObj ) == nullptr )
211 return false;
214 return true;
217 bool OSectionView::IsDragResize() const
219 const SdrDragMethod* pDragMethod = GetDragMethod();
220 if (pDragMethod)
222 bool bMoveOnly = pDragMethod->getMoveOnly();
223 if (!bMoveOnly)
225 // current marked components will be resized
226 return true;
229 return false;
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() )
244 break;
247 return nRet;
251 } // rptui
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */