1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 #include <editeng/unoedhlp.hxx>
21 #include <editeng/editdata.hxx>
22 #include <editeng/editeng.hxx>
24 //------------------------------------------------------------------------
26 TYPEINIT1( SvxEditSourceHint
, TextHint
);
28 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId
) :
35 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId
, sal_uLong nValue
, sal_Int32 nStart
, sal_Int32 nEnd
) :
36 TextHint( _nId
, nValue
),
42 sal_uLong
SvxEditSourceHint::GetValue() const
44 return TextHint::GetValue();
47 sal_Int32
SvxEditSourceHint::GetStartValue() const
52 sal_Int32
SvxEditSourceHint::GetEndValue() const
57 //------------------------------------------------------------------------
59 ::std::auto_ptr
<SfxHint
> SvxEditSourceHelper::EENotification2Hint( EENotify
* aNotify
)
63 switch( aNotify
->eNotificationType
)
65 case EE_NOTIFY_TEXTMODIFIED
:
66 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_MODIFIED
, aNotify
->nParagraph
) );
68 case EE_NOTIFY_PARAGRAPHINSERTED
:
69 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_PARAINSERTED
, aNotify
->nParagraph
) );
71 case EE_NOTIFY_PARAGRAPHREMOVED
:
72 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_PARAREMOVED
, aNotify
->nParagraph
) );
74 case EE_NOTIFY_PARAGRAPHSMOVED
:
75 return ::std::auto_ptr
<SfxHint
>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED
, aNotify
->nParagraph
, aNotify
->nParam1
, aNotify
->nParam2
) );
77 case EE_NOTIFY_TEXTHEIGHTCHANGED
:
78 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED
, aNotify
->nParagraph
) );
80 case EE_NOTIFY_TEXTVIEWSCROLLED
:
81 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_VIEWSCROLLED
) );
83 case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED
:
84 return ::std::auto_ptr
<SfxHint
>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED
) );
86 case EE_NOTIFY_BLOCKNOTIFICATION_START
:
87 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START
, 0 ) );
89 case EE_NOTIFY_BLOCKNOTIFICATION_END
:
90 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END
, 0 ) );
92 case EE_NOTIFY_INPUT_START
:
93 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_INPUT_START
, 0 ) );
95 case EE_NOTIFY_INPUT_END
:
96 return ::std::auto_ptr
<SfxHint
>( new TextHint( TEXT_HINT_INPUT_END
, 0 ) );
99 OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
104 return ::std::auto_ptr
<SfxHint
>( new SfxHint() );
107 sal_Bool
SvxEditSourceHelper::GetAttributeRun( sal_uInt16
& nStartIndex
, sal_uInt16
& nEndIndex
, const EditEngine
& rEE
, sal_Int32 nPara
, sal_uInt16 nIndex
)
109 std::vector
<EECharAttrib
> aCharAttribs
;
111 rEE
.GetCharAttribs( nPara
, aCharAttribs
);
113 // find closest index in front of nIndex
114 sal_uInt16 nCurrIndex
;
115 sal_Int32 nClosestStartIndex
= 0;
116 for(std::vector
<EECharAttrib
>::iterator i
= aCharAttribs
.begin(); i
< aCharAttribs
.end(); ++i
)
118 nCurrIndex
= i
->nStart
;
120 if( nCurrIndex
> nIndex
)
121 break; // aCharAttribs array is sorted in increasing order for nStart values
122 else if( nCurrIndex
> nClosestStartIndex
)
124 nClosestStartIndex
= nCurrIndex
;
128 // find closest index behind of nIndex
129 sal_Int32 nClosestEndIndex
= rEE
.GetTextLen(nPara
);
130 for(std::vector
<EECharAttrib
>::iterator i
= aCharAttribs
.begin(); i
< aCharAttribs
.end(); ++i
)
132 nCurrIndex
= i
->nEnd
;
134 if( nCurrIndex
> nIndex
&& nCurrIndex
< nClosestEndIndex
)
135 nClosestEndIndex
= nCurrIndex
;
138 nStartIndex
= static_cast<sal_uInt16
>( nClosestStartIndex
);
139 nEndIndex
= static_cast<sal_uInt16
>( nClosestEndIndex
);
144 Point
SvxEditSourceHelper::EEToUserSpace( const Point
& rPoint
, const Size
& rEESize
, bool bIsVertical
)
146 return bIsVertical
? Point( -rPoint
.Y() + rEESize
.Height(), rPoint
.X() ) : rPoint
;
149 Point
SvxEditSourceHelper::UserSpaceToEE( const Point
& rPoint
, const Size
& rEESize
, bool bIsVertical
)
151 return bIsVertical
? Point( rPoint
.Y(), -rPoint
.X() + rEESize
.Height() ) : rPoint
;
154 Rectangle
SvxEditSourceHelper::EEToUserSpace( const Rectangle
& rRect
, const Size
& rEESize
, bool bIsVertical
)
156 return bIsVertical
? Rectangle( EEToUserSpace(rRect
.BottomLeft(), rEESize
, bIsVertical
),
157 EEToUserSpace(rRect
.TopRight(), rEESize
, bIsVertical
) ) : rRect
;
160 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */