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 : #include <vcl/settings.hxx>
33 :
34 : #include <cmdid.h>
35 : #include <SidebarWin.hxx>
36 :
37 : namespace sw { namespace annotation {
38 :
39 0 : Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color& aFront, const Color& aBack)
40 : {
41 0 : return Color(sal_uInt8(aFront.GetRed() * aTransparency / 255.0 + aBack.GetRed() * (1 - aTransparency / 255.0)),
42 0 : sal_uInt8(aFront.GetGreen() * aTransparency / 255.0 + aBack.GetGreen() * (1 - aTransparency / 255.0)),
43 0 : sal_uInt8(aFront.GetBlue() * aTransparency / 255.0 + aBack.GetBlue() * (1 - aTransparency / 255.0)));
44 : }
45 :
46 84 : AnnotationMenuButton::AnnotationMenuButton(sw::sidebarwindows::SwSidebarWin& rSidebarWin)
47 : : MenuButton(&rSidebarWin)
48 84 : , mrSidebarWin(rSidebarWin)
49 : {
50 84 : AddEventListener(LINK(&mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener));
51 :
52 84 : SetAccessibleName(SW_RES(STR_ACCESS_ANNOTATION_BUTTON_NAME));
53 84 : SetAccessibleDescription(SW_RES(STR_ACCESS_ANNOTATION_BUTTON_DESC));
54 84 : SetQuickHelpText(GetAccessibleDescription());
55 84 : }
56 :
57 252 : AnnotationMenuButton::~AnnotationMenuButton()
58 : {
59 84 : disposeOnce();
60 168 : }
61 :
62 84 : void AnnotationMenuButton::dispose()
63 : {
64 84 : RemoveEventListener(LINK(&mrSidebarWin, sw::sidebarwindows::SwSidebarWin, WindowEventListener));
65 84 : MenuButton::dispose();
66 84 : }
67 :
68 0 : void AnnotationMenuButton::Select()
69 : {
70 0 : mrSidebarWin.ExecuteCommand( GetCurItemId() );
71 0 : }
72 :
73 0 : void AnnotationMenuButton::MouseButtonDown( const MouseEvent& rMEvt )
74 : {
75 0 : PopupMenu* pButtonPopup(GetPopupMenu());
76 0 : if (mrSidebarWin.IsReadOnly())
77 : {
78 0 : pButtonPopup->EnableItem(FN_REPLY, false );
79 0 : pButtonPopup->EnableItem(FN_DELETE_COMMENT, false );
80 0 : pButtonPopup->EnableItem(FN_DELETE_NOTE_AUTHOR, false );
81 0 : pButtonPopup->EnableItem(FN_DELETE_ALL_NOTES, false );
82 0 : pButtonPopup->EnableItem(FN_FORMAT_ALL_NOTES, false );
83 : }
84 : else
85 : {
86 0 : pButtonPopup->EnableItem(FN_DELETE_COMMENT, !mrSidebarWin.IsProtected() );
87 0 : pButtonPopup->EnableItem(FN_DELETE_NOTE_AUTHOR, true );
88 0 : pButtonPopup->EnableItem(FN_DELETE_ALL_NOTES, true );
89 0 : pButtonPopup->EnableItem(FN_FORMAT_ALL_NOTES, true );
90 : }
91 :
92 0 : if (mrSidebarWin.IsProtected())
93 : {
94 0 : pButtonPopup->EnableItem(FN_REPLY, false);
95 : }
96 : else
97 : {
98 0 : SvtUserOptions aUserOpt;
99 0 : OUString sAuthor;
100 0 : if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
101 : {
102 0 : if ((sAuthor = aUserOpt.GetID()).isEmpty())
103 : {
104 0 : sAuthor = 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 0 : if (sAuthor == mrSidebarWin.GetAuthor())
109 : {
110 0 : pButtonPopup->EnableItem(FN_REPLY, false);
111 : }
112 : else
113 : {
114 0 : pButtonPopup->EnableItem(FN_REPLY, true);
115 0 : }
116 : }
117 :
118 0 : MenuButton::MouseButtonDown(rMEvt);
119 0 : }
120 :
121 0 : void AnnotationMenuButton::Paint(vcl::RenderContext& rRenderContext, const Rectangle& /*rRect*/)
122 : {
123 0 : bool bHighContrast = rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode();
124 :
125 0 : if (bHighContrast)
126 0 : rRenderContext.SetFillColor(COL_BLACK);
127 : else
128 0 : rRenderContext.SetFillColor(mrSidebarWin.ColorDark());
129 0 : rRenderContext.SetLineColor();
130 0 : const Rectangle aRect(Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel())));
131 0 : rRenderContext.DrawRect(aRect);
132 :
133 0 : if (bHighContrast)
134 : {
135 : //draw rect around button
136 0 : rRenderContext.SetFillColor(COL_BLACK);
137 0 : rRenderContext.SetLineColor(COL_WHITE);
138 : }
139 : else
140 : {
141 : //draw button
142 0 : Gradient aGradient;
143 0 : if (IsMouseOver())
144 0 : aGradient = Gradient(GradientStyle_LINEAR,
145 0 : ColorFromAlphaColor(80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark()),
146 0 : ColorFromAlphaColor(15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark()));
147 : else
148 0 : aGradient = Gradient(GradientStyle_LINEAR,
149 0 : ColorFromAlphaColor(15, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark()),
150 0 : ColorFromAlphaColor(80, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark()));
151 0 : rRenderContext.DrawGradient(aRect, aGradient);
152 :
153 : //draw rect around button
154 0 : rRenderContext.SetFillColor();
155 0 : rRenderContext.SetLineColor(ColorFromAlphaColor(90, mrSidebarWin.ColorAnchor(), mrSidebarWin.ColorDark()));
156 : }
157 0 : rRenderContext.DrawRect(aRect);
158 :
159 0 : if (mrSidebarWin.IsPreview())
160 : {
161 0 : vcl::Font aOldFont(mrSidebarWin.GetFont());
162 0 : vcl::Font aFont(aOldFont);
163 0 : Color aCol(COL_BLACK);
164 0 : aFont.SetColor(aCol);
165 0 : aFont.SetHeight(200);
166 0 : aFont.SetWeight(WEIGHT_MEDIUM);
167 0 : rRenderContext.SetFont(aFont);
168 0 : rRenderContext.DrawText(aRect, OUString("Edit Note"), DrawTextFlags::Center);
169 0 : rRenderContext.SetFont(aOldFont);
170 : }
171 : else
172 : {
173 0 : Rectangle aSymbolRect(aRect);
174 : // 25% distance to the left and right button border
175 0 : const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth() * 250) + 500) / 1000;
176 0 : aSymbolRect.Left() += nBorderDistanceLeftAndRight;
177 0 : aSymbolRect.Right() -= nBorderDistanceLeftAndRight;
178 : // 40% distance to the top button border
179 0 : const long nBorderDistanceTop = ((aSymbolRect.GetHeight() * 400) + 500) / 1000;
180 0 : aSymbolRect.Top()+=nBorderDistanceTop;
181 : // 15% distance to the bottom button border
182 0 : const long nBorderDistanceBottom = ((aSymbolRect.GetHeight() * 150) + 500) / 1000;
183 0 : aSymbolRect.Bottom() -= nBorderDistanceBottom;
184 0 : DecorationView aDecoView(&rRenderContext);
185 0 : aDecoView.DrawSymbol(aSymbolRect, SymbolType::SPIN_DOWN, (bHighContrast ? Color(COL_WHITE) : Color(COL_BLACK)));
186 : }
187 0 : }
188 :
189 0 : void AnnotationMenuButton::KeyInput(const KeyEvent& rKeyEvt)
190 : {
191 0 : const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
192 0 : if (rKeyCode.GetCode() == KEY_TAB)
193 : {
194 0 : mrSidebarWin.ActivatePostIt();
195 0 : mrSidebarWin.GrabFocus();
196 : }
197 : else
198 : {
199 0 : MenuButton::KeyInput(rKeyEvt);
200 : }
201 0 : }
202 :
203 177 : }} // end of namespace sw::annotation
204 :
205 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|