1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: AccessibleStringWrap.cxx,v $
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"
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
) :
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
);
69 rRect
.SetSize( Size(mrDev
.GetTextHeight(), 1) );
74 mrDev
.GetCaretPositions( maText
, aXArray
, static_cast< USHORT
>(nIndex
), 1 );
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()));
91 sal_Int32
AccessibleStringWrap::GetIndexAtPoint( const Point
& rPoint
)
93 // search for character bounding box containing given point
95 sal_Int32 i
, nLen
= maText
.Len();
96 for( i
=0; i
<nLen
; ++i
)
98 GetCharacterBounds(i
, aRect
);
99 if( aRect
.IsInside(rPoint
) )