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