1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "sddll.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/beans/XMultiPropertyStates.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/view/XSelectionSupplier.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/style/XStyle.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/style/XStyleFamiliesSupplier.hpp> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 40*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 41*cdf0e10cSrcweir #include <vcl/bmpacc.hxx> 42*cdf0e10cSrcweir #include <svl/style.hxx> 43*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 44*cdf0e10cSrcweir #include <sfx2/bindings.hxx> 45*cdf0e10cSrcweir #include <sfx2/app.hxx> 46*cdf0e10cSrcweir #include <sfx2/request.hxx> 47*cdf0e10cSrcweir #include <sfx2/dispatch.hxx> 48*cdf0e10cSrcweir #include <svx/svxids.hrc> 49*cdf0e10cSrcweir #include <svx/svdetc.hxx> 50*cdf0e10cSrcweir #include <editeng/boxitem.hxx> 51*cdf0e10cSrcweir #include <editeng/borderline.hxx> 52*cdf0e10cSrcweir #include <editeng/colritem.hxx> 53*cdf0e10cSrcweir #include <editeng/eeitem.hxx> 54*cdf0e10cSrcweir #include <svx/sdr/table/tabledesign.hxx> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir #include "TableDesignPane.hxx" 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include "DrawDocShell.hxx" 59*cdf0e10cSrcweir #include "ViewShellBase.hxx" 60*cdf0e10cSrcweir #include "DrawViewShell.hxx" 61*cdf0e10cSrcweir #include "DrawController.hxx" 62*cdf0e10cSrcweir #include "glob.hrc" 63*cdf0e10cSrcweir #include "sdresid.hxx" 64*cdf0e10cSrcweir #include "EventMultiplexer.hxx" 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir #define C2U(x) OUString( RTL_CONSTASCII_USTRINGPARAM( x ) ) 67*cdf0e10cSrcweir using ::rtl::OUString; 68*cdf0e10cSrcweir using namespace ::com::sun::star; 69*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 70*cdf0e10cSrcweir using namespace ::com::sun::star::drawing; 71*cdf0e10cSrcweir using namespace ::com::sun::star::container; 72*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 73*cdf0e10cSrcweir using namespace ::com::sun::star::view; 74*cdf0e10cSrcweir using namespace ::com::sun::star::style; 75*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 76*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 77*cdf0e10cSrcweir using namespace ::com::sun::star::ui; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir namespace sd { 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir static const sal_Int32 nPreviewColumns = 5; 82*cdf0e10cSrcweir static const sal_Int32 nPreviewRows = 5; 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir // -------------------------------------------------------------------- 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir static const OUString* getPropertyNames() 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir static const OUString gPropNames[ CB_BANDED_COLUMNS-CB_HEADER_ROW+1 ] = 89*cdf0e10cSrcweir { 90*cdf0e10cSrcweir 91*cdf0e10cSrcweir C2U( "UseFirstRowStyle" ), 92*cdf0e10cSrcweir C2U( "UseLastRowStyle" ), 93*cdf0e10cSrcweir C2U( "UseBandingRowStyle" ), 94*cdf0e10cSrcweir C2U( "UseFirstColumnStyle" ), 95*cdf0e10cSrcweir C2U( "UseLastColumnStyle" ), 96*cdf0e10cSrcweir C2U( "UseBandingColumnStyle" ) 97*cdf0e10cSrcweir }; 98*cdf0e10cSrcweir return &gPropNames[0]; 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir // -------------------------------------------------------------------- 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir TableDesignPane::TableDesignPane( ::Window* pParent, ViewShellBase& rBase, bool bModal ) 103*cdf0e10cSrcweir : Control( pParent, SdResId(DLG_TABLEDESIGNPANE) ) 104*cdf0e10cSrcweir , mrBase( rBase ) 105*cdf0e10cSrcweir , msTableTemplate( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) ) 106*cdf0e10cSrcweir , mbModal( bModal ) 107*cdf0e10cSrcweir , mbStyleSelected( false ) 108*cdf0e10cSrcweir , mbOptionsChanged( false ) 109*cdf0e10cSrcweir { 110*cdf0e10cSrcweir Window* pControlParent = mbModal ? pParent : this; 111*cdf0e10cSrcweir 112*cdf0e10cSrcweir mxControls[FL_TABLE_STYLES].reset( new FixedLine( pControlParent, SdResId( FL_TABLE_STYLES + 1 ) ) ); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir ValueSet* pValueSet = new ValueSet( pControlParent, SdResId( CT_TABLE_STYLES+1 ) ); 115*cdf0e10cSrcweir mxControls[CT_TABLE_STYLES].reset( pValueSet ); 116*cdf0e10cSrcweir if( !mbModal ) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir pValueSet->SetStyle( (pValueSet->GetStyle() & ~(WB_ITEMBORDER|WB_BORDER)) | WB_NO_DIRECTSELECT | WB_FLATVALUESET | WB_NOBORDER ); 119*cdf0e10cSrcweir pValueSet->SetColor(); 120*cdf0e10cSrcweir pValueSet->SetExtraSpacing(8); 121*cdf0e10cSrcweir } 122*cdf0e10cSrcweir else 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir pValueSet->SetColor( Color( COL_WHITE ) ); 125*cdf0e10cSrcweir pValueSet->SetBackground( Color( COL_WHITE ) ); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir pValueSet->SetSelectHdl (LINK(this, TableDesignPane, implValueSetHdl)); 128*cdf0e10cSrcweir 129*cdf0e10cSrcweir mxControls[FL_STYLE_OPTIONS].reset( new FixedLine( pControlParent, SdResId( FL_STYLE_OPTIONS + 1 ) ) ); 130*cdf0e10cSrcweir sal_uInt16 i; 131*cdf0e10cSrcweir for( i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i ) 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir CheckBox *pCheckBox = new CheckBox( pControlParent, SdResId( i+1 ) ); 134*cdf0e10cSrcweir mxControls[i].reset( pCheckBox ); 135*cdf0e10cSrcweir pCheckBox->SetClickHdl( LINK( this, TableDesignPane, implCheckBoxHdl ) ); 136*cdf0e10cSrcweir } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir for( i = 0; i < DESIGNPANE_CONTROL_COUNT; i++ ) 139*cdf0e10cSrcweir mnOrgOffsetY[i] = mxControls[i]->GetPosPixel().Y(); 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir // get current controller and initialize listeners 142*cdf0e10cSrcweir try 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir mxView = Reference< XDrawView >::query(mrBase.GetController()); 145*cdf0e10cSrcweir addListener(); 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir Reference< XController > xController( mrBase.GetController(), UNO_QUERY_THROW ); 148*cdf0e10cSrcweir Reference< XStyleFamiliesSupplier > xFamiliesSupp( xController->getModel(), UNO_QUERY_THROW ); 149*cdf0e10cSrcweir Reference< XNameAccess > xFamilies( xFamiliesSupp->getStyleFamilies() ); 150*cdf0e10cSrcweir const OUString sFamilyName( RTL_CONSTASCII_USTRINGPARAM("table" ) ); 151*cdf0e10cSrcweir mxTableFamily = Reference< XIndexAccess >( xFamilies->getByName( sFamilyName ), UNO_QUERY_THROW ); 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir catch( Exception& e ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir (void)e; 157*cdf0e10cSrcweir DBG_ERROR( "sd::CustomAnimationPane::CustomAnimationPane(), Exception caught!" ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir onSelectionChanged(); 161*cdf0e10cSrcweir updateControls(); 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir FreeResource(); 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir // -------------------------------------------------------------------- 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir TableDesignPane::~TableDesignPane() 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir removeListener(); 171*cdf0e10cSrcweir } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir // -------------------------------------------------------------------- 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir void TableDesignPane::DataChanged( const DataChangedEvent& /*rDCEvt*/ ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir updateLayout(); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir // -------------------------------------------------------------------- 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir void TableDesignPane::Resize() 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir updateLayout(); 185*cdf0e10cSrcweir } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir // -------------------------------------------------------------------- 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir static SfxBindings* getBindings( ViewShellBase& rBase ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() ) 192*cdf0e10cSrcweir return &rBase.GetMainViewShell()->GetViewFrame()->GetBindings(); 193*cdf0e10cSrcweir else 194*cdf0e10cSrcweir return 0; 195*cdf0e10cSrcweir } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir // -------------------------------------------------------------------- 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir static SfxDispatcher* getDispatcher( ViewShellBase& rBase ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir if( rBase.GetMainViewShell().get() && rBase.GetMainViewShell()->GetViewFrame() ) 202*cdf0e10cSrcweir return rBase.GetMainViewShell()->GetViewFrame()->GetDispatcher(); 203*cdf0e10cSrcweir else 204*cdf0e10cSrcweir return 0; 205*cdf0e10cSrcweir } 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir // -------------------------------------------------------------------- 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir IMPL_LINK( TableDesignPane, implValueSetHdl, Control*, EMPTYARG ) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir mbStyleSelected = true; 212*cdf0e10cSrcweir if( !mbModal ) 213*cdf0e10cSrcweir ApplyStyle(); 214*cdf0e10cSrcweir return 0; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // -------------------------------------------------------------------- 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void TableDesignPane::ApplyStyle() 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir try 222*cdf0e10cSrcweir { 223*cdf0e10cSrcweir OUString sStyleName; 224*cdf0e10cSrcweir ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() ); 225*cdf0e10cSrcweir sal_Int32 nIndex = static_cast< sal_Int32 >( pValueSet->GetSelectItemId() ) - 1; 226*cdf0e10cSrcweir 227*cdf0e10cSrcweir if( (nIndex >= 0) && (nIndex < mxTableFamily->getCount()) ) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY_THROW ); 230*cdf0e10cSrcweir sStyleName = xNames->getElementNames()[nIndex]; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir if( sStyleName.getLength() == 0 ) 234*cdf0e10cSrcweir return; 235*cdf0e10cSrcweir 236*cdf0e10cSrcweir SdrView* pView = mrBase.GetDrawView(); 237*cdf0e10cSrcweir if( mxSelectedTable.is() ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir if( pView ) 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir SfxRequest aReq( SID_TABLE_STYLE, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() ); 242*cdf0e10cSrcweir aReq.AppendItem( SfxStringItem( SID_TABLE_STYLE, sStyleName ) ); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() ); 245*cdf0e10cSrcweir if( xController.is() ) 246*cdf0e10cSrcweir xController->Execute( aReq ); 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir SfxBindings* pBindings = getBindings( mrBase ); 249*cdf0e10cSrcweir if( pBindings ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir pBindings->Invalidate( SID_UNDO ); 252*cdf0e10cSrcweir pBindings->Invalidate( SID_REDO ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir } 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir else 257*cdf0e10cSrcweir { 258*cdf0e10cSrcweir SfxDispatcher* pDispatcher = getDispatcher( mrBase ); 259*cdf0e10cSrcweir SfxStringItem aArg( SID_TABLE_STYLE, sStyleName ); 260*cdf0e10cSrcweir pDispatcher->Execute(SID_INSERT_TABLE, SFX_CALLMODE_ASYNCHRON, &aArg, 0 ); 261*cdf0e10cSrcweir } 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir catch( Exception& ) 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir DBG_ERROR("TableDesignPane::implValueSetHdl(), exception caught!"); 266*cdf0e10cSrcweir } 267*cdf0e10cSrcweir } 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir // -------------------------------------------------------------------- 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir IMPL_LINK( TableDesignPane, implCheckBoxHdl, Control*, EMPTYARG ) 272*cdf0e10cSrcweir { 273*cdf0e10cSrcweir mbOptionsChanged = true; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir if( !mbModal ) 276*cdf0e10cSrcweir ApplyOptions(); 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir FillDesignPreviewControl(); 279*cdf0e10cSrcweir return 0; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir // -------------------------------------------------------------------- 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir void TableDesignPane::ApplyOptions() 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir static sal_uInt16 gParamIds[CB_BANDED_COLUMNS-CB_HEADER_ROW+1] = 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir ID_VAL_USEFIRSTROWSTYLE, ID_VAL_USELASTROWSTYLE, ID_VAL_USEBANDINGROWSTYLE, 289*cdf0e10cSrcweir ID_VAL_USEFIRSTCOLUMNSTYLE, ID_VAL_USELASTCOLUMNSTYLE, ID_VAL_USEBANDINGCOLUMNSTYLE 290*cdf0e10cSrcweir }; 291*cdf0e10cSrcweir 292*cdf0e10cSrcweir if( mxSelectedTable.is() ) 293*cdf0e10cSrcweir { 294*cdf0e10cSrcweir SfxRequest aReq( SID_TABLE_STYLE_SETTINGS, SFX_CALLMODE_SYNCHRON, SFX_APP()->GetPool() ); 295*cdf0e10cSrcweir 296*cdf0e10cSrcweir for( sal_uInt16 i = 0; i < (CB_BANDED_COLUMNS-CB_HEADER_ROW+1); ++i ) 297*cdf0e10cSrcweir { 298*cdf0e10cSrcweir aReq.AppendItem( SfxBoolItem( gParamIds[i], static_cast< CheckBox* >( mxControls[CB_HEADER_ROW+i].get() )->IsChecked() ) ); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir SdrView* pView = mrBase.GetDrawView(); 302*cdf0e10cSrcweir if( pView ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir rtl::Reference< sdr::SelectionController > xController( pView->getSelectionController() ); 305*cdf0e10cSrcweir if( xController.is() ) 306*cdf0e10cSrcweir { 307*cdf0e10cSrcweir xController->Execute( aReq ); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir SfxBindings* pBindings = getBindings( mrBase ); 310*cdf0e10cSrcweir if( pBindings ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir pBindings->Invalidate( SID_UNDO ); 313*cdf0e10cSrcweir pBindings->Invalidate( SID_REDO ); 314*cdf0e10cSrcweir } 315*cdf0e10cSrcweir } 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir } 318*cdf0e10cSrcweir } 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir // -------------------------------------------------------------------- 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir void TableDesignPane::onSelectionChanged() 323*cdf0e10cSrcweir { 324*cdf0e10cSrcweir Reference< XPropertySet > xNewSelection; 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir if( mxView.is() ) try 327*cdf0e10cSrcweir { 328*cdf0e10cSrcweir Reference< XSelectionSupplier > xSel( mxView, UNO_QUERY_THROW ); 329*cdf0e10cSrcweir if (xSel.is()) 330*cdf0e10cSrcweir { 331*cdf0e10cSrcweir Any aSel( xSel->getSelection() ); 332*cdf0e10cSrcweir Sequence< XShape > xShapeSeq; 333*cdf0e10cSrcweir if( aSel >>= xShapeSeq ) 334*cdf0e10cSrcweir { 335*cdf0e10cSrcweir if( xShapeSeq.getLength() == 1 ) 336*cdf0e10cSrcweir aSel <<= xShapeSeq[0]; 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir else 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir Reference< XShapes > xShapes( aSel, UNO_QUERY ); 341*cdf0e10cSrcweir if( xShapes.is() && (xShapes->getCount() == 1) ) 342*cdf0e10cSrcweir aSel <<= xShapes->getByIndex(0); 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir 345*cdf0e10cSrcweir Reference< XShapeDescriptor > xDesc( aSel, UNO_QUERY ); 346*cdf0e10cSrcweir if( xDesc.is() && 347*cdf0e10cSrcweir ( xDesc->getShapeType().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.drawing.TableShape" ) ) || 348*cdf0e10cSrcweir xDesc->getShapeType().equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.presentation.TableShape" ) ) ) ) 349*cdf0e10cSrcweir { 350*cdf0e10cSrcweir xNewSelection = Reference< XPropertySet >::query( xDesc ); 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir catch( Exception& ) 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir DBG_ERROR( "sd::TableDesignPane::onSelectionChanged(), Exception caught!" ); 357*cdf0e10cSrcweir } 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir if( mxSelectedTable != xNewSelection ) 360*cdf0e10cSrcweir { 361*cdf0e10cSrcweir mxSelectedTable = xNewSelection; 362*cdf0e10cSrcweir updateControls(); 363*cdf0e10cSrcweir } 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir // -------------------------------------------------------------------- 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir void TableDesignPane::updateLayout() 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir ::Size aPaneSize( GetSizePixel() ); 371*cdf0e10cSrcweir if(IsVisible() && aPaneSize.Width() > 0) 372*cdf0e10cSrcweir { 373*cdf0e10cSrcweir Point aOffset( LogicToPixel( Point(3,3), MAP_APPFONT ) ); 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() ); 376*cdf0e10cSrcweir 377*cdf0e10cSrcweir Size aValueSetSize; 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir if( !mbModal ) 380*cdf0e10cSrcweir { 381*cdf0e10cSrcweir const long nOptionsHeight = mnOrgOffsetY[CB_BANDED_COLUMNS] + mxControls[CB_BANDED_COLUMNS]->GetSizePixel().Height() + aOffset.Y(); 382*cdf0e10cSrcweir 383*cdf0e10cSrcweir const long nStylesHeight = aPaneSize.Height() - nOptionsHeight; 384*cdf0e10cSrcweir 385*cdf0e10cSrcweir // set with of controls to size of pane 386*cdf0e10cSrcweir for( sal_Int32 nId = 0; nId < DESIGNPANE_CONTROL_COUNT; ++nId ) 387*cdf0e10cSrcweir { 388*cdf0e10cSrcweir Size aSize( mxControls[nId]->GetSizePixel() ); 389*cdf0e10cSrcweir aSize.Width() = aPaneSize.Width() - aOffset.X() - mxControls[nId]->GetPosPixel().X(); 390*cdf0e10cSrcweir mxControls[nId]->SetSizePixel( aSize ); 391*cdf0e10cSrcweir mxControls[nId]->SetPaintTransparent(sal_True); 392*cdf0e10cSrcweir mxControls[nId]->SetBackground(); 393*cdf0e10cSrcweir } 394*cdf0e10cSrcweir aValueSetSize = Size( pValueSet->GetSizePixel().Width(), nStylesHeight - mxControls[FL_TABLE_STYLES]->GetSizePixel().Height() - mnOrgOffsetY[FL_TABLE_STYLES] ); 395*cdf0e10cSrcweir } 396*cdf0e10cSrcweir else 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir aValueSetSize = pValueSet->GetSizePixel(); 399*cdf0e10cSrcweir } 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir // Calculate the number of rows and columns. 403*cdf0e10cSrcweir if( pValueSet->GetItemCount() > 0 ) 404*cdf0e10cSrcweir { 405*cdf0e10cSrcweir Image aImage = pValueSet->GetItemImage(pValueSet->GetItemId(0)); 406*cdf0e10cSrcweir Size aItemSize = pValueSet->CalcItemSizePixel(aImage.GetSizePixel()); 407*cdf0e10cSrcweir pValueSet->SetItemWidth( aItemSize.Width() ); 408*cdf0e10cSrcweir pValueSet->SetItemHeight( aItemSize.Height() ); 409*cdf0e10cSrcweir 410*cdf0e10cSrcweir aItemSize.Width() += 10; 411*cdf0e10cSrcweir aItemSize.Height() += 10; 412*cdf0e10cSrcweir int nColumnCount = (aValueSetSize.Width() - pValueSet->GetScrollWidth()) / aItemSize.Width(); 413*cdf0e10cSrcweir if (nColumnCount < 1) 414*cdf0e10cSrcweir nColumnCount = 1; 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir int nRowCount = (pValueSet->GetItemCount() + nColumnCount - 1) / nColumnCount; 417*cdf0e10cSrcweir if (nRowCount < 1) 418*cdf0e10cSrcweir nRowCount = 1; 419*cdf0e10cSrcweir 420*cdf0e10cSrcweir int nVisibleRowCount = (aValueSetSize.Height()+2) / aItemSize.Height(); 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir pValueSet->SetLineCount ( (nRowCount < nVisibleRowCount) ? (sal_uInt16)nRowCount : 0 ); 423*cdf0e10cSrcweir 424*cdf0e10cSrcweir pValueSet->SetColCount ((sal_uInt16)nColumnCount); 425*cdf0e10cSrcweir pValueSet->SetLineCount ((sal_uInt16)nRowCount); 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir if( !mbModal ) 428*cdf0e10cSrcweir { 429*cdf0e10cSrcweir WinBits nStyle = pValueSet->GetStyle() & ~(WB_VSCROLL); 430*cdf0e10cSrcweir if( nRowCount < nVisibleRowCount ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir aValueSetSize.Height() = nRowCount * aItemSize.Height(); 433*cdf0e10cSrcweir } 434*cdf0e10cSrcweir else if( nRowCount > nVisibleRowCount ) 435*cdf0e10cSrcweir { 436*cdf0e10cSrcweir nStyle |= WB_VSCROLL; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir pValueSet->SetStyle( nStyle ); 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir } 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir if( !mbModal ) 443*cdf0e10cSrcweir { 444*cdf0e10cSrcweir pValueSet->SetSizePixel( aValueSetSize ); 445*cdf0e10cSrcweir pValueSet->SetBackground( GetSettings().GetStyleSettings().GetWindowColor() ); 446*cdf0e10cSrcweir pValueSet->SetColor( GetSettings().GetStyleSettings().GetWindowColor() ); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir Point aPos( pValueSet->GetPosPixel() ); 449*cdf0e10cSrcweir 450*cdf0e10cSrcweir // The following line may look like a no-op but without it the 451*cdf0e10cSrcweir // control is placed off-screen when RTL is active. 452*cdf0e10cSrcweir pValueSet->SetPosPixel(pValueSet->GetPosPixel()); 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir // shift show options section down 455*cdf0e10cSrcweir const long nOptionsPos = aPos.Y() + aValueSetSize.Height(); 456*cdf0e10cSrcweir for( sal_Int32 nId = FL_STYLE_OPTIONS; nId <= CB_BANDED_COLUMNS; ++nId ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir Point aCPos( mxControls[nId]->GetPosPixel() ); 459*cdf0e10cSrcweir aCPos.X() = ( nId == FL_STYLE_OPTIONS ? 1 : 2 ) * aOffset.X(); 460*cdf0e10cSrcweir aCPos.Y() = mnOrgOffsetY[nId] + nOptionsPos; 461*cdf0e10cSrcweir mxControls[nId]->SetPosPixel( aCPos ); 462*cdf0e10cSrcweir } 463*cdf0e10cSrcweir } 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir 466*cdf0e10cSrcweir if( !mbModal ) 467*cdf0e10cSrcweir SetBackground( GetSettings().GetStyleSettings().GetWindowColor() ); 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir // -------------------------------------------------------------------- 471*cdf0e10cSrcweir 472*cdf0e10cSrcweir void TableDesignPane::updateControls() 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir static sal_Bool gDefaults[CB_BANDED_COLUMNS-CB_HEADER_ROW+1] = { sal_True, sal_False, sal_True, sal_False, sal_False, sal_False }; 475*cdf0e10cSrcweir 476*cdf0e10cSrcweir const bool bHasTable = mxSelectedTable.is(); 477*cdf0e10cSrcweir const OUString* pPropNames = getPropertyNames(); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir for( sal_uInt16 i = CB_HEADER_ROW; i <= CB_BANDED_COLUMNS; ++i ) 480*cdf0e10cSrcweir { 481*cdf0e10cSrcweir sal_Bool bUse = gDefaults[i-CB_HEADER_ROW]; 482*cdf0e10cSrcweir if( bHasTable ) try 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir mxSelectedTable->getPropertyValue( *pPropNames++ ) >>= bUse; 485*cdf0e10cSrcweir } 486*cdf0e10cSrcweir catch( Exception& ) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir DBG_ERROR("sd::TableDesignPane::updateControls(), exception caught!"); 489*cdf0e10cSrcweir } 490*cdf0e10cSrcweir static_cast< CheckBox* >( mxControls[i].get() )->Check( bUse ? sal_True : sal_False ); 491*cdf0e10cSrcweir mxControls[i]->Enable(bHasTable ? sal_True : sal_False ); 492*cdf0e10cSrcweir } 493*cdf0e10cSrcweir 494*cdf0e10cSrcweir FillDesignPreviewControl(); 495*cdf0e10cSrcweir updateLayout(); 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir sal_uInt16 nSelection = 0; 499*cdf0e10cSrcweir if( mxSelectedTable.is() ) 500*cdf0e10cSrcweir { 501*cdf0e10cSrcweir Reference< XNamed > xNamed( mxSelectedTable->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "TableTemplate" ) ) ), UNO_QUERY ); 502*cdf0e10cSrcweir if( xNamed.is() ) 503*cdf0e10cSrcweir { 504*cdf0e10cSrcweir const OUString sStyleName( xNamed->getName() ); 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir Reference< XNameAccess > xNames( mxTableFamily, UNO_QUERY ); 507*cdf0e10cSrcweir if( xNames.is() ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir Sequence< OUString > aNames( xNames->getElementNames() ); 510*cdf0e10cSrcweir for( sal_Int32 nIndex = 0; nIndex < aNames.getLength(); nIndex++ ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir if( aNames[nIndex] == sStyleName ) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir nSelection = (sal_uInt16)nIndex+1; 515*cdf0e10cSrcweir break; 516*cdf0e10cSrcweir } 517*cdf0e10cSrcweir } 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir } 520*cdf0e10cSrcweir } 521*cdf0e10cSrcweir ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() ); 522*cdf0e10cSrcweir pValueSet->SelectItem( nSelection ); 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir 525*cdf0e10cSrcweir // -------------------------------------------------------------------- 526*cdf0e10cSrcweir 527*cdf0e10cSrcweir void TableDesignPane::addListener() 528*cdf0e10cSrcweir { 529*cdf0e10cSrcweir Link aLink( LINK(this,TableDesignPane,EventMultiplexerListener) ); 530*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->AddEventListener ( 531*cdf0e10cSrcweir aLink, 532*cdf0e10cSrcweir tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION 533*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_CURRENT_PAGE 534*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED 535*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED 536*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_DISPOSING); 537*cdf0e10cSrcweir } 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir // -------------------------------------------------------------------- 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir void TableDesignPane::removeListener() 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir Link aLink( LINK(this,TableDesignPane,EventMultiplexerListener) ); 544*cdf0e10cSrcweir mrBase.GetEventMultiplexer()->RemoveEventListener( aLink ); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir // -------------------------------------------------------------------- 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir IMPL_LINK(TableDesignPane,EventMultiplexerListener, 550*cdf0e10cSrcweir tools::EventMultiplexerEvent*,pEvent) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir switch (pEvent->meEventId) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_CURRENT_PAGE: 555*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_EDIT_VIEW_SELECTION: 556*cdf0e10cSrcweir onSelectionChanged(); 557*cdf0e10cSrcweir break; 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_MAIN_VIEW_REMOVED: 560*cdf0e10cSrcweir mxView = Reference<XDrawView>(); 561*cdf0e10cSrcweir onSelectionChanged(); 562*cdf0e10cSrcweir break; 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_MAIN_VIEW_ADDED: 565*cdf0e10cSrcweir mxView = Reference<XDrawView>::query( mrBase.GetController() ); 566*cdf0e10cSrcweir onSelectionChanged(); 567*cdf0e10cSrcweir break; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir return 0; 570*cdf0e10cSrcweir } 571*cdf0e10cSrcweir 572*cdf0e10cSrcweir // -------------------------------------------------------------------- 573*cdf0e10cSrcweir 574*cdf0e10cSrcweir struct CellInfo 575*cdf0e10cSrcweir { 576*cdf0e10cSrcweir Color maCellColor; 577*cdf0e10cSrcweir Color maTextColor; 578*cdf0e10cSrcweir SvxBoxItem maBorder; 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir explicit CellInfo( const Reference< XStyle >& xStyle ); 581*cdf0e10cSrcweir }; 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir CellInfo::CellInfo( const Reference< XStyle >& xStyle ) 584*cdf0e10cSrcweir : maBorder(SDRATTR_TABLE_BORDER) 585*cdf0e10cSrcweir { 586*cdf0e10cSrcweir SfxStyleSheet* pStyleSheet = SfxUnoStyleSheet::getUnoStyleSheet( xStyle ); 587*cdf0e10cSrcweir if( pStyleSheet ) 588*cdf0e10cSrcweir { 589*cdf0e10cSrcweir SfxItemSet& rSet = pStyleSheet->GetItemSet(); 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir // get style fill color 592*cdf0e10cSrcweir if( !GetDraftFillColor(rSet, maCellColor) ) 593*cdf0e10cSrcweir maCellColor.SetColor( COL_TRANSPARENT ); 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir // get style text color 596*cdf0e10cSrcweir const SvxColorItem* pTextColor = dynamic_cast<const SvxColorItem*>( rSet.GetItem(EE_CHAR_COLOR) ); 597*cdf0e10cSrcweir if( pTextColor ) 598*cdf0e10cSrcweir maTextColor = pTextColor->GetValue(); 599*cdf0e10cSrcweir else 600*cdf0e10cSrcweir maTextColor.SetColor( COL_TRANSPARENT ); 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // get border 603*cdf0e10cSrcweir const SvxBoxItem* pBoxItem = dynamic_cast<const SvxBoxItem*>(rSet.GetItem( SDRATTR_TABLE_BORDER ) ); 604*cdf0e10cSrcweir if( pBoxItem ) 605*cdf0e10cSrcweir maBorder = *pBoxItem; 606*cdf0e10cSrcweir } 607*cdf0e10cSrcweir } 608*cdf0e10cSrcweir 609*cdf0e10cSrcweir // -------------------------------------------------------------------- 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir typedef std::vector< boost::shared_ptr< CellInfo > > CellInfoVector; 612*cdf0e10cSrcweir typedef boost::shared_ptr< CellInfo > CellInfoMatrix[nPreviewColumns][nPreviewRows]; 613*cdf0e10cSrcweir 614*cdf0e10cSrcweir struct TableStyleSettings 615*cdf0e10cSrcweir { 616*cdf0e10cSrcweir bool mbUseFirstRow; 617*cdf0e10cSrcweir bool mbUseLastRow; 618*cdf0e10cSrcweir bool mbUseFirstColumn; 619*cdf0e10cSrcweir bool mbUseLastColumn; 620*cdf0e10cSrcweir bool mbUseRowBanding; 621*cdf0e10cSrcweir bool mbUseColumnBanding; 622*cdf0e10cSrcweir 623*cdf0e10cSrcweir TableStyleSettings() 624*cdf0e10cSrcweir : mbUseFirstRow(true) 625*cdf0e10cSrcweir , mbUseLastRow(false) 626*cdf0e10cSrcweir , mbUseFirstColumn(false) 627*cdf0e10cSrcweir , mbUseLastColumn(false) 628*cdf0e10cSrcweir , mbUseRowBanding(true) 629*cdf0e10cSrcweir , mbUseColumnBanding(false) {} 630*cdf0e10cSrcweir }; 631*cdf0e10cSrcweir 632*cdf0e10cSrcweir // -------------------------------------------------------------------- 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir static void FillCellInfoVector( const Reference< XIndexAccess >& xTableStyle, CellInfoVector& rVector ) 635*cdf0e10cSrcweir { 636*cdf0e10cSrcweir DBG_ASSERT( xTableStyle.is() && (xTableStyle->getCount() == sdr::table::style_count ), "sd::FillCellInfoVector(), inavlid table style!" ); 637*cdf0e10cSrcweir if( xTableStyle.is() ) try 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir rVector.resize( sdr::table::style_count ); 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir for( sal_Int32 nStyle = 0; nStyle < sdr::table::style_count; ++nStyle ) 642*cdf0e10cSrcweir { 643*cdf0e10cSrcweir Reference< XStyle > xStyle( xTableStyle->getByIndex( nStyle ), UNO_QUERY ); 644*cdf0e10cSrcweir if( xStyle.is() ) 645*cdf0e10cSrcweir rVector[nStyle].reset( new CellInfo( xStyle ) ); 646*cdf0e10cSrcweir } 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir catch(Exception&) 649*cdf0e10cSrcweir { 650*cdf0e10cSrcweir DBG_ERROR("sd::FillCellInfoVector(), exception caught!"); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir } 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir static void FillCellInfoMatrix( const CellInfoVector& rStyle, const TableStyleSettings& rSettings, CellInfoMatrix& rMatrix ) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir for( sal_Int32 nRow = 0; nRow < nPreviewColumns; ++nRow ) 657*cdf0e10cSrcweir { 658*cdf0e10cSrcweir const bool bFirstRow = rSettings.mbUseFirstRow && (nRow == 0); 659*cdf0e10cSrcweir const bool bLastRow = rSettings.mbUseLastRow && (nRow == nPreviewColumns - 1); 660*cdf0e10cSrcweir 661*cdf0e10cSrcweir for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol ) 662*cdf0e10cSrcweir { 663*cdf0e10cSrcweir boost::shared_ptr< CellInfo > xCellInfo; 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir // first and last row win first, if used and available 666*cdf0e10cSrcweir if( bFirstRow ) 667*cdf0e10cSrcweir { 668*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::first_row_style]; 669*cdf0e10cSrcweir } 670*cdf0e10cSrcweir else if( bLastRow ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::last_row_style]; 673*cdf0e10cSrcweir } 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir if( !xCellInfo.get() ) 676*cdf0e10cSrcweir { 677*cdf0e10cSrcweir // next come first and last column, if used and available 678*cdf0e10cSrcweir if( rSettings.mbUseFirstColumn && (nCol == 0) ) 679*cdf0e10cSrcweir { 680*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::first_column_style]; 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir else if( rSettings.mbUseLastColumn && (nCol == nPreviewColumns-1) ) 683*cdf0e10cSrcweir { 684*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::last_column_style]; 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir if( !xCellInfo.get() ) 689*cdf0e10cSrcweir { 690*cdf0e10cSrcweir if( rSettings.mbUseRowBanding ) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir if( (nRow & 1) == 0 ) 693*cdf0e10cSrcweir { 694*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::even_rows_style]; 695*cdf0e10cSrcweir } 696*cdf0e10cSrcweir else 697*cdf0e10cSrcweir { 698*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::odd_rows_style]; 699*cdf0e10cSrcweir } 700*cdf0e10cSrcweir } 701*cdf0e10cSrcweir } 702*cdf0e10cSrcweir 703*cdf0e10cSrcweir if( !xCellInfo.get() ) 704*cdf0e10cSrcweir { 705*cdf0e10cSrcweir if( rSettings.mbUseColumnBanding ) 706*cdf0e10cSrcweir { 707*cdf0e10cSrcweir if( (nCol & 1) == 0 ) 708*cdf0e10cSrcweir { 709*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::even_columns_style]; 710*cdf0e10cSrcweir } 711*cdf0e10cSrcweir else 712*cdf0e10cSrcweir { 713*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::odd_columns_style]; 714*cdf0e10cSrcweir } 715*cdf0e10cSrcweir } 716*cdf0e10cSrcweir } 717*cdf0e10cSrcweir 718*cdf0e10cSrcweir if( !xCellInfo.get() ) 719*cdf0e10cSrcweir { 720*cdf0e10cSrcweir // use default cell style if non found yet 721*cdf0e10cSrcweir xCellInfo = rStyle[sdr::table::body_style]; 722*cdf0e10cSrcweir } 723*cdf0e10cSrcweir 724*cdf0e10cSrcweir rMatrix[nCol][nRow] = xCellInfo; 725*cdf0e10cSrcweir } 726*cdf0e10cSrcweir } 727*cdf0e10cSrcweir } 728*cdf0e10cSrcweir 729*cdf0e10cSrcweir // -------------------------------------------------------------------- 730*cdf0e10cSrcweir 731*cdf0e10cSrcweir const Bitmap CreateDesignPreview( const Reference< XIndexAccess >& xTableStyle, const TableStyleSettings& rSettings, bool bIsPageDark ) 732*cdf0e10cSrcweir { 733*cdf0e10cSrcweir CellInfoVector aCellInfoVector(sdr::table::style_count); 734*cdf0e10cSrcweir FillCellInfoVector( xTableStyle, aCellInfoVector ); 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir CellInfoMatrix aMatrix; 737*cdf0e10cSrcweir FillCellInfoMatrix( aCellInfoVector, rSettings, aMatrix ); 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir // bbbbbbbbbbbb w = 12 pixel 740*cdf0e10cSrcweir // bccccccccccb h = 7 pixel 741*cdf0e10cSrcweir // bccccccccccb b = border color 742*cdf0e10cSrcweir // bcttttttttcb c = cell color 743*cdf0e10cSrcweir // bccccccccccb t = text color 744*cdf0e10cSrcweir // bccccccccccb 745*cdf0e10cSrcweir // bbbbbbbbbbbb 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir 748*cdf0e10cSrcweir const sal_Int32 nCellWidth = 12; // one pixel is shared with the next cell! 749*cdf0e10cSrcweir const sal_Int32 nCellHeight = 7; // one pixel is shared with the next cell! 750*cdf0e10cSrcweir 751*cdf0e10cSrcweir Bitmap aPreviewBmp( Size( (nCellWidth * nPreviewColumns) - (nPreviewColumns - 1), (nCellHeight * nPreviewRows) - (nPreviewRows - 1)), 24, NULL ); 752*cdf0e10cSrcweir BitmapWriteAccess* pAccess = aPreviewBmp.AcquireWriteAccess(); 753*cdf0e10cSrcweir if( pAccess ) 754*cdf0e10cSrcweir { 755*cdf0e10cSrcweir pAccess->Erase( Color( bIsPageDark ? COL_BLACK : COL_WHITE ) ); 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir // first draw cell background and text line previews 758*cdf0e10cSrcweir sal_Int32 nY = 0; 759*cdf0e10cSrcweir sal_Int32 nRow; 760*cdf0e10cSrcweir for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 ) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir sal_Int32 nX = 0; 763*cdf0e10cSrcweir for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 ) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] ); 766*cdf0e10cSrcweir 767*cdf0e10cSrcweir Color aTextColor( COL_AUTO ); 768*cdf0e10cSrcweir if( xCellInfo.get() ) 769*cdf0e10cSrcweir { 770*cdf0e10cSrcweir // fill cell background 771*cdf0e10cSrcweir const Rectangle aRect( nX, nY, nX + nCellWidth - 1, nY + nCellHeight - 1 ); 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir if( xCellInfo->maCellColor.GetColor() != COL_TRANSPARENT ) 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir pAccess->SetFillColor( xCellInfo->maCellColor ); 776*cdf0e10cSrcweir pAccess->FillRect( aRect ); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir aTextColor = xCellInfo->maTextColor; 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir // draw text preview line 783*cdf0e10cSrcweir if( aTextColor.GetColor() == COL_AUTO ) 784*cdf0e10cSrcweir aTextColor.SetColor( bIsPageDark ? COL_WHITE : COL_BLACK ); 785*cdf0e10cSrcweir pAccess->SetLineColor( aTextColor ); 786*cdf0e10cSrcweir const Point aPnt1( nX + 2, nY + ((nCellHeight - 1 ) >> 1) ); 787*cdf0e10cSrcweir const Point aPnt2( nX + nCellWidth - 3, aPnt1.Y() ); 788*cdf0e10cSrcweir pAccess->DrawLine( aPnt1, aPnt2 ); 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir } 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir // second draw border lines 793*cdf0e10cSrcweir nY = 0; 794*cdf0e10cSrcweir for( nRow = 0; nRow < nPreviewRows; ++nRow, nY += nCellHeight-1 ) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir sal_Int32 nX = 0; 797*cdf0e10cSrcweir for( sal_Int32 nCol = 0; nCol < nPreviewColumns; ++nCol, nX += nCellWidth-1 ) 798*cdf0e10cSrcweir { 799*cdf0e10cSrcweir boost::shared_ptr< CellInfo > xCellInfo( aMatrix[nCol][nRow] ); 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir if( xCellInfo.get() ) 802*cdf0e10cSrcweir { 803*cdf0e10cSrcweir const Point aPntTL( nX, nY ); 804*cdf0e10cSrcweir const Point aPntTR( nX + nCellWidth - 1, nY ); 805*cdf0e10cSrcweir const Point aPntBL( nX, nY + nCellHeight - 1 ); 806*cdf0e10cSrcweir const Point aPntBR( nX + nCellWidth - 1, nY + nCellHeight - 1 ); 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir sal_Int32 border_diffs[8] = { 0,-1, 0,1, -1,0, 1,0 }; 809*cdf0e10cSrcweir sal_Int32* pDiff = &border_diffs[0]; 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir // draw top border 812*cdf0e10cSrcweir for( sal_uInt16 nLine = 0; nLine < 4; ++nLine ) 813*cdf0e10cSrcweir { 814*cdf0e10cSrcweir const SvxBorderLine* pBorderLine = xCellInfo->maBorder.GetLine(nLine); 815*cdf0e10cSrcweir if( !pBorderLine || ((pBorderLine->GetOutWidth() == 0) && (pBorderLine->GetInWidth()==0)) ) 816*cdf0e10cSrcweir continue; 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir sal_Int32 nBorderCol = nCol + *pDiff++; 819*cdf0e10cSrcweir sal_Int32 nBorderRow = nRow + *pDiff++; 820*cdf0e10cSrcweir if( (nBorderCol >= 0) && (nBorderCol < nPreviewColumns) && (nBorderRow >= 0) && (nBorderRow < nPreviewRows) ) 821*cdf0e10cSrcweir { 822*cdf0e10cSrcweir // check border 823*cdf0e10cSrcweir boost::shared_ptr< CellInfo > xBorderInfo( aMatrix[nBorderCol][nBorderRow] ); 824*cdf0e10cSrcweir if( xBorderInfo.get() ) 825*cdf0e10cSrcweir { 826*cdf0e10cSrcweir const sal_uInt16 nOtherLine = nLine ^ 1; 827*cdf0e10cSrcweir const SvxBorderLine* pBorderLine2 = xBorderInfo->maBorder.GetLine(nOtherLine^1); 828*cdf0e10cSrcweir if( pBorderLine2 && pBorderLine2->HasPriority(*pBorderLine) ) 829*cdf0e10cSrcweir continue; // other border line wins 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir } 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir pAccess->SetLineColor( pBorderLine->GetColor() ); 834*cdf0e10cSrcweir switch( nLine ) 835*cdf0e10cSrcweir { 836*cdf0e10cSrcweir case 0: pAccess->DrawLine( aPntTL, aPntTR ); break; 837*cdf0e10cSrcweir case 1: pAccess->DrawLine( aPntBL, aPntBR ); break; 838*cdf0e10cSrcweir case 2: pAccess->DrawLine( aPntTL, aPntBL ); break; 839*cdf0e10cSrcweir case 3: pAccess->DrawLine( aPntTR, aPntBR ); break; 840*cdf0e10cSrcweir } 841*cdf0e10cSrcweir } 842*cdf0e10cSrcweir } 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir } 845*cdf0e10cSrcweir 846*cdf0e10cSrcweir aPreviewBmp.ReleaseAccess( pAccess ); 847*cdf0e10cSrcweir } 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir return aPreviewBmp; 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir void TableDesignPane::FillDesignPreviewControl() 853*cdf0e10cSrcweir { 854*cdf0e10cSrcweir ValueSet* pValueSet = static_cast< ValueSet* >( mxControls[CT_TABLE_STYLES].get() ); 855*cdf0e10cSrcweir 856*cdf0e10cSrcweir sal_uInt16 nSelectedItem = pValueSet->GetSelectItemId(); 857*cdf0e10cSrcweir pValueSet->Clear(); 858*cdf0e10cSrcweir try 859*cdf0e10cSrcweir { 860*cdf0e10cSrcweir TableStyleSettings aSettings; 861*cdf0e10cSrcweir if( mxSelectedTable.is() ) 862*cdf0e10cSrcweir { 863*cdf0e10cSrcweir aSettings.mbUseFirstRow = static_cast< CheckBox* >(mxControls[CB_HEADER_ROW].get())->IsChecked(); 864*cdf0e10cSrcweir aSettings.mbUseLastRow = static_cast< CheckBox* >(mxControls[CB_TOTAL_ROW].get())->IsChecked(); 865*cdf0e10cSrcweir aSettings.mbUseRowBanding = static_cast< CheckBox* >(mxControls[CB_BANDED_ROWS].get())->IsChecked(); 866*cdf0e10cSrcweir aSettings.mbUseFirstColumn = static_cast< CheckBox* >(mxControls[CB_FIRST_COLUMN].get())->IsChecked(); 867*cdf0e10cSrcweir aSettings.mbUseLastColumn = static_cast< CheckBox* >(mxControls[CB_LAST_COLUMN].get())->IsChecked(); 868*cdf0e10cSrcweir aSettings.mbUseColumnBanding = static_cast< CheckBox* >(mxControls[CB_BANDED_COLUMNS].get())->IsChecked(); 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir 871*cdf0e10cSrcweir sal_Bool bIsPageDark = sal_False; 872*cdf0e10cSrcweir if( mxView.is() ) 873*cdf0e10cSrcweir { 874*cdf0e10cSrcweir Reference< XPropertySet > xPageSet( mxView->getCurrentPage(), UNO_QUERY ); 875*cdf0e10cSrcweir if( xPageSet.is() ) 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir const OUString sIsBackgroundDark( RTL_CONSTASCII_USTRINGPARAM( "IsBackgroundDark" ) ); 878*cdf0e10cSrcweir xPageSet->getPropertyValue(sIsBackgroundDark) >>= bIsPageDark; 879*cdf0e10cSrcweir } 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir for( sal_Int32 nIndex = 0; nIndex < mxTableFamily->getCount(); nIndex++ ) try 883*cdf0e10cSrcweir { 884*cdf0e10cSrcweir Reference< XIndexAccess > xTableStyle( mxTableFamily->getByIndex( nIndex ), UNO_QUERY ); 885*cdf0e10cSrcweir if( xTableStyle.is() ) 886*cdf0e10cSrcweir pValueSet->InsertItem( sal::static_int_cast<sal_uInt16>( nIndex + 1 ), Image( CreateDesignPreview( xTableStyle, aSettings, bIsPageDark ) ) ); 887*cdf0e10cSrcweir } 888*cdf0e10cSrcweir catch( Exception& ) 889*cdf0e10cSrcweir { 890*cdf0e10cSrcweir DBG_ERROR("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!"); 891*cdf0e10cSrcweir } 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir catch( Exception& ) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir DBG_ERROR("sd::TableDesignPane::FillDesignPreviewControl(), exception caught!"); 896*cdf0e10cSrcweir } 897*cdf0e10cSrcweir pValueSet->SelectItem(nSelectedItem); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir 900*cdf0e10cSrcweir // ==================================================================== 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir TableDesignDialog::TableDesignDialog(::Window* pParent, ViewShellBase& rBase ) 903*cdf0e10cSrcweir : ModalDialog( pParent, SdResId( DLG_TABLEDESIGNPANE )) 904*cdf0e10cSrcweir , mrBase( rBase ) 905*cdf0e10cSrcweir { 906*cdf0e10cSrcweir mxFlSep1.reset( new FixedLine( this, SdResId( FL_SEP1 ) ) ); 907*cdf0e10cSrcweir mxFlSep2.reset( new FixedLine( this, SdResId( FL_SEP2 ) ) ); 908*cdf0e10cSrcweir mxHelpButton.reset( new HelpButton( this, SdResId( BTN_HELP ) ) ); 909*cdf0e10cSrcweir mxOkButton.reset( new OKButton( this, SdResId( BTN_OK ) ) ); 910*cdf0e10cSrcweir mxCancelButton.reset( new CancelButton( this, SdResId( BTN_CANCEL ) ) ); 911*cdf0e10cSrcweir FreeResource(); 912*cdf0e10cSrcweir 913*cdf0e10cSrcweir mpDesignPane.reset( new TableDesignPane( this, rBase, true ) ); 914*cdf0e10cSrcweir mpDesignPane->Hide(); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir // -------------------------------------------------------------------- 918*cdf0e10cSrcweir 919*cdf0e10cSrcweir short TableDesignDialog::Execute() 920*cdf0e10cSrcweir { 921*cdf0e10cSrcweir if( ModalDialog::Execute() ) 922*cdf0e10cSrcweir { 923*cdf0e10cSrcweir if( mpDesignPane->isStyleChanged() ) 924*cdf0e10cSrcweir mpDesignPane->ApplyStyle(); 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir if( mpDesignPane->isOptionsChanged() ) 927*cdf0e10cSrcweir mpDesignPane->ApplyOptions(); 928*cdf0e10cSrcweir return sal_True; 929*cdf0e10cSrcweir } 930*cdf0e10cSrcweir return sal_False; 931*cdf0e10cSrcweir } 932*cdf0e10cSrcweir 933*cdf0e10cSrcweir // ==================================================================== 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir ::Window * createTableDesignPanel( ::Window* pParent, ViewShellBase& rBase ) 936*cdf0e10cSrcweir { 937*cdf0e10cSrcweir return new TableDesignPane( pParent, rBase, false ); 938*cdf0e10cSrcweir } 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir // ==================================================================== 941*cdf0e10cSrcweir 942*cdf0e10cSrcweir void showTableDesignDialog( ::Window* pParent, ViewShellBase& rBase ) 943*cdf0e10cSrcweir { 944*cdf0e10cSrcweir boost::scoped_ptr< TableDesignDialog > xDialog( new TableDesignDialog( pParent, rBase ) ); 945*cdf0e10cSrcweir xDialog->Execute(); 946*cdf0e10cSrcweir } 947*cdf0e10cSrcweir 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir } 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir 952