xref: /aoo42x/main/basic/source/runtime/stdobj1.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 <vcl/wrkwin.hxx>
31 #include <vcl/svapp.hxx>
32 #include <svtools/transfer.hxx>
33 #include "runtime.hxx"
34 #include <basic/sbstdobj.hxx>
35 
36 #define ATTR_IMP_TYPE			1
37 #define ATTR_IMP_WIDTH			2
38 #define ATTR_IMP_HEIGHT			3
39 #define ATTR_IMP_BOLD			4
40 #define ATTR_IMP_ITALIC			5
41 #define ATTR_IMP_STRIKETHROUGH	6
42 #define ATTR_IMP_UNDERLINE		7
43 #define ATTR_IMP_WEIGHT			8
44 #define ATTR_IMP_SIZE			9
45 #define ATTR_IMP_NAME			10
46 
47 #define METH_CLEAR				20
48 #define METH_GETDATA			21
49 #define METH_GETFORMAT			22
50 #define METH_GETTEXT			23
51 #define METH_SETDATA			24
52 #define METH_SETTEXT			25
53 
54 //------------------------------------------------------------------------------
55 SbStdFactory::SbStdFactory()
56 {
57 }
58 
59 SbxObject* SbStdFactory::CreateObject( const String& rClassName )
60 {
61 	if( rClassName.EqualsIgnoreCaseAscii( String( RTL_CONSTASCII_USTRINGPARAM("Picture") ) ) )
62 		return new SbStdPicture;
63 	else
64 		if( rClassName.EqualsIgnoreCaseAscii( String( RTL_CONSTASCII_USTRINGPARAM("Font") ) ) )
65 		return new SbStdFont;
66 	else
67 		return NULL;
68 }
69 
70 //------------------------------------------------------------------------------
71 
72 
73 
74 void SbStdPicture::PropType( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
75 {
76 	if( bWrite )
77 	{
78 		StarBASIC::Error( SbERR_PROP_READONLY );
79 		return;
80 	}
81 
82 	GraphicType eType = aGraphic.GetType();
83 	sal_Int16 nType = 0;
84 
85 	if( eType == GRAPHIC_BITMAP )
86 		nType = 1;
87 	else
88 	if( eType != GRAPHIC_NONE )
89 		nType = 2;
90 
91 	pVar->PutInteger( nType );
92 }
93 
94 
95 void SbStdPicture::PropWidth( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
96 {
97 	if( bWrite )
98 	{
99 		StarBASIC::Error( SbERR_PROP_READONLY );
100 		return;
101 	}
102 
103 	Size aSize = aGraphic.GetPrefSize();
104 	aSize =	GetpApp()->GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
105 	aSize = GetpApp()->GetAppWindow()->PixelToLogic( aSize, MapMode( MAP_TWIP ) );
106 
107 	pVar->PutInteger( (sal_Int16)aSize.Width() );
108 }
109 
110 void SbStdPicture::PropHeight( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
111 {
112 	if( bWrite )
113 	{
114 		StarBASIC::Error( SbERR_PROP_READONLY );
115 		return;
116 	}
117 
118 	Size aSize = aGraphic.GetPrefSize();
119 	aSize =	GetpApp()->GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
120 	aSize = GetpApp()->GetAppWindow()->PixelToLogic( aSize, MapMode( MAP_TWIP ) );
121 
122 	pVar->PutInteger( (sal_Int16)aSize.Height() );
123 }
124 
125 
126 TYPEINIT1( SbStdPicture, SbxObject );
127 
128 SbStdPicture::SbStdPicture() :
129 	SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Picture") ) )
130 {
131 	// Properties
132 	SbxVariable* p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Type") ), SbxCLASS_PROPERTY, SbxVARIANT );
133 	p->SetFlags( SBX_READ | SBX_DONTSTORE );
134 	p->SetUserData( ATTR_IMP_TYPE );
135 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Width") ), SbxCLASS_PROPERTY, SbxVARIANT );
136 	p->SetFlags( SBX_READ | SBX_DONTSTORE );
137 	p->SetUserData( ATTR_IMP_WIDTH );
138 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Height") ), SbxCLASS_PROPERTY, SbxVARIANT );
139 	p->SetFlags( SBX_READ | SBX_DONTSTORE );
140 	p->SetUserData( ATTR_IMP_HEIGHT );
141 }
142 
143 SbStdPicture::~SbStdPicture()
144 {
145 }
146 
147 
148 SbxVariable* SbStdPicture::Find( const String& rName, SbxClassType t )
149 {
150 	// Bereits eingetragen?
151 	return SbxObject::Find( rName, t );
152 }
153 
154 
155 
156 void SbStdPicture::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
157 							   const SfxHint& rHint, const TypeId& rHintType )
158 
159 {
160 	const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
161 
162 	if( pHint )
163 	{
164 		if( pHint->GetId() == SBX_HINT_INFOWANTED )
165 		{
166 			SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
167 			return;
168 		}
169 
170 		SbxVariable* pVar 	= pHint->GetVar();
171 		SbxArray*    pPar_ 	= pVar->GetParameters();
172 		sal_uInt16       nWhich	= (sal_uInt16)pVar->GetUserData();
173 		sal_Bool		 bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
174 
175 		// Propteries
176 		switch( nWhich )
177 		{
178 			case ATTR_IMP_TYPE:		PropType( pVar, pPar_, bWrite ); return;
179 			case ATTR_IMP_WIDTH:	PropWidth( pVar, pPar_, bWrite ); return;
180 			case ATTR_IMP_HEIGHT:	PropHeight( pVar, pPar_, bWrite ); return;
181 		}
182 
183 		SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
184 	}
185 }
186 
187 //-----------------------------------------------------------------------------
188 
189 void SbStdFont::PropBold( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
190 {
191 	if( bWrite )
192 		SetBold( pVar->GetBool() );
193 	else
194 		pVar->PutBool( IsBold() );
195 }
196 
197 void SbStdFont::PropItalic( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
198 {
199 	if( bWrite )
200 		SetItalic( pVar->GetBool() );
201 	else
202 		pVar->PutBool( IsItalic() );
203 }
204 
205 void SbStdFont::PropStrikeThrough( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
206 {
207 	if( bWrite )
208 		SetStrikeThrough( pVar->GetBool() );
209 	else
210 		pVar->PutBool( IsStrikeThrough() );
211 }
212 
213 void SbStdFont::PropUnderline( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
214 {
215 	if( bWrite )
216 		SetUnderline( pVar->GetBool() );
217 	else
218 		pVar->PutBool( IsUnderline() );
219 }
220 
221 void SbStdFont::PropSize( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
222 {
223 	if( bWrite )
224 		SetSize( (sal_uInt16)pVar->GetInteger() );
225 	else
226 		pVar->PutInteger( (sal_Int16)GetSize() );
227 }
228 
229 void SbStdFont::PropName( SbxVariable* pVar, SbxArray*, sal_Bool bWrite )
230 {
231 	if( bWrite )
232 		SetFontName( pVar->GetString() );
233 	else
234 		pVar->PutString( GetFontName() );
235 }
236 
237 
238 TYPEINIT1( SbStdFont, SbxObject );
239 
240 SbStdFont::SbStdFont() :
241 	SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Font") ) )
242 {
243 	// Properties
244 	SbxVariable* p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Bold") ), SbxCLASS_PROPERTY, SbxVARIANT );
245 	p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
246 	p->SetUserData( ATTR_IMP_BOLD );
247 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Italic") ), SbxCLASS_PROPERTY, SbxVARIANT );
248 	p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
249 	p->SetUserData( ATTR_IMP_ITALIC );
250 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("StrikeThrough") ), SbxCLASS_PROPERTY, SbxVARIANT );
251 	p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
252 	p->SetUserData( ATTR_IMP_STRIKETHROUGH );
253 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Underline") ), SbxCLASS_PROPERTY, SbxVARIANT );
254 	p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
255 	p->SetUserData( ATTR_IMP_UNDERLINE );
256 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Size") ), SbxCLASS_PROPERTY, SbxVARIANT );
257 	p->SetFlags( SBX_READWRITE | SBX_DONTSTORE );
258 	p->SetUserData( ATTR_IMP_SIZE );
259 
260 	// Name Property selbst verarbeiten
261 	p = Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_PROPERTY );
262 	DBG_ASSERT( p, "Keine Name Property" );
263 	p->SetUserData( ATTR_IMP_NAME );
264 }
265 
266 SbStdFont::~SbStdFont()
267 {
268 }
269 
270 
271 SbxVariable* SbStdFont::Find( const String& rName, SbxClassType t )
272 {
273 	// Bereits eingetragen?
274 	return SbxObject::Find( rName, t );
275 }
276 
277 
278 
279 void SbStdFont::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
280 							const SfxHint& rHint, const TypeId& rHintType )
281 {
282 	const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
283 
284 	if( pHint )
285 	{
286 		if( pHint->GetId() == SBX_HINT_INFOWANTED )
287 		{
288 			SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
289 			return;
290 		}
291 
292 		SbxVariable* pVar 	= pHint->GetVar();
293 		SbxArray*    pPar_ 	= pVar->GetParameters();
294 		sal_uInt16       nWhich	= (sal_uInt16)pVar->GetUserData();
295 		sal_Bool		 bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
296 
297 		// Propteries
298 		switch( nWhich )
299 		{
300 			case ATTR_IMP_BOLD:			PropBold( pVar, pPar_, bWrite ); return;
301 			case ATTR_IMP_ITALIC:		PropItalic( pVar, pPar_, bWrite ); return;
302 			case ATTR_IMP_STRIKETHROUGH:PropStrikeThrough( pVar, pPar_, bWrite ); return;
303 			case ATTR_IMP_UNDERLINE:	PropUnderline( pVar, pPar_, bWrite ); return;
304 			case ATTR_IMP_SIZE:			PropSize( pVar, pPar_, bWrite ); return;
305 			case ATTR_IMP_NAME:			PropName( pVar, pPar_, bWrite ); return;
306 		}
307 
308 		SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
309 	}
310 }
311 
312 
313 //-----------------------------------------------------------------------------
314 
315 /*
316 class TransferableHelperImpl : public TransferableHelper
317 {
318     SotFormatStringId   mFormat;
319     String              mString;
320     Graphic             mGraphic;
321 
322     virtual void        AddSupportedFormats();
323     virtual sal_Bool    GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor );
324 
325 public:
326     TransferableHelperImpl( void ) { mFormat = 0; }
327     TransferableHelperImpl( const String& rStr )
328         mFormat( FORMAT_STRING ), mString( rStr ) {}
329     TransferableHelperImpl( const Graphic& rGraphic );
330         mFormat( FORMAT_BITMAP ), mGraphic( rGraphic ) {}
331 
332 };
333 
334 void TransferableHelperImpl::AddSupportedFormats()
335 {
336 }
337 
338 sal_Bool TransferableHelperImpl::GetData( const ::com::sun::star::datatransfer::DataFlavor& rFlavor )
339 {
340 	sal_uInt32 nFormat = SotExchange::GetFormat( rFlavor );
341     if( nFormat == FORMAT_STRING )
342     {
343     }
344     else if( nFormat == FORMAT_BITMAP ||
345              nFormat == FORMAT_GDIMETAFILE )
346     {
347     }
348 }
349 */
350 
351 void SbStdClipboard::MethClear( SbxVariable*, SbxArray* pPar_, sal_Bool )
352 {
353 	if( pPar_ && (pPar_->Count() > 1) )
354 	{
355 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
356 		return;
357 	}
358 
359 	//Clipboard::Clear();
360 }
361 
362 void SbStdClipboard::MethGetData( SbxVariable* pVar, SbxArray* pPar_, sal_Bool )
363 {
364     (void)pVar;
365 
366 	if( !pPar_ || (pPar_->Count() != 2) )
367 	{
368 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
369 		return;
370 	}
371 
372 	sal_uInt16 nFormat = pPar_->Get(1)->GetInteger();
373 	if( !nFormat  || nFormat > 3 )
374 	{
375 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
376 		return;
377 	}
378 
379     /*
380 	if( nFormat == FORMAT_STRING )
381 		pVar->PutString( Clipboard::PasteString() );
382 	else
383 	if( (nFormat == FORMAT_BITMAP) ||
384 		(nFormat == FORMAT_GDIMETAFILE ) )
385 	{
386 		SbxObjectRef xPic = new SbStdPicture;
387 		Graphic aGraph;
388 		aGraph.Paste();
389 		((SbStdPicture*)(SbxObject*)xPic)->SetGraphic( aGraph );
390 		pVar->PutObject( xPic );
391 	}
392     */
393 }
394 
395 void SbStdClipboard::MethGetFormat( SbxVariable* pVar, SbxArray* pPar_, sal_Bool )
396 {
397 	if( !pPar_ || (pPar_->Count() != 2) )
398 	{
399 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
400 		return;
401 	}
402 
403 	sal_uInt16 nFormat = pPar_->Get(1)->GetInteger();
404 	if( !nFormat  || nFormat > 3 )
405 	{
406 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
407 		return;
408 	}
409 
410 	pVar->PutBool( sal_False );
411 	//pVar->PutBool( Clipboard::HasFormat( nFormat ) );
412 }
413 
414 void SbStdClipboard::MethGetText( SbxVariable* pVar, SbxArray* pPar_, sal_Bool )
415 {
416 	if( pPar_ && (pPar_->Count() > 1) )
417 	{
418 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
419 		return;
420 	}
421 
422 	pVar->PutString( String() );
423 	//pVar->PutString( Clipboard::PasteString() );
424 }
425 
426 void SbStdClipboard::MethSetData( SbxVariable* pVar, SbxArray* pPar_, sal_Bool )
427 {
428     (void)pVar;
429 
430 	if( !pPar_ || (pPar_->Count() != 3) )
431 	{
432 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
433 		return;
434 	}
435 
436 	sal_uInt16 nFormat = pPar_->Get(2)->GetInteger();
437 	if( !nFormat  || nFormat > 3 )
438 	{
439 		StarBASIC::Error( SbERR_BAD_ARGUMENT );
440 		return;
441 	}
442 
443     /*
444 	if( nFormat == FORMAT_STRING )
445 	{
446 		Clipboard::CopyString( pPar_->Get(1)->GetString() );
447 	}
448 	else
449 	if( (nFormat == FORMAT_BITMAP) ||
450 		(nFormat == FORMAT_GDIMETAFILE) )
451 	{
452 		SbxObject* pObj = (SbxObject*)pPar_->Get(1)->GetObject();
453 
454 		if( pObj && pObj->IsA( TYPE( SbStdPicture ) ) )
455 			((SbStdPicture*)(SbxObject*)pObj)->GetGraphic().Copy();
456 	}
457     */
458 }
459 
460 void SbStdClipboard::MethSetText( SbxVariable* pVar, SbxArray* pPar_, sal_Bool )
461 {
462     (void)pVar;
463 
464 	if( !pPar_ || (pPar_->Count() != 2) )
465 	{
466 		StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS );
467 		return;
468 	}
469 
470 	// Clipboard::CopyString( pPar_->Get(1)->GetString() );
471 }
472 
473 
474 TYPEINIT1( SbStdClipboard, SbxObject );
475 
476 SbStdClipboard::SbStdClipboard() :
477 	SbxObject( String( RTL_CONSTASCII_USTRINGPARAM("Clipboard") ) )
478 {
479 	// Name Property selbst verarbeiten
480 	SbxVariable* p = Find( String( RTL_CONSTASCII_USTRINGPARAM("Name") ), SbxCLASS_PROPERTY );
481 	DBG_ASSERT( p, "Keine Name Property" );
482 	p->SetUserData( ATTR_IMP_NAME );
483 
484 	//Methoden registrieren
485 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("Clear") ), SbxCLASS_METHOD, SbxEMPTY );
486 	p->SetFlag( SBX_DONTSTORE );
487 	p->SetUserData( METH_CLEAR );
488 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetData") ), SbxCLASS_METHOD, SbxEMPTY );
489 	p->SetFlag( SBX_DONTSTORE );
490 	p->SetUserData( METH_GETDATA );
491 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetFormat") ), SbxCLASS_METHOD, SbxEMPTY );
492 	p->SetFlag( SBX_DONTSTORE );
493 	p->SetUserData( METH_GETFORMAT );
494 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("GetText") ), SbxCLASS_METHOD, SbxEMPTY );
495 	p->SetFlag( SBX_DONTSTORE );
496 	p->SetUserData( METH_GETTEXT );
497 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("SetData") ), SbxCLASS_METHOD, SbxEMPTY );
498 	p->SetFlag( SBX_DONTSTORE );
499 	p->SetUserData( METH_SETDATA );
500 	p = Make( String( RTL_CONSTASCII_USTRINGPARAM("SetText") ), SbxCLASS_METHOD, SbxEMPTY );
501 	p->SetFlag( SBX_DONTSTORE );
502 	p->SetUserData( METH_SETTEXT );
503 }
504 
505 SbStdClipboard::~SbStdClipboard()
506 {
507 }
508 
509 
510 SbxVariable* SbStdClipboard::Find( const String& rName, SbxClassType t )
511 {
512 	// Bereits eingetragen?
513 	return SbxObject::Find( rName, t );
514 }
515 
516 
517 
518 void SbStdClipboard::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCType,
519 								 const SfxHint& rHint, const TypeId& rHintType )
520 {
521 	const SbxHint* pHint = PTR_CAST( SbxHint, &rHint );
522 
523 	if( pHint )
524 	{
525 		if( pHint->GetId() == SBX_HINT_INFOWANTED )
526 		{
527 			SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
528 			return;
529 		}
530 
531 		SbxVariable* pVar 	= pHint->GetVar();
532 		SbxArray*    pPar_ 	= pVar->GetParameters();
533 		sal_uInt16       nWhich	= (sal_uInt16)pVar->GetUserData();
534 		sal_Bool		 bWrite = pHint->GetId() == SBX_HINT_DATACHANGED;
535 
536 		// Methods
537 		switch( nWhich )
538 		{
539 			case METH_CLEAR:			MethClear( pVar, pPar_, bWrite ); return;
540 			case METH_GETDATA:			MethGetData( pVar, pPar_, bWrite ); return;
541 			case METH_GETFORMAT:		MethGetFormat( pVar, pPar_, bWrite ); return;
542 			case METH_GETTEXT:			MethGetText( pVar, pPar_, bWrite ); return;
543 			case METH_SETDATA:			MethSetData( pVar, pPar_, bWrite ); return;
544 			case METH_SETTEXT:			MethSetText( pVar, pPar_, bWrite ); return;
545 		}
546 
547 		SbxObject::SFX_NOTIFY( rBC, rBCType, rHint, rHintType );
548 	}
549 }
550 
551 
552