LCOV - code coverage report
Current view: top level - reportdesign/source/ui/report - StartMarker.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 167 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "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(sal_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(Region(PixelToLogic(Rectangle(Point(),Size(nSize,aSize.Height())))));
     114             :     }
     115             : 
     116           0 :     const Point aGcc3WorkaroundTemporary;
     117           0 :     Rectangle aWholeRect(aGcc3WorkaroundTemporary,aSize);
     118             :     {
     119           0 :         const ColorChanger aColors( this, m_nTextBoundaries, m_nColor );
     120           0 :         PolyPolygon aPoly;
     121           0 :         aPoly.Insert(Polygon(aWholeRect,nCornerWidth,nCornerWidth));
     122             : 
     123           0 :         Color aStartColor(m_nColor);
     124           0 :         aStartColor.IncreaseLuminance(10);
     125           0 :         sal_uInt16 nHue = 0;
     126           0 :         sal_uInt16 nSat = 0;
     127           0 :         sal_uInt16 nBri = 0;
     128           0 :         aStartColor.RGBtoHSB(nHue, nSat, nBri);
     129           0 :         nSat += 40;
     130           0 :         Color aEndColor(Color::HSBtoRGB(nHue, nSat, nBri));
     131           0 :         Gradient aGradient(GradientStyle_LINEAR,aStartColor,aEndColor);
     132           0 :         aGradient.SetSteps(static_cast<sal_uInt16>(aSize.Height()));
     133             : 
     134           0 :         DrawGradient(PixelToLogic(aPoly) ,aGradient);
     135             :     }
     136           0 :     if ( m_bMarked )
     137             :     {
     138           0 :         const long nCornerHeight = long(CORNER_SPACE * (double)GetMapMode().GetScaleY());
     139             :         Rectangle aRect( Point(nCornerWidth,nCornerHeight),
     140           0 :                          Size(aSize.Width() - nCornerWidth - nCornerWidth,aSize.Height() - nCornerHeight - nCornerHeight));
     141           0 :         ColorChanger aColors( this, COL_WHITE, COL_WHITE );
     142           0 :         DrawPolyLine(Polygon(PixelToLogic(aRect)),LineInfo(LINE_SOLID,2 ));
     143             :     }
     144           0 : }
     145             : 
     146           0 : void OStartMarker::setColor()
     147             : {
     148           0 :     const Color aColor(m_nColor);
     149           0 :     Color aTextColor = GetTextColor();
     150           0 :     if ( aColor.GetLuminance() < 128 )
     151           0 :         aTextColor = COL_WHITE;
     152           0 :     m_aText.SetTextColor(aTextColor);
     153           0 :     m_aText.SetLineColor(m_nColor);
     154           0 : }
     155             : 
     156           0 : void OStartMarker::MouseButtonUp( const MouseEvent& rMEvt )
     157             : {
     158           0 :     if ( !rMEvt.IsLeft() )
     159           0 :         return;
     160             : 
     161           0 :     Point aPos( rMEvt.GetPosPixel());
     162             : 
     163           0 :     const Size aOutputSize = GetOutputSizePixel();
     164           0 :     if( aPos.X() > aOutputSize.Width() || aPos.Y() > aOutputSize.Height() )
     165           0 :         return;
     166           0 :     Rectangle aRect(m_aImage.GetPosPixel(),m_aImage.GetSizePixel());
     167           0 :     if ( rMEvt.GetClicks() == 2 || aRect.IsInside( aPos ) )
     168             :     {
     169           0 :         m_bCollapsed = !m_bCollapsed;
     170             : 
     171           0 :         changeImage();
     172             : 
     173           0 :         m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
     174           0 :         if ( m_aCollapsedLink.IsSet() )
     175           0 :             m_aCollapsedLink.Call(this);
     176             :     }
     177             : 
     178           0 :     m_pParent->showProperties();
     179             : }
     180             : 
     181           0 : void OStartMarker::changeImage()
     182             : {
     183           0 :     Image* pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
     184           0 :     m_aImage.SetImage(*pImage);
     185           0 : }
     186             : 
     187           0 : void OStartMarker::initDefaultNodeImages()
     188             : {
     189           0 :     if ( !s_pDefCollapsed )
     190             :     {
     191           0 :         s_pDefCollapsed     = new Image( ModuleRes( RID_IMG_TREENODE_COLLAPSED      ) );
     192           0 :         s_pDefExpanded      = new Image( ModuleRes( RID_IMG_TREENODE_EXPANDED       ) );
     193             :     }
     194             : 
     195           0 :     Image* pImage = m_bCollapsed ? s_pDefCollapsed : s_pDefExpanded;
     196           0 :     m_aImage.SetImage(*pImage);
     197           0 :     m_aImage.SetMouseTransparent(true);
     198           0 :     m_aImage.SetBackground();
     199           0 :     m_aText.SetBackground();
     200           0 :     m_aText.SetMouseTransparent(true);
     201           0 : }
     202             : 
     203           0 : void OStartMarker::ImplInitSettings()
     204             : {
     205           0 :     SetBackground( );
     206           0 :     SetFillColor( Application::GetSettings().GetStyleSettings().GetDialogColor() );
     207           0 :     setColor();
     208           0 : }
     209             : 
     210           0 : void OStartMarker::Resize()
     211             : {
     212           0 :     const Size aOutputSize( GetOutputSizePixel() );
     213           0 :     const long nOutputWidth  = aOutputSize.Width();
     214           0 :     const long nOutputHeight = aOutputSize.Height();
     215             : 
     216           0 :     const long nVRulerWidth = m_aVRuler.GetSizePixel().Width();
     217           0 :     const Point aRulerPos(nOutputWidth - nVRulerWidth,0);
     218           0 :     m_aVRuler.SetPosSizePixel(aRulerPos,Size(nVRulerWidth,nOutputHeight));
     219             : 
     220           0 :     Size aImageSize = m_aImage.GetImage().GetSizePixel();
     221           0 :     const MapMode& rMapMode = GetMapMode();
     222           0 :     aImageSize.Width() = long(aImageSize.Width() * (double)rMapMode.GetScaleX());
     223           0 :     aImageSize.Height() = long(aImageSize.Height() * (double)rMapMode.GetScaleY());
     224             : 
     225           0 :     Fraction aExtraWidth(long(REPORT_EXTRA_SPACE));
     226           0 :     aExtraWidth *= rMapMode.GetScaleX();
     227             : 
     228           0 :     Point aPos(aImageSize.Width() + (long)(aExtraWidth + aExtraWidth), aExtraWidth);
     229           0 :     const long nHeight = ::std::max<sal_Int32>(nOutputHeight - 2*aPos.Y(),LogicToPixel(Size(0,m_aText.GetTextHeight())).Height());
     230           0 :     m_aText.SetPosSizePixel(aPos,Size(aRulerPos.X() - aPos.X(),nHeight));
     231             : 
     232           0 :     aPos.X() = aExtraWidth;
     233           0 :     aPos.Y() += static_cast<sal_Int32>((LogicToPixel(Size(0,m_aText.GetTextHeight())).Height() - aImageSize.Height()) * 0.5) ;
     234           0 :     m_aImage.SetPosSizePixel(aPos,aImageSize);
     235           0 : }
     236             : 
     237           0 : void OStartMarker::setTitle(const OUString& _sTitle)
     238             : {
     239           0 :     m_aText.SetText(_sTitle);
     240           0 : }
     241             : 
     242           0 : void OStartMarker::Notify(SfxBroadcaster & rBc, SfxHint const & rHint)
     243             : {
     244           0 :     OColorListener::Notify(rBc, rHint);
     245           0 :     if (rHint.ISA(SfxSimpleHint)
     246           0 :         && (static_cast< SfxSimpleHint const & >(rHint).GetId()
     247             :             == SFX_HINT_COLORS_CHANGED))
     248             :     {
     249           0 :         setColor();
     250           0 :         Invalidate(INVALIDATE_CHILDREN);
     251             :     }
     252           0 : }
     253             : 
     254           0 : void OStartMarker::showRuler(sal_Bool _bShow)
     255             : {
     256           0 :     m_bShowRuler = _bShow;
     257           0 :     m_aVRuler.Show(!m_bCollapsed && m_bShowRuler);
     258           0 : }
     259             : 
     260           0 : void OStartMarker::RequestHelp( const HelpEvent& rHEvt )
     261             : {
     262           0 :     if( !m_aText.GetText().isEmpty())
     263             :     {
     264             :         // Hilfe anzeigen
     265           0 :         Rectangle aItemRect(rHEvt.GetMousePosPixel(),Size(GetSizePixel().Width(),getMinHeight()));
     266           0 :         Point aPt = OutputToScreenPixel( aItemRect.TopLeft() );
     267           0 :         aItemRect.Left()   = aPt.X();
     268           0 :         aItemRect.Top()    = aPt.Y();
     269           0 :         aPt = OutputToScreenPixel( aItemRect.BottomRight() );
     270           0 :         aItemRect.Right()  = aPt.X();
     271           0 :         aItemRect.Bottom() = aPt.Y();
     272           0 :         if( rHEvt.GetMode() == HELPMODE_BALLOON )
     273           0 :             Help::ShowBalloon( this, aItemRect.Center(), aItemRect, m_aText.GetText());
     274             :         else
     275           0 :             Help::ShowQuickHelp( this, aItemRect, m_aText.GetText() );
     276             :     }
     277           0 : }
     278             : 
     279           0 : void OStartMarker::setCollapsed(sal_Bool _bCollapsed)
     280             : {
     281           0 :     OColorListener::setCollapsed(_bCollapsed);
     282           0 :     showRuler(_bCollapsed);
     283           0 :     changeImage();
     284           0 : }
     285             : 
     286           0 : void OStartMarker::zoom(const Fraction& _aZoom)
     287             : {
     288           0 :     setZoomFactor(_aZoom,*this);
     289           0 :     m_aVRuler.SetZoom(_aZoom);
     290           0 :     setZoomFactor(_aZoom,m_aText);
     291           0 :     Resize();
     292           0 :     Invalidate();
     293           0 : }
     294             : 
     295             : 
     296             : }
     297             : 
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10