bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / table / TableDesignPane.cxx
blob206a08bb0993b543610e0705384416840f5f4a67
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "sddll.hxx"
22 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
23 #include <com/sun/star/frame/XController.hpp>
24 #include <com/sun/star/view/XSelectionSupplier.hpp>
25 #include <com/sun/star/style/XStyle.hpp>
26 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
28 #include <comphelper/processfactory.hxx>
29 #include <sfx2/viewfrm.hxx>
30 #include <vcl/bmpacc.hxx>
31 #include <vcl/layout.hxx>
32 #include <vcl/settings.hxx>
33 #include <vcl/builderfactory.hxx>
35 #include <svl/style.hxx>
36 #include <sfx2/bindings.hxx>
37 #include <sfx2/app.hxx>
38 #include <sfx2/request.hxx>
39 #include <sfx2/dispatch.hxx>
40 #include <svx/svxids.hrc>
41 #include <svx/svdetc.hxx>
42 #include <editeng/boxitem.hxx>
43 #include <editeng/borderline.hxx>
44 #include <editeng/colritem.hxx>
45 #include <editeng/eeitem.hxx>
46 #include <svx/sdr/table/tabledesign.hxx>
47 #include <o3tl/enumrange.hxx>
49 #include "TableDesignPane.hxx"
50 #include "createtabledesignpanel.hxx"
52 #include "DrawDocShell.hxx"
53 #include "ViewShellBase.hxx"
54 #include "DrawViewShell.hxx"
55 #include "DrawController.hxx"
56 #include "glob.hrc"
57 #include "sdresid.hxx"
58 #include "EventMultiplexer.hxx"
60 using namespace ::com::sun::star;
61 using namespace ::com::sun::star::uno;
62 using namespace ::com::sun::star::drawing;
63 using namespace ::com::sun::star::container;
64 using namespace ::com::sun::star::beans;
65 using namespace ::com::sun::star::view;
66 using namespace ::com::sun::star::style;
67 using namespace ::com::sun::star::frame;
68 using namespace ::com::sun::star::lang;
69 using namespace ::com::sun::star::ui;
71 namespace sd {
73 static const sal_Int32 nPreviewColumns = 5;
74 static const sal_Int32 nPreviewRows = 5;
75 static const sal_Int32 nCellWidth = 12; // one pixel is shared with the next cell!
76 static const sal_Int32 nCellHeight = 7; // one pixel is shared with the next cell!
77 static const sal_Int32 nBitmapWidth = (nCellWidth * nPreviewColumns) - (nPreviewColumns - 1);
78 static const sal_Int32 nBitmapHeight = (nCellHeight * nPreviewRows) - (nPreviewRows - 1);
80 static const OUString* getPropertyNames()
82 static const OUString gPropNames[ CB_COUNT ] =
84 OUString("UseFirstRowStyle") ,
85 OUString("UseLastRowStyle") ,
86 OUString("UseBandingRowStyle") ,
87 OUString("UseFirstColumnStyle") ,
88 OUString("UseLastColumnStyle") ,
89 OUString("UseBandingColumnStyle")
91 return &gPropNames[0];
94 TableDesignWidget::TableDesignWidget( VclBuilderContainer* pParent, ViewShellBase& rBase, bool bModal )
95 : mrBase(rBase)
96 , mbModal(bModal)
97 , mbStyleSelected(false)
98 , mbOptionsChanged(false)
100 pParent->get(m_pValueSet, "previews");
101 m_pValueSet->SetStyle(m_pValueSet->GetStyle() | WB_NO_DIRECTSELECT | WB_FLATVALUESET | WB_ITEMBORDER);
102 m_pValueSet->SetExtraSpacing(8);
103 m_pValueSet->setModal(mbModal);
104 if( !mbModal )
106 m_pValueSet->SetColor();
108 else
110 m_pValueSet->SetColor( Color( COL_WHITE ) );
111 m_pValueSet->SetBackground( Color( COL_WHITE ) );
113 m_pValueSet->SetSelectHdl (LINK(this, TableDesignWidget, implValueSetHdl));
115 const OUString* pPropNames = getPropertyNames();
116 for (sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i)
118 pParent->get(m_aCheckBoxes[i], OUStringToOString(pPropNames[i], RTL_TEXTENCODING_UTF8));
119 m_aCheckBoxes[i]->SetClickHdl( LINK( this, TableDesignWidget, implCheckBoxHdl ) );
122 // get current controller and initialize listeners
125 mxView = Reference< XDrawView >::query(mrBase.GetController());
126 addListener();
128 Reference< XController > xController( mrBase.GetController(), UNO_QUERY_THROW );
129 Reference< XStyleFamiliesSupplier > xFamiliesSupp( xController->getModel(), UNO_QUERY_THROW );
130 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
131 const OUString sFamilyName( "table" );
132 mxTableFamily = Reference< XIndexAccess >( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
134 catch (const Exception&)
136 OSL_FAIL( "sd::CustomAnimationPane::CustomAnimationPane(), Exception caught!" );
139 onSelectionChanged();
140 updateControls();
143 TableDesignWidget::~TableDesignWidget()
145 removeListener();
148 static SfxBindings* getBindings( ViewShellBase& rBase )
150 if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
151 return &rBase.GetMainViewShell()->GetViewFrame()->GetBindings();
152 else
153 return 0;
156 static SfxDispatcher* getDispatcher( ViewShellBase& rBase )
158 if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
159 return rBase.GetMainViewShell()->GetViewFrame()->GetDispatcher();
160 else
161 return 0;
164 IMPL_LINK_NOARG(TableDesignWidget, implValueSetHdl)
166 mbStyleSelected = true;
167 if( !mbModal )
168 ApplyStyle();
169 return 0;
172 void TableDesignWidget::ApplyStyle()
176 OUString sStyleName;
177 sal_Int32 nIndex = static_cast< sal_Int32 >( m_pValueSet->GetSelectItemId() ) - 1;
179 if( (nIndex >= 0) && (nIndex < mxTableFamily->getCount()) )
181 Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY_THROW );
182 sStyleName = xNames->getElementNames()[nIndex];
185 if( sStyleName.isEmpty() )
186 return;
188 SdrView* pView = mrBase.GetDrawView();
189 if( mxSelectedTable.is() )
191 if( pView )
193 SfxRequest aReq( SID_TABLE_STYLE, SfxCallMode::SYNCHRON, SfxGetpApp()->GetPool() );
194 aReq.AppendItem( SfxStringItem( SID_TABLE_STYLE, sStyleName ) );
196 rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() );
197 if( xController.is() )
198 xController->Execute( aReq );
200 SfxBindings* pBindings = getBindings( mrBase );
201 if( pBindings )
203 pBindings->Invalidate( SID_UNDO );
204 pBindings->Invalidate( SID_REDO );
208 else
210 SfxDispatcher* pDispatcher = getDispatcher( mrBase );
211 SfxStringItem aArg( SID_TABLE_STYLE, sStyleName );
212 pDispatcher->Execute(SID_INSERT_TABLE, SfxCallMode::ASYNCHRON, &aArg, 0 );
215 catch( Exception& )
217 OSL_FAIL("TableDesignWidget::implValueSetHdl(), exception caught!");
221 IMPL_LINK_NOARG(TableDesignWidget, implCheckBoxHdl)
223 mbOptionsChanged = true;
225 if( !mbModal )
226 ApplyOptions();
228 FillDesignPreviewControl();
229 return 0;
232 void TableDesignWidget::ApplyOptions()
234 static const sal_uInt16 gParamIds[CB_COUNT] =
236 ID_VAL_USEFIRSTROWSTYLE, ID_VAL_USELASTROWSTYLE, ID_VAL_USEBANDINGROWSTYLE,
237 ID_VAL_USEFIRSTCOLUMNSTYLE, ID_VAL_USELASTCOLUMNSTYLE, ID_VAL_USEBANDINGCOLUMNSTYLE
240 if( mxSelectedTable.is() )
242 SfxRequest aReq( SID_TABLE_STYLE_SETTINGS, SfxCallMode::SYNCHRON, SfxGetpApp()->GetPool() );
244 for( sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i )
246 aReq.AppendItem( SfxBoolItem( gParamIds[i], m_aCheckBoxes[i]->IsChecked() ) );
249 SdrView* pView = mrBase.GetDrawView();
250 if( pView )
252 rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() );
253 if( xController.is() )
255 xController->Execute( aReq );
257 SfxBindings* pBindings = getBindings( mrBase );
258 if( pBindings )
260 pBindings->Invalidate( SID_UNDO );
261 pBindings->Invalidate( SID_REDO );
268 void TableDesignWidget::onSelectionChanged()
270 Reference< XPropertySet > xNewSelection;
272 if( mxView.is() ) try
274 Reference< XSelectionSupplier > xSel( mxView, UNO_QUERY_THROW );
275 if (xSel.is())
277 Any aSel( xSel->getSelection() );
278 Sequence< XShape > xShapeSeq;
279 if( aSel >>= xShapeSeq )
281 if( xShapeSeq.getLength() == 1 )
282 aSel <<= xShapeSeq[0];
284 else
286 Reference< XShapes > xShapes( aSel, UNO_QUERY );
287 if( xShapes.is() && (xShapes->getCount() == 1) )
288 aSel <<= xShapes->getByIndex(0);
291 Reference< XShapeDescriptor > xDesc( aSel, UNO_QUERY );
292 if( xDesc.is() && ( xDesc->getShapeType() == "com.sun.star.drawing.TableShape" || xDesc->getShapeType() == "com.sun.star.presentation.TableShape" ) )
294 xNewSelection = Reference< XPropertySet >::query( xDesc );
298 catch( Exception& )
300 OSL_FAIL( "sd::TableDesignWidget::onSelectionChanged(), Exception caught!" );
303 if( mxSelectedTable != xNewSelection )
305 mxSelectedTable = xNewSelection;
306 updateControls();
310 void TableValueSet::Resize()
312 ValueSet::Resize();
313 // Calculate the number of rows and columns.
314 if( GetItemCount() > 0 )
316 Size aValueSetSize = GetSizePixel();
318 Image aImage = GetItemImage(GetItemId(0));
319 Size aItemSize = aImage.GetSizePixel();
321 aItemSize.Width() += 10;
322 aItemSize.Height() += 10;
323 int nColumnCount = (aValueSetSize.Width() - GetScrollWidth()) / aItemSize.Width();
324 if (nColumnCount < 1)
325 nColumnCount = 1;
327 int nRowCount = (GetItemCount() + nColumnCount - 1) / nColumnCount;
328 if (nRowCount < 1)
329 nRowCount = 1;
331 int nVisibleRowCount = (aValueSetSize.Height()+2) / aItemSize.Height();
333 SetColCount ((sal_uInt16)nColumnCount);
334 SetLineCount ((sal_uInt16)nRowCount);
336 if( !m_bModal )
338 WinBits nStyle = GetStyle() & ~(WB_VSCROLL);
339 if( nRowCount > nVisibleRowCount )
341 nStyle |= WB_VSCROLL;
343 SetStyle( nStyle );
348 TableValueSet::TableValueSet(Window *pParent, WinBits nStyle)
349 : ValueSet(pParent, nStyle)
350 , m_bModal(false)
354 void TableValueSet::DataChanged( const DataChangedEvent& /*rDCEvt*/ )
356 updateSettings();
359 void TableValueSet::updateSettings()
361 if( !m_bModal )
363 SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
364 SetColor( GetSettings().GetStyleSettings().GetWindowColor() );
365 SetExtraSpacing(8);
369 VCL_BUILDER_DECL_FACTORY(TableValueSet)
371 WinBits nWinStyle = WB_TABSTOP;
372 OString sBorder = VclBuilder::extractCustomProperty(rMap);
373 if (!sBorder.isEmpty())
374 nWinStyle |= WB_BORDER;
375 rRet = VclPtr<TableValueSet>::Create(pParent, nWinStyle);
378 void TableDesignWidget::updateControls()
380 static const sal_Bool gDefaults[CB_COUNT] = { sal_True, sal_False, sal_True, sal_False, sal_False, sal_False };
382 const bool bHasTable = mxSelectedTable.is();
383 const OUString* pPropNames = getPropertyNames();
385 for (sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i)
387 bool bUse = gDefaults[i];
388 if( bHasTable ) try
390 mxSelectedTable->getPropertyValue( *pPropNames++ ) >>= bUse;
392 catch( Exception& )
394 OSL_FAIL("sd::TableDesignWidget::updateControls(), exception caught!");
396 m_aCheckBoxes[i]->Check(bUse);
397 m_aCheckBoxes[i]->Enable(bHasTable);
400 FillDesignPreviewControl();
401 m_pValueSet->updateSettings();
402 m_pValueSet->Resize();
404 sal_uInt16 nSelection = 0;
405 if( mxSelectedTable.is() )
407 Reference< XNamed > xNamed( mxSelectedTable->getPropertyValue( "TableTemplate" ), UNO_QUERY );
408 if( xNamed.is() )
410 const OUString sStyleName( xNamed->getName() );
412 Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY );
413 if( xNames.is() )
415 Sequence< OUString > aNames( xNames->getElementNames() );
416 for( sal_Int32 nIndex = 0; nIndex < aNames.getLength(); nIndex++ )
418 if( aNames[nIndex] == sStyleName )
420 nSelection = (sal_uInt16)nIndex+1;
421 break;
427 m_pValueSet->SelectItem( nSelection );
430 void TableDesignWidget::addListener()
432 Link<> aLink( LINK(this,TableDesignWidget,EventMultiplexerListener) );
433 mrBase.GetEventMultiplexer()->AddEventListener (
434 aLink,
435 tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
436 | tools::EventMultiplexerEvent::EID_CURRENT_PAGE
437 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
438 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
439 | tools::EventMultiplexerEvent::EID_DISPOSING);
442 void TableDesignWidget::removeListener()
444 Link<> aLink( LINK(this,TableDesignWidget,EventMultiplexerListener) );
445 mrBase.GetEventMultiplexer()->RemoveEventListener( aLink );
448 IMPL_LINK(TableDesignWidget,EventMultiplexerListener,
449 tools::EventMultiplexerEvent*,pEvent)
451 switch (pEvent->meEventId)
453 case tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
454 case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION:
455 onSelectionChanged();
456 break;
458 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
459 mxView.clear();
460 onSelectionChanged();
461 break;
463 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
464 mxView = Reference<XDrawView>::query( mrBase.GetController() );
465 onSelectionChanged();
466 break;
468 return 0;
471 struct CellInfo
473 Color maCellColor;
474 Color maTextColor;
475 SvxBoxItem maBorder;
477 explicit CellInfo( const Reference< XStyle >& xStyle );
480 CellInfo::CellInfo( const Reference< XStyle >& xStyle )
481 : maBorder(SDRATTR_TABLE_BORDER)
483 SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );
484 if( pStyleSheet )
486 SfxItemSet& rSet = pStyleSheet->GetItemSet();
488 // get style fill color
489 if( !GetDraftFillColor(rSet, maCellColor) )
490 maCellColor.SetColor( COL_TRANSPARENT );
492 // get style text color
493 const SvxColorItem* pTextColor = dynamic_cast<const SvxColorItem*>( rSet.GetItem(EE_CHAR_COLOR) );
494 if( pTextColor )
495 maTextColor = pTextColor->GetValue();
496 else
497 maTextColor.SetColor( COL_TRANSPARENT );
499 // get border
500 const SvxBoxItem* pBoxItem = dynamic_cast<const SvxBoxItem*>(rSet.GetItem( SDRATTR_TABLE_BORDER ) );
501 if( pBoxItem )
502 maBorder = *pBoxItem;
506 typedef std::vector< boost::shared_ptr< CellInfo > > CellInfoVector;
507 typedef boost::shared_ptr< CellInfo > CellInfoMatrix[nPreviewColumns][nPreviewRows];
509 struct TableStyleSettings
511 bool mbUseFirstRow;
512 bool mbUseLastRow;
513 bool mbUseFirstColumn;
514 bool mbUseLastColumn;
515 bool mbUseRowBanding;
516 bool mbUseColumnBanding;
518 TableStyleSettings()
519 : mbUseFirstRow(true)
520 , mbUseLastRow(false)
521 , mbUseFirstColumn(false)
522 , mbUseLastColumn(false)
523 , mbUseRowBanding(true)
524 , mbUseColumnBanding(false) {}
527 static void FillCellInfoVector( const Reference< XIndexAccess >& xTableStyle, CellInfoVector& rVector )
529 DBG_ASSERT( xTableStyle.is() && (xTableStyle->getCount() == sdr::table::style_count ), "sd::FillCellInfoVector(), invalid table style!" );
530 if( xTableStyle.is() ) try
532 rVector.resize( sdr::table::style_count );
534 for( sal_Int32 nStyle = 0; nStyle < sdr::table::style_count; ++nStyle )
536 Reference< XStyle > xStyle( xTableStyle->getByIndex( nStyle ), UNO_QUERY );
537 if( xStyle.is() )
538 rVector[nStyle].reset( new CellInfo( xStyle ) );
541 catch(Exception&)
543 OSL_FAIL("sd::FillCellInfoVector(), exception caught!");
547 static void FillCellInfoMatrix( const CellInfoVector& rStyle, const TableStyleSettings& rSettings, CellInfoMatrix& rMatrix )
549 for( sal_Int32 nRow = 0; nRow < nPreviewColumns; ++nRow )
551 const bool bFirstRow = rSettings.mbUseFirstRow && (nRow == 0);
552 const bool bLastRow = rSettings.mbUseLastRow && (nRow == nPreviewColumns - 1);
554 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol )
556 boost::shared_ptr< CellInfo > xCellInfo;
558 // first and last row win first, if used and available
559 if( bFirstRow )
561 xCellInfo = rStyle[sdr::table::first_row_style];
563 else if( bLastRow )
565 xCellInfo = rStyle[sdr::table::last_row_style];
568 if( !xCellInfo.get() )
570 // next come first and last column, if used and available
571 if( rSettings.mbUseFirstColumn && (nCol == 0) )
573 xCellInfo = rStyle[sdr::table::first_column_style];
575 else if( rSettings.mbUseLastColumn && (nCol == nPreviewColumns-1) )
577 xCellInfo = rStyle[sdr::table::last_column_style];
581 if( !xCellInfo.get() )
583 if( rSettings.mbUseRowBanding )
585 if( (nRow & 1) == 0 )
587 xCellInfo = rStyle[sdr::table::even_rows_style];
589 else
591 xCellInfo = rStyle[sdr::table::odd_rows_style];
596 if( !xCellInfo.get() )
598 if( rSettings.mbUseColumnBanding )
600 if( (nCol & 1) == 0 )
602 xCellInfo = rStyle[sdr::table::even_columns_style];
604 else
606 xCellInfo = rStyle[sdr::table::odd_columns_style];
611 if( !xCellInfo.get() )
613 // use default cell style if non found yet
614 xCellInfo = rStyle[sdr::table::body_style];
617 rMatrix[nCol][nRow] = xCellInfo;
622 const Bitmap CreateDesignPreview( const Reference< XIndexAccess >& xTableStyle, const TableStyleSettings& rSettings, bool bIsPageDark )
624 CellInfoVector aCellInfoVector(sdr::table::style_count);
625 FillCellInfoVector( xTableStyle, aCellInfoVector );
627 CellInfoMatrix aMatrix;
628 FillCellInfoMatrix( aCellInfoVector, rSettings, aMatrix );
630 // bbbbbbbbbbbb w = 12 pixel
631 // bccccccccccb h = 7 pixel
632 // bccccccccccb b = border color
633 // bcttttttttcb c = cell color
634 // bccccccccccb t = text color
635 // bccccccccccb
636 // bbbbbbbbbbbb
638 Bitmap aPreviewBmp( Size( nBitmapWidth, nBitmapHeight), 24, NULL );
639 BitmapWriteAccess* pAccess = aPreviewBmp.AcquireWriteAccess();
640 if( pAccess )
642 pAccess->Erase( Color( bIsPageDark ? COL_BLACK : COL_WHITE ) );
644 // first draw cell background and text line previews
645 sal_Int32 nY = 0;
646 sal_Int32 nRow;
647 for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 )
649 sal_Int32 nX = 0;
650 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 )
652 boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] );
654 Color aTextColor( COL_AUTO );
655 if( xCellInfo.get() )
657 // fill cell background
658 const Rectangle aRect( nX, nY, nX + nCellWidth - 1, nY + nCellHeight - 1 );
660 if( xCellInfo->maCellColor.GetColor() != COL_TRANSPARENT )
662 pAccess->SetFillColor( xCellInfo->maCellColor );
663 pAccess->FillRect( aRect );
666 aTextColor = xCellInfo->maTextColor;
669 // draw text preview line
670 if( aTextColor.GetColor() == COL_AUTO )
671 aTextColor.SetColor( bIsPageDark ? COL_WHITE : COL_BLACK );
672 pAccess->SetLineColor( aTextColor );
673 const Point aPnt1( nX + 2, nY + ((nCellHeight - 1 ) >> 1) );
674 const Point aPnt2( nX + nCellWidth - 3, aPnt1.Y() );
675 pAccess->DrawLine( aPnt1, aPnt2 );
679 // second draw border lines
680 nY = 0;
681 for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 )
683 sal_Int32 nX = 0;
684 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 )
686 boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] );
688 if( xCellInfo.get() )
690 const Point aPntTL( nX, nY );
691 const Point aPntTR( nX + nCellWidth - 1, nY );
692 const Point aPntBL( nX, nY + nCellHeight - 1 );
693 const Point aPntBR( nX + nCellWidth - 1, nY + nCellHeight - 1 );
695 sal_Int32 border_diffs[8] = { 0,-1, 0,1, -1,0, 1,0 };
696 sal_Int32* pDiff = &border_diffs[0];
698 // draw top border
699 for( SvxBoxItemLine nLine : o3tl::enumrange<SvxBoxItemLine>() )
701 const ::editeng::SvxBorderLine* pBorderLine = xCellInfo->maBorder.GetLine(nLine);
702 if( !pBorderLine || ((pBorderLine->GetOutWidth() == 0) && (pBorderLine->GetInWidth()==0)) )
703 continue;
705 sal_Int32 nBorderCol = nCol + *pDiff++;
706 sal_Int32 nBorderRow = nRow + *pDiff++;
707 if( (nBorderCol >= 0) && (nBorderCol < nPreviewColumns) && (nBorderRow >= 0) && (nBorderRow < nPreviewRows) )
709 // check border
710 boost::shared_ptr< CellInfo > xBorderInfo( aMatrix[nBorderCol][nBorderRow] );
711 if( xBorderInfo.get() )
713 const ::editeng::SvxBorderLine* pBorderLine2 = xBorderInfo->maBorder.GetLine(static_cast<SvxBoxItemLine>(static_cast<int>(nLine)^1));
714 if( pBorderLine2 && pBorderLine2->HasPriority(*pBorderLine) )
715 continue; // other border line wins
719 pAccess->SetLineColor( pBorderLine->GetColor() );
720 switch( nLine )
722 case SvxBoxItemLine::TOP: pAccess->DrawLine( aPntTL, aPntTR ); break;
723 case SvxBoxItemLine::BOTTOM: pAccess->DrawLine( aPntBL, aPntBR ); break;
724 case SvxBoxItemLine::LEFT: pAccess->DrawLine( aPntTL, aPntBL ); break;
725 case SvxBoxItemLine::RIGHT: pAccess->DrawLine( aPntTR, aPntBR ); break;
732 Bitmap::ReleaseAccess( pAccess );
735 return aPreviewBmp;
738 void TableDesignWidget::FillDesignPreviewControl()
740 sal_uInt16 nSelectedItem = m_pValueSet->GetSelectItemId();
741 m_pValueSet->Clear();
744 TableStyleSettings aSettings;
745 if( mxSelectedTable.is() )
747 aSettings.mbUseFirstRow = m_aCheckBoxes[CB_HEADER_ROW]->IsChecked();
748 aSettings.mbUseLastRow = m_aCheckBoxes[CB_TOTAL_ROW]->IsChecked();
749 aSettings.mbUseRowBanding = m_aCheckBoxes[CB_BANDED_ROWS]->IsChecked();
750 aSettings.mbUseFirstColumn = m_aCheckBoxes[CB_FIRST_COLUMN]->IsChecked();
751 aSettings.mbUseLastColumn = m_aCheckBoxes[CB_LAST_COLUMN]->IsChecked();
752 aSettings.mbUseColumnBanding = m_aCheckBoxes[CB_BANDED_COLUMNS]->IsChecked();
755 bool bIsPageDark = false;
756 if( mxView.is() )
758 Reference< XPropertySet > xPageSet( mxView->getCurrentPage(), UNO_QUERY );
759 if( xPageSet.is() )
761 const OUString sIsBackgroundDark( "IsBackgroundDark" );
762 xPageSet->getPropertyValue(sIsBackgroundDark) >>= bIsPageDark;
766 sal_Int32 nCount = mxTableFamily->getCount();
767 for( sal_Int32 nIndex = 0; nIndex < nCount; ++nIndex ) try
769 Reference< XIndexAccess > xTableStyle( mxTableFamily->getByIndex( nIndex ), UNO_QUERY );
770 if( xTableStyle.is() )
771 m_pValueSet->InsertItem( sal::static_int_cast<sal_uInt16>( nIndex + 1 ), Image( CreateDesignPreview( xTableStyle, aSettings, bIsPageDark ) ) );
773 catch( Exception& )
775 OSL_FAIL("sd::TableDesignWidget::FillDesignPreviewControl(), exception caught!");
777 sal_Int32 nCols = 3;
778 sal_Int32 nRows = (nCount+2)/3;
779 m_pValueSet->SetColCount(nCols);
780 m_pValueSet->SetLineCount(nRows);
781 WinBits nStyle = m_pValueSet->GetStyle() & ~(WB_VSCROLL);
782 m_pValueSet->SetStyle(nStyle);
783 Size aSize(m_pValueSet->GetOptimalSize());
784 aSize.Width() += (10 * nCols);
785 aSize.Height() += (10 * nRows);
786 m_pValueSet->set_width_request(aSize.Width());
787 m_pValueSet->set_height_request(aSize.Height());
789 catch( Exception& )
791 OSL_FAIL("sd::TableDesignWidget::FillDesignPreviewControl(), exception caught!");
793 m_pValueSet->SelectItem(nSelectedItem);
796 short TableDesignDialog::Execute()
798 if( ModalDialog::Execute() )
800 if( aImpl.isStyleChanged() )
801 aImpl.ApplyStyle();
803 if( aImpl.isOptionsChanged() )
804 aImpl.ApplyOptions();
805 return RET_OK;
807 return RET_CANCEL;
810 VclPtr<vcl::Window> createTableDesignPanel( vcl::Window* pParent, ViewShellBase& rBase )
812 return VclPtr<TableDesignPane>::Create( pParent, rBase );
815 void showTableDesignDialog( vcl::Window* pParent, ViewShellBase& rBase )
817 ScopedVclPtrInstance< TableDesignDialog > xDialog( pParent, rBase );
818 xDialog->Execute();
823 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */