1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_reportdesign.hxx"
28 #include "SectionView.hxx"
29 #include "DesignView.hxx"
30 #include <RptPage.hxx>
31 #include <RptObject.hxx>
32 #include <RptDef.hxx>
33 #include <svx/svxids.hrc>
34 #include <svx/svddrgmt.hxx>
35 #include <vcl/scrbar.hxx>
36 #include "ReportSection.hxx"
37 #include "ReportWindow.hxx"
38 #include "uistrings.hrc"
39 #include <tools/debug.hxx>
40 #include <tools/diagnose_ex.h>
41 
42 namespace rptui
43 {
44     using namespace ::com::sun::star;
45 TYPEINIT1( OSectionView, SdrView );
46 
47 //----------------------------------------------------------------------------
48 DBG_NAME( rpt_OSectionView )
49 OSectionView::OSectionView( SdrModel* pModel, OReportSection* _pSectionWindow, OReportWindow* pEditor )
50 	:SdrView( pModel, _pSectionWindow )
51 	,m_pReportWindow( pEditor )
52 	,m_pSectionWindow(_pSectionWindow)
53 {
54 	DBG_CTOR( rpt_OSectionView,NULL);
55     // SetPagePaintingAllowed(false);
56     SetBufferedOutputAllowed(true);
57     SetBufferedOverlayAllowed(true);
58     SetPageBorderVisible(false);
59     SetBordVisible();
60     SetQuickTextEditMode(sal_False);
61 }
62 
63 //----------------------------------------------------------------------------
64 
65 OSectionView::~OSectionView()
66 {
67 	DBG_DTOR( rpt_OSectionView,NULL);
68 }
69 
70 //----------------------------------------------------------------------------
71 
72 void OSectionView::MarkListHasChanged()
73 {
74 	DBG_CHKTHIS( rpt_OSectionView,NULL);
75 	SdrView::MarkListHasChanged();
76 
77 	if ( m_pReportWindow && m_pSectionWindow && !m_pSectionWindow->getPage()->getSpecialMode() )
78     {
79 		//m_pReportWindow->unmarkAllObjects(this); // WHY
80 		DlgEdHint aHint( RPTUI_HINT_SELECTIONCHANGED );
81 		m_pReportWindow->getReportView()->Broadcast( aHint );
82         m_pReportWindow->getReportView()->UpdatePropertyBrowserDelayed(*this);
83     }
84 }
85 
86 //----------------------------------------------------------------------------
87 
88 void OSectionView::MakeVisible( const Rectangle& rRect, Window& rWin )
89 {
90 	DBG_CHKTHIS( rpt_OSectionView,NULL);
91 	// visible area
92 	MapMode aMap( rWin.GetMapMode() );
93 	const Point aOrg( aMap.GetOrigin() );
94 	const Size aVisSize( rWin.GetOutputSize() );
95 	const Rectangle aVisRect( Point(-aOrg.X(),-aOrg.Y()), aVisSize );
96 
97 	// check, if rectangle is inside visible area
98 	if ( !aVisRect.IsInside( rRect ) )
99 	{
100 		// calculate scroll distance; the rectangle must be inside the visible area
101 		sal_Int32 nScrollX = 0, nScrollY = 0;
102 
103 		const sal_Int32 nVisLeft   = aVisRect.Left();
104 		const sal_Int32 nVisRight  = aVisRect.Right();
105 		const sal_Int32 nVisTop    = aVisRect.Top();
106 		const sal_Int32 nVisBottom = aVisRect.Bottom();
107 
108 		// don't scroll beyond the page size
109 		Size aPageSize = m_pSectionWindow->getPage()->GetSize();
110 		const sal_Int32 nPageWidth  = aPageSize.Width();
111 		const sal_Int32 nPageHeight = aPageSize.Height();
112 
113 		if ( nVisRight + nScrollX > nPageWidth )
114 			nScrollX = nPageWidth - nVisRight;
115 
116 		if ( nVisLeft + nScrollX < 0 )
117 			nScrollX = -nVisLeft;
118 
119 		if ( nVisBottom + nScrollY > nPageHeight )
120 			nScrollY = nPageHeight - nVisBottom;
121 
122 		if ( nVisTop + nScrollY < 0 )
123 			nScrollY = -nVisTop;
124 
125 		// scroll window
126 		rWin.Update();
127 		rWin.Scroll( -nScrollX, -nScrollY );
128 		aMap.SetOrigin( Point( aOrg.X() - nScrollX, aOrg.Y() - nScrollY ) );
129 		rWin.SetMapMode( aMap );
130 		rWin.Update();
131         rWin.Invalidate();
132 
133 		if ( m_pReportWindow )
134         {
135             const DlgEdHint aHint( RPTUI_HINT_WINDOWSCROLLED );
136 			m_pReportWindow->getReportView()->Broadcast( aHint );
137         }
138 	}
139     else
140     {
141         rWin.Invalidate(INVALIDATE_NOERASE);
142     }
143 }
144 //------------------------------------------------------------------------------
145 void OSectionView::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
146 {
147 	DBG_CHKTHIS( rpt_OSectionView,NULL);
148     SdrView::Notify(rBC,rHint);
149     if ( rHint.ISA(SdrHint) )
150     {
151         const SdrObject* pObj = ((SdrHint&)rHint).GetObject();
152         const SdrHintKind eKind = ((SdrHint&)rHint).GetKind();
153         // check for change of selected object
154         if(HINT_OBJCHG == eKind && pObj && IsObjMarked(const_cast<SdrObject*>(pObj)))
155             AdjustMarkHdl();
156 	    else if ( eKind == HINT_OBJREMOVED )
157 		    ObjectRemovedInAliveMode(pObj);
158     }
159 }
160 
161 //------------------------------------------------------------------------------
162 void OSectionView::ObjectRemovedInAliveMode( const SdrObject* _pObject )
163 {
164 	DBG_CHKTHIS( rpt_OSectionView,NULL);
165     const SdrMarkList& rMarkedList = GetMarkedObjectList();
166 	const sal_uLong nMark = rMarkedList.GetMarkCount();
167 
168 	for( sal_uLong i = 0; i < nMark; i++ )
169 	{
170 		SdrObject* pSdrObj = rMarkedList.GetMark(i)->GetMarkedSdrObj();
171 		if (_pObject == pSdrObj)
172 		{
173 			SdrPageView*    pPgView = GetSdrPageView();
174 			BrkAction();
175 			MarkObj( pSdrObj, pPgView, sal_True );
176 			break;
177 		}
178 	}
179 }
180 
181 // -----------------------------------------------------------------------------
182 void OSectionView::SetMarkedToLayer( SdrLayerID _nLayerNo )
183 {
184 	if (AreObjectsMarked())
185 	{
186 		//	#i11702# use SdrUndoObjectLayerChange for undo
187 		//	STR_UNDO_SELATTR is "Attributes" - should use a different text later
188 		BegUndo( );
189 
190 		const SdrMarkList& rMark = GetMarkedObjectList();
191 		sal_uLong nCount = rMark.GetMarkCount();
192 		for (sal_uLong i=0; i<nCount; i++)
193 		{
194 			SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
195 			if ( pObj->ISA(OCustomShape) )
196 			{
197 				AddUndo( new SdrUndoObjectLayerChange( *pObj, pObj->GetLayer(), _nLayerNo) );
198 				pObj->SetLayer( _nLayerNo );
199                 OObjectBase* pBaseObj = dynamic_cast<OObjectBase*>(pObj);
200                 try
201                 {
202                     pBaseObj->getReportComponent()->setPropertyValue(PROPERTY_OPAQUE,uno::makeAny(_nLayerNo == RPT_LAYER_FRONT));
203                 }
204                 catch(const uno::Exception&)
205                 {
206                     DBG_UNHANDLED_EXCEPTION();
207                 }
208 			}
209 		}
210 
211 		EndUndo();
212 
213 		//	#84073# check mark list now instead of later in a timer
214 		CheckMarked();
215 		MarkListHasChanged();
216 	}
217 }
218 // -----------------------------------------------------------------------------
219 bool OSectionView::OnlyShapesMarked() const
220 {
221     const SdrMarkList& rMark = GetMarkedObjectList();
222 	const sal_uLong nCount = rMark.GetMarkCount();
223     if ( !nCount )
224         return false;
225     sal_uLong i=0;
226 	for (; i<nCount; i++)
227 	{
228 		SdrObject* pObj = rMark.GetMark(i)->GetMarkedSdrObj();
229 		if ( !pObj->ISA(OCustomShape) )
230         {
231             break;
232         }
233     } // for (sal_uLong i=0; i<nCount; i++)
234     return i == nCount;
235 }
236 
237 bool OSectionView::IsDragResize() const
238 {
239     const SdrDragMethod* pDragMethod = GetDragMethod();
240     if (pDragMethod)
241     {
242         bool bMoveOnly = pDragMethod->getMoveOnly();
243         if (bMoveOnly == false)
244         {
245             // current marked components will be resized
246             return true;
247         }
248     }
249     return false;
250 }
251 
252 // -----------------------------------------------------------------------------
253 short OSectionView::GetLayerIdOfMarkedObjects() const
254 {
255 	short nRet = SHRT_MAX;
256 	const SdrMarkList &rMrkList = GetMarkedObjectList();
257 	for ( sal_uInt16 i = 0; i < rMrkList.GetMarkCount(); ++i )
258 	{
259 		const SdrObject *pObj = rMrkList.GetMark( i )->GetMarkedSdrObj();
260 		if ( nRet == SHRT_MAX )
261 			nRet = pObj->GetLayer();
262 		else if ( nRet != pObj->GetLayer() )
263 		{
264 			nRet = -1;
265 			break;
266 		}
267 	}
268 	if ( nRet == SHRT_MAX )
269 		nRet = -1;
270 	return nRet;
271 }
272 
273 //============================================================================
274 } // rptui
275 //============================================================================
276