LibreOffice Module svl (master) 1
lckbitem.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 <svl/lckbitem.hxx>
21#include <tools/stream.hxx>
22#include <osl/diagnose.h>
23#include <com/sun/star/uno/Any.hxx>
24#include <com/sun/star/uno/Sequence.hxx>
25
26
28
29
31{
32}
33
34
36{
37}
38
39
40bool SfxLockBytesItem::operator==( const SfxPoolItem& rItem ) const
41{
42 return SfxPoolItem::operator==(rItem) && static_cast<const SfxLockBytesItem&>(rItem)._xVal == _xVal;
43}
44
46{
47 return new SfxLockBytesItem( *this );
48}
49
50// virtual
51bool SfxLockBytesItem::PutValue( const css::uno::Any& rVal, sal_uInt8 )
52{
53 css::uno::Sequence< sal_Int8 > aSeq;
54 if ( rVal >>= aSeq )
55 {
56 if ( aSeq.hasElements() )
57 {
58 SvMemoryStream* pStream = new SvMemoryStream();
59 pStream->WriteBytes( aSeq.getConstArray(), aSeq.getLength() );
60 pStream->Seek(0);
61
62 _xVal = new SvLockBytes( pStream, true );
63 }
64 else
65 _xVal = nullptr;
66
67 return true;
68 }
69
70 OSL_FAIL( "SfxLockBytesItem::PutValue - Wrong type!" );
71 return true;
72}
73
74// virtual
75bool SfxLockBytesItem::QueryValue( css::uno::Any& rVal, sal_uInt8 ) const
76{
77 if ( _xVal.is() )
78 {
79 sal_uInt32 nLen;
80 SvLockBytesStat aStat;
81
82 if ( _xVal->Stat( &aStat ) == ERRCODE_NONE )
83 nLen = aStat.nSize;
84 else
85 return false;
86
87 std::size_t nRead = 0;
88 css::uno::Sequence< sal_Int8 > aSeq( nLen );
89
90 _xVal->ReadAt( 0, aSeq.getArray(), nLen, &nRead );
91 rVal <<= aSeq;
92 }
93 else
94 {
95 css::uno::Sequence< sal_Int8 > aSeq( 0 );
96 rVal <<= aSeq;
97 }
98
99 return true;
100}
101
102/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
virtual ~SfxLockBytesItem() override
Definition: lckbitem.cxx:35
virtual bool operator==(const SfxPoolItem &) const override
Definition: lckbitem.cxx:40
SvLockBytesRef _xVal
Definition: lckbitem.hxx:28
static SfxPoolItem * CreateDefault()
Definition: lckbitem.cxx:27
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: lckbitem.cxx:75
virtual SfxLockBytesItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: lckbitem.cxx:45
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: lckbitem.cxx:51
virtual bool operator==(const SfxPoolItem &) const =0
Definition: poolitem.cxx:478
std::size_t WriteBytes(const void *pData, std::size_t nSize)
sal_uInt64 Seek(sal_uInt64 nPos)
bool is() const
#define ERRCODE_NONE
Sequence< sal_Int8 > aSeq
std::size_t nSize
unsigned char sal_uInt8