1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
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 // =============================================================================
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();
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)
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
) );
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
);
127 //m_pModel->GetUndoEnv().RemoveSection(m_xSection.get());
131 if ( m_pReportListener
.is() )
132 m_pReportListener
->dispose();
133 m_pFunc
= ::std::auto_ptr
<DlgEdFunc
>();
136 ::std::auto_ptr
<OSectionView
> aTemp( m_pView
);
138 m_pView
->EndListening( *m_pModel
);
141 /*m_pModel->DeletePage(m_pPage->GetPageNum());*/
143 //------------------------------------------------------------------------------
144 void OReportSection::Paint( const Rectangle
& rRect
)
146 Window::Paint(rRect
);
150 // repaint, get PageView and prepare Region
151 SdrPageView
* pPgView
= m_pView
->GetSdrPageView();
152 const Region
aPaintRectRegion(rRect
);
155 SdrPaintWindow
* pTargetPaintWindow
= 0;
157 // mark repaint start
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
173 pPgView
->DrawLayer(0, this);
174 pPgView
->GetView().EndDrawLayers(*pTargetPaintWindow
, true);
177 m_pView
->CompleteRedraw(this,aPaintRectRegion
);
180 //------------------------------------------------------------------------------
181 void OReportSection::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() )
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
);
247 // m_pPage->SetUppBorder(-10000);
249 m_pView
->SetDesignMode( TRUE
);
251 m_pView
->StartListening( *m_pModel
);
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
;
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
;
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!");
334 //----------------------------------------------------------------------------
335 void OReportSection::Delete()
337 if( !m_pView
->AreObjectsMarked() )
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 ));
354 m_pFunc
.reset(new DlgEdFuncSelect( this ));
356 m_pFunc
->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
357 m_pModel
->SetReadOnly(eNewMode
== RPTUI_READONLY
);
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() )
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; )
388 SdrObject
* pSdrObject
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
389 OObjectBase
* pObj
= dynamic_cast<OObjectBase
*>(pSdrObject
);
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
); // mark the section in which is clicked
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
);
441 //----------------------------------------------------------------------------
442 void OReportSection::SetGridVisible(BOOL _bVisible
)
444 m_pView
->SetGridVisible( _bVisible
);
446 //------------------------------------------------------------------------------
447 void OReportSection::SelectAll(const sal_uInt16 _nObjectType
)
451 if ( _nObjectType
== OBJ_NONE
)
452 m_pView
->MarkAllObj();
455 m_pView
->UnmarkAll();
456 SdrObjListIter
aIter(*m_pPage
,IM_DEEPNOGROUPS
);
457 SdrObject
* pObjIter
= NULL
;
458 while( (pObjIter
= aIter
.Next()) != NULL
)
460 if ( pObjIter
->GetObjIdentifier() == _nObjectType
)
461 m_pView
->MarkObj( pObjIter
, m_pView
->GetSdrPageView() );
466 void lcl_insertMenuItemImages(PopupMenu
& rContextMenu
,OReportController
& rController
,const uno::Reference
< report::XReportDefinition
>& _xReportDefinition
,uno::Reference
<frame::XFrame
>& _rFrame
,BOOL _bHiContrast
)
468 const USHORT nCount
= rContextMenu
.GetItemCount();
469 for (USHORT i
= 0; i
< nCount
; ++i
)
471 if ( MENUITEM_SEPARATOR
!= rContextMenu
.GetItemType(i
))
473 const USHORT nId
= rContextMenu
.GetItemId(i
);
474 PopupMenu
* pPopupMenu
= rContextMenu
.GetPopupMenu( nId
);
477 lcl_insertMenuItemImages(*pPopupMenu
,rController
,_xReportDefinition
,_rFrame
,_bHiContrast
);
481 const ::rtl::OUString sCommand
= rContextMenu
.GetItemCommand(nId
);
482 rContextMenu
.SetItemImage(nId
,framework::GetImageFromURL(_rFrame
,sCommand
,FALSE
,_bHiContrast
));
483 if ( nId
== SID_PAGEHEADERFOOTER
)
485 String sText
= String(ModuleRes((_xReportDefinition
.is() && _xReportDefinition
->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE
: RID_STR_PAGEHEADERFOOTER_INSERT
));
486 rContextMenu
.SetItemText(nId
,sText
);
488 else if ( nId
== SID_REPORTHEADERFOOTER
)
490 String sText
= String(ModuleRes((_xReportDefinition
.is() && _xReportDefinition
->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE
: RID_STR_REPORTHEADERFOOTER_INSERT
));
491 rContextMenu
.SetItemText(nId
,sText
);
494 rContextMenu
.CheckItem(nId
,rController
.isCommandChecked(nId
));
495 rContextMenu
.EnableItem(nId
,rController
.isCommandEnabled(nId
));
497 } // for (USHORT i = 0; i < nCount; ++i)
499 //----------------------------------------------------------------------------
500 void OReportSection::Command( const CommandEvent
& _rCEvt
)
502 Window::Command(_rCEvt
);
503 switch (_rCEvt
.GetCommand())
505 case COMMAND_CONTEXTMENU
:
507 const StyleSettings
& rSettings
= Application::GetSettings().GetStyleSettings();
508 BOOL bHiContrast
= rSettings
.GetMenuColor().IsDark();
509 OReportController
& rController
= m_pParent
->getViewsWindow()->getView()->getReportView()->getController();
510 uno::Reference
<frame::XFrame
> xFrame
= rController
.getFrame();
511 PopupMenu
aContextMenu( ModuleRes( RID_MENU_REPORT
) );
512 uno::Reference
< report::XReportDefinition
> xReportDefinition
= getSection()->getReportDefinition();
514 lcl_insertMenuItemImages(aContextMenu
,rController
,xReportDefinition
,xFrame
,bHiContrast
);
516 Point aPos
= _rCEvt
.GetMousePosPixel();
517 m_pView
->EndAction();
518 const USHORT nId
= aContextMenu
.Execute(this, aPos
);
521 uno::Sequence
< beans::PropertyValue
> aArgs
;
522 if ( nId
== SID_ATTR_CHAR_COLOR_BACKGROUND
)
525 aArgs
[0].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Selection"));
526 aArgs
[0].Value
<<= m_xSection
;
528 rController
.executeChecked(nId
,aArgs
);
534 // -----------------------------------------------------------------------------
535 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
) throw( uno::RuntimeException
)
537 if ( m_xSection
.is() )
539 if ( _rEvent
.Source
== m_xSection
|| PROPERTY_BACKCOLOR
== _rEvent
.PropertyName
)
541 sal_Int32 nColor
= m_xSection
->getBackColor();
542 if ( nColor
== (sal_Int32
)COL_TRANSPARENT
)
543 nColor
= getStyleProperty
<sal_Int32
>(m_xSection
->getReportDefinition(),PROPERTY_BACKCOLOR
);
544 m_pView
->SetApplicationDocumentColor(nColor
);
545 Invalidate(INVALIDATE_NOCHILDREN
|INVALIDATE_NOERASE
);
549 uno::Reference
<report::XReportDefinition
> xReportDefinition
= m_xSection
->getReportDefinition();
550 if ( _rEvent
.PropertyName
== PROPERTY_LEFTMARGIN
)
552 const sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
553 m_pPage
->SetLftBorder(nLeftMargin
);
555 else if ( _rEvent
.PropertyName
== PROPERTY_RIGHTMARGIN
)
557 const sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
558 m_pPage
->SetRgtBorder(nRightMargin
);
563 const sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
564 const sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
565 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(xReportDefinition
,PROPERTY_PAPERSIZE
).Width
;
566 const sal_Int32 nCount
= m_xSection
->getCount();
567 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
569 bool bChanged
= false;
570 uno::Reference
< report::XReportComponent
> xReportComponent(m_xSection
->getByIndex(i
),uno::UNO_QUERY_THROW
);
571 awt::Point aPos
= xReportComponent
->getPosition();
572 awt::Size aSize
= xReportComponent
->getSize();
573 SvxShape
* pShape
= SvxShape::getImplementation( xReportComponent
);
574 SdrObject
* pObject
= pShape
? pShape
->GetSdrObject() : NULL
;
577 OObjectBase
* pBase
= dynamic_cast<OObjectBase
*>(pObject
);
578 pBase
->EndListening(sal_False
);
579 if ( aPos
.X
< nLeftMargin
)
581 aPos
.X
= nLeftMargin
;
584 if ( (aPos
.X
+ aSize
.Width
) > (nPaperWidth
- nRightMargin
) )
586 aPos
.X
= nPaperWidth
- nRightMargin
- aSize
.Width
;
587 if ( aPos
.X
< nLeftMargin
)
589 aSize
.Width
+= aPos
.X
- nLeftMargin
;
590 aPos
.X
= nLeftMargin
;
591 // add listener around
592 pBase
->StartListening();
593 xReportComponent
->setSize(aSize
);
594 pBase
->EndListening(sal_False
);
602 xReportComponent
->setPosition(aPos
);
603 correctOverlapping(pObject
,*this,false);
604 Rectangle
aRet(VCLPoint(xReportComponent
->getPosition()),VCLSize(xReportComponent
->getSize()));
605 aRet
.setHeight(aRet
.getHeight() + 1);
606 aRet
.setWidth(aRet
.getWidth() + 1);
607 if ( m_xSection
.is() && (static_cast<sal_uInt32
>(aRet
.getHeight() + aRet
.Top()) > m_xSection
->getHeight()) )
608 m_xSection
->setHeight(aRet
.getHeight() + aRet
.Top());
610 pBase
->StartListening();
612 } // for (sal_Int32 i = 0; i < nCount; ++i)
614 catch(uno::Exception
)
616 OSL_ENSURE(0,"Exception caught: OReportSection::_propertyChanged(");
623 //------------------------------------------------------------------------------
624 sal_Bool
OReportSection::handleKeyEvent(const KeyEvent
& _rEvent
)
626 return m_pFunc
.get() ? m_pFunc
->handleKeyEvent(_rEvent
) : sal_False
;
628 // -----------------------------------------------------------------------------
629 void OReportSection::deactivateOle()
632 m_pFunc
->deactivateOle(true);
634 // -----------------------------------------------------------------------------
635 void OReportSection::createDefault(const ::rtl::OUString
& _sType
)
637 SdrObject
* pObj
= m_pView
->GetCreateObj();//rMarkList.GetMark(0)->GetObj();
640 createDefault(_sType
,pObj
);
642 // -----------------------------------------------------------------------------
643 void OReportSection::createDefault(const ::rtl::OUString
& _sType
,SdrObject
* _pObj
)
645 sal_Bool bAttributesAppliedFromGallery
= sal_False
;
647 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
649 std::vector
< rtl::OUString
> aObjList
;
650 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
652 std::vector
< rtl::OUString
>::iterator aIter
= aObjList
.begin();
653 std::vector
< rtl::OUString
>::iterator aEnd
= aObjList
.end();
654 for (sal_uInt32 i
=0 ; aIter
!= aEnd
; ++aIter
,++i
)
656 if ( aIter
->equalsIgnoreAsciiCase( _sType
) )
658 OReportModel
aReportModel(NULL
);
659 SfxItemPool
& rPool
= aReportModel
.GetItemPool();
660 rPool
.FreezeIdRanges();
661 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aReportModel
) )
663 const SdrObject
* pSourceObj
= aReportModel
.GetPage( 0 )->GetObj( 0 );
666 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
667 SfxItemSet
aDest( _pObj
->GetModel()->GetItemPool(), // ranges from SdrAttrObj
668 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
669 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
670 SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
,
671 // Graphic Attributes
672 SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
,
674 SDRATTR_3D_FIRST
, SDRATTR_3D_LAST
,
675 // CustomShape properties
676 SDRATTR_CUSTOMSHAPE_FIRST
, SDRATTR_CUSTOMSHAPE_LAST
,
677 // range from SdrTextObj
678 EE_ITEMS_START
, EE_ITEMS_END
,
681 aDest
.Set( rSource
);
682 _pObj
->SetMergedItemSet( aDest
);
683 sal_Int32 nAngle
= pSourceObj
->GetRotateAngle();
686 double a
= nAngle
* F_PI18000
;
687 _pObj
->NbcRotate( _pObj
->GetSnapRect().Center(), nAngle
, sin( a
), cos( a
) );
689 bAttributesAppliedFromGallery
= sal_True
;
697 if ( !bAttributesAppliedFromGallery
)
699 _pObj
->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER
,ITEMID_ADJUST
) );
700 _pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
701 _pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
702 _pObj
->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False
) );
703 ((SdrObjCustomShape
*)_pObj
)->MergeDefaultAttributes( &_sType
);
706 // -----------------------------------------------------------------------------
707 uno::Reference
< report::XReportComponent
> OReportSection::getCurrentControlModel() const
709 uno::Reference
< report::XReportComponent
> xModel
;
712 const SdrMarkList
& rMarkList
= m_pView
->GetMarkedObjectList();
713 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
715 if ( nMarkCount
== 1 )
717 SdrObject
* pDlgEdObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
718 OObjectBase
* pObj
= dynamic_cast<OObjectBase
*>(pDlgEdObj
);
720 xModel
= pObj
->getReportComponent().get();
725 // -----------------------------------------------------------------------------
726 void OReportSection::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
730 const SdrMarkList
& rMarkList
= m_pView
->GetMarkedObjectList();
731 const sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
733 for (sal_uInt32 i
=0; i
< nMarkCount
; ++i
)
735 const SdrObject
* pDlgEdObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
736 const OObjectBase
* pObj
= dynamic_cast<const OObjectBase
*>(pDlgEdObj
);
738 _rSelection
.push_back(pObj
->getReportComponent());
742 // -----------------------------------------------------------------------------
743 sal_Int8
OReportSection::AcceptDrop( const AcceptDropEvent
& _rEvt
)
745 OSL_TRACE("AcceptDrop::DropEvent.Action %i\n", _rEvt
.mnAction
);
747 ::Point
aDropPos(_rEvt
.maPosPixel
);
748 const MouseEvent
aMouseEvt(aDropPos
);
749 if ( m_pFunc
->isOverlapping(aMouseEvt
) )
750 return DND_ACTION_NONE
;
752 if ( _rEvt
.mnAction
== DND_ACTION_COPY
||
753 _rEvt
.mnAction
== DND_ACTION_LINK
756 if (!m_pParent
) return DND_ACTION_NONE
;
757 USHORT nCurrentPosition
= 0;
758 nCurrentPosition
= m_pParent
->getViewsWindow()->getPosition(m_pParent
);
759 if (_rEvt
.mnAction
== DND_ACTION_COPY
)
761 // we must assure, we can't drop in the top section
762 if (nCurrentPosition
< 1)
764 return DND_ACTION_NONE
;
766 return DND_ACTION_LINK
;
768 if (_rEvt
.mnAction
== DND_ACTION_LINK
)
770 // we must assure, we can't drop in the bottom section
771 if (m_pParent
->getViewsWindow()->getSectionCount() > (nCurrentPosition
+ 1) )
773 return DND_ACTION_COPY
;
775 return DND_ACTION_NONE
;
780 const DataFlavorExVector
& rFlavors
= GetDataFlavorExVector();
781 if ( ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors
)
782 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors
, CTF_FIELD_DESCRIPTOR
| CTF_CONTROL_EXCHANGE
| CTF_COLUMN_DESCRIPTOR
) )
783 return _rEvt
.mnAction
;
785 const sal_Int8 nDropOption
= ( OReportExchange::canExtract(rFlavors
) ) ? DND_ACTION_COPYMOVE
: DND_ACTION_NONE
;
789 return DND_ACTION_NONE
;
792 // -----------------------------------------------------------------------------
793 sal_Int8
OReportSection::ExecuteDrop( const ExecuteDropEvent
& _rEvt
)
795 OSL_TRACE("ExecuteDrop::DropEvent.Action %i\n", _rEvt
.mnAction
);
796 ::Point
aDropPos(PixelToLogic(_rEvt
.maPosPixel
));
797 const MouseEvent
aMouseEvt(aDropPos
);
798 if ( m_pFunc
->isOverlapping(aMouseEvt
) )
799 return DND_ACTION_NONE
;
801 sal_Int8 nDropOption
= DND_ACTION_NONE
;
802 const TransferableDataHelper
aDropped(_rEvt
.maDropEvent
.Transferable
);
803 DataFlavorExVector
& rFlavors
= aDropped
.GetDataFlavorExVector();
804 bool bMultipleFormat
= ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors
);
805 if ( OReportExchange::canExtract(rFlavors
) )
807 OReportExchange::TSectionElements aCopies
= OReportExchange::extractCopies(aDropped
);
809 nDropOption
= DND_ACTION_COPYMOVE
;
810 m_pParent
->getViewsWindow()->BrkAction();
811 m_pParent
->getViewsWindow()->unmarkAllObjects(m_pView
);
812 //m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
813 } // if ( OReportExchange::canExtract(rFlavors) )
814 else if ( bMultipleFormat
815 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors
, CTF_FIELD_DESCRIPTOR
| CTF_CONTROL_EXCHANGE
| CTF_COLUMN_DESCRIPTOR
) )
817 m_pParent
->getViewsWindow()->getView()->setMarked(m_pView
,sal_True
);
818 m_pView
->UnmarkAll();
819 const Rectangle
& rRect
= m_pView
->GetWorkArea();
820 if ( aDropPos
.X() < rRect
.Left() )
821 aDropPos
.X() = rRect
.Left();
822 else if ( aDropPos
.X() > rRect
.Right() )
823 aDropPos
.X() = rRect
.Right();
825 if ( aDropPos
.Y() > rRect
.Bottom() )
826 aDropPos
.Y() = rRect
.Bottom();
828 uno::Sequence
<beans::PropertyValue
> aValues
;
829 if ( !bMultipleFormat
)
831 ::svx::ODataAccessDescriptor aDescriptor
= ::svx::OColumnTransferable::extractColumnDescriptor(aDropped
);
834 aValues
[0].Value
<<= aDescriptor
.createPropertyValueSequence();
835 } // if ( !bMultipleFormat )
837 aValues
= ::svx::OMultiColumnTransferable::extractDescriptor(aDropped
);
839 beans::PropertyValue
* pIter
= aValues
.getArray();
840 beans::PropertyValue
* pEnd
= pIter
+ aValues
.getLength();
841 for(;pIter
!= pEnd
; ++pIter
)
843 uno::Sequence
<beans::PropertyValue
> aCurrent
;
844 pIter
->Value
>>= aCurrent
;
845 sal_Int32 nLength
= aCurrent
.getLength();
848 aCurrent
.realloc(nLength
+ 3);
849 aCurrent
[nLength
].Name
= PROPERTY_POSITION
;
850 aCurrent
[nLength
++].Value
<<= AWTPoint(aDropPos
);
851 // give also the DND Action (Shift|Ctrl) Key to really say what we want
852 aCurrent
[nLength
].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DNDAction"));
853 aCurrent
[nLength
++].Value
<<= _rEvt
.mnAction
;
855 aCurrent
[nLength
].Name
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Section"));
856 aCurrent
[nLength
++].Value
<<= getSection();
857 pIter
->Value
<<= aCurrent
;
861 // we use this way to create undo actions
862 OReportController
& rController
= m_pParent
->getViewsWindow()->getView()->getReportView()->getController();
863 rController
.executeChecked(SID_ADD_CONTROL_PAIR
,aValues
);
864 nDropOption
= DND_ACTION_COPY
;
868 // -----------------------------------------------------------------------------
869 void OReportSection::stopScrollTimer()
871 m_pFunc
->stopScrollTimer();
873 // -----------------------------------------------------------------------------
874 bool OReportSection::isUiActive() const
876 return m_pFunc
->isUiActive();
878 // -----------------------------------------------------------------------------
879 // =============================================================================
881 // =============================================================================