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