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