LibreOffice Module sw (master)  1
AnnotationMenuButton.cxx
Go to the documentation of this file.
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 <strings.hrc>
23 
24 #include <unotools/useroptions.hxx>
25 
26 #include <vcl/menu.hxx>
27 #include <vcl/decoview.hxx>
28 #include <vcl/gradient.hxx>
29 #include <vcl/settings.hxx>
30 #include <vcl/event.hxx>
31 
32 #include <cmdid.h>
33 #include <AnnotationWin.hxx>
34 #include <swtypes.hxx>
35 
36 namespace sw::annotation {
37 
38 static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color& aFront, const Color& aBack)
39 {
40  return Color(sal_uInt8(aFront.GetRed() * aTransparency / 255.0 + aBack.GetRed() * (1 - aTransparency / 255.0)),
41  sal_uInt8(aFront.GetGreen() * aTransparency / 255.0 + aBack.GetGreen() * (1 - aTransparency / 255.0)),
42  sal_uInt8(aFront.GetBlue() * aTransparency / 255.0 + aBack.GetBlue() * (1 - aTransparency / 255.0)));
43 }
44 
46  : MenuButton(&rSidebarWin)
47  , mrSidebarWin(rSidebarWin)
48 {
50 
51  SetAccessibleName(SwResId(STR_ACCESS_ANNOTATION_BUTTON_NAME));
52  SetAccessibleDescription(SwResId(STR_ACCESS_ANNOTATION_BUTTON_DESC));
54 }
55 
57 {
58  disposeOnce();
59 }
60 
62 {
65 }
66 
68 {
69  OString sIdent = GetCurItemIdent();
70  if (sIdent.isEmpty())
71  return;
72 
73  // tdf#136682 ensure this is the currently active sidebar win so the command
74  // operates in an active sidebar context
75  bool bSwitchedFocus = mrSidebarWin.SetActiveSidebarWin();
76 
77  if (sIdent == "reply")
79  if (sIdent == "resolve" || sIdent == "unresolve")
81  else if (sIdent == "resolvethread" || sIdent == "unresolvethread")
83  else if (sIdent == "delete")
85  else if (sIdent == "deletethread")
87  else if (sIdent == "deleteby")
89  else if (sIdent == "deleteall")
91  else if (sIdent == "formatall")
93 
94  if (bSwitchedFocus)
97 }
98 
100 {
101  PopupMenu* pButtonPopup(GetPopupMenu());
102  if (mrSidebarWin.IsReadOnly())
103  {
104  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
105  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), false);
106  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), false);
107  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolvethread"), false);
108  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolvethread"), false);
109  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), false );
110  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deletethread"), false );
111  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"), false );
112  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"), false );
113  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"), false );
114  }
115  else
116  {
117  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), !mrSidebarWin.IsResolved());
118  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), mrSidebarWin.IsResolved());
119  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolvethread"), !mrSidebarWin.IsThreadResolved());
120  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolvethread"), mrSidebarWin.IsThreadResolved());
121  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), !mrSidebarWin.IsProtected());
122  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deletethread"));
123  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"));
124  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"));
125  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"));
126  }
127 
129  {
130  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
131  }
132  else
133  {
134  SvtUserOptions aUserOpt;
135  OUString sAuthor;
136  if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
137  {
138  if ((sAuthor = aUserOpt.GetID()).isEmpty())
139  {
140  sAuthor = SwResId(STR_REDLINE_UNKNOWN_AUTHOR);
141  }
142  }
143  // do not allow to reply to ourself and no answer possible if this note is in a protected section
144  if (sAuthor == mrSidebarWin.GetAuthor())
145  {
146  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
147  }
148  else
149  {
150  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"));
151  }
152  }
153 
155 }
156 
157 void AnnotationMenuButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
158 {
159  bool bHighContrast = rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode();
160 
161  if (bHighContrast)
162  rRenderContext.SetFillColor(COL_BLACK);
163  else
164  rRenderContext.SetFillColor(mrSidebarWin.ColorDark());
165  rRenderContext.SetLineColor();
166  const tools::Rectangle aRect(tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel())));
167  rRenderContext.DrawRect(aRect);
168 
169  if (bHighContrast)
170  {
171  //draw rect around button
172  rRenderContext.SetFillColor(COL_BLACK);
173  rRenderContext.SetLineColor(COL_WHITE);
174  }
175  else
176  {
177  //draw button
178  Gradient aGradient;
179  if (IsMouseOver())
180  aGradient = Gradient(GradientStyle::Linear,
183  else
184  aGradient = Gradient(GradientStyle::Linear,
187  rRenderContext.DrawGradient(aRect, aGradient);
188 
189  //draw rect around button
190  rRenderContext.SetFillColor();
192  }
193  rRenderContext.DrawRect(aRect);
194 
195  tools::Rectangle aSymbolRect(aRect);
196  // 25% distance to the left and right button border
197  const tools::Long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth() * 250) + 500) / 1000;
198  aSymbolRect.AdjustLeft(nBorderDistanceLeftAndRight );
199  aSymbolRect.AdjustRight( -nBorderDistanceLeftAndRight );
200  // 40% distance to the top button border
201  const tools::Long nBorderDistanceTop = ((aSymbolRect.GetHeight() * 400) + 500) / 1000;
202  aSymbolRect.AdjustTop(nBorderDistanceTop );
203  // 15% distance to the bottom button border
204  const tools::Long nBorderDistanceBottom = ((aSymbolRect.GetHeight() * 150) + 500) / 1000;
205  aSymbolRect.AdjustBottom( -nBorderDistanceBottom );
206  DecorationView aDecoView(&rRenderContext);
207  aDecoView.DrawSymbol(aSymbolRect, SymbolType::SPIN_DOWN, (bHighContrast ? COL_WHITE : COL_BLACK));
208 }
209 
211 {
212  const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
213  if (rKeyCode.GetCode() == KEY_TAB)
214  {
217  }
218  else
219  {
220  MenuButton::KeyInput(rKeyEvt);
221  }
222 }
223 
224 } // end of namespace sw::annotation
225 
226 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt8 GetRed() const
tools::Long AdjustRight(tools::Long nHorzMoveDelta)
long Long
const StyleSettings & GetStyleSettings() const
virtual void dispose() override
void SetAccessibleName(const OUString &rName)
virtual Size GetSizePixel() const
sal_uInt16 GetCode() const
tools::Long GetWidth() const
OUString GetAccessibleDescription() const
AnnotationMenuButton(sw::annotation::SwAnnotationWin &rSidebarWin)
virtual void KeyInput(const KeyEvent &rKEvt) override
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect) override
void SetQuickHelpText(const OUString &rHelpText)
#define FN_FORMAT_ALL_NOTES
Definition: cmdid.h:754
void ExecuteCommand(sal_uInt16 nSlot)
bool GetHighContrastMode() const
#define FN_DELETE_COMMENT
Definition: cmdid.h:752
tools::Long AdjustBottom(tools::Long nVertMoveDelta)
sal_uInt8 GetBlue() const
void DrawRect(const tools::Rectangle &rRect)
#define FN_RESOLVE_NOTE
Definition: cmdid.h:755
#define FN_REPLY
Definition: cmdid.h:753
void SetLineColor()
sw::annotation::SwAnnotationWin & mrSidebarWin
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
PopupMenu * GetPopupMenu() const
OString const & GetCurItemIdent() const
#define FN_DELETE_NOTE_AUTHOR
Definition: cmdid.h:746
sal_uInt16 GetItemId(sal_uInt16 nPos) const
void SetFillColor()
void GrabFocusToDocument()
#define FN_DELETE_COMMENT_THREAD
Definition: cmdid.h:757
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
OUString GetID() const
void GrabFocus()
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
tools::Long AdjustTop(tools::Long nVertMoveDelta)
Point PixelToLogic(const Point &rDevicePt) const
sal_uInt8 GetGreen() const
void AddEventListener(const Link< VclWindowEvent &, void > &rEventListener)
const vcl::KeyCode & GetKeyCode() const
bool IsMouseOver() const
virtual void MouseButtonDown(const MouseEvent &rMEvt) override
virtual void KeyInput(const KeyEvent &rKeyEvt) override
unsigned char sal_uInt8
void SetAccessibleDescription(const OUString &rDescr)
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_WHITE
const ::std::vector< Color > ImpSvNumberformatScan::StandardColor COL_BLACK
tools::Long GetHeight() const
OUString GetFullName() const
tools::Long AdjustLeft(tools::Long nHorzMoveDelta)
void RemoveEventListener(const Link< VclWindowEvent &, void > &rEventListener)
void DrawSymbol(const tools::Rectangle &rRect, SymbolType eType, const Color &rColor, DrawSymbolFlags nStyle=DrawSymbolFlags::NONE)
void DrawGradient(const tools::Rectangle &rRect, const Gradient &rGradient)
constexpr sal_uInt16 KEY_TAB
#define FN_RESOLVE_NOTE_THREAD
Definition: cmdid.h:756
static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color &aFront, const Color &aBack)
#define FN_DELETE_ALL_NOTES
Definition: cmdid.h:747