update dev300-m58
[ooovba.git] / svx / source / accessibility / AccessibleStringWrap.cxx
blob6a38e254ffbb7e05ed2d33316c33651c63e359bc
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleStringWrap.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <algorithm>
35 #include <tools/debug.hxx>
36 #include <vcl/outdev.hxx>
38 #include <svx/svxfont.hxx>
39 #include "AccessibleStringWrap.hxx"
42 //------------------------------------------------------------------------
44 // AccessibleStringWrap implementation
46 //------------------------------------------------------------------------
48 AccessibleStringWrap::AccessibleStringWrap( OutputDevice& rDev, SvxFont& rFont, const String& rText ) :
49 mrDev( rDev ),
50 mrFont( rFont ),
51 maText( rText )
55 sal_Bool AccessibleStringWrap::GetCharacterBounds( sal_Int32 nIndex, Rectangle& rRect )
57 DBG_ASSERT(nIndex >= 0 && nIndex <= USHRT_MAX,
58 "SvxAccessibleStringWrap::GetCharacterBounds: index value overflow");
60 mrFont.SetPhysFont( &mrDev );
62 // #108900# Handle virtual position one-past-the end of the string
63 if( nIndex >= maText.Len() )
65 // create a caret bounding rect that has the height of the
66 // current font and is one pixel wide.
67 rRect.Left() = mrDev.GetTextWidth(maText);
68 rRect.Top() = 0;
69 rRect.SetSize( Size(mrDev.GetTextHeight(), 1) );
71 else
73 sal_Int32 aXArray[2];
74 mrDev.GetCaretPositions( maText, aXArray, static_cast< USHORT >(nIndex), 1 );
75 rRect.Left() = 0;
76 rRect.Top() = 0;
77 rRect.SetSize( Size(mrDev.GetTextHeight(), labs(aXArray[0] - aXArray[1])) );
78 rRect.Move( ::std::min(aXArray[0], aXArray[1]), 0 );
81 if( mrFont.IsVertical() )
83 // #101701# Rotate to vertical
84 rRect = Rectangle( Point(-rRect.Top(), rRect.Left()),
85 Point(-rRect.Bottom(), rRect.Right()));
88 return sal_True;
91 sal_Int32 AccessibleStringWrap::GetIndexAtPoint( const Point& rPoint )
93 // search for character bounding box containing given point
94 Rectangle aRect;
95 sal_Int32 i, nLen = maText.Len();
96 for( i=0; i<nLen; ++i )
98 GetCharacterBounds(i, aRect);
99 if( aRect.IsInside(rPoint) )
100 return i;
103 return -1;