update dev300-m58
[ooovba.git] / basic / source / runtime / stdobj1.cxx
blob20698ad332109300b2d87c9e86fa5e25a988310a
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: stdobj1.cxx,v $
10 * $Revision: 1.10 $
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 <vcl/wrkwin.hxx>
34 #include <vcl/svapp.hxx>
35 #include <svtools/transfer.hxx>
36 #include "runtime.hxx"
37 #include <basic/sbstdobj.hxx>
39 #define ATTR_IMP_TYPE 1
40 #define ATTR_IMP_WIDTH 2
41 #define ATTR_IMP_HEIGHT 3
42 #define ATTR_IMP_BOLD 4
43 #define ATTR_IMP_ITALIC 5
44 #define ATTR_IMP_STRIKETHROUGH 6
45 #define ATTR_IMP_UNDERLINE 7
46 #define ATTR_IMP_WEIGHT 8
47 #define ATTR_IMP_SIZE 9
48 #define ATTR_IMP_NAME 10
50 #define METH_CLEAR 20
51 #define METH_GETDATA 21
52 #define METH_GETFORMAT 22
53 #define METH_GETTEXT 23
54 #define METH_SETDATA 24
55 #define METH_SETTEXT 25
57 //------------------------------------------------------------------------------
58 SbStdFactory::SbStdFactory()
62 SbxObject* SbStdFactory::CreateObject( const String& rClassName )
64 if( rClassName.EqualsIgnoreCaseAscii( String( RTL_CONSTASCII_USTRINGPARAM("Picture") ) ) )
65 return new SbStdPicture;
66 else
67 if( rClassName.EqualsIgnoreCaseAscii( String( RTL_CONSTASCII_USTRINGPARAM("Font") ) ) )
68 return new SbStdFont;
69 else
70 return NULL;
73 //------------------------------------------------------------------------------
77 void SbStdPicture::PropType( SbxVariable* pVar, SbxArray*, BOOL bWrite )
79 if( bWrite )
81 StarBASIC::Error( SbERR_PROP_READONLY );
82 return;
85 GraphicType eType = aGraphic.GetType();
86 INT16 nType = 0;
88 if( eType == GRAPHIC_BITMAP )
89 nType = 1;
90 else
91 if( eType != GRAPHIC_NONE )
92 nType = 2;
94 pVar->PutInteger( nType );
98 void SbStdPicture::PropWidth( SbxVariable* pVar, SbxArray*, BOOL bWrite )
100 if( bWrite )
102 StarBASIC::Error( SbERR_PROP_READONLY );
103 return;
106 Size aSize = aGraphic.GetPrefSize();
107 aSize = GetpApp()->GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
108 aSize = GetpApp()->GetAppWindow()->PixelToLogic( aSize, MapMode( MAP_TWIP ) );
110 pVar->PutInteger( (INT16)aSize.Width() );
113 void SbStdPicture::PropHeight( SbxVariable* pVar, SbxArray*, BOOL bWrite )
115 if( bWrite )
117 StarBASIC::Error( SbERR_PROP_READONLY );
118 return;
121 Size aSize = aGraphic.GetPrefSize();
122 aSize = GetpApp()->GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
123 aSize = GetpApp()->GetAppWindow()->PixelToLogic( aSize, MapMode( MAP_TWIP ) );
125 pVar->PutInteger( (INT16)aSize.Height() );
129 TYPEINIT1( SbStdPicture, SbxObject );
131 SbStdPicture::SbStdPicture() :
132 SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Picture") ) )
134 // Properties
135 SbxVariable* p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Type") ), SbxCLASS_PROPERTY, SbxVARIANT );
136 p->SetFlags( SBX_READ | SBX_DONTSTORE );
137 p->SetUserData( ATTR_IMP_TYPE );
138 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Width") ), SbxCLASS_PROPERTY, SbxVARIANT );
139 p->SetFlags( SBX_READ | SBX_DONTSTORE );
140 p->SetUserData( ATTR_IMP_WIDTH );
141 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Height") ), SbxCLASS_PROPERTY, SbxVARIANT );
142 p->SetFlags( SBX_READ | SBX_DONTSTORE );
143 p->SetUserData( ATTR_IMP_HEIGHT );
146 SbStdPicture::~SbStdPicture()
151 SbxVariable* SbStdPicture::Find( const String& rName, SbxClassType t )
153 // Bereits eingetragen?
154 return SbxObject::Find( rName, t );
159 void SbStdPicture::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
160 const SfxHint& rHint, const TypeId& rHintType )
163 const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
165 if( pHint )
167 if( pHint->GetId() == SBX_HINT_INFOWANTED )
169 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
170 return;
173 SbxVariable* pVar = pHint->GetVar();
174 SbxArray* pPar_ = pVar->GetParameters();
175 USHORT nWhich = (USHORT)pVar->GetUserData();
176 BOOL bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
178 // Propteries
179 switch( nWhich )
181 case ATTR_IMP_TYPE: PropType( pVar, pPar_, bWrite ); return;
182 case ATTR_IMP_WIDTH: PropWidth( pVar, pPar_, bWrite ); return;
183 case ATTR_IMP_HEIGHT: PropHeight( pVar, pPar_, bWrite ); return;
186 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
190 //-----------------------------------------------------------------------------
192 void SbStdFont::PropBold( SbxVariable* pVar, SbxArray*, BOOL bWrite )
194 if( bWrite )
195 SetBold( pVar->GetBool() );
196 else
197 pVar->PutBool( IsBold() );
200 void SbStdFont::PropItalic( SbxVariable* pVar, SbxArray*, BOOL bWrite )
202 if( bWrite )
203 SetItalic( pVar->GetBool() );
204 else
205 pVar->PutBool( IsItalic() );
208 void SbStdFont::PropStrikeThrough( SbxVariable* pVar, SbxArray*, BOOL bWrite )
210 if( bWrite )
211 SetStrikeThrough( pVar->GetBool() );
212 else
213 pVar->PutBool( IsStrikeThrough() );
216 void SbStdFont::PropUnderline( SbxVariable* pVar, SbxArray*, BOOL bWrite )
218 if( bWrite )
219 SetUnderline( pVar->GetBool() );
220 else
221 pVar->PutBool( IsUnderline() );
224 void SbStdFont::PropSize( SbxVariable* pVar, SbxArray*, BOOL bWrite )
226 if( bWrite )
227 SetSize( (USHORT)pVar->GetInteger() );
228 else
229 pVar->PutInteger( (INT16)GetSize() );
232 void SbStdFont::PropName( SbxVariable* pVar, SbxArray*, BOOL bWrite )
234 if( bWrite )
235 SetFontName( pVar->GetString() );
236 else
237 pVar->PutString( GetFontName() );
241 TYPEINIT1( SbStdFont, SbxObject );
243 SbStdFont::SbStdFont() :
244 SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Font") ) )
246 // Properties
247 SbxVariable* p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Bold") ), SbxCLASS_PROPERTY, SbxVARIANT );
248 p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
249 p->SetUserData( ATTR_IMP_BOLD );
250 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Italic") ), SbxCLASS_PROPERTY, SbxVARIANT );
251 p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
252 p->SetUserData( ATTR_IMP_ITALIC );
253 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("StrikeThrough") ), SbxCLASS_PROPERTY, SbxVARIANT );
254 p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
255 p->SetUserData( ATTR_IMP_STRIKETHROUGH );
256 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Underline") ), SbxCLASS_PROPERTY, SbxVARIANT );
257 p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
258 p->SetUserData( ATTR_IMP_UNDERLINE );
259 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Size") ), SbxCLASS_PROPERTY, SbxVARIANT );
260 p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
261 p->SetUserData( ATTR_IMP_SIZE );
263 // Name Property selbst verarbeiten
264 p = Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_PROPERTY );
265 DBG_ASSERT( p, "Keine Name Property" );
266 p->SetUserData( ATTR_IMP_NAME );
269 SbStdFont::~SbStdFont()
274 SbxVariable* SbStdFont::Find( const String& rName, SbxClassType t )
276 // Bereits eingetragen?
277 return SbxObject::Find( rName, t );
282 void SbStdFont::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
283 const SfxHint& rHint, const TypeId& rHintType )
285 const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
287 if( pHint )
289 if( pHint->GetId() == SBX_HINT_INFOWANTED )
291 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
292 return;
295 SbxVariable* pVar = pHint->GetVar();
296 SbxArray* pPar_ = pVar->GetParameters();
297 USHORT nWhich = (USHORT)pVar->GetUserData();
298 BOOL bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
300 // Propteries
301 switch( nWhich )
303 case ATTR_IMP_BOLD: PropBold( pVar, pPar_, bWrite ); return;
304 case ATTR_IMP_ITALIC: PropItalic( pVar, pPar_, bWrite ); return;
305 case ATTR_IMP_STRIKETHROUGH:PropStrikeThrough( pVar, pPar_, bWrite ); return;
306 case ATTR_IMP_UNDERLINE: PropUnderline( pVar, pPar_, bWrite ); return;
307 case ATTR_IMP_SIZE: PropSize( pVar, pPar_, bWrite ); return;
308 case ATTR_IMP_NAME: PropName( pVar, pPar_, bWrite ); return;
311 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
316 //-----------------------------------------------------------------------------
319 class TransferableHelperImpl : public TransferableHelper
321 SotFormatStringId mFormat;
322 String mString;
323 Graphic mGraphic;
325 virtual void AddSupportedFormats();
326 virtual sal_Bool GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
328 public:
329 TransferableHelperImpl( void ) { mFormat = 0; }
330 TransferableHelperImpl( const String& rStr )
331 mFormat( FORMAT_STRING ), mString( rStr ) {}
332 TransferableHelperImpl( const Graphic& rGraphic );
333 mFormat( FORMAT_BITMAP ), mGraphic( rGraphic ) {}
337 void TransferableHelperImpl::AddSupportedFormats()
341 sal_Bool TransferableHelperImpl::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
343 sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
344 if( nFormat == FORMAT_STRING )
347 else if( nFormat == FORMAT_BITMAP ||
348 nFormat == FORMAT_GDIMETAFILE )
354 void SbStdClipboard::MethClear( SbxVariable*, SbxArray* pPar_, BOOL )
356 if( pPar_ && (pPar_->Count() > 1) )
358 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
359 return;
362 //Clipboard::Clear();
365 void SbStdClipboard::MethGetData( SbxVariable* pVar, SbxArray* pPar_, BOOL )
367 (void)pVar;
369 if( !pPar_ || (pPar_->Count() != 2) )
371 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
372 return;
375 USHORT nFormat = pPar_->Get(1)->GetInteger();
376 if( !nFormat || nFormat > 3 )
378 StarBASIC::Error( SbERR_BAD_ARGUMENT );
379 return;
383 if( nFormat == FORMAT_STRING )
384 pVar->PutString( Clipboard::PasteString() );
385 else
386 if( (nFormat == FORMAT_BITMAP) ||
387 (nFormat == FORMAT_GDIMETAFILE ) )
389 SbxObjectRef xPic = new SbStdPicture;
390 Graphic aGraph;
391 aGraph.Paste();
392 ((SbStdPicture*)(SbxObject*)xPic)->SetGraphic( aGraph );
393 pVar->PutObject( xPic );
398 void SbStdClipboard::MethGetFormat( SbxVariable* pVar, SbxArray* pPar_, BOOL )
400 if( !pPar_ || (pPar_->Count() != 2) )
402 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
403 return;
406 USHORT nFormat = pPar_->Get(1)->GetInteger();
407 if( !nFormat || nFormat > 3 )
409 StarBASIC::Error( SbERR_BAD_ARGUMENT );
410 return;
413 pVar->PutBool( FALSE );
414 //pVar->PutBool( Clipboard::HasFormat( nFormat ) );
417 void SbStdClipboard::MethGetText( SbxVariable* pVar, SbxArray* pPar_, BOOL )
419 if( pPar_ && (pPar_->Count() > 1) )
421 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
422 return;
425 pVar->PutString( String() );
426 //pVar->PutString( Clipboard::PasteString() );
429 void SbStdClipboard::MethSetData( SbxVariable* pVar, SbxArray* pPar_, BOOL )
431 (void)pVar;
433 if( !pPar_ || (pPar_->Count() != 3) )
435 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
436 return;
439 USHORT nFormat = pPar_->Get(2)->GetInteger();
440 if( !nFormat || nFormat > 3 )
442 StarBASIC::Error( SbERR_BAD_ARGUMENT );
443 return;
447 if( nFormat == FORMAT_STRING )
449 Clipboard::CopyString( pPar_->Get(1)->GetString() );
451 else
452 if( (nFormat == FORMAT_BITMAP) ||
453 (nFormat == FORMAT_GDIMETAFILE) )
455 SbxObject* pObj = (SbxObject*)pPar_->Get(1)->GetObject();
457 if( pObj && pObj->IsA( TYPE( SbStdPicture ) ) )
458 ((SbStdPicture*)(SbxObject*)pObj)->GetGraphic().Copy();
463 void SbStdClipboard::MethSetText( SbxVariable* pVar, SbxArray* pPar_, BOOL )
465 (void)pVar;
467 if( !pPar_ || (pPar_->Count() != 2) )
469 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
470 return;
473 // Clipboard::CopyString( pPar_->Get(1)->GetString() );
477 TYPEINIT1( SbStdClipboard, SbxObject );
479 SbStdClipboard::SbStdClipboard() :
480 SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Clipboard") ) )
482 // Name Property selbst verarbeiten
483 SbxVariable* p = Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_PROPERTY );
484 DBG_ASSERT( p, "Keine Name Property" );
485 p->SetUserData( ATTR_IMP_NAME );
487 //Methoden registrieren
488 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Clear") ), SbxCLASS_METHOD, SbxEMPTY );
489 p->SetFlag( SBX_DONTSTORE );
490 p->SetUserData( METH_CLEAR );
491 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetData") ), SbxCLASS_METHOD, SbxEMPTY );
492 p->SetFlag( SBX_DONTSTORE );
493 p->SetUserData( METH_GETDATA );
494 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetFormat") ), SbxCLASS_METHOD, SbxEMPTY );
495 p->SetFlag( SBX_DONTSTORE );
496 p->SetUserData( METH_GETFORMAT );
497 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetText") ), SbxCLASS_METHOD, SbxEMPTY );
498 p->SetFlag( SBX_DONTSTORE );
499 p->SetUserData( METH_GETTEXT );
500 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("SetData") ), SbxCLASS_METHOD, SbxEMPTY );
501 p->SetFlag( SBX_DONTSTORE );
502 p->SetUserData( METH_SETDATA );
503 p = Make( String( RTL_CONSTASCII_USTRINGPARAM("SetText") ), SbxCLASS_METHOD, SbxEMPTY );
504 p->SetFlag( SBX_DONTSTORE );
505 p->SetUserData( METH_SETTEXT );
508 SbStdClipboard::~SbStdClipboard()
513 SbxVariable* SbStdClipboard::Find( const String& rName, SbxClassType t )
515 // Bereits eingetragen?
516 return SbxObject::Find( rName, t );
521 void SbStdClipboard::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
522 const SfxHint& rHint, const TypeId& rHintType )
524 const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
526 if( pHint )
528 if( pHint->GetId() == SBX_HINT_INFOWANTED )
530 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
531 return;
534 SbxVariable* pVar = pHint->GetVar();
535 SbxArray* pPar_ = pVar->GetParameters();
536 USHORT nWhich = (USHORT)pVar->GetUserData();
537 BOOL bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
539 // Methods
540 switch( nWhich )
542 case METH_CLEAR: MethClear( pVar, pPar_, bWrite ); return;
543 case METH_GETDATA: MethGetData( pVar, pPar_, bWrite ); return;
544 case METH_GETFORMAT: MethGetFormat( pVar, pPar_, bWrite ); return;
545 case METH_GETTEXT: MethGetText( pVar, pPar_, bWrite ); return;
546 case METH_SETDATA: MethSetData( pVar, pPar_, bWrite ); return;
547 case METH_SETTEXT: MethSetText( pVar, pPar_, bWrite ); return;
550 SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );