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 : #include <osl/diagnose.h>
26 :
27 :
28 3 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId ) :
29 : TextHint( _nId ),
30 : mnStart( 0 ),
31 3 : mnEnd( 0 )
32 : {
33 3 : }
34 :
35 0 : SvxEditSourceHint::SvxEditSourceHint( sal_uLong _nId, sal_uLong nValue, sal_Int32 nStart, sal_Int32 nEnd ) :
36 : TextHint( _nId, nValue ),
37 : mnStart( nStart),
38 0 : mnEnd( nEnd )
39 : {
40 0 : }
41 :
42 0 : sal_uLong SvxEditSourceHint::GetValue() const
43 : {
44 0 : return TextHint::GetValue();
45 : }
46 :
47 :
48 25 : ::std::unique_ptr<SfxHint> SvxEditSourceHelper::EENotification2Hint( EENotify* aNotify )
49 : {
50 25 : if( aNotify )
51 : {
52 25 : switch( aNotify->eNotificationType )
53 : {
54 : case EE_NOTIFY_TEXTMODIFIED:
55 1 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_MODIFIED, aNotify->nParagraph ) );
56 :
57 : case EE_NOTIFY_PARAGRAPHINSERTED:
58 1 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAINSERTED, aNotify->nParagraph ) );
59 :
60 : case EE_NOTIFY_PARAGRAPHREMOVED:
61 1 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_PARAREMOVED, aNotify->nParagraph ) );
62 :
63 : case EE_NOTIFY_PARAGRAPHSMOVED:
64 0 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_PARASMOVED, aNotify->nParagraph, aNotify->nParam1, aNotify->nParam2 ) );
65 :
66 : case EE_NOTIFY_TEXTHEIGHTCHANGED:
67 5 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_TEXTHEIGHTCHANGED, aNotify->nParagraph ) );
68 :
69 : case EE_NOTIFY_TEXTVIEWSCROLLED:
70 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_VIEWSCROLLED ) );
71 :
72 : case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED:
73 3 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHint( EDITSOURCE_HINT_SELECTIONCHANGED ) );
74 :
75 : case EE_NOTIFY_BLOCKNOTIFICATION_START:
76 7 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_START, 0 ) );
77 :
78 : case EE_NOTIFY_BLOCKNOTIFICATION_END:
79 7 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_BLOCKNOTIFICATION_END, 0 ) );
80 :
81 : case EE_NOTIFY_INPUT_START:
82 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_START, 0 ) );
83 :
84 : case EE_NOTIFY_INPUT_END:
85 0 : return ::std::unique_ptr<SfxHint>( new TextHint( TEXT_HINT_INPUT_END, 0 ) );
86 : case EE_NOTIFY_TEXTVIEWSELECTIONCHANGED_ENDD_PARA:
87 0 : return ::std::unique_ptr<SfxHint>( new SvxEditSourceHintEndPara( EDITSOURCE_HINT_SELECTIONCHANGED ) );
88 : default:
89 : OSL_FAIL( "SvxEditSourceHelper::EENotification2Hint unknown notification" );
90 0 : break;
91 : }
92 : }
93 :
94 0 : return ::std::unique_ptr<SfxHint>( new SfxHint() );
95 : }
96 :
97 0 : bool SvxEditSourceHelper::GetAttributeRun( sal_Int32& nStartIndex, sal_Int32& nEndIndex, const EditEngine& rEE, sal_Int32 nPara, sal_Int32 nIndex, bool bInCell )
98 : {
99 : // IA2 CWS introduced bInCell, but also did many other changes here.
100 : // Need to verify implementation with AT (IA2 and ATK)
101 : // Old implementation at the end of the method for reference...
102 :
103 : //added dummy attributes for the default text
104 0 : std::vector<EECharAttrib> aCharAttribs, aTempCharAttribs;
105 0 : rEE.GetCharAttribs( nPara, aTempCharAttribs );
106 :
107 0 : if (!aTempCharAttribs.empty())
108 : {
109 0 : sal_Int32 nIndex2 = 0;
110 0 : sal_Int32 nParaLen = rEE.GetTextLen(nPara);
111 0 : for (size_t nAttr = 0; nAttr < aTempCharAttribs.size(); ++nAttr)
112 : {
113 0 : if (nIndex2 < aTempCharAttribs[nAttr].nStart)
114 : {
115 : EECharAttrib aEEAttr;
116 0 : aEEAttr.nStart = nIndex2;
117 0 : aEEAttr.nEnd = aTempCharAttribs[nAttr].nStart;
118 0 : aCharAttribs.insert(aCharAttribs.begin() + nAttr, aEEAttr);
119 : }
120 0 : nIndex2 = aTempCharAttribs[nAttr].nEnd;
121 0 : aCharAttribs.push_back(aTempCharAttribs[nAttr]);
122 : }
123 0 : if ( nIndex2 != nParaLen )
124 : {
125 : EECharAttrib aEEAttr;
126 0 : aEEAttr.nStart = nIndex2;
127 0 : aEEAttr.nEnd = nParaLen;
128 0 : aCharAttribs.push_back(aEEAttr);
129 : }
130 : }
131 : // find closest index in front of nIndex
132 : sal_Int32 nCurrIndex;
133 0 : sal_Int32 nClosestStartIndex_s = 0, nClosestStartIndex_e = 0;
134 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
135 : {
136 0 : nCurrIndex = i->nStart;
137 :
138 0 : if( nCurrIndex > nClosestStartIndex_s &&
139 : nCurrIndex <= nIndex)
140 : {
141 0 : nClosestStartIndex_s = nCurrIndex;
142 : }
143 0 : nCurrIndex = i->nEnd;
144 0 : if ( nCurrIndex > nClosestStartIndex_e &&
145 : nCurrIndex < nIndex )
146 : {
147 0 : nClosestStartIndex_e = nCurrIndex;
148 : }
149 : }
150 0 : sal_Int32 nClosestStartIndex = nClosestStartIndex_s > nClosestStartIndex_e ? nClosestStartIndex_s : nClosestStartIndex_e;
151 :
152 : // find closest index behind of nIndex
153 : sal_Int32 nClosestEndIndex_s, nClosestEndIndex_e;
154 0 : nClosestEndIndex_s = nClosestEndIndex_e = rEE.GetTextLen(nPara);
155 0 : for(std::vector<EECharAttrib>::iterator i = aCharAttribs.begin(); i < aCharAttribs.end(); ++i)
156 : {
157 0 : nCurrIndex = i->nEnd;
158 :
159 0 : if( nCurrIndex > nIndex &&
160 : nCurrIndex < nClosestEndIndex_e )
161 : {
162 0 : nClosestEndIndex_e = nCurrIndex;
163 : }
164 0 : nCurrIndex = i->nStart;
165 0 : if ( nCurrIndex > nIndex &&
166 : nCurrIndex < nClosestEndIndex_s)
167 : {
168 0 : nClosestEndIndex_s = nCurrIndex;
169 : }
170 : }
171 0 : sal_Int32 nClosestEndIndex = nClosestEndIndex_s < nClosestEndIndex_e ? nClosestEndIndex_s : nClosestEndIndex_e;
172 :
173 0 : nStartIndex = nClosestStartIndex;
174 0 : nEndIndex = nClosestEndIndex;
175 :
176 0 : if ( bInCell )
177 : {
178 0 : EPosition aStartPos( nPara, nStartIndex ), aEndPos( nPara, nEndIndex );
179 0 : sal_Int32 nParaCount = rEE.GetParagraphCount();
180 0 : sal_Int32 nCrrntParaLen = rEE.GetTextLen(nPara);
181 : //need to find closest index in front of nIndex in the previous paragraphs
182 0 : if ( aStartPos.nIndex == 0 )
183 : {
184 0 : SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, 0, 1, GetAttribsFlags::CHARATTRIBS );
185 0 : for ( sal_Int32 nParaIdx = nPara-1; nParaIdx >= 0; nParaIdx-- )
186 : {
187 0 : sal_uInt32 nLen = rEE.GetTextLen(nParaIdx);
188 0 : if ( nLen )
189 : {
190 : sal_Int32 nStartIdx, nEndIdx;
191 0 : GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, nLen, false );
192 0 : SfxItemSet aSet = rEE.GetAttribs( nParaIdx, nLen-1, nLen, GetAttribsFlags::CHARATTRIBS );
193 0 : if ( aSet == aCrrntSet )
194 : {
195 0 : aStartPos.nPara = nParaIdx;
196 0 : aStartPos.nIndex = nStartIdx;
197 0 : if ( aStartPos.nIndex != 0 )
198 : {
199 0 : break;
200 : }
201 0 : }
202 : }
203 0 : }
204 : }
205 : //need find closest index behind nIndex in the following paragrphs
206 0 : if ( aEndPos.nIndex == nCrrntParaLen )
207 : {
208 0 : SfxItemSet aCrrntSet = rEE.GetAttribs( nPara, nCrrntParaLen-1, nCrrntParaLen, GetAttribsFlags::CHARATTRIBS );
209 0 : for ( sal_Int32 nParaIdx = nPara+1; nParaIdx < nParaCount; nParaIdx++ )
210 : {
211 0 : sal_Int32 nLen = rEE.GetTextLen( nParaIdx );
212 0 : if ( nLen )
213 : {
214 : sal_Int32 nStartIdx, nEndIdx;
215 0 : GetAttributeRun( nStartIdx, nEndIdx, rEE, nParaIdx, 0, false );
216 0 : SfxItemSet aSet = rEE.GetAttribs( nParaIdx, 0, 1, GetAttribsFlags::CHARATTRIBS );
217 0 : if ( aSet == aCrrntSet )
218 : {
219 0 : aEndPos.nPara = nParaIdx;
220 0 : aEndPos.nIndex = nEndIdx;
221 0 : if ( aEndPos.nIndex != nLen )
222 : {
223 0 : break;
224 : }
225 0 : }
226 : }
227 0 : }
228 : }
229 0 : nStartIndex = 0;
230 0 : if ( aStartPos.nPara > 0 )
231 : {
232 0 : for ( sal_Int32 i = 0; i < aStartPos.nPara; i++ )
233 : {
234 0 : nStartIndex += rEE.GetTextLen(i)+1;
235 : }
236 : }
237 0 : nStartIndex += aStartPos.nIndex;
238 0 : nEndIndex = 0;
239 0 : if ( aEndPos.nPara > 0 )
240 : {
241 0 : for ( sal_Int32 i = 0; i < aEndPos.nPara; i++ )
242 : {
243 0 : nEndIndex += rEE.GetTextLen(i)+1;
244 : }
245 : }
246 0 : nEndIndex += aEndPos.nIndex;
247 : }
248 :
249 0 : return true;
250 : }
251 :
252 0 : Point SvxEditSourceHelper::EEToUserSpace( const Point& rPoint, const Size& rEESize, bool bIsVertical )
253 : {
254 0 : return bIsVertical ? Point( -rPoint.Y() + rEESize.Height(), rPoint.X() ) : rPoint;
255 : }
256 :
257 11 : Point SvxEditSourceHelper::UserSpaceToEE( const Point& rPoint, const Size& rEESize, bool bIsVertical )
258 : {
259 11 : return bIsVertical ? Point( rPoint.Y(), -rPoint.X() + rEESize.Height() ) : rPoint;
260 : }
261 :
262 21 : Rectangle SvxEditSourceHelper::EEToUserSpace( const Rectangle& rRect, const Size& rEESize, bool bIsVertical )
263 : {
264 21 : return bIsVertical ? Rectangle( EEToUserSpace(rRect.BottomLeft(), rEESize, bIsVertical),
265 42 : EEToUserSpace(rRect.TopRight(), rEESize, bIsVertical) ) : rRect;
266 : }
267 :
268 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|