1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #include "precompiled_reportdesign.hxx"
28 #include "ReportSection.hxx"
29 #include "ReportWindow.hxx"
30 #include "DesignView.hxx"
31 #include "uistrings.hrc"
32 #include "RptObject.hxx"
33 #include "RptModel.hxx"
34 #include "SectionView.hxx"
35 #include "RptPage.hxx"
36 #include "ReportController.hxx"
37 #include "UITools.hxx"
38 #include "ViewsWindow.hxx"
39 
40 #include <svx/svdpagv.hxx>
41 #include <editeng/eeitemid.hxx>
42 #include <editeng/adjitem.hxx>
43 #include <svx/sdrpaintwindow.hxx>
44 #include <svx/unoshape.hxx>
45 #include <svx/gallery.hxx>
46 #include <svx/svxids.hrc>
47 #include <svx/svditer.hxx>
48 #include <svx/dbaexchange.hxx>
49 
50 #include <vcl/svapp.hxx>
51 
52 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
53 #include <toolkit/helper/convert.hxx>
54 #include "RptDef.hxx"
55 #include "SectionWindow.hxx"
56 #include "helpids.hrc"
57 #include "RptResId.hrc"
58 #include "dlgedclip.hxx"
59 #include "UndoActions.hxx"
60 #include "rptui_slotid.hrc"
61 
62 #include <connectivity/dbtools.hxx>
63 
64 #include <vcl/lineinfo.hxx>
65 #include "ColorChanger.hxx"
66 
67 #include <svl/itempool.hxx>
68 #include <svtools/extcolorcfg.hxx>
69 #include <unotools/confignode.hxx>
70 #include <framework/imageproducer.hxx>
71 
72 // =============================================================================
73 namespace rptui
74 {
75 // =============================================================================
76 using namespace ::com::sun::star;
77 // -----------------------------------------------------------------------------
78 
79 sal_Int32 lcl_getOverlappedControlColor(/*const uno::Reference <lang::XMultiServiceFactory> _rxFactory*/)
80 {
81 	svtools::ExtendedColorConfig aConfig;
82     sal_Int32 nColor = aConfig.GetColorValue(CFG_REPORTDESIGNER, DBOVERLAPPEDCONTROL).getColor();
83     return nColor;
84 }
85 //------------------------------------------------------------------------------
86 DBG_NAME( rpt_OReportSection )
87 OReportSection::OReportSection(OSectionWindow* _pParent,const uno::Reference< report::XSection >& _xSection)
88 : Window(_pParent,WB_DIALOGCONTROL)
89 , ::comphelper::OPropertyChangeListener(m_aMutex)
90 , DropTargetHelper(this)
91 ,m_pPage(NULL)
92 ,m_pView(NULL)
93 ,m_pParent(_pParent)
94 ,m_pFunc(NULL)
95 ,m_pMulti(NULL)
96 ,m_pReportListener(NULL)
97 ,m_xSection(_xSection)
98 ,m_nPaintEntranceCount(0)
99 ,m_eMode(RPTUI_SELECT)
100 ,m_bDialogModelChanged(sal_False)
101 ,m_bInDrag(sal_False)
102 {
103 	DBG_CTOR( rpt_OReportSection,NULL);
104     //EnableChildTransparentMode();
105 	SetHelpId(HID_REPORTSECTION);
106 	SetMapMode( MapMode( MAP_100TH_MM ) );
107     SetParentClipMode( PARENTCLIPMODE_CLIP );
108     EnableChildTransparentMode( sal_False );
109     SetPaintTransparent( sal_False );
110 
111 	try
112 	{
113 		fill();
114 	}
115 	catch(uno::Exception&)
116 	{
117 		OSL_ENSURE(0,"Exception catched!");
118 	}
119 
120     m_pFunc.reset(new DlgEdFuncSelect( this ));
121     m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( /* m_pParent->getViewsWindow()->getView()->getReportView()->getController().getORB() */ ) );
122 }
123 //------------------------------------------------------------------------------
124 OReportSection::~OReportSection()
125 {
126 	DBG_DTOR( rpt_OReportSection,NULL);
127     m_pPage = NULL;
128 	//m_pModel->GetUndoEnv().RemoveSection(m_xSection.get());
129 	if ( m_pMulti.is() )
130     	m_pMulti->dispose();
131 
132 	if ( m_pReportListener.is() )
133 		m_pReportListener->dispose();
134 	m_pFunc = ::std::auto_ptr<DlgEdFunc>();
135 
136 	{
137 		::std::auto_ptr<OSectionView> aTemp( m_pView);
138 		if ( m_pView )
139 			m_pView->EndListening( *m_pModel );
140 		m_pView = NULL;
141 	}
142     /*m_pModel->DeletePage(m_pPage->GetPageNum());*/
143 }
144 //------------------------------------------------------------------------------
145 void OReportSection::Paint( const Rectangle& rRect )
146 {
147     Window::Paint(rRect);
148 
149 	if ( m_pView && m_nPaintEntranceCount == 0)
150 	{
151         ++m_nPaintEntranceCount;
152          // repaint, get PageView and prepare Region
153         SdrPageView* pPgView = m_pView->GetSdrPageView();
154         const Region aPaintRectRegion(rRect);
155 
156         // #i74769#
157         SdrPaintWindow* pTargetPaintWindow = 0;
158 
159         // mark repaint start
160         if(pPgView)
161         {
162             pTargetPaintWindow = pPgView->GetView().BeginDrawLayers(this, aPaintRectRegion);
163             OSL_ENSURE(pTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
164             // draw background self using wallpaper
165             OutputDevice& rTargetOutDev = pTargetPaintWindow->GetTargetOutputDevice();
166             rTargetOutDev.DrawWallpaper(rRect, Wallpaper(pPgView->GetApplicationDocumentColor()));
167         }
168 
169         // do paint (unbuffered) and mark repaint end
170         if(pPgView)
171         {
172             pPgView->DrawLayer(0, this);
173             pPgView->GetView().EndDrawLayers(*pTargetPaintWindow, true);
174         }
175 
176 		m_pView->CompleteRedraw(this,aPaintRectRegion);
177         --m_nPaintEntranceCount;
178 	}
179 }
180 //------------------------------------------------------------------------------
181 void OReportSection::Resize()
182 {
183 	Window::Resize();
184 }
185 //------------------------------------------------------------------------------
186 void OReportSection::fill()
187 {
188 	if ( !m_xSection.is() )
189 		return;
190 
191 	m_pMulti = new comphelper::OPropertyChangeMultiplexer(this,m_xSection.get());
192 	m_pMulti->addProperty(PROPERTY_BACKCOLOR);
193 
194 	m_pReportListener = addStyleListener(m_xSection->getReportDefinition(),this);
195 
196     m_pModel = m_pParent->getViewsWindow()->getView()->getReportView()->getController().getSdrModel();
197     m_pPage = m_pModel->getPage(m_xSection);
198 
199 	m_pView = new OSectionView( m_pModel.get(), this, m_pParent->getViewsWindow()->getView() );
200 
201     // #i93597# tell SdrPage that only left and right page border is defined
202     // instead of the full rectangle definition
203     m_pPage->setPageBorderOnlyLeftRight(true);
204 
205     // without the following call, no grid is painted
206 	m_pView->ShowSdrPage( m_pPage );
207 
208 	m_pView->SetMoveSnapOnlyTopLeft( sal_True );
209 	ODesignView* pDesignView = m_pParent->getViewsWindow()->getView()->getReportView();
210 
211     // #i93595# Adapted grid to a more coarse grid and subdivisions for better visualisation. This
212     // is only for visualisation and has nothing to do with the actual snap
213     const Size aGridSizeCoarse(pDesignView->getGridSizeCoarse());
214     const Size aGridSizeFine(pDesignView->getGridSizeFine());
215     m_pView->SetGridCoarse(aGridSizeCoarse);
216     m_pView->SetGridFine(aGridSizeFine);
217 
218     // #i93595# set snap grid width to snap to all existing subdivisions
219     const Fraction aX(aGridSizeFine.A());
220     const Fraction aY(aGridSizeFine.B());
221     m_pView->SetSnapGridWidth(aX, aY);
222 
223 	m_pView->SetGridSnap( pDesignView->isGridSnap() );
224 	m_pView->SetGridFront( sal_False );
225 	m_pView->SetDragStripes( sal_True );
226 	m_pView->SetPageVisible();
227     sal_Int32 nColor = m_xSection->getBackColor();
228     if ( nColor == (sal_Int32)COL_TRANSPARENT )
229         nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
230 	m_pView->SetApplicationDocumentColor(nColor);
231 
232     uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
233     const sal_Int32 nLeftMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
234 	const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
235 	m_pPage->SetLftBorder(nLeftMargin);
236 	m_pPage->SetRgtBorder(nRightMargin);
237 
238 // LLA: TODO
239 //  m_pPage->SetUppBorder(-10000);
240 
241 	m_pView->SetDesignMode( sal_True );
242 
243 	m_pView->StartListening( *m_pModel  );
244 	/*Resize();*/
245 	m_pPage->SetSize( Size( getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width,5*m_xSection->getHeight()) );
246 	const Size aPageSize = m_pPage->GetSize();
247 	m_pView->SetWorkArea( Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
248 
249     //SetBackground( Wallpaper( COL_BLUE ));
250 }
251 // -----------------------------------------------------------------------------
252 void OReportSection::Paste(const uno::Sequence< beans::NamedValue >& _aAllreadyCopiedObjects,bool _bForce)
253 {
254     OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
255     if ( m_xSection.is() && _aAllreadyCopiedObjects.getLength() )
256     {
257 	    // stop all drawing actions
258 	    m_pView->BrkAction();
259 
260 	    // unmark all objects
261 	    m_pView->UnmarkAll();
262         const ::rtl::OUString sSectionName = m_xSection->getName();
263         const sal_Int32 nLength = _aAllreadyCopiedObjects.getLength();
264         const beans::NamedValue* pIter = _aAllreadyCopiedObjects.getConstArray();
265         const beans::NamedValue* pEnd  = pIter + nLength;
266         for(;pIter != pEnd;++pIter)
267         {
268             if ( _bForce || pIter->Name == sSectionName)
269             {
270                 try
271                 {
272                     uno::Sequence< uno::Reference<report::XReportComponent> > aCopies;
273                     pIter->Value >>= aCopies;
274                     const uno::Reference<report::XReportComponent>* pCopiesIter = aCopies.getConstArray();
275                     const uno::Reference<report::XReportComponent>* pCopiesEnd = pCopiesIter + aCopies.getLength();
276                     for (;pCopiesIter != pCopiesEnd ; ++pCopiesIter)
277                     {
278 						SvxShape* pShape = SvxShape::getImplementation( *pCopiesIter );
279                         SdrObject* pObject = pShape ? pShape->GetSdrObject() : NULL;
280 						if ( pObject )
281 						{
282                             SdrObject* pNeuObj = pObject->Clone();
283 
284                             pNeuObj->SetPage( m_pPage );
285 							pNeuObj->SetModel( m_pModel.get() );
286 			                SdrInsertReason aReason(SDRREASON_VIEWCALL);
287 			                m_pPage->InsertObject(pNeuObj,CONTAINER_APPEND,&aReason);
288 
289 							Rectangle aRet(VCLPoint((*pCopiesIter)->getPosition()),VCLSize((*pCopiesIter)->getSize()));
290 							aRet.setHeight(aRet.getHeight() + 1);
291 							aRet.setWidth(aRet.getWidth() + 1);
292 							bool bOverlapping = true;
293 							while ( bOverlapping )
294 							{
295 								bOverlapping = isOver(aRet,*m_pPage,*m_pView,true,pNeuObj) != NULL;
296 								if ( bOverlapping )
297 								{
298 									aRet.Move(0,aRet.getHeight()+1);
299                                     pNeuObj->SetLogicRect(aRet);
300 									//(*pCopiesIter)->setPositionY(aRet.Top());
301 								}
302 							}
303 							m_pView->AddUndo( m_pView->GetModel()->GetSdrUndoFactory().CreateUndoNewObject( *pNeuObj ) );
304 							m_pView->MarkObj( pNeuObj, m_pView->GetSdrPageView() );
305                             if ( m_xSection.is() && (static_cast<sal_uInt32>(aRet.getHeight() + aRet.Top()) > m_xSection->getHeight()) )
306 			                    m_xSection->setHeight(aRet.getHeight() + aRet.Top());
307 						}
308                     }
309                 }
310                 catch(uno::Exception&)
311                 {
312                     OSL_ENSURE(0,"Exception caught while pasting a new object!");
313                 }
314                 if ( !_bForce )
315                     break;
316             }
317         }
318     }
319 }
320 //----------------------------------------------------------------------------
321 void OReportSection::Delete()
322 {
323 	if( !m_pView->AreObjectsMarked() )
324 		return;
325 
326 	m_pView->BrkAction();
327 	m_pView->DeleteMarked();
328 }
329 //----------------------------------------------------------------------------
330 void OReportSection::SetMode( DlgEdMode eNewMode )
331 {
332 	if ( eNewMode != m_eMode )
333 	{
334 		if ( eNewMode == RPTUI_INSERT )
335 		{
336 			m_pFunc.reset(new DlgEdFuncInsert( this ));
337 		}
338 		else
339 		{
340 			m_pFunc.reset(new DlgEdFuncSelect( this ));
341 		}
342         m_pFunc->setOverlappedControlColor(lcl_getOverlappedControlColor( ) );
343         m_pModel->SetReadOnly(eNewMode == RPTUI_READONLY);
344         m_eMode = eNewMode;
345 	}
346 }
347 // -----------------------------------------------------------------------------
348 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects)
349 {
350     Copy(_rAllreadyCopiedObjects,false);
351 }
352 //----------------------------------------------------------------------------
353 void OReportSection::Copy(uno::Sequence< beans::NamedValue >& _rAllreadyCopiedObjects,bool _bEraseAnddNoClone)
354 {
355     OSL_ENSURE(m_xSection.is(),"Why is the section here NULL!");
356 	if( !m_pView->AreObjectsMarked() || !m_xSection.is() )
357 		return;
358 
359 	// stop all drawing actions
360 	//m_pView->BrkAction();
361 
362 	// insert control models of marked objects into clipboard dialog model
363     const SdrMarkList& rMarkedList = m_pView->GetMarkedObjectList();
364 	const sal_uLong nMark = rMarkedList.GetMarkCount();
365 
366     ::std::vector< uno::Reference<report::XReportComponent> > aCopies;
367     aCopies.reserve(nMark);
368 
369     SdrUndoFactory& rUndo = m_pView->GetModel()->GetSdrUndoFactory();
370 
371 	for( sal_uLong i = nMark; i > 0; )
372 	{
373         --i;
374         SdrObject* pSdrObject = rMarkedList.GetMark(i)->GetMarkedSdrObj();
375         OObjectBase* pObj = dynamic_cast<OObjectBase*>(pSdrObject);
376 		if ( pObj  )
377 		{
378             try
379             {
380                 SdrObject* pNeuObj = pSdrObject->Clone();
381                 aCopies.push_back(uno::Reference<report::XReportComponent>(pNeuObj->getUnoShape(),uno::UNO_QUERY));
382                 if ( _bEraseAnddNoClone )
383                 {
384                     m_pView->AddUndo( rUndo.CreateUndoDeleteObject( *pSdrObject ) );
385                     m_pPage->RemoveObject(pSdrObject->GetOrdNum());
386                 }
387 
388             }
389             catch(uno::Exception&)
390             {
391                 OSL_ENSURE(0,"Can't copy report elements!");
392             }
393 		}
394 	} // for( sal_uLong i = 0; i < nMark; i++ )
395 
396     if ( !aCopies.empty() )
397     {
398         ::std::reverse(aCopies.begin(),aCopies.end());
399         const sal_Int32 nLength = _rAllreadyCopiedObjects.getLength();
400         _rAllreadyCopiedObjects.realloc( nLength + 1);
401         beans::NamedValue* pNewValue = _rAllreadyCopiedObjects.getArray() + nLength;
402         pNewValue->Name = m_xSection->getName();
403         pNewValue->Value <<= uno::Sequence< uno::Reference<report::XReportComponent> >(&(*aCopies.begin()),aCopies.size());
404     }
405 }
406 //----------------------------------------------------------------------------
407 void OReportSection::MouseButtonDown( const MouseEvent& rMEvt )
408 {
409     m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True); // mark the section in which is clicked
410 	m_pFunc->MouseButtonDown( rMEvt );
411     Window::MouseButtonDown(rMEvt);
412 }
413 //----------------------------------------------------------------------------
414 void OReportSection::MouseButtonUp( const MouseEvent& rMEvt )
415 {
416 	if ( !m_pFunc->MouseButtonUp( rMEvt ) )
417         m_pParent->getViewsWindow()->getView()->getReportView()->getController().executeUnChecked(SID_OBJECT_SELECT,uno::Sequence< beans::PropertyValue>());
418 }
419 
420 //----------------------------------------------------------------------------
421 
422 void OReportSection::MouseMove( const MouseEvent& rMEvt )
423 {
424 	m_pFunc->MouseMove( rMEvt );
425 
426 }
427 //----------------------------------------------------------------------------
428 void OReportSection::SetGridVisible(sal_Bool _bVisible)
429 {
430 	m_pView->SetGridVisible( _bVisible );
431 }
432 //------------------------------------------------------------------------------
433 void OReportSection::SelectAll(const sal_uInt16 _nObjectType)
434 {
435 	if ( m_pView )
436     {
437         if ( _nObjectType == OBJ_NONE )
438             m_pView->MarkAllObj();
439         else
440         {
441             m_pView->UnmarkAll();
442             SdrObjListIter aIter(*m_pPage,IM_DEEPNOGROUPS);
443             SdrObject* pObjIter = NULL;
444             while( (pObjIter = aIter.Next()) != NULL )
445             {
446                 if ( pObjIter->GetObjIdentifier() == _nObjectType )
447                     m_pView->MarkObj( pObjIter, m_pView->GetSdrPageView() );
448             }
449         }
450     }
451 }
452 void lcl_insertMenuItemImages(PopupMenu& rContextMenu,OReportController& rController,const uno::Reference< report::XReportDefinition>& _xReportDefinition,uno::Reference<frame::XFrame>& _rFrame,sal_Bool _bHiContrast)
453 {
454     const sal_uInt16 nCount = rContextMenu.GetItemCount();
455 	for (sal_uInt16 i = 0; i < nCount; ++i)
456 	{
457 		if ( MENUITEM_SEPARATOR != rContextMenu.GetItemType(i))
458 		{
459 			const sal_uInt16 nId = rContextMenu.GetItemId(i);
460             PopupMenu* pPopupMenu = rContextMenu.GetPopupMenu( nId );
461             if ( pPopupMenu )
462             {
463                 lcl_insertMenuItemImages(*pPopupMenu,rController,_xReportDefinition,_rFrame,_bHiContrast);
464             }
465             else
466             {
467                 const ::rtl::OUString sCommand = rContextMenu.GetItemCommand(nId);
468                 rContextMenu.SetItemImage(nId,framework::GetImageFromURL(_rFrame,sCommand,sal_False,_bHiContrast));
469                 if ( nId == SID_PAGEHEADERFOOTER )
470                 {
471                     String sText = String(ModuleRes((_xReportDefinition.is() && _xReportDefinition->getPageHeaderOn()) ? RID_STR_PAGEHEADERFOOTER_DELETE : RID_STR_PAGEHEADERFOOTER_INSERT));
472                     rContextMenu.SetItemText(nId,sText);
473                 }
474                 else if ( nId == SID_REPORTHEADERFOOTER )
475                 {
476                     String sText = String(ModuleRes((_xReportDefinition.is() && _xReportDefinition->getReportHeaderOn()) ? RID_STR_REPORTHEADERFOOTER_DELETE : RID_STR_REPORTHEADERFOOTER_INSERT));
477                     rContextMenu.SetItemText(nId,sText);
478                 }
479             }
480 			rContextMenu.CheckItem(nId,rController.isCommandChecked(nId));
481 			rContextMenu.EnableItem(nId,rController.isCommandEnabled(nId));
482 		}
483 	} // for (sal_uInt16 i = 0; i < nCount; ++i)
484 }
485 //----------------------------------------------------------------------------
486 void OReportSection::Command( const CommandEvent& _rCEvt )
487 {
488     Window::Command(_rCEvt);
489 	switch (_rCEvt.GetCommand())
490 	{
491 		case COMMAND_CONTEXTMENU:
492 		{
493             const StyleSettings& rSettings = Application::GetSettings().GetStyleSettings();
494             sal_Bool bHiContrast = rSettings.GetHighContrastMode();
495             OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
496             uno::Reference<frame::XFrame> xFrame = rController.getFrame();
497             PopupMenu aContextMenu( ModuleRes( RID_MENU_REPORT ) );
498             uno::Reference< report::XReportDefinition> xReportDefinition = getSection()->getReportDefinition();
499 
500             lcl_insertMenuItemImages(aContextMenu,rController,xReportDefinition,xFrame,bHiContrast);
501 
502 			Point aPos = _rCEvt.GetMousePosPixel();
503 			m_pView->EndAction();
504 			const sal_uInt16 nId = aContextMenu.Execute(this, aPos);
505 			if ( nId )
506 			{
507                 uno::Sequence< beans::PropertyValue> aArgs;
508                 if ( nId == SID_ATTR_CHAR_COLOR_BACKGROUND )
509                 {
510                     aArgs.realloc(1);
511                     aArgs[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Selection"));
512                     aArgs[0].Value <<= m_xSection;
513                 }
514 				rController.executeChecked(nId,aArgs);
515 			}
516 		}
517 		break;
518 	}
519 }
520 // -----------------------------------------------------------------------------
521 void OReportSection::_propertyChanged(const beans::PropertyChangeEvent& _rEvent) throw( uno::RuntimeException)
522 {
523 	if ( m_xSection.is() )
524 	{
525 		if ( _rEvent.Source == m_xSection || PROPERTY_BACKCOLOR == _rEvent.PropertyName )
526 		{
527             sal_Int32 nColor = m_xSection->getBackColor();
528             if ( nColor == (sal_Int32)COL_TRANSPARENT )
529                 nColor = getStyleProperty<sal_Int32>(m_xSection->getReportDefinition(),PROPERTY_BACKCOLOR);
530 			m_pView->SetApplicationDocumentColor(nColor);
531 			Invalidate(INVALIDATE_NOCHILDREN|INVALIDATE_NOERASE);
532 		}
533 		else
534 		{
535             uno::Reference<report::XReportDefinition> xReportDefinition = m_xSection->getReportDefinition();
536             const sal_Int32 nLeftMargin  = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_LEFTMARGIN);
537             const sal_Int32 nRightMargin = getStyleProperty<sal_Int32>(xReportDefinition,PROPERTY_RIGHTMARGIN);
538             const sal_Int32 nPaperWidth  = getStyleProperty<awt::Size>(xReportDefinition,PROPERTY_PAPERSIZE).Width;
539 
540             if ( _rEvent.PropertyName == PROPERTY_LEFTMARGIN )
541             {
542 	            m_pPage->SetLftBorder(nLeftMargin);
543             }
544             else if ( _rEvent.PropertyName == PROPERTY_RIGHTMARGIN )
545             {
546 	            m_pPage->SetRgtBorder(nRightMargin);
547             }
548             const Size aOldPageSize = m_pPage->GetSize();
549             sal_Int32 nNewHeight = 5*m_xSection->getHeight();
550             if ( aOldPageSize.Height() != nNewHeight || nPaperWidth != aOldPageSize.Width() )
551             {
552 		        m_pPage->SetSize( Size( nPaperWidth,nNewHeight) );
553 		        const Size aPageSize = m_pPage->GetSize();
554 		        m_pView->SetWorkArea( Rectangle( Point( nLeftMargin, 0), Size(aPageSize.Width() - nLeftMargin - nRightMargin,aPageSize.Height()) ) );
555             }
556             impl_adjustObjectSizePosition(nPaperWidth,nLeftMargin,nRightMargin);
557             m_pParent->Invalidate(INVALIDATE_UPDATE | INVALIDATE_TRANSPARENT);
558 		}
559 	}
560 }
561 void OReportSection::impl_adjustObjectSizePosition(sal_Int32 i_nPaperWidth,sal_Int32 i_nLeftMargin,sal_Int32 i_nRightMargin)
562 {
563     try
564     {
565 	    sal_Int32 nRightBorder = i_nPaperWidth - i_nRightMargin;
566         const sal_Int32 nCount = m_xSection->getCount();
567         for (sal_Int32 i = 0; i < nCount; ++i)
568         {
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;
575             if ( pObject )
576             {
577                 OObjectBase* pBase = dynamic_cast<OObjectBase*>(pObject);
578                 pBase->EndListening(sal_False);
579                 if ( aPos.X < i_nLeftMargin )
580                 {
581                     aPos.X  = i_nLeftMargin;
582                     bChanged = true;
583                 }
584                 if ( (aPos.X + aSize.Width) > nRightBorder )
585                 {
586                     aPos.X = nRightBorder - aSize.Width;
587                     if ( aPos.X < i_nLeftMargin )
588                     {
589                         aSize.Width += aPos.X - i_nLeftMargin;
590                         aPos.X = i_nLeftMargin;
591                         // add listener around
592                         pBase->StartListening();
593                         xReportComponent->setSize(aSize);
594                         pBase->EndListening(sal_False);
595                     }
596                     bChanged = true;
597                 }
598                 if ( aPos.Y < 0 )
599                     aPos.Y = 0;
600                 if ( bChanged )
601                 {
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());
609 
610                     pObject->RecalcBoundRect();
611                 }
612                 pBase->StartListening();
613             }
614         } // for (sal_Int32 i = 0; i < nCount; ++i)
615     }
616     catch(uno::Exception)
617     {
618         OSL_ENSURE(0,"Exception caught: OReportSection::_propertyChanged(");
619     }
620 }
621 //------------------------------------------------------------------------------
622 sal_Bool OReportSection::handleKeyEvent(const KeyEvent& _rEvent)
623 {
624 	return m_pFunc.get() ? m_pFunc->handleKeyEvent(_rEvent) : sal_False;
625 }
626 // -----------------------------------------------------------------------------
627 void OReportSection::deactivateOle()
628 {
629     if ( m_pFunc.get() )
630 		m_pFunc->deactivateOle(true);
631 }
632 // -----------------------------------------------------------------------------
633 void OReportSection::createDefault(const ::rtl::OUString& _sType)
634 {
635     SdrObject* pObj = m_pView->GetCreateObj();//rMarkList.GetMark(0)->GetObj();
636     if ( !pObj )
637         return;
638     createDefault(_sType,pObj);
639 }
640 // -----------------------------------------------------------------------------
641 void OReportSection::createDefault(const ::rtl::OUString& _sType,SdrObject* _pObj)
642 {
643     sal_Bool bAttributesAppliedFromGallery = sal_False;
644 
645 	if ( GalleryExplorer::GetSdrObjCount( GALLERY_THEME_POWERPOINT ) )
646 	{
647 		std::vector< rtl::OUString > aObjList;
648 		if ( GalleryExplorer::FillObjListTitle( GALLERY_THEME_POWERPOINT, aObjList ) )
649 		{
650             std::vector< rtl::OUString >::iterator aIter = aObjList.begin();
651             std::vector< rtl::OUString >::iterator aEnd = aObjList.end();
652 			for (sal_uInt32 i=0 ; aIter != aEnd; ++aIter,++i)
653 			{
654 				if ( aIter->equalsIgnoreAsciiCase( _sType ) )
655 				{
656 					OReportModel aReportModel(NULL);
657 					SfxItemPool& rPool = aReportModel.GetItemPool();
658 					rPool.FreezeIdRanges();
659 					if ( GalleryExplorer::GetSdrObj( GALLERY_THEME_POWERPOINT, i, &aReportModel ) )
660 					{
661 						const SdrObject* pSourceObj = aReportModel.GetPage( 0 )->GetObj( 0 );
662 						if( pSourceObj )
663 						{
664 							const SfxItemSet& rSource = pSourceObj->GetMergedItemSet();
665 							SfxItemSet aDest( _pObj->GetModel()->GetItemPool(), 				// ranges from SdrAttrObj
666 							SDRATTR_START, SDRATTR_SHADOW_LAST,
667 							SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
668 							SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
669 							// Graphic Attributes
670 							SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
671 							// 3d Properties
672 							SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
673 							// CustomShape properties
674 							SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
675 							// range from SdrTextObj
676 							EE_ITEMS_START, EE_ITEMS_END,
677 							// end
678 							0, 0);
679 							aDest.Set( rSource );
680 							_pObj->SetMergedItemSet( aDest );
681 							sal_Int32 nAngle = pSourceObj->GetRotateAngle();
682 							if ( nAngle )
683 							{
684 								double a = nAngle * F_PI18000;
685 								_pObj->NbcRotate( _pObj->GetSnapRect().Center(), nAngle, sin( a ), cos( a ) );
686 							}
687 							bAttributesAppliedFromGallery = sal_True;
688 						}
689 					}
690 					break;
691 				}
692 			}
693 		}
694 	}
695 	if ( !bAttributesAppliedFromGallery )
696 	{
697 		_pObj->SetMergedItem( SvxAdjustItem( SVX_ADJUST_CENTER ,ITEMID_ADJUST) );
698 		_pObj->SetMergedItem( SdrTextVertAdjustItem( SDRTEXTVERTADJUST_CENTER ) );
699 		_pObj->SetMergedItem( SdrTextHorzAdjustItem( SDRTEXTHORZADJUST_BLOCK ) );
700 		_pObj->SetMergedItem( SdrTextAutoGrowHeightItem( sal_False ) );
701 		((SdrObjCustomShape*)_pObj)->MergeDefaultAttributes( &_sType );
702 	}
703 }
704 // -----------------------------------------------------------------------------
705 uno::Reference< report::XReportComponent > OReportSection::getCurrentControlModel() const
706 {
707 	uno::Reference< report::XReportComponent > xModel;
708 	if ( m_pView )
709 	{
710 		const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
711         sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
712 
713         if ( nMarkCount == 1 )
714         {
715 			SdrObject* pDlgEdObj = rMarkList.GetMark(0)->GetMarkedSdrObj();
716 			OObjectBase* pObj = dynamic_cast<OObjectBase*>(pDlgEdObj);
717 			if ( pObj )
718 				xModel = pObj->getReportComponent().get();
719 		}
720 	}
721 	return xModel;
722 }
723 // -----------------------------------------------------------------------------
724 void OReportSection::fillControlModelSelection(::std::vector< uno::Reference< uno::XInterface > >& _rSelection) const
725 {
726     if ( m_pView )
727 	{
728 		const SdrMarkList& rMarkList = m_pView->GetMarkedObjectList();
729         const sal_uInt32 nMarkCount = rMarkList.GetMarkCount();
730 
731         for (sal_uInt32 i=0; i < nMarkCount; ++i)
732         {
733 			const SdrObject* pDlgEdObj = rMarkList.GetMark(i)->GetMarkedSdrObj();
734 			const OObjectBase* pObj = dynamic_cast<const OObjectBase*>(pDlgEdObj);
735 			if ( pObj )
736                 _rSelection.push_back(pObj->getReportComponent());
737 		}
738 	}
739 }
740 // -----------------------------------------------------------------------------
741 sal_Int8 OReportSection::AcceptDrop( const AcceptDropEvent& _rEvt )
742 {
743     OSL_TRACE("AcceptDrop::DropEvent.Action %i\n", _rEvt.mnAction);
744 
745     ::Point aDropPos(_rEvt.maPosPixel);
746     const MouseEvent aMouseEvt(aDropPos);
747     if ( m_pFunc->isOverlapping(aMouseEvt) )
748         return DND_ACTION_NONE;
749 
750     if ( _rEvt.mnAction == DND_ACTION_COPY ||
751          _rEvt.mnAction == DND_ACTION_LINK
752          )
753     {
754 		if (!m_pParent) return DND_ACTION_NONE;
755 		sal_uInt16 nCurrentPosition = 0;
756 		nCurrentPosition = m_pParent->getViewsWindow()->getPosition(m_pParent);
757 		if (_rEvt.mnAction == DND_ACTION_COPY )
758 		{
759 			// we must assure, we can't drop in the top section
760 			if (nCurrentPosition < 1)
761 			{
762 				return DND_ACTION_NONE;
763 			}
764 			return DND_ACTION_LINK;
765 		}
766 		if (_rEvt.mnAction == DND_ACTION_LINK)
767 		{
768 			// we must assure, we can't drop in the bottom section
769 			if (m_pParent->getViewsWindow()->getSectionCount() > (nCurrentPosition + 1)  )
770 			{
771 				return DND_ACTION_COPY;
772 			}
773 			return DND_ACTION_NONE;
774 		}
775     }
776     else
777     {
778         const DataFlavorExVector& rFlavors = GetDataFlavorExVector();
779         if (   ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors)
780             || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR) )
781             return _rEvt.mnAction;
782 
783         const sal_Int8 nDropOption = ( OReportExchange::canExtract(rFlavors) ) ? DND_ACTION_COPYMOVE : DND_ACTION_NONE;
784 
785         return nDropOption;
786     }
787     return DND_ACTION_NONE;
788 }
789 
790 // -----------------------------------------------------------------------------
791 sal_Int8 OReportSection::ExecuteDrop( const ExecuteDropEvent& _rEvt )
792 {
793     OSL_TRACE("ExecuteDrop::DropEvent.Action %i\n", _rEvt.mnAction);
794     ::Point aDropPos(PixelToLogic(_rEvt.maPosPixel));
795     const MouseEvent aMouseEvt(aDropPos);
796     if ( m_pFunc->isOverlapping(aMouseEvt) )
797         return DND_ACTION_NONE;
798 
799     sal_Int8 nDropOption = DND_ACTION_NONE;
800     const TransferableDataHelper aDropped(_rEvt.maDropEvent.Transferable);
801     DataFlavorExVector& rFlavors = aDropped.GetDataFlavorExVector();
802     bool bMultipleFormat = ::svx::OMultiColumnTransferable::canExtractDescriptor(rFlavors);
803     if ( OReportExchange::canExtract(rFlavors) )
804     {
805         OReportExchange::TSectionElements aCopies = OReportExchange::extractCopies(aDropped);
806 		Paste(aCopies,true);
807         nDropOption = DND_ACTION_COPYMOVE;
808         m_pParent->getViewsWindow()->BrkAction();
809         m_pParent->getViewsWindow()->unmarkAllObjects(m_pView);
810         //m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
811     } // if ( OReportExchange::canExtract(rFlavors) )
812     else if ( bMultipleFormat
813         || ::svx::OColumnTransferable::canExtractColumnDescriptor(rFlavors, CTF_FIELD_DESCRIPTOR | CTF_CONTROL_EXCHANGE | CTF_COLUMN_DESCRIPTOR) )
814     {
815         m_pParent->getViewsWindow()->getView()->setMarked(m_pView,sal_True);
816         m_pView->UnmarkAll();
817         const Rectangle& rRect = m_pView->GetWorkArea();
818         if ( aDropPos.X() < rRect.Left() )
819             aDropPos.X() = rRect.Left();
820         else if ( aDropPos.X() > rRect.Right() )
821             aDropPos.X() = rRect.Right();
822 
823         if ( aDropPos.Y() > rRect.Bottom() )
824             aDropPos.Y() = rRect.Bottom();
825 
826         uno::Sequence<beans::PropertyValue> aValues;
827         if ( !bMultipleFormat )
828         {
829             ::svx::ODataAccessDescriptor aDescriptor = ::svx::OColumnTransferable::extractColumnDescriptor(aDropped);
830 
831             aValues.realloc(1);
832             aValues[0].Value <<= aDescriptor.createPropertyValueSequence();
833         } // if ( !bMultipleFormat )
834         else
835             aValues = ::svx::OMultiColumnTransferable::extractDescriptor(aDropped);
836 
837         beans::PropertyValue* pIter = aValues.getArray();
838         beans::PropertyValue* pEnd  = pIter + aValues.getLength();
839         for(;pIter != pEnd; ++pIter)
840         {
841             uno::Sequence<beans::PropertyValue> aCurrent;
842             pIter->Value >>= aCurrent;
843             sal_Int32 nLength = aCurrent.getLength();
844             if ( nLength )
845             {
846                 aCurrent.realloc(nLength + 3);
847                 aCurrent[nLength].Name = PROPERTY_POSITION;
848                 aCurrent[nLength++].Value <<= AWTPoint(aDropPos);
849                 // give also the DND Action (Shift|Ctrl) Key to really say what we want
850                 aCurrent[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DNDAction"));
851                 aCurrent[nLength++].Value <<= _rEvt.mnAction;
852 
853                 aCurrent[nLength].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Section"));
854                 aCurrent[nLength++].Value <<= getSection();
855                 pIter->Value <<= aCurrent;
856             }
857         }
858 
859         // we use this way to create undo actions
860         OReportController& rController = m_pParent->getViewsWindow()->getView()->getReportView()->getController();
861 		rController.executeChecked(SID_ADD_CONTROL_PAIR,aValues);
862         nDropOption = DND_ACTION_COPY;
863     }
864 	return nDropOption;
865 }
866 // -----------------------------------------------------------------------------
867 void OReportSection::stopScrollTimer()
868 {
869     m_pFunc->stopScrollTimer();
870 }
871 // -----------------------------------------------------------------------------
872 bool OReportSection::isUiActive() const
873 {
874     return m_pFunc->isUiActive();
875 }
876 // -----------------------------------------------------------------------------
877 // =============================================================================
878 }
879 // =============================================================================
880