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