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

Generated by: LCOV version 1.10