merge the formfield patch from ooo-build
[ooovba.git] / sc / source / core / tool / editutil.cxx
blob524eaf1f894bbcecad48dc19d19e6983154128d4
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: editutil.cxx,v $
10 * $Revision: 1.33 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 // System - Includes -----------------------------------------------------
38 // INCLUDE ---------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <svx/eeitem.hxx>
43 #include <svx/algitem.hxx>
44 #include <svtools/colorcfg.hxx>
45 #include <svx/editview.hxx>
46 #include <svx/editstat.hxx>
47 #include <svx/escpitem.hxx>
48 #include <svx/flditem.hxx>
49 #include <svx/numitem.hxx>
50 #include <vcl/svapp.hxx>
51 #include <vcl/outdev.hxx>
52 #include <svtools/inethist.hxx>
53 #include <svtools/syslocale.hxx>
54 #ifndef _SVSTDARR_USHORTS
55 #define _SVSTDARR_USHORTS
56 #include <svtools/svstdarr.hxx>
57 #endif
59 #include "editutil.hxx"
60 #include "global.hxx"
61 #include "attrib.hxx"
62 #include "document.hxx"
63 #include "docpool.hxx"
64 #include "patattr.hxx"
65 #include "scmod.hxx"
66 #include "inputopt.hxx"
67 #include "compiler.hxx"
69 // STATIC DATA -----------------------------------------------------------
71 // Delimiters zusaetzlich zu EditEngine-Default:
73 const sal_Char __FAR_DATA ScEditUtil::pCalcDelimiters[] = "=()+-*/^&<>";
76 //------------------------------------------------------------------------
78 String ScEditUtil::ModifyDelimiters( const String& rOld )
80 String aRet = rOld;
81 aRet.EraseAllChars( '_' ); // underscore is used in function argument names
82 aRet.AppendAscii( RTL_CONSTASCII_STRINGPARAM( pCalcDelimiters ) );
83 aRet.Append(ScCompiler::GetNativeSymbol(ocSep)); // argument separator is localized.
84 return aRet;
87 static String lcl_GetDelimitedString( const EditEngine& rEngine, const sal_Char c )
89 String aRet;
90 USHORT nParCount = rEngine.GetParagraphCount();
91 for (USHORT nPar=0; nPar<nParCount; nPar++)
93 if (nPar > 0)
94 aRet += c;
95 aRet += rEngine.GetText( nPar );
97 return aRet;
100 String ScEditUtil::GetSpaceDelimitedString( const EditEngine& rEngine )
102 return lcl_GetDelimitedString(rEngine, ' ');
105 String ScEditUtil::GetMultilineString( const EditEngine& rEngine )
107 return lcl_GetDelimitedString(rEngine, '\n');
110 //------------------------------------------------------------------------
112 Rectangle ScEditUtil::GetEditArea( const ScPatternAttr* pPattern, BOOL bForceToTop )
114 // bForceToTop = always align to top, for editing
115 // (FALSE for querying URLs etc.)
117 if (!pPattern)
118 pPattern = pDoc->GetPattern( nCol, nRow, nTab );
120 Point aStartPos = aScrPos;
122 BOOL bLayoutRTL = pDoc->IsLayoutRTL( nTab );
123 long nLayoutSign = bLayoutRTL ? -1 : 1;
125 const ScMergeAttr* pMerge = (const ScMergeAttr*)&pPattern->GetItem(ATTR_MERGE);
126 long nCellX = (long) ( pDoc->GetColWidth(nCol,nTab) * nPPTX );
127 if ( pMerge->GetColMerge() > 1 )
129 SCCOL nCountX = pMerge->GetColMerge();
130 for (SCCOL i=1; i<nCountX; i++)
131 nCellX += (long) ( pDoc->GetColWidth(nCol+i,nTab) * nPPTX );
133 long nCellY = (long) ( pDoc->GetRowHeight(nRow,nTab) * nPPTY );
134 if ( pMerge->GetRowMerge() > 1 )
136 SCROW nCountY = pMerge->GetRowMerge();
137 nCellY += (long) pDoc->GetScaledRowHeight( nRow+1, nRow+nCountY-1, nTab, nPPTY);
140 const SvxMarginItem* pMargin = (const SvxMarginItem*)&pPattern->GetItem(ATTR_MARGIN);
141 USHORT nIndent = 0;
142 if ( ((const SvxHorJustifyItem&)pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue() ==
143 SVX_HOR_JUSTIFY_LEFT )
144 nIndent = ((const SfxUInt16Item&)pPattern->GetItem(ATTR_INDENT)).GetValue();
145 long nPixDifX = (long) ( ( pMargin->GetLeftMargin() + nIndent ) * nPPTX );
146 aStartPos.X() += nPixDifX * nLayoutSign;
147 nCellX -= nPixDifX + (long) ( pMargin->GetRightMargin() * nPPTX ); // wegen Umbruch etc.
149 // vertikale Position auf die in der Tabelle anpassen
151 long nPixDifY;
152 long nTopMargin = (long) ( pMargin->GetTopMargin() * nPPTY );
153 SvxCellVerJustify eJust = (SvxCellVerJustify) ((const SvxVerJustifyItem&)pPattern->
154 GetItem(ATTR_VER_JUSTIFY)).GetValue();
156 // asian vertical is always edited top-aligned
157 BOOL bAsianVertical = ((const SfxBoolItem&)pPattern->GetItem( ATTR_STACKED )).GetValue() &&
158 ((const SfxBoolItem&)pPattern->GetItem( ATTR_VERTICAL_ASIAN )).GetValue();
160 if ( eJust == SVX_VER_JUSTIFY_TOP ||
161 ( bForceToTop && ( SC_MOD()->GetInputOptions().GetTextWysiwyg() || bAsianVertical ) ) )
162 nPixDifY = nTopMargin;
163 else
165 MapMode aMode = pDev->GetMapMode();
166 pDev->SetMapMode( MAP_PIXEL );
168 long nTextHeight = pDoc->GetNeededSize( nCol, nRow, nTab,
169 pDev, nPPTX, nPPTY, aZoomX, aZoomY, FALSE );
170 if (!nTextHeight)
171 { // leere Zelle
172 Font aFont;
173 // font color doesn't matter here
174 pPattern->GetFont( aFont, SC_AUTOCOL_BLACK, pDev, &aZoomY );
175 pDev->SetFont(aFont);
176 nTextHeight = pDev->GetTextHeight() + nTopMargin +
177 (long) ( pMargin->GetBottomMargin() * nPPTY );
180 pDev->SetMapMode(aMode);
182 if ( nTextHeight > nCellY + nTopMargin || bForceToTop )
183 nPixDifY = 0; // zu gross -> oben anfangen
184 else
186 if ( eJust == SVX_VER_JUSTIFY_CENTER )
187 nPixDifY = nTopMargin + ( nCellY - nTextHeight ) / 2;
188 else
189 nPixDifY = nCellY - nTextHeight + nTopMargin; // JUSTIFY_BOTTOM
193 aStartPos.Y() += nPixDifY;
194 nCellY -= nPixDifY;
196 if ( bLayoutRTL )
197 aStartPos.X() -= nCellX - 2; // excluding grid on both sides
199 // -1 -> Gitter nicht ueberschreiben
200 return Rectangle( aStartPos, Size(nCellX-1,nCellY-1) );
203 //------------------------------------------------------------------------
205 ScEditAttrTester::ScEditAttrTester( ScEditEngineDefaulter* pEng ) :
206 pEngine( pEng ),
207 pEditAttrs( NULL ),
208 bNeedsObject( FALSE ),
209 bNeedsCellAttr( FALSE )
211 if ( pEngine->GetParagraphCount() > 1 )
213 bNeedsObject = TRUE; //! Zellatribute finden ?
215 else
217 const SfxPoolItem* pItem = NULL;
218 pEditAttrs = new SfxItemSet( pEngine->GetAttribs(
219 ESelection(0,0,0,pEngine->GetTextLen(0)), EditEngineAttribs_OnlyHard ) );
220 const SfxItemSet& rEditDefaults = pEngine->GetDefaults();
222 for (USHORT nId = EE_CHAR_START; nId <= EE_CHAR_END && !bNeedsObject; nId++)
224 SfxItemState eState = pEditAttrs->GetItemState( nId, FALSE, &pItem );
225 if (eState == SFX_ITEM_DONTCARE)
226 bNeedsObject = TRUE;
227 else if (eState == SFX_ITEM_SET)
229 if ( nId == EE_CHAR_ESCAPEMENT || nId == EE_CHAR_PAIRKERNING ||
230 nId == EE_CHAR_KERNING || nId == EE_CHAR_XMLATTRIBS )
232 // Escapement and kerning are kept in EditEngine because there are no
233 // corresponding cell format items. User defined attributes are kept in
234 // EditEngine because "user attributes applied to all the text" is different
235 // from "user attributes applied to the cell".
237 if ( *pItem != rEditDefaults.Get(nId) )
238 bNeedsObject = TRUE;
240 else
241 if (!bNeedsCellAttr)
242 if ( *pItem != rEditDefaults.Get(nId) )
243 bNeedsCellAttr = TRUE;
244 // rEditDefaults contains the defaults from the cell format
248 // Feldbefehle enthalten?
250 SfxItemState eFieldState = pEditAttrs->GetItemState( EE_FEATURE_FIELD, FALSE );
251 if ( eFieldState == SFX_ITEM_DONTCARE || eFieldState == SFX_ITEM_SET )
252 bNeedsObject = TRUE;
254 // not converted characters?
256 SfxItemState eConvState = pEditAttrs->GetItemState( EE_FEATURE_NOTCONV, FALSE );
257 if ( eConvState == SFX_ITEM_DONTCARE || eConvState == SFX_ITEM_SET )
258 bNeedsObject = TRUE;
262 ScEditAttrTester::~ScEditAttrTester()
264 delete pEditAttrs;
268 //------------------------------------------------------------------------
270 ScEnginePoolHelper::ScEnginePoolHelper( SfxItemPool* pEnginePoolP,
271 BOOL bDeleteEnginePoolP )
273 pEnginePool( pEnginePoolP ),
274 pDefaults( NULL ),
275 bDeleteEnginePool( bDeleteEnginePoolP ),
276 bDeleteDefaults( FALSE )
281 ScEnginePoolHelper::ScEnginePoolHelper( const ScEnginePoolHelper& rOrg )
283 pEnginePool( rOrg.bDeleteEnginePool ? rOrg.pEnginePool->Clone() : rOrg.pEnginePool ),
284 pDefaults( NULL ),
285 bDeleteEnginePool( rOrg.bDeleteEnginePool ),
286 bDeleteDefaults( FALSE )
291 ScEnginePoolHelper::~ScEnginePoolHelper()
293 if ( bDeleteDefaults )
294 delete pDefaults;
295 if ( bDeleteEnginePool )
296 SfxItemPool::Free(pEnginePool);
300 //------------------------------------------------------------------------
302 ScEditEngineDefaulter::ScEditEngineDefaulter( SfxItemPool* pEnginePoolP,
303 BOOL bDeleteEnginePoolP )
305 ScEnginePoolHelper( pEnginePoolP, bDeleteEnginePoolP ),
306 EditEngine( pEnginePoolP )
308 // All EditEngines use ScGlobal::GetEditDefaultLanguage as DefaultLanguage.
309 // DefaultLanguage for InputHandler's EditEngine is updated later.
311 SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
315 ScEditEngineDefaulter::ScEditEngineDefaulter( const ScEditEngineDefaulter& rOrg )
317 ScEnginePoolHelper( rOrg ),
318 EditEngine( pEnginePool )
320 SetDefaultLanguage( ScGlobal::GetEditDefaultLanguage() );
324 ScEditEngineDefaulter::~ScEditEngineDefaulter()
329 void ScEditEngineDefaulter::SetDefaults( const SfxItemSet& rSet, BOOL bRememberCopy )
331 if ( bRememberCopy )
333 if ( bDeleteDefaults )
334 delete pDefaults;
335 pDefaults = new SfxItemSet( rSet );
336 bDeleteDefaults = TRUE;
338 const SfxItemSet& rNewSet = bRememberCopy ? *pDefaults : rSet;
339 BOOL bUndo = IsUndoEnabled();
340 EnableUndo( FALSE );
341 BOOL bUpdateMode = GetUpdateMode();
342 if ( bUpdateMode )
343 SetUpdateMode( FALSE );
344 USHORT nPara = GetParagraphCount();
345 for ( USHORT j=0; j<nPara; j++ )
347 SetParaAttribs( j, rNewSet );
349 if ( bUpdateMode )
350 SetUpdateMode( TRUE );
351 if ( bUndo )
352 EnableUndo( TRUE );
356 void ScEditEngineDefaulter::SetDefaults( SfxItemSet* pSet, BOOL bTakeOwnership )
358 if ( bDeleteDefaults )
359 delete pDefaults;
360 pDefaults = pSet;
361 bDeleteDefaults = bTakeOwnership;
362 if ( pDefaults )
363 SetDefaults( *pDefaults, FALSE );
367 void ScEditEngineDefaulter::SetDefaultItem( const SfxPoolItem& rItem )
369 if ( !pDefaults )
371 pDefaults = new SfxItemSet( GetEmptyItemSet() );
372 bDeleteDefaults = TRUE;
374 pDefaults->Put( rItem );
375 SetDefaults( *pDefaults, FALSE );
378 const SfxItemSet& ScEditEngineDefaulter::GetDefaults()
380 if ( !pDefaults )
382 pDefaults = new SfxItemSet( GetEmptyItemSet() );
383 bDeleteDefaults = TRUE;
385 return *pDefaults;
388 void ScEditEngineDefaulter::SetText( const EditTextObject& rTextObject )
390 BOOL bUpdateMode = GetUpdateMode();
391 if ( bUpdateMode )
392 SetUpdateMode( FALSE );
393 EditEngine::SetText( rTextObject );
394 if ( pDefaults )
395 SetDefaults( *pDefaults, FALSE );
396 if ( bUpdateMode )
397 SetUpdateMode( TRUE );
400 void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
401 const SfxItemSet& rSet, BOOL bRememberCopy )
403 BOOL bUpdateMode = GetUpdateMode();
404 if ( bUpdateMode )
405 SetUpdateMode( FALSE );
406 EditEngine::SetText( rTextObject );
407 SetDefaults( rSet, bRememberCopy );
408 if ( bUpdateMode )
409 SetUpdateMode( TRUE );
412 void ScEditEngineDefaulter::SetTextNewDefaults( const EditTextObject& rTextObject,
413 SfxItemSet* pSet, BOOL bTakeOwnership )
415 BOOL bUpdateMode = GetUpdateMode();
416 if ( bUpdateMode )
417 SetUpdateMode( FALSE );
418 EditEngine::SetText( rTextObject );
419 SetDefaults( pSet, bTakeOwnership );
420 if ( bUpdateMode )
421 SetUpdateMode( TRUE );
425 void ScEditEngineDefaulter::SetText( const String& rText )
427 BOOL bUpdateMode = GetUpdateMode();
428 if ( bUpdateMode )
429 SetUpdateMode( FALSE );
430 EditEngine::SetText( rText );
431 if ( pDefaults )
432 SetDefaults( *pDefaults, FALSE );
433 if ( bUpdateMode )
434 SetUpdateMode( TRUE );
437 void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
438 const SfxItemSet& rSet, BOOL bRememberCopy )
440 BOOL bUpdateMode = GetUpdateMode();
441 if ( bUpdateMode )
442 SetUpdateMode( FALSE );
443 EditEngine::SetText( rText );
444 SetDefaults( rSet, bRememberCopy );
445 if ( bUpdateMode )
446 SetUpdateMode( TRUE );
449 void ScEditEngineDefaulter::SetTextNewDefaults( const String& rText,
450 SfxItemSet* pSet, BOOL bTakeOwnership )
452 BOOL bUpdateMode = GetUpdateMode();
453 if ( bUpdateMode )
454 SetUpdateMode( FALSE );
455 EditEngine::SetText( rText );
456 SetDefaults( pSet, bTakeOwnership );
457 if ( bUpdateMode )
458 SetUpdateMode( TRUE );
461 void ScEditEngineDefaulter::RepeatDefaults()
463 if ( pDefaults )
465 USHORT nPara = GetParagraphCount();
466 for ( USHORT j=0; j<nPara; j++ )
467 SetParaAttribs( j, *pDefaults );
471 void ScEditEngineDefaulter::RemoveParaAttribs()
473 SfxItemSet* pCharItems = NULL;
474 BOOL bUpdateMode = GetUpdateMode();
475 if ( bUpdateMode )
476 SetUpdateMode( FALSE );
477 USHORT nParCount = GetParagraphCount();
478 for (USHORT nPar=0; nPar<nParCount; nPar++)
480 const SfxItemSet& rParaAttribs = GetParaAttribs( nPar );
481 USHORT nWhich;
482 for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
484 const SfxPoolItem* pParaItem;
485 if ( rParaAttribs.GetItemState( nWhich, FALSE, &pParaItem ) == SFX_ITEM_SET )
487 // if defaults are set, use only items that are different from default
488 if ( !pDefaults || *pParaItem != pDefaults->Get(nWhich) )
490 if (!pCharItems)
491 pCharItems = new SfxItemSet( GetEmptyItemSet() );
492 pCharItems->Put( *pParaItem );
497 if ( pCharItems )
499 SvUShorts aPortions;
500 GetPortions( nPar, aPortions );
502 // loop through the portions of the paragraph, and set only those items
503 // that are not overridden by existing character attributes
505 USHORT nPCount = aPortions.Count();
506 USHORT nStart = 0;
507 for ( USHORT nPos=0; nPos<nPCount; nPos++ )
509 USHORT nEnd = aPortions.GetObject( nPos );
510 ESelection aSel( nPar, nStart, nPar, nEnd );
511 SfxItemSet aOldCharAttrs = GetAttribs( aSel );
512 SfxItemSet aNewCharAttrs = *pCharItems;
513 for (nWhich = EE_CHAR_START; nWhich <= EE_CHAR_END; nWhich ++)
515 // Clear those items that are different from existing character attributes.
516 // Where no character attributes are set, GetAttribs returns the paragraph attributes.
517 const SfxPoolItem* pItem;
518 if ( aNewCharAttrs.GetItemState( nWhich, FALSE, &pItem ) == SFX_ITEM_SET &&
519 *pItem != aOldCharAttrs.Get(nWhich) )
521 aNewCharAttrs.ClearItem(nWhich);
524 if ( aNewCharAttrs.Count() )
525 QuickSetAttribs( aNewCharAttrs, aSel );
527 nStart = nEnd;
530 DELETEZ( pCharItems );
533 if ( rParaAttribs.Count() )
535 // clear all paragraph attributes (including defaults),
536 // so they are not contained in resulting EditTextObjects
538 SetParaAttribs( nPar, SfxItemSet( *rParaAttribs.GetPool(), rParaAttribs.GetRanges() ) );
541 if ( bUpdateMode )
542 SetUpdateMode( TRUE );
545 //------------------------------------------------------------------------
547 ScTabEditEngine::ScTabEditEngine( ScDocument* pDoc )
548 : ScEditEngineDefaulter( pDoc->GetEnginePool() )
550 SetEditTextObjectPool( pDoc->GetEditPool() );
551 Init((const ScPatternAttr&)pDoc->GetPool()->GetDefaultItem(ATTR_PATTERN));
554 ScTabEditEngine::ScTabEditEngine( const ScPatternAttr& rPattern,
555 SfxItemPool* pEnginePoolP, SfxItemPool* pTextObjectPool )
556 : ScEditEngineDefaulter( pEnginePoolP )
558 if ( pTextObjectPool )
559 SetEditTextObjectPool( pTextObjectPool );
560 Init( rPattern );
563 void ScTabEditEngine::Init( const ScPatternAttr& rPattern )
565 SetRefMapMode(MAP_100TH_MM);
566 SfxItemSet* pEditDefaults = new SfxItemSet( GetEmptyItemSet() );
567 rPattern.FillEditItemSet( pEditDefaults );
568 SetDefaults( pEditDefaults );
569 // wir haben keine StyleSheets fuer Text
570 SetControlWord( GetControlWord() & ~EE_CNTRL_RTFSTYLESHEETS );
573 //------------------------------------------------------------------------
574 // Feldbefehle fuer Kopf- und Fusszeilen
575 //------------------------------------------------------------------------
578 // Zahlen aus \sw\source\core\doc\numbers.cxx
581 String lcl_GetCharStr( sal_Int32 nNo )
583 DBG_ASSERT( nNo, "0 ist eine ungueltige Nummer !!" );
584 String aStr;
586 const sal_Int32 coDiff = 'Z' - 'A' +1;
587 sal_Int32 nCalc;
589 do {
590 nCalc = nNo % coDiff;
591 if( !nCalc )
592 nCalc = coDiff;
593 aStr.Insert( (sal_Unicode)('a' - 1 + nCalc ), 0 );
594 nNo = sal::static_int_cast<sal_Int32>( nNo - nCalc );
595 if( nNo )
596 nNo /= coDiff;
597 } while( nNo );
598 return aStr;
601 String lcl_GetNumStr( sal_Int32 nNo, SvxNumType eType )
603 String aTmpStr( '0' );
604 if( nNo )
606 switch( eType )
608 case SVX_CHARS_UPPER_LETTER:
609 case SVX_CHARS_LOWER_LETTER:
610 aTmpStr = lcl_GetCharStr( nNo );
611 break;
613 case SVX_ROMAN_UPPER:
614 case SVX_ROMAN_LOWER:
615 if( nNo < 4000 )
616 aTmpStr = SvxNumberFormat::CreateRomanString( nNo, ( eType == SVX_ROMAN_UPPER ) );
617 else
618 aTmpStr.Erase();
619 break;
621 case SVX_NUMBER_NONE:
622 aTmpStr.Erase();
623 break;
625 // CHAR_SPECIAL:
626 // ????
628 // case ARABIC: ist jetzt default
629 default:
630 aTmpStr = String::CreateFromInt32( nNo );
631 break;
634 if( SVX_CHARS_UPPER_LETTER == eType )
635 aTmpStr.ToUpperAscii();
637 return aTmpStr;
640 ScHeaderFieldData::ScHeaderFieldData()
642 nPageNo = nTotalPages = 0;
643 eNumType = SVX_ARABIC;
646 ScHeaderEditEngine::ScHeaderEditEngine( SfxItemPool* pEnginePoolP, BOOL bDeleteEnginePoolP )
647 : ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
651 String __EXPORT ScHeaderEditEngine::CalcFieldValue( const SvxFieldItem& rField,
652 USHORT /* nPara */, USHORT /* nPos */,
653 Color*& /* rTxtColor */, Color*& /* rFldColor */ )
655 String aRet;
656 const SvxFieldData* pFieldData = rField.GetField();
657 if ( pFieldData )
659 TypeId aType = pFieldData->Type();
660 if (aType == TYPE(SvxPageField))
661 aRet = lcl_GetNumStr( aData.nPageNo,aData.eNumType );
662 else if (aType == TYPE(SvxPagesField))
663 aRet = lcl_GetNumStr( aData.nTotalPages,aData.eNumType );
664 else if (aType == TYPE(SvxTimeField))
665 aRet = ScGlobal::pLocaleData->getTime(aData.aTime);
666 else if (aType == TYPE(SvxFileField))
667 aRet = aData.aTitle;
668 else if (aType == TYPE(SvxExtFileField))
670 switch ( ((const SvxExtFileField*)pFieldData)->GetFormat() )
672 case SVXFILEFORMAT_FULLPATH :
673 aRet = aData.aLongDocName;
674 break;
675 default:
676 aRet = aData.aShortDocName;
679 else if (aType == TYPE(SvxTableField))
680 aRet = aData.aTabName;
681 else if (aType == TYPE(SvxDateField))
682 aRet = ScGlobal::pLocaleData->getDate(aData.aDate);
683 else
685 //DBG_ERROR("unbekannter Feldbefehl");
686 aRet = '?';
689 else
691 DBG_ERROR("FieldData ist 0");
692 aRet = '?';
695 return aRet;
698 //------------------------------------------------------------------------
700 // Feld-Daten
702 //------------------------------------------------------------------------
704 ScFieldEditEngine::ScFieldEditEngine( SfxItemPool* pEnginePoolP,
705 SfxItemPool* pTextObjectPool, BOOL bDeleteEnginePoolP )
707 ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP ),
708 bExecuteURL( TRUE )
710 if ( pTextObjectPool )
711 SetEditTextObjectPool( pTextObjectPool );
712 // EE_CNTRL_URLSFXEXECUTE nicht, weil die Edit-Engine den ViewFrame nicht kennt
713 // wir haben keine StyleSheets fuer Text
714 SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );
717 String __EXPORT ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField,
718 USHORT /* nPara */, USHORT /* nPos */,
719 Color*& rTxtColor, Color*& /* rFldColor */ )
721 String aRet;
722 const SvxFieldData* pFieldData = rField.GetField();
724 if ( pFieldData )
726 TypeId aType = pFieldData->Type();
728 if (aType == TYPE(SvxURLField))
730 String aURL = ((const SvxURLField*)pFieldData)->GetURL();
732 switch ( ((const SvxURLField*)pFieldData)->GetFormat() )
734 case SVXURLFORMAT_APPDEFAULT: //!!! einstellbar an App???
735 case SVXURLFORMAT_REPR:
736 aRet = ((const SvxURLField*)pFieldData)->GetRepresentation();
737 break;
739 case SVXURLFORMAT_URL:
740 aRet = aURL;
741 break;
744 svtools::ColorConfigEntry eEntry =
745 INetURLHistory::GetOrCreate()->QueryUrl( aURL ) ? svtools::LINKSVISITED : svtools::LINKS;
746 rTxtColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor );
748 else
750 //DBG_ERROR("unbekannter Feldbefehl");
751 aRet = '?';
755 if (!aRet.Len()) // leer ist baeh
756 aRet = ' '; // Space ist Default der Editengine
758 return aRet;
761 void __EXPORT ScFieldEditEngine::FieldClicked( const SvxFieldItem& rField, USHORT, USHORT )
763 const SvxFieldData* pFld = rField.GetField();
765 if ( pFld && pFld->ISA( SvxURLField ) && bExecuteURL )
767 const SvxURLField* pURLField = (const SvxURLField*) pFld;
768 ScGlobal::OpenURL( pURLField->GetURL(), pURLField->GetTargetFrame() );
772 //------------------------------------------------------------------------
774 ScNoteEditEngine::ScNoteEditEngine( SfxItemPool* pEnginePoolP,
775 SfxItemPool* pTextObjectPool, BOOL bDeleteEnginePoolP ) :
776 ScEditEngineDefaulter( pEnginePoolP, bDeleteEnginePoolP )
778 if ( pTextObjectPool )
779 SetEditTextObjectPool( pTextObjectPool );
780 SetControlWord( (GetControlWord() | EE_CNTRL_MARKFIELDS) & ~EE_CNTRL_RTFSTYLESHEETS );