LCOV - code coverage report
Current view: top level - sw/source/core/uibase/docvw - AnnotationMenuButton.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 92 0.0 %
Date: 2014-04-14 Functions: 0 8 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 <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           0 : AnnotationMenuButton::AnnotationMenuButton( sw::sidebarwindows::SwSidebarWin& rSidebarWin )
      49             :     : MenuButton( &rSidebarWin )
      50           0 :     , mrSidebarWin( rSidebarWin )
      51             : {
      52           0 :     AddEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      53             : 
      54           0 :     SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_NAME ) );
      55           0 :     SetAccessibleDescription( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_DESC ) );
      56           0 :     SetQuickHelpText( GetAccessibleDescription() );
      57           0 : }
      58             : 
      59           0 : AnnotationMenuButton::~AnnotationMenuButton()
      60             : {
      61           0 :     RemoveEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      62           0 : }
      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             :     }
      79             :     else
      80             :     {
      81           0 :         pButtonPopup->EnableItem( FN_DELETE_COMMENT, !mrSidebarWin.IsProtected() );
      82           0 :         pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, true );
      83           0 :         pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, true );
      84             :     }
      85             : 
      86           0 :     if ( mrSidebarWin.IsProtected() )
      87             :     {
      88           0 :         pButtonPopup->EnableItem( FN_REPLY, false );
      89             :     }
      90             :     else
      91             :     {
      92           0 :         SvtUserOptions aUserOpt;
      93           0 :         OUString sAuthor;
      94           0 :         if ( (sAuthor = aUserOpt.GetFullName()).isEmpty() )
      95             :         {
      96           0 :             if ( (sAuthor = aUserOpt.GetID()).isEmpty() )
      97             :             {
      98           0 :                 sAuthor = SW_RES( STR_REDLINE_UNKNOWN_AUTHOR );
      99             :             }
     100             :         }
     101             :         // do not allow to reply to ourself and no answer possible if this note is in a protected section
     102           0 :         if ( sAuthor == mrSidebarWin.GetAuthor() )
     103             :         {
     104           0 :             pButtonPopup->EnableItem( FN_REPLY, false );
     105             :         }
     106             :         else
     107             :         {
     108           0 :             pButtonPopup->EnableItem( FN_REPLY, true );
     109           0 :         }
     110             :     }
     111             : 
     112           0 :     MenuButton::MouseButtonDown( rMEvt );
     113           0 : }
     114             : 
     115           0 : void AnnotationMenuButton::Paint( const Rectangle& /*rRect*/ )
     116             : {
     117           0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
     118           0 :         SetFillColor(COL_BLACK);
     119             :     else
     120           0 :         SetFillColor( mrSidebarWin.ColorDark() );
     121           0 :     SetLineColor();
     122           0 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
     123           0 :     DrawRect( aRect );
     124             : 
     125           0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     126             :     {
     127             :         //draw rect around button
     128           0 :         SetFillColor(COL_BLACK);
     129           0 :         SetLineColor(COL_WHITE);
     130             :     }
     131             :     else
     132             :     {
     133             :         //draw button
     134           0 :         Gradient aGradient;
     135           0 :         if ( IsMouseOver() )
     136           0 :             aGradient = Gradient( GradientStyle_LINEAR,
     137           0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     138           0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     139             :         else
     140           0 :             aGradient = Gradient( GradientStyle_LINEAR,
     141           0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     142           0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     143           0 :         DrawGradient( aRect, aGradient );
     144             : 
     145             :         //draw rect around button
     146           0 :         SetFillColor();
     147           0 :         SetLineColor( ColorFromAlphaColor( 90, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     148             :     }
     149           0 :     DrawRect( aRect );
     150             : 
     151           0 :     if ( mrSidebarWin.IsPreview() )
     152             :     {
     153           0 :         Font aOldFont( mrSidebarWin.GetFont() );
     154           0 :         Font aFont(aOldFont);
     155           0 :         Color aCol( COL_BLACK);
     156           0 :         aFont.SetColor( aCol );
     157           0 :         aFont.SetHeight(200);
     158           0 :         aFont.SetWeight(WEIGHT_MEDIUM);
     159           0 :         SetFont( aFont );
     160             :         DrawText(  aRect ,
     161             :                    OUString("Edit Note"),
     162           0 :                    TEXT_DRAW_CENTER );
     163           0 :         SetFont( aOldFont );
     164             :     }
     165             :     else
     166             :     {
     167           0 :         Rectangle aSymbolRect( aRect );
     168             :         // 25% distance to the left and right button border
     169           0 :         const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth()*250)+500)/1000;
     170           0 :         aSymbolRect.Left()+=nBorderDistanceLeftAndRight;
     171           0 :         aSymbolRect.Right()-=nBorderDistanceLeftAndRight;
     172             :         // 40% distance to the top button border
     173           0 :         const long nBorderDistanceTop = ((aSymbolRect.GetHeight()*400)+500)/1000;
     174           0 :         aSymbolRect.Top()+=nBorderDistanceTop;
     175             :         // 15% distance to the bottom button border
     176           0 :         const long nBorderDistanceBottom = ((aSymbolRect.GetHeight()*150)+500)/1000;
     177           0 :         aSymbolRect.Bottom()-=nBorderDistanceBottom;
     178           0 :         DecorationView aDecoView( this );
     179             :         aDecoView.DrawSymbol( aSymbolRect, SYMBOL_SPIN_DOWN,
     180           0 :                               ( Application::GetSettings().GetStyleSettings().GetHighContrastMode()
     181             :                                 ? Color( COL_WHITE )
     182           0 :                                 : Color( COL_BLACK ) ) );
     183             :     }
     184           0 : }
     185             : 
     186           0 : void AnnotationMenuButton::KeyInput( const KeyEvent& rKeyEvt )
     187             : {
     188           0 :     const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
     189           0 :     const sal_uInt16 nKey = rKeyCode.GetCode();
     190           0 :     if ( nKey == KEY_TAB )
     191             :     {
     192           0 :         mrSidebarWin.ActivatePostIt();
     193           0 :         mrSidebarWin.GrabFocus();
     194             :     }
     195             :     else
     196             :     {
     197           0 :         MenuButton::KeyInput( rKeyEvt );
     198             :     }
     199           0 : }
     200             : 
     201             : } } // end of namespace sw::annotation
     202             : 
     203             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10