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