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