summaryrefslogtreecommitdiff
path: root/sw/source/uibase/utlui/AccessibilityStatusBarControl.cxx
blob: 100313f709b1b08f0ddf204ff45101b85d0a7e34 (plain)
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
/* -*- 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/.
 */

#include <swtypes.hxx>
#include <strings.hrc>
#include <AccessibilityStatusBarControl.hxx>
#include <svl/intitem.hxx>
#include <vcl/status.hxx>
#include <vcl/event.hxx>

SFX_IMPL_STATUSBAR_CONTROL(sw::AccessibilityStatusBarControl, SfxInt32Item);

namespace sw
{
AccessibilityStatusBarControl::AccessibilityStatusBarControl(sal_uInt16 _nSlotId, sal_uInt16 _nId,
                                                             StatusBar& rStb)
    : SfxStatusBarControl(_nSlotId, _nId, rStb)
    , mnIssues(0)
{
}

AccessibilityStatusBarControl::~AccessibilityStatusBarControl() = default;

void AccessibilityStatusBarControl::StateChangedAtStatusBarControl(sal_uInt16 /*nSID*/,
                                                                   SfxItemState eState,
                                                                   const SfxPoolItem* pState)
{
    if (eState != SfxItemState::DEFAULT)
    {
        mnIssues = -1;
    }
    else if (auto pItem = dynamic_cast<const SfxInt32Item*>(pState))
    {
        mnIssues = pItem->GetValue();
    }
    else
    {
        mnIssues = -1;
    }

    GetStatusBar().SetItemData(GetId(), nullptr); // necessary ?
    GetStatusBar().SetItemText(GetId(), ""); // necessary ?

    if (eState == SfxItemState::DEFAULT) // Can access pState
    {
        GetStatusBar().SetQuickHelpText(GetId(), SwResId(STR_ACCESSIBILITY_CHECK_HINT));
    }
    else
    {
        GetStatusBar().SetQuickHelpText(GetId(), u"");
    }
}

void AccessibilityStatusBarControl::Paint(const UserDrawEvent& rUserEvent)
{
    vcl::RenderContext* pRenderContext = rUserEvent.GetRenderContext();

    tools::Rectangle aRect = rUserEvent.GetRect();
    Color aOldLineColor = pRenderContext->GetLineColor();
    Color aOldFillColor = pRenderContext->GetFillColor();

    if (mnIssues > 0)
        pRenderContext->SetFillColor(COL_RED);
    else
        pRenderContext->SetFillColor(COL_GREEN);

    pRenderContext->DrawRect(aRect);

    pRenderContext->SetLineColor(aOldLineColor);
    pRenderContext->SetFillColor(aOldFillColor);
}

} // end sw

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */