1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_editeng.hxx" 30 #include <tools/debug.hxx> 31 32 #include <editeng/unoedhlp.hxx> 33 #include <editeng/editdata.hxx> 34 #include <editeng/editeng.hxx> 35 36 //------------------------------------------------------------------------ 37 38 TYPEINIT1( SvxEditSourceHint, TextHint ); 39 40 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) : 41 TextHint( _nId ), 42 mnStart( 0 ), 43 mnEnd( 0 ) 44 { 45 } 46 47 SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_uLong nStart, sal_uLong nEnd ) : 48 TextHint( _nId, nValue ), 49 mnStart( nStart), 50 mnEnd( nEnd ) 51 { 52 } 53 54 sal_uLong SvxEditSourceHint::GetValue() const 55 { 56 return TextHint::GetValue(); 57 } 58 59 sal_uLong SvxEditSourceHint::GetStartValue() const 60 { 61 return mnStart; 62 } 63 64 sal_uLong SvxEditSourceHint::GetEndValue() const 65 { 66 return mnEnd; 67 } 68 69 void SvxEditSourceHint::SetValue( sal_uLong n ) 70 { 71 TextHint::SetValue( n ); 72 } 73 74 void SvxEditSourceHint::SetStartValue( sal_uLong n ) 75 { 76 mnStart = n; 77 } 78 79 void SvxEditSourceHint::SetEndValue( sal_uLong n ) 80 { 81 mnEnd = n; 82 } 83 84 //------------------------------------------------------------------------ 85 86 ::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify ) 87 { 88 if( aNotify ) 89 { 90 switch( aNotify->eNotificationType ) 91 { 92 case EE_NOTIFY_TEXTMODIFIED: 93 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) ); 94 95 case EE_NOTIFY_PARAGRAPHINSERTED: 96 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) ); 97 98 case EE_NOTIFY_PARAGRAPHREMOVED: 99 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) ); 100 101 case EE_NOTIFY_PARAGRAPHSMOVED: 102 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) ); 103 104 case EE_NOTIFY_TEXTHEIGHTCHANGED: 105 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) ); 106 107 case EE_NOTIFY_TEXTVIEWSCROLLED: 108 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) ); 109 110 case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED: 111 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) ); 112 113 case EE_NOTIFY_BLOCKNOTIFICATION_START: 114 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) ); 115 116 case EE_NOTIFY_BLOCKNOTIFICATION_END: 117 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) ); 118 119 case EE_NOTIFY_INPUT_START: 120 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) ); 121 122 case EE_NOTIFY_INPUT_END: 123 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) ); 124 125 default: 126 DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" ); 127 break; 128 } 129 } 130 131 return ::std::auto_ptr<SfxHint>( new SfxHint() ); 132 } 133 134 sal_Bool SvxEditSourceHelper::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, const EditEngine& rEE, sal_uInt16 nPara, sal_uInt16 nIndex ) 135 { 136 EECharAttribArray aCharAttribs; 137 138 rEE.GetCharAttribs( nPara, aCharAttribs ); 139 140 // find closest index in front of nIndex 141 sal_uInt16 nAttr, nCurrIndex; 142 sal_Int32 nClosestStartIndex; 143 for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr ) 144 { 145 nCurrIndex = aCharAttribs[nAttr].nStart; 146 147 if( nCurrIndex > nIndex ) 148 break; // aCharAttribs array is sorted in increasing order for nStart values 149 150 if( nCurrIndex > nClosestStartIndex ) 151 { 152 nClosestStartIndex = nCurrIndex; 153 } 154 } 155 156 // find closest index behind of nIndex 157 sal_Int32 nClosestEndIndex; 158 for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr ) 159 { 160 nCurrIndex = aCharAttribs[nAttr].nEnd; 161 162 if( nCurrIndex > nIndex && 163 nCurrIndex < nClosestEndIndex ) 164 { 165 nClosestEndIndex = nCurrIndex; 166 } 167 } 168 169 nStartIndex = static_cast<sal_uInt16>( nClosestStartIndex ); 170 nEndIndex = static_cast<sal_uInt16>( nClosestEndIndex ); 171 172 return sal_True; 173 } 174 175 Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical ) 176 { 177 return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint; 178 } 179 180 Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical ) 181 { 182 return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint; 183 } 184 185 Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical ) 186 { 187 // #106775# Don't touch rect if not vertical 188 return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical), 189 EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect; 190 } 191 192 Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical ) 193 { 194 // #106775# Don't touch rect if not vertical 195 return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical), 196 UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect; 197 } 198