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

Generated by: LCOV version 1.10