1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_basic.hxx" 26 #include <tools/errcode.hxx> 27 #include <vcl/msgbox.hxx> 28 #include <basic/sbx.hxx> 29 #include "collelem.hxx" 30 31 // Das Sample-Element ist ein kleines Objekt, das die Properties 32 // Name und Value enth�lt sowie die Methode Say, die den �bergebenen 33 // Text mit dem eigenen Namen verkoppelt und ausgibt. 34 35 SampleElement::SampleElement( const String& r ) : SbxObject( r ) 36 { 37 // Methode Say mit einem String-Parameter 38 SbxVariable* pMeth = Make( String( RTL_CONSTASCII_USTRINGPARAM("Say") ), SbxCLASS_METHOD, SbxEMPTY ); 39 pMeth->SetUserData( 0x12345678 ); 40 pMeth->ResetFlag( SBX_FIXED ); 41 SbxInfo* pInfo_ = new SbxInfo; 42 pInfo_->AddParam( String( RTL_CONSTASCII_USTRINGPARAM("text") ), SbxSTRING, SBX_READ ); 43 pMeth->SetInfo( pInfo_ ); 44 } 45 46 void SampleElement::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType, 47 const SfxHint& rHint, const TypeId& rHintType ) 48 { 49 const SbxHint* pHint = PTR_CAST(SbxHint,&rHint); 50 if( pHint ) 51 { 52 SbxVariable* pVar = pHint->GetVar(); 53 SbxArray* pPar_ = pVar->GetParameters(); 54 sal_uIntPtr t = pHint->GetId(); 55 if( t == SBX_HINT_DATAWANTED && pVar->GetUserData() == 0x12345678 ) 56 { 57 // Die Say-Methode: 58 // 1 Parameter + Returnwert 59 if( !pPar_ || pPar_->Count() != 2 ) 60 SetError( SbxERR_WRONG_ARGS ); 61 else 62 { 63 String s( GetName() ); 64 s.AppendAscii( " says: " ); 65 s += pPar_->Get( 1 )->GetString(); 66 pPar_->Get( 0 )->SetType(SbxSTRING); 67 pPar_->Get( 0 )->PutString( s ); 68 InfoBox( NULL, s ).Execute(); 69 } 70 return; 71 } 72 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType ); 73 } 74 } 75 76