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