1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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"
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>
49 #include <o3tl/compat_functional.hxx>
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;
63 Rectangle aNewRect
= _aObjRect
;
64 SdrObject
* pOverlappedObj
= NULL
;
68 switch(_nControlModification
)
70 case ControlModification::HEIGHT_GREATEST
:
71 case ControlModification::WIDTH_GREATEST
:
72 aNewRect
.setWidth(_nXMov
);
73 aNewRect
.setHeight(_nYMov
);
76 aNewRect
.Move(_nXMov
,_nYMov
);
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
;
93 case ControlModification::RIGHT
:
94 nXTemp
+= aOverlappingRect
.Left() - aNewRect
.Right();
95 bMoveAllowed
= _nXMov
!= nXTemp
;
97 case ControlModification::TOP
:
98 nYTemp
+= aOverlappingRect
.Bottom() - aNewRect
.Top();
99 bMoveAllowed
= _nYMov
!= nYTemp
;
101 case ControlModification::BOTTOM
:
102 nYTemp
+= aOverlappingRect
.Top() - aNewRect
.Bottom();
103 bMoveAllowed
= _nYMov
!= nYTemp
;
105 case ControlModification::CENTER_HORIZONTAL
:
106 if ( _aObjRect
.Left() < aOverlappingRect
.Left() )
107 nXTemp
+= aOverlappingRect
.Left() - aNewRect
.Left() - aNewRect
.getWidth();
109 nXTemp
+= aOverlappingRect
.Right() - aNewRect
.Left();
110 bMoveAllowed
= _nXMov
!= nXTemp
;
112 case ControlModification::CENTER_VERTICAL
:
113 if ( _aObjRect
.Top() < aOverlappingRect
.Top() )
114 nYTemp
+= aOverlappingRect
.Top() - aNewRect
.Top() - aNewRect
.getHeight();
116 nYTemp
+= aOverlappingRect
.Bottom() - aNewRect
.Top();
117 bMoveAllowed
= _nYMov
!= nYTemp
;
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
;
162 pOverlappedObj
= NULL
;
165 while ( pOverlappedObj
&& 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);
184 // -----------------------------------------------------------------------------
185 OViewsWindow::~OViewsWindow()
187 m_aColorConfig
.RemoveListener(this);
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());
214 _rSectionWindow
.SetPosSizePixel(_rStartPoint
,aSectionSize
);
216 _rStartPoint
.Y() += aSectionSize
.Height();
219 // -----------------------------------------------------------------------------
220 void OViewsWindow::resize(const OSectionWindow
& _rSectionWindow
)
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();
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()
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
);
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
) )
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);
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
);
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();
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
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()));
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
);
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() )
446 else if ( nsa
== PREVIOUS
)
448 if (nCurrentPosition
> 0)
453 pRet
= (*m_aSections
.begin());
458 // if we are out of bounds return the first one
459 pRet
= (*m_aSections
.begin());
463 else if ( nsa
== POST
)
465 sal_uInt32 nSize
= m_aSections
.size();
466 if ((nCurrentPosition
+ 1) < nSize
)
476 // if we are out of bounds return the last one
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
)
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
)
532 // -----------------------------------------------------------------------------
533 void OViewsWindow::MouseButtonDown( const MouseEvent
& rMEvt
)
535 if ( rMEvt
.IsLeft() )
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
);
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
);
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
;
597 //------------------------------------------------------------------------
598 void OViewsWindow::setMarked(OSectionView
* _pSectionView
,sal_Bool _bMark
)
600 OSL_ENSURE(_pSectionView
!= NULL
,"SectionView is NULL!");
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
)
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();
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!" );
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() )
682 switch(_nControlModification
)
684 case ControlModification::WIDTH_SMALLEST
:
685 if ( _rResize
.getWidth() > aObjRect
.getWidth() )
688 case ControlModification::HEIGHT_SMALLEST
:
689 if ( _rResize
.getHeight() > aObjRect
.getHeight() )
692 case ControlModification::WIDTH_GREATEST
:
693 if ( _rResize
.getWidth() < aObjRect
.getWidth() )
696 case ControlModification::HEIGHT_GREATEST
:
697 if ( _rResize
.getHeight() < aObjRect
.getHeight() )
702 SdrObjTransformInfoRec aInfo
;
703 const SdrObject
* pObj
= aRectIter
->second
.first
;
704 pObj
->TakeObjInfo(aInfo
);
705 sal_Bool bHasFixed
= !aInfo
.bMoveAllowed
|| pObj
->IsMoveProtect();
707 _rBound
.Union(aObjRect
);
710 if ( _bAlignAtSection
|| _rSortRectangles
.size() == 1 )
711 { // einzelnes Obj an der Seite ausrichten
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
&){}
730 _rBound
.Union(aRectIter
->second
.second
->GetMarkedObjBoundRect());
732 _rBound
.Union(aRectIter
->second
.second
->GetMarkedObjRect());
737 // -----------------------------------------------------------------------------
738 void OViewsWindow::alignMarkedObjects(sal_Int32 _nControlModification
,bool _bAlignAtSection
, bool _bBoundRects
)
740 if ( _nControlModification
== ControlModification::NONE
)
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();
764 RectangleLess
aCompare(eCompareMode
,aRefPoint
);
765 TRectangleMap
aSortRectangles(aCompare
);
766 collectRectangles(aSortRectangles
,_bBoundRects
);
770 collectBoundResizeRect(aSortRectangles
,_nControlModification
,_bAlignAtSection
,_bBoundRects
,aBound
,aResize
);
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())
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
);
798 case ControlModification::BOTTOM
:
799 // defaults are already set
802 case ControlModification::CENTER_VERTICAL
:
803 nYMov
= aCenter
.Y() - aObjRect
.Center().Y();
807 case ControlModification::RIGHT
:
808 aGetFun
= ::std::mem_fun
<long&,Rectangle
>(&Rectangle::Right
);
809 aRefFun
= ::std::mem_fun
<long&,Rectangle
>(&Rectangle::Left
);
811 case ControlModification::CENTER_HORIZONTAL
:
812 nXMov
= aCenter
.X() - aObjRect
.Center().X();
815 case ControlModification::LEFT
:
816 aGetFun
= ::std::mem_fun
<long&,Rectangle
>(&Rectangle::Left
);
817 aRefFun
= ::std::mem_fun
<long&,Rectangle
>(&Rectangle::Right
);
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
);
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
));
850 aObjRect
= (_bBoundRects
? pObj
->GetCurrentBoundRect() : pObj
->GetSnapRect());
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
);
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?");
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
));
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() )
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
];
944 // -----------------------------------------------------------------------------
947 enum SectionViewAction
956 class ApplySectionViewAction
: public ::std::unary_function
< OViewsWindow::TSectionsMap::value_type
, void >
959 SectionViewAction m_eAction
;
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() );
974 rView
.EndDragObj( m_bCopy
);
977 if ( rView
.IsAction() )
981 rView
.MovAction ( m_aPoint
);
984 rView
.BegMarkObj ( m_aPoint
);
986 case eForceToAnotherPage
:
987 rView
.ForceMarkedToAnotherPage();
990 if ( rView
.IsAction() )
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();
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"));
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
)
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" );
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
);
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());
1121 for (aIter
= m_aSections
.begin(); aIter
!= aEnd
; ++aIter
)
1123 OReportSection
& rReportSection
= (*aIter
)->getReportSection();
1125 SdrHdl
* pHdl
= _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
)
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
)
1162 aNewPos
= _aPnt
; // 2,2
1166 const long nSectionHeight
= rReportSection
.PixelToLogic(rReportSection
.GetOutputSizePixel()).Height();
1167 aNewPos
.Y() += nSectionHeight
;
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
)
1190 OSL_ENSURE(aIter
!= aEnd
,"This can never happen!");
1191 if ( _rPnt
.Y() < 0 )
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) )
1204 pSection
= &(*m_aSections
.begin())->getReportSection().getSectionView();
1206 pSection
= &(*aIter
)->getReportSection().getSectionView();
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 )
1216 _rPnt
.Y() -= nHeight
;
1218 if ( aIter
!= aEnd
)
1219 pSection
= &(*aIter
)->getReportSection().getSectionView();
1221 pSection
= &(*(aEnd
-1))->getReportSection().getSectionView();
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);
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 )
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 )
1313 if ( aNewPos
.X() < 0 )
1315 aSize
.Width
+= aNewPos
.X();
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);
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
)
1353 Point aRealMousePos
= _aPnt
;
1354 Point aCurrentSectionPos
;
1355 OSL_TRACE("MovAction X:%d Y:%d", aRealMousePos
.X(), aRealMousePos
.Y() );
1358 SdrHdl
* pHdl
= _pSection
->GetDragHdl();
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
)
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
);
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();
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();
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();
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();
1446 // -----------------------------------------------------------------------------
1447 void OViewsWindow::handleKey(const KeyCode
& _rCode
)
1449 const sal_uInt16 nCode
= _rCode
.GetCode();
1450 if ( _rCode
.IsMod1() )
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
);
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();
1467 if ( nCode
== KEY_UP
)
1469 else if ( nCode
== KEY_DOWN
)
1471 else if ( nCode
== KEY_LEFT
)
1473 else if ( nCode
== KEY_RIGHT
)
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();
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();
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());
1537 SdrObject
* pOverlapped
= isOver(aMarkRect
,*rReportSection
.getPage(),rView
);
1542 Rectangle aOver
= pOverlapped
->GetLastBoundRect();
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
) )
1574 pOverlapped
= isOver(aMarkRect
,*rReportSection
.getPage(),rView
);
1576 while(pOverlapped
!= NULL
);
1577 if (pOverlapped
!= NULL
)
1583 if ( nX
!= 0 || nY
!= 0 )
1585 rView
.MoveAllMarked( Size( nX
, nY
) );
1586 rView
.MakeVisible( rView
.GetAllMarkedRect(), rReportSection
);
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();
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
1609 ((SdrDragStat
&)rDragStat
).SetNoSnap( sal_True
);
1610 if ( bWasSnapEnabled
)
1611 rView
.SetSnapEnabled( sal_False
);
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
;
1621 aNewRect
.Union(pMark
->GetMarkedSdrObj()->GetLastBoundRect());
1624 switch(pHdl
->GetKind())
1630 aNewRect
.Left() += nX
;
1631 aNewRect
.Top() += nY
;
1637 aNewRect
.setWidth(aNewRect
.getWidth() + nX
);
1638 aNewRect
.setHeight(aNewRect
.getHeight() + nY
);
1643 if ( !(bCheck
&& isOver(aNewRect
,*rReportSection
.getPage(),rView
)) )
1644 rView
.MovAction(aEndPoint
);
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();
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
);
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 //==============================================================================
1759 //==============================================================================
1761 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */