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 
CreateDefault()30 SfxPoolItem* SfxRectangleItem::CreateDefault() { return new SfxRectangleItem; }
31 
32 
SfxRectangleItem()33 SfxRectangleItem::SfxRectangleItem()
34 {
35 }
36 
37 
SfxRectangleItem(sal_uInt16 nW,const tools::Rectangle & rVal)38 SfxRectangleItem::SfxRectangleItem( sal_uInt16 nW, const tools::Rectangle& rVal ) :
39     SfxPoolItem( nW ),
40     aVal( rVal )
41 {
42 }
43 
44 
GetPresentation(SfxItemPresentation,MapUnit,MapUnit,OUString & rText,const IntlWrapper &) const45 bool SfxRectangleItem::GetPresentation
46 (
47     SfxItemPresentation     /*ePresentation*/,
48     MapUnit                 /*eCoreMetric*/,
49     MapUnit                 /*ePresentationMetric*/,
50     OUString&               rText,
51     const IntlWrapper&
52 )   const
53 {
54     rText = OUString::number(aVal.Top())    + ", " +
55             OUString::number(aVal.Left())   + ", " +
56             OUString::number(aVal.Bottom()) + ", " +
57             OUString::number(aVal.Right());
58     return true;
59 }
60 
61 
operator ==(const SfxPoolItem & rItem) const62 bool SfxRectangleItem::operator==( const SfxPoolItem& rItem ) const
63 {
64     assert(SfxPoolItem::operator==(rItem));
65     return static_cast<const SfxRectangleItem&>(rItem).aVal == aVal;
66 }
67 
Clone(SfxItemPool *) const68 SfxRectangleItem* SfxRectangleItem::Clone(SfxItemPool *) const
69 {
70     return new SfxRectangleItem( *this );
71 }
72 
QueryValue(css::uno::Any & rVal,sal_uInt8 nMemberId) const73 bool 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( aVal.getX(),
82                                              aVal.getY(),
83                                              aVal.getWidth(),
84                                              aVal.getHeight() );
85             break;
86         }
87         case MID_RECT_LEFT:  rVal <<= aVal.getX(); break;
88         case MID_RECT_RIGHT: rVal <<= aVal.getY(); break;
89         case MID_WIDTH: rVal <<= aVal.getWidth(); break;
90         case MID_HEIGHT: rVal <<= aVal.getHeight(); break;
91         default: OSL_FAIL("Wrong MemberID!"); return false;
92     }
93 
94     return true;
95 }
96 
97 
PutValue(const css::uno::Any & rVal,sal_uInt8 nMemberId)98 bool 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                 aVal.setX( aValue.X );
116                 aVal.setY( aValue.Y );
117                 aVal.setWidth( aValue.Width );
118                 aVal.setHeight( aValue.Height );
119                 break;
120             case MID_RECT_LEFT:  aVal.setX( nVal ); break;
121             case MID_RECT_RIGHT: aVal.setY( nVal ); break;
122             case MID_WIDTH: aVal.setWidth( nVal ); break;
123             case MID_HEIGHT: aVal.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: */
133