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