bump product version to 4.1.6.2
[LibreOffice.git] / reportdesign / source / ui / report / ViewsWindow.cxx
blobd7277b84babe79ebaaaf9620148266388cbceb20
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ViewsWindow.hxx"
21 #include "ScrollHelper.hxx"
22 #include "UndoActions.hxx"
23 #include "ReportWindow.hxx"
24 #include "DesignView.hxx"
25 #include <svtools/colorcfg.hxx>
26 #include "ReportController.hxx"
27 #include "UITools.hxx"
28 #include "RptDef.hxx"
29 #include "RptResId.hrc"
30 #include "SectionView.hxx"
31 #include "ReportSection.hxx"
32 #include "uistrings.hrc"
33 #include "rptui_slotid.hrc"
34 #include "dlgedclip.hxx"
35 #include "ColorChanger.hxx"
36 #include "RptObject.hxx"
37 #include "ModuleHelper.hxx"
38 #include "EndMarker.hxx"
39 #include <svx/svdpagv.hxx>
40 #include <svx/unoshape.hxx>
41 #include <vcl/svapp.hxx>
42 #include <boost/bind.hpp>
44 #include "helpids.hrc"
45 #include <svx/svdundo.hxx>
46 #include <toolkit/helper/convert.hxx>
47 #include <algorithm>
48 #include <numeric>
49 #include <o3tl/compat_functional.hxx>
51 namespace rptui
53 #define DEFAUL_MOVE_SIZE 100
55 using namespace ::com::sun::star;
56 using namespace ::comphelper;
57 // -----------------------------------------------------------------------------
58 bool lcl_getNewRectSize(const Rectangle& _aObjRect,long& _nXMov, long& _nYMov,SdrObject* _pObj,SdrView* _pView,sal_Int32 _nControlModification, bool _bBoundRects)
60 bool bMoveAllowed = _nXMov != 0 || _nYMov != 0;
61 if ( bMoveAllowed )
63 Rectangle aNewRect = _aObjRect;
64 SdrObject* pOverlappedObj = NULL;
67 aNewRect = _aObjRect;
68 switch(_nControlModification)
70 case ControlModification::HEIGHT_GREATEST:
71 case ControlModification::WIDTH_GREATEST:
72 aNewRect.setWidth(_nXMov);
73 aNewRect.setHeight(_nYMov);
74 break;
75 default:
76 aNewRect.Move(_nXMov,_nYMov);
77 break;
79 if (dynamic_cast<OUnoObject*>(_pObj) != NULL || dynamic_cast<OOle2Obj*>(_pObj) != NULL)
81 pOverlappedObj = isOver(aNewRect,*_pObj->GetPage(),*_pView,true,_pObj);
82 if ( pOverlappedObj && _pObj != pOverlappedObj )
84 Rectangle aOverlappingRect = (_bBoundRects ? pOverlappedObj->GetCurrentBoundRect() : pOverlappedObj->GetSnapRect());
85 sal_Int32 nXTemp = _nXMov;
86 sal_Int32 nYTemp = _nYMov;
87 switch(_nControlModification)
89 case ControlModification::LEFT:
90 nXTemp += aOverlappingRect.Right() - aNewRect.Left();
91 bMoveAllowed = _nXMov != nXTemp;
92 break;
93 case ControlModification::RIGHT:
94 nXTemp += aOverlappingRect.Left() - aNewRect.Right();
95 bMoveAllowed = _nXMov != nXTemp;
96 break;
97 case ControlModification::TOP:
98 nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
99 bMoveAllowed = _nYMov != nYTemp;
100 break;
101 case ControlModification::BOTTOM:
102 nYTemp += aOverlappingRect.Top() - aNewRect.Bottom();
103 bMoveAllowed = _nYMov != nYTemp;
104 break;
105 case ControlModification::CENTER_HORIZONTAL:
106 if ( _aObjRect.Left() < aOverlappingRect.Left() )
107 nXTemp += aOverlappingRect.Left() - aNewRect.Left() - aNewRect.getWidth();
108 else
109 nXTemp += aOverlappingRect.Right() - aNewRect.Left();
110 bMoveAllowed = _nXMov != nXTemp;
111 break;
112 case ControlModification::CENTER_VERTICAL:
113 if ( _aObjRect.Top() < aOverlappingRect.Top() )
114 nYTemp += aOverlappingRect.Top() - aNewRect.Top() - aNewRect.getHeight();
115 else
116 nYTemp += aOverlappingRect.Bottom() - aNewRect.Top();
117 bMoveAllowed = _nYMov != nYTemp;
118 break;
119 case ControlModification::HEIGHT_GREATEST:
120 case ControlModification::WIDTH_GREATEST:
122 Rectangle aIntersectionRect = aNewRect.GetIntersection(aOverlappingRect);
123 if ( !aIntersectionRect.IsEmpty() )
125 if ( _nControlModification == ControlModification::WIDTH_GREATEST )
127 if ( aNewRect.Left() < aIntersectionRect.Left() )
129 aNewRect.Right() = aIntersectionRect.Left();
131 else if ( aNewRect.Left() < aIntersectionRect.Right() )
133 aNewRect.Left() = aIntersectionRect.Right();
136 else if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
138 if ( aNewRect.Top() < aIntersectionRect.Top() )
140 aNewRect.Bottom() = aIntersectionRect.Top();
142 else if ( aNewRect.Top() < aIntersectionRect.Bottom() )
144 aNewRect.Top() = aIntersectionRect.Bottom();
147 nYTemp = aNewRect.getHeight();
148 bMoveAllowed = _nYMov != nYTemp;
149 nXTemp = aNewRect.getWidth();
150 bMoveAllowed = bMoveAllowed && _nXMov != nXTemp;
153 break;
154 default:
155 break;
158 _nXMov = nXTemp;
159 _nYMov = nYTemp;
161 else
162 pOverlappedObj = NULL;
165 while ( pOverlappedObj && bMoveAllowed );
167 return bMoveAllowed;
169 // -----------------------------------------------------------------------------
171 DBG_NAME( rpt_OViewsWindow );
172 OViewsWindow::OViewsWindow( OReportWindow* _pReportWindow)
173 : Window( _pReportWindow,WB_DIALOGCONTROL)
174 ,m_pParent(_pReportWindow)
175 ,m_bInUnmark(sal_False)
177 DBG_CTOR( rpt_OViewsWindow,NULL);
178 SetPaintTransparent(sal_True);
179 SetUniqueId(UID_RPT_VIEWSWINDOW);
180 SetMapMode( MapMode( MAP_100TH_MM ) );
181 m_aColorConfig.AddListener(this);
182 ImplInitSettings();
184 // -----------------------------------------------------------------------------
185 OViewsWindow::~OViewsWindow()
187 m_aColorConfig.RemoveListener(this);
188 m_aSections.clear();
190 DBG_DTOR( rpt_OViewsWindow,NULL);
192 // -----------------------------------------------------------------------------
193 void OViewsWindow::initialize()
197 // -----------------------------------------------------------------------------
198 void OViewsWindow::impl_resizeSectionWindow(OSectionWindow& _rSectionWindow,Point& _rStartPoint,bool _bSet)
200 const uno::Reference< report::XSection> xSection = _rSectionWindow.getReportSection().getSection();
202 Size aSectionSize = _rSectionWindow.LogicToPixel( Size( 0,xSection->getHeight() ) );
203 aSectionSize.Width() = getView()->GetTotalWidth();
205 const sal_Int32 nMinHeight = _rSectionWindow.getStartMarker().getMinHeight();
206 if ( _rSectionWindow.getStartMarker().isCollapsed() || nMinHeight > aSectionSize.Height() )
208 aSectionSize.Height() = nMinHeight;
210 const StyleSettings& rSettings = GetSettings().GetStyleSettings();
211 aSectionSize.Height() += (long)(rSettings.GetSplitSize() * (double)_rSectionWindow.GetMapMode().GetScaleY());
213 if ( _bSet )
214 _rSectionWindow.SetPosSizePixel(_rStartPoint,aSectionSize);
216 _rStartPoint.Y() += aSectionSize.Height();
219 // -----------------------------------------------------------------------------
220 void OViewsWindow::resize(const OSectionWindow& _rSectionWindow)
222 bool bSet = false;
223 Point aStartPoint;
224 TSectionsMap::iterator aIter = m_aSections.begin();
225 TSectionsMap::iterator aEnd = m_aSections.end();
226 for (;aIter != aEnd ; ++aIter)
228 const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
229 if ( pSectionWindow.get() == &_rSectionWindow )
231 aStartPoint = pSectionWindow->GetPosPixel();
232 bSet = true;
235 if ( bSet )
237 impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,bSet);
238 static sal_Int32 nIn = INVALIDATE_UPDATE | INVALIDATE_TRANSPARENT;
239 pSectionWindow->getStartMarker().Invalidate( nIn ); // INVALIDATE_NOERASE |INVALIDATE_NOCHILDREN| INVALIDATE_TRANSPARENT
240 pSectionWindow->getEndMarker().Invalidate( nIn );
243 m_pParent->notifySizeChanged();
245 //------------------------------------------------------------------------------
246 void OViewsWindow::Resize()
248 Window::Resize();
249 if ( !m_aSections.empty() )
251 const Point aOffset(m_pParent->getThumbPos());
252 Point aStartPoint(0,-aOffset.Y());
253 TSectionsMap::iterator aIter = m_aSections.begin();
254 TSectionsMap::iterator aEnd = m_aSections.end();
255 for (;aIter != aEnd ; ++aIter)
257 const ::boost::shared_ptr<OSectionWindow> pSectionWindow = (*aIter);
258 impl_resizeSectionWindow(*pSectionWindow.get(),aStartPoint,true);
262 // -----------------------------------------------------------------------------
263 void OViewsWindow::Paint( const Rectangle& rRect )
265 Window::Paint( rRect );
267 Size aOut = GetOutputSizePixel();
268 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
269 aStartWidth *= GetMapMode().GetScaleX();
271 aOut.Width() -= (long)aStartWidth;
272 aOut = PixelToLogic(aOut);
274 Rectangle aRect(PixelToLogic(Point(aStartWidth,0)),aOut);
275 Wallpaper aWall( m_aColorConfig.GetColorValue(::svtools::APPBACKGROUND).nColor );
276 DrawWallpaper(aRect,aWall);
278 //------------------------------------------------------------------------------
279 void OViewsWindow::ImplInitSettings()
281 EnableChildTransparentMode( sal_True );
282 SetBackground( );
283 SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
284 SetTextFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
286 //-----------------------------------------------------------------------------
287 void OViewsWindow::DataChanged( const DataChangedEvent& rDCEvt )
289 Window::DataChanged( rDCEvt );
291 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
292 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
294 ImplInitSettings();
295 Invalidate();
298 //----------------------------------------------------------------------------
299 void OViewsWindow::addSection(const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry,sal_uInt16 _nPosition)
301 ::boost::shared_ptr<OSectionWindow> pSectionWindow( new OSectionWindow(this,_xSection,_sColorEntry) );
302 m_aSections.insert(getIteratorAtPos(_nPosition) , TSectionsMap::value_type(pSectionWindow));
303 m_pParent->setMarked(&pSectionWindow->getReportSection().getSectionView(),m_aSections.size() == 1);
304 Resize();
306 //----------------------------------------------------------------------------
307 void OViewsWindow::removeSection(sal_uInt16 _nPosition)
309 if ( _nPosition < m_aSections.size() )
311 TSectionsMap::iterator aPos = getIteratorAtPos(_nPosition);
312 TSectionsMap::iterator aNew = getIteratorAtPos(_nPosition == 0 ? _nPosition+1: _nPosition - 1);
314 m_pParent->getReportView()->UpdatePropertyBrowserDelayed((*aNew)->getReportSection().getSectionView());
316 m_aSections.erase(aPos);
317 Resize();
320 //------------------------------------------------------------------------------
321 void OViewsWindow::toggleGrid(sal_Bool _bVisible)
323 ::std::for_each(m_aSections.begin(),m_aSections.end(),
324 ::o3tl::compose1(::boost::bind(&OReportSection::SetGridVisible,_1,_bVisible),TReportPairHelper()));
325 ::std::for_each(m_aSections.begin(),m_aSections.end(),
326 ::o3tl::compose1(::boost::bind(&OReportSection::Window::Invalidate,_1,INVALIDATE_NOERASE),TReportPairHelper()));
328 //------------------------------------------------------------------------------
329 sal_Int32 OViewsWindow::getTotalHeight() const
331 sal_Int32 nHeight = 0;
332 TSectionsMap::const_iterator aIter = m_aSections.begin();
333 TSectionsMap::const_iterator aEnd = m_aSections.end();
334 for (;aIter != aEnd ; ++aIter)
336 nHeight += (*aIter)->GetSizePixel().Height();
338 return nHeight;
340 //----------------------------------------------------------------------------
341 sal_uInt16 OViewsWindow::getSectionCount() const
343 return static_cast<sal_uInt16>(m_aSections.size());
345 //----------------------------------------------------------------------------
346 void OViewsWindow::SetInsertObj( sal_uInt16 eObj,const OUString& _sShapeType )
348 TSectionsMap::iterator aIter = m_aSections.begin();
349 TSectionsMap::iterator aEnd = m_aSections.end();
350 for (;aIter != aEnd ; ++aIter)
351 (*aIter)->getReportSection().getSectionView().SetCurrentObj( eObj, ReportInventor );
353 m_sShapeType = _sShapeType;
355 //----------------------------------------------------------------------------
356 OUString OViewsWindow::GetInsertObjString() const
358 return m_sShapeType;
361 //------------------------------------------------------------------------------
362 void OViewsWindow::SetMode( DlgEdMode eNewMode )
364 ::std::for_each(m_aSections.begin(),m_aSections.end(),
365 ::o3tl::compose1(::boost::bind(&OReportSection::SetMode,_1,eNewMode),TReportPairHelper()));
367 //----------------------------------------------------------------------------
368 sal_Bool OViewsWindow::HasSelection() const
370 TSectionsMap::const_iterator aIter = m_aSections.begin();
371 TSectionsMap::const_iterator aEnd = m_aSections.end();
372 for (;aIter != aEnd && !(*aIter)->getReportSection().getSectionView().AreObjectsMarked(); ++aIter)
374 return aIter != aEnd;
376 //----------------------------------------------------------------------------
377 void OViewsWindow::Delete()
379 m_bInUnmark = sal_True;
380 ::std::for_each(m_aSections.begin(),m_aSections.end(),
381 ::o3tl::compose1(::boost::mem_fn(&OReportSection::Delete),TReportPairHelper()));
382 m_bInUnmark = sal_False;
384 //----------------------------------------------------------------------------
385 void OViewsWindow::Copy()
387 uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
388 ::std::for_each(m_aSections.begin(),m_aSections.end(),
389 ::o3tl::compose1(::boost::bind(&OReportSection::Copy,_1,::boost::ref(aAllreadyCopiedObjects)),TReportPairHelper()));
391 OReportExchange* pCopy = new OReportExchange(aAllreadyCopiedObjects);
392 uno::Reference< datatransfer::XTransferable> aEnsureDelete = pCopy;
393 pCopy->CopyToClipboard(this);
395 //----------------------------------------------------------------------------
396 void OViewsWindow::Paste()
398 TransferableDataHelper aTransferData(TransferableDataHelper::CreateFromSystemClipboard(this));
399 OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aTransferData);
400 if ( aCopies.getLength() > 1 )
401 ::std::for_each(m_aSections.begin(),m_aSections.end(),
402 ::o3tl::compose1(::boost::bind(&OReportSection::Paste,_1,aCopies,false),TReportPairHelper()));
403 else
405 ::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
406 if ( pMarkedSection )
407 pMarkedSection->getReportSection().Paste(aCopies,true);
410 // ---------------------------------------------------------------------------
411 ::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const uno::Reference< report::XSection>& _xSection) const
413 OSL_ENSURE(_xSection.is(),"Section is NULL!");
415 ::boost::shared_ptr<OSectionWindow> pSectionWindow;
416 TSectionsMap::const_iterator aIter = m_aSections.begin();
417 TSectionsMap::const_iterator aEnd = m_aSections.end();
418 for (; aIter != aEnd ; ++aIter)
420 if ((*aIter)->getReportSection().getSection() == _xSection)
422 pSectionWindow = (*aIter);
423 break;
427 return pSectionWindow;
430 //----------------------------------------------------------------------------
431 ::boost::shared_ptr<OSectionWindow> OViewsWindow::getMarkedSection(NearSectionAccess nsa) const
433 ::boost::shared_ptr<OSectionWindow> pRet;
434 TSectionsMap::const_iterator aIter = m_aSections.begin();
435 TSectionsMap::const_iterator aEnd = m_aSections.end();
436 sal_uInt32 nCurrentPosition = 0;
437 for (; aIter != aEnd ; ++aIter)
439 if ( (*aIter)->getStartMarker().isMarked() )
441 if (nsa == CURRENT)
443 pRet = (*aIter);
444 break;
446 else if ( nsa == PREVIOUS )
448 if (nCurrentPosition > 0)
450 pRet = (*(--aIter));
451 if (pRet == NULL)
453 pRet = (*m_aSections.begin());
456 else
458 // if we are out of bounds return the first one
459 pRet = (*m_aSections.begin());
461 break;
463 else if ( nsa == POST )
465 sal_uInt32 nSize = m_aSections.size();
466 if ((nCurrentPosition + 1) < nSize)
468 pRet = *(++aIter);
469 if (pRet == NULL)
471 pRet = (*(--aEnd));
474 else
476 // if we are out of bounds return the last one
477 pRet = (*(--aEnd));
479 break;
482 ++nCurrentPosition;
485 return pRet;
487 // -------------------------------------------------------------------------
488 void OViewsWindow::markSection(const sal_uInt16 _nPos)
490 if ( _nPos < m_aSections.size() )
491 m_pParent->setMarked(m_aSections[_nPos]->getReportSection().getSection(),sal_True);
493 //----------------------------------------------------------------------------
494 sal_Bool OViewsWindow::IsPasteAllowed() const
496 TransferableDataHelper aTransferData( TransferableDataHelper::CreateFromSystemClipboard( const_cast< OViewsWindow* >( this ) ) );
497 return aTransferData.HasFormat(OReportExchange::getDescriptorFormatId());
499 //-----------------------------------------------------------------------------
500 void OViewsWindow::SelectAll(const sal_uInt16 _nObjectType)
502 m_bInUnmark = sal_True;
503 ::std::for_each(m_aSections.begin(),m_aSections.end(),
504 ::o3tl::compose1(::boost::bind(::boost::mem_fn(&OReportSection::SelectAll),_1,_nObjectType),TReportPairHelper()));
505 m_bInUnmark = sal_False;
507 //-----------------------------------------------------------------------------
508 void OViewsWindow::unmarkAllObjects(OSectionView* _pSectionView)
510 if ( !m_bInUnmark )
512 m_bInUnmark = sal_True;
513 TSectionsMap::iterator aIter = m_aSections.begin();
514 TSectionsMap::iterator aEnd = m_aSections.end();
515 for (; aIter != aEnd ; ++aIter)
517 if ( &(*aIter)->getReportSection().getSectionView() != _pSectionView )
519 (*aIter)->getReportSection().deactivateOle();
520 (*aIter)->getReportSection().getSectionView().UnmarkAllObj();
523 m_bInUnmark = sal_False;
526 // -----------------------------------------------------------------------
527 void OViewsWindow::ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32)
529 ImplInitSettings();
530 Invalidate();
532 // -----------------------------------------------------------------------------
533 void OViewsWindow::MouseButtonDown( const MouseEvent& rMEvt )
535 if ( rMEvt.IsLeft() )
537 GrabFocus();
538 const uno::Sequence< beans::PropertyValue> aArgs;
539 getView()->getReportView()->getController().executeChecked(SID_SELECT_REPORT,aArgs);
541 Window::MouseButtonDown(rMEvt);
543 //----------------------------------------------------------------------------
544 void OViewsWindow::showRuler(sal_Bool _bShow)
546 ::std::for_each(m_aSections.begin(),m_aSections.end(),
547 ::o3tl::compose1(::boost::bind(&OStartMarker::showRuler,_1,_bShow),TStartMarkerHelper()));
548 ::std::for_each(m_aSections.begin(),m_aSections.end(),
549 ::o3tl::compose1(::boost::bind(&OStartMarker::Window::Invalidate, _1, sal_uInt16(INVALIDATE_NOERASE)), TStartMarkerHelper()));
551 //----------------------------------------------------------------------------
552 void OViewsWindow::MouseButtonUp( const MouseEvent& rMEvt )
554 if ( rMEvt.IsLeft() )
556 TSectionsMap::iterator aIter = m_aSections.begin();
557 TSectionsMap::iterator aEnd = m_aSections.end();
558 for (;aIter != aEnd ; ++aIter)
560 if ( (*aIter)->getReportSection().getSectionView().AreObjectsMarked() )
562 (*aIter)->getReportSection().MouseButtonUp(rMEvt);
563 break;
567 // remove special insert mode
568 for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
570 (*aIter)->getReportSection().getPage()->resetSpecialMode();
574 //------------------------------------------------------------------------------
575 sal_Bool OViewsWindow::handleKeyEvent(const KeyEvent& _rEvent)
577 sal_Bool bRet = sal_False;
578 TSectionsMap::iterator aIter = m_aSections.begin();
579 TSectionsMap::iterator aEnd = m_aSections.end();
580 for (;aIter != aEnd ; ++aIter)
582 if ( (*aIter)->getStartMarker().isMarked() )
584 bRet = (*aIter)->getReportSection().handleKeyEvent(_rEvent);
587 return bRet;
589 //----------------------------------------------------------------------------
590 OViewsWindow::TSectionsMap::iterator OViewsWindow::getIteratorAtPos(sal_uInt16 _nPos)
592 TSectionsMap::iterator aRet = m_aSections.end();
593 if ( _nPos < m_aSections.size() )
594 aRet = m_aSections.begin() + _nPos;
595 return aRet;
597 //------------------------------------------------------------------------
598 void OViewsWindow::setMarked(OSectionView* _pSectionView,sal_Bool _bMark)
600 OSL_ENSURE(_pSectionView != NULL,"SectionView is NULL!");
601 if ( _pSectionView )
602 setMarked(_pSectionView->getReportSection()->getSection(),_bMark);
604 //------------------------------------------------------------------------
605 void OViewsWindow::setMarked(const uno::Reference< report::XSection>& _xSection,sal_Bool _bMark)
607 TSectionsMap::iterator aIter = m_aSections.begin();
608 TSectionsMap::iterator aEnd = m_aSections.end();
609 for (; aIter != aEnd ; ++aIter)
611 if ( (*aIter)->getReportSection().getSection() != _xSection )
613 (*aIter)->setMarked(sal_False);
615 else if ( (*aIter)->getStartMarker().isMarked() != _bMark )
617 (*aIter)->setMarked(_bMark);
621 //------------------------------------------------------------------------
622 void OViewsWindow::setMarked(const uno::Sequence< uno::Reference< report::XReportComponent> >& _aShapes,sal_Bool _bMark)
624 bool bFirst = true;
625 const uno::Reference< report::XReportComponent>* pIter = _aShapes.getConstArray();
626 const uno::Reference< report::XReportComponent>* pEnd = pIter + _aShapes.getLength();
627 for(;pIter != pEnd;++pIter)
629 const uno::Reference< report::XSection> xSection = (*pIter)->getSection();
630 if ( xSection.is() )
632 if ( bFirst )
634 bFirst = false;
635 m_pParent->setMarked(xSection,_bMark);
637 ::boost::shared_ptr<OSectionWindow> pSectionWindow = getSectionWindow(xSection);
638 if ( pSectionWindow )
640 SvxShape* pShape = SvxShape::getImplementation( *pIter );
641 SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
642 OSL_ENSURE( pObject, "OViewsWindow::setMarked: no SdrObject for the shape!" );
643 if ( pObject )
644 pSectionWindow->getReportSection().getSectionView().MarkObj( pObject, pSectionWindow->getReportSection().getSectionView().GetSdrPageView(), !_bMark );
649 // -----------------------------------------------------------------------------
650 void OViewsWindow::collectRectangles(TRectangleMap& _rSortRectangles, bool _bBoundRects)
652 TSectionsMap::iterator aIter = m_aSections.begin();
653 TSectionsMap::iterator aEnd = m_aSections.end();
654 for (aIter = m_aSections.begin();aIter != aEnd ; ++aIter)
656 OSectionView& rView = (*aIter)->getReportSection().getSectionView();
657 if ( rView.AreObjectsMarked() )
659 rView.SortMarkedObjects();
660 const sal_uInt32 nCount = rView.GetMarkedObjectCount();
661 for (sal_uInt32 i=0; i < nCount; ++i)
663 const SdrMark* pM = rView.GetSdrMarkByIndex(i);
664 SdrObject* pObj = pM->GetMarkedSdrObj();
665 Rectangle aObjRect(_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
666 _rSortRectangles.insert(TRectangleMap::value_type(aObjRect,TRectangleMap::mapped_type(pObj,&rView)));
671 // -----------------------------------------------------------------------------
672 void OViewsWindow::collectBoundResizeRect(const TRectangleMap& _rSortRectangles,sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects,Rectangle& _rBound,Rectangle& _rResize)
674 bool bOnlyOnce = false;
675 TRectangleMap::const_iterator aRectIter = _rSortRectangles.begin();
676 TRectangleMap::const_iterator aRectEnd = _rSortRectangles.end();
677 for (;aRectIter != aRectEnd ; ++aRectIter)
679 Rectangle aObjRect = aRectIter->first;
680 if ( _rResize.IsEmpty() )
681 _rResize = aObjRect;
682 switch(_nControlModification)
684 case ControlModification::WIDTH_SMALLEST:
685 if ( _rResize.getWidth() > aObjRect.getWidth() )
686 _rResize = aObjRect;
687 break;
688 case ControlModification::HEIGHT_SMALLEST:
689 if ( _rResize.getHeight() > aObjRect.getHeight() )
690 _rResize = aObjRect;
691 break;
692 case ControlModification::WIDTH_GREATEST:
693 if ( _rResize.getWidth() < aObjRect.getWidth() )
694 _rResize = aObjRect;
695 break;
696 case ControlModification::HEIGHT_GREATEST:
697 if ( _rResize.getHeight() < aObjRect.getHeight() )
698 _rResize = aObjRect;
699 break;
702 SdrObjTransformInfoRec aInfo;
703 const SdrObject* pObj = aRectIter->second.first;
704 pObj->TakeObjInfo(aInfo);
705 sal_Bool bHasFixed = !aInfo.bMoveAllowed || pObj->IsMoveProtect();
706 if ( bHasFixed )
707 _rBound.Union(aObjRect);
708 else
710 if ( _bAlignAtSection || _rSortRectangles.size() == 1 )
711 { // einzelnes Obj an der Seite ausrichten
712 if ( ! bOnlyOnce )
714 bOnlyOnce = true;
715 OReportSection* pReportSection = aRectIter->second.second->getReportSection();
716 const uno::Reference< report::XSection> xSection = pReportSection->getSection();
719 uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
720 _rBound.Union(Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
721 getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
722 xSection->getHeight()));
724 catch(const uno::Exception &){}
727 else
729 if (_bBoundRects)
730 _rBound.Union(aRectIter->second.second->GetMarkedObjBoundRect());
731 else
732 _rBound.Union(aRectIter->second.second->GetMarkedObjRect());
737 // -----------------------------------------------------------------------------
738 void OViewsWindow::alignMarkedObjects(sal_Int32 _nControlModification,bool _bAlignAtSection, bool _bBoundRects)
740 if ( _nControlModification == ControlModification::NONE )
741 return;
743 Point aRefPoint;
744 RectangleLess::CompareMode eCompareMode = RectangleLess::POS_LEFT;
745 switch (_nControlModification)
747 case ControlModification::TOP : eCompareMode = RectangleLess::POS_UPPER; break;
748 case ControlModification::BOTTOM: eCompareMode = RectangleLess::POS_DOWN; break;
749 case ControlModification::LEFT : eCompareMode = RectangleLess::POS_LEFT; break;
750 case ControlModification::RIGHT : eCompareMode = RectangleLess::POS_RIGHT; break;
751 case ControlModification::CENTER_HORIZONTAL :
752 case ControlModification::CENTER_VERTICAL :
754 eCompareMode = (ControlModification::CENTER_VERTICAL == _nControlModification) ? RectangleLess::POS_CENTER_VERTICAL : RectangleLess::POS_CENTER_HORIZONTAL;
755 uno::Reference<report::XSection> xSection = (*m_aSections.begin())->getReportSection().getSection();
756 uno::Reference<report::XReportDefinition> xReportDefinition = xSection->getReportDefinition();
757 aRefPoint = Rectangle(getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN),0,
758 getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width - getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN),
759 xSection->getHeight()).Center();
761 break;
762 default: break;
764 RectangleLess aCompare(eCompareMode,aRefPoint);
765 TRectangleMap aSortRectangles(aCompare);
766 collectRectangles(aSortRectangles,_bBoundRects);
768 Rectangle aBound;
769 Rectangle aResize;
770 collectBoundResizeRect(aSortRectangles,_nControlModification,_bAlignAtSection,_bBoundRects,aBound,aResize);
772 bool bMove = true;
774 ::std::mem_fun_t<long&,Rectangle> aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
775 ::std::mem_fun_t<long&,Rectangle> aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
776 TRectangleMap::iterator aRectIter = aSortRectangles.begin();
777 TRectangleMap::iterator aRectEnd = aSortRectangles.end();
778 for (;aRectIter != aRectEnd ; ++aRectIter)
780 Rectangle aObjRect = aRectIter->first;
781 SdrObject* pObj = aRectIter->second.first;
782 SdrView* pView = aRectIter->second.second;
783 Point aCenter(aBound.Center());
784 SdrObjTransformInfoRec aInfo;
785 pObj->TakeObjInfo(aInfo);
786 if (aInfo.bMoveAllowed && !pObj->IsMoveProtect())
788 long nXMov = 0;
789 long nYMov = 0;
790 long* pValue = &nXMov;
791 switch(_nControlModification)
793 case ControlModification::TOP :
794 aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Top);
795 aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Bottom);
796 pValue = &nYMov;
797 break;
798 case ControlModification::BOTTOM:
799 // defaults are already set
800 pValue = &nYMov;
801 break;
802 case ControlModification::CENTER_VERTICAL:
803 nYMov = aCenter.Y() - aObjRect.Center().Y();
804 pValue = &nYMov;
805 bMove = false;
806 break;
807 case ControlModification::RIGHT :
808 aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
809 aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
810 break;
811 case ControlModification::CENTER_HORIZONTAL:
812 nXMov = aCenter.X() - aObjRect.Center().X();
813 bMove = false;
814 break;
815 case ControlModification::LEFT :
816 aGetFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Left);
817 aRefFun = ::std::mem_fun<long&,Rectangle>(&Rectangle::Right);
818 break;
819 default:
820 bMove = false;
821 break;
823 if ( bMove )
825 Rectangle aTest = aObjRect;
826 aGetFun(&aTest) = aGetFun(&aBound);
827 TRectangleMap::iterator aInterSectRectIter = aSortRectangles.begin();
828 for (; aInterSectRectIter != aRectIter; ++aInterSectRectIter)
830 if ( pView == aInterSectRectIter->second.second && (dynamic_cast<OUnoObject*>(aInterSectRectIter->second.first) || dynamic_cast<OOle2Obj*>(aInterSectRectIter->second.first)))
832 SdrObject* pPreviousObj = aInterSectRectIter->second.first;
833 Rectangle aIntersectRect = aTest.GetIntersection(_bBoundRects ? pPreviousObj->GetCurrentBoundRect() : pPreviousObj->GetSnapRect());
834 if ( !aIntersectRect.IsEmpty() && (aIntersectRect.Left() != aIntersectRect.Right() && aIntersectRect.Top() != aIntersectRect.Bottom() ) )
836 *pValue = aRefFun(&aIntersectRect) - aGetFun(&aObjRect);
837 break;
841 if ( aInterSectRectIter == aRectIter )
842 *pValue = aGetFun(&aBound) - aGetFun(&aObjRect);
845 if ( lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects) )
847 const Size aSize(nXMov,nYMov);
848 pView->AddUndo(pView->GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*pObj,aSize));
849 pObj->Move(aSize);
850 aObjRect = (_bBoundRects ? pObj->GetCurrentBoundRect() : pObj->GetSnapRect());
853 // resizing control
854 if ( !aResize.IsEmpty() && aObjRect != aResize )
856 nXMov = aResize.getWidth();
857 nYMov = aResize.getHeight();
858 switch(_nControlModification)
860 case ControlModification::WIDTH_GREATEST:
861 case ControlModification::HEIGHT_GREATEST:
862 if ( _nControlModification == ControlModification::HEIGHT_GREATEST )
863 nXMov = aObjRect.getWidth();
864 else if ( _nControlModification == ControlModification::WIDTH_GREATEST )
865 nYMov = aObjRect.getHeight();
866 lcl_getNewRectSize(aObjRect,nXMov,nYMov,pObj,pView,_nControlModification,_bBoundRects);
867 // run through
868 case ControlModification::WIDTH_SMALLEST:
869 case ControlModification::HEIGHT_SMALLEST:
870 pView->AddUndo( pView->GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*pObj));
872 OObjectBase* pObjBase = dynamic_cast<OObjectBase*>(pObj);
873 OSL_ENSURE(pObjBase,"Where comes this object from?");
874 if ( pObjBase )
876 if ( _nControlModification == ControlModification::WIDTH_SMALLEST || _nControlModification == ControlModification::WIDTH_GREATEST )
877 pObjBase->getReportComponent()->setSize(awt::Size(nXMov,aObjRect.getHeight()));
878 else if ( _nControlModification == ControlModification::HEIGHT_GREATEST || _nControlModification == ControlModification::HEIGHT_SMALLEST )
879 pObjBase->getReportComponent()->setSize(awt::Size(aObjRect.getWidth(),nYMov));
882 break;
883 default:
884 break;
888 pView->AdjustMarkHdl();
891 // -----------------------------------------------------------------------------
892 void OViewsWindow::createDefault()
894 ::boost::shared_ptr<OSectionWindow> pMarkedSection = getMarkedSection();
895 if ( pMarkedSection )
896 pMarkedSection->getReportSection().createDefault(m_sShapeType);
898 // -----------------------------------------------------------------------------
899 void OViewsWindow::setGridSnap(sal_Bool bOn)
901 TSectionsMap::iterator aIter = m_aSections.begin();
902 TSectionsMap::iterator aEnd = m_aSections.end();
903 for (; aIter != aEnd ; ++aIter)
905 (*aIter)->getReportSection().getSectionView().SetGridSnap(bOn);
906 static sal_Int32 nIn = 0;
907 (*aIter)->getReportSection().Invalidate(nIn);
910 // -----------------------------------------------------------------------------
911 void OViewsWindow::setDragStripes(sal_Bool bOn)
913 TSectionsMap::iterator aIter = m_aSections.begin();
914 TSectionsMap::iterator aEnd = m_aSections.end();
915 for (; aIter != aEnd ; ++aIter)
916 (*aIter)->getReportSection().getSectionView().SetDragStripes(bOn);
918 // -----------------------------------------------------------------------------
919 sal_uInt16 OViewsWindow::getPosition(const OSectionWindow* _pSectionWindow) const
921 TSectionsMap::const_iterator aIter = m_aSections.begin();
922 TSectionsMap::const_iterator aEnd = m_aSections.end();
923 sal_uInt16 nPosition = 0;
924 for (; aIter != aEnd ; ++aIter)
926 if ( _pSectionWindow == (*aIter).get() )
928 break;
930 ++nPosition;
932 return nPosition;
934 // -----------------------------------------------------------------------------
935 ::boost::shared_ptr<OSectionWindow> OViewsWindow::getSectionWindow(const sal_uInt16 _nPos) const
937 ::boost::shared_ptr<OSectionWindow> aReturn;
939 if ( _nPos < m_aSections.size() )
940 aReturn = m_aSections[_nPos];
942 return aReturn;
944 // -----------------------------------------------------------------------------
945 namespace
947 enum SectionViewAction
949 eEndDragObj,
950 eEndAction,
951 eMoveAction,
952 eMarkAction,
953 eForceToAnotherPage,
954 eBreakAction
956 class ApplySectionViewAction : public ::std::unary_function< OViewsWindow::TSectionsMap::value_type, void >
958 private:
959 SectionViewAction m_eAction;
960 sal_Bool m_bCopy;
961 Point m_aPoint;
963 public:
964 ApplySectionViewAction( sal_Bool _bCopy ) : m_eAction( eEndDragObj ), m_bCopy( _bCopy ) { }
965 ApplySectionViewAction(SectionViewAction _eAction = eEndAction ) : m_eAction( _eAction ) { }
966 ApplySectionViewAction( const Point& _rPoint, SectionViewAction _eAction = eMoveAction ) : m_eAction( _eAction ), m_bCopy( sal_False ), m_aPoint( _rPoint ) { }
968 void operator() ( const OViewsWindow::TSectionsMap::value_type& _rhs )
970 OSectionView& rView( _rhs->getReportSection().getSectionView() );
971 switch ( m_eAction )
973 case eEndDragObj:
974 rView.EndDragObj( m_bCopy );
975 break;
976 case eEndAction:
977 if ( rView.IsAction() )
978 rView.EndAction ( );
979 break;
980 case eMoveAction:
981 rView.MovAction ( m_aPoint );
982 break;
983 case eMarkAction:
984 rView.BegMarkObj ( m_aPoint );
985 break;
986 case eForceToAnotherPage:
987 rView.ForceMarkedToAnotherPage();
988 break;
989 case eBreakAction:
990 if ( rView.IsAction() )
991 rView.BrkAction ( );
992 break;
993 // default:
999 // -----------------------------------------------------------------------------
1000 void OViewsWindow::BrkAction()
1002 EndDragObj_removeInvisibleObjects();
1003 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eBreakAction) );
1005 // -----------------------------------------------------------------------------
1006 void OViewsWindow::BegDragObj_createInvisibleObjectAtPosition(const Rectangle& _aRect, const OSectionView& _rSection)
1008 TSectionsMap::iterator aIter = m_aSections.begin();
1009 TSectionsMap::iterator aEnd = m_aSections.end();
1010 Point aNewPos(0,0);
1012 for (; aIter != aEnd; ++aIter)
1014 OReportSection& rReportSection = (*aIter)->getReportSection();
1015 rReportSection.getPage()->setSpecialMode();
1016 OSectionView& rView = rReportSection.getSectionView();
1018 if ( &rView != &_rSection )
1020 SdrObject *pNewObj = new SdrUnoObj(OUString("com.sun.star.form.component.FixedText"));
1021 if (pNewObj)
1023 pNewObj->SetLogicRect(_aRect);
1025 pNewObj->Move(Size(0, aNewPos.Y()));
1026 sal_Bool bChanged = rView.GetModel()->IsChanged();
1027 rReportSection.getPage()->InsertObject(pNewObj);
1028 rView.GetModel()->SetChanged(bChanged);
1029 m_aBegDragTempList.push_back(pNewObj);
1031 rView.MarkObj( pNewObj, rView.GetSdrPageView() );
1034 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1035 aNewPos.Y() -= nSectionHeight;
1038 // -----------------------------------------------------------------------------
1039 bool OViewsWindow::isObjectInMyTempList(SdrObject *_pObj)
1041 return ::std::find(m_aBegDragTempList.begin(),m_aBegDragTempList.end(),_pObj) != m_aBegDragTempList.end();
1044 // -----------------------------------------------------------------------------
1045 void OViewsWindow::BegDragObj(const Point& _aPnt, SdrHdl* _pHdl,const OSectionView* _pSection)
1047 OSL_TRACE("BegDragObj Clickpoint X:%d Y:%d", _aPnt.X(), _aPnt.Y() );
1049 m_aBegDragTempList.clear();
1051 // Calculate the absolute clickpoint in the views
1052 Point aAbsolutePnt = _aPnt;
1053 TSectionsMap::iterator aIter = m_aSections.begin();
1054 TSectionsMap::iterator aEnd = m_aSections.end();
1055 for (; aIter != aEnd; ++aIter)
1057 OReportSection& rReportSection = (*aIter)->getReportSection();
1058 OSectionView* pView = &rReportSection.getSectionView();
1059 if (pView == _pSection)
1060 break;
1061 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1062 aAbsolutePnt.Y() += nSectionHeight;
1064 m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1065 OSL_TRACE("BegDragObj Absolute X:%d Y:%d", aAbsolutePnt.X(), aAbsolutePnt.Y() );
1067 // Create drag lines over all viewable Views
1068 // Therefore we need to identify the marked objects
1069 // and create temporary objects on all other views at the same position
1070 // relative to its occurrence.
1072 OSL_TRACE("BegDragObj createInvisible Objects" );
1073 int nViewCount = 0;
1074 Point aNewObjPos(0,0);
1075 Point aLeftTop = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1076 for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1078 OReportSection& rReportSection = (*aIter)->getReportSection();
1080 OSectionView& rView = rReportSection.getSectionView();
1082 if ( rView.AreObjectsMarked() )
1084 const sal_uInt32 nCount = rView.GetMarkedObjectCount();
1085 for (sal_uInt32 i=0; i < nCount; ++i)
1087 const SdrMark* pM = rView.GetSdrMarkByIndex(i);
1088 SdrObject* pObj = pM->GetMarkedSdrObj();
1089 if (!isObjectInMyTempList(pObj))
1091 Rectangle aRect( pObj->GetCurrentBoundRect() );
1092 aRect.Move(0, aNewObjPos.Y());
1094 aLeftTop.X() = ::std::min( aRect.Left(), aLeftTop.X() );
1095 aLeftTop.Y() = ::std::min( aRect.Top(), aLeftTop.Y() );
1097 OSL_TRACE("BegDragObj createInvisible X:%d Y:%d on View #%d", aRect.Left(), aRect.Top(), nViewCount );
1099 BegDragObj_createInvisibleObjectAtPosition(aRect, rView);
1103 ++nViewCount;
1104 Rectangle aClipRect = rView.GetWorkArea();
1105 aClipRect.Top() = -aNewObjPos.Y();
1106 rView.SetWorkArea( aClipRect );
1108 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1109 aNewObjPos.Y() += nSectionHeight;
1112 const sal_Int32 nDeltaX = abs(aLeftTop.X() - aAbsolutePnt.X());
1113 const sal_Int32 nDeltaY = abs(aLeftTop.Y() - aAbsolutePnt.Y());
1114 m_aDragDelta.X() = nDeltaX;
1115 m_aDragDelta.Y() = nDeltaY;
1117 Point aNewPos = aAbsolutePnt;
1119 const short nDrgLog = static_cast<short>(PixelToLogic(Size(3,0)).Width());
1120 nViewCount = 0;
1121 for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1123 OReportSection& rReportSection = (*aIter)->getReportSection();
1125 SdrHdl* pHdl = _pHdl;
1126 if ( pHdl )
1128 if ( &rReportSection.getSectionView() != _pSection )
1130 const SdrHdlList& rHdlList = rReportSection.getSectionView().GetHdlList();
1131 pHdl = rHdlList.GetHdl(_pHdl->GetKind());
1134 OSL_TRACE("BegDragObj X:%d Y:%d on View#%d", aNewPos.X(), aNewPos.Y(), nViewCount++ );
1135 rReportSection.getSectionView().BegDragObj(aNewPos, (OutputDevice*)NULL, pHdl, nDrgLog, NULL);
1137 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1138 aNewPos.Y() -= nSectionHeight;
1142 // -----------------------------------------------------------------------------
1143 void OViewsWindow::ForceMarkedToAnotherPage()
1145 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction(eForceToAnotherPage ) );
1147 // -----------------------------------------------------------------------------
1148 void OViewsWindow::BegMarkObj(const Point& _aPnt,const OSectionView* _pSection)
1150 bool bAdd = true;
1151 Point aNewPos = _aPnt;
1153 TSectionsMap::iterator aIter = m_aSections.begin();
1154 TSectionsMap::iterator aEnd = m_aSections.end();
1155 long nLastSectionHeight = 0;
1156 for (; aIter != aEnd; ++aIter)
1158 OReportSection& rReportSection = (*aIter)->getReportSection();
1159 if ( &rReportSection.getSectionView() == _pSection )
1161 bAdd = false;
1162 aNewPos = _aPnt; // 2,2
1164 else if ( bAdd )
1166 const long nSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1167 aNewPos.Y() += nSectionHeight;
1169 else
1171 aNewPos.Y() -= nLastSectionHeight;
1173 rReportSection.getSectionView().BegMarkObj ( aNewPos );
1174 nLastSectionHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1177 // -----------------------------------------------------------------------------
1178 OSectionView* OViewsWindow::getSectionRelativeToPosition(const OSectionView* _pSection,Point& _rPnt)
1180 OSectionView* pSection = NULL;
1181 sal_Int32 nCount = 0;
1182 TSectionsMap::iterator aIter = m_aSections.begin();
1183 const TSectionsMap::iterator aEnd = m_aSections.end();
1184 for (; aIter != aEnd ; ++aIter,++nCount)
1186 OReportSection& rReportSection = (*aIter)->getReportSection();
1187 if ( &rReportSection.getSectionView() == _pSection)
1188 break;
1190 OSL_ENSURE(aIter != aEnd,"This can never happen!");
1191 if ( _rPnt.Y() < 0 )
1193 if ( nCount )
1194 --aIter;
1195 for (; nCount && (_rPnt.Y() < 0); --nCount)
1197 OReportSection& rReportSection = (*aIter)->getReportSection();
1198 const sal_Int32 nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1199 _rPnt.Y() += nHeight;
1200 if ( (nCount -1) > 0 && (_rPnt.Y() < 0) )
1201 --aIter;
1203 if ( nCount == 0 )
1204 pSection = &(*m_aSections.begin())->getReportSection().getSectionView();
1205 else
1206 pSection = &(*aIter)->getReportSection().getSectionView();
1208 else
1210 for (; aIter != aEnd; ++aIter)
1212 OReportSection& rReportSection = (*aIter)->getReportSection();
1213 const long nHeight = rReportSection.PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1214 if ( (_rPnt.Y() - nHeight) < 0 )
1215 break;
1216 _rPnt.Y() -= nHeight;
1218 if ( aIter != aEnd )
1219 pSection = &(*aIter)->getReportSection().getSectionView();
1220 else
1221 pSection = &(*(aEnd-1))->getReportSection().getSectionView();
1224 return pSection;
1226 // -----------------------------------------------------------------------------
1227 void OViewsWindow::EndDragObj_removeInvisibleObjects()
1229 TSectionsMap::iterator aIter = m_aSections.begin();
1230 TSectionsMap::iterator aEnd = m_aSections.end();
1232 for (; aIter != aEnd; ++aIter)
1234 OReportSection& rReportSection = (*aIter)->getReportSection();
1235 rReportSection.getPage()->resetSpecialMode();
1238 // -----------------------------------------------------------------------------
1239 void OViewsWindow::EndDragObj(sal_Bool _bControlKeyPressed, const OSectionView* _pSection,const Point& _aPnt)
1241 const String sUndoAction = String((ModuleRes(RID_STR_UNDO_CHANGEPOSITION)));
1242 const UndoContext aUndoContext( getView()->getReportView()->getController().getUndoManager(), sUndoAction );
1244 Point aNewPos = _aPnt;
1245 OSectionView* pInSection = getSectionRelativeToPosition(_pSection, aNewPos);
1246 if (!_bControlKeyPressed &&
1247 (_pSection && ( _pSection->IsDragResize() == false ) ) && /* Not in resize mode */
1248 _pSection != pInSection)
1250 EndDragObj_removeInvisibleObjects();
1252 // we need to manipulate the current clickpoint, we substract the old delta from BeginDrag
1253 aNewPos -= m_aDragDelta;
1255 uno::Sequence< beans::NamedValue > aAllreadyCopiedObjects;
1256 TSectionsMap::iterator aIter = m_aSections.begin();
1257 const TSectionsMap::iterator aEnd = m_aSections.end();
1258 for (; aIter != aEnd; ++aIter)
1260 OReportSection& rReportSection = (*aIter)->getReportSection();
1261 if ( pInSection != &rReportSection.getSectionView() )
1263 rReportSection.getSectionView().BrkAction();
1264 rReportSection.Copy(aAllreadyCopiedObjects,true);
1266 else
1267 pInSection->EndDragObj(sal_False);
1270 if ( aAllreadyCopiedObjects.getLength() )
1272 beans::NamedValue* pIter = aAllreadyCopiedObjects.getArray();
1273 const beans::NamedValue* pEnd = pIter + aAllreadyCopiedObjects.getLength();
1276 uno::Reference<report::XReportDefinition> xReportDefinition = getView()->getReportView()->getController().getReportDefinition();
1277 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
1278 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
1279 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
1281 if ( aNewPos.X() < nLeftMargin )
1282 aNewPos.X() = nLeftMargin;
1283 if ( aNewPos.Y() < 0 )
1284 aNewPos.Y() = 0;
1286 Point aPrevious;
1287 for (; pIter != pEnd; ++pIter)
1289 uno::Sequence< uno::Reference<report::XReportComponent> > aClones;
1290 pIter->Value >>= aClones;
1291 uno::Reference<report::XReportComponent>* pColIter = aClones.getArray();
1292 const uno::Reference<report::XReportComponent>* pColEnd = pColIter + aClones.getLength();
1294 // move the cloned Components to new positions
1295 for (; pColIter != pColEnd; ++pColIter)
1297 uno::Reference< report::XReportComponent> xRC(*pColIter);
1298 aPrevious = VCLPoint(xRC->getPosition());
1299 awt::Size aSize = xRC->getSize();
1301 if ( aNewPos.X() < nLeftMargin )
1303 aNewPos.X() = nLeftMargin;
1305 else if ( (aNewPos.X() + aSize.Width) > (nPaperWidth - nRightMargin) )
1307 aNewPos.X() = nPaperWidth - nRightMargin - aSize.Width;
1309 if ( aNewPos.Y() < 0 )
1311 aNewPos.Y() = 0;
1313 if ( aNewPos.X() < 0 )
1315 aSize.Width += aNewPos.X();
1316 aNewPos.X()= 0;
1317 xRC->setSize(aSize);
1319 xRC->setPosition(AWTPoint(aNewPos));
1320 if ( (pColIter+1) != pColEnd )
1322 // bring aNewPos to the position of the next object
1323 uno::Reference< report::XReportComponent> xRCNext(*(pColIter + 1),uno::UNO_QUERY);
1324 Point aNextPosition = VCLPoint(xRCNext->getPosition());
1325 aNewPos += (aNextPosition - aPrevious);
1330 catch(uno::Exception&)
1333 pInSection->getReportSection()->Paste(aAllreadyCopiedObjects,true);
1336 else
1338 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction( sal_False ) );
1339 EndDragObj_removeInvisibleObjects();
1341 m_aDragDelta = Point(SAL_MAX_INT32, SAL_MAX_INT32);
1343 // -----------------------------------------------------------------------------
1344 void OViewsWindow::EndAction()
1346 ::std::for_each( m_aSections.begin(), m_aSections.end(), ApplySectionViewAction() );
1348 // -----------------------------------------------------------------------------
1349 void OViewsWindow::MovAction(const Point& _aPnt,const OSectionView* _pSection,bool _bMove, bool _bControlKeySet)
1351 (void)_bMove;
1353 Point aRealMousePos = _aPnt;
1354 Point aCurrentSectionPos;
1355 OSL_TRACE("MovAction X:%d Y:%d", aRealMousePos.X(), aRealMousePos.Y() );
1357 Point aHdlPos;
1358 SdrHdl* pHdl = _pSection->GetDragHdl();
1359 if ( pHdl )
1361 aHdlPos = pHdl->GetPos();
1364 TSectionsMap::iterator aIter;
1365 TSectionsMap::iterator aEnd = m_aSections.end();
1367 for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1369 OReportSection& rReportSection = (*aIter)->getReportSection();
1370 if ( &rReportSection.getSectionView() == _pSection )
1371 break;
1372 const long nSectionHeight = (*aIter)->PixelToLogic(rReportSection.GetOutputSizePixel()).Height();
1373 aCurrentSectionPos.Y() += nSectionHeight;
1375 aRealMousePos += aCurrentSectionPos;
1377 // If control key is pressed the work area is limited to the section with the current selection.
1378 Point aPosForWorkArea(0,0);
1379 for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1381 OReportSection& rReportSection = (*aIter)->getReportSection();
1382 OSectionView& rView = rReportSection.getSectionView();
1383 const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
1385 if (_bControlKeySet)
1387 Rectangle aClipRect = rView.GetWorkArea();
1388 aClipRect.Top() = aCurrentSectionPos.Y() - aPosForWorkArea.Y();
1389 aClipRect.Bottom() = aClipRect.Top() + nSectionHeight;
1390 rView.SetWorkArea( aClipRect );
1392 else
1394 Rectangle aClipRect = rView.GetWorkArea();
1395 aClipRect.Top() = -aPosForWorkArea.Y();
1396 rView.SetWorkArea( aClipRect );
1398 aPosForWorkArea.Y() += nSectionHeight;
1402 for (aIter = m_aSections.begin(); aIter != aEnd; ++aIter)
1404 OReportSection& rReportSection = (*aIter)->getReportSection();
1405 SdrHdl* pCurrentHdl = rReportSection.getSectionView().GetDragHdl();
1406 if ( pCurrentHdl )
1408 if ( aRealMousePos.Y() > 0 )
1409 aRealMousePos = _aPnt + pCurrentHdl->GetPos() - aHdlPos;
1411 rReportSection.getSectionView().MovAction ( aRealMousePos );
1412 const long nSectionHeight = (*aIter)->PixelToLogic((*aIter)->GetOutputSizePixel()).Height();
1413 aRealMousePos.Y() -= nSectionHeight;
1416 // -----------------------------------------------------------------------------
1417 sal_Bool OViewsWindow::IsAction() const
1419 sal_Bool bAction = sal_False;
1420 TSectionsMap::const_iterator aIter = m_aSections.begin();
1421 TSectionsMap::const_iterator aEnd = m_aSections.end();
1422 for (; !bAction && aIter != aEnd; ++aIter)
1423 bAction = (*aIter)->getReportSection().getSectionView().IsAction();
1424 return bAction;
1426 // -----------------------------------------------------------------------------
1427 sal_Bool OViewsWindow::IsDragObj() const
1429 sal_Bool bAction = sal_False;
1430 TSectionsMap::const_iterator aIter = m_aSections.begin();
1431 TSectionsMap::const_iterator aEnd = m_aSections.end();
1432 for (; !bAction && aIter != aEnd; ++aIter)
1433 bAction = (*aIter)->getReportSection().getSectionView().IsAction();
1434 return bAction;
1436 // -----------------------------------------------------------------------------
1437 sal_uInt32 OViewsWindow::getMarkedObjectCount() const
1439 sal_uInt32 nCount = 0;
1440 TSectionsMap::const_iterator aIter = m_aSections.begin();
1441 TSectionsMap::const_iterator aEnd = m_aSections.end();
1442 for (; aIter != aEnd; ++aIter)
1443 nCount += (*aIter)->getReportSection().getSectionView().GetMarkedObjectCount();
1444 return nCount;
1446 // -----------------------------------------------------------------------------
1447 void OViewsWindow::handleKey(const KeyCode& _rCode)
1449 const sal_uInt16 nCode = _rCode.GetCode();
1450 if ( _rCode.IsMod1() )
1452 // scroll page
1453 OScrollWindowHelper* pScrollWindow = getView()->getScrollWindow();
1454 ScrollBar* pScrollBar = ( nCode == KEY_LEFT || nCode == KEY_RIGHT ) ? pScrollWindow->GetHScroll() : pScrollWindow->GetVScroll();
1455 if ( pScrollBar && pScrollBar->IsVisible() )
1456 pScrollBar->DoScrollAction(( nCode == KEY_RIGHT || nCode == KEY_UP ) ? SCROLL_LINEUP : SCROLL_LINEDOWN );
1457 return;
1459 TSectionsMap::const_iterator aIter = m_aSections.begin();
1460 TSectionsMap::const_iterator aEnd = m_aSections.end();
1461 for (; aIter != aEnd; ++aIter)
1463 OReportSection& rReportSection = (*aIter)->getReportSection();
1464 long nX = 0;
1465 long nY = 0;
1467 if ( nCode == KEY_UP )
1468 nY = -1;
1469 else if ( nCode == KEY_DOWN )
1470 nY = 1;
1471 else if ( nCode == KEY_LEFT )
1472 nX = -1;
1473 else if ( nCode == KEY_RIGHT )
1474 nX = 1;
1476 if ( rReportSection.getSectionView().AreObjectsMarked() )
1478 if ( _rCode.IsMod2() )
1480 // move in 1 pixel distance
1481 const Size aPixelSize = rReportSection.PixelToLogic( Size( 1, 1 ) );
1482 nX *= aPixelSize.Width();
1483 nY *= aPixelSize.Height();
1485 else
1487 // move in 1 mm distance
1488 nX *= DEFAUL_MOVE_SIZE;
1489 nY *= DEFAUL_MOVE_SIZE;
1492 OSectionView& rView = rReportSection.getSectionView();
1493 const SdrHdlList& rHdlList = rView.GetHdlList();
1494 SdrHdl* pHdl = rHdlList.GetFocusHdl();
1496 if ( pHdl == 0 )
1498 // no handle selected
1499 if ( rView.IsMoveAllowed() )
1501 // restrict movement to work area
1502 Rectangle rWorkArea = rView.GetWorkArea();
1503 rWorkArea.Right()++;
1505 if ( !rWorkArea.IsEmpty() )
1507 if ( rWorkArea.Top() < 0 )
1508 rWorkArea.Top() = 0;
1509 Rectangle aMarkRect( rView.GetMarkedObjRect() );
1510 aMarkRect.Move( nX, nY );
1512 if ( !rWorkArea.IsInside( aMarkRect ) )
1514 if ( aMarkRect.Left() < rWorkArea.Left() )
1515 nX += rWorkArea.Left() - aMarkRect.Left();
1517 if ( aMarkRect.Right() > rWorkArea.Right() )
1518 nX -= aMarkRect.Right() - rWorkArea.Right();
1520 if ( aMarkRect.Top() < rWorkArea.Top() )
1521 nY += rWorkArea.Top() - aMarkRect.Top();
1523 if ( aMarkRect.Bottom() > rWorkArea.Bottom() )
1524 nY -= aMarkRect.Bottom() - rWorkArea.Bottom();
1526 bool bCheck = false;
1527 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1528 for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
1530 SdrMark* pMark = rMarkList.GetMark(i);
1531 bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL|| dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj());
1535 if ( bCheck )
1537 SdrObject* pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1538 if ( pOverlapped )
1542 Rectangle aOver = pOverlapped->GetLastBoundRect();
1543 Point aPos;
1544 if ( nCode == KEY_UP )
1546 aPos.X() = aMarkRect.Left();
1547 aPos.Y() = aOver.Top() - aMarkRect.getHeight();
1548 nY += (aPos.Y() - aMarkRect.Top());
1550 else if ( nCode == KEY_DOWN )
1552 aPos.X() = aMarkRect.Left();
1553 aPos.Y() = aOver.Bottom();
1554 nY += (aPos.Y() - aMarkRect.Top());
1556 else if ( nCode == KEY_LEFT )
1558 aPos.X() = aOver.Left() - aMarkRect.getWidth();
1559 aPos.Y() = aMarkRect.Top();
1560 nX += (aPos.X() - aMarkRect.Left());
1562 else if ( nCode == KEY_RIGHT )
1564 aPos.X() = aOver.Right();
1565 aPos.Y() = aMarkRect.Top();
1566 nX += (aPos.X() - aMarkRect.Left());
1569 aMarkRect.SetPos(aPos);
1570 if ( !rWorkArea.IsInside( aMarkRect ) )
1572 break;
1574 pOverlapped = isOver(aMarkRect,*rReportSection.getPage(),rView);
1576 while(pOverlapped != NULL);
1577 if (pOverlapped != NULL)
1578 break;
1583 if ( nX != 0 || nY != 0 )
1585 rView.MoveAllMarked( Size( nX, nY ) );
1586 rView.MakeVisible( rView.GetAllMarkedRect(), rReportSection);
1590 else
1592 // move the handle
1593 if ( pHdl && ( nX || nY ) )
1595 const Point aStartPoint( pHdl->GetPos() );
1596 const Point aEndPoint( pHdl->GetPos() + Point( nX, nY ) );
1597 const SdrDragStat& rDragStat = rView.GetDragStat();
1599 // start dragging
1600 rView.BegDragObj( aStartPoint, 0, pHdl, 0 );
1602 if ( rView.IsDragObj() )
1604 const bool bWasNoSnap = rDragStat.IsNoSnap();
1605 const sal_Bool bWasSnapEnabled = rView.IsSnapEnabled();
1607 // switch snapping off
1608 if ( !bWasNoSnap )
1609 ((SdrDragStat&)rDragStat).SetNoSnap( sal_True );
1610 if ( bWasSnapEnabled )
1611 rView.SetSnapEnabled( sal_False );
1613 Rectangle aNewRect;
1614 bool bCheck = false;
1615 const SdrMarkList& rMarkList = rView.GetMarkedObjectList();
1616 for (sal_uInt32 i = 0; !bCheck && i < rMarkList.GetMarkCount();++i )
1618 SdrMark* pMark = rMarkList.GetMark(i);
1619 bCheck = dynamic_cast<OUnoObject*>(pMark->GetMarkedSdrObj()) != NULL || dynamic_cast<OOle2Obj*>(pMark->GetMarkedSdrObj()) != NULL;
1620 if ( bCheck )
1621 aNewRect.Union(pMark->GetMarkedSdrObj()->GetLastBoundRect());
1624 switch(pHdl->GetKind())
1626 case HDL_LEFT:
1627 case HDL_UPLFT:
1628 case HDL_LWLFT:
1629 case HDL_UPPER:
1630 aNewRect.Left() += nX;
1631 aNewRect.Top() += nY;
1632 break;
1633 case HDL_UPRGT:
1634 case HDL_RIGHT:
1635 case HDL_LWRGT:
1636 case HDL_LOWER:
1637 aNewRect.setWidth(aNewRect.getWidth() + nX);
1638 aNewRect.setHeight(aNewRect.getHeight() + nY);
1639 break;
1640 default:
1641 break;
1643 if ( !(bCheck && isOver(aNewRect,*rReportSection.getPage(),rView)) )
1644 rView.MovAction(aEndPoint);
1645 rView.EndDragObj();
1647 // restore snap
1648 if ( !bWasNoSnap )
1649 ((SdrDragStat&)rDragStat).SetNoSnap( bWasNoSnap );
1650 if ( bWasSnapEnabled )
1651 rView.SetSnapEnabled( bWasSnapEnabled );
1654 // make moved handle visible
1655 const Rectangle aVisRect( aEndPoint - Point( DEFAUL_MOVE_SIZE, DEFAUL_MOVE_SIZE ), Size( 200, 200 ) );
1656 rView.MakeVisible( aVisRect, rReportSection);
1659 rView.AdjustMarkHdl();
1663 // -----------------------------------------------------------------------------
1664 void OViewsWindow::stopScrollTimer()
1666 ::std::for_each(m_aSections.begin(),m_aSections.end(),
1667 ::o3tl::compose1(::boost::mem_fn(&OReportSection::stopScrollTimer),TReportPairHelper()));
1669 // -----------------------------------------------------------------------------
1670 void OViewsWindow::fillCollapsedSections(::std::vector<sal_uInt16>& _rCollapsedPositions) const
1672 TSectionsMap::const_iterator aIter = m_aSections.begin();
1673 TSectionsMap::const_iterator aEnd = m_aSections.end();
1674 for (sal_uInt16 i = 0;aIter != aEnd ; ++aIter,++i)
1676 if ( (*aIter)->getStartMarker().isCollapsed() )
1677 _rCollapsedPositions.push_back(i);
1680 // -----------------------------------------------------------------------------
1681 void OViewsWindow::collapseSections(const uno::Sequence< beans::PropertyValue>& _aCollpasedSections)
1683 const beans::PropertyValue* pIter = _aCollpasedSections.getConstArray();
1684 const beans::PropertyValue* pEnd = pIter + _aCollpasedSections.getLength();
1685 for (; pIter != pEnd; ++pIter)
1687 sal_uInt16 nPos = sal_uInt16(-1);
1688 if ( (pIter->Value >>= nPos) && nPos < m_aSections.size() )
1690 m_aSections[nPos]->setCollapsed(sal_True);
1694 // -----------------------------------------------------------------------------
1695 void OViewsWindow::zoom(const Fraction& _aZoom)
1697 const MapMode& aMapMode = GetMapMode();
1699 Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
1700 if ( _aZoom < aMapMode.GetScaleX() )
1701 aStartWidth *= aMapMode.GetScaleX();
1702 else
1703 aStartWidth *= _aZoom;
1705 setZoomFactor(_aZoom,*this);
1707 TSectionsMap::iterator aIter = m_aSections.begin();
1708 TSectionsMap::iterator aEnd = m_aSections.end();
1709 for (;aIter != aEnd ; ++aIter)
1711 (*aIter)->zoom(_aZoom);
1714 Resize();
1716 Size aOut = GetOutputSizePixel();
1717 aOut.Width() = aStartWidth;
1718 aOut = PixelToLogic(aOut);
1720 Rectangle aRect(PixelToLogic(Point(0,0)),aOut);
1721 static sal_Int32 nIn = INVALIDATE_NOCHILDREN;
1722 Invalidate(aRect,nIn);
1724 //----------------------------------------------------------------------------
1725 void OViewsWindow::scrollChildren(const Point& _aThumbPos)
1727 const Point aPos(PixelToLogic(_aThumbPos));
1729 MapMode aMapMode = GetMapMode();
1730 const Point aOld = aMapMode.GetOrigin();
1731 aMapMode.SetOrigin(m_pParent->GetMapMode().GetOrigin());
1733 const Point aPosY(m_pParent->PixelToLogic(_aThumbPos,aMapMode));
1735 aMapMode.SetOrigin( Point(aOld.X() , - aPosY.Y()));
1736 SetMapMode( aMapMode );
1737 Scroll(0, -( aOld.Y() + aPosY.Y()),SCROLL_CHILDREN);
1740 TSectionsMap::iterator aIter = m_aSections.begin();
1741 TSectionsMap::iterator aEnd = m_aSections.end();
1742 for (;aIter != aEnd ; ++aIter)
1744 (*aIter)->scrollChildren(aPos.X());
1747 // -----------------------------------------------------------------------------
1748 void OViewsWindow::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
1750 TSectionsMap::const_iterator aIter = m_aSections.begin();
1751 TSectionsMap::const_iterator aEnd = m_aSections.end();
1752 for(;aIter != aEnd; ++aIter)
1754 (*aIter)->getReportSection().fillControlModelSelection(_rSelection);
1757 //==============================================================================
1758 } // rptui
1759 //==============================================================================
1761 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */