LibreOffice Module svl (master) 1
rectitem.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/rectitem.hxx>
22#include <com/sun/star/uno/Any.hxx>
23#include <com/sun/star/awt/Rectangle.hpp>
24#include <osl/diagnose.h>
25
26#include <svl/poolitem.hxx>
27#include <svl/memberid.h>
28
29
31
32
34{
35}
36
37
39 SfxPoolItem( nW ),
40 maVal( rVal )
41{
42}
43
44
46(
47 SfxItemPresentation /*ePresentation*/,
48 MapUnit /*eCoreMetric*/,
49 MapUnit /*ePresentationMetric*/,
50 OUString& rText,
51 const IntlWrapper&
52) const
53{
54 rText = OUString::number(maVal.Top()) + ", " +
55 OUString::number(maVal.Left()) + ", " +
56 OUString::number(maVal.Bottom()) + ", " +
57 OUString::number(maVal.Right());
58 return true;
59}
60
61
62bool SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
63{
64 assert(SfxPoolItem::operator==(rItem));
65 return static_cast<const SfxRectangleItem&>(rItem).maVal == maVal;
66}
67
69{
70 return new SfxRectangleItem( *this );
71}
72
73bool SfxRectangleItem::QueryValue( css::uno::Any& rVal,
74 sal_uInt8 nMemberId) const
75{
76 nMemberId &= ~CONVERT_TWIPS;
77 switch ( nMemberId )
78 {
79 case 0:
80 {
81 rVal <<= css::awt::Rectangle( maVal.Left(),
82 maVal.Top(),
85 break;
86 }
87 case MID_RECT_LEFT: rVal <<= maVal.Left(); break;
88 case MID_RECT_RIGHT: rVal <<= maVal.Top(); break;
89 case MID_WIDTH: rVal <<= maVal.getOpenWidth(); break;
90 case MID_HEIGHT: rVal <<= maVal.getOpenHeight(); break;
91 default: OSL_FAIL("Wrong MemberID!"); return false;
92 }
93
94 return true;
95}
96
97
98bool SfxRectangleItem::PutValue( const css::uno::Any& rVal,
99 sal_uInt8 nMemberId )
100{
101 bool bRet = false;
102 nMemberId &= ~CONVERT_TWIPS;
103 css::awt::Rectangle aValue;
104 sal_Int32 nVal = 0;
105 if ( !nMemberId )
106 bRet = (rVal >>= aValue);
107 else
108 bRet = (rVal >>= nVal);
109
110 if ( bRet )
111 {
112 switch ( nMemberId )
113 {
114 case 0:
115 maVal.SetLeft( aValue.X );
116 maVal.SetTop( aValue.Y );
117 maVal.setWidth( aValue.Width );
118 maVal.setHeight( aValue.Height );
119 break;
120 case MID_RECT_LEFT: maVal.SetPosX( nVal ); break;
121 case MID_RECT_RIGHT: maVal.SetPosY( nVal ); break;
122 case MID_WIDTH: maVal.setWidth( nVal ); break;
123 case MID_HEIGHT: maVal.setHeight( nVal ); break;
124 default: OSL_FAIL("Wrong MemberID!"); return false;
125 }
126 }
127
128 return bRet;
129}
130
131
132/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Base class for providers of defaults of SfxPoolItems.
Definition: itempool.hxx:51
virtual bool operator==(const SfxPoolItem &) const override
Definition: rectitem.cxx:62
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt8 nMemberId=0) const override
Definition: rectitem.cxx:73
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt8 nMemberId) override
Definition: rectitem.cxx:98
static SfxPoolItem * CreateDefault()
Definition: rectitem.cxx:30
tools::Rectangle maVal
Definition: rectitem.hxx:30
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: rectitem.cxx:46
virtual SfxRectangleItem * Clone(SfxItemPool *pPool=nullptr) const override
Definition: rectitem.cxx:68
constexpr void SetLeft(tools::Long v)
constexpr void SetTop(tools::Long v)
constexpr tools::Long Top() const
tools::Long getOpenHeight() const
void SetPosY(tools::Long y)
void setWidth(tools::Long n)
constexpr tools::Long Right() const
void setHeight(tools::Long n)
tools::Long getOpenWidth() const
constexpr tools::Long Left() const
constexpr tools::Long Bottom() const
void SetPosX(tools::Long x)
MapUnit
#define MID_RECT_RIGHT
Definition: memberid.h:29
#define MID_HEIGHT
Definition: memberid.h:28
#define MID_WIDTH
Definition: memberid.h:27
#define MID_RECT_LEFT
Definition: memberid.h:25
SfxItemPresentation
Definition: poolitem.hxx:72
unsigned char sal_uInt8