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