1*efeef26fSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*efeef26fSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*efeef26fSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*efeef26fSAndrew Rist * distributed with this work for additional information 6*efeef26fSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*efeef26fSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*efeef26fSAndrew Rist * "License"); you may not use this file except in compliance 9*efeef26fSAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*efeef26fSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*efeef26fSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*efeef26fSAndrew Rist * software distributed under the License is distributed on an 15*efeef26fSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*efeef26fSAndrew Rist * KIND, either express or implied. See the License for the 17*efeef26fSAndrew Rist * specific language governing permissions and limitations 18*efeef26fSAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*efeef26fSAndrew Rist *************************************************************/ 21*efeef26fSAndrew Rist 22*efeef26fSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir #include "precompiled_sw.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <AnnotationMenuButton.hxx> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <annotation.hrc> 30cdf0e10cSrcweir #include <app.hrc> 31cdf0e10cSrcweir #include <access.hrc> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #include <unotools/useroptions.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #include <vcl/svapp.hxx> 36cdf0e10cSrcweir #include <vcl/menu.hxx> 37cdf0e10cSrcweir #include <vcl/decoview.hxx> 38cdf0e10cSrcweir #include <vcl/gradient.hxx> 39cdf0e10cSrcweir 40cdf0e10cSrcweir #include <cmdid.h> 41cdf0e10cSrcweir #include <SidebarWin.hxx> 42cdf0e10cSrcweir 43cdf0e10cSrcweir namespace sw { namespace annotation { 44cdf0e10cSrcweir 45cdf0e10cSrcweir Color ColorFromAlphaColor( const sal_uInt8 aTransparency, 46cdf0e10cSrcweir const Color &aFront, 47cdf0e10cSrcweir const Color &aBack ) 48cdf0e10cSrcweir { 49cdf0e10cSrcweir return Color((sal_uInt8)(aFront.GetRed() * aTransparency/(double)255 + aBack.GetRed() * (1-aTransparency/(double)255)), 50cdf0e10cSrcweir (sal_uInt8)(aFront.GetGreen() * aTransparency/(double)255 + aBack.GetGreen() * (1-aTransparency/(double)255)), 51cdf0e10cSrcweir (sal_uInt8)(aFront.GetBlue() * aTransparency/(double)255 + aBack.GetBlue() * (1-aTransparency/(double)255))); 52cdf0e10cSrcweir } 53cdf0e10cSrcweir 54cdf0e10cSrcweir AnnotationMenuButton::AnnotationMenuButton( sw::sidebarwindows::SwSidebarWin& rSidebarWin ) 55cdf0e10cSrcweir : MenuButton( &rSidebarWin ) 56cdf0e10cSrcweir , mrSidebarWin( rSidebarWin ) 57cdf0e10cSrcweir { 58cdf0e10cSrcweir AddEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) ); 59cdf0e10cSrcweir 60cdf0e10cSrcweir SetAccessibleName( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_NAME ) ); 61cdf0e10cSrcweir SetAccessibleDescription( SW_RES( STR_ACCESS_ANNOTATION_BUTTON_DESC ) ); 62cdf0e10cSrcweir SetQuickHelpText( GetAccessibleDescription() ); 63cdf0e10cSrcweir } 64cdf0e10cSrcweir 65cdf0e10cSrcweir AnnotationMenuButton::~AnnotationMenuButton() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir RemoveEventListener( LINK( &mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener ) ); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir void AnnotationMenuButton::Select() 71cdf0e10cSrcweir { 72cdf0e10cSrcweir mrSidebarWin.ExecuteCommand( GetCurItemId() ); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir 75cdf0e10cSrcweir void AnnotationMenuButton::MouseButtonDown( const MouseEvent& rMEvt ) 76cdf0e10cSrcweir { 77cdf0e10cSrcweir PopupMenu* pButtonPopup( GetPopupMenu() ); 78cdf0e10cSrcweir if ( mrSidebarWin.IsReadOnly() ) 79cdf0e10cSrcweir { 80cdf0e10cSrcweir pButtonPopup->EnableItem( FN_REPLY, false ); 81cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_COMMENT, false ); 82cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, false ); 83cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, false ); 84cdf0e10cSrcweir } 85cdf0e10cSrcweir else 86cdf0e10cSrcweir { 87cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_COMMENT, !mrSidebarWin.IsProtected() ); 88cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_NOTE_AUTHOR, true ); 89cdf0e10cSrcweir pButtonPopup->EnableItem( FN_DELETE_ALL_NOTES, true ); 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir if ( mrSidebarWin.IsProtected() ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir pButtonPopup->EnableItem( FN_REPLY, false ); 95cdf0e10cSrcweir } 96cdf0e10cSrcweir else 97cdf0e10cSrcweir { 98cdf0e10cSrcweir SvtUserOptions aUserOpt; 99cdf0e10cSrcweir String sAuthor; 100cdf0e10cSrcweir if ( !(sAuthor = aUserOpt.GetFullName()).Len() ) 101cdf0e10cSrcweir { 102cdf0e10cSrcweir if ( !(sAuthor = aUserOpt.GetID()).Len() ) 103cdf0e10cSrcweir { 104cdf0e10cSrcweir sAuthor = String( SW_RES( STR_REDLINE_UNKNOWN_AUTHOR )); 105cdf0e10cSrcweir } 106cdf0e10cSrcweir } 107cdf0e10cSrcweir // do not allow to reply to ourself and no answer possible if this note is in a protected section 108cdf0e10cSrcweir if ( sAuthor == mrSidebarWin.GetAuthor() ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir pButtonPopup->EnableItem( FN_REPLY, false ); 111cdf0e10cSrcweir } 112cdf0e10cSrcweir else 113cdf0e10cSrcweir { 114cdf0e10cSrcweir pButtonPopup->EnableItem( FN_REPLY, true ); 115cdf0e10cSrcweir } 116cdf0e10cSrcweir } 117cdf0e10cSrcweir 118cdf0e10cSrcweir MenuButton::MouseButtonDown( rMEvt ); 119cdf0e10cSrcweir } 120cdf0e10cSrcweir 121cdf0e10cSrcweir void AnnotationMenuButton::Paint( const Rectangle& /*rRect*/ ) 122cdf0e10cSrcweir { 123cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() ) 124cdf0e10cSrcweir SetFillColor(COL_BLACK); 125cdf0e10cSrcweir else 126cdf0e10cSrcweir SetFillColor( mrSidebarWin.ColorDark() ); 127cdf0e10cSrcweir SetLineColor(); 128cdf0e10cSrcweir const Rectangle aRect( Rectangle( Point( 0, 0 ), PixelToLogic( GetSizePixel() ) ) ); 129cdf0e10cSrcweir DrawRect( aRect ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if ( Application::GetSettings().GetStyleSettings().GetHighContrastMode()) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir //draw rect around button 134cdf0e10cSrcweir SetFillColor(COL_BLACK); 135cdf0e10cSrcweir SetLineColor(COL_WHITE); 136cdf0e10cSrcweir } 137cdf0e10cSrcweir else 138cdf0e10cSrcweir { 139cdf0e10cSrcweir //draw button 140cdf0e10cSrcweir Gradient aGradient; 141cdf0e10cSrcweir if ( IsMouseOver() ) 142cdf0e10cSrcweir aGradient = Gradient( GRADIENT_LINEAR, 143cdf0e10cSrcweir ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ), 144cdf0e10cSrcweir ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() )); 145cdf0e10cSrcweir else 146cdf0e10cSrcweir aGradient = Gradient( GRADIENT_LINEAR, 147cdf0e10cSrcweir ColorFromAlphaColor( 15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() ), 148cdf0e10cSrcweir ColorFromAlphaColor( 80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() )); 149cdf0e10cSrcweir DrawGradient( aRect, aGradient ); 150cdf0e10cSrcweir 151cdf0e10cSrcweir //draw rect around button 152cdf0e10cSrcweir SetFillColor(); 153cdf0e10cSrcweir SetLineColor( ColorFromAlphaColor( 90, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark() )); 154cdf0e10cSrcweir } 155cdf0e10cSrcweir DrawRect( aRect ); 156cdf0e10cSrcweir 157cdf0e10cSrcweir if ( mrSidebarWin.IsPreview() ) 158cdf0e10cSrcweir { 159cdf0e10cSrcweir Font aOldFont( mrSidebarWin.GetFont() ); 160cdf0e10cSrcweir Font aFont(aOldFont); 161cdf0e10cSrcweir Color aCol( COL_BLACK); 162cdf0e10cSrcweir aFont.SetColor( aCol ); 163cdf0e10cSrcweir aFont.SetHeight(200); 164cdf0e10cSrcweir aFont.SetWeight(WEIGHT_MEDIUM); 165cdf0e10cSrcweir SetFont( aFont ); 166cdf0e10cSrcweir DrawText( aRect , 167cdf0e10cSrcweir rtl::OUString::createFromAscii("Edit Note"), 168cdf0e10cSrcweir TEXT_DRAW_CENTER ); 169cdf0e10cSrcweir SetFont( aOldFont ); 170cdf0e10cSrcweir } 171cdf0e10cSrcweir else 172cdf0e10cSrcweir { 173cdf0e10cSrcweir Rectangle aSymbolRect( aRect ); 174cdf0e10cSrcweir // 25% distance to the left and right button border 175cdf0e10cSrcweir const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth()*250)+500)/1000; 176cdf0e10cSrcweir aSymbolRect.Left()+=nBorderDistanceLeftAndRight; 177cdf0e10cSrcweir aSymbolRect.Right()-=nBorderDistanceLeftAndRight; 178cdf0e10cSrcweir // 40% distance to the top button border 179cdf0e10cSrcweir const long nBorderDistanceTop = ((aSymbolRect.GetHeight()*400)+500)/1000; 180cdf0e10cSrcweir aSymbolRect.Top()+=nBorderDistanceTop; 181cdf0e10cSrcweir // 15% distance to the bottom button border 182cdf0e10cSrcweir const long nBorderDistanceBottom = ((aSymbolRect.GetHeight()*150)+500)/1000; 183cdf0e10cSrcweir aSymbolRect.Bottom()-=nBorderDistanceBottom; 184cdf0e10cSrcweir DecorationView aDecoView( this ); 185cdf0e10cSrcweir aDecoView.DrawSymbol( aSymbolRect, SYMBOL_SPIN_DOWN, 186cdf0e10cSrcweir ( Application::GetSettings().GetStyleSettings().GetHighContrastMode() 187cdf0e10cSrcweir ? Color( COL_WHITE ) 188cdf0e10cSrcweir : Color( COL_BLACK ) ) ); 189cdf0e10cSrcweir } 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir void AnnotationMenuButton::KeyInput( const KeyEvent& rKeyEvt ) 193cdf0e10cSrcweir { 194cdf0e10cSrcweir const KeyCode& rKeyCode = rKeyEvt.GetKeyCode(); 195cdf0e10cSrcweir const sal_uInt16 nKey = rKeyCode.GetCode(); 196cdf0e10cSrcweir if ( nKey == KEY_TAB ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir mrSidebarWin.ActivatePostIt(); 199cdf0e10cSrcweir mrSidebarWin.GrabFocus(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir else 202cdf0e10cSrcweir { 203cdf0e10cSrcweir MenuButton::KeyInput( rKeyEvt ); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir } 206cdf0e10cSrcweir 207cdf0e10cSrcweir } } // end of namespace sw::annotation 208cdf0e10cSrcweir 209