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