Use o3tl::convert in Math
[LibreOffice.git] / reportdesign / source / ui / report / ReportSection.cxx
blob35aff0e6d6b3e33e5c3fb9724a15458e17bce971
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include <memory>
20 #include <ReportSection.hxx>
21 #include <ReportWindow.hxx>
22 #include <DesignView.hxx>
23 #include <strings.hxx>
24 #include <RptObject.hxx>
25 #include <RptModel.hxx>
26 #include <SectionView.hxx>
27 #include <RptPage.hxx>
28 #include <ReportController.hxx>
29 #include <UITools.hxx>
30 #include <ViewsWindow.hxx>
32 #include <svx/svdpagv.hxx>
33 #include <editeng/adjustitem.hxx>
34 #include <svx/sdrpaintwindow.hxx>
35 #include <svx/unoshape.hxx>
36 #include <svx/gallery.hxx>
37 #include <svx/svxids.hrc>
38 #include <svx/svditer.hxx>
39 #include <svx/dbaexchange.hxx>
40 #include <svx/sdtagitm.hxx>
42 #include <com/sun/star/awt/PopupMenuDirection.hpp>
43 #include <com/sun/star/frame/XPopupMenuController.hpp>
44 #include <comphelper/propertyvalue.hxx>
45 #include <toolkit/helper/convert.hxx>
46 #include <tools/diagnose_ex.h>
47 #include <RptDef.hxx>
48 #include <SectionWindow.hxx>
49 #include <helpids.h>
50 #include <dlgedclip.hxx>
51 #include <rptui_slotid.hrc>
53 #include <vcl/commandevent.hxx>
54 #include <o3tl/safeint.hxx>
56 #include <svl/itempool.hxx>
57 #include <svtools/extcolorcfg.hxx>
60 namespace rptui
63 using namespace ::com::sun::star;
66 static Color lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
68 svtools::ExtendedColorConfig aConfig;
69 return aConfig.GetColorValue(CFG_REPORTDESIGNER, DBOVERLAPPEDCONTROL).getColor();
72 OReportSection::OReportSection(OSectionWindow* _pParent,const uno::Reference< report::XSection >& _xSection)
73 : Window(_pParent,WB_DIALOGCONTROL)
74 , ::comphelper::OPropertyChangeListener(m_aMutex)
75 , DropTargetHelper(this)
76 , m_pPage(nullptr)
77 , m_pView(nullptr)
78 , m_pParent(_pParent)
79 , m_xSection(_xSection)
80 , m_nPaintEntranceCount(0)
81 , m_eMode(DlgEdMode::Select)
83 //EnableChildTransparentMode();
84 SetHelpId(HID_REPORTSECTION);
85 SetMapMode(MapMode(MapUnit::Map100thMM));
86 SetParentClipMode(ParentClipMode::Clip);
87 EnableChildTransparentMode( false );
88 SetPaintTransparent( false );
90 try
92 fill();
94 catch(uno::Exception&)
96 TOOLS_WARN_EXCEPTION( "reportdesign", "");
99 m_pFunc.reset(new DlgEdFuncSelect( this ));
100 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor() );
103 OReportSection::~OReportSection()
105 disposeOnce();
108 void OReportSection::dispose()
110 m_pPage = nullptr;
111 if ( m_pMulti.is() )
112 m_pMulti->dispose();
113 m_pMulti.clear();
115 if ( m_pReportListener.is() )
116 m_pReportListener->dispose();
117 m_pReportListener.clear();
118 m_pFunc.reset();
121 if ( m_pView )
122 m_pView->EndListening( *m_pModel );
123 delete m_pView;
124 m_pView = nullptr;
126 m_pParent.clear();
127 vcl::Window::dispose();
130 void OReportSection::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
132 Window::Paint(rRenderContext, rRect);
134 if ( !(m_pView && m_nPaintEntranceCount == 0))
135 return;
137 ++m_nPaintEntranceCount;
138 // repaint, get PageView and prepare Region
139 SdrPageView* pPgView = m_pView->GetSdrPageView();
140 const vcl::Region aPaintRectRegion(rRect);
142 // #i74769#
143 SdrPaintWindow* pTargetPaintWindow = nullptr;
145 // mark repaint start
146 if (pPgView)
148 pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(GetOutDev(), aPaintRectRegion);
149 OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
150 // draw background self using wallpaper
151 OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
152 rTargetOutDev.DrawWallpaper(rRect, Wallpaper(pPgView->GetApplicationDocumentColor()));
154 // do paint (unbuffered) and mark repaint end
155 pPgView->DrawLayer(RPT_LAYER_FRONT, &rRenderContext);
156 pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
159 m_pView->CompleteRedraw(&rRenderContext, aPaintRectRegion);
160 --m_nPaintEntranceCount;
163 void OReportSection::fill()
165 if ( !m_xSection.is() )
166 return;
168 m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection);
169 m_pMulti->addProperty(PROPERTY_BACKCOLOR);
171 m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);
173 m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
174 m_pPage = m_pModel->getPage(m_xSection);
176 m_pView = new OSectionView(
177 *m_pModel,
178 this,
179 m_pParent->getViewsWindow()->getView());
181 // #i93597# tell SdrPage that only left and right page border is defined
182 // instead of the full rectangle definition
183 m_pPage->setPageBorderOnlyLeftRight(true);
185 // without the following call, no grid is painted
186 m_pView->ShowSdrPage( m_pPage );
188 m_pView->SetMoveSnapOnlyTopLeft( true );
189 ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();
191 // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
192 // is only for visualisation and has nothing to do with the actual snap
193 const Size aGridSizeCoarse(pDesignView->getGridSizeCoarse());
194 const Size aGridSizeFine(pDesignView->getGridSizeFine());
195 m_pView->SetGridCoarse(aGridSizeCoarse);
196 m_pView->SetGridFine(aGridSizeFine);
198 // #i93595# set snap grid width to snap to all existing subdivisions
199 const Fraction aX(aGridSizeFine.Width());
200 const Fraction aY(aGridSizeFine.Height());
201 m_pView->SetSnapGridWidth(aX, aY);
203 m_pView->SetGridSnap( true );
204 m_pView->SetGridFront( false );
205 m_pView->SetDragStripes( true );
206 m_pView->SetPageVisible();
207 sal_Int32 nColor = m_xSection->getBackColor();
208 if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
209 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
210 m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));
212 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
213 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
214 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
215 m_pPage->SetLeftBorder(nLeftMargin);
216 m_pPage->SetRightBorder(nRightMargin);
218 // LLA: TODO
219 // m_pPage->SetUpperBorder(-10000);
221 m_pView->SetDesignMode();
223 m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
224 const Size aPageSize = m_pPage->GetSize();
225 m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
228 void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
230 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
231 if ( !(m_xSection.is() && _aAllreadyCopiedObjects.hasElements()) )
232 return;
234 // stop all drawing actions
235 m_pView->BrkAction();
237 // unmark all objects
238 m_pView->UnmarkAll();
239 const OUString sSectionName = m_xSection->getName();
240 for(const beans::NamedValue& rObject : _aAllreadyCopiedObjects)
242 if ( _bForce || rObject.Name == sSectionName)
246 uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
247 rObject.Value >>= aCopies;
248 for (const uno::Reference<report::XReportComponent>& rCopy : std::as_const(aCopies))
250 SdrObject* pObject = SdrObject::getSdrObjectFromXShape( rCopy );
251 if ( pObject )
253 // Clone to target SdrModel
254 SdrObject* pNewObj(pObject->CloneSdrObject(*m_pModel));
255 m_pPage->InsertObject(pNewObj, SAL_MAX_SIZE);
256 tools::Rectangle aRet(VCLPoint(rCopy->getPosition()),VCLSize(rCopy->getSize()));
257 aRet.setHeight(aRet.getHeight() + 1);
258 aRet.setWidth(aRet.getWidth() + 1);
259 bool bOverlapping = true;
260 while ( bOverlapping )
262 bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj) != nullptr;
263 if ( bOverlapping )
265 aRet.Move(0,aRet.getHeight()+1);
266 pNewObj->SetLogicRect(aRet);
269 m_pView->AddUndo( m_pView->GetModel()->GetSdrUndoFactory().CreateUndoNewObject( *pNewObj ) );
270 m_pView->MarkObj( pNewObj, m_pView->GetSdrPageView() );
271 if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getHeight() + aRet.Top()) > m_xSection->getHeight()) )
272 m_xSection->setHeight(aRet.getHeight() + aRet.Top());
276 catch(uno::Exception&)
278 TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while pasting a new object!");
280 if ( !_bForce )
281 break;
286 void OReportSection::Delete()
288 if( !m_pView->AreObjectsMarked() )
289 return;
291 m_pView->BrkAction();
292 m_pView->DeleteMarked();
295 void OReportSection::SetMode( DlgEdMode eNewMode )
297 if ( eNewMode == m_eMode )
298 return;
300 if ( eNewMode == DlgEdMode::Insert )
302 m_pFunc.reset(new DlgEdFuncInsert( this ));
304 else
306 m_pFunc.reset(new DlgEdFuncSelect( this ));
308 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
309 m_pModel->SetReadOnly(false);
310 m_eMode = eNewMode;
313 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
315 Copy(_rAllreadyCopiedObjects,false);
318 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
320 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
321 if( !m_pView->AreObjectsMarked() || !m_xSection.is() )
322 return;
324 // insert control models of marked objects into clipboard dialog model
325 const SdrMarkList& rMarkedList = m_pView->GetMarkedObjectList();
326 const size_t nMark = rMarkedList.GetMarkCount();
328 ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
329 aCopies.reserve(nMark);
331 SdrUndoFactory& rUndo = m_pView->GetModel()->GetSdrUndoFactory();
333 for( size_t i = nMark; i > 0; )
335 --i;
336 SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
337 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
338 if ( pObj )
342 SdrObject* pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject()));
343 aCopies.emplace_back(pNewObj->getUnoShape(),uno::UNO_QUERY);
344 if ( _bEraseAnddNoClone )
346 m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
347 m_pPage->RemoveObject(pSdrObject->GetOrdNum());
351 catch(uno::Exception&)
353 OSL_FAIL("Can't copy report elements!");
358 if ( !aCopies.empty() )
360 ::std::reverse(aCopies.begin(),aCopies.end());
361 const sal_Int32 nLength = _rAllreadyCopiedObjects.getLength();
362 _rAllreadyCopiedObjects.realloc( nLength + 1);
363 beans::NamedValue* pNewValue = _rAllreadyCopiedObjects.getArray() + nLength;
364 pNewValue->Name = m_xSection->getName();
365 pNewValue->Value <<= uno::Sequence< uno::Reference<report::XReportComponent> >(&(*aCopies.begin()),aCopies.size());
369 void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
371 m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true); // mark the section in which is clicked
372 m_pFunc->MouseButtonDown( rMEvt );
373 Window::MouseButtonDown(rMEvt);
376 void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
378 if ( !m_pFunc->MouseButtonUp( rMEvt ) )
379 m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
383 void OReportSection::MouseMove( const MouseEvent& rMEvt )
385 m_pFunc->MouseMove( rMEvt );
389 void OReportSection::SetGridVisible(bool _bVisible)
391 m_pView->SetGridVisible( _bVisible );
394 void OReportSection::SelectAll(const sal_uInt16 _nObjectType)
396 if ( !m_pView )
397 return;
399 if ( _nObjectType == OBJ_NONE )
400 m_pView->MarkAllObj();
401 else
403 m_pView->UnmarkAll();
404 SdrObjListIter aIter(m_pPage,SdrIterMode::DeepNoGroups);
405 SdrObject* pObjIter = nullptr;
406 while( (pObjIter = aIter.Next()) != nullptr )
408 if ( pObjIter->GetObjIdentifier() == _nObjectType )
409 m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
414 void OReportSection::Command( const CommandEvent& _rCEvt )
416 Window::Command(_rCEvt);
417 if (_rCEvt.GetCommand() != CommandEventId::ContextMenu)
418 return;
420 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
421 uno::Reference<frame::XFrame> xFrame = rController.getFrame();
422 css::uno::Sequence<css::uno::Any> aArgs {
423 css::uno::makeAny(comphelper::makePropertyValue("Value", OUString("report"))),
424 css::uno::makeAny(comphelper::makePropertyValue("Frame", xFrame)),
425 css::uno::makeAny(comphelper::makePropertyValue("IsContextMenu", true))
428 css::uno::Reference<css::uno::XComponentContext> xContext(rController.getORB());
429 css::uno::Reference<css::frame::XPopupMenuController> xMenuController(
430 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
431 "com.sun.star.comp.framework.ResourceMenuController", aArgs, xContext), css::uno::UNO_QUERY);
433 if (!xMenuController.is())
434 return;
436 css::uno::Reference<css::awt::XPopupMenu> xPopupMenu(
437 xContext->getServiceManager()->createInstanceWithContext(
438 "com.sun.star.awt.PopupMenu", xContext), css::uno::UNO_QUERY);
440 if (!xPopupMenu.is())
441 return;
443 xMenuController->setPopupMenu(xPopupMenu);
445 Point aPos = _rCEvt.GetMousePosPixel();
446 m_pView->EndAction();
448 xPopupMenu->execute(GetComponentInterface(),
449 css::awt::Rectangle(aPos.X(), aPos.Y(), 1, 1),
450 css::awt::PopupMenuDirection::EXECUTE_DOWN);
452 css::uno::Reference<css::lang::XComponent> xComponent(xMenuController, css::uno::UNO_QUERY);
453 xComponent->dispose();
456 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
458 if ( !m_xSection.is() )
459 return;
461 if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
463 sal_Int32 nColor = m_xSection->getBackColor();
464 if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
465 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
466 m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));
467 Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::NoErase);
469 else
471 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
472 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
473 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
474 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
476 if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
478 m_pPage->SetLeftBorder(nLeftMargin);
480 else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
482 m_pPage->SetRightBorder(nRightMargin);
484 const Size aOldPageSize = m_pPage->GetSize();
485 sal_Int32 nNewHeight = 5*m_xSection->getHeight();
486 if ( aOldPageSize.Height() != nNewHeight || nPaperWidth != aOldPageSize.Width() )
488 m_pPage->SetSize( Size( nPaperWidth,nNewHeight) );
489 const Size aPageSize = m_pPage->GetSize();
490 m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
492 impl_adjustObjectSizePosition(nPaperWidth,nLeftMargin,nRightMargin);
493 m_pParent->Invalidate(InvalidateFlags::Update | InvalidateFlags::Transparent);
496 void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth,sal_Int32 i_nLeftMargin,sal_Int32 i_nRightMargin)
500 sal_Int32 nRightBorder = i_nPaperWidth - i_nRightMargin;
501 const sal_Int32 nCount = m_xSection->getCount();
502 for (sal_Int32 i = 0; i < nCount; ++i)
504 uno::Reference< report::XReportComponent> xReportComponent(m_xSection->getByIndex(i),uno::UNO_QUERY_THROW);
505 awt::Point aPos = xReportComponent->getPosition();
506 awt::Size aSize = xReportComponent->getSize();
507 SdrObject* pObject = SdrObject::getSdrObjectFromXShape( xReportComponent );
508 if ( pObject )
510 bool bChanged = false;
512 OObjectBase& rBase = dynamic_cast<OObjectBase&>(*pObject);
513 rBase.EndListening();
514 if ( aPos.X < i_nLeftMargin )
516 aPos.X = i_nLeftMargin;
517 bChanged = true;
519 if ( (aPos.X + aSize.Width) > nRightBorder )
521 aPos.X = nRightBorder - aSize.Width;
522 if ( aPos.X < i_nLeftMargin )
524 aSize.Width += aPos.X - i_nLeftMargin;
525 aPos.X = i_nLeftMargin;
526 // add listener around
527 rBase.StartListening();
528 xReportComponent->setSize(aSize);
529 rBase.EndListening();
531 bChanged = true;
533 if ( aPos.Y < 0 )
534 aPos.Y = 0;
535 if ( bChanged )
537 xReportComponent->setPosition(aPos);
538 correctOverlapping(pObject,*this,false);
539 tools::Rectangle aRet(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
540 aRet.setHeight(aRet.getHeight() + 1);
541 aRet.setWidth(aRet.getWidth() + 1);
542 if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getHeight() + aRet.Top()) > m_xSection->getHeight()) )
543 m_xSection->setHeight(aRet.getHeight() + aRet.Top());
545 pObject->RecalcBoundRect();
547 rBase.StartListening();
551 catch(const uno::Exception &)
553 TOOLS_WARN_EXCEPTION( "reportdesign", "OReportSection::impl_adjustObjectSizePosition()");
557 bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
559 return m_pFunc && m_pFunc->handleKeyEvent(_rEvent);
562 void OReportSection::deactivateOle()
564 if (m_pFunc)
565 m_pFunc->deactivateOle(true);
568 void OReportSection::createDefault(const OUString& _sType)
570 SdrObject* pObj = m_pView->GetCreateObj();
571 if ( !pObj )
572 return;
573 createDefault(_sType,pObj);
576 void OReportSection::createDefault(const OUString& _sType,SdrObject* _pObj)
578 bool bAttributesAppliedFromGallery = false;
580 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
582 std::vector< OUString > aObjList;
583 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
585 auto aIter = std::find_if(aObjList.begin(), aObjList.end(),
586 [&_sType](const OUString& rObj) { return rObj.equalsIgnoreAsciiCase(_sType); });
587 if (aIter != aObjList.end())
589 auto i = static_cast<sal_uInt32>(std::distance(aObjList.begin(), aIter));
590 OReportModel aReportModel(nullptr);
591 SfxItemPool& rPool = aReportModel.GetItemPool();
592 rPool.FreezeIdRanges();
593 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aReportModel ) )
595 const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
596 if( pSourceObj )
598 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
599 SfxItemSetFixed<
600 // Ranges from SdrAttrObj:
601 SDRATTR_START, SDRATTR_SHADOW_LAST,
602 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
603 SDRATTR_TEXTDIRECTION,
604 SDRATTR_TEXTDIRECTION,
605 // Graphic attributes, 3D properties,
606 // CustomShape properties:
607 SDRATTR_GRAF_FIRST,
608 SDRATTR_CUSTOMSHAPE_LAST,
609 // Range from SdrTextObj:
610 EE_ITEMS_START, EE_ITEMS_END>
611 aDest( _pObj->getSdrModelFromSdrObject().GetItemPool() );
612 aDest.Set( rSource );
613 _pObj->SetMergedItemSet( aDest );
614 Degree100 nAngle = pSourceObj->GetRotateAngle();
615 if ( nAngle )
616 _pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle );
617 bAttributesAppliedFromGallery = true;
623 if ( !bAttributesAppliedFromGallery )
625 _pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST) );
626 _pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
627 _pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
628 _pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
629 static_cast<SdrObjCustomShape*>(_pObj)->MergeDefaultAttributes( &_sType );
633 uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
635 uno::Reference< report::XReportComponent > xModel;
636 if ( m_pView )
638 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
640 if ( rMarkList.GetMarkCount() == 1 )
642 SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
643 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
644 if ( pObj )
645 xModel = pObj->getReportComponent().get();
648 return xModel;
651 void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
653 if ( !m_pView )
654 return;
656 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
657 const size_t nMarkCount = rMarkList.GetMarkCount();
659 for (size_t i=0; i < nMarkCount; ++i)
661 const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
662 const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
663 if ( pObj )
665 uno::Reference<uno::XInterface> xInterface(pObj->getReportComponent());
666 _rSelection.push_back(xInterface);
671 sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
673 ::Point aDropPos(_rEvt.maPosPixel);
674 const MouseEvent aMouseEvt(aDropPos);
675 if ( m_pFunc->isOverlapping(aMouseEvt) )
676 return DND_ACTION_NONE;
678 if ( _rEvt.mnAction == DND_ACTION_COPY ||
679 _rEvt.mnAction == DND_ACTION_LINK
682 if (!m_pParent) return DND_ACTION_NONE;
683 sal_uInt16 nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
684 if (_rEvt.mnAction == DND_ACTION_COPY )
686 // we must assure, we can't drop in the top section
687 if (nCurrentPosition < 1)
689 return DND_ACTION_NONE;
691 return DND_ACTION_LINK;
693 if (_rEvt.mnAction == DND_ACTION_LINK)
695 // we must assure, we can't drop in the bottom section
696 if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1) )
698 return DND_ACTION_COPY;
700 return DND_ACTION_NONE;
703 else
705 const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
706 if ( svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors)
707 || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
708 return _rEvt.mnAction;
710 const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;
712 return nDropOption;
714 return DND_ACTION_NONE;
718 sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
720 ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
721 const MouseEvent aMouseEvt(aDropPos);
722 if ( m_pFunc->isOverlapping(aMouseEvt) )
723 return DND_ACTION_NONE;
725 sal_Int8 nDropOption = DND_ACTION_NONE;
726 const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
727 const DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
728 bool bMultipleFormat = svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
729 if ( OReportExchange::canExtract(rFlavors) )
731 OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
732 Paste(aCopies,true);
733 nDropOption = DND_ACTION_COPYMOVE;
734 m_pParent->getViewsWindow()->BrkAction();
735 m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
737 else if ( bMultipleFormat
738 || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
740 m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true);
741 m_pView->UnmarkAll();
742 const tools::Rectangle& rRect = m_pView->GetWorkArea();
743 if ( aDropPos.X() < rRect.Left() )
744 aDropPos.setX( rRect.Left() );
745 else if ( aDropPos.X() > rRect.Right() )
746 aDropPos.setX( rRect.Right() );
748 if ( aDropPos.Y() > rRect.Bottom() )
749 aDropPos.setY( rRect.Bottom() );
751 uno::Sequence<beans::PropertyValue> aValues;
752 if ( !bMultipleFormat )
754 svx::ODataAccessDescriptor aDescriptor = svx::OColumnTransferable::extractColumnDescriptor(aDropped);
756 aValues.realloc(1);
757 aValues.getArray()[0].Value <<= aDescriptor.createPropertyValueSequence();
759 else
760 aValues = svx::OMultiColumnTransferable::extractDescriptor(aDropped);
762 for(beans::PropertyValue & propVal : asNonConstRange(aValues))
764 uno::Sequence<beans::PropertyValue> aCurrent;
765 propVal.Value >>= aCurrent;
766 sal_Int32 nLength = aCurrent.getLength();
767 if ( nLength )
769 aCurrent.realloc(nLength + 3);
770 auto pCurrent = aCurrent.getArray();
771 pCurrent[nLength].Name = PROPERTY_POSITION;
772 pCurrent[nLength++].Value <<= AWTPoint(aDropPos);
773 // give also the DND Action (Shift|Ctrl) Key to really say what we want
774 pCurrent[nLength].Name = "DNDAction";
775 pCurrent[nLength++].Value <<= _rEvt.mnAction;
777 pCurrent[nLength].Name = "Section";
778 pCurrent[nLength++].Value <<= getSection();
779 propVal.Value <<= aCurrent;
783 // we use this way to create undo actions
784 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
785 rController.executeChecked(SID_ADD_CONTROL_PAIR,aValues);
786 nDropOption = DND_ACTION_COPY;
788 return nDropOption;
791 void OReportSection::stopScrollTimer()
793 m_pFunc->stopScrollTimer();
796 bool OReportSection::isUiActive() const
798 return m_pFunc->isUiActive();
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */