LibreOffice Module basic (master) 1
stdobj1.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <basic/sberrors.hxx>
21#include <basic/sbstar.hxx>
22#include <vcl/outdev.hxx>
23#include <sbstdobj.hxx>
24
25namespace {
26 enum UserData
27 {
28 ATTR_IMP_TYPE = 1,
29 ATTR_IMP_WIDTH = 2,
30 ATTR_IMP_HEIGHT = 3,
31 ATTR_IMP_BOLD = 4,
32 ATTR_IMP_ITALIC = 5,
33 ATTR_IMP_STRIKETHROUGH = 6,
34 ATTR_IMP_UNDERLINE = 7,
35 ATTR_IMP_SIZE = 9,
36 ATTR_IMP_NAME = 10,
37 METH_CLEAR = 20,
38 METH_GETDATA = 21,
39 METH_GETFORMAT = 22,
40 METH_GETTEXT = 23,
41 METH_SETDATA = 24,
42 METH_SETTEXT = 25
43 };
44}
45
47{
48}
49
50SbxObjectRef SbStdFactory::CreateObject( const OUString& rClassName )
51{
52 if( rClassName.equalsIgnoreAsciiCase("Picture") )
53 return new SbStdPicture;
54 else if( rClassName.equalsIgnoreAsciiCase("Font") )
55 return new SbStdFont;
56 else
57 return nullptr;
58}
59
60
61void SbStdPicture::PropType( SbxVariable* pVar, bool bWrite )
62{
63 if( bWrite )
64 {
66 return;
67 }
68
70 sal_Int16 nType = 0;
71
72 if( eType == GraphicType::Bitmap )
73 nType = 1;
74 else if( eType != GraphicType::NONE )
75 nType = 2;
76
77 pVar->PutInteger( nType );
78}
79
80
81void SbStdPicture::PropWidth( SbxVariable* pVar, bool bWrite )
82{
83 if( bWrite )
84 {
86 return;
87 }
88
90 pVar->PutInteger( static_cast<sal_Int16>(aSize.Width()) );
91}
92
93void SbStdPicture::PropHeight( SbxVariable* pVar, bool bWrite )
94{
95 if( bWrite )
96 {
98 return;
99 }
100
102 pVar->PutInteger( static_cast<sal_Int16>(aSize.Height()) );
103}
104
105
107 SbxObject( "Picture" )
108{
109 // Properties
112 p->SetUserData( ATTR_IMP_TYPE );
115 p->SetUserData( ATTR_IMP_WIDTH );
116 p = Make( "Height", SbxClassType::Property, SbxVARIANT );
118 p->SetUserData( ATTR_IMP_HEIGHT );
119}
120
122{
123}
124
125
127
128{
129 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
130
131 if( !pHint )
132 return;
133
134 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
135 {
136 SbxObject::Notify( rBC, rHint );
137 return;
138 }
139
140 SbxVariable* pVar = pHint->GetVar();
141 const sal_uInt32 nWhich = pVar->GetUserData();
142 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
143
144 // Properties
145 switch( nWhich )
146 {
147 case ATTR_IMP_TYPE: PropType( pVar, bWrite ); return;
148 case ATTR_IMP_WIDTH: PropWidth( pVar, bWrite ); return;
149 case ATTR_IMP_HEIGHT: PropHeight( pVar, bWrite ); return;
150 default: break;
151 }
152
153 SbxObject::Notify( rBC, rHint );
154}
155
156
157void SbStdFont::PropBold( SbxVariable* pVar, bool bWrite )
158{
159 if( bWrite )
160 SetBold( pVar->GetBool() );
161 else
162 pVar->PutBool( IsBold() );
163}
164
165void SbStdFont::PropItalic( SbxVariable* pVar, bool bWrite )
166{
167 if( bWrite )
168 SetItalic( pVar->GetBool() );
169 else
170 pVar->PutBool( IsItalic() );
171}
172
174{
175 if( bWrite )
176 SetStrikeThrough( pVar->GetBool() );
177 else
178 pVar->PutBool( IsStrikeThrough() );
179}
180
181void SbStdFont::PropUnderline( SbxVariable* pVar, bool bWrite )
182{
183 if( bWrite )
184 SetUnderline( pVar->GetBool() );
185 else
186 pVar->PutBool( IsUnderline() );
187}
188
189void SbStdFont::PropSize( SbxVariable* pVar, bool bWrite )
190{
191 if( bWrite )
192 SetSize( static_cast<sal_uInt16>(pVar->GetInteger()) );
193 else
194 pVar->PutInteger( static_cast<sal_Int16>(GetSize()) );
195}
196
197void SbStdFont::PropName( SbxVariable* pVar, bool bWrite )
198{
199 if( bWrite )
200 {
201 aName = pVar->GetOUString();
202 }
203 else
204 {
205 pVar->PutString( aName );
206 }
207}
208
209
211 : SbxObject( "Font" )
212 , bBold(false)
213 , bItalic(false)
214 , bStrikeThrough(false)
215 , bUnderline(false)
216 , nSize(0)
217{
218 // Properties
221 p->SetUserData( ATTR_IMP_BOLD );
222 p = Make( "Italic", SbxClassType::Property, SbxVARIANT );
224 p->SetUserData( ATTR_IMP_ITALIC );
225 p = Make( "StrikeThrough", SbxClassType::Property, SbxVARIANT );
227 p->SetUserData( ATTR_IMP_STRIKETHROUGH );
228 p = Make( "Underline", SbxClassType::Property, SbxVARIANT );
230 p->SetUserData( ATTR_IMP_UNDERLINE );
233 p->SetUserData( ATTR_IMP_SIZE );
234
235 // handle name property yourself
236 p = Find( "Name", SbxClassType::Property );
237 assert(p && "No Name Property");
238 p->SetUserData( ATTR_IMP_NAME );
239}
240
242{
243}
244
245void SbStdFont::Notify( SfxBroadcaster& rBC, const SfxHint& rHint )
246{
247 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
248
249 if( !pHint )
250 return;
251
252 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
253 {
254 SbxObject::Notify( rBC, rHint );
255 return;
256 }
257
258 SbxVariable* pVar = pHint->GetVar();
259 const sal_uInt32 nWhich = pVar->GetUserData();
260 bool bWrite = pHint->GetId() == SfxHintId::BasicDataChanged;
261
262 // Properties
263 switch( nWhich )
264 {
265 case ATTR_IMP_BOLD: PropBold( pVar, bWrite ); return;
266 case ATTR_IMP_ITALIC: PropItalic( pVar, bWrite ); return;
267 case ATTR_IMP_STRIKETHROUGH:PropStrikeThrough( pVar, bWrite ); return;
268 case ATTR_IMP_UNDERLINE: PropUnderline( pVar, bWrite ); return;
269 case ATTR_IMP_SIZE: PropSize( pVar, bWrite ); return;
270 case ATTR_IMP_NAME: PropName( pVar, bWrite ); return;
271 default: break;
272 }
273
274 SbxObject::Notify( rBC, rHint );
275}
276
277
279{
280 if (pPar_ && (pPar_->Count() > 1))
281 {
283 return;
284 }
285
286}
287
289{
290 if (!pPar_ || (pPar_->Count() != 2))
291 {
293 return;
294 }
295
296 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
297 if( nFormat <= 0 || nFormat > 3 )
298 {
300 return;
301 }
302
303}
304
306{
307 if (!pPar_ || (pPar_->Count() != 2))
308 {
310 return;
311 }
312
313 sal_Int16 nFormat = pPar_->Get(1)->GetInteger();
314 if( nFormat <= 0 || nFormat > 3 )
315 {
317 return;
318 }
319
320 pVar->PutBool( false );
321}
322
324{
325 if (pPar_ && (pPar_->Count() > 1))
326 {
328 return;
329 }
330
331 pVar->PutString( OUString() );
332}
333
335{
336 if (!pPar_ || (pPar_->Count() != 3))
337 {
339 return;
340 }
341
342 sal_Int16 nFormat = pPar_->Get(2)->GetInteger();
343 if( nFormat <= 0 || nFormat > 3 )
344 {
346 return;
347 }
348
349}
350
352{
353 if (!pPar_ || (pPar_->Count() != 2))
354 {
356 return;
357 }
358
359}
360
361
363 SbxObject( "Clipboard" )
364{
366 assert(p && "No Name Property");
367 p->SetUserData( ATTR_IMP_NAME );
368
369 // register methods
370 p = Make( "Clear", SbxClassType::Method, SbxEMPTY );
371 p->SetFlag( SbxFlagBits::DontStore );
372 p->SetUserData( METH_CLEAR );
373 p = Make( "GetData", SbxClassType::Method, SbxEMPTY );
374 p->SetFlag( SbxFlagBits::DontStore );
375 p->SetUserData( METH_GETDATA );
376 p = Make( "GetFormat", SbxClassType::Method, SbxEMPTY );
377 p->SetFlag( SbxFlagBits::DontStore );
378 p->SetUserData( METH_GETFORMAT );
379 p = Make( "GetText", SbxClassType::Method, SbxEMPTY );
380 p->SetFlag( SbxFlagBits::DontStore );
381 p->SetUserData( METH_GETTEXT );
382 p = Make( "SetData", SbxClassType::Method, SbxEMPTY );
383 p->SetFlag( SbxFlagBits::DontStore );
384 p->SetUserData( METH_SETDATA );
385 p = Make( "SetText", SbxClassType::Method, SbxEMPTY );
386 p->SetFlag( SbxFlagBits::DontStore );
387 p->SetUserData( METH_SETTEXT );
388}
389
391{
392}
393
395{
396 const SbxHint* pHint = dynamic_cast<const SbxHint*>(&rHint);
397
398 if( !pHint )
399 return;
400
401 if( pHint->GetId() == SfxHintId::BasicInfoWanted )
402 {
403 SbxObject::Notify( rBC, rHint );
404 return;
405 }
406
407 SbxVariable* pVar = pHint->GetVar();
408 SbxArray* pPar_ = pVar->GetParameters();
409 const sal_uInt32 nWhich = pVar->GetUserData();
410
411 // Methods
412 switch( nWhich )
413 {
414 case METH_CLEAR: MethClear( pPar_ ); return;
415 case METH_GETDATA: MethGetData( pPar_ ); return;
416 case METH_GETFORMAT: MethGetFormat( pVar, pPar_ ); return;
417 case METH_GETTEXT: MethGetText( pVar, pPar_ ); return;
418 case METH_SETDATA: MethSetData( pPar_ ); return;
419 case METH_SETTEXT: MethSetText( pPar_ ); return;
420 default: break;
421 }
422
423 SbxObject::Notify( rBC, rHint );
424}
425
426
427/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size GetPrefSize() const
GraphicType GetType() const
MapMode GetPrefMapMode() const
SAL_WARN_UNUSED_RESULT Point LogicToLogic(const Point &rPtSource, const MapMode *pMapModeSource, const MapMode *pMapModeDest) const
static void MethSetText(SbxArray const *pPar_)
Definition: stdobj1.cxx:351
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: stdobj1.cxx:394
virtual ~SbStdClipboard() override
Definition: stdobj1.cxx:390
static void MethGetText(SbxVariable *pVar, SbxArray const *pPar_)
Definition: stdobj1.cxx:323
static void MethGetData(SbxArray *pPar_)
Definition: stdobj1.cxx:288
static void MethClear(SbxArray const *pPar_)
Definition: stdobj1.cxx:278
static void MethSetData(SbxArray *pPar_)
Definition: stdobj1.cxx:334
static void MethGetFormat(SbxVariable *pVar, SbxArray *pPar_)
Definition: stdobj1.cxx:305
virtual SbxObjectRef CreateObject(const OUString &rClassName) override
Definition: stdobj1.cxx:50
void SetUnderline(bool bU)
Definition: sbstdobj.hxx:82
void PropSize(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:189
bool IsUnderline() const
Definition: sbstdobj.hxx:83
void PropName(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:197
bool IsBold() const
Definition: sbstdobj.hxx:77
void SetSize(sal_uInt16 nS)
Definition: sbstdobj.hxx:84
void PropStrikeThrough(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:173
void SetStrikeThrough(bool bS)
Definition: sbstdobj.hxx:80
bool IsItalic() const
Definition: sbstdobj.hxx:79
void PropUnderline(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:181
void PropBold(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:157
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: stdobj1.cxx:245
void SetBold(bool bB)
Definition: sbstdobj.hxx:76
bool IsStrikeThrough() const
Definition: sbstdobj.hxx:81
OUString aName
Definition: sbstdobj.hxx:60
void SetItalic(bool bI)
Definition: sbstdobj.hxx:78
void PropItalic(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:165
virtual ~SbStdFont() override
Definition: stdobj1.cxx:241
sal_uInt16 GetSize() const
Definition: sbstdobj.hxx:85
Graphic aGraphic
Definition: sbstdobj.hxx:36
void PropHeight(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:93
void PropType(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:61
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: stdobj1.cxx:126
void PropWidth(SbxVariable *pVar, bool bWrite)
Definition: stdobj1.cxx:81
virtual ~SbStdPicture() override
Definition: stdobj1.cxx:121
Definition: sbx.hxx:95
sal_uInt32 Count() const
Definition: sbxarray.cxx:87
SbxVariable * Get(sal_uInt32)
Definition: sbxarray.cxx:108
Definition: sbx.hxx:81
SbxVariable * GetVar() const
Definition: sbx.hxx:85
virtual SbxVariable * Find(const OUString &, SbxClassType)
Definition: sbxobj.cxx:182
SbxVariable * Make(const OUString &, SbxClassType, SbxDataType, bool bIsRuntimeFunction=false)
Definition: sbxobj.cxx:347
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: sbxobj.cxx:140
OUString GetOUString() const
Definition: sbxvalue.cxx:380
bool PutString(const OUString &)
Definition: sbxvalue.cxx:585
bool PutBool(bool)
Definition: sbxvalue.cxx:543
bool GetBool() const
Definition: sbxvar.hxx:153
bool PutInteger(sal_Int16)
sal_Int16 GetInteger() const
Definition: sbxvar.hxx:141
SbxArray * GetParameters() const
Definition: sbxvar.cxx:111
sal_uInt32 GetUserData() const
Definition: sbxvar.hxx:278
SfxHintId GetId() const
constexpr tools::Long Height() const
constexpr tools::Long Width() const
static void Error(ErrCode, const OUString &rMsg={})
Definition: sb.cxx:1683
DocumentType eType
GraphicType
void * p
QPRO_FUNC_TYPE nType
#define ERRCODE_BASIC_PROP_READONLY
Definition: sberrors.hxx:39
#define ERRCODE_BASIC_BAD_ARGUMENT
Definition: sberrors.hxx:26
#define ERRCODE_BASIC_BAD_NUMBER_OF_ARGS
Definition: sberrors.hxx:116
@ SbxEMPTY
Definition: sbxdef.hxx:38
@ SbxVARIANT
Definition: sbxdef.hxx:51