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