Get the style color and number just once
[LibreOffice.git] / reportdesign / source / ui / report / ReportSection.cxx
blob77ad558e039665a2da9a9c908e80c13a32b5f2db
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 <editeng/eeitem.hxx>
35 #include <svx/sdrpaintwindow.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/awt/vclxmenu.hxx>
46 #include <comphelper/diagnose_ex.hxx>
47 #include <RptDef.hxx>
48 #include <SectionWindow.hxx>
49 #include <helpids.h>
50 #include <dlgedclip.hxx>
51 #include <rptui_slotid.hrc>
53 #include <utility>
54 #include <vcl/commandevent.hxx>
55 #include <vcl/unohelp.hxx>
56 #include <o3tl/safeint.hxx>
58 #include <svl/itempool.hxx>
59 #include <svtools/extcolorcfg.hxx>
62 namespace rptui
65 using namespace ::com::sun::star;
68 static Color lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
70 svtools::ExtendedColorConfig aConfig;
71 return aConfig.GetColorValue(CFG_REPORTDESIGNER, DBOVERLAPPEDCONTROL).getColor();
74 OReportSection::OReportSection(OSectionWindow* _pParent,uno::Reference< report::XSection > _xSection)
75 : Window(_pParent,WB_DIALOGCONTROL)
76 , ::comphelper::OPropertyChangeListener()
77 , DropTargetHelper(this)
78 , m_pPage(nullptr)
79 , m_pView(nullptr)
80 , m_pParent(_pParent)
81 , m_xSection(std::move(_xSection))
82 , m_nPaintEntranceCount(0)
83 , m_eMode(DlgEdMode::Select)
85 //EnableChildTransparentMode();
86 SetHelpId(HID_REPORTSECTION);
87 SetMapMode(MapMode(MapUnit::Map100thMM));
88 SetParentClipMode(ParentClipMode::Clip);
89 EnableChildTransparentMode( false );
90 SetPaintTransparent( false );
92 try
94 fill();
96 catch(uno::Exception&)
98 TOOLS_WARN_EXCEPTION( "reportdesign", "");
101 m_pFunc.reset(new DlgEdFuncSelect( this ));
102 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor() );
105 OReportSection::~OReportSection()
107 disposeOnce();
110 void OReportSection::dispose()
112 m_pPage = nullptr;
113 if ( m_pMulti.is() )
114 m_pMulti->dispose();
115 m_pMulti.clear();
117 if ( m_pReportListener.is() )
118 m_pReportListener->dispose();
119 m_pReportListener.clear();
120 m_pFunc.reset();
123 if ( m_pView )
124 m_pView->EndListening( *m_pModel );
125 delete m_pView;
126 m_pView = nullptr;
128 m_pParent.clear();
129 vcl::Window::dispose();
132 void OReportSection::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
134 Window::Paint(rRenderContext, rRect);
136 if ( !(m_pView && m_nPaintEntranceCount == 0))
137 return;
139 ++m_nPaintEntranceCount;
140 // repaint, get PageView and prepare Region
141 SdrPageView* pPgView = m_pView->GetSdrPageView();
142 const vcl::Region aPaintRectRegion(rRect);
144 // #i74769#
145 SdrPaintWindow* pTargetPaintWindow = nullptr;
147 // mark repaint start
148 if (pPgView)
150 pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(GetOutDev(), aPaintRectRegion);
151 assert(pTargetPaintWindow && "BeginDrawLayers: Got no SdrPaintWindow (!)");
152 // draw background self using wallpaper
153 OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
154 rTargetOutDev.DrawWallpaper(rRect, Wallpaper(pPgView->GetApplicationDocumentColor()));
156 // do paint (unbuffered) and mark repaint end
157 pPgView->DrawLayer(RPT_LAYER_FRONT, &rRenderContext);
158 pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
161 m_pView->CompleteRedraw(&rRenderContext, aPaintRectRegion);
162 --m_nPaintEntranceCount;
165 void OReportSection::fill()
167 if ( !m_xSection.is() )
168 return;
170 m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection);
171 m_pMulti->addProperty(PROPERTY_BACKCOLOR);
173 m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);
175 m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
176 m_pPage = m_pModel->getPage(m_xSection);
178 m_pView = new OSectionView(
179 *m_pModel,
180 this,
181 m_pParent->getViewsWindow()->getView());
183 // #i93597# tell SdrPage that only left and right page border is defined
184 // instead of the full rectangle definition
185 m_pPage->setPageBorderOnlyLeftRight(true);
187 // without the following call, no grid is painted
188 m_pView->ShowSdrPage( m_pPage );
190 m_pView->SetMoveSnapOnlyTopLeft( true );
191 ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();
193 // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
194 // is only for visualisation and has nothing to do with the actual snap
195 const Size aGridSizeCoarse(pDesignView->getGridSizeCoarse());
196 const Size aGridSizeFine(pDesignView->getGridSizeFine());
197 m_pView->SetGridCoarse(aGridSizeCoarse);
198 m_pView->SetGridFine(aGridSizeFine);
200 // #i93595# set snap grid width to snap to all existing subdivisions
201 const Fraction aX(aGridSizeFine.Width());
202 const Fraction aY(aGridSizeFine.Height());
203 m_pView->SetSnapGridWidth(aX, aY);
205 m_pView->SetGridSnap( true );
206 m_pView->SetGridFront( false );
207 m_pView->SetDragStripes( true );
208 m_pView->SetPageVisible();
209 sal_Int32 nColor = m_xSection->getBackColor();
210 if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
211 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
212 m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));
214 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
215 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
216 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
217 m_pPage->SetLeftBorder(nLeftMargin);
218 m_pPage->SetRightBorder(nRightMargin);
220 // LLA: TODO
221 // m_pPage->SetUpperBorder(-10000);
223 m_pView->SetDesignMode();
225 m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
226 const Size aPageSize = m_pPage->GetSize();
227 m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
230 void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
232 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
233 if ( !(m_xSection.is() && _aAllreadyCopiedObjects.hasElements()) )
234 return;
236 // stop all drawing actions
237 m_pView->BrkAction();
239 // unmark all objects
240 m_pView->UnmarkAll();
241 const OUString sSectionName = m_xSection->getName();
242 for(const beans::NamedValue& rObject : _aAllreadyCopiedObjects)
244 if ( _bForce || rObject.Name == sSectionName)
248 uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
249 rObject.Value >>= aCopies;
250 for (const uno::Reference<report::XReportComponent>& rCopy : aCopies)
252 SdrObject* pObject = SdrObject::getSdrObjectFromXShape( rCopy );
253 if ( pObject )
255 // Clone to target SdrModel
256 rtl::Reference<SdrObject> pNewObj(pObject->CloneSdrObject(*m_pModel));
257 m_pPage->InsertObject(pNewObj.get(), SAL_MAX_SIZE);
258 tools::Rectangle aRet(vcl::unohelper::ConvertToVCLPoint(rCopy->getPosition()),
259 vcl::unohelper::ConvertToVCLSize(rCopy->getSize()));
260 aRet.setHeight(aRet.getOpenHeight() + 1);
261 aRet.setWidth(aRet.getOpenWidth() + 1);
262 bool bOverlapping = true;
263 while ( bOverlapping )
265 bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj.get()) != nullptr;
266 if ( bOverlapping )
268 aRet.Move(0,aRet.getOpenHeight()+1);
269 pNewObj->SetLogicRect(aRet);
272 m_pView->AddUndo(m_pView->GetModel().GetSdrUndoFactory().CreateUndoNewObject(*pNewObj));
273 m_pView->MarkObj( pNewObj.get(), m_pView->GetSdrPageView() );
274 if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getOpenHeight() + aRet.Top()) > m_xSection->getHeight()) )
275 m_xSection->setHeight(aRet.getOpenHeight() + aRet.Top());
279 catch(uno::Exception&)
281 TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while pasting a new object!");
283 if ( !_bForce )
284 break;
289 void OReportSection::Delete()
291 if( m_pView->GetMarkedObjectList().GetMarkCount() == 0 )
292 return;
294 m_pView->BrkAction();
295 m_pView->DeleteMarked();
298 void OReportSection::SetMode( DlgEdMode eNewMode )
300 if ( eNewMode == m_eMode )
301 return;
303 if ( eNewMode == DlgEdMode::Insert )
305 m_pFunc.reset(new DlgEdFuncInsert( this ));
307 else
309 m_pFunc.reset(new DlgEdFuncSelect( this ));
311 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
312 m_pModel->SetReadOnly(false);
313 m_eMode = eNewMode;
316 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
318 Copy(_rAllreadyCopiedObjects,false);
321 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
323 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
324 if( m_pView->GetMarkedObjectList().GetMarkCount() == 0 || !m_xSection.is() )
325 return;
327 // insert control models of marked objects into clipboard dialog model
328 const SdrMarkList& rMarkedList = m_pView->GetMarkedObjectList();
329 const size_t nMark = rMarkedList.GetMarkCount();
331 ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
332 aCopies.reserve(nMark);
334 SdrUndoFactory& rUndo = m_pView->GetModel().GetSdrUndoFactory();
336 for( size_t i = nMark; i > 0; )
338 --i;
339 SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
340 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
341 if ( pObj )
345 rtl::Reference<SdrObject> pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject()));
346 aCopies.emplace_back(pNewObj->getUnoShape(),uno::UNO_QUERY);
347 if ( _bEraseAnddNoClone )
349 m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
350 m_pPage->RemoveObject(pSdrObject->GetOrdNum());
354 catch(uno::Exception&)
356 OSL_FAIL("Can't copy report elements!");
361 if ( !aCopies.empty() )
363 ::std::reverse(aCopies.begin(),aCopies.end());
364 const sal_Int32 nLength = _rAllreadyCopiedObjects.getLength();
365 _rAllreadyCopiedObjects.realloc( nLength + 1);
366 beans::NamedValue* pNewValue = _rAllreadyCopiedObjects.getArray() + nLength;
367 pNewValue->Name = m_xSection->getName();
368 pNewValue->Value <<= uno::Sequence< uno::Reference<report::XReportComponent> >(&(*aCopies.begin()),aCopies.size());
372 void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
374 m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true); // mark the section in which is clicked
375 m_pFunc->MouseButtonDown( rMEvt );
376 Window::MouseButtonDown(rMEvt);
379 void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
381 if ( !m_pFunc->MouseButtonUp( rMEvt ) )
382 m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
386 void OReportSection::MouseMove( const MouseEvent& rMEvt )
388 m_pFunc->MouseMove( rMEvt );
392 void OReportSection::SetGridVisible(bool _bVisible)
394 m_pView->SetGridVisible( _bVisible );
397 void OReportSection::SelectAll(const SdrObjKind _nObjectType)
399 if ( !m_pView )
400 return;
402 if ( _nObjectType == SdrObjKind::NONE )
403 m_pView->MarkAllObj();
404 else
406 m_pView->UnmarkAll();
407 SdrObjListIter aIter(m_pPage,SdrIterMode::DeepNoGroups);
408 SdrObject* pObjIter = nullptr;
409 while( (pObjIter = aIter.Next()) != nullptr )
411 if ( pObjIter->GetObjIdentifier() == _nObjectType )
412 m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
417 void OReportSection::Command( const CommandEvent& _rCEvt )
419 Window::Command(_rCEvt);
420 if (_rCEvt.GetCommand() != CommandEventId::ContextMenu)
421 return;
423 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
424 uno::Reference<frame::XFrame> xFrame = rController.getFrame();
425 css::uno::Sequence<css::uno::Any> aArgs {
426 css::uno::Any(comphelper::makePropertyValue(u"Value"_ustr, u"report"_ustr)),
427 css::uno::Any(comphelper::makePropertyValue(u"Frame"_ustr, xFrame)),
428 css::uno::Any(comphelper::makePropertyValue(u"IsContextMenu"_ustr, true))
431 css::uno::Reference<css::uno::XComponentContext> xContext(rController.getORB());
432 css::uno::Reference<css::frame::XPopupMenuController> xMenuController(
433 xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
434 u"com.sun.star.comp.framework.ResourceMenuController"_ustr, aArgs, xContext), css::uno::UNO_QUERY);
436 if (!xMenuController.is())
437 return;
439 rtl::Reference<VCLXPopupMenu> xPopupMenu = new VCLXPopupMenu();
441 if (!xPopupMenu.is())
442 return;
444 xMenuController->setPopupMenu(xPopupMenu);
446 Point aPos = _rCEvt.GetMousePosPixel();
447 m_pView->EndAction();
449 xPopupMenu->execute(GetComponentInterface(),
450 css::awt::Rectangle(aPos.X(), aPos.Y(), 1, 1),
451 css::awt::PopupMenuDirection::EXECUTE_DOWN);
453 css::uno::Reference<css::lang::XComponent> xComponent(xMenuController, css::uno::UNO_QUERY);
454 xComponent->dispose();
457 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
459 if ( !m_xSection.is() )
460 return;
462 if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
464 sal_Int32 nColor = m_xSection->getBackColor();
465 if ( nColor == static_cast<sal_Int32>(COL_TRANSPARENT) )
466 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
467 m_pView->SetApplicationDocumentColor(Color(ColorTransparency, nColor));
468 Invalidate(InvalidateFlags::NoChildren|InvalidateFlags::NoErase);
470 else
472 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
473 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
474 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
475 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
477 if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
479 m_pPage->SetLeftBorder(nLeftMargin);
481 else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
483 m_pPage->SetRightBorder(nRightMargin);
485 const Size aOldPageSize = m_pPage->GetSize();
486 sal_Int32 nNewHeight = 5*m_xSection->getHeight();
487 if ( aOldPageSize.Height() != nNewHeight || nPaperWidth != aOldPageSize.Width() )
489 m_pPage->SetSize( Size( nPaperWidth,nNewHeight) );
490 const Size aPageSize = m_pPage->GetSize();
491 m_pView->SetWorkArea( tools::Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
493 impl_adjustObjectSizePosition(nPaperWidth,nLeftMargin,nRightMargin);
494 m_pParent->Invalidate(InvalidateFlags::Update | InvalidateFlags::Transparent);
497 void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth,sal_Int32 i_nLeftMargin,sal_Int32 i_nRightMargin)
501 sal_Int32 nRightBorder = i_nPaperWidth - i_nRightMargin;
502 const sal_Int32 nCount = m_xSection->getCount();
503 for (sal_Int32 i = 0; i < nCount; ++i)
505 uno::Reference< report::XReportComponent> xReportComponent(m_xSection->getByIndex(i),uno::UNO_QUERY_THROW);
506 awt::Point aPos = xReportComponent->getPosition();
507 awt::Size aSize = xReportComponent->getSize();
508 SdrObject* pObject = SdrObject::getSdrObjectFromXShape( xReportComponent );
509 if ( pObject )
511 bool bChanged = false;
513 OObjectBase& rBase = dynamic_cast<OObjectBase&>(*pObject);
514 rBase.EndListening();
515 if ( aPos.X < i_nLeftMargin )
517 aPos.X = i_nLeftMargin;
518 bChanged = true;
520 if ( (aPos.X + aSize.Width) > nRightBorder )
522 aPos.X = nRightBorder - aSize.Width;
523 if ( aPos.X < i_nLeftMargin )
525 aSize.Width += aPos.X - i_nLeftMargin;
526 aPos.X = i_nLeftMargin;
527 // add listener around
528 rBase.StartListening();
529 xReportComponent->setSize(aSize);
530 rBase.EndListening();
532 bChanged = true;
534 if ( aPos.Y < 0 )
535 aPos.Y = 0;
536 if ( bChanged )
538 xReportComponent->setPosition(aPos);
539 correctOverlapping(pObject,*this,false);
540 tools::Rectangle aRet(
541 vcl::unohelper::ConvertToVCLPoint(xReportComponent->getPosition()),
542 vcl::unohelper::ConvertToVCLSize(xReportComponent->getSize()));
543 aRet.setHeight(aRet.getOpenHeight() + 1);
544 aRet.setWidth(aRet.getOpenWidth() + 1);
545 if ( m_xSection.is() && (o3tl::make_unsigned(aRet.getOpenHeight() + aRet.Top()) > m_xSection->getHeight()) )
546 m_xSection->setHeight(aRet.getOpenHeight() + aRet.Top());
548 pObject->RecalcBoundRect();
550 rBase.StartListening();
554 catch(const uno::Exception &)
556 TOOLS_WARN_EXCEPTION( "reportdesign", "OReportSection::impl_adjustObjectSizePosition()");
560 bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
562 return m_pFunc && m_pFunc->handleKeyEvent(_rEvent);
565 void OReportSection::deactivateOle()
567 if (m_pFunc)
568 m_pFunc->deactivateOle(true);
571 void OReportSection::createDefault(const OUString& _sType)
573 SdrObject* pObj = m_pView->GetCreateObj();
574 if ( !pObj )
575 return;
576 createDefault(_sType,pObj);
579 void OReportSection::createDefault(const OUString& _sType,SdrObject* _pObj)
581 bool bAttributesAppliedFromGallery = false;
583 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
585 std::vector< OUString > aObjList;
586 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
588 auto aIter = std::find_if(aObjList.begin(), aObjList.end(),
589 [&_sType](const OUString& rObj) { return rObj.equalsIgnoreAsciiCase(_sType); });
590 if (aIter != aObjList.end())
592 auto i = static_cast<sal_uInt32>(std::distance(aObjList.begin(), aIter));
593 OReportModel aReportModel(nullptr);
595 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aReportModel ) )
597 const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
598 if( pSourceObj )
600 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
601 SfxItemSetFixed<
602 // Ranges from SdrAttrObj:
603 SDRATTR_START, SDRATTR_SHADOW_LAST,
604 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
605 SDRATTR_TEXTDIRECTION,
606 SDRATTR_TEXTDIRECTION,
607 // Graphic attributes, 3D properties,
608 // CustomShape properties:
609 SDRATTR_GRAF_FIRST,
610 SDRATTR_CUSTOMSHAPE_LAST,
611 // Range from SdrTextObj:
612 EE_ITEMS_START, EE_ITEMS_END>
613 aDest( _pObj->getSdrModelFromSdrObject().GetItemPool() );
614 aDest.Set( rSource );
615 _pObj->SetMergedItemSet( aDest );
616 Degree100 nAngle = pSourceObj->GetRotateAngle();
617 if ( nAngle )
618 _pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle );
619 bAttributesAppliedFromGallery = true;
625 if ( !bAttributesAppliedFromGallery )
627 _pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST) );
628 _pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
629 _pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
630 _pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
631 static_cast<SdrObjCustomShape*>(_pObj)->MergeDefaultAttributes( &_sType );
635 uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
637 uno::Reference< report::XReportComponent > xModel;
638 if ( m_pView )
640 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
642 if ( rMarkList.GetMarkCount() == 1 )
644 SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
645 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
646 if ( pObj )
647 xModel = pObj->getReportComponent().get();
650 return xModel;
653 void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
655 if ( !m_pView )
656 return;
658 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
659 const size_t nMarkCount = rMarkList.GetMarkCount();
661 for (size_t i=0; i < nMarkCount; ++i)
663 const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
664 const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
665 if ( pObj )
667 uno::Reference<uno::XInterface> xInterface(pObj->getReportComponent());
668 _rSelection.push_back(xInterface);
673 sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
675 ::Point aDropPos(_rEvt.maPosPixel);
676 const MouseEvent aMouseEvt(aDropPos);
677 if ( m_pFunc->isOverlapping(aMouseEvt) )
678 return DND_ACTION_NONE;
680 if ( _rEvt.mnAction == DND_ACTION_COPY ||
681 _rEvt.mnAction == DND_ACTION_LINK
684 if (!m_pParent) return DND_ACTION_NONE;
685 sal_uInt16 nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
686 if (_rEvt.mnAction == DND_ACTION_COPY )
688 // we must assure, we can't drop in the top section
689 if (nCurrentPosition < 1)
691 return DND_ACTION_NONE;
693 return DND_ACTION_LINK;
695 if (_rEvt.mnAction == DND_ACTION_LINK)
697 // we must assure, we can't drop in the bottom section
698 if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1) )
700 return DND_ACTION_COPY;
702 return DND_ACTION_NONE;
705 else
707 const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
708 if ( svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors)
709 || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
710 return _rEvt.mnAction;
712 const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;
714 return nDropOption;
716 return DND_ACTION_NONE;
720 sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
722 ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
723 const MouseEvent aMouseEvt(aDropPos);
724 if ( m_pFunc->isOverlapping(aMouseEvt) )
725 return DND_ACTION_NONE;
727 sal_Int8 nDropOption = DND_ACTION_NONE;
728 const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
729 const DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
730 bool bMultipleFormat = svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
731 if ( OReportExchange::canExtract(rFlavors) )
733 OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
734 Paste(aCopies,true);
735 nDropOption = DND_ACTION_COPYMOVE;
736 m_pParent->getViewsWindow()->BrkAction();
737 m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
739 else if ( bMultipleFormat
740 || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
742 m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true);
743 m_pView->UnmarkAll();
744 const tools::Rectangle& rRect = m_pView->GetWorkArea();
745 if ( aDropPos.X() < rRect.Left() )
746 aDropPos.setX( rRect.Left() );
747 else if ( aDropPos.X() > rRect.Right() )
748 aDropPos.setX( rRect.Right() );
750 if ( aDropPos.Y() > rRect.Bottom() )
751 aDropPos.setY( rRect.Bottom() );
753 uno::Sequence<beans::PropertyValue> aValues;
754 if ( !bMultipleFormat )
756 svx::ODataAccessDescriptor aDescriptor = svx::OColumnTransferable::extractColumnDescriptor(aDropped);
758 aValues.realloc(1);
759 aValues.getArray()[0].Value <<= aDescriptor.createPropertyValueSequence();
761 else
762 aValues = svx::OMultiColumnTransferable::extractDescriptor(aDropped);
764 for(beans::PropertyValue & propVal : asNonConstRange(aValues))
766 uno::Sequence<beans::PropertyValue> aCurrent;
767 propVal.Value >>= aCurrent;
768 sal_Int32 nLength = aCurrent.getLength();
769 if ( nLength )
771 aCurrent.realloc(nLength + 3);
772 auto pCurrent = aCurrent.getArray();
773 pCurrent[nLength].Name = PROPERTY_POSITION;
774 pCurrent[nLength++].Value <<= vcl::unohelper::ConvertToAWTPoint(aDropPos);
775 // give also the DND Action (Shift|Ctrl) Key to really say what we want
776 pCurrent[nLength].Name = "DNDAction";
777 pCurrent[nLength++].Value <<= _rEvt.mnAction;
779 pCurrent[nLength].Name = "Section";
780 pCurrent[nLength++].Value <<= getSection();
781 propVal.Value <<= aCurrent;
785 // we use this way to create undo actions
786 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
787 rController.executeChecked(SID_ADD_CONTROL_PAIR,aValues);
788 nDropOption = DND_ACTION_COPY;
790 return nDropOption;
793 void OReportSection::stopScrollTimer()
795 m_pFunc->stopScrollTimer();
798 bool OReportSection::isUiActive() const
800 return m_pFunc->isUiActive();
807 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */