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 == "reply")
72  if (sIdent == "resolve" || sIdent == "unresolve")
74  else if (sIdent == "delete")
76  else if (sIdent == "deleteby")
78  else if (sIdent == "deleteall")
80  else if (sIdent == "formatall")
82 }
83 
85 {
86  PopupMenu* pButtonPopup(GetPopupMenu());
88  {
89  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
90  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), false);
91  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), false);
92  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), false );
93  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"), false );
94  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"), false );
95  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"), false );
96  }
97  else
98  {
99  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), !mrSidebarWin.IsResolved());
100  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), mrSidebarWin.IsResolved());
101  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), !mrSidebarWin.IsProtected());
102  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"));
103  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"));
104  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"));
105  }
106 
108  {
109  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
110  }
111  else
112  {
113  SvtUserOptions aUserOpt;
114  OUString sAuthor;
115  if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
116  {
117  if ((sAuthor = aUserOpt.GetID()).isEmpty())
118  {
119  sAuthor = SwResId(STR_REDLINE_UNKNOWN_AUTHOR);
120  }
121  }
122  // do not allow to reply to ourself and no answer possible if this note is in a protected section
123  if (sAuthor == mrSidebarWin.GetAuthor())
124  {
125  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
126  }
127  else
128  {
129  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"));
130  }
131  }
132 
134 }
135 
136 void AnnotationMenuButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
137 {
138  bool bHighContrast = rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode();
139 
140  if (bHighContrast)
141  rRenderContext.SetFillColor(COL_BLACK);
142  else
143  rRenderContext.SetFillColor(mrSidebarWin.ColorDark());
144  rRenderContext.SetLineColor();
145  const tools::Rectangle aRect(tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel())));
146  rRenderContext.DrawRect(aRect);
147 
148  if (bHighContrast)
149  {
150  //draw rect around button
151  rRenderContext.SetFillColor(COL_BLACK);
152  rRenderContext.SetLineColor(COL_WHITE);
153  }
154  else
155  {
156  //draw button
157  Gradient aGradient;
158  if (IsMouseOver())
159  aGradient = Gradient(GradientStyle::Linear,
162  else
163  aGradient = Gradient(GradientStyle::Linear,
166  rRenderContext.DrawGradient(aRect, aGradient);
167 
168  //draw rect around button
169  rRenderContext.SetFillColor();
171  }
172  rRenderContext.DrawRect(aRect);
173 
174  tools::Rectangle aSymbolRect(aRect);
175  // 25% distance to the left and right button border
176  const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth() * 250) + 500) / 1000;
177  aSymbolRect.AdjustLeft(nBorderDistanceLeftAndRight );
178  aSymbolRect.AdjustRight( -nBorderDistanceLeftAndRight );
179  // 40% distance to the top button border
180  const long nBorderDistanceTop = ((aSymbolRect.GetHeight() * 400) + 500) / 1000;
181  aSymbolRect.AdjustTop(nBorderDistanceTop );
182  // 15% distance to the bottom button border
183  const long nBorderDistanceBottom = ((aSymbolRect.GetHeight() * 150) + 500) / 1000;
184  aSymbolRect.AdjustBottom( -nBorderDistanceBottom );
185  DecorationView aDecoView(&rRenderContext);
186  aDecoView.DrawSymbol(aSymbolRect, SymbolType::SPIN_DOWN, (bHighContrast ? COL_WHITE : COL_BLACK));
187 }
188 
190 {
191  const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
192  if (rKeyCode.GetCode() == KEY_TAB)
193  {
196  }
197  else
198  {
199  MenuButton::KeyInput(rKeyEvt);
200  }
201 }
202 
203 } // end of namespace sw::annotation
204 
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
long GetWidth() const
long GetHeight() const
constexpr::Color COL_BLACK(0x00, 0x00, 0x00)
sal_uInt8 GetRed() const
#define KEY_TAB
long AdjustLeft(long nHorzMoveDelta)
const StyleSettings & GetStyleSettings() const
virtual void dispose() override
void SetAccessibleName(const OUString &rName)
virtual Size GetSizePixel() const
sal_uInt16 GetCode() 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)
long AdjustBottom(long nVertMoveDelta)
#define FN_FORMAT_ALL_NOTES
Definition: cmdid.h:743
void ExecuteCommand(sal_uInt16 nSlot)
bool GetHighContrastMode() const
#define FN_DELETE_COMMENT
Definition: cmdid.h:741
sal_uInt8 GetBlue() const
void DrawRect(const tools::Rectangle &rRect)
#define FN_RESOLVE_NOTE
Definition: cmdid.h:744
#define FN_REPLY
Definition: cmdid.h:742
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:735
sal_uInt16 GetItemId(sal_uInt16 nPos) const
void SetFillColor()
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:178
OUString GetID() const
void GrabFocus()
void EnableItem(sal_uInt16 nItemId, bool bEnable=true)
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
long AdjustRight(long nHorzMoveDelta)
unsigned char sal_uInt8
void SetAccessibleDescription(const OUString &rDescr)
long AdjustTop(long nVertMoveDelta)
constexpr::Color COL_WHITE(0xFF, 0xFF, 0xFF)
OUString GetFullName() const
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)
static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color &aFront, const Color &aBack)
#define FN_DELETE_ALL_NOTES
Definition: cmdid.h:736