19e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
39e0e4191SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
49e0e4191SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
59e0e4191SAndrew Rist  * distributed with this work for additional information
69e0e4191SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
79e0e4191SAndrew Rist  * to you under the Apache License, Version 2.0 (the
89e0e4191SAndrew Rist  * "License"); you may not use this file except in compliance
99e0e4191SAndrew Rist  * with the License.  You may obtain a copy of the License at
109e0e4191SAndrew Rist  *
119e0e4191SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
129e0e4191SAndrew Rist  *
139e0e4191SAndrew Rist  * Unless required by applicable law or agreed to in writing,
149e0e4191SAndrew Rist  * software distributed under the License is distributed on an
159e0e4191SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0e4191SAndrew Rist  * KIND, either express or implied.  See the License for the
179e0e4191SAndrew Rist  * specific language governing permissions and limitations
189e0e4191SAndrew Rist  * under the License.
199e0e4191SAndrew Rist  *
209e0e4191SAndrew Rist  *************************************************************/
219e0e4191SAndrew Rist 
229e0e4191SAndrew Rist 
23*b63233d8Sdamjan #include "precompiled_rptui.hxx"
24cdf0e10cSrcweir #include "SectionView.hxx"
25cdf0e10cSrcweir #include "DesignView.hxx"
26cdf0e10cSrcweir #include <RptPage.hxx>
27cdf0e10cSrcweir #include <RptObject.hxx>
28cdf0e10cSrcweir #include <RptDef.hxx>
29cdf0e10cSrcweir #include <svx/svxids.hrc>
30cdf0e10cSrcweir #include <svx/svddrgmt.hxx>
31cdf0e10cSrcweir #include <vcl/scrbar.hxx>
32cdf0e10cSrcweir #include "ReportSection.hxx"
33cdf0e10cSrcweir #include "ReportWindow.hxx"
34cdf0e10cSrcweir #include "uistrings.hrc"
35cdf0e10cSrcweir #include <tools/debug.hxx>
36cdf0e10cSrcweir #include <tools/diagnose_ex.h>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace rptui
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     using namespace ::com::sun::star;
41cdf0e10cSrcweir TYPEINIT1( OSectionView, SdrView );
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //----------------------------------------------------------------------------
DBG_NAME(rpt_OSectionView)44cdf0e10cSrcweir DBG_NAME( rpt_OSectionView )
45cdf0e10cSrcweir OSectionView::OSectionView( SdrModel* pModel, OReportSection* _pSectionWindow, OReportWindow* pEditor )
46cdf0e10cSrcweir 	:SdrView( pModel, _pSectionWindow )
47cdf0e10cSrcweir 	,m_pReportWindow( pEditor )
48cdf0e10cSrcweir 	,m_pSectionWindow(_pSectionWindow)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	DBG_CTOR( rpt_OSectionView,NULL);
51cdf0e10cSrcweir     // SetPagePaintingAllowed(false);
52cdf0e10cSrcweir     SetBufferedOutputAllowed(true);
53cdf0e10cSrcweir     SetBufferedOverlayAllowed(true);
54cdf0e10cSrcweir     SetPageBorderVisible(false);
55cdf0e10cSrcweir     SetBordVisible();
56cdf0e10cSrcweir     SetQuickTextEditMode(sal_False);
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
59cdf0e10cSrcweir //----------------------------------------------------------------------------
60cdf0e10cSrcweir 
~OSectionView()61cdf0e10cSrcweir OSectionView::~OSectionView()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	DBG_DTOR( rpt_OSectionView,NULL);
64cdf0e10cSrcweir }
65cdf0e10cSrcweir 
66cdf0e10cSrcweir //----------------------------------------------------------------------------
67cdf0e10cSrcweir 
MarkListHasChanged()68cdf0e10cSrcweir void OSectionView::MarkListHasChanged()
69cdf0e10cSrcweir {
70cdf0e10cSrcweir 	DBG_CHKTHIS( rpt_OSectionView,NULL);
71cdf0e10cSrcweir 	SdrView::MarkListHasChanged();
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	if ( m_pReportWindow && m_pSectionWindow && !m_pSectionWindow->getPage()->getSpecialMode() )
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir 		//m_pReportWindow->unmarkAllObjects(this); // WHY
76cdf0e10cSrcweir 		DlgEdHint aHint( RPTUI_HINT_SELECTIONCHANGED );
77cdf0e10cSrcweir 		m_pReportWindow->getReportView()->Broadcast( aHint );
78cdf0e10cSrcweir         m_pReportWindow->getReportView()->UpdatePropertyBrowserDelayed(*this);
79cdf0e10cSrcweir     }
80cdf0e10cSrcweir }
81cdf0e10cSrcweir 
82cdf0e10cSrcweir //----------------------------------------------------------------------------
83cdf0e10cSrcweir 
MakeVisible(const Rectangle & rRect,Window & rWin)84cdf0e10cSrcweir void OSectionView::MakeVisible( const Rectangle& rRect, Window& rWin )
85cdf0e10cSrcweir {
86cdf0e10cSrcweir 	DBG_CHKTHIS( rpt_OSectionView,NULL);
87cdf0e10cSrcweir 	// visible area
88cdf0e10cSrcweir 	MapMode aMap( rWin.GetMapMode() );
89cdf0e10cSrcweir 	const Point aOrg( aMap.GetOrigin() );
90cdf0e10cSrcweir 	const Size aVisSize( rWin.GetOutputSize() );
91cdf0e10cSrcweir 	const Rectangle aVisRect( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	// check, if rectangle is inside visible area
94cdf0e10cSrcweir 	if ( !aVisRect.IsInside( rRect ) )
95cdf0e10cSrcweir 	{
96cdf0e10cSrcweir 		// calculate scroll distance; the rectangle must be inside the visible area
97cdf0e10cSrcweir 		sal_Int32 nScrollX = 0, nScrollY = 0;
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 		const sal_Int32 nVisLeft   = aVisRect.Left();
100cdf0e10cSrcweir 		const sal_Int32 nVisRight  = aVisRect.Right();
101cdf0e10cSrcweir 		const sal_Int32 nVisTop    = aVisRect.Top();
102cdf0e10cSrcweir 		const sal_Int32 nVisBottom = aVisRect.Bottom();
103cdf0e10cSrcweir 
104cdf0e10cSrcweir 		// don't scroll beyond the page size
105cdf0e10cSrcweir 		Size aPageSize = m_pSectionWindow->getPage()->GetSize();
106cdf0e10cSrcweir 		const sal_Int32 nPageWidth  = aPageSize.Width();
107cdf0e10cSrcweir 		const sal_Int32 nPageHeight = aPageSize.Height();
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 		if ( nVisRight + nScrollX > nPageWidth )
110cdf0e10cSrcweir 			nScrollX = nPageWidth - nVisRight;
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 		if ( nVisLeft + nScrollX < 0 )
113cdf0e10cSrcweir 			nScrollX = -nVisLeft;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 		if ( nVisBottom + nScrollY > nPageHeight )
116cdf0e10cSrcweir 			nScrollY = nPageHeight - nVisBottom;
117cdf0e10cSrcweir 
118cdf0e10cSrcweir 		if ( nVisTop + nScrollY < 0 )
119cdf0e10cSrcweir 			nScrollY = -nVisTop;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 		// scroll window
122cdf0e10cSrcweir 		rWin.Update();
123cdf0e10cSrcweir 		rWin.Scroll( -nScrollX, -nScrollY );
124cdf0e10cSrcweir 		aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
125cdf0e10cSrcweir 		rWin.SetMapMode( aMap );
126cdf0e10cSrcweir 		rWin.Update();
127cdf0e10cSrcweir         rWin.Invalidate();
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 		if ( m_pReportWindow )
130cdf0e10cSrcweir         {
131cdf0e10cSrcweir             const DlgEdHint aHint( RPTUI_HINT_WINDOWSCROLLED );
132cdf0e10cSrcweir 			m_pReportWindow->getReportView()->Broadcast( aHint );
133cdf0e10cSrcweir         }
134cdf0e10cSrcweir 	}
135cdf0e10cSrcweir     else
136cdf0e10cSrcweir     {
137cdf0e10cSrcweir         rWin.Invalidate(INVALIDATE_NOERASE);
138cdf0e10cSrcweir     }
139cdf0e10cSrcweir }
140cdf0e10cSrcweir //------------------------------------------------------------------------------
Notify(SfxBroadcaster & rBC,const SfxHint & rHint)141cdf0e10cSrcweir void OSectionView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir 	DBG_CHKTHIS( rpt_OSectionView,NULL);
144cdf0e10cSrcweir     SdrView::Notify(rBC,rHint);
145cdf0e10cSrcweir     if ( rHint.ISA(SdrHint) )
146cdf0e10cSrcweir     {
147cdf0e10cSrcweir         const SdrObject* pObj = ((SdrHint&)rHint).GetObject();
148cdf0e10cSrcweir         const SdrHintKind eKind = ((SdrHint&)rHint).GetKind();
149cdf0e10cSrcweir         // check for change of selected object
150cdf0e10cSrcweir         if(HINT_OBJCHG == eKind && pObj && IsObjMarked(const_cast<SdrObject*>(pObj)))
151cdf0e10cSrcweir             AdjustMarkHdl();
152cdf0e10cSrcweir 	    else if ( eKind == HINT_OBJREMOVED )
153cdf0e10cSrcweir 		    ObjectRemovedInAliveMode(pObj);
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //------------------------------------------------------------------------------
ObjectRemovedInAliveMode(const SdrObject * _pObject)158cdf0e10cSrcweir void OSectionView::ObjectRemovedInAliveMode( const SdrObject* _pObject )
159cdf0e10cSrcweir {
160cdf0e10cSrcweir 	DBG_CHKTHIS( rpt_OSectionView,NULL);
161cdf0e10cSrcweir     const SdrMarkList& rMarkedList = GetMarkedObjectList();
162cdf0e10cSrcweir 	const sal_uLong nMark = rMarkedList.GetMarkCount();
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 	for( sal_uLong i = 0; i < nMark; i++ )
165cdf0e10cSrcweir 	{
166cdf0e10cSrcweir 		SdrObject* pSdrObj = rMarkedList.GetMark(i)->GetMarkedSdrObj();
167cdf0e10cSrcweir 		if (_pObject == pSdrObj)
168cdf0e10cSrcweir 		{
169cdf0e10cSrcweir 			SdrPageView*    pPgView = GetSdrPageView();
170cdf0e10cSrcweir 			BrkAction();
171cdf0e10cSrcweir 			MarkObj( pSdrObj, pPgView, sal_True );
172cdf0e10cSrcweir 			break;
173cdf0e10cSrcweir 		}
174cdf0e10cSrcweir 	}
175cdf0e10cSrcweir }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir // -----------------------------------------------------------------------------
SetMarkedToLayer(SdrLayerID _nLayerNo)178cdf0e10cSrcweir void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo )
179cdf0e10cSrcweir {
180cdf0e10cSrcweir 	if (AreObjectsMarked())
181cdf0e10cSrcweir 	{
182cdf0e10cSrcweir 		//	#i11702# use SdrUndoObjectLayerChange for undo
183cdf0e10cSrcweir 		//	STR_UNDO_SELATTR is "Attributes" - should use a different text later
184cdf0e10cSrcweir 		BegUndo( );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 		const SdrMarkList& rMark = GetMarkedObjectList();
187cdf0e10cSrcweir 		sal_uLong nCount = rMark.GetMarkCount();
188cdf0e10cSrcweir 		for (sal_uLong i=0; i<nCount; i++)
189cdf0e10cSrcweir 		{
190cdf0e10cSrcweir 			SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
191cdf0e10cSrcweir 			if ( pObj->ISA(OCustomShape) )
192cdf0e10cSrcweir 			{
193cdf0e10cSrcweir 				AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), _nLayerNo) );
194cdf0e10cSrcweir 				pObj->SetLayer( _nLayerNo );
195cdf0e10cSrcweir                 OObjectBase* pBaseObj = dynamic_cast<OObjectBase*>(pObj);
196cdf0e10cSrcweir                 try
197cdf0e10cSrcweir                 {
198cdf0e10cSrcweir                     pBaseObj->getReportComponent()->setPropertyValue(PROPERTY_OPAQUE,uno::makeAny(_nLayerNo == RPT_LAYER_FRONT));
199cdf0e10cSrcweir                 }
200cdf0e10cSrcweir                 catch(const uno::Exception&)
201cdf0e10cSrcweir                 {
202cdf0e10cSrcweir                     DBG_UNHANDLED_EXCEPTION();
203cdf0e10cSrcweir                 }
204cdf0e10cSrcweir 			}
205cdf0e10cSrcweir 		}
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 		EndUndo();
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 		//	#84073# check mark list now instead of later in a timer
210cdf0e10cSrcweir 		CheckMarked();
211cdf0e10cSrcweir 		MarkListHasChanged();
212cdf0e10cSrcweir 	}
213cdf0e10cSrcweir }
214cdf0e10cSrcweir // -----------------------------------------------------------------------------
OnlyShapesMarked() const215cdf0e10cSrcweir bool OSectionView::OnlyShapesMarked() const
216cdf0e10cSrcweir {
217cdf0e10cSrcweir     const SdrMarkList& rMark = GetMarkedObjectList();
218cdf0e10cSrcweir 	const sal_uLong nCount = rMark.GetMarkCount();
219cdf0e10cSrcweir     if ( !nCount )
220cdf0e10cSrcweir         return false;
221cdf0e10cSrcweir     sal_uLong i=0;
222cdf0e10cSrcweir 	for (; i<nCount; i++)
223cdf0e10cSrcweir 	{
224cdf0e10cSrcweir 		SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
225cdf0e10cSrcweir 		if ( !pObj->ISA(OCustomShape) )
226cdf0e10cSrcweir         {
227cdf0e10cSrcweir             break;
228cdf0e10cSrcweir         }
229cdf0e10cSrcweir     } // for (sal_uLong i=0; i<nCount; i++)
230cdf0e10cSrcweir     return i == nCount;
231cdf0e10cSrcweir }
232cdf0e10cSrcweir 
IsDragResize() const233cdf0e10cSrcweir bool OSectionView::IsDragResize() const
234cdf0e10cSrcweir {
235cdf0e10cSrcweir     const SdrDragMethod* pDragMethod = GetDragMethod();
236cdf0e10cSrcweir     if (pDragMethod)
237cdf0e10cSrcweir     {
238cdf0e10cSrcweir         bool bMoveOnly = pDragMethod->getMoveOnly();
239cdf0e10cSrcweir         if (bMoveOnly == false)
240cdf0e10cSrcweir         {
241cdf0e10cSrcweir             // current marked components will be resized
242cdf0e10cSrcweir             return true;
243cdf0e10cSrcweir         }
244cdf0e10cSrcweir     }
245cdf0e10cSrcweir     return false;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir // -----------------------------------------------------------------------------
GetLayerIdOfMarkedObjects() const249cdf0e10cSrcweir short OSectionView::GetLayerIdOfMarkedObjects() const
250cdf0e10cSrcweir {
251cdf0e10cSrcweir 	short nRet = SHRT_MAX;
252cdf0e10cSrcweir 	const SdrMarkList &rMrkList = GetMarkedObjectList();
253cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i )
254cdf0e10cSrcweir 	{
255cdf0e10cSrcweir 		const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
256cdf0e10cSrcweir 		if ( nRet == SHRT_MAX )
257cdf0e10cSrcweir 			nRet = pObj->GetLayer();
258cdf0e10cSrcweir 		else if ( nRet != pObj->GetLayer() )
259cdf0e10cSrcweir 		{
260cdf0e10cSrcweir 			nRet = -1;
261cdf0e10cSrcweir 			break;
262cdf0e10cSrcweir 		}
263cdf0e10cSrcweir 	}
264cdf0e10cSrcweir 	if ( nRet == SHRT_MAX )
265cdf0e10cSrcweir 		nRet = -1;
266cdf0e10cSrcweir 	return nRet;
267cdf0e10cSrcweir }
268cdf0e10cSrcweir 
269cdf0e10cSrcweir //============================================================================
270cdf0e10cSrcweir } // rptui
271cdf0e10cSrcweir //============================================================================
272