LCOV - code coverage report
Current view: top level - sfx2/source/sidebar - MenuButton.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 17 42 40.5 %
Date: 2015-06-13 12:38:46 Functions: 2 5 40.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 "MenuButton.hxx"
      21             : 
      22             : #include "DrawHelper.hxx"
      23             : #include "Paint.hxx"
      24             : #include <sfx2/sidebar/Tools.hxx>
      25             : #include <sfx2/sidebar/Theme.hxx>
      26             : 
      27             : using namespace css;
      28             : using namespace css::uno;
      29             : 
      30             : namespace sfx2 { namespace sidebar {
      31             : 
      32        3155 : MenuButton::MenuButton (vcl::Window* pParentWindow)
      33             :     : CheckBox(pParentWindow),
      34             :       mbIsLeftButtonDown(false),
      35        3155 :       mePaintType(PT_Theme)
      36             : {
      37             : #ifdef DEBUG
      38             :     SetText(OUString("MenuButton"));
      39             : #endif
      40        3155 : }
      41             : 
      42        6375 : void MenuButton::Paint(vcl::RenderContext& rRenderContext, const Rectangle& rUpdateArea)
      43             : {
      44        6375 :     switch (mePaintType)
      45             :     {
      46             :         case PT_Theme:
      47             :         default:
      48             :         {
      49        6375 :             const bool bIsSelected (IsChecked());
      50        6375 :             const bool bIsHighlighted (IsMouseOver() || HasFocus());
      51             :             DrawHelper::DrawRoundedRectangle(
      52             :                         rRenderContext,
      53        6375 :                         Rectangle(Point(0,0), GetSizePixel()),
      54             :                         3,
      55        6375 :                         (bIsHighlighted || bIsSelected
      56             :                             ? Theme::GetColor(Theme::Color_TabItemBorder)
      57             :                             : Color(0xffffffff)),
      58             :                         (bIsHighlighted
      59             :                             ? Theme::GetPaint(Theme::Paint_TabItemBackgroundHighlight)
      60       12750 :                             : Theme::GetPaint(Theme::Paint_TabItemBackgroundNormal)));
      61             : 
      62        6375 :             const Image aIcon(Button::GetModeImage());
      63        6375 :             const Size aIconSize(aIcon.GetSizePixel());
      64       12750 :             const Point aIconLocation((GetSizePixel().Width() - aIconSize.Width()) / 2,
      65       19125 :                                       (GetSizePixel().Height() - aIconSize.Height()) / 2);
      66        6375 :             rRenderContext.DrawImage(aIconLocation, aIcon);
      67        6375 :             break;
      68             :         }
      69             :         case PT_Native:
      70           0 :             Button::Paint(rRenderContext, rUpdateArea);
      71           0 :             break;
      72             :     }
      73        6375 : }
      74             : 
      75           0 : void MenuButton::MouseMove (const MouseEvent& rEvent)
      76             : {
      77           0 :     if (rEvent.IsEnterWindow() || rEvent.IsLeaveWindow())
      78           0 :         Invalidate();
      79           0 :     CheckBox::MouseMove(rEvent);
      80           0 : }
      81             : 
      82           0 : void MenuButton::MouseButtonDown (const MouseEvent& rMouseEvent)
      83             : {
      84           0 :     if (rMouseEvent.IsLeft())
      85             :     {
      86           0 :         mbIsLeftButtonDown = true;
      87           0 :         CaptureMouse();
      88           0 :         Invalidate();
      89             :     }
      90           0 : }
      91             : 
      92           0 : void MenuButton::MouseButtonUp (const MouseEvent& rMouseEvent)
      93             : {
      94           0 :     if (IsMouseCaptured())
      95           0 :         ReleaseMouse();
      96             : 
      97           0 :     if (rMouseEvent.IsLeft())
      98             :     {
      99           0 :         if (mbIsLeftButtonDown)
     100             :         {
     101           0 :             Check();
     102           0 :             Click();
     103           0 :             GetParent()->Invalidate();
     104             :         }
     105             :     }
     106           0 :     if (mbIsLeftButtonDown)
     107             :     {
     108           0 :         mbIsLeftButtonDown = false;
     109           0 :         Invalidate();
     110             :     }
     111           0 : }
     112             : 
     113             : } } // end of namespace sfx2::sidebar
     114             : 
     115             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11