Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include <editeng/unoedhlp.hxx>
21 : #include <editeng/editdata.hxx>
22 : #include <editeng/editeng.hxx>
23 : #include <svl/itemset.hxx>
24 :
25 :
26 :
27 0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) :
28 : TextHint( _nId ),
29 : mnStart( 0 ),
30 0 : mnEnd( 0 )
31 : {
32 0 : }
33 :
34 0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_Int32 nStart, sal_Int32 nEnd ) :
35 : TextHint( _nId, nValue ),
36 : mnStart( nStart),
37 0 : mnEnd( nEnd )
38 : {
39 0 : }
40 :
41 0 : sal_uLong SvxEditSourceHint::GetValue() const
42 : {
43 0 : return TextHint::GetValue();
44 : }
45 :
46 :
47 24 : ::std::unique_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
48 : {
49 24 : if( aNotify )
50 : {
51 24 : switch( aNotify->eNotificationType )
52 : {
53 : case EE_NOTIFY_TEXTMODIFIED:
54 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
55 :
56 : case EE_NOTIFY_PARAGRAPHINSERTED:
57 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
58 :
59 : case EE_NOTIFY_PARAGRAPHREMOVED:
60 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
61 :
62 : case EE_NOTIFY_PARAGRAPHSMOVED:
63 0 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
64 :
65 : case EE_NOTIFY_TEXTHEIGHTCHANGED:
66 8 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
67 :
68 : case EE_NOTIFY_TEXTVIEWSCROLLED:
69 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
70 :
71 : case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
72 0 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
73 :
74 : case EE_NOTIFY_BLOCKNOTIFICATION_START:
75 8 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
76 :
77 : case EE_NOTIFY_BLOCKNOTIFICATION_END:
78 8 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
79 :
80 : case EE_NOTIFY_INPUT_START:
81 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
82 :
83 : case EE_NOTIFY_INPUT_END:
84 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
85 : case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED_ENDD_PARA:
86 0 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHintEndPara( EDITSOURCE_HINT_SELECTIONCHANGED ) );
87 : default:
88 : OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
89 0 : break;
90 : }
91 : }
92 :
93 0 : return ::std::unique_ptr<SfxHint>( new SfxHint() );
94 : }
95 :
96 0 : bool SvxEditSourceHelper::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, const EditEngine& rEE, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell )
97 : {
98 : // IA2 CWS introduced bInCell, but also did many other changes here.
99 : // Need to verify implementation with AT (IA2 and ATK)
100 : // Old implementation at the end of the method for reference...
101 :
102 : //added dummy attributes for the default text
103 0 : std::vector<EECharAttrib> aCharAttribs, aTempCharAttribs;
104 0 : rEE.GetCharAttribs( nPara, aTempCharAttribs );
105 :
106 0 : if (!aTempCharAttribs.empty())
107 : {
108 0 : sal_Int32 nIndex2 = 0;
109 0 : sal_Int32 nParaLen = rEE.GetTextLen(nPara);
110 0 : for (size_t nAttr = 0; nAttr < aTempCharAttribs.size(); ++nAttr)
111 : {
112 0 : if (nIndex2 < aTempCharAttribs[nAttr].nStart)
113 : {
114 : EECharAttrib aEEAttr;
115 0 : aEEAttr.nStart = nIndex2;
116 0 : aEEAttr.nEnd = aTempCharAttribs[nAttr].nStart;
117 0 : aCharAttribs.insert(aCharAttribs.begin() + nAttr, aEEAttr);
118 : }
119 0 : nIndex2 = aTempCharAttribs[nAttr].nEnd;
120 0 : aCharAttribs.push_back(aTempCharAttribs[nAttr]);
121 : }
122 0 : if ( nIndex2 != nParaLen )
123 : {
124 : EECharAttrib aEEAttr;
125 0 : aEEAttr.nStart = nIndex2;
126 0 : aEEAttr.nEnd = nParaLen;
127 0 : aCharAttribs.push_back(aEEAttr);
128 : }
129 : }
130 : // find closest index in front of nIndex
131 : sal_Int32 nCurrIndex;
132 0 : sal_Int32 nClosestStartIndex_s = 0, nClosestStartIndex_e = 0;
133 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
134 : {
135 0 : nCurrIndex = i->nStart;
136 :
137 0 : if( nCurrIndex > nClosestStartIndex_s &&
138 : nCurrIndex <= nIndex)
139 : {
140 0 : nClosestStartIndex_s = nCurrIndex;
141 : }
142 0 : nCurrIndex = i->nEnd;
143 0 : if ( nCurrIndex > nClosestStartIndex_e &&
144 : nCurrIndex < nIndex )
145 : {
146 0 : nClosestStartIndex_e = nCurrIndex;
147 : }
148 : }
149 0 : sal_Int32 nClosestStartIndex = nClosestStartIndex_s > nClosestStartIndex_e ? nClosestStartIndex_s : nClosestStartIndex_e;
150 :
151 : // find closest index behind of nIndex
152 : sal_Int32 nClosestEndIndex_s, nClosestEndIndex_e;
153 0 : nClosestEndIndex_s = nClosestEndIndex_e = rEE.GetTextLen(nPara);
154 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
155 : {
156 0 : nCurrIndex = i->nEnd;
157 :
158 0 : if( nCurrIndex > nIndex &&
159 : nCurrIndex < nClosestEndIndex_e )
160 : {
161 0 : nClosestEndIndex_e = nCurrIndex;
162 : }
163 0 : nCurrIndex = i->nStart;
164 0 : if ( nCurrIndex > nIndex &&
165 : nCurrIndex < nClosestEndIndex_s)
166 : {
167 0 : nClosestEndIndex_s = nCurrIndex;
168 : }
169 : }
170 0 : sal_Int32 nClosestEndIndex = nClosestEndIndex_s < nClosestEndIndex_e ? nClosestEndIndex_s : nClosestEndIndex_e;
171 :
172 0 : nStartIndex = nClosestStartIndex;
173 0 : nEndIndex = nClosestEndIndex;
174 :
175 0 : if ( bInCell )
176 : {
177 0 : EPosition aStartPos( nPara, nStartIndex ), aEndPos( nPara, nEndIndex );
178 0 : sal_Int32 nParaCount = rEE.GetParagraphCount();
179 0 : sal_Int32 nCrrntParaLen = rEE.GetTextLen(nPara);
180 : //need to find closest index in front of nIndex in the previous paragraphs
181 0 : if ( aStartPos.nIndex == 0 )
182 : {
183 0 : SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, 0, 1, GETATTRIBS_CHARATTRIBS );
184 0 : for ( sal_Int32 nParaIdx = nPara-1; nParaIdx >= 0; nParaIdx-- )
185 : {
186 0 : sal_uInt32 nLen = rEE.GetTextLen(nParaIdx);
187 0 : if ( nLen )
188 : {
189 : sal_Int32 nStartIdx, nEndIdx;
190 0 : GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, nLen, false );
191 0 : SfxItemSet aSet = rEE.GetAttribs( nParaIdx, nLen-1, nLen, GETATTRIBS_CHARATTRIBS );
192 0 : if ( aSet == aCrrntSet )
193 : {
194 0 : aStartPos.nPara = nParaIdx;
195 0 : aStartPos.nIndex = nStartIdx;
196 0 : if ( aStartPos.nIndex != 0 )
197 : {
198 0 : break;
199 : }
200 0 : }
201 : }
202 0 : }
203 : }
204 : //need find closest index behind nIndex in the following paragrphs
205 0 : if ( aEndPos.nIndex == nCrrntParaLen )
206 : {
207 0 : SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, nCrrntParaLen-1, nCrrntParaLen, GETATTRIBS_CHARATTRIBS );
208 0 : for ( sal_Int32 nParaIdx = nPara+1; nParaIdx < nParaCount; nParaIdx++ )
209 : {
210 0 : sal_Int32 nLen = rEE.GetTextLen( nParaIdx );
211 0 : if ( nLen )
212 : {
213 : sal_Int32 nStartIdx, nEndIdx;
214 0 : GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, 0, false );
215 0 : SfxItemSet aSet = rEE.GetAttribs( nParaIdx, 0, 1, GETATTRIBS_CHARATTRIBS );
216 0 : if ( aSet == aCrrntSet )
217 : {
218 0 : aEndPos.nPara = nParaIdx;
219 0 : aEndPos.nIndex = nEndIdx;
220 0 : if ( aEndPos.nIndex != nLen )
221 : {
222 0 : break;
223 : }
224 0 : }
225 : }
226 0 : }
227 : }
228 0 : nStartIndex = 0;
229 0 : if ( aStartPos.nPara > 0 )
230 : {
231 0 : for ( sal_Int32 i = 0; i < aStartPos.nPara; i++ )
232 : {
233 0 : nStartIndex += rEE.GetTextLen(i)+1;
234 : }
235 : }
236 0 : nStartIndex += aStartPos.nIndex;
237 0 : nEndIndex = 0;
238 0 : if ( aEndPos.nPara > 0 )
239 : {
240 0 : for ( sal_Int32 i = 0; i < aEndPos.nPara; i++ )
241 : {
242 0 : nEndIndex += rEE.GetTextLen(i)+1;
243 : }
244 : }
245 0 : nEndIndex += aEndPos.nIndex;
246 : }
247 :
248 0 : return true;
249 : }
250 :
251 0 : Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
252 : {
253 0 : return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
254 : }
255 :
256 22 : Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
257 : {
258 22 : return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
259 : }
260 :
261 42 : Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
262 : {
263 42 : return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
264 84 : EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
265 : }
266 :
267 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|