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

Generated by: LCOV version 1.10