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