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

Generated by: LCOV version 1.11