LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - StartMarker.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 167 0.6 %
Date: 2014-11-03 Functions: 2 19 10.5 %
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 "StartMarker.hxx"
      20             : #include <vcl/image.hxx>
      21             : #include <vcl/svapp.hxx>
      22             : #include "RptResId.hrc"
      23             : #include "ModuleHelper.hxx"
      24             : #include "ColorChanger.hxx"
      25             : #include "ReportDefines.hxx"
      26             : #include "SectionWindow.hxx"
      27             : #include "helpids.hrc"
      28             : #include <vcl/help.hxx>
      29             : #include <vcl/gradient.hxx>
      30             : #include <vcl/lineinfo.hxx>
      31             : #include <vcl/settings.hxx>
      32             : 
      33             : #include <toolkit/helper/vclunohelper.hxx>
      34             : #include <unotools/syslocale.hxx>
      35             : #include <svl/smplhint.hxx>
      36             : 
      37             : #define CORNER_SPACE     5
      38             : 
      39             : 
      40             : namespace rptui
      41             : {
      42             : 
      43             : 
      44             : Image*  OStartMarker::s_pDefCollapsed       = NULL;
      45             : Image*  OStartMarker::s_pDefExpanded        = NULL;
      46             : oslInterlockedCount OStartMarker::s_nImageRefCount  = 0;
      47             : 
      48             : 
      49           0 : OStartMarker::OStartMarker(OSectionWindow* _pParent,const OUString& _sColorEntry)
      50             : : OColorListener(_pParent,_sColorEntry)
      51             : ,m_aVRuler(this,WB_VERT)
      52             : ,m_aText(this,WB_HYPHENATION)
      53             : ,m_aImage(this,WB_LEFT|WB_TOP|WB_SCALE)
      54             : ,m_pParent(_pParent)
      55           0 : ,m_bShowRuler(true)
      56             : {
      57           0 :     SetUniqueId(HID_RPT_STARTMARKER);
      58             : 
      59           0 :     osl_atomic_increment(&s_nImageRefCount);
      60           0 :     initDefaultNodeImages();
      61           0 :     ImplInitSettings();
      62           0 :     m_aText.SetHelpId(HID_RPT_START_TITLE);
      63           0 :     m_aText.SetPaintTransparent(true);
      64           0 :     m_aImage.SetHelpId(HID_RPT_START_IMAGE);
      65           0 :     m_aText.Show();
      66           0 :     m_aImage.Show();
      67           0 :     m_aVRuler.Show();
      68           0 :     m_aVRuler.Activate();
      69           0 :     m_aVRuler.SetPagePos(0);
      70           0 :     m_aVRuler.SetBorders();
      71           0 :     m_aVRuler.SetIndents();
      72           0 :     m_aVRuler.SetMargin1();
      73           0 :     m_aVRuler.SetMargin2();
      74           0 :     const MeasurementSystem eSystem = SvtSysLocale().GetLocaleData().getMeasurementSystemEnum();
      75           0 :     m_aVRuler.SetUnit(MEASURE_METRIC == eSystem ? FUNIT_CM : FUNIT_INCH);
      76           0 :     EnableChildTransparentMode( true );
      77           0 :     SetParentClipMode( PARENTCLIPMODE_NOCLIP );
      78           0 :     SetPaintTransparent( true );
      79           0 : }
      80             : 
      81           0 : OStartMarker::~OStartMarker()
      82             : {
      83           0 :     if ( osl_atomic_decrement(&s_nImageRefCount) == 0 )
      84             :     {
      85           0 :         DELETEZ(s_pDefCollapsed);
      86           0 :         DELETEZ(s_pDefExpanded);
      87             :     }
      88           0 : }
      89             : 
      90           0 : sal_Int32 OStartMarker::getMinHeight() const
      91             : {
      92           0 :     Fraction aExtraWidth(long(2*REPORT_EXTRA_SPACE));
      93           0 :     aExtraWidth *= GetMapMode().GetScaleX();
      94           0 :     return LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() + (long)aExtraWidth;
      95             : }
      96             : 
      97           0 : void OStartMarker::Paint( const Rectangle& rRect )
      98             : {
      99             :     (void)rRect;
     100           0 :     Size aSize = GetOutputSizePixel();
     101           0 :     long nSize = aSize.Width();
     102           0 :     const long nCornerWidth = long(CORNER_SPACE * (double)GetMapMode().GetScaleX());
     103             : 
     104           0 :     if ( isCollapsed() )
     105             :     {
     106           0 :         SetClipRegion();
     107             :     }
     108             :     else
     109             :     {
     110           0 :         const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
     111           0 :         nSize = aSize.Width() - nVRulerWidth;
     112           0 :         aSize.Width() += nCornerWidth;
     113           0 :         SetClipRegion(vcl::Region(PixelToLogic(Rectangle(Point(),Size(nSize,aSize.Height())))));
     114             :     }
     115             : 
     116           0 :     Rectangle aWholeRect(Point(),aSize);
     117             :     {
     118           0 :         const ColorChanger aColors( this, m_nTextBoundaries, m_nColor );
     119           0 :         tools::PolyPolygon aPoly;
     120           0 :         aPoly.Insert(Polygon(aWholeRect,nCornerWidth,nCornerWidth));
     121             : 
     122           0 :         Color aStartColor(m_nColor);
     123           0 :         aStartColor.IncreaseLuminance(10);
     124           0 :         sal_uInt16 nHue = 0;
     125           0 :         sal_uInt16 nSat = 0;
     126           0 :         sal_uInt16 nBri = 0;
     127           0 :         aStartColor.RGBtoHSB(nHue, nSat, nBri);
     128           0 :         nSat += 40;
     129           0 :         Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
     130           0 :         Gradient aGradient(GradientStyle_LINEAR,aStartColor,aEndColor);
     131           0 :         aGradient.SetSteps(static_cast<sal_uInt16>(aSize.Height()));
     132             : 
     133           0 :         DrawGradient(PixelToLogic(aPoly) ,aGradient);
     134             :     }
     135           0 :     if ( m_bMarked )
     136             :     {
     137           0 :         const long nCornerHeight = long(CORNER_SPACE * (double)GetMapMode().GetScaleY());
     138             :         Rectangle aRect( Point(nCornerWidth,nCornerHeight),
     139           0 :                          Size(aSize.Width() - nCornerWidth - nCornerWidth,aSize.Height() - nCornerHeight - nCornerHeight));
     140           0 :         ColorChanger aColors( this, COL_WHITE, COL_WHITE );
     141           0 :         DrawPolyLine(Polygon(PixelToLogic(aRect)),LineInfo(LINE_SOLID,2 ));
     142             :     }
     143           0 : }
     144             : 
     145           0 : void OStartMarker::setColor()
     146             : {
     147           0 :     const Color aColor(m_nColor);
     148           0 :     Color aTextColor = GetTextColor();
     149           0 :     if ( aColor.GetLuminance() < 128 )
     150           0 :         aTextColor = COL_WHITE;
     151           0 :     m_aText.SetTextColor(aTextColor);
     152           0 :     m_aText.SetLineColor(m_nColor);
     153           0 : }
     154             : 
     155           0 : void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
     156             : {
     157           0 :     if ( !rMEvt.IsLeft() )
     158           0 :         return;
     159             : 
     160           0 :     Point aPos( rMEvt.GetPosPixel());
     161             : 
     162           0 :     const Size aOutputSize = GetOutputSizePixel();
     163           0 :     if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
     164           0 :         return;
     165           0 :     Rectangle aRect(m_aImage.GetPosPixel(),m_aImage.GetSizePixel());
     166           0 :     if ( rMEvt.GetClicks() == 2 || aRect.IsInside( aPos ) )
     167             :     {
     168           0 :         m_bCollapsed = !m_bCollapsed;
     169             : 
     170           0 :         changeImage();
     171             : 
     172           0 :         m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
     173           0 :         if ( m_aCollapsedLink.IsSet() )
     174           0 :             m_aCollapsedLink.Call(this);
     175             :     }
     176             : 
     177           0 :     m_pParent->showProperties();
     178             : }
     179             : 
     180           0 : void OStartMarker::changeImage()
     181             : {
     182           0 :     Image* pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
     183           0 :     m_aImage.SetImage(*pImage);
     184           0 : }
     185             : 
     186           0 : void OStartMarker::initDefaultNodeImages()
     187             : {
     188           0 :     if ( !s_pDefCollapsed )
     189             :     {
     190           0 :         s_pDefCollapsed     = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED      ) );
     191           0 :         s_pDefExpanded      = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED       ) );
     192             :     }
     193             : 
     194           0 :     Image* pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
     195           0 :     m_aImage.SetImage(*pImage);
     196           0 :     m_aImage.SetMouseTransparent(true);
     197           0 :     m_aImage.SetBackground();
     198           0 :     m_aText.SetBackground();
     199           0 :     m_aText.SetMouseTransparent(true);
     200           0 : }
     201             : 
     202           0 : void OStartMarker::ImplInitSettings()
     203             : {
     204           0 :     SetBackground( );
     205           0 :     SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
     206           0 :     setColor();
     207           0 : }
     208             : 
     209           0 : void OStartMarker::Resize()
     210             : {
     211           0 :     const Size aOutputSize( GetOutputSizePixel() );
     212           0 :     const long nOutputWidth  = aOutputSize.Width();
     213           0 :     const long nOutputHeight = aOutputSize.Height();
     214             : 
     215           0 :     const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
     216           0 :     const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
     217           0 :     m_aVRuler.SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
     218             : 
     219           0 :     Size aImageSize = m_aImage.GetImage().GetSizePixel();
     220           0 :     const MapMode& rMapMode = GetMapMode();
     221           0 :     aImageSize.Width() = long(aImageSize.Width() * (double)rMapMode.GetScaleX());
     222           0 :     aImageSize.Height() = long(aImageSize.Height() * (double)rMapMode.GetScaleY());
     223             : 
     224           0 :     Fraction aExtraWidth(long(REPORT_EXTRA_SPACE));
     225           0 :     aExtraWidth *= rMapMode.GetScaleX();
     226             : 
     227           0 :     Point aPos(aImageSize.Width() + (long)(aExtraWidth + aExtraWidth), aExtraWidth);
     228           0 :     const long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0,m_aText.GetTextHeight())).Height());
     229           0 :     m_aText.SetPosSizePixel(aPos,Size(aRulerPos.X() - aPos.X(),nHeight));
     230             : 
     231           0 :     aPos.X() = aExtraWidth;
     232           0 :     aPos.Y() += static_cast<sal_Int32>((LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ;
     233           0 :     m_aImage.SetPosSizePixel(aPos,aImageSize);
     234           0 : }
     235             : 
     236           0 : void OStartMarker::setTitle(const OUString& _sTitle)
     237             : {
     238           0 :     m_aText.SetText(_sTitle);
     239           0 : }
     240             : 
     241           0 : void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
     242             : {
     243           0 :     OColorListener::Notify(rBc, rHint);
     244           0 :     const SfxSimpleHint* pSimpleHint = dynamic_cast<const SfxSimpleHint*>(&rHint);
     245           0 :     if (pSimpleHint && pSimpleHint->GetId() == SFX_HINT_COLORS_CHANGED)
     246             :     {
     247           0 :         setColor();
     248           0 :         Invalidate(INVALIDATE_CHILDREN);
     249             :     }
     250           0 : }
     251             : 
     252           0 : void OStartMarker::showRuler(bool _bShow)
     253             : {
     254           0 :     m_bShowRuler = _bShow;
     255           0 :     m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
     256           0 : }
     257             : 
     258           0 : void OStartMarker::RequestHelp( const HelpEvent& rHEvt )
     259             : {
     260           0 :     if( !m_aText.GetText().isEmpty())
     261             :     {
     262             :         // Hilfe anzeigen
     263           0 :         Rectangle aItemRect(rHEvt.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
     264           0 :         Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
     265           0 :         aItemRect.Left()   = aPt.X();
     266           0 :         aItemRect.Top()    = aPt.Y();
     267           0 :         aPt = OutputToScreenPixel( aItemRect.BottomRight() );
     268           0 :         aItemRect.Right()  = aPt.X();
     269           0 :         aItemRect.Bottom() = aPt.Y();
     270           0 :         if( rHEvt.GetMode() == HELPMODE_BALLOON )
     271           0 :             Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText.GetText());
     272             :         else
     273           0 :             Help::ShowQuickHelp( this, aItemRect, m_aText.GetText() );
     274             :     }
     275           0 : }
     276             : 
     277           0 : void OStartMarker::setCollapsed(bool _bCollapsed)
     278             : {
     279           0 :     OColorListener::setCollapsed(_bCollapsed);
     280           0 :     showRuler(_bCollapsed);
     281           0 :     changeImage();
     282           0 : }
     283             : 
     284           0 : void OStartMarker::zoom(const Fraction& _aZoom)
     285             : {
     286           0 :     setZoomFactor(_aZoom,*this);
     287           0 :     m_aVRuler.SetZoom(_aZoom);
     288           0 :     setZoomFactor(_aZoom,m_aText);
     289           0 :     Resize();
     290           0 :     Invalidate();
     291           0 : }
     292             : 
     293             : 
     294           6 : }
     295             : 
     296             : 
     297             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10