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