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