xref: /aoo41x/main/basic/source/sample/collelem.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_basic.hxx"
30 #include <tools/errcode.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <basic/sbx.hxx>
33 #include "collelem.hxx"
34 
35 // Das Sample-Element ist ein kleines Objekt, das die Properties
36 // Name und Value enth�lt sowie die Methode Say, die den �bergebenen
37 // Text mit dem eigenen Namen verkoppelt und ausgibt.
38 
39 SampleElement::SampleElement( const String& r ) : SbxObject( r )
40 {
41 	// Methode Say mit einem String-Parameter
42 	SbxVariable* pMeth = Make( String( RTL_CONSTASCII_USTRINGPARAM("Say") ), SbxCLASS_METHOD, SbxEMPTY );
43 	pMeth->SetUserData( 0x12345678 );
44 	pMeth->ResetFlag( SBX_FIXED );
45 	SbxInfo* pInfo_ = new SbxInfo;
46 	pInfo_->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("text") ), SbxSTRING, SBX_READ );
47 	pMeth->SetInfo( pInfo_ );
48 }
49 
50 void SampleElement::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
51 								const SfxHint& rHint, const TypeId& rHintType )
52 {
53 	const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
54 	if( pHint )
55 	{
56 		SbxVariable* pVar = pHint->GetVar();
57 		SbxArray* pPar_ = pVar->GetParameters();
58 		sal_uIntPtr t = pHint->GetId();
59 		if( t == SBX_HINT_DATAWANTED &&	pVar->GetUserData() == 0x12345678 )
60 		{
61 			// Die Say-Methode:
62 			// 1 Parameter + Returnwert
63 			if( !pPar_ || pPar_->Count() != 2 )
64 				SetError( SbxERR_WRONG_ARGS );
65 			else
66 			{
67 				String s( GetName() );
68 				s.AppendAscii( " says: " );
69 				s += pPar_->Get( 1 )->GetString();
70 				pPar_->Get( 0 )->SetType(SbxSTRING);
71 				pPar_->Get( 0 )->PutString( s );
72 				InfoBox( NULL, s ).Execute();
73 			}
74 			return;
75 		}
76 		SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
77 	}
78 }
79 
80