Kaydet (Commit) d5268ee6 authored tarafından Miklos Vajna's avatar Miklos Vajna

comphelper: the makePropertyValue<> template is useful outside sw

Change-Id: Id6392d105bbc01bb38f5615621f4d852a94e5df9
üst e15eacb5
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef INCLUDED_COMPHELPER_PROPERTYVALUE_HXX
#define INCLUDED_COMPHELPER_PROPERTYVALUE_HXX
#include <com/sun/star/beans/PropertyValue.hpp>
namespace comphelper
{
/**
* Creates a beans::PropertyValue easily, i.e. you can write:
*
* function(comphelper::makePropertyValue("Foo", nBar));
*
* instead of writing 3 extra lines to set the name and value of the beans::PropertyValue.
*/
template<typename T> css::beans::PropertyValue makePropertyValue(const OUString& rName, const T& rValue)
{
css::beans::PropertyValue aValue;
aValue.Name = rName;
aValue.Value <<= rValue;
return aValue;
}
}
#endif // INCLUDED_COMPHELPER_PROPERTYVALUE_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -67,6 +67,7 @@ ...@@ -67,6 +67,7 @@
#include <comphelper/servicehelper.hxx> #include <comphelper/servicehelper.hxx>
#include <comphelper/sequence.hxx> #include <comphelper/sequence.hxx>
#include <cppuhelper/supportsservice.hxx> #include <cppuhelper/supportsservice.hxx>
#include <comphelper/propertyvalue.hxx>
#include <paratr.hxx> #include <paratr.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -76,12 +77,6 @@ using namespace ::com::sun::star::beans; ...@@ -76,12 +77,6 @@ using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::text; using namespace ::com::sun::star::text;
using namespace ::com::sun::star::style; using namespace ::com::sun::star::style;
template<typename T>
PropertyValue makePropertyValue(T const& rValue, OUString const& rName)
{
return PropertyValue(rName, -1, makeAny(rValue), PropertyState_DIRECT_VALUE);
}
// Constants for the css::text::ColumnSeparatorStyle // Constants for the css::text::ColumnSeparatorStyle
#define API_COL_LINE_NONE 0 #define API_COL_LINE_NONE 0
#define API_COL_LINE_SOLID 1 #define API_COL_LINE_SOLID 1
...@@ -1357,47 +1352,44 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1357,47 +1352,44 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
//adjust //adjust
SvxAdjust eAdj = rFmt.GetNumAdjust(); SvxAdjust eAdj = rFmt.GetNumAdjust();
sal_Int16 nINT16 = aSvxToUnoAdjust[eAdj]; sal_Int16 nINT16 = aSvxToUnoAdjust[eAdj];
aPropertyValues.push_back(makePropertyValue(nINT16, "Adjust")); aPropertyValues.push_back(comphelper::makePropertyValue("Adjust", nINT16));
//parentnumbering //parentnumbering
nINT16 = rFmt.GetIncludeUpperLevels(); nINT16 = rFmt.GetIncludeUpperLevels();
aPropertyValues.push_back(makePropertyValue(nINT16, "ParentNumbering")); aPropertyValues.push_back(comphelper::makePropertyValue("ParentNumbering", nINT16));
//prefix //prefix
OUString aUString = rFmt.GetPrefix(); OUString aUString = rFmt.GetPrefix();
aPropertyValues.push_back(makePropertyValue(aUString, "Prefix")); aPropertyValues.push_back(comphelper::makePropertyValue("Prefix", aUString));
//suffix //suffix
aUString = rFmt.GetSuffix(); aUString = rFmt.GetSuffix();
aPropertyValues.push_back(makePropertyValue(aUString, "Suffix")); aPropertyValues.push_back(comphelper::makePropertyValue("Suffix", aUString));
//char style name //char style name
OUString CharStyleName(rCharFormatName); OUString CharStyleName(rCharFormatName);
aUString.clear(); aUString.clear();
SwStyleNameMapper::FillProgName( CharStyleName, aUString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true ); SwStyleNameMapper::FillProgName( CharStyleName, aUString, nsSwGetPoolIdFromName::GET_POOLID_CHRFMT, true );
aPropertyValues.push_back(makePropertyValue(aUString, "CharStyleName")); aPropertyValues.push_back(comphelper::makePropertyValue("CharStyleName", aUString));
//startvalue //startvalue
nINT16 = rFmt.GetStart(); nINT16 = rFmt.GetStart();
aPropertyValues.push_back(makePropertyValue(nINT16, "StartWith")); aPropertyValues.push_back(comphelper::makePropertyValue("StartWith", nINT16));
if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION ) if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_WIDTH_AND_POSITION )
{ {
//leftmargin //leftmargin
sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetAbsLSpace()); sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetAbsLSpace());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LEFT_MARGIN, nINT32));
makePropertyValue(nINT32, UNO_NAME_LEFT_MARGIN));
//chartextoffset //chartextoffset
nINT32 = convertTwipToMm100(rFmt.GetCharTextDistance()); nINT32 = convertTwipToMm100(rFmt.GetCharTextDistance());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_SYMBOL_TEXT_DISTANCE, nINT32));
makePropertyValue(nINT32, UNO_NAME_SYMBOL_TEXT_DISTANCE));
//firstlineoffset //firstlineoffset
nINT32 = convertTwipToMm100(rFmt.GetFirstLineOffset()); nINT32 = convertTwipToMm100(rFmt.GetFirstLineOffset());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_FIRST_LINE_OFFSET, nINT32));
makePropertyValue(nINT32, UNO_NAME_FIRST_LINE_OFFSET));
} }
// PositionAndSpaceMode // PositionAndSpaceMode
...@@ -1406,8 +1398,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1406,8 +1398,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
{ {
nINT16 = PositionAndSpaceMode::LABEL_ALIGNMENT; nINT16 = PositionAndSpaceMode::LABEL_ALIGNMENT;
} }
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_POSITION_AND_SPACE_MODE, nINT16));
makePropertyValue(nINT16, UNO_NAME_POSITION_AND_SPACE_MODE));
if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT ) if ( rFmt.GetPositionAndSpaceMode() == SvxNumberFormat::LABEL_ALIGNMENT )
{ {
...@@ -1421,28 +1412,24 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1421,28 +1412,24 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
{ {
nINT16 = LabelFollow::NOTHING; nINT16 = LabelFollow::NOTHING;
} }
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LABEL_FOLLOWED_BY, nINT16));
makePropertyValue(nINT16, UNO_NAME_LABEL_FOLLOWED_BY));
// ListtabStopPosition // ListtabStopPosition
sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetListtabPos()); sal_Int32 nINT32 = convertTwipToMm100(rFmt.GetListtabPos());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_LISTTAB_STOP_POSITION, nINT32));
makePropertyValue(nINT32, UNO_NAME_LISTTAB_STOP_POSITION));
// FirstLineIndent // FirstLineIndent
nINT32 = convertTwipToMm100(rFmt.GetFirstLineIndent()); nINT32 = convertTwipToMm100(rFmt.GetFirstLineIndent());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_FIRST_LINE_INDENT, nINT32));
makePropertyValue(nINT32, UNO_NAME_FIRST_LINE_INDENT));
// IndentAt // IndentAt
nINT32 = convertTwipToMm100(rFmt.GetIndentAt()); nINT32 = convertTwipToMm100(rFmt.GetIndentAt());
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_INDENT_AT, nINT32));
makePropertyValue(nINT32, UNO_NAME_INDENT_AT));
} }
//numberingtype //numberingtype
nINT16 = rFmt.GetNumberingType(); nINT16 = rFmt.GetNumberingType();
aPropertyValues.push_back(makePropertyValue(nINT16, "NumberingType")); aPropertyValues.push_back(comphelper::makePropertyValue("NumberingType", nINT16));
if(!bChapterNum) if(!bChapterNum)
{ {
...@@ -1450,25 +1437,24 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1450,25 +1437,24 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
{ {
//BulletId //BulletId
nINT16 = rFmt.GetBulletChar(); nINT16 = rFmt.GetBulletChar();
aPropertyValues.push_back(makePropertyValue(nINT16, "BulletId")); aPropertyValues.push_back(comphelper::makePropertyValue("BulletId", nINT16));
const vcl::Font* pFont = rFmt.GetBulletFont(); const vcl::Font* pFont = rFmt.GetBulletFont();
//BulletChar //BulletChar
aUString = OUString(rFmt.GetBulletChar()); aUString = OUString(rFmt.GetBulletChar());
aPropertyValues.push_back(makePropertyValue(aUString, "BulletChar")); aPropertyValues.push_back(comphelper::makePropertyValue("BulletChar", aUString));
//BulletFontName //BulletFontName
aUString = pFont ? pFont->GetStyleName() : OUString(); aUString = pFont ? pFont->GetStyleName() : OUString();
aPropertyValues.push_back(makePropertyValue(aUString, "BulletFontName")); aPropertyValues.push_back(comphelper::makePropertyValue("BulletFontName", aUString));
//BulletFont //BulletFont
if(pFont) if(pFont)
{ {
awt::FontDescriptor aDesc; awt::FontDescriptor aDesc;
SvxUnoFontDescriptor::ConvertFromFont( *pFont, aDesc ); SvxUnoFontDescriptor::ConvertFromFont( *pFont, aDesc );
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_BULLET_FONT, aDesc));
makePropertyValue(aDesc, UNO_NAME_BULLET_FONT));
} }
} }
if(SVX_NUM_BITMAP == rFmt.GetNumberingType()) if(SVX_NUM_BITMAP == rFmt.GetNumberingType())
...@@ -1483,8 +1469,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1483,8 +1469,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
} }
else else
aUString.clear(); aUString.clear();
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_GRAPHIC_URL, aUString));
makePropertyValue(aUString, UNO_NAME_GRAPHIC_URL));
//graphicbitmap //graphicbitmap
const Graphic* pGraphic = 0; const Graphic* pGraphic = 0;
...@@ -1493,15 +1478,13 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1493,15 +1478,13 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
if(pGraphic) if(pGraphic)
{ {
uno::Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( pGraphic->GetBitmapEx() ); uno::Reference<awt::XBitmap> xBmp = VCLUnoHelper::CreateBitmap( pGraphic->GetBitmapEx() );
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_GRAPHIC_BITMAP, xBmp));
makePropertyValue(xBmp, UNO_NAME_GRAPHIC_BITMAP));
} }
Size aSize = rFmt.GetGraphicSize(); Size aSize = rFmt.GetGraphicSize();
// #i101131# // #i101131#
// adjust conversion due to type mismatch between <Size> and <awt::Size> // adjust conversion due to type mismatch between <Size> and <awt::Size>
awt::Size aAwtSize(convertTwipToMm100(aSize.Width()), convertTwipToMm100(aSize.Height())); awt::Size aAwtSize(convertTwipToMm100(aSize.Width()), convertTwipToMm100(aSize.Height()));
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_GRAPHIC_SIZE, aAwtSize));
makePropertyValue(aAwtSize, UNO_NAME_GRAPHIC_SIZE));
const SwFmtVertOrient* pOrient = rFmt.GetGraphicOrientation(); const SwFmtVertOrient* pOrient = rFmt.GetGraphicOrientation();
if(pOrient) if(pOrient)
...@@ -1516,8 +1499,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt( ...@@ -1516,8 +1499,7 @@ uno::Sequence<beans::PropertyValue> SwXNumberingRules::GetPropertiesForNumFmt(
else else
{ {
aUString = *pHeadingStyleName; aUString = *pHeadingStyleName;
aPropertyValues.push_back( aPropertyValues.push_back(comphelper::makePropertyValue(UNO_NAME_HEADING_STYLE_NAME, aUString));
makePropertyValue(aUString, UNO_NAME_HEADING_STYLE_NAME));
} }
return ::comphelper::containerToSequence(aPropertyValues); return ::comphelper::containerToSequence(aPropertyValues);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment