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

Generated by: LCOV version 1.10