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