Coverage Report

Created: 2026-08-14 10:22

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/svx/source/items/pageitem.cxx
Line
Count
Source
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 <sal/config.h>
21
22
#include <utility>
23
24
#include <osl/diagnose.h>
25
#include <comphelper/processfactory.hxx>
26
#include <tools/resary.hxx>
27
#include <svx/pageitem.hxx>
28
#include <svx/strarray.hxx>
29
#include <editeng/itemtype.hxx>
30
#include <svx/unomid.hxx>
31
#include <com/sun/star/text/DefaultNumberingProvider.hpp>
32
#include <com/sun/star/text/XNumberingTypeInfo.hpp>
33
#include <com/sun/star/style/NumberingType.hpp>
34
#include <com/sun/star/style/PageStyleLayout.hpp>
35
#include <svl/itemset.hxx>
36
#include <svx/strings.hrc>
37
#include <svx/dialmgr.hxx>
38
39
using namespace ::com::sun::star;
40
41
0
SfxPoolItem* SvxPageItem::CreateDefault() { return new SvxPageItem(TypedWhichId<SvxPageItem>(0));}
42
43
SvxPageItem::SvxPageItem( const TypedWhichId<SvxPageItem> nId )
44
282k
    : SfxPoolItem( nId ),
45
46
282k
    m_eNumType    ( SVX_NUM_ARABIC ),
47
282k
    m_bLandscape  ( false ),
48
282k
    m_eUse        ( SvxPageUsage::All )
49
282k
{
50
282k
}
51
52
// Copy-Ctor
53
SvxPageItem::SvxPageItem( const SvxPageItem& rItem )
54
581k
    : SfxPoolItem( rItem )
55
581k
{
56
581k
    m_eNumType    = rItem.m_eNumType;
57
581k
    m_bLandscape  = rItem.m_bLandscape;
58
581k
    m_eUse        = rItem.m_eUse;
59
581k
}
60
61
863k
SvxPageItem::~SvxPageItem() {}
62
63
// Clone
64
SvxPageItem* SvxPageItem::Clone( SfxItemPool * ) const
65
579k
{
66
579k
    return new SvxPageItem( *this );
67
579k
}
68
69
// Test for equality
70
bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const
71
77.4k
{
72
77.4k
    assert(SfxPoolItem::operator==(rAttr));
73
77.4k
    const SvxPageItem& rItem = static_cast<const SvxPageItem&>(rAttr);
74
77.4k
    return ( m_eNumType   == rItem.m_eNumType   &&
75
77.4k
             m_bLandscape == rItem.m_bLandscape &&
76
77.3k
             m_eUse       == rItem.m_eUse );
77
77.4k
}
78
79
static OUString GetUsageText( const SvxPageUsage eU )
80
0
{
81
0
    switch( eU )
82
0
    {
83
0
        case SvxPageUsage::Left  : return SvxResId(RID_SVXITEMS_PAGE_USAGE_LEFT);
84
0
        case SvxPageUsage::Right : return SvxResId(RID_SVXITEMS_PAGE_USAGE_RIGHT);
85
0
        case SvxPageUsage::All   : return SvxResId(RID_SVXITEMS_PAGE_USAGE_ALL);
86
0
        case SvxPageUsage::Mirror: return SvxResId(RID_SVXITEMS_PAGE_USAGE_MIRROR);
87
0
        default:              return OUString();
88
0
    }
89
0
}
90
91
const TranslateId RID_SVXITEMS_PAGE_NUMS[] =
92
{
93
    RID_SVXITEMS_PAGE_NUM_CHR_UPPER,
94
    RID_SVXITEMS_PAGE_NUM_CHR_LOWER,
95
    RID_SVXITEMS_PAGE_NUM_ROM_UPPER,
96
    RID_SVXITEMS_PAGE_NUM_ROM_LOWER,
97
    RID_SVXITEMS_PAGE_NUM_ARABIC,
98
    RID_SVXITEMS_PAGE_NUM_NONE
99
};
100
101
namespace
102
{
103
    OUString GetNumberingDescription(SvxNumType eNumType)
104
0
    {
105
        // classic ones, keep displaying the old name
106
0
        if (eNumType <= css::style::NumberingType::NUMBER_NONE)
107
0
            return SvxResId(RID_SVXITEMS_PAGE_NUMS[eNumType]);
108
        // new ones, reuse the text used in the numbering dropdown list
109
0
        sal_uInt32 n = SvxNumberingTypeTable::FindIndex(eNumType);
110
0
        if (n != RESARRAY_INDEX_NOTFOUND)
111
0
            return SvxNumberingTypeTable::GetString(n);
112
0
        const css::uno::Reference<css::uno::XComponentContext>& xContext = comphelper::getProcessComponentContext();
113
0
        css::uno::Reference<css::text::XDefaultNumberingProvider> xDefNum = css::text::DefaultNumberingProvider::create(xContext);
114
0
        css::uno::Reference<css::text::XNumberingTypeInfo> xInfo(xDefNum, css::uno::UNO_QUERY);
115
0
        if (!xInfo.is())
116
0
            return OUString();
117
0
        return xInfo->getNumberingIdentifier(eNumType);
118
0
    }
119
}
120
121
bool SvxPageItem::GetPresentation
122
(
123
    SfxItemPresentation ePres,
124
    MapUnit             /*eCoreUnit*/,
125
    MapUnit             /*ePresUnit*/,
126
    OUString&           rText, const IntlWrapper&
127
)   const
128
0
{
129
0
    rText.clear();
130
0
    OUString cpDelimTmp(cpDelim);
131
132
0
    switch ( ePres )
133
0
    {
134
0
        case SfxItemPresentation::Nameless:
135
0
        {
136
0
            if ( !m_aDescName.isEmpty() )
137
0
            {
138
0
                rText = m_aDescName + cpDelimTmp;
139
0
            }
140
0
            rText += GetNumberingDescription(m_eNumType) + cpDelimTmp;
141
0
            if ( m_bLandscape )
142
0
                rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
143
0
            else
144
0
                rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
145
0
            OUString aUsageText = GetUsageText( m_eUse );
146
0
            if (!aUsageText.isEmpty())
147
0
            {
148
0
                rText += cpDelimTmp + aUsageText;
149
0
            }
150
0
            return true;
151
0
        }
152
0
        case SfxItemPresentation::Complete:
153
0
        {
154
0
            rText += SvxResId(RID_SVXITEMS_PAGE_COMPLETE);
155
0
            if ( !m_aDescName.isEmpty() )
156
0
            {
157
0
                rText += m_aDescName + cpDelimTmp;
158
0
            }
159
0
            rText += GetNumberingDescription(m_eNumType) + cpDelimTmp;
160
0
            if ( m_bLandscape )
161
0
                rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE);
162
0
            else
163
0
                rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE);
164
0
            OUString aUsageText = GetUsageText( m_eUse );
165
0
            if (!aUsageText.isEmpty())
166
0
            {
167
0
                rText += cpDelimTmp + aUsageText;
168
0
            }
169
0
            return true;
170
0
        }
171
0
        default: ;//prevent warning
172
0
    }
173
0
    return false;
174
0
}
175
176
177
bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const
178
120
{
179
//    sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
180
120
    nMemberId &= ~CONVERT_TWIPS;
181
120
    switch( nMemberId )
182
120
    {
183
40
        case MID_PAGE_NUMTYPE:
184
40
        {
185
            //! constants aren't in IDLs any more ?!?
186
40
            rVal <<= static_cast<sal_Int16>( m_eNumType );
187
40
        }
188
40
        break;
189
40
        case MID_PAGE_ORIENTATION:
190
40
            rVal <<= m_bLandscape;
191
40
        break;
192
40
        case MID_PAGE_LAYOUT     :
193
40
        {
194
40
            style::PageStyleLayout eRet;
195
40
            switch(m_eUse)
196
40
            {
197
0
                case SvxPageUsage::Left  : eRet = style::PageStyleLayout_LEFT;      break;
198
0
                case SvxPageUsage::Right : eRet = style::PageStyleLayout_RIGHT;     break;
199
40
                case SvxPageUsage::All   : eRet = style::PageStyleLayout_ALL;       break;
200
0
                case SvxPageUsage::Mirror: eRet = style::PageStyleLayout_MIRRORED; break;
201
0
                default:
202
0
                    OSL_FAIL("what layout is this?");
203
0
                    return false;
204
40
            }
205
40
            rVal <<= eRet;
206
40
        }
207
0
        break;
208
120
    }
209
210
120
    return true;
211
120
}
212
213
bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId )
214
20.8k
{
215
20.8k
    switch( nMemberId & ~CONVERT_TWIPS )
216
20.8k
    {
217
4.16k
        case MID_PAGE_NUMTYPE:
218
4.16k
        {
219
4.16k
            sal_Int32 nValue = 0;
220
4.16k
            if(!(rVal >>= nValue))
221
0
                return false;
222
223
4.16k
            m_eNumType = static_cast<SvxNumType>(nValue);
224
4.16k
        }
225
0
        break;
226
12.2k
        case MID_PAGE_ORIENTATION:
227
12.2k
            m_bLandscape = Any2Bool(rVal);
228
12.2k
        break;
229
4.41k
        case MID_PAGE_LAYOUT     :
230
4.41k
        {
231
4.41k
            style::PageStyleLayout eLayout;
232
4.41k
            if(!(rVal >>= eLayout))
233
0
            {
234
0
                sal_Int32 nValue = 0;
235
0
                if(!(rVal >>= nValue))
236
0
                    return false;
237
0
                eLayout = static_cast<style::PageStyleLayout>(nValue);
238
0
            }
239
4.41k
            switch( eLayout )
240
4.41k
            {
241
117
                case style::PageStyleLayout_LEFT    : m_eUse = SvxPageUsage::Left ; break;
242
151
                case style::PageStyleLayout_RIGHT   : m_eUse = SvxPageUsage::Right; break;
243
4.02k
                case style::PageStyleLayout_ALL     : m_eUse = SvxPageUsage::All  ; break;
244
123
                case style::PageStyleLayout_MIRRORED: m_eUse = SvxPageUsage::Mirror;break;
245
0
                default: ;//prevent warning
246
4.41k
            }
247
4.41k
        }
248
4.41k
        break;
249
20.8k
    }
250
20.8k
    return true;
251
20.8k
}
252
253
// HeaderFooterSet
254
SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, const SfxItemSet& rSet ) :
255
256
421k
    SfxSetItem( nId, rSet )
257
421k
{
258
421k
}
259
260
SvxSetItem::SvxSetItem( const SvxSetItem& rItem, SfxItemPool* pPool ) :
261
262
743k
    SfxSetItem( rItem, pPool )
263
743k
{
264
743k
}
265
266
SvxSetItem::SvxSetItem( const TypedWhichId<SvxSetItem> nId, SfxItemSet&& _pSet ) :
267
268
0
    SfxSetItem( nId, std::move(_pSet) )
269
0
{
270
0
}
271
272
SvxSetItem* SvxSetItem::Clone( SfxItemPool * pPool ) const
273
502k
{
274
502k
    return new SvxSetItem(*this, pPool);
275
502k
}
276
277
bool SvxSetItem::GetPresentation
278
(
279
    SfxItemPresentation /*ePres*/,
280
    MapUnit             /*eCoreUnit*/,
281
    MapUnit             /*ePresUnit*/,
282
    OUString&           rText, const IntlWrapper&
283
)   const
284
0
{
285
0
    rText.clear();
286
0
    return false;
287
0
}
288
289
290
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */