Kaydet (Commit) 90b63345 authored tarafından Oliver-Rainer Wittmann's avatar Oliver-Rainer Wittmann

125086: correct UNO-API implementation for <com::sun::star::text::XTextField> in…

125086: correct UNO-API implementation for <com::sun::star::text::XTextField> in Writer to reflect changes made for the in-place editing of Input Fields
üst 0ce4a90e
...@@ -27,6 +27,8 @@ ...@@ -27,6 +27,8 @@
#include <tools/string.hxx> #include <tools/string.hxx>
#include <pam.hxx> #include <pam.hxx>
#include <boost/shared_ptr.hpp>
class SwTxtNode; class SwTxtNode;
// ATT_FLD *********************************** // ATT_FLD ***********************************
...@@ -68,6 +70,13 @@ public: ...@@ -68,6 +70,13 @@ public:
// enable notification that field content has changed and needs reformatting // enable notification that field content has changed and needs reformatting
virtual void NotifyContentChange( SwFmtFld& rFmtFld ); virtual void NotifyContentChange( SwFmtFld& rFmtFld );
// deletes the given field via removing the corresponding text selection from the document's content
static void DeleteTxtFld( const SwTxtFld& rTxtFld );
// return text selection for the given field
static void GetPamForTxtFld( const SwTxtFld& rTxtFld,
boost::shared_ptr< SwPaM >& rPamForTxtFld );
}; };
class SwTxtInputFld : public SwTxtFld class SwTxtInputFld : public SwTxtFld
......
...@@ -456,6 +456,43 @@ void SwTxtFld::NotifyContentChange(SwFmtFld& rFmtFld) ...@@ -456,6 +456,43 @@ void SwTxtFld::NotifyContentChange(SwFmtFld& rFmtFld)
} }
/*static*/
void SwTxtFld::GetPamForTxtFld(
const SwTxtFld& rTxtFld,
boost::shared_ptr< SwPaM >& rPamForTxtFld )
{
if ( rTxtFld.GetpTxtNode() == NULL )
{
ASSERT( false, "<SwTxtFld::GetPamForField> - missing <SwTxtNode>" );
return;
}
const SwTxtNode& rTxtNode = rTxtFld.GetTxtNode();
rPamForTxtFld.reset( new SwPaM( rTxtNode,
( (rTxtFld.End() != NULL) ? *(rTxtFld.End()) : ( *(rTxtFld.GetStart()) + 1 ) ),
rTxtNode,
*(rTxtFld.GetStart()) ) );
}
/*static*/
void SwTxtFld::DeleteTxtFld( const SwTxtFld& rTxtFld )
{
if ( rTxtFld.GetpTxtNode() != NULL )
{
boost::shared_ptr< SwPaM > pPamForTxtFld;
GetPamForTxtFld( rTxtFld, pPamForTxtFld );
if ( pPamForTxtFld.get() != NULL )
{
rTxtFld.GetTxtNode().GetDoc()->DeleteAndJoin( *pPamForTxtFld );
}
}
}
// input field in-place editing // input field in-place editing
SwTxtInputFld::SwTxtInputFld( SwTxtInputFld::SwTxtInputFld(
SwFmtFld & rAttr, SwFmtFld & rAttr,
......
...@@ -910,37 +910,34 @@ void SwXFieldMaster::removeVetoableChangeListener(const OUString& /*PropertyName ...@@ -910,37 +910,34 @@ void SwXFieldMaster::removeVetoableChangeListener(const OUString& /*PropertyName
void SwXFieldMaster::dispose(void) throw( uno::RuntimeException ) void SwXFieldMaster::dispose(void) throw( uno::RuntimeException )
{ {
vos::OGuard aGuard(Application::GetSolarMutex()); vos::OGuard aGuard( Application::GetSolarMutex() );
SwFieldType* pFldType = GetFldType(sal_True);
if(pFldType) SwFieldType* pFldType = GetFldType( sal_True );
if ( pFldType != NULL )
{ {
sal_uInt16 nTypeIdx = USHRT_MAX; sal_uInt16 nTypeIdx = USHRT_MAX;
const SwFldTypes* pTypes = GetDoc()->GetFldTypes(); const SwFldTypes* pTypes = GetDoc()->GetFldTypes();
for( sal_uInt16 i = 0; i < pTypes->Count(); i++ ) for ( sal_uInt16 i = 0; i < pTypes->Count(); i++ )
{ {
if((*pTypes)[i] == pFldType) if ( ( *pTypes )[i] == pFldType )
nTypeIdx = i; nTypeIdx = i;
} }
// zuerst alle Felder loeschen // zuerst alle Felder loeschen
SwIterator<SwFmtFld,SwFieldType> aIter( *pFldType ); SwIterator< SwFmtFld, SwFieldType > aIter( *pFldType );
SwFmtFld* pFld = aIter.First(); SwFmtFld* pFld = aIter.First();
while(pFld) while ( pFld != NULL )
{ {
// Feld im Undo? SwTxtFld* pTxtFld = pFld->GetTxtFld();
SwTxtFld *pTxtFld = pFld->GetTxtFld(); if ( pTxtFld != NULL
if(pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() ) && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() )
{ {
SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode(); SwTxtFld::DeleteTxtFld( *pTxtFld );
SwPaM aPam(rTxtNode, *pTxtFld->GetStart());
aPam.SetMark();
aPam.Move();
GetDoc()->DeleteAndJoin(aPam);
} }
pFld = aIter.Next(); pFld = aIter.Next();
} }
// dann den FieldType loeschen // dann den FieldType loeschen
GetDoc()->RemoveFldType(nTypeIdx); GetDoc()->RemoveFldType( nTypeIdx );
} }
else else
throw uno::RuntimeException(); throw uno::RuntimeException();
...@@ -1891,38 +1888,41 @@ void SwXTextField::attach( const uno::Reference< text::XTextRange > & xTextRange ...@@ -1891,38 +1888,41 @@ void SwXTextField::attach( const uno::Reference< text::XTextRange > & xTextRange
uno::Reference< text::XTextRange > SwXTextField::getAnchor(void) throw( uno::RuntimeException ) uno::Reference< text::XTextRange > SwXTextField::getAnchor(void) throw( uno::RuntimeException )
{ {
vos::OGuard aGuard(Application::GetSolarMutex()); vos::OGuard aGuard( Application::GetSolarMutex() );
uno::Reference< text::XTextRange > aRef;
SwField* pField = (SwField*)GetField(); uno::Reference< text::XTextRange > aRef;
if(pField)
SwField* pField = (SwField*) GetField();
if ( pField != NULL )
{ {
const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld(); const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld();
if(!pTxtFld) if ( !pTxtFld )
throw uno::RuntimeException(); throw uno::RuntimeException();
const SwTxtNode& rTxtNode = pTxtFld->GetTxtNode();
SwPaM aPam(rTxtNode, *pTxtFld->GetStart() + 1, rTxtNode, *pTxtFld->GetStart()); boost::shared_ptr< SwPaM > pPamForTxtFld;
SwTxtFld::GetPamForTxtFld( *pTxtFld, pPamForTxtFld );
aRef = SwXTextRange::CreateXTextRange( if ( pPamForTxtFld.get() != NULL )
*m_pDoc, *aPam.GetPoint(), aPam.GetMark()); {
aRef = SwXTextRange::CreateXTextRange( *m_pDoc,
*(pPamForTxtFld->GetPoint()),
pPamForTxtFld->GetMark() );
}
} }
return aRef; return aRef;
} }
void SwXTextField::dispose(void) throw( uno::RuntimeException ) void SwXTextField::dispose(void) throw( uno::RuntimeException )
{ {
vos::OGuard aGuard(Application::GetSolarMutex()); vos::OGuard aGuard( Application::GetSolarMutex() );
SwField* pField = (SwField*)GetField(); SwField* pField = (SwField*) GetField();
if(pField) if ( pField != NULL )
{ {
UnoActionContext aContext(GetDoc()); UnoActionContext aContext( GetDoc() );
const SwTxtFld* pTxtFld = m_pFmtFld->GetTxtFld();
SwTxtNode& rTxtNode = (SwTxtNode&)*pTxtFld->GetpTxtNode(); ASSERT( m_pFmtFld->GetTxtFld(), "<SwXTextField::dispose()> - missing <SwTxtFld> --> crash" );
SwPaM aPam(rTxtNode, *pTxtFld->GetStart()); SwTxtFld::DeleteTxtFld( *( m_pFmtFld->GetTxtFld() ) );
aPam.SetMark();
aPam.Move();
GetDoc()->DeleteAndJoin(aPam);
} }
if ( m_pTextObject ) if ( m_pTextObject )
...@@ -1983,19 +1983,19 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An ...@@ -1983,19 +1983,19 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An
if ( pEntry->nFlags & beans::PropertyAttribute::READONLY) if ( pEntry->nFlags & beans::PropertyAttribute::READONLY)
throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) ); throw beans::PropertyVetoException ( OUString ( RTL_CONSTASCII_USTRINGPARAM ( "Property is read-only: " ) ) + rPropertyName, static_cast < cppu::OWeakObject * > ( this ) );
if(pField) if ( pField )
{ {
// Sonderbehandlung Serienbrieffeld // Sonderbehandlung Serienbrieffeld
sal_uInt16 nWhich = pField->Which(); sal_uInt16 nWhich = pField->Which();
if( RES_DBFLD == nWhich && if ( RES_DBFLD == nWhich
(rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_NAME)) || && ( rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_BASE_NAME ) )
rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_BASE_URL))|| || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_BASE_URL ) )
rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_TABLE_NAME))|| || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_TABLE_NAME ) )
rPropertyName.equalsAsciiL( SW_PROP_NAME(UNO_NAME_DATA_COLUMN_NAME)))) || rPropertyName.equalsAsciiL( SW_PROP_NAME( UNO_NAME_DATA_COLUMN_NAME ) ) ) )
{ {
// hier muss ein neuer Feldtyp angelegt werden und // hier muss ein neuer Feldtyp angelegt werden und
// das Feld an den neuen Typ umgehaengt werden // das Feld an den neuen Typ umgehaengt werden
DBG_WARNING("not implemented"); DBG_WARNING( "not implemented" );
} }
else else
{ {
...@@ -2015,30 +2015,30 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An ...@@ -2015,30 +2015,30 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An
} }
pField->PutValue( rValue, pEntry->nWID ); pField->PutValue( rValue, pEntry->nWID );
//#i100374# notify SwPostIt about new field content //#i100374# notify SwPostIt about new field content
if (RES_POSTITFLD== nWhich && m_pFmtFld) if ( RES_POSTITFLD == nWhich && m_pFmtFld )
{ {
const_cast<SwFmtFld*>(m_pFmtFld)->Broadcast(SwFmtFldHint( 0, SWFMTFLD_CHANGED )); const_cast< SwFmtFld* >( m_pFmtFld )->Broadcast( SwFmtFldHint( 0, SWFMTFLD_CHANGED ) );
} }
//#114571# changes of the expanded string have to be notified //#114571# changes of the expanded string have to be notified
//#to the SwTxtFld //#to the SwTxtFld
if(RES_DBFLD == nWhich && m_pFmtFld->GetTxtFld()) if ( RES_DBFLD == nWhich && m_pFmtFld->GetTxtFld() )
{ {
m_pFmtFld->GetTxtFld()->ExpandTxtFld(); m_pFmtFld->GetTxtFld()->ExpandTxtFld();
} }
//#i100374# changing a document field should set the modify flag //#i100374# changing a document field should set the modify flag
SwDoc* pDoc = GetDoc(); SwDoc* pDoc = GetDoc();
if (pDoc) if ( pDoc )
pDoc->SetModified(); pDoc->SetModified();
} }
else if(m_pProps) else if ( m_pProps )
{ {
String* pStr = 0; String* pStr = 0;
sal_Bool* pBool = 0; sal_Bool* pBool = 0;
switch(pEntry->nWID) switch (pEntry->nWID)
{ {
case FIELD_PROP_PAR1: case FIELD_PROP_PAR1:
pStr = &m_pProps->sPar1; pStr = &m_pProps->sPar1;
...@@ -2059,54 +2059,54 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An ...@@ -2059,54 +2059,54 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An
case FIELD_PROP_SUBTYPE: case FIELD_PROP_SUBTYPE:
m_pProps->nSubType = SWUnoHelper::GetEnumAsInt32( rValue ); m_pProps->nSubType = SWUnoHelper::GetEnumAsInt32( rValue );
break; break;
case FIELD_PROP_BYTE1 : case FIELD_PROP_BYTE1:
rValue >>= m_pProps->nByte1; rValue >>= m_pProps->nByte1;
break; break;
case FIELD_PROP_BOOL1 : case FIELD_PROP_BOOL1:
pBool = &m_pProps->bBool1; pBool = &m_pProps->bBool1;
break; break;
case FIELD_PROP_BOOL2 : case FIELD_PROP_BOOL2:
pBool = &m_pProps->bBool2; pBool = &m_pProps->bBool2;
break; break;
case FIELD_PROP_BOOL3 : case FIELD_PROP_BOOL3:
pBool = &m_pProps->bBool3; pBool = &m_pProps->bBool3;
break; break;
case FIELD_PROP_BOOL4: case FIELD_PROP_BOOL4:
pBool = &m_pProps->bBool4; pBool = &m_pProps->bBool4;
break; break;
case FIELD_PROP_DATE : case FIELD_PROP_DATE:
{ {
if(rValue.getValueType() != ::getCppuType(static_cast<const util::Date*>(0))) if ( rValue.getValueType() != ::getCppuType( static_cast< const util::Date* >( 0 ) ) )
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
util::Date aTemp = *(const util::Date*)rValue.getValue(); util::Date aTemp = *(const util::Date*) rValue.getValue();
m_pProps->aDate = Date(aTemp.Day, aTemp.Month, aTemp.Year); m_pProps->aDate = Date( aTemp.Day, aTemp.Month, aTemp.Year );
} }
break; break;
case FIELD_PROP_USHORT1: case FIELD_PROP_USHORT1:
case FIELD_PROP_USHORT2: case FIELD_PROP_USHORT2:
{ {
sal_Int16 nVal = 0; sal_Int16 nVal = 0;
rValue >>= nVal; rValue >>= nVal;
if( FIELD_PROP_USHORT1 == pEntry->nWID) if ( FIELD_PROP_USHORT1 == pEntry->nWID )
m_pProps->nUSHORT1 = nVal; m_pProps->nUSHORT1 = nVal;
else else
m_pProps->nUSHORT2 = nVal; m_pProps->nUSHORT2 = nVal;
} }
break; break;
case FIELD_PROP_SHORT1: case FIELD_PROP_SHORT1:
rValue >>= m_pProps->nSHORT1; rValue >>= m_pProps->nSHORT1;
break; break;
case FIELD_PROP_DOUBLE: case FIELD_PROP_DOUBLE:
if(rValue.getValueType() != ::getCppuType(static_cast<const double*>(0))) if ( rValue.getValueType() != ::getCppuType( static_cast< const double* >( 0 ) ) )
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
m_pProps->fDouble = *(double*)rValue.getValue(); m_pProps->fDouble = *(double*) rValue.getValue();
break; break;
case FIELD_PROP_DATE_TIME : case FIELD_PROP_DATE_TIME:
if(!m_pProps->pDateTime) if ( !m_pProps->pDateTime )
m_pProps->pDateTime = new util::DateTime; m_pProps->pDateTime = new util::DateTime;
rValue >>= (*m_pProps->pDateTime); rValue >>= ( *m_pProps->pDateTime );
break; break;
case FIELD_PROP_PROP_SEQ: case FIELD_PROP_PROP_SEQ:
rValue >>= m_pProps->aPropSeq; rValue >>= m_pProps->aPropSeq;
...@@ -2115,12 +2115,12 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An ...@@ -2115,12 +2115,12 @@ void SwXTextField::setPropertyValue(const OUString& rPropertyName, const uno::An
rValue >>= m_pProps->aStrings; rValue >>= m_pProps->aStrings;
break; break;
} }
if( pStr ) if ( pStr )
::GetString( rValue, *pStr ); ::GetString( rValue, *pStr );
else if( pBool ) else if ( pBool )
{ {
if( rValue.getValueType() == getCppuBooleanType() ) if ( rValue.getValueType() == getCppuBooleanType() )
*pBool = *(sal_Bool*)rValue.getValue(); *pBool = *(sal_Bool*) rValue.getValue();
else else
throw lang::IllegalArgumentException(); throw lang::IllegalArgumentException();
} }
...@@ -2383,10 +2383,8 @@ void SwXTextField::update( ) throw (uno::RuntimeException) ...@@ -2383,10 +2383,8 @@ void SwXTextField::update( ) throw (uno::RuntimeException)
} }
break; break;
} }
// --> FME 2004-10-06 #116480#
// Text formatting has to be triggered. // Text formatting has to be triggered.
const_cast<SwFmtFld*>(m_pFmtFld)->ModifyNotification( 0, 0 ); const_cast< SwFmtFld* >( m_pFmtFld )->ModifyNotification( 0, 0 );
// <--
} }
else else
m_bCallUpdate = sal_True; m_bCallUpdate = sal_True;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment