Index: basic/inc/sbmeth.hxx
===================================================================
RCS file: /cvs/script/basic/inc/sbmeth.hxx,v
retrieving revision 1.7
retrieving revision 1.6.74.2
diff -u -p -u -p -r1.7 -r1.6.74.2
--- basic/inc/sbmeth.hxx	19 Jun 2006 17:29:57 -0000	1.7
+++ basic/inc/sbmeth.hxx	28 Jun 2006 10:55:01 -0000	1.6.74.2
@@ -62,7 +62,7 @@ class SbMethod : public SbxMethod
 	SbModule* pMod;
 	USHORT    nDebugFlags;
 	USHORT	  nLine1, nLine2;
-	USHORT	  nStart;
+	UINT32	  nStart;
 	BOOL	  bInvalid;
 	SbMethod( const String&, SbxDataType, SbModule* );
 	SbMethod( const SbMethod& );
@@ -77,7 +77,7 @@ public:
 	SbxArray* GetLocals();
 	SbxArray* GetStatics();
 	SbModule* GetModule() 				 { return pMod; 	   }
-	USHORT	  GetId() const				 { return nStart;	   }
+	UINT32	  GetId() const				 { return nStart;	   }
 	USHORT    GetDebugFlags()			 { return nDebugFlags; }
 	void 	  SetDebugFlags( USHORT n )  { nDebugFlags = n;    }
 	void 	  GetLineRange( USHORT&, USHORT& );
Index: basic/inc/sbmod.hxx
===================================================================
RCS file: /cvs/script/basic/inc/sbmod.hxx,v
retrieving revision 1.12
retrieving revision 1.12.4.5
diff -u -p -u -p -r1.12 -r1.12.4.5
--- basic/inc/sbmod.hxx	19 Jun 2006 17:30:09 -0000	1.12
+++ basic/inc/sbmod.hxx	3 Oct 2006 16:53:31 -0000	1.12.4.5
@@ -130,7 +130,11 @@ public:
 
     // Store only image, no source (needed for new password protection)
    	BOOL StoreBinaryData( SvStream& );    
+   	BOOL StoreBinaryData( SvStream&, USHORT nVer );    
+	BOOL LoadBinaryData( SvStream&, USHORT nVer );
 	BOOL LoadBinaryData( SvStream& );
+	BOOL ExceedsLegacyModuleSize();
+	void fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg = NULL ) const;
 };
 
 #ifndef __SB_SBMODULEREF_HXX
Index: basic/source/classes/disas.cxx
===================================================================
RCS file: /cvs/script/basic/source/classes/disas.cxx,v
retrieving revision 1.20
retrieving revision 1.19.4.2
diff -u -p -u -p -r1.20 -r1.19.4.2
--- basic/source/classes/disas.cxx	17 Sep 2006 09:59:11 -0000	1.20
+++ basic/source/classes/disas.cxx	28 Sep 2006 22:28:22 -0000	1.19.4.2
@@ -429,7 +429,9 @@ BOOL SbiDisas::DisasLine( String& rText 
 		}
 		else
 		{
-            snprintf( cBuf, sizeof(cBuf), "Lbl%04X", nPC );
+            // fix warning (now error) for "Lbl%04lX" format
+            // nPC is now a sal_Int32
+            snprintf( cBuf, sizeof(cBuf), "Lbl%08lX", nPC ); 
 			rText.AppendAscii( cBuf );
 		}
 		rText += ':';
Index: basic/source/classes/image.cxx
===================================================================
RCS file: /cvs/script/basic/source/classes/image.cxx,v
retrieving revision 1.20
retrieving revision 1.18.68.12
diff -u -p -u -p -r1.20 -r1.18.68.12
--- basic/source/classes/image.cxx	17 Sep 2006 09:59:37 -0000	1.20
+++ basic/source/classes/image.cxx	5 Oct 2006 13:36:01 -0000	1.18.68.12
@@ -44,17 +44,18 @@
 #include "sb.hxx"
 #include <string.h>		// memset() etc
 #include "image.hxx"
-#include "filefmt.hxx"
-
+#include <codegen.hxx>
 SbiImage::SbiImage()
 {
 	pStringOff = NULL;
 	pStrings   = NULL;
 	pCode  	   = NULL;
+	pLegacyPCode  	   = NULL;
 	nFlags	   =
 	nStrings   =
 	nStringSize=
 	nCodeSize  =
+	nLegacyCodeSize  =
 	nDimBase   = 0;
 	bInit	   =
 	bError	   = FALSE;
@@ -72,12 +73,14 @@ void SbiImage::Clear()
 	delete[] pStringOff;
 	delete[] pStrings;
 	delete[] pCode;
+	ReleaseLegacyBuffer();
 	pStringOff = NULL;
 	pStrings   = NULL;
 	pCode  	   = NULL;
 	nFlags	   =
 	nStrings   =
 	nStringSize=
+	nLegacyCodeSize  = 0;
 	nCodeSize  = 0;
 	eCharSet   = gsl_getSystemTextEncoding();
 	nDimBase   = 0;
@@ -125,6 +128,12 @@ void SbiCloseRecord( SvStream& r, ULONG 
 
 BOOL SbiImage::Load( SvStream& r )
 {
+	UINT32 nVersion = 0;			// Versionsnummer
+	return Load( r, nVersion );
+}
+BOOL SbiImage::Load( SvStream& r, UINT32& nVersion )
+{
+
 	UINT16 nSign, nCount;
 	UINT32 nLen, nOff;
 
@@ -132,7 +141,6 @@ BOOL SbiImage::Load( SvStream& r )
 	// Master-Record einlesen
 	r >> nSign >> nLen >> nCount;
 	ULONG nLast = r.Tell() + nLen;
-	UINT32 nVersion = 0;			// Versionsnummer
 	UINT32 nCharSet;			   	// System-Zeichensatz
 	UINT32 lDimBase;
 	UINT16 nReserved1;
@@ -145,10 +153,12 @@ BOOL SbiImage::Load( SvStream& r )
 		  >> nFlags >> nReserved1 >> nReserved2 >> nReserved3;
 		eCharSet = (CharSet) nCharSet;
         eCharSet = GetSOLoadTextEncoding( eCharSet );
-		bBadVer  = BOOL( nVersion != B_CURVERSION );
+		bBadVer  = BOOL( nVersion > B_CURVERSION );
 		nDimBase = (USHORT) lDimBase;
 	}
 
+	bool bLegacy = ( nVersion < B_EXT_IMG_VERSION );
+
 	ULONG nNext;
 	while( ( nNext = r.Tell() ) < nLast )
 	{
@@ -190,8 +200,27 @@ BOOL SbiImage::Load( SvStream& r )
 			case B_PCODE:
 				if( bBadVer ) break;
 				pCode = new char[ nLen ];
-				nCodeSize = (USHORT) nLen;
+				nCodeSize = nLen;
 				r.Read( pCode, nCodeSize );
+				if ( bLegacy )
+				{
+					ReleaseLegacyBuffer(); // release any previously held buffer
+					nLegacyCodeSize = nCodeSize;
+					pLegacyPCode = pCode;
+
+					PCodeBuffConvertor< UINT16, UINT32 > aLegacyToNew( (BYTE*)pLegacyPCode, nLegacyCodeSize );
+					aLegacyToNew.convert();
+					pCode = (char*)aLegacyToNew.GetBuffer();
+					nCodeSize = aLegacyToNew.GetSize();
+					// we don't release the legacy buffer
+					// right now, thats because the module
+					// needs it to fix up the method
+					// nStart members. When that is done
+					// the module can release the buffer
+					// or it can wait until this routine
+					// is called again or when this class						// destructs all of which will trigger
+					// release of the buffer.
+				}
 				break;
 			case B_PUBLICS:
 			case B_POOLDIR:
@@ -241,16 +270,29 @@ done:
 	return BOOL( !bError );
 }
 
-BOOL SbiImage::Save( SvStream& r )
+BOOL SbiImage::Save( SvStream& r, UINT32 nVer )
 {
+	bool bLegacy = ( nVer < B_EXT_IMG_VERSION );
+
+	// detect if old code exceeds legacy limits
+	// if so, then disallow save
+	if ( bLegacy && ExceedsLegacyLimits() )
+	{
+		SbiImage aEmptyImg;
+		aEmptyImg.aName = aName;
+		aEmptyImg.Save( r, B_LEGACYVERSION );	      		
+		return TRUE;
+	}
 	// Erst mal der Header:
 	ULONG nStart = SbiOpenRecord( r, B_MODULE, 1 );
 	ULONG nPos;
 
     eCharSet = GetSOStoreTextEncoding( eCharSet );
-
-	r << (INT32) B_CURVERSION
-	  << (INT32) eCharSet
+	if ( bLegacy )
+		r << (INT32) B_LEGACYVERSION;
+	else
+		r << (INT32) B_CURVERSION;
+	r  << (INT32) eCharSet
 	  << (INT32) nDimBase
 	  << (INT16) nFlags
 	  << (INT16) 0
@@ -310,7 +352,17 @@ BOOL SbiImage::Save( SvStream& r )
 	if( pCode && SbiGood( r ) )
 	{
 		nPos = SbiOpenRecord( r, B_PCODE, 1 );
-		r.Write( pCode, nCodeSize );
+		if ( bLegacy )
+		{
+			ReleaseLegacyBuffer(); // release any previously held buffer
+			PCodeBuffConvertor< UINT32, UINT16 > aNewToLegacy( (BYTE*)pCode, nCodeSize );
+			aNewToLegacy.convert();
+			pLegacyPCode = (char*)aNewToLegacy.GetBuffer();
+			nLegacyCodeSize = aNewToLegacy.GetSize();
+		        r.Write( pLegacyPCode, nLegacyCodeSize );
+		}
+		else
+			r.Write( pCode, nCodeSize );
 		SbiCloseRecord( r, nPos );
 	}
 	// String-Pool?
@@ -356,11 +408,11 @@ void SbiImage::MakeStrings( short nSize 
 	nStrings = nStringIdx = nStringOff = 0;
 	nStringSize = 1024;
 	pStrings = new sal_Unicode[ nStringSize ];
-	pStringOff = new UINT16[ nSize ];
+	pStringOff = new UINT32[ nSize ];
 	if( pStrings && pStringOff )
 	{
 		nStrings = nSize;
-		memset( pStringOff, 0, nSize * sizeof( UINT16 ) );
+		memset( pStringOff, 0, nSize * sizeof( UINT32 ) );
 		memset( pStrings, 0, nStringSize * sizeof( sal_Unicode ) );
 	}
 	else
@@ -378,16 +430,16 @@ void SbiImage::AddString( const String& 
 		bError = TRUE;
 	if( !bError )
 	{
-		UINT16 len = r.Len() + 1;
-		long needed = (long) nStringOff + len;
-		if( needed > 0xFF00L )
+		xub_StrLen  len = r.Len() + 1;
+		UINT32 needed = nStringOff + len;
+		if( needed > 0xFFFFFF00L )
 			bError = TRUE;	// out of mem!
-		else if( (USHORT) needed > nStringSize )
+		else if( needed > nStringSize )
 		{
             UINT32 nNewLen = needed + 1024;
             nNewLen &= 0xFFFFFC00;  // trim to 1K border
-			if( nNewLen > 0xFF00L )
-				nNewLen = 0xFF00L;
+			if( nNewLen > 0xFFFFFF00L )
+				nNewLen = 0xFFFFFF00L;
 			sal_Unicode* p = NULL;
 			if( (p = new sal_Unicode[ nNewLen ]) != NULL )
 			{
@@ -418,7 +470,7 @@ void SbiImage::AddString( const String& 
 // und ist bereits per new angelegt. Ausserdem enthaelt er alle Integers
 // im Big Endian-Format, kann also direkt gelesen/geschrieben werden.
 
-void SbiImage::AddCode( char* p, USHORT s )
+void SbiImage::AddCode( char* p, UINT32 s )
 {
 	pCode = p;
 	nCodeSize = s;
@@ -452,14 +504,14 @@ String SbiImage::GetString( short nId ) 
 {
 	if( nId && nId <= nStrings )
 	{
-		USHORT nOff = pStringOff[ nId - 1 ];
+		UINT32 nOff = pStringOff[ nId - 1 ];
 		sal_Unicode* pStr = pStrings + nOff;
 
 		// #i42467: Special treatment for vbNullChar
 		if( *pStr == 0 )
 		{
-			USHORT nNextOff = (nId < nStrings) ? pStringOff[ nId ] : nStringOff;
-			USHORT nLen = nNextOff - nOff - 1;
+			UINT32 nNextOff = (nId < nStrings) ? pStringOff[ nId ] : nStringOff;
+			UINT32 nLen = nNextOff - nOff - 1;
 			if( nLen == 1 )
 			{
 				// Force length 1 and make char 0 afterwards
@@ -482,3 +534,29 @@ const SbxObject* SbiImage::FindType (Str
 	return rTypes.Is() ? (SbxObject*)rTypes->Find(aTypeName,SbxCLASS_OBJECT) : NULL;
 }
 
+UINT16
+SbiImage::CalcLegacyOffset( INT32 nOffset )
+{
+	return SbiCodeGen::calcLegacyOffSet( (BYTE*)pCode, nOffset ) ;
+}
+UINT32
+SbiImage::CalcNewOffset( INT16 nOffset )
+{
+	return SbiCodeGen::calcNewOffSet( (BYTE*)pLegacyPCode, nOffset ) ;
+}
+
+void 
+SbiImage::ReleaseLegacyBuffer()
+{
+	delete[] pLegacyPCode;
+	pLegacyPCode = NULL;
+	nLegacyCodeSize = 0;
+}
+
+BOOL 
+SbiImage::ExceedsLegacyLimits()
+{
+	if ( ( nStringSize > 0xFF00L ) || ( CalcLegacyOffset( nCodeSize ) > 0xFF00L ) )
+		return TRUE;
+	return FALSE;
+}
Index: basic/source/classes/sbxmod.cxx
===================================================================
RCS file: /cvs/script/basic/source/classes/sbxmod.cxx,v
retrieving revision 1.33
retrieving revision 1.28.4.9
diff -u -p -u -p -r1.33 -r1.28.4.9
--- basic/source/classes/sbxmod.cxx	17 Sep 2006 10:00:50 -0000	1.33
+++ basic/source/classes/sbxmod.cxx	5 Oct 2006 13:36:02 -0000	1.28.4.9
@@ -992,7 +992,7 @@ const BYTE* SbModule::FindNextStmnt( con
 const BYTE* SbModule::FindNextStmnt( const BYTE* p, USHORT& nLine, USHORT& nCol, 
 	BOOL bFollowJumps, const SbiImage* pImg ) const
 {
-	USHORT nPC = (USHORT) ( p - (const BYTE*) pImage->GetCode() );
+	UINT32 nPC = (UINT32) ( p - (const BYTE*) pImage->GetCode() );
 	while( nPC < pImage->GetCodeSize() )
 	{
 		SbiOpcode eOp = (SbiOpcode ) ( *p++ );
@@ -1000,21 +1000,24 @@ const BYTE* SbModule::FindNextStmnt( con
 		if( bFollowJumps && eOp == _JUMP && pImg )
 		{
 			DBG_ASSERT( pImg, "FindNextStmnt: pImg==NULL with FollowJumps option" );
-			USHORT nOp1 = *p++; nOp1 |= *p++ << 8;
+			UINT32 nOp1 = *p++; nOp1 |= *p++ << 8;
+			nOp1 |= *p++ << 16; nOp1 |= *p++ << 24;
 			p = (const BYTE*) pImg->GetCode() + nOp1;
 		}
 		else if( eOp >= SbOP1_START && eOp <= SbOP1_END )
-			p += 2, nPC += 2;
+			p += 4, nPC += 4;
 		else if( eOp == _STMNT )
 		{
-			USHORT nl, nc;
+			UINT32 nl, nc;
 			nl = *p++; nl |= *p++ << 8;
+			nl |= *p++ << 16 ; nl |= *p++ << 24;
 			nc = *p++; nc |= *p++ << 8;
+			nc |= *p++ << 16 ; nc |= *p++ << 24;
 			nLine = nl; nCol = nc;
 			return p;
 		}
 		else if( eOp >= SbOP2_START && eOp <= SbOP2_END )
-			p += 4, nPC += 4;
+			p += 8, nPC += 8;
 		else if( !( eOp >= SbOP0_START && eOp <= SbOP0_END ) )
 		{
 			StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
@@ -1123,6 +1126,26 @@ void SbModule::ClearAllBP()
 	delete pBreaks; pBreaks = NULL;
 }
 
+void
+SbModule::fixUpMethodStart( bool bCvtToLegacy, SbiImage* pImg ) const
+{	
+		if ( !pImg )
+			pImg = pImage;
+		for( UINT32 i = 0; i < pMethods->Count(); i++ )
+		{
+			SbMethod* pMeth = PTR_CAST(SbMethod,pMethods->Get( i ) );
+			if( pMeth )
+			{
+				//fixup method start positions
+				if ( bCvtToLegacy )
+					pMeth->nStart = pImg->CalcLegacyOffset( pMeth->nStart );
+				else
+					pMeth->nStart = pImg->CalcNewOffset( pMeth->nStart );
+			}
+		}
+	
+}
+
 BOOL SbModule::LoadData( SvStream& rStrm, USHORT nVer )
 {
 	Clear();
@@ -1135,25 +1158,32 @@ BOOL SbModule::LoadData( SvStream& rStrm
 	if( bImage )
 	{
 		SbiImage* p = new SbiImage;
-		if( !p->Load( rStrm ) )
+		UINT32 nImgVer = 0;
+
+		if( !p->Load( rStrm, nImgVer ) )
 		{
 			delete p;
 			return FALSE;
 		}
+		// If the image is in old format, we fix up the method start offsets
+		if ( nImgVer < B_EXT_IMG_VERSION ) 
+		{
+			fixUpMethodStart( false, p );
+			p->ReleaseLegacyBuffer();
+		}
 		aComment = p->aComment;
 		SetName( p->aName );
-		// Ist Code vorhanden?
 		if( p->GetCodeSize() )
 		{
 			aOUSource = p->aOUSource;
-			// Alte Version: Image weg
-			if( nVer == 1 )
+			// Alte Version: Image weg 
+			if( nVer == 1 ) 
 			{
 				SetSource32( p->aOUSource );
 				delete p;
 			}
 			else
-				pImage = p;
+				pImage = p; 
 		}
 		else
 		{
@@ -1166,15 +1196,28 @@ BOOL SbModule::LoadData( SvStream& rStrm
 
 BOOL SbModule::StoreData( SvStream& rStrm ) const
 {
-	if( !SbxObject::StoreData( rStrm ) )
+	BOOL bFixup = ( pImage && !pImage->ExceedsLegacyLimits() );
+	if ( bFixup ) 
+		fixUpMethodStart( true );
+	BOOL bRet = SbxObject::StoreData( rStrm );
+	if ( !bRet )	
 		return FALSE;
+	
 	if( pImage )
 	{
 		pImage->aOUSource = aOUSource;
 		pImage->aComment = aComment;
 		pImage->aName = GetName();
 		rStrm << (BYTE) 1;
-		return pImage->Save( rStrm );
+		// # PCode is saved only for legacy formats only
+		// It should be noted that it probably isn't necessary
+		// It would be better not to store the image ( more flexible with
+		// formats )
+		bool bRes = pImage->Save( rStrm, B_LEGACYVERSION );
+		if ( bFixup ) 
+			fixUpMethodStart( false ); // restore method starts
+		return bRes;
+		
 	}
 	else
 	{
@@ -1187,12 +1230,31 @@ BOOL SbModule::StoreData( SvStream& rStr
 	}
 }
 
+BOOL SbModule::ExceedsLegacyModuleSize()
+{
+	if ( !IsCompiled() )
+		Compile();
+	if ( pImage && pImage->ExceedsLegacyLimits() )
+		return true;
+	return false;
+}
+
+
 // Store only image, no source
 BOOL SbModule::StoreBinaryData( SvStream& rStrm )
 {
+	return StoreBinaryData( rStrm, 0 );
+}
+
+BOOL SbModule::StoreBinaryData( SvStream& rStrm, USHORT nVer )
+{
     BOOL bRet = Compile();
     if( bRet )
     {
+		BOOL bFixup = ( !nVer && !pImage->ExceedsLegacyLimits() );// save in old image format, fix up method starts
+
+		if ( bFixup ) // save in old image format, fix up method starts
+			fixUpMethodStart( true ); 
      	bRet = SbxObject::StoreData( rStrm );
         if( bRet )
         {
@@ -1201,14 +1263,22 @@ BOOL SbModule::StoreBinaryData( SvStream
 		    pImage->aName = GetName();
 
 		    rStrm << (BYTE) 1;
-		    bRet = pImage->Save( rStrm );
-
+                    if ( nVer )
+						bRet = pImage->Save( rStrm, B_EXT_IMG_VERSION );
+                    else
+                        bRet = pImage->Save( rStrm, B_LEGACYVERSION );
+                    if ( bFixup )
+                        fixUpMethodStart( false ); // restore method starts
+			
 		    pImage->aOUSource = aOUSource;
         }
     }
     return bRet;
 }
 
+// Called for >= OO 1.0 passwd protected libraries only
+// 
+
 BOOL SbModule::LoadBinaryData( SvStream& rStrm )
 {
 	OUString aKeepSource = aOUSource;
@@ -1880,11 +1950,13 @@ BOOL SbMethod::LoadData( SvStream& rStrm
 		return FALSE;
 	INT16 n;
 	rStrm >> n;
+	INT16 nTempStart = nStart;
 	// nDebugFlags = n; 	// AB 16.1.96: Nicht mehr uebernehmen
 	if( nVer == 2 )
-		rStrm >> nLine1 >> nLine2 >> nStart >> bInvalid;
+		rStrm >> nLine1 >> nLine2 >> nTempStart >> bInvalid;
 	// AB: 2.7.1996: HACK wegen 'Referenz kann nicht gesichert werden'
 	SetFlag( SBX_NO_MODIFY );
+	nStart = nTempStart;
 	return TRUE;
 }
 
Index: basic/source/comp/buffer.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/buffer.cxx,v
retrieving revision 1.9
retrieving revision 1.7.68.4
diff -u -p -u -p -r1.9 -r1.7.68.4
--- basic/source/comp/buffer.cxx	17 Sep 2006 10:01:05 -0000	1.9
+++ basic/source/comp/buffer.cxx	28 Sep 2006 22:29:26 -0000	1.7.68.4
@@ -40,6 +40,8 @@
 #include "buffer.hxx"
 #include <string.h>
 
+const static UINT32 UP_LIMIT=0xFFFFFF00L;
+
 // Der SbiBuffer wird in Inkrements von mindestens 16 Bytes erweitert.
 // Dies ist notwendig, da viele Klassen von einer Pufferlaenge
 // von x*16 Bytes ausgehen.
@@ -78,14 +80,14 @@ char* SbiBuffer::GetBuffer()
 BOOL SbiBuffer::Check( USHORT n )
 {
 	if( !n ) return TRUE;
-	if( ((long) nOff + n ) > (long) nSize )
+	if( ( static_cast<UINT32>( nOff )+ n ) >  static_cast<UINT32>( nSize ) )
 	{
 		if( nInc == 0 )
 			return FALSE;
 		USHORT nn = 0;
 		while( nn < n ) nn += nInc;
 		char* p;
-		if( ((long) nSize + nn ) > 0xFF00L ) p = NULL;
+		if( ( static_cast<UINT32>( nSize ) + nn ) > UP_LIMIT ) p = NULL;
 		else p = new char [nSize + nn];
 		if( !p )
 		{
@@ -108,11 +110,11 @@ BOOL SbiBuffer::Check( USHORT n )
 
 // Angleich des Puffers auf die uebergebene Byte-Grenze
 
-void SbiBuffer::Align( short n )
+void SbiBuffer::Align( INT32 n )
 {
 	if( nOff % n ) {
-		USHORT nn =( ( nOff + n ) / n ) * n;
-		if( nn <= 0xFF00 )
+		UINT32 nn =( ( nOff + n ) / n ) * n;
+		if( nn <= UP_LIMIT )
 		{
 			nn -= nOff;
 			if( Check( nn ) )
@@ -127,13 +129,17 @@ void SbiBuffer::Align( short n )
 
 // Patch einer Location
 
-void SbiBuffer::Patch( USHORT off, UINT16 val )
+void SbiBuffer::Patch( UINT32 off, UINT32 val )
 {
-	if( ( off + sizeof( UINT16 ) ) < nOff )
+	if( ( off + sizeof( UINT32 ) ) < nOff )
 	{
+		UINT16 val1 = ( val & 0xFFFF );
+		UINT16 val2 = ( val >> 16 );
 		BYTE* p = (BYTE*) pBuf + off;
-		*p++ = (char) ( val & 0xFF );
-		*p   = (char) ( val >> 8 );
+		*p++ = (char) ( val1 & 0xFF );
+		*p++ = (char) ( val1 >> 8 );
+		*p++ = (char) ( val2 & 0xFF );
+		*p   = (char) ( val2 >> 8 );
 	}
 }
 
@@ -141,24 +147,29 @@ void SbiBuffer::Patch( USHORT off, UINT1
 // bauen eine Kette auf. Der Anfang der Kette ist beim uebergebenen
 // Parameter, das Ende der Kette ist 0.
 
-void SbiBuffer::Chain( USHORT off )
+void SbiBuffer::Chain( UINT32 off )
 {
 	if( off && pBuf )
 	{
 		BYTE *ip;
-		USHORT i = off;
-		USHORT val = nOff;
+		UINT32 i = off;
+		UINT32 val1 = (nOff & 0xFFFF);
+		UINT32 val2 = (nOff >> 16);
 		do
 		{
 			ip = (BYTE*) pBuf + i;
-			i = ( *ip ) | ( *(ip+1) << 8 );
+			BYTE* pTmp = ip;
+             		i =  *pTmp++; i |= *pTmp++ << 8; i |= *pTmp++ << 16; i |= *pTmp++ << 24;
+
 			if( i >= nOff )
 			{
 				pParser->Error( SbERR_INTERNAL_ERROR, "BACKCHAIN" );
 				break;
 			}
-			*ip++ = (char) ( val & 0xFF );
-			*ip   = (char) ( val >> 8 );
+			*ip++ = (char) ( val1 & 0xFF );
+			*ip++ = (char) ( val1 >> 8 );
+			*ip++ = (char) ( val2 & 0xFF );
+			*ip   = (char) ( val2 >> 8 );
 		} while( i );
 	}
 }
@@ -199,6 +210,25 @@ BOOL SbiBuffer::operator +=( UINT16 n )
 	} else return FALSE;
 }
 
+BOOL SbiBuffer::operator +=( UINT32 n )
+{
+	if( Check( 4 ) )
+	{
+		UINT16 n1 = ( n & 0xFFFF );
+		UINT16 n2 = ( n >> 16 );
+		if ( operator +=( n1 ) && operator +=( n2 ) )
+			return TRUE;
+		return TRUE;
+	} 
+	return FALSE;
+}
+
+BOOL SbiBuffer::operator +=( INT32 n )
+{
+	return operator +=( (UINT32) n );
+}
+
+
 BOOL SbiBuffer::operator +=( const String& n )
 {
 	USHORT l = n.Len() + 1;
Index: basic/source/comp/codegen.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/codegen.cxx,v
retrieving revision 1.14
retrieving revision 1.11.68.6
diff -u -p -u -p -r1.14 -r1.11.68.6
--- basic/source/comp/codegen.cxx	17 Sep 2006 10:01:20 -0000	1.14
+++ basic/source/comp/codegen.cxx	28 Sep 2006 22:29:32 -0000	1.11.68.6
@@ -39,6 +39,7 @@
 #include <sbx.hxx>
 #include "sbcomp.hxx"
 #include "image.hxx"
+#include <limits>
 
 // nInc ist die Inkrementgroesse der Puffer
 
@@ -52,7 +53,7 @@ SbiCodeGen::SbiCodeGen( SbModule& r, Sbi
 	nForLevel = 0;
 }
 
-USHORT SbiCodeGen::GetPC()
+UINT32 SbiCodeGen::GetPC()
 {
 	return aCode.GetSize();
 }
@@ -85,7 +86,7 @@ void SbiCodeGen::GenStmnt()
 // Die Gen-Routinen returnen den Offset des 1. Operanden,
 // damit Jumps dort ihr Backchain versenken koennen
 
-USHORT SbiCodeGen::Gen( SbiOpcode eOpcode )
+UINT32 SbiCodeGen::Gen( SbiOpcode eOpcode )
 {
 #ifndef PRODUCT
 	if( eOpcode < SbOP0_START || eOpcode > SbOP0_END )
@@ -96,7 +97,7 @@ USHORT SbiCodeGen::Gen( SbiOpcode eOpcod
 	return GetPC();
 }
 
-USHORT SbiCodeGen::Gen( SbiOpcode eOpcode, UINT16 nOpnd )
+UINT32 SbiCodeGen::Gen( SbiOpcode eOpcode, UINT32 nOpnd )
 {
 #ifndef PRODUCT
 	if( eOpcode < SbOP1_START || eOpcode > SbOP1_END )
@@ -104,12 +105,12 @@ USHORT SbiCodeGen::Gen( SbiOpcode eOpcod
 #endif
 	GenStmnt();
 	aCode += (UINT8) eOpcode;
-	USHORT n = GetPC();
+	UINT32 n = GetPC();
 	aCode += nOpnd;
 	return n;
 }
 
-USHORT SbiCodeGen::Gen( SbiOpcode eOpcode, UINT16 nOpnd1, UINT16 nOpnd2 )
+UINT32 SbiCodeGen::Gen( SbiOpcode eOpcode, UINT32 nOpnd1, UINT32 nOpnd2 )
 {
 #ifndef PRODUCT
 	if( eOpcode < SbOP2_START || eOpcode > SbOP2_END )
@@ -117,7 +118,7 @@ USHORT SbiCodeGen::Gen( SbiOpcode eOpcod
 #endif
 	GenStmnt();
 	aCode += (UINT8) eOpcode;
-	USHORT n = GetPC();
+	UINT32 n = GetPC();
 	aCode += nOpnd1;
 	aCode += nOpnd2;
 	return n;
@@ -340,3 +341,197 @@ void SbiCodeGen::Save()
 	rMod.EndDefinitions();
 }
 
+template < class T >
+class PCodeVisitor
+{
+public:
+   virtual void start( BYTE* pStart ) = 0;
+   virtual void processOpCode0( SbiOpcode eOp ) = 0; 
+   virtual void processOpCode1( SbiOpcode eOp, T nOp1 ) = 0; 
+   virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 ) = 0; 
+   virtual bool processParams() = 0;
+   virtual void end() = 0;
+};
+
+template <class T>
+class PCodeBufferWalker
+{
+private:
+	T  m_nBytes;
+	BYTE* m_pCode;
+	T readParam( BYTE*& pCode )
+	{
+		short nBytes = sizeof( T );
+		T nOp1=0;
+		for ( int i=0; i<nBytes; ++i )
+			nOp1 |= *pCode++ << ( i * 8);
+		return nOp1;
+	}
+public:
+	PCodeBufferWalker( BYTE* pCode, T nBytes ): m_nBytes( nBytes ), m_pCode( pCode )
+	{
+	}
+	void visitBuffer( PCodeVisitor< T >& visitor )
+	{
+		BYTE* pCode = m_pCode;
+		if ( !pCode )
+			return;
+		BYTE* pEnd = pCode + m_nBytes;
+		visitor.start( m_pCode );
+		T nOp1 = 0, nOp2 = 0;
+		for( ; pCode < pEnd; )
+		{
+			SbiOpcode eOp = (SbiOpcode)(*pCode++);
+			
+			if ( eOp <= SbOP0_END )
+				visitor.processOpCode0( eOp );
+			else if( eOp >= SbOP1_START && eOp <= SbOP1_END )
+			{
+				if ( visitor.processParams() )
+					nOp1 = readParam( pCode );
+				else
+					pCode += sizeof( T );
+				visitor.processOpCode1( eOp, nOp1 );
+			}
+			else if( eOp >= SbOP2_START && eOp <= SbOP2_END )
+			{
+				if ( visitor.processParams() )
+				{
+					nOp1 = readParam( pCode );
+					nOp2 = readParam( pCode );
+				}
+				else
+					pCode += ( sizeof( T ) * 2 );
+				visitor.processOpCode2( eOp, nOp1, nOp2 );
+			}	
+		}
+		visitor.end();
+	}
+};
+
+template < class T, class S >
+class OffSetAccumulator : public PCodeVisitor< T >
+{
+	T m_nNumOp0;
+	T m_nNumSingleParams;
+	T m_nNumDoubleParams;
+public:
+	
+	OffSetAccumulator() : m_nNumOp0(0), m_nNumSingleParams(0), m_nNumDoubleParams(0){}
+	virtual void start( BYTE* /*pStart*/ ){}
+	virtual void processOpCode0( SbiOpcode /*eOp*/ ){ ++m_nNumOp0; }
+	virtual void processOpCode1( SbiOpcode /*eOp*/, T /*nOp1*/ ){  ++m_nNumSingleParams; }
+	virtual void processOpCode2( SbiOpcode /*eOp*/, T /*nOp1*/, T /*nOp2*/ ) { ++m_nNumDoubleParams; }
+	virtual void end(){}
+	S offset() 
+	{ 
+		T result = 0 ; 
+		static const S max = std::numeric_limits< S >::max();
+		result = m_nNumOp0 + ( ( sizeof(S) + 1 ) * m_nNumSingleParams ) + ( (( sizeof(S) * 2 )+ 1 )  * m_nNumDoubleParams ); 
+		if ( result > max ) 
+			return max;
+	
+		return static_cast<S>(result); 
+	}
+   virtual bool processParams(){ return false; }
+};
+
+
+
+template < class T, class S >
+
+class BufferTransformer : public PCodeVisitor< T >
+{
+	BYTE* m_pStart;
+	SbiBuffer m_ConvertedBuf;
+public:
+	BufferTransformer():m_pStart(NULL), m_ConvertedBuf( NULL, 1024 ) {}
+	virtual void start( BYTE* pStart ){ m_pStart = pStart; }
+	virtual void processOpCode0( SbiOpcode eOp ) 
+	{
+		m_ConvertedBuf += (UINT8)eOp;
+	}
+	virtual void processOpCode1( SbiOpcode eOp, T nOp1 )
+	{
+		m_ConvertedBuf += (UINT8)eOp;
+		switch( eOp )
+		{
+			case _JUMP:
+			case _JUMPT:
+			case _JUMPF:
+			case _GOSUB:
+			case _CASEIS:
+			case _RETURN:
+			case _ERRHDL:
+			case _TESTFOR:
+				nOp1 = convertBufferOffSet(m_pStart, nOp1);
+				break;
+			case _RESUME:
+				if ( nOp1 > 1 )
+					nOp1 = convertBufferOffSet(m_pStart, nOp1);
+				break;
+			default:
+				break; // 
+				
+		}
+		m_ConvertedBuf += (S)nOp1;
+	}
+	virtual void processOpCode2( SbiOpcode eOp, T nOp1, T nOp2 ) 
+	{
+		m_ConvertedBuf += (UINT8)eOp;
+		if ( eOp == _CASEIS )
+				if ( nOp1 )
+					nOp1  = convertBufferOffSet(m_pStart, nOp1);
+		m_ConvertedBuf += (S)nOp1;
+		m_ConvertedBuf += (S)nOp2;
+		
+	}
+	virtual bool processParams(){ return true; }
+	virtual void end() {}
+	// yeuch, careful here, you can only call
+	// GetBuffer on the returned SbiBuffer once, also
+	// you (as the caller) get to own the memory
+	SbiBuffer& buffer() 
+	{ 
+		return m_ConvertedBuf;
+	}
+	static S convertBufferOffSet( BYTE* pStart, T nOp1 )
+	{
+		PCodeBufferWalker< T > aBuff( pStart, nOp1);
+		OffSetAccumulator< T, S > aVisitor;
+		aBuff.visitBuffer( aVisitor ); 
+		return aVisitor.offset();
+	}
+};
+
+UINT32 
+SbiCodeGen::calcNewOffSet( BYTE* pCode, UINT16 nOffset )
+{
+	return BufferTransformer< UINT16, UINT32 >::convertBufferOffSet( pCode, nOffset );
+}
+
+UINT16 
+SbiCodeGen::calcLegacyOffSet( BYTE* pCode, UINT32 nOffset )
+{
+	return BufferTransformer< UINT32, UINT16 >::convertBufferOffSet( pCode, nOffset );
+}
+
+template <class T, class S>
+void
+PCodeBuffConvertor<T,S>::convert()
+{
+	PCodeBufferWalker< T > aBuf( m_pStart, m_nSize );
+	BufferTransformer< T, S > aTrnsfrmer;
+	aBuf.visitBuffer( aTrnsfrmer );	
+	m_pCnvtdBuf = (BYTE*)aTrnsfrmer.buffer().GetBuffer();
+	m_nCnvtdSize = aTrnsfrmer.buffer().GetSize();
+}
+
+void NeverRunsEver()
+{
+	// force instatiation of templates... I dunno why, but I have to do
+	// this to force instatiation of the template. Otherwise using the template
+	// in another code module results in link errors :-(
+	PCodeBuffConvertor< UINT16, UINT32 > aInst1(0,0);	
+	PCodeBuffConvertor< UINT32, UINT16 > aInst2(0,0);	
+}
Index: basic/source/comp/dim.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/dim.cxx,v
retrieving revision 1.24
retrieving revision 1.21.68.3
diff -u -p -u -p -r1.24 -r1.21.68.3
--- basic/source/comp/dim.cxx	17 Sep 2006 10:01:33 -0000	1.24
+++ basic/source/comp/dim.cxx	28 Sep 2006 22:29:20 -0000	1.21.68.3
@@ -267,7 +267,7 @@ void SbiParser::DefVar( SbiOpcode eOp, B
 	SbiDimList* pDim;
 
 	// AB 9.7.97, #40689, Statics -> Modul-Initialisierung, in Sub ueberspringen
-	USHORT nEndOfStaticLbl = 0;
+	UINT32 nEndOfStaticLbl = 0;
 	if( bStatic )
 	{
 		nEndOfStaticLbl = aGen.Gen( _JUMP, 0 );
Index: basic/source/comp/loops.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/loops.cxx,v
retrieving revision 1.10
retrieving revision 1.8.4.3
diff -u -p -u -p -r1.10 -r1.8.4.3
--- basic/source/comp/loops.cxx	17 Sep 2006 10:02:49 -0000	1.10
+++ basic/source/comp/loops.cxx	28 Sep 2006 22:30:03 -0000	1.8.4.3
@@ -42,7 +42,7 @@
 
 void SbiParser::If()
 {
-	USHORT nEndLbl;
+	UINT32 nEndLbl;
 	SbiToken eTok = NIL;
 	// Ende-Tokens ignorieren:
 	SbiExpression aCond( this );
@@ -54,7 +54,7 @@ void SbiParser::If()
 		// eingefuegt werden, damit bei ELSEIF nicht erneut die Bedingung
 		// ausgewertet wird. Die Tabelle nimmt alle Absprungstellen auf.
 #define JMP_TABLE_SIZE 100
-		USHORT pnJmpToEndLbl[JMP_TABLE_SIZE];	// 100 ELSEIFs zulaessig
+		UINT32 pnJmpToEndLbl[JMP_TABLE_SIZE];	// 100 ELSEIFs zulaessig
 		USHORT iJmp = 0;						// aktueller Tabellen-Index
 
 		// multiline IF
@@ -102,7 +102,7 @@ void SbiParser::If()
 		if( eTok == ELSE )
 		{
 			Next();
-			USHORT nElseLbl = nEndLbl;
+			UINT32 nElseLbl = nEndLbl;
 			nEndLbl = aGen.Gen( _JUMP, 0 );
 			aGen.BackChain( nElseLbl );
 
@@ -135,7 +135,7 @@ void SbiParser::If()
 		if( eTok == ELSE )
 		{
 			Next();
-			USHORT nElseLbl = nEndLbl;
+			UINT32 nElseLbl = nEndLbl;
 			nEndLbl = aGen.Gen( _JUMP, 0 );
 			aGen.BackChain( nElseLbl );
 			while( !bAbort )
@@ -164,7 +164,7 @@ void SbiParser::NoIf()
 
 void SbiParser::DoLoop()
 {
-	USHORT nStartLbl = aGen.GetPC();
+	UINT32 nStartLbl = aGen.GetPC();
 	OpenBlock( DO );
 	SbiToken eTok = Next();
 	if( IsEoln( eTok ) )
@@ -191,7 +191,7 @@ void SbiParser::DoLoop()
 			SbiExpression aCond( this );
 			aCond.Gen();
 		}
-		USHORT nEndLbl = aGen.Gen( eTok == UNTIL ? _JUMPT : _JUMPF, 0 );
+		UINT32 nEndLbl = aGen.Gen( eTok == UNTIL ? _JUMPT : _JUMPF, 0 );
 		StmntBlock( LOOP );
 		TestEoln();
 		aGen.Gen( _JUMP, nStartLbl );
@@ -205,9 +205,9 @@ void SbiParser::DoLoop()
 void SbiParser::While()
 {
 	SbiExpression aCond( this );
-	USHORT nStartLbl = aGen.GetPC();
+	UINT32 nStartLbl = aGen.GetPC();
 	aCond.Gen();
-	USHORT nEndLbl = aGen.Gen( _JUMPF, 0 );
+	UINT32 nEndLbl = aGen.Gen( _JUMPF, 0 );
 	StmntBlock( WEND );
 	aGen.Gen( _JUMP, nStartLbl );
 	aGen.BackChain( nEndLbl );
@@ -256,9 +256,9 @@ void SbiParser::For()
 		aGen.Gen( _INITFOR );
 	}
 
-	USHORT nLoop = aGen.GetPC();
+	UINT32 nLoop = aGen.GetPC();
 	// Test durchfuehren, evtl. Stack freigeben
-	USHORT nEndTarget = aGen.Gen( _TESTFOR, 0 );
+	UINT32 nEndTarget = aGen.Gen( _TESTFOR, 0 );
 	OpenBlock( FOR );
 	StmntBlock( NEXT );
 	aGen.Gen( _NEXT );
@@ -313,7 +313,7 @@ void SbiParser::OnGoto()
 {
 	SbiExpression aCond( this );
 	aCond.Gen();
-	USHORT nLabelsTarget = aGen.Gen( _ONJUMP, 0 );
+	UINT32 nLabelsTarget = aGen.Gen( _ONJUMP, 0 );
 	SbiToken eTok = Next();
 	if( eTok != GOTO && eTok != GOSUB )
 	{
@@ -321,14 +321,14 @@ void SbiParser::OnGoto()
 		eTok = GOTO;
 	}
 	// Label-Tabelle einlesen:
-	short nLbl = 0;
+	UINT32 nLbl = 0;
 	do
 	{
 		SbiToken eTok2 = NIL;
 		eTok2 = Next();	// Label holen
 		if( MayBeLabel() )
 		{
-			USHORT nOff = pProc->GetLabels().Reference( aSym );
+			UINT32 nOff = pProc->GetLabels().Reference( aSym );
 			aGen.Gen( _JUMP, nOff );
 			nLbl++;
 		}
@@ -348,7 +348,7 @@ void SbiParser::Goto()
 	Next();
 	if( MayBeLabel() )
 	{
-		USHORT nOff = pProc->GetLabels().Reference( aSym );
+		UINT32 nOff = pProc->GetLabels().Reference( aSym );
 		aGen.Gen( eOp, nOff );
 	}
 	else Error( SbERR_LABEL_EXPECTED );
@@ -361,7 +361,7 @@ void SbiParser::Return()
 	Next();
 	if( MayBeLabel() )
 	{
-		USHORT nOff = pProc->GetLabels().Reference( aSym );
+		UINT32 nOff = pProc->GetLabels().Reference( aSym );
 		aGen.Gen( _RETURN, nOff );
 	}
 	else aGen.Gen( _RETURN, 0 );
@@ -377,8 +377,8 @@ void SbiParser::Select()
 	aCase.Gen();
 	aGen.Gen( _CASE );
 	TestEoln();
-	USHORT nNextTarget = 0;
-	USHORT nDoneTarget = 0;
+	UINT32 nNextTarget = 0;
+	UINT32 nDoneTarget = 0;
 	BOOL bElse = FALSE;
 	// Die Cases einlesen:
 	while( !bAbort )
@@ -391,7 +391,7 @@ void SbiParser::Select()
 			aGen.Statement();
 			// Jeden Case einlesen
 			BOOL bDone = FALSE;
-			USHORT nTrueTarget = 0;
+			UINT32 nTrueTarget = 0;
 			if( Peek() == ELSE )
 			{
 				// CASE ELSE
@@ -499,7 +499,7 @@ void SbiParser::On()
 					aGen.Gen( _STDERROR );
 				else
 				{
-					USHORT nOff = pProc->GetLabels().Reference( aSym );
+					UINT32 nOff = pProc->GetLabels().Reference( aSym );
 					aGen.Gen( _ERRHDL, nOff );
 				}
 			}
@@ -531,7 +531,7 @@ void SbiParser::On()
 
 void SbiParser::Resume()
 {
-	USHORT nLbl;
+	UINT32 nLbl;
 
 	switch( Next() )
 	{
Index: basic/source/comp/parser.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/parser.cxx,v
retrieving revision 1.17
retrieving revision 1.13.64.3
diff -u -p -u -p -r1.17 -r1.13.64.3
--- basic/source/comp/parser.cxx	17 Sep 2006 10:03:03 -0000	1.17
+++ basic/source/comp/parser.cxx	28 Sep 2006 22:30:08 -0000	1.13.64.3
@@ -45,7 +45,7 @@ struct SbiParseStack {				// "Stack" fue
 	SbiParseStack* pNext;  			// Chain
 	SbiExprNode* pWithVar;			// Variable fuer WITH
 	SbiToken eExitTok;				// Exit-Token
-	USHORT  nChain;					// JUMP-Chain
+	UINT32  nChain;					// JUMP-Chain
 };
 
 struct SbiStatement {
Index: basic/source/comp/symtbl.cxx
===================================================================
RCS file: /cvs/script/basic/source/comp/symtbl.cxx,v
retrieving revision 1.15
retrieving revision 1.13.68.3
diff -u -p -u -p -r1.15 -r1.13.68.3
--- basic/source/comp/symtbl.cxx	17 Sep 2006 10:03:42 -0000	1.15
+++ basic/source/comp/symtbl.cxx	28 Sep 2006 22:30:26 -0000	1.13.68.3
@@ -265,7 +265,7 @@ USHORT SbiSymPool::Define( const String&
 	return p->Define();
 }
 
-USHORT SbiSymPool::Reference( const String& rName )
+UINT32 SbiSymPool::Reference( const String& rName )
 {
 	SbiSymDef* p = Find( rName );
 	if( !p )
@@ -365,11 +365,11 @@ void SbiSymDef::SetType( SbxDataType t )
 // Es wird der Wert zurueckgeliefert, der als Operand gespeichert
 // werden soll.
 
-USHORT SbiSymDef::Reference()
+UINT32 SbiSymDef::Reference()
 {
 	if( !bChained )
 	{
-		USHORT n = nChain;
+		UINT32 n = nChain;
 		nChain = pIn->pParser->aGen.GetOffset();
 		return n;
 	}
@@ -381,7 +381,7 @@ USHORT SbiSymDef::Reference()
 
 USHORT SbiSymDef::Define()
 {
-	USHORT n = pIn->pParser->aGen.GetPC();
+	UINT32 n = pIn->pParser->aGen.GetPC();
 	pIn->pParser->aGen.GenStmnt();
 	if( nChain ) pIn->pParser->aGen.BackChain( nChain );
 	nChain = n;
Index: basic/source/inc/buffer.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/buffer.hxx,v
retrieving revision 1.4
retrieving revision 1.4.70.1
diff -u -p -u -p -r1.4 -r1.4.70.1
--- basic/source/inc/buffer.hxx	29 Sep 2005 16:31:37 -0000	1.4
+++ basic/source/inc/buffer.hxx	20 Apr 2006 09:41:56 -0000	1.4.70.1
@@ -49,24 +49,27 @@ class SbiBuffer { 					// Code/Konstante
 	SbiParser* pParser;				// fuer Fehlermeldungen
 	char*	pBuf;					// Puffer-Pointer
 	char*	pCur;					// aktueller Puffer-Pointer
-	USHORT	nOff;					// aktuelles Offset
-	USHORT	nSize;					// aktuelle Groesse
+	UINT32	nOff;					// aktuelles Offset
+	UINT32	nSize;					// aktuelle Groesse
 	short	nInc;					// Inkrement
 	BOOL    Check( USHORT );		// Buffergroesse testen
 public:
 	SbiBuffer( SbiParser*, short );	// Inkrement
    ~SbiBuffer();
-	void Patch( USHORT, USHORT );	// Patchen
-	void Chain( USHORT );			// Back-Chain
-	void Align( short );			// Alignment
+	void Patch( UINT32, UINT32 );	// Patchen
+	void Chain( UINT32 );			// Back-Chain
+	void Align( INT32 );			// Alignment
 	BOOL Add( const void*, USHORT );// Element anfuegen
 	BOOL operator += (const String&);// Basic-String speichern
 	BOOL operator += (INT8);		// Zeichen speichern
 	BOOL operator += (INT16);		// Integer speichern
 	BOOL operator += (UINT8);		// Zeichen speichern
 	BOOL operator += (UINT16);		// Integer speichern
+	BOOL operator += (UINT32);		// Integer speichern
+	BOOL operator += (INT32);		// Integer speichern
 	char*  GetBuffer();				// Puffer rausgeben (selbst loeschen!)
-	USHORT GetSize()				{ return nOff; }
+	char*  GetBufferPtr(){ return pBuf; }
+	UINT32 GetSize()				{ return nOff; }
 };
 
 #endif
Index: basic/source/inc/codegen.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/codegen.hxx,v
retrieving revision 1.5
retrieving revision 1.5.70.2
diff -u -p -u -p -r1.5 -r1.5.70.2
--- basic/source/inc/codegen.hxx	29 Sep 2005 16:31:37 -0000	1.5
+++ basic/source/inc/codegen.hxx	18 Aug 2006 14:26:58 -0000	1.5.70.2
@@ -56,20 +56,44 @@ class SbiCodeGen { 				// Code-Erzeugung
 public:
 	SbiCodeGen( SbModule&, SbiParser*, short );
 	SbiParser* GetParser() { return pParser; }
-	USHORT Gen( SbiOpcode );
-	USHORT Gen( SbiOpcode, UINT16 );
-	USHORT Gen( SbiOpcode, UINT16, UINT16 );
-	void Patch( USHORT o, USHORT v ){ aCode.Patch( o, v ); }
-	void BackChain( USHORT off )	{ aCode.Chain( off );  }
+	UINT32 Gen( SbiOpcode );
+	UINT32 Gen( SbiOpcode, UINT32 );
+	UINT32 Gen( SbiOpcode, UINT32, UINT32 );
+	void Patch( UINT32 o, UINT32 v ){ aCode.Patch( o, v ); }
+	void BackChain( UINT32 off )	{ aCode.Chain( off );  }
 	void Statement();
 	void GenStmnt();			// evtl. Statement-Opcode erzeugen
-	USHORT GetPC();
-	USHORT GetOffset()				{ return GetPC() + 1; }
+	UINT32 GetPC();
+	UINT32 GetOffset()				{ return GetPC() + 1; }
 	void Save();
 
 	// #29955 for-Schleifen-Ebene pflegen
 	void IncForLevel( void ) { nForLevel++; }
 	void DecForLevel( void ) { nForLevel--; }
+
+	static UINT32 calcNewOffSet( BYTE* pCode, UINT16 nOffset );
+	static UINT16 calcLegacyOffSet( BYTE* pCode, UINT32 nOffset );
+
+};
+
+template < class T, class S >
+class PCodeBuffConvertor 
+{
+	T m_nSize; // 
+	BYTE* m_pStart;
+	BYTE* m_pCnvtdBuf;
+	S m_nCnvtdSize; // 
+
+	//  Disable usual copying symantics and bodgy default ctor
+	PCodeBuffConvertor(); 
+	PCodeBuffConvertor(const PCodeBuffConvertor& );
+	PCodeBuffConvertor& operator = ( const PCodeBuffConvertor& );
+public:
+	PCodeBuffConvertor( BYTE* pCode, T nSize ): m_nSize( nSize ),  m_pStart( pCode ), m_pCnvtdBuf( NULL ), m_nCnvtdSize( 0 ){ convert(); }
+	S GetSize(){ return m_nCnvtdSize; }
+	void convert();
+	// Caller owns the buffer returned
+	BYTE* GetBuffer() { return m_pCnvtdBuf; }
 };
 
 // #111897 PARAM_INFO flags start at 0x00010000 to not
Index: basic/source/inc/disas.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/disas.hxx,v
retrieving revision 1.4
retrieving revision 1.4.70.1
diff -u -p -u -p -r1.4 -r1.4.70.1
--- basic/source/inc/disas.hxx	29 Sep 2005 16:31:37 -0000	1.4
+++ basic/source/inc/disas.hxx	20 Apr 2006 09:41:56 -0000	1.4.70.1
@@ -38,15 +38,15 @@
 
 #include "image.hxx"
 #include "opcodes.hxx"
-
+// find a place for this limit ( also used in 
 class SvStream;
-
+#define MAX_LABELS 0x20000000L
 class SbiDisas {
 	const SbiImage& rImg;
 	SbModule* pMod;
-	char	 cLabels[ 8192 ];		// Bitvektor fuer Labels
-	USHORT	 nOff;					// aktuelle Position
-	USHORT   nPC;					// Position des Opcodes
+	char	 cLabels[ MAX_LABELS ];		// Bitvektor fuer Labels
+	UINT32	 nOff;					// aktuelle Position
+	UINT32   nPC;					// Position des Opcodes
 	SbiOpcode eOp;					// Opcode
 	USHORT   nOp1, nOp2;			// Operanden
 	short	 nParts;				// 1, 2 oder 3
Index: basic/source/inc/filefmt.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/filefmt.hxx,v
retrieving revision 1.5
retrieving revision 1.5.70.1
diff -u -p -u -p -r1.5 -r1.5.70.1
--- basic/source/inc/filefmt.hxx	29 Sep 2005 16:31:37 -0000	1.5
+++ basic/source/inc/filefmt.hxx	20 Apr 2006 09:41:56 -0000	1.5.70.1
@@ -59,7 +59,9 @@ class SvStream;
 // Version 10: #29955 For-Schleifen-Level in Statement-PCodes generieren
 // Version 11: #29955 Wegen Build-Inkonsistenzen Neu-Compilieren erzwingen
 
-#define B_CURVERSION 0x00000011L
+#define B_LEGACYVERSION 0x00000011L
+#define B_CURVERSION 0x00000012L
+#define B_EXT_IMG_VERSION 0x00000012L
 
 // Eine Datei enthaelt entweder einen Modul- oder einen Library-Record.
 // Diese Records enthalten wiederum weitere Records. Jeder Record hat
Index: basic/source/inc/image.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/image.hxx,v
retrieving revision 1.9
retrieving revision 1.8.70.6
diff -u -p -u -p -r1.9 -r1.8.70.6
--- basic/source/inc/image.hxx	5 May 2006 10:12:10 -0000	1.9
+++ basic/source/inc/image.hxx	3 Oct 2006 16:53:32 -0000	1.8.70.6
@@ -40,6 +40,7 @@
 #ifndef _RTL_USTRING_HXX
 #include <rtl/ustring.hxx>
 #endif
+#include <filefmt.hxx>
 
 // Diese Klasse liest das vom Compiler erzeugte Image ein und verwaltet
 // den Zugriff auf die einzelnen Elemente.
@@ -51,23 +52,25 @@ class SbiImage {
 
 	SbxArrayRef    rTypes;			// User defined types
 	SbxArrayRef    rEnums;			// Enum types
-	UINT16*		   pStringOff;		// StringId-Offsets
+	UINT32*		   pStringOff;		// StringId-Offsets
 	sal_Unicode*   pStrings;		// StringPool
 	char* 		   pCode;			// Code-Image
+	char* 		   pLegacyPCode;		// Code-Image
 	BOOL		   bError;			// TRUE: Fehler
 	USHORT		   nFlags;			// Flags (s.u.)
 	short		   nStrings;   		// Anzahl Strings
-	UINT16		   nStringSize;		// Groesse des String-Puffers
-	UINT16		   nCodeSize;		// Groesse des Code-Blocks
+	UINT32		   nStringSize;		// Groesse des String-Puffers
+	UINT32		   nCodeSize;		// Groesse des Code-Blocks
+	UINT16		   nLegacyCodeSize;		// Groesse des Code-Blocks
 	UINT16		   nDimBase;		// OPTION BASE-Wert
 	rtl_TextEncoding eCharSet;		// Zeichensatz fuer Strings
 									// temporaere Verwaltungs-Variable:
 	short		   nStringIdx;		// aktueller String-Index
-	UINT16		   nStringOff;		// aktuelle Pos im Stringpuffer
+	UINT32		   nStringOff;		// aktuelle Pos im Stringpuffer
 									// Routinen fuer Compiler:
 	void MakeStrings( short );		// StringPool einrichten
 	void AddString( const String& );// String zufuegen
-	void AddCode( char*, USHORT );	// Codeblock dazu
+	void AddCode( char*, UINT32 );	// Codeblock dazu
 	void AddType(SbxObject *);      // User-Type mit aufnehmen
 	void AddEnum(SbxObject *);      // Register enum type
 
@@ -81,12 +84,15 @@ public:
 	SbiImage();
    ~SbiImage();
 	void Clear();					// Inhalt loeschen
+	BOOL Load( SvStream&, UINT32& nVer );		// Loads image from stream
+							// nVer is set to version
+							// of image
 	BOOL Load( SvStream& );
-	BOOL Save( SvStream& );
+	BOOL Save( SvStream&, UINT32 = B_CURVERSION );
 	BOOL IsError() 					{ return bError;    }
 
 	const char* GetCode() const 	{ return pCode; 	}
-	USHORT		GetCodeSize() const	{ return nCodeSize;	}
+	UINT32		GetCodeSize() const	{ return nCodeSize;	}
     ::rtl::OUString& GetSource32() 	{ return aOUSource; }
 	USHORT		GetBase() const		{ return nDimBase;	}
 	String		GetString( short nId ) const;
@@ -97,6 +103,11 @@ public:
 
 	void		SetFlag( USHORT n )	{ nFlags |= n;		}
 	USHORT		GetFlag( USHORT n )	const { return nFlags & n; }
+	UINT16		CalcLegacyOffset( INT32 nOffset );
+	UINT32		CalcNewOffset( INT16 nOffset );
+	void		ReleaseLegacyBuffer();
+	BOOL		ExceedsLegacyLimits();
+	
 };
 
 #define	SBIMG_EXPLICIT		0x0001	// OPTION EXPLICIT ist aktiv
Index: basic/source/inc/parser.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/parser.hxx,v
retrieving revision 1.9
retrieving revision 1.8.70.2
diff -u -p -u -p -r1.9 -r1.8.70.2
--- basic/source/inc/parser.hxx	5 May 2006 10:12:25 -0000	1.9
+++ basic/source/inc/parser.hxx	28 Jun 2006 11:03:33 -0000	1.8.70.2
@@ -60,7 +60,7 @@ class SbiParser : public SbiTokenizer
 	SbiProcDef* pProc;				// aktuelle Prozedur
 	SbiExprNode*  pWithVar;			// aktuelle With-Variable
 	SbiToken    eEndTok;   			// das Ende-Token
-	USHORT		nGblChain;			// Chainkette fuer globale DIMs
+	UINT32		nGblChain;			// Chainkette fuer globale DIMs
 	BOOL		bGblDefs; 			// TRUE globale Definitionen allgemein
 	BOOL		bNewGblDefs; 		// TRUE globale Definitionen vor Sub
 	BOOL		bSingleLineIf; 		// TRUE einzeiliges if-Statement
Index: basic/source/inc/runtime.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/runtime.hxx,v
retrieving revision 1.30
retrieving revision 1.28.4.2
diff -u -p -u -p -r1.30 -r1.28.4.2
--- basic/source/inc/runtime.hxx	19 Jun 2006 17:44:06 -0000	1.30
+++ basic/source/inc/runtime.hxx	28 Jun 2006 11:03:47 -0000	1.28.4.2
@@ -321,8 +321,8 @@ public:
 class SbiRuntime
 {
 	typedef void( SbiRuntime::*pStep0 )();
-	typedef void( SbiRuntime::*pStep1 )( USHORT nOp1 );
-	typedef void( SbiRuntime::*pStep2 )( USHORT nOp1, USHORT nOp2 );
+	typedef void( SbiRuntime::*pStep1 )( UINT32 nOp1 );
+	typedef void( SbiRuntime::*pStep2 )( UINT32 nOp1, UINT32 nOp2 );
 	static pStep0 aStep0[];         // Opcode-Tabelle Gruppe 0
 	static pStep1 aStep1[];         // Opcode-Tabelle Gruppe 1
 	static pStep2 aStep2[];         // Opcode-Tabelle Gruppe 2
@@ -390,8 +390,8 @@ class SbiRuntime
 	}
 
 	SbxVariable* FindElement
-	( SbxObject* pObj, USHORT nOp1, USHORT nOp2, SbError, BOOL );
-	void SetupArgs( SbxVariable*, USHORT );
+	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError, BOOL );
+	void SetupArgs( SbxVariable*, UINT32 );
 	SbxVariable* CheckArray( SbxVariable* );
 
 	void PushVar( SbxVariable* );   // Variable push
@@ -448,38 +448,39 @@ class SbiRuntime
 	void StepRESTART(), StepEMPTY(),    StepLEAVE();
 	void StepLSET(),	StepRSET(),		StepREDIMP_ERASE();
 	// Alle Opcodes mit einem Operanden
-	void StepLOADNC( USHORT ),  StepLOADSC( USHORT ),   StepLOADI( USHORT );
-	void StepARGN( USHORT ),	StepBASED( USHORT ),	StepPAD( USHORT );
-	void StepJUMP( USHORT ),    StepJUMPT( USHORT );
-	void StepJUMPF( USHORT ),   StepONJUMP( USHORT );
-	void StepGOSUB( USHORT ),   StepRETURN( USHORT );
-	void StepTESTFOR( USHORT ), StepCASETO( USHORT ),   StepERRHDL( USHORT );
-	void StepRESUME( USHORT ),  StepSETCLASS( USHORT ),	StepTESTCLASS( USHORT ), StepLIB( USHORT );
+	void StepLOADNC( UINT32 ),  StepLOADSC( UINT32 ),   StepLOADI( UINT32 );
+	void StepARGN( UINT32 ),	StepBASED( UINT32 ),	StepPAD( UINT32 );
+	void StepJUMP( UINT32 ),    StepJUMPT( UINT32 );
+	void StepJUMPF( UINT32 ),   StepONJUMP( UINT32 );
+	void StepGOSUB( UINT32 ),   StepRETURN( UINT32 );
+	void StepTESTFOR( UINT32 ), StepCASETO( UINT32 ),   StepERRHDL( UINT32 );
+	void StepRESUME( UINT32 ),  StepSETCLASS( UINT32 ),	StepTESTCLASS( UINT32 ), StepLIB( UINT32 );
 	bool checkClass_Impl( const SbxVariableRef& refVal, const String& aClass, bool bRaiseErrors );
-	void StepCLOSE( USHORT ),   StepPRCHAR( USHORT ),   StepARGTYP( USHORT );
+	void StepCLOSE( UINT32 ),   StepPRCHAR( UINT32 ),   StepARGTYP( UINT32 );
 	// Alle Opcodes mit zwei Operanden
-	void StepRTL( USHORT, USHORT ),		StepPUBLIC( USHORT, USHORT );		
-	void StepPUBLIC_Impl( USHORT, USHORT, bool bUsedForClassModule );
-	void StepFIND( USHORT, USHORT ),    StepELEM( USHORT, USHORT );
-	void StepGLOBAL( USHORT, USHORT ),  StepLOCAL( USHORT, USHORT );
-	void StepPARAM( USHORT, USHORT), 	StepCREATE( USHORT, USHORT );
-	void StepCALL( USHORT, USHORT ),    StepCALLC( USHORT, USHORT );
-	void StepCASEIS( USHORT, USHORT ),  StepSTMNT( USHORT, USHORT );
-	void StepOPEN( USHORT, USHORT ),	StepSTATIC( USHORT, USHORT );
-	void StepTCREATE(USHORT,USHORT),	StepDCREATE(USHORT,USHORT);
-	void StepGLOBAL_P( USHORT, USHORT ),StepFIND_G( USHORT, USHORT );
-	void StepDCREATE_REDIMP(USHORT,USHORT), StepDCREATE_IMPL(USHORT,USHORT);
-	void StepFIND_CM( USHORT, USHORT );
+	void StepRTL( UINT32, UINT32 ),		StepPUBLIC( UINT32, UINT32 );		
+	void StepPUBLIC_Impl( UINT32, UINT32, bool bUsedForClassModule );
+	void StepFIND( UINT32, UINT32 ),    StepELEM( UINT32, UINT32 );
+	void StepGLOBAL( UINT32, UINT32 ),  StepLOCAL( UINT32, UINT32 );
+	void StepPARAM( UINT32, UINT32), 	StepCREATE( UINT32, UINT32 );
+	void StepCALL( UINT32, UINT32 ),    StepCALLC( UINT32, UINT32 );
+	void StepCASEIS( UINT32, UINT32 ),  StepSTMNT( UINT32, UINT32 );
+	void StepOPEN( UINT32, UINT32 ),	StepSTATIC( UINT32, UINT32 );
+	void StepTCREATE(UINT32,UINT32),	StepDCREATE(UINT32,UINT32);
+	void StepGLOBAL_P( UINT32, UINT32 ),StepFIND_G( UINT32, UINT32 );
+	void StepDCREATE_REDIMP(UINT32,UINT32), StepDCREATE_IMPL(UINT32,UINT32);
+	void StepFIND_CM( UINT32, UINT32 );
 public:
 	USHORT		GetImageFlag( USHORT n ) const;
 	USHORT		GetBase();
 	xub_StrLen  nLine,nCol1,nCol2;	// aktuelle Zeile, Spaltenbereich
 	SbiRuntime* pNext;               // Stack-Chain
 
-	SbiRuntime( SbModule*, SbMethod*, USHORT );
+	SbiRuntime( SbModule*, SbMethod*, UINT32 );
    ~SbiRuntime();
 	void Error( SbError );			// Fehler setzen, falls != 0
 	void FatalError( SbError );		// Fehlerbehandlung=Standard, Fehler setzen
+	void DumpPCode();
 	BOOL Step();                    // Einzelschritt (ein Opcode)
 	void Stop()     	   { bRun = FALSE;   }
     BOOL IsRun()           { return bRun;    }
Index: basic/source/inc/symtbl.hxx
===================================================================
RCS file: /cvs/script/basic/source/inc/symtbl.hxx,v
retrieving revision 1.8
retrieving revision 1.8.76.1
diff -u -p -u -p -r1.8 -r1.8.76.1
--- basic/source/inc/symtbl.hxx	7 Sep 2005 21:37:20 -0000	1.8
+++ basic/source/inc/symtbl.hxx	20 Apr 2006 09:41:57 -0000	1.8.76.1
@@ -120,7 +120,7 @@ public:
 	SbiSymDef* First(), *Next();  		// Iteratoren
 
 	USHORT Define( const String& );		// Label definieren
-	USHORT Reference( const String& );  // Label referenzieren
+	UINT32 Reference( const String& );  // Label referenzieren
 	void   CheckRefs();					// offene Referenzen suchen
 };
 
@@ -139,7 +139,7 @@ protected:
 	USHORT	   nTypeId;				// String-ID des Datentyps (Dim X AS Dytentyp)
 	USHORT	   nProcId;				// aktuelles ProcId fuer STATIC-Variable
 	USHORT	   nPos;				// Positions-Nummer
-	USHORT	   nChain;				// Backchain-Kette
+	UINT32	   nChain;				// Backchain-Kette
 	BOOL	   bNew		: 1;		// TRUE: Dim As New...
 	BOOL	   bChained : 1;		// TRUE: Symbol ist in Code definiert
 	BOOL	   bByVal   : 1;		// TRUE: ByVal-Parameter
@@ -160,7 +160,7 @@ public:
 	const String& GetName();
 	SbiSymScope GetScope() const;
 	USHORT	   GetProcId() const{ return nProcId;	}
-	USHORT	   GetAddr() const	{ return nChain;	}
+	UINT32	   GetAddr() const	{ return nChain;	}
 	USHORT	   GetId() const 	{ return nId;		}
 	USHORT	   GetTypeId() const{ return nTypeId;	}
 	void 	   SetTypeId( USHORT n ) { nTypeId = n; eType = SbxOBJECT; }
@@ -189,7 +189,7 @@ public:
 
 	SbiSymPool& GetPool();
 	USHORT	   Define();		// Symbol in Code definieren
-	USHORT	   Reference();		// Symbol in Code referenzieren
+	UINT32	   Reference();		// Symbol in Code referenzieren
 
 private:
 	SbiSymDef( const SbiSymDef& );
Index: basic/source/runtime/runtime.cxx
===================================================================
RCS file: /cvs/script/basic/source/runtime/runtime.cxx,v
retrieving revision 1.30
retrieving revision 1.26.42.4
diff -u -p -u -p -r1.30 -r1.26.42.4
--- basic/source/runtime/runtime.cxx	17 Sep 2006 10:05:55 -0000	1.30
+++ basic/source/runtime/runtime.cxx	28 Sep 2006 22:31:31 -0000	1.26.42.4
@@ -503,7 +503,7 @@ SbxArray* SbiInstance::GetLocals( SbMeth
 
 // Achtung: pMeth kann auch NULL sein (beim Aufruf des Init-Codes)
 
-SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, USHORT nStart )
+SbiRuntime::SbiRuntime( SbModule* pm, SbMethod* pe, UINT32 nStart )
 		 : rBasic( *(StarBASIC*)pm->pParent ), pInst( pINST ), 
 		   pMod( pm ), pMeth( pe ), pImg( pMod->pImage )
 {
@@ -669,22 +669,22 @@ BOOL SbiRuntime::Step()
 			if( pInst->IsReschedule() && bStaticGlobalEnableReschedule )
 				Application::Reschedule();
 		}
-
 		SbiOpcode eOp = (SbiOpcode ) ( *pCode++ );
-		USHORT nOp1, nOp2;
+		UINT32 nOp1, nOp2;
 		if( eOp <= SbOP0_END )
 		{
 			(this->*( aStep0[ eOp ] ) )();
 		}
 		else if( eOp >= SbOP1_START && eOp <= SbOP1_END )
 		{
-			nOp1 = *pCode++; nOp1 |= *pCode++ << 8;
+			nOp1 = *pCode++; nOp1 |= *pCode++ << 8; nOp1 |= *pCode++ << 16; nOp1 |= *pCode++ << 24;
+			
 			(this->*( aStep1[ eOp - SbOP1_START ] ) )( nOp1 );
 		}
 		else if( eOp >= SbOP2_START && eOp <= SbOP2_END )
 		{
-			nOp1 = *pCode++; nOp1 |= *pCode++ << 8;
-			nOp2 = *pCode++; nOp2 |= *pCode++ << 8;
+			nOp1 = *pCode++; nOp1 |= *pCode++ << 8; nOp1 |= *pCode++ << 16; nOp1 |= *pCode++ << 24;
+			nOp2 = *pCode++; nOp2 |= *pCode++ << 8; nOp2 |= *pCode++ << 16; nOp2 |= *pCode++ << 24;
 			(this->*( aStep2[ eOp - SbOP2_START ] ) )( nOp1, nOp2 );
 		}
 		else
Index: basic/source/runtime/step1.cxx
===================================================================
RCS file: /cvs/script/basic/source/runtime/step1.cxx,v
retrieving revision 1.13
retrieving revision 1.11.74.4
diff -u -p -u -p -r1.13 -r1.11.74.4
--- basic/source/runtime/step1.cxx	17 Sep 2006 10:06:49 -0000	1.13
+++ basic/source/runtime/step1.cxx	28 Sep 2006 22:31:56 -0000	1.11.74.4
@@ -46,7 +46,7 @@
 
 // Laden einer numerischen Konstanten (+ID)
 
-void SbiRuntime::StepLOADNC( USHORT nOp1 )
+void SbiRuntime::StepLOADNC( UINT32 nOp1 )
 {
 	SbxVariable* p = new SbxVariable( SbxDOUBLE );
 
@@ -70,7 +70,7 @@ void SbiRuntime::StepLOADNC( USHORT nOp1
 
 // Laden einer Stringkonstanten (+ID)
 
-void SbiRuntime::StepLOADSC( USHORT nOp1 )
+void SbiRuntime::StepLOADSC( UINT32 nOp1 )
 {
 	SbxVariable* p = new SbxVariable;
 	p->PutString( pImg->GetString( nOp1 ) );
@@ -79,7 +79,7 @@ void SbiRuntime::StepLOADSC( USHORT nOp1
 
 // Immediate Load (+Wert)
 
-void SbiRuntime::StepLOADI( USHORT nOp1 )
+void SbiRuntime::StepLOADI( UINT32 nOp1 )
 {
 	SbxVariable* p = new SbxVariable;
 	p->PutInteger( nOp1 );
@@ -88,7 +88,7 @@ void SbiRuntime::StepLOADI( USHORT nOp1 
 
 // Speichern eines named Arguments in Argv (+Arg-Nr ab 1!)
 
-void SbiRuntime::StepARGN( USHORT nOp1 )
+void SbiRuntime::StepARGN( UINT32 nOp1 )
 {
 	if( !refArgv )
 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
@@ -103,7 +103,7 @@ void SbiRuntime::StepARGN( USHORT nOp1 )
 
 // Konvertierung des Typs eines Arguments in Argv fuer DECLARE-Fkt. (+Typ)
 
-void SbiRuntime::StepARGTYP( USHORT nOp1 )
+void SbiRuntime::StepARGTYP( UINT32 nOp1 )
 {
 	if( !refArgv )
 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
@@ -148,7 +148,7 @@ void SbiRuntime::StepARGTYP( USHORT nOp1
 
 // String auf feste Laenge bringen (+Laenge)
 
-void SbiRuntime::StepPAD( USHORT nOp1 )
+void SbiRuntime::StepPAD( UINT32 nOp1 )
 {
 	SbxVariable* p = GetTOS();
 	String& s = (String&)(const String&) *p;
@@ -160,9 +160,11 @@ void SbiRuntime::StepPAD( USHORT nOp1 )
 
 // Sprung (+Target)
 
-void SbiRuntime::StepJUMP( USHORT nOp1 )
+void SbiRuntime::StepJUMP( UINT32 nOp1 )
 {
 #ifndef PRODUCT
+	// #QUESTION shouln't this be 
+	// if( (BYTE*)( nOp1+pImagGetCode() ) >= pImg->GetCodeSize() )
 	if( nOp1 >= pImg->GetCodeSize() )
 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
 #endif
@@ -171,7 +173,7 @@ void SbiRuntime::StepJUMP( USHORT nOp1 )
 
 // TOS auswerten, bedingter Sprung (+Target)
 
-void SbiRuntime::StepJUMPT( USHORT nOp1 )
+void SbiRuntime::StepJUMPT( UINT32 nOp1 )
 {
 	SbxVariableRef p = PopVar();
 	if( p->GetBool() )
@@ -180,7 +182,7 @@ void SbiRuntime::StepJUMPT( USHORT nOp1 
 
 // TOS auswerten, bedingter Sprung (+Target)
 
-void SbiRuntime::StepJUMPF( USHORT nOp1 )
+void SbiRuntime::StepJUMPF( UINT32 nOp1 )
 {
 	SbxVariableRef p = PopVar();
 	if( !p->GetBool() )
@@ -195,24 +197,26 @@ void SbiRuntime::StepJUMPF( USHORT nOp1 
 // ...
 //Falls im Operanden 0x8000 gesetzt ist, Returnadresse pushen (ON..GOSUB)
 
-void SbiRuntime::StepONJUMP( USHORT nOp1 )
+void SbiRuntime::StepONJUMP( UINT32 nOp1 )
 {
 	SbxVariableRef p = PopVar();
 	INT16 n = p->GetInteger();
 	if( nOp1 & 0x8000 )
 	{
 		nOp1 &= 0x7FFF;
-		PushGosub( pCode + 3 * nOp1 );
+		//PushGosub( pCode + 3 * nOp1 );
+		PushGosub( pCode + 5 * nOp1 );
 	}
-	if( n < 1 || n > (short) nOp1 )
+	if( n < 1 || static_cast<UINT32>(n) >  nOp1 )
 		n = nOp1 + 1;
-	nOp1 = (USHORT) ( (const char*) pCode - pImg->GetCode() ) + 3 * --n;
+	//nOp1 = (UINT32) ( (const char*) pCode - pImg->GetCode() ) + 3 * --n;
+	nOp1 = (UINT32) ( (const char*) pCode - pImg->GetCode() ) + 5 * --n;
 	StepJUMP( nOp1 );
 }
 
 // UP-Aufruf (+Target)
 
-void SbiRuntime::StepGOSUB( USHORT nOp1 )
+void SbiRuntime::StepGOSUB( UINT32 nOp1 )
 {
 	PushGosub( pCode );
 	if( nOp1 >= pImg->GetCodeSize() )
@@ -222,7 +226,7 @@ void SbiRuntime::StepGOSUB( USHORT nOp1 
 
 // UP-Return (+0 oder Target)
 
-void SbiRuntime::StepRETURN( USHORT nOp1 )
+void SbiRuntime::StepRETURN( UINT32 nOp1 )
 {
 	PopGosub();
 	if( nOp1 )
@@ -233,7 +237,7 @@ void SbiRuntime::StepRETURN( USHORT nOp1
 
 void unoToSbxValue( SbxVariable* pVar, const Any& aValue );
 
-void SbiRuntime::StepTESTFOR( USHORT nOp1 )
+void SbiRuntime::StepTESTFOR( UINT32 nOp1 )
 {
 	if( !pForStk )
 	{
@@ -335,7 +339,7 @@ void SbiRuntime::StepTESTFOR( USHORT nOp
 
 // Tos+1 <= Tos+2 <= Tos, 2xremove (+Target)
 
-void SbiRuntime::StepCASETO( USHORT nOp1 )
+void SbiRuntime::StepCASETO( UINT32 nOp1 )
 {
 	if( !refCaseStk || !refCaseStk->Count() )
 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
@@ -351,7 +355,7 @@ void SbiRuntime::StepCASETO( USHORT nOp1
 
 // Fehler-Handler
 
-void SbiRuntime::StepERRHDL( USHORT nOp1 )
+void SbiRuntime::StepERRHDL( UINT32 nOp1 )
 {
 	const BYTE* p = pCode;
 	StepJUMP( nOp1 );
@@ -365,7 +369,7 @@ void SbiRuntime::StepERRHDL( USHORT nOp1
 
 // Resume nach Fehlern (+0=statement, 1=next or Label)
 
-void SbiRuntime::StepRESUME( USHORT nOp1 )
+void SbiRuntime::StepRESUME( UINT32 nOp1 )
 {
 	// AB #32714 Resume ohne Error? -> Fehler
 	if( !bInError )
@@ -397,7 +401,7 @@ void SbiRuntime::StepRESUME( USHORT nOp1
 }
 
 // Kanal schliessen (+Kanal, 0=Alle)
-void SbiRuntime::StepCLOSE( USHORT nOp1 )
+void SbiRuntime::StepCLOSE( UINT32 nOp1 )
 {
 	short err;
 	if( !nOp1 )
@@ -416,7 +420,7 @@ void SbiRuntime::StepCLOSE( USHORT nOp1 
 
 // Zeichen ausgeben (+char)
 
-void SbiRuntime::StepPRCHAR( USHORT nOp1 )
+void SbiRuntime::StepPRCHAR( UINT32 nOp1 )
 {
 	ByteString s( (char) nOp1 );
 	pIosys->Write( s );
@@ -493,7 +497,7 @@ bool SbiRuntime::checkClass_Impl( const 
 	return bOk;
 }
 
-void SbiRuntime::StepSETCLASS( USHORT nOp1 )
+void SbiRuntime::StepSETCLASS( UINT32 nOp1 )
 {
 	SbxVariableRef refVal = PopVar();
 	SbxVariableRef refVar = PopVar();
@@ -504,7 +508,7 @@ void SbiRuntime::StepSETCLASS( USHORT nO
 		StepSET_Impl( refVal, refVar );
 }
 
-void SbiRuntime::StepTESTCLASS( USHORT nOp1 )
+void SbiRuntime::StepTESTCLASS( UINT32 nOp1 )
 {
 	SbxVariableRef xObjVal = PopVar();
 	String aClass( pImg->GetString( nOp1 ) );
@@ -517,7 +521,7 @@ void SbiRuntime::StepTESTCLASS( USHORT n
 
 // Library fuer anschliessenden Declare-Call definieren
 
-void SbiRuntime::StepLIB( USHORT nOp1 )
+void SbiRuntime::StepLIB( UINT32 nOp1 )
 {
 	aLibName = pImg->GetString( nOp1 );
 }
@@ -526,7 +530,7 @@ void SbiRuntime::StepLIB( USHORT nOp1 )
 // Dieser Opcode wird vor DIM/REDIM-Anweisungen gepusht,
 // wenn nur ein Index angegeben wurde.
 
-void SbiRuntime::StepBASED( USHORT nOp1 )
+void SbiRuntime::StepBASED( UINT32 nOp1 )
 {
 	SbxVariable* p1 = new SbxVariable;
 	SbxVariableRef x2 = PopVar();
Index: basic/source/runtime/step2.cxx
===================================================================
RCS file: /cvs/script/basic/source/runtime/step2.cxx,v
retrieving revision 1.22
retrieving revision 1.19.4.3
diff -u -p -u -p -r1.22 -r1.19.4.3
--- basic/source/runtime/step2.cxx	17 Sep 2006 10:07:02 -0000	1.22
+++ basic/source/runtime/step2.cxx	28 Sep 2006 22:32:02 -0000	1.19.4.3
@@ -58,7 +58,7 @@ using namespace com::sun::star::lang;
 // 0x8000 - Argv ist belegt
 
 SbxVariable* SbiRuntime::FindElement
-	( SbxObject* pObj, USHORT nOp1, USHORT nOp2, SbError nNotFound, BOOL bLocal )
+	( SbxObject* pObj, UINT32 nOp1, UINT32 nOp2, SbError nNotFound, BOOL bLocal )
 {
 	SbxVariable* pElem = NULL;
 	if( !pObj )
@@ -298,7 +298,7 @@ SbxBase* SbiRuntime::FindElementExtern( 
 // Dabei auch die Argumente umsetzen, falls benannte Parameter
 // verwendet wurden
 
-void SbiRuntime::SetupArgs( SbxVariable* p, USHORT nOp1 )
+void SbiRuntime::SetupArgs( SbxVariable* p, UINT32 nOp1 )
 {
 	if( nOp1 & 0x8000 )
 	{
@@ -542,14 +542,14 @@ SbxVariable* SbiRuntime::CheckArray( Sbx
 
 // Laden eines Elements aus der Runtime-Library (+StringID+Typ)
 
-void SbiRuntime::StepRTL( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepRTL( UINT32 nOp1, UINT32 nOp2 )
 {
 	PushVar( FindElement( rBasic.pRtl, nOp1, nOp2, SbERR_PROC_UNDEFINED, FALSE ) );
 }
 
 // Laden einer lokalen/globalen Variablen (+StringID+Typ)
 
-void SbiRuntime::StepFIND( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepFIND( UINT32 nOp1, UINT32 nOp2 )
 {
 	if( !refLocals )
 		refLocals = new SbxArray;
@@ -557,7 +557,7 @@ void SbiRuntime::StepFIND( USHORT nOp1, 
 }
 
 // Search inside a class module (CM) to enable global search in time
-void SbiRuntime::StepFIND_CM( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepFIND_CM( UINT32 nOp1, UINT32 nOp2 )
 {
 	if( !refLocals )
 		refLocals = new SbxArray;
@@ -573,7 +573,7 @@ void SbiRuntime::StepFIND_CM( USHORT nOp
 // Laden eines Objekt-Elements (+StringID+Typ)
 // Das Objekt liegt auf TOS
 
-void SbiRuntime::StepELEM( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepELEM( UINT32 nOp1, UINT32 nOp2 )
 {
 	// Liegt auf dem TOS ein Objekt?
 	SbxVariableRef pObjVar = PopVar();
@@ -597,12 +597,12 @@ void SbiRuntime::StepELEM( USHORT nOp1, 
 
 // Laden eines Parameters (+Offset+Typ)
 // Wenn der Datentyp nicht stimmen sollte, eine Kopie anlegen
-// Der Datentyp SbxEMPTY zeigt an, da� kein Parameter angegeben ist.
+// Der Datentyp SbxEMPTY zeigt an, daa kein Parameter angegeben ist.
 // Get( 0 ) darf EMPTY sein
 
-void SbiRuntime::StepPARAM( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepPARAM( UINT32 nOp1, UINT32 nOp2 )
 {
-	USHORT i = nOp1 & 0x7FFF;
+	UINT32 i = nOp1 & 0x7FFF;
 	SbxDataType t = (SbxDataType) nOp2;
 	SbxVariable* p;
 
@@ -660,7 +660,7 @@ void SbiRuntime::StepPARAM( USHORT nOp1,
 
 // Case-Test (+True-Target+Test-Opcode)
 
-void SbiRuntime::StepCASEIS( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepCASEIS( UINT32 nOp1, UINT32 nOp2 )
 {
 	if( !refCaseStk || !refCaseStk->Count() )
 		StarBASIC::FatalError( SbERR_INTERNAL_ERROR );
@@ -676,7 +676,7 @@ void SbiRuntime::StepCASEIS( USHORT nOp1
 // Aufruf einer DLL-Prozedur (+StringID+Typ)
 // Auch hier zeigt das MSB des StringIDs an, dass Argv belegt ist
 
-void SbiRuntime::StepCALL( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepCALL( UINT32 nOp1, UINT32 nOp2 )
 {
 	String aName = pImg->GetString( nOp1 & 0x7FFF );
 	SbxArray* pArgs = NULL;
@@ -691,7 +691,7 @@ void SbiRuntime::StepCALL( USHORT nOp1, 
 // Aufruf einer DLL-Prozedur nach CDecl (+StringID+Typ)
 // Auch hier zeigt das MSB des StringIDs an, dass Argv belegt ist
 
-void SbiRuntime::StepCALLC( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepCALLC( UINT32 nOp1, UINT32 nOp2 )
 {
 	String aName = pImg->GetString( nOp1 & 0x7FFF );
 	SbxArray* pArgs = NULL;
@@ -706,7 +706,7 @@ void SbiRuntime::StepCALLC( USHORT nOp1,
 
 // Beginn eines Statements (+Line+Col)
 
-void SbiRuntime::StepSTMNT( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepSTMNT( UINT32 nOp1, UINT32 nOp2 )
 {
 	// Wenn der Expr-Stack am Anfang einen Statements eine Variable enthaelt,
 	// hat ein Trottel X als Funktion aufgerufen, obwohl es eine Variable ist!
@@ -736,7 +736,7 @@ void SbiRuntime::StepSTMNT( USHORT nOp1,
 		StarBASIC::FatalError( SbERR_NO_METHOD );
 		return;
 	}
-	pStmnt = pCode - 5;
+	pStmnt = pCode - 9;
 	USHORT nOld = nLine;
 	nLine = nOp1;
 
@@ -807,7 +807,7 @@ void SbiRuntime::StepSTMNT( USHORT nOp1,
 //        Kanalnummer
 //        Dateiname
 
-void SbiRuntime::StepOPEN( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepOPEN( UINT32 nOp1, UINT32 nOp2 )
 {
 	SbxVariableRef pName = PopVar();
 	SbxVariableRef pChan = PopVar();
@@ -821,7 +821,7 @@ void SbiRuntime::StepOPEN( USHORT nOp1, 
 
 // Objekt kreieren (+StringID+StringID)
 
-void SbiRuntime::StepCREATE( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepCREATE( UINT32 nOp1, UINT32 nOp2 )
 {
 	String aClass( pImg->GetString( nOp2 ) );
 	SbxObject *pObj = SbxBase::CreateObject( aClass );
@@ -839,12 +839,12 @@ void SbiRuntime::StepCREATE( USHORT nOp1
 	}
 }
 
-void SbiRuntime::StepDCREATE( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepDCREATE( UINT32 nOp1, UINT32 nOp2 )
 {
     StepDCREATE_IMPL( nOp1, nOp2 );
 }
 
-void SbiRuntime::StepDCREATE_REDIMP( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepDCREATE_REDIMP( UINT32 nOp1, UINT32 nOp2 )
 {
     StepDCREATE_IMPL( nOp1, nOp2 );
 }
@@ -871,7 +871,7 @@ void implCopyDimArray_DCREATE( SbxDimArr
 }
 
 // #56204 Objekt-Array kreieren (+StringID+StringID), DCREATE == Dim-Create
-void SbiRuntime::StepDCREATE_IMPL( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepDCREATE_IMPL( UINT32 nOp1, UINT32 nOp2 )
 {
 	SbxVariableRef refVar = PopVar();
 
@@ -986,7 +986,7 @@ void SbiRuntime::StepDCREATE_IMPL( USHOR
 
 SbxObject* createUserTypeImpl( const String& rClassName );	// sb.cxx
 
-void SbiRuntime::StepTCREATE( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepTCREATE( UINT32 nOp1, UINT32 nOp2 )
 {
 	String aName( pImg->GetString( nOp1 ) );
 	String aClass( pImg->GetString( nOp2 ) );
@@ -1002,7 +1002,7 @@ void SbiRuntime::StepTCREATE( USHORT nOp
 
 // Einrichten einer lokalen Variablen (+StringID+Typ)
 
-void SbiRuntime::StepLOCAL( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepLOCAL( UINT32 nOp1, UINT32 nOp2 )
 {
 	if( !refLocals.Is() )
 		refLocals = new SbxArray;
@@ -1018,7 +1018,7 @@ void SbiRuntime::StepLOCAL( USHORT nOp1,
 
 // Einrichten einer modulglobalen Variablen (+StringID+Typ)
 
-void SbiRuntime::StepPUBLIC_Impl( USHORT nOp1, USHORT nOp2, bool bUsedForClassModule )
+void SbiRuntime::StepPUBLIC_Impl( UINT32 nOp1, UINT32 nOp2, bool bUsedForClassModule )
 {
 	String aName( pImg->GetString( nOp1 ) );
 	SbxDataType t = (SbxDataType) nOp2;
@@ -1040,14 +1040,14 @@ void SbiRuntime::StepPUBLIC_Impl( USHORT
 	}
 }
 
-void SbiRuntime::StepPUBLIC( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepPUBLIC( UINT32 nOp1, UINT32 nOp2 )
 {
 	StepPUBLIC_Impl( nOp1, nOp2, false );
 }
 
 // Einrichten einer globalen Variablen (+StringID+Typ)
 
-void SbiRuntime::StepGLOBAL( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepGLOBAL( UINT32 nOp1, UINT32 nOp2 )
 {
 	if( pImg->GetFlag( SBIMG_CLASSMODULE ) )
 		StepPUBLIC_Impl( nOp1, nOp2, true );
@@ -1074,7 +1074,7 @@ void SbiRuntime::StepGLOBAL( USHORT nOp1
 // Creates global variable that isn't reinitialised when
 // basic is restarted, P=PERSIST (+StringID+Typ)
 
-void SbiRuntime::StepGLOBAL_P( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepGLOBAL_P( UINT32 nOp1, UINT32 nOp2 )
 {
     if( pMod->pImage->bFirstInit )
     {
@@ -1086,7 +1086,7 @@ void SbiRuntime::StepGLOBAL_P( USHORT nO
 // Searches for global variable, behavior depends on the fact
 // if the variable is initialised for the first time
 
-void SbiRuntime::StepFIND_G( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepFIND_G( UINT32 nOp1, UINT32 nOp2 )
 {
     if( pMod->pImage->bFirstInit )
     {
@@ -1108,7 +1108,7 @@ void SbiRuntime::StepFIND_G( USHORT nOp1
 
 // Einrichten einer statischen Variablen (+StringID+Typ)
 
-void SbiRuntime::StepSTATIC( USHORT nOp1, USHORT nOp2 )
+void SbiRuntime::StepSTATIC( UINT32 nOp1, UINT32 nOp2 )
 {
     (void)nOp1;
     (void)nOp2;
Index: uui/source/iahndl.cxx
===================================================================
RCS file: /cvs/ucb/uui/source/iahndl.cxx,v
retrieving revision 1.52
retrieving revision 1.52.6.2
diff -u -p -u -p -r1.52 -r1.52.6.2
--- uui/source/iahndl.cxx	29 Aug 2006 11:15:04 -0000	1.52
+++ uui/source/iahndl.cxx	4 Oct 2006 18:23:24 -0000	1.52.6.2
@@ -88,6 +88,7 @@
 #ifndef _COM_SUN_STAR_TASK_DOCUMENTPASSWORDREQUEST_HPP_
 #include "com/sun/star/task/DocumentPasswordRequest.hpp"
 #endif
+#include "com/sun/star/script/ModuleSizeExceededRequest.hpp"
 #ifndef _COM_SUN_STAR_TASK_XINTERACTIONABORT_HPP_
 #include "com/sun/star/task/XInteractionAbort.hpp"
 #endif
@@ -704,7 +705,30 @@ UUIInteractionHandler::handle_impl(
 									   rRequest->getContinuations());
 			return;
 		}
-
+		star::script::ModuleSizeExceededRequest aModSizeException;
+		if (aAnyRequest >>= aModSizeException )
+		{
+			ErrCode nErrorCode = ERRCODE_UUI_IO_MODULESIZEEXCEEDED;
+			std::vector< rtl::OUString > aArguments;
+			star::uno::Sequence< rtl::OUString > sModules = aModSizeException.Names;
+			if ( sModules.getLength() )
+			{
+				rtl::OUString aName;
+				for ( sal_Int32 index=0; index< sModules.getLength(); ++index )
+				{
+					if ( index )
+						aName = aName + rtl::OUString( ',' ) + sModules[index];
+					else
+						aName = sModules[index]; // 1st name
+				}
+				aArguments.push_back( aName );
+			}
+			handleErrorRequest( star::task::InteractionClassification_WARNING,
+                                nErrorCode,
+                                aArguments,
+                                rRequest->getContinuations());
+			return;
+		}
 		star::ucb::NameClashException aNCException;
         if (aAnyRequest >>= aNCException)
 		{
Index: uui/source/ids.hrc
===================================================================
RCS file: /cvs/ucb/uui/source/ids.hrc,v
retrieving revision 1.20
retrieving revision 1.20.72.1
diff -u -p -u -p -r1.20 -r1.20.72.1
--- uui/source/ids.hrc	9 Sep 2005 10:20:32 -0000	1.20
+++ uui/source/ids.hrc	28 Sep 2006 21:38:48 -0000	1.20.72.1
@@ -123,6 +123,7 @@
 #define ERRCODE_UUI_CONFIGURATION_BACKENDMISSING (ERRCODE_AREA_UUI + 55)
 #define ERRCODE_UUI_CONFIGURATION_BACKENDMISSING_WITHRECOVER (ERRCODE_AREA_UUI + 56)
 #define ERRCODE_UUI_INVALID_XFORMS_SUBMISSION_DATA (ERRCODE_AREA_UUI + 57)
+#define ERRCODE_UUI_IO_MODULESIZEEXCEEDED (ERRCODE_AREA_UUI + 58)
 
 #define HID_DLG_LOGIN (HID_UUI_START + 0)
 #define HID_DLG_COOKIES (HID_UUI_START + 1)
Index: uui/source/ids.src
===================================================================
RCS file: /cvs/ucb/uui/source/ids.src,v
retrieving revision 1.62
retrieving revision 1.61.32.3
diff -u -p -u -p -r1.62 -r1.61.32.3
--- uui/source/ids.src	1 Aug 2006 11:16:28 -0000	1.62
+++ uui/source/ids.src	4 Oct 2006 15:58:24 -0000	1.61.32.3
@@ -77,6 +77,13 @@ Resource RID_UUI_ERRHDL
 		Text [ en-US ] = "Target already exists.";
 	};
 
+    String (ERRCODE_UUI_IO_MODULESIZEEXCEEDED & ERRCODE_RES_MASK)
+    {
+        Text [ de ] = "Sie sind im Begriff, eine per Kennwort geschützte Basic Bibliothek zu speichern/zu exportieren. Deren Modul(e)\n$(ARG1)\nsind zu groß, um im Binärformat gespeichert zu werden. Wenn Sie möchten, dass Benutzer, die nicht über das Kennwort verfügen, Makros aus diesem/n Modul(en) ausführen können, müssen Sie sie in eine Reihe kleinerer Module aufteilen. Möchten Sie fortfahren, diese Bibliothek zu speichern/zu exportieren?" ;
+        Text [ en-US ] = "You are about to save/export a password protected basic library containing module(s) \n$(ARG1)\nwhich are too large to store in binary format. If you wish users that don't have access to the library password to be able to run macros in those module(s) you must split those modules into a number of smaller modules. Do you wish to continue to save/export this library?" ;
+       Text [ x-comment ] = " ";
+    };
+
     String (ERRCODE_UUI_IO_BADCRC & ERRCODE_RES_MASK)
     {
         Text [ de ] = "Die Daten von $(ARG1) haben eine inkorrekte Prüfsumme.";
Index: offapi/com/sun/star/script/ModuleSizeExceededRequest.idl
===================================================================
RCS file: offapi/com/sun/star/script/ModuleSizeExceededRequest.idl
diff -N offapi/com/sun/star/script/ModuleSizeExceededRequest.idl
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ offapi/com/sun/star/script/ModuleSizeExceededRequest.idl	4 Oct 2006 18:24:30 -0000	1.1.2.3
@@ -0,0 +1,63 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: cws-npower3-m4.diff,v $
+ *
+ *  $Revision: 1.2 $
+ *
+ *  last change: $Author: noelpwer $ $Date: 2006/10/09 15:38:28 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+#ifndef __com_sun_star_document_ModuleSizeExceededRequest_idl__
+#define __com_sun_star_document_ModuleSizeExceededRequest_idl__
+
+#ifndef __com_sun_star_uno_Exception_idl__
+#include <com/sun/star/uno/Exception.idl>
+#endif
+
+//=============================================================================
+
+module com { module sun { module star { module script {
+
+//=============================================================================
+/** Is used for interaction handle in case password protected modules exceed the size that can be stored in Openoffice 2.x, 1.x formats
+
+*/
+exception ModuleSizeExceededRequest : ::com::sun::star::uno::Exception
+{
+    /** The name of the modules that exceed size that can be stored
+     */
+	sequence< string > Names;
+
+};
+
+//=============================================================================
+
+}; }; }; };
+
+#endif
+
Index: offapi/com/sun/star/script/makefile.mk
===================================================================
RCS file: /cvs/api/offapi/com/sun/star/script/makefile.mk,v
retrieving revision 1.3
retrieving revision 1.3.102.1
diff -u -p -u -p -r1.3 -r1.3.102.1
--- offapi/com/sun/star/script/makefile.mk	5 May 2006 08:52:39 -0000	1.3
+++ offapi/com/sun/star/script/makefile.mk	28 Sep 2006 17:08:00 -0000	1.3.102.1
@@ -50,6 +50,7 @@ IDLFILES=\
 	XLibraryContainer2.idl\
 	XLibraryContainerPassword.idl\
 	XLibraryContainerExport.idl\
+	ModuleSizeExceededRequest.idl\
 
 # ------------------------------------------------------------------
 
Index: sfx2/inc/objsh.hxx
===================================================================
RCS file: /cvs/framework/sfx2/inc/objsh.hxx,v
retrieving revision 1.68
retrieving revision 1.67.16.7
diff -u -p -u -p -r1.68 -r1.67.16.7
--- sfx2/inc/objsh.hxx	28 Aug 2006 15:09:37 -0000	1.68
+++ sfx2/inc/objsh.hxx	9 Oct 2006 10:15:47 -0000	1.67.16.7
@@ -64,6 +64,9 @@
 #ifndef _COM_SUN_STAR_SECURITY_DOCUMENTSIGNATUREINFORMATION_HPP_
 #include <com/sun/star/security/DocumentSignatureInformation.hpp>
 #endif
+#ifndef _COM_SUN_STAR_TASK_XINTERACTIONHANDLER_HPP_
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#endif
 
 //________________________________________________________________________________________________________________
 //	include something else
@@ -335,6 +338,7 @@ public:
     sal_Bool					HasModalViews() const;
     sal_Bool                    IsInPrepareClose() const;
     sal_Bool                    IsHelpDocument() const;
+
 #if _SOLAR__PRIVATE
 	SAL_DLLPRIVATE void SetModalMode_Impl(sal_Bool bModal=sal_True);
     SAL_DLLPRIVATE void SetMacroMode_Impl(sal_Bool bModal=sal_True);
@@ -775,6 +779,7 @@ public:
     SAL_DLLPRIVATE SfxToolBoxConfig* GetToolBoxConfig_Impl();
     SAL_DLLPRIVATE sal_uInt16 ImplGetSignatureState( sal_Bool bScriptingContent = FALSE );
     SAL_DLLPRIVATE void ImplSign( sal_Bool bScriptingContent = FALSE );
+	SAL_DLLPRIVATE sal_Bool QuerySaveSizeExceededModules_Impl( const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler );
 #endif
 };
 
Index: sfx2/inc/sfxbasemodel.hxx
===================================================================
RCS file: /cvs/framework/sfx2/inc/sfxbasemodel.hxx,v
retrieving revision 1.30
retrieving revision 1.30.94.3
diff -u -p -u -p -r1.30 -r1.30.94.3
--- sfx2/inc/sfxbasemodel.hxx	27 Mar 2006 09:30:39 -0000	1.30
+++ sfx2/inc/sfxbasemodel.hxx	5 Oct 2006 10:00:28 -0000	1.30.94.3
@@ -215,6 +215,8 @@
 #include <com/sun/star/document/XViewDataSupplier.hpp>
 #include <com/sun/star/lang/XUnoTunnel.hpp>
 
+#include <com/sun/star/task/XInteractionHandler.hpp>
+
 //________________________________________________________________________________________________________
 //	include of my own project
 //________________________________________________________________________________________________________
@@ -1418,6 +1420,7 @@ private:
 	SAL_DLLPRIVATE void postEvent_Impl( sal_uInt16 nEventID );
 	SAL_DLLPRIVATE String getEventName_Impl( long nID );
 	SAL_DLLPRIVATE void NotifyStorageListeners_Impl();
+   	SAL_DLLPRIVATE bool QuerySaveSizeExceededModules( const com::sun::star::uno::Reference< com::sun::star::task::XInteractionHandler >& xHandler );
 
 //________________________________________________________________________________________________________
 //	private variables and methods
Index: sfx2/source/appl/makefile.mk
===================================================================
RCS file: /cvs/framework/sfx2/source/appl/makefile.mk,v
retrieving revision 1.43
retrieving revision 1.43.68.1
diff -u -p -u -p -r1.43 -r1.43.68.1
--- sfx2/source/appl/makefile.mk	3 May 2006 07:35:51 -0000	1.43
+++ sfx2/source/appl/makefile.mk	5 Oct 2006 08:04:48 -0000	1.43.68.1
@@ -102,6 +102,7 @@ SLOFILES =  \
 	$(SLO)$/workwin.obj \
         $(SLO)$/xpackcreator.obj \
     $(SLO)$/fwkhelper.obj \
+    $(SLO)$/modsizeexceeded.obj \
     $(SLO)$/updatedlg.obj
 
 EXCEPTIONSFILES=\
Index: sfx2/source/appl/modsizeexceeded.cxx
===================================================================
RCS file: sfx2/source/appl/modsizeexceeded.cxx
diff -N sfx2/source/appl/modsizeexceeded.cxx
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sfx2/source/appl/modsizeexceeded.cxx	5 Oct 2006 08:04:48 -0000	1.1.2.1
@@ -0,0 +1,74 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: cws-npower3-m4.diff,v $
+ *
+ *  $Revision: 1.2 $
+ *
+ *  last change: $Author: noelpwer $ $Date: 2006/10/09 15:38:28 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+#include "modsizeexceeded.hxx"
+
+#include <framework/interaction.hxx>
+#include <com/sun/star/script/ModuleSizeExceededRequest.hpp>
+
+using namespace com::sun::star;
+using namespace cppu;
+using namespace rtl;
+using namespace osl;
+
+ModuleSizeExceeded::ModuleSizeExceeded( const uno::Sequence< ::rtl::OUString >& sModules )
+{
+	script::ModuleSizeExceededRequest aReq;
+	aReq.Names = sModules;
+
+	m_aRequest <<= aReq;	
+
+	m_xAbort.set( uno::Reference< task::XInteractionAbort >(new framework::ContinuationAbort), uno::UNO_QUERY );	
+	m_xApprove.set( uno::Reference< task::XInteractionApprove >(new framework::ContinuationApprove ), uno::UNO_QUERY );	
+	m_lContinuations.realloc( 2 );
+	m_lContinuations[0] =  m_xApprove;
+	m_lContinuations[1] = m_xAbort;
+}
+
+sal_Bool 
+ModuleSizeExceeded::isAbort() const 
+{ 
+	framework::ContinuationAbort* pBase = static_cast< framework::ContinuationAbort* >( m_xAbort.get() );
+	return pBase->isSelected();
+}
+
+sal_Bool 
+ModuleSizeExceeded::isApprove() const 
+{
+	framework::ContinuationApprove* pBase = static_cast< framework::ContinuationApprove* >( m_xApprove.get() );
+	return pBase->isSelected();
+}
+
+
Index: sfx2/source/appl/namecont.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/appl/namecont.cxx,v
retrieving revision 1.56
retrieving revision 1.55.16.4
diff -u -p -u -p -r1.56 -r1.55.16.4
--- sfx2/source/appl/namecont.cxx	17 Sep 2006 16:19:39 -0000	1.56
+++ sfx2/source/appl/namecont.cxx	29 Sep 2006 07:49:50 -0000	1.55.16.4
@@ -107,6 +107,8 @@
 #include <comphelper/storagehelper.hxx>
 #include <comphelper/anytostring.hxx>
 #include <cppuhelper/exc_hlp.hxx>
+#include <cppuhelper/exc_hlp.hxx>
+#include <basic/sbmod.hxx>
 
 using namespace com::sun::star::container;
 using namespace com::sun::star::uno;
@@ -1088,7 +1090,9 @@ SfxLibrary_Impl* SfxLibraryContainer_Imp
 sal_Bool SfxLibraryContainer_Impl::implStorePasswordLibrary( 
     SfxLibrary_Impl*,
     const OUString&, 
-    const uno::Reference< embed::XStorage >& )
+    const uno::Reference< embed::XStorage >&,
+    const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& )
+
 {
     return sal_False;
 }
@@ -1098,7 +1102,8 @@ sal_Bool SfxLibraryContainer_Impl::implS
     const ::rtl::OUString& /*aName*/, 
     const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& /*xStorage*/,
     const ::rtl::OUString& /*aTargetURL*/, 
-    const Reference< XSimpleFileAccess > /*xToUseSFI*/ )
+    const Reference< XSimpleFileAccess > /*xToUseSFI*/,
+    const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& /*Handler*/ )
 {
     return sal_False;
 }
@@ -1536,6 +1541,53 @@ void SfxLibraryContainer_Impl::storeLibr
 	storeLibraries_Impl( xStorage, bComplete );
 }
 
+bool SfxLibraryContainer_Impl::LegacyPsswdBinaryLimitExceeded( Sequence< rtl::OUString >& rNames )
+{
+	Sequence< OUString > aNames = maNameContainer.getElementNames();
+	const OUString* pNames = aNames.getConstArray();
+	sal_Int32 i, nNameCount = aNames.getLength();
+	for( i = 0 ; i < nNameCount ; i++ )
+	{
+		SfxLibrary_Impl* pLib = getImplLib( pNames[ i ] );
+		if( !pLib->mbSharedIndexFile  && pLib->mbPasswordProtected 
+		)
+		{
+			StarBASIC* pBasicLib = NULL;
+			if ( mpBasMgr && ( pBasicLib = mpBasMgr->GetLib( pNames[ i ] ) ) )
+			{
+				Sequence< OUString > aElementNames = pLib->getElementNames();
+				sal_Int32 nLen = aElementNames.getLength();
+				const OUString* pStr = aElementNames.getConstArray();
+				Sequence< OUString > aBigModules( nLen );
+				sal_Int32 nBigModules = 0;
+				
+				for( sal_Int32 index = 0 ; index < nLen ; index++ )
+				{
+					OUString aElementName = pStr[ index ];
+					SbModule* pMod = pBasicLib->FindModule( aElementName );
+					if ( pMod )
+					{
+						if ( pMod->ExceedsLegacyModuleSize() )
+						{
+							aBigModules[ nBigModules++ ] = aElementName;
+						}
+					}
+
+				}
+				if ( nBigModules )
+				{
+					aBigModules.realloc( nBigModules );	
+					rNames = aBigModules;
+					return true;
+				}
+			}
+
+		}
+	}
+	return false;
+
+}
+
 // Methods of new XLibraryStorage interface?
 void SfxLibraryContainer_Impl::storeLibraries_Impl( const uno::Reference< embed::XStorage >& xStorage, sal_Bool bComplete )
 {
@@ -1649,7 +1701,7 @@ void SfxLibraryContainer_Impl::storeLibr
 					loadLibrary( rLib.aName );
 
     			if( pImplLib->mbPasswordProtected )
-				    implStorePasswordLibrary( pImplLib, rLib.aName, xLibraryStor );
+				    implStorePasswordLibrary( pImplLib, rLib.aName, xLibraryStor, uno::Reference< task::XInteractionHandler >() );
                     // TODO: Check return value
                 else
 				    implStoreLibrary( pImplLib, rLib.aName, xLibraryStor );
@@ -2287,7 +2339,7 @@ void SAL_CALL SfxLibraryContainer_Impl::
 
 	uno::Reference< ::com::sun::star::embed::XStorage > xDummyStor;
     if( pImplLib->mbPasswordProtected )
-		implStorePasswordLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI );
+		implStorePasswordLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI, Handler );
     else
 		implStoreLibrary( pImplLib, Name, xDummyStor, URL, xToUseSFI );
 
Index: sfx2/source/appl/scriptcont.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/appl/scriptcont.cxx,v
retrieving revision 1.31
retrieving revision 1.30.16.7
diff -u -p -u -p -r1.31 -r1.30.16.7
--- sfx2/source/appl/scriptcont.cxx	17 Sep 2006 16:20:09 -0000	1.31
+++ sfx2/source/appl/scriptcont.cxx	4 Oct 2006 18:22:32 -0000	1.30.16.7
@@ -73,6 +73,7 @@
 #include <com/sun/star/script/XStarBasicAccess.hpp>
 #include <com/sun/star/script/XStarBasicModuleInfo.hpp>
 #include <com/sun/star/script/XStarBasicLibraryInfo.hpp>
+#include <com/sun/star/util/VetoException.hpp>
 
 
 #include "scriptcont.hxx"
@@ -111,7 +112,12 @@
 #include <basic/sbmod.hxx>
 #include <xmlscript/xmlmod_imexp.hxx>
 #include <app.hxx>
-
+#include <app.hrc>
+#include <vcl/msgbox.hxx>
+#include <sfxresid.hxx>
+#include <modsizeexceeded.hxx>
+#include <com/sun/star/task/XInteractionRequest.hpp>
+#include <com/sun/star/task/XInteractionHandler.hpp>
 
 using namespace com::sun::star::container;
 using namespace com::sun::star::io;
@@ -538,17 +544,35 @@ void setStreamKey( uno::Reference< io::X
 
 // Impl methods
 sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary_Impl* pLib,
-    const ::rtl::OUString& aName, const uno::Reference< embed::XStorage >& xStorage )
+    const ::rtl::OUString& aName, const uno::Reference< embed::XStorage >& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler )
 {
 	OUString aDummyLocation;
 	Reference< XSimpleFileAccess > xDummySFA;
-	return implStorePasswordLibrary( pLib, aName, xStorage, aDummyLocation, xDummySFA );
+	return implStorePasswordLibrary( pLib, aName, xStorage, aDummyLocation, xDummySFA, xHandler );
 }
 
 sal_Bool SfxScriptLibraryContainer::implStorePasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& aName, 
         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
-						const ::rtl::OUString& aTargetURL, const Reference< XSimpleFileAccess > xToUseSFI )
+						const ::rtl::OUString& aTargetURL, const Reference< XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& xHandler )
 {
+
+    bool bExport = aTargetURL.getLength();
+    // Only need to handle the export case here, 
+    // save/saveas etc are handled in sfxbasemodel::storeSelf &
+    // sfxbasemodel::impl_store
+    uno::Sequence<rtl::OUString> aNames;
+    if ( bExport && LegacyPsswdBinaryLimitExceeded(aNames) )
+    {
+	if ( xHandler.is() )
+	{
+		ModuleSizeExceeded* pReq =  new ModuleSizeExceeded( aNames );
+		uno::Reference< task::XInteractionRequest > xReq( pReq );
+		xHandler->handle( xReq );	
+        	if ( pReq->isAbort() )
+            		throw util::VetoException();
+	}
+    }
+
     BasicManager* pBasicMgr = getBasicManager();
     StarBASIC* pBasicLib = pBasicMgr->GetLib( aName );
     if( !pBasicLib )
@@ -560,7 +584,6 @@ sal_Bool SfxScriptLibraryContainer::impl
 
 	sal_Bool bLink = pLib->mbLink;
 	sal_Bool bStorage = xStorage.is() && !bLink;
-	bool bExport = aTargetURL.getLength();
 	if( bStorage )
 	{
 		for( sal_Int32 i = 0 ; i < nNameCount ; i++ )
Index: sfx2/source/doc/objserv.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/doc/objserv.cxx,v
retrieving revision 1.94
retrieving revision 1.92.16.8
diff -u -p -u -p -r1.94 -r1.92.16.8
--- sfx2/source/doc/objserv.cxx	17 Sep 2006 16:43:20 -0000	1.94
+++ sfx2/source/doc/objserv.cxx	9 Oct 2006 10:15:47 -0000	1.92.16.8
@@ -181,7 +181,7 @@
 #include "../appl/app.hrc"
 #include <com/sun/star/document/XDocumentSubStorageSupplier.hpp>
 #include <com/sun/star/embed/XTransactedObject.hpp>
-
+#include "scriptcont.hxx"
 
 #ifndef _SFX_HELPID_HRC
 #include "helpid.hrc"
Index: sfx2/source/doc/objstor.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/doc/objstor.cxx,v
retrieving revision 1.182
retrieving revision 1.182.12.2
diff -u -p -u -p -r1.182 -r1.182.12.2
--- sfx2/source/doc/objstor.cxx	17 Sep 2006 16:43:37 -0000	1.182
+++ sfx2/source/doc/objstor.cxx	9 Oct 2006 10:15:47 -0000	1.182.12.2
@@ -229,6 +229,7 @@
 #include "fltoptint.hxx"
 #include "viewfrm.hxx"
 #include "graphhelp.hxx"
+#include "modsizeexceeded.hxx"
 
 #include "../appl/app.hrc"
 
@@ -1253,6 +1254,14 @@ sal_Bool SfxObjectShell::SaveTo_Impl
 	sal_Bool bOwnSource = IsOwnStorageFormat_Impl( *pMedium );
 	sal_Bool bOwnTarget = IsOwnStorageFormat_Impl( rMedium );
 
+	// Examine target format to determine whether to query if any password
+	// protected libraries exceed the size we can handler
+	if ( bOwnTarget && !QuerySaveSizeExceededModules_Impl( rMedium.GetInteractionHandler() ) )
+	{
+		SetError( ERRCODE_IO_ABORT );
+		return sal_False;
+	}
+
 	sal_Bool bNeedsDisconnectionOnFail = sal_False;
 
 	sal_Bool bStoreToSameLocation = sal_False;
@@ -3844,3 +3853,22 @@ void SfxObjectShell::UpdateLinks()
 {
 }
 
+sal_Bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< task::XInteractionHandler >& xHandler )
+{
+	uno::Sequence< rtl::OUString > sModules;
+	if ( xHandler.is() )
+	{
+		SfxScriptLibraryContainer* pBasicCont = pImp->pBasicLibContainer;
+		if( pBasicCont && pBasicCont->LegacyPsswdBinaryLimitExceeded( sModules ) )
+		{
+			ModuleSizeExceeded* pReq =  new ModuleSizeExceeded( sModules );
+			uno::Reference< task::XInteractionRequest > xReq( pReq );
+			xHandler->handle( xReq );
+			return pReq->isApprove();
+		}
+	}
+
+	// No interaction handler, default is to continue to save
+	return sal_True;
+}
+
Index: sfx2/source/doc/sfxbasemodel.cxx
===================================================================
RCS file: /cvs/framework/sfx2/source/doc/sfxbasemodel.cxx,v
retrieving revision 1.116
retrieving revision 1.113.10.7
diff -u -p -u -p -r1.116 -r1.113.10.7
--- sfx2/source/doc/sfxbasemodel.cxx	17 Sep 2006 16:45:28 -0000	1.116
+++ sfx2/source/doc/sfxbasemodel.cxx	9 Oct 2006 09:24:59 -0000	1.113.10.7
@@ -2187,8 +2187,8 @@ void SAL_CALL SfxBaseModel::storeSelf( c
 
 	if ( m_pData->m_pObjectShell.Is() )
     {
-        SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
-
+		SfxSaveGuard aSaveGuard(this, m_pData, sal_False);
+			
 		for ( sal_Int32 nInd = 0; nInd < aSeqArgs.getLength(); nInd++ )
 		{
 			// check that only acceptable parameters are provided here
@@ -3417,6 +3417,7 @@ void SfxBaseModel::impl_store(  const	OU
     	TransformParameters( SID_SAVEASDOC, seqArguments, *aParams );
 
     	SFX_ITEMSET_ARG( aParams, pCopyStreamItem, SfxBoolItem, SID_COPY_STREAM_IF_POSSIBLE, sal_False );
+
 		if ( pCopyStreamItem && pCopyStreamItem->GetValue() && !bSaveTo )
 			throw ILLEGALARGUMENTIOEXCEPTION(
 					::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("CopyStreamIfPossible parameter is not acceptable for storeAsURL() call!") ),
Index: sfx2/source/inc/modsizeexceeded.hxx
===================================================================
RCS file: sfx2/source/inc/modsizeexceeded.hxx
diff -N sfx2/source/inc/modsizeexceeded.hxx
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ sfx2/source/inc/modsizeexceeded.hxx	4 Oct 2006 17:20:38 -0000	1.1.2.1
@@ -0,0 +1,69 @@
+/*************************************************************************
+ *
+ *  OpenOffice.org - a multi-platform office productivity suite
+ *
+ *  $RCSfile: cws-npower3-m4.diff,v $
+ *
+ *  $Revision: 1.2 $
+ *
+ *  last change: $Author: noelpwer $ $Date: 2006/10/09 15:38:28 $
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Sun Microsystems, Inc.
+ *    901 San Antonio Road, Palo Alto, CA 94303, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+#ifndef _SFX_MODSIZEEXCEEDED_HXX
+#define _SFX_MODSIZEEXCEEDED_HXX
+
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <cppuhelper/implbase1.hxx>
+
+class ModuleSizeExceeded : public ::cppu::WeakImplHelper1< ::com::sun::star::task::XInteractionRequest >
+{
+	// c++ interface
+	public:
+	ModuleSizeExceeded( const com::sun::star::uno::Sequence< ::rtl::OUString>& sModules ); 
+
+	sal_Bool isAbort() const;
+	sal_Bool isApprove() const;
+
+	// uno interface
+	public:
+	virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Reference< com::sun::star::task::XInteractionContinuation > > SAL_CALL getContinuations() throw( ::com::sun::star::uno::RuntimeException ) { return m_lContinuations; }
+	com::sun::star::uno::Any SAL_CALL getRequest() throw( com::sun::star::uno::RuntimeException )
+	{
+		return m_aRequest;
+	}
+	// member
+	private:
+	rtl::OUString m_sMods;
+	com::sun::star::uno::Any m_aRequest;
+	com::sun::star::uno::Sequence< com::sun::star::uno::Reference< com::sun::star::task::XInteractionContinuation > > m_lContinuations;
+	com::sun::star::uno::Reference< com::sun::star::task::XInteractionContinuation > m_xAbort;
+	com::sun::star::uno::Reference< com::sun::star::task::XInteractionContinuation> m_xApprove; 
+};
+
+
+#endif
+
Index: sfx2/source/inc/namecont.hxx
===================================================================
RCS file: /cvs/framework/sfx2/source/inc/namecont.hxx,v
retrieving revision 1.27
retrieving revision 1.27.86.3
diff -u -p -u -p -r1.27 -r1.27.86.3
--- sfx2/source/inc/namecont.hxx	7 Apr 2006 08:43:02 -0000	1.27
+++ sfx2/source/inc/namecont.hxx	29 Sep 2006 07:36:45 -0000	1.27.86.3
@@ -304,13 +304,15 @@ protected:
 
     // Password encryption
 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& aName, 
-        				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage );
+        				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
+		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); 
 
 	// New variant for library export
 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& aName, 
         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
 						const ::rtl::OUString& aTargetURL, 
-						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI );
+						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI,
+		const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); 
 
     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& Name,
         sal_Bool bVerifyPasswordOnly=false ) 
@@ -350,6 +352,7 @@ public:
 	SfxLibraryContainer_Impl( void );
 	~SfxLibraryContainer_Impl();
  
+	bool LegacyPsswdBinaryLimitExceeded(::com::sun::star::uno::Sequence< rtl::OUString >&);
  	// Allows to check whether the container is modified
 	sal_Bool isContainerModified();
 
Index: sfx2/source/inc/scriptcont.hxx
===================================================================
RCS file: /cvs/framework/sfx2/source/inc/scriptcont.hxx,v
retrieving revision 1.18
retrieving revision 1.18.16.3
diff -u -p -u -p -r1.18 -r1.18.16.3
--- sfx2/source/inc/scriptcont.hxx	19 Jun 2006 22:33:57 -0000	1.18
+++ sfx2/source/inc/scriptcont.hxx	29 Sep 2006 07:36:46 -0000	1.18.16.3
@@ -79,13 +79,13 @@ class SfxScriptLibraryContainer : public
 
     // Password encryption
 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& aName, 
-        				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>& xStorage );
+        				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage>& xStorage, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); 
 
 	// New variant for library export
 	virtual sal_Bool implStorePasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& aName, 
         				const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage,
 						const ::rtl::OUString& aTargetURL, 
-						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI );
+						const ::com::sun::star::uno::Reference< ::com::sun::star::ucb::XSimpleFileAccess > xToUseSFI, const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler ); 
 
     virtual sal_Bool implLoadPasswordLibrary( SfxLibrary_Impl* pLib, const ::rtl::OUString& Name,
         sal_Bool bVerifyPasswordOnly=false ) 
@@ -113,7 +113,7 @@ public:
 		const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage = 
 										::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >() );
 
-
+	bool LegacyPsswdBinaryLimitExceeded( ::com::sun::star::uno::Sequence< rtl::OUString >& rNames ) { return SfxLibraryContainer_Impl::LegacyPsswdBinaryLimitExceeded( rNames ); }
 	// TODO: Methods of new XLibraryStorage interface?
 	virtual void SAL_CALL storeLibraries( sal_Bool bComplete );
 	virtual void SAL_CALL storeLibrariesToStorage(
Index: basctl/source/basicide/moduldl2.cxx
===================================================================
RCS file: /cvs/script/basctl/source/basicide/moduldl2.cxx,v
retrieving revision 1.56
retrieving revision 1.55.4.4
diff -u -p -u -p -r1.56 -r1.55.4.4
--- basctl/source/basicide/moduldl2.cxx	17 Sep 2006 00:28:55 -0000	1.56
+++ basctl/source/basicide/moduldl2.cxx	4 Oct 2006 16:26:35 -0000	1.55.4.4
@@ -109,6 +109,9 @@
 #include <comphelper/processfactory.hxx>
 #endif
 
+#include <com/sun/star/util/VetoException.hpp> 
+#include <com/sun/star/script/ModuleSizeExceededRequest.hpp> 
+
 using namespace ::comphelper;
 using namespace ::rtl;
 using namespace ::com::sun::star;
@@ -118,10 +121,28 @@ using namespace ::com::sun::star::ucb;
 using namespace ::com::sun::star::ui::dialogs;
 
 
+typedef ::cppu::WeakImplHelper1< task::XInteractionHandler > HandlerImpl_BASE;
+
+class DummyInteractionHandler  : public HandlerImpl_BASE
+{
+    Reference< task::XInteractionHandler > m_xHandler;
+public:
+    DummyInteractionHandler( const Reference< task::XInteractionHandler >& xHandler ) : m_xHandler( xHandler ){} 
+
+    virtual void SAL_CALL handle( const Reference< task::XInteractionRequest >& rRequest ) throw (::com::sun::star::uno::RuntimeException)
+    {
+        if ( m_xHandler.is() )
+        {
+		script::ModuleSizeExceededRequest aModSizeException;
+		if ( rRequest->getRequest() >>= aModSizeException )
+			m_xHandler->handle( rRequest );
+        }
+    } 
+};
+
 //----------------------------------------------------------------------------
 //  BasicLibUserData
 //----------------------------------------------------------------------------
-
 class BasicLibUserData
 {
 private:
@@ -1253,22 +1274,27 @@ void LibPage::Export( void )
 
     if ( xNewDlg->Execute() == RET_OK )
 	{
-		if( xNewDlg->isExportAsPackage() )
-			ExportAsPackage( aLibName );
-		else
-			ExportAsBasic( aLibName );
+		try
+		{
+			if( xNewDlg->isExportAsPackage() )
+				ExportAsPackage( aLibName );
+			else
+				ExportAsBasic( aLibName );
+		}
+		catch( util::VetoException& ve ) // user cancled operation
+		{
+		}
 	}
 }
 
 void LibPage::implExportLib( const String& aLibName, const String& aTargetURL,
-	const Reference< task::XInteractionHandler > Handler )
+	const Reference< task::XInteractionHandler >& Handler )
 {
 	::rtl::OUString aOULibName( aLibName );
 	Reference< script::XLibraryContainerExport > xModLibContainerExport
 		( BasicIDE::GetModuleLibraryContainer( m_pCurShell ), UNO_QUERY );
 	Reference< script::XLibraryContainerExport > xDlgLibContainerExport
 		( BasicIDE::GetDialogLibraryContainer( m_pCurShell ), UNO_QUERY );
-
 	if ( xModLibContainerExport.is() )
 		xModLibContainerExport->exportLibrary( aOULibName, aTargetURL, Handler );
 
@@ -1377,7 +1403,7 @@ void LibPage::ExportAsPackage( const Str
 		OUString aSourcePath = aInetObj.GetMainURL( INetURLObject::NO_DECODE );
         if( xSFA->exists( aSourcePath ) )
 			xSFA->kill( aSourcePath );
-		Reference< task::XInteractionHandler > xDummyHandler;
+		Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
 		implExportLib( aLibName, aTmpPath, xDummyHandler );
 
 		Reference< XCommandEnvironment > xCmdEnv = 
@@ -1485,8 +1511,8 @@ void LibPage::ExportAsBasic( const Strin
 		{
 			String aTargetURL = xFolderPicker->getDirectory();
 	        IDE_DLL()->GetExtraData()->SetAddLibPath( aTargetURL );
-
-			Reference< task::XInteractionHandler > xDummyHandler;
+			
+			Reference< task::XInteractionHandler > xDummyHandler( new DummyInteractionHandler( xHandler ) );
 			implExportLib( aLibName, aTargetURL, xDummyHandler );
 		}
 	}
Index: basctl/source/basicide/moduldlg.hxx
===================================================================
RCS file: /cvs/script/basctl/source/basicide/moduldlg.hxx,v
retrieving revision 1.19
retrieving revision 1.19.40.1
diff -u -p -u -p -r1.19 -r1.19.40.1
--- basctl/source/basicide/moduldlg.hxx	7 Apr 2006 08:44:49 -0000	1.19
+++ basctl/source/basicide/moduldlg.hxx	28 Sep 2006 21:29:15 -0000	1.19.40.1
@@ -279,7 +279,7 @@ protected:
 	void				NewLib();
 	void				InsertLib();
 	void				implExportLib( const String& aLibName, const String& aTargetURL,
-							const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler > Handler );
+							const ::com::sun::star::uno::Reference< ::com::sun::star::task::XInteractionHandler >& Handler );
 	void				Export();
 	void				ExportAsPackage( const String& aLibName );
 	void				ExportAsBasic( const String& aLibName );
