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