Update ooo320-m1
[ooovba.git] / svx / source / unoedit / unoedhlp.cxx
blob7de489be70e36e3c0207e3d69b4d840b470277dd
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: unoedhlp.cxx,v $
10 * $Revision: 1.11 $
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"
33 #include <tools/debug.hxx>
35 #include "unoedhlp.hxx"
36 #include <svx/editdata.hxx>
37 #include <svx/editeng.hxx>
39 //------------------------------------------------------------------------
41 TYPEINIT1( SvxEditSourceHint, TextHint );
43 SvxEditSourceHint::SvxEditSourceHint( ULONG _nId ) :
44 TextHint( _nId ),
45 mnStart( 0 ),
46 mnEnd( 0 )
50 SvxEditSourceHint::SvxEditSourceHint( ULONG _nId, ULONG nValue, ULONG nStart, ULONG nEnd ) :
51 TextHint( _nId, nValue ),
52 mnStart( nStart),
53 mnEnd( nEnd )
57 ULONG SvxEditSourceHint::GetValue() const
59 return TextHint::GetValue();
62 ULONG SvxEditSourceHint::GetStartValue() const
64 return mnStart;
67 ULONG SvxEditSourceHint::GetEndValue() const
69 return mnEnd;
72 void SvxEditSourceHint::SetValue( ULONG n )
74 TextHint::SetValue( n );
77 void SvxEditSourceHint::SetStartValue( ULONG n )
79 mnStart = n;
82 void SvxEditSourceHint::SetEndValue( ULONG n )
84 mnEnd = n;
87 //------------------------------------------------------------------------
89 ::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
91 if( aNotify )
93 switch( aNotify->eNotificationType )
95 case EE_NOTIFY_TEXTMODIFIED:
96 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
98 case EE_NOTIFY_PARAGRAPHINSERTED:
99 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
101 case EE_NOTIFY_PARAGRAPHREMOVED:
102 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
104 case EE_NOTIFY_PARAGRAPHSMOVED:
105 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
107 case EE_NOTIFY_TEXTHEIGHTCHANGED:
108 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
110 case EE_NOTIFY_TEXTVIEWSCROLLED:
111 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
113 case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
114 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
116 case EE_NOTIFY_BLOCKNOTIFICATION_START:
117 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
119 case EE_NOTIFY_BLOCKNOTIFICATION_END:
120 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
122 case EE_NOTIFY_INPUT_START:
123 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
125 case EE_NOTIFY_INPUT_END:
126 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
128 default:
129 DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
130 break;
134 return ::std::auto_ptr<SfxHint>( new SfxHint() );
137 sal_Bool SvxEditSourceHelper::GetAttributeRun( USHORT& nStartIndex, USHORT& nEndIndex, const EditEngine& rEE, USHORT nPara, USHORT nIndex )
139 EECharAttribArray aCharAttribs;
141 rEE.GetCharAttribs( nPara, aCharAttribs );
143 // find closest index in front of nIndex
144 USHORT nAttr, nCurrIndex;
145 sal_Int32 nClosestStartIndex;
146 for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr )
148 nCurrIndex = aCharAttribs[nAttr].nStart;
150 if( nCurrIndex > nIndex )
151 break; // aCharAttribs array is sorted in increasing order for nStart values
153 if( nCurrIndex > nClosestStartIndex )
155 nClosestStartIndex = nCurrIndex;
159 // find closest index behind of nIndex
160 sal_Int32 nClosestEndIndex;
161 for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr )
163 nCurrIndex = aCharAttribs[nAttr].nEnd;
165 if( nCurrIndex > nIndex &&
166 nCurrIndex < nClosestEndIndex )
168 nClosestEndIndex = nCurrIndex;
172 nStartIndex = static_cast<USHORT>( nClosestStartIndex );
173 nEndIndex = static_cast<USHORT>( nClosestEndIndex );
175 return sal_True;
178 Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
180 return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
183 Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
185 return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
188 Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
190 // #106775# Don't touch rect if not vertical
191 return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
192 EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
195 Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
197 // #106775# Don't touch rect if not vertical
198 return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical),
199 UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect;