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