sync master with lastest vba changes
[ooovba.git] / reportdesign / source / ui / report / ReportSection.cxx
blob26d6895c5411994061463fdb47c981179381ffcc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ReportSection.cxx,v $
10 * $Revision: 1.11.18.3 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "ReportSection.hxx"
32 #include "ReportWindow.hxx"
33 #include "DesignView.hxx"
34 #include "uistrings.hrc"
35 #include "RptObject.hxx"
36 #include "RptModel.hxx"
37 #include "SectionView.hxx"
38 #include "RptPage.hxx"
39 #include "ReportController.hxx"
40 #include "UITools.hxx"
41 #include "ViewsWindow.hxx"
43 #include <svx/svdpagv.hxx>
44 #include <svx/eeitemid.hxx>
45 #include <svx/adjitem.hxx>
46 #include <svx/sdrpaintwindow.hxx>
47 #include <svx/unoshape.hxx>
48 #include <svx/gallery.hxx>
49 #include <svx/svxids.hrc>
50 #include <svx/svditer.hxx>
51 #include <svx/dbaexchange.hxx>
53 #include <vcl/svapp.hxx>
55 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
56 #include <toolkit/helper/convert.hxx>
57 #include "RptDef.hxx"
58 #include "SectionWindow.hxx"
59 #include "helpids.hrc"
60 #include "RptResId.hrc"
61 #include "dlgedclip.hxx"
62 #include "UndoActions.hxx"
63 #include "rptui_slotid.hrc"
65 #include <connectivity/dbtools.hxx>
67 #include <vcl/lineinfo.hxx>
68 #include "ColorChanger.hxx"
70 #include <svtools/itempool.hxx>
71 #include <svtools/extcolorcfg.hxx>
72 #include <unotools/confignode.hxx>
73 #include <framework/imageproducer.hxx>
75 // =============================================================================
76 namespace rptui
78 // =============================================================================
79 using namespace ::com::sun::star;
80 // -----------------------------------------------------------------------------
82 sal_Int32 lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
84 svtools::ExtendedColorConfig aConfig;
85 sal_Int32 nColor = aConfig.GetColorValue(CFG_REPORTDESIGNER, DBOVERLAPPEDCONTROL).getColor();
86 return nColor;
88 //------------------------------------------------------------------------------
89 DBG_NAME( rpt_OReportSection )
90 OReportSection::OReportSection(OSectionWindow* _pParent,const uno::Reference< report::XSection >& _xSection)
91 : Window(_pParent,WB_DIALOGCONTROL)
92 , ::comphelper::OPropertyChangeListener(m_aMutex)
93 , DropTargetHelper(this)
94 ,m_pPage(NULL)
95 ,m_pView(NULL)
96 ,m_pParent(_pParent)
97 ,m_pFunc(NULL)
98 ,m_pMulti(NULL)
99 ,m_pReportListener(NULL)
100 ,m_xSection(_xSection)
101 ,m_eMode(RPTUI_SELECT)
102 ,m_bDialogModelChanged(FALSE)
103 ,m_bInDrag(sal_False)
105 DBG_CTOR( rpt_OReportSection,NULL);
106 EnableChildTransparentMode();
107 SetHelpId(HID_REPORTSECTION);
108 SetMapMode( MapMode( MAP_100TH_MM ) );
112 fill();
114 catch(uno::Exception&)
116 OSL_ENSURE(0,"Exception catched!");
119 m_pFunc.reset(new DlgEdFuncSelect( this ));
120 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( /* m_pParent->getViewsWindow()->getView()->getReportView()->getController().getORB() */ ) );
122 //------------------------------------------------------------------------------
123 OReportSection::~OReportSection()
125 DBG_DTOR( rpt_OReportSection,NULL);
126 m_pPage = NULL;
127 //m_pModel->GetUndoEnv().RemoveSection(m_xSection.get());
128 if ( m_pMulti.is() )
129 m_pMulti->dispose();
131 if ( m_pReportListener.is() )
132 m_pReportListener->dispose();
133 m_pFunc = ::std::auto_ptr<DlgEdFunc>();
136 ::std::auto_ptr<OSectionView> aTemp( m_pView);
137 if ( m_pView )
138 m_pView->EndListening( *m_pModel );
139 m_pView = NULL;
141 /*m_pModel->DeletePage(m_pPage->GetPageNum());*/
143 //------------------------------------------------------------------------------
144 void OReportSection::Paint( const Rectangle& rRect )
146 Window::Paint(rRect);
148 if ( m_pView )
150 // repaint, get PageView and prepare Region
151 SdrPageView* pPgView = m_pView->GetSdrPageView();
152 const Region aPaintRectRegion(rRect);
154 // #i74769#
155 SdrPaintWindow* pTargetPaintWindow = 0;
157 // mark repaint start
158 if(pPgView)
160 pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(this, aPaintRectRegion);
161 OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
162 // draw background self using wallpaper
163 OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
164 sal_Int32 nColor = m_xSection->getBackColor();
165 if ( nColor == (sal_Int32)COL_TRANSPARENT )
166 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
167 rTargetOutDev.DrawWallpaper(rRect, Wallpaper(Color(nColor)));
170 // do paint (unbuffered) and mark repaint end
171 if(pPgView)
173 pPgView->DrawLayer(0, this);
174 pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
177 m_pView->CompleteRedraw(this,aPaintRectRegion);
180 //------------------------------------------------------------------------------
181 void OReportSection::Resize()
183 Window::Resize();
184 if ( m_xSection.is() && m_pPage && m_pView )
186 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
187 m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
188 const Size aPageSize = m_pPage->GetSize();
189 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
190 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
191 m_pView->SetWorkArea( Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
194 //------------------------------------------------------------------------------
195 void OReportSection::fill()
197 if ( !m_xSection.is() )
198 return;
200 m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection.get());
201 m_pMulti->addProperty(PROPERTY_BACKCOLOR);
203 m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);
205 m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
206 m_pPage = m_pModel->getPage(m_xSection);
208 m_pView = new OSectionView( m_pModel.get(), this, m_pParent->getViewsWindow()->getView() );
210 // #i93597# tell SdrPage that only left and right page border is defined
211 // instead of the full rectangle definition
212 m_pPage->setPageBorderOnlyLeftRight(true);
214 // without the following call, no grid is painted
215 m_pView->ShowSdrPage( m_pPage );
217 m_pView->SetMoveSnapOnlyTopLeft( TRUE );
218 ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();
220 // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
221 // is only for visualisation and has nothing to do with the actual snap
222 const Size aGridSizeCoarse(pDesignView->getGridSizeCoarse());
223 const Size aGridSizeFine(pDesignView->getGridSizeFine());
224 m_pView->SetGridCoarse(aGridSizeCoarse);
225 m_pView->SetGridFine(aGridSizeFine);
227 // #i93595# set snap grid width to snap to all existing subdivisions
228 const Fraction aX(aGridSizeFine.A());
229 const Fraction aY(aGridSizeFine.B());
230 m_pView->SetSnapGridWidth(aX, aY);
232 m_pView->SetGridSnap( pDesignView->isGridSnap() );
233 m_pView->SetGridFront( FALSE );
234 m_pView->SetDragStripes( TRUE );
235 m_pView->SetPageVisible();
236 sal_Int32 nColor = m_xSection->getBackColor();
237 if ( nColor == (sal_Int32)COL_TRANSPARENT )
238 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
239 m_pView->SetApplicationDocumentColor(nColor);
241 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_LEFTMARGIN);
242 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_RIGHTMARGIN);
243 m_pPage->SetLftBorder(nLeftMargin);
244 m_pPage->SetRgtBorder(nRightMargin);
246 // LLA: TODO
247 // m_pPage->SetUppBorder(-10000);
249 m_pView->SetDesignMode( TRUE );
251 m_pView->StartListening( *m_pModel );
252 /*Resize();*/
253 if ( m_xSection.is() && m_pPage && m_pView )
255 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
256 m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
257 const Size aPageSize = m_pPage->GetSize();
258 const sal_Int32 nWorkAreaLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
259 const sal_Int32 nWorkAreaRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
260 m_pView->SetWorkArea( Rectangle( Point( nWorkAreaLeftMargin, 0), Size(aPageSize.Width() - nWorkAreaLeftMargin - nWorkAreaRightMargin,aPageSize.Height()) ) );
261 } // if ( m_xSection.is() && m_pPage && m_pView )
263 //SetBackground( Wallpaper( COL_BLUE ));
265 // -----------------------------------------------------------------------------
266 void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
268 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
269 if ( m_xSection.is() && _aAllreadyCopiedObjects.getLength() )
271 // stop all drawing actions
272 m_pView->BrkAction();
274 // unmark all objects
275 m_pView->UnmarkAll();
276 const ::rtl::OUString sSectionName = m_xSection->getName();
277 const sal_Int32 nLength = _aAllreadyCopiedObjects.getLength();
278 const beans::NamedValue* pIter = _aAllreadyCopiedObjects.getConstArray();
279 const beans::NamedValue* pEnd = pIter + nLength;
280 for(;pIter != pEnd;++pIter)
282 if ( _bForce || pIter->Name == sSectionName)
286 uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
287 pIter->Value >>= aCopies;
288 const uno::Reference<report::XReportComponent>* pCopiesIter = aCopies.getConstArray();
289 const uno::Reference<report::XReportComponent>* pCopiesEnd = pCopiesIter + aCopies.getLength();
290 for (;pCopiesIter != pCopiesEnd ; ++pCopiesIter)
292 SvxShape* pShape = SvxShape::getImplementation( *pCopiesIter );
293 SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
294 if ( pObject )
296 SdrObject* pNeuObj = pObject->Clone();
298 pNeuObj->SetPage( m_pPage );
299 pNeuObj->SetModel( m_pModel.get() );
300 SdrInsertReason aReason(SDRREASON_VIEWCALL);
301 m_pPage->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
303 Rectangle aRet(VCLPoint((*pCopiesIter)->getPosition()),VCLSize((*pCopiesIter)->getSize()));
304 aRet.setHeight(aRet.getHeight() + 1);
305 aRet.setWidth(aRet.getWidth() + 1);
306 bool bOverlapping = true;
307 while ( bOverlapping )
309 bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNeuObj) != NULL;
310 if ( bOverlapping )
312 aRet.Move(0,aRet.getHeight()+1);
313 pNeuObj->SetLogicRect(aRet);
314 //(*pCopiesIter)->setPositionY(aRet.Top());
317 m_pView->AddUndo( m_pView->GetModel()->GetSdrUndoFactory().CreateUndoNewObject( *pNeuObj ) );
318 m_pView->MarkObj( pNeuObj, m_pView->GetSdrPageView() );
319 if ( m_xSection.is() && (static_cast<sal_uInt32>(aRet.getHeight() + aRet.Top()) > m_xSection->getHeight()) )
320 m_xSection->setHeight(aRet.getHeight() + aRet.Top());
324 catch(uno::Exception&)
326 OSL_ENSURE(0,"Exception caught while pasting a new object!");
328 if ( !_bForce )
329 break;
334 //----------------------------------------------------------------------------
335 void OReportSection::Delete()
337 if( !m_pView->AreObjectsMarked() )
338 return;
340 m_pView->BrkAction();
341 m_pView->DeleteMarked();
343 //----------------------------------------------------------------------------
344 void OReportSection::SetMode( DlgEdMode eNewMode )
346 if ( eNewMode != m_eMode )
348 if ( eNewMode == RPTUI_INSERT )
350 m_pFunc.reset(new DlgEdFuncInsert( this ));
352 else
354 m_pFunc.reset(new DlgEdFuncSelect( this ));
356 m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
357 m_pModel->SetReadOnly(eNewMode == RPTUI_READONLY);
358 m_eMode = eNewMode;
361 // -----------------------------------------------------------------------------
362 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
364 Copy(_rAllreadyCopiedObjects,false);
366 //----------------------------------------------------------------------------
367 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
369 OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
370 if( !m_pView->AreObjectsMarked() || !m_xSection.is() )
371 return;
373 // stop all drawing actions
374 //m_pView->BrkAction();
376 // insert control models of marked objects into clipboard dialog model
377 const SdrMarkList& rMarkedList = m_pView->GetMarkedObjectList();
378 const ULONG nMark = rMarkedList.GetMarkCount();
380 ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
381 aCopies.reserve(nMark);
383 SdrUndoFactory& rUndo = m_pView->GetModel()->GetSdrUndoFactory();
385 for( ULONG i = nMark; i > 0; )
387 --i;
388 SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
389 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
390 if ( pObj )
394 SdrObject* pNeuObj = pSdrObject->Clone();
395 aCopies.push_back(uno::Reference<report::XReportComponent>(pNeuObj->getUnoShape(),uno::UNO_QUERY));
396 if ( _bEraseAnddNoClone )
398 m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
399 m_pPage->RemoveObject(pSdrObject->GetOrdNum());
403 catch(uno::Exception&)
405 OSL_ENSURE(0,"Can't copy report elements!");
408 } // for( ULONG i = 0; i < nMark; i++ )
410 if ( !aCopies.empty() )
412 ::std::reverse(aCopies.begin(),aCopies.end());
413 const sal_Int32 nLength = _rAllreadyCopiedObjects.getLength();
414 _rAllreadyCopiedObjects.realloc( nLength + 1);
415 beans::NamedValue* pNewValue = _rAllreadyCopiedObjects.getArray() + nLength;
416 pNewValue->Name = m_xSection->getName();
417 pNewValue->Value <<= uno::Sequence< uno::Reference<report::XReportComponent> >(&(*aCopies.begin()),aCopies.size());
420 //----------------------------------------------------------------------------
421 void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
423 m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
424 m_pFunc->MouseButtonDown( rMEvt );
425 Window::MouseButtonDown(rMEvt);
427 //----------------------------------------------------------------------------
428 void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
430 if ( !m_pFunc->MouseButtonUp( rMEvt ) )
431 m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
434 //----------------------------------------------------------------------------
436 void OReportSection::MouseMove( const MouseEvent& rMEvt )
438 m_pFunc->MouseMove( rMEvt );
440 //----------------------------------------------------------------------------
441 void OReportSection::SetGridVisible(BOOL _bVisible)
443 m_pView->SetGridVisible( _bVisible );
445 //------------------------------------------------------------------------------
446 void OReportSection::SelectAll(const sal_uInt16 _nObjectType)
448 if ( m_pView )
450 if ( _nObjectType == OBJ_NONE )
451 m_pView->MarkAllObj();
452 else
454 m_pView->UnmarkAll();
455 SdrObjListIter aIter(*m_pPage,IM_DEEPNOGROUPS);
456 SdrObject* pObjIter = NULL;
457 while( (pObjIter = aIter.Next()) != NULL )
459 if ( pObjIter->GetObjIdentifier() == _nObjectType )
460 m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
465 void lcl_insertMenuItemImages(PopupMenu& rContextMenu,OReportController& rController,const uno::Reference< report::XReportDefinition>& _xReportDefinition,uno::Reference<frame::XFrame>& _rFrame,BOOL _bHiContrast)
467 const USHORT nCount = rContextMenu.GetItemCount();
468 for (USHORT i = 0; i < nCount; ++i)
470 if ( MENUITEM_SEPARATOR != rContextMenu.GetItemType(i))
472 const USHORT nId = rContextMenu.GetItemId(i);
473 PopupMenu* pPopupMenu = rContextMenu.GetPopupMenu( nId );
474 if ( pPopupMenu )
476 lcl_insertMenuItemImages(*pPopupMenu,rController,_xReportDefinition,_rFrame,_bHiContrast);
478 else
480 const ::rtl::OUString sCommand = rContextMenu.GetItemCommand(nId);
481 rContextMenu.SetItemImage(nId,framework::GetImageFromURL(_rFrame,sCommand,FALSE,_bHiContrast));
482 if ( nId == SID_PAGEHEADERFOOTER )
484 String sText = String(ModuleRes((_xReportDefinition.is() && _xReportDefinition->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE : RID_STR_PAGEHEADERFOOTER_INSERT));
485 rContextMenu.SetItemText(nId,sText);
487 else if ( nId == SID_REPORTHEADERFOOTER )
489 String sText = String(ModuleRes((_xReportDefinition.is() && _xReportDefinition->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE : RID_STR_REPORTHEADERFOOTER_INSERT));
490 rContextMenu.SetItemText(nId,sText);
493 rContextMenu.CheckItem(nId,rController.isCommandChecked(nId));
494 rContextMenu.EnableItem(nId,rController.isCommandEnabled(nId));
496 } // for (USHORT i = 0; i < nCount; ++i)
498 //----------------------------------------------------------------------------
499 void OReportSection::Command( const CommandEvent& _rCEvt )
501 Window::Command(_rCEvt);
502 switch (_rCEvt.GetCommand())
504 case COMMAND_CONTEXTMENU:
506 const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
507 BOOL bHiContrast = rSettings.GetMenuColor().IsDark();
508 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
509 uno::Reference<frame::XFrame> xFrame = rController.getFrame();
510 PopupMenu aContextMenu( ModuleRes( RID_MENU_REPORT ) );
511 uno::Reference< report::XReportDefinition> xReportDefinition = getSection()->getReportDefinition();
513 lcl_insertMenuItemImages(aContextMenu,rController,xReportDefinition,xFrame,bHiContrast);
515 Point aPos = _rCEvt.GetMousePosPixel();
516 m_pView->EndAction();
517 const USHORT nId = aContextMenu.Execute(this, aPos);
518 if ( nId )
520 uno::Sequence< beans::PropertyValue> aArgs;
521 if ( nId == SID_ATTR_CHAR_COLOR_BACKGROUND )
523 aArgs.realloc(1);
524 aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Selection"));
525 aArgs[0].Value <<= m_xSection;
527 rController.executeChecked(nId,aArgs);
530 break;
533 // -----------------------------------------------------------------------------
534 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
536 if ( m_xSection.is() )
538 if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
540 sal_Int32 nColor = m_xSection->getBackColor();
541 if ( nColor == (sal_Int32)COL_TRANSPARENT )
542 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
543 m_pView->SetApplicationDocumentColor(nColor);
544 Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_NOERASE);
546 else
548 uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
549 if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
551 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
552 m_pPage->SetLftBorder(nLeftMargin);
554 else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
556 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
557 m_pPage->SetRgtBorder(nRightMargin);
562 const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
563 const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
564 const sal_Int32 nPaperWidth = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
565 const sal_Int32 nCount = m_xSection->getCount();
566 for (sal_Int32 i = 0; i < nCount; ++i)
568 bool bChanged = false;
569 uno::Reference< report::XReportComponent> xReportComponent(m_xSection->getByIndex(i),uno::UNO_QUERY_THROW);
570 awt::Point aPos = xReportComponent->getPosition();
571 awt::Size aSize = xReportComponent->getSize();
572 SvxShape* pShape = SvxShape::getImplementation( xReportComponent );
573 SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
574 if ( pObject )
576 OObjectBase* pBase = dynamic_cast<OObjectBase*>(pObject);
577 pBase->EndListening(sal_False);
578 if ( aPos.X < nLeftMargin )
580 aPos.X = nLeftMargin;
581 bChanged = true;
583 if ( (aPos.X + aSize.Width) > (nPaperWidth - nRightMargin) )
585 aPos.X = nPaperWidth - nRightMargin - aSize.Width;
586 if ( aPos.X < nLeftMargin )
588 aSize.Width += aPos.X - nLeftMargin;
589 aPos.X = nLeftMargin;
590 // add listener around
591 pBase->StartListening();
592 xReportComponent->setSize(aSize);
593 pBase->EndListening(sal_False);
595 bChanged = true;
597 if ( aPos.Y < 0 )
598 aPos.Y = 0;
599 if ( bChanged )
601 xReportComponent->setPosition(aPos);
602 correctOverlapping(pObject,*this,false);
603 Rectangle aRet(VCLPoint(xReportComponent->getPosition()),VCLSize(xReportComponent->getSize()));
604 aRet.setHeight(aRet.getHeight() + 1);
605 aRet.setWidth(aRet.getWidth() + 1);
606 if ( m_xSection.is() && (static_cast<sal_uInt32>(aRet.getHeight() + aRet.Top()) > m_xSection->getHeight()) )
607 m_xSection->setHeight(aRet.getHeight() + aRet.Top());
609 pBase->StartListening();
611 } // for (sal_Int32 i = 0; i < nCount; ++i)
613 catch(uno::Exception)
615 OSL_ENSURE(0,"Exception caught: OReportSection::_propertyChanged(");
618 Resize();
622 //------------------------------------------------------------------------------
623 sal_Bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
625 return m_pFunc.get() ? m_pFunc->handleKeyEvent(_rEvent) : sal_False;
627 // -----------------------------------------------------------------------------
628 void OReportSection::deactivateOle()
630 if ( m_pFunc.get() )
631 m_pFunc->deactivateOle(true);
633 // -----------------------------------------------------------------------------
634 void OReportSection::createDefault(const ::rtl::OUString& _sType)
636 SdrObject* pObj = m_pView->GetCreateObj();//rMarkList.GetMark(0)->GetObj();
637 if ( !pObj )
638 return;
639 createDefault(_sType,pObj);
641 // -----------------------------------------------------------------------------
642 void OReportSection::createDefault(const ::rtl::OUString& _sType,SdrObject* _pObj)
644 sal_Bool bAttributesAppliedFromGallery = sal_False;
646 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
648 std::vector< rtl::OUString > aObjList;
649 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
651 std::vector< rtl::OUString >::iterator aIter = aObjList.begin();
652 std::vector< rtl::OUString >::iterator aEnd = aObjList.end();
653 for (sal_uInt32 i=0 ; aIter != aEnd; ++aIter,++i)
655 if ( aIter->equalsIgnoreAsciiCase( _sType ) )
657 OReportModel aReportModel(NULL);
658 SfxItemPool& rPool = aReportModel.GetItemPool();
659 rPool.FreezeIdRanges();
660 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aReportModel ) )
662 const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
663 if( pSourceObj )
665 const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
666 SfxItemSet aDest( _pObj->GetModel()->GetItemPool(), // ranges from SdrAttrObj
667 SDRATTR_START, SDRATTR_SHADOW_LAST,
668 SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
669 SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
670 // Graphic Attributes
671 SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
672 // 3d Properties
673 SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
674 // CustomShape properties
675 SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
676 // range from SdrTextObj
677 EE_ITEMS_START, EE_ITEMS_END,
678 // end
679 0, 0);
680 aDest.Set( rSource );
681 _pObj->SetMergedItemSet( aDest );
682 sal_Int32 nAngle = pSourceObj->GetRotateAngle();
683 if ( nAngle )
685 double a = nAngle * F_PI18000;
686 _pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
688 bAttributesAppliedFromGallery = sal_True;
691 break;
696 if ( !bAttributesAppliedFromGallery )
698 _pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER ,ITEMID_ADJUST) );
699 _pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
700 _pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
701 _pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
702 ((SdrObjCustomShape*)_pObj)->MergeDefaultAttributes( &_sType );
705 // -----------------------------------------------------------------------------
706 uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
708 uno::Reference< report::XReportComponent > xModel;
709 if ( m_pView )
711 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
712 sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
714 if ( nMarkCount == 1 )
716 SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
717 OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
718 if ( pObj )
719 xModel = pObj->getReportComponent().get();
722 return xModel;
724 // -----------------------------------------------------------------------------
725 void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
727 if ( m_pView )
729 const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
730 const sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
732 for (sal_uInt32 i=0; i < nMarkCount; ++i)
734 const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
735 const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
736 if ( pObj )
737 _rSelection.push_back(pObj->getReportComponent());
741 // -----------------------------------------------------------------------------
742 sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
744 OSL_TRACE("AcceptDrop::DropEvent.Action %i\n", _rEvt.mnAction);
746 ::Point aDropPos(_rEvt.maPosPixel);
747 const MouseEvent aMouseEvt(aDropPos);
748 if ( m_pFunc->isOverlapping(aMouseEvt) )
749 return DND_ACTION_NONE;
751 if ( _rEvt.mnAction == DND_ACTION_COPY ||
752 _rEvt.mnAction == DND_ACTION_LINK
755 if (!m_pParent) return DND_ACTION_NONE;
756 USHORT nCurrentPosition = 0;
757 nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
758 if (_rEvt.mnAction == DND_ACTION_COPY )
760 // we must assure, we can't drop in the top section
761 if (nCurrentPosition < 1)
763 return DND_ACTION_NONE;
765 return DND_ACTION_LINK;
767 if (_rEvt.mnAction == DND_ACTION_LINK)
769 // we must assure, we can't drop in the bottom section
770 if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1) )
772 return DND_ACTION_COPY;
774 return DND_ACTION_NONE;
777 else
779 const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
780 if ( ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors)
781 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR) )
782 return _rEvt.mnAction;
784 const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;
786 return nDropOption;
788 return DND_ACTION_NONE;
791 // -----------------------------------------------------------------------------
792 sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
794 OSL_TRACE("ExecuteDrop::DropEvent.Action %i\n", _rEvt.mnAction);
795 ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
796 const MouseEvent aMouseEvt(aDropPos);
797 if ( m_pFunc->isOverlapping(aMouseEvt) )
798 return DND_ACTION_NONE;
800 sal_Int8 nDropOption = DND_ACTION_NONE;
801 const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
802 DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
803 bool bMultipleFormat = ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
804 if ( OReportExchange::canExtract(rFlavors) )
806 OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
807 Paste(aCopies,true);
808 nDropOption = DND_ACTION_COPYMOVE;
809 m_pParent->getViewsWindow()->BrkAction();
810 m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
811 //m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
812 } // if ( OReportExchange::canExtract(rFlavors) )
813 else if ( bMultipleFormat
814 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR) )
816 m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
817 m_pView->UnmarkAll();
818 const Rectangle& rRect = m_pView->GetWorkArea();
819 if ( aDropPos.X() < rRect.Left() )
820 aDropPos.X() = rRect.Left();
821 else if ( aDropPos.X() > rRect.Right() )
822 aDropPos.X() = rRect.Right();
824 if ( aDropPos.Y() > rRect.Bottom() )
825 aDropPos.Y() = rRect.Bottom();
827 uno::Sequence<beans::PropertyValue> aValues;
828 if ( !bMultipleFormat )
830 ::svx::ODataAccessDescriptor aDescriptor = ::svx::OColumnTransferable::extractColumnDescriptor(aDropped);
832 aValues.realloc(1);
833 aValues[0].Value <<= aDescriptor.createPropertyValueSequence();
834 } // if ( !bMultipleFormat )
835 else
836 aValues = ::svx::OMultiColumnTransferable::extractDescriptor(aDropped);
838 beans::PropertyValue* pIter = aValues.getArray();
839 beans::PropertyValue* pEnd = pIter + aValues.getLength();
840 for(;pIter != pEnd; ++pIter)
842 uno::Sequence<beans::PropertyValue> aCurrent;
843 pIter->Value >>= aCurrent;
844 sal_Int32 nLength = aCurrent.getLength();
845 if ( nLength )
847 aCurrent.realloc(nLength + 3);
848 aCurrent[nLength].Name = PROPERTY_POSITION;
849 aCurrent[nLength++].Value <<= AWTPoint(aDropPos);
850 // give also the DND Action (Shift|Ctrl) Key to really say what we want
851 aCurrent[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DNDAction"));
852 aCurrent[nLength++].Value <<= _rEvt.mnAction;
854 aCurrent[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Section"));
855 aCurrent[nLength++].Value <<= getSection();
856 pIter->Value <<= aCurrent;
860 // we use this way to create undo actions
861 OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
862 rController.executeChecked(SID_ADD_CONTROL_PAIR,aValues);
863 nDropOption = DND_ACTION_COPY;
865 return nDropOption;
867 // -----------------------------------------------------------------------------
868 void OReportSection::stopScrollTimer()
870 m_pFunc->stopScrollTimer();
872 // -----------------------------------------------------------------------------
873 bool OReportSection::isUiActive() const
875 return m_pFunc->isUiActive();
877 // -----------------------------------------------------------------------------
878 // =============================================================================
880 // =============================================================================