LibreOffice Module reportdesign (master)  1
ReportSection.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  * Licensed to the Apache Software Foundation (ASF) under one or more
12  * contributor license agreements. See the NOTICE file distributed
13  * with this work for additional information regarding copyright
14  * ownership. The ASF licenses this file to you under the Apache
15  * License, Version 2.0 (the "License"); you may not use this file
16  * except in compliance with the License. You may obtain a copy of
17  * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 #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>
31 
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>
41 
42 #include <com/sun/star/awt/PopupMenuDirection.hpp>
43 #include <com/sun/star/frame/XPopupMenuController.hpp>
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>
52 
53 #include <vcl/commandevent.hxx>
54 #include <o3tl/safeint.hxx>
55 
56 #include <svl/itempool.hxx>
57 #include <svtools/extcolorcfg.hxx>
58 
59 
60 namespace rptui
61 {
62 
63 using namespace ::com::sun::star;
64 
65 
66 static Color lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
67 {
70 }
71 
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)
82 {
83  //EnableChildTransparentMode();
84  SetHelpId(HID_REPORTSECTION);
85  SetMapMode(MapMode(MapUnit::Map100thMM));
86  SetParentClipMode(ParentClipMode::Clip);
87  EnableChildTransparentMode( false );
88  SetPaintTransparent( false );
89 
90  try
91  {
92  fill();
93  }
94  catch(uno::Exception&)
95  {
96  TOOLS_WARN_EXCEPTION( "reportdesign", "");
97  }
98 
99  m_pFunc.reset(new DlgEdFuncSelect( this ));
100  m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor() );
101 }
102 
103 OReportSection::~OReportSection()
104 {
105  disposeOnce();
106 }
107 
108 void OReportSection::dispose()
109 {
110  m_pPage = nullptr;
111  if ( m_pMulti.is() )
112  m_pMulti->dispose();
113  m_pMulti.clear();
114 
115  if ( m_pReportListener.is() )
116  m_pReportListener->dispose();
117  m_pReportListener.clear();
118  m_pFunc.reset();
119 
120  {
121  if ( m_pView )
122  m_pView->EndListening( *m_pModel );
123  delete m_pView;
124  m_pView = nullptr;
125  }
126  m_pParent.clear();
128 }
129 
130 void OReportSection::Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect )
131 {
132  Window::Paint(rRenderContext, rRect);
133 
134  if ( !(m_pView && m_nPaintEntranceCount == 0))
135  return;
136 
137  ++m_nPaintEntranceCount;
138  // repaint, get PageView and prepare Region
139  SdrPageView* pPgView = m_pView->GetSdrPageView();
140  const vcl::Region aPaintRectRegion(rRect);
141 
142  // #i74769#
143  SdrPaintWindow* pTargetPaintWindow = nullptr;
144 
145  // mark repaint start
146  if (pPgView)
147  {
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()));
153 
154  // do paint (unbuffered) and mark repaint end
155  pPgView->DrawLayer(RPT_LAYER_FRONT, &rRenderContext);
156  pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
157  }
158 
159  m_pView->CompleteRedraw(&rRenderContext, aPaintRectRegion);
160  --m_nPaintEntranceCount;
161 }
162 
163 void OReportSection::fill()
164 {
165  if ( !m_xSection.is() )
166  return;
167 
168  m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection);
169  m_pMulti->addProperty(PROPERTY_BACKCOLOR);
170 
171  m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);
172 
173  m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
174  m_pPage = m_pModel->getPage(m_xSection);
175 
176  m_pView = new OSectionView(
177  *m_pModel,
178  this,
179  m_pParent->getViewsWindow()->getView());
180 
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);
184 
185  // without the following call, no grid is painted
186  m_pView->ShowSdrPage( m_pPage );
187 
188  m_pView->SetMoveSnapOnlyTopLeft( true );
189  ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();
190 
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);
197 
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);
202 
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));
211 
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);
217 
218 // LLA: TODO
219 // m_pPage->SetUpperBorder(-10000);
220 
221  m_pView->SetDesignMode();
222 
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()) ) );
226 }
227 
228 void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
229 {
230  OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
231  if ( !(m_xSection.is() && _aAllreadyCopiedObjects.hasElements()) )
232  return;
233 
234  // stop all drawing actions
235  m_pView->BrkAction();
236 
237  // unmark all objects
238  m_pView->UnmarkAll();
239  const OUString sSectionName = m_xSection->getName();
240  for(const beans::NamedValue& rObject : _aAllreadyCopiedObjects)
241  {
242  if ( _bForce || rObject.Name == sSectionName)
243  {
244  try
245  {
246  uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
247  rObject.Value >>= aCopies;
248  for (const uno::Reference<report::XReportComponent>& rCopy : std::as_const(aCopies))
249  {
251  if ( pObject )
252  {
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 )
261  {
262  bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNewObj) != nullptr;
263  if ( bOverlapping )
264  {
265  aRet.Move(0,aRet.getHeight()+1);
266  pNewObj->SetLogicRect(aRet);
267  }
268  }
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());
273  }
274  }
275  }
276  catch(uno::Exception&)
277  {
278  TOOLS_WARN_EXCEPTION( "reportdesign", "Exception caught while pasting a new object!");
279  }
280  if ( !_bForce )
281  break;
282  }
283  }
284 }
285 
286 void OReportSection::Delete()
287 {
288  if( !m_pView->AreObjectsMarked() )
289  return;
290 
291  m_pView->BrkAction();
292  m_pView->DeleteMarked();
293 }
294 
295 void OReportSection::SetMode( DlgEdMode eNewMode )
296 {
297  if ( eNewMode == m_eMode )
298  return;
299 
300  if ( eNewMode == DlgEdMode::Insert )
301  {
302  m_pFunc.reset(new DlgEdFuncInsert( this ));
303  }
304  else
305  {
306  m_pFunc.reset(new DlgEdFuncSelect( this ));
307  }
308  m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
309  m_pModel->SetReadOnly(false);
310  m_eMode = eNewMode;
311 }
312 
313 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
314 {
315  Copy(_rAllreadyCopiedObjects,false);
316 }
317 
318 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
319 {
320  OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
321  if( !m_pView->AreObjectsMarked() || !m_xSection.is() )
322  return;
323 
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();
327 
328  ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
329  aCopies.reserve(nMark);
330 
331  SdrUndoFactory& rUndo = m_pView->GetModel()->GetSdrUndoFactory();
332 
333  for( size_t i = nMark; i > 0; )
334  {
335  --i;
336  SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
337  OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
338  if ( pObj )
339  {
340  try
341  {
342  SdrObject* pNewObj(pSdrObject->CloneSdrObject(pSdrObject->getSdrModelFromSdrObject()));
343  aCopies.emplace_back(pNewObj->getUnoShape(),uno::UNO_QUERY);
344  if ( _bEraseAnddNoClone )
345  {
346  m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
347  m_pPage->RemoveObject(pSdrObject->GetOrdNum());
348  }
349 
350  }
351  catch(uno::Exception&)
352  {
353  OSL_FAIL("Can't copy report elements!");
354  }
355  }
356  }
357 
358  if ( !aCopies.empty() )
359  {
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());
366  }
367 }
368 
369 void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
370 {
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);
374 }
375 
376 void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
377 {
378  if ( !m_pFunc->MouseButtonUp( rMEvt ) )
379  m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
380 }
381 
382 
383 void OReportSection::MouseMove( const MouseEvent& rMEvt )
384 {
385  m_pFunc->MouseMove( rMEvt );
386 
387 }
388 
389 void OReportSection::SetGridVisible(bool _bVisible)
390 {
391  m_pView->SetGridVisible( _bVisible );
392 }
393 
394 void OReportSection::SelectAll(const sal_uInt16 _nObjectType)
395 {
396  if ( !m_pView )
397  return;
398 
399  if ( _nObjectType == OBJ_NONE )
400  m_pView->MarkAllObj();
401  else
402  {
403  m_pView->UnmarkAll();
404  SdrObjListIter aIter(m_pPage,SdrIterMode::DeepNoGroups);
405  SdrObject* pObjIter = nullptr;
406  while( (pObjIter = aIter.Next()) != nullptr )
407  {
408  if ( pObjIter->GetObjIdentifier() == _nObjectType )
409  m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
410  }
411  }
412 }
413 
414 void OReportSection::Command( const CommandEvent& _rCEvt )
415 {
416  Window::Command(_rCEvt);
417  if (_rCEvt.GetCommand() != CommandEventId::ContextMenu)
418  return;
419 
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))
426  };
427 
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);
432 
433  if (!xMenuController.is())
434  return;
435 
436  css::uno::Reference<css::awt::XPopupMenu> xPopupMenu(
437  xContext->getServiceManager()->createInstanceWithContext(
438  "com.sun.star.awt.PopupMenu", xContext), css::uno::UNO_QUERY);
439 
440  if (!xPopupMenu.is())
441  return;
442 
443  xMenuController->setPopupMenu(xPopupMenu);
444 
445  Point aPos = _rCEvt.GetMousePosPixel();
446  m_pView->EndAction();
447 
448  xPopupMenu->execute(GetComponentInterface(),
449  css::awt::Rectangle(aPos.X(), aPos.Y(), 1, 1),
450  css::awt::PopupMenuDirection::EXECUTE_DOWN);
451 
452  css::uno::Reference<css::lang::XComponent> xComponent(xMenuController, css::uno::UNO_QUERY);
453  xComponent->dispose();
454 }
455 
456 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
457 {
458  if ( !m_xSection.is() )
459  return;
460 
461  if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
462  {
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);
468  }
469  else
470  {
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;
475 
476  if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
477  {
478  m_pPage->SetLeftBorder(nLeftMargin);
479  }
480  else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
481  {
482  m_pPage->SetRightBorder(nRightMargin);
483  }
484  const Size aOldPageSize = m_pPage->GetSize();
485  sal_Int32 nNewHeight = 5*m_xSection->getHeight();
486  if ( aOldPageSize.Height() != nNewHeight || nPaperWidth != aOldPageSize.Width() )
487  {
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()) ) );
491  }
492  impl_adjustObjectSizePosition(nPaperWidth,nLeftMargin,nRightMargin);
493  m_pParent->Invalidate(InvalidateFlags::Update | InvalidateFlags::Transparent);
494  }
495 }
496 void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth,sal_Int32 i_nLeftMargin,sal_Int32 i_nRightMargin)
497 {
498  try
499  {
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)
503  {
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 )
509  {
510  bool bChanged = false;
511 
512  OObjectBase& rBase = dynamic_cast<OObjectBase&>(*pObject);
513  rBase.EndListening();
514  if ( aPos.X < i_nLeftMargin )
515  {
516  aPos.X = i_nLeftMargin;
517  bChanged = true;
518  }
519  if ( (aPos.X + aSize.Width) > nRightBorder )
520  {
521  aPos.X = nRightBorder - aSize.Width;
522  if ( aPos.X < i_nLeftMargin )
523  {
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();
530  }
531  bChanged = true;
532  }
533  if ( aPos.Y < 0 )
534  aPos.Y = 0;
535  if ( bChanged )
536  {
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());
544 
545  pObject->RecalcBoundRect();
546  }
547  rBase.StartListening();
548  }
549  }
550  }
551  catch(const uno::Exception &)
552  {
553  TOOLS_WARN_EXCEPTION( "reportdesign", "OReportSection::impl_adjustObjectSizePosition()");
554  }
555 }
556 
557 bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
558 {
559  return m_pFunc && m_pFunc->handleKeyEvent(_rEvent);
560 }
561 
562 void OReportSection::deactivateOle()
563 {
564  if (m_pFunc)
565  m_pFunc->deactivateOle(true);
566 }
567 
568 void OReportSection::createDefault(const OUString& _sType)
569 {
570  SdrObject* pObj = m_pView->GetCreateObj();
571  if ( !pObj )
572  return;
573  createDefault(_sType,pObj);
574 }
575 
576 void OReportSection::createDefault(const OUString& _sType,SdrObject* _pObj)
577 {
578  bool bAttributesAppliedFromGallery = false;
579 
581  {
582  std::vector< OUString > aObjList;
584  {
585  auto aIter = std::find_if(aObjList.begin(), aObjList.end(),
586  [&_sType](const OUString& rObj) { return rObj.equalsIgnoreAsciiCase(_sType); });
587  if (aIter != aObjList.end())
588  {
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 ) )
594  {
595  const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
596  if( pSourceObj )
597  {
598  const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
599  SfxItemSet aDest(
601  svl::Items<
602  // Ranges from SdrAttrObj:
606  SDRATTR_TEXTDIRECTION,
607  // Graphic attributes, 3D properties,
608  // CustomShape properties:
611  // Range from SdrTextObj:
613  aDest.Set( rSource );
614  _pObj->SetMergedItemSet( aDest );
615  Degree100 nAngle = pSourceObj->GetRotateAngle();
616  if ( nAngle )
617  _pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle );
618  bAttributesAppliedFromGallery = true;
619  }
620  }
621  }
622  }
623  }
624  if ( !bAttributesAppliedFromGallery )
625  {
626  _pObj->SetMergedItem( SvxAdjustItem( SvxAdjust::Center, EE_PARA_JUST) );
629  _pObj->SetMergedItem( makeSdrTextAutoGrowHeightItem( false ) );
630  static_cast<SdrObjCustomShape*>(_pObj)->MergeDefaultAttributes( &_sType );
631  }
632 }
633 
634 uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
635 {
636  uno::Reference< report::XReportComponent > xModel;
637  if ( m_pView )
638  {
639  const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
640 
641  if ( rMarkList.GetMarkCount() == 1 )
642  {
643  SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
644  OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
645  if ( pObj )
646  xModel = pObj->getReportComponent().get();
647  }
648  }
649  return xModel;
650 }
651 
652 void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
653 {
654  if ( !m_pView )
655  return;
656 
657  const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
658  const size_t nMarkCount = rMarkList.GetMarkCount();
659 
660  for (size_t i=0; i < nMarkCount; ++i)
661  {
662  const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
663  const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
664  if ( pObj )
665  {
666  uno::Reference<uno::XInterface> xInterface(pObj->getReportComponent());
667  _rSelection.push_back(xInterface);
668  }
669  }
670 }
671 
672 sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
673 {
674  ::Point aDropPos(_rEvt.maPosPixel);
675  const MouseEvent aMouseEvt(aDropPos);
676  if ( m_pFunc->isOverlapping(aMouseEvt) )
677  return DND_ACTION_NONE;
678 
679  if ( _rEvt.mnAction == DND_ACTION_COPY ||
680  _rEvt.mnAction == DND_ACTION_LINK
681  )
682  {
683  if (!m_pParent) return DND_ACTION_NONE;
684  sal_uInt16 nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
685  if (_rEvt.mnAction == DND_ACTION_COPY )
686  {
687  // we must assure, we can't drop in the top section
688  if (nCurrentPosition < 1)
689  {
690  return DND_ACTION_NONE;
691  }
692  return DND_ACTION_LINK;
693  }
694  if (_rEvt.mnAction == DND_ACTION_LINK)
695  {
696  // we must assure, we can't drop in the bottom section
697  if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1) )
698  {
699  return DND_ACTION_COPY;
700  }
701  return DND_ACTION_NONE;
702  }
703  }
704  else
705  {
706  const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
708  || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
709  return _rEvt.mnAction;
710 
711  const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;
712 
713  return nDropOption;
714  }
715  return DND_ACTION_NONE;
716 }
717 
718 
719 sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
720 {
721  ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
722  const MouseEvent aMouseEvt(aDropPos);
723  if ( m_pFunc->isOverlapping(aMouseEvt) )
724  return DND_ACTION_NONE;
725 
726  sal_Int8 nDropOption = DND_ACTION_NONE;
727  const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
728  const DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
729  bool bMultipleFormat = svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
730  if ( OReportExchange::canExtract(rFlavors) )
731  {
732  OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
733  Paste(aCopies,true);
734  nDropOption = DND_ACTION_COPYMOVE;
735  m_pParent->getViewsWindow()->BrkAction();
736  m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
737  }
738  else if ( bMultipleFormat
739  || svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, ColumnTransferFormatFlags::FIELD_DESCRIPTOR | ColumnTransferFormatFlags::CONTROL_EXCHANGE | ColumnTransferFormatFlags::COLUMN_DESCRIPTOR) )
740  {
741  m_pParent->getViewsWindow()->getView()->setMarked(m_pView, true);
742  m_pView->UnmarkAll();
743  const tools::Rectangle& rRect = m_pView->GetWorkArea();
744  if ( aDropPos.X() < rRect.Left() )
745  aDropPos.setX( rRect.Left() );
746  else if ( aDropPos.X() > rRect.Right() )
747  aDropPos.setX( rRect.Right() );
748 
749  if ( aDropPos.Y() > rRect.Bottom() )
750  aDropPos.setY( rRect.Bottom() );
751 
752  uno::Sequence<beans::PropertyValue> aValues;
753  if ( !bMultipleFormat )
754  {
756 
757  aValues.realloc(1);
758  aValues[0].Value <<= aDescriptor.createPropertyValueSequence();
759  }
760  else
762 
763  for(beans::PropertyValue & propVal : aValues)
764  {
765  uno::Sequence<beans::PropertyValue> aCurrent;
766  propVal.Value >>= aCurrent;
767  sal_Int32 nLength = aCurrent.getLength();
768  if ( nLength )
769  {
770  aCurrent.realloc(nLength + 3);
771  aCurrent[nLength].Name = PROPERTY_POSITION;
772  aCurrent[nLength++].Value <<= AWTPoint(aDropPos);
773  // give also the DND Action (Shift|Ctrl) Key to really say what we want
774  aCurrent[nLength].Name = "DNDAction";
775  aCurrent[nLength++].Value <<= _rEvt.mnAction;
776 
777  aCurrent[nLength].Name = "Section";
778  aCurrent[nLength++].Value <<= getSection();
779  propVal.Value <<= aCurrent;
780  }
781  }
782 
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;
787  }
788  return nDropOption;
789 }
790 
791 void OReportSection::stopScrollTimer()
792 {
793  m_pFunc->stopScrollTimer();
794 }
795 
796 bool OReportSection::isUiActive() const
797 {
798  return m_pFunc->isUiActive();
799 }
800 
801 
802 }
803 
804 
805 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const css::datatransfer::dnd::DropTargetDropEvent maDropEvent
size_t GetMarkCount() const
css::awt::Point AWTPoint(const ::Point &rVCLPoint)
#define PROPERTY_RIGHTMARGIN
Definition: strings.hxx:105
osl::Mutex m_aMutex
void EndDrawLayers(SdrPaintWindow &rPaintWindow, bool bPaintFormLayer)
SdrObject * isOver(const tools::Rectangle &_rRect, SdrPage const &_rPage, SdrView const &_rView, bool _bAllObjects=false, SdrObject const *_pIgnore=nullptr, sal_Int16 _nIgnoreType=0)
checks whether the given rectangle overlapps another OUnoObject object in that view.
Definition: UITools.cxx:867
#define DND_ACTION_COPY
bool Set(const SfxItemSet &, bool bDeep=true)
static constexpr auto Items
tools::Long getWidth() const
signed char sal_Int8
SdrView & GetView()
virtual void NbcRotate(const Point &rRef, Degree100 nAngle, double sn, double cs)
tools::Long const nLeftMargin
::std::vector< DataFlavorEx > DataFlavorExVector
constexpr::Color COL_TRANSPARENT(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
Reference< XFrame > xFrame
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
SdrObject * GetObj(size_t nNum) const
constexpr sal_uInt16 EE_ITEMS_END(EE_FEATURE_END)
#define DND_ACTION_COPYMOVE
SdrMark * GetMark(size_t nNum) const
constexpr TypedWhichId< SvxAdjustItem > EE_PARA_JUST(EE_PARA_START+15)
css::uno::Sequence< css::beans::NamedValue > TSectionElements
Definition: dlgedclip.hxx:39
css::uno::Sequence< css::beans::PropertyValue > const & createPropertyValueSequence()
virtual SdrObjKind GetObjIdentifier() const
virtual void dispose() override
constexpr sal_uInt16 SDRATTR_MISC_LAST(SDRATTR_TEXT_CHAINNEXTNAME)
EmbeddedObjectRef * pObject
void FreezeIdRanges()
const css::uno::Reference< css::report::XReportComponent > & getReportComponent() const
Definition: RptObject.hxx:105
constexpr sal_uInt16 SDRATTR_START(XATTR_START)
SdrOnOffItem makeSdrTextAutoGrowHeightItem(bool bAuto)
virtual const tools::Rectangle & GetSnapRect() const
virtual std::unique_ptr< SdrUndoAction > CreateUndoDeleteObject(SdrObject &rObject, bool bOrdNumDirect=false)
tools::Long getHeight() const
OReportSection(OReportSection const &)=delete
constexpr tools::Long Width() const
std::deque< AttachedObject_Impl > aObjList
tools::Long Left() const
OutputDevice & GetTargetOutputDevice()
#define PROPERTY_LEFTMARGIN
Definition: strings.hxx:104
int nCount
#define DND_ACTION_NONE
tools::Long Bottom() const
constexpr SdrLayerID RPT_LAYER_FRONT(0)
static bool extractColumnDescriptor(const TransferableDataHelper &_rData, OUString &_rDatasource, OUString &_rDatabaseLocation, OUString &_rConnectionResource, sal_Int32 &_nCommandType, OUString &_rCommand, OUString &_rFieldName)
void SetMergedItemSet(const SfxItemSet &rSet, bool bClearAllItems=false)
SdrPageView * ShowSdrPage(SdrPage *pPage) override
constexpr tools::Long getHeight() const
void setX(tools::Long x)
static bool canExtractColumnDescriptor(const DataFlavorExVector &_rFlavors, ColumnTransferFormatFlags _nFormats)
const Color & GetApplicationDocumentColor() const
const Size & getGridSizeFine() const
Definition: DesignView.hxx:158
SdrObject * GetMarkedSdrObj() const
WinBits const WB_DIALOGCONTROL
SDRTEXTHORZADJUST_BLOCK
constexpr TypedWhichId< SvxWritingModeItem > SDRATTR_TEXTDIRECTION(SDRATTR_NOTPERSIST_FIRST+34)
#define TOOLS_WARN_EXCEPTION(area, stream)
#define CFG_REPORTDESIGNER
Definition: strings.hxx:251
SdrPaintWindow * BeginDrawLayers(OutputDevice *pOut, const vcl::Region &rReg, bool bDisableIntersect=false)
int i
#define PROPERTY_PAPERSIZE
Definition: strings.hxx:62
void correctOverlapping(SdrObject *pControl, OReportSection const &_aReportSection, bool _bInsert=true)
ensures that no control overlaps the given one.
Definition: UITools.cxx:997
#define HID_REPORTSECTION
Definition: helpids.h:30
#define DBOVERLAPPEDCONTROL
Definition: strings.hxx:267
const SdrPage * GetPage(sal_uInt16 nPgNum) const
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
constexpr sal_uInt16 EE_ITEMS_START(OWN_ATTR_VALUE_END+1)
CommandEventId GetCommand() const
SdrModel & getSdrModelFromSdrObject() const
sal_uInt32 GetOrdNum() const
constexpr sal_uInt16 SDRATTR_GRAF_FIRST(SDRATTR_NOTPERSIST_LAST+1)
css::uno::Reference< css::uno::XInterface > createDefault(css::uno::Reference< css::uno::XComponentContext > const &context)
inline::Point VCLPoint(const css::awt::Point &rAWTPoint)
void SetMergedItem(const SfxPoolItem &rItem)
ColorTransparency
virtual void RecalcBoundRect()
#define DND_ACTION_LINK
tools::Long Top() const
static bool FillObjListTitle(const sal_uInt32 nThemeId, std::vector< OUString > &rList)
const Point & GetMousePosPixel() const
SdrObject * Next()
inline::Size VCLSize(const css::awt::Size &rAWTSize)
constexpr sal_uInt16 SDRATTR_SHADOW_LAST(SDRATTR_SHADOWBLUR)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
const Size & getGridSizeCoarse() const
Definition: DesignView.hxx:157
::rtl::Reference< comphelper::OPropertyChangeMultiplexer > addStyleListener(const css::uno::Reference< css::report::XReportDefinition > &_xReportDefinition,::comphelper::OPropertyChangeListener *_pListener)
add a listener for the properties size, left margin, right margin to the page style ...
constexpr tools::Long Height() const
void setWidth(tools::Long n)
const SfxItemSet & GetMergedItemSet() const
virtual SdrObject * CloneSdrObject(SdrModel &rTargetModel) const
void DrawLayer(SdrLayerID nID, OutputDevice *pGivenTarget, sdr::contact::ViewObjectContactRedirector *pRedirector=nullptr, const tools::Rectangle &rRect=tools::Rectangle(), basegfx::B2IRectangle const *pPageFrame=nullptr)
static bool canExtractDescriptor(const DataFlavorExVector &_rFlavors)
tools::Long const nRightMargin
#define PROPERTY_POSITION
Definition: strings.hxx:264
void Move(tools::Long nHorzMoveDelta, tools::Long nVertMoveDelta)
ExtendedColorConfigValue GetColorValue(const OUString &_sComponentName, const OUString &_sName) const
constexpr sal_uInt16 SDRATTR_CUSTOMSHAPE_LAST(SDRATTR_CUSTOMSHAPE_GEOMETRY)
Reference< XModel > xModel
const SfxItemPool & GetItemPool() const
virtual Degree100 GetRotateAngle() const
sal_Int32 nLength
#define PROPERTY_BACKCOLOR
Definition: strings.hxx:38
static bool GetSdrObj(std::u16string_view rThemeName, sal_uInt32 nSdrModelPos, SdrModel *pModel, BitmapEx *pThumb=nullptr)
sal_Int8 mnAction
constexpr sal_uInt16 SDRATTR_MISC_FIRST(SDRATTR_CAPTION_LAST+1)
OBJ_NONE
SAL_DLLPRIVATE void DrawWallpaper(tools::Long nX, tools::Long nY, tools::Long nWidth, tools::Long nHeight, const Wallpaper &rWallpaper)
static css::uno::Sequence< css::beans::PropertyValue > extractDescriptor(const TransferableDataHelper &_rData)
tools::Long Right() const
static Color lcl_getOverlappedControlColor()
Point Center() const
void setHeight(tools::Long n)
static sal_uInt32 GetSdrObjCount(std::u16string_view rThemeName)
SDRTEXTVERTADJUST_CENTER
const DataFlavorExVector & GetDataFlavorExVector() const