1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TableDesignPane.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
36 //#include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/beans/XMultiPropertyStates.hpp>
38 #include <com/sun/star/frame/XController.hpp>
39 #include <com/sun/star/view/XSelectionSupplier.hpp>
40 #include <com/sun/star/style/XStyle.hpp>
41 #include <com/sun/star/style/XStyleFamiliesSupplier.hpp>
42 //#include <com/sun/star/ui/XUIElementFactory.hpp>
44 #include <comphelper/processfactory.hxx>
46 //#include <toolkit/helper/vclunohelper.hxx>
48 #include <sfx2/viewfrm.hxx>
50 #include <vcl/bmpacc.hxx>
51 //#include <vcl/toolbox.hxx>
53 #include <svtools/style.hxx>
55 #include <sfx2/viewfrm.hxx>
56 #include <sfx2/bindings.hxx>
57 #include <sfx2/app.hxx>
58 #include <sfx2/request.hxx>
59 #include <sfx2/dispatch.hxx>
61 #include <svx/svdetc.hxx>
62 #include <svx/boxitem.hxx>
63 #include <svx/borderline.hxx>
64 #include <svx/colritem.hxx>
65 #include <svx/eeitem.hxx>
66 #include <svx/sdr/table/tabledesign.hxx>
68 #include "TableDesignPane.hxx"
70 #include "DrawDocShell.hxx"
71 #include "ViewShellBase.hxx"
72 #include "DrawViewShell.hxx"
73 #include "DrawController.hxx"
75 #include "sdresid.hxx"
76 #include "EventMultiplexer.hxx"
78 #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) )
79 using ::rtl::OUString
;
80 using namespace ::com::sun::star
;
81 using namespace ::com::sun::star::uno
;
82 using namespace ::com::sun::star::drawing
;
83 using namespace ::com::sun::star::container
;
84 using namespace ::com::sun::star::beans
;
85 using namespace ::com::sun::star::view
;
86 using namespace ::com::sun::star::style
;
87 using namespace ::com::sun::star::frame
;
88 using namespace ::com::sun::star::lang
;
89 using namespace ::com::sun::star::ui
;
93 static const sal_Int32 nPreviewColumns
= 5;
94 static const sal_Int32 nPreviewRows
= 5;
96 // --------------------------------------------------------------------
98 static const OUString
* getPropertyNames()
100 static const OUString gPropNames
[ CB_BANDED_COLUMNS
-CB_HEADER_ROW
+1 ] =
103 C2U( "UseFirstRowStyle" ),
104 C2U( "UseLastRowStyle" ),
105 C2U( "UseBandingRowStyle" ),
106 C2U( "UseFirstColumnStyle" ),
107 C2U( "UseLastColumnStyle" ),
108 C2U( "UseBandingColumnStyle" )
110 return &gPropNames
[0];
112 // --------------------------------------------------------------------
114 TableDesignPane::TableDesignPane( ::Window
* pParent
, ViewShellBase
& rBase
, bool bModal
)
115 : Control( pParent
, SdResId(DLG_TABLEDESIGNPANE
) )
117 , msTableTemplate( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) )
119 , mbStyleSelected( false )
120 , mbOptionsChanged( false )
122 Window
* pControlParent
= mbModal
? pParent
: this;
124 mxControls
[FL_TABLE_STYLES
].reset( new FixedLine( pControlParent
, SdResId( FL_TABLE_STYLES
+ 1 ) ) );
126 ValueSet
* pValueSet
= new ValueSet( pControlParent
, SdResId( CT_TABLE_STYLES
+1 ) );
127 mxControls
[CT_TABLE_STYLES
].reset( pValueSet
);
130 pValueSet
->SetStyle( (pValueSet
->GetStyle() & ~(WB_ITEMBORDER
|WB_BORDER
)) | WB_NO_DIRECTSELECT
| WB_FLATVALUESET
| WB_NOBORDER
);
131 pValueSet
->SetColor();
132 pValueSet
->SetExtraSpacing(8);
136 pValueSet
->SetColor( Color( COL_WHITE
) );
137 pValueSet
->SetBackground( Color( COL_WHITE
) );
139 pValueSet
->SetSelectHdl (LINK(this, TableDesignPane
, implValueSetHdl
));
141 mxControls
[FL_STYLE_OPTIONS
].reset( new FixedLine( pControlParent
, SdResId( FL_STYLE_OPTIONS
+ 1 ) ) );
143 for( i
= CB_HEADER_ROW
; i
<= CB_BANDED_COLUMNS
; ++i
)
145 CheckBox
*pCheckBox
= new CheckBox( pControlParent
, SdResId( i
+1 ) );
146 mxControls
[i
].reset( pCheckBox
);
147 pCheckBox
->SetClickHdl( LINK( this, TableDesignPane
, implCheckBoxHdl
) );
150 for( i
= 0; i
< DESIGNPANE_CONTROL_COUNT
; i
++ )
151 mnOrgOffsetY
[i
] = mxControls
[i
]->GetPosPixel().Y();
153 // get current controller and initialize listeners
156 mxView
= Reference
< XDrawView
>::query(mrBase
.GetController());
159 Reference
< XController
> xController( mrBase
.GetController(), UNO_QUERY_THROW
);
160 Reference
< XStyleFamiliesSupplier
> xFamiliesSupp( xController
->getModel(), UNO_QUERY_THROW
);
161 Reference
< XNameAccess
> xFamilies( xFamiliesSupp
->getStyleFamilies() );
162 const OUString
sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) );
163 mxTableFamily
= Reference
< XIndexAccess
>( xFamilies
->getByName( sFamilyName
), UNO_QUERY_THROW
);
166 catch( Exception
& e
)
169 DBG_ERROR( "sd::CustomAnimationPane::CustomAnimationPane(), Exception caught!" );
172 onSelectionChanged();
178 // --------------------------------------------------------------------
180 TableDesignPane::~TableDesignPane()
185 // --------------------------------------------------------------------
187 void TableDesignPane::DataChanged( const DataChangedEvent
& /*rDCEvt*/ )
192 // --------------------------------------------------------------------
194 void TableDesignPane::Resize()
199 // --------------------------------------------------------------------
201 static SfxBindings
* getBindings( ViewShellBase
& rBase
)
203 if( rBase
.GetMainViewShell().get() && rBase
.GetMainViewShell()->GetViewFrame() )
204 return &rBase
.GetMainViewShell()->GetViewFrame()->GetBindings();
209 // --------------------------------------------------------------------
211 static SfxDispatcher
* getDispatcher( ViewShellBase
& rBase
)
213 if( rBase
.GetMainViewShell().get() && rBase
.GetMainViewShell()->GetViewFrame() )
214 return rBase
.GetMainViewShell()->GetViewFrame()->GetDispatcher();
219 // --------------------------------------------------------------------
221 IMPL_LINK( TableDesignPane
, implValueSetHdl
, Control
*, EMPTYARG
)
223 mbStyleSelected
= true;
229 // --------------------------------------------------------------------
231 void TableDesignPane::ApplyStyle()
236 ValueSet
* pValueSet
= static_cast< ValueSet
* >( mxControls
[CT_TABLE_STYLES
].get() );
237 sal_Int32 nIndex
= static_cast< sal_Int32
>( pValueSet
->GetSelectItemId() ) - 1;
239 if( (nIndex
>= 0) && (nIndex
< mxTableFamily
->getCount()) )
241 Reference
< XNameAccess
> xNames( mxTableFamily
, UNO_QUERY_THROW
);
242 sStyleName
= xNames
->getElementNames()[nIndex
];
245 if( sStyleName
.getLength() == 0 )
248 SdrView
* pView
= mrBase
.GetDrawView();
249 if( mxSelectedTable
.is() )
253 SfxRequest
aReq( SID_TABLE_STYLE
, SFX_CALLMODE_SYNCHRON
, SFX_APP()->GetPool() );
254 aReq
.AppendItem( SfxStringItem( SID_TABLE_STYLE
, sStyleName
) );
256 rtl::Reference
< sdr::SelectionController
> xController( pView
->getSelectionController() );
257 if( xController
.is() )
258 xController
->Execute( aReq
);
260 SfxBindings
* pBindings
= getBindings( mrBase
);
263 pBindings
->Invalidate( SID_UNDO
);
264 pBindings
->Invalidate( SID_REDO
);
270 SfxDispatcher
* pDispatcher
= getDispatcher( mrBase
);
271 SfxStringItem
aArg( SID_TABLE_STYLE
, sStyleName
);
272 pDispatcher
->Execute(SID_INSERT_TABLE
, SFX_CALLMODE_ASYNCHRON
, &aArg
, 0 );
277 DBG_ERROR("TableDesignPane::implValueSetHdl(), exception caught!");
281 // --------------------------------------------------------------------
283 IMPL_LINK( TableDesignPane
, implCheckBoxHdl
, Control
*, EMPTYARG
)
285 mbOptionsChanged
= true;
290 FillDesignPreviewControl();
294 // --------------------------------------------------------------------
296 void TableDesignPane::ApplyOptions()
298 static sal_uInt16 gParamIds
[CB_BANDED_COLUMNS
-CB_HEADER_ROW
+1] =
300 ID_VAL_USEFIRSTROWSTYLE
, ID_VAL_USELASTROWSTYLE
, ID_VAL_USEBANDINGROWSTYLE
,
301 ID_VAL_USEFIRSTCOLUMNSTYLE
, ID_VAL_USELASTCOLUMNSTYLE
, ID_VAL_USEBANDINGCOLUMNSTYLE
304 if( mxSelectedTable
.is() )
306 SfxRequest
aReq( SID_TABLE_STYLE_SETTINGS
, SFX_CALLMODE_SYNCHRON
, SFX_APP()->GetPool() );
308 for( sal_uInt16 i
= 0; i
< (CB_BANDED_COLUMNS
-CB_HEADER_ROW
+1); ++i
)
310 aReq
.AppendItem( SfxBoolItem( gParamIds
[i
], static_cast< CheckBox
* >( mxControls
[CB_HEADER_ROW
+i
].get() )->IsChecked() ) );
313 SdrView
* pView
= mrBase
.GetDrawView();
316 rtl::Reference
< sdr::SelectionController
> xController( pView
->getSelectionController() );
317 if( xController
.is() )
319 xController
->Execute( aReq
);
321 SfxBindings
* pBindings
= getBindings( mrBase
);
324 pBindings
->Invalidate( SID_UNDO
);
325 pBindings
->Invalidate( SID_REDO
);
332 // --------------------------------------------------------------------
334 void TableDesignPane::onSelectionChanged()
336 Reference
< XPropertySet
> xNewSelection
;
338 if( mxView
.is() ) try
340 Reference
< XSelectionSupplier
> xSel( mxView
, UNO_QUERY_THROW
);
343 Any
aSel( xSel
->getSelection() );
344 Sequence
< XShape
> xShapeSeq
;
345 if( aSel
>>= xShapeSeq
)
347 if( xShapeSeq
.getLength() == 1 )
348 aSel
<<= xShapeSeq
[0];
352 Reference
< XShapes
> xShapes( aSel
, UNO_QUERY
);
353 if( xShapes
.is() && (xShapes
->getCount() == 1) )
354 aSel
<<= xShapes
->getByIndex(0);
357 Reference
< XShapeDescriptor
> xDesc( aSel
, UNO_QUERY
);
358 if( xDesc
.is() && xDesc
->getShapeType().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.TableShape" ) ) )
360 xNewSelection
= Reference
< XPropertySet
>::query( xDesc
);
366 DBG_ERROR( "sd::TableDesignPane::onSelectionChanged(), Exception caught!" );
369 if( mxSelectedTable
!= xNewSelection
)
371 mxSelectedTable
= xNewSelection
;
376 // --------------------------------------------------------------------
378 void TableDesignPane::updateLayout()
380 ::Size
aPaneSize( GetSizePixel() );
381 if(IsVisible() && aPaneSize
.Width() > 0)
383 Point
aOffset( LogicToPixel( Point(3,3), MAP_APPFONT
) );
385 ValueSet
* pValueSet
= static_cast< ValueSet
* >( mxControls
[CT_TABLE_STYLES
].get() );
391 const long nOptionsHeight
= mnOrgOffsetY
[CB_BANDED_COLUMNS
] + mxControls
[CB_BANDED_COLUMNS
]->GetSizePixel().Height() + aOffset
.Y();
393 const long nStylesHeight
= aPaneSize
.Height() - nOptionsHeight
;
395 // set with of controls to size of pane
396 for( sal_Int32 nId
= 0; nId
< DESIGNPANE_CONTROL_COUNT
; ++nId
)
398 Size
aSize( mxControls
[nId
]->GetSizePixel() );
399 aSize
.Width() = aPaneSize
.Width() - aOffset
.X() - mxControls
[nId
]->GetPosPixel().X();
400 mxControls
[nId
]->SetSizePixel( aSize
);
401 mxControls
[nId
]->SetPaintTransparent(TRUE
);
402 mxControls
[nId
]->SetBackground();
404 aValueSetSize
= Size( aPaneSize
.Width() - 2 * aOffset
.X(), nStylesHeight
- mxControls
[FL_TABLE_STYLES
]->GetSizePixel().Height() - mnOrgOffsetY
[FL_TABLE_STYLES
] );
408 aValueSetSize
= pValueSet
->GetSizePixel();
412 // Calculate the number of rows and columns.
413 if( pValueSet
->GetItemCount() > 0 )
415 Image aImage
= pValueSet
->GetItemImage(pValueSet
->GetItemId(0));
416 Size aItemSize
= pValueSet
->CalcItemSizePixel(aImage
.GetSizePixel());
417 pValueSet
->SetItemWidth( aItemSize
.Width() );
418 pValueSet
->SetItemHeight( aItemSize
.Height() );
420 aItemSize
.Width() += 10;
421 aItemSize
.Height() += 10;
422 int nColumnCount
= (aValueSetSize
.Width() - pValueSet
->GetScrollWidth()) / aItemSize
.Width();
423 if (nColumnCount
< 1)
426 int nRowCount
= (pValueSet
->GetItemCount() + nColumnCount
- 1) / nColumnCount
;
430 int nVisibleRowCount
= (aValueSetSize
.Height()+2) / aItemSize
.Height();
432 pValueSet
->SetLineCount ( (nRowCount
< nVisibleRowCount
) ? (USHORT
)nRowCount
: 0 );
434 pValueSet
->SetColCount ((USHORT
)nColumnCount
);
435 pValueSet
->SetLineCount ((USHORT
)nRowCount
);
439 WinBits nStyle
= pValueSet
->GetStyle() & ~(WB_VSCROLL
);
440 if( nRowCount
< nVisibleRowCount
)
442 aValueSetSize
.Height() = nRowCount
* aItemSize
.Height();
444 else if( nRowCount
> nVisibleRowCount
)
446 nStyle
|= WB_VSCROLL
;
448 pValueSet
->SetStyle( nStyle
);
454 pValueSet
->SetSizePixel( aValueSetSize
);
455 pValueSet
->SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
456 pValueSet
->SetColor( GetSettings().GetStyleSettings().GetWindowColor() );
458 Point
aPos( pValueSet
->GetPosPixel() );
460 // shift show options section down
461 const long nOptionsPos
= aPos
.Y() + aValueSetSize
.Height();
462 for( sal_Int32 nId
= FL_STYLE_OPTIONS
; nId
<= CB_BANDED_COLUMNS
; ++nId
)
464 Point
aCPos( mxControls
[nId
]->GetPosPixel() );
465 aCPos
.X() = ( nId
== FL_STYLE_OPTIONS
? 1 : 2 ) * aOffset
.X();
466 aCPos
.Y() = mnOrgOffsetY
[nId
] + nOptionsPos
;
467 mxControls
[nId
]->SetPosPixel( aCPos
);
473 SetBackground( GetSettings().GetStyleSettings().GetWindowColor() );
476 // --------------------------------------------------------------------
478 void TableDesignPane::updateControls()
480 static sal_Bool gDefaults
[CB_BANDED_COLUMNS
-CB_HEADER_ROW
+1] = { sal_True
, sal_False
, sal_True
, sal_False
, sal_False
, sal_False
};
482 const bool bHasTable
= mxSelectedTable
.is();
483 const OUString
* pPropNames
= getPropertyNames();
485 for( USHORT i
= CB_HEADER_ROW
; i
<= CB_BANDED_COLUMNS
; ++i
)
487 sal_Bool bUse
= gDefaults
[i
-CB_HEADER_ROW
];
490 mxSelectedTable
->getPropertyValue( *pPropNames
++ ) >>= bUse
;
494 DBG_ERROR("sd::TableDesignPane::updateControls(), exception caught!");
496 static_cast< CheckBox
* >( mxControls
[i
].get() )->Check( bUse
? TRUE
: FALSE
);
497 mxControls
[i
]->Enable(bHasTable
? TRUE
: FALSE
);
500 FillDesignPreviewControl();
504 USHORT nSelection
= 0;
505 if( mxSelectedTable
.is() )
507 Reference
< XNamed
> xNamed( mxSelectedTable
->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) ) ), UNO_QUERY
);
510 const OUString
sStyleName( xNamed
->getName() );
512 Reference
< XNameAccess
> xNames( mxTableFamily
, UNO_QUERY
);
515 Sequence
< OUString
> aNames( xNames
->getElementNames() );
516 for( sal_Int32 nIndex
= 0; nIndex
< aNames
.getLength(); nIndex
++ )
518 if( aNames
[nIndex
] == sStyleName
)
520 nSelection
= (USHORT
)nIndex
+1;
527 ValueSet
* pValueSet
= static_cast< ValueSet
* >( mxControls
[CT_TABLE_STYLES
].get() );
528 pValueSet
->SelectItem( nSelection
);
531 // --------------------------------------------------------------------
533 void TableDesignPane::addListener()
535 Link
aLink( LINK(this,TableDesignPane
,EventMultiplexerListener
) );
536 mrBase
.GetEventMultiplexer()->AddEventListener (
538 tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
539 | tools::EventMultiplexerEvent::EID_CURRENT_PAGE
540 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
541 | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
542 | tools::EventMultiplexerEvent::EID_DISPOSING
);
545 // --------------------------------------------------------------------
547 void TableDesignPane::removeListener()
549 Link
aLink( LINK(this,TableDesignPane
,EventMultiplexerListener
) );
550 mrBase
.GetEventMultiplexer()->RemoveEventListener( aLink
);
553 // --------------------------------------------------------------------
555 IMPL_LINK(TableDesignPane
,EventMultiplexerListener
,
556 tools::EventMultiplexerEvent
*,pEvent
)
558 switch (pEvent
->meEventId
)
560 case tools::EventMultiplexerEvent::EID_CURRENT_PAGE
:
561 case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION
:
562 onSelectionChanged();
565 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED
:
566 mxView
= Reference
<XDrawView
>();
567 onSelectionChanged();
570 case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED
:
571 mxView
= Reference
<XDrawView
>::query( mrBase
.GetController() );
572 onSelectionChanged();
578 // --------------------------------------------------------------------
586 explicit CellInfo( const Reference
< XStyle
>& xStyle
);
589 CellInfo::CellInfo( const Reference
< XStyle
>& xStyle
)
590 : maBorder(SDRATTR_TABLE_BORDER
)
592 SfxStyleSheet
* pStyleSheet
= SfxUnoStyleSheet::getUnoStyleSheet( xStyle
);
595 SfxItemSet
& rSet
= pStyleSheet
->GetItemSet();
597 // get style fill color
598 if( !GetDraftFillColor(rSet
, maCellColor
) )
599 maCellColor
.SetColor( COL_TRANSPARENT
);
601 // get style text color
602 const SvxColorItem
* pTextColor
= dynamic_cast<const SvxColorItem
*>( rSet
.GetItem(EE_CHAR_COLOR
) );
604 maTextColor
= pTextColor
->GetValue();
606 maTextColor
.SetColor( COL_TRANSPARENT
);
609 const SvxBoxItem
* pBoxItem
= dynamic_cast<const SvxBoxItem
*>(rSet
.GetItem( SDRATTR_TABLE_BORDER
) );
611 maBorder
= *pBoxItem
;
615 // --------------------------------------------------------------------
617 typedef std::vector
< boost::shared_ptr
< CellInfo
> > CellInfoVector
;
618 typedef boost::shared_ptr
< CellInfo
> CellInfoMatrix
[nPreviewColumns
][nPreviewRows
];
620 struct TableStyleSettings
624 bool mbUseFirstColumn
;
625 bool mbUseLastColumn
;
626 bool mbUseRowBanding
;
627 bool mbUseColumnBanding
;
630 : mbUseFirstRow(true)
631 , mbUseLastRow(false)
632 , mbUseFirstColumn(false)
633 , mbUseLastColumn(false)
634 , mbUseRowBanding(true)
635 , mbUseColumnBanding(false) {}
638 // --------------------------------------------------------------------
640 static void FillCellInfoVector( const Reference
< XIndexAccess
>& xTableStyle
, CellInfoVector
& rVector
)
642 DBG_ASSERT( xTableStyle
.is() && (xTableStyle
->getCount() == sdr::table::style_count
), "sd::FillCellInfoVector(), inavlid table style!" );
643 if( xTableStyle
.is() ) try
645 rVector
.resize( sdr::table::style_count
);
647 for( sal_Int32 nStyle
= 0; nStyle
< sdr::table::style_count
; ++nStyle
)
649 Reference
< XStyle
> xStyle( xTableStyle
->getByIndex( nStyle
), UNO_QUERY
);
651 rVector
[nStyle
].reset( new CellInfo( xStyle
) );
656 DBG_ERROR("sd::FillCellInfoVector(), exception caught!");
660 static void FillCellInfoMatrix( const CellInfoVector
& rStyle
, const TableStyleSettings
& rSettings
, CellInfoMatrix
& rMatrix
)
662 for( sal_Int32 nRow
= 0; nRow
< nPreviewColumns
; ++nRow
)
664 const bool bFirstRow
= rSettings
.mbUseFirstRow
&& (nRow
== 0);
665 const bool bLastRow
= rSettings
.mbUseLastRow
&& (nRow
== nPreviewColumns
- 1);
667 for( sal_Int32 nCol
= 0; nCol
< nPreviewColumns
; ++nCol
)
669 boost::shared_ptr
< CellInfo
> xCellInfo
;
671 // first and last row win first, if used and available
674 xCellInfo
= rStyle
[sdr::table::first_row_style
];
678 xCellInfo
= rStyle
[sdr::table::last_row_style
];
681 if( !xCellInfo
.get() )
683 // next come first and last column, if used and available
684 if( rSettings
.mbUseFirstColumn
&& (nCol
== 0) )
686 xCellInfo
= rStyle
[sdr::table::first_column_style
];
688 else if( rSettings
.mbUseLastColumn
&& (nCol
== nPreviewColumns
-1) )
690 xCellInfo
= rStyle
[sdr::table::last_column_style
];
694 if( !xCellInfo
.get() )
696 if( rSettings
.mbUseRowBanding
)
698 if( (nRow
& 1) == 0 )
700 xCellInfo
= rStyle
[sdr::table::even_rows_style
];
704 xCellInfo
= rStyle
[sdr::table::odd_rows_style
];
709 if( !xCellInfo
.get() )
711 if( rSettings
.mbUseColumnBanding
)
713 if( (nCol
& 1) == 0 )
715 xCellInfo
= rStyle
[sdr::table::even_columns_style
];
719 xCellInfo
= rStyle
[sdr::table::odd_columns_style
];
724 if( !xCellInfo
.get() )
726 // use default cell style if non found yet
727 xCellInfo
= rStyle
[sdr::table::body_style
];
730 rMatrix
[nCol
][nRow
] = xCellInfo
;
735 // --------------------------------------------------------------------
737 const Bitmap
CreateDesignPreview( const Reference
< XIndexAccess
>& xTableStyle
, const TableStyleSettings
& rSettings
, bool bIsPageDark
)
739 CellInfoVector
aCellInfoVector(sdr::table::style_count
);
740 FillCellInfoVector( xTableStyle
, aCellInfoVector
);
742 CellInfoMatrix aMatrix
;
743 FillCellInfoMatrix( aCellInfoVector
, rSettings
, aMatrix
);
745 // bbbbbbbbbbbb w = 12 pixel
746 // bccccccccccb h = 7 pixel
747 // bccccccccccb b = border color
748 // bcttttttttcb c = cell color
749 // bccccccccccb t = text color
754 const sal_Int32 nCellWidth
= 12; // one pixel is shared with the next cell!
755 const sal_Int32 nCellHeight
= 7; // one pixel is shared with the next cell!
757 Bitmap
aPreviewBmp( Size( (nCellWidth
* nPreviewColumns
) - (nPreviewColumns
- 1), (nCellHeight
* nPreviewRows
) - (nPreviewRows
- 1)), 24, NULL
);
758 BitmapWriteAccess
* pAccess
= aPreviewBmp
.AcquireWriteAccess();
761 pAccess
->Erase( Color( bIsPageDark
? COL_BLACK
: COL_WHITE
) );
763 // first draw cell background and text line previews
766 for( nRow
= 0; nRow
< nPreviewRows
; ++nRow
, nY
+= nCellHeight
-1 )
769 for( sal_Int32 nCol
= 0; nCol
< nPreviewColumns
; ++nCol
, nX
+= nCellWidth
-1 )
771 boost::shared_ptr
< CellInfo
> xCellInfo( aMatrix
[nCol
][nRow
] );
773 Color
aTextColor( COL_AUTO
);
774 if( xCellInfo
.get() )
776 // fill cell background
777 const Rectangle
aRect( nX
, nY
, nX
+ nCellWidth
- 1, nY
+ nCellHeight
- 1 );
779 if( xCellInfo
->maCellColor
.GetColor() != COL_TRANSPARENT
)
781 pAccess
->SetFillColor( xCellInfo
->maCellColor
);
782 pAccess
->FillRect( aRect
);
785 aTextColor
= xCellInfo
->maTextColor
;
788 // draw text preview line
789 if( aTextColor
.GetColor() == COL_AUTO
)
790 aTextColor
.SetColor( bIsPageDark
? COL_WHITE
: COL_BLACK
);
791 pAccess
->SetLineColor( aTextColor
);
792 const Point
aPnt1( nX
+ 2, nY
+ ((nCellHeight
- 1 ) >> 1) );
793 const Point
aPnt2( nX
+ nCellWidth
- 3, aPnt1
.Y() );
794 pAccess
->DrawLine( aPnt1
, aPnt2
);
798 // second draw border lines
800 for( nRow
= 0; nRow
< nPreviewRows
; ++nRow
, nY
+= nCellHeight
-1 )
803 for( sal_Int32 nCol
= 0; nCol
< nPreviewColumns
; ++nCol
, nX
+= nCellWidth
-1 )
805 boost::shared_ptr
< CellInfo
> xCellInfo( aMatrix
[nCol
][nRow
] );
807 if( xCellInfo
.get() )
809 const Point
aPntTL( nX
, nY
);
810 const Point
aPntTR( nX
+ nCellWidth
- 1, nY
);
811 const Point
aPntBL( nX
, nY
+ nCellHeight
- 1 );
812 const Point
aPntBR( nX
+ nCellWidth
- 1, nY
+ nCellHeight
- 1 );
814 sal_Int32 border_diffs
[8] = { 0,-1, 0,1, -1,0, 1,0 };
815 sal_Int32
* pDiff
= &border_diffs
[0];
818 for( USHORT nLine
= 0; nLine
< 4; ++nLine
)
820 const SvxBorderLine
* pBorderLine
= xCellInfo
->maBorder
.GetLine(nLine
);
821 if( !pBorderLine
|| ((pBorderLine
->GetOutWidth() == 0) && (pBorderLine
->GetInWidth()==0)) )
824 sal_Int32 nBorderCol
= nCol
+ *pDiff
++;
825 sal_Int32 nBorderRow
= nRow
+ *pDiff
++;
826 if( (nBorderCol
>= 0) && (nBorderCol
< nPreviewColumns
) && (nBorderRow
>= 0) && (nBorderRow
< nPreviewRows
) )
829 boost::shared_ptr
< CellInfo
> xBorderInfo( aMatrix
[nBorderCol
][nBorderRow
] );
830 if( xBorderInfo
.get() )
832 const USHORT nOtherLine
= nLine
^ 1;
833 const SvxBorderLine
* pBorderLine2
= xBorderInfo
->maBorder
.GetLine(nOtherLine
^1);
834 if( pBorderLine2
&& pBorderLine2
->HasPriority(*pBorderLine
) )
835 continue; // other border line wins
839 pAccess
->SetLineColor( pBorderLine
->GetColor() );
842 case 0: pAccess
->DrawLine( aPntTL
, aPntTR
); break;
843 case 1: pAccess
->DrawLine( aPntBL
, aPntBR
); break;
844 case 2: pAccess
->DrawLine( aPntTL
, aPntBL
); break;
845 case 3: pAccess
->DrawLine( aPntTR
, aPntBR
); break;
852 aPreviewBmp
.ReleaseAccess( pAccess
);
858 void TableDesignPane::FillDesignPreviewControl()
860 ValueSet
* pValueSet
= static_cast< ValueSet
* >( mxControls
[CT_TABLE_STYLES
].get() );
862 USHORT nSelectedItem
= pValueSet
->GetSelectItemId();
866 TableStyleSettings aSettings
;
867 if( mxSelectedTable
.is() )
869 aSettings
.mbUseFirstRow
= static_cast< CheckBox
* >(mxControls
[CB_HEADER_ROW
].get())->IsChecked();
870 aSettings
.mbUseLastRow
= static_cast< CheckBox
* >(mxControls
[CB_TOTAL_ROW
].get())->IsChecked();
871 aSettings
.mbUseRowBanding
= static_cast< CheckBox
* >(mxControls
[CB_BANDED_ROWS
].get())->IsChecked();
872 aSettings
.mbUseFirstColumn
= static_cast< CheckBox
* >(mxControls
[CB_FIRST_COLUMN
].get())->IsChecked();
873 aSettings
.mbUseLastColumn
= static_cast< CheckBox
* >(mxControls
[CB_LAST_COLUMN
].get())->IsChecked();
874 aSettings
.mbUseColumnBanding
= static_cast< CheckBox
* >(mxControls
[CB_BANDED_COLUMNS
].get())->IsChecked();
877 sal_Bool bIsPageDark
= sal_False
;
880 Reference
< XPropertySet
> xPageSet( mxView
->getCurrentPage(), UNO_QUERY
);
883 const OUString
sIsBackgroundDark( RTL_CONSTASCII_USTRINGPARAM( "IsBackgroundDark" ) );
884 xPageSet
->getPropertyValue(sIsBackgroundDark
) >>= bIsPageDark
;
888 for( sal_Int32 nIndex
= 0; nIndex
< mxTableFamily
->getCount(); nIndex
++ ) try
890 Reference
< XIndexAccess
> xTableStyle( mxTableFamily
->getByIndex( nIndex
), UNO_QUERY
);
891 if( xTableStyle
.is() )
892 pValueSet
->InsertItem( sal::static_int_cast
<USHORT
>( nIndex
+ 1 ), Image( CreateDesignPreview( xTableStyle
, aSettings
, bIsPageDark
) ) );
896 DBG_ERROR("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!");
901 DBG_ERROR("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!");
903 pValueSet
->SelectItem(nSelectedItem
);
906 // ====================================================================
908 TableDesignDialog::TableDesignDialog(::Window
* pParent
, ViewShellBase
& rBase
)
909 : ModalDialog( pParent
, SdResId( DLG_TABLEDESIGNPANE
))
912 mxFlSep1
.reset( new FixedLine( this, SdResId( FL_SEP1
) ) );
913 mxFlSep2
.reset( new FixedLine( this, SdResId( FL_SEP2
) ) );
914 mxHelpButton
.reset( new HelpButton( this, SdResId( BTN_HELP
) ) );
915 mxOkButton
.reset( new OKButton( this, SdResId( BTN_OK
) ) );
916 mxCancelButton
.reset( new CancelButton( this, SdResId( BTN_CANCEL
) ) );
919 mpDesignPane
.reset( new TableDesignPane( this, rBase
, true ) );
920 mpDesignPane
->Hide();
923 // --------------------------------------------------------------------
925 short TableDesignDialog::Execute()
927 if( ModalDialog::Execute() )
929 if( mpDesignPane
->isStyleChanged() )
930 mpDesignPane
->ApplyStyle();
932 if( mpDesignPane
->isOptionsChanged() )
933 mpDesignPane
->ApplyOptions();
939 // ====================================================================
941 ::Window
* createTableDesignPanel( ::Window
* pParent
, ViewShellBase
& rBase
)
943 return new TableDesignPane( pParent
, rBase
, false );
946 // ====================================================================
948 void showTableDesignDialog( ::Window
* pParent
, ViewShellBase
& rBase
)
950 boost::scoped_ptr
< TableDesignDialog
> xDialog( new TableDesignDialog( pParent
, rBase
) );