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