LCOV - code coverage report
Current view: top level - sw/source/uibase/docvw - AnnotationMenuButton.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 11 95 11.6 %
Date: 2014-11-03 Functions: 5 10 50.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 <AnnotationMenuButton.hxx>
      21             : 
      22             : #include <annotation.hrc>
      23             : #include <app.hrc>
      24             : #include <access.hrc>
      25             : 
      26             : #include <unotools/useroptions.hxx>
      27             : 
      28             : #include <vcl/svapp.hxx>
      29             : #include <vcl/menu.hxx>
      30             : #include <vcl/decoview.hxx>
      31             : #include <vcl/gradient.hxx>
      32             : #include <vcl/settings.hxx>
      33             : 
      34             : #include <cmdid.h>
      35             : #include <SidebarWin.hxx>
      36             : 
      37             : namespace sw { namespace annotation {
      38             : 
      39           0 : Color ColorFromAlphaColor( const sal_uInt8 aTransparency,
      40             :                            const Color &aFront,
      41             :                            const Color &aBack )
      42             : {
      43           0 :     return Color((sal_uInt8)(aFront.GetRed()    * aTransparency/(double)255 + aBack.GetRed()    * (1-aTransparency/(double)255)),
      44           0 :                  (sal_uInt8)(aFront.GetGreen()  * aTransparency/(double)255 + aBack.GetGreen()  * (1-aTransparency/(double)255)),
      45           0 :                  (sal_uInt8)(aFront.GetBlue()   * aTransparency/(double)255 + aBack.GetBlue()   * (1-aTransparency/(double)255)));
      46             : }
      47             : 
      48         130 : AnnotationMenuButton::AnnotationMenuButton( sw::sidebarwindows::SwSidebarWin& rSidebarWin )
      49             :     : MenuButton( &rSidebarWin )
      50         130 :     , mrSidebarWin( rSidebarWin )
      51             : {
      52         130 :     AddEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      53             : 
      54         130 :     SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_NAME ) );
      55         130 :     SetAccessibleDescription( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_DESC ) );
      56         130 :     SetQuickHelpText( GetAccessibleDescription() );
      57         130 : }
      58             : 
      59         390 : AnnotationMenuButton::~AnnotationMenuButton()
      60             : {
      61         130 :     RemoveEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      62         260 : }
      63             : 
      64           0 : void AnnotationMenuButton::Select()
      65             : {
      66           0 :     mrSidebarWin.ExecuteCommand( GetCurItemId() );
      67           0 : }
      68             : 
      69           0 : void AnnotationMenuButton::MouseButtonDown( const MouseEvent& rMEvt )
      70             : {
      71           0 :     PopupMenu* pButtonPopup( GetPopupMenu() );
      72           0 :     if ( mrSidebarWin.IsReadOnly() )
      73             :     {
      74           0 :         pButtonPopup->EnableItem( FN_REPLY, false );
      75           0 :         pButtonPopup->EnableItem( FN_DELETE_COMMENT, false );
      76           0 :         pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, false );
      77           0 :         pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, false );
      78           0 :         pButtonPopup->EnableItem( FN_FORMAT_ALL_NOTES, false );
      79             :     }
      80             :     else
      81             :     {
      82           0 :         pButtonPopup->EnableItem( FN_DELETE_COMMENT, !mrSidebarWin.IsProtected() );
      83           0 :         pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, true );
      84           0 :         pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, true );
      85           0 :         pButtonPopup->EnableItem( FN_FORMAT_ALL_NOTES, true );
      86             :     }
      87             : 
      88           0 :     if ( mrSidebarWin.IsProtected() )
      89             :     {
      90           0 :         pButtonPopup->EnableItem( FN_REPLY, false );
      91             :     }
      92             :     else
      93             :     {
      94           0 :         SvtUserOptions aUserOpt;
      95           0 :         OUString sAuthor;
      96           0 :         if ( (sAuthor = aUserOpt.GetFullName()).isEmpty() )
      97             :         {
      98           0 :             if ( (sAuthor = aUserOpt.GetID()).isEmpty() )
      99             :             {
     100           0 :                 sAuthor = SW_RES( STR_REDLINE_UNKNOWN_AUTHOR );
     101             :             }
     102             :         }
     103             :         // do not allow to reply to ourself and no answer possible if this note is in a protected section
     104           0 :         if ( sAuthor == mrSidebarWin.GetAuthor() )
     105             :         {
     106           0 :             pButtonPopup->EnableItem( FN_REPLY, false );
     107             :         }
     108             :         else
     109             :         {
     110           0 :             pButtonPopup->EnableItem( FN_REPLY, true );
     111           0 :         }
     112             :     }
     113             : 
     114           0 :     MenuButton::MouseButtonDown( rMEvt );
     115           0 : }
     116             : 
     117           0 : void AnnotationMenuButton::Paint( const Rectangle& /*rRect*/ )
     118             : {
     119           0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
     120           0 :         SetFillColor(COL_BLACK);
     121             :     else
     122           0 :         SetFillColor( mrSidebarWin.ColorDark() );
     123           0 :     SetLineColor();
     124           0 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
     125           0 :     DrawRect( aRect );
     126             : 
     127           0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     128             :     {
     129             :         //draw rect around button
     130           0 :         SetFillColor(COL_BLACK);
     131           0 :         SetLineColor(COL_WHITE);
     132             :     }
     133             :     else
     134             :     {
     135             :         //draw button
     136           0 :         Gradient aGradient;
     137           0 :         if ( IsMouseOver() )
     138           0 :             aGradient = Gradient( GradientStyle_LINEAR,
     139           0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     140           0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     141             :         else
     142           0 :             aGradient = Gradient( GradientStyle_LINEAR,
     143           0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     144           0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     145           0 :         DrawGradient( aRect, aGradient );
     146             : 
     147             :         //draw rect around button
     148           0 :         SetFillColor();
     149           0 :         SetLineColor( ColorFromAlphaColor( 90, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     150             :     }
     151           0 :     DrawRect( aRect );
     152             : 
     153           0 :     if ( mrSidebarWin.IsPreview() )
     154             :     {
     155           0 :         vcl::Font aOldFont( mrSidebarWin.GetFont() );
     156           0 :         vcl::Font aFont(aOldFont);
     157           0 :         Color aCol( COL_BLACK);
     158           0 :         aFont.SetColor( aCol );
     159           0 :         aFont.SetHeight(200);
     160           0 :         aFont.SetWeight(WEIGHT_MEDIUM);
     161           0 :         SetFont( aFont );
     162             :         DrawText(  aRect ,
     163             :                    OUString("Edit Note"),
     164           0 :                    TEXT_DRAW_CENTER );
     165           0 :         SetFont( aOldFont );
     166             :     }
     167             :     else
     168             :     {
     169           0 :         Rectangle aSymbolRect( aRect );
     170             :         // 25% distance to the left and right button border
     171           0 :         const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth()*250)+500)/1000;
     172           0 :         aSymbolRect.Left()+=nBorderDistanceLeftAndRight;
     173           0 :         aSymbolRect.Right()-=nBorderDistanceLeftAndRight;
     174             :         // 40% distance to the top button border
     175           0 :         const long nBorderDistanceTop = ((aSymbolRect.GetHeight()*400)+500)/1000;
     176           0 :         aSymbolRect.Top()+=nBorderDistanceTop;
     177             :         // 15% distance to the bottom button border
     178           0 :         const long nBorderDistanceBottom = ((aSymbolRect.GetHeight()*150)+500)/1000;
     179           0 :         aSymbolRect.Bottom()-=nBorderDistanceBottom;
     180           0 :         DecorationView aDecoView( this );
     181             :         aDecoView.DrawSymbol( aSymbolRect, SymbolType::SPIN_DOWN,
     182           0 :                               ( Application::GetSettings().GetStyleSettings().GetHighContrastMode()
     183             :                                 ? Color( COL_WHITE )
     184           0 :                                 : Color( COL_BLACK ) ) );
     185             :     }
     186           0 : }
     187             : 
     188           0 : void AnnotationMenuButton::KeyInput( const KeyEvent& rKeyEvt )
     189             : {
     190           0 :     const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
     191           0 :     const sal_uInt16 nKey = rKeyCode.GetCode();
     192           0 :     if ( nKey == KEY_TAB )
     193             :     {
     194           0 :         mrSidebarWin.ActivatePostIt();
     195           0 :         mrSidebarWin.GrabFocus();
     196             :     }
     197             :     else
     198             :     {
     199           0 :         MenuButton::KeyInput( rKeyEvt );
     200             :     }
     201           0 : }
     202             : 
     203         270 : } } // end of namespace sw::annotation
     204             : 
     205             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10