LibreOffice Module svtools (master) 1
editbrowsebox2.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
21#include <com/sun/star/accessibility/XAccessible.hpp>
22#include <com/sun/star/accessibility/AccessibleEventId.hpp>
23#include "editbrowseboximpl.hxx"
24#include <comphelper/types.hxx>
27#include <vcl/svapp.hxx>
28#include <tools/debug.hxx>
30
31namespace svt
32{
33 using namespace com::sun::star::accessibility;
34 using namespace com::sun::star::uno;
35 using namespace ::com::sun::star::accessibility::AccessibleEventId;
36
37
38Reference< XAccessible > EditBrowseBox::CreateAccessibleCheckBoxCell(sal_Int32 _nRow, sal_uInt16 _nColumnPos,const TriState& eState)
39{
42 if ( xAccessible.is() )
43 xAccContext = xAccessible->getAccessibleContext();
44
46 if ( xAccContext.is() )
47 {
49 xAccContext->getAccessibleChild( ::vcl::BBINDEX_TABLE ),
50 *this,
51 nullptr,
52 _nRow,
53 _nColumnPos,
54 eState,
55 true
56 );
57 }
58 return xReturn;
59}
60
62{
63 return IsEditing() ? 1 : 0;
64}
65
67{
68 DBG_ASSERT( IsEditing(), "EditBrowseBox::implCreateActiveAccessible: not to be called if we're not editing currently!" );
69 DBG_ASSERT( !m_aImpl->m_xActiveCell.is(), "EditBrowseBox::implCreateActiveAccessible: not to be called if the old one is still alive!" );
70
71 if ( m_aImpl->m_xActiveCell.is() || !IsEditing() )
72 return;
73
74 Reference< XAccessible > xCont = aController->GetWindow().GetAccessible();
76 if ( !(xMy.is() && xCont.is()) )
77 return;
78
80 xMy, // parent accessible
81 xCont, // control accessible
82 VCLUnoHelper::GetInterface( &aController->GetWindow() ), // focus window (for notifications)
83 *this, // the browse box
84 GetCurRow(),
86 );
87
88 commitBrowseBoxEvent( CHILD, Any( m_aImpl->m_xActiveCell ), Any() );
89}
90
91
93{
94 DBG_ASSERT( 0 == _nIndex, "EditBrowseBox::CreateAccessibleControl: invalid index!" );
95
96 if ( isAccessibleAlive() )
97 {
98 if ( !m_aImpl->m_xActiveCell.is() )
100 }
101
102 return m_aImpl->m_xActiveCell;
103}
104
106{
107 try
108 {
109 ::comphelper::disposeComponent(m_xActiveCell);
110 }
111 catch(const Exception&)
112 {
113 TOOLS_WARN_EXCEPTION( "svtools", "EditBrowseBoxImpl::clearActiveCell: caught an exception while disposing the AccessibleCell!" );
114 }
115
116 m_xActiveCell = nullptr;
117}
118
120{
121 if ( aController.is() )
122 aController->GetWindow().GrabFocus();
123}
124
125void EditBrowseBox::DetermineFocus( const GetFocusFlags _nGetFocusFlags )
126{
127 bool bFocus = ControlHasFocus();
129 pWindow && !bFocus;
130 pWindow = pWindow->GetParent())
131 bFocus = pWindow == this;
132
133 if (bFocus == bHasFocus)
134 return;
135
136 bHasFocus = bFocus;
137
139 return;
140
141 if ( !(bHasFocus // we got the focus
142 && ( _nGetFocusFlags & GetFocusFlags::Tab )) // using the TAB key
143 )
144 return;
145
146 sal_Int32 nRows = GetRowCount();
147 sal_uInt16 nCols = ColCount();
148
149 if (( nRows <= 0 ) || ( nCols <= 0 ))
150 return;
151
152 if ( _nGetFocusFlags & GetFocusFlags::Forward )
153 {
154 if ( GetColumnId( 0 ) != HandleColumnId )
155 {
156 GoToRowColumnId( 0, GetColumnId( 0 ) );
157 }
158 else
159 { // the first column is the handle column -> not focussable
160 if ( nCols > 1 )
161 GoToRowColumnId( 0, GetColumnId( 1 ) );
162 }
163 }
164 else if ( _nGetFocusFlags & GetFocusFlags::Backward )
165 {
166 GoToRowColumnId( nRows - 1, GetColumnId( nCols -1 ) );
167 }
168}
169
170tools::Rectangle EditBrowseBox::GetFieldCharacterBounds(sal_Int32 _nRow,sal_Int32 _nColumnPos,sal_Int32 _nIndex)
171{
172 tools::Rectangle aRect;
173 if ( SeekRow(_nRow) )
174 {
175 CellController* pController = GetController(
176 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
177 if ( pController )
178 aRect = pController->GetWindow().GetCharacterBounds(_nIndex);
179 }
180 return aRect;
181}
182
183sal_Int32 EditBrowseBox::GetFieldIndexAtPoint(sal_Int32 _nRow,sal_Int32 _nColumnPos,const Point& _rPoint)
184{
185 sal_Int32 nRet = -1;
186 if ( SeekRow(_nRow) )
187 {
188 CellController* pController = GetController(
189 _nRow, GetColumnId( sal::static_int_cast< sal_uInt16 >(_nColumnPos) ) );
190 if ( pController )
191 nRet = pController->GetWindow().GetIndexForPoint(_rPoint);
192 }
193 return nRet;
194}
195
196
197} // namespace svt
198
199
200/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static vcl::Window * GetFocusWindow()
sal_uInt16 GetColumnId(sal_uInt16 nPos) const
Definition: brwbox2.cxx:379
::vcl::IAccessibleFactory & getAccessibleFactory()
retrieves the XAccessible implementation associated with the BrowseBox instance
Definition: brwbox3.cxx:423
virtual css::uno::Reference< css::accessibility::XAccessible > GetAccessible() override
Definition: brwbox3.cxx:549
sal_Int32 GetCurRow() const
Definition: brwbox.hxx:544
sal_uInt16 ColCount() const
Definition: brwbox1.cxx:849
bool GoToRowColumnId(sal_Int32 nRow, sal_uInt16 nColId)
Definition: brwbox1.cxx:1584
sal_uInt16 GetColumnPos(sal_uInt16 nColumnId) const
Definition: brwbox2.cxx:388
static const sal_uInt16 HandleColumnId
Definition: brwbox.hxx:267
sal_uInt16 GetCurColumnId() const
Definition: brwbox.hxx:545
virtual sal_Int32 GetRowCount() const override
Definition: brwbox1.cxx:844
bool isAccessibleAlive() const
return <TRUE> if and only if the accessible object for this instance has been created and is alive
Definition: brwbox3.cxx:428
void commitBrowseBoxEvent(sal_Int16 nEventId, const css::uno::Any &rNewValue, const css::uno::Any &rOldValue)
commitBrowseBoxEvent commit the event at all listeners of the browsebox
Definition: brwbox3.cxx:417
tools::Long GetIndexForPoint(const Point &rPoint) const
tools::Rectangle GetCharacterBounds(tools::Long nIndex) const
static css::uno::Reference< css::awt::XWindow > GetInterface(vcl::Window *pWindow)
ControlBase & GetWindow() const
css::uno::Reference< css::accessibility::XAccessible > m_xActiveCell
virtual CellController * GetController(sal_Int32 nRow, sal_uInt16 nCol)
css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleCheckBoxCell(sal_Int32 _nRow, sal_uInt16 _nColumnPos, const TriState &eState)
SVT_DLLPRIVATE void DetermineFocus(const GetFocusFlags _nGetFocusFlags=GetFocusFlags::NONE)
CellControllerRef aController
std::unique_ptr< EditBrowseBoxImpl > m_aImpl
void implCreateActiveAccessible()
bool IsEditing() const
virtual sal_Int32 GetFieldIndexAtPoint(sal_Int32 _nRow, sal_Int32 _nColumnPos, const Point &_rPoint) override
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessibleControl(sal_Int32 nIndex) override
Creates the accessible object of an additional control.
EditBrowseBoxFlags GetBrowserFlags() const
bool ControlHasFocus() const
virtual void GrabTableFocus() override
Sets focus to current cell of the data table.
virtual bool SeekRow(sal_Int32 nRow) override
seeks for the given row position
virtual sal_Int32 GetAccessibleControlCount() const override
virtual tools::Rectangle GetFieldCharacterBounds(sal_Int32 _nRow, sal_Int32 _nColumnPos, sal_Int32 nIndex) override
bool is() const
virtual css::uno::Reference< css::accessibility::XAccessible > createAccessibleCheckBoxCell(const css::uno::Reference< css::accessibility::XAccessible > &_rxParent, vcl::IAccessibleTableProvider &_rBrowseBox, const css::uno::Reference< css::awt::XWindow > &_xFocusWindow, sal_Int32 _nRowPos, sal_uInt16 _nColPos, const TriState &_eState, bool _bIsTriState) const=0
virtual css::uno::Reference< css::accessibility::XAccessible > createEditBrowseBoxTableCellAccess(const css::uno::Reference< css::accessibility::XAccessible > &_rxParent, const css::uno::Reference< css::accessibility::XAccessible > &_rxControlAccessible, const css::uno::Reference< css::awt::XWindow > &_rxFocusWindow, vcl::IAccessibleTableProvider &_rBrowseBox, sal_Int32 _nRowPos, sal_uInt16 _nColPos) const=0
vcl::Window * GetParent() const
#define DBG_ASSERT(sCon, aError)
#define TOOLS_WARN_EXCEPTION(area, stream)
@ SMART_TAB_TRAVEL
If this bit is set, tab traveling is somewhat modified If the control gets the focus because the use...
TriState
@ Exception
GetFocusFlags