Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / accessibility / inc / helper / listboxhelper.hxx
blobdfadf37aa015b7ba7d2298b8659e1d2d4b4fde25
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #pragma once
22 #include <helper/IComboListBoxHelper.hxx>
23 #include <com/sun/star/datatransfer/clipboard/XClipboard.hpp>
24 #include <tools/gen.hxx>
27 // globals
30 const sal_Int32 DEFAULT_INDEX_IN_PARENT = -1;
35 template< class T > class VCLListBoxHelper final : public ::accessibility::IComboListBoxHelper
37 private:
38 T& m_aComboListBox;
40 public:
41 VCLListBoxHelper( T& _pListBox ) :
42 m_aComboListBox( _pListBox ){}
45 virtual OUString GetEntry( sal_Int32 nPos ) const override
47 return m_aComboListBox.GetEntry( nPos );
50 virtual tools::Rectangle GetDropDownPosSizePixel() const override
52 tools::Rectangle aTemp = m_aComboListBox.GetWindowExtentsRelative(nullptr);
53 tools::Rectangle aRet = m_aComboListBox.GetDropDownPosSizePixel();
54 aRet.Move(aTemp.Left(), aTemp.Top());
55 return aRet;
58 virtual tools::Rectangle GetBoundingRectangle( sal_uInt16 nItem ) const override
60 tools::Rectangle aRect;
61 if ( m_aComboListBox.IsInDropDown() && IsEntryVisible( nItem ) )
63 tools::Rectangle aTemp = m_aComboListBox.GetDropDownPosSizePixel();
64 Size aSize = aTemp.GetSize();
65 sal_uInt16 nLineCount = m_aComboListBox.GetDisplayLineCount();
66 assert(nLineCount && "div-by-zero");
67 aSize.setHeight( aSize.Height() / nLineCount );
68 Point aTopLeft = aTemp.TopLeft();
69 aTopLeft.AdjustY( aSize.Height() * ( nItem - m_aComboListBox.GetTopEntry() ) );
70 aRect = tools::Rectangle( aTopLeft, aSize );
72 else
73 aRect = m_aComboListBox.GetBoundingRectangle( nItem );
74 return aRect;
77 virtual tools::Rectangle GetWindowExtentsRelative() override
79 return m_aComboListBox.GetWindowExtentsRelative( nullptr );
82 virtual bool IsEnabled() const override
84 return m_aComboListBox.IsEnabled();
87 virtual bool IsEntryVisible( sal_Int32 nPos ) const override
89 sal_Int32 nTopEntry = m_aComboListBox.GetTopEntry();
90 sal_uInt16 nLines = m_aComboListBox.GetDisplayLineCount();
91 return ( nPos >= nTopEntry && nPos < ( nTopEntry + nLines ) );
94 virtual sal_uInt16 GetDisplayLineCount() const override
96 return m_aComboListBox.GetDisplayLineCount();
99 virtual void GetMaxVisColumnsAndLines( sal_uInt16& rnCols, sal_uInt16& rnLines ) const override
101 m_aComboListBox.GetMaxVisColumnsAndLines(rnCols,rnLines);
104 virtual WinBits GetStyle() const override
106 return m_aComboListBox.GetStyle();
109 virtual bool IsMultiSelectionEnabled() const override
111 return m_aComboListBox.IsMultiSelectionEnabled();
114 virtual sal_Int32 GetTopEntry() const override
116 return m_aComboListBox.GetTopEntry();
119 virtual bool IsEntryPosSelected( sal_Int32 nPos ) const override
121 return m_aComboListBox.IsEntryPosSelected(nPos);
124 virtual sal_Int32 GetEntryCount() const override
126 return m_aComboListBox.GetEntryCount();
129 virtual void Select() override
131 m_aComboListBox.Select();
134 virtual void SelectEntryPos( sal_Int32 nPos, bool bSelect = true ) override
136 m_aComboListBox.SelectEntryPos(nPos,bSelect);
139 virtual sal_Int32 GetSelectedEntryCount() const override
141 return m_aComboListBox.GetSelectedEntryCount();
144 virtual void SetNoSelection() override
146 m_aComboListBox.SetNoSelection();
149 virtual sal_Int32 GetSelectedEntryPos( sal_Int32 nSelIndex = 0 ) const override
151 return m_aComboListBox.GetSelectedEntryPos(nSelIndex);
154 virtual bool IsInDropDown() const override
156 return m_aComboListBox.IsInDropDown();
159 virtual tools::Rectangle GetEntryCharacterBounds( const sal_Int32 _nEntryPos, const sal_Int32 _nCharacterIndex ) const override
161 tools::Rectangle aRect;
163 Pair aEntryCharacterRange = m_aComboListBox.GetLineStartEnd( _nEntryPos );
164 if ( aEntryCharacterRange.A() + _nCharacterIndex <= aEntryCharacterRange.B() )
166 tools::Long nIndex = aEntryCharacterRange.A() + _nCharacterIndex;
167 aRect = m_aComboListBox.GetCharacterBounds( nIndex );
169 return aRect;
172 tools::Long GetIndexForPoint( const Point& rPoint, sal_Int32& nPos ) const override
174 return m_aComboListBox.GetIndexForPoint( rPoint, nPos );
177 css::uno::Reference< css::datatransfer::clipboard::XClipboard >
178 GetClipboard() override
180 return m_aComboListBox.GetClipboard();
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */