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 <basic/sberrors.hxx>
21 #include <basic/sbstar.hxx>
22 #include <vcl/outdev.hxx>
23 #include <sbstdobj.hxx>
25 #define ATTR_IMP_TYPE 1
26 #define ATTR_IMP_WIDTH 2
27 #define ATTR_IMP_HEIGHT 3
28 #define ATTR_IMP_BOLD 4
29 #define ATTR_IMP_ITALIC 5
30 #define ATTR_IMP_STRIKETHROUGH 6
31 #define ATTR_IMP_UNDERLINE 7
32 #define ATTR_IMP_SIZE 9
33 #define ATTR_IMP_NAME 10
36 #define METH_GETDATA 21
37 #define METH_GETFORMAT 22
38 #define METH_GETTEXT 23
39 #define METH_SETDATA 24
40 #define METH_SETTEXT 25
43 SbStdFactory::SbStdFactory()
47 SbxObjectRef
SbStdFactory::CreateObject( const OUString
& rClassName
)
49 if( rClassName
.equalsIgnoreAsciiCase("Picture") )
50 return new SbStdPicture
;
51 else if( rClassName
.equalsIgnoreAsciiCase("Font") )
58 void SbStdPicture::PropType( SbxVariable
* pVar
, bool bWrite
)
62 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY
);
66 GraphicType eType
= aGraphic
.GetType();
69 if( eType
== GraphicType::Bitmap
)
71 else if( eType
!= GraphicType::NONE
)
74 pVar
->PutInteger( nType
);
78 void SbStdPicture::PropWidth( SbxVariable
* pVar
, bool bWrite
)
82 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY
);
86 Size aSize
= OutputDevice::LogicToLogic(aGraphic
.GetPrefSize(), aGraphic
.GetPrefMapMode(), MapMode(MapUnit::MapTwip
));
87 pVar
->PutInteger( static_cast<sal_Int16
>(aSize
.Width()) );
90 void SbStdPicture::PropHeight( SbxVariable
* pVar
, bool bWrite
)
94 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY
);
98 Size aSize
= OutputDevice::LogicToLogic(aGraphic
.GetPrefSize(), aGraphic
.GetPrefMapMode(), MapMode(MapUnit::MapTwip
));
99 pVar
->PutInteger( static_cast<sal_Int16
>(aSize
.Height()) );
103 SbStdPicture::SbStdPicture() :
104 SbxObject( "Picture" )
107 SbxVariable
* p
= Make( "Type", SbxClassType::Property
, SbxVARIANT
);
108 p
->SetFlags( SbxFlagBits::Read
| SbxFlagBits::DontStore
);
109 p
->SetUserData( ATTR_IMP_TYPE
);
110 p
= Make( "Width", SbxClassType::Property
, SbxVARIANT
);
111 p
->SetFlags( SbxFlagBits::Read
| SbxFlagBits::DontStore
);
112 p
->SetUserData( ATTR_IMP_WIDTH
);
113 p
= Make( "Height", SbxClassType::Property
, SbxVARIANT
);
114 p
->SetFlags( SbxFlagBits::Read
| SbxFlagBits::DontStore
);
115 p
->SetUserData( ATTR_IMP_HEIGHT
);
118 SbStdPicture::~SbStdPicture()
123 void SbStdPicture::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
126 const SbxHint
* pHint
= dynamic_cast<const SbxHint
*>(&rHint
);
131 if( pHint
->GetId() == SfxHintId::BasicInfoWanted
)
133 SbxObject::Notify( rBC
, rHint
);
137 SbxVariable
* pVar
= pHint
->GetVar();
138 const sal_uInt32 nWhich
= pVar
->GetUserData();
139 bool bWrite
= pHint
->GetId() == SfxHintId::BasicDataChanged
;
144 case ATTR_IMP_TYPE
: PropType( pVar
, bWrite
); return;
145 case ATTR_IMP_WIDTH
: PropWidth( pVar
, bWrite
); return;
146 case ATTR_IMP_HEIGHT
: PropHeight( pVar
, bWrite
); return;
149 SbxObject::Notify( rBC
, rHint
);
153 void SbStdFont::PropBold( SbxVariable
* pVar
, bool bWrite
)
156 SetBold( pVar
->GetBool() );
158 pVar
->PutBool( IsBold() );
161 void SbStdFont::PropItalic( SbxVariable
* pVar
, bool bWrite
)
164 SetItalic( pVar
->GetBool() );
166 pVar
->PutBool( IsItalic() );
169 void SbStdFont::PropStrikeThrough( SbxVariable
* pVar
, bool bWrite
)
172 SetStrikeThrough( pVar
->GetBool() );
174 pVar
->PutBool( IsStrikeThrough() );
177 void SbStdFont::PropUnderline( SbxVariable
* pVar
, bool bWrite
)
180 SetUnderline( pVar
->GetBool() );
182 pVar
->PutBool( IsUnderline() );
185 void SbStdFont::PropSize( SbxVariable
* pVar
, bool bWrite
)
188 SetSize( static_cast<sal_uInt16
>(pVar
->GetInteger()) );
190 pVar
->PutInteger( static_cast<sal_Int16
>(GetSize()) );
193 void SbStdFont::PropName( SbxVariable
* pVar
, bool bWrite
)
197 aName
= pVar
->GetOUString();
201 pVar
->PutString( aName
);
206 SbStdFont::SbStdFont()
207 : SbxObject( "Font" )
210 , bStrikeThrough(false)
215 SbxVariable
* p
= Make( "Bold", SbxClassType::Property
, SbxVARIANT
);
216 p
->SetFlags( SbxFlagBits::ReadWrite
| SbxFlagBits::DontStore
);
217 p
->SetUserData( ATTR_IMP_BOLD
);
218 p
= Make( "Italic", SbxClassType::Property
, SbxVARIANT
);
219 p
->SetFlags( SbxFlagBits::ReadWrite
| SbxFlagBits::DontStore
);
220 p
->SetUserData( ATTR_IMP_ITALIC
);
221 p
= Make( "StrikeThrough", SbxClassType::Property
, SbxVARIANT
);
222 p
->SetFlags( SbxFlagBits::ReadWrite
| SbxFlagBits::DontStore
);
223 p
->SetUserData( ATTR_IMP_STRIKETHROUGH
);
224 p
= Make( "Underline", SbxClassType::Property
, SbxVARIANT
);
225 p
->SetFlags( SbxFlagBits::ReadWrite
| SbxFlagBits::DontStore
);
226 p
->SetUserData( ATTR_IMP_UNDERLINE
);
227 p
= Make( "Size", SbxClassType::Property
, SbxVARIANT
);
228 p
->SetFlags( SbxFlagBits::ReadWrite
| SbxFlagBits::DontStore
);
229 p
->SetUserData( ATTR_IMP_SIZE
);
231 // handle name property yourself
232 p
= Find( "Name", SbxClassType::Property
);
233 assert(p
&& "No Name Property");
234 p
->SetUserData( ATTR_IMP_NAME
);
237 SbStdFont::~SbStdFont()
241 void SbStdFont::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
243 const SbxHint
* pHint
= dynamic_cast<const SbxHint
*>(&rHint
);
248 if( pHint
->GetId() == SfxHintId::BasicInfoWanted
)
250 SbxObject::Notify( rBC
, rHint
);
254 SbxVariable
* pVar
= pHint
->GetVar();
255 const sal_uInt32 nWhich
= pVar
->GetUserData();
256 bool bWrite
= pHint
->GetId() == SfxHintId::BasicDataChanged
;
261 case ATTR_IMP_BOLD
: PropBold( pVar
, bWrite
); return;
262 case ATTR_IMP_ITALIC
: PropItalic( pVar
, bWrite
); return;
263 case ATTR_IMP_STRIKETHROUGH
:PropStrikeThrough( pVar
, bWrite
); return;
264 case ATTR_IMP_UNDERLINE
: PropUnderline( pVar
, bWrite
); return;
265 case ATTR_IMP_SIZE
: PropSize( pVar
, bWrite
); return;
266 case ATTR_IMP_NAME
: PropName( pVar
, bWrite
); return;
269 SbxObject::Notify( rBC
, rHint
);
273 void SbStdClipboard::MethClear( SbxArray
const * pPar_
)
275 if (pPar_
&& (pPar_
->Count() > 1))
277 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
283 void SbStdClipboard::MethGetData( SbxArray
* pPar_
)
285 if (!pPar_
|| (pPar_
->Count() != 2))
287 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
291 sal_Int16 nFormat
= pPar_
->Get(1)->GetInteger();
292 if( nFormat
<= 0 || nFormat
> 3 )
294 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT
);
300 void SbStdClipboard::MethGetFormat( SbxVariable
* pVar
, SbxArray
* pPar_
)
302 if (!pPar_
|| (pPar_
->Count() != 2))
304 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
308 sal_Int16 nFormat
= pPar_
->Get(1)->GetInteger();
309 if( nFormat
<= 0 || nFormat
> 3 )
311 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT
);
315 pVar
->PutBool( false );
318 void SbStdClipboard::MethGetText( SbxVariable
* pVar
, SbxArray
const * pPar_
)
320 if (pPar_
&& (pPar_
->Count() > 1))
322 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
326 pVar
->PutString( OUString() );
329 void SbStdClipboard::MethSetData( SbxArray
* pPar_
)
331 if (!pPar_
|| (pPar_
->Count() != 3))
333 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
337 sal_Int16 nFormat
= pPar_
->Get(2)->GetInteger();
338 if( nFormat
<= 0 || nFormat
> 3 )
340 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT
);
346 void SbStdClipboard::MethSetText( SbxArray
const * pPar_
)
348 if (!pPar_
|| (pPar_
->Count() != 2))
350 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
);
357 SbStdClipboard::SbStdClipboard() :
358 SbxObject( "Clipboard" )
360 SbxVariable
* p
= Find( "Name", SbxClassType::Property
);
361 assert(p
&& "No Name Property");
362 p
->SetUserData( ATTR_IMP_NAME
);
365 p
= Make( "Clear", SbxClassType::Method
, SbxEMPTY
);
366 p
->SetFlag( SbxFlagBits::DontStore
);
367 p
->SetUserData( METH_CLEAR
);
368 p
= Make( "GetData", SbxClassType::Method
, SbxEMPTY
);
369 p
->SetFlag( SbxFlagBits::DontStore
);
370 p
->SetUserData( METH_GETDATA
);
371 p
= Make( "GetFormat", SbxClassType::Method
, SbxEMPTY
);
372 p
->SetFlag( SbxFlagBits::DontStore
);
373 p
->SetUserData( METH_GETFORMAT
);
374 p
= Make( "GetText", SbxClassType::Method
, SbxEMPTY
);
375 p
->SetFlag( SbxFlagBits::DontStore
);
376 p
->SetUserData( METH_GETTEXT
);
377 p
= Make( "SetData", SbxClassType::Method
, SbxEMPTY
);
378 p
->SetFlag( SbxFlagBits::DontStore
);
379 p
->SetUserData( METH_SETDATA
);
380 p
= Make( "SetText", SbxClassType::Method
, SbxEMPTY
);
381 p
->SetFlag( SbxFlagBits::DontStore
);
382 p
->SetUserData( METH_SETTEXT
);
385 SbStdClipboard::~SbStdClipboard()
389 void SbStdClipboard::Notify( SfxBroadcaster
& rBC
, const SfxHint
& rHint
)
391 const SbxHint
* pHint
= dynamic_cast<const SbxHint
*>(&rHint
);
396 if( pHint
->GetId() == SfxHintId::BasicInfoWanted
)
398 SbxObject::Notify( rBC
, rHint
);
402 SbxVariable
* pVar
= pHint
->GetVar();
403 SbxArray
* pPar_
= pVar
->GetParameters();
404 const sal_uInt32 nWhich
= pVar
->GetUserData();
409 case METH_CLEAR
: MethClear( pPar_
); return;
410 case METH_GETDATA
: MethGetData( pPar_
); return;
411 case METH_GETFORMAT
: MethGetFormat( pVar
, pPar_
); return;
412 case METH_GETTEXT
: MethGetText( pVar
, pPar_
); return;
413 case METH_SETDATA
: MethSetData( pPar_
); return;
414 case METH_SETTEXT
: MethSetText( pPar_
); return;
417 SbxObject::Notify( rBC
, rHint
);
421 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */