LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - SectionWindow.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 1 222 0.5 %
Date: 2015-06-13 12:38:46 Functions: 2 27 7.4 %
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 "SectionWindow.hxx"
      20             : #include "ReportWindow.hxx"
      21             : #include "rptui_slotid.hrc"
      22             : #include "ReportController.hxx"
      23             : #include "SectionView.hxx"
      24             : #include "RptDef.hxx"
      25             : #include "ReportSection.hxx"
      26             : #include "DesignView.hxx"
      27             : #include "uistrings.hrc"
      28             : #include "helpids.hrc"
      29             : #include "RptResId.hrc"
      30             : #include "StartMarker.hxx"
      31             : #include "EndMarker.hxx"
      32             : #include "ViewsWindow.hxx"
      33             : 
      34             : #include <svtools/colorcfg.hxx>
      35             : #include <functional>
      36             : #include <algorithm>
      37             : #include <vcl/svapp.hxx>
      38             : #include <vcl/settings.hxx>
      39             : 
      40             : #include <connectivity/dbtools.hxx>
      41             : 
      42             : namespace rptui
      43             : {
      44             : using namespace ::com::sun::star;
      45             : using namespace ::comphelper;
      46             : 
      47           0 : OSectionWindow::OSectionWindow( OViewsWindow* _pParent,const uno::Reference< report::XSection >& _xSection,const OUString& _sColorEntry)
      48             : : Window( _pParent,WB_DIALOGCONTROL)
      49             : ,OPropertyChangeListener(m_aMutex)
      50             : ,m_pParent(_pParent)
      51             : ,m_aStartMarker( VclPtr<rptui::OStartMarker>::Create(this,_sColorEntry))
      52             : ,m_aReportSection( VclPtr<rptui::OReportSection>::Create(this,_xSection))
      53             : ,m_aSplitter(VclPtr<Splitter>::Create(this))
      54           0 : ,m_aEndMarker( VclPtr<rptui::OEndMarker>::Create(this,_sColorEntry))
      55             : {
      56           0 :     SetUniqueId(UID_RPT_SECTIONSWINDOW);
      57           0 :     const MapMode& rMapMode = _pParent->GetMapMode();
      58           0 :     SetMapMode( rMapMode );
      59           0 :     ImplInitSettings();
      60             :     // TRY
      61           0 :     m_aSplitter->SetMapMode( MapMode( MAP_100TH_MM ) );
      62           0 :     m_aSplitter->SetStartSplitHdl(LINK(this, OSectionWindow,StartSplitHdl));
      63           0 :     m_aSplitter->SetSplitHdl(LINK(this, OSectionWindow,SplitHdl));
      64           0 :     m_aSplitter->SetEndSplitHdl(LINK(this, OSectionWindow,EndSplitHdl));
      65           0 :     m_aSplitter->SetBackground( Wallpaper( Application::GetSettings().GetStyleSettings().GetFaceColor() ));
      66           0 :     m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,_xSection->getHeight())).Height());
      67             : 
      68             : 
      69           0 :     m_aStartMarker->setCollapsedHdl(LINK(this,OSectionWindow,Collapsed));
      70             : 
      71           0 :     m_aStartMarker->zoom(rMapMode.GetScaleX());
      72           0 :     setZoomFactor(rMapMode.GetScaleX(), *m_aReportSection.get());
      73           0 :     setZoomFactor(rMapMode.GetScaleX(), *m_aSplitter.get());
      74           0 :     setZoomFactor(rMapMode.GetScaleX(), *m_aEndMarker.get());
      75             : 
      76           0 :     m_aSplitter->Show();
      77           0 :     m_aStartMarker->Show();
      78           0 :     m_aReportSection->Show();
      79           0 :     m_aEndMarker->Show();
      80           0 :     Show();
      81             : 
      82           0 :     m_pSectionMulti = new OPropertyChangeMultiplexer(this,_xSection.get());
      83           0 :     m_pSectionMulti->addProperty(PROPERTY_NAME);
      84           0 :     m_pSectionMulti->addProperty(PROPERTY_HEIGHT);
      85             : 
      86           0 :     beans::PropertyChangeEvent aEvent;
      87           0 :     aEvent.Source = _xSection;
      88           0 :     aEvent.PropertyName = PROPERTY_NAME;
      89           0 :     uno::Reference< report::XGroup > xGroup(_xSection->getGroup());
      90           0 :     if ( xGroup.is() )
      91             :     {
      92           0 :         m_pGroupMulti = new OPropertyChangeMultiplexer(this,xGroup.get());
      93           0 :         m_pGroupMulti->addProperty(PROPERTY_EXPRESSION);
      94           0 :         aEvent.Source = xGroup;
      95           0 :         aEvent.PropertyName = PROPERTY_EXPRESSION;
      96             :     }
      97             : 
      98           0 :     _propertyChanged(aEvent);
      99           0 : }
     100             : 
     101           0 : OSectionWindow::~OSectionWindow()
     102             : {
     103           0 :     disposeOnce();
     104           0 : }
     105             : 
     106           0 : void OSectionWindow::dispose()
     107             : {
     108             :     try
     109             :     {
     110           0 :         if ( m_pSectionMulti.is() )
     111           0 :             m_pSectionMulti->dispose();
     112           0 :         if ( m_pGroupMulti.is() )
     113           0 :             m_pGroupMulti->dispose();
     114             :     }
     115           0 :     catch (uno::Exception&)
     116             :     {
     117             :     }
     118           0 :     m_aStartMarker.disposeAndClear();
     119           0 :     m_aReportSection.disposeAndClear();
     120           0 :     m_aSplitter.disposeAndClear();
     121           0 :     m_aEndMarker.disposeAndClear();
     122           0 :     m_pParent.clear();
     123           0 :     vcl::Window::dispose();
     124           0 : }
     125             : 
     126           0 : void OSectionWindow::_propertyChanged(const beans::PropertyChangeEvent& _rEvent)
     127             :     throw (uno::RuntimeException, std::exception)
     128             : {
     129           0 :     SolarMutexGuard g;
     130           0 :     const uno::Reference< report::XSection > xSection(_rEvent.Source,uno::UNO_QUERY);
     131           0 :     if ( xSection.is() )
     132             :     {
     133           0 :         const uno::Reference< report::XSection> xCurrentSection = m_aReportSection->getSection();
     134           0 :         if ( _rEvent.PropertyName == PROPERTY_HEIGHT )
     135             :         {
     136           0 :             m_pParent->getView()->SetUpdateMode(false);
     137             :             //Resize();
     138           0 :             m_pParent->getView()->notifySizeChanged();
     139           0 :             m_pParent->resize(*this);
     140           0 :             m_pParent->getView()->SetUpdateMode(true);
     141             :             // getViewsWindow()->getView()->getReportView()->getController().resetZoomType();
     142             :         }
     143           0 :         else if ( _rEvent.PropertyName == PROPERTY_NAME && !xSection->getGroup().is() )
     144             :         {
     145           0 :             uno::Reference< report::XReportDefinition > xReport = xSection->getReportDefinition();
     146           0 :             if (    setReportSectionTitle(xReport,RID_STR_REPORT_HEADER,::std::mem_fun(&OReportHelper::getReportHeader),::std::mem_fun(&OReportHelper::getReportHeaderOn))
     147           0 :                 ||  setReportSectionTitle(xReport,RID_STR_REPORT_FOOTER,::std::mem_fun(&OReportHelper::getReportFooter),::std::mem_fun(&OReportHelper::getReportFooterOn))
     148           0 :                 ||  setReportSectionTitle(xReport,RID_STR_PAGE_HEADER,::std::mem_fun(&OReportHelper::getPageHeader),::std::mem_fun(&OReportHelper::getPageHeaderOn))
     149           0 :                 ||  setReportSectionTitle(xReport,RID_STR_PAGE_FOOTER,::std::mem_fun(&OReportHelper::getPageFooter),::std::mem_fun(&OReportHelper::getPageFooterOn)) )
     150             :             {
     151           0 :                 m_aStartMarker->Invalidate(InvalidateFlags::NoErase);
     152             :             }
     153             :             else
     154             :             {
     155           0 :                 OUString sTitle = ModuleRes(RID_STR_DETAIL);
     156           0 :                 m_aStartMarker->setTitle(sTitle);
     157           0 :                 m_aStartMarker->Invalidate(InvalidateFlags::Children);
     158           0 :             }
     159           0 :         }
     160             :     }
     161           0 :     else if ( _rEvent.PropertyName == PROPERTY_EXPRESSION )
     162             :     {
     163           0 :         uno::Reference< report::XGroup > xGroup(_rEvent.Source,uno::UNO_QUERY);
     164           0 :         if ( xGroup.is() && !setGroupSectionTitle(xGroup,RID_STR_HEADER,::std::mem_fun(&OGroupHelper::getHeader),::std::mem_fun(&OGroupHelper::getHeaderOn)))
     165             :         {
     166           0 :             setGroupSectionTitle(xGroup,RID_STR_FOOTER,::std::mem_fun(&OGroupHelper::getFooter),::std::mem_fun(&OGroupHelper::getFooterOn));
     167           0 :         }
     168           0 :     }
     169           0 : }
     170             : 
     171           0 : bool OSectionWindow::setReportSectionTitle(const uno::Reference< report::XReportDefinition>& _xReport,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OReportHelper> _pGetSection, const ::std::mem_fun_t<bool,OReportHelper>& _pIsSectionOn)
     172             : {
     173           0 :     OReportHelper aReportHelper(_xReport);
     174           0 :     const bool bRet = _pIsSectionOn(&aReportHelper) && _pGetSection(&aReportHelper) == m_aReportSection->getSection();
     175           0 :     if ( bRet )
     176             :     {
     177           0 :         OUString sTitle = ModuleRes(_nResId);
     178           0 :         m_aStartMarker->setTitle(sTitle);
     179           0 :         m_aStartMarker->Invalidate(InvalidateFlags::Children);
     180             :     }
     181           0 :     return bRet;
     182             : }
     183             : 
     184           0 : bool OSectionWindow::setGroupSectionTitle(const uno::Reference< report::XGroup>& _xGroup,sal_uInt16 _nResId,::std::mem_fun_t<uno::Reference<report::XSection> , OGroupHelper> _pGetSection, const ::std::mem_fun_t<bool,OGroupHelper>& _pIsSectionOn)
     185             : {
     186           0 :     OGroupHelper aGroupHelper(_xGroup);
     187           0 :     const bool bRet = _pIsSectionOn(&aGroupHelper) && _pGetSection(&aGroupHelper) == m_aReportSection->getSection() ;
     188           0 :     if ( bRet )
     189             :     {
     190           0 :         OUString sExpression = _xGroup->getExpression();
     191           0 :         OUString sLabel = getViewsWindow()->getView()->getReportView()->getController().getColumnLabel_throw(sExpression);
     192           0 :         if ( !sLabel.isEmpty() )
     193             :         {
     194           0 :             sExpression = sLabel;
     195             :         }
     196             : 
     197           0 :         OUString sTitle( ModuleRes(_nResId).toString() );
     198           0 :         sTitle = sTitle.replaceFirst("#", sExpression);
     199           0 :         m_aStartMarker->setTitle( sTitle );
     200           0 :         m_aStartMarker->Invalidate(InvalidateFlags::Children);
     201             :     }
     202           0 :     return bRet;
     203             : }
     204             : 
     205           0 : void OSectionWindow::ImplInitSettings()
     206             : {
     207             :     static bool t = false;
     208           0 :     if ( t )
     209             :     {
     210           0 :     EnableChildTransparentMode( true );
     211           0 :     SetParentClipMode( ParentClipMode::NoClip );
     212           0 :     SetPaintTransparent( true );
     213             :     }
     214           0 :     SetBackground( );
     215           0 : }
     216             : 
     217           0 : void OSectionWindow::DataChanged( const DataChangedEvent& rDCEvt )
     218             : {
     219           0 :     Window::DataChanged( rDCEvt );
     220             : 
     221           0 :     if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
     222           0 :          (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
     223             :     {
     224           0 :         ImplInitSettings();
     225           0 :         Invalidate();
     226             :     }
     227           0 : }
     228             : 
     229           0 : void OSectionWindow::Resize()
     230             : {
     231           0 :     Window::Resize();
     232             : 
     233           0 :     Size aOutputSize = GetOutputSizePixel();
     234           0 :     Fraction aEndWidth(long(REPORT_ENDMARKER_WIDTH));
     235           0 :     aEndWidth *= GetMapMode().GetScaleX();
     236             : 
     237           0 :     const Point aThumbPos = m_pParent->getView()->getThumbPos();
     238           0 :     aOutputSize.Width() -= aThumbPos.X();
     239           0 :     aOutputSize.Height() -=  m_aSplitter->GetSizePixel().Height();
     240             : 
     241           0 :     if ( m_aStartMarker->isCollapsed() )
     242             :     {
     243           0 :         Point aPos(0,0);
     244           0 :         m_aStartMarker->SetPosSizePixel(aPos,aOutputSize);
     245             :     }
     246             :     else
     247             :     {
     248           0 :         const bool bShowEndMarker = m_pParent->getView()->GetTotalWidth() <= (aThumbPos.X() +  aOutputSize.Width() );
     249             : 
     250           0 :         Fraction aStartWidth(long(REPORT_STARTMARKER_WIDTH));
     251           0 :         aStartWidth *= GetMapMode().GetScaleX();
     252             : 
     253             :         // set start marker
     254           0 :         m_aStartMarker->SetPosSizePixel(Point(0,0),Size(aStartWidth,aOutputSize.Height()));
     255             : 
     256             :         // set report section
     257           0 :         const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
     258           0 :         Size aSectionSize = LogicToPixel( Size( 0,xSection->getHeight() ) );
     259           0 :         Point aReportPos(aStartWidth,0);
     260           0 :         aSectionSize.Width() = aOutputSize.Width() - (long)aStartWidth;
     261           0 :         if ( bShowEndMarker )
     262           0 :             aSectionSize.Width() -= (long)aEndWidth;
     263             : 
     264           0 :         m_aReportSection->SetPosSizePixel(aReportPos,aSectionSize);
     265             : 
     266             :         // set splitter
     267           0 :         aReportPos.Y() += aSectionSize.Height();
     268           0 :         m_aSplitter->SetPosSizePixel(aReportPos,Size(aSectionSize.Width(),m_aSplitter->GetSizePixel().Height()));
     269           0 :         aSectionSize.Height() = (long)(1000 * (double)GetMapMode().GetScaleY());
     270           0 :         m_aSplitter->SetDragRectPixel( Rectangle(Point(aStartWidth,0),aSectionSize));
     271             : 
     272             :         // set end marker
     273           0 :         aReportPos.X() += aSectionSize.Width();
     274           0 :         aReportPos.Y() = 0;
     275           0 :         m_aEndMarker->Show(bShowEndMarker);
     276           0 :         m_aEndMarker->SetPosSizePixel(aReportPos,Size(aEndWidth,aOutputSize.Height()));
     277           0 :     }
     278           0 : }
     279             : 
     280           0 : void OSectionWindow::setCollapsed(bool _bCollapsed)
     281             : {
     282           0 :     if ( m_aStartMarker->isCollapsed() != _bCollapsed )
     283             :     {
     284           0 :         m_aStartMarker->setCollapsed(_bCollapsed);
     285             :     }
     286           0 : }
     287             : 
     288           0 : void OSectionWindow::showProperties()
     289             : {
     290           0 :     m_pParent->getView()->showProperties( m_aReportSection->getSection().get() );
     291           0 : }
     292             : 
     293           0 : void OSectionWindow::setMarked(bool _bMark)
     294             : {
     295           0 :     m_aStartMarker->setMarked(_bMark);
     296           0 :     m_aEndMarker->setMarked(_bMark);
     297           0 : }
     298             : 
     299           0 : IMPL_LINK( OSectionWindow, Collapsed, OColorListener *, _pMarker )
     300             : {
     301           0 :     if ( _pMarker )
     302             :     {
     303           0 :         bool bShow = !_pMarker->isCollapsed();
     304           0 :         m_aReportSection->Show(bShow);
     305           0 :         m_aEndMarker->Show(bShow);
     306           0 :         m_aSplitter->Show(bShow);
     307             : 
     308           0 :         m_pParent->resize(*this);
     309             :     }
     310           0 :     return 0L;
     311             : }
     312             : 
     313           0 : void OSectionWindow::zoom(const Fraction& _aZoom)
     314             : {
     315           0 :     setZoomFactor(_aZoom,*this);
     316           0 :     m_aStartMarker->zoom(_aZoom);
     317             : 
     318           0 :     setZoomFactor(_aZoom, *m_aReportSection.get());
     319           0 :     setZoomFactor(_aZoom, *m_aSplitter.get());
     320           0 :     setZoomFactor(_aZoom, *m_aEndMarker.get());
     321           0 :     Invalidate();
     322           0 : }
     323             : 
     324           0 : IMPL_LINK( OSectionWindow, StartSplitHdl, Splitter*,  )
     325             : {
     326           0 :     const OUString sUndoAction( ModuleRes( RID_STR_UNDO_CHANGE_SIZE ) );
     327           0 :     getViewsWindow()->getView()->getReportView()->getController().getUndoManager().EnterListAction( sUndoAction, OUString() );
     328           0 :     return 0L;
     329             : }
     330             : 
     331           0 : IMPL_LINK( OSectionWindow, EndSplitHdl, Splitter*,  )
     332             : {
     333           0 :     getViewsWindow()->getView()->getReportView()->getController().getUndoManager().LeaveListAction();
     334           0 :     return 0L;
     335             : }
     336             : 
     337           0 : IMPL_LINK( OSectionWindow, SplitHdl, Splitter*, _pSplitter )
     338             : {
     339           0 :     if ( !getViewsWindow()->getView()->getReportView()->getController().isEditable() )
     340             :     {
     341           0 :         return 0L;
     342             :     }
     343             : 
     344           0 :     sal_Int32 nSplitPos = _pSplitter->GetSplitPosPixel();
     345             : 
     346           0 :     const uno::Reference< report::XSection> xSection = m_aReportSection->getSection();
     347           0 :     nSplitPos = m_aSplitter->PixelToLogic(Size(0,nSplitPos)).Height();
     348             : 
     349           0 :     const sal_Int32 nCount = xSection->getCount();
     350           0 :     for (sal_Int32 i = 0; i < nCount; ++i)
     351             :     {
     352           0 :         uno::Reference<report::XReportComponent> xReportComponent(xSection->getByIndex(i),uno::UNO_QUERY);
     353           0 :         if ( xReportComponent.is() )
     354             :         {
     355           0 :             nSplitPos = ::std::max(nSplitPos,xReportComponent->getPositionY() + xReportComponent->getHeight());
     356             :         }
     357           0 :     }
     358             : 
     359           0 :     if ( nSplitPos < 0 )
     360           0 :         nSplitPos = 0;
     361             : 
     362           0 :     xSection->setHeight(nSplitPos);
     363           0 :     m_aSplitter->SetSplitPosPixel(m_aSplitter->LogicToPixel(Size(0,nSplitPos)).Height());
     364             : 
     365           0 :     return 0L;
     366             : }
     367             : 
     368           0 : void lcl_scroll(vcl::Window& _rWindow,const Point& _aDelta)
     369             : {
     370           0 :     _rWindow.Scroll(-_aDelta.X(),-_aDelta.Y());
     371           0 :     _rWindow.Invalidate(InvalidateFlags::Transparent);
     372           0 : }
     373             : 
     374           0 : void lcl_setOrigin(vcl::Window& _rWindow,long _nX, long _nY)
     375             : {
     376           0 :     MapMode aMap = _rWindow.GetMapMode();
     377           0 :     aMap.SetOrigin( Point(- _nX, - _nY));
     378           0 :     _rWindow.SetMapMode( aMap );
     379           0 : }
     380             : 
     381           0 : void OSectionWindow::scrollChildren(long _nX)
     382             : {
     383           0 :     const Point aDelta( _nX,0 );
     384             : 
     385           0 :     MapMode aMapMode( m_aReportSection->GetMapMode() );
     386           0 :     const Point aOld = aMapMode.GetOrigin();
     387           0 :     lcl_setOrigin(*m_aReportSection.get(), aDelta.X(), 0);
     388             : 
     389           0 :     aMapMode = m_aReportSection->GetMapMode();
     390           0 :     const Point aNew = aMapMode.GetOrigin();
     391           0 :     const Point aDiff = aOld - aNew;
     392             :     {
     393           0 :         lcl_scroll(*m_aReportSection.get(), aDiff);
     394             :     }
     395             : 
     396           0 :     lcl_scroll(*m_aEndMarker.get(), m_aEndMarker->PixelToLogic(Point(_nX,0)));
     397             : 
     398           0 :     lcl_setOrigin(*m_aSplitter.get(),_nX, 0);
     399           0 :     lcl_scroll(*m_aSplitter.get(),aDiff);
     400           0 : }
     401             : 
     402           3 : } // rptui
     403             : 
     404             : 
     405             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11