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 "uistrings.hrc"
30 #include <tools/debug.hxx>
31 #include <tools/diagnose_ex.h>
35 using namespace ::com::sun::star
;
36 TYPEINIT1( OSectionView
, SdrView
);
39 OSectionView::OSectionView( SdrModel
* pModel
, OReportSection
* _pSectionWindow
, OReportWindow
* pEditor
)
40 :SdrView( pModel
, _pSectionWindow
)
41 ,m_pReportWindow( pEditor
)
42 ,m_pSectionWindow(_pSectionWindow
)
44 // SetPagePaintingAllowed(false);
45 SetBufferedOutputAllowed(true);
46 SetBufferedOverlayAllowed(true);
47 SetPageBorderVisible(false);
49 SetQuickTextEditMode(false);
54 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);
74 void OSectionView::MakeVisible( const Rectangle
& rRect
, vcl::Window
& rWin
)
77 MapMode
aMap( rWin
.GetMapMode() );
78 const Point
aOrg( aMap
.GetOrigin() );
79 const Size
aVisSize( rWin
.GetOutputSize() );
80 const Rectangle
aVisRect( Point(-aOrg
.X(),-aOrg
.Y()), aVisSize
);
82 // check, if rectangle is inside visible area
83 if ( !aVisRect
.IsInside( rRect
) )
85 // calculate scroll distance; the rectangle must be inside the visible area
86 sal_Int32 nScrollX
= 0, nScrollY
= 0;
88 const sal_Int32 nVisLeft
= aVisRect
.Left();
89 const sal_Int32 nVisRight
= aVisRect
.Right();
90 const sal_Int32 nVisTop
= aVisRect
.Top();
91 const sal_Int32 nVisBottom
= aVisRect
.Bottom();
93 // don't scroll beyond the page size
94 Size aPageSize
= m_pSectionWindow
->getPage()->GetSize();
95 const sal_Int32 nPageWidth
= aPageSize
.Width();
96 const sal_Int32 nPageHeight
= aPageSize
.Height();
98 if ( nVisRight
+ nScrollX
> nPageWidth
)
99 nScrollX
= nPageWidth
- nVisRight
;
101 if ( nVisLeft
+ nScrollX
< 0 )
102 nScrollX
= -nVisLeft
;
104 if ( nVisBottom
+ nScrollY
> nPageHeight
)
105 nScrollY
= nPageHeight
- nVisBottom
;
107 if ( nVisTop
+ nScrollY
< 0 )
112 rWin
.Scroll( -nScrollX
, -nScrollY
);
113 aMap
.SetOrigin( Point( aOrg
.X() - nScrollX
, aOrg
.Y() - nScrollY
) );
114 rWin
.SetMapMode( aMap
);
118 if ( m_pReportWindow
)
120 const DlgEdHint
aHint( RPTUI_HINT_WINDOWSCROLLED
);
121 m_pReportWindow
->getReportView()->Broadcast( aHint
);
126 rWin
.Invalidate(INVALIDATE_NOERASE
);
130 void OSectionView::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
132 SdrView::Notify(rBC
,rHint
);
133 const SdrHint
* pSdrHint
= dynamic_cast<const SdrHint
*>(&rHint
);
136 const SdrObject
* pObj
= pSdrHint
->GetObject();
137 const SdrHintKind eKind
= pSdrHint
->GetKind();
138 // check for change of selected object
139 if(HINT_OBJCHG
== eKind
&& pObj
&& IsObjMarked(const_cast<SdrObject
*>(pObj
)))
141 else if ( eKind
== HINT_OBJREMOVED
)
142 ObjectRemovedInAliveMode(pObj
);
147 void OSectionView::ObjectRemovedInAliveMode( const SdrObject
* _pObject
)
149 const SdrMarkList
& rMarkedList
= GetMarkedObjectList();
150 const size_t nMark
= rMarkedList
.GetMarkCount();
152 for( size_t i
= 0; i
< nMark
; ++i
)
154 SdrObject
* pSdrObj
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
155 if (_pObject
== pSdrObj
)
157 SdrPageView
* pPgView
= GetSdrPageView();
159 MarkObj( pSdrObj
, pPgView
, true );
166 void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo
)
168 if (AreObjectsMarked())
170 // #i11702# use SdrUndoObjectLayerChange for undo
171 // STR_UNDO_SELATTR is "Attributes" - should use a different text later
174 const SdrMarkList
& rMark
= GetMarkedObjectList();
175 const size_t nCount
= rMark
.GetMarkCount();
176 for (size_t i
= 0; i
<nCount
; ++i
)
178 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
179 if ( pObj
->ISA(OCustomShape
) )
181 AddUndo( new SdrUndoObjectLayerChange( *pObj
, pObj
->GetLayer(), _nLayerNo
) );
182 pObj
->SetLayer( _nLayerNo
);
183 OObjectBase
& rBaseObj
= dynamic_cast<OObjectBase
&>(*pObj
);
186 rBaseObj
.getReportComponent()->setPropertyValue(PROPERTY_OPAQUE
,uno::makeAny(_nLayerNo
== RPT_LAYER_FRONT
));
188 catch(const uno::Exception
&)
190 DBG_UNHANDLED_EXCEPTION();
197 // check mark list now instead of later in a timer
199 MarkListHasChanged();
203 bool OSectionView::OnlyShapesMarked() const
205 const SdrMarkList
& rMark
= GetMarkedObjectList();
206 const size_t nCount
= rMark
.GetMarkCount();
209 for (size_t i
= 0; i
<nCount
; ++i
)
211 SdrObject
* pObj
= rMark
.GetMark(i
)->GetMarkedSdrObj();
212 if ( !pObj
->ISA(OCustomShape
) )
220 bool OSectionView::IsDragResize() const
222 const SdrDragMethod
* pDragMethod
= GetDragMethod();
225 bool bMoveOnly
= pDragMethod
->getMoveOnly();
228 // current marked components will be resized
236 short OSectionView::GetLayerIdOfMarkedObjects() const
238 short nRet
= SHRT_MAX
;
239 const SdrMarkList
&rMrkList
= GetMarkedObjectList();
240 for ( size_t i
= 0; i
< rMrkList
.GetMarkCount(); ++i
)
242 const SdrObject
*pObj
= rMrkList
.GetMark( i
)->GetMarkedSdrObj();
243 if ( nRet
== SHRT_MAX
)
244 nRet
= pObj
->GetLayer();
245 else if ( nRet
!= pObj
->GetLayer() )
251 if ( nRet
== SHRT_MAX
)
260 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */