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