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