Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / basic / source / runtime / stdobj1.cxx
blobd6ae5d5dc35ad76d6da2e50df3ca2fe4b3dd46c0
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/wrkwin.hxx>
23 #include <vcl/svapp.hxx>
24 #include <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
36 #define METH_CLEAR 20
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
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") )
53 return new SbStdFont;
54 else
55 return nullptr;
59 void SbStdPicture::PropType( SbxVariable* pVar, bool bWrite )
61 if( bWrite )
63 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
64 return;
67 GraphicType eType = aGraphic.GetType();
68 sal_Int16 nType = 0;
70 if( eType == GraphicType::Bitmap )
71 nType = 1;
72 else if( eType != GraphicType::NONE )
73 nType = 2;
75 pVar->PutInteger( nType );
79 void SbStdPicture::PropWidth( SbxVariable* pVar, bool bWrite )
81 if( bWrite )
83 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
84 return;
87 Size aSize = aGraphic.GetPrefSize();
88 aSize = Application::GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
89 aSize = Application::GetAppWindow()->PixelToLogic( aSize, MapMode( MapUnit::MapTwip ) );
91 pVar->PutInteger( static_cast<sal_Int16>(aSize.Width()) );
94 void SbStdPicture::PropHeight( SbxVariable* pVar, bool bWrite )
96 if( bWrite )
98 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
99 return;
102 Size aSize = aGraphic.GetPrefSize();
103 aSize = Application::GetAppWindow()->LogicToPixel( aSize, aGraphic.GetPrefMapMode() );
104 aSize = Application::GetAppWindow()->PixelToLogic( aSize, MapMode( MapUnit::MapTwip ) );
106 pVar->PutInteger( static_cast<sal_Int16>(aSize.Height()) );
110 SbStdPicture::SbStdPicture() :
111 SbxObject( "Picture" )
113 // Properties
114 SbxVariable* p = Make( "Type", SbxClassType::Property, SbxVARIANT );
115 p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
116 p->SetUserData( ATTR_IMP_TYPE );
117 p = Make( "Width", SbxClassType::Property, SbxVARIANT );
118 p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
119 p->SetUserData( ATTR_IMP_WIDTH );
120 p = Make( "Height", SbxClassType::Property, SbxVARIANT );
121 p->SetFlags( SbxFlagBits::Read | SbxFlagBits::DontStore );
122 p->SetUserData( ATTR_IMP_HEIGHT );
125 SbStdPicture::~SbStdPicture()
130 void SbStdPicture::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
133 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
135 if( pHint )
137 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
139 SbxObject::Notify( rBC, rHint );
140 return;
143 SbxVariable* pVar = pHint->GetVar();
144 const sal_uInt32 nWhich = pVar->GetUserData();
145 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
147 // Properties
148 switch( nWhich )
150 case ATTR_IMP_TYPE: PropType( pVar, bWrite ); return;
151 case ATTR_IMP_WIDTH: PropWidth( pVar, bWrite ); return;
152 case ATTR_IMP_HEIGHT: PropHeight( pVar, bWrite ); return;
155 SbxObject::Notify( rBC, rHint );
160 void SbStdFont::PropBold( SbxVariable* pVar, bool bWrite )
162 if( bWrite )
163 SetBold( pVar->GetBool() );
164 else
165 pVar->PutBool( IsBold() );
168 void SbStdFont::PropItalic( SbxVariable* pVar, bool bWrite )
170 if( bWrite )
171 SetItalic( pVar->GetBool() );
172 else
173 pVar->PutBool( IsItalic() );
176 void SbStdFont::PropStrikeThrough( SbxVariable* pVar, bool bWrite )
178 if( bWrite )
179 SetStrikeThrough( pVar->GetBool() );
180 else
181 pVar->PutBool( IsStrikeThrough() );
184 void SbStdFont::PropUnderline( SbxVariable* pVar, bool bWrite )
186 if( bWrite )
187 SetUnderline( pVar->GetBool() );
188 else
189 pVar->PutBool( IsUnderline() );
192 void SbStdFont::PropSize( SbxVariable* pVar, bool bWrite )
194 if( bWrite )
195 SetSize( static_cast<sal_uInt16>(pVar->GetInteger()) );
196 else
197 pVar->PutInteger( static_cast<sal_Int16>(GetSize()) );
200 void SbStdFont::PropName( SbxVariable* pVar, bool bWrite )
202 if( bWrite )
204 aName = pVar->GetOUString();
206 else
208 pVar->PutString( GetFontName() );
213 SbStdFont::SbStdFont()
214 : SbxObject( "Font" )
215 , bBold(false)
216 , bItalic(false)
217 , bStrikeThrough(false)
218 , bUnderline(false)
219 , nSize(0)
221 // Properties
222 SbxVariable* p = Make( "Bold", SbxClassType::Property, SbxVARIANT );
223 p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
224 p->SetUserData( ATTR_IMP_BOLD );
225 p = Make( "Italic", SbxClassType::Property, SbxVARIANT );
226 p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
227 p->SetUserData( ATTR_IMP_ITALIC );
228 p = Make( "StrikeThrough", SbxClassType::Property, SbxVARIANT );
229 p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
230 p->SetUserData( ATTR_IMP_STRIKETHROUGH );
231 p = Make( "Underline", SbxClassType::Property, SbxVARIANT );
232 p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
233 p->SetUserData( ATTR_IMP_UNDERLINE );
234 p = Make( "Size", SbxClassType::Property, SbxVARIANT );
235 p->SetFlags( SbxFlagBits::ReadWrite | SbxFlagBits::DontStore );
236 p->SetUserData( ATTR_IMP_SIZE );
238 // handle name property yourself
239 p = Find( "Name", SbxClassType::Property );
240 assert(p && "No Name Property");
241 p->SetUserData( ATTR_IMP_NAME );
244 SbStdFont::~SbStdFont()
248 void SbStdFont::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
250 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
252 if( pHint )
254 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
256 SbxObject::Notify( rBC, rHint );
257 return;
260 SbxVariable* pVar = pHint->GetVar();
261 const sal_uInt32 nWhich = pVar->GetUserData();
262 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
264 // Properties
265 switch( nWhich )
267 case ATTR_IMP_BOLD: PropBold( pVar, bWrite ); return;
268 case ATTR_IMP_ITALIC: PropItalic( pVar, bWrite ); return;
269 case ATTR_IMP_STRIKETHROUGH:PropStrikeThrough( pVar, bWrite ); return;
270 case ATTR_IMP_UNDERLINE: PropUnderline( pVar, bWrite ); return;
271 case ATTR_IMP_SIZE: PropSize( pVar, bWrite ); return;
272 case ATTR_IMP_NAME: PropName( pVar, bWrite ); return;
275 SbxObject::Notify( rBC, rHint );
280 void SbStdClipboard::MethClear( SbxArray const * pPar_ )
282 if( pPar_ && (pPar_->Count() > 1) )
284 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
285 return;
290 void SbStdClipboard::MethGetData( SbxArray* pPar_ )
292 if( !pPar_ || (pPar_->Count() != 2) )
294 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
295 return;
298 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
299 if( nFormat <= 0 || nFormat > 3 )
301 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
302 return;
307 void SbStdClipboard::MethGetFormat( SbxVariable* pVar, SbxArray* pPar_ )
309 if( !pPar_ || (pPar_->Count() != 2) )
311 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
312 return;
315 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
316 if( nFormat <= 0 || nFormat > 3 )
318 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
319 return;
322 pVar->PutBool( false );
325 void SbStdClipboard::MethGetText( SbxVariable* pVar, SbxArray const * pPar_ )
327 if( pPar_ && (pPar_->Count() > 1) )
329 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
330 return;
333 pVar->PutString( OUString() );
336 void SbStdClipboard::MethSetData( SbxArray* pPar_ )
338 if( !pPar_ || (pPar_->Count() != 3) )
340 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
341 return;
344 sal_Int16 nFormat = pPar_->Get(2)->GetInteger();
345 if( nFormat <= 0 || nFormat > 3 )
347 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
348 return;
353 void SbStdClipboard::MethSetText( SbxArray const * pPar_ )
355 if( !pPar_ || (pPar_->Count() != 2) )
357 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
358 return;
364 SbStdClipboard::SbStdClipboard() :
365 SbxObject( "Clipboard" )
367 SbxVariable* p = Find( "Name", SbxClassType::Property );
368 assert(p && "No Name Property");
369 p->SetUserData( ATTR_IMP_NAME );
371 // register methods
372 p = Make( "Clear", SbxClassType::Method, SbxEMPTY );
373 p->SetFlag( SbxFlagBits::DontStore );
374 p->SetUserData( METH_CLEAR );
375 p = Make( "GetData", SbxClassType::Method, SbxEMPTY );
376 p->SetFlag( SbxFlagBits::DontStore );
377 p->SetUserData( METH_GETDATA );
378 p = Make( "GetFormat", SbxClassType::Method, SbxEMPTY );
379 p->SetFlag( SbxFlagBits::DontStore );
380 p->SetUserData( METH_GETFORMAT );
381 p = Make( "GetText", SbxClassType::Method, SbxEMPTY );
382 p->SetFlag( SbxFlagBits::DontStore );
383 p->SetUserData( METH_GETTEXT );
384 p = Make( "SetData", SbxClassType::Method, SbxEMPTY );
385 p->SetFlag( SbxFlagBits::DontStore );
386 p->SetUserData( METH_SETDATA );
387 p = Make( "SetText", SbxClassType::Method, SbxEMPTY );
388 p->SetFlag( SbxFlagBits::DontStore );
389 p->SetUserData( METH_SETTEXT );
392 SbStdClipboard::~SbStdClipboard()
396 void SbStdClipboard::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
398 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
400 if( pHint )
402 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
404 SbxObject::Notify( rBC, rHint );
405 return;
408 SbxVariable* pVar = pHint->GetVar();
409 SbxArray* pPar_ = pVar->GetParameters();
410 const sal_uInt32 nWhich = pVar->GetUserData();
412 // Methods
413 switch( nWhich )
415 case METH_CLEAR: MethClear( pPar_ ); return;
416 case METH_GETDATA: MethGetData( pPar_ ); return;
417 case METH_GETFORMAT: MethGetFormat( pVar, pPar_ ); return;
418 case METH_GETTEXT: MethGetText( pVar, pPar_ ); return;
419 case METH_SETDATA: MethSetData( pPar_ ); return;
420 case METH_SETTEXT: MethSetText( pPar_ ); return;
423 SbxObject::Notify( rBC, rHint );
428 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */