Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "scitems.hxx"
30 : : #include <comphelper/string.hxx>
31 : : #include <editeng/eeitem.hxx>
32 : :
33 : : #include <svx/algitem.hxx>
34 : : #include <svtools/colorcfg.hxx>
35 : : #include <editeng/editview.hxx>
36 : : #include <editeng/editstat.hxx>
37 : : #include <editeng/escpitem.hxx>
38 : : #include <editeng/flditem.hxx>
39 : : #include <editeng/numitem.hxx>
40 : : #include <editeng/justifyitem.hxx>
41 : : #include <vcl/svapp.hxx>
42 : : #include <vcl/outdev.hxx>
43 : : #include <svl/inethist.hxx>
44 : : #include <unotools/syslocale.hxx>
45 : :
46 : : #include <com/sun/star/text/textfield/Type.hpp>
47 : : #include <com/sun/star/document/XDocumentProperties.hpp>
48 : :
49 : : #include "editutil.hxx"
50 : : #include "global.hxx"
51 : : #include "attrib.hxx"
52 : : #include "document.hxx"
53 : : #include "docpool.hxx"
54 : : #include "patattr.hxx"
55 : : #include "scmod.hxx"
56 : : #include "inputopt.hxx"
57 : : #include "compiler.hxx"
58 : :
59 : : using namespace com::sun::star;
60 : :
61 : : // STATIC DATA -----------------------------------------------------------
62 : :
63 : : // Delimiters zusaetzlich zu EditEngine-Default:
64 : :
65 : : const sal_Char ScEditUtil::pCalcDelimiters[] = "=()+-*/^&<>";
66 : :
67 : :
68 : : //------------------------------------------------------------------------
69 : :
70 : 2548 : String ScEditUtil::ModifyDelimiters( const String& rOld )
71 : : {
72 : : // underscore is used in function argument names
73 [ + - ]: 2548 : String aRet = comphelper::string::remove(rOld, '_');
74 [ + - ]: 2548 : aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( pCalcDelimiters ) );
75 [ + - ][ + - ]: 2548 : aRet.Append(ScCompiler::GetNativeSymbol(ocSep)); // argument separator is localized.
76 : 2548 : return aRet;
77 : : }
78 : :
79 : 941 : static String lcl_GetDelimitedString( const EditEngine& rEngine, const sal_Char c )
80 : : {
81 : 941 : String aRet;
82 [ + - ]: 941 : sal_uInt16 nParCount = rEngine.GetParagraphCount();
83 [ + + ]: 1971 : for (sal_uInt16 nPar=0; nPar<nParCount; nPar++)
84 : : {
85 [ + + ]: 1030 : if (nPar > 0)
86 [ + - ]: 89 : aRet += c;
87 [ + - ][ + - ]: 1030 : aRet += rEngine.GetText( nPar );
[ + - ]
88 : : }
89 : 941 : return aRet;
90 : : }
91 : :
92 : 576 : String ScEditUtil::GetSpaceDelimitedString( const EditEngine& rEngine )
93 : : {
94 : 576 : return lcl_GetDelimitedString(rEngine, ' ');
95 : : }
96 : :
97 : 365 : String ScEditUtil::GetMultilineString( const EditEngine& rEngine )
98 : : {
99 : 365 : return lcl_GetDelimitedString(rEngine, '\n');
100 : : }
101 : :
102 : : //------------------------------------------------------------------------
103 : :
104 : 0 : Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, sal_Bool bForceToTop )
105 : : {
106 : : // bForceToTop = always align to top, for editing
107 : : // (sal_False for querying URLs etc.)
108 : :
109 [ # # ]: 0 : if (!pPattern)
110 [ # # ]: 0 : pPattern = pDoc->GetPattern( nCol, nRow, nTab );
111 : :
112 : 0 : Point aStartPos = aScrPos;
113 : :
114 [ # # ]: 0 : sal_Bool bLayoutRTL = pDoc->IsLayoutRTL( nTab );
115 [ # # ]: 0 : long nLayoutSign = bLayoutRTL ? -1 : 1;
116 : :
117 [ # # ]: 0 : const ScMergeAttr* pMerge = (const ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
118 [ # # ]: 0 : long nCellX = (long) ( pDoc->GetColWidth(nCol,nTab) * nPPTX );
119 [ # # ]: 0 : if ( pMerge->GetColMerge() > 1 )
120 : : {
121 : 0 : SCCOL nCountX = pMerge->GetColMerge();
122 [ # # ]: 0 : for (SCCOL i=1; i<nCountX; i++)
123 [ # # ]: 0 : nCellX += (long) ( pDoc->GetColWidth(nCol+i,nTab) * nPPTX );
124 : : }
125 [ # # ]: 0 : long nCellY = (long) ( pDoc->GetRowHeight(nRow,nTab) * nPPTY );
126 [ # # ]: 0 : if ( pMerge->GetRowMerge() > 1 )
127 : : {
128 : 0 : SCROW nCountY = pMerge->GetRowMerge();
129 [ # # ]: 0 : nCellY += (long) pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY);
130 : : }
131 : :
132 [ # # ]: 0 : const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
133 : 0 : sal_uInt16 nIndent = 0;
134 [ # # ][ # # ]: 0 : if ( ((const SvxHorJustifyItem&)pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue() ==
135 : : SVX_HOR_JUSTIFY_LEFT )
136 [ # # ]: 0 : nIndent = ((const SfxUInt16Item&)pPattern->GetItem(ATTR_INDENT)).GetValue();
137 : 0 : long nPixDifX = (long) ( ( pMargin->GetLeftMargin() + nIndent ) * nPPTX );
138 : 0 : aStartPos.X() += nPixDifX * nLayoutSign;
139 : 0 : nCellX -= nPixDifX + (long) ( pMargin->GetRightMargin() * nPPTX ); // wegen Umbruch etc.
140 : :
141 : : // vertikale Position auf die in der Tabelle anpassen
142 : :
143 : : long nPixDifY;
144 : 0 : long nTopMargin = (long) ( pMargin->GetTopMargin() * nPPTY );
145 : : SvxCellVerJustify eJust = (SvxCellVerJustify) ((const SvxVerJustifyItem&)pPattern->
146 [ # # ]: 0 : GetItem(ATTR_VER_JUSTIFY)).GetValue();
147 : :
148 : : // asian vertical is always edited top-aligned
149 [ # # ]: 0 : sal_Bool bAsianVertical = ((const SfxBoolItem&)pPattern->GetItem( ATTR_STACKED )).GetValue() &&
150 [ # # ][ # # ]: 0 : ((const SfxBoolItem&)pPattern->GetItem( ATTR_VERTICAL_ASIAN )).GetValue();
[ # # ]
151 : :
152 [ # # ]: 0 : if ( eJust == SVX_VER_JUSTIFY_TOP ||
[ # # # # ]
[ # # ][ # # ]
153 [ # # ][ # # ]: 0 : ( bForceToTop && ( SC_MOD()->GetInputOptions().GetTextWysiwyg() || bAsianVertical ) ) )
154 : 0 : nPixDifY = nTopMargin;
155 : : else
156 : : {
157 [ # # ]: 0 : MapMode aMode = pDev->GetMapMode();
158 [ # # ][ # # ]: 0 : pDev->SetMapMode( MAP_PIXEL );
[ # # ]
159 : :
160 : : long nTextHeight = pDoc->GetNeededSize( nCol, nRow, nTab,
161 [ # # ]: 0 : pDev, nPPTX, nPPTY, aZoomX, aZoomY, false );
162 [ # # ]: 0 : if (!nTextHeight)
163 : : { // leere Zelle
164 [ # # ]: 0 : Font aFont;
165 : : // font color doesn't matter here
166 [ # # ]: 0 : pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &aZoomY );
167 [ # # ]: 0 : pDev->SetFont(aFont);
168 [ # # ]: 0 : nTextHeight = pDev->GetTextHeight() + nTopMargin +
169 [ # # ]: 0 : (long) ( pMargin->GetBottomMargin() * nPPTY );
170 : : }
171 : :
172 [ # # ]: 0 : pDev->SetMapMode(aMode);
173 : :
174 [ # # ][ # # ]: 0 : if ( nTextHeight > nCellY + nTopMargin || bForceToTop )
175 : 0 : nPixDifY = 0; // zu gross -> oben anfangen
176 : : else
177 : : {
178 [ # # ]: 0 : if ( eJust == SVX_VER_JUSTIFY_CENTER )
179 : 0 : nPixDifY = nTopMargin + ( nCellY - nTextHeight ) / 2;
180 : : else
181 : 0 : nPixDifY = nCellY - nTextHeight + nTopMargin; // JUSTIFY_BOTTOM
182 [ # # ]: 0 : }
183 : : }
184 : :
185 : 0 : aStartPos.Y() += nPixDifY;
186 : 0 : nCellY -= nPixDifY;
187 : :
188 [ # # ]: 0 : if ( bLayoutRTL )
189 : 0 : aStartPos.X() -= nCellX - 2; // excluding grid on both sides
190 : :
191 : : // -1 -> Gitter nicht ueberschreiben
192 [ # # ]: 0 : return Rectangle( aStartPos, Size(nCellX-1,nCellY-1) );
193 : : }
194 : :
195 : : //------------------------------------------------------------------------
196 : :
197 : 262 : ScEditAttrTester::ScEditAttrTester( ScEditEngineDefaulter* pEng ) :
198 : : pEngine( pEng ),
199 : : pEditAttrs( NULL ),
200 : : bNeedsObject( false ),
201 : 262 : bNeedsCellAttr( false )
202 : : {
203 [ + + ]: 262 : if ( pEngine->GetParagraphCount() > 1 )
204 : : {
205 : 27 : bNeedsObject = sal_True; //! Zellatribute finden ?
206 : : }
207 : : else
208 : : {
209 : 235 : const SfxPoolItem* pItem = NULL;
210 : : pEditAttrs = new SfxItemSet( pEngine->GetAttribs(
211 [ + - ][ + - ]: 235 : ESelection(0,0,0,pEngine->GetTextLen(0)), EditEngineAttribs_OnlyHard ) );
[ + - ]
212 [ + - ]: 235 : const SfxItemSet& rEditDefaults = pEngine->GetDefaults();
213 : :
214 [ + + ][ + + ]: 4591 : for (sal_uInt16 nId = EE_CHAR_START; nId <= EE_CHAR_END && !bNeedsObject; nId++)
[ + + ]
215 : : {
216 [ + - ]: 4356 : SfxItemState eState = pEditAttrs->GetItemState( nId, false, &pItem );
217 [ + + ]: 4356 : if (eState == SFX_ITEM_DONTCARE)
218 : 3 : bNeedsObject = sal_True;
219 [ + + ]: 4353 : else if (eState == SFX_ITEM_SET)
220 : : {
221 [ + + ][ + - ]: 1585 : if ( nId == EE_CHAR_ESCAPEMENT || nId == EE_CHAR_PAIRKERNING ||
[ + - ][ - + ]
222 : : nId == EE_CHAR_KERNING || nId == EE_CHAR_XMLATTRIBS )
223 : : {
224 : : // Escapement and kerning are kept in EditEngine because there are no
225 : : // corresponding cell format items. User defined attributes are kept in
226 : : // EditEngine because "user attributes applied to all the text" is different
227 : : // from "user attributes applied to the cell".
228 : :
229 [ + - ][ + - ]: 276 : if ( *pItem != rEditDefaults.Get(nId) )
[ + - ]
230 : 138 : bNeedsObject = sal_True;
231 : : }
232 : : else
233 [ + + ]: 1447 : if (!bNeedsCellAttr)
234 [ + - ][ + - ]: 165 : if ( *pItem != rEditDefaults.Get(nId) )
[ + - ]
235 : 1585 : bNeedsCellAttr = sal_True;
236 : : // rEditDefaults contains the defaults from the cell format
237 : : }
238 : : }
239 : :
240 : : // Feldbefehle enthalten?
241 : :
242 [ + - ]: 235 : SfxItemState eFieldState = pEditAttrs->GetItemState( EE_FEATURE_FIELD, false );
243 [ + + ][ + + ]: 235 : if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET )
244 : 32 : bNeedsObject = sal_True;
245 : :
246 : : // not converted characters?
247 : :
248 [ + - ]: 235 : SfxItemState eConvState = pEditAttrs->GetItemState( EE_FEATURE_NOTCONV, false );
249 [ + - ][ - + ]: 235 : if ( eConvState == SFX_ITEM_DONTCARE || eConvState == SFX_ITEM_SET )
250 : 235 : bNeedsObject = sal_True;
251 : : }
252 : 262 : }
253 : :
254 : 262 : ScEditAttrTester::~ScEditAttrTester()
255 : : {
256 [ + + ]: 262 : delete pEditAttrs;
257 : 262 : }
258 : :
259 : :
260 : : //------------------------------------------------------------------------
261 : :
262 : 6973 : ScEnginePoolHelper::ScEnginePoolHelper( SfxItemPool* pEnginePoolP,
263 : : sal_Bool bDeleteEnginePoolP )
264 : : :
265 : : pEnginePool( pEnginePoolP ),
266 : : pDefaults( NULL ),
267 : : bDeleteEnginePool( bDeleteEnginePoolP ),
268 : 6973 : bDeleteDefaults( false )
269 : : {
270 : 6973 : }
271 : :
272 : :
273 : 176 : ScEnginePoolHelper::ScEnginePoolHelper( const ScEnginePoolHelper& rOrg )
274 : : :
275 : 73 : pEnginePool( rOrg.bDeleteEnginePool ? rOrg.pEnginePool->Clone() : rOrg.pEnginePool ),
276 : : pDefaults( NULL ),
277 : : bDeleteEnginePool( rOrg.bDeleteEnginePool ),
278 [ + + ]: 176 : bDeleteDefaults( false )
279 : : {
280 : 176 : }
281 : :
282 : :
283 : 7145 : ScEnginePoolHelper::~ScEnginePoolHelper()
284 : : {
285 [ + + ]: 7145 : if ( bDeleteDefaults )
286 [ + - ]: 1624 : delete pDefaults;
287 [ + + ]: 7145 : if ( bDeleteEnginePool )
288 : 4102 : SfxItemPool::Free(pEnginePool);
289 [ - + ]: 7145 : }
290 : :
291 : :
292 : : //------------------------------------------------------------------------
293 : :
294 : 6973 : ScEditEngineDefaulter::ScEditEngineDefaulter( SfxItemPool* pEnginePoolP,
295 : : sal_Bool bDeleteEnginePoolP )
296 : : :
297 : : ScEnginePoolHelper( pEnginePoolP, bDeleteEnginePoolP ),
298 [ + - ]: 6973 : EditEngine( pEnginePoolP )
299 : : {
300 : : // All EditEngines use ScGlobal::GetEditDefaultLanguage as DefaultLanguage.
301 : : // DefaultLanguage for InputHandler's EditEngine is updated later.
302 : :
303 [ + - ][ + - ]: 6973 : SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
304 : 6973 : }
305 : :
306 : :
307 : 176 : ScEditEngineDefaulter::ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg )
308 : : :
309 : : ScEnginePoolHelper( rOrg ),
310 [ + - ]: 176 : EditEngine( pEnginePool )
311 : : {
312 [ + - ][ + - ]: 176 : SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
313 : 176 : }
314 : :
315 : :
316 [ + - ]: 7145 : ScEditEngineDefaulter::~ScEditEngineDefaulter()
317 : : {
318 [ - + ]: 7569 : }
319 : :
320 : :
321 : 15563 : void ScEditEngineDefaulter::SetDefaults( const SfxItemSet& rSet, sal_Bool bRememberCopy )
322 : : {
323 [ + + ]: 15563 : if ( bRememberCopy )
324 : : {
325 [ + + ]: 1105 : if ( bDeleteDefaults )
326 [ + - ]: 79 : delete pDefaults;
327 [ + - ]: 1105 : pDefaults = new SfxItemSet( rSet );
328 : 1105 : bDeleteDefaults = sal_True;
329 : : }
330 [ + + ]: 15563 : const SfxItemSet& rNewSet = bRememberCopy ? *pDefaults : rSet;
331 : 15563 : sal_Bool bUndo = IsUndoEnabled();
332 : 15563 : EnableUndo( false );
333 : 15563 : sal_Bool bUpdateMode = GetUpdateMode();
334 [ + + ]: 15563 : if ( bUpdateMode )
335 : 5656 : SetUpdateMode( false );
336 : 15563 : sal_uInt16 nPara = GetParagraphCount();
337 [ + + ]: 31303 : for ( sal_uInt16 j=0; j<nPara; j++ )
338 : : {
339 : 15740 : SetParaAttribs( j, rNewSet );
340 : : }
341 [ + + ]: 15563 : if ( bUpdateMode )
342 : 5656 : SetUpdateMode( sal_True );
343 [ + + ]: 15563 : if ( bUndo )
344 : 11198 : EnableUndo( sal_True );
345 : 15563 : }
346 : :
347 : :
348 : 6306 : void ScEditEngineDefaulter::SetDefaults( SfxItemSet* pSet, sal_Bool bTakeOwnership )
349 : : {
350 [ + + ]: 6306 : if ( bDeleteDefaults )
351 [ + - ]: 2950 : delete pDefaults;
352 : 6306 : pDefaults = pSet;
353 : 6306 : bDeleteDefaults = bTakeOwnership;
354 [ + - ]: 6306 : if ( pDefaults )
355 : 6306 : SetDefaults( *pDefaults, false );
356 : 6306 : }
357 : :
358 : :
359 : 861 : void ScEditEngineDefaulter::SetDefaultItem( const SfxPoolItem& rItem )
360 : : {
361 [ - + ]: 861 : if ( !pDefaults )
362 : : {
363 [ # # ]: 0 : pDefaults = new SfxItemSet( GetEmptyItemSet() );
364 : 0 : bDeleteDefaults = sal_True;
365 : : }
366 : 861 : pDefaults->Put( rItem );
367 : 861 : SetDefaults( *pDefaults, false );
368 : 861 : }
369 : :
370 : 235 : const SfxItemSet& ScEditEngineDefaulter::GetDefaults()
371 : : {
372 [ - + ]: 235 : if ( !pDefaults )
373 : : {
374 [ # # ]: 0 : pDefaults = new SfxItemSet( GetEmptyItemSet() );
375 : 0 : bDeleteDefaults = sal_True;
376 : : }
377 : 235 : return *pDefaults;
378 : : }
379 : :
380 : 1759 : void ScEditEngineDefaulter::SetText( const EditTextObject& rTextObject )
381 : : {
382 : 1759 : sal_Bool bUpdateMode = GetUpdateMode();
383 [ + + ]: 1759 : if ( bUpdateMode )
384 : 1456 : SetUpdateMode( false );
385 : 1759 : EditEngine::SetText( rTextObject );
386 [ + + ]: 1759 : if ( pDefaults )
387 : 1505 : SetDefaults( *pDefaults, false );
388 [ + + ]: 1759 : if ( bUpdateMode )
389 : 1456 : SetUpdateMode( sal_True );
390 : 1759 : }
391 : :
392 : 2674 : void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
393 : : const SfxItemSet& rSet, sal_Bool bRememberCopy )
394 : : {
395 : 2674 : sal_Bool bUpdateMode = GetUpdateMode();
396 [ + + ]: 2674 : if ( bUpdateMode )
397 : 2668 : SetUpdateMode( false );
398 : 2674 : EditEngine::SetText( rTextObject );
399 : 2674 : SetDefaults( rSet, bRememberCopy );
400 [ + + ]: 2674 : if ( bUpdateMode )
401 : 2668 : SetUpdateMode( sal_True );
402 : 2674 : }
403 : :
404 : 740 : void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
405 : : SfxItemSet* pSet, sal_Bool bTakeOwnership )
406 : : {
407 : 740 : sal_Bool bUpdateMode = GetUpdateMode();
408 [ - + ]: 740 : if ( bUpdateMode )
409 : 0 : SetUpdateMode( false );
410 : 740 : EditEngine::SetText( rTextObject );
411 : 740 : SetDefaults( pSet, bTakeOwnership );
412 [ - + ]: 740 : if ( bUpdateMode )
413 : 0 : SetUpdateMode( sal_True );
414 : 740 : }
415 : :
416 : :
417 : 7681 : void ScEditEngineDefaulter::SetText( const String& rText )
418 : : {
419 : 7681 : sal_Bool bUpdateMode = GetUpdateMode();
420 [ + + ]: 7681 : if ( bUpdateMode )
421 : 4721 : SetUpdateMode( false );
422 : 7681 : EditEngine::SetText( rText );
423 [ + + ]: 7681 : if ( pDefaults )
424 : 3176 : SetDefaults( *pDefaults, false );
425 [ + + ]: 7681 : if ( bUpdateMode )
426 : 4721 : SetUpdateMode( sal_True );
427 : 7681 : }
428 : :
429 : 59 : void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
430 : : const SfxItemSet& rSet, sal_Bool bRememberCopy )
431 : : {
432 : 59 : sal_Bool bUpdateMode = GetUpdateMode();
433 [ + - ]: 59 : if ( bUpdateMode )
434 : 59 : SetUpdateMode( false );
435 : 59 : EditEngine::SetText( rText );
436 : 59 : SetDefaults( rSet, bRememberCopy );
437 [ + - ]: 59 : if ( bUpdateMode )
438 : 59 : SetUpdateMode( sal_True );
439 : 59 : }
440 : :
441 : 325 : void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
442 : : SfxItemSet* pSet, sal_Bool bTakeOwnership )
443 : : {
444 : 325 : sal_Bool bUpdateMode = GetUpdateMode();
445 [ - + ]: 325 : if ( bUpdateMode )
446 : 0 : SetUpdateMode( false );
447 : 325 : EditEngine::SetText( rText );
448 : 325 : SetDefaults( pSet, bTakeOwnership );
449 [ - + ]: 325 : if ( bUpdateMode )
450 : 0 : SetUpdateMode( sal_True );
451 : 325 : }
452 : :
453 : 0 : void ScEditEngineDefaulter::RepeatDefaults()
454 : : {
455 [ # # ]: 0 : if ( pDefaults )
456 : : {
457 : 0 : sal_uInt16 nPara = GetParagraphCount();
458 [ # # ]: 0 : for ( sal_uInt16 j=0; j<nPara; j++ )
459 : 0 : SetParaAttribs( j, *pDefaults );
460 : : }
461 : 0 : }
462 : :
463 : 0 : void ScEditEngineDefaulter::RemoveParaAttribs()
464 : : {
465 : 0 : SfxItemSet* pCharItems = NULL;
466 : 0 : sal_Bool bUpdateMode = GetUpdateMode();
467 [ # # ]: 0 : if ( bUpdateMode )
468 : 0 : SetUpdateMode( false );
469 : 0 : sal_uInt16 nParCount = GetParagraphCount();
470 [ # # ]: 0 : for (sal_uInt16 nPar=0; nPar<nParCount; nPar++)
471 : : {
472 : 0 : const SfxItemSet& rParaAttribs = GetParaAttribs( nPar );
473 : : sal_uInt16 nWhich;
474 [ # # ]: 0 : for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
475 : : {
476 : : const SfxPoolItem* pParaItem;
477 [ # # ][ # # ]: 0 : if ( rParaAttribs.GetItemState( nWhich, false, &pParaItem ) == SFX_ITEM_SET )
478 : : {
479 : : // if defaults are set, use only items that are different from default
480 [ # # ][ # # ]: 0 : if ( !pDefaults || *pParaItem != pDefaults->Get(nWhich) )
[ # # ][ # # ]
[ # # ]
481 : : {
482 [ # # ]: 0 : if (!pCharItems)
483 [ # # ][ # # ]: 0 : pCharItems = new SfxItemSet( GetEmptyItemSet() );
[ # # ]
484 [ # # ]: 0 : pCharItems->Put( *pParaItem );
485 : : }
486 : : }
487 : : }
488 : :
489 [ # # ]: 0 : if ( pCharItems )
490 : : {
491 [ # # ]: 0 : std::vector<sal_uInt16> aPortions;
492 [ # # ]: 0 : GetPortions( nPar, aPortions );
493 : :
494 : : // loop through the portions of the paragraph, and set only those items
495 : : // that are not overridden by existing character attributes
496 : :
497 : 0 : sal_uInt16 nStart = 0;
498 [ # # ][ # # ]: 0 : for ( std::vector<sal_uInt16>::const_iterator it(aPortions.begin()); it != aPortions.end(); ++it )
[ # # ][ # # ]
499 : : {
500 [ # # ]: 0 : sal_uInt16 nEnd = *it;
501 : 0 : ESelection aSel( nPar, nStart, nPar, nEnd );
502 [ # # ]: 0 : SfxItemSet aOldCharAttrs = GetAttribs( aSel );
503 [ # # ]: 0 : SfxItemSet aNewCharAttrs = *pCharItems;
504 [ # # ]: 0 : for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
505 : : {
506 : : // Clear those items that are different from existing character attributes.
507 : : // Where no character attributes are set, GetAttribs returns the paragraph attributes.
508 : : const SfxPoolItem* pItem;
509 [ # # ][ # # ]: 0 : if ( aNewCharAttrs.GetItemState( nWhich, false, &pItem ) == SFX_ITEM_SET &&
[ # # ][ # # ]
510 [ # # ][ # # ]: 0 : *pItem != aOldCharAttrs.Get(nWhich) )
511 : : {
512 [ # # ]: 0 : aNewCharAttrs.ClearItem(nWhich);
513 : : }
514 : : }
515 [ # # ]: 0 : if ( aNewCharAttrs.Count() )
516 [ # # ]: 0 : QuickSetAttribs( aNewCharAttrs, aSel );
517 : :
518 : 0 : nStart = nEnd;
519 [ # # ][ # # ]: 0 : }
520 : :
521 [ # # ][ # # ]: 0 : DELETEZ( pCharItems );
522 : : }
523 : :
524 [ # # ]: 0 : if ( rParaAttribs.Count() )
525 : : {
526 : : // clear all paragraph attributes (including defaults),
527 : : // so they are not contained in resulting EditTextObjects
528 : :
529 [ # # ]: 0 : SetParaAttribs( nPar, SfxItemSet( *rParaAttribs.GetPool(), rParaAttribs.GetRanges() ) );
530 : : }
531 : : }
532 [ # # ]: 0 : if ( bUpdateMode )
533 : 0 : SetUpdateMode( sal_True );
534 : 0 : }
535 : :
536 : : //------------------------------------------------------------------------
537 : :
538 : 1913 : ScTabEditEngine::ScTabEditEngine( ScDocument* pDoc )
539 : 1913 : : ScEditEngineDefaulter( pDoc->GetEnginePool() )
540 : : {
541 [ + - ][ + - ]: 1913 : SetEditTextObjectPool( pDoc->GetEditPool() );
542 [ + - ][ + - ]: 1913 : Init((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
[ + - ]
543 : 1913 : }
544 : :
545 : 3 : ScTabEditEngine::ScTabEditEngine( const ScPatternAttr& rPattern,
546 : : SfxItemPool* pEnginePoolP, SfxItemPool* pTextObjectPool )
547 : 3 : : ScEditEngineDefaulter( pEnginePoolP )
548 : : {
549 [ - + ]: 3 : if ( pTextObjectPool )
550 [ # # ]: 0 : SetEditTextObjectPool( pTextObjectPool );
551 [ + - ]: 3 : Init( rPattern );
552 : 3 : }
553 : :
554 : 1916 : void ScTabEditEngine::Init( const ScPatternAttr& rPattern )
555 : : {
556 [ + - ]: 1916 : SetRefMapMode(MAP_100TH_MM);
557 [ + - ]: 1916 : SfxItemSet* pEditDefaults = new SfxItemSet( GetEmptyItemSet() );
558 : 1916 : rPattern.FillEditItemSet( pEditDefaults );
559 : 1916 : SetDefaults( pEditDefaults );
560 : : // wir haben keine StyleSheets fuer Text
561 : 1916 : SetControlWord( GetControlWord() & ~EE_CNTRL_RTFSTYLESHEETS );
562 : 1916 : }
563 : :
564 : : //------------------------------------------------------------------------
565 : : // Feldbefehle fuer Kopf- und Fusszeilen
566 : : //------------------------------------------------------------------------
567 : :
568 : : //
569 : : // Zahlen aus \sw\source\core\doc\numbers.cxx
570 : : //
571 : :
572 : 0 : String lcl_GetCharStr( sal_Int32 nNo )
573 : : {
574 : : OSL_ENSURE( nNo, "0 ist eine ungueltige Nummer !!" );
575 : 0 : String aStr;
576 : :
577 : 0 : const sal_Int32 coDiff = 'Z' - 'A' +1;
578 : : sal_Int32 nCalc;
579 : :
580 [ # # ]: 0 : do {
581 : 0 : nCalc = nNo % coDiff;
582 [ # # ]: 0 : if( !nCalc )
583 : 0 : nCalc = coDiff;
584 [ # # ]: 0 : aStr.Insert( (sal_Unicode)('a' - 1 + nCalc ), 0 );
585 : 0 : nNo = sal::static_int_cast<sal_Int32>( nNo - nCalc );
586 [ # # ]: 0 : if( nNo )
587 : 0 : nNo /= coDiff;
588 : : } while( nNo );
589 : 0 : return aStr;
590 : : }
591 : :
592 : 486 : String lcl_GetNumStr( sal_Int32 nNo, SvxNumType eType )
593 : : {
594 [ + - ]: 486 : String aTmpStr(rtl::OUString('0'));
595 [ + + ]: 486 : if( nNo )
596 : : {
597 [ - - - + ]: 232 : switch( eType )
598 : : {
599 : : case SVX_CHARS_UPPER_LETTER:
600 : : case SVX_CHARS_LOWER_LETTER:
601 [ # # ][ # # ]: 0 : aTmpStr = lcl_GetCharStr( nNo );
[ # # ]
602 : 0 : break;
603 : :
604 : : case SVX_ROMAN_UPPER:
605 : : case SVX_ROMAN_LOWER:
606 [ # # ]: 0 : if( nNo < 4000 )
607 [ # # ][ # # ]: 0 : aTmpStr = SvxNumberFormat::CreateRomanString( nNo, ( eType == SVX_ROMAN_UPPER ) );
[ # # ]
608 : : else
609 [ # # ]: 0 : aTmpStr.Erase();
610 : 0 : break;
611 : :
612 : : case SVX_NUMBER_NONE:
613 [ # # ]: 0 : aTmpStr.Erase();
614 : 0 : break;
615 : :
616 : : // CHAR_SPECIAL:
617 : : // ????
618 : :
619 : : // case ARABIC: ist jetzt default
620 : : default:
621 [ + - ][ + - ]: 232 : aTmpStr = String::CreateFromInt32( nNo );
[ + - ]
622 : 232 : break;
623 : : }
624 : :
625 [ - + ]: 232 : if( SVX_CHARS_UPPER_LETTER == eType )
626 [ # # ]: 0 : aTmpStr.ToUpperAscii();
627 : : }
628 : 486 : return aTmpStr;
629 : : }
630 : :
631 : 4721 : ScHeaderFieldData::ScHeaderFieldData()
632 : : :
633 : : aDate( Date::EMPTY ),
634 [ + - ][ + - ]: 4721 : aTime( Time::EMPTY )
[ + - ]
635 : : {
636 : 4721 : nPageNo = nTotalPages = 0;
637 : 4721 : eNumType = SVX_ARABIC;
638 : 4721 : }
639 : :
640 : 3515 : ScHeaderEditEngine::ScHeaderEditEngine( SfxItemPool* pEnginePoolP, sal_Bool bDeleteEnginePoolP )
641 [ + - ]: 3515 : : ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
642 : : {
643 : 3515 : }
644 : :
645 : 982 : String ScHeaderEditEngine::CalcFieldValue( const SvxFieldItem& rField,
646 : : sal_uInt16 /* nPara */, sal_uInt16 /* nPos */,
647 : : Color*& /* rTxtColor */, Color*& /* rFldColor */ )
648 : : {
649 : 982 : const SvxFieldData* pFieldData = rField.GetField();
650 [ - + ]: 982 : if (!pFieldData)
651 [ # # ]: 0 : return rtl::OUString("?");
652 : :
653 : 982 : rtl::OUString aRet;
654 [ + - ]: 982 : sal_Int32 nClsId = pFieldData->GetClassId();
655 [ + + + + : 982 : switch (nClsId)
- + + - ]
656 : : {
657 : : case text::textfield::Type::PAGE:
658 [ + - ][ + - ]: 464 : aRet = lcl_GetNumStr( aData.nPageNo,aData.eNumType );
[ + - ]
659 : 464 : break;
660 : : case text::textfield::Type::PAGES:
661 [ + - ][ + - ]: 22 : aRet = lcl_GetNumStr( aData.nTotalPages,aData.eNumType );
[ + - ]
662 : 22 : break;
663 : : case text::textfield::Type::TIME:
664 [ + - ]: 22 : aRet = ScGlobal::pLocaleData->getTime(aData.aTime);
665 : 22 : break;
666 : : case text::textfield::Type::DOCINFO_TITLE:
667 [ + - ]: 22 : aRet = aData.aTitle;
668 : 22 : break;
669 : : case text::textfield::Type::EXTENDED_FILE:
670 : : {
671 [ # # ]: 0 : switch (static_cast<const SvxExtFileField*>(pFieldData)->GetFormat())
672 : : {
673 : : case SVXFILEFORMAT_FULLPATH :
674 [ # # ]: 0 : aRet = aData.aLongDocName;
675 : 0 : break;
676 : : default:
677 [ # # ]: 0 : aRet = aData.aShortDocName;
678 : : }
679 : : }
680 : 0 : break;
681 : : case text::textfield::Type::TABLE:
682 [ + - ]: 430 : aRet = aData.aTabName;
683 : 430 : break;
684 : : case text::textfield::Type::DATE:
685 [ + - ]: 22 : aRet = ScGlobal::pLocaleData->getDate(aData.aDate);
686 : 22 : break;
687 : : default:
688 : 0 : aRet = "?";
689 : : }
690 : :
691 [ + - ]: 982 : return aRet;
692 : : }
693 : :
694 : : //------------------------------------------------------------------------
695 : : //
696 : : // Feld-Daten
697 : : //
698 : : //------------------------------------------------------------------------
699 : :
700 : 1009 : ScFieldEditEngine::ScFieldEditEngine(
701 : : ScDocument* pDoc, SfxItemPool* pEnginePoolP,
702 : : SfxItemPool* pTextObjectPool, bool bDeleteEnginePoolP) :
703 : : ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP ),
704 : 1009 : mpDoc(pDoc), bExecuteURL(true)
705 : : {
706 [ + + ]: 1009 : if ( pTextObjectPool )
707 [ + - ]: 604 : SetEditTextObjectPool( pTextObjectPool );
708 : : // EE_CNTRL_URLSFXEXECUTE nicht, weil die Edit-Engine den ViewFrame nicht kennt
709 : : // wir haben keine StyleSheets fuer Text
710 [ + - ][ + - ]: 1009 : SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );
711 : 1009 : }
712 : :
713 : 101 : String ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField,
714 : : sal_uInt16 /* nPara */, sal_uInt16 /* nPos */,
715 : : Color*& rTxtColor, Color*& /* rFldColor */ )
716 : : {
717 : 101 : rtl::OUString aRet;
718 : 101 : const SvxFieldData* pFieldData = rField.GetField();
719 : :
720 [ - + ]: 101 : if (!pFieldData)
721 [ # # ]: 0 : return rtl::OUString(" ");
722 : :
723 [ + - ]: 101 : sal_uInt16 nClsId = pFieldData->GetClassId();
724 [ + - - - : 101 : switch (nClsId)
- - ]
725 : : {
726 : : case text::textfield::Type::URL:
727 : : {
728 : 101 : const SvxURLField* pField = static_cast<const SvxURLField*>(pFieldData);
729 : 101 : rtl::OUString aURL = pField->GetURL();
730 : :
731 [ + - - ]: 101 : switch (pField->GetFormat())
732 : : {
733 : : case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
734 : : case SVXURLFORMAT_REPR:
735 : 101 : aRet = pField->GetRepresentation();
736 : 101 : break;
737 : : case SVXURLFORMAT_URL:
738 : 0 : aRet = aURL;
739 : 0 : break;
740 : : default:
741 : : ;
742 : : }
743 : :
744 : : svtools::ColorConfigEntry eEntry =
745 [ + - ][ + - ]: 101 : INetURLHistory::GetOrCreate()->QueryUrl(String(aURL)) ? svtools::LINKSVISITED : svtools::LINKS;
[ + - ][ - + ]
[ + - ]
746 [ + - ][ + - ]: 101 : rTxtColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor );
[ + - ][ + - ]
747 : : }
748 : 101 : break;
749 : : case text::textfield::Type::EXTENDED_TIME:
750 : : {
751 : 0 : const SvxExtTimeField* pField = static_cast<const SvxExtTimeField*>(pFieldData);
752 [ # # ]: 0 : if (mpDoc)
753 [ # # ][ # # ]: 0 : aRet = pField->GetFormatted(*mpDoc->GetFormatTable(), ScGlobal::eLnge);
754 : : }
755 : 0 : break;
756 : : case text::textfield::Type::DATE:
757 : : {
758 [ # # ]: 0 : Date aDate(Date::SYSTEM);
759 [ # # ]: 0 : aRet = ScGlobal::pLocaleData->getDate(aDate);
760 : : }
761 : 0 : break;
762 : : case text::textfield::Type::DOCINFO_TITLE:
763 : : {
764 : 0 : SfxObjectShell* pDocShell = mpDoc->GetDocumentShell();
765 [ # # ][ # # ]: 0 : aRet = pDocShell->getDocProperties()->getTitle();
[ # # ]
766 [ # # ]: 0 : if (aRet.isEmpty())
767 [ # # ][ # # ]: 0 : aRet = pDocShell->GetTitle();
[ # # ]
768 : : }
769 : 0 : break;
770 : : case text::textfield::Type::TABLE:
771 : : {
772 : 0 : const SvxTableField* pField = static_cast<const SvxTableField*>(pFieldData);
773 [ # # ]: 0 : SCTAB nTab = pField->GetTab();
774 : 0 : rtl::OUString aName;
775 [ # # ][ # # ]: 0 : if (mpDoc->GetName(nTab, aName))
776 : 0 : aRet = aName;
777 : : else
778 : 0 : aRet = "?";
779 : : }
780 : 0 : break;
781 : : default:
782 : 0 : aRet = "?";
783 : : }
784 : :
785 [ + + ]: 101 : if (aRet.isEmpty()) // leer ist baeh
786 : 17 : aRet = " "; // Space ist Default der Editengine
787 : :
788 [ + - ]: 101 : return aRet;
789 : : }
790 : :
791 : 0 : void ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField, sal_uInt16, sal_uInt16 )
792 : : {
793 : 0 : const SvxFieldData* pFld = rField.GetField();
794 : :
795 [ # # ][ # # ]: 0 : if ( pFld && pFld->ISA( SvxURLField ) && bExecuteURL )
[ # # ][ # # ]
796 : : {
797 : 0 : const SvxURLField* pURLField = (const SvxURLField*) pFld;
798 [ # # ][ # # ]: 0 : ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
[ # # ]
799 : : }
800 : 0 : }
801 : :
802 : : //------------------------------------------------------------------------
803 : :
804 : 7 : ScNoteEditEngine::ScNoteEditEngine( SfxItemPool* pEnginePoolP,
805 : : SfxItemPool* pTextObjectPool, sal_Bool bDeleteEnginePoolP ) :
806 : 7 : ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
807 : : {
808 [ + - ]: 7 : if ( pTextObjectPool )
809 [ + - ]: 7 : SetEditTextObjectPool( pTextObjectPool );
810 [ + - ][ + - ]: 7 : SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );
811 : 7 : }
812 : :
813 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|