LanguageTool: don't crash if REST protocol isn't set
[LibreOffice.git] / basic / source / runtime / stdobj1.cxx
blobee7df8d7a62df6b2cc8cac4804151ee82f04fc57
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/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
35 #define METH_CLEAR 20
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") )
52 return new SbStdFont;
53 else
54 return nullptr;
58 void SbStdPicture::PropType( SbxVariable* pVar, bool bWrite )
60 if( bWrite )
62 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
63 return;
66 GraphicType eType = aGraphic.GetType();
67 sal_Int16 nType = 0;
69 if( eType == GraphicType::Bitmap )
70 nType = 1;
71 else if( eType != GraphicType::NONE )
72 nType = 2;
74 pVar->PutInteger( nType );
78 void SbStdPicture::PropWidth( SbxVariable* pVar, bool bWrite )
80 if( bWrite )
82 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
83 return;
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 )
92 if( bWrite )
94 StarBASIC::Error( ERRCODE_BASIC_PROP_READONLY );
95 return;
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" )
106 // Properties
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);
128 if( !pHint )
129 return;
131 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
133 SbxObject::Notify( rBC, rHint );
134 return;
137 SbxVariable* pVar = pHint->GetVar();
138 const sal_uInt32 nWhich = pVar->GetUserData();
139 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
141 // Properties
142 switch( nWhich )
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 )
155 if( bWrite )
156 SetBold( pVar->GetBool() );
157 else
158 pVar->PutBool( IsBold() );
161 void SbStdFont::PropItalic( SbxVariable* pVar, bool bWrite )
163 if( bWrite )
164 SetItalic( pVar->GetBool() );
165 else
166 pVar->PutBool( IsItalic() );
169 void SbStdFont::PropStrikeThrough( SbxVariable* pVar, bool bWrite )
171 if( bWrite )
172 SetStrikeThrough( pVar->GetBool() );
173 else
174 pVar->PutBool( IsStrikeThrough() );
177 void SbStdFont::PropUnderline( SbxVariable* pVar, bool bWrite )
179 if( bWrite )
180 SetUnderline( pVar->GetBool() );
181 else
182 pVar->PutBool( IsUnderline() );
185 void SbStdFont::PropSize( SbxVariable* pVar, bool bWrite )
187 if( bWrite )
188 SetSize( static_cast<sal_uInt16>(pVar->GetInteger()) );
189 else
190 pVar->PutInteger( static_cast<sal_Int16>(GetSize()) );
193 void SbStdFont::PropName( SbxVariable* pVar, bool bWrite )
195 if( bWrite )
197 aName = pVar->GetOUString();
199 else
201 pVar->PutString( aName );
206 SbStdFont::SbStdFont()
207 : SbxObject( "Font" )
208 , bBold(false)
209 , bItalic(false)
210 , bStrikeThrough(false)
211 , bUnderline(false)
212 , nSize(0)
214 // Properties
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);
245 if( !pHint )
246 return;
248 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
250 SbxObject::Notify( rBC, rHint );
251 return;
254 SbxVariable* pVar = pHint->GetVar();
255 const sal_uInt32 nWhich = pVar->GetUserData();
256 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
258 // Properties
259 switch( nWhich )
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 );
278 return;
283 void SbStdClipboard::MethGetData( SbxArray* pPar_ )
285 if (!pPar_ || (pPar_->Count() != 2))
287 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
288 return;
291 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
292 if( nFormat <= 0 || nFormat > 3 )
294 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
295 return;
300 void SbStdClipboard::MethGetFormat( SbxVariable* pVar, SbxArray* pPar_ )
302 if (!pPar_ || (pPar_->Count() != 2))
304 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
305 return;
308 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
309 if( nFormat <= 0 || nFormat > 3 )
311 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
312 return;
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 );
323 return;
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 );
334 return;
337 sal_Int16 nFormat = pPar_->Get(2)->GetInteger();
338 if( nFormat <= 0 || nFormat > 3 )
340 StarBASIC::Error( ERRCODE_BASIC_BAD_ARGUMENT );
341 return;
346 void SbStdClipboard::MethSetText( SbxArray const * pPar_ )
348 if (!pPar_ || (pPar_->Count() != 2))
350 StarBASIC::Error( ERRCODE_BASIC_BAD_NUMBER_OF_ARGS );
351 return;
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 );
364 // register methods
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);
393 if( !pHint )
394 return;
396 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
398 SbxObject::Notify( rBC, rHint );
399 return;
402 SbxVariable* pVar = pHint->GetVar();
403 SbxArray* pPar_ = pVar->GetParameters();
404 const sal_uInt32 nWhich = pVar->GetUserData();
406 // Methods
407 switch( nWhich )
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: */