1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <vcl/wrkwin.hxx>
21 #include <vcl/svapp.hxx>
22 #include <svtools/transfer.hxx>
23 #include "runtime.hxx"
24 #include <basic/sbstdobj.hxx>
26 #define ATTR_IMP_TYPE 1
27 #define ATTR_IMP_WIDTH 2
28 #define ATTR_IMP_HEIGHT 3
29 #define ATTR_IMP_BOLD 4
30 #define ATTR_IMP_ITALIC 5
31 #define ATTR_IMP_STRIKETHROUGH 6
32 #define ATTR_IMP_UNDERLINE 7
33 #define ATTR_IMP_SIZE 9
34 #define ATTR_IMP_NAME 10
37 #define METH_GETDATA 21
38 #define METH_GETFORMAT 22
39 #define METH_GETTEXT 23
40 #define METH_SETDATA 24
41 #define METH_SETTEXT 25
43 //------------------------------------------------------------------------------
44 SbStdFactory::SbStdFactory()
48 SbxObject
* SbStdFactory::CreateObject( const OUString
& rClassName
)
50 if( rClassName
.equalsIgnoreAsciiCase("Picture") )
51 return new SbStdPicture
;
52 else if( rClassName
.equalsIgnoreAsciiCase("Font") )
58 //------------------------------------------------------------------------------
62 void SbStdPicture::PropType( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
66 StarBASIC::Error( SbERR_PROP_READONLY
);
70 GraphicType eType
= aGraphic
.GetType();
73 if( eType
== GRAPHIC_BITMAP
)
75 else if( eType
!= GRAPHIC_NONE
)
78 pVar
->PutInteger( nType
);
82 void SbStdPicture::PropWidth( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
86 StarBASIC::Error( SbERR_PROP_READONLY
);
90 Size aSize
= aGraphic
.GetPrefSize();
91 aSize
= GetpApp()->GetAppWindow()->LogicToPixel( aSize
, aGraphic
.GetPrefMapMode() );
92 aSize
= GetpApp()->GetAppWindow()->PixelToLogic( aSize
, MapMode( MAP_TWIP
) );
94 pVar
->PutInteger( (sal_Int16
)aSize
.Width() );
97 void SbStdPicture::PropHeight( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
101 StarBASIC::Error( SbERR_PROP_READONLY
);
105 Size aSize
= aGraphic
.GetPrefSize();
106 aSize
= GetpApp()->GetAppWindow()->LogicToPixel( aSize
, aGraphic
.GetPrefMapMode() );
107 aSize
= GetpApp()->GetAppWindow()->PixelToLogic( aSize
, MapMode( MAP_TWIP
) );
109 pVar
->PutInteger( (sal_Int16
)aSize
.Height() );
113 TYPEINIT1( SbStdPicture
, SbxObject
);
115 SbStdPicture::SbStdPicture() :
116 SbxObject( OUString("Picture"))
119 SbxVariable
* p
= Make( OUString("Type"), SbxCLASS_PROPERTY
, SbxVARIANT
);
120 p
->SetFlags( SBX_READ
| SBX_DONTSTORE
);
121 p
->SetUserData( ATTR_IMP_TYPE
);
122 p
= Make( OUString("Width"), SbxCLASS_PROPERTY
, SbxVARIANT
);
123 p
->SetFlags( SBX_READ
| SBX_DONTSTORE
);
124 p
->SetUserData( ATTR_IMP_WIDTH
);
125 p
= Make( OUString("Height"), SbxCLASS_PROPERTY
, SbxVARIANT
);
126 p
->SetFlags( SBX_READ
| SBX_DONTSTORE
);
127 p
->SetUserData( ATTR_IMP_HEIGHT
);
130 SbStdPicture::~SbStdPicture()
135 SbxVariable
* SbStdPicture::Find( const OUString
& rName
, SbxClassType t
)
138 return SbxObject::Find( rName
, t
);
143 void SbStdPicture::SFX_NOTIFY( SfxBroadcaster
& rBC
, const TypeId
& rBCType
,
144 const SfxHint
& rHint
, const TypeId
& rHintType
)
147 const SbxHint
* pHint
= PTR_CAST( SbxHint
, &rHint
);
151 if( pHint
->GetId() == SBX_HINT_INFOWANTED
)
153 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
157 SbxVariable
* pVar
= pHint
->GetVar();
158 SbxArray
* pPar_
= pVar
->GetParameters();
159 sal_uInt16 nWhich
= (sal_uInt16
)pVar
->GetUserData();
160 sal_Bool bWrite
= pHint
->GetId() == SBX_HINT_DATACHANGED
;
165 case ATTR_IMP_TYPE
: PropType( pVar
, pPar_
, bWrite
); return;
166 case ATTR_IMP_WIDTH
: PropWidth( pVar
, pPar_
, bWrite
); return;
167 case ATTR_IMP_HEIGHT
: PropHeight( pVar
, pPar_
, bWrite
); return;
170 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
174 //-----------------------------------------------------------------------------
176 void SbStdFont::PropBold( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
179 SetBold( pVar
->GetBool() );
181 pVar
->PutBool( IsBold() );
184 void SbStdFont::PropItalic( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
187 SetItalic( pVar
->GetBool() );
189 pVar
->PutBool( IsItalic() );
192 void SbStdFont::PropStrikeThrough( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
195 SetStrikeThrough( pVar
->GetBool() );
197 pVar
->PutBool( IsStrikeThrough() );
200 void SbStdFont::PropUnderline( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
203 SetUnderline( pVar
->GetBool() );
205 pVar
->PutBool( IsUnderline() );
208 void SbStdFont::PropSize( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
211 SetSize( (sal_uInt16
)pVar
->GetInteger() );
213 pVar
->PutInteger( (sal_Int16
)GetSize() );
216 void SbStdFont::PropName( SbxVariable
* pVar
, SbxArray
*, sal_Bool bWrite
)
220 SetFontName( pVar
->GetOUString() );
224 pVar
->PutString( GetFontName() );
229 TYPEINIT1( SbStdFont
, SbxObject
);
231 SbStdFont::SbStdFont() :
232 SbxObject( OUString("Font") )
235 SbxVariable
* p
= Make( OUString("Bold"), SbxCLASS_PROPERTY
, SbxVARIANT
);
236 p
->SetFlags( SBX_READWRITE
| SBX_DONTSTORE
);
237 p
->SetUserData( ATTR_IMP_BOLD
);
238 p
= Make( OUString("Italic"), SbxCLASS_PROPERTY
, SbxVARIANT
);
239 p
->SetFlags( SBX_READWRITE
| SBX_DONTSTORE
);
240 p
->SetUserData( ATTR_IMP_ITALIC
);
241 p
= Make( OUString("StrikeThrough"), SbxCLASS_PROPERTY
, SbxVARIANT
);
242 p
->SetFlags( SBX_READWRITE
| SBX_DONTSTORE
);
243 p
->SetUserData( ATTR_IMP_STRIKETHROUGH
);
244 p
= Make( OUString("Underline"), SbxCLASS_PROPERTY
, SbxVARIANT
);
245 p
->SetFlags( SBX_READWRITE
| SBX_DONTSTORE
);
246 p
->SetUserData( ATTR_IMP_UNDERLINE
);
247 p
= Make( OUString("Size"), SbxCLASS_PROPERTY
, SbxVARIANT
);
248 p
->SetFlags( SBX_READWRITE
| SBX_DONTSTORE
);
249 p
->SetUserData( ATTR_IMP_SIZE
);
251 // handle name property yourself
252 p
= Find( OUString("Name"), SbxCLASS_PROPERTY
);
253 DBG_ASSERT( p
, "No Name Property" );
254 p
->SetUserData( ATTR_IMP_NAME
);
257 SbStdFont::~SbStdFont()
262 SbxVariable
* SbStdFont::Find( const OUString
& rName
, SbxClassType t
)
264 return SbxObject::Find( rName
, t
);
269 void SbStdFont::SFX_NOTIFY( SfxBroadcaster
& rBC
, const TypeId
& rBCType
,
270 const SfxHint
& rHint
, const TypeId
& rHintType
)
272 const SbxHint
* pHint
= PTR_CAST( SbxHint
, &rHint
);
276 if( pHint
->GetId() == SBX_HINT_INFOWANTED
)
278 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
282 SbxVariable
* pVar
= pHint
->GetVar();
283 SbxArray
* pPar_
= pVar
->GetParameters();
284 sal_uInt16 nWhich
= (sal_uInt16
)pVar
->GetUserData();
285 sal_Bool bWrite
= pHint
->GetId() == SBX_HINT_DATACHANGED
;
290 case ATTR_IMP_BOLD
: PropBold( pVar
, pPar_
, bWrite
); return;
291 case ATTR_IMP_ITALIC
: PropItalic( pVar
, pPar_
, bWrite
); return;
292 case ATTR_IMP_STRIKETHROUGH
:PropStrikeThrough( pVar
, pPar_
, bWrite
); return;
293 case ATTR_IMP_UNDERLINE
: PropUnderline( pVar
, pPar_
, bWrite
); return;
294 case ATTR_IMP_SIZE
: PropSize( pVar
, pPar_
, bWrite
); return;
295 case ATTR_IMP_NAME
: PropName( pVar
, pPar_
, bWrite
); return;
298 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
303 //-----------------------------------------------------------------------------
306 void SbStdClipboard::MethClear( SbxVariable
*, SbxArray
* pPar_
, sal_Bool
)
308 if( pPar_
&& (pPar_
->Count() > 1) )
310 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
316 void SbStdClipboard::MethGetData( SbxVariable
* pVar
, SbxArray
* pPar_
, sal_Bool
)
320 if( !pPar_
|| (pPar_
->Count() != 2) )
322 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
326 sal_uInt16 nFormat
= pPar_
->Get(1)->GetInteger();
327 if( !nFormat
|| nFormat
> 3 )
329 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
335 void SbStdClipboard::MethGetFormat( SbxVariable
* pVar
, SbxArray
* pPar_
, sal_Bool
)
337 if( !pPar_
|| (pPar_
->Count() != 2) )
339 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
343 sal_uInt16 nFormat
= pPar_
->Get(1)->GetInteger();
344 if( !nFormat
|| nFormat
> 3 )
346 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
350 pVar
->PutBool( sal_False
);
353 void SbStdClipboard::MethGetText( SbxVariable
* pVar
, SbxArray
* pPar_
, sal_Bool
)
355 if( pPar_
&& (pPar_
->Count() > 1) )
357 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
361 pVar
->PutString( OUString() );
364 void SbStdClipboard::MethSetData( SbxVariable
* pVar
, SbxArray
* pPar_
, sal_Bool
)
368 if( !pPar_
|| (pPar_
->Count() != 3) )
370 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
374 sal_uInt16 nFormat
= pPar_
->Get(2)->GetInteger();
375 if( !nFormat
|| nFormat
> 3 )
377 StarBASIC::Error( SbERR_BAD_ARGUMENT
);
383 void SbStdClipboard::MethSetText( SbxVariable
* pVar
, SbxArray
* pPar_
, sal_Bool
)
387 if( !pPar_
|| (pPar_
->Count() != 2) )
389 StarBASIC::Error( SbERR_BAD_NUMBER_OF_ARGS
);
396 TYPEINIT1( SbStdClipboard
, SbxObject
);
398 SbStdClipboard::SbStdClipboard() :
399 SbxObject( OUString("Clipboard") )
401 SbxVariable
* p
= Find( OUString("Name"), SbxCLASS_PROPERTY
);
402 DBG_ASSERT( p
, "No Name Property" );
403 p
->SetUserData( ATTR_IMP_NAME
);
406 p
= Make( OUString("Clear"), SbxCLASS_METHOD
, SbxEMPTY
);
407 p
->SetFlag( SBX_DONTSTORE
);
408 p
->SetUserData( METH_CLEAR
);
409 p
= Make( OUString("GetData"), SbxCLASS_METHOD
, SbxEMPTY
);
410 p
->SetFlag( SBX_DONTSTORE
);
411 p
->SetUserData( METH_GETDATA
);
412 p
= Make( OUString("GetFormat"), SbxCLASS_METHOD
, SbxEMPTY
);
413 p
->SetFlag( SBX_DONTSTORE
);
414 p
->SetUserData( METH_GETFORMAT
);
415 p
= Make( OUString("GetText"), SbxCLASS_METHOD
, SbxEMPTY
);
416 p
->SetFlag( SBX_DONTSTORE
);
417 p
->SetUserData( METH_GETTEXT
);
418 p
= Make( OUString("SetData"), SbxCLASS_METHOD
, SbxEMPTY
);
419 p
->SetFlag( SBX_DONTSTORE
);
420 p
->SetUserData( METH_SETDATA
);
421 p
= Make( OUString("SetText"), SbxCLASS_METHOD
, SbxEMPTY
);
422 p
->SetFlag( SBX_DONTSTORE
);
423 p
->SetUserData( METH_SETTEXT
);
426 SbStdClipboard::~SbStdClipboard()
431 SbxVariable
* SbStdClipboard::Find( const OUString
& rName
, SbxClassType t
)
433 return SbxObject::Find( rName
, t
);
438 void SbStdClipboard::SFX_NOTIFY( SfxBroadcaster
& rBC
, const TypeId
& rBCType
,
439 const SfxHint
& rHint
, const TypeId
& rHintType
)
441 const SbxHint
* pHint
= PTR_CAST( SbxHint
, &rHint
);
445 if( pHint
->GetId() == SBX_HINT_INFOWANTED
)
447 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
451 SbxVariable
* pVar
= pHint
->GetVar();
452 SbxArray
* pPar_
= pVar
->GetParameters();
453 sal_uInt16 nWhich
= (sal_uInt16
)pVar
->GetUserData();
454 sal_Bool bWrite
= pHint
->GetId() == SBX_HINT_DATACHANGED
;
459 case METH_CLEAR
: MethClear( pVar
, pPar_
, bWrite
); return;
460 case METH_GETDATA
: MethGetData( pVar
, pPar_
, bWrite
); return;
461 case METH_GETFORMAT
: MethGetFormat( pVar
, pPar_
, bWrite
); return;
462 case METH_GETTEXT
: MethGetText( pVar
, pPar_
, bWrite
); return;
463 case METH_SETDATA
: MethSetData( pVar
, pPar_
, bWrite
); return;
464 case METH_SETTEXT
: MethSetText( pVar
, pPar_
, bWrite
); return;
467 SbxObject::SFX_NOTIFY( rBC
, rBCType
, rHint
, rHintType
);
472 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */