Bump for 3.6-28
[LibreOffice.git] / editeng / source / accessibility / AccessibleStringWrap.cxx
blob88641580eea95fa1f93b9c1c36ff9b8ceecc13ee
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <algorithm>
31 #include <tools/debug.hxx>
32 #include <vcl/outdev.hxx>
34 #include <editeng/svxfont.hxx>
35 #include <editeng/AccessibleStringWrap.hxx>
37 //------------------------------------------------------------------------
39 // AccessibleStringWrap implementation
41 //------------------------------------------------------------------------
43 AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, const String& rText ) :
44 mrDev( rDev ),
45 mrFont( rFont ),
46 maText( rText )
50 sal_Bool AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, Rectangle& rRect )
52 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
53 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow");
55 mrFont.SetPhysFont( &mrDev );
57 // #108900# Handle virtual position one-past-the end of the string
58 if( nIndex >= maText.Len() )
60 // create a caret bounding rect that has the height of the
61 // current font and is one pixel wide.
62 rRect.Left() = mrDev.GetTextWidth(maText);
63 rRect.Top() = 0;
64 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) );
66 else
68 sal_Int32 aXArray[2];
69 mrDev.GetCaretPositions( maText, aXArray, static_cast< sal_uInt16 >(nIndex), 1 );
70 rRect.Left() = 0;
71 rRect.Top() = 0;
72 rRect.SetSize( Size(mrDev.GetTextHeight(), labs(aXArray[0] - aXArray[1])) );
73 rRect.Move( ::std::min(aXArray[0], aXArray[1]), 0 );
76 if( mrFont.IsVertical() )
78 // #101701# Rotate to vertical
79 rRect = Rectangle( Point(-rRect.Top(), rRect.Left()),
80 Point(-rRect.Bottom(), rRect.Right()));
83 return sal_True;
86 sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint )
88 // search for character bounding box containing given point
89 Rectangle aRect;
90 sal_Int32 i, nLen = maText.Len();
91 for( i=0; i<nLen; ++i )
93 GetCharacterBounds(i, aRect);
94 if( aRect.IsInside(rPoint) )
95 return i;
98 return -1;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */