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