LibreOffice Module reportdesign (master)  1
SectionView.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #include <SectionView.hxx>
20 #include <DesignView.hxx>
21 #include <RptPage.hxx>
22 #include <RptObject.hxx>
23 #include <RptDef.hxx>
24 #include <svx/svddrgmt.hxx>
25 #include <ReportSection.hxx>
26 #include <ReportWindow.hxx>
27 #include <strings.hxx>
28 #include <tools/diagnose_ex.h>
29 
30 namespace rptui
31 {
32  using namespace ::com::sun::star;
33 
35  SdrModel& rSdrModel,
36  OReportSection* _pSectionWindow,
37  OReportWindow* pEditor)
38 : SdrView(rSdrModel, _pSectionWindow->GetOutDev())
39  ,m_pReportWindow( pEditor )
40  ,m_pSectionWindow(_pSectionWindow)
41 {
42  // SetPagePaintingAllowed(false);
45  SetPageBorderVisible(false);
47  SetQuickTextEditMode(false);
48 }
49 
50 
52 {
53 }
54 
55 
57 {
59 
60  if ( m_pReportWindow && m_pSectionWindow && !m_pSectionWindow->getPage()->getSpecialMode() )
61  {
63  m_pReportWindow->getReportView()->Broadcast( aHint );
64  m_pReportWindow->getReportView()->UpdatePropertyBrowserDelayed(*this);
65  }
66 }
67 
68 
70 {
71  // visible area
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 );
76 
77  // check, if rectangle is inside visible area
78  if ( !aVisRect.IsInside( rRect ) )
79  {
80  // calculate scroll distance; the rectangle must be inside the visible area
81  sal_Int32 nScrollX = 0, nScrollY = 0;
82 
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();
87 
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();
92 
93  if ( nVisRight + nScrollX > nPageWidth )
94  nScrollX = nPageWidth - nVisRight;
95 
96  if ( nVisLeft + nScrollX < 0 )
97  nScrollX = -nVisLeft;
98 
99  if ( nVisBottom + nScrollY > nPageHeight )
100  nScrollY = nPageHeight - nVisBottom;
101 
102  if ( nVisTop + nScrollY < 0 )
103  nScrollY = -nVisTop;
104 
105  // scroll window
106  rWin.PaintImmediately();
107  rWin.Scroll( -nScrollX, -nScrollY );
108  aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
109  rWin.SetMapMode( aMap );
110  rWin.Invalidate();
111 
112  if ( m_pReportWindow )
113  {
114  const DlgEdHint aHint( RPTUI_HINT_WINDOWSCROLLED );
115  m_pReportWindow->getReportView()->Broadcast( aHint );
116  }
117  }
118  else
119  {
120  rWin.Invalidate(InvalidateFlags::NoErase);
121  }
122 }
123 
124 void OSectionView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
125 {
126  SdrView::Notify(rBC,rHint);
127  if (rHint.GetId() != SfxHintId::ThisIsAnSdrHint)
128  return;
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))
134  AdjustMarkHdl();
135  else if ( eKind == SdrHintKind::ObjectRemoved )
137 }
138 
139 
141 {
142  const SdrMarkList& rMarkedList = GetMarkedObjectList();
143  const size_t nMark = rMarkedList.GetMarkCount();
144 
145  for( size_t i = 0; i < nMark; ++i )
146  {
147  SdrObject* pSdrObj = rMarkedList.GetMark(i)->GetMarkedSdrObj();
148  if (_pObject == pSdrObj)
149  {
150  SdrPageView* pPgView = GetSdrPageView();
151  BrkAction();
152  MarkObj( pSdrObj, pPgView, true );
153  break;
154  }
155  }
156 }
157 
158 
160 {
161  if (!AreObjectsMarked())
162  return;
163 
164  // #i11702# use SdrUndoObjectLayerChange for undo
165  // STR_UNDO_SELATTR is "Attributes" - should use a different text later
166  BegUndo( );
167 
168  const SdrMarkList& rMark = GetMarkedObjectList();
169  const size_t nCount = rMark.GetMarkCount();
170  for (size_t i = 0; i<nCount; ++i)
171  {
172  SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
173  if ( dynamic_cast< const OCustomShape *>( pObj ) != nullptr )
174  {
175  AddUndo( std::make_unique<SdrUndoObjectLayerChange>( *pObj, pObj->GetLayer(), _nLayerNo) );
176  pObj->SetLayer( _nLayerNo );
177  OObjectBase& rBaseObj = dynamic_cast<OObjectBase&>(*pObj);
178  try
179  {
180  rBaseObj.getReportComponent()->setPropertyValue(PROPERTY_OPAQUE,uno::makeAny(_nLayerNo == RPT_LAYER_FRONT));
181  }
182  catch(const uno::Exception&)
183  {
184  DBG_UNHANDLED_EXCEPTION("reportdesign");
185  }
186  }
187  }
188 
189  EndUndo();
190 
191  // check mark list now instead of later in a timer
192  CheckMarked();
194 }
195 
197 {
198  const SdrMarkList& rMark = GetMarkedObjectList();
199  const size_t nCount = rMark.GetMarkCount();
200  if ( !nCount )
201  return false;
202  for (size_t i = 0; i<nCount; ++i)
203  {
204  SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
205  if ( dynamic_cast< const OCustomShape *>( pObj ) == nullptr )
206  {
207  return false;
208  }
209  }
210  return true;
211 }
212 
214 {
215  const SdrDragMethod* pDragMethod = GetDragMethod();
216  if (pDragMethod)
217  {
218  bool bMoveOnly = pDragMethod->getMoveOnly();
219  if (!bMoveOnly)
220  {
221  // current marked components will be resized
222  return true;
223  }
224  }
225  return false;
226 }
227 
228 
230 {
232  const SdrMarkList &rMrkList = GetMarkedObjectList();
233  for ( size_t i = 0; i < rMrkList.GetMarkCount(); ++i )
234  {
235  const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
236  if ( nRet == SDRLAYER_NOTFOUND )
237  nRet = pObj->GetLayer();
238  else if ( nRet != pObj->GetLayer() )
239  {
240  break;
241  }
242  }
243  return nRet;
244 }
245 
246 
247 } // rptui
248 
249 
250 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OSectionView(const OSectionView &)=delete
SdrHintKind GetKind() const
size_t GetMarkCount() const
bool AreObjectsMarked() const
SdrHintKind
VclPtr< OReportWindow > m_pReportWindow
Definition: SectionView.hxx:37
void BegUndo()
SdrMark * GetMark(size_t nNum) const
SdrLayerID GetLayerIdOfMarkedObjects() const
void ObjectRemovedInAliveMode(const SdrObject *pObject)
void PaintImmediately()
virtual void MarkListHasChanged() override
SfxHintId GetId() const
virtual void MarkListHasChanged() override
Definition: SectionView.cxx:56
const css::uno::Reference< css::report::XReportComponent > & getReportComponent() const
Definition: RptObject.hxx:105
virtual ~OSectionView() override
Definition: SectionView.cxx:51
constexpr tools::Long Width() const
void SetBufferedOutputAllowed(bool bNew)
HashMap_OWString_Interface aMap
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
bool getMoveOnly() const
int nCount
void SetBordVisible(bool bOn=true)
constexpr SdrLayerID RPT_LAYER_FRONT(0)
constexpr SdrLayerID SDRLAYER_NOTFOUND(0xff)
const tools::Long nScrollY
virtual void MakeVisible(const tools::Rectangle &rRect, vcl::Window &rWin) override
Definition: SectionView.cxx:69
void EndUndo()
const tools::Long nScrollX
#define PROPERTY_OPAQUE
Definition: strings.hxx:207
SdrObject * GetMarkedSdrObj() const
void AddUndo(std::unique_ptr< SdrUndoAction > pUndo)
virtual void SetLayer(SdrLayerID nLayer)
#define DBG_UNHANDLED_EXCEPTION(...)
SdrDragMethod * GetDragMethod() const
void SetBufferedOverlayAllowed(bool bNew)
int i
void SetQuickTextEditMode(bool bOn)
const MapMode & GetMapMode() const
virtual void Invalidate(InvalidateFlags nFlags=InvalidateFlags::NONE)
const SdrMarkList & GetMarkedObjectList() const
Size GetOutputSize() const
VclPtr< OReportSection > m_pSectionWindow
Definition: SectionView.hxx:38
bool IsDragResize() const
bool OnlyShapesMarked() const
void SetMarkedToLayer(SdrLayerID nLayerNo)
virtual SdrLayerID GetLayer() const
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
virtual void Scroll(tools::Long nHorzScroll, tools::Long nVertScroll, ScrollFlags nFlags=ScrollFlags::NONE)
constexpr tools::Long Height() const
::OutputDevice const * GetOutDev() const
void AdjustMarkHdl(SfxViewShell *pOtherShell=nullptr)
SdrPageView * GetSdrPageView() const
void SetPageBorderVisible(bool bOn=true)
bool MarkObj(const Point &rPnt, short nTol=-2, bool bToggle=false, bool bDeep=false)
virtual void BrkAction() override
void SetMapMode()
void CheckMarked()
bool IsObjMarked(SdrObject const *pObj) const
const SdrObject * GetObject() const