Coverage Report

Created: 2026-11-06 11:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svtools/source/brwbox/editbrowsebox2.cxx
Line
Count
Source
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 <svtools/editbrowsebox.hxx>
21
#include <com/sun/star/accessibility/XAccessible.hpp>
22
#include <com/sun/star/accessibility/AccessibleEventId.hpp>
23
#include <comphelper/types.hxx>
24
#include <svtools/strings.hrc>
25
#include <svtools/svtresid.hxx>
26
#include <toolkit/helper/vclunohelper.hxx>
27
#include <vcl/accessibility/AccessibleBrowseBoxCheckBoxCell.hxx>
28
#include <vcl/svapp.hxx>
29
#include <vcl/weld/Builder.hxx>
30
#include <tools/debug.hxx>
31
#include <comphelper/diagnose_ex.hxx>
32
33
namespace svt
34
{
35
    using namespace com::sun::star::accessibility;
36
    using namespace com::sun::star::uno;
37
    using namespace ::com::sun::star::accessibility::AccessibleEventId;
38
39
rtl::Reference<comphelper::OAccessible>
40
EditBrowseBox::CreateAccessibleCheckBoxCell(sal_Int32 _nRow, sal_uInt16 _nColumnPos,
41
                                            const TriState& eState)
42
0
{
43
0
    rtl::Reference<comphelper::OAccessible> pAccessible = GetAccessible();
44
0
    if (!pAccessible.is())
45
0
        return {};
46
47
0
    return new AccessibleCheckBoxCell(pAccessible->getAccessibleChild(::vcl::BBINDEX_TABLE),
48
0
                                      *this, _nRow, _nColumnPos, eState, true);
49
0
}
50
51
sal_Int32 EditBrowseBox::GetAccessibleControlCount() const
52
0
{
53
0
    return IsEditing() ? 1 : 0;
54
0
}
55
56
void EditBrowseBox::implCreateActiveAccessible( )
57
0
{
58
0
    DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
59
0
    DBG_ASSERT(!m_pActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called "
60
0
                                    "if the old one is still alive!");
61
62
0
    if (m_pActiveCell.is() || !IsEditing())
63
0
        return;
64
65
0
    ControlBase& rControl = aController->GetWindow();
66
67
    // set accessible name based on current cell (which is the one that is being edited)
68
0
    const sal_uInt16 nCol = GetColumnPos(GetCurColumnId());
69
0
    const sal_Int32 nRow = GetCurRow();
70
0
    OUString sAccName
71
0
        = SvtResId(STR_ACC_COLUMN_NUM).replaceAll("%COLUMNNUMBER", OUString::number(nCol - 1))
72
0
          + ", " + SvtResId(STR_ACC_ROW_NUM).replaceAll("%ROWNUMBER", OUString::number(nRow));
73
0
    rControl.SetAccessibleName(sAccName);
74
75
0
    m_pActiveCell = rControl.GetAccessible();
76
77
0
    commitBrowseBoxEvent(CHILD, Any(css::uno::Reference<XAccessible>(m_pActiveCell)), Any());
78
0
}
79
80
rtl::Reference<comphelper::OAccessible> EditBrowseBox::CreateAccessibleControl(sal_Int32 _nIndex)
81
0
{
82
0
    DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
83
84
0
    if ( isAccessibleAlive() )
85
0
    {
86
0
        if (!m_pActiveCell.is())
87
0
            implCreateActiveAccessible();
88
0
    }
89
90
0
    return m_pActiveCell;
91
0
}
92
93
void EditBrowseBox::GrabTableFocus()
94
0
{
95
0
    if ( aController.is() )
96
0
        aController->GetWindow().GrabFocus();
97
0
}
98
99
void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags )
100
0
{
101
0
    bool bFocus = ControlHasFocus();
102
0
    for (vcl::Window* pWindow = Application::GetFocusWindow();
103
0
         pWindow && !bFocus;
104
0
         pWindow = pWindow->GetParent())
105
0
         bFocus = pWindow == this;
106
107
0
    if (bFocus == bHasFocus)
108
0
        return;
109
110
0
    bHasFocus = bFocus;
111
112
0
    if ( !(GetBrowserFlags( ) & EditBrowseBoxFlags::SMART_TAB_TRAVEL) )
113
0
        return;
114
115
0
    if  (   !(bHasFocus                           // we got the focus
116
0
        &&  ( _nGetFocusFlags & GetFocusFlags::Tab ))  // using the TAB key
117
0
        )
118
0
        return;
119
120
0
    sal_Int32 nRows = GetRowCount();
121
0
    sal_uInt16 nCols = ColCount();
122
123
0
    if (( nRows <= 0 ) || ( nCols <= 0 ))
124
0
        return;
125
126
0
    if ( _nGetFocusFlags & GetFocusFlags::Forward )
127
0
    {
128
0
        if ( GetColumnId( 0 ) != HandleColumnId )
129
0
        {
130
0
            GoToRowColumnId( 0, GetColumnId( 0 ) );
131
0
        }
132
0
        else
133
0
        {   // the first column is the handle column -> not focussable
134
0
            if ( nCols > 1 )
135
0
                GoToRowColumnId( 0, GetColumnId( 1 ) );
136
0
        }
137
0
    }
138
0
    else if ( _nGetFocusFlags & GetFocusFlags::Backward )
139
0
    {
140
0
        GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
141
0
    }
142
0
}
143
144
tools::Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
145
0
{
146
0
    tools::Rectangle aRect;
147
0
    if ( SeekRow(_nRow) )
148
0
    {
149
0
        CellController* pController = GetController(
150
0
            _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
151
0
        if ( pController )
152
0
            aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
153
0
    }
154
0
    return aRect;
155
0
}
156
157
sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
158
0
{
159
0
    sal_Int32 nRet = -1;
160
0
    if ( SeekRow(_nRow) )
161
0
    {
162
0
        CellController* pController = GetController(
163
0
            _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
164
0
        if ( pController )
165
0
            nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
166
0
    }
167
0
    return nRet;
168
0
}
169
170
171
} // namespace svt
172
173
174
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */