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 : :
29 : : #include "ViewsWindow.hxx"
30 : : #include "ScrollHelper.hxx"
31 : : #include "UndoActions.hxx"
32 : : #include "ReportWindow.hxx"
33 : : #include "DesignView.hxx"
34 : : #include <svtools/colorcfg.hxx>
35 : : #include "ReportController.hxx"
36 : : #include "UITools.hxx"
37 : : #include "RptDef.hxx"
38 : : #include "RptResId.hrc"
39 : : #include "SectionView.hxx"
40 : : #include "ReportSection.hxx"
41 : : #include "uistrings.hrc"
42 : : #include "rptui_slotid.hrc"
43 : : #include "dlgedclip.hxx"
44 : : #include "ColorChanger.hxx"
45 : : #include "RptObject.hxx"
46 : : #include "RptObject.hxx"
47 : : #include "ModuleHelper.hxx"
48 : : #include "EndMarker.hxx"
49 : : #include <svx/svdpagv.hxx>
50 : : #include <svx/unoshape.hxx>
51 : : #include <vcl/svapp.hxx>
52 : : #include <boost/bind.hpp>
53 : :
54 : : #include "helpids.hrc"
55 : : #include <svx/svdundo.hxx>
56 : : #include <toolkit/helper/convert.hxx>
57 : : #include <algorithm>
58 : : #include <numeric>
59 : : #include <o3tl/compat_functional.hxx>
60 : :
61 : : namespace rptui
62 : : {
63 : : #define DEFAUL_MOVE_SIZE 100
64 : :
65 : : using namespace ::com::sun::star;
66 : : using namespace ::comphelper;
67 : : // -----------------------------------------------------------------------------
68 : 0 : bool lcl_getNewRectSize(const Rectangle& _aObjRect,long& _nXMov, long& _nYMov,SdrObject* _pObj,SdrView* _pView,sal_Int32 _nControlModification, bool _bBoundRects)
69 : : {
70 : 0 : bool bMoveAllowed = _nXMov != 0 || _nYMov != 0;
71 : 0 : if ( bMoveAllowed )
72 : : {
73 : 0 : Rectangle aNewRect = _aObjRect;
74 : 0 : SdrObject* pOverlappedObj = NULL;
75 : 0 : do
76 : : {
77 : 0 : aNewRect = _aObjRect;
78 : 0 : switch(_nControlModification)
79 : : {
80 : : case ControlModification::HEIGHT_GREATEST:
81 : : case ControlModification::WIDTH_GREATEST:
82 : 0 : aNewRect.setWidth(_nXMov);
83 : 0 : aNewRect.setHeight(_nYMov);
84 : 0 : break;
85 : : default:
86 : 0 : aNewRect.Move(_nXMov,_nYMov);
87 : 0 : break;
88 : : }
89 : 0 : if (dynamic_cast<OUnoObject*>(_pObj) != NULL || dynamic_cast<OOle2Obj*>(_pObj) != NULL)
90 : : {
91 : 0 : pOverlappedObj = isOver(aNewRect,*_pObj->GetPage(),*_pView,true,_pObj);
92 : 0 : if ( pOverlappedObj && _pObj != pOverlappedObj )
93 : : {
94 : 0 : Rectangle aOverlappingRect = (_bBoundRects ? pOverlappedObj->GetCurrentBoundRect() : pOverlappedObj->GetSnapRect());
95 : 0 : sal_Int32 nXTemp = _nXMov;
96 : 0 : sal_Int32 nYTemp = _nYMov;
97 : 0 : switch(_nControlModification)
98 : : {
99 : : case ControlModification::LEFT:
100 : 0 : nXTemp += aOverlappingRect.Right() - aNewRect.Left();
101 : 0 : bMoveAllowed = _nXMov != nXTemp;
102 : 0 : break;
103 : : case ControlModification::RIGHT:
104 : 0 : nXTemp += aOverlappingRect.Left() - aNewRect.Right();
105 : 0 : bMoveAllowed = _nXMov != nXTemp;
106 : 0 : break;
107 : : case ControlModification::TOP:
108 : 0 : nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
109 : 0 : bMoveAllowed = _nYMov != nYTemp;
110 : 0 : break;
111 : : case ControlModification::BOTTOM:
112 : 0 : nYTemp += aOverlappingRect.Top() - aNewRect.Bottom();
113 : 0 : bMoveAllowed = _nYMov != nYTemp;
114 : 0 : break;
115 : : case ControlModification::CENTER_HORIZONTAL:
116 : 0 : if ( _aObjRect.Left() < aOverlappingRect.Left() )
117 : 0 : nXTemp += aOverlappingRect.Left() - aNewRect.Left() - aNewRect.getWidth();
118 : : else
119 : 0 : nXTemp += aOverlappingRect.Right() - aNewRect.Left();
120 : 0 : bMoveAllowed = _nXMov != nXTemp;
121 : 0 : break;
122 : : case ControlModification::CENTER_VERTICAL:
123 : 0 : if ( _aObjRect.Top() < aOverlappingRect.Top() )
124 : 0 : nYTemp += aOverlappingRect.Top() - aNewRect.Top() - aNewRect.getHeight();
125 : : else
126 : 0 : nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
127 : 0 : bMoveAllowed = _nYMov != nYTemp;
128 : 0 : break;
129 : : case ControlModification::HEIGHT_GREATEST:
130 : : case ControlModification::WIDTH_GREATEST:
131 : : {
132 : 0 : Rectangle aIntersectionRect = aNewRect.GetIntersection(aOverlappingRect);
133 : 0 : if ( !aIntersectionRect.IsEmpty() )
134 : : {
135 : 0 : if ( _nControlModification == ControlModification::WIDTH_GREATEST )
136 : : {
137 : 0 : if ( aNewRect.Left() < aIntersectionRect.Left() )
138 : : {
139 : 0 : aNewRect.Right() = aIntersectionRect.Left();
140 : : }
141 : 0 : else if ( aNewRect.Left() < aIntersectionRect.Right() )
142 : : {
143 : 0 : aNewRect.Left() = aIntersectionRect.Right();
144 : : }
145 : : }
146 : 0 : else if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
147 : : {
148 : 0 : if ( aNewRect.Top() < aIntersectionRect.Top() )
149 : : {
150 : 0 : aNewRect.Bottom() = aIntersectionRect.Top();
151 : : }
152 : 0 : else if ( aNewRect.Top() < aIntersectionRect.Bottom() )
153 : : {
154 : 0 : aNewRect.Top() = aIntersectionRect.Bottom();
155 : : }
156 : : }
157 : 0 : nYTemp = aNewRect.getHeight();
158 : 0 : bMoveAllowed = _nYMov != nYTemp;
159 : 0 : nXTemp = aNewRect.getWidth();
160 : 0 : bMoveAllowed = bMoveAllowed && _nXMov != nXTemp;
161 : : }
162 : : }
163 : 0 : break;
164 : : default:
165 : 0 : break;
166 : : }
167 : :
168 : 0 : _nXMov = nXTemp;
169 : 0 : _nYMov = nYTemp;
170 : : }
171 : : else
172 : 0 : pOverlappedObj = NULL;
173 : : }
174 : : }
175 : : while ( pOverlappedObj && bMoveAllowed );
176 : : }
177 : 0 : return bMoveAllowed;
178 : : }
179 : : // -----------------------------------------------------------------------------
180 : :
181 : : DBG_NAME( rpt_OViewsWindow );
182 : 0 : OViewsWindow::OViewsWindow( OReportWindow* _pReportWindow)
183 : : : Window( _pReportWindow,WB_DIALOGCONTROL)
184 : : ,m_pParent(_pReportWindow)
185 : 0 : ,m_bInUnmark(sal_False)
186 : : {
187 : : DBG_CTOR( rpt_OViewsWindow,NULL);
188 : 0 : SetPaintTransparent(sal_True);
189 : 0 : SetUniqueId(UID_RPT_VIEWSWINDOW);
190 : 0 : SetMapMode( MapMode( MAP_100TH_MM ) );
191 : 0 : m_aColorConfig.AddListener(this);
192 : 0 : ImplInitSettings();
193 : 0 : }
194 : : // -----------------------------------------------------------------------------
195 : 0 : OViewsWindow::~OViewsWindow()
196 : : {
197 : 0 : m_aColorConfig.RemoveListener(this);
198 : 0 : m_aSections.clear();
199 : :
200 : : DBG_DTOR( rpt_OViewsWindow,NULL);
201 : 0 : }
202 : : // -----------------------------------------------------------------------------
203 : 0 : void OViewsWindow::initialize()
204 : : {
205 : :
206 : 0 : }
207 : : // -----------------------------------------------------------------------------
208 : 0 : void OViewsWindow::impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet)
209 : : {
210 : 0 : const uno::Reference< report::XSection> xSection = _rSectionWindow.getReportSection().getSection();
211 : :
212 : 0 : Size aSectionSize = _rSectionWindow.LogicToPixel( Size( 0,xSection->getHeight() ) );
213 : 0 : aSectionSize.Width() = getView()->GetTotalWidth();
214 : :
215 : 0 : const sal_Int32 nMinHeight = _rSectionWindow.getStartMarker().getMinHeight();
216 : 0 : if ( _rSectionWindow.getStartMarker().isCollapsed() || nMinHeight > aSectionSize.Height() )
217 : : {
218 : 0 : aSectionSize.Height() = nMinHeight;
219 : : }
220 : 0 : const StyleSettings& rSettings = GetSettings().GetStyleSettings();
221 : 0 : aSectionSize.Height() += (long)(rSettings.GetSplitSize() * (double)_rSectionWindow.GetMapMode().GetScaleY());
222 : :
223 : 0 : if ( _bSet )
224 : 0 : _rSectionWindow.SetPosSizePixel(_rStartPoint,aSectionSize);
225 : :
226 : 0 : _rStartPoint.Y() += aSectionSize.Height();
227 : 0 : }
228 : :
229 : : // -----------------------------------------------------------------------------
230 : 0 : void OViewsWindow::resize(const OSectionWindow& _rSectionWindow)
231 : : {
232 : 0 : bool bSet = false;
233 : 0 : Point aStartPoint;
234 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
235 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
236 : 0 : for (;aIter != aEnd ; ++aIter)
237 : : {
238 : 0 : const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
239 : 0 : if ( pSectionWindow.get() == &_rSectionWindow )
240 : : {
241 : 0 : aStartPoint = pSectionWindow->GetPosPixel();
242 : 0 : bSet = true;
243 : : }
244 : :
245 : 0 : if ( bSet )
246 : : {
247 : 0 : impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,bSet);
248 : : static sal_Int32 nIn = INVALIDATE_UPDATE | INVALIDATE_TRANSPARENT;
249 : 0 : pSectionWindow->getStartMarker().Invalidate( nIn ); // INVALIDATE_NOERASE |INVALIDATE_NOCHILDREN| INVALIDATE_TRANSPARENT
250 : 0 : pSectionWindow->getEndMarker().Invalidate( nIn );
251 : : }
252 : 0 : }
253 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
254 : 0 : aStartWidth *= GetMapMode().GetScaleX();
255 : 0 : Size aOut = GetOutputSizePixel();
256 : 0 : aOut.Width() = aStartWidth;
257 : 0 : aOut = PixelToLogic(aOut);
258 : 0 : m_pParent->notifySizeChanged();
259 : :
260 : 0 : Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
261 : 0 : }
262 : : //------------------------------------------------------------------------------
263 : 0 : void OViewsWindow::Resize()
264 : : {
265 : 0 : Window::Resize();
266 : 0 : if ( !m_aSections.empty() )
267 : : {
268 : 0 : const Point aOffset(m_pParent->getThumbPos());
269 : 0 : Point aStartPoint(0,-aOffset.Y());
270 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
271 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
272 : 0 : for (;aIter != aEnd ; ++aIter)
273 : : {
274 : 0 : const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
275 : 0 : impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,true);
276 : 0 : }
277 : : }
278 : 0 : }
279 : : // -----------------------------------------------------------------------------
280 : 0 : void OViewsWindow::Paint( const Rectangle& rRect )
281 : : {
282 : 0 : Window::Paint( rRect );
283 : :
284 : 0 : Size aOut = GetOutputSizePixel();
285 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
286 : 0 : aStartWidth *= GetMapMode().GetScaleX();
287 : :
288 : 0 : aOut.Width() -= (long)aStartWidth;
289 : 0 : aOut = PixelToLogic(aOut);
290 : :
291 : 0 : Rectangle aRect(PixelToLogic(Point(aStartWidth,0)),aOut);
292 : 0 : Wallpaper aWall( m_aColorConfig.GetColorValue(::svtools::APPBACKGROUND).nColor );
293 : 0 : DrawWallpaper(aRect,aWall);
294 : 0 : }
295 : : //------------------------------------------------------------------------------
296 : 0 : void OViewsWindow::ImplInitSettings()
297 : : {
298 : 0 : EnableChildTransparentMode( sal_True );
299 : 0 : SetBackground( );
300 : 0 : SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
301 : 0 : SetTextFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
302 : 0 : }
303 : : //-----------------------------------------------------------------------------
304 : 0 : void OViewsWindow::DataChanged( const DataChangedEvent& rDCEvt )
305 : : {
306 : 0 : Window::DataChanged( rDCEvt );
307 : :
308 : 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
309 : 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
310 : : {
311 : 0 : ImplInitSettings();
312 : 0 : Invalidate();
313 : : }
314 : 0 : }
315 : : //----------------------------------------------------------------------------
316 : 0 : void OViewsWindow::addSection(const uno::Reference< report::XSection >& _xSection,const ::rtl::OUString& _sColorEntry,sal_uInt16 _nPosition)
317 : : {
318 : 0 : ::boost::shared_ptr<OSectionWindow> pSectionWindow( new OSectionWindow(this,_xSection,_sColorEntry) );
319 : 0 : m_aSections.insert(getIteratorAtPos(_nPosition) , TSectionsMap::value_type(pSectionWindow));
320 : 0 : m_pParent->setMarked(&pSectionWindow->getReportSection().getSectionView(),m_aSections.size() == 1);
321 : 0 : Resize();
322 : 0 : }
323 : : //----------------------------------------------------------------------------
324 : 0 : void OViewsWindow::removeSection(sal_uInt16 _nPosition)
325 : : {
326 : 0 : if ( _nPosition < m_aSections.size() )
327 : : {
328 : 0 : TSectionsMap::iterator aPos = getIteratorAtPos(_nPosition);
329 : 0 : TSectionsMap::iterator aNew = getIteratorAtPos(_nPosition == 0 ? _nPosition+1: _nPosition - 1);
330 : :
331 : 0 : m_pParent->getReportView()->UpdatePropertyBrowserDelayed((*aNew)->getReportSection().getSectionView());
332 : :
333 : 0 : m_aSections.erase(aPos);
334 : 0 : Resize();
335 : : }
336 : 0 : }
337 : : //------------------------------------------------------------------------------
338 : 0 : void OViewsWindow::toggleGrid(sal_Bool _bVisible)
339 : : {
340 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
341 : 0 : ::o3tl::compose1(::boost::bind(&OReportSection::SetGridVisible,_1,_bVisible),TReportPairHelper()));
342 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
343 : 0 : ::o3tl::compose1(::boost::bind(&OReportSection::Window::Invalidate,_1,INVALIDATE_NOERASE),TReportPairHelper()));
344 : 0 : }
345 : : //------------------------------------------------------------------------------
346 : 0 : sal_Int32 OViewsWindow::getTotalHeight() const
347 : : {
348 : 0 : sal_Int32 nHeight = 0;
349 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
350 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
351 : 0 : for (;aIter != aEnd ; ++aIter)
352 : : {
353 : 0 : nHeight += (*aIter)->GetSizePixel().Height();
354 : : }
355 : 0 : return nHeight;
356 : : }
357 : : //----------------------------------------------------------------------------
358 : 0 : sal_uInt16 OViewsWindow::getSectionCount() const
359 : : {
360 : 0 : return static_cast<sal_uInt16>(m_aSections.size());
361 : : }
362 : : //----------------------------------------------------------------------------
363 : 0 : void OViewsWindow::SetInsertObj( sal_uInt16 eObj,const ::rtl::OUString& _sShapeType )
364 : : {
365 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
366 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
367 : 0 : for (;aIter != aEnd ; ++aIter)
368 : 0 : (*aIter)->getReportSection().getSectionView().SetCurrentObj( eObj, ReportInventor );
369 : :
370 : 0 : m_sShapeType = _sShapeType;
371 : 0 : }
372 : : //----------------------------------------------------------------------------
373 : 0 : rtl::OUString OViewsWindow::GetInsertObjString() const
374 : : {
375 : 0 : return m_sShapeType;
376 : : }
377 : :
378 : : //------------------------------------------------------------------------------
379 : 0 : void OViewsWindow::SetMode( DlgEdMode eNewMode )
380 : : {
381 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
382 : 0 : ::o3tl::compose1(::boost::bind(&OReportSection::SetMode,_1,eNewMode),TReportPairHelper()));
383 : 0 : }
384 : : //----------------------------------------------------------------------------
385 : 0 : sal_Bool OViewsWindow::HasSelection() const
386 : : {
387 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
388 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
389 : 0 : for (;aIter != aEnd && !(*aIter)->getReportSection().getSectionView().AreObjectsMarked(); ++aIter)
390 : : ;
391 : 0 : return aIter != aEnd;
392 : : }
393 : : //----------------------------------------------------------------------------
394 : 0 : void OViewsWindow::Delete()
395 : : {
396 : 0 : m_bInUnmark = sal_True;
397 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
398 : 0 : ::o3tl::compose1(::boost::mem_fn(&OReportSection::Delete),TReportPairHelper()));
399 : 0 : m_bInUnmark = sal_False;
400 : 0 : }
401 : : //----------------------------------------------------------------------------
402 : 0 : void OViewsWindow::Copy()
403 : : {
404 : 0 : uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
405 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
406 : 0 : ::o3tl::compose1(::boost::bind(&OReportSection::Copy,_1,::boost::ref(aAllreadyCopiedObjects)),TReportPairHelper()));
407 : :
408 : 0 : OReportExchange* pCopy = new OReportExchange(aAllreadyCopiedObjects);
409 : 0 : uno::Reference< datatransfer::XTransferable> aEnsureDelete = pCopy;
410 : 0 : pCopy->CopyToClipboard(this);
411 : 0 : }
412 : : //----------------------------------------------------------------------------
413 : 0 : void OViewsWindow::Paste()
414 : : {
415 : 0 : TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(this));
416 : 0 : OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aTransferData);
417 : 0 : if ( aCopies.getLength() > 1 )
418 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
419 : 0 : ::o3tl::compose1(::boost::bind(&OReportSection::Paste,_1,aCopies,false),TReportPairHelper()));
420 : : else
421 : : {
422 : 0 : ::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
423 : 0 : if ( pMarkedSection )
424 : 0 : pMarkedSection->getReportSection().Paste(aCopies,true);
425 : 0 : }
426 : 0 : }
427 : : // ---------------------------------------------------------------------------
428 : 0 : ::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const uno::Reference< report::XSection>& _xSection) const
429 : : {
430 : : OSL_ENSURE(_xSection.is(),"Section is NULL!");
431 : :
432 : 0 : ::boost::shared_ptr<OSectionWindow> pSectionWindow;
433 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
434 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
435 : 0 : for (; aIter != aEnd ; ++aIter)
436 : : {
437 : 0 : if ((*aIter)->getReportSection().getSection() == _xSection)
438 : : {
439 : 0 : pSectionWindow = (*aIter);
440 : 0 : break;
441 : : }
442 : : }
443 : :
444 : 0 : return pSectionWindow;
445 : : }
446 : :
447 : : //----------------------------------------------------------------------------
448 : 0 : ::boost::shared_ptr<OSectionWindow> OViewsWindow::getMarkedSection(NearSectionAccess nsa) const
449 : : {
450 : 0 : ::boost::shared_ptr<OSectionWindow> pRet;
451 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
452 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
453 : 0 : sal_uInt32 nCurrentPosition = 0;
454 : 0 : for (; aIter != aEnd ; ++aIter)
455 : : {
456 : 0 : if ( (*aIter)->getStartMarker().isMarked() )
457 : : {
458 : 0 : if (nsa == CURRENT)
459 : : {
460 : 0 : pRet = (*aIter);
461 : 0 : break;
462 : : }
463 : 0 : else if ( nsa == PREVIOUS )
464 : : {
465 : 0 : if (nCurrentPosition > 0)
466 : : {
467 : 0 : pRet = (*(--aIter));
468 : 0 : if (pRet == NULL)
469 : : {
470 : 0 : pRet = (*m_aSections.begin());
471 : : }
472 : : }
473 : : else
474 : : {
475 : : // if we are out of bounds return the first one
476 : 0 : pRet = (*m_aSections.begin());
477 : : }
478 : 0 : break;
479 : : }
480 : 0 : else if ( nsa == POST )
481 : : {
482 : 0 : sal_uInt32 nSize = m_aSections.size();
483 : 0 : if ((nCurrentPosition + 1) < nSize)
484 : : {
485 : 0 : pRet = *(++aIter);
486 : 0 : if (pRet == NULL)
487 : : {
488 : 0 : pRet = (*(--aEnd));
489 : : }
490 : : }
491 : : else
492 : : {
493 : : // if we are out of bounds return the last one
494 : 0 : pRet = (*(--aEnd));
495 : : }
496 : 0 : break;
497 : : }
498 : : }
499 : 0 : ++nCurrentPosition;
500 : : }
501 : :
502 : 0 : return pRet;
503 : : }
504 : : // -------------------------------------------------------------------------
505 : 0 : void OViewsWindow::markSection(const sal_uInt16 _nPos)
506 : : {
507 : 0 : if ( _nPos < m_aSections.size() )
508 : 0 : m_pParent->setMarked(m_aSections[_nPos]->getReportSection().getSection(),sal_True);
509 : 0 : }
510 : : //----------------------------------------------------------------------------
511 : 0 : sal_Bool OViewsWindow::IsPasteAllowed() const
512 : : {
513 : 0 : TransferableDataHelper aTransferData( TransferableDataHelper::CreateFromSystemClipboard( const_cast< OViewsWindow* >( this ) ) );
514 : 0 : return aTransferData.HasFormat(OReportExchange::getDescriptorFormatId());
515 : : }
516 : : //-----------------------------------------------------------------------------
517 : 0 : void OViewsWindow::SelectAll(const sal_uInt16 _nObjectType)
518 : : {
519 : 0 : m_bInUnmark = sal_True;
520 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
521 : 0 : ::o3tl::compose1(::boost::bind(::boost::mem_fn(&OReportSection::SelectAll),_1,_nObjectType),TReportPairHelper()));
522 : 0 : m_bInUnmark = sal_False;
523 : 0 : }
524 : : //-----------------------------------------------------------------------------
525 : 0 : void OViewsWindow::unmarkAllObjects(OSectionView* _pSectionView)
526 : : {
527 : 0 : if ( !m_bInUnmark )
528 : : {
529 : 0 : m_bInUnmark = sal_True;
530 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
531 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
532 : 0 : for (; aIter != aEnd ; ++aIter)
533 : : {
534 : 0 : if ( &(*aIter)->getReportSection().getSectionView() != _pSectionView )
535 : : {
536 : 0 : (*aIter)->getReportSection().deactivateOle();
537 : 0 : (*aIter)->getReportSection().getSectionView().UnmarkAllObj();
538 : : }
539 : : }
540 : 0 : m_bInUnmark = sal_False;
541 : : }
542 : 0 : }
543 : : // -----------------------------------------------------------------------
544 : 0 : void OViewsWindow::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32)
545 : : {
546 : 0 : ImplInitSettings();
547 : 0 : Invalidate();
548 : 0 : }
549 : : // -----------------------------------------------------------------------------
550 : 0 : void OViewsWindow::MouseButtonDown( const MouseEvent& rMEvt )
551 : : {
552 : 0 : if ( rMEvt.IsLeft() )
553 : : {
554 : 0 : GrabFocus();
555 : 0 : const uno::Sequence< beans::PropertyValue> aArgs;
556 : 0 : getView()->getReportView()->getController().executeChecked(SID_SELECT_REPORT,aArgs);
557 : : }
558 : 0 : Window::MouseButtonDown(rMEvt);
559 : 0 : }
560 : : //----------------------------------------------------------------------------
561 : 0 : void OViewsWindow::showRuler(sal_Bool _bShow)
562 : : {
563 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
564 : 0 : ::o3tl::compose1(::boost::bind(&OStartMarker::showRuler,_1,_bShow),TStartMarkerHelper()));
565 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
566 : 0 : ::o3tl::compose1(::boost::bind(&OStartMarker::Window::Invalidate, _1, sal_uInt16(INVALIDATE_NOERASE)), TStartMarkerHelper()));
567 : 0 : }
568 : : //----------------------------------------------------------------------------
569 : 0 : void OViewsWindow::MouseButtonUp( const MouseEvent& rMEvt )
570 : : {
571 : 0 : if ( rMEvt.IsLeft() )
572 : : {
573 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
574 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
575 : 0 : for (;aIter != aEnd ; ++aIter)
576 : : {
577 : 0 : if ( (*aIter)->getReportSection().getSectionView().AreObjectsMarked() )
578 : : {
579 : 0 : (*aIter)->getReportSection().MouseButtonUp(rMEvt);
580 : 0 : break;
581 : : }
582 : : }
583 : :
584 : : // remove special insert mode
585 : 0 : for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
586 : : {
587 : 0 : (*aIter)->getReportSection().getPage()->resetSpecialMode();
588 : : }
589 : : }
590 : 0 : }
591 : : //------------------------------------------------------------------------------
592 : 0 : sal_Bool OViewsWindow::handleKeyEvent(const KeyEvent& _rEvent)
593 : : {
594 : 0 : sal_Bool bRet = sal_False;
595 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
596 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
597 : 0 : for (;aIter != aEnd ; ++aIter)
598 : : {
599 : 0 : if ( (*aIter)->getStartMarker().isMarked() )
600 : : {
601 : 0 : bRet = (*aIter)->getReportSection().handleKeyEvent(_rEvent);
602 : : }
603 : : }
604 : 0 : return bRet;
605 : : }
606 : : //----------------------------------------------------------------------------
607 : 0 : OViewsWindow::TSectionsMap::iterator OViewsWindow::getIteratorAtPos(sal_uInt16 _nPos)
608 : : {
609 : 0 : TSectionsMap::iterator aRet = m_aSections.end();
610 : 0 : if ( _nPos < m_aSections.size() )
611 : 0 : aRet = m_aSections.begin() + _nPos;
612 : 0 : return aRet;
613 : : }
614 : : //------------------------------------------------------------------------
615 : 0 : void OViewsWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
616 : : {
617 : : OSL_ENSURE(_pSectionView != NULL,"SectionView is NULL!");
618 : 0 : if ( _pSectionView )
619 : 0 : setMarked(_pSectionView->getReportSection()->getSection(),_bMark);
620 : 0 : }
621 : : //------------------------------------------------------------------------
622 : 0 : void OViewsWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
623 : : {
624 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
625 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
626 : 0 : for (; aIter != aEnd ; ++aIter)
627 : : {
628 : 0 : if ( (*aIter)->getReportSection().getSection() != _xSection )
629 : : {
630 : 0 : (*aIter)->setMarked(sal_False);
631 : : }
632 : 0 : else if ( (*aIter)->getStartMarker().isMarked() != _bMark )
633 : : {
634 : 0 : (*aIter)->setMarked(_bMark);
635 : : }
636 : : }
637 : 0 : }
638 : : //------------------------------------------------------------------------
639 : 0 : void OViewsWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _aShapes,sal_Bool _bMark)
640 : : {
641 : 0 : bool bFirst = true;
642 : 0 : const uno::Reference< report::XReportComponent>* pIter = _aShapes.getConstArray();
643 : 0 : const uno::Reference< report::XReportComponent>* pEnd = pIter + _aShapes.getLength();
644 : 0 : for(;pIter != pEnd;++pIter)
645 : : {
646 : 0 : const uno::Reference< report::XSection> xSection = (*pIter)->getSection();
647 : 0 : if ( xSection.is() )
648 : : {
649 : 0 : if ( bFirst )
650 : : {
651 : 0 : bFirst = false;
652 : 0 : m_pParent->setMarked(xSection,_bMark);
653 : : }
654 : 0 : ::boost::shared_ptr<OSectionWindow> pSectionWindow = getSectionWindow(xSection);
655 : 0 : if ( pSectionWindow )
656 : : {
657 : 0 : SvxShape* pShape = SvxShape::getImplementation( *pIter );
658 : 0 : SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
659 : : OSL_ENSURE( pObject, "OViewsWindow::setMarked: no SdrObject for the shape!" );
660 : 0 : if ( pObject )
661 : 0 : pSectionWindow->getReportSection().getSectionView().MarkObj( pObject, pSectionWindow->getReportSection().getSectionView().GetSdrPageView(), !_bMark );
662 : 0 : }
663 : : }
664 : 0 : }
665 : 0 : }
666 : : // -----------------------------------------------------------------------------
667 : 0 : void OViewsWindow::collectRectangles(TRectangleMap& _rSortRectangles, bool _bBoundRects)
668 : : {
669 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
670 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
671 : 0 : for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
672 : : {
673 : 0 : OSectionView& rView = (*aIter)->getReportSection().getSectionView();
674 : 0 : if ( rView.AreObjectsMarked() )
675 : : {
676 : 0 : rView.SortMarkedObjects();
677 : 0 : const sal_uInt32 nCount = rView.GetMarkedObjectCount();
678 : 0 : for (sal_uInt32 i=0; i < nCount; ++i)
679 : : {
680 : 0 : const SdrMark* pM = rView.GetSdrMarkByIndex(i);
681 : 0 : SdrObject* pObj = pM->GetMarkedSdrObj();
682 : 0 : Rectangle aObjRect(_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
683 : 0 : _rSortRectangles.insert(TRectangleMap::value_type(aObjRect,TRectangleMap::mapped_type(pObj,&rView)));
684 : : }
685 : : }
686 : : }
687 : 0 : }
688 : : // -----------------------------------------------------------------------------
689 : 0 : void OViewsWindow::collectBoundResizeRect(const TRectangleMap& _rSortRectangles,sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects,Rectangle& _rBound,Rectangle& _rResize)
690 : : {
691 : 0 : bool bOnlyOnce = false;
692 : 0 : TRectangleMap::const_iterator aRectIter = _rSortRectangles.begin();
693 : 0 : TRectangleMap::const_iterator aRectEnd = _rSortRectangles.end();
694 : 0 : for (;aRectIter != aRectEnd ; ++aRectIter)
695 : : {
696 : 0 : Rectangle aObjRect = aRectIter->first;
697 : 0 : if ( _rResize.IsEmpty() )
698 : 0 : _rResize = aObjRect;
699 : 0 : switch(_nControlModification)
700 : : {
701 : : case ControlModification::WIDTH_SMALLEST:
702 : 0 : if ( _rResize.getWidth() > aObjRect.getWidth() )
703 : 0 : _rResize = aObjRect;
704 : 0 : break;
705 : : case ControlModification::HEIGHT_SMALLEST:
706 : 0 : if ( _rResize.getHeight() > aObjRect.getHeight() )
707 : 0 : _rResize = aObjRect;
708 : 0 : break;
709 : : case ControlModification::WIDTH_GREATEST:
710 : 0 : if ( _rResize.getWidth() < aObjRect.getWidth() )
711 : 0 : _rResize = aObjRect;
712 : 0 : break;
713 : : case ControlModification::HEIGHT_GREATEST:
714 : 0 : if ( _rResize.getHeight() < aObjRect.getHeight() )
715 : 0 : _rResize = aObjRect;
716 : 0 : break;
717 : : }
718 : :
719 : 0 : SdrObjTransformInfoRec aInfo;
720 : 0 : const SdrObject* pObj = aRectIter->second.first;
721 : 0 : pObj->TakeObjInfo(aInfo);
722 : 0 : sal_Bool bHasFixed = !aInfo.bMoveAllowed || pObj->IsMoveProtect();
723 : 0 : if ( bHasFixed )
724 : 0 : _rBound.Union(aObjRect);
725 : : else
726 : : {
727 : 0 : if ( _bAlignAtSection || _rSortRectangles.size() == 1 )
728 : : { // einzelnes Obj an der Seite ausrichten
729 : 0 : if ( ! bOnlyOnce )
730 : : {
731 : 0 : bOnlyOnce = true;
732 : 0 : OReportSection* pReportSection = aRectIter->second.second->getReportSection();
733 : 0 : const uno::Reference< report::XSection> xSection = pReportSection->getSection();
734 : : try
735 : : {
736 : 0 : uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
737 : : _rBound.Union(Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
738 : 0 : getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
739 : 0 : xSection->getHeight()));
740 : : }
741 : 0 : catch(const uno::Exception &){}
742 : : }
743 : : }
744 : : else
745 : : {
746 : 0 : if (_bBoundRects)
747 : 0 : _rBound.Union(aRectIter->second.second->GetMarkedObjBoundRect());
748 : : else
749 : 0 : _rBound.Union(aRectIter->second.second->GetMarkedObjRect());
750 : : }
751 : : }
752 : : }
753 : 0 : }
754 : : // -----------------------------------------------------------------------------
755 : 0 : void OViewsWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects)
756 : : {
757 : 0 : if ( _nControlModification == ControlModification::NONE )
758 : 0 : return;
759 : :
760 : 0 : Point aRefPoint;
761 : 0 : RectangleLess::CompareMode eCompareMode = RectangleLess::POS_LEFT;
762 : 0 : switch (_nControlModification)
763 : : {
764 : 0 : case ControlModification::TOP : eCompareMode = RectangleLess::POS_UPPER; break;
765 : 0 : case ControlModification::BOTTOM: eCompareMode = RectangleLess::POS_DOWN; break;
766 : 0 : case ControlModification::LEFT : eCompareMode = RectangleLess::POS_LEFT; break;
767 : 0 : case ControlModification::RIGHT : eCompareMode = RectangleLess::POS_RIGHT; break;
768 : : case ControlModification::CENTER_HORIZONTAL :
769 : : case ControlModification::CENTER_VERTICAL :
770 : : {
771 : 0 : eCompareMode = (ControlModification::CENTER_VERTICAL == _nControlModification) ? RectangleLess::POS_CENTER_VERTICAL : RectangleLess::POS_CENTER_HORIZONTAL;
772 : 0 : uno::Reference<report::XSection> xSection = (*m_aSections.begin())->getReportSection().getSection();
773 : 0 : uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
774 : : aRefPoint = Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
775 : 0 : getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
776 : 0 : xSection->getHeight()).Center();
777 : : }
778 : 0 : break;
779 : 0 : default: break;
780 : : }
781 : 0 : RectangleLess aCompare(eCompareMode,aRefPoint);
782 : 0 : TRectangleMap aSortRectangles(aCompare);
783 : 0 : collectRectangles(aSortRectangles,_bBoundRects);
784 : :
785 : 0 : Rectangle aBound;
786 : 0 : Rectangle aResize;
787 : 0 : collectBoundResizeRect(aSortRectangles,_nControlModification,_bAlignAtSection,_bBoundRects,aBound,aResize);
788 : :
789 : 0 : bool bMove = true;
790 : :
791 : 0 : ::std::mem_fun_t<long&,Rectangle> aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
792 : 0 : ::std::mem_fun_t<long&,Rectangle> aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
793 : 0 : TRectangleMap::iterator aRectIter = aSortRectangles.begin();
794 : 0 : TRectangleMap::iterator aRectEnd = aSortRectangles.end();
795 : 0 : for (;aRectIter != aRectEnd ; ++aRectIter)
796 : : {
797 : 0 : Rectangle aObjRect = aRectIter->first;
798 : 0 : SdrObject* pObj = aRectIter->second.first;
799 : 0 : SdrView* pView = aRectIter->second.second;
800 : 0 : Point aCenter(aBound.Center());
801 : 0 : SdrObjTransformInfoRec aInfo;
802 : 0 : pObj->TakeObjInfo(aInfo);
803 : 0 : if (aInfo.bMoveAllowed && !pObj->IsMoveProtect())
804 : : {
805 : 0 : long nXMov = 0;
806 : 0 : long nYMov = 0;
807 : 0 : long* pValue = &nXMov;
808 : 0 : switch(_nControlModification)
809 : : {
810 : : case ControlModification::TOP :
811 : 0 : aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
812 : 0 : aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
813 : 0 : pValue = &nYMov;
814 : 0 : break;
815 : : case ControlModification::BOTTOM:
816 : : // defaults are already set
817 : 0 : pValue = &nYMov;
818 : 0 : break;
819 : : case ControlModification::CENTER_VERTICAL:
820 : 0 : nYMov = aCenter.Y() - aObjRect.Center().Y();
821 : 0 : pValue = &nYMov;
822 : 0 : bMove = false;
823 : 0 : break;
824 : : case ControlModification::RIGHT :
825 : 0 : aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
826 : 0 : aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
827 : 0 : break;
828 : : case ControlModification::CENTER_HORIZONTAL:
829 : 0 : nXMov = aCenter.X() - aObjRect.Center().X();
830 : 0 : bMove = false;
831 : 0 : break;
832 : : case ControlModification::LEFT :
833 : 0 : aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
834 : 0 : aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
835 : 0 : break;
836 : : default:
837 : 0 : bMove = false;
838 : 0 : break;
839 : : }
840 : 0 : if ( bMove )
841 : : {
842 : 0 : Rectangle aTest = aObjRect;
843 : 0 : aGetFun(&aTest) = aGetFun(&aBound);
844 : 0 : TRectangleMap::iterator aInterSectRectIter = aSortRectangles.begin();
845 : 0 : for (; aInterSectRectIter != aRectIter; ++aInterSectRectIter)
846 : : {
847 : 0 : if ( pView == aInterSectRectIter->second.second && (dynamic_cast<OUnoObject*>(aInterSectRectIter->second.first) || dynamic_cast<OOle2Obj*>(aInterSectRectIter->second.first)))
848 : : {
849 : 0 : SdrObject* pPreviousObj = aInterSectRectIter->second.first;
850 : 0 : Rectangle aIntersectRect = aTest.GetIntersection(_bBoundRects ? pPreviousObj->GetCurrentBoundRect() : pPreviousObj->GetSnapRect());
851 : 0 : if ( !aIntersectRect.IsEmpty() && (aIntersectRect.Left() != aIntersectRect.Right() && aIntersectRect.Top() != aIntersectRect.Bottom() ) )
852 : : {
853 : 0 : *pValue = aRefFun(&aIntersectRect) - aGetFun(&aObjRect);
854 : : break;
855 : : }
856 : : }
857 : : }
858 : 0 : if ( aInterSectRectIter == aRectIter )
859 : 0 : *pValue = aGetFun(&aBound) - aGetFun(&aObjRect);
860 : : }
861 : :
862 : 0 : if ( lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects) )
863 : : {
864 : 0 : const Size aSize(nXMov,nYMov);
865 : 0 : pView->AddUndo(pView->GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pObj,aSize));
866 : 0 : pObj->Move(aSize);
867 : 0 : aObjRect = (_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
868 : : }
869 : :
870 : : // resizing control
871 : 0 : if ( !aResize.IsEmpty() && aObjRect != aResize )
872 : : {
873 : 0 : nXMov = aResize.getWidth();
874 : 0 : nYMov = aResize.getHeight();
875 : 0 : switch(_nControlModification)
876 : : {
877 : : case ControlModification::WIDTH_GREATEST:
878 : : case ControlModification::HEIGHT_GREATEST:
879 : 0 : if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
880 : 0 : nXMov = aObjRect.getWidth();
881 : 0 : else if ( _nControlModification == ControlModification::WIDTH_GREATEST )
882 : 0 : nYMov = aObjRect.getHeight();
883 : 0 : lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects);
884 : : // run through
885 : : case ControlModification::WIDTH_SMALLEST:
886 : : case ControlModification::HEIGHT_SMALLEST:
887 : 0 : pView->AddUndo( pView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
888 : : {
889 : 0 : OObjectBase* pObjBase = dynamic_cast<OObjectBase*>(pObj);
890 : : OSL_ENSURE(pObjBase,"Where comes this object from?");
891 : 0 : if ( pObjBase )
892 : : {
893 : 0 : if ( _nControlModification == ControlModification::WIDTH_SMALLEST || _nControlModification == ControlModification::WIDTH_GREATEST )
894 : 0 : pObjBase->getReportComponent()->setSize(awt::Size(nXMov,aObjRect.getHeight()));
895 : 0 : else if ( _nControlModification == ControlModification::HEIGHT_GREATEST || _nControlModification == ControlModification::HEIGHT_SMALLEST )
896 : 0 : pObjBase->getReportComponent()->setSize(awt::Size(aObjRect.getWidth(),nYMov));
897 : : }
898 : : }
899 : 0 : break;
900 : : default:
901 : 0 : break;
902 : : }
903 : : }
904 : : }
905 : 0 : pView->AdjustMarkHdl();
906 : 0 : }
907 : : }
908 : : // -----------------------------------------------------------------------------
909 : 0 : void OViewsWindow::createDefault()
910 : : {
911 : 0 : ::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
912 : 0 : if ( pMarkedSection )
913 : 0 : pMarkedSection->getReportSection().createDefault(m_sShapeType);
914 : 0 : }
915 : : // -----------------------------------------------------------------------------
916 : 0 : void OViewsWindow::setGridSnap(sal_Bool bOn)
917 : : {
918 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
919 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
920 : 0 : for (; aIter != aEnd ; ++aIter)
921 : : {
922 : 0 : (*aIter)->getReportSection().getSectionView().SetGridSnap(bOn);
923 : : static sal_Int32 nIn = 0;
924 : 0 : (*aIter)->getReportSection().Invalidate(nIn);
925 : : }
926 : 0 : }
927 : : // -----------------------------------------------------------------------------
928 : 0 : void OViewsWindow::setDragStripes(sal_Bool bOn)
929 : : {
930 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
931 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
932 : 0 : for (; aIter != aEnd ; ++aIter)
933 : 0 : (*aIter)->getReportSection().getSectionView().SetDragStripes(bOn);
934 : 0 : }
935 : : // -----------------------------------------------------------------------------
936 : 0 : sal_uInt16 OViewsWindow::getPosition(const OSectionWindow* _pSectionWindow) const
937 : : {
938 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
939 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
940 : 0 : sal_uInt16 nPosition = 0;
941 : 0 : for (; aIter != aEnd ; ++aIter)
942 : : {
943 : 0 : if ( _pSectionWindow == (*aIter).get() )
944 : : {
945 : 0 : break;
946 : : }
947 : 0 : ++nPosition;
948 : : }
949 : 0 : return nPosition;
950 : : }
951 : : // -----------------------------------------------------------------------------
952 : 0 : ::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const sal_uInt16 _nPos) const
953 : : {
954 : 0 : ::boost::shared_ptr<OSectionWindow> aReturn;
955 : :
956 : 0 : if ( _nPos < m_aSections.size() )
957 : 0 : aReturn = m_aSections[_nPos];
958 : :
959 : 0 : return aReturn;
960 : : }
961 : : // -----------------------------------------------------------------------------
962 : : namespace
963 : : {
964 : : enum SectionViewAction
965 : : {
966 : : eEndDragObj,
967 : : eEndAction,
968 : : eMoveAction,
969 : : eMarkAction,
970 : : eForceToAnotherPage,
971 : : eBreakAction
972 : : };
973 : : class ApplySectionViewAction : public ::std::unary_function< OViewsWindow::TSectionsMap::value_type, void >
974 : : {
975 : : private:
976 : : SectionViewAction m_eAction;
977 : : sal_Bool m_bCopy;
978 : : Point m_aPoint;
979 : :
980 : : public:
981 : 0 : ApplySectionViewAction( sal_Bool _bCopy ) : m_eAction( eEndDragObj ), m_bCopy( _bCopy ) { }
982 : 0 : ApplySectionViewAction(SectionViewAction _eAction = eEndAction ) : m_eAction( _eAction ) { }
983 : : ApplySectionViewAction( const Point& _rPoint, SectionViewAction _eAction = eMoveAction ) : m_eAction( _eAction ), m_bCopy( sal_False ), m_aPoint( _rPoint ) { }
984 : :
985 : 0 : void operator() ( const OViewsWindow::TSectionsMap::value_type& _rhs )
986 : : {
987 : 0 : OSectionView& rView( _rhs->getReportSection().getSectionView() );
988 : 0 : switch ( m_eAction )
989 : : {
990 : : case eEndDragObj:
991 : 0 : rView.EndDragObj( m_bCopy );
992 : 0 : break;
993 : : case eEndAction:
994 : 0 : if ( rView.IsAction() )
995 : 0 : rView.EndAction ( );
996 : 0 : break;
997 : : case eMoveAction:
998 : 0 : rView.MovAction ( m_aPoint );
999 : 0 : break;
1000 : : case eMarkAction:
1001 : 0 : rView.BegMarkObj ( m_aPoint );
1002 : 0 : break;
1003 : : case eForceToAnotherPage:
1004 : 0 : rView.ForceMarkedToAnotherPage();
1005 : 0 : break;
1006 : : case eBreakAction:
1007 : 0 : if ( rView.IsAction() )
1008 : 0 : rView.BrkAction ( );
1009 : 0 : break;
1010 : : // default:
1011 : :
1012 : : }
1013 : 0 : }
1014 : : };
1015 : : }
1016 : : // -----------------------------------------------------------------------------
1017 : 0 : void OViewsWindow::BrkAction()
1018 : : {
1019 : 0 : EndDragObj_removeInvisibleObjects();
1020 : 0 : ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eBreakAction) );
1021 : 0 : }
1022 : : // -----------------------------------------------------------------------------
1023 : 0 : void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const Rectangle& _aRect, const OSectionView& _rSection)
1024 : : {
1025 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1026 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1027 : 0 : Point aNewPos(0,0);
1028 : :
1029 : 0 : for (; aIter != aEnd; ++aIter)
1030 : : {
1031 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1032 : 0 : rReportSection.getPage()->setSpecialMode();
1033 : 0 : OSectionView& rView = rReportSection.getSectionView();
1034 : :
1035 : 0 : if ( &rView != &_rSection )
1036 : : {
1037 : 0 : SdrObject *pNewObj = new SdrUnoObj(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText")));
1038 : 0 : if (pNewObj)
1039 : : {
1040 : 0 : pNewObj->SetLogicRect(_aRect);
1041 : :
1042 : 0 : pNewObj->Move(Size(0, aNewPos.Y()));
1043 : 0 : sal_Bool bChanged = rView.GetModel()->IsChanged();
1044 : 0 : rReportSection.getPage()->InsertObject(pNewObj);
1045 : 0 : rView.GetModel()->SetChanged(bChanged);
1046 : 0 : m_aBegDragTempList.push_back(pNewObj);
1047 : :
1048 : 0 : rView.MarkObj( pNewObj, rView.GetSdrPageView() );
1049 : : }
1050 : : }
1051 : 0 : const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1052 : 0 : aNewPos.Y() -= nSectionHeight;
1053 : : }
1054 : 0 : }
1055 : : // -----------------------------------------------------------------------------
1056 : 0 : bool OViewsWindow::isObjectInMyTempList(SdrObject *_pObj)
1057 : : {
1058 : 0 : return ::std::find(m_aBegDragTempList.begin(),m_aBegDragTempList.end(),_pObj) != m_aBegDragTempList.end();
1059 : : }
1060 : :
1061 : : // -----------------------------------------------------------------------------
1062 : 0 : void OViewsWindow::BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection)
1063 : : {
1064 : : OSL_TRACE("BegDragObj Clickpoint X:%d Y:%d", _aPnt.X(), _aPnt.Y() );
1065 : :
1066 : 0 : m_aBegDragTempList.clear();
1067 : :
1068 : : // Calculate the absolute clickpoint in the views
1069 : 0 : Point aAbsolutePnt = _aPnt;
1070 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1071 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1072 : 0 : for (; aIter != aEnd; ++aIter)
1073 : : {
1074 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1075 : 0 : OSectionView* pView = &rReportSection.getSectionView();
1076 : 0 : if (pView == _pSection)
1077 : 0 : break;
1078 : 0 : const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1079 : 0 : aAbsolutePnt.Y() += nSectionHeight;
1080 : : }
1081 : 0 : m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1082 : : OSL_TRACE("BegDragObj Absolute X:%d Y:%d", aAbsolutePnt.X(), aAbsolutePnt.Y() );
1083 : :
1084 : : // Create drag lines over all viewable Views
1085 : : // Therefore we need to identify the marked objects
1086 : : // and create temporary objects on all other views at the same position
1087 : : // relative to its occurrence.
1088 : :
1089 : : OSL_TRACE("BegDragObj createInvisible Objects" );
1090 : 0 : int nViewCount = 0;
1091 : 0 : Point aNewObjPos(0,0);
1092 : 0 : Point aLeftTop = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1093 : 0 : for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1094 : : {
1095 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1096 : :
1097 : 0 : OSectionView& rView = rReportSection.getSectionView();
1098 : :
1099 : 0 : if ( rView.AreObjectsMarked() )
1100 : : {
1101 : 0 : const sal_uInt32 nCount = rView.GetMarkedObjectCount();
1102 : 0 : for (sal_uInt32 i=0; i < nCount; ++i)
1103 : : {
1104 : 0 : const SdrMark* pM = rView.GetSdrMarkByIndex(i);
1105 : 0 : SdrObject* pObj = pM->GetMarkedSdrObj();
1106 : 0 : if (!isObjectInMyTempList(pObj))
1107 : : {
1108 : 0 : Rectangle aRect( pObj->GetCurrentBoundRect() );
1109 : 0 : aRect.Move(0, aNewObjPos.Y());
1110 : :
1111 : 0 : aLeftTop.X() = ::std::min( aRect.Left(), aLeftTop.X() );
1112 : 0 : aLeftTop.Y() = ::std::min( aRect.Top(), aLeftTop.Y() );
1113 : :
1114 : : OSL_TRACE("BegDragObj createInvisible X:%d Y:%d on View #%d", aRect.Left(), aRect.Top(), nViewCount );
1115 : :
1116 : 0 : BegDragObj_createInvisibleObjectAtPosition(aRect, rView);
1117 : : }
1118 : : }
1119 : : }
1120 : 0 : ++nViewCount;
1121 : 0 : Rectangle aClipRect = rView.GetWorkArea();
1122 : 0 : aClipRect.Top() = -aNewObjPos.Y();
1123 : 0 : rView.SetWorkArea( aClipRect );
1124 : :
1125 : 0 : const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1126 : 0 : aNewObjPos.Y() += nSectionHeight;
1127 : : }
1128 : :
1129 : 0 : const sal_Int32 nDeltaX = abs(aLeftTop.X() - aAbsolutePnt.X());
1130 : 0 : const sal_Int32 nDeltaY = abs(aLeftTop.Y() - aAbsolutePnt.Y());
1131 : 0 : m_aDragDelta.X() = nDeltaX;
1132 : 0 : m_aDragDelta.Y() = nDeltaY;
1133 : :
1134 : 0 : Point aNewPos = aAbsolutePnt;
1135 : :
1136 : 0 : const short nDrgLog = static_cast<short>(PixelToLogic(Size(3,0)).Width());
1137 : 0 : nViewCount = 0;
1138 : 0 : for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1139 : : {
1140 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1141 : :
1142 : 0 : SdrHdl* pHdl = _pHdl;
1143 : 0 : if ( pHdl )
1144 : : {
1145 : 0 : if ( &rReportSection.getSectionView() != _pSection )
1146 : : {
1147 : 0 : const SdrHdlList& rHdlList = rReportSection.getSectionView().GetHdlList();
1148 : 0 : pHdl = rHdlList.GetHdl(_pHdl->GetKind());
1149 : : }
1150 : : }
1151 : : OSL_TRACE("BegDragObj X:%d Y:%d on View#%d", aNewPos.X(), aNewPos.Y(), nViewCount++ );
1152 : 0 : rReportSection.getSectionView().BegDragObj(aNewPos, (OutputDevice*)NULL, pHdl, nDrgLog, NULL);
1153 : :
1154 : 0 : const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1155 : 0 : aNewPos.Y() -= nSectionHeight;
1156 : : }
1157 : 0 : }
1158 : :
1159 : : // -----------------------------------------------------------------------------
1160 : 0 : void OViewsWindow::ForceMarkedToAnotherPage()
1161 : : {
1162 : 0 : ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eForceToAnotherPage ) );
1163 : 0 : }
1164 : : // -----------------------------------------------------------------------------
1165 : 0 : void OViewsWindow::BegMarkObj(const Point& _aPnt,const OSectionView* _pSection)
1166 : : {
1167 : 0 : bool bAdd = true;
1168 : 0 : Point aNewPos = _aPnt;
1169 : :
1170 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1171 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1172 : 0 : long nLastSectionHeight = 0;
1173 : 0 : for (; aIter != aEnd; ++aIter)
1174 : : {
1175 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1176 : 0 : if ( &rReportSection.getSectionView() == _pSection )
1177 : : {
1178 : 0 : bAdd = false;
1179 : 0 : aNewPos = _aPnt; // 2,2
1180 : : }
1181 : 0 : else if ( bAdd )
1182 : : {
1183 : 0 : const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1184 : 0 : aNewPos.Y() += nSectionHeight;
1185 : : }
1186 : : else
1187 : : {
1188 : 0 : aNewPos.Y() -= nLastSectionHeight;
1189 : : }
1190 : 0 : rReportSection.getSectionView().BegMarkObj ( aNewPos );
1191 : 0 : nLastSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1192 : : }
1193 : 0 : }
1194 : : // -----------------------------------------------------------------------------
1195 : 0 : OSectionView* OViewsWindow::getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt)
1196 : : {
1197 : 0 : OSectionView* pSection = NULL;
1198 : 0 : sal_Int32 nCount = 0;
1199 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1200 : 0 : const TSectionsMap::iterator aEnd = m_aSections.end();
1201 : 0 : for (; aIter != aEnd ; ++aIter,++nCount)
1202 : : {
1203 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1204 : 0 : if ( &rReportSection.getSectionView() == _pSection)
1205 : 0 : break;
1206 : : }
1207 : : OSL_ENSURE(aIter != aEnd,"This can never happen!");
1208 : 0 : if ( _rPnt.Y() < 0 )
1209 : : {
1210 : 0 : if ( nCount )
1211 : 0 : --aIter;
1212 : 0 : for (; nCount && (_rPnt.Y() < 0); --nCount)
1213 : : {
1214 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1215 : 0 : const sal_Int32 nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1216 : 0 : _rPnt.Y() += nHeight;
1217 : 0 : if ( (nCount -1) > 0 && (_rPnt.Y() < 0) )
1218 : 0 : --aIter;
1219 : : }
1220 : 0 : if ( nCount == 0 )
1221 : 0 : pSection = &(*m_aSections.begin())->getReportSection().getSectionView();
1222 : : else
1223 : 0 : pSection = &(*aIter)->getReportSection().getSectionView();
1224 : : }
1225 : : else
1226 : : {
1227 : 0 : for (; aIter != aEnd; ++aIter)
1228 : : {
1229 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1230 : 0 : const long nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1231 : 0 : if ( (_rPnt.Y() - nHeight) < 0 )
1232 : 0 : break;
1233 : 0 : _rPnt.Y() -= nHeight;
1234 : : }
1235 : 0 : if ( aIter != aEnd )
1236 : 0 : pSection = &(*aIter)->getReportSection().getSectionView();
1237 : : else
1238 : 0 : pSection = &(*(aEnd-1))->getReportSection().getSectionView();
1239 : : }
1240 : :
1241 : 0 : return pSection;
1242 : : }
1243 : : // -----------------------------------------------------------------------------
1244 : 0 : void OViewsWindow::EndDragObj_removeInvisibleObjects()
1245 : : {
1246 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1247 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1248 : :
1249 : 0 : for (; aIter != aEnd; ++aIter)
1250 : : {
1251 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1252 : 0 : rReportSection.getPage()->resetSpecialMode();
1253 : : }
1254 : 0 : }
1255 : : // -----------------------------------------------------------------------------
1256 : 0 : void OViewsWindow::EndDragObj(sal_Bool _bControlKeyPressed, const OSectionView* _pSection,const Point& _aPnt)
1257 : : {
1258 : 0 : const String sUndoAction = String((ModuleRes(RID_STR_UNDO_CHANGEPOSITION)));
1259 : 0 : const UndoContext aUndoContext( getView()->getReportView()->getController().getUndoManager(), sUndoAction );
1260 : :
1261 : 0 : Point aNewPos = _aPnt;
1262 : 0 : OSectionView* pInSection = getSectionRelativeToPosition(_pSection, aNewPos);
1263 : 0 : if (!_bControlKeyPressed &&
1264 : 0 : (_pSection && ( _pSection->IsDragResize() == false ) ) && /* Not in resize mode */
1265 : : _pSection != pInSection)
1266 : : {
1267 : 0 : EndDragObj_removeInvisibleObjects();
1268 : :
1269 : : // we need to manipulate the current clickpoint, we substract the old delta from BeginDrag
1270 : 0 : aNewPos -= m_aDragDelta;
1271 : :
1272 : 0 : uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
1273 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1274 : 0 : const TSectionsMap::iterator aEnd = m_aSections.end();
1275 : 0 : for (; aIter != aEnd; ++aIter)
1276 : : {
1277 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1278 : 0 : if ( pInSection != &rReportSection.getSectionView() )
1279 : : {
1280 : 0 : rReportSection.getSectionView().BrkAction();
1281 : 0 : rReportSection.Copy(aAllreadyCopiedObjects,true);
1282 : : }
1283 : : else
1284 : 0 : pInSection->EndDragObj(sal_False);
1285 : : }
1286 : :
1287 : 0 : if ( aAllreadyCopiedObjects.getLength() )
1288 : : {
1289 : 0 : beans::NamedValue* pIter = aAllreadyCopiedObjects.getArray();
1290 : 0 : const beans::NamedValue* pEnd = pIter + aAllreadyCopiedObjects.getLength();
1291 : : try
1292 : : {
1293 : 0 : uno::Reference<report::XReportDefinition> xReportDefinition = getView()->getReportView()->getController().getReportDefinition();
1294 : 0 : const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
1295 : 0 : const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
1296 : 0 : const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
1297 : :
1298 : 0 : if ( aNewPos.X() < nLeftMargin )
1299 : 0 : aNewPos.X() = nLeftMargin;
1300 : 0 : if ( aNewPos.Y() < 0 )
1301 : 0 : aNewPos.Y() = 0;
1302 : :
1303 : 0 : Point aPrevious;
1304 : 0 : for (; pIter != pEnd; ++pIter)
1305 : : {
1306 : 0 : uno::Sequence< uno::Reference<report::XReportComponent> > aClones;
1307 : 0 : pIter->Value >>= aClones;
1308 : 0 : uno::Reference<report::XReportComponent>* pColIter = aClones.getArray();
1309 : 0 : const uno::Reference<report::XReportComponent>* pColEnd = pColIter + aClones.getLength();
1310 : :
1311 : : // move the cloned Components to new positions
1312 : 0 : for (; pColIter != pColEnd; ++pColIter)
1313 : : {
1314 : 0 : uno::Reference< report::XReportComponent> xRC(*pColIter);
1315 : 0 : aPrevious = VCLPoint(xRC->getPosition());
1316 : 0 : awt::Size aSize = xRC->getSize();
1317 : :
1318 : 0 : if ( aNewPos.X() < nLeftMargin )
1319 : : {
1320 : 0 : aNewPos.X() = nLeftMargin;
1321 : : }
1322 : 0 : else if ( (aNewPos.X() + aSize.Width) > (nPaperWidth - nRightMargin) )
1323 : : {
1324 : 0 : aNewPos.X() = nPaperWidth - nRightMargin - aSize.Width;
1325 : : }
1326 : 0 : if ( aNewPos.Y() < 0 )
1327 : : {
1328 : 0 : aNewPos.Y() = 0;
1329 : : }
1330 : 0 : if ( aNewPos.X() < 0 )
1331 : : {
1332 : 0 : aSize.Width += aNewPos.X();
1333 : 0 : aNewPos.X()= 0;
1334 : 0 : xRC->setSize(aSize);
1335 : : }
1336 : 0 : xRC->setPosition(AWTPoint(aNewPos));
1337 : 0 : if ( (pColIter+1) != pColEnd )
1338 : : {
1339 : : // bring aNewPos to the position of the next object
1340 : 0 : uno::Reference< report::XReportComponent> xRCNext(*(pColIter + 1),uno::UNO_QUERY);
1341 : 0 : Point aNextPosition = VCLPoint(xRCNext->getPosition());
1342 : 0 : aNewPos += (aNextPosition - aPrevious);
1343 : : }
1344 : 0 : }
1345 : 0 : }
1346 : : }
1347 : 0 : catch(uno::Exception&)
1348 : : {
1349 : : }
1350 : 0 : pInSection->getReportSection()->Paste(aAllreadyCopiedObjects,true);
1351 : 0 : }
1352 : : }
1353 : : else
1354 : : {
1355 : 0 : ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction( sal_False ) );
1356 : 0 : EndDragObj_removeInvisibleObjects();
1357 : : }
1358 : 0 : m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1359 : 0 : }
1360 : : // -----------------------------------------------------------------------------
1361 : 0 : void OViewsWindow::EndAction()
1362 : : {
1363 : 0 : ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction() );
1364 : 0 : }
1365 : : // -----------------------------------------------------------------------------
1366 : 0 : void OViewsWindow::MovAction(const Point& _aPnt,const OSectionView* _pSection,bool _bMove, bool _bControlKeySet)
1367 : : {
1368 : : (void)_bMove;
1369 : :
1370 : 0 : Point aRealMousePos = _aPnt;
1371 : 0 : Point aCurrentSectionPos;
1372 : : OSL_TRACE("MovAction X:%d Y:%d", aRealMousePos.X(), aRealMousePos.Y() );
1373 : :
1374 : 0 : Point aHdlPos;
1375 : 0 : SdrHdl* pHdl = _pSection->GetDragHdl();
1376 : 0 : if ( pHdl )
1377 : : {
1378 : 0 : aHdlPos = pHdl->GetPos();
1379 : : }
1380 : :
1381 : 0 : TSectionsMap::iterator aIter;
1382 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1383 : :
1384 : 0 : for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1385 : : {
1386 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1387 : 0 : if ( &rReportSection.getSectionView() == _pSection )
1388 : 0 : break;
1389 : 0 : const long nSectionHeight = (*aIter)->PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1390 : 0 : aCurrentSectionPos.Y() += nSectionHeight;
1391 : : }
1392 : 0 : aRealMousePos += aCurrentSectionPos;
1393 : :
1394 : : // If control key is pressed the work area is limited to the section with the current selection.
1395 : 0 : Point aPosForWorkArea(0,0);
1396 : 0 : for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1397 : : {
1398 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1399 : 0 : OSectionView& rView = rReportSection.getSectionView();
1400 : 0 : const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
1401 : :
1402 : 0 : if (_bControlKeySet)
1403 : : {
1404 : 0 : Rectangle aClipRect = rView.GetWorkArea();
1405 : 0 : aClipRect.Top() = aCurrentSectionPos.Y() - aPosForWorkArea.Y();
1406 : 0 : aClipRect.Bottom() = aClipRect.Top() + nSectionHeight;
1407 : 0 : rView.SetWorkArea( aClipRect );
1408 : : }
1409 : : else
1410 : : {
1411 : 0 : Rectangle aClipRect = rView.GetWorkArea();
1412 : 0 : aClipRect.Top() = -aPosForWorkArea.Y();
1413 : 0 : rView.SetWorkArea( aClipRect );
1414 : : }
1415 : 0 : aPosForWorkArea.Y() += nSectionHeight;
1416 : : }
1417 : :
1418 : :
1419 : 0 : for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1420 : : {
1421 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1422 : 0 : SdrHdl* pCurrentHdl = rReportSection.getSectionView().GetDragHdl();
1423 : 0 : if ( pCurrentHdl )
1424 : : {
1425 : 0 : if ( aRealMousePos.Y() > 0 )
1426 : 0 : aRealMousePos = _aPnt + pCurrentHdl->GetPos() - aHdlPos;
1427 : : }
1428 : 0 : rReportSection.getSectionView().MovAction ( aRealMousePos );
1429 : 0 : const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
1430 : 0 : aRealMousePos.Y() -= nSectionHeight;
1431 : : }
1432 : 0 : }
1433 : : // -----------------------------------------------------------------------------
1434 : 0 : sal_Bool OViewsWindow::IsAction() const
1435 : : {
1436 : 0 : sal_Bool bAction = sal_False;
1437 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1438 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1439 : 0 : for (; !bAction && aIter != aEnd; ++aIter)
1440 : 0 : bAction = (*aIter)->getReportSection().getSectionView().IsAction();
1441 : 0 : return bAction;
1442 : : }
1443 : : // -----------------------------------------------------------------------------
1444 : 0 : sal_Bool OViewsWindow::IsDragObj() const
1445 : : {
1446 : 0 : sal_Bool bAction = sal_False;
1447 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1448 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1449 : 0 : for (; !bAction && aIter != aEnd; ++aIter)
1450 : 0 : bAction = (*aIter)->getReportSection().getSectionView().IsAction();
1451 : 0 : return bAction;
1452 : : }
1453 : : // -----------------------------------------------------------------------------
1454 : 0 : sal_uInt32 OViewsWindow::getMarkedObjectCount() const
1455 : : {
1456 : 0 : sal_uInt32 nCount = 0;
1457 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1458 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1459 : 0 : for (; aIter != aEnd; ++aIter)
1460 : 0 : nCount += (*aIter)->getReportSection().getSectionView().GetMarkedObjectCount();
1461 : 0 : return nCount;
1462 : : }
1463 : : // -----------------------------------------------------------------------------
1464 : 0 : void OViewsWindow::handleKey(const KeyCode& _rCode)
1465 : : {
1466 : 0 : const sal_uInt16 nCode = _rCode.GetCode();
1467 : 0 : if ( _rCode.IsMod1() )
1468 : : {
1469 : : // scroll page
1470 : 0 : OScrollWindowHelper* pScrollWindow = getView()->getScrollWindow();
1471 : 0 : ScrollBar* pScrollBar = ( nCode == KEY_LEFT || nCode == KEY_RIGHT ) ? pScrollWindow->GetHScroll() : pScrollWindow->GetVScroll();
1472 : 0 : if ( pScrollBar && pScrollBar->IsVisible() )
1473 : 0 : pScrollBar->DoScrollAction(( nCode == KEY_RIGHT || nCode == KEY_UP ) ? SCROLL_LINEUP : SCROLL_LINEDOWN );
1474 : 0 : return;
1475 : : }
1476 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1477 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1478 : 0 : for (; aIter != aEnd; ++aIter)
1479 : : {
1480 : 0 : OReportSection& rReportSection = (*aIter)->getReportSection();
1481 : 0 : long nX = 0;
1482 : 0 : long nY = 0;
1483 : :
1484 : 0 : if ( nCode == KEY_UP )
1485 : 0 : nY = -1;
1486 : 0 : else if ( nCode == KEY_DOWN )
1487 : 0 : nY = 1;
1488 : 0 : else if ( nCode == KEY_LEFT )
1489 : 0 : nX = -1;
1490 : 0 : else if ( nCode == KEY_RIGHT )
1491 : 0 : nX = 1;
1492 : :
1493 : 0 : if ( rReportSection.getSectionView().AreObjectsMarked() )
1494 : : {
1495 : 0 : if ( _rCode.IsMod2() )
1496 : : {
1497 : : // move in 1 pixel distance
1498 : 0 : const Size aPixelSize = rReportSection.PixelToLogic( Size( 1, 1 ) );
1499 : 0 : nX *= aPixelSize.Width();
1500 : 0 : nY *= aPixelSize.Height();
1501 : : }
1502 : : else
1503 : : {
1504 : : // move in 1 mm distance
1505 : 0 : nX *= DEFAUL_MOVE_SIZE;
1506 : 0 : nY *= DEFAUL_MOVE_SIZE;
1507 : : }
1508 : :
1509 : 0 : OSectionView& rView = rReportSection.getSectionView();
1510 : 0 : const SdrHdlList& rHdlList = rView.GetHdlList();
1511 : 0 : SdrHdl* pHdl = rHdlList.GetFocusHdl();
1512 : :
1513 : 0 : if ( pHdl == 0 )
1514 : : {
1515 : : // no handle selected
1516 : 0 : if ( rView.IsMoveAllowed() )
1517 : : {
1518 : : // restrict movement to work area
1519 : 0 : Rectangle rWorkArea = rView.GetWorkArea();
1520 : 0 : rWorkArea.Right()++;
1521 : :
1522 : 0 : if ( !rWorkArea.IsEmpty() )
1523 : : {
1524 : 0 : if ( rWorkArea.Top() < 0 )
1525 : 0 : rWorkArea.Top() = 0;
1526 : 0 : Rectangle aMarkRect( rView.GetMarkedObjRect() );
1527 : 0 : aMarkRect.Move( nX, nY );
1528 : :
1529 : 0 : if ( !rWorkArea.IsInside( aMarkRect ) )
1530 : : {
1531 : 0 : if ( aMarkRect.Left() < rWorkArea.Left() )
1532 : 0 : nX += rWorkArea.Left() - aMarkRect.Left();
1533 : :
1534 : 0 : if ( aMarkRect.Right() > rWorkArea.Right() )
1535 : 0 : nX -= aMarkRect.Right() - rWorkArea.Right();
1536 : :
1537 : 0 : if ( aMarkRect.Top() < rWorkArea.Top() )
1538 : 0 : nY += rWorkArea.Top() - aMarkRect.Top();
1539 : :
1540 : 0 : if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
1541 : 0 : nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
1542 : : }
1543 : 0 : bool bCheck = false;
1544 : 0 : const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1545 : 0 : for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
1546 : : {
1547 : 0 : SdrMark* pMark = rMarkList.GetMark(i);
1548 : 0 : bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL|| dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
1549 : : }
1550 : :
1551 : :
1552 : 0 : if ( bCheck )
1553 : : {
1554 : 0 : SdrObject* pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1555 : 0 : if ( pOverlapped )
1556 : : {
1557 : 0 : do
1558 : : {
1559 : 0 : Rectangle aOver = pOverlapped->GetLastBoundRect();
1560 : 0 : Point aPos;
1561 : 0 : if ( nCode == KEY_UP )
1562 : : {
1563 : 0 : aPos.X() = aMarkRect.Left();
1564 : 0 : aPos.Y() = aOver.Top() - aMarkRect.getHeight();
1565 : 0 : nY += (aPos.Y() - aMarkRect.Top());
1566 : : }
1567 : 0 : else if ( nCode == KEY_DOWN )
1568 : : {
1569 : 0 : aPos.X() = aMarkRect.Left();
1570 : 0 : aPos.Y() = aOver.Bottom();
1571 : 0 : nY += (aPos.Y() - aMarkRect.Top());
1572 : : }
1573 : 0 : else if ( nCode == KEY_LEFT )
1574 : : {
1575 : 0 : aPos.X() = aOver.Left() - aMarkRect.getWidth();
1576 : 0 : aPos.Y() = aMarkRect.Top();
1577 : 0 : nX += (aPos.X() - aMarkRect.Left());
1578 : : }
1579 : 0 : else if ( nCode == KEY_RIGHT )
1580 : : {
1581 : 0 : aPos.X() = aOver.Right();
1582 : 0 : aPos.Y() = aMarkRect.Top();
1583 : 0 : nX += (aPos.X() - aMarkRect.Left());
1584 : : }
1585 : :
1586 : 0 : aMarkRect.SetPos(aPos);
1587 : 0 : if ( !rWorkArea.IsInside( aMarkRect ) )
1588 : : {
1589 : : break;
1590 : : }
1591 : 0 : pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1592 : : }
1593 : : while(pOverlapped != NULL);
1594 : 0 : if (pOverlapped != NULL)
1595 : : break;
1596 : : }
1597 : : }
1598 : : }
1599 : :
1600 : 0 : if ( nX != 0 || nY != 0 )
1601 : : {
1602 : 0 : rView.MoveAllMarked( Size( nX, nY ) );
1603 : 0 : rView.MakeVisible( rView.GetAllMarkedRect(), rReportSection);
1604 : : }
1605 : : }
1606 : : }
1607 : : else
1608 : : {
1609 : : // move the handle
1610 : 0 : if ( pHdl && ( nX || nY ) )
1611 : : {
1612 : 0 : const Point aStartPoint( pHdl->GetPos() );
1613 : 0 : const Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
1614 : 0 : const SdrDragStat& rDragStat = rView.GetDragStat();
1615 : :
1616 : : // start dragging
1617 : 0 : rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
1618 : :
1619 : 0 : if ( rView.IsDragObj() )
1620 : : {
1621 : 0 : const bool bWasNoSnap = rDragStat.IsNoSnap();
1622 : 0 : const sal_Bool bWasSnapEnabled = rView.IsSnapEnabled();
1623 : :
1624 : : // switch snapping off
1625 : 0 : if ( !bWasNoSnap )
1626 : 0 : ((SdrDragStat&)rDragStat).SetNoSnap( sal_True );
1627 : 0 : if ( bWasSnapEnabled )
1628 : 0 : rView.SetSnapEnabled( sal_False );
1629 : :
1630 : 0 : Rectangle aNewRect;
1631 : 0 : bool bCheck = false;
1632 : 0 : const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1633 : 0 : for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
1634 : : {
1635 : 0 : SdrMark* pMark = rMarkList.GetMark(i);
1636 : 0 : bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL || dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj()) != NULL;
1637 : 0 : if ( bCheck )
1638 : 0 : aNewRect.Union(pMark->GetMarkedSdrObj()->GetLastBoundRect());
1639 : : }
1640 : :
1641 : 0 : switch(pHdl->GetKind())
1642 : : {
1643 : : case HDL_LEFT:
1644 : : case HDL_UPLFT:
1645 : : case HDL_LWLFT:
1646 : : case HDL_UPPER:
1647 : 0 : aNewRect.Left() += nX;
1648 : 0 : aNewRect.Top() += nY;
1649 : 0 : break;
1650 : : case HDL_UPRGT:
1651 : : case HDL_RIGHT:
1652 : : case HDL_LWRGT:
1653 : : case HDL_LOWER:
1654 : 0 : aNewRect.setWidth(aNewRect.getWidth() + nX);
1655 : 0 : aNewRect.setHeight(aNewRect.getHeight() + nY);
1656 : 0 : break;
1657 : : default:
1658 : 0 : break;
1659 : : }
1660 : 0 : if ( !(bCheck && isOver(aNewRect,*rReportSection.getPage(),rView)) )
1661 : 0 : rView.MovAction(aEndPoint);
1662 : 0 : rView.EndDragObj();
1663 : :
1664 : : // restore snap
1665 : 0 : if ( !bWasNoSnap )
1666 : 0 : ((SdrDragStat&)rDragStat).SetNoSnap( bWasNoSnap );
1667 : 0 : if ( bWasSnapEnabled )
1668 : 0 : rView.SetSnapEnabled( bWasSnapEnabled );
1669 : : }
1670 : :
1671 : : // make moved handle visible
1672 : 0 : const Rectangle aVisRect( aEndPoint - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
1673 : 0 : rView.MakeVisible( aVisRect, rReportSection);
1674 : : }
1675 : : }
1676 : 0 : rView.AdjustMarkHdl();
1677 : : }
1678 : : }
1679 : : }
1680 : : // -----------------------------------------------------------------------------
1681 : 0 : void OViewsWindow::stopScrollTimer()
1682 : : {
1683 : : ::std::for_each(m_aSections.begin(),m_aSections.end(),
1684 : 0 : ::o3tl::compose1(::boost::mem_fn(&OReportSection::stopScrollTimer),TReportPairHelper()));
1685 : 0 : }
1686 : : // -----------------------------------------------------------------------------
1687 : 0 : void OViewsWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
1688 : : {
1689 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1690 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1691 : 0 : for (sal_uInt16 i = 0;aIter != aEnd ; ++aIter,++i)
1692 : : {
1693 : 0 : if ( (*aIter)->getStartMarker().isCollapsed() )
1694 : 0 : _rCollapsedPositions.push_back(i);
1695 : : }
1696 : 0 : }
1697 : : // -----------------------------------------------------------------------------
1698 : 0 : void OViewsWindow::collapseSections(const uno::Sequence< beans::PropertyValue>& _aCollpasedSections)
1699 : : {
1700 : 0 : const beans::PropertyValue* pIter = _aCollpasedSections.getConstArray();
1701 : 0 : const beans::PropertyValue* pEnd = pIter + _aCollpasedSections.getLength();
1702 : 0 : for (; pIter != pEnd; ++pIter)
1703 : : {
1704 : 0 : sal_uInt16 nPos = sal_uInt16(-1);
1705 : 0 : if ( (pIter->Value >>= nPos) && nPos < m_aSections.size() )
1706 : : {
1707 : 0 : m_aSections[nPos]->setCollapsed(sal_True);
1708 : : }
1709 : : }
1710 : 0 : }
1711 : : // -----------------------------------------------------------------------------
1712 : 0 : void OViewsWindow::zoom(const Fraction& _aZoom)
1713 : : {
1714 : 0 : const MapMode& aMapMode = GetMapMode();
1715 : :
1716 : 0 : Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
1717 : 0 : if ( _aZoom < aMapMode.GetScaleX() )
1718 : 0 : aStartWidth *= aMapMode.GetScaleX();
1719 : : else
1720 : 0 : aStartWidth *= _aZoom;
1721 : :
1722 : 0 : setZoomFactor(_aZoom,*this);
1723 : :
1724 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1725 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1726 : 0 : for (;aIter != aEnd ; ++aIter)
1727 : : {
1728 : 0 : (*aIter)->zoom(_aZoom);
1729 : : }
1730 : :
1731 : 0 : Resize();
1732 : :
1733 : 0 : Size aOut = GetOutputSizePixel();
1734 : 0 : aOut.Width() = aStartWidth;
1735 : 0 : aOut = PixelToLogic(aOut);
1736 : :
1737 : 0 : Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
1738 : : static sal_Int32 nIn = INVALIDATE_NOCHILDREN;
1739 : 0 : Invalidate(aRect,nIn);
1740 : 0 : }
1741 : : //----------------------------------------------------------------------------
1742 : 0 : void OViewsWindow::scrollChildren(const Point& _aThumbPos)
1743 : : {
1744 : 0 : const Point aPos(PixelToLogic(_aThumbPos));
1745 : : {
1746 : 0 : MapMode aMapMode = GetMapMode();
1747 : 0 : const Point aOld = aMapMode.GetOrigin();
1748 : 0 : aMapMode.SetOrigin(m_pParent->GetMapMode().GetOrigin());
1749 : :
1750 : 0 : const Point aPosY(m_pParent->PixelToLogic(_aThumbPos,aMapMode));
1751 : :
1752 : 0 : aMapMode.SetOrigin( Point(aOld.X() , - aPosY.Y()));
1753 : 0 : SetMapMode( aMapMode );
1754 : 0 : Scroll(0, -( aOld.Y() + aPosY.Y()),SCROLL_CHILDREN);
1755 : : }
1756 : :
1757 : 0 : TSectionsMap::iterator aIter = m_aSections.begin();
1758 : 0 : TSectionsMap::iterator aEnd = m_aSections.end();
1759 : 0 : for (;aIter != aEnd ; ++aIter)
1760 : : {
1761 : 0 : (*aIter)->scrollChildren(aPos.X());
1762 : : }
1763 : 0 : }
1764 : : // -----------------------------------------------------------------------------
1765 : 0 : void OViewsWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
1766 : : {
1767 : 0 : TSectionsMap::const_iterator aIter = m_aSections.begin();
1768 : 0 : TSectionsMap::const_iterator aEnd = m_aSections.end();
1769 : 0 : for(;aIter != aEnd; ++aIter)
1770 : : {
1771 : 0 : (*aIter)->getReportSection().fillControlModelSelection(_rSelection);
1772 : : }
1773 : 0 : }
1774 : : //==============================================================================
1775 : 0 : } // rptui
1776 : : //==============================================================================
1777 : :
1778 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|