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 <tools/stream.hxx> 26 #include <svx/pageitem.hxx> 27 #include <editeng/itemtype.hxx> 28 #include <svx/unomid.hxx> 29 #include <com/sun/star/style/NumberingType.hpp> 30 #include <com/sun/star/style/PageStyleLayout.hpp> 31 #include <com/sun/star/style/BreakType.hpp> 32 #include <svl/itemset.hxx> 33 #include <svx/strings.hrc> 34 #include <svx/svxitems.hrc> 35 #include <svx/dialmgr.hxx> 36 37 using namespace ::com::sun::star; 38 39 SfxPoolItem* SvxPageItem::CreateDefault() { return new SvxPageItem(0);} 40 41 SvxPageItem::SvxPageItem( const sal_uInt16 nId ) : SfxPoolItem( nId ), 42 43 eNumType ( SVX_NUM_ARABIC ), 44 bLandscape ( false ), 45 eUse ( SvxPageUsage::All ) 46 { 47 } 48 49 // Copy-Ctor 50 SvxPageItem::SvxPageItem( const SvxPageItem& rItem ) 51 : SfxPoolItem( rItem ) 52 { 53 eNumType = rItem.eNumType; 54 bLandscape = rItem.bLandscape; 55 eUse = rItem.eUse; 56 } 57 58 SvxPageItem::~SvxPageItem() {} 59 60 // Clone 61 SfxPoolItem* SvxPageItem::Clone( SfxItemPool * ) const 62 { 63 return new SvxPageItem( *this ); 64 } 65 66 // Test for equality 67 bool SvxPageItem::operator==( const SfxPoolItem& rAttr ) const 68 { 69 assert(SfxPoolItem::operator==(rAttr)); 70 const SvxPageItem& rItem = static_cast<const SvxPageItem&>(rAttr); 71 return ( eNumType == rItem.eNumType && 72 bLandscape == rItem.bLandscape && 73 eUse == rItem.eUse ); 74 } 75 76 static OUString GetUsageText( const SvxPageUsage eU ) 77 { 78 switch( eU ) 79 { 80 case SvxPageUsage::Left : return SvxResId(RID_SVXITEMS_PAGE_USAGE_LEFT); 81 case SvxPageUsage::Right : return SvxResId(RID_SVXITEMS_PAGE_USAGE_RIGHT); 82 case SvxPageUsage::All : return SvxResId(RID_SVXITEMS_PAGE_USAGE_ALL); 83 case SvxPageUsage::Mirror: return SvxResId(RID_SVXITEMS_PAGE_USAGE_MIRROR); 84 default: return OUString(); 85 } 86 } 87 88 static const char* RID_SVXITEMS_PAGE_NUMS[] = 89 { 90 RID_SVXITEMS_PAGE_NUM_CHR_UPPER, 91 RID_SVXITEMS_PAGE_NUM_CHR_LOWER, 92 RID_SVXITEMS_PAGE_NUM_ROM_UPPER, 93 RID_SVXITEMS_PAGE_NUM_ROM_LOWER, 94 RID_SVXITEMS_PAGE_NUM_ARABIC, 95 RID_SVXITEMS_PAGE_NUM_NONE 96 }; 97 98 bool SvxPageItem::GetPresentation 99 ( 100 SfxItemPresentation ePres, 101 MapUnit /*eCoreUnit*/, 102 MapUnit /*ePresUnit*/, 103 OUString& rText, const IntlWrapper& 104 ) const 105 { 106 rText.clear(); 107 OUString cpDelimTmp(cpDelim); 108 109 switch ( ePres ) 110 { 111 case SfxItemPresentation::Nameless: 112 { 113 if ( !aDescName.isEmpty() ) 114 { 115 rText = aDescName + cpDelimTmp; 116 } 117 assert(eNumType <= css::style::NumberingType::NUMBER_NONE && "enum overflow"); 118 rText += SvxResId(RID_SVXITEMS_PAGE_NUMS[eNumType]) + cpDelimTmp; 119 if ( bLandscape ) 120 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE); 121 else 122 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE); 123 OUString aUsageText = GetUsageText( eUse ); 124 if (!aUsageText.isEmpty()) 125 { 126 rText += cpDelimTmp + aUsageText; 127 } 128 return true; 129 } 130 case SfxItemPresentation::Complete: 131 { 132 rText += SvxResId(RID_SVXITEMS_PAGE_COMPLETE); 133 if ( !aDescName.isEmpty() ) 134 { 135 rText += aDescName + cpDelimTmp; 136 } 137 assert(eNumType <= css::style::NumberingType::NUMBER_NONE && "enum overflow"); 138 rText += SvxResId(RID_SVXITEMS_PAGE_NUMS[eNumType]) + cpDelimTmp; 139 if ( bLandscape ) 140 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_TRUE); 141 else 142 rText += SvxResId(RID_SVXITEMS_PAGE_LAND_FALSE); 143 OUString aUsageText = GetUsageText( eUse ); 144 if (!aUsageText.isEmpty()) 145 { 146 rText += cpDelimTmp + aUsageText; 147 } 148 return true; 149 } 150 default: ;//prevent warning 151 } 152 return false; 153 } 154 155 156 bool SvxPageItem::QueryValue( uno::Any& rVal, sal_uInt8 nMemberId ) const 157 { 158 // sal_Bool bConvert = 0!=(nMemberId&CONVERT_TWIPS); 159 nMemberId &= ~CONVERT_TWIPS; 160 switch( nMemberId ) 161 { 162 case MID_PAGE_NUMTYPE: 163 { 164 //! constants aren't in IDLs any more ?!? 165 rVal <<= static_cast<sal_Int16>( eNumType ); 166 } 167 break; 168 case MID_PAGE_ORIENTATION: 169 rVal <<= bLandscape; 170 break; 171 case MID_PAGE_LAYOUT : 172 { 173 style::PageStyleLayout eRet; 174 switch(eUse) 175 { 176 case SvxPageUsage::Left : eRet = style::PageStyleLayout_LEFT; break; 177 case SvxPageUsage::Right : eRet = style::PageStyleLayout_RIGHT; break; 178 case SvxPageUsage::All : eRet = style::PageStyleLayout_ALL; break; 179 case SvxPageUsage::Mirror: eRet = style::PageStyleLayout_MIRRORED; break; 180 default: 181 OSL_FAIL("what layout is this?"); 182 return false; 183 } 184 rVal <<= eRet; 185 } 186 break; 187 } 188 189 return true; 190 } 191 192 bool SvxPageItem::PutValue( const uno::Any& rVal, sal_uInt8 nMemberId ) 193 { 194 switch( nMemberId & ~CONVERT_TWIPS ) 195 { 196 case MID_PAGE_NUMTYPE: 197 { 198 sal_Int32 nValue = 0; 199 if(!(rVal >>= nValue)) 200 return false; 201 202 eNumType = static_cast<SvxNumType>(nValue); 203 } 204 break; 205 case MID_PAGE_ORIENTATION: 206 bLandscape = Any2Bool(rVal); 207 break; 208 case MID_PAGE_LAYOUT : 209 { 210 style::PageStyleLayout eLayout; 211 if(!(rVal >>= eLayout)) 212 { 213 sal_Int32 nValue = 0; 214 if(!(rVal >>= nValue)) 215 return false; 216 eLayout = static_cast<style::PageStyleLayout>(nValue); 217 } 218 switch( eLayout ) 219 { 220 case style::PageStyleLayout_LEFT : eUse = SvxPageUsage::Left ; break; 221 case style::PageStyleLayout_RIGHT : eUse = SvxPageUsage::Right; break; 222 case style::PageStyleLayout_ALL : eUse = SvxPageUsage::All ; break; 223 case style::PageStyleLayout_MIRRORED: eUse = SvxPageUsage::Mirror;break; 224 default: ;//prevent warning 225 } 226 } 227 break; 228 } 229 return true; 230 } 231 232 // HeaderFooterSet 233 SvxSetItem::SvxSetItem( const sal_uInt16 nId, const SfxItemSet& rSet ) : 234 235 SfxSetItem( nId, rSet ) 236 { 237 } 238 239 SvxSetItem::SvxSetItem( const SvxSetItem& rItem ) : 240 241 SfxSetItem( rItem ) 242 { 243 } 244 245 SvxSetItem::SvxSetItem( const sal_uInt16 nId, std::unique_ptr<SfxItemSet>&& _pSet ) : 246 247 SfxSetItem( nId, std::move(_pSet) ) 248 { 249 } 250 251 SfxPoolItem* SvxSetItem::Clone( SfxItemPool * ) const 252 { 253 return new SvxSetItem(*this); 254 } 255 256 257 bool SvxSetItem::GetPresentation 258 ( 259 SfxItemPresentation /*ePres*/, 260 MapUnit /*eCoreUnit*/, 261 MapUnit /*ePresUnit*/, 262 OUString& rText, const IntlWrapper& 263 ) const 264 { 265 rText.clear(); 266 return false; 267 } 268 269 270 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 271
