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