LibreOffice Module svx (master)  1
tablecolumn.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 <com/sun/star/lang/DisposedException.hpp>
22 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
23 
24 #include <tablemodel.hxx>
25 #include "tablecolumn.hxx"
26 #include "tableundo.hxx"
27 #include <svx/svdmodel.hxx>
28 #include <svx/svdotable.hxx>
29 
30 
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star::lang;
33 using namespace ::com::sun::star::container;
34 using namespace ::com::sun::star::table;
35 using namespace ::com::sun::star::beans;
36 
37 
38 namespace sdr::table {
39 
40 const sal_Int32 Property_Width = 0;
41 const sal_Int32 Property_OptimalWidth = 1;
42 const sal_Int32 Property_IsVisible = 2;
43 const sal_Int32 Property_IsStartOfNewPage = 3;
44 
45 
46 // TableRow
47 
48 
49 TableColumn::TableColumn( const TableModelRef& xTableModel, sal_Int32 nColumn )
50 : TableColumnBase( getStaticPropertySetInfo() )
51 , mxTableModel( xTableModel )
52 , mnColumn( nColumn )
53 , mnWidth( 0 )
54 , mbOptimalWidth( true )
55 , mbIsVisible( true )
56 , mbIsStartOfNewPage( false )
57 {
58 }
59 
60 
62 {
63 }
64 
65 
67 {
68  mxTableModel.clear();
69 }
70 
71 
73 {
74  if( !mxTableModel.is() )
75  throw DisposedException();
76 }
77 
78 
80 {
81  mnWidth = r.mnWidth;
85  maName = r.maName;
86  mnColumn = r.mnColumn;
87 
88  return *this;
89 }
90 
91 
92 // XCellRange
93 
94 
95 Reference< XCell > SAL_CALL TableColumn::getCellByPosition( sal_Int32 nColumn, sal_Int32 nRow )
96 {
98  if( nColumn != 0 )
99  throw IndexOutOfBoundsException();
100 
101  return mxTableModel->getCellByPosition( mnColumn, nRow );
102 }
103 
104 
105 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByPosition( sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom )
106 {
107  throwIfDisposed();
108  if( (nTop >= 0 ) && (nLeft == 0) && (nBottom >= nTop) && (nRight == 0) )
109  {
110  return mxTableModel->getCellRangeByPosition( mnColumn, nTop, mnColumn, nBottom );
111  }
112  throw IndexOutOfBoundsException();
113 }
114 
115 
116 Reference< XCellRange > SAL_CALL TableColumn::getCellRangeByName( const OUString& /*aRange*/ )
117 {
118  return Reference< XCellRange >();
119 }
120 
121 
122 // XNamed
123 
124 
125 OUString SAL_CALL TableColumn::getName()
126 {
127  return maName;
128 }
129 
130 
131 void SAL_CALL TableColumn::setName( const OUString& aName )
132 {
133  maName = aName;
134 }
135 
136 
137 // XFastPropertySet
138 
139 
140 void SAL_CALL TableColumn::setFastPropertyValue( sal_Int32 nHandle, const Any& aValue )
141 {
142  bool bOk = false;
143  bool bChange = false;
144 
145  SdrModel& rModel(mxTableModel->getSdrTableObj()->getSdrModelFromSdrObject());
146  std::unique_ptr<TableColumnUndo> pUndo;
147 
148  if( mxTableModel.is() && mxTableModel->getSdrTableObj() && mxTableModel->getSdrTableObj()->IsInserted() && rModel.IsUndoEnabled() )
149  {
150  TableColumnRef xThis( this );
151  pUndo.reset( new TableColumnUndo( xThis ) );
152  }
153 
154  switch( nHandle )
155  {
156  case Property_Width:
157  {
158  sal_Int32 nWidth = mnWidth;
159  bOk = aValue >>= nWidth;
160  if( bOk && (nWidth != mnWidth) )
161  {
162  mnWidth = nWidth;
163  mbOptimalWidth = mnWidth == 0;
164  bChange = true;
165  }
166  break;
167  }
168  case Property_OptimalWidth:
169  {
170  bool bOptimalWidth = mbOptimalWidth;
171  bOk = aValue >>= bOptimalWidth;
172  if( bOk && (mbOptimalWidth != bOptimalWidth) )
173  {
174  mbOptimalWidth = bOptimalWidth;
175  if( bOptimalWidth )
176  mnWidth = 0;
177  bChange = true;
178  }
179  break;
180  }
181  case Property_IsVisible:
182  {
183  bool bIsVisible = mbIsVisible;
184  bOk = aValue >>= bIsVisible;
185  if( bOk && (mbIsVisible != bIsVisible) )
186  {
187  mbIsVisible = bIsVisible;
188  bChange = true;
189  }
190  break;
191  }
192 
193  case Property_IsStartOfNewPage:
194  {
195  bool bIsStartOfNewPage = mbIsStartOfNewPage;
196  bOk = aValue >>= bIsStartOfNewPage;
197  if( bOk && (mbIsStartOfNewPage != bIsStartOfNewPage) )
198  {
199  mbIsStartOfNewPage = bIsStartOfNewPage;
200  bChange = true;
201  }
202  break;
203  }
204  default:
205  throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
206  }
207  if( !bOk )
208  {
209  throw IllegalArgumentException();
210  }
211 
212  if( bChange )
213  {
214  if( pUndo )
215  {
216  rModel.AddUndo( std::move(pUndo) );
217  }
218  mxTableModel->setModified(true);
219  }
220 }
221 
222 
223 Any SAL_CALL TableColumn::getFastPropertyValue( sal_Int32 nHandle )
224 {
225  switch( nHandle )
226  {
227  case Property_Width: return Any( mnWidth );
228  case Property_OptimalWidth: return Any( mbOptimalWidth );
229  case Property_IsVisible: return Any( mbIsVisible );
230  case Property_IsStartOfNewPage: return Any( mbIsStartOfNewPage );
231  default: throw UnknownPropertyException( OUString::number(nHandle), static_cast<cppu::OWeakObject*>(this));
232  }
233 }
234 
235 
237 {
238  static rtl::Reference<FastPropertySetInfo> xInfo = []() {
240 
241  aProperties[0].Name = "Width";
242  aProperties[0].Handle = Property_Width;
243  aProperties[0].Type = ::cppu::UnoType<sal_Int32>::get();
244  aProperties[0].Attributes = 0;
245 
246  aProperties[1].Name = "OptimalWidth";
247  aProperties[1].Handle = Property_OptimalWidth;
248  aProperties[1].Type = cppu::UnoType<bool>::get();
249  aProperties[1].Attributes = 0;
250 
251  aProperties[2].Name = "IsVisible";
252  aProperties[2].Handle = Property_IsVisible;
253  aProperties[2].Type = cppu::UnoType<bool>::get();
254  aProperties[2].Attributes = 0;
255 
256  aProperties[3].Name = "IsStartOfNewPage";
257  aProperties[3].Handle = Property_IsStartOfNewPage;
258  aProperties[3].Type = cppu::UnoType<bool>::get();
259  aProperties[3].Attributes = 0;
260 
261  aProperties[4].Name = "Size";
262  aProperties[4].Handle = Property_Width;
263  aProperties[4].Type = ::cppu::UnoType<sal_Int32>::get();
264  aProperties[4].Attributes = 0;
265 
266  aProperties[5].Name = "OptimalSize";
267  aProperties[5].Handle = Property_OptimalWidth;
268  aProperties[5].Type = cppu::UnoType<bool>::get();
269  aProperties[5].Attributes = 0;
270 
272  }();
273 
274  return xInfo;
275 }
276 
278 {
279  return mxTableModel;
280 }
281 
282 sal_Int32 TableColumn::getWidth() const
283 {
284  return mnWidth;
285 }
286 
287 }
288 
289 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL setFastPropertyValue(::sal_Int32 nHandle, const css::uno::Any &aValue) override
const sal_Int32 Property_OptimalWidth
Definition: tablecolumn.cxx:41
std::vector< css::beans::Property > PropertyVector
Definition: propertyset.hxx:35
const sal_Int32 Property_IsStartOfNewPage
Definition: tablecolumn.cxx:43
void throwIfDisposed() const
Definition: tablecolumn.cxx:72
TableColumn & operator=(const TableColumn &)
Definition: tablecolumn.cxx:79
virtual css::uno::Any SAL_CALL getFastPropertyValue(::sal_Int32 nHandle) override
static rtl::Reference< FastPropertySetInfo > getStaticPropertySetInfo()
const sal_Int32 Property_IsVisible
Definition: tablecolumn.cxx:42
virtual ~TableColumn() override
Definition: tablecolumn.cxx:61
PropertiesInfo aProperties
const sal_Int32 Property_Width
Definition: tablecolumn.cxx:40
virtual OUString SAL_CALL getName() override
::cppu::ImplInheritanceHelper< FastPropertySet, css::table::XCellRange, css::container::XNamed > TableColumnBase
Definition: tablecolumn.hxx:33
sal_Int32 getWidth() const
Get the width of this column.
virtual void SAL_CALL setName(const OUString &aName) override
css::uno::Type const & get()
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByName(const OUString &aRange) override
TableColumn(const TableModelRef &xTableModel, sal_Int32 nColumn)
Definition: tablecolumn.cxx:49
virtual css::uno::Reference< css::table::XCell > SAL_CALL getCellByPosition(sal_Int32 nColumn, sal_Int32 nRow) override
Definition: tablecolumn.cxx:95
double mnWidth
virtual css::uno::Reference< css::table::XCellRange > SAL_CALL getCellRangeByPosition(sal_Int32 nLeft, sal_Int32 nTop, sal_Int32 nRight, sal_Int32 nBottom) override
TableModelRef const & getModel() const
Get the table that owns this column.
TableModelRef mxTableModel
Definition: tablecolumn.hxx:70
friend class TableColumnUndo
Definition: tablecolumn.hxx:37