LCOV - code coverage report
Current view: top level - sc/source/ui/cctrl - dpcontrol.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 129 0.0 %
Date: 2014-04-14 Functions: 0 12 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             : 
      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           0 : 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           0 :     mbPopupLeft(false)
      40             : {
      41           0 :     if (pZoomX)
      42           0 :         maZoomX = *pZoomX;
      43             :     else
      44           0 :         maZoomX = Fraction(1, 1);
      45             : 
      46           0 :     if (pZoomY)
      47           0 :         maZoomY = *pZoomY;
      48             :     else
      49           0 :         maZoomY = Fraction(1, 1);
      50           0 : }
      51             : 
      52           0 : ScDPFieldButton::~ScDPFieldButton()
      53             : {
      54           0 : }
      55             : 
      56           0 : void ScDPFieldButton::setText(const OUString& rText)
      57             : {
      58           0 :     maText = rText;
      59           0 : }
      60             : 
      61           0 : void ScDPFieldButton::setBoundingBox(const Point& rPos, const Size& rSize, bool bLayoutRTL)
      62             : {
      63           0 :     maPos = rPos;
      64           0 :     maSize = rSize;
      65           0 :     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           0 : }
      71             : 
      72           0 : void ScDPFieldButton::setDrawBaseButton(bool b)
      73             : {
      74           0 :     mbBaseButton = b;
      75           0 : }
      76             : 
      77           0 : void ScDPFieldButton::setDrawPopupButton(bool b)
      78             : {
      79           0 :     mbPopupButton = b;
      80           0 : }
      81             : 
      82           0 : void ScDPFieldButton::setHasHiddenMember(bool b)
      83             : {
      84           0 :     mbHasHiddenMember = b;
      85           0 : }
      86             : 
      87           0 : void ScDPFieldButton::setPopupPressed(bool b)
      88             : {
      89           0 :     mbPopupPressed = b;
      90           0 : }
      91             : 
      92           0 : void ScDPFieldButton::setPopupLeft(bool b)
      93             : {
      94           0 :     mbPopupLeft = b;
      95           0 : }
      96             : 
      97           0 : void ScDPFieldButton::draw()
      98             : {
      99           0 :     bool bOldMapEnablaed = mpOutDev->IsMapModeEnabled();
     100           0 :     mpOutDev->EnableMapMode(false);
     101             : 
     102           0 :     if (mbBaseButton)
     103             :     {
     104             :         // Background
     105           0 :         Rectangle aRect(maPos, maSize);
     106           0 :         mpOutDev->SetLineColor(mpStyle->GetFaceColor());
     107           0 :         mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     108           0 :         mpOutDev->DrawRect(aRect);
     109             : 
     110             :         // Border lines
     111           0 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     112           0 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X(), maPos.Y()+maSize.Height()-1));
     113           0 :         mpOutDev->DrawLine(Point(maPos), Point(maPos.X()+maSize.Width()-1, maPos.Y()));
     114             : 
     115           0 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     116           0 :         mpOutDev->DrawLine(Point(maPos.X(), maPos.Y()+maSize.Height()-1),
     117           0 :                            Point(maPos.X()+maSize.Width()-1, maPos.Y()+maSize.Height()-1));
     118           0 :         mpOutDev->DrawLine(Point(maPos.X()+maSize.Width()-1, maPos.Y()),
     119           0 :                            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           0 :         Font aTextFont( mpStyle->GetAppFont() );
     124           0 :         if ( mpDoc )
     125             :         {
     126             :             //  use ScPatternAttr::GetFont only for font size
     127           0 :             Font aAttrFont;
     128           0 :             static_cast<const ScPatternAttr&>(mpDoc->GetPool()->GetDefaultItem(ATTR_PATTERN)).
     129           0 :                 GetFont( aAttrFont, SC_AUTOCOL_BLACK, mpOutDev, &maZoomY );
     130           0 :             aTextFont.SetSize( aAttrFont.GetSize() );
     131             :         }
     132           0 :         mpOutDev->SetFont(aTextFont);
     133           0 :         mpOutDev->SetTextColor(mpStyle->GetButtonTextColor());
     134             : 
     135           0 :         Point aTextPos = maPos;
     136           0 :         long nTHeight = mpOutDev->GetTextHeight();
     137           0 :         aTextPos.setX(maPos.getX() + 2); // 2 = Margin
     138           0 :         aTextPos.setY(maPos.getY() + (maSize.Height()-nTHeight)/2);
     139             : 
     140           0 :         mpOutDev->Push(PUSH_CLIPREGION);
     141           0 :         mpOutDev->IntersectClipRegion(aRect);
     142           0 :         mpOutDev->DrawText(aTextPos, maText);
     143           0 :         mpOutDev->Pop();
     144             :     }
     145             : 
     146           0 :     if (mbPopupButton)
     147           0 :         drawPopupButton();
     148             : 
     149           0 :     mpOutDev->EnableMapMode(bOldMapEnablaed);
     150           0 : }
     151             : 
     152           0 : void ScDPFieldButton::getPopupBoundingBox(Point& rPos, Size& rSize) const
     153             : {
     154           0 :     long nW = maSize.getWidth() / 2;
     155           0 :     long nH = maSize.getHeight();
     156           0 :     if (nW > 18)
     157           0 :         nW = 18;
     158           0 :     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           0 :     if (mbPopupLeft)
     164           0 :         rPos.setX(maPos.getX());
     165             :     else
     166           0 :         rPos.setX(maPos.getX() + maSize.getWidth() - nW);
     167           0 :     rPos.setY(maPos.getY() + maSize.getHeight() - nH);
     168           0 :     rSize.setWidth(nW);
     169           0 :     rSize.setHeight(nH);
     170           0 : }
     171             : 
     172           0 : void ScDPFieldButton::drawPopupButton()
     173             : {
     174           0 :     Point aPos;
     175           0 :     Size aSize;
     176           0 :     getPopupBoundingBox(aPos, aSize);
     177             : 
     178             :     // Background & outer black border
     179           0 :     mpOutDev->SetLineColor(COL_BLACK);
     180           0 :     mpOutDev->SetFillColor(mpStyle->GetFaceColor());
     181           0 :     mpOutDev->DrawRect(Rectangle(aPos, aSize));
     182             : 
     183           0 :     if (!mbPopupPressed)
     184             :     {
     185             :         // border lines
     186           0 :         mpOutDev->SetLineColor(mpStyle->GetLightColor());
     187           0 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+1, aPos.Y()+aSize.Height()-2));
     188           0 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+1), Point(aPos.X()+aSize.Width()-2, aPos.Y()+1));
     189             : 
     190           0 :         mpOutDev->SetLineColor(mpStyle->GetShadowColor());
     191           0 :         mpOutDev->DrawLine(Point(aPos.X()+1, aPos.Y()+aSize.Height()-2),
     192           0 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     193           0 :         mpOutDev->DrawLine(Point(aPos.X()+aSize.Width()-2, aPos.Y()+1),
     194           0 :                            Point(aPos.X()+aSize.Width()-2, aPos.Y()+aSize.Height()-2));
     195             :     }
     196             : 
     197             :     // the arrowhead
     198           0 :     Color aArrowColor = mbHasHiddenMember ? mpStyle->GetHighlightLinkColor() : mpStyle->GetButtonTextColor();
     199           0 :     mpOutDev->SetLineColor(aArrowColor);
     200           0 :     mpOutDev->SetFillColor(aArrowColor);
     201           0 :     Point aCenter(aPos.X() + (aSize.Width() >> 1), aPos.Y() + (aSize.Height() >> 1));
     202           0 :     Point aPos1, aPos2;
     203           0 :     aPos1.X() = aCenter.X() - 4;
     204           0 :     aPos2.X() = aCenter.X() + 4;
     205           0 :     aPos1.Y() = aCenter.Y() - 3;
     206           0 :     aPos2.Y() = aCenter.Y() - 3;
     207             : 
     208           0 :     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           0 :     do
     217             :     {
     218           0 :         ++aPos1.X();
     219           0 :         --aPos2.X();
     220           0 :         ++aPos1.Y();
     221           0 :         ++aPos2.Y();
     222           0 :         mpOutDev->DrawLine(aPos1, aPos2);
     223             :     }
     224             :     while (aPos1 != aPos2);
     225             : 
     226           0 :     if (mbHasHiddenMember)
     227             :     {
     228             :         // tiny little box to display in presence of hidden member(s).
     229           0 :         Point aBoxPos(aPos.X() + aSize.Width() - 5, aPos.Y() + aSize.Height() - 5);
     230           0 :         if (mbPopupPressed)
     231             :         {
     232           0 :             aBoxPos.X() += 1;
     233           0 :             aBoxPos.Y() += 1;
     234             :         }
     235           0 :         Size aBoxSize(3, 3);
     236           0 :         mpOutDev->DrawRect(Rectangle(aBoxPos, aBoxSize));
     237             :     }
     238           0 : }
     239             : 
     240             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10