xref: /trunk/main/svx/source/unodraw/tableshape.cxx (revision f6e50924)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_svx.hxx"
26 
27 #include "shapeimpl.hxx"
28 #include "svx/unoshprp.hxx"
29 #include "svx/svdotable.hxx"
30 #include <svx/svdpool.hxx>
31 
32 ///////////////////////////////////////////////////////////////////////
33 
34 using ::rtl::OUString;
35 
36 using namespace ::osl;
37 using namespace ::cppu;
38 using namespace ::sdr::table;
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::lang;
42 using namespace ::com::sun::star::container;
43 using namespace ::com::sun::star::beans;
44 
SvxTableShape(SdrObject * pObj)45 SvxTableShape::SvxTableShape( SdrObject* pObj ) throw()
46 :	SvxShape( pObj, aSvxMapProvider.GetMap(SVXMAP_TABLE), aSvxMapProvider.GetPropertySet(SVXMAP_TABLE, SdrObject::GetGlobalDrawObjectItemPool()) )
47 {
48 	SetShapeType( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.drawing.TableShape" ) ) );
49 }
50 
51 //----------------------------------------------------------------------
~SvxTableShape()52 SvxTableShape::~SvxTableShape() throw()
53 {
54 }
55 
56 //----------------------------------------------------------------------
57 
setPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,const::com::sun::star::uno::Any & rValue)58 bool SvxTableShape::setPropertyValueImpl(
59     const ::rtl::OUString& rName,
60     const SfxItemPropertySimpleEntry* pProperty,
61     const ::com::sun::star::uno::Any& rValue )
62         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
63 {
64 	switch( pProperty->nWID )
65 	{
66 	case OWN_ATTR_TABLETEMPLATE:
67 	{
68 		Reference< XIndexAccess > xTemplate;
69 
70 		if( !(rValue >>= xTemplate) )
71 			throw IllegalArgumentException();
72 
73 		if( mpObj.is() )
74 			static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->setTableStyle(xTemplate);
75 
76 		return true;
77 	}
78 	case OWN_ATTR_TABLETEMPLATE_FIRSTROW:
79 	case OWN_ATTR_TABLETEMPLATE_LASTROW:
80 	case OWN_ATTR_TABLETEMPLATE_FIRSTCOLUMN:
81 	case OWN_ATTR_TABLETEMPLATE_LASTCOLUMN:
82 	case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:
83 	case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:
84 	{
85 		if( mpObj.is() )
86 		{
87 			TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyleSettings() );
88 
89 			switch( pProperty->nWID )
90 			{
91 			case OWN_ATTR_TABLETEMPLATE_FIRSTROW:			rValue >>= aSettings.mbUseFirstRow; break;
92 			case OWN_ATTR_TABLETEMPLATE_LASTROW:			rValue >>= aSettings.mbUseLastRow; break;
93 			case OWN_ATTR_TABLETEMPLATE_FIRSTCOLUMN:		rValue >>= aSettings.mbUseFirstColumn; break;
94 			case OWN_ATTR_TABLETEMPLATE_LASTCOLUMN:			rValue >>= aSettings.mbUseLastColumn; break;
95 			case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:		rValue >>= aSettings.mbUseRowBanding; break;
96 			case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:	rValue >>= aSettings.mbUseColumnBanding; break;
97 			}
98 
99 			static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->setTableStyleSettings(aSettings);
100 		}
101 
102 		return true;
103 	}
104 	default:
105 	{
106         return SvxShape::setPropertyValueImpl( rName, pProperty, rValue );
107 	}
108 	}
109 }
110 
111 extern Graphic SvxGetGraphicForShape( SdrObject& rShape, bool bVector );
112 
getPropertyValueImpl(const::rtl::OUString & rName,const SfxItemPropertySimpleEntry * pProperty,::com::sun::star::uno::Any & rValue)113 bool SvxTableShape::getPropertyValueImpl(
114     const ::rtl::OUString& rName,
115     const SfxItemPropertySimpleEntry* pProperty,
116     ::com::sun::star::uno::Any& rValue )
117         throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException)
118 {
119 	switch( pProperty->nWID )
120 	{
121 	case OWN_ATTR_OLEMODEL:
122 	{
123 		if( mpObj.is() )
124 		{
125 			rValue <<= static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTable();
126 		}
127 		return true;
128 	}
129 	case OWN_ATTR_TABLETEMPLATE:
130 	{
131 		if( mpObj.is() )
132 		{
133 			rValue <<= static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyle();
134 		}
135 		return true;
136 	}
137 	case OWN_ATTR_BITMAP:
138 	{
139 		if( mpObj.is() )
140 		{
141 			Graphic aGraphic( SvxGetGraphicForShape( *mpObj.get(), true ) );
142 			rValue <<= aGraphic.GetXGraphic();
143 		}
144 		return true;
145 	}
146 	case OWN_ATTR_TABLETEMPLATE_FIRSTROW:
147 	case OWN_ATTR_TABLETEMPLATE_LASTROW:
148 	case OWN_ATTR_TABLETEMPLATE_FIRSTCOLUMN:
149 	case OWN_ATTR_TABLETEMPLATE_LASTCOLUMN:
150 	case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:
151 	case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:
152 	{
153 		if( mpObj.is() )
154 		{
155 			TableStyleSettings aSettings( static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->getTableStyleSettings() );
156 
157 			switch( pProperty->nWID )
158 			{
159 			case OWN_ATTR_TABLETEMPLATE_FIRSTROW:			rValue <<= aSettings.mbUseFirstRow; break;
160 			case OWN_ATTR_TABLETEMPLATE_LASTROW:			rValue <<= aSettings.mbUseLastRow; break;
161 			case OWN_ATTR_TABLETEMPLATE_FIRSTCOLUMN:		rValue <<= aSettings.mbUseFirstColumn; break;
162 			case OWN_ATTR_TABLETEMPLATE_LASTCOLUMN:			rValue <<= aSettings.mbUseLastColumn; break;
163 			case OWN_ATTR_TABLETEMPLATE_BANDINGROWS:		rValue <<= aSettings.mbUseRowBanding; break;
164 			case OWN_ATTR_TABLETEMPLATE_BANDINGCOULUMNS:	rValue <<= aSettings.mbUseColumnBanding; break;
165 			}
166 		}
167 
168 		return true;
169 	}
170 	default:
171 	{
172         return SvxShape::getPropertyValueImpl( rName, pProperty, rValue );
173 	}
174 	}
175 }
176 
lock()177 void SvxTableShape::lock()
178 {
179 	SvxShape::lock();
180 	if( mpObj.is() )
181 		static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->uno_lock();
182 }
183 
unlock()184 void SvxTableShape::unlock()
185 {
186 	if( mpObj.is() )
187 		static_cast< sdr::table::SdrTableObj* >( mpObj.get() )->uno_unlock();
188 	SvxShape::unlock();
189 }
190 
191