LibreOffice Module svx (master) 1
viewlayoutitem.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
21#include <com/sun/star/uno/Sequence.hxx>
22#include <com/sun/star/beans/PropertyValue.hpp>
23
25#include <osl/diagnose.h>
26
27#include <cassert>
28
29
31
32constexpr OUStringLiteral VIEWLAYOUT_PARAM_COLUMNS = u"Columns";
33constexpr OUStringLiteral VIEWLAYOUT_PARAM_BOOKMODE = u"BookMode";
34#define VIEWLAYOUT_PARAMS 2
35
36
38(
39 sal_uInt16 nColumns,
40 bool bBookMode,
42)
43: SfxUInt16Item( _nWhich, nColumns ),
44 mbBookMode( bBookMode )
45{
46}
47
48
50: SfxUInt16Item( rOrig ),
51 mbBookMode( rOrig.IsBookMode() )
52{
53}
54
55
57{
58}
59
61{
62 return new SvxViewLayoutItem( *this );
63}
64
66{
67 assert(SfxPoolItem::operator==(rAttr));
68
69 const SvxViewLayoutItem& rItem = static_cast<const SvxViewLayoutItem&>(rAttr);
70
71 return ( GetValue() == rItem.GetValue() &&
72 mbBookMode == rItem.IsBookMode() );
73}
74
75bool SvxViewLayoutItem::QueryValue( css::uno::Any& rVal, sal_uInt8 nMemberId ) const
76{
77 nMemberId &= ~CONVERT_TWIPS;
78 switch ( nMemberId )
79 {
80 case 0 :
81 {
82 css::uno::Sequence< css::beans::PropertyValue > aSeq{
85 };
86 assert(aSeq.getLength() == VIEWLAYOUT_PARAMS);
87 rVal <<= aSeq;
88 }
89 break;
90
91 case MID_VIEWLAYOUT_COLUMNS : rVal <<= static_cast<sal_Int32>(GetValue()); break;
92 case MID_VIEWLAYOUT_BOOKMODE: rVal <<= mbBookMode; break;
93 default:
94 OSL_FAIL("svx::SvxViewLayoutItem::QueryValue(), Wrong MemberId!");
95 return false;
96 }
97
98 return true;
99}
100
101bool SvxViewLayoutItem::PutValue( const css::uno::Any& rVal, sal_uInt8 nMemberId )
102{
103 nMemberId &= ~CONVERT_TWIPS;
104 switch ( nMemberId )
105 {
106 case 0 :
107 {
108 css::uno::Sequence< css::beans::PropertyValue > aSeq;
109 if (( rVal >>= aSeq ) && ( aSeq.getLength() == VIEWLAYOUT_PARAMS ))
110 {
111 sal_Int32 nColumns( 0 );
112 bool bBookMode = false;
113 bool bAllConverted( true );
114 sal_Int16 nConvertedCount( 0 );
115 for ( const auto& rProp : std::as_const(aSeq) )
116 {
117 if ( rProp.Name == VIEWLAYOUT_PARAM_COLUMNS )
118 {
119 bAllConverted &= ( rProp.Value >>= nColumns );
120 ++nConvertedCount;
121 }
122 else if ( rProp.Name == VIEWLAYOUT_PARAM_BOOKMODE )
123 {
124 bAllConverted &= ( rProp.Value >>= bBookMode );
125 ++nConvertedCount;
126 }
127 }
128
129 if ( bAllConverted && nConvertedCount == VIEWLAYOUT_PARAMS )
130 {
131 SetValue( static_cast<sal_uInt16>(nColumns) );
132 mbBookMode = bBookMode;
133 return true;
134 }
135 }
136
137 return false;
138 }
139
140 case MID_VIEWLAYOUT_COLUMNS:
141 {
142 sal_Int32 nVal = 0;
143 if ( rVal >>= nVal )
144 {
145 SetValue( static_cast<sal_uInt16>(nVal) );
146 return true;
147 }
148 else
149 return false;
150 }
151
152 case MID_VIEWLAYOUT_BOOKMODE:
153 {
154 bool bBookMode = false;
155 if ( rVal >>= bBookMode )
156 {
157 mbBookMode = bBookMode;
158 return true;
159 }
160 else
161 return false;
162 }
163
164 default:
165 OSL_FAIL("svx::SvxViewLayoutItem::PutValue(), Wrong MemberId!");
166 return false;
167 }
168}
169
170/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetValue() const
void SetValue(sal_uInt16 nTheValue)
virtual bool operator==(const SfxPoolItem &) const override
virtual ~SvxViewLayoutItem() override
bool IsBookMode() const
SvxViewLayoutItem(sal_uInt16 nColumns=0, bool bBookMode=false, TypedWhichId< SvxViewLayoutItem > nWhich=SID_ATTR_VIEWLAYOUT)
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
static SfxPoolItem * CreateDefault()
virtual SvxViewLayoutItem * Clone(SfxItemPool *pPool=nullptr) const override
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
float u
Sequence< sal_Int8 > aSeq
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
unsigned char sal_uInt8
constexpr OUStringLiteral VIEWLAYOUT_PARAM_BOOKMODE
#define VIEWLAYOUT_PARAMS
constexpr OUStringLiteral VIEWLAYOUT_PARAM_COLUMNS