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