LCOV - code coverage report
Current view: top level - libreoffice/reportdesign/source/ui/report - ReportSection.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 454 0.0 %
Date: 2012-12-27 Functions: 0 31 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10