1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "ReportSection.hxx"
20 #include "ReportWindow.hxx"
21 #include "DesignView.hxx"
22 #include "uistrings.hrc"
23 #include "RptObject.hxx"
24 #include "RptModel.hxx"
25 #include "SectionView.hxx"
26 #include "RptPage.hxx"
27 #include "ReportController.hxx"
28 #include "UITools.hxx"
29 #include "ViewsWindow.hxx"
31 #include <svx/svdpagv.hxx>
32 #include <editeng/eeitemid.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>
41 #include <vcl/svapp.hxx>
43 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
44 #include <toolkit/helper/convert.hxx>
46 #include "SectionWindow.hxx"
47 #include "helpids.hrc"
48 #include "RptResId.hrc"
49 #include "dlgedclip.hxx"
50 #include "UndoActions.hxx"
51 #include "rptui_slotid.hrc"
53 #include <connectivity/dbtools.hxx>
55 #include <vcl/lineinfo.hxx>
56 #include "ColorChanger.hxx"
58 #include <svl/itempool.hxx>
59 #include <svtools/extcolorcfg.hxx>
60 #include <unotools/confignode.hxx>
61 #include <framework/imageproducer.hxx>
63 // =============================================================================
66 // =============================================================================
67 using namespace ::com::sun::star
;
68 // -----------------------------------------------------------------------------
70 sal_Int32
lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
72 svtools::ExtendedColorConfig aConfig
;
73 sal_Int32 nColor
= aConfig
.GetColorValue(CFG_REPORTDESIGNER
, DBOVERLAPPEDCONTROL
).getColor();
76 //------------------------------------------------------------------------------
77 DBG_NAME( rpt_OReportSection
)
78 OReportSection::OReportSection(OSectionWindow
* _pParent
,const uno::Reference
< report::XSection
>& _xSection
)
79 : Window(_pParent
,WB_DIALOGCONTROL
)
80 , ::comphelper::OPropertyChangeListener(m_aMutex
)
81 , DropTargetHelper(this)
87 ,m_pReportListener(NULL
)
88 ,m_xSection(_xSection
)
89 ,m_nPaintEntranceCount(0)
90 ,m_eMode(RPTUI_SELECT
)
91 ,m_bDialogModelChanged(sal_False
)
94 DBG_CTOR( rpt_OReportSection
,NULL
);
95 //EnableChildTransparentMode();
96 SetHelpId(HID_REPORTSECTION
);
97 SetMapMode( MapMode( MAP_100TH_MM
) );
98 SetParentClipMode( PARENTCLIPMODE_CLIP
);
99 EnableChildTransparentMode( sal_False
);
100 SetPaintTransparent( sal_False
);
106 catch(uno::Exception
&)
108 OSL_FAIL("Exception catched!");
111 m_pFunc
.reset(new DlgEdFuncSelect( this ));
112 m_pFunc
->setOverlappedControlColor(lcl_getOverlappedControlColor() );
114 //------------------------------------------------------------------------------
115 OReportSection::~OReportSection()
117 DBG_DTOR( rpt_OReportSection
,NULL
);
122 if ( m_pReportListener
.is() )
123 m_pReportListener
->dispose();
124 m_pFunc
= ::std::auto_ptr
<DlgEdFunc
>();
127 ::std::auto_ptr
<OSectionView
> aTemp( m_pView
);
129 m_pView
->EndListening( *m_pModel
);
133 //------------------------------------------------------------------------------
134 void OReportSection::Paint( const Rectangle
& rRect
)
136 Window::Paint(rRect
);
138 if ( m_pView
&& m_nPaintEntranceCount
== 0)
140 ++m_nPaintEntranceCount
;
141 // repaint, get PageView and prepare Region
142 SdrPageView
* pPgView
= m_pView
->GetSdrPageView();
143 const Region
aPaintRectRegion(rRect
);
146 SdrPaintWindow
* pTargetPaintWindow
= 0;
148 // mark repaint start
151 pTargetPaintWindow
= pPgView
->GetView().BeginDrawLayers(this, aPaintRectRegion
);
152 OSL_ENSURE(pTargetPaintWindow
, "BeginDrawLayers: Got no SdrPaintWindow (!)");
153 // draw background self using wallpaper
154 OutputDevice
& rTargetOutDev
= pTargetPaintWindow
->GetTargetOutputDevice();
155 rTargetOutDev
.DrawWallpaper(rRect
, Wallpaper(pPgView
->GetApplicationDocumentColor()));
158 // do paint (unbuffered) and mark repaint end
161 pPgView
->DrawLayer(0, this);
162 pPgView
->GetView().EndDrawLayers(*pTargetPaintWindow
, true);
165 m_pView
->CompleteRedraw(this,aPaintRectRegion
);
166 --m_nPaintEntranceCount
;
169 //------------------------------------------------------------------------------
170 void OReportSection::Resize()
174 //------------------------------------------------------------------------------
175 void OReportSection::fill()
177 if ( !m_xSection
.is() )
180 m_pMulti
= new comphelper::OPropertyChangeMultiplexer(this,m_xSection
.get());
181 m_pMulti
->addProperty(PROPERTY_BACKCOLOR
);
183 m_pReportListener
= addStyleListener(m_xSection
->getReportDefinition(),this);
185 m_pModel
= m_pParent
->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
186 m_pPage
= m_pModel
->getPage(m_xSection
);
188 m_pView
= new OSectionView( m_pModel
.get(), this, m_pParent
->getViewsWindow()->getView() );
190 // #i93597# tell SdrPage that only left and right page border is defined
191 // instead of the full rectangle definition
192 m_pPage
->setPageBorderOnlyLeftRight(true);
194 // without the following call, no grid is painted
195 m_pView
->ShowSdrPage( m_pPage
);
197 m_pView
->SetMoveSnapOnlyTopLeft( sal_True
);
198 ODesignView
* pDesignView
= m_pParent
->getViewsWindow()->getView()->getReportView();
200 // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
201 // is only for visualisation and has nothing to do with the actual snap
202 const Size
aGridSizeCoarse(pDesignView
->getGridSizeCoarse());
203 const Size
aGridSizeFine(pDesignView
->getGridSizeFine());
204 m_pView
->SetGridCoarse(aGridSizeCoarse
);
205 m_pView
->SetGridFine(aGridSizeFine
);
207 // #i93595# set snap grid width to snap to all existing subdivisions
208 const Fraction
aX(aGridSizeFine
.A());
209 const Fraction
aY(aGridSizeFine
.B());
210 m_pView
->SetSnapGridWidth(aX
, aY
);
212 m_pView
->SetGridSnap( pDesignView
->isGridSnap() );
213 m_pView
->SetGridFront( sal_False
);
214 m_pView
->SetDragStripes( sal_True
);
215 m_pView
->SetPageVisible();
216 sal_Int32 nColor
= m_xSection
->getBackColor();
217 if ( nColor
== (sal_Int32
)COL_TRANSPARENT
)
218 nColor
= getStyleProperty
<sal_Int32
>(m_xSection
->getReportDefinition(),PROPERTY_BACKCOLOR
);
219 m_pView
->SetApplicationDocumentColor(nColor
);
221 uno::Reference
<report::XReportDefinition
> xReportDefinition
= m_xSection
->getReportDefinition();
222 const sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
223 const sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
224 m_pPage
->SetLftBorder(nLeftMargin
);
225 m_pPage
->SetRgtBorder(nRightMargin
);
228 // m_pPage->SetUppBorder(-10000);
230 m_pView
->SetDesignMode( sal_True
);
232 m_pView
->StartListening( *m_pModel
);
233 m_pPage
->SetSize( Size( getStyleProperty
<awt::Size
>(xReportDefinition
,PROPERTY_PAPERSIZE
).Width
,5*m_xSection
->getHeight()) );
234 const Size aPageSize
= m_pPage
->GetSize();
235 m_pView
->SetWorkArea( Rectangle( Point( nLeftMargin
, 0), Size(aPageSize
.Width() - nLeftMargin
- nRightMargin
,aPageSize
.Height()) ) );
237 // -----------------------------------------------------------------------------
238 void OReportSection::Paste(const uno::Sequence
< beans::NamedValue
>& _aAllreadyCopiedObjects
,bool _bForce
)
240 OSL_ENSURE(m_xSection
.is(),"Why is the section here NULL!");
241 if ( m_xSection
.is() && _aAllreadyCopiedObjects
.getLength() )
243 // stop all drawing actions
244 m_pView
->BrkAction();
246 // unmark all objects
247 m_pView
->UnmarkAll();
248 const OUString sSectionName
= m_xSection
->getName();
249 const sal_Int32 nLength
= _aAllreadyCopiedObjects
.getLength();
250 const beans::NamedValue
* pIter
= _aAllreadyCopiedObjects
.getConstArray();
251 const beans::NamedValue
* pEnd
= pIter
+ nLength
;
252 for(;pIter
!= pEnd
;++pIter
)
254 if ( _bForce
|| pIter
->Name
== sSectionName
)
258 uno::Sequence
< uno::Reference
<report::XReportComponent
> > aCopies
;
259 pIter
->Value
>>= aCopies
;
260 const uno::Reference
<report::XReportComponent
>* pCopiesIter
= aCopies
.getConstArray();
261 const uno::Reference
<report::XReportComponent
>* pCopiesEnd
= pCopiesIter
+ aCopies
.getLength();
262 for (;pCopiesIter
!= pCopiesEnd
; ++pCopiesIter
)
264 SvxShape
* pShape
= SvxShape::getImplementation( *pCopiesIter
);
265 SdrObject
* pObject
= pShape
? pShape
->GetSdrObject() : NULL
;
268 SdrObject
* pNeuObj
= pObject
->Clone();
270 pNeuObj
->SetPage( m_pPage
);
271 pNeuObj
->SetModel( m_pModel
.get() );
272 SdrInsertReason
aReason(SDRREASON_VIEWCALL
);
273 m_pPage
->InsertObject(pNeuObj
,CONTAINER_APPEND
,&aReason
);
275 Rectangle
aRet(VCLPoint((*pCopiesIter
)->getPosition()),VCLSize((*pCopiesIter
)->getSize()));
276 aRet
.setHeight(aRet
.getHeight() + 1);
277 aRet
.setWidth(aRet
.getWidth() + 1);
278 bool bOverlapping
= true;
279 while ( bOverlapping
)
281 bOverlapping
= isOver(aRet
,*m_pPage
,*m_pView
,true,pNeuObj
) != NULL
;
284 aRet
.Move(0,aRet
.getHeight()+1);
285 pNeuObj
->SetLogicRect(aRet
);
288 m_pView
->AddUndo( m_pView
->GetModel()->GetSdrUndoFactory().CreateUndoNewObject( *pNeuObj
) );
289 m_pView
->MarkObj( pNeuObj
, m_pView
->GetSdrPageView() );
290 if ( m_xSection
.is() && (static_cast<sal_uInt32
>(aRet
.getHeight() + aRet
.Top()) > m_xSection
->getHeight()) )
291 m_xSection
->setHeight(aRet
.getHeight() + aRet
.Top());
295 catch(uno::Exception
&)
297 OSL_FAIL("Exception caught while pasting a new object!");
305 //----------------------------------------------------------------------------
306 void OReportSection::Delete()
308 if( !m_pView
->AreObjectsMarked() )
311 m_pView
->BrkAction();
312 m_pView
->DeleteMarked();
314 //----------------------------------------------------------------------------
315 void OReportSection::SetMode( DlgEdMode eNewMode
)
317 if ( eNewMode
!= m_eMode
)
319 if ( eNewMode
== RPTUI_INSERT
)
321 m_pFunc
.reset(new DlgEdFuncInsert( this ));
325 m_pFunc
.reset(new DlgEdFuncSelect( this ));
327 m_pFunc
->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
328 m_pModel
->SetReadOnly(eNewMode
== RPTUI_READONLY
);
332 // -----------------------------------------------------------------------------
333 void OReportSection::Copy(uno::Sequence
< beans::NamedValue
>& _rAllreadyCopiedObjects
)
335 Copy(_rAllreadyCopiedObjects
,false);
337 //----------------------------------------------------------------------------
338 void OReportSection::Copy(uno::Sequence
< beans::NamedValue
>& _rAllreadyCopiedObjects
,bool _bEraseAnddNoClone
)
340 OSL_ENSURE(m_xSection
.is(),"Why is the section here NULL!");
341 if( !m_pView
->AreObjectsMarked() || !m_xSection
.is() )
344 // insert control models of marked objects into clipboard dialog model
345 const SdrMarkList
& rMarkedList
= m_pView
->GetMarkedObjectList();
346 const sal_uLong nMark
= rMarkedList
.GetMarkCount();
348 ::std::vector
< uno::Reference
<report::XReportComponent
> > aCopies
;
349 aCopies
.reserve(nMark
);
351 SdrUndoFactory
& rUndo
= m_pView
->GetModel()->GetSdrUndoFactory();
353 for( sal_uLong i
= nMark
; i
> 0; )
356 SdrObject
* pSdrObject
= rMarkedList
.GetMark(i
)->GetMarkedSdrObj();
357 OObjectBase
* pObj
= dynamic_cast<OObjectBase
*>(pSdrObject
);
362 SdrObject
* pNeuObj
= pSdrObject
->Clone();
363 aCopies
.push_back(uno::Reference
<report::XReportComponent
>(pNeuObj
->getUnoShape(),uno::UNO_QUERY
));
364 if ( _bEraseAnddNoClone
)
366 m_pView
->AddUndo( rUndo
.CreateUndoDeleteObject( *pSdrObject
) );
367 m_pPage
->RemoveObject(pSdrObject
->GetOrdNum());
371 catch(uno::Exception
&)
373 OSL_FAIL("Can't copy report elements!");
378 if ( !aCopies
.empty() )
380 ::std::reverse(aCopies
.begin(),aCopies
.end());
381 const sal_Int32 nLength
= _rAllreadyCopiedObjects
.getLength();
382 _rAllreadyCopiedObjects
.realloc( nLength
+ 1);
383 beans::NamedValue
* pNewValue
= _rAllreadyCopiedObjects
.getArray() + nLength
;
384 pNewValue
->Name
= m_xSection
->getName();
385 pNewValue
->Value
<<= uno::Sequence
< uno::Reference
<report::XReportComponent
> >(&(*aCopies
.begin()),aCopies
.size());
388 //----------------------------------------------------------------------------
389 void OReportSection::MouseButtonDown( const MouseEvent
& rMEvt
)
391 m_pParent
->getViewsWindow()->getView()->setMarked(m_pView
,sal_True
); // mark the section in which is clicked
392 m_pFunc
->MouseButtonDown( rMEvt
);
393 Window::MouseButtonDown(rMEvt
);
395 //----------------------------------------------------------------------------
396 void OReportSection::MouseButtonUp( const MouseEvent
& rMEvt
)
398 if ( !m_pFunc
->MouseButtonUp( rMEvt
) )
399 m_pParent
->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT
,uno::Sequence
< beans::PropertyValue
>());
402 //----------------------------------------------------------------------------
404 void OReportSection::MouseMove( const MouseEvent
& rMEvt
)
406 m_pFunc
->MouseMove( rMEvt
);
409 //----------------------------------------------------------------------------
410 void OReportSection::SetGridVisible(sal_Bool _bVisible
)
412 m_pView
->SetGridVisible( _bVisible
);
414 //------------------------------------------------------------------------------
415 void OReportSection::SelectAll(const sal_uInt16 _nObjectType
)
419 if ( _nObjectType
== OBJ_NONE
)
420 m_pView
->MarkAllObj();
423 m_pView
->UnmarkAll();
424 SdrObjListIter
aIter(*m_pPage
,IM_DEEPNOGROUPS
);
425 SdrObject
* pObjIter
= NULL
;
426 while( (pObjIter
= aIter
.Next()) != NULL
)
428 if ( pObjIter
->GetObjIdentifier() == _nObjectType
)
429 m_pView
->MarkObj( pObjIter
, m_pView
->GetSdrPageView() );
434 void lcl_insertMenuItemImages(
435 PopupMenu
& rContextMenu
,
436 OReportController
& rController
,
437 const uno::Reference
< report::XReportDefinition
>& _xReportDefinition
,uno::Reference
<frame::XFrame
>& _rFrame
440 const sal_uInt16 nCount
= rContextMenu
.GetItemCount();
441 for (sal_uInt16 i
= 0; i
< nCount
; ++i
)
443 if ( MENUITEM_SEPARATOR
!= rContextMenu
.GetItemType(i
))
445 const sal_uInt16 nId
= rContextMenu
.GetItemId(i
);
446 PopupMenu
* pPopupMenu
= rContextMenu
.GetPopupMenu( nId
);
449 lcl_insertMenuItemImages(*pPopupMenu
,rController
,_xReportDefinition
,_rFrame
);
453 const OUString sCommand
= rContextMenu
.GetItemCommand(nId
);
454 rContextMenu
.SetItemImage(nId
,framework::GetImageFromURL(_rFrame
,sCommand
,sal_False
));
455 if ( nId
== SID_PAGEHEADERFOOTER
)
457 String sText
= String(ModuleRes((_xReportDefinition
.is() && _xReportDefinition
->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE
: RID_STR_PAGEHEADERFOOTER_INSERT
));
458 rContextMenu
.SetItemText(nId
,sText
);
460 else if ( nId
== SID_REPORTHEADERFOOTER
)
462 String sText
= String(ModuleRes((_xReportDefinition
.is() && _xReportDefinition
->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE
: RID_STR_REPORTHEADERFOOTER_INSERT
));
463 rContextMenu
.SetItemText(nId
,sText
);
466 rContextMenu
.CheckItem(nId
,rController
.isCommandChecked(nId
));
467 rContextMenu
.EnableItem(nId
,rController
.isCommandEnabled(nId
));
471 //----------------------------------------------------------------------------
472 void OReportSection::Command( const CommandEvent
& _rCEvt
)
474 Window::Command(_rCEvt
);
475 switch (_rCEvt
.GetCommand())
477 case COMMAND_CONTEXTMENU
:
479 OReportController
& rController
= m_pParent
->getViewsWindow()->getView()->getReportView()->getController();
480 uno::Reference
<frame::XFrame
> xFrame
= rController
.getFrame();
481 PopupMenu
aContextMenu( ModuleRes( RID_MENU_REPORT
) );
482 uno::Reference
< report::XReportDefinition
> xReportDefinition
= getSection()->getReportDefinition();
484 lcl_insertMenuItemImages(aContextMenu
,rController
,xReportDefinition
,xFrame
);
486 Point aPos
= _rCEvt
.GetMousePosPixel();
487 m_pView
->EndAction();
488 const sal_uInt16 nId
= aContextMenu
.Execute(this, aPos
);
491 uno::Sequence
< beans::PropertyValue
> aArgs
;
492 if ( nId
== SID_ATTR_CHAR_COLOR_BACKGROUND
)
495 aArgs
[0].Name
= OUString("Selection");
496 aArgs
[0].Value
<<= m_xSection
;
498 rController
.executeChecked(nId
,aArgs
);
504 // -----------------------------------------------------------------------------
505 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent
& _rEvent
) throw( uno::RuntimeException
)
507 if ( m_xSection
.is() )
509 if ( _rEvent
.Source
== m_xSection
|| PROPERTY_BACKCOLOR
== _rEvent
.PropertyName
)
511 sal_Int32 nColor
= m_xSection
->getBackColor();
512 if ( nColor
== (sal_Int32
)COL_TRANSPARENT
)
513 nColor
= getStyleProperty
<sal_Int32
>(m_xSection
->getReportDefinition(),PROPERTY_BACKCOLOR
);
514 m_pView
->SetApplicationDocumentColor(nColor
);
515 Invalidate(INVALIDATE_NOCHILDREN
|INVALIDATE_NOERASE
);
519 uno::Reference
<report::XReportDefinition
> xReportDefinition
= m_xSection
->getReportDefinition();
520 const sal_Int32 nLeftMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_LEFTMARGIN
);
521 const sal_Int32 nRightMargin
= getStyleProperty
<sal_Int32
>(xReportDefinition
,PROPERTY_RIGHTMARGIN
);
522 const sal_Int32 nPaperWidth
= getStyleProperty
<awt::Size
>(xReportDefinition
,PROPERTY_PAPERSIZE
).Width
;
524 if ( _rEvent
.PropertyName
== PROPERTY_LEFTMARGIN
)
526 m_pPage
->SetLftBorder(nLeftMargin
);
528 else if ( _rEvent
.PropertyName
== PROPERTY_RIGHTMARGIN
)
530 m_pPage
->SetRgtBorder(nRightMargin
);
532 const Size aOldPageSize
= m_pPage
->GetSize();
533 sal_Int32 nNewHeight
= 5*m_xSection
->getHeight();
534 if ( aOldPageSize
.Height() != nNewHeight
|| nPaperWidth
!= aOldPageSize
.Width() )
536 m_pPage
->SetSize( Size( nPaperWidth
,nNewHeight
) );
537 const Size aPageSize
= m_pPage
->GetSize();
538 m_pView
->SetWorkArea( Rectangle( Point( nLeftMargin
, 0), Size(aPageSize
.Width() - nLeftMargin
- nRightMargin
,aPageSize
.Height()) ) );
540 impl_adjustObjectSizePosition(nPaperWidth
,nLeftMargin
,nRightMargin
);
541 m_pParent
->Invalidate(INVALIDATE_UPDATE
| INVALIDATE_TRANSPARENT
);
545 void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth
,sal_Int32 i_nLeftMargin
,sal_Int32 i_nRightMargin
)
549 sal_Int32 nRightBorder
= i_nPaperWidth
- i_nRightMargin
;
550 const sal_Int32 nCount
= m_xSection
->getCount();
551 for (sal_Int32 i
= 0; i
< nCount
; ++i
)
553 bool bChanged
= false;
554 uno::Reference
< report::XReportComponent
> xReportComponent(m_xSection
->getByIndex(i
),uno::UNO_QUERY_THROW
);
555 awt::Point aPos
= xReportComponent
->getPosition();
556 awt::Size aSize
= xReportComponent
->getSize();
557 SvxShape
* pShape
= SvxShape::getImplementation( xReportComponent
);
558 SdrObject
* pObject
= pShape
? pShape
->GetSdrObject() : NULL
;
561 OObjectBase
* pBase
= dynamic_cast<OObjectBase
*>(pObject
);
562 pBase
->EndListening(sal_False
);
563 if ( aPos
.X
< i_nLeftMargin
)
565 aPos
.X
= i_nLeftMargin
;
568 if ( (aPos
.X
+ aSize
.Width
) > nRightBorder
)
570 aPos
.X
= nRightBorder
- aSize
.Width
;
571 if ( aPos
.X
< i_nLeftMargin
)
573 aSize
.Width
+= aPos
.X
- i_nLeftMargin
;
574 aPos
.X
= i_nLeftMargin
;
575 // add listener around
576 pBase
->StartListening();
577 xReportComponent
->setSize(aSize
);
578 pBase
->EndListening(sal_False
);
586 xReportComponent
->setPosition(aPos
);
587 correctOverlapping(pObject
,*this,false);
588 Rectangle
aRet(VCLPoint(xReportComponent
->getPosition()),VCLSize(xReportComponent
->getSize()));
589 aRet
.setHeight(aRet
.getHeight() + 1);
590 aRet
.setWidth(aRet
.getWidth() + 1);
591 if ( m_xSection
.is() && (static_cast<sal_uInt32
>(aRet
.getHeight() + aRet
.Top()) > m_xSection
->getHeight()) )
592 m_xSection
->setHeight(aRet
.getHeight() + aRet
.Top());
594 pObject
->RecalcBoundRect();
596 pBase
->StartListening();
600 catch(const uno::Exception
&)
602 OSL_FAIL("Exception caught: OReportSection::impl_adjustObjectSizePosition()");
605 //------------------------------------------------------------------------------
606 sal_Bool
OReportSection::handleKeyEvent(const KeyEvent
& _rEvent
)
608 return m_pFunc
.get() ? m_pFunc
->handleKeyEvent(_rEvent
) : sal_False
;
610 // -----------------------------------------------------------------------------
611 void OReportSection::deactivateOle()
614 m_pFunc
->deactivateOle(true);
616 // -----------------------------------------------------------------------------
617 void OReportSection::createDefault(const OUString
& _sType
)
619 SdrObject
* pObj
= m_pView
->GetCreateObj();
622 createDefault(_sType
,pObj
);
624 // -----------------------------------------------------------------------------
625 void OReportSection::createDefault(const OUString
& _sType
,SdrObject
* _pObj
)
627 sal_Bool bAttributesAppliedFromGallery
= sal_False
;
629 if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT
) )
631 std::vector
< OUString
> aObjList
;
632 if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT
, aObjList
) )
634 std::vector
< OUString
>::iterator aIter
= aObjList
.begin();
635 std::vector
< OUString
>::iterator aEnd
= aObjList
.end();
636 for (sal_uInt32 i
=0 ; aIter
!= aEnd
; ++aIter
,++i
)
638 if ( aIter
->equalsIgnoreAsciiCase( _sType
) )
640 OReportModel
aReportModel(NULL
);
641 SfxItemPool
& rPool
= aReportModel
.GetItemPool();
642 rPool
.FreezeIdRanges();
643 if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT
, i
, &aReportModel
) )
645 const SdrObject
* pSourceObj
= aReportModel
.GetPage( 0 )->GetObj( 0 );
648 const SfxItemSet
& rSource
= pSourceObj
->GetMergedItemSet();
649 SfxItemSet
aDest( _pObj
->GetModel()->GetItemPool(), // ranges from SdrAttrObj
650 SDRATTR_START
, SDRATTR_SHADOW_LAST
,
651 SDRATTR_MISC_FIRST
, SDRATTR_MISC_LAST
,
652 SDRATTR_TEXTDIRECTION
, SDRATTR_TEXTDIRECTION
,
653 // Graphic Attributes
654 SDRATTR_GRAF_FIRST
, SDRATTR_GRAF_LAST
,
656 SDRATTR_3D_FIRST
, SDRATTR_3D_LAST
,
657 // CustomShape properties
658 SDRATTR_CUSTOMSHAPE_FIRST
, SDRATTR_CUSTOMSHAPE_LAST
,
659 // range from SdrTextObj
660 EE_ITEMS_START
, EE_ITEMS_END
,
663 aDest
.Set( rSource
);
664 _pObj
->SetMergedItemSet( aDest
);
665 sal_Int32 nAngle
= pSourceObj
->GetRotateAngle();
668 double a
= nAngle
* F_PI18000
;
669 _pObj
->NbcRotate( _pObj
->GetSnapRect().Center(), nAngle
, sin( a
), cos( a
) );
671 bAttributesAppliedFromGallery
= sal_True
;
679 if ( !bAttributesAppliedFromGallery
)
681 _pObj
->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER
,ITEMID_ADJUST
) );
682 _pObj
->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER
) );
683 _pObj
->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK
) );
684 _pObj
->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False
) );
685 ((SdrObjCustomShape
*)_pObj
)->MergeDefaultAttributes( &_sType
);
688 // -----------------------------------------------------------------------------
689 uno::Reference
< report::XReportComponent
> OReportSection::getCurrentControlModel() const
691 uno::Reference
< report::XReportComponent
> xModel
;
694 const SdrMarkList
& rMarkList
= m_pView
->GetMarkedObjectList();
695 sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
697 if ( nMarkCount
== 1 )
699 SdrObject
* pDlgEdObj
= rMarkList
.GetMark(0)->GetMarkedSdrObj();
700 OObjectBase
* pObj
= dynamic_cast<OObjectBase
*>(pDlgEdObj
);
702 xModel
= pObj
->getReportComponent().get();
707 // -----------------------------------------------------------------------------
708 void OReportSection::fillControlModelSelection(::std::vector
< uno::Reference
< uno::XInterface
> >& _rSelection
) const
712 const SdrMarkList
& rMarkList
= m_pView
->GetMarkedObjectList();
713 const sal_uInt32 nMarkCount
= rMarkList
.GetMarkCount();
715 for (sal_uInt32 i
=0; i
< nMarkCount
; ++i
)
717 const SdrObject
* pDlgEdObj
= rMarkList
.GetMark(i
)->GetMarkedSdrObj();
718 const OObjectBase
* pObj
= dynamic_cast<const OObjectBase
*>(pDlgEdObj
);
721 uno::Reference
<uno::XInterface
> xInterface(pObj
->getReportComponent());
722 _rSelection
.push_back(xInterface
);
727 // -----------------------------------------------------------------------------
728 sal_Int8
OReportSection::AcceptDrop( const AcceptDropEvent
& _rEvt
)
730 OSL_TRACE("AcceptDrop::DropEvent.Action %i", _rEvt
.mnAction
);
732 ::Point
aDropPos(_rEvt
.maPosPixel
);
733 const MouseEvent
aMouseEvt(aDropPos
);
734 if ( m_pFunc
->isOverlapping(aMouseEvt
) )
735 return DND_ACTION_NONE
;
737 if ( _rEvt
.mnAction
== DND_ACTION_COPY
||
738 _rEvt
.mnAction
== DND_ACTION_LINK
741 if (!m_pParent
) return DND_ACTION_NONE
;
742 sal_uInt16 nCurrentPosition
= 0;
743 nCurrentPosition
= m_pParent
->getViewsWindow()->getPosition(m_pParent
);
744 if (_rEvt
.mnAction
== DND_ACTION_COPY
)
746 // we must assure, we can't drop in the top section
747 if (nCurrentPosition
< 1)
749 return DND_ACTION_NONE
;
751 return DND_ACTION_LINK
;
753 if (_rEvt
.mnAction
== DND_ACTION_LINK
)
755 // we must assure, we can't drop in the bottom section
756 if (m_pParent
->getViewsWindow()->getSectionCount() > (nCurrentPosition
+ 1) )
758 return DND_ACTION_COPY
;
760 return DND_ACTION_NONE
;
765 const DataFlavorExVector
& rFlavors
= GetDataFlavorExVector();
766 if ( ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors
)
767 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors
, CTF_FIELD_DESCRIPTOR
| CTF_CONTROL_EXCHANGE
| CTF_COLUMN_DESCRIPTOR
) )
768 return _rEvt
.mnAction
;
770 const sal_Int8 nDropOption
= ( OReportExchange::canExtract(rFlavors
) ) ? DND_ACTION_COPYMOVE
: DND_ACTION_NONE
;
774 return DND_ACTION_NONE
;
777 // -----------------------------------------------------------------------------
778 sal_Int8
OReportSection::ExecuteDrop( const ExecuteDropEvent
& _rEvt
)
780 OSL_TRACE("ExecuteDrop::DropEvent.Action %i", _rEvt
.mnAction
);
781 ::Point
aDropPos(PixelToLogic(_rEvt
.maPosPixel
));
782 const MouseEvent
aMouseEvt(aDropPos
);
783 if ( m_pFunc
->isOverlapping(aMouseEvt
) )
784 return DND_ACTION_NONE
;
786 sal_Int8 nDropOption
= DND_ACTION_NONE
;
787 const TransferableDataHelper
aDropped(_rEvt
.maDropEvent
.Transferable
);
788 DataFlavorExVector
& rFlavors
= aDropped
.GetDataFlavorExVector();
789 bool bMultipleFormat
= ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors
);
790 if ( OReportExchange::canExtract(rFlavors
) )
792 OReportExchange::TSectionElements aCopies
= OReportExchange::extractCopies(aDropped
);
794 nDropOption
= DND_ACTION_COPYMOVE
;
795 m_pParent
->getViewsWindow()->BrkAction();
796 m_pParent
->getViewsWindow()->unmarkAllObjects(m_pView
);
798 else if ( bMultipleFormat
799 || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors
, CTF_FIELD_DESCRIPTOR
| CTF_CONTROL_EXCHANGE
| CTF_COLUMN_DESCRIPTOR
) )
801 m_pParent
->getViewsWindow()->getView()->setMarked(m_pView
,sal_True
);
802 m_pView
->UnmarkAll();
803 const Rectangle
& rRect
= m_pView
->GetWorkArea();
804 if ( aDropPos
.X() < rRect
.Left() )
805 aDropPos
.X() = rRect
.Left();
806 else if ( aDropPos
.X() > rRect
.Right() )
807 aDropPos
.X() = rRect
.Right();
809 if ( aDropPos
.Y() > rRect
.Bottom() )
810 aDropPos
.Y() = rRect
.Bottom();
812 uno::Sequence
<beans::PropertyValue
> aValues
;
813 if ( !bMultipleFormat
)
815 ::svx::ODataAccessDescriptor aDescriptor
= ::svx::OColumnTransferable::extractColumnDescriptor(aDropped
);
818 aValues
[0].Value
<<= aDescriptor
.createPropertyValueSequence();
821 aValues
= ::svx::OMultiColumnTransferable::extractDescriptor(aDropped
);
823 beans::PropertyValue
* pIter
= aValues
.getArray();
824 beans::PropertyValue
* pEnd
= pIter
+ aValues
.getLength();
825 for(;pIter
!= pEnd
; ++pIter
)
827 uno::Sequence
<beans::PropertyValue
> aCurrent
;
828 pIter
->Value
>>= aCurrent
;
829 sal_Int32 nLength
= aCurrent
.getLength();
832 aCurrent
.realloc(nLength
+ 3);
833 aCurrent
[nLength
].Name
= PROPERTY_POSITION
;
834 aCurrent
[nLength
++].Value
<<= AWTPoint(aDropPos
);
835 // give also the DND Action (Shift|Ctrl) Key to really say what we want
836 aCurrent
[nLength
].Name
= OUString("DNDAction");
837 aCurrent
[nLength
++].Value
<<= _rEvt
.mnAction
;
839 aCurrent
[nLength
].Name
= OUString("Section");
840 aCurrent
[nLength
++].Value
<<= getSection();
841 pIter
->Value
<<= aCurrent
;
845 // we use this way to create undo actions
846 OReportController
& rController
= m_pParent
->getViewsWindow()->getView()->getReportView()->getController();
847 rController
.executeChecked(SID_ADD_CONTROL_PAIR
,aValues
);
848 nDropOption
= DND_ACTION_COPY
;
852 // -----------------------------------------------------------------------------
853 void OReportSection::stopScrollTimer()
855 m_pFunc
->stopScrollTimer();
857 // -----------------------------------------------------------------------------
858 bool OReportSection::isUiActive() const
860 return m_pFunc
->isUiActive();
862 // -----------------------------------------------------------------------------
863 // =============================================================================
865 // =============================================================================
867 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */