LibreOffice Module svl (master) 1
ptitem.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
20
21#include <svl/ptitem.hxx>
22#include <com/sun/star/uno/Any.hxx>
23#include <com/sun/star/awt/Point.hpp>
24#include <osl/diagnose.h>
25#include <tools/mapunit.hxx>
27
28#include <svl/poolitem.hxx>
29#include <svl/memberid.h>
30
31using namespace ::com::sun::star;
32
33
35
36
38{
39}
40
41
42SfxPointItem::SfxPointItem( sal_uInt16 nW, const Point& rVal ) :
43 SfxPoolItem( nW ),
44 aVal( rVal )
45{
46}
47
48
50(
51 SfxItemPresentation /*ePresentation*/,
52 MapUnit /*eCoreMetric*/,
53 MapUnit /*ePresentationMetric*/,
54 OUString& rText,
55 const IntlWrapper&
56) const
57{
58 rText = OUString::number(aVal.X()) + ", " + OUString::number(aVal.Y()) + ", ";
59 return true;
60}
61
62
63bool SfxPointItem::operator==( const SfxPoolItem& rItem ) const
64{
65 assert(SfxPoolItem::operator==(rItem));
66 return static_cast<const SfxPointItem&>(rItem).aVal == aVal;
67}
68
70{
71 return new SfxPointItem( *this );
72}
73
75 sal_uInt8 nMemberId ) const
76{
77 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
78 awt::Point aTmp(aVal.X(), aVal.Y());
79 if( bConvert )
80 {
81 aTmp.X = convertTwipToMm100(aTmp.X);
82 aTmp.Y = convertTwipToMm100(aTmp.Y);
83 }
84 nMemberId &= ~CONVERT_TWIPS;
85 switch ( nMemberId )
86 {
87 case 0: rVal <<= aTmp; break;
88 case MID_X: rVal <<= aTmp.X; break;
89 case MID_Y: rVal <<= aTmp.Y; break;
90 default: OSL_FAIL("Wrong MemberId!"); return true;
91 }
92
93 return true;
94}
95
96
98 sal_uInt8 nMemberId )
99{
100 bool bConvert = 0!=(nMemberId&CONVERT_TWIPS);
101 nMemberId &= ~CONVERT_TWIPS;
102 bool bRet = false;
103 awt::Point aValue;
104 sal_Int32 nVal = 0;
105 if ( !nMemberId )
106 {
107 bRet = ( rVal >>= aValue );
108 if( bConvert )
109 {
110 aValue.X = o3tl::toTwips(aValue.X, o3tl::Length::mm100);
111 aValue.Y = o3tl::toTwips(aValue.Y, o3tl::Length::mm100);
112 }
113 }
114 else
115 {
116 bRet = ( rVal >>= nVal );
117 if( bConvert )
119 }
120
121 if ( bRet )
122 {
123 switch ( nMemberId )
124 {
125 case 0: aVal.setX( aValue.X ); aVal.setY( aValue.Y ); break;
126 case MID_X: aVal.setX( nVal ); break;
127 case MID_Y: aVal.setY( nVal ); break;
128 default: OSL_FAIL("Wrong MemberId!"); return false;
129 }
130 }
131
132 return bRet;
133}
134
135
136/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr auto convertTwipToMm100(N n)
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
constexpr tools::Long X() const
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: ptitem.cxx:97
virtual bool operator==(const SfxPoolItem &) const override
Definition: ptitem.cxx:63
virtual SfxPointItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: ptitem.cxx:69
SfxPointItem()
Definition: ptitem.cxx:37
Point aVal
Definition: ptitem.hxx:31
virtual bool GetPresentation(SfxItemPresentation ePres, MapUnit eCoreMetric, MapUnit ePresMetric, OUString &rText, const IntlWrapper &) const override
This virtual method allows to get a textual representation of the value for the SfxPoolItem subclasse...
Definition: ptitem.cxx:50
static SfxPoolItem * CreateDefault()
Definition: ptitem.cxx:34
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: ptitem.cxx:74
MapUnit
#define MID_X
Definition: memberid.h:23
#define MID_Y
Definition: memberid.h:24
constexpr auto toTwips(N number, Length from)
SfxItemPresentation
Definition: poolitem.hxx:72
#define CONVERT_TWIPS
Definition: poolitem.hxx:50
unsigned char sal_uInt8