fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / sd / source / ui / table / TableDesignPane.cxx
blob29b278c67b21d2d476d2555537ddd0d249878019
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 .
21 #include "sddll.hxx"
23 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
24 #include <com/sun/star/frame/XController.hpp>
25 #include <com/sun/star/view/XSelectionSupplier.hpp>
26 #include <com/sun/star/style/XStyle.hpp>
27 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
29 #include <comphelper/processfactory.hxx>
30 #include <sfx2/viewfrm.hxx>
31 #include <vcl/bmpacc.hxx>
32 #include <svl/style.hxx>
33 #include <sfx2/bindings.hxx>
34 #include <sfx2/app.hxx>
35 #include <sfx2/request.hxx>
36 #include <sfx2/dispatch.hxx>
37 #include <svx/svxids.hrc>
38 #include <svx/svdetc.hxx>
39 #include <editeng/boxitem.hxx>
40 #include <editeng/borderline.hxx>
41 #include <editeng/colritem.hxx>
42 #include <editeng/eeitem.hxx>
43 #include <svx/sdr/table/tabledesign.hxx>
45 #include "TableDesignPane.hxx"
46 #include <svtools/valueset.hxx>
48 #include "DrawDocShell.hxx"
49 #include "ViewShellBase.hxx"
50 #include "DrawViewShell.hxx"
51 #include "DrawController.hxx"
52 #include "glob.hrc"
53 #include "sdresid.hxx"
54 #include "EventMultiplexer.hxx"
56 using namespace ::com::sun::star;
57 using namespace ::com::sun::star::uno;
58 using namespace ::com::sun::star::drawing;
59 using namespace ::com::sun::star::container;
60 using namespace ::com::sun::star::beans;
61 using namespace ::com::sun::star::view;
62 using namespace ::com::sun::star::style;
63 using namespace ::com::sun::star::frame;
64 using namespace ::com::sun::star::lang;
65 using namespace ::com::sun::star::ui;
67 namespace sd {
69 static const sal_Int32 nPreviewColumns = 5;
70 static const sal_Int32 nPreviewRows = 5;
72 // --------------------------------------------------------------------
74 static const OUString* getPropertyNames()
76 static const OUString gPropNames[ CB_BANDED_COLUMNS-CB_HEADER_ROW+1 ] =
78 OUString("UseFirstRowStyle") ,
79 OUString("UseLastRowStyle") ,
80 OUString("UseBandingRowStyle") ,
81 OUString("UseFirstColumnStyle") ,
82 OUString("UseLastColumnStyle") ,
83 OUString("UseBandingColumnStyle")
85 return &gPropNames[0];
87 // --------------------------------------------------------------------
89 TableDesignPane::TableDesignPane( ::Window* pParent, ViewShellBase& rBase, bool bModal )
90 : Control( pParent, SdResId(DLG_TABLEDESIGNPANE) )
91 , mrBase( rBase )
92 , msTableTemplate( "TableTemplate" )
93 , mbModal( bModal )
94 , mbStyleSelected( false )
95 , mbOptionsChanged( false )
97 Window* pControlParent = mbModal ? pParent : this;
99 // mxControls[FL_TABLE_STYLES].reset( new FixedLine( pControlParent, SdResId( FL_TABLE_STYLES + 1 ) ) );
101 ValueSet* pValueSet = new ValueSet( pControlParent, SdResId( CT_TABLE_STYLES+1 ) );
102 mxControls[CT_TABLE_STYLES].reset( pValueSet );
103 if( !mbModal )
105 pValueSet->SetStyle( (pValueSet->GetStyle() & ~(WB_ITEMBORDER|WB_BORDER)) | WB_NO_DIRECTSELECT | WB_FLATVALUESET | WB_NOBORDER );
106 pValueSet->SetColor();
107 pValueSet->SetExtraSpacing(8);
109 else
111 pValueSet->SetColor( Color( COL_WHITE ) );
112 pValueSet->SetBackground( Color( COL_WHITE ) );
114 pValueSet->SetSelectHdl (LINK(this, TableDesignPane, implValueSetHdl));
116 // mxControls[FL_STYLE_OPTIONS].reset( new FixedLine( pControlParent, SdResId( FL_STYLE_OPTIONS + 1 ) ) );
117 sal_uInt16 i;
118 for( i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i )
120 CheckBox *pCheckBox = new CheckBox( pControlParent, SdResId( i+1 ) );
121 mxControls[i].reset( pCheckBox );
122 pCheckBox->SetClickHdl( LINK( this, TableDesignPane, implCheckBoxHdl ) );
125 for( i = 0; i < DESIGNPANE_CONTROL_COUNT; i++ )
127 if (mxControls[i])
128 mnOrgOffsetY[i] = mxControls[i]->GetPosPixel().Y();
129 else if (i > 0)
130 mnOrgOffsetY[i] = mnOrgOffsetY[i-1];
131 else
132 mnOrgOffsetY[i] = 0;
135 // get current controller and initialize listeners
138 mxView = Reference< XDrawView >::query(mrBase.GetController());
139 addListener();
141 Reference< XController > xController( mrBase.GetController(), UNO_QUERY_THROW );
142 Reference< XStyleFamiliesSupplier > xFamiliesSupp( xController->getModel(), UNO_QUERY_THROW );
143 Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() );
144 const OUString sFamilyName( "table" );
145 mxTableFamily = Reference< XIndexAccess >( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW );
148 catch( Exception& )
150 OSL_FAIL( "sd::CustomAnimationPane::CustomAnimationPane(), Exception caught!" );
153 onSelectionChanged();
154 updateControls();
156 FreeResource();
159 // --------------------------------------------------------------------
161 TableDesignPane::~TableDesignPane()
163 removeListener();
166 // --------------------------------------------------------------------
168 void TableDesignPane::DataChanged( const DataChangedEvent& /*rDCEvt*/ )
170 updateLayout();
173 // --------------------------------------------------------------------
175 void TableDesignPane::Resize()
177 updateLayout();
183 LayoutSize TableDesignPane::GetHeightForWidth (const sal_Int32 nWidth)
185 if ( ! IsVisible() || nWidth<=0)
186 return LayoutSize(0,0,0);
188 // Initialize the height with the offset above and below the value
189 // set and below the check boxes.
190 const Point aOffset (LogicToPixel( Point(3,3), MAP_APPFONT));
191 sal_Int32 nHeight (3 * aOffset.Y());
193 // Add the height for the check boxes.
194 nHeight += mnOrgOffsetY[CB_BANDED_COLUMNS] - mnOrgOffsetY[CB_HEADER_ROW]
195 + mxControls[CB_BANDED_COLUMNS]->GetSizePixel().Height();
197 // Setup minimal and maximal heights that include all check boxes
198 // and a small or large value set.
199 const sal_Int32 nMinimalHeight (nHeight+100);
200 const sal_Int32 nMaximalHeight (nHeight+450);
202 // Calculate the number of rows and columns and then add the
203 // preferred size of the value set.
204 ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() );
205 if (pValueSet->GetItemCount() > 0)
207 Image aImage = pValueSet->GetItemImage(pValueSet->GetItemId(0));
208 Size aItemSize = pValueSet->CalcItemSizePixel(aImage.GetSizePixel());
209 aItemSize.Width() += 10;
210 aItemSize.Height() += 10;
212 int nColumnCount = (pValueSet->GetSizePixel().Width() - pValueSet->GetScrollWidth()) / aItemSize.Width();
213 if (nColumnCount < 1)
214 nColumnCount = 1;
216 int nRowCount = (pValueSet->GetItemCount() + nColumnCount - 1) / nColumnCount;
217 if (nRowCount < 1)
218 nRowCount = 1;
220 nHeight += nRowCount * aItemSize.Height();
223 // Clip the requested height.
224 if (nHeight<nMinimalHeight)
225 nHeight = nMinimalHeight;
226 else if (nHeight>nMaximalHeight)
227 nHeight = nMaximalHeight;
228 return LayoutSize(nMinimalHeight, nMaximalHeight, nHeight);
234 // --------------------------------------------------------------------
236 static SfxBindings* getBindings( ViewShellBase& rBase )
238 if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
239 return &rBase.GetMainViewShell()->GetViewFrame()->GetBindings();
240 else
241 return 0;
244 // --------------------------------------------------------------------
246 static SfxDispatcher* getDispatcher( ViewShellBase& rBase )
248 if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() )
249 return rBase.GetMainViewShell()->GetViewFrame()->GetDispatcher();
250 else
251 return 0;
254 // --------------------------------------------------------------------
256 IMPL_LINK_NOARG(TableDesignPane, implValueSetHdl)
258 mbStyleSelected = true;
259 if( !mbModal )
260 ApplyStyle();
261 return 0;
264 // --------------------------------------------------------------------
266 void TableDesignPane::ApplyStyle()
270 OUString sStyleName;
271 ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() );
272 sal_Int32 nIndex = static_cast< sal_Int32 >( pValueSet->GetSelectItemId() ) - 1;
274 if( (nIndex >= 0) && (nIndex < mxTableFamily->getCount()) )
276 Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY_THROW );
277 sStyleName = xNames->getElementNames()[nIndex];
280 if( sStyleName.isEmpty() )
281 return;
283 SdrView* pView = mrBase.GetDrawView();
284 if( mxSelectedTable.is() )
286 if( pView )
288 SfxRequest aReq( SID_TABLE_STYLE, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
289 aReq.AppendItem( SfxStringItem( SID_TABLE_STYLE, sStyleName ) );
291 rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() );
292 if( xController.is() )
293 xController->Execute( aReq );
295 SfxBindings* pBindings = getBindings( mrBase );
296 if( pBindings )
298 pBindings->Invalidate( SID_UNDO );
299 pBindings->Invalidate( SID_REDO );
303 else
305 SfxDispatcher* pDispatcher = getDispatcher( mrBase );
306 SfxStringItem aArg( SID_TABLE_STYLE, sStyleName );
307 pDispatcher->Execute(SID_INSERT_TABLE, SFX_CALLMODE_ASYNCHRON, &aArg, 0 );
310 catch( Exception& )
312 OSL_FAIL("TableDesignPane::implValueSetHdl(), exception caught!");
316 // --------------------------------------------------------------------
318 IMPL_LINK_NOARG(TableDesignPane, implCheckBoxHdl)
320 mbOptionsChanged = true;
322 if( !mbModal )
323 ApplyOptions();
325 FillDesignPreviewControl();
326 return 0;
329 // --------------------------------------------------------------------
331 void TableDesignPane::ApplyOptions()
333 static sal_uInt16 gParamIds[CB_BANDED_COLUMNS-CB_HEADER_ROW+1] =
335 ID_VAL_USEFIRSTROWSTYLE, ID_VAL_USELASTROWSTYLE, ID_VAL_USEBANDINGROWSTYLE,
336 ID_VAL_USEFIRSTCOLUMNSTYLE, ID_VAL_USELASTCOLUMNSTYLE, ID_VAL_USEBANDINGCOLUMNSTYLE
339 if( mxSelectedTable.is() )
341 SfxRequest aReq( SID_TABLE_STYLE_SETTINGS, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() );
343 for( sal_uInt16 i = 0; i < (CB_BANDED_COLUMNS-CB_HEADER_ROW+1); ++i )
345 aReq.AppendItem( SfxBoolItem( gParamIds[i], static_cast< CheckBox* >( mxControls[CB_HEADER_ROW+i].get() )->IsChecked() ) );
348 SdrView* pView = mrBase.GetDrawView();
349 if( pView )
351 rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() );
352 if( xController.is() )
354 xController->Execute( aReq );
356 SfxBindings* pBindings = getBindings( mrBase );
357 if( pBindings )
359 pBindings->Invalidate( SID_UNDO );
360 pBindings->Invalidate( SID_REDO );
367 // --------------------------------------------------------------------
369 void TableDesignPane::onSelectionChanged()
371 Reference< XPropertySet > xNewSelection;
373 if( mxView.is() ) try
375 Reference< XSelectionSupplier > xSel( mxView, UNO_QUERY_THROW );
376 if (xSel.is())
378 Any aSel( xSel->getSelection() );
379 Sequence< XShape > xShapeSeq;
380 if( aSel >>= xShapeSeq )
382 if( xShapeSeq.getLength() == 1 )
383 aSel <<= xShapeSeq[0];
385 else
387 Reference< XShapes > xShapes( aSel, UNO_QUERY );
388 if( xShapes.is() && (xShapes->getCount() == 1) )
389 aSel <<= xShapes->getByIndex(0);
392 Reference< XShapeDescriptor > xDesc( aSel, UNO_QUERY );
393 if( xDesc.is() && ( xDesc->getShapeType() == "com.sun.star.drawing.TableShape" || xDesc->getShapeType() == "com.sun.star.presentation.TableShape" ) )
395 xNewSelection = Reference< XPropertySet >::query( xDesc );
399 catch( Exception& )
401 OSL_FAIL( "sd::TableDesignPane::onSelectionChanged(), Exception caught!" );
404 if( mxSelectedTable != xNewSelection )
406 mxSelectedTable = xNewSelection;
407 updateControls();
411 // --------------------------------------------------------------------
413 void TableDesignPane::updateLayout()
415 ::Size aPaneSize( GetSizePixel() );
416 if(IsVisible() && aPaneSize.Width() > 0)
418 Point aOffset( LogicToPixel( Point(3,3), MAP_APPFONT ) );
420 ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() );
422 Size aValueSetSize;
424 if( !mbModal )
426 const long nOptionsHeight = mnOrgOffsetY[CB_BANDED_COLUMNS] + mxControls[CB_BANDED_COLUMNS]->GetSizePixel().Height() + aOffset.Y();
428 const long nStylesHeight = aPaneSize.Height() - nOptionsHeight;
430 // set width of controls to size of pane
431 for( sal_Int32 nId = 0; nId < DESIGNPANE_CONTROL_COUNT; ++nId )
433 if (mxControls[nId])
435 Size aSize( mxControls[nId]->GetSizePixel() );
436 aSize.Width() = aPaneSize.Width() - aOffset.X() - mxControls[nId]->GetPosPixel().X();
437 mxControls[nId]->SetSizePixel( aSize );
438 mxControls[nId]->SetPaintTransparent(sal_True);
439 mxControls[nId]->SetBackground();
442 aValueSetSize = Size( pValueSet->GetSizePixel().Width(), nStylesHeight );
444 else
446 aValueSetSize = pValueSet->GetSizePixel();
450 // Calculate the number of rows and columns.
451 if( pValueSet->GetItemCount() > 0 )
453 Image aImage = pValueSet->GetItemImage(pValueSet->GetItemId(0));
454 Size aItemSize = pValueSet->CalcItemSizePixel(aImage.GetSizePixel());
455 pValueSet->SetItemWidth( aItemSize.Width() );
456 pValueSet->SetItemHeight( aItemSize.Height() );
458 aItemSize.Width() += 10;
459 aItemSize.Height() += 10;
460 int nColumnCount = (aValueSetSize.Width() - pValueSet->GetScrollWidth()) / aItemSize.Width();
461 if (nColumnCount < 1)
462 nColumnCount = 1;
464 int nRowCount = (pValueSet->GetItemCount() + nColumnCount - 1) / nColumnCount;
465 if (nRowCount < 1)
466 nRowCount = 1;
468 int nVisibleRowCount = (aValueSetSize.Height()+2) / aItemSize.Height();
470 pValueSet->SetLineCount ( (nRowCount < nVisibleRowCount) ? (sal_uInt16)nRowCount : 0 );
472 pValueSet->SetColCount ((sal_uInt16)nColumnCount);
473 pValueSet->SetLineCount ((sal_uInt16)nRowCount);
475 if( !mbModal )
477 WinBits nStyle = pValueSet->GetStyle() & ~(WB_VSCROLL);
478 if( nRowCount < nVisibleRowCount )
480 aValueSetSize.Height() = nRowCount * aItemSize.Height();
482 else if( nRowCount > nVisibleRowCount )
484 nStyle |= WB_VSCROLL;
486 pValueSet->SetStyle( nStyle );
490 if( !mbModal )
492 pValueSet->SetSizePixel( aValueSetSize );
493 pValueSet->SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
494 pValueSet->SetColor( GetSettings().GetStyleSettings().GetWindowColor() );
496 Point aPos( pValueSet->GetPosPixel() );
498 // The following line may look like a no-op but without it the
499 // control is placed off-screen when RTL is active.
500 pValueSet->SetPosPixel(pValueSet->GetPosPixel());
502 // shift show options section down
503 const long nOptionsPos = aPos.Y() + aValueSetSize.Height();
504 sal_Int32 nMaxY (0);
505 for( sal_Int32 nId = FL_STYLE_OPTIONS+1; nId <= CB_BANDED_COLUMNS; ++nId )
507 if (mxControls[nId])
509 Point aCPos( mxControls[nId]->GetPosPixel() );
510 aCPos.X() = ( nId == FL_STYLE_OPTIONS ? 1 : 2 ) * aOffset.X();
511 aCPos.Y() = mnOrgOffsetY[nId] + nOptionsPos;
512 mxControls[nId]->SetPosPixel( aCPos );
513 const sal_Int32 nBottom (aCPos.Y() + mxControls[nId]->GetSizePixel().Height());
514 if (nBottom > nMaxY)
515 nMaxY = nBottom;
522 // --------------------------------------------------------------------
524 void TableDesignPane::updateControls()
526 static sal_Bool gDefaults[CB_BANDED_COLUMNS-CB_HEADER_ROW+1] = { sal_True, sal_False, sal_True, sal_False, sal_False, sal_False };
528 const bool bHasTable = mxSelectedTable.is();
529 const OUString* pPropNames = getPropertyNames();
531 for( sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i )
533 sal_Bool bUse = gDefaults[i-CB_HEADER_ROW];
534 if( bHasTable ) try
536 mxSelectedTable->getPropertyValue( *pPropNames++ ) >>= bUse;
538 catch( Exception& )
540 OSL_FAIL("sd::TableDesignPane::updateControls(), exception caught!");
542 static_cast< CheckBox* >( mxControls[i].get() )->Check( bUse ? sal_True : sal_False );
543 mxControls[i]->Enable(bHasTable ? sal_True : sal_False );
546 FillDesignPreviewControl();
547 updateLayout();
550 sal_uInt16 nSelection = 0;
551 if( mxSelectedTable.is() )
553 Reference< XNamed > xNamed( mxSelectedTable->getPropertyValue( "TableTemplate" ), UNO_QUERY );
554 if( xNamed.is() )
556 const OUString sStyleName( xNamed->getName() );
558 Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY );
559 if( xNames.is() )
561 Sequence< OUString > aNames( xNames->getElementNames() );
562 for( sal_Int32 nIndex = 0; nIndex < aNames.getLength(); nIndex++ )
564 if( aNames[nIndex] == sStyleName )
566 nSelection = (sal_uInt16)nIndex+1;
567 break;
573 ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() );
574 pValueSet->SelectItem( nSelection );
577 // --------------------------------------------------------------------
579 void TableDesignPane::addListener()
581 Link aLink( LINK(this,TableDesignPane,EventMultiplexerListener) );
582 mrBase.GetEventMultiplexer()->AddEventListener (
583 aLink,
584 tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
585 | tools::EventMultiplexerEvent::EID_CURRENT_PAGE
586 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
587 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
588 | tools::EventMultiplexerEvent::EID_DISPOSING);
591 // --------------------------------------------------------------------
593 void TableDesignPane::removeListener()
595 Link aLink( LINK(this,TableDesignPane,EventMultiplexerListener) );
596 mrBase.GetEventMultiplexer()->RemoveEventListener( aLink );
599 // --------------------------------------------------------------------
601 IMPL_LINK(TableDesignPane,EventMultiplexerListener,
602 tools::EventMultiplexerEvent*,pEvent)
604 switch (pEvent->meEventId)
606 case tools::EventMultiplexerEvent::EID_CURRENT_PAGE:
607 case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION:
608 onSelectionChanged();
609 break;
611 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED:
612 mxView = Reference<XDrawView>();
613 onSelectionChanged();
614 break;
616 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED:
617 mxView = Reference<XDrawView>::query( mrBase.GetController() );
618 onSelectionChanged();
619 break;
621 return 0;
624 // --------------------------------------------------------------------
626 struct CellInfo
628 Color maCellColor;
629 Color maTextColor;
630 SvxBoxItem maBorder;
632 explicit CellInfo( const Reference< XStyle >& xStyle );
635 CellInfo::CellInfo( const Reference< XStyle >& xStyle )
636 : maBorder(SDRATTR_TABLE_BORDER)
638 SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle );
639 if( pStyleSheet )
641 SfxItemSet& rSet = pStyleSheet->GetItemSet();
643 // get style fill color
644 if( !GetDraftFillColor(rSet, maCellColor) )
645 maCellColor.SetColor( COL_TRANSPARENT );
647 // get style text color
648 const SvxColorItem* pTextColor = dynamic_cast<const SvxColorItem*>( rSet.GetItem(EE_CHAR_COLOR) );
649 if( pTextColor )
650 maTextColor = pTextColor->GetValue();
651 else
652 maTextColor.SetColor( COL_TRANSPARENT );
654 // get border
655 const SvxBoxItem* pBoxItem = dynamic_cast<const SvxBoxItem*>(rSet.GetItem( SDRATTR_TABLE_BORDER ) );
656 if( pBoxItem )
657 maBorder = *pBoxItem;
661 // --------------------------------------------------------------------
663 typedef std::vector< boost::shared_ptr< CellInfo > > CellInfoVector;
664 typedef boost::shared_ptr< CellInfo > CellInfoMatrix[nPreviewColumns][nPreviewRows];
666 struct TableStyleSettings
668 bool mbUseFirstRow;
669 bool mbUseLastRow;
670 bool mbUseFirstColumn;
671 bool mbUseLastColumn;
672 bool mbUseRowBanding;
673 bool mbUseColumnBanding;
675 TableStyleSettings()
676 : mbUseFirstRow(true)
677 , mbUseLastRow(false)
678 , mbUseFirstColumn(false)
679 , mbUseLastColumn(false)
680 , mbUseRowBanding(true)
681 , mbUseColumnBanding(false) {}
684 // --------------------------------------------------------------------
686 static void FillCellInfoVector( const Reference< XIndexAccess >& xTableStyle, CellInfoVector& rVector )
688 DBG_ASSERT( xTableStyle.is() && (xTableStyle->getCount() == sdr::table::style_count ), "sd::FillCellInfoVector(), invalid table style!" );
689 if( xTableStyle.is() ) try
691 rVector.resize( sdr::table::style_count );
693 for( sal_Int32 nStyle = 0; nStyle < sdr::table::style_count; ++nStyle )
695 Reference< XStyle > xStyle( xTableStyle->getByIndex( nStyle ), UNO_QUERY );
696 if( xStyle.is() )
697 rVector[nStyle].reset( new CellInfo( xStyle ) );
700 catch(Exception&)
702 OSL_FAIL("sd::FillCellInfoVector(), exception caught!");
706 static void FillCellInfoMatrix( const CellInfoVector& rStyle, const TableStyleSettings& rSettings, CellInfoMatrix& rMatrix )
708 for( sal_Int32 nRow = 0; nRow < nPreviewColumns; ++nRow )
710 const bool bFirstRow = rSettings.mbUseFirstRow && (nRow == 0);
711 const bool bLastRow = rSettings.mbUseLastRow && (nRow == nPreviewColumns - 1);
713 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol )
715 boost::shared_ptr< CellInfo > xCellInfo;
717 // first and last row win first, if used and available
718 if( bFirstRow )
720 xCellInfo = rStyle[sdr::table::first_row_style];
722 else if( bLastRow )
724 xCellInfo = rStyle[sdr::table::last_row_style];
727 if( !xCellInfo.get() )
729 // next come first and last column, if used and available
730 if( rSettings.mbUseFirstColumn && (nCol == 0) )
732 xCellInfo = rStyle[sdr::table::first_column_style];
734 else if( rSettings.mbUseLastColumn && (nCol == nPreviewColumns-1) )
736 xCellInfo = rStyle[sdr::table::last_column_style];
740 if( !xCellInfo.get() )
742 if( rSettings.mbUseRowBanding )
744 if( (nRow & 1) == 0 )
746 xCellInfo = rStyle[sdr::table::even_rows_style];
748 else
750 xCellInfo = rStyle[sdr::table::odd_rows_style];
755 if( !xCellInfo.get() )
757 if( rSettings.mbUseColumnBanding )
759 if( (nCol & 1) == 0 )
761 xCellInfo = rStyle[sdr::table::even_columns_style];
763 else
765 xCellInfo = rStyle[sdr::table::odd_columns_style];
770 if( !xCellInfo.get() )
772 // use default cell style if non found yet
773 xCellInfo = rStyle[sdr::table::body_style];
776 rMatrix[nCol][nRow] = xCellInfo;
781 // --------------------------------------------------------------------
783 const Bitmap CreateDesignPreview( const Reference< XIndexAccess >& xTableStyle, const TableStyleSettings& rSettings, bool bIsPageDark )
785 CellInfoVector aCellInfoVector(sdr::table::style_count);
786 FillCellInfoVector( xTableStyle, aCellInfoVector );
788 CellInfoMatrix aMatrix;
789 FillCellInfoMatrix( aCellInfoVector, rSettings, aMatrix );
791 // bbbbbbbbbbbb w = 12 pixel
792 // bccccccccccb h = 7 pixel
793 // bccccccccccb b = border color
794 // bcttttttttcb c = cell color
795 // bccccccccccb t = text color
796 // bccccccccccb
797 // bbbbbbbbbbbb
800 const sal_Int32 nCellWidth = 12; // one pixel is shared with the next cell!
801 const sal_Int32 nCellHeight = 7; // one pixel is shared with the next cell!
803 Bitmap aPreviewBmp( Size( (nCellWidth * nPreviewColumns) - (nPreviewColumns - 1), (nCellHeight * nPreviewRows) - (nPreviewRows - 1)), 24, NULL );
804 BitmapWriteAccess* pAccess = aPreviewBmp.AcquireWriteAccess();
805 if( pAccess )
807 pAccess->Erase( Color( bIsPageDark ? COL_BLACK : COL_WHITE ) );
809 // first draw cell background and text line previews
810 sal_Int32 nY = 0;
811 sal_Int32 nRow;
812 for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 )
814 sal_Int32 nX = 0;
815 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 )
817 boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] );
819 Color aTextColor( COL_AUTO );
820 if( xCellInfo.get() )
822 // fill cell background
823 const Rectangle aRect( nX, nY, nX + nCellWidth - 1, nY + nCellHeight - 1 );
825 if( xCellInfo->maCellColor.GetColor() != COL_TRANSPARENT )
827 pAccess->SetFillColor( xCellInfo->maCellColor );
828 pAccess->FillRect( aRect );
831 aTextColor = xCellInfo->maTextColor;
834 // draw text preview line
835 if( aTextColor.GetColor() == COL_AUTO )
836 aTextColor.SetColor( bIsPageDark ? COL_WHITE : COL_BLACK );
837 pAccess->SetLineColor( aTextColor );
838 const Point aPnt1( nX + 2, nY + ((nCellHeight - 1 ) >> 1) );
839 const Point aPnt2( nX + nCellWidth - 3, aPnt1.Y() );
840 pAccess->DrawLine( aPnt1, aPnt2 );
844 // second draw border lines
845 nY = 0;
846 for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 )
848 sal_Int32 nX = 0;
849 for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 )
851 boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] );
853 if( xCellInfo.get() )
855 const Point aPntTL( nX, nY );
856 const Point aPntTR( nX + nCellWidth - 1, nY );
857 const Point aPntBL( nX, nY + nCellHeight - 1 );
858 const Point aPntBR( nX + nCellWidth - 1, nY + nCellHeight - 1 );
860 sal_Int32 border_diffs[8] = { 0,-1, 0,1, -1,0, 1,0 };
861 sal_Int32* pDiff = &border_diffs[0];
863 // draw top border
864 for( sal_uInt16 nLine = 0; nLine < 4; ++nLine )
866 const ::editeng::SvxBorderLine* pBorderLine = xCellInfo->maBorder.GetLine(nLine);
867 if( !pBorderLine || ((pBorderLine->GetOutWidth() == 0) && (pBorderLine->GetInWidth()==0)) )
868 continue;
870 sal_Int32 nBorderCol = nCol + *pDiff++;
871 sal_Int32 nBorderRow = nRow + *pDiff++;
872 if( (nBorderCol >= 0) && (nBorderCol < nPreviewColumns) && (nBorderRow >= 0) && (nBorderRow < nPreviewRows) )
874 // check border
875 boost::shared_ptr< CellInfo > xBorderInfo( aMatrix[nBorderCol][nBorderRow] );
876 if( xBorderInfo.get() )
878 const sal_uInt16 nOtherLine = nLine ^ 1;
879 const ::editeng::SvxBorderLine* pBorderLine2 = xBorderInfo->maBorder.GetLine(nOtherLine^1);
880 if( pBorderLine2 && pBorderLine2->HasPriority(*pBorderLine) )
881 continue; // other border line wins
885 pAccess->SetLineColor( pBorderLine->GetColor() );
886 switch( nLine )
888 case 0: pAccess->DrawLine( aPntTL, aPntTR ); break;
889 case 1: pAccess->DrawLine( aPntBL, aPntBR ); break;
890 case 2: pAccess->DrawLine( aPntTL, aPntBL ); break;
891 case 3: pAccess->DrawLine( aPntTR, aPntBR ); break;
898 aPreviewBmp.ReleaseAccess( pAccess );
901 return aPreviewBmp;
904 void TableDesignPane::FillDesignPreviewControl()
906 ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() );
908 sal_uInt16 nSelectedItem = pValueSet->GetSelectItemId();
909 pValueSet->Clear();
912 TableStyleSettings aSettings;
913 if( mxSelectedTable.is() )
915 aSettings.mbUseFirstRow = static_cast< CheckBox* >(mxControls[CB_HEADER_ROW].get())->IsChecked();
916 aSettings.mbUseLastRow = static_cast< CheckBox* >(mxControls[CB_TOTAL_ROW].get())->IsChecked();
917 aSettings.mbUseRowBanding = static_cast< CheckBox* >(mxControls[CB_BANDED_ROWS].get())->IsChecked();
918 aSettings.mbUseFirstColumn = static_cast< CheckBox* >(mxControls[CB_FIRST_COLUMN].get())->IsChecked();
919 aSettings.mbUseLastColumn = static_cast< CheckBox* >(mxControls[CB_LAST_COLUMN].get())->IsChecked();
920 aSettings.mbUseColumnBanding = static_cast< CheckBox* >(mxControls[CB_BANDED_COLUMNS].get())->IsChecked();
923 sal_Bool bIsPageDark = sal_False;
924 if( mxView.is() )
926 Reference< XPropertySet > xPageSet( mxView->getCurrentPage(), UNO_QUERY );
927 if( xPageSet.is() )
929 const OUString sIsBackgroundDark( "IsBackgroundDark" );
930 xPageSet->getPropertyValue(sIsBackgroundDark) >>= bIsPageDark;
934 for( sal_Int32 nIndex = 0; nIndex < mxTableFamily->getCount(); nIndex++ ) try
936 Reference< XIndexAccess > xTableStyle( mxTableFamily->getByIndex( nIndex ), UNO_QUERY );
937 if( xTableStyle.is() )
938 pValueSet->InsertItem( sal::static_int_cast<sal_uInt16>( nIndex + 1 ), Image( CreateDesignPreview( xTableStyle, aSettings, bIsPageDark ) ) );
940 catch( Exception& )
942 OSL_FAIL("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!");
945 catch( Exception& )
947 OSL_FAIL("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!");
949 pValueSet->SelectItem(nSelectedItem);
952 // ====================================================================
954 TableDesignDialog::TableDesignDialog(::Window* pParent, ViewShellBase& rBase )
955 : ModalDialog( pParent, SdResId( DLG_TABLEDESIGNPANE ))
957 mxFlSep1.reset( new FixedLine( this, SdResId( FL_SEP1 ) ) );
958 mxFlSep2.reset( new FixedLine( this, SdResId( FL_SEP2 ) ) );
959 mxHelpButton.reset( new HelpButton( this, SdResId( BTN_HELP ) ) );
960 mxOkButton.reset( new OKButton( this, SdResId( BTN_OK ) ) );
961 mxCancelButton.reset( new CancelButton( this, SdResId( BTN_CANCEL ) ) );
962 FreeResource();
964 mpDesignPane.reset( new TableDesignPane( this, rBase, true ) );
965 mpDesignPane->Hide();
968 // --------------------------------------------------------------------
970 short TableDesignDialog::Execute()
972 if( ModalDialog::Execute() )
974 if( mpDesignPane->isStyleChanged() )
975 mpDesignPane->ApplyStyle();
977 if( mpDesignPane->isOptionsChanged() )
978 mpDesignPane->ApplyOptions();
979 return sal_True;
981 return sal_False;
984 // ====================================================================
986 ::Window * createTableDesignPanel( ::Window* pParent, ViewShellBase& rBase )
988 return new TableDesignPane( pParent, rBase, false );
991 // ====================================================================
993 void showTableDesignDialog( ::Window* pParent, ViewShellBase& rBase )
995 boost::scoped_ptr< TableDesignDialog > xDialog( new TableDesignDialog( pParent, rBase ) );
996 xDialog->Execute();
1003 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */