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 <app.hrc>
23 #include <strings.hrc>
24 
25 #include <unotools/useroptions.hxx>
26 
27 #include <vcl/svapp.hxx>
28 #include <vcl/menu.hxx>
29 #include <vcl/decoview.hxx>
30 #include <vcl/gradient.hxx>
31 #include <vcl/settings.hxx>
32 #include <vcl/event.hxx>
33 
34 #include <cmdid.h>
35 #include <AnnotationWin.hxx>
36 #include <swtypes.hxx>
37 
38 namespace sw { namespace annotation {
39 
40 static Color ColorFromAlphaColor(const sal_uInt8 aTransparency, const Color& aFront, const Color& aBack)
41 {
42  return Color(sal_uInt8(aFront.GetRed() * aTransparency / 255.0 + aBack.GetRed() * (1 - aTransparency / 255.0)),
43  sal_uInt8(aFront.GetGreen() * aTransparency / 255.0 + aBack.GetGreen() * (1 - aTransparency / 255.0)),
44  sal_uInt8(aFront.GetBlue() * aTransparency / 255.0 + aBack.GetBlue() * (1 - aTransparency / 255.0)));
45 }
46 
48  : MenuButton(&rSidebarWin)
49  , mrSidebarWin(rSidebarWin)
50 {
52 
53  SetAccessibleName(SwResId(STR_ACCESS_ANNOTATION_BUTTON_NAME));
54  SetAccessibleDescription(SwResId(STR_ACCESS_ANNOTATION_BUTTON_DESC));
56 }
57 
59 {
60  disposeOnce();
61 }
62 
64 {
67 }
68 
70 {
71  OString sIdent = GetCurItemIdent();
72  if (sIdent == "reply")
74  if (sIdent == "resolve" || sIdent == "unresolve")
76  else if (sIdent == "delete")
78  else if (sIdent == "deleteby")
80  else if (sIdent == "deleteall")
82  else if (sIdent == "formatall")
84 }
85 
87 {
88  PopupMenu* pButtonPopup(GetPopupMenu());
90  {
91  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
92  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), false);
93  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), false);
94  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), false );
95  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"), false );
96  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"), false );
97  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"), false );
98  }
99  else
100  {
101  pButtonPopup->EnableItem(pButtonPopup->GetItemId("resolve"), !mrSidebarWin.IsResolved());
102  pButtonPopup->EnableItem(pButtonPopup->GetItemId("unresolve"), mrSidebarWin.IsResolved());
103  pButtonPopup->EnableItem(pButtonPopup->GetItemId("delete"), !mrSidebarWin.IsProtected());
104  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteby"));
105  pButtonPopup->EnableItem(pButtonPopup->GetItemId("deleteall"));
106  pButtonPopup->EnableItem(pButtonPopup->GetItemId("formatall"));
107  }
108 
110  {
111  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
112  }
113  else
114  {
115  SvtUserOptions aUserOpt;
116  OUString sAuthor;
117  if ((sAuthor = aUserOpt.GetFullName()).isEmpty())
118  {
119  if ((sAuthor = aUserOpt.GetID()).isEmpty())
120  {
121  sAuthor = SwResId(STR_REDLINE_UNKNOWN_AUTHOR);
122  }
123  }
124  // do not allow to reply to ourself and no answer possible if this note is in a protected section
125  if (sAuthor == mrSidebarWin.GetAuthor())
126  {
127  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"), false);
128  }
129  else
130  {
131  pButtonPopup->EnableItem(pButtonPopup->GetItemId("reply"));
132  }
133  }
134 
136 }
137 
138 void AnnotationMenuButton::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle& /*rRect*/)
139 {
140  bool bHighContrast = rRenderContext.GetSettings().GetStyleSettings().GetHighContrastMode();
141 
142  if (bHighContrast)
143  rRenderContext.SetFillColor(COL_BLACK);
144  else
145  rRenderContext.SetFillColor(mrSidebarWin.ColorDark());
146  rRenderContext.SetLineColor();
147  const tools::Rectangle aRect(tools::Rectangle(Point(0, 0), rRenderContext.PixelToLogic(GetSizePixel())));
148  rRenderContext.DrawRect(aRect);
149 
150  if (bHighContrast)
151  {
152  //draw rect around button
153  rRenderContext.SetFillColor(COL_BLACK);
154  rRenderContext.SetLineColor(COL_WHITE);
155  }
156  else
157  {
158  //draw button
159  Gradient aGradient;
160  if (IsMouseOver())
161  aGradient = Gradient(GradientStyle::Linear,
164  else
165  aGradient = Gradient(GradientStyle::Linear,
168  rRenderContext.DrawGradient(aRect, aGradient);
169 
170  //draw rect around button
171  rRenderContext.SetFillColor();
173  }
174  rRenderContext.DrawRect(aRect);
175 
176  tools::Rectangle aSymbolRect(aRect);
177  // 25% distance to the left and right button border
178  const long nBorderDistanceLeftAndRight = ((aSymbolRect.GetWidth() * 250) + 500) / 1000;
179  aSymbolRect.AdjustLeft(nBorderDistanceLeftAndRight );
180  aSymbolRect.AdjustRight( -nBorderDistanceLeftAndRight );
181  // 40% distance to the top button border
182  const long nBorderDistanceTop = ((aSymbolRect.GetHeight() * 400) + 500) / 1000;
183  aSymbolRect.AdjustTop(nBorderDistanceTop );
184  // 15% distance to the bottom button border
185  const long nBorderDistanceBottom = ((aSymbolRect.GetHeight() * 150) + 500) / 1000;
186  aSymbolRect.AdjustBottom( -nBorderDistanceBottom );
187  DecorationView aDecoView(&rRenderContext);
188  aDecoView.DrawSymbol(aSymbolRect, SymbolType::SPIN_DOWN, (bHighContrast ? COL_WHITE : COL_BLACK));
189 }
190 
192 {
193  const vcl::KeyCode& rKeyCode = rKeyEvt.GetKeyCode();
194  if (rKeyCode.GetCode() == KEY_TAB)
195  {
198  }
199  else
200  {
201  MenuButton::KeyInput(rKeyEvt);
202  }
203 }
204 
205 }} // end of namespace sw::annotation
206 
207 /* 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)
Dialog to specify the properties of date form field.
Definition: accfrmobj.cxx:40
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:731
void ExecuteCommand(sal_uInt16 nSlot)
bool GetHighContrastMode() const
#define FN_DELETE_COMMENT
Definition: cmdid.h:729
sal_uInt8 GetBlue() const
void DrawRect(const tools::Rectangle &rRect)
#define FN_RESOLVE_NOTE
Definition: cmdid.h:732
#define FN_REPLY
Definition: cmdid.h:730
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:723
sal_uInt16 GetItemId(sal_uInt16 nPos) const
void SetFillColor()
const AllSettings & GetSettings() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
OUString GetID() const
void GrabFocus()
bool IsMouseOver()
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
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:724