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

Generated by: LCOV version 1.10