xref: /AOO41X/main/editeng/source/uno/unoedhlp.cxx (revision 190118d08a3be86671f4129b3e9a490e144719cd)
1*190118d0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*190118d0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*190118d0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*190118d0SAndrew Rist  * distributed with this work for additional information
6*190118d0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*190118d0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*190118d0SAndrew Rist  * "License"); you may not use this file except in compliance
9*190118d0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11*190118d0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13*190118d0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*190118d0SAndrew Rist  * software distributed under the License is distributed on an
15*190118d0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*190118d0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*190118d0SAndrew Rist  * specific language governing permissions and limitations
18*190118d0SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20*190118d0SAndrew Rist  *************************************************************/
21*190118d0SAndrew Rist 
22*190118d0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_editeng.hxx"
26cdf0e10cSrcweir #include <tools/debug.hxx>
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <editeng/unoedhlp.hxx>
29cdf0e10cSrcweir #include <editeng/editdata.hxx>
30cdf0e10cSrcweir #include <editeng/editeng.hxx>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir //------------------------------------------------------------------------
33cdf0e10cSrcweir 
34cdf0e10cSrcweir TYPEINIT1( SvxEditSourceHint, TextHint );
35cdf0e10cSrcweir 
36cdf0e10cSrcweir SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) :
37cdf0e10cSrcweir     TextHint( _nId ),
38cdf0e10cSrcweir     mnStart( 0 ),
39cdf0e10cSrcweir     mnEnd( 0 )
40cdf0e10cSrcweir {
41cdf0e10cSrcweir }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_uLong nStart, sal_uLong nEnd ) :
44cdf0e10cSrcweir     TextHint( _nId, nValue ),
45cdf0e10cSrcweir     mnStart( nStart),
46cdf0e10cSrcweir     mnEnd( nEnd )
47cdf0e10cSrcweir {
48cdf0e10cSrcweir }
49cdf0e10cSrcweir 
50cdf0e10cSrcweir sal_uLong SvxEditSourceHint::GetValue() const
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     return TextHint::GetValue();
53cdf0e10cSrcweir }
54cdf0e10cSrcweir 
55cdf0e10cSrcweir sal_uLong SvxEditSourceHint::GetStartValue() const
56cdf0e10cSrcweir {
57cdf0e10cSrcweir     return mnStart;
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir sal_uLong SvxEditSourceHint::GetEndValue() const
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     return mnEnd;
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir void SvxEditSourceHint::SetValue( sal_uLong n )
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     TextHint::SetValue( n );
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
70cdf0e10cSrcweir void SvxEditSourceHint::SetStartValue( sal_uLong n )
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     mnStart = n;
73cdf0e10cSrcweir }
74cdf0e10cSrcweir 
75cdf0e10cSrcweir void SvxEditSourceHint::SetEndValue( sal_uLong n )
76cdf0e10cSrcweir {
77cdf0e10cSrcweir     mnEnd = n;
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //------------------------------------------------------------------------
81cdf0e10cSrcweir 
82cdf0e10cSrcweir ::std::auto_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir     if( aNotify )
85cdf0e10cSrcweir     {
86cdf0e10cSrcweir         switch( aNotify->eNotificationType )
87cdf0e10cSrcweir         {
88cdf0e10cSrcweir             case EE_NOTIFY_TEXTMODIFIED:
89cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
90cdf0e10cSrcweir 
91cdf0e10cSrcweir             case EE_NOTIFY_PARAGRAPHINSERTED:
92cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir             case EE_NOTIFY_PARAGRAPHREMOVED:
95cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
96cdf0e10cSrcweir 
97cdf0e10cSrcweir             case EE_NOTIFY_PARAGRAPHSMOVED:
98cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
99cdf0e10cSrcweir 
100cdf0e10cSrcweir             case EE_NOTIFY_TEXTHEIGHTCHANGED:
101cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
102cdf0e10cSrcweir 
103cdf0e10cSrcweir             case EE_NOTIFY_TEXTVIEWSCROLLED:
104cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
105cdf0e10cSrcweir 
106cdf0e10cSrcweir             case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
107cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
108cdf0e10cSrcweir 
109cdf0e10cSrcweir             case EE_NOTIFY_BLOCKNOTIFICATION_START:
110cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
111cdf0e10cSrcweir 
112cdf0e10cSrcweir             case EE_NOTIFY_BLOCKNOTIFICATION_END:
113cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
114cdf0e10cSrcweir 
115cdf0e10cSrcweir             case EE_NOTIFY_INPUT_START:
116cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
117cdf0e10cSrcweir 
118cdf0e10cSrcweir             case EE_NOTIFY_INPUT_END:
119cdf0e10cSrcweir                 return ::std::auto_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
120cdf0e10cSrcweir 
121cdf0e10cSrcweir             default:
122cdf0e10cSrcweir                 DBG_ERROR( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
123cdf0e10cSrcweir                 break;
124cdf0e10cSrcweir         }
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir 
127cdf0e10cSrcweir     return ::std::auto_ptr<SfxHint>( new SfxHint() );
128cdf0e10cSrcweir }
129cdf0e10cSrcweir 
130cdf0e10cSrcweir sal_Bool SvxEditSourceHelper::GetAttributeRun( sal_uInt16& nStartIndex, sal_uInt16& nEndIndex, const EditEngine& rEE, sal_uInt16 nPara, sal_uInt16 nIndex )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     EECharAttribArray aCharAttribs;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     rEE.GetCharAttribs( nPara, aCharAttribs );
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     // find closest index in front of nIndex
137cdf0e10cSrcweir     sal_uInt16 nAttr, nCurrIndex;
138cdf0e10cSrcweir     sal_Int32 nClosestStartIndex;
139cdf0e10cSrcweir     for( nAttr=0, nClosestStartIndex=0; nAttr<aCharAttribs.Count(); ++nAttr )
140cdf0e10cSrcweir     {
141cdf0e10cSrcweir         nCurrIndex = aCharAttribs[nAttr].nStart;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir         if( nCurrIndex > nIndex )
144cdf0e10cSrcweir             break; // aCharAttribs array is sorted in increasing order for nStart values
145cdf0e10cSrcweir 
146cdf0e10cSrcweir         if( nCurrIndex > nClosestStartIndex )
147cdf0e10cSrcweir         {
148cdf0e10cSrcweir             nClosestStartIndex = nCurrIndex;
149cdf0e10cSrcweir         }
150cdf0e10cSrcweir     }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     // find closest index behind of nIndex
153cdf0e10cSrcweir     sal_Int32 nClosestEndIndex;
154cdf0e10cSrcweir     for( nAttr=0, nClosestEndIndex=rEE.GetTextLen(nPara); nAttr<aCharAttribs.Count(); ++nAttr )
155cdf0e10cSrcweir     {
156cdf0e10cSrcweir         nCurrIndex = aCharAttribs[nAttr].nEnd;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir         if( nCurrIndex > nIndex &&
159cdf0e10cSrcweir             nCurrIndex < nClosestEndIndex )
160cdf0e10cSrcweir         {
161cdf0e10cSrcweir             nClosestEndIndex = nCurrIndex;
162cdf0e10cSrcweir         }
163cdf0e10cSrcweir     }
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     nStartIndex = static_cast<sal_uInt16>( nClosestStartIndex );
166cdf0e10cSrcweir     nEndIndex = static_cast<sal_uInt16>( nClosestEndIndex );
167cdf0e10cSrcweir 
168cdf0e10cSrcweir     return sal_True;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir     return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
174cdf0e10cSrcweir }
175cdf0e10cSrcweir 
176cdf0e10cSrcweir Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir     return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
179cdf0e10cSrcweir }
180cdf0e10cSrcweir 
181cdf0e10cSrcweir Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
182cdf0e10cSrcweir {
183cdf0e10cSrcweir     // #106775# Don't touch rect if not vertical
184cdf0e10cSrcweir     return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
185cdf0e10cSrcweir                                     EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir 
188cdf0e10cSrcweir Rectangle SvxEditSourceHelper::UserSpaceToEE( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     // #106775# Don't touch rect if not vertical
191cdf0e10cSrcweir     return bIsVertical ? Rectangle( UserSpaceToEE(rRect.TopRight(), rEESize, bIsVertical),
192cdf0e10cSrcweir                                     UserSpaceToEE(rRect.BottomLeft(), rEESize, bIsVertical) ) : rRect;
193cdf0e10cSrcweir }
194