LCOV - code coverage report
Current view: top level - sc/source/ui/cctrl - dpcontrol.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 113 131 86.3 %
Date: 2012-08-25 Functions: 11 12 91.7 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 60 128 46.9 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include "dpcontrol.hxx"
      30                 :            : 
      31                 :            : #include <vcl/outdev.hxx>
      32                 :            : #include <vcl/settings.hxx>
      33                 :            : #include "global.hxx"
      34                 :            : #include "scitems.hxx"
      35                 :            : #include "document.hxx"
      36                 :            : #include "docpool.hxx"
      37                 :            : #include "patattr.hxx"
      38                 :            : 
      39                 :            : using rtl::OUString;
      40                 :            : 
      41                 :       1278 : ScDPFieldButton::ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomX, const Fraction* pZoomY, ScDocument* pDoc) :
      42                 :            :     mpDoc(pDoc),
      43                 :            :     mpOutDev(pOutDev),
      44                 :            :     mpStyle(pStyle),
      45                 :            :     mbBaseButton(true),
      46                 :            :     mbPopupButton(false),
      47                 :            :     mbHasHiddenMember(false),
      48                 :            :     mbPopupPressed(false),
      49                 :       1278 :     mbPopupLeft(false)
      50                 :            : {
      51         [ +  - ]:       1278 :     if (pZoomX)
      52         [ +  - ]:       1278 :         maZoomX = *pZoomX;
      53                 :            :     else
      54 [ #  # ][ #  # ]:          0 :         maZoomX = Fraction(1, 1);
      55                 :            : 
      56         [ +  - ]:       1278 :     if (pZoomY)
      57         [ +  - ]:       1278 :         maZoomY = *pZoomY;
      58                 :            :     else
      59 [ #  # ][ #  # ]:          0 :         maZoomY = Fraction(1, 1);
      60                 :       1278 : }
      61                 :            : 
      62                 :       1278 : ScDPFieldButton::~ScDPFieldButton()
      63                 :            : {
      64                 :       1278 : }
      65                 :            : 
      66                 :         84 : void ScDPFieldButton::setText(const OUString& rText)
      67                 :            : {
      68                 :         84 :     maText = rText;
      69                 :         84 : }
      70                 :            : 
      71                 :         86 : void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
      72                 :            : {
      73                 :         86 :     maPos = rPos;
      74                 :         86 :     maSize = rSize;
      75         [ -  + ]:         86 :     if (bLayoutRTL)
      76                 :            :     {
      77                 :            :         // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
      78                 :          0 :         maPos.X() -= maSize.Width() - 1;
      79                 :            :     }
      80                 :         86 : }
      81                 :            : 
      82                 :         86 : void ScDPFieldButton::setDrawBaseButton(bool b)
      83                 :            : {
      84                 :         86 :     mbBaseButton = b;
      85                 :         86 : }
      86                 :            : 
      87                 :         86 : void ScDPFieldButton::setDrawPopupButton(bool b)
      88                 :            : {
      89                 :         86 :     mbPopupButton = b;
      90                 :         86 : }
      91                 :            : 
      92                 :         86 : void ScDPFieldButton::setHasHiddenMember(bool b)
      93                 :            : {
      94                 :         86 :     mbHasHiddenMember = b;
      95                 :         86 : }
      96                 :            : 
      97                 :          0 : void ScDPFieldButton::setPopupPressed(bool b)
      98                 :            : {
      99                 :          0 :     mbPopupPressed = b;
     100                 :          0 : }
     101                 :            : 
     102                 :         86 : void ScDPFieldButton::setPopupLeft(bool b)
     103                 :            : {
     104                 :         86 :     mbPopupLeft = b;
     105                 :         86 : }
     106                 :            : 
     107                 :         86 : void ScDPFieldButton::draw()
     108                 :            : {
     109                 :         86 :     const long nMargin = 2;
     110                 :         86 :     bool bOldMapEnablaed = mpOutDev->IsMapModeEnabled();
     111                 :         86 :     mpOutDev->EnableMapMode(false);
     112                 :            : 
     113         [ +  + ]:         86 :     if (mbBaseButton)
     114                 :            :     {
     115                 :            :         // Background
     116         [ +  - ]:         84 :         Rectangle aRect(maPos, maSize);
     117         [ +  - ]:         84 :         mpOutDev->SetLineColor(mpStyle->GetFaceColor());
     118         [ +  - ]:         84 :         mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     119         [ +  - ]:         84 :         mpOutDev->DrawRect(aRect);
     120                 :            : 
     121                 :            :         // Border lines
     122         [ +  - ]:         84 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     123         [ +  - ]:         84 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X(), maPos.Y()+maSize.Height()-1));
     124         [ +  - ]:         84 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X()+maSize.Width()-1, maPos.Y()));
     125                 :            : 
     126         [ +  - ]:         84 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     127                 :         84 :         mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
     128         [ +  - ]:        168 :                            Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
     129                 :         84 :         mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
     130         [ +  - ]:        168 :                            Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
     131                 :            : 
     132                 :            :         // Field name.
     133                 :            :         // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
     134         [ +  - ]:         84 :         Font aTextFont( mpStyle->GetAppFont() );
     135         [ +  - ]:         84 :         if ( mpDoc )
     136                 :            :         {
     137                 :            :             //  use ScPatternAttr::GetFont only for font size
     138         [ +  - ]:         84 :             Font aAttrFont;
     139 [ +  - ][ +  - ]:         84 :             static_cast<const ScPatternAttr&>(mpDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)).
     140         [ +  - ]:         84 :                 GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
     141 [ +  - ][ +  - ]:         84 :             aTextFont.SetSize( aAttrFont.GetSize() );
                 [ +  - ]
     142                 :            :         }
     143         [ +  - ]:         84 :         mpOutDev->SetFont(aTextFont);
     144         [ +  - ]:         84 :         mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());
     145                 :            : 
     146                 :         84 :         Point aTextPos = maPos;
     147         [ +  - ]:         84 :         long nTHeight = mpOutDev->GetTextHeight();
     148                 :         84 :         aTextPos.setX(maPos.getX() + nMargin);
     149                 :         84 :         aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
     150                 :            : 
     151         [ +  - ]:         84 :         mpOutDev->Push(PUSH_CLIPREGION);
     152         [ +  - ]:         84 :         mpOutDev->IntersectClipRegion(aRect);
     153 [ +  - ][ +  - ]:         84 :         mpOutDev->DrawText(aTextPos, maText);
                 [ +  - ]
     154 [ +  - ][ +  - ]:         84 :         mpOutDev->Pop();
     155                 :            :     }
     156                 :            : 
     157         [ +  + ]:         86 :     if (mbPopupButton)
     158                 :         54 :         drawPopupButton();
     159                 :            : 
     160                 :         86 :     mpOutDev->EnableMapMode(bOldMapEnablaed);
     161                 :         86 : }
     162                 :            : 
     163                 :         54 : void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
     164                 :            : {
     165                 :         54 :     long nW = maSize.getWidth() / 2;
     166                 :         54 :     long nH = maSize.getHeight();
     167         [ +  - ]:         54 :     if (nW > 18)
     168                 :         54 :         nW = 18;
     169         [ -  + ]:         54 :     if (nH > 18)
     170                 :          0 :         nH = 18;
     171                 :            : 
     172                 :            :     // #i114944# AutoFilter button is left-aligned in RTL.
     173                 :            :     // DataPilot button is always right-aligned for now, so text output isn't affected.
     174         [ -  + ]:         54 :     if (mbPopupLeft)
     175                 :          0 :         rPos.setX(maPos.getX());
     176                 :            :     else
     177                 :         54 :         rPos.setX(maPos.getX() + maSize.getWidth() - nW);
     178                 :         54 :     rPos.setY(maPos.getY() + maSize.getHeight() - nH);
     179                 :         54 :     rSize.setWidth(nW);
     180                 :         54 :     rSize.setHeight(nH);
     181                 :         54 : }
     182                 :            : 
     183                 :         54 : void ScDPFieldButton::drawPopupButton()
     184                 :            : {
     185                 :         54 :     Point aPos;
     186                 :         54 :     Size aSize;
     187                 :         54 :     getPopupBoundingBox(aPos, aSize);
     188                 :            : 
     189                 :            :     // Background & outer black border
     190         [ +  - ]:         54 :     mpOutDev->SetLineColor(COL_BLACK);
     191         [ +  - ]:         54 :     mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     192 [ +  - ][ +  - ]:         54 :     mpOutDev->DrawRect(Rectangle(aPos, aSize));
     193                 :            : 
     194         [ +  - ]:         54 :     if (!mbPopupPressed)
     195                 :            :     {
     196                 :            :         // border lines
     197         [ +  - ]:         54 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     198         [ +  - ]:         54 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+1, aPos.Y()+aSize.Height()-2));
     199         [ +  - ]:         54 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+aSize.Width()-2, aPos.Y()+1));
     200                 :            : 
     201         [ +  - ]:         54 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     202                 :         54 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+aSize.Height()-2),
     203         [ +  - ]:        108 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     204                 :         54 :         mpOutDev->DrawLine(Point(aPos.X()+aSize.Width()-2, aPos.Y()+1),
     205         [ +  - ]:        108 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     206                 :            :     }
     207                 :            : 
     208                 :            :     // the arrowhead
     209         [ -  + ]:         54 :     Color aArrowColor = mbHasHiddenMember ? mpStyle->GetHighlightLinkColor() : mpStyle->GetButtonTextColor();
     210         [ +  - ]:         54 :     mpOutDev->SetLineColor(aArrowColor);
     211         [ +  - ]:         54 :     mpOutDev->SetFillColor(aArrowColor);
     212                 :         54 :     Point aCenter(aPos.X() + (aSize.Width() >> 1), aPos.Y() + (aSize.Height() >> 1));
     213                 :         54 :     Point aPos1, aPos2;
     214                 :         54 :     aPos1.X() = aCenter.X() - 4;
     215                 :         54 :     aPos2.X() = aCenter.X() + 4;
     216                 :         54 :     aPos1.Y() = aCenter.Y() - 3;
     217                 :         54 :     aPos2.Y() = aCenter.Y() - 3;
     218                 :            : 
     219         [ -  + ]:         54 :     if (mbPopupPressed)
     220                 :            :     {
     221                 :          0 :         aPos1.X() += 1;
     222                 :          0 :         aPos2.X() += 1;
     223                 :          0 :         aPos1.Y() += 1;
     224                 :          0 :         aPos2.Y() += 1;
     225                 :            :     }
     226                 :            : 
     227         [ +  + ]:        216 :     do
     228                 :            :     {
     229                 :        216 :         ++aPos1.X();
     230                 :        216 :         --aPos2.X();
     231                 :        216 :         ++aPos1.Y();
     232                 :        216 :         ++aPos2.Y();
     233         [ +  - ]:        216 :         mpOutDev->DrawLine(aPos1, aPos2);
     234                 :            :     }
     235                 :        216 :     while (aPos1 != aPos2);
     236                 :            : 
     237         [ -  + ]:         54 :     if (mbHasHiddenMember)
     238                 :            :     {
     239                 :            :         // tiny little box to display in presence of hidden member(s).
     240                 :          0 :         Point aBoxPos(aPos.X() + aSize.Width() - 5, aPos.Y() + aSize.Height() - 5);
     241         [ #  # ]:          0 :         if (mbPopupPressed)
     242                 :            :         {
     243                 :          0 :             aBoxPos.X() += 1;
     244                 :          0 :             aBoxPos.Y() += 1;
     245                 :            :         }
     246                 :          0 :         Size aBoxSize(3, 3);
     247 [ #  # ][ #  # ]:          0 :         mpOutDev->DrawRect(Rectangle(aBoxPos, aBoxSize));
     248                 :            :     }
     249                 :         54 : }
     250                 :            : 
     251                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10