Line data Source code
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 : #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
21 : #include <com/sun/star/container/XNamed.hpp>
22 : #include <com/sun/star/container/XNameAccess.hpp>
23 : #include <com/sun/star/container/XIndexAccess.hpp>
24 :
25 : #include <vcl/canvastools.hxx>
26 : #include <com/sun/star/style/XStyle.hpp>
27 : #include <com/sun/star/beans/XPropertySet.hpp>
28 : #include <basegfx/polygon/b2dpolygontools.hxx>
29 : #include <basegfx/polygon/b2dpolypolygon.hxx>
30 : #include <basegfx/polygon/b2dpolygon.hxx>
31 : #include <svl/style.hxx>
32 : #include "editeng/editstat.hxx"
33 : #include "editeng/outlobj.hxx"
34 : #include "svx/svdview.hxx"
35 : #include "svx/sdr/properties/textproperties.hxx"
36 : #include "svx/svdotable.hxx"
37 : #include "svx/svdhdl.hxx"
38 : #include "viewcontactoftableobj.hxx"
39 : #include "svx/svdoutl.hxx"
40 : #include "svx/svddrag.hxx"
41 : #include "svx/svdpagv.hxx"
42 : #include "tablemodel.hxx"
43 : #include "cell.hxx"
44 : #include "svx/xflclit.hxx"
45 : #include "tablelayouter.hxx"
46 : #include "svx/svdetc.hxx"
47 : #include "tablehandles.hxx"
48 : #include "editeng/boxitem.hxx"
49 : #include "svx/framelink.hxx"
50 : #include "svx/sdr/table/tabledesign.hxx"
51 : #include "svx/svdundo.hxx"
52 : #include "svx/svdstr.hrc"
53 : #include "svx/svdglob.hxx"
54 : #include "editeng/writingmodeitem.hxx"
55 : #include "editeng/frmdiritem.hxx"
56 : #include "svx/xflhtit.hxx"
57 : #include "svx/xflftrit.hxx"
58 : #include "svx/xfltrit.hxx"
59 :
60 : // -----------------------------------------------------------------------------
61 :
62 : using ::com::sun::star::uno::Any;
63 : using ::com::sun::star::uno::Reference;
64 : using ::com::sun::star::uno::XInterface;
65 : using ::com::sun::star::uno::UNO_QUERY;
66 : using ::com::sun::star::uno::UNO_QUERY_THROW;
67 : using ::com::sun::star::uno::Exception;
68 : using ::com::sun::star::container::XIndexAccess;
69 : using ::com::sun::star::style::XStyle;
70 : using ::com::sun::star::table::XTableRows;
71 : using ::com::sun::star::table::XTableColumns;
72 : using ::com::sun::star::table::XTable;
73 : using ::com::sun::star::beans::XPropertySet;
74 : using ::com::sun::star::util::XModifyBroadcaster;
75 : using sdr::properties::TextProperties;
76 : using sdr::properties::BaseProperties;
77 : using namespace ::com::sun::star::text;
78 : using namespace ::com::sun::star::container;
79 : using namespace ::com::sun::star::style;
80 :
81 : namespace sdr { namespace table {
82 :
83 : class TableProperties : public TextProperties
84 : {
85 : protected:
86 : // create a new itemset
87 : SfxItemSet& CreateObjectSpecificItemSet(SfxItemPool& rPool);
88 :
89 : public:
90 : // basic constructor
91 : TableProperties(SdrObject& rObj );
92 :
93 : // constructor for copying, but using new object
94 : TableProperties(const TableProperties& rProps, SdrObject& rObj );
95 :
96 : // destructor
97 : ~TableProperties();
98 :
99 : // Clone() operator, normally just calls the local copy constructor
100 : BaseProperties& Clone(SdrObject& rObj) const;
101 :
102 : virtual void ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem);
103 : };
104 :
105 35 : TableProperties::TableProperties(SdrObject& rObj)
106 35 : : TextProperties(rObj)
107 : {
108 35 : }
109 :
110 0 : TableProperties::TableProperties(const TableProperties& rProps, SdrObject& rObj)
111 0 : : TextProperties(rProps, rObj)
112 : {
113 0 : }
114 :
115 70 : TableProperties::~TableProperties()
116 : {
117 70 : }
118 :
119 0 : BaseProperties& TableProperties::Clone(SdrObject& rObj) const
120 : {
121 0 : return *(new TableProperties(*this, rObj));
122 : }
123 :
124 22 : void TableProperties::ItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem)
125 : {
126 22 : if( nWhich == SDRATTR_TEXTDIRECTION )
127 20 : AttributeProperties::ItemChange( nWhich, pNewItem );
128 : else
129 2 : TextProperties::ItemChange( nWhich, pNewItem );
130 22 : }
131 :
132 : // create a new itemset
133 35 : SfxItemSet& TableProperties::CreateObjectSpecificItemSet(SfxItemPool& rPool)
134 : {
135 : return *(new SfxItemSet(rPool,
136 :
137 : // range from SdrAttrObj
138 : SDRATTR_START, SDRATTR_SHADOW_LAST,
139 : SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
140 : SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
141 :
142 : // range for SdrTableObj
143 : SDRATTR_TABLE_FIRST, SDRATTR_TABLE_LAST,
144 :
145 : // range from SdrTextObj
146 : EE_ITEMS_START, EE_ITEMS_END,
147 :
148 : // end
149 35 : 0, 0));
150 : }
151 :
152 0 : class TableObjectGeoData : public SdrTextObjGeoData
153 : {
154 : public:
155 : Rectangle maLogicRect;
156 : };
157 :
158 : //------------------------------------------------------------------------
159 : // TableStyleSettings
160 : //------------------------------------------------------------------------
161 :
162 35 : TableStyleSettings::TableStyleSettings()
163 : : mbUseFirstRow(true)
164 : , mbUseLastRow(false)
165 : , mbUseFirstColumn(false)
166 : , mbUseLastColumn(false)
167 : , mbUseRowBanding(true)
168 35 : , mbUseColumnBanding(false)
169 : {
170 35 : }
171 :
172 12 : TableStyleSettings::TableStyleSettings( const TableStyleSettings& rStyle )
173 : {
174 12 : (*this) = rStyle;
175 12 : }
176 :
177 24 : TableStyleSettings& TableStyleSettings::operator=(const TableStyleSettings& rStyle)
178 : {
179 24 : mbUseFirstRow = rStyle.mbUseFirstRow;
180 24 : mbUseLastRow = rStyle.mbUseLastRow;
181 24 : mbUseFirstColumn = rStyle.mbUseFirstColumn;
182 24 : mbUseLastColumn = rStyle.mbUseLastColumn;
183 24 : mbUseRowBanding = rStyle.mbUseRowBanding;
184 24 : mbUseColumnBanding = rStyle.mbUseColumnBanding;
185 24 : return *this;
186 : }
187 :
188 0 : bool TableStyleSettings::operator==( const TableStyleSettings& rStyle ) const
189 : {
190 : return
191 0 : (mbUseFirstRow == rStyle.mbUseFirstRow) &&
192 0 : (mbUseLastRow == rStyle.mbUseLastRow) &&
193 0 : (mbUseFirstColumn == rStyle.mbUseFirstColumn) &&
194 0 : (mbUseLastColumn == rStyle.mbUseLastColumn) &&
195 0 : (mbUseRowBanding == rStyle.mbUseRowBanding) &&
196 0 : (mbUseColumnBanding == rStyle.mbUseColumnBanding);
197 : }
198 :
199 : // -----------------------------------------------------------------------------
200 :
201 : class SdrTableObjImpl : public TableDesignUser, public ::cppu::WeakImplHelper1< ::com::sun::star::util::XModifyListener >
202 : {
203 : public:
204 : CellRef mxActiveCell;
205 : TableModelRef mxTable;
206 : SdrTableObj* mpTableObj;
207 : TableLayouter* mpLayouter;
208 : CellPos maEditPos;
209 : TableStyleSettings maTableStyle;
210 : Reference< XIndexAccess > mxTableStyle;
211 : bool mbModifyPending;
212 :
213 : void SetModel(SdrModel* pOldModel, SdrModel* pNewModel);
214 :
215 : CellRef getCell( const CellPos& rPos ) const;
216 : void LayoutTable( Rectangle& rArea, bool bFitWidth, bool bFitHeight );
217 :
218 : bool ApplyCellStyles();
219 : void UpdateCells( Rectangle& rArea );
220 :
221 : SdrTableObjImpl();
222 : virtual ~SdrTableObjImpl();
223 :
224 : void init( SdrTableObj* pTable, sal_Int32 nColumns, sal_Int32 nRows );
225 : void dispose();
226 :
227 : sal_Int32 getColumnCount() const;
228 : sal_Int32 getRowCount() const;
229 :
230 : void DragEdge( bool mbHorizontal, int nEdge, sal_Int32 nOffset );
231 :
232 : SdrTableObjImpl& operator=( const SdrTableObjImpl& rSource );
233 :
234 : // XModifyListener
235 : virtual void SAL_CALL modified( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
236 :
237 : // XEventListener
238 : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
239 :
240 : void update();
241 :
242 : void connectTableStyle();
243 : void disconnectTableStyle();
244 : virtual bool isInUse();
245 : };
246 :
247 : // -----------------------------------------------------------------------------
248 :
249 35 : SdrTableObjImpl::SdrTableObjImpl()
250 : : mpTableObj( 0 )
251 : , mpLayouter( 0 )
252 35 : , mbModifyPending( false )
253 : {
254 35 : }
255 :
256 : // -----------------------------------------------------------------------------
257 :
258 70 : SdrTableObjImpl::~SdrTableObjImpl()
259 : {
260 70 : }
261 :
262 : // -----------------------------------------------------------------------------
263 :
264 35 : void SdrTableObjImpl::init( SdrTableObj* pTable, sal_Int32 nColumns, sal_Int32 nRows )
265 : {
266 35 : mpTableObj = pTable;
267 35 : mxTable = new TableModel( pTable );
268 35 : mxTable->init( nColumns, nRows );
269 35 : mpLayouter = new TableLayouter( mxTable );
270 35 : Reference< XModifyListener > xListener( static_cast< ::com::sun::star::util::XModifyListener* >(this) );
271 35 : mxTable->addModifyListener( xListener );
272 35 : LayoutTable( mpTableObj->aRect, true, true );
273 35 : mpTableObj->maLogicRect = mpTableObj->aRect;
274 35 : }
275 :
276 : // -----------------------------------------------------------------------------
277 :
278 0 : SdrTableObjImpl& SdrTableObjImpl::operator=( const SdrTableObjImpl& rSource )
279 : {
280 0 : if (this != &rSource)
281 : {
282 0 : if( mpLayouter )
283 : {
284 0 : delete mpLayouter;
285 0 : mpLayouter = 0;
286 : }
287 :
288 0 : if( mxTable.is() )
289 : {
290 0 : Reference< XModifyListener > xListener( static_cast< ::com::sun::star::util::XModifyListener* >(this) );
291 0 : mxTable->removeModifyListener( xListener );
292 0 : mxTable->dispose();
293 0 : mxTable.clear();
294 : }
295 :
296 0 : maTableStyle = rSource.maTableStyle;
297 :
298 0 : mxTable = new TableModel( mpTableObj, rSource.mxTable );
299 0 : mpLayouter = new TableLayouter( mxTable );
300 0 : Reference< XModifyListener > xListener( static_cast< ::com::sun::star::util::XModifyListener* >(this) );
301 0 : mxTable->addModifyListener( xListener );
302 0 : mxTableStyle = rSource.mxTableStyle;
303 0 : ApplyCellStyles();
304 0 : mpTableObj->aRect = mpTableObj->maLogicRect;
305 0 : LayoutTable( mpTableObj->aRect, false, false );
306 : }
307 0 : return *this;
308 : }
309 :
310 : // -----------------------------------------------------------------------------
311 :
312 0 : void SdrTableObjImpl::SetModel(SdrModel* /*pOldModel*/, SdrModel* pNewModel)
313 : {
314 : // try to find new table style
315 0 : disconnectTableStyle();
316 :
317 0 : Reference< XIndexAccess > xNewTableStyle;
318 0 : if( mxTableStyle.is() ) try
319 : {
320 0 : const OUString sStyleName( Reference< XNamed >( mxTableStyle, UNO_QUERY_THROW )->getName() );
321 :
322 0 : Reference< XStyleFamiliesSupplier > xSFS( pNewModel->getUnoModel(), UNO_QUERY_THROW );
323 0 : Reference< XNameAccess > xFamilyNameAccess( xSFS->getStyleFamilies(), UNO_QUERY_THROW );
324 0 : const OUString sFamilyName( "table" );
325 0 : Reference< XNameAccess > xTableFamilyAccess( xFamilyNameAccess->getByName( sFamilyName ), UNO_QUERY_THROW );
326 :
327 0 : if( xTableFamilyAccess->hasByName( sStyleName ) )
328 : {
329 : // found table style with the same name
330 0 : xTableFamilyAccess->getByName( sStyleName ) >>= xNewTableStyle;
331 : }
332 : else
333 : {
334 : // copy or?
335 0 : Reference< XIndexAccess > xIndexAccess( xTableFamilyAccess, UNO_QUERY_THROW );
336 0 : xIndexAccess->getByIndex( 0 ) >>= xNewTableStyle;
337 0 : }
338 : }
339 0 : catch( Exception& )
340 : {
341 : OSL_FAIL("svx::SdrTableObjImpl::SetModel(), exception caught!");
342 : }
343 :
344 0 : mxTableStyle = xNewTableStyle;
345 :
346 0 : connectTableStyle();
347 0 : update();
348 0 : }
349 :
350 : // -----------------------------------------------------------------------------
351 :
352 108 : bool SdrTableObjImpl::ApplyCellStyles()
353 : {
354 108 : if( !mxTable.is() || !mxTable.is() || !mxTableStyle.is() )
355 90 : return false;
356 :
357 18 : bool bChanges = false;
358 :
359 18 : const sal_Int32 nColCount = getColumnCount();
360 18 : const sal_Int32 nRowCount = getRowCount();
361 :
362 18 : const TableStyleSettings& rStyle = maTableStyle;
363 :
364 18 : CellPos aPos;
365 52 : for( aPos.mnRow = 0; aPos.mnRow < nRowCount; ++aPos.mnRow )
366 : {
367 34 : const bool bFirstRow = (aPos.mnRow == 0) && rStyle.mbUseFirstRow;
368 34 : const bool bLastRow = (aPos.mnRow == nRowCount-1) && rStyle.mbUseLastRow;
369 :
370 80 : for( aPos.mnCol = 0; aPos.mnCol < nColCount; ++aPos.mnCol )
371 : {
372 46 : Reference< XStyle > xStyle;
373 :
374 : // first and last row win first, if used and available
375 46 : if( bFirstRow )
376 : {
377 30 : mxTableStyle->getByIndex(first_row_style) >>= xStyle;
378 : }
379 16 : else if( bLastRow )
380 : {
381 0 : mxTableStyle->getByIndex(last_row_style) >>= xStyle;
382 : }
383 :
384 46 : if( !xStyle.is() )
385 : {
386 : // next come first and last column, if used and available
387 16 : if( rStyle.mbUseFirstColumn && (aPos.mnCol == 0) )
388 : {
389 0 : mxTableStyle->getByIndex(first_column_style) >>= xStyle;
390 : }
391 16 : else if( rStyle.mbUseLastColumn && (aPos.mnCol == nColCount-1) )
392 : {
393 0 : mxTableStyle->getByIndex(last_column_style) >>= xStyle;
394 : }
395 : }
396 :
397 46 : if( !xStyle.is() && rStyle.mbUseRowBanding )
398 : {
399 16 : if( (aPos.mnRow & 1) == 0 )
400 : {
401 8 : mxTableStyle->getByIndex(even_rows_style) >>= xStyle;
402 : }
403 : else
404 : {
405 8 : mxTableStyle->getByIndex(odd_rows_style) >>= xStyle;
406 : }
407 : }
408 :
409 46 : if( !xStyle.is() && rStyle.mbUseColumnBanding )
410 : {
411 0 : if( (aPos.mnCol & 1) == 0 )
412 : {
413 0 : mxTableStyle->getByIndex(even_columns_style) >>= xStyle;
414 : }
415 : else
416 : {
417 0 : mxTableStyle->getByIndex(odd_columns_style) >>= xStyle;
418 : }
419 : }
420 :
421 46 : if( !xStyle.is() )
422 : {
423 : // use default cell style if non found yet
424 8 : mxTableStyle->getByIndex(body_style) >>= xStyle;
425 : }
426 :
427 :
428 46 : if( xStyle.is() )
429 : {
430 46 : SfxUnoStyleSheet* pStyle = SfxUnoStyleSheet::getUnoStyleSheet(xStyle);
431 :
432 46 : if( pStyle )
433 : {
434 46 : CellRef xCell( getCell( aPos ) );
435 46 : if( xCell.is() && ( xCell->GetStyleSheet() != pStyle ) )
436 : {
437 16 : bChanges = true;
438 16 : xCell->SetStyleSheet( pStyle, sal_True );
439 46 : }
440 : }
441 : }
442 46 : }
443 : }
444 :
445 18 : return bChanges;
446 : }
447 :
448 : // -----------------------------------------------------------------------------
449 :
450 35 : void SdrTableObjImpl::dispose()
451 : {
452 35 : if( mxTable.is() )
453 35 : mxTable->dispose();
454 35 : }
455 :
456 : // -----------------------------------------------------------------------------
457 :
458 0 : void SdrTableObjImpl::DragEdge( bool mbHorizontal, int nEdge, sal_Int32 nOffset )
459 : {
460 0 : if( (nEdge >= 0) && mxTable.is()) try
461 : {
462 0 : const OUString sSize( "Size" );
463 0 : if( mbHorizontal )
464 : {
465 0 : if( (nEdge >= 0) && (nEdge <= getRowCount()) )
466 : {
467 0 : sal_Int32 nHeigth = mpLayouter->getRowHeight( (!nEdge)?nEdge:(nEdge-1) );
468 0 : if(nEdge==0)
469 0 : nHeigth -= nOffset;
470 : else
471 0 : nHeigth += nOffset;
472 0 : Reference< XIndexAccess > xRows( mxTable->getRows(), UNO_QUERY_THROW );
473 0 : Reference< XPropertySet > xRowSet( xRows->getByIndex( (!nEdge)?nEdge:(nEdge-1) ), UNO_QUERY_THROW );
474 0 : xRowSet->setPropertyValue( sSize, Any( nHeigth ) );
475 : }
476 : }
477 : else
478 : {
479 : /*
480 : fixes fdo#59889 and resizing of table in edge dragging
481 : Total vertical edges in a NxN table is N+1, indexed from 0 to N and total Columns is N, indexed from 0 to N-1
482 : In LTR table vertical edge responsible for dragging of column x(x=0 to N-1) is, Edge x+1
483 : But in RTL table vertical edge responisble for dragging of column x(x=0 to N-1, but from right to left)is, Edge x
484 : In LTR table dragging of edge 0(for RTL table edge N) does nothing.
485 : */
486 : //Todo: Implement Dragging functionality for leftmost edge of table.
487 0 : if( (nEdge >= 0) && (nEdge <= getColumnCount()) )
488 : {
489 0 : const bool bRTL = !mpTableObj? false: (mpTableObj->GetWritingMode() == WritingMode_RL_TB);
490 : sal_Int32 nWidth;
491 0 : if(bRTL)
492 : {
493 0 : nWidth = mpLayouter->getColumnWidth( nEdge );
494 : }
495 : else
496 : {
497 0 : nWidth = mpLayouter->getColumnWidth( (!nEdge)?nEdge:(nEdge-1) );
498 : }
499 0 : Reference< XIndexAccess > xCols( mxTable->getColumns(), UNO_QUERY_THROW );
500 0 : nWidth += nOffset;
501 0 : if(bRTL && nEdge<getColumnCount())
502 : {
503 0 : Reference< XPropertySet > xColSet( xCols->getByIndex( nEdge ), UNO_QUERY_THROW );
504 0 : xColSet->setPropertyValue( sSize, Any( nWidth ) );
505 : }
506 0 : else if(!bRTL && nEdge>0)
507 : {
508 0 : Reference< XPropertySet > xColSet( xCols->getByIndex( (nEdge-1) ), UNO_QUERY_THROW );
509 0 : xColSet->setPropertyValue( sSize, Any( nWidth ) );
510 : }
511 : /* To prevent the table resizing on edge dragging */
512 0 : if( nEdge > 0 && nEdge < mxTable->getColumnCount() )
513 : {
514 :
515 0 : if( bRTL )
516 0 : nEdge--;
517 :
518 0 : if( (bRTL && (nEdge >= 0)) || (!bRTL && (nEdge < mxTable->getColumnCount())) )
519 : {
520 0 : nWidth = mpLayouter->getColumnWidth( nEdge );
521 0 : nWidth = std::max( (sal_Int32)(nWidth - nOffset), (sal_Int32)0 );
522 :
523 0 : Reference< XPropertySet > xColSet( xCols->getByIndex( nEdge ), UNO_QUERY_THROW );
524 0 : xColSet->setPropertyValue( sSize, Any( nWidth ) );
525 : }
526 0 : }
527 : }
528 0 : }
529 : }
530 0 : catch( Exception& )
531 : {
532 : OSL_FAIL( "svx::SdrTableObjImpl::DragEdge(), exception caught!" );
533 : }
534 0 : }
535 :
536 : // -----------------------------------------------------------------------------
537 : // XModifyListener
538 : // -----------------------------------------------------------------------------
539 :
540 94 : void SAL_CALL SdrTableObjImpl::modified( const ::com::sun::star::lang::EventObject& /*aEvent*/ ) throw (::com::sun::star::uno::RuntimeException)
541 : {
542 94 : update();
543 94 : }
544 :
545 108 : void SdrTableObjImpl::update()
546 : {
547 : // source can be the table model itself or the assigned table template
548 108 : TableModelNotifyGuard aGuard( mxTable.get() );
549 108 : if( mpTableObj )
550 : {
551 108 : if( (maEditPos.mnRow >= getRowCount()) || (maEditPos.mnCol >= getColumnCount()) || (getCell( maEditPos ) != mxActiveCell) )
552 : {
553 68 : if(maEditPos.mnRow >= getRowCount())
554 0 : maEditPos.mnRow = getRowCount()-1;
555 :
556 68 : if(maEditPos.mnCol >= getColumnCount())
557 0 : maEditPos.mnCol = getColumnCount()-1;
558 :
559 68 : mpTableObj->setActiveCell( maEditPos );
560 : }
561 :
562 108 : ApplyCellStyles();
563 :
564 108 : mpTableObj->aRect = mpTableObj->maLogicRect;
565 108 : LayoutTable( mpTableObj->aRect, false, false );
566 :
567 108 : mpTableObj->SetRectsDirty();
568 108 : mpTableObj->ActionChanged();
569 108 : mpTableObj->BroadcastObjectChange();
570 108 : }
571 108 : }
572 :
573 : // -----------------------------------------------------------------------------
574 :
575 2 : void SdrTableObjImpl::connectTableStyle()
576 : {
577 2 : if( mxTableStyle.is() )
578 : {
579 2 : Reference< XModifyBroadcaster > xBroadcaster( mxTableStyle, UNO_QUERY );
580 2 : if( xBroadcaster.is() )
581 : {
582 2 : Reference< XModifyListener > xListener( static_cast< ::com::sun::star::util::XModifyListener* >(this) );
583 2 : xBroadcaster->addModifyListener( xListener );
584 2 : }
585 : }
586 2 : }
587 :
588 : // -----------------------------------------------------------------------------
589 :
590 2 : void SdrTableObjImpl::disconnectTableStyle()
591 : {
592 2 : if( mxTableStyle.is() )
593 : {
594 0 : Reference< XModifyBroadcaster > xBroadcaster( mxTableStyle, UNO_QUERY );
595 0 : if( xBroadcaster.is() )
596 : {
597 0 : Reference< XModifyListener > xListener( static_cast< ::com::sun::star::util::XModifyListener* >(this) );
598 0 : xBroadcaster->removeModifyListener( xListener );
599 0 : }
600 : }
601 2 : }
602 :
603 : // -----------------------------------------------------------------------------
604 :
605 0 : bool SdrTableObjImpl::isInUse()
606 : {
607 0 : return mpTableObj && mpTableObj->IsInserted();
608 : }
609 :
610 : // -----------------------------------------------------------------------------
611 : // XEventListener
612 : // -----------------------------------------------------------------------------
613 :
614 37 : void SAL_CALL SdrTableObjImpl::disposing( const ::com::sun::star::lang::EventObject& /*Source*/ ) throw (::com::sun::star::uno::RuntimeException)
615 : {
616 37 : mxActiveCell.clear();
617 37 : mxTable.clear();
618 37 : if( mpLayouter )
619 : {
620 35 : delete mpLayouter;
621 35 : mpLayouter = 0;
622 : }
623 37 : mpTableObj = 0;
624 37 : }
625 :
626 : // -----------------------------------------------------------------------------
627 :
628 135554 : CellRef SdrTableObjImpl::getCell( const CellPos& rPos ) const
629 : {
630 135554 : CellRef xCell;
631 135554 : if( mxTable.is() ) try
632 : {
633 135554 : xCell.set( dynamic_cast< Cell* >( mxTable->getCellByPosition( rPos.mnCol, rPos.mnRow ).get() ) );
634 : }
635 0 : catch( Exception& )
636 : {
637 : OSL_FAIL( "svx::SdrTableObjImpl::getCell(), exception caught!" );
638 : }
639 135554 : return xCell;
640 : }
641 :
642 : // -----------------------------------------------------------------------------
643 :
644 598 : sal_Int32 SdrTableObjImpl::getColumnCount() const
645 : {
646 598 : return mxTable.is() ? mxTable->getColumnCount() : 0;
647 : }
648 :
649 : // -----------------------------------------------------------------------------
650 :
651 198 : sal_Int32 SdrTableObjImpl::getRowCount() const
652 : {
653 198 : return mxTable.is() ? mxTable->getRowCount() : 0;
654 : }
655 :
656 : // -----------------------------------------------------------------------------
657 :
658 4793 : void SdrTableObjImpl::LayoutTable( Rectangle& rArea, bool bFitWidth, bool bFitHeight )
659 : {
660 4793 : if( mpLayouter && mpTableObj->GetModel() )
661 : {
662 4793 : TableModelNotifyGuard aGuard( mxTable.get() );
663 4793 : mpLayouter->LayoutTable( rArea, bFitWidth, bFitHeight );
664 : }
665 4793 : }
666 :
667 : // -----------------------------------------------------------------------------
668 :
669 2 : void SdrTableObjImpl::UpdateCells( Rectangle& rArea )
670 : {
671 2 : if( mpLayouter && mxTable.is() )
672 : {
673 2 : TableModelNotifyGuard aGuard( mxTable.get() );
674 2 : mpLayouter->updateCells( rArea );
675 2 : mxTable->setModified(sal_True);
676 : }
677 2 : }
678 :
679 : // -----------------------------------------------------------------------------
680 : // BaseProperties section
681 : // -----------------------------------------------------------------------------
682 :
683 35 : sdr::properties::BaseProperties* SdrTableObj::CreateObjectSpecificProperties()
684 : {
685 35 : return new TableProperties(*this);
686 : }
687 :
688 : // -----------------------------------------------------------------------------
689 : // DrawContact section
690 : // -----------------------------------------------------------------------------
691 :
692 35 : sdr::contact::ViewContact* SdrTableObj::CreateObjectSpecificViewContact()
693 : {
694 35 : return new sdr::contact::ViewContactOfTableObj(*this);
695 : }
696 :
697 : // --------------------------------------------------------------------
698 :
699 41777 : TYPEINIT1(SdrTableObj,SdrTextObj);
700 :
701 : // --------------------------------------------------------------------
702 :
703 35 : SdrTableObj::SdrTableObj(SdrModel* _pModel)
704 : {
705 35 : pModel = _pModel;
706 35 : init( 1, 1 );
707 35 : }
708 :
709 : // --------------------------------------------------------------------
710 :
711 0 : SdrTableObj::SdrTableObj(SdrModel* _pModel, const ::Rectangle& rNewRect, sal_Int32 nColumns, sal_Int32 nRows)
712 : : SdrTextObj( rNewRect )
713 0 : , maLogicRect( rNewRect )
714 : {
715 0 : pModel = _pModel;
716 :
717 0 : if( nColumns <= 0 )
718 0 : nColumns = 1;
719 :
720 0 : if( nRows <= 0 )
721 0 : nRows = 1;
722 :
723 0 : init( nColumns, nRows );
724 0 : }
725 :
726 : // --------------------------------------------------------------------
727 :
728 35 : void SdrTableObj::init( sal_Int32 nColumns, sal_Int32 nRows )
729 : {
730 35 : bClosedObj = sal_True;
731 :
732 35 : mpImpl = new SdrTableObjImpl;
733 35 : mpImpl->acquire();
734 35 : mpImpl->init( this, nColumns, nRows );
735 35 : }
736 :
737 : // --------------------------------------------------------------------
738 :
739 105 : SdrTableObj::~SdrTableObj()
740 : {
741 35 : mpImpl->dispose();
742 35 : mpImpl->release();
743 70 : }
744 :
745 : // --------------------------------------------------------------------
746 : // table stuff
747 : // --------------------------------------------------------------------
748 :
749 442 : Reference< XTable > SdrTableObj::getTable() const
750 : {
751 442 : return Reference< XTable >( mpImpl->mxTable.get() );
752 : }
753 :
754 : // --------------------------------------------------------------------
755 :
756 0 : bool SdrTableObj::isValid( const CellPos& rPos ) const
757 : {
758 0 : return (rPos.mnCol >= 0) && (rPos.mnCol < mpImpl->getColumnCount()) && (rPos.mnRow >= 0) && (rPos.mnRow < mpImpl->getRowCount());
759 : }
760 :
761 : // --------------------------------------------------------------------
762 :
763 0 : CellPos SdrTableObj::getFirstCell() const
764 : {
765 0 : return CellPos( 0,0 );
766 : }
767 :
768 : // --------------------------------------------------------------------
769 :
770 0 : CellPos SdrTableObj::getLastCell() const
771 : {
772 0 : CellPos aPos;
773 0 : if( mpImpl->mxTable.is() )
774 : {
775 0 : aPos.mnCol = mpImpl->getColumnCount()-1;
776 0 : aPos.mnRow = mpImpl->getRowCount()-1;
777 : }
778 0 : return aPos;
779 : }
780 :
781 : // --------------------------------------------------------------------
782 :
783 0 : CellPos SdrTableObj::getLeftCell( const CellPos& rPos, bool bEdgeTravel ) const
784 : {
785 0 : switch( GetWritingMode() )
786 : {
787 : default:
788 : case WritingMode_LR_TB:
789 0 : return getPreviousCell( rPos, bEdgeTravel );
790 : case WritingMode_RL_TB:
791 0 : return getNextCell( rPos, bEdgeTravel );
792 : case WritingMode_TB_RL:
793 0 : return getPreviousRow( rPos, bEdgeTravel );
794 : }
795 : }
796 :
797 : // --------------------------------------------------------------------
798 :
799 0 : CellPos SdrTableObj::getRightCell( const CellPos& rPos, bool bEdgeTravel ) const
800 : {
801 0 : switch( GetWritingMode() )
802 : {
803 : default:
804 : case WritingMode_LR_TB:
805 0 : return getNextCell( rPos, bEdgeTravel );
806 : case WritingMode_RL_TB:
807 0 : return getPreviousCell( rPos, bEdgeTravel );
808 : case WritingMode_TB_RL:
809 0 : return getNextRow( rPos, bEdgeTravel );
810 : }
811 : }
812 :
813 : // --------------------------------------------------------------------
814 :
815 0 : CellPos SdrTableObj::getUpCell( const CellPos& rPos, bool bEdgeTravel ) const
816 : {
817 0 : switch( GetWritingMode() )
818 : {
819 : default:
820 : case WritingMode_LR_TB:
821 : case WritingMode_RL_TB:
822 0 : return getPreviousRow( rPos, bEdgeTravel );
823 : case WritingMode_TB_RL:
824 0 : return getPreviousCell( rPos, bEdgeTravel );
825 : }
826 : }
827 :
828 : // --------------------------------------------------------------------
829 :
830 0 : CellPos SdrTableObj::getDownCell( const CellPos& rPos, bool bEdgeTravel ) const
831 : {
832 0 : switch( GetWritingMode() )
833 : {
834 : default:
835 : case WritingMode_LR_TB:
836 : case WritingMode_RL_TB:
837 0 : return getNextRow( rPos, bEdgeTravel );
838 : case WritingMode_TB_RL:
839 0 : return getNextCell( rPos, bEdgeTravel );
840 : }
841 : }
842 :
843 : // --------------------------------------------------------------------
844 :
845 0 : CellPos SdrTableObj::getPreviousCell( const CellPos& rPos, bool bEdgeTravel ) const
846 : {
847 0 : CellPos aPos( rPos );
848 0 : if( mpImpl )
849 : {
850 0 : CellRef xCell( mpImpl->getCell( aPos ) );
851 0 : if( xCell.is() && xCell->isMerged() )
852 : {
853 0 : sal_Int32 nTemp = 0;
854 0 : findMergeOrigin( mpImpl->mxTable.get(), aPos.mnCol, aPos.mnRow, aPos.mnCol, nTemp );
855 : }
856 :
857 0 : if( aPos.mnCol > 0 )
858 : {
859 0 : --aPos.mnCol;
860 : }
861 :
862 0 : else if( bEdgeTravel && (aPos.mnRow > 0) )
863 : {
864 0 : aPos.mnCol = mpImpl->mxTable->getColumnCount()-1;
865 0 : --aPos.mnRow;
866 0 : }
867 : }
868 0 : return aPos;
869 : }
870 :
871 : // --------------------------------------------------------------------
872 :
873 0 : CellPos SdrTableObj::getNextCell( const CellPos& rPos, bool bEdgeTravel ) const
874 : {
875 0 : CellPos aPos( rPos );
876 0 : if( mpImpl )
877 : {
878 0 : CellRef xCell( mpImpl->getCell( aPos ) );
879 0 : if( xCell.is() )
880 : {
881 0 : if( xCell->isMerged() )
882 : {
883 0 : findMergeOrigin( mpImpl->mxTable, aPos.mnCol, aPos.mnRow, aPos.mnCol, aPos.mnRow );
884 :
885 0 : xCell = mpImpl->getCell(aPos);
886 :
887 0 : if( xCell.is() )
888 : {
889 0 : aPos.mnCol += xCell->getColumnSpan();
890 0 : aPos.mnRow = rPos.mnRow;
891 : }
892 : }
893 : else
894 : {
895 0 : aPos.mnCol += xCell->getColumnSpan();
896 : }
897 :
898 0 : if( aPos.mnCol < mpImpl->mxTable->getColumnCount() )
899 0 : return aPos;
900 :
901 0 : if( bEdgeTravel && ((aPos.mnRow + 1) < mpImpl->getRowCount()) )
902 : {
903 0 : aPos.mnCol = 0;
904 0 : aPos.mnRow += 1;
905 0 : return aPos;
906 : }
907 0 : }
908 : }
909 :
910 : // last cell reached, no traveling possible
911 0 : return rPos;
912 : }
913 :
914 : // --------------------------------------------------------------------
915 :
916 0 : CellPos SdrTableObj::getPreviousRow( const CellPos& rPos, bool bEdgeTravel ) const
917 : {
918 0 : CellPos aPos( rPos );
919 0 : if( mpImpl )
920 : {
921 0 : CellRef xCell( mpImpl->getCell( aPos ) );
922 0 : if( xCell.is() )
923 : {
924 0 : if( xCell->isMerged() )
925 : {
926 0 : sal_Int32 nTemp = 0;
927 0 : findMergeOrigin( mpImpl->mxTable, aPos.mnCol, aPos.mnRow, nTemp, aPos.mnRow );
928 : }
929 : }
930 :
931 0 : if( aPos.mnRow > 0 )
932 : {
933 0 : --aPos.mnRow;
934 : }
935 0 : else if( bEdgeTravel && (aPos.mnCol > 0) )
936 : {
937 0 : aPos.mnRow = mpImpl->mxTable->getRowCount()-1;
938 0 : --aPos.mnCol;
939 0 : }
940 : }
941 0 : return aPos;
942 : }
943 :
944 : // --------------------------------------------------------------------
945 :
946 0 : CellPos SdrTableObj::getNextRow( const CellPos& rPos, bool bEdgeTravel ) const
947 : {
948 0 : CellPos aPos( rPos );
949 :
950 0 : if( mpImpl )
951 : {
952 0 : CellRef xCell( mpImpl->getCell( rPos ) );
953 0 : if( xCell.is() )
954 : {
955 0 : if( xCell->isMerged() )
956 : {
957 0 : findMergeOrigin( mpImpl->mxTable, aPos.mnCol, aPos.mnRow, aPos.mnCol, aPos.mnRow );
958 0 : xCell = mpImpl->getCell(aPos);
959 0 : aPos.mnCol = rPos.mnCol;
960 : }
961 :
962 0 : if( xCell.is() )
963 0 : aPos.mnRow += xCell->getRowSpan();
964 :
965 0 : if( aPos.mnRow < mpImpl->mxTable->getRowCount() )
966 0 : return aPos;
967 :
968 0 : if( bEdgeTravel && (aPos.mnCol + 1) < mpImpl->mxTable->getColumnCount() )
969 : {
970 0 : aPos.mnRow = 0;
971 0 : aPos.mnCol += 1;
972 :
973 0 : while( aPos.mnCol < mpImpl->mxTable->getColumnCount() )
974 : {
975 0 : xCell = mpImpl->getCell( aPos );
976 0 : if( xCell.is() && !xCell->isMerged() )
977 0 : return aPos;
978 0 : aPos.mnCol += 1;
979 : }
980 : }
981 0 : }
982 : }
983 :
984 : // last position reached, no more traveling possible
985 0 : return rPos;
986 : }
987 :
988 : // --------------------------------------------------------------------
989 :
990 12 : const TableStyleSettings& SdrTableObj::getTableStyleSettings() const
991 : {
992 12 : if( mpImpl )
993 : {
994 12 : return mpImpl->maTableStyle;
995 : }
996 : else
997 : {
998 0 : static TableStyleSettings aTmp;
999 0 : return aTmp;
1000 : }
1001 : }
1002 :
1003 : // --------------------------------------------------------------------
1004 :
1005 12 : void SdrTableObj::setTableStyleSettings( const TableStyleSettings& rStyle )
1006 : {
1007 12 : if( mpImpl )
1008 : {
1009 12 : mpImpl->maTableStyle = rStyle;
1010 12 : mpImpl->update();
1011 : }
1012 12 : }
1013 :
1014 : // --------------------------------------------------------------------
1015 :
1016 0 : TableHitKind SdrTableObj::CheckTableHit( const Point& rPos, sal_Int32& rnX, sal_Int32& rnY, int nTol ) const
1017 : {
1018 0 : if( !mpImpl || !mpImpl->mxTable.is() )
1019 0 : return SDRTABLEHIT_NONE;
1020 :
1021 0 : rnX = 0;
1022 0 : rnY = 0;
1023 :
1024 0 : const sal_Int32 nColCount = mpImpl->getColumnCount();
1025 0 : const sal_Int32 nRowCount = mpImpl->getRowCount();
1026 :
1027 0 : sal_Int32 nX = rPos.X() + nTol - aRect.Left();
1028 0 : sal_Int32 nY = rPos.Y() + nTol - aRect.Top();
1029 :
1030 0 : if( (nX < 0) || (nX > (aRect.GetWidth() + nTol)) || (nY < 0) || (nY > (aRect.GetHeight() + nTol) ) )
1031 0 : return SDRTABLEHIT_NONE;
1032 :
1033 : // get vertical edge number and check for a hit
1034 0 : const bool bRTL = (GetWritingMode() == WritingMode_RL_TB);
1035 0 : bool bVrtHit = false;
1036 0 : if( nX >= 0 )
1037 : {
1038 0 : if( !bRTL )
1039 : {
1040 0 : while( rnX <= nColCount )
1041 : {
1042 0 : if( nX <= (2*nTol) )
1043 : {
1044 0 : bVrtHit = true;
1045 0 : break;
1046 : }
1047 :
1048 0 : if( rnX == nColCount )
1049 0 : break;
1050 :
1051 0 : nX -= mpImpl->mpLayouter->getColumnWidth( rnX );
1052 0 : if( nX < 0 )
1053 0 : break;
1054 0 : rnX++;
1055 : }
1056 : }
1057 : else
1058 : {
1059 0 : rnX = nColCount;
1060 0 : while( rnX >= 0 )
1061 : {
1062 0 : if( nX <= (2*nTol) )
1063 : {
1064 0 : bVrtHit = true;
1065 0 : break;
1066 : }
1067 :
1068 0 : if( rnX == 0 )
1069 0 : break;
1070 :
1071 0 : rnX--;
1072 0 : nX -= mpImpl->mpLayouter->getColumnWidth( rnX );
1073 0 : if( nX < 0 )
1074 0 : break;
1075 : }
1076 : }
1077 : }
1078 :
1079 : // rnX is now the edge number left to the pointer, if it was hit bHrzHit is also true
1080 :
1081 : // get vertical edge number and check for a hit
1082 0 : bool bHrzHit = false;
1083 0 : if( nY >= 0 )
1084 : {
1085 0 : while( rnY <= nRowCount )
1086 : {
1087 0 : if( nY <= (2*nTol) )
1088 : {
1089 0 : bHrzHit = true;
1090 0 : break;
1091 : }
1092 :
1093 0 : if( rnY == nRowCount )
1094 0 : break;
1095 :
1096 0 : nY -= mpImpl->mpLayouter->getRowHeight(rnY);
1097 0 : if( nY < 0 )
1098 0 : break;
1099 0 : rnY++;
1100 : }
1101 : }
1102 :
1103 : // rnY is now the edge number above the pointer, if it was hit bVrtHit is also true
1104 :
1105 0 : if( bVrtHit && mpImpl->mpLayouter->isEdgeVisible( rnX, rnY, false ) )
1106 0 : return SDRTABLEHIT_VERTICAL_BORDER;
1107 :
1108 0 : if( bHrzHit && mpImpl->mpLayouter->isEdgeVisible( rnX, rnY, true ) )
1109 0 : return SDRTABLEHIT_HORIZONTAL_BORDER;
1110 :
1111 0 : CellRef xCell( mpImpl->getCell( CellPos( rnX, rnY ) ) );
1112 0 : if( xCell.is() && xCell->isMerged() )
1113 0 : findMergeOrigin( mpImpl->mxTable.get(), rnX, rnY, rnX, rnY );
1114 :
1115 0 : if( xCell.is() )
1116 : {
1117 0 : nX += mpImpl->mpLayouter->getColumnWidth( rnX );
1118 : //Fix for fdo#62673 : non-editable cell in table on cell merge
1119 0 : sal_Int32 i=0;
1120 0 : while(xCell.is() && xCell->isMerged())
1121 : {
1122 0 : nX += mpImpl->mpLayouter->getColumnWidth( rnX+i );
1123 0 : i++;
1124 0 : if(rnX+i < nColCount)
1125 0 : xCell=mpImpl->getCell( CellPos( rnX+i, rnY) );
1126 : else
1127 0 : break;
1128 : }
1129 :
1130 0 : if( nX < xCell->GetTextLeftDistance() )
1131 0 : return SDRTABLEHIT_CELL;
1132 : }
1133 :
1134 0 : return SDRTABLEHIT_CELLTEXTAREA;
1135 : }
1136 :
1137 0 : const SfxItemSet& SdrTableObj::GetActiveCellItemSet() const
1138 : {
1139 0 : return getActiveCell()->GetItemSet();
1140 : }
1141 :
1142 : // --------------------------------------------------------------------
1143 :
1144 2 : void SdrTableObj::setTableStyle( const Reference< XIndexAccess >& xTableStyle )
1145 : {
1146 2 : if( mpImpl && (mpImpl->mxTableStyle != xTableStyle) )
1147 : {
1148 2 : mpImpl->disconnectTableStyle();
1149 2 : mpImpl->mxTableStyle = xTableStyle;
1150 2 : mpImpl->connectTableStyle();
1151 2 : mpImpl->update();
1152 : }
1153 2 : }
1154 :
1155 : // --------------------------------------------------------------------
1156 :
1157 0 : const Reference< XIndexAccess >& SdrTableObj::getTableStyle() const
1158 : {
1159 0 : if( mpImpl )
1160 : {
1161 0 : return mpImpl->mxTableStyle;
1162 : }
1163 : else
1164 : {
1165 0 : static Reference< XIndexAccess > aTmp;
1166 0 : return aTmp;
1167 : }
1168 : }
1169 :
1170 : // --------------------------------------------------------------------
1171 : // text stuff
1172 : // --------------------------------------------------------------------
1173 :
1174 : /** returns the currently active text. */
1175 0 : SdrText* SdrTableObj::getActiveText() const
1176 : {
1177 0 : return dynamic_cast< SdrText* >( getActiveCell().get() );
1178 : }
1179 :
1180 : // --------------------------------------------------------------------
1181 :
1182 : /** returns the nth available text. */
1183 400 : SdrText* SdrTableObj::getText( sal_Int32 nIndex ) const
1184 : {
1185 400 : if( mpImpl->mxTable.is() )
1186 : {
1187 400 : const sal_Int32 nColCount = mpImpl->getColumnCount();
1188 400 : if( nColCount )
1189 : {
1190 400 : CellPos aPos( nIndex % nColCount, nIndex / nColCount );
1191 :
1192 400 : CellRef xCell( mpImpl->getCell( aPos ) );
1193 400 : return dynamic_cast< SdrText* >( xCell.get() );
1194 : }
1195 : }
1196 0 : return 0;
1197 : }
1198 :
1199 : // --------------------------------------------------------------------
1200 :
1201 : /** returns the number of texts available for this object. */
1202 4 : sal_Int32 SdrTableObj::getTextCount() const
1203 : {
1204 4 : if( mpImpl->mxTable.is() )
1205 : {
1206 4 : const sal_Int32 nColCount = mpImpl->getColumnCount();
1207 4 : const sal_Int32 nRowCount = mpImpl->getRowCount();
1208 :
1209 4 : return nColCount * nRowCount;
1210 : }
1211 : else
1212 : {
1213 0 : return 0;
1214 : }
1215 : }
1216 :
1217 : // --------------------------------------------------------------------
1218 :
1219 : /** changes the current active text */
1220 0 : void SdrTableObj::setActiveText( sal_Int32 nIndex )
1221 : {
1222 0 : if( mpImpl && mpImpl->mxTable.is() )
1223 : {
1224 0 : const sal_Int32 nColCount = mpImpl->mxTable->getColumnCount();
1225 0 : if( nColCount )
1226 : {
1227 0 : CellPos aPos( nIndex % nColCount, nIndex / nColCount );
1228 0 : if( isValid( aPos ) )
1229 0 : setActiveCell( aPos );
1230 : }
1231 : }
1232 0 : }
1233 :
1234 : // --------------------------------------------------------------------
1235 :
1236 : /** returns the index of the text that contains the given point or -1 */
1237 0 : sal_Int32 SdrTableObj::CheckTextHit(const Point& rPnt) const
1238 : {
1239 0 : if( mpImpl && mpImpl->mxTable.is() )
1240 : {
1241 0 : CellPos aPos;
1242 0 : if( CheckTableHit( rPnt, aPos.mnCol, aPos.mnRow, 0 ) == SDRTABLEHIT_CELLTEXTAREA )
1243 0 : return aPos.mnRow * mpImpl->mxTable->getColumnCount() + aPos.mnCol;
1244 : }
1245 :
1246 0 : return 0;
1247 : }
1248 :
1249 : // --------------------------------------------------------------------
1250 :
1251 135000 : SdrOutliner* SdrTableObj::GetCellTextEditOutliner( const Cell& rCell ) const
1252 : {
1253 135000 : if( mpImpl && (mpImpl->getCell( mpImpl->maEditPos ).get() == &rCell) )
1254 9586 : return pEdtOutl;
1255 : else
1256 125414 : return 0;
1257 : }
1258 :
1259 :
1260 : // --------------------------------------------------------------------
1261 :
1262 0 : const TableLayouter& SdrTableObj::getTableLayouter() const
1263 : {
1264 : OSL_ENSURE(mpImpl && mpImpl->mpLayouter, "getTableLayouter() error: no mpImpl or mpLayouter (!)");
1265 0 : return *(mpImpl->mpLayouter);
1266 : }
1267 :
1268 : // --------------------------------------------------------------------
1269 :
1270 0 : bool SdrTableObj::IsAutoGrowHeight() const
1271 : {
1272 0 : return true;
1273 : }
1274 :
1275 : // --------------------------------------------------------------------
1276 :
1277 0 : bool SdrTableObj::IsAutoGrowWidth() const
1278 : {
1279 0 : return true;
1280 : }
1281 :
1282 : // --------------------------------------------------------------------
1283 :
1284 2 : bool SdrTableObj::HasText() const
1285 : {
1286 2 : return true;
1287 : }
1288 :
1289 : // --------------------------------------------------------------------
1290 :
1291 0 : bool SdrTableObj::IsTextEditActive( const CellPos& rPos )
1292 : {
1293 0 : return pEdtOutl && mpImpl && (rPos == mpImpl->maEditPos);
1294 : }
1295 :
1296 : // --------------------------------------------------------------------
1297 :
1298 0 : void SdrTableObj::onEditOutlinerStatusEvent( EditStatus* pEditStatus )
1299 : {
1300 0 : if( (pEditStatus->GetStatusWord() & EE_STAT_TEXTHEIGHTCHANGED) && mpImpl && mpImpl->mpLayouter )
1301 : {
1302 0 : Rectangle aRect0( aRect );
1303 0 : aRect = maLogicRect;
1304 0 : mpImpl->LayoutTable( aRect, false, false );
1305 0 : SetRectsDirty();
1306 0 : ActionChanged();
1307 0 : BroadcastObjectChange();
1308 0 : if( aRect0 != aRect )
1309 0 : SendUserCall(SDRUSERCALL_RESIZE,aRect0);
1310 : }
1311 0 : }
1312 :
1313 : // --------------------------------------------------------------------
1314 :
1315 0 : void SdrTableObj::TakeObjInfo(SdrObjTransformInfoRec& rInfo) const
1316 : {
1317 0 : rInfo.bResizeFreeAllowed=sal_True;
1318 0 : rInfo.bResizePropAllowed=sal_True;
1319 0 : rInfo.bRotateFreeAllowed=sal_False;
1320 0 : rInfo.bRotate90Allowed =sal_False;
1321 0 : rInfo.bMirrorFreeAllowed=sal_False;
1322 0 : rInfo.bMirror45Allowed =sal_False;
1323 0 : rInfo.bMirror90Allowed =sal_False;
1324 :
1325 : // allow transparence
1326 0 : rInfo.bTransparenceAllowed = sal_True;
1327 :
1328 : // gradient depends on fillstyle
1329 0 : XFillStyle eFillStyle = ((XFillStyleItem&)(GetObjectItem(XATTR_FILLSTYLE))).GetValue();
1330 0 : rInfo.bGradientAllowed = (eFillStyle == XFILL_GRADIENT);
1331 0 : rInfo.bShearAllowed =sal_False;
1332 0 : rInfo.bEdgeRadiusAllowed=sal_False;
1333 0 : rInfo.bCanConvToPath =sal_False;
1334 0 : rInfo.bCanConvToPoly =sal_False;
1335 0 : rInfo.bCanConvToPathLineToArea=sal_False;
1336 0 : rInfo.bCanConvToPolyLineToArea=sal_False;
1337 0 : rInfo.bCanConvToContour = sal_False;
1338 0 : }
1339 :
1340 : // --------------------------------------------------------------------
1341 :
1342 139 : sal_uInt16 SdrTableObj::GetObjIdentifier() const
1343 : {
1344 139 : return static_cast<sal_uInt16>(OBJ_TABLE);
1345 : }
1346 :
1347 : // --------------------------------------------------------------------
1348 :
1349 37 : void SdrTableObj::SetPage(SdrPage* pNewPage)
1350 : {
1351 37 : SdrTextObj::SetPage(pNewPage);
1352 37 : }
1353 :
1354 : // --------------------------------------------------------------------
1355 :
1356 2 : void SdrTableObj::SetModel(SdrModel* pNewModel)
1357 : {
1358 2 : SdrModel* pOldModel = GetModel();
1359 2 : if( pNewModel != pOldModel )
1360 : {
1361 0 : SdrTextObj::SetModel(pNewModel);
1362 :
1363 0 : if( mpImpl )
1364 : {
1365 0 : mpImpl->SetModel( pOldModel, pNewModel );
1366 :
1367 0 : if( !maLogicRect.IsEmpty() )
1368 : {
1369 0 : aRect = maLogicRect;
1370 0 : mpImpl->LayoutTable( aRect, false, false );
1371 : }
1372 : }
1373 : }
1374 2 : }
1375 :
1376 : // --------------------------------------------------------------------
1377 :
1378 0 : void SdrTableObj::TakeTextRect( SdrOutliner& rOutliner, Rectangle& rTextRect, bool bNoEditText, Rectangle* pAnchorRect, bool bLineWidth ) const
1379 : {
1380 0 : if( mpImpl )
1381 0 : TakeTextRect( mpImpl->maEditPos, rOutliner, rTextRect, bNoEditText, pAnchorRect, bLineWidth );
1382 0 : }
1383 :
1384 : // --------------------------------------------------------------------
1385 :
1386 0 : void SdrTableObj::TakeTextRect( const CellPos& rPos, SdrOutliner& rOutliner, Rectangle& rTextRect, bool bNoEditText, Rectangle* pAnchorRect, bool /*bLineWidth*/ ) const
1387 : {
1388 0 : if( !mpImpl )
1389 0 : return;
1390 :
1391 0 : CellRef xCell( mpImpl->getCell( rPos ) );
1392 0 : if( !xCell.is() )
1393 0 : return;
1394 :
1395 0 : Rectangle aAnkRect;
1396 0 : TakeTextAnchorRect( rPos, aAnkRect );
1397 :
1398 0 : SdrTextVertAdjust eVAdj=xCell->GetTextVerticalAdjust();
1399 :
1400 0 : sal_uIntPtr nStat0=rOutliner.GetControlWord();
1401 0 : Size aNullSize;
1402 0 : nStat0 |= EE_CNTRL_AUTOPAGESIZE;
1403 0 : rOutliner.SetControlWord(nStat0);
1404 0 : rOutliner.SetMinAutoPaperSize(aNullSize);
1405 0 : rOutliner.SetMaxAutoPaperSize(aAnkRect.GetSize());
1406 0 : rOutliner.SetPaperSize(aAnkRect.GetSize());
1407 :
1408 : // #103516# New try with _BLOCK for hor and ver after completely
1409 : // supporting full width for vertical text.
1410 : // if( SDRTEXTHORZADJUST_BLOCK == eHAdj && !IsVerticalWriting())
1411 : // {
1412 0 : rOutliner.SetMinAutoPaperSize(Size(aAnkRect.GetWidth(), 0));
1413 : // }
1414 : // else if(SDRTEXTVERTADJUST_BLOCK == eVAdj && IsVerticalWriting())
1415 : // {
1416 : // rOutliner.SetMinAutoPaperSize(Size(0, aAnkRect.GetHeight()));
1417 : // }
1418 :
1419 : // ---
1420 :
1421 : // set text at outliner, maybe from edit outliner
1422 0 : OutlinerParaObject* pPara= xCell->GetOutlinerParaObject();
1423 0 : if (pEdtOutl && !bNoEditText && mpImpl->mxActiveCell == xCell )
1424 0 : pPara=pEdtOutl->CreateParaObject();
1425 :
1426 0 : if (pPara)
1427 : {
1428 0 : const bool bHitTest = pModel && (&pModel->GetHitTestOutliner() == &rOutliner);
1429 :
1430 0 : const SdrTextObj* pTestObj = rOutliner.GetTextObj();
1431 0 : if( !pTestObj || !bHitTest || (pTestObj != this) || (pTestObj->GetOutlinerParaObject() != xCell->GetOutlinerParaObject()) )
1432 : {
1433 0 : if( bHitTest ) // #i33696# take back fix #i27510#
1434 0 : rOutliner.SetTextObj( this );
1435 :
1436 0 : rOutliner.SetUpdateMode(sal_True);
1437 0 : rOutliner.SetText(*pPara);
1438 : }
1439 : }
1440 : else
1441 : {
1442 0 : rOutliner.SetTextObj( NULL );
1443 : }
1444 :
1445 0 : if (pEdtOutl && !bNoEditText && pPara && mpImpl->mxActiveCell == xCell )
1446 0 : delete pPara;
1447 :
1448 0 : rOutliner.SetUpdateMode(sal_True);
1449 0 : rOutliner.SetControlWord(nStat0);
1450 :
1451 0 : Point aTextPos(aAnkRect.TopLeft());
1452 0 : Size aTextSiz(rOutliner.GetPaperSize());
1453 0 : if (eVAdj==SDRTEXTVERTADJUST_CENTER || eVAdj==SDRTEXTVERTADJUST_BOTTOM)
1454 : {
1455 0 : long nFreeHgt=aAnkRect.GetHeight()-aTextSiz.Height();
1456 0 : if (eVAdj==SDRTEXTVERTADJUST_CENTER)
1457 0 : aTextPos.Y()+=nFreeHgt/2;
1458 0 : if (eVAdj==SDRTEXTVERTADJUST_BOTTOM)
1459 0 : aTextPos.Y()+=nFreeHgt;
1460 : }
1461 :
1462 0 : if (pAnchorRect)
1463 0 : *pAnchorRect=aAnkRect;
1464 :
1465 0 : rTextRect=Rectangle(aTextPos,aTextSiz);
1466 : }
1467 :
1468 : // --------------------------------------------------------------------
1469 :
1470 13744 : const CellRef& SdrTableObj::getActiveCell() const
1471 : {
1472 13744 : if( mpImpl )
1473 : {
1474 13744 : if( !mpImpl->mxActiveCell.is() )
1475 : {
1476 0 : CellPos aPos;
1477 0 : const_cast< SdrTableObj* >(this)->setActiveCell( aPos );
1478 : }
1479 13744 : return mpImpl->mxActiveCell;
1480 : }
1481 : else
1482 : {
1483 0 : static CellRef xCell;
1484 0 : return xCell;
1485 : }
1486 : }
1487 :
1488 : // --------------------------------------------------------------------
1489 :
1490 0 : sal_Int32 SdrTableObj::getRowCount() const
1491 : {
1492 0 : return mpImpl ? mpImpl->getRowCount() : 0;
1493 : }
1494 :
1495 : // --------------------------------------------------------------------
1496 :
1497 0 : sal_Int32 SdrTableObj::getColumnCount() const
1498 : {
1499 0 : return mpImpl ? mpImpl->getColumnCount() : 0;
1500 : }
1501 :
1502 : // --------------------------------------------------------------------
1503 :
1504 68 : void SdrTableObj::setActiveCell( const CellPos& rPos )
1505 : {
1506 68 : if( mpImpl && mpImpl->mxTable.is() ) try
1507 : {
1508 68 : mpImpl->mxActiveCell.set( dynamic_cast< Cell* >( mpImpl->mxTable->getCellByPosition( rPos.mnCol, rPos.mnRow ).get() ) );
1509 68 : if( mpImpl->mxActiveCell.is() && mpImpl->mxActiveCell->isMerged() )
1510 : {
1511 0 : CellPos aOrigin;
1512 0 : findMergeOrigin( mpImpl->mxTable.get(), rPos.mnCol, rPos.mnRow, aOrigin.mnCol, aOrigin.mnRow );
1513 0 : mpImpl->mxActiveCell.set( dynamic_cast< Cell* >( mpImpl->mxTable->getCellByPosition( aOrigin.mnCol, aOrigin.mnRow ).get() ) );
1514 0 : mpImpl->maEditPos = aOrigin;
1515 : }
1516 : else
1517 : {
1518 68 : mpImpl->maEditPos = rPos;
1519 : }
1520 : }
1521 0 : catch( Exception& )
1522 : {
1523 : OSL_FAIL("SdrTableObj::setActiveCell(), exception caught!");
1524 : }
1525 68 : }
1526 :
1527 : // --------------------------------------------------------------------
1528 :
1529 0 : void SdrTableObj::getActiveCellPos( CellPos& rPos ) const
1530 : {
1531 0 : rPos = mpImpl->maEditPos;
1532 0 : }
1533 :
1534 : // --------------------------------------------------------------------
1535 :
1536 0 : void SdrTableObj::getCellBounds( const CellPos& rPos, ::Rectangle& rCellRect )
1537 : {
1538 0 : if( mpImpl )
1539 : {
1540 0 : CellRef xCell( mpImpl->getCell( rPos ) );
1541 0 : if( xCell.is() )
1542 0 : rCellRect = xCell->getCellRect();
1543 : }
1544 0 : }
1545 :
1546 : // --------------------------------------------------------------------
1547 :
1548 0 : void SdrTableObj::TakeTextAnchorRect(Rectangle& rAnchorRect) const
1549 : {
1550 0 : if( mpImpl )
1551 0 : TakeTextAnchorRect( mpImpl->maEditPos, rAnchorRect );
1552 0 : }
1553 :
1554 : // --------------------------------------------------------------------
1555 :
1556 0 : void SdrTableObj::TakeTextAnchorRect( const CellPos& rPos, Rectangle& rAnchorRect ) const
1557 : {
1558 0 : Rectangle aAnkRect(aRect);
1559 :
1560 0 : if( mpImpl )
1561 : {
1562 0 : CellRef xCell( mpImpl->getCell( rPos ) );
1563 0 : if( xCell.is() )
1564 0 : xCell->TakeTextAnchorRect( aAnkRect );
1565 : }
1566 :
1567 0 : ImpJustifyRect(aAnkRect);
1568 0 : rAnchorRect=aAnkRect;
1569 0 : }
1570 :
1571 : // --------------------------------------------------------------------
1572 :
1573 0 : void SdrTableObj::TakeTextEditArea(Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin) const
1574 : {
1575 0 : if( mpImpl )
1576 0 : TakeTextEditArea( mpImpl->maEditPos, pPaperMin, pPaperMax, pViewInit, pViewMin );
1577 0 : }
1578 :
1579 : // --------------------------------------------------------------------
1580 :
1581 0 : void SdrTableObj::TakeTextEditArea( const CellPos& rPos, Size* pPaperMin, Size* pPaperMax, Rectangle* pViewInit, Rectangle* pViewMin ) const
1582 : {
1583 0 : Size aPaperMin,aPaperMax;
1584 0 : Rectangle aViewInit;
1585 0 : TakeTextAnchorRect( rPos, aViewInit );
1586 :
1587 0 : Size aAnkSiz(aViewInit.GetSize());
1588 0 : aAnkSiz.Width()--; aAnkSiz.Height()--; // weil GetSize() ein draufaddiert
1589 :
1590 0 : Size aMaxSiz(aAnkSiz.Width(),1000000);
1591 0 : if (pModel!=NULL)
1592 : {
1593 0 : Size aTmpSiz(pModel->GetMaxObjSize());
1594 0 : if (aTmpSiz.Height()!=0)
1595 0 : aMaxSiz.Height()=aTmpSiz.Height();
1596 : }
1597 :
1598 0 : CellRef xCell( mpImpl->getCell( rPos ) );
1599 0 : SdrTextVertAdjust eVAdj = xCell.is() ? xCell->GetTextVerticalAdjust() : SDRTEXTVERTADJUST_TOP;
1600 :
1601 0 : aPaperMax=aMaxSiz;
1602 :
1603 0 : aPaperMin.Width() = aAnkSiz.Width();
1604 :
1605 0 : if (pViewMin!=NULL)
1606 : {
1607 0 : *pViewMin=aViewInit;
1608 0 : long nYFree=aAnkSiz.Height()-aPaperMin.Height();
1609 :
1610 0 : if (eVAdj==SDRTEXTVERTADJUST_TOP)
1611 : {
1612 0 : pViewMin->Bottom()-=nYFree;
1613 : }
1614 0 : else if (eVAdj==SDRTEXTVERTADJUST_BOTTOM)
1615 : {
1616 0 : pViewMin->Top()+=nYFree;
1617 : }
1618 : else
1619 : {
1620 0 : pViewMin->Top()+=nYFree/2;
1621 0 : pViewMin->Bottom()=pViewMin->Top()+aPaperMin.Height();
1622 : }
1623 : }
1624 :
1625 :
1626 0 : if(IsVerticalWriting())
1627 0 : aPaperMin.Width() = 0;
1628 : else
1629 0 : aPaperMin.Height() = 0;
1630 :
1631 0 : if (pPaperMin!=NULL) *pPaperMin=aPaperMin;
1632 0 : if (pPaperMax!=NULL) *pPaperMax=aPaperMax;
1633 0 : if (pViewInit!=NULL) *pViewInit=aViewInit;
1634 0 : }
1635 :
1636 : // --------------------------------------------------------------------
1637 :
1638 0 : sal_uInt16 SdrTableObj::GetOutlinerViewAnchorMode() const
1639 : {
1640 0 : EVAnchorMode eRet=ANCHOR_TOP_LEFT;
1641 0 : CellRef xCell( getActiveCell() );
1642 0 : if( xCell.is() )
1643 : {
1644 0 : SdrTextVertAdjust eV=xCell->GetTextVerticalAdjust();
1645 :
1646 : {
1647 0 : if (eV==SDRTEXTVERTADJUST_TOP)
1648 : {
1649 0 : eRet=ANCHOR_TOP_LEFT;
1650 : }
1651 0 : else if (eV==SDRTEXTVERTADJUST_BOTTOM)
1652 : {
1653 0 : eRet=ANCHOR_BOTTOM_LEFT;
1654 : }
1655 : else
1656 : {
1657 0 : eRet=ANCHOR_VCENTER_LEFT;
1658 : }
1659 : }
1660 : }
1661 0 : return (sal_uInt16)eRet;
1662 : }
1663 :
1664 : // --------------------------------------------------------------------
1665 :
1666 1209 : OutlinerParaObject* SdrTableObj::GetEditOutlinerParaObject() const
1667 : {
1668 1209 : return SdrTextObj::GetEditOutlinerParaObject();
1669 : }
1670 :
1671 : // --------------------------------------------------------------------
1672 :
1673 : struct ImplTableShadowPaintInfo
1674 : {
1675 : Color maShadowColor;
1676 : sal_uInt32 mnXDistance;
1677 : sal_uInt32 mnYDistance;
1678 : sal_uInt16 mnShadowTransparence;
1679 :
1680 : ImplTableShadowPaintInfo( const SfxItemSet& rSet )
1681 : {
1682 : const SdrShadowColorItem& rShadColItem = ((const SdrShadowColorItem&)(rSet.Get(SDRATTR_SHADOWCOLOR)));
1683 : maShadowColor = rShadColItem.GetColorValue();
1684 : mnShadowTransparence = ((const SdrShadowTransparenceItem&)(rSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue();
1685 :
1686 : mnXDistance = ((SdrShadowXDistItem&)(rSet.Get(SDRATTR_SHADOWXDIST))).GetValue();
1687 : mnYDistance = ((SdrShadowYDistItem&)(rSet.Get(SDRATTR_SHADOWYDIST))).GetValue();
1688 : }
1689 : };
1690 :
1691 : // --------------------------------------------------------------------
1692 :
1693 0 : void SdrTableObj::TakeObjNameSingul(XubString& rName) const
1694 : {
1695 0 : rName = ImpGetResStr(STR_ObjNameSingulTable);
1696 :
1697 0 : String aName( GetName() );
1698 0 : if(aName.Len())
1699 : {
1700 0 : rName += sal_Unicode(' ');
1701 0 : rName += sal_Unicode('\'');
1702 0 : rName += aName;
1703 0 : rName += sal_Unicode('\'');
1704 0 : }
1705 0 : }
1706 :
1707 : // --------------------------------------------------------------------
1708 :
1709 0 : void SdrTableObj::TakeObjNamePlural(XubString& rName) const
1710 : {
1711 0 : rName = ImpGetResStr(STR_ObjNamePluralTable);
1712 0 : }
1713 :
1714 : // --------------------------------------------------------------------
1715 :
1716 0 : SdrTableObj* SdrTableObj::Clone() const
1717 : {
1718 0 : return CloneHelper< SdrTableObj >();
1719 : }
1720 :
1721 0 : SdrTableObj& SdrTableObj::operator=(const SdrTableObj& rObj)
1722 : {
1723 0 : if( this == &rObj )
1724 0 : return *this;
1725 : // call parent
1726 0 : SdrObject::operator=(rObj);
1727 :
1728 0 : TableModelNotifyGuard aGuard( mpImpl ? mpImpl->mxTable.get() : 0 );
1729 :
1730 0 : maLogicRect = rObj.maLogicRect;
1731 0 : aRect = rObj.aRect;
1732 0 : aGeo = rObj.aGeo;
1733 0 : eTextKind = rObj.eTextKind;
1734 0 : bTextFrame = rObj.bTextFrame;
1735 0 : aTextSize = rObj.aTextSize;
1736 0 : bTextSizeDirty = rObj.bTextSizeDirty;
1737 0 : bNoShear = rObj.bNoShear;
1738 0 : bNoRotate = rObj.bNoRotate;
1739 0 : bNoMirror = rObj.bNoMirror;
1740 0 : bDisableAutoWidthOnDragging = rObj.bDisableAutoWidthOnDragging;
1741 :
1742 0 : if( rObj.mpImpl )
1743 0 : *mpImpl = *rObj.mpImpl;
1744 0 : return *this;
1745 : }
1746 :
1747 : // --------------------------------------------------------------------
1748 :
1749 0 : basegfx::B2DPolyPolygon SdrTableObj::TakeXorPoly() const
1750 : {
1751 0 : return SdrTextObj::TakeXorPoly();
1752 : }
1753 :
1754 : // --------------------------------------------------------------------
1755 :
1756 0 : basegfx::B2DPolyPolygon SdrTableObj::TakeContour() const
1757 : {
1758 0 : return SdrTextObj::TakeContour();
1759 : }
1760 :
1761 : // --------------------------------------------------------------------
1762 :
1763 15 : const Rectangle& SdrTableObj::GetSnapRect() const
1764 : {
1765 15 : return aRect;
1766 : }
1767 :
1768 : // --------------------------------------------------------------------
1769 :
1770 37 : void SdrTableObj::NbcSetSnapRect(const Rectangle& rRect)
1771 : {
1772 37 : NbcSetLogicRect( rRect );
1773 37 : }
1774 :
1775 : // --------------------------------------------------------------------
1776 :
1777 8 : const Rectangle& SdrTableObj::GetLogicRect() const
1778 : {
1779 8 : return maLogicRect;
1780 : }
1781 :
1782 : // --------------------------------------------------------------------
1783 :
1784 0 : void SdrTableObj::RecalcSnapRect()
1785 : {
1786 0 : }
1787 :
1788 : // --------------------------------------------------------------------
1789 :
1790 0 : sal_uInt32 SdrTableObj::GetSnapPointCount() const
1791 : {
1792 0 : return SdrTextObj::GetSnapPointCount();
1793 : }
1794 :
1795 : // --------------------------------------------------------------------
1796 :
1797 :
1798 0 : Point SdrTableObj::GetSnapPoint(sal_uInt32 i) const
1799 : {
1800 0 : return SdrTextObj::GetSnapPoint(i);
1801 : }
1802 :
1803 : // --------------------------------------------------------------------
1804 :
1805 0 : sal_Bool SdrTableObj::BegTextEdit(SdrOutliner& rOutl)
1806 : {
1807 0 : if( pEdtOutl != NULL )
1808 0 : return sal_False;
1809 :
1810 0 : pEdtOutl=&rOutl;
1811 :
1812 0 : mbInEditMode = sal_True;
1813 :
1814 0 : rOutl.Init( OUTLINERMODE_TEXTOBJECT );
1815 0 : rOutl.SetRefDevice( pModel->GetRefDevice() );
1816 :
1817 0 : bool bUpdMerk=rOutl.GetUpdateMode();
1818 0 : if (bUpdMerk) rOutl.SetUpdateMode(sal_False);
1819 0 : Size aPaperMin;
1820 0 : Size aPaperMax;
1821 0 : Rectangle aEditArea;
1822 0 : TakeTextEditArea(&aPaperMin,&aPaperMax,&aEditArea,NULL);
1823 :
1824 0 : rOutl.SetMinAutoPaperSize(aPaperMin);
1825 0 : rOutl.SetMaxAutoPaperSize(aPaperMax);
1826 0 : rOutl.SetPaperSize(aPaperMax);
1827 :
1828 0 : if (bUpdMerk) rOutl.SetUpdateMode(sal_True);
1829 :
1830 0 : sal_uIntPtr nStat=rOutl.GetControlWord();
1831 0 : nStat |= EE_CNTRL_AUTOPAGESIZE;
1832 0 : nStat &=~EE_CNTRL_STRETCHING;
1833 0 : rOutl.SetControlWord(nStat);
1834 :
1835 0 : OutlinerParaObject* pPara = GetOutlinerParaObject();
1836 0 : if(pPara)
1837 0 : rOutl.SetText(*pPara);
1838 :
1839 0 : rOutl.UpdateFields();
1840 0 : rOutl.ClearModifyFlag();
1841 :
1842 0 : return sal_True;
1843 : }
1844 :
1845 : // --------------------------------------------------------------------
1846 :
1847 0 : void SdrTableObj::EndTextEdit(SdrOutliner& rOutl)
1848 : {
1849 0 : if(rOutl.IsModified())
1850 : {
1851 0 : if( GetModel() && GetModel()->IsUndoEnabled() )
1852 0 : GetModel()->AddUndo( GetModel()->GetSdrUndoFactory().CreateUndoGeoObject(*this) );
1853 :
1854 0 : OutlinerParaObject* pNewText = 0;
1855 0 : Paragraph* p1stPara = rOutl.GetParagraph( 0 );
1856 0 : sal_Int32 nParaAnz = rOutl.GetParagraphCount();
1857 :
1858 0 : if(p1stPara)
1859 : {
1860 0 : if(nParaAnz == 1)
1861 : {
1862 : // if its only one paragraph, check if it is empty
1863 0 : OUString aStr(rOutl.GetText(p1stPara));
1864 0 : if (aStr.isEmpty())
1865 : {
1866 : // gotcha!
1867 0 : nParaAnz = 0;
1868 0 : }
1869 : }
1870 :
1871 : // to remove the grey field background
1872 0 : rOutl.UpdateFields();
1873 :
1874 0 : if(nParaAnz != 0)
1875 : {
1876 : // create new text object
1877 0 : pNewText = rOutl.CreateParaObject( 0, nParaAnz );
1878 : }
1879 : }
1880 0 : SetOutlinerParaObject(pNewText);
1881 : }
1882 :
1883 0 : pEdtOutl = 0;
1884 0 : rOutl.Clear();
1885 0 : sal_uInt32 nStat = rOutl.GetControlWord();
1886 0 : nStat &= ~EE_CNTRL_AUTOPAGESIZE;
1887 0 : rOutl.SetControlWord(nStat);
1888 :
1889 0 : mbInEditMode = sal_False;
1890 0 : }
1891 :
1892 : // --------------------------------------------------------------------
1893 :
1894 40 : OutlinerParaObject* SdrTableObj::GetOutlinerParaObject() const
1895 : {
1896 40 : CellRef xCell( getActiveCell() );
1897 40 : if( xCell.is() )
1898 40 : return xCell->GetOutlinerParaObject();
1899 : else
1900 0 : return 0;
1901 : }
1902 :
1903 : // --------------------------------------------------------------------
1904 :
1905 0 : void SdrTableObj::NbcSetOutlinerParaObject( OutlinerParaObject* pTextObject)
1906 : {
1907 0 : CellRef xCell( getActiveCell() );
1908 0 : if( xCell.is() )
1909 : {
1910 0 : if( pModel )
1911 : {
1912 : // Update HitTestOutliner
1913 0 : const SdrTextObj* pTestObj = pModel->GetHitTestOutliner().GetTextObj();
1914 0 : if( pTestObj && pTestObj->GetOutlinerParaObject() == xCell->GetOutlinerParaObject() )
1915 0 : pModel->GetHitTestOutliner().SetTextObj( NULL );
1916 : }
1917 :
1918 0 : xCell->SetOutlinerParaObject( pTextObject );
1919 :
1920 0 : SetTextSizeDirty();
1921 0 : NbcAdjustTextFrameWidthAndHeight();
1922 0 : }
1923 0 : }
1924 :
1925 : // --------------------------------------------------------------------
1926 :
1927 39 : void SdrTableObj::NbcSetLogicRect(const Rectangle& rRect)
1928 : {
1929 39 : maLogicRect=rRect;
1930 39 : ImpJustifyRect(maLogicRect);
1931 39 : const bool bWidth = maLogicRect.getWidth() != aRect.getWidth();
1932 39 : const bool bHeight = maLogicRect.getHeight() != aRect.getHeight();
1933 39 : aRect=maLogicRect;
1934 39 : NbcAdjustTextFrameWidthAndHeight( !bHeight, !bWidth );
1935 39 : SetRectsDirty();
1936 39 : }
1937 :
1938 :
1939 : // --------------------------------------------------------------------
1940 :
1941 0 : void SdrTableObj::AdjustToMaxRect( const Rectangle& rMaxRect, bool /* bShrinkOnly = false */ )
1942 : {
1943 0 : Rectangle aAdjustRect( rMaxRect );
1944 0 : aAdjustRect.setHeight( GetLogicRect().getHeight() );
1945 0 : SetLogicRect( aAdjustRect );
1946 0 : }
1947 :
1948 : // --------------------------------------------------------------------
1949 :
1950 2 : void SdrTableObj::NbcMove(const Size& rSiz)
1951 : {
1952 2 : MoveRect(maLogicRect,rSiz);
1953 2 : SdrTextObj::NbcMove( rSiz );
1954 2 : if( mpImpl )
1955 2 : mpImpl->UpdateCells( aRect );
1956 2 : }
1957 :
1958 : // --------------------------------------------------------------------
1959 :
1960 0 : void SdrTableObj::NbcResize(const Point& rRef, const Fraction& xFact, const Fraction& yFact)
1961 : {
1962 0 : Rectangle aOldRect( maLogicRect );
1963 0 : ResizeRect(maLogicRect,rRef,xFact,yFact);
1964 :
1965 0 : aRect = maLogicRect;
1966 0 : NbcAdjustTextFrameWidthAndHeight( maLogicRect.GetHeight() == aOldRect.GetHeight(), maLogicRect.GetWidth() == aOldRect.GetWidth() );
1967 0 : SetRectsDirty();
1968 0 : }
1969 :
1970 : // --------------------------------------------------------------------
1971 :
1972 0 : bool SdrTableObj::AdjustTextFrameWidthAndHeight(bool bHgt, bool bWdt)
1973 : {
1974 0 : Rectangle aNeuRect(maLogicRect);
1975 0 : bool bRet=AdjustTextFrameWidthAndHeight(aNeuRect,bHgt,bWdt);
1976 0 : if (bRet)
1977 : {
1978 0 : Rectangle aBoundRect0;
1979 0 : if (pUserCall!=NULL)
1980 0 : aBoundRect0=GetLastBoundRect();
1981 0 : aRect=aNeuRect;
1982 0 : SetRectsDirty();
1983 0 : SetChanged();
1984 0 : BroadcastObjectChange();
1985 0 : SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
1986 : }
1987 0 : return bRet;
1988 : }
1989 :
1990 : // --------------------------------------------------------------------
1991 :
1992 39 : bool SdrTableObj::AdjustTextFrameWidthAndHeight(Rectangle& rR, bool bHeight, bool bWidth) const
1993 : {
1994 39 : if((pModel == NULL) || rR.IsEmpty() || !mpImpl || !mpImpl->mxTable.is() )
1995 0 : return sal_False;
1996 :
1997 39 : Rectangle aRectangle( rR );
1998 39 : mpImpl->LayoutTable( aRectangle, !bWidth, !bHeight );
1999 :
2000 39 : if( aRectangle != rR )
2001 : {
2002 15 : rR = aRectangle;
2003 15 : return sal_True;
2004 : }
2005 : else
2006 : {
2007 24 : return sal_False;
2008 : }
2009 : }
2010 :
2011 : // --------------------------------------------------------------------
2012 :
2013 0 : void SdrTableObj::NbcReformatText()
2014 : {
2015 0 : NbcAdjustTextFrameWidthAndHeight();
2016 0 : }
2017 :
2018 : // --------------------------------------------------------------------
2019 :
2020 0 : void SdrTableObj::ReformatText()
2021 : {
2022 0 : Rectangle aBoundRect0;
2023 0 : if (pUserCall!=NULL)
2024 0 : aBoundRect0=GetLastBoundRect();
2025 0 : NbcReformatText();
2026 0 : SetChanged();
2027 0 : BroadcastObjectChange();
2028 0 : SendUserCall(SDRUSERCALL_RESIZE,aBoundRect0);
2029 0 : }
2030 :
2031 : // --------------------------------------------------------------------
2032 :
2033 0 : sal_Bool SdrTableObj::IsVerticalWriting() const
2034 : {
2035 0 : const SvxWritingModeItem* pModeItem = dynamic_cast< const SvxWritingModeItem* >( &GetObjectItem( SDRATTR_TEXTDIRECTION ) );
2036 0 : return pModeItem && pModeItem->GetValue() == com::sun::star::text::WritingMode_TB_RL;
2037 : }
2038 :
2039 : // --------------------------------------------------------------------
2040 :
2041 0 : void SdrTableObj::SetVerticalWriting(sal_Bool bVertical )
2042 : {
2043 0 : if( bVertical != IsVerticalWriting() )
2044 : {
2045 0 : SvxWritingModeItem aModeItem( com::sun::star::text::WritingMode_LR_TB, SDRATTR_TEXTDIRECTION );
2046 0 : SetObjectItem( aModeItem );
2047 : }
2048 0 : }
2049 :
2050 : // --------------------------------------------------------------------
2051 :
2052 139809 : WritingMode SdrTableObj::GetWritingMode() const
2053 : {
2054 139809 : SfxStyleSheet* pStyle = GetStyleSheet();
2055 139809 : if ( !pStyle )
2056 139149 : return WritingMode_LR_TB;
2057 :
2058 660 : WritingMode eWritingMode = WritingMode_LR_TB;
2059 660 : const SfxItemSet &rSet = pStyle->GetItemSet();
2060 : const SfxPoolItem *pItem;
2061 :
2062 660 : if ( rSet.GetItemState( SDRATTR_TEXTDIRECTION, sal_False, &pItem ) == SFX_ITEM_SET )
2063 0 : eWritingMode = static_cast< WritingMode >( static_cast< const SvxWritingModeItem * >( pItem )->GetValue() );
2064 :
2065 1320 : if ( ( eWritingMode != WritingMode_TB_RL ) &&
2066 660 : ( rSet.GetItemState( EE_PARA_WRITINGDIR, sal_False, &pItem ) == SFX_ITEM_SET ) )
2067 : {
2068 0 : if ( static_cast< const SvxFrameDirectionItem * >( pItem )->GetValue() == FRMDIR_HORI_LEFT_TOP )
2069 0 : eWritingMode = WritingMode_LR_TB;
2070 : else
2071 0 : eWritingMode = WritingMode_RL_TB;
2072 : }
2073 :
2074 660 : return eWritingMode;
2075 : }
2076 :
2077 : // --------------------------------------------------------------------
2078 :
2079 : // gets base transformation and rectangle of object. If it's an SdrPathObj it fills the PolyPolygon
2080 : // with the base geometry and returns TRUE. Otherwise it returns FALSE.
2081 2 : sal_Bool SdrTableObj::TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& rPolyPolygon ) const
2082 : {
2083 2 : return SdrTextObj::TRGetBaseGeometry( rMatrix, rPolyPolygon );
2084 : }
2085 :
2086 : // --------------------------------------------------------------------
2087 :
2088 : // sets the base geometry of the object using infos contained in the homogen 3x3 matrix.
2089 : // If it's an SdrPathObj it will use the provided geometry information. The Polygon has
2090 : // to use (0,0) as upper left and will be scaled to the given size in the matrix.
2091 2 : void SdrTableObj::TRSetBaseGeometry(const basegfx::B2DHomMatrix& rMatrix, const basegfx::B2DPolyPolygon& rPolyPolygon )
2092 : {
2093 2 : SdrTextObj::TRSetBaseGeometry( rMatrix, rPolyPolygon );
2094 2 : }
2095 :
2096 : // --------------------------------------------------------------------
2097 :
2098 0 : bool SdrTableObj::IsRealyEdited() const
2099 : {
2100 0 : return pEdtOutl && pEdtOutl->IsModified();
2101 : }
2102 :
2103 : // --------------------------------------------------------------------
2104 :
2105 0 : bool SdrTableObj::IsFontwork() const
2106 : {
2107 0 : return false;
2108 : }
2109 :
2110 : // --------------------------------------------------------------------
2111 :
2112 0 : sal_uInt32 SdrTableObj::GetHdlCount() const
2113 : {
2114 0 : sal_uInt32 nCount = SdrTextObj::GetHdlCount();
2115 0 : const sal_Int32 nRowCount = mpImpl->getRowCount();
2116 0 : const sal_Int32 nColCount = mpImpl->getColumnCount();
2117 :
2118 0 : if( nRowCount && nColCount )
2119 0 : nCount += nRowCount + nColCount + 2 + 1;
2120 :
2121 0 : return nCount;
2122 : }
2123 :
2124 : // --------------------------------------------------------------------
2125 :
2126 0 : void SdrTableObj::AddToHdlList(SdrHdlList& rHdlList) const
2127 : {
2128 0 : const sal_Int32 nRowCount = mpImpl->getRowCount();
2129 0 : const sal_Int32 nColCount = mpImpl->getColumnCount();
2130 :
2131 : // first add row handles
2132 0 : std::vector< TableEdgeHdl* > aRowEdges( nRowCount + 1 );
2133 :
2134 0 : for( sal_Int32 nRow = 0; nRow <= nRowCount; nRow++ )
2135 : {
2136 : sal_Int32 nEdgeMin, nEdgeMax;
2137 0 : const sal_Int32 nEdge = mpImpl->mpLayouter->getHorizontalEdge( nRow, &nEdgeMin, &nEdgeMax );
2138 0 : nEdgeMin -= nEdge;
2139 0 : nEdgeMax -= nEdge;
2140 :
2141 0 : Point aPoint( aRect.TopLeft() );
2142 0 : aPoint.Y() += nEdge;
2143 :
2144 0 : TableEdgeHdl* pHdl= new TableEdgeHdl(aPoint,true,nEdgeMin,nEdgeMax,nColCount+1);
2145 0 : pHdl->SetPointNum( nRow );
2146 0 : rHdlList.AddHdl( pHdl );
2147 0 : aRowEdges[nRow] = pHdl;
2148 : }
2149 :
2150 : // second add column handles
2151 0 : std::vector< TableEdgeHdl* > aColEdges( nColCount + 1 );
2152 :
2153 0 : for( sal_Int32 nCol = 0; nCol <= nColCount; nCol++ )
2154 : {
2155 : sal_Int32 nEdgeMin, nEdgeMax;
2156 0 : const sal_Int32 nEdge = mpImpl->mpLayouter->getVerticalEdge( nCol, &nEdgeMin, &nEdgeMax );
2157 0 : nEdgeMin -= nEdge;
2158 0 : nEdgeMax -= nEdge;
2159 :
2160 0 : Point aPoint( aRect.TopLeft() );
2161 0 : aPoint.X() += nEdge;
2162 :
2163 0 : TableEdgeHdl* pHdl = new TableEdgeHdl(aPoint,false,nEdgeMin,nEdgeMax, nRowCount+1);
2164 0 : pHdl->SetPointNum( nCol );
2165 0 : rHdlList.AddHdl( pHdl );
2166 0 : aColEdges[nCol] = pHdl;
2167 : }
2168 :
2169 : // now add visible edges to row and column handles
2170 0 : if( mpImpl && mpImpl->mpLayouter )
2171 : {
2172 0 : TableLayouter& rLayouter = *mpImpl->mpLayouter;
2173 :
2174 0 : sal_Int32 nY = 0;
2175 :
2176 0 : for( sal_Int32 nRow = 0; nRow <= nRowCount; ++nRow )
2177 : {
2178 0 : const sal_Int32 nRowHeight = (nRow == nRowCount) ? 0 : rLayouter.getRowHeight(nRow);
2179 0 : sal_Int32 nX = 0;
2180 :
2181 0 : for( sal_Int32 nCol = 0; nCol <= nColCount; ++nCol )
2182 : {
2183 0 : const sal_Int32 nColWidth = (nCol == nColCount) ? 0 : rLayouter.getColumnWidth(nCol);
2184 :
2185 0 : if( nRowHeight > 0 )
2186 : {
2187 0 : if( rLayouter.isEdgeVisible( nCol, nRow, false ) )
2188 0 : aColEdges[nCol]->SetEdge( nRow, nY, nY + nRowHeight, (rLayouter.getBorderLine( nCol, nRow, false ) == 0) ? Visible : Invisible);
2189 : }
2190 :
2191 0 : if( nColWidth > 0 )
2192 : {
2193 0 : if( rLayouter.isEdgeVisible( nCol, nRow, true ) )
2194 0 : aRowEdges[nRow]->SetEdge( nCol, nX, nX + nColWidth, (rLayouter.getBorderLine( nCol, nRow, true ) == 0) ? Visible : Invisible);
2195 : }
2196 :
2197 0 : nX += nColWidth;
2198 : }
2199 :
2200 0 : nY += nRowHeight;
2201 : }
2202 : }
2203 :
2204 : // add remaining handles
2205 0 : SdrHdl* pH=0;
2206 0 : rHdlList.AddHdl( pH = new TableBorderHdl( aRect, !IsTextEditActive() ) ); pH->SetMoveOutside( true );
2207 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.TopLeft(),HDL_UPLFT) ); pH->SetMoveOutside( true );
2208 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.TopCenter(),HDL_UPPER) ); pH->SetMoveOutside( true );
2209 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.TopRight(),HDL_UPRGT) ); pH->SetMoveOutside( true );
2210 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.LeftCenter(),HDL_LEFT) ); pH->SetMoveOutside( true );
2211 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.RightCenter(),HDL_RIGHT) ); pH->SetMoveOutside( true );
2212 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.BottomLeft(),HDL_LWLFT) ); pH->SetMoveOutside( true );
2213 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.BottomCenter(),HDL_LOWER) ); pH->SetMoveOutside( true );
2214 0 : rHdlList.AddHdl( pH = new SdrHdl(aRect.BottomRight(),HDL_LWRGT) ); pH->SetMoveOutside( true );
2215 :
2216 0 : sal_uIntPtr nHdlCount = rHdlList.GetHdlCount();
2217 0 : for( sal_uIntPtr nHdl = 0; nHdl < nHdlCount; nHdl++ )
2218 0 : rHdlList.GetHdl(nHdl)->SetObj((SdrObject*)this);
2219 0 : }
2220 :
2221 : // --------------------------------------------------------------------
2222 :
2223 0 : SdrHdl* SdrTableObj::GetHdl(sal_uInt32 nHdlNum) const
2224 : {
2225 : // #i73248#
2226 : // Warn the user that this is ineffective and show alternatives. Should not be used at all.
2227 : OSL_FAIL("SdrTableObj::GetHdl(): ineffective, use AddToHdlList instead (!)");
2228 :
2229 : // to have an alternative, get single handle using the ineffective way
2230 0 : SdrHdl* pRetval = 0;
2231 0 : SdrHdlList aLocalList(0);
2232 0 : AddToHdlList(aLocalList);
2233 0 : const sal_uInt32 nHdlCount(aLocalList.GetHdlCount());
2234 :
2235 0 : if(nHdlCount && nHdlNum < nHdlCount)
2236 : {
2237 : // remove and remember. The other created handles will be deleted again with the
2238 : // destruction of the local list
2239 0 : pRetval = aLocalList.RemoveHdl(nHdlNum);
2240 : }
2241 :
2242 0 : return pRetval;
2243 : }
2244 :
2245 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2246 : // Draging
2247 :
2248 0 : bool SdrTableObj::hasSpecialDrag() const
2249 : {
2250 0 : return true;
2251 : }
2252 :
2253 0 : bool SdrTableObj::beginSpecialDrag(SdrDragStat& rDrag) const
2254 : {
2255 0 : const SdrHdl* pHdl = rDrag.GetHdl();
2256 0 : const SdrHdlKind eHdl((pHdl == NULL) ? HDL_MOVE : pHdl->GetKind());
2257 :
2258 0 : switch( eHdl )
2259 : {
2260 : case HDL_UPLFT:
2261 : case HDL_UPPER:
2262 : case HDL_UPRGT:
2263 : case HDL_LEFT:
2264 : case HDL_RIGHT:
2265 : case HDL_LWLFT:
2266 : case HDL_LOWER:
2267 : case HDL_LWRGT:
2268 : case HDL_MOVE:
2269 : {
2270 0 : break;
2271 : }
2272 :
2273 : case HDL_USER:
2274 : {
2275 0 : rDrag.SetEndDragChangesAttributes(false);
2276 0 : rDrag.SetNoSnap(true);
2277 0 : break;
2278 : }
2279 :
2280 : default:
2281 : {
2282 0 : return false;
2283 : }
2284 : }
2285 :
2286 0 : return true;
2287 : }
2288 :
2289 0 : bool SdrTableObj::applySpecialDrag(SdrDragStat& rDrag)
2290 : {
2291 0 : bool bRet(true);
2292 0 : const SdrHdl* pHdl = rDrag.GetHdl();
2293 0 : const SdrHdlKind eHdl((pHdl == NULL) ? HDL_MOVE : pHdl->GetKind());
2294 :
2295 0 : switch( eHdl )
2296 : {
2297 : case HDL_UPLFT:
2298 : case HDL_UPPER:
2299 : case HDL_UPRGT:
2300 : case HDL_LEFT:
2301 : case HDL_RIGHT:
2302 : case HDL_LWLFT:
2303 : case HDL_LOWER:
2304 : case HDL_LWRGT:
2305 : {
2306 0 : const Rectangle aNewRectangle(ImpDragCalcRect(rDrag));
2307 :
2308 0 : if(aNewRectangle != aRect)
2309 : {
2310 0 : NbcSetLogicRect(aNewRectangle);
2311 : }
2312 :
2313 0 : break;
2314 : }
2315 :
2316 : case HDL_MOVE:
2317 : {
2318 0 : NbcMove( Size( rDrag.GetDX(), rDrag.GetDY() ) );
2319 0 : break;
2320 : }
2321 :
2322 : case HDL_USER:
2323 : {
2324 0 : rDrag.SetEndDragChangesAttributes(false);
2325 0 : rDrag.SetNoSnap(true);
2326 0 : const TableEdgeHdl* pEdgeHdl = dynamic_cast< const TableEdgeHdl* >( pHdl );
2327 :
2328 0 : if( pEdgeHdl )
2329 : {
2330 0 : if( GetModel() && IsInserted() )
2331 : {
2332 0 : rDrag.SetEndDragChangesAttributes(true);
2333 : }
2334 :
2335 0 : mpImpl->DragEdge( pEdgeHdl->IsHorizontalEdge(), pEdgeHdl->GetPointNum(), pEdgeHdl->GetValidDragOffset( rDrag ) );
2336 : }
2337 0 : break;
2338 : }
2339 :
2340 : default:
2341 : {
2342 0 : bRet = false;
2343 : }
2344 : }
2345 :
2346 0 : return bRet;
2347 : }
2348 :
2349 0 : String SdrTableObj::getSpecialDragComment(const SdrDragStat& rDrag) const
2350 : {
2351 0 : return SdrTextObj::getSpecialDragComment( rDrag );
2352 : }
2353 :
2354 0 : basegfx::B2DPolyPolygon SdrTableObj::getSpecialDragPoly(const SdrDragStat& rDrag) const
2355 : {
2356 0 : basegfx::B2DPolyPolygon aRetval;
2357 0 : const SdrHdl* pHdl = rDrag.GetHdl();
2358 :
2359 0 : if( pHdl && (HDL_USER == pHdl->GetKind()) )
2360 : {
2361 0 : const TableEdgeHdl* pEdgeHdl = dynamic_cast< const TableEdgeHdl* >( pHdl );
2362 :
2363 0 : if( pEdgeHdl )
2364 : {
2365 0 : aRetval = pEdgeHdl->getSpecialDragPoly( rDrag );
2366 : }
2367 : }
2368 :
2369 0 : return aRetval;
2370 : }
2371 :
2372 : ////////////////////////////////////////////////////////////////////////////////////////////////////
2373 : // Create
2374 : // --------------------------------------------------------------------
2375 :
2376 0 : bool SdrTableObj::BegCreate(SdrDragStat& rStat)
2377 : {
2378 0 : rStat.SetOrtho4Possible();
2379 0 : Rectangle aRect1(rStat.GetStart(), rStat.GetNow());
2380 0 : aRect1.Justify();
2381 0 : rStat.SetActionRect(aRect1);
2382 0 : aRect = aRect1;
2383 0 : return true;
2384 : }
2385 :
2386 : // --------------------------------------------------------------------
2387 :
2388 0 : bool SdrTableObj::MovCreate(SdrDragStat& rStat)
2389 : {
2390 0 : Rectangle aRect1;
2391 0 : rStat.TakeCreateRect(aRect1);
2392 0 : ImpJustifyRect(aRect1);
2393 0 : rStat.SetActionRect(aRect1);
2394 0 : aRect=aRect1; // fuer ObjName
2395 0 : SetBoundRectDirty();
2396 0 : bSnapRectDirty=sal_True;
2397 0 : return true;
2398 : }
2399 :
2400 : // --------------------------------------------------------------------
2401 :
2402 0 : bool SdrTableObj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
2403 : {
2404 0 : rStat.TakeCreateRect(aRect);
2405 0 : ImpJustifyRect(aRect);
2406 0 : return (eCmd==SDRCREATE_FORCEEND || rStat.GetPointAnz()>=2);
2407 : }
2408 :
2409 0 : void SdrTableObj::BrkCreate(SdrDragStat& /*rStat*/)
2410 : {
2411 0 : }
2412 :
2413 : // --------------------------------------------------------------------
2414 :
2415 0 : bool SdrTableObj::BckCreate(SdrDragStat& /*rStat*/)
2416 : {
2417 0 : return true;
2418 : }
2419 :
2420 : // --------------------------------------------------------------------
2421 :
2422 0 : basegfx::B2DPolyPolygon SdrTableObj::TakeCreatePoly(const SdrDragStat& rDrag) const
2423 : {
2424 0 : Rectangle aRect1;
2425 0 : rDrag.TakeCreateRect(aRect1);
2426 0 : aRect1.Justify();
2427 :
2428 0 : basegfx::B2DPolyPolygon aRetval;
2429 0 : const basegfx::B2DRange aRange(aRect1.Left(), aRect1.Top(), aRect1.Right(), aRect1.Bottom());
2430 0 : aRetval.append(basegfx::tools::createPolygonFromRect(aRange));
2431 0 : return aRetval;
2432 : }
2433 :
2434 : // --------------------------------------------------------------------
2435 :
2436 0 : Pointer SdrTableObj::GetCreatePointer() const
2437 : {
2438 0 : return Pointer(POINTER_CROSS);
2439 : }
2440 :
2441 : // --------------------------------------------------------------------
2442 :
2443 407 : void SdrTableObj::createCell( CellRef& xNewCell )
2444 : {
2445 407 : xNewCell = Cell::create( *this, 0 );
2446 407 : }
2447 :
2448 : // --------------------------------------------------------------------
2449 :
2450 0 : SdrObjGeoData *SdrTableObj::NewGeoData() const
2451 : {
2452 0 : return new TableObjectGeoData;
2453 : }
2454 :
2455 : // --------------------------------------------------------------------
2456 :
2457 0 : void SdrTableObj::SaveGeoData(SdrObjGeoData& rGeo) const
2458 : {
2459 : DBG_ASSERT( dynamic_cast< TableObjectGeoData* >( &rGeo ), "svx::SdrTableObj::SaveGeoData(), illegal geo data!" );
2460 0 : SdrTextObj::SaveGeoData (rGeo);
2461 :
2462 0 : ((TableObjectGeoData &) rGeo).maLogicRect = maLogicRect;
2463 0 : }
2464 :
2465 : // --------------------------------------------------------------------
2466 :
2467 0 : void SdrTableObj::RestGeoData(const SdrObjGeoData& rGeo)
2468 : {
2469 : DBG_ASSERT( dynamic_cast< const TableObjectGeoData* >( &rGeo ), "svx::SdrTableObj::SaveGeoData(), illegal geo data!" );
2470 :
2471 0 : maLogicRect = ((TableObjectGeoData &) rGeo).maLogicRect;
2472 :
2473 0 : SdrTextObj::RestGeoData (rGeo);
2474 :
2475 0 : if( mpImpl )
2476 0 : mpImpl->LayoutTable( aRect, false, false );
2477 0 : ActionChanged();
2478 0 : }
2479 :
2480 : // --------------------------------------------------------------------
2481 :
2482 0 : SdrTableObj* SdrTableObj::CloneRange( const CellPos& rStart, const CellPos& rEnd )
2483 : {
2484 0 : const sal_Int32 nColumns = rEnd.mnCol - rStart.mnCol + 1;
2485 0 : const sal_Int32 nRows = rEnd.mnRow - rStart.mnRow + 1;
2486 :
2487 0 : SdrTableObj* pNewTableObj = new SdrTableObj( GetModel(), GetCurrentBoundRect(), nColumns, nRows);
2488 0 : pNewTableObj->setTableStyleSettings( getTableStyleSettings() );
2489 0 : pNewTableObj->setTableStyle( getTableStyle() );
2490 :
2491 0 : Reference< XTable > xTable( getTable() );
2492 0 : Reference< XTable > xNewTable( pNewTableObj->getTable() );
2493 :
2494 0 : if( !xTable.is() || !xNewTable.is() )
2495 : {
2496 0 : delete pNewTableObj;
2497 0 : return 0;
2498 : }
2499 :
2500 : // copy cells
2501 0 : for( sal_Int32 nRow = 0; nRow < nRows; ++nRow )
2502 : {
2503 0 : for( sal_Int32 nCol = 0; nCol < nColumns; ++nCol ) try
2504 : {
2505 0 : CellRef xTargetCell( dynamic_cast< Cell* >( xNewTable->getCellByPosition( nCol, nRow ).get() ) );
2506 0 : if( xTargetCell.is() )
2507 0 : xTargetCell->cloneFrom( dynamic_cast< Cell* >( xTable->getCellByPosition( rStart.mnCol + nCol, rStart.mnRow + nRow ).get() ) );
2508 : }
2509 0 : catch( Exception& )
2510 : {
2511 : OSL_FAIL( "svx::SvxTableController::GetMarkedObjModel(), exception caught!" );
2512 : }
2513 : }
2514 :
2515 : // copy row heights
2516 0 : Reference< XTableRows > xNewRows( xNewTable->getRows(), UNO_QUERY_THROW );
2517 0 : const OUString sHeight( "Height" );
2518 0 : for( sal_Int32 nRow = 0; nRow < nRows; ++nRow )
2519 : {
2520 0 : Reference< XPropertySet > xNewSet( xNewRows->getByIndex( nRow ), UNO_QUERY_THROW );
2521 0 : xNewSet->setPropertyValue( sHeight, Any( mpImpl->mpLayouter->getRowHeight( rStart.mnRow + nRow ) ) );
2522 0 : }
2523 :
2524 : // copy column widths
2525 0 : Reference< XTableColumns > xNewColumns( xNewTable->getColumns(), UNO_QUERY_THROW );
2526 0 : const OUString sWidth( "Width" );
2527 0 : for( sal_Int32 nCol = 0; nCol < nColumns; ++nCol )
2528 : {
2529 0 : Reference< XPropertySet > xNewSet( xNewColumns->getByIndex( nCol ), UNO_QUERY_THROW );
2530 0 : xNewSet->setPropertyValue( sWidth, Any( mpImpl->mpLayouter->getColumnWidth( rStart.mnCol + nCol ) ) );
2531 0 : }
2532 :
2533 0 : pNewTableObj->NbcReformatText();
2534 0 : pNewTableObj->SetLogicRect( pNewTableObj->GetCurrentBoundRect() );
2535 :
2536 0 : return pNewTableObj;
2537 : }
2538 :
2539 : // --------------------------------------------------------------------
2540 :
2541 0 : void SdrTableObj::DistributeColumns( sal_Int32 nFirstColumn, sal_Int32 nLastColumn )
2542 : {
2543 0 : if( mpImpl && mpImpl->mpLayouter )
2544 : {
2545 0 : TableModelNotifyGuard aGuard( mpImpl->mxTable.get() );
2546 0 : mpImpl->mpLayouter->DistributeColumns( aRect, nFirstColumn, nLastColumn );
2547 : }
2548 0 : }
2549 :
2550 : // --------------------------------------------------------------------
2551 :
2552 0 : void SdrTableObj::DistributeRows( sal_Int32 nFirstRow, sal_Int32 nLastRow )
2553 : {
2554 0 : if( mpImpl && mpImpl->mpLayouter )
2555 : {
2556 0 : TableModelNotifyGuard aGuard( mpImpl->mxTable.get() );
2557 0 : mpImpl->mpLayouter->DistributeRows( aRect, nFirstRow, nLastRow );
2558 : }
2559 0 : }
2560 :
2561 : // --------------------------------------------------------------------
2562 :
2563 4611 : void SdrTableObj::SetChanged()
2564 : {
2565 4611 : if( mpImpl )
2566 : {
2567 4611 : mpImpl->LayoutTable( aRect, false, false );
2568 : }
2569 :
2570 4611 : ::SdrTextObj::SetChanged();
2571 4611 : }
2572 :
2573 : // --------------------------------------------------------------------
2574 :
2575 35 : void SdrTableObj::uno_lock()
2576 : {
2577 35 : if( mpImpl && mpImpl->mxTable.is() )
2578 35 : mpImpl->mxTable->lockBroadcasts();
2579 35 : }
2580 :
2581 : // --------------------------------------------------------------------
2582 :
2583 35 : void SdrTableObj::uno_unlock()
2584 : {
2585 35 : if( mpImpl && mpImpl->mxTable.is() )
2586 35 : mpImpl->mxTable->unlockBroadcasts();
2587 35 : }
2588 :
2589 : // --------------------------------------------------------------------
2590 :
2591 :
2592 :
2593 258 : } }
2594 :
2595 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|