LCOV - code coverage report
Current view: top level - sc/source/ui/cctrl - dpcontrol.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 115 129 89.1 %
Date: 2014-04-11 Functions: 11 12 91.7 %
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             : 
      20             : #include "dpcontrol.hxx"
      21             : 
      22             : #include <vcl/outdev.hxx>
      23             : #include <vcl/settings.hxx>
      24             : #include "global.hxx"
      25             : #include "scitems.hxx"
      26             : #include "document.hxx"
      27             : #include "docpool.hxx"
      28             : #include "patattr.hxx"
      29             : 
      30             : 
      31        1579 : ScDPFieldButton::ScDPFieldButton(OutputDevice* pOutDev, const StyleSettings* pStyle, const Fraction* pZoomX, const Fraction* pZoomY, ScDocument* pDoc) :
      32             :     mpDoc(pDoc),
      33             :     mpOutDev(pOutDev),
      34             :     mpStyle(pStyle),
      35             :     mbBaseButton(true),
      36             :     mbPopupButton(false),
      37             :     mbHasHiddenMember(false),
      38             :     mbPopupPressed(false),
      39        1579 :     mbPopupLeft(false)
      40             : {
      41        1579 :     if (pZoomX)
      42        1579 :         maZoomX = *pZoomX;
      43             :     else
      44           0 :         maZoomX = Fraction(1, 1);
      45             : 
      46        1579 :     if (pZoomY)
      47        1579 :         maZoomY = *pZoomY;
      48             :     else
      49           0 :         maZoomY = Fraction(1, 1);
      50        1579 : }
      51             : 
      52        1579 : ScDPFieldButton::~ScDPFieldButton()
      53             : {
      54        1579 : }
      55             : 
      56         740 : void ScDPFieldButton::setText(const OUString& rText)
      57             : {
      58         740 :     maText = rText;
      59         740 : }
      60             : 
      61         770 : void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
      62             : {
      63         770 :     maPos = rPos;
      64         770 :     maSize = rSize;
      65         770 :     if (bLayoutRTL)
      66             :     {
      67             :         // rPos is the logical-left position, adjust maPos to visual-left (inside the cell border)
      68           0 :         maPos.X() -= maSize.Width() - 1;
      69             :     }
      70         770 : }
      71             : 
      72         770 : void ScDPFieldButton::setDrawBaseButton(bool b)
      73             : {
      74         770 :     mbBaseButton = b;
      75         770 : }
      76             : 
      77         770 : void ScDPFieldButton::setDrawPopupButton(bool b)
      78             : {
      79         770 :     mbPopupButton = b;
      80         770 : }
      81             : 
      82         770 : void ScDPFieldButton::setHasHiddenMember(bool b)
      83             : {
      84         770 :     mbHasHiddenMember = b;
      85         770 : }
      86             : 
      87           0 : void ScDPFieldButton::setPopupPressed(bool b)
      88             : {
      89           0 :     mbPopupPressed = b;
      90           0 : }
      91             : 
      92         770 : void ScDPFieldButton::setPopupLeft(bool b)
      93             : {
      94         770 :     mbPopupLeft = b;
      95         770 : }
      96             : 
      97         770 : void ScDPFieldButton::draw()
      98             : {
      99         770 :     bool bOldMapEnablaed = mpOutDev->IsMapModeEnabled();
     100         770 :     mpOutDev->EnableMapMode(false);
     101             : 
     102         770 :     if (mbBaseButton)
     103             :     {
     104             :         // Background
     105         108 :         Rectangle aRect(maPos, maSize);
     106         108 :         mpOutDev->SetLineColor(mpStyle->GetFaceColor());
     107         108 :         mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     108         108 :         mpOutDev->DrawRect(aRect);
     109             : 
     110             :         // Border lines
     111         108 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     112         108 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X(), maPos.Y()+maSize.Height()-1));
     113         108 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X()+maSize.Width()-1, maPos.Y()));
     114             : 
     115         108 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     116         216 :         mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
     117         324 :                            Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
     118         216 :         mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
     119         324 :                            Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
     120             : 
     121             :         // Field name.
     122             :         // Get the font and size the same way as in scenario selection (lcl_DrawOneFrame in gridwin4.cxx)
     123         108 :         Font aTextFont( mpStyle->GetAppFont() );
     124         108 :         if ( mpDoc )
     125             :         {
     126             :             //  use ScPatternAttr::GetFont only for font size
     127         108 :             Font aAttrFont;
     128         216 :             static_cast<const ScPatternAttr&>(mpDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)).
     129         324 :                 GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
     130         108 :             aTextFont.SetSize( aAttrFont.GetSize() );
     131             :         }
     132         108 :         mpOutDev->SetFont(aTextFont);
     133         108 :         mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());
     134             : 
     135         108 :         Point aTextPos = maPos;
     136         108 :         long nTHeight = mpOutDev->GetTextHeight();
     137         108 :         aTextPos.setX(maPos.getX() + 2); // 2 = Margin
     138         108 :         aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
     139             : 
     140         108 :         mpOutDev->Push(PUSH_CLIPREGION);
     141         108 :         mpOutDev->IntersectClipRegion(aRect);
     142         108 :         mpOutDev->DrawText(aTextPos, maText);
     143         108 :         mpOutDev->Pop();
     144             :     }
     145             : 
     146         770 :     if (mbPopupButton)
     147          98 :         drawPopupButton();
     148             : 
     149         770 :     mpOutDev->EnableMapMode(bOldMapEnablaed);
     150         770 : }
     151             : 
     152          98 : void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
     153             : {
     154          98 :     long nW = maSize.getWidth() / 2;
     155          98 :     long nH = maSize.getHeight();
     156          98 :     if (nW > 18)
     157          98 :         nW = 18;
     158          98 :     if (nH > 18)
     159           0 :         nH = 18;
     160             : 
     161             :     // #i114944# AutoFilter button is left-aligned in RTL.
     162             :     // DataPilot button is always right-aligned for now, so text output isn't affected.
     163          98 :     if (mbPopupLeft)
     164           0 :         rPos.setX(maPos.getX());
     165             :     else
     166          98 :         rPos.setX(maPos.getX() + maSize.getWidth() - nW);
     167          98 :     rPos.setY(maPos.getY() + maSize.getHeight() - nH);
     168          98 :     rSize.setWidth(nW);
     169          98 :     rSize.setHeight(nH);
     170          98 : }
     171             : 
     172          98 : void ScDPFieldButton::drawPopupButton()
     173             : {
     174          98 :     Point aPos;
     175          98 :     Size aSize;
     176          98 :     getPopupBoundingBox(aPos, aSize);
     177             : 
     178             :     // Background & outer black border
     179          98 :     mpOutDev->SetLineColor(COL_BLACK);
     180          98 :     mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     181          98 :     mpOutDev->DrawRect(Rectangle(aPos, aSize));
     182             : 
     183          98 :     if (!mbPopupPressed)
     184             :     {
     185             :         // border lines
     186          98 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     187          98 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+1, aPos.Y()+aSize.Height()-2));
     188          98 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+aSize.Width()-2, aPos.Y()+1));
     189             : 
     190          98 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     191         196 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+aSize.Height()-2),
     192         294 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     193         196 :         mpOutDev->DrawLine(Point(aPos.X()+aSize.Width()-2, aPos.Y()+1),
     194         294 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     195             :     }
     196             : 
     197             :     // the arrowhead
     198          98 :     Color aArrowColor = mbHasHiddenMember ? mpStyle->GetHighlightLinkColor() : mpStyle->GetButtonTextColor();
     199          98 :     mpOutDev->SetLineColor(aArrowColor);
     200          98 :     mpOutDev->SetFillColor(aArrowColor);
     201          98 :     Point aCenter(aPos.X() + (aSize.Width() >> 1), aPos.Y() + (aSize.Height() >> 1));
     202          98 :     Point aPos1, aPos2;
     203          98 :     aPos1.X() = aCenter.X() - 4;
     204          98 :     aPos2.X() = aCenter.X() + 4;
     205          98 :     aPos1.Y() = aCenter.Y() - 3;
     206          98 :     aPos2.Y() = aCenter.Y() - 3;
     207             : 
     208          98 :     if (mbPopupPressed)
     209             :     {
     210           0 :         aPos1.X() += 1;
     211           0 :         aPos2.X() += 1;
     212           0 :         aPos1.Y() += 1;
     213           0 :         aPos2.Y() += 1;
     214             :     }
     215             : 
     216         392 :     do
     217             :     {
     218         392 :         ++aPos1.X();
     219         392 :         --aPos2.X();
     220         392 :         ++aPos1.Y();
     221         392 :         ++aPos2.Y();
     222         392 :         mpOutDev->DrawLine(aPos1, aPos2);
     223             :     }
     224             :     while (aPos1 != aPos2);
     225             : 
     226          98 :     if (mbHasHiddenMember)
     227             :     {
     228             :         // tiny little box to display in presence of hidden member(s).
     229           4 :         Point aBoxPos(aPos.X() + aSize.Width() - 5, aPos.Y() + aSize.Height() - 5);
     230           4 :         if (mbPopupPressed)
     231             :         {
     232           0 :             aBoxPos.X() += 1;
     233           0 :             aBoxPos.Y() += 1;
     234             :         }
     235           4 :         Size aBoxSize(3, 3);
     236           4 :         mpOutDev->DrawRect(Rectangle(aBoxPos, aBoxSize));
     237             :     }
     238          98 : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10