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 ************************************************************************/
29 #include <editeng/unoedhlp.hxx>
30 #include <editeng/editdata.hxx>
31 #include <editeng/editeng.hxx>
33 //------------------------------------------------------------------------
35 TYPEINIT1( SvxEditSourceHint
, TextHint
);
37 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId
) :
44 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId
, sal_uLong nValue
, sal_uLong nStart
, sal_uLong nEnd
) :
45 TextHint( _nId
, nValue
),
51 sal_uLong
SvxEditSourceHint::GetValue() const
53 return TextHint::GetValue();
56 sal_uLong
SvxEditSourceHint::GetStartValue() const
61 sal_uLong
SvxEditSourceHint::GetEndValue() const
66 //------------------------------------------------------------------------
68 ::std::auto_ptr
<SfxHint
> SvxEditSourceHelper::EENotification2Hint( EENotify
* aNotify
)
72 switch( aNotify
->eNotificationType
)
74 case EE_NOTIFY_TEXTMODIFIED
:
75 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_MODIFIED
, aNotify
->nParagraph
) );
77 case EE_NOTIFY_PARAGRAPHINSERTED
:
78 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_PARAINSERTED
, aNotify
->nParagraph
) );
80 case EE_NOTIFY_PARAGRAPHREMOVED
:
81 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_PARAREMOVED
, aNotify
->nParagraph
) );
83 case EE_NOTIFY_PARAGRAPHSMOVED
:
84 return ::std::auto_ptr
<SfxHint
>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED
, aNotify
->nParagraph
, aNotify
->nParam1
, aNotify
->nParam2
) );
86 case EE_NOTIFY_TEXTHEIGHTCHANGED
:
87 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED
, aNotify
->nParagraph
) );
89 case EE_NOTIFY_TEXTVIEWSCROLLED
:
90 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_VIEWSCROLLED
) );
92 case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED
:
93 return ::std::auto_ptr
<SfxHint
>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED
) );
95 case EE_NOTIFY_BLOCKNOTIFICATION_START
:
96 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START
, 0 ) );
98 case EE_NOTIFY_BLOCKNOTIFICATION_END
:
99 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END
, 0 ) );
101 case EE_NOTIFY_INPUT_START
:
102 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_INPUT_START
, 0 ) );
104 case EE_NOTIFY_INPUT_END
:
105 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_INPUT_END
, 0 ) );
108 OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
113 return ::std::auto_ptr
<SfxHint
>( new SfxHint() );
116 sal_Bool
SvxEditSourceHelper::GetAttributeRun( sal_uInt16
& nStartIndex
, sal_uInt16
& nEndIndex
, const EditEngine
& rEE
, sal_uInt16 nPara
, sal_uInt16 nIndex
)
118 std::vector
<EECharAttrib
> aCharAttribs
;
120 rEE
.GetCharAttribs( nPara
, aCharAttribs
);
122 // find closest index in front of nIndex
123 sal_uInt16 nCurrIndex
;
124 sal_Int32 nClosestStartIndex
= 0;
125 for(std::vector
<EECharAttrib
>::iterator i
= aCharAttribs
.begin(); i
< aCharAttribs
.end(); ++i
)
127 nCurrIndex
= i
->nStart
;
129 if( nCurrIndex
> nIndex
)
130 break; // aCharAttribs array is sorted in increasing order for nStart values
131 else if( nCurrIndex
> nClosestStartIndex
)
133 nClosestStartIndex
= nCurrIndex
;
137 // find closest index behind of nIndex
138 sal_Int32 nClosestEndIndex
= rEE
.GetTextLen(nPara
);
139 for(std::vector
<EECharAttrib
>::iterator i
= aCharAttribs
.begin(); i
< aCharAttribs
.end(); ++i
)
141 nCurrIndex
= i
->nEnd
;
143 if( nCurrIndex
> nIndex
&& nCurrIndex
< nClosestEndIndex
)
144 nClosestEndIndex
= nCurrIndex
;
147 nStartIndex
= static_cast<sal_uInt16
>( nClosestStartIndex
);
148 nEndIndex
= static_cast<sal_uInt16
>( nClosestEndIndex
);
153 Point
SvxEditSourceHelper::EEToUserSpace( const Point
& rPoint
, const Size
& rEESize
, bool bIsVertical
)
155 return bIsVertical
? Point( -rPoint
.Y() + rEESize
.Height(), rPoint
.X() ) : rPoint
;
158 Point
SvxEditSourceHelper::UserSpaceToEE( const Point
& rPoint
, const Size
& rEESize
, bool bIsVertical
)
160 return bIsVertical
? Point( rPoint
.Y(), -rPoint
.X() + rEESize
.Height() ) : rPoint
;
163 Rectangle
SvxEditSourceHelper::EEToUserSpace( const Rectangle
& rRect
, const Size
& rEESize
, bool bIsVertical
)
165 return bIsVertical
? Rectangle( EEToUserSpace(rRect
.BottomLeft(), rEESize
, bIsVertical
),
166 EEToUserSpace(rRect
.TopRight(), rEESize
, bIsVertical
) ) : rRect
;
169 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */