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