LCOV - code coverage report
Current view: top level - sw/source/ui/docvw - AnnotationMenuButton.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 10 90 11.1 %
Date: 2012-08-25 Functions: 3 8 37.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 166 8.4 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /************************************************************************* *
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2008 by Sun Microsystems, Inc.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <AnnotationMenuButton.hxx>
      30                 :            : 
      31                 :            : #include <annotation.hrc>
      32                 :            : #include <app.hrc>
      33                 :            : #include <access.hrc>
      34                 :            : 
      35                 :            : #include <unotools/useroptions.hxx>
      36                 :            : 
      37                 :            : #include <vcl/svapp.hxx>
      38                 :            : #include <vcl/menu.hxx>
      39                 :            : #include <vcl/decoview.hxx>
      40                 :            : #include <vcl/gradient.hxx>
      41                 :            : 
      42                 :            : #include <cmdid.h>
      43                 :            : #include <SidebarWin.hxx>
      44                 :            : 
      45                 :            : namespace sw { namespace annotation {
      46                 :            : 
      47                 :          0 : Color ColorFromAlphaColor( const sal_uInt8 aTransparency,
      48                 :            :                            const Color &aFront,
      49                 :            :                            const Color &aBack )
      50                 :            : {
      51                 :          0 :     return Color((sal_uInt8)(aFront.GetRed()    * aTransparency/(double)255 + aBack.GetRed()    * (1-aTransparency/(double)255)),
      52                 :          0 :                  (sal_uInt8)(aFront.GetGreen()  * aTransparency/(double)255 + aBack.GetGreen()  * (1-aTransparency/(double)255)),
      53                 :          0 :                  (sal_uInt8)(aFront.GetBlue()   * aTransparency/(double)255 + aBack.GetBlue()   * (1-aTransparency/(double)255)));
      54                 :            : }
      55                 :            : 
      56                 :         18 : AnnotationMenuButton::AnnotationMenuButton( sw::sidebarwindows::SwSidebarWin& rSidebarWin )
      57                 :            :     : MenuButton( &rSidebarWin )
      58                 :         18 :     , mrSidebarWin( rSidebarWin )
      59                 :            : {
      60 [ +  - ][ +  - ]:         18 :     AddEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      61                 :            : 
      62 [ +  - ][ +  - ]:         18 :     SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_NAME ) );
                 [ +  - ]
      63 [ +  - ][ +  - ]:         18 :     SetAccessibleDescription( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_DESC ) );
                 [ +  - ]
      64 [ +  - ][ +  - ]:         18 :     SetQuickHelpText( GetAccessibleDescription() );
                 [ +  - ]
      65                 :         18 : }
      66                 :            : 
      67                 :         15 : AnnotationMenuButton::~AnnotationMenuButton()
      68                 :            : {
      69 [ +  - ][ +  - ]:         15 :     RemoveEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) );
      70         [ -  + ]:         30 : }
      71                 :            : 
      72                 :          0 : void AnnotationMenuButton::Select()
      73                 :            : {
      74                 :          0 :     mrSidebarWin.ExecuteCommand( GetCurItemId() );
      75                 :          0 : }
      76                 :            : 
      77                 :          0 : void AnnotationMenuButton::MouseButtonDown( const MouseEvent& rMEvt )
      78                 :            : {
      79                 :          0 :     PopupMenu* pButtonPopup( GetPopupMenu() );
      80         [ #  # ]:          0 :     if ( mrSidebarWin.IsReadOnly() )
      81                 :            :     {
      82                 :          0 :         pButtonPopup->EnableItem( FN_REPLY, false );
      83                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_COMMENT, false );
      84                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, false );
      85                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, false );
      86                 :            :     }
      87                 :            :     else
      88                 :            :     {
      89                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_COMMENT, !mrSidebarWin.IsProtected() );
      90                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, true );
      91                 :          0 :         pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, true );
      92                 :            :     }
      93                 :            : 
      94         [ #  # ]:          0 :     if ( mrSidebarWin.IsProtected() )
      95                 :            :     {
      96                 :          0 :         pButtonPopup->EnableItem( FN_REPLY, false );
      97                 :            :     }
      98                 :            :     else
      99                 :            :     {
     100         [ #  # ]:          0 :         SvtUserOptions aUserOpt;
     101         [ #  # ]:          0 :         String sAuthor;
     102 [ #  # ][ #  # ]:          0 :         if ( !(sAuthor = aUserOpt.GetFullName()).Len() )
                 [ #  # ]
     103                 :            :         {
     104 [ #  # ][ #  # ]:          0 :             if ( !(sAuthor = aUserOpt.GetID()).Len() )
                 [ #  # ]
     105                 :            :             {
     106 [ #  # ][ #  # ]:          0 :                 sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR ));
                 [ #  # ]
     107                 :            :             }
     108                 :            :         }
     109                 :            :         // do not allow to reply to ourself and no answer possible if this note is in a protected section
     110 [ #  # ][ #  # ]:          0 :         if ( sAuthor == mrSidebarWin.GetAuthor() )
         [ #  # ][ #  # ]
     111                 :            :         {
     112         [ #  # ]:          0 :             pButtonPopup->EnableItem( FN_REPLY, false );
     113                 :            :         }
     114                 :            :         else
     115                 :            :         {
     116         [ #  # ]:          0 :             pButtonPopup->EnableItem( FN_REPLY, true );
     117 [ #  # ][ #  # ]:          0 :         }
     118                 :            :     }
     119                 :            : 
     120                 :          0 :     MenuButton::MouseButtonDown( rMEvt );
     121                 :          0 : }
     122                 :            : 
     123                 :          0 : void AnnotationMenuButton::Paint( const Rectangle& /*rRect*/ )
     124                 :            : {
     125 [ #  # ][ #  # ]:          0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() )
     126         [ #  # ]:          0 :         SetFillColor(COL_BLACK);
     127                 :            :     else
     128         [ #  # ]:          0 :         SetFillColor( mrSidebarWin.ColorDark() );
     129         [ #  # ]:          0 :     SetLineColor();
     130 [ #  # ][ #  # ]:          0 :     const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) );
                 [ #  # ]
     131         [ #  # ]:          0 :     DrawRect( aRect );
     132                 :            : 
     133 [ #  # ][ #  # ]:          0 :     if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode())
     134                 :            :     {
     135                 :            :         //draw rect around button
     136         [ #  # ]:          0 :         SetFillColor(COL_BLACK);
     137         [ #  # ]:          0 :         SetLineColor(COL_WHITE);
     138                 :            :     }
     139                 :            :     else
     140                 :            :     {
     141                 :            :         //draw button
     142         [ #  # ]:          0 :         Gradient aGradient;
     143 [ #  # ][ #  # ]:          0 :         if ( IsMouseOver() )
     144                 :            :             aGradient = Gradient( GradientStyle_LINEAR,
     145                 :          0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     146 [ #  # ][ #  # ]:          0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
                 [ #  # ]
     147                 :            :         else
     148                 :            :             aGradient = Gradient( GradientStyle_LINEAR,
     149                 :          0 :                                   ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ),
     150 [ #  # ][ #  # ]:          0 :                                   ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
                 [ #  # ]
     151         [ #  # ]:          0 :         DrawGradient( aRect, aGradient );
     152                 :            : 
     153                 :            :         //draw rect around button
     154         [ #  # ]:          0 :         SetFillColor();
     155 [ #  # ][ #  # ]:          0 :         SetLineColor( ColorFromAlphaColor( 90, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ));
     156                 :            :     }
     157         [ #  # ]:          0 :     DrawRect( aRect );
     158                 :            : 
     159         [ #  # ]:          0 :     if ( mrSidebarWin.IsPreview() )
     160                 :            :     {
     161         [ #  # ]:          0 :         Font aOldFont( mrSidebarWin.GetFont() );
     162         [ #  # ]:          0 :         Font aFont(aOldFont);
     163                 :          0 :         Color aCol( COL_BLACK);
     164         [ #  # ]:          0 :         aFont.SetColor( aCol );
     165         [ #  # ]:          0 :         aFont.SetHeight(200);
     166         [ #  # ]:          0 :         aFont.SetWeight(WEIGHT_MEDIUM);
     167         [ #  # ]:          0 :         SetFont( aFont );
     168                 :            :         DrawText(  aRect ,
     169                 :            :                    rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Edit Note")),
     170 [ #  # ][ #  # ]:          0 :                    TEXT_DRAW_CENTER );
         [ #  # ][ #  # ]
     171 [ #  # ][ #  # ]:          0 :         SetFont( aOldFont );
                 [ #  # ]
     172                 :            :     }
     173                 :            :     else
     174                 :            :     {
     175                 :          0 :         Rectangle aSymbolRect( aRect );
     176                 :            :         // 25% distance to the left and right button border
     177         [ #  # ]:          0 :         const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth()*250)+500)/1000;
     178                 :          0 :         aSymbolRect.Left()+=nBorderDistanceLeftAndRight;
     179                 :          0 :         aSymbolRect.Right()-=nBorderDistanceLeftAndRight;
     180                 :            :         // 40% distance to the top button border
     181         [ #  # ]:          0 :         const long nBorderDistanceTop = ((aSymbolRect.GetHeight()*400)+500)/1000;
     182                 :          0 :         aSymbolRect.Top()+=nBorderDistanceTop;
     183                 :            :         // 15% distance to the bottom button border
     184         [ #  # ]:          0 :         const long nBorderDistanceBottom = ((aSymbolRect.GetHeight()*150)+500)/1000;
     185                 :          0 :         aSymbolRect.Bottom()-=nBorderDistanceBottom;
     186                 :          0 :         DecorationView aDecoView( this );
     187                 :            :         aDecoView.DrawSymbol( aSymbolRect, SYMBOL_SPIN_DOWN,
     188         [ #  # ]:          0 :                               ( Application::GetSettings().GetStyleSettings().GetHighContrastMode()
     189                 :            :                                 ? Color( COL_WHITE )
     190 [ #  # ][ #  # ]:          0 :                                 : Color( COL_BLACK ) ) );
     191                 :            :     }
     192                 :          0 : }
     193                 :            : 
     194                 :          0 : void AnnotationMenuButton::KeyInput( const KeyEvent& rKeyEvt )
     195                 :            : {
     196                 :          0 :     const KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
     197                 :          0 :     const sal_uInt16 nKey = rKeyCode.GetCode();
     198         [ #  # ]:          0 :     if ( nKey == KEY_TAB )
     199                 :            :     {
     200                 :          0 :         mrSidebarWin.ActivatePostIt();
     201                 :          0 :         mrSidebarWin.GrabFocus();
     202                 :            :     }
     203                 :            :     else
     204                 :            :     {
     205                 :          0 :         MenuButton::KeyInput( rKeyEvt );
     206                 :            :     }
     207                 :          0 : }
     208                 :            : 
     209                 :            : } } // end of namespace sw::annotation
     210                 :            : 
     211                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10