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