merge the formfield patch from ooo-build
[ooovba.git] / sw / source / ui / table / tautofmt.cxx
blob1b756f47efb6f15d219944664533c6bc1010e6a7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tautofmt.cxx,v $
10 * $Revision: 1.24.190.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #ifdef SW_DLLIMPLEMENTATION
35 #undef SW_DLLIMPLEMENTATION
36 #endif
41 #ifndef _EDIT_HXX //autogen
42 #include <vcl/edit.hxx>
43 #endif
44 #ifndef _MSGBOX_HXX //autogen
45 #include <vcl/msgbox.hxx>
46 #endif
47 #include <vcl/svapp.hxx>
48 #include <svtools/zforlist.hxx>
49 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
50 #include <com/sun/star/i18n/XBreakIterator.hpp>
51 #include <comphelper/processfactory.hxx>
52 #include <svtools/scriptedtext.hxx>
53 #include <svtools/accessibilityoptions.hxx>
54 #include <svx/framelinkarray.hxx>
55 #include "swmodule.hxx"
56 #include "swtypes.hxx"
57 #ifndef _VIEW_HXX
58 #include "view.hxx"
59 #endif
60 #include "wrtsh.hxx"
61 #include "tblafmt.hxx"
62 #ifndef _TAUTOFMT_HXX
63 #include "tautofmt.hxx"
64 #endif
65 #include "shellres.hxx"
66 #ifndef _TAUTOFMT_HRC
67 #include "tautofmt.hrc"
68 #endif
70 using namespace com::sun::star;
72 #define FRAME_OFFSET 4
74 //========================================================================
76 class AutoFmtPreview : public Window
78 public:
79 AutoFmtPreview( Window* pParent, const ResId& rRes, SwWrtShell* pWrtShell );
80 ~AutoFmtPreview();
82 void NotifyChange( const SwTableAutoFmt& rNewData );
84 protected:
85 virtual void Paint( const Rectangle& rRect );
87 private:
88 SwTableAutoFmt aCurData;
89 VirtualDevice aVD;
90 SvtScriptedTextHelper aScriptedText;
91 svx::frame::Array maArray; /// Implementation to draw the frame borders.
92 BOOL bFitWidth;
93 bool mbRTL;
94 Size aPrvSize;
95 long nLabelColWidth;
96 long nDataColWidth1;
97 long nDataColWidth2;
98 long nRowHeight;
99 const String aStrJan;
100 const String aStrFeb;
101 const String aStrMar;
102 const String aStrNorth;
103 const String aStrMid;
104 const String aStrSouth;
105 const String aStrSum;
106 SvNumberFormatter* pNumFmt;
108 uno::Reference< lang::XMultiServiceFactory > m_xMSF;
109 uno::Reference< i18n::XBreakIterator > m_xBreak;
111 //-------------------------------------------
112 void Init ();
113 void DoPaint ( const Rectangle& rRect );
114 void CalcCellArray ( BOOL bFitWidth );
115 void CalcLineMap ();
116 void PaintCells ();
118 BYTE GetFormatIndex( size_t nCol, size_t nRow ) const;
119 const SvxBoxItem& GetBoxItem( size_t nCol, size_t nRow ) const;
121 void DrawString( size_t nCol, size_t nRow );
122 void DrawStrings();
123 void DrawBackground();
125 void MakeFonts ( BYTE nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont );
126 String MakeNumberString( String cellString, BOOL bAddDec );
129 //========================================================================
131 class SwStringInputDlg : public ModalDialog
133 public:
134 SwStringInputDlg( Window* pParent,
135 const String& rTitle,
136 const String& rEditTitle,
137 const String& rDefault );
138 ~SwStringInputDlg();
140 void GetInputString( String& rString ) const;
142 private:
143 Edit aEdInput; // Edit erhaelt so den Focus
144 FixedText aFtEditTitle;
145 OKButton aBtnOk;
146 CancelButton aBtnCancel;
150 SwStringInputDlg::SwStringInputDlg( Window* pParent,
151 const String& rTitle,
152 const String& rEditTitle,
153 const String& rDefault ) :
154 ModalDialog ( pParent, SW_RES( DLG_SWDLG_STRINPUT ) ),
156 aEdInput ( this, SW_RES( ED_INPUT ) ),
157 aFtEditTitle ( this, SW_RES( FT_LABEL ) ),
158 aBtnOk ( this, SW_RES( BTN_OK ) ),
159 aBtnCancel ( this, SW_RES( BTN_CANCEL ) )
161 SetText( rTitle );
162 aFtEditTitle.SetText( rEditTitle );
163 aEdInput.SetText( rDefault );
164 //-------------
165 FreeResource();
168 //------------------------------------------------------------------------
170 void SwStringInputDlg::GetInputString( String& rString ) const
172 rString = aEdInput.GetText();
176 __EXPORT SwStringInputDlg::~SwStringInputDlg()
180 //========================================================================
181 // AutoFormat-Dialog:
184 SwAutoFormatDlg::SwAutoFormatDlg( Window* pParent, SwWrtShell* pWrtShell,
185 BOOL bSetAutoFormat, const SwTableAutoFmt* pSelFmt )
186 : SfxModalDialog( pParent, SW_RES( DLG_AUTOFMT_TABLE ) ),
188 aFlFormat ( this, SW_RES( FL_FORMAT ) ),
189 aLbFormat ( this, SW_RES( LB_FORMAT ) ),
191 aBtnNumFormat ( this, SW_RES( BTN_NUMFORMAT ) ),
192 aBtnBorder ( this, SW_RES( BTN_BORDER ) ),
193 aBtnFont ( this, SW_RES( BTN_FONT ) ),
194 aBtnPattern ( this, SW_RES( BTN_PATTERN ) ),
195 aBtnAlignment ( this, SW_RES( BTN_ALIGNMENT ) ),
196 aFlFormats ( this, SW_RES( FL_FORMATS ) ),
197 aBtnOk ( this, SW_RES( BTN_OK ) ),
198 aBtnCancel ( this, SW_RES( BTN_CANCEL ) ),
199 aBtnHelp ( this, SW_RES( BTN_HELP ) ),
200 aBtnAdd ( this, SW_RES( BTN_ADD ) ),
201 aBtnRemove ( this, SW_RES( BTN_REMOVE ) ),
202 aBtnRename ( this, SW_RES( BTN_RENAME ) ),
203 aBtnMore ( this, SW_RES( BTN_MORE ) ),
204 aStrTitle ( SW_RES( STR_ADD_TITLE ) ),
205 aStrLabel ( SW_RES( STR_ADD_LABEL ) ),
206 aStrClose ( SW_RES( STR_BTN_CLOSE ) ),
207 aStrDelTitle ( SW_RES( STR_DEL_TITLE ) ),
208 aStrDelMsg ( SW_RES( STR_DEL_MSG ) ),
209 aStrRenameTitle ( SW_RES( STR_RENAME_TITLE ) ),
210 aStrInvalidFmt ( SW_RES( STR_INVALID_AFNAME )),
211 pWndPreview ( new AutoFmtPreview( this, SW_RES( WND_PREVIEW ), pWrtShell )),
213 pShell ( pWrtShell ),
214 nIndex ( 0 ),
215 nDfltStylePos ( 0 ),
216 bCoreDataChanged( FALSE ),
217 bSetAutoFmt ( bSetAutoFormat )
219 pTableTbl = new SwTableAutoFmtTbl;
220 pTableTbl->Load();
222 Init( pSelFmt );
223 //------------- >
224 FreeResource();
227 //------------------------------------------------------------------------
230 __EXPORT SwAutoFormatDlg::~SwAutoFormatDlg()
232 delete pWndPreview;
234 if( bCoreDataChanged )
235 pTableTbl->Save();
236 delete pTableTbl;
239 //------------------------------------------------------------------------
242 void SwAutoFormatDlg::Init( const SwTableAutoFmt* pSelFmt )
244 Link aLk( LINK( this, SwAutoFormatDlg, CheckHdl ) );
245 aBtnBorder.SetClickHdl( aLk );
246 aBtnFont.SetClickHdl( aLk );
247 aBtnPattern.SetClickHdl( aLk );
248 aBtnAlignment.SetClickHdl( aLk );
249 aBtnNumFormat.SetClickHdl( aLk );
251 aBtnAdd.SetClickHdl ( LINK( this, SwAutoFormatDlg, AddHdl ) );
252 aBtnRemove.SetClickHdl ( LINK( this, SwAutoFormatDlg, RemoveHdl ) );
253 aBtnRename.SetClickHdl ( LINK( this, SwAutoFormatDlg, RenameHdl ) );
254 aBtnOk.SetClickHdl ( LINK( this, SwAutoFormatDlg, OkHdl ) );
255 aLbFormat.SetSelectHdl( LINK( this, SwAutoFormatDlg, SelFmtHdl ) );
257 aBtnMore.AddWindow( &aBtnNumFormat );
258 aBtnMore.AddWindow( &aBtnBorder );
259 aBtnMore.AddWindow( &aBtnFont );
260 aBtnMore.AddWindow( &aBtnPattern );
261 aBtnMore.AddWindow( &aBtnAlignment );
262 aBtnMore.AddWindow( &aFlFormats );
263 aBtnMore.AddWindow( &aBtnRename );
265 aBtnAdd.Enable( bSetAutoFmt );
267 nIndex = 0;
268 if( !bSetAutoFmt )
270 // dann muss die Liste um den Eintrag <Keins> erweitert werden.
271 aLbFormat.InsertEntry( ViewShell::GetShellRes()->aStrNone );
272 nDfltStylePos = 1;
273 nIndex = 255;
276 for( BYTE i = 0, nCount = (BYTE)pTableTbl->Count(); i < nCount; i++ )
278 SwTableAutoFmt* pFmt = (*pTableTbl)[ i ];
279 aLbFormat.InsertEntry( pFmt->GetName() );
280 if( pSelFmt && pFmt->GetName() == pSelFmt->GetName() )
281 nIndex = i;
284 aLbFormat.SelectEntryPos( 255 != nIndex ? (nDfltStylePos + nIndex) : 0 );
285 SelFmtHdl( 0 );
288 //------------------------------------------------------------------------
291 void SwAutoFormatDlg::UpdateChecks( const SwTableAutoFmt& rFmt, BOOL bEnable )
293 aBtnNumFormat.Enable( bEnable );
294 aBtnNumFormat.Check( rFmt.IsValueFormat() );
296 aBtnBorder.Enable( bEnable );
297 aBtnBorder.Check( rFmt.IsFrame() );
299 aBtnFont.Enable( bEnable );
300 aBtnFont.Check( rFmt.IsFont() );
302 aBtnPattern.Enable( bEnable );
303 aBtnPattern.Check( rFmt.IsBackground() );
305 aBtnAlignment.Enable( bEnable );
306 aBtnAlignment.Check( rFmt.IsJustify() );
309 void SwAutoFormatDlg::FillAutoFmtOfIndex( SwTableAutoFmt*& rToFill ) const
311 if( 255 != nIndex )
313 if( rToFill )
314 *rToFill = *(*pTableTbl)[ nIndex ];
315 else
316 rToFill = new SwTableAutoFmt( *(*pTableTbl)[ nIndex ] );
318 else if( rToFill )
319 delete rToFill, rToFill = 0;
323 /*------------------------------------------------------------------------
324 Handler:
325 ---------*/
328 IMPL_LINK( SwAutoFormatDlg, CheckHdl, Button *, pBtn )
330 SwTableAutoFmtPtr pData = (*pTableTbl)[nIndex];
331 BOOL bCheck = ((CheckBox*)pBtn)->IsChecked(), bDataChgd = TRUE;
333 if( pBtn == &aBtnNumFormat )
334 pData->SetValueFormat( bCheck );
335 else if ( pBtn == &aBtnBorder )
336 pData->SetFrame( bCheck );
337 else if ( pBtn == &aBtnFont )
338 pData->SetFont( bCheck );
339 else if ( pBtn == &aBtnPattern )
340 pData->SetBackground( bCheck );
341 else if ( pBtn == &aBtnAlignment )
342 pData->SetJustify( bCheck );
343 // else if ( pBtn == &aBtnAdjust )
344 // pData->SetIncludeWidthHeight( bCheck );
345 else
346 bDataChgd = FALSE;
348 if( bDataChgd )
350 if( !bCoreDataChanged )
352 aBtnCancel.SetText( aStrClose );
353 bCoreDataChanged = TRUE;
356 pWndPreview->NotifyChange( *pData );
358 return 0;
361 /*------------------------------------------------------------------------*/
364 IMPL_LINK( SwAutoFormatDlg, AddHdl, void *, EMPTYARG )
366 BOOL bOk = FALSE, bFmtInserted = FALSE;
367 while( !bOk )
369 SwStringInputDlg* pDlg = new SwStringInputDlg( this,
370 aStrTitle,
371 aStrLabel,
372 aEmptyStr );
373 if( RET_OK == pDlg->Execute() )
375 String aFormatName;
376 pDlg->GetInputString( aFormatName );
378 if( aFormatName.Len() > 0 )
380 USHORT n;
381 for( n = 0; n < pTableTbl->Count(); ++n )
382 if( (*pTableTbl)[n]->GetName() == aFormatName )
383 break;
385 if( n >= pTableTbl->Count() )
387 // Format mit dem Namen noch nicht vorhanden, also
388 // aufnehmen
389 SwTableAutoFmtPtr pNewData = new
390 SwTableAutoFmt( aFormatName );
391 pShell->GetTableAutoFmt( *pNewData );
393 // Sortiert einfuegen!!
394 for( n = 1; n < pTableTbl->Count(); ++n )
395 if( (*pTableTbl)[ n ]->GetName() > aFormatName )
396 break;
398 pTableTbl->Insert( pNewData, n );
399 aLbFormat.InsertEntry( aFormatName, nDfltStylePos + n );
400 aLbFormat.SelectEntryPos( nDfltStylePos + n );
401 bFmtInserted = TRUE;
402 aBtnAdd.Enable( FALSE );
403 if ( !bCoreDataChanged )
405 aBtnCancel.SetText( aStrClose );
406 bCoreDataChanged = TRUE;
409 SelFmtHdl( 0 );
410 bOk = TRUE;
414 if( !bFmtInserted )
416 bOk = RET_CANCEL == ErrorBox( this,
417 WinBits( WB_OK_CANCEL | WB_DEF_OK),
418 aStrInvalidFmt
419 ).Execute();
422 else
423 bOk = TRUE;
424 delete pDlg;
426 return 0;
429 //------------------------------------------------------------------------
431 IMPL_LINK( SwAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
433 String aMessage = aStrDelMsg ;
434 aMessage.AppendAscii("\n\n");
435 aMessage += aLbFormat.GetSelectEntry() ;
436 aMessage += '\n';
438 MessBox* pBox = new MessBox( this, WinBits( WB_OK_CANCEL ),
439 aStrDelTitle, aMessage);
441 if ( pBox->Execute() == RET_OK )
443 aLbFormat.RemoveEntry( nDfltStylePos + nIndex );
444 aLbFormat.SelectEntryPos( nDfltStylePos + nIndex-1 );
446 pTableTbl->DeleteAndDestroy( nIndex );
447 nIndex--;
449 if( !nIndex )
451 aBtnRemove.Enable(FALSE);
452 aBtnRename.Enable(FALSE);
455 if( !bCoreDataChanged )
457 aBtnCancel.SetText( aStrClose );
458 bCoreDataChanged = TRUE;
461 delete pBox;
463 SelFmtHdl( 0 );
465 return 0;
468 IMPL_LINK( SwAutoFormatDlg, RenameHdl, void *, EMPTYARG )
470 BOOL bOk = FALSE;
471 while( !bOk )
473 SwStringInputDlg* pDlg = new SwStringInputDlg( this,
474 aStrRenameTitle, aLbFormat.GetSelectEntry(),
475 aEmptyStr );
476 if( pDlg->Execute() == RET_OK )
478 BOOL bFmtRenamed = FALSE;
479 String aFormatName;
480 pDlg->GetInputString( aFormatName );
482 if ( aFormatName.Len() > 0 )
484 USHORT n;
485 for( n = 0; n < pTableTbl->Count(); ++n )
486 if ((*pTableTbl)[n]->GetName() == aFormatName)
487 break;
489 if( n >= pTableTbl->Count() )
491 // Format mit dem Namen noch nicht vorhanden, also
492 // umbenennen
494 aLbFormat.RemoveEntry( nDfltStylePos + nIndex );
495 SwTableAutoFmtPtr p = (*pTableTbl)[ nIndex ];
496 pTableTbl->Remove( nIndex );
498 p->SetName( aFormatName );
500 // Sortiert einfuegen!!
501 for( n = 1; n < pTableTbl->Count(); ++n )
502 if( (*pTableTbl)[ n ]->GetName() > aFormatName )
503 break;
505 pTableTbl->Insert( p, n );
506 aLbFormat.InsertEntry( aFormatName, nDfltStylePos + n );
507 aLbFormat.SelectEntryPos( nDfltStylePos + n );
509 if ( !bCoreDataChanged )
511 aBtnCancel.SetText( aStrClose );
512 bCoreDataChanged = TRUE;
515 SelFmtHdl( 0 );
516 bOk = TRUE;
517 bFmtRenamed = TRUE;
521 if( !bFmtRenamed )
523 bOk = RET_CANCEL == ErrorBox( this,
524 WinBits( WB_OK_CANCEL | WB_DEF_OK),
525 aStrInvalidFmt
526 ).Execute();
529 else
530 bOk = TRUE;
531 delete pDlg;
533 return 0;
536 //------------------------------------------------------------------------
538 IMPL_LINK( SwAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
540 BOOL bBtnEnable = FALSE;
541 BYTE nSelPos = (BYTE) aLbFormat.GetSelectEntryPos(), nOldIdx = nIndex;
542 if( nSelPos >= nDfltStylePos )
544 nIndex = nSelPos - nDfltStylePos;
545 pWndPreview->NotifyChange( *(*pTableTbl)[nIndex] );
546 bBtnEnable = 0 != nIndex;
547 UpdateChecks( *(*pTableTbl)[nIndex], TRUE );
549 else
551 nIndex = 255;
553 SwTableAutoFmt aTmp( ViewShell::GetShellRes()->aStrNone );
554 aTmp.SetFont( FALSE );
555 aTmp.SetJustify( FALSE );
556 aTmp.SetFrame( FALSE );
557 aTmp.SetBackground( FALSE );
558 aTmp.SetValueFormat( FALSE );
559 aTmp.SetWidthHeight( FALSE );
561 if( nOldIdx != nIndex )
562 pWndPreview->NotifyChange( aTmp );
563 UpdateChecks( aTmp, FALSE );
566 aBtnRemove.Enable( bBtnEnable );
567 aBtnRename.Enable( bBtnEnable );
569 return 0;
571 //------------------------------------------------------------------------
573 IMPL_LINK_INLINE_START( SwAutoFormatDlg, OkHdl, Button *, EMPTYARG )
575 if( bSetAutoFmt )
576 pShell->SetTableAutoFmt( *(*pTableTbl)[ nIndex ] );
577 EndDialog( RET_OK );
578 return TRUE;
580 IMPL_LINK_INLINE_END( SwAutoFormatDlg, OkHdl, Button *, EMPTYARG )
582 //========================================================================
583 // AutoFmtPreview
585 //------------------------------------------------------------------------
587 AutoFmtPreview::AutoFmtPreview( Window* pParent, const ResId& rRes, SwWrtShell* pWrtShell ) :
588 Window ( pParent, rRes ),
590 aCurData ( aEmptyStr ),
591 aVD ( *this ),
592 aScriptedText ( aVD ),
593 bFitWidth ( FALSE ),
594 mbRTL ( false ),
595 aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ),
596 nLabelColWidth ( (aPrvSize.Width() - 4) / 4 - 12 ),
597 nDataColWidth1 ( (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 3 ),
598 nDataColWidth2 ( (aPrvSize.Width() - 4 - 2 * nLabelColWidth) / 4 ),
599 nRowHeight ( (aPrvSize.Height() - 4) / 5 ),
600 aStrJan ( SW_RES( STR_JAN ) ),
601 aStrFeb ( SW_RES( STR_FEB ) ),
602 aStrMar ( SW_RES( STR_MAR ) ),
603 aStrNorth ( SW_RES( STR_NORTH ) ),
604 aStrMid ( SW_RES( STR_MID ) ),
605 aStrSouth ( SW_RES( STR_SOUTH ) ),
606 aStrSum ( SW_RES( STR_SUM ) ),
607 m_xMSF ( comphelper::getProcessServiceFactory() )
609 if (!pWrtShell->IsCrsrInTbl()) // We haven't created the table yet
610 mbRTL = Application::GetSettings().GetLayoutRTL();
611 else
612 mbRTL = pWrtShell->IsTableRightToLeft();
614 DBG_ASSERT( m_xMSF.is(), "AutoFmtPreview: no MultiServiceFactory");
615 if ( m_xMSF.is() )
617 m_xBreak = uno::Reference< i18n::XBreakIterator >(
618 m_xMSF->createInstance (
619 rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ),
620 uno::UNO_QUERY);
622 pNumFmt = new SvNumberFormatter( m_xMSF, LANGUAGE_SYSTEM );
624 Init();
627 //------------------------------------------------------------------------
629 __EXPORT AutoFmtPreview::~AutoFmtPreview()
631 delete pNumFmt;
634 //------------------------------------------------------------------------
636 static void lcl_SetFontProperties(
637 Font& rFont,
638 const SvxFontItem& rFontItem,
639 const SvxWeightItem& rWeightItem,
640 const SvxPostureItem& rPostureItem )
642 rFont.SetFamily ( rFontItem.GetFamily() );
643 rFont.SetName ( rFontItem.GetFamilyName() );
644 rFont.SetStyleName ( rFontItem.GetStyleName() );
645 rFont.SetCharSet ( rFontItem.GetCharSet() );
646 rFont.SetPitch ( rFontItem.GetPitch() );
647 rFont.SetWeight ( (FontWeight)rWeightItem.GetValue() );
648 rFont.SetItalic ( (FontItalic)rPostureItem.GetValue() );
651 #define SETONALLFONTS( MethodName, Value ) \
652 rFont.MethodName( Value ); \
653 rCJKFont.MethodName( Value ); \
654 rCTLFont.MethodName( Value );
656 void AutoFmtPreview::MakeFonts( BYTE nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont )
658 const SwBoxAutoFmt& rBoxFmt = aCurData.GetBoxFmt( nIndex );
660 rFont = rCJKFont = rCTLFont = GetFont();
661 Size aFontSize( rFont.GetSize().Width(), 10 );
663 lcl_SetFontProperties( rFont, rBoxFmt.GetFont(), rBoxFmt.GetWeight(), rBoxFmt.GetPosture() );
664 lcl_SetFontProperties( rCJKFont, rBoxFmt.GetCJKFont(), rBoxFmt.GetCJKWeight(), rBoxFmt.GetCJKPosture() );
665 lcl_SetFontProperties( rCTLFont, rBoxFmt.GetCTLFont(), rBoxFmt.GetCTLWeight(), rBoxFmt.GetCTLPosture() );
667 SETONALLFONTS( SetUnderline, (FontUnderline)rBoxFmt.GetUnderline().GetValue() );
668 SETONALLFONTS( SetOverline, (FontUnderline)rBoxFmt.GetOverline().GetValue() );
669 SETONALLFONTS( SetStrikeout, (FontStrikeout)rBoxFmt.GetCrossedOut().GetValue() );
670 SETONALLFONTS( SetOutline, rBoxFmt.GetContour().GetValue() );
671 SETONALLFONTS( SetShadow, rBoxFmt.GetShadowed().GetValue() );
672 SETONALLFONTS( SetColor, rBoxFmt.GetColor().GetValue() );
673 SETONALLFONTS( SetSize, aFontSize );
674 SETONALLFONTS( SetTransparent, TRUE );
677 //------------------------------------------------------------------------
679 BYTE AutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const
681 static const BYTE pnFmtMap[] =
683 0, 1, 2, 1, 3,
684 4, 5, 6, 5, 7,
685 8, 9, 10, 9, 11,
686 4, 5, 6, 5, 7,
687 12, 13, 14, 13, 15
689 return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ];
692 const SvxBoxItem& AutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const
694 return aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBox();
697 //------------------------------------------------------------------------
699 void AutoFmtPreview::DrawString( size_t nCol, size_t nRow )
701 //------------------------
702 // Ausgabe des Zelltextes:
703 //------------------------
704 ULONG nNum;
705 double nVal;
706 String cellString;
707 BYTE nIndex = static_cast< BYTE >( maArray.GetCellIndex( nCol, nRow, mbRTL ) );
709 switch( nIndex )
711 case 1: cellString = aStrJan; break;
712 case 2: cellString = aStrFeb; break;
713 case 3: cellString = aStrMar; break;
714 case 5: cellString = aStrNorth; break;
715 case 10: cellString = aStrMid; break;
716 case 15: cellString = aStrSouth; break;
717 case 4:
718 case 20: cellString = aStrSum; break;
720 case 6:
721 case 8:
722 case 16:
723 case 18: nVal = nIndex;
724 nNum = 5;
725 goto MAKENUMSTR;
726 case 17:
727 case 7: nVal = nIndex;
728 nNum = 6;
729 goto MAKENUMSTR;
730 case 11:
731 case 12:
732 case 13: nVal = nIndex;
733 nNum = 12 == nIndex ? 10 : 9;
734 goto MAKENUMSTR;
736 case 9: nVal = 21; nNum = 7; goto MAKENUMSTR;
737 case 14: nVal = 36; nNum = 11; goto MAKENUMSTR;
738 case 19: nVal = 51; nNum = 7; goto MAKENUMSTR;
739 case 21: nVal = 33; nNum = 13; goto MAKENUMSTR;
740 case 22: nVal = 36; nNum = 14; goto MAKENUMSTR;
741 case 23: nVal = 39; nNum = 13; goto MAKENUMSTR;
742 case 24: nVal = 108; nNum = 15; goto MAKENUMSTR;
743 MAKENUMSTR:
744 if( aCurData.IsValueFormat() )
746 String sFmt; LanguageType eLng, eSys;
747 aCurData.GetBoxFmt( (BYTE)nNum ).GetValueFormat( sFmt, eLng, eSys );
749 short nType;
750 BOOL bNew;
751 xub_StrLen nCheckPos;
752 sal_uInt32 nKey = pNumFmt->GetIndexPuttingAndConverting( sFmt, eLng,
753 eSys, nType, bNew, nCheckPos);
754 Color* pDummy;
755 pNumFmt->GetOutputString( nVal, nKey, cellString, &pDummy );
757 else
758 cellString = String::CreateFromInt32((sal_Int32)nVal);
759 break;
763 if( cellString.Len() )
765 Size aStrSize;
766 BYTE nFmtIndex = GetFormatIndex( nCol, nRow );
767 Rectangle cellRect = maArray.GetCellRect( nCol, nRow );
768 Point aPos = cellRect.TopLeft();
769 USHORT nRightX = 0;
770 // BOOL bJustify = aCurData.IsJustify();
771 // ScHorJustifyAttr aHorJustifyItem;
772 // CellHorJustify eJustification;
774 Size theMaxStrSize( cellRect.GetWidth() - FRAME_OFFSET,
775 cellRect.GetHeight() - FRAME_OFFSET );
776 if( aCurData.IsFont() )
778 Font aFont, aCJKFont, aCTLFont;
779 MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont );
780 aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont );
782 else
783 aScriptedText.SetDefaultFont();
785 aScriptedText.SetText( cellString, m_xBreak );
786 aStrSize = aScriptedText.GetTextSize();
788 if( aCurData.IsFont() &&
789 theMaxStrSize.Height() < aStrSize.Height() )
791 // wenn der String in diesem Font nicht
792 // in die Zelle passt, wird wieder der
793 // Standard-Font genommen:
794 aScriptedText.SetDefaultFont();
795 aStrSize = aScriptedText.GetTextSize();
798 while( theMaxStrSize.Width() <= aStrSize.Width() &&
799 cellString.Len() > 1 )
801 // if( eJustification == SVX_HOR_JUSTIFY_RIGHT )
802 // cellString.Erase( 0, 1 );
803 // else
804 cellString.Erase( cellString.Len() - 1 );
805 aScriptedText.SetText( cellString, m_xBreak );
806 aStrSize = aScriptedText.GetTextSize();
809 nRightX = (USHORT)( cellRect.GetWidth()
810 - aStrSize.Width()
811 - FRAME_OFFSET );
812 //-------------
813 // Ausrichtung:
814 //-------------
815 /* if ( bJustify )
817 aCurData.GetHorJustify( nFmtIndex, aHorJustifyItem );
818 eJustification = (CellHorJustify)aHorJustifyItem.GetValue();
820 else
822 eJustification = SC_HOR_JUSTIFY_STANDARD;
825 //-----------------------------
826 // vertikal (immer zentrieren):
827 //-----------------------------
828 aPos.Y() += (nRowHeight - (USHORT)aStrSize.Height()) / 2;
830 //-----------
831 // horizontal
832 //-----------
833 /* if ( eJustification != SC_HOR_JUSTIFY_STANDARD )*/
834 if( mbRTL )
835 aPos.X() += nRightX;
836 else if (aCurData.IsJustify())
838 USHORT nHorPos = (USHORT)
839 ((cellRect.GetWidth()-aStrSize.Width())/2);
840 const SvxAdjustItem& rAdj = aCurData.GetBoxFmt(nFmtIndex).GetAdjust();
841 switch ( rAdj.GetAdjust() )
843 case SVX_ADJUST_LEFT:
844 aPos.X() += FRAME_OFFSET;
845 break;
846 case SVX_ADJUST_RIGHT:
847 aPos.X() += nRightX;
848 break;
849 default:
850 aPos.X() += nHorPos;
851 break;
854 else
856 //---------------------
857 // Standardausrichtung:
858 //---------------------
859 if ( (nCol == 0) || (nIndex == 4) )
861 // Text-Label links oder Summe linksbuendig
862 aPos.X() += FRAME_OFFSET;
864 else
866 // Zahlen/Datum rechtsbuendig
867 aPos.X() += nRightX;
871 //-------------------------------
872 aScriptedText.DrawText( aPos );
873 //-------------------------------
877 #undef FRAME_OFFSET
879 //------------------------------------------------------------------------
881 void AutoFmtPreview::DrawStrings()
883 for( size_t nRow = 0; nRow < 5; ++nRow )
884 for( size_t nCol = 0; nCol < 5; ++nCol )
885 DrawString( nCol, nRow );
888 //------------------------------------------------------------------------
891 void AutoFmtPreview::DrawBackground()
893 for( size_t nRow = 0; nRow < 5; ++nRow )
895 for( size_t nCol = 0; nCol < 5; ++nCol )
897 SvxBrushItem aBrushItem( aCurData.GetBoxFmt( GetFormatIndex( nCol, nRow ) ).GetBackground() );
899 aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR );
900 aVD.SetLineColor();
901 aVD.SetFillColor( aBrushItem.GetColor() );
902 aVD.DrawRect( maArray.GetCellRect( nCol, nRow ) );
903 aVD.Pop();
908 //------------------------------------------------------------------------
911 void AutoFmtPreview::PaintCells()
913 // 1) background
914 if ( aCurData.IsBackground() )
915 DrawBackground();
917 // 2) values
918 DrawStrings();
920 // 3) border
921 if ( aCurData.IsFrame() )
922 maArray.DrawArray( aVD );
925 //------------------------------------------------------------------------
928 void __EXPORT AutoFmtPreview::Init()
930 SetBorderStyle( GetBorderStyle() | WINDOW_BORDER_MONO );
931 maArray.Initialize( 5, 5 );
932 maArray.SetUseDiagDoubleClipping( false );
933 CalcCellArray( FALSE );
934 CalcLineMap();
937 //------------------------------------------------------------------------
940 void AutoFmtPreview::CalcCellArray( BOOL _bFitWidth )
942 maArray.SetXOffset( 2 );
943 maArray.SetAllColWidths( _bFitWidth ? nDataColWidth2 : nDataColWidth1 );
944 maArray.SetColWidth( 0, nLabelColWidth );
945 maArray.SetColWidth( 4, nLabelColWidth );
947 maArray.SetYOffset( 2 );
948 maArray.SetAllRowHeights( nRowHeight );
950 aPrvSize.Width() = maArray.GetWidth() + 4;
951 aPrvSize.Height() = maArray.GetHeight() + 4;
954 //------------------------------------------------------------------------
956 inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const SvxBorderLine* pBorder )
958 rStyle.Set( pBorder, 0.05, 5 );
961 void AutoFmtPreview::CalcLineMap()
963 for( size_t nRow = 0; nRow < 5; ++nRow )
965 for( size_t nCol = 0; nCol < 5; ++nCol )
967 svx::frame::Style aStyle;
969 const SvxBoxItem& rItem = GetBoxItem( nCol, nRow );
970 lclSetStyleFromBorder( aStyle, rItem.GetLeft() );
971 maArray.SetCellStyleLeft( nCol, nRow, aStyle );
972 lclSetStyleFromBorder( aStyle, rItem.GetRight() );
973 maArray.SetCellStyleRight( nCol, nRow, aStyle );
974 lclSetStyleFromBorder( aStyle, rItem.GetTop() );
975 maArray.SetCellStyleTop( nCol, nRow, aStyle );
976 lclSetStyleFromBorder( aStyle, rItem.GetBottom() );
977 maArray.SetCellStyleBottom( nCol, nRow, aStyle );
979 // FIXME - uncomment to draw diagonal borders
980 // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() );
981 // maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
982 // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() );
983 // maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
988 //------------------------------------------------------------------------
991 void AutoFmtPreview::NotifyChange( const SwTableAutoFmt& rNewData )
993 aCurData = rNewData;
994 bFitWidth = aCurData.IsJustify();//TRUE; //???
995 CalcCellArray( bFitWidth );
996 CalcLineMap();
997 DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
1000 //------------------------------------------------------------------------
1003 void AutoFmtPreview::DoPaint( const Rectangle& /*rRect*/ )
1005 sal_uInt32 nOldDrawMode = aVD.GetDrawMode();
1006 if( GetSettings().GetStyleSettings().GetHighContrastMode() &&
1007 SW_MOD()->GetAccessibilityOptions().GetIsForBorders() )
1008 aVD.SetDrawMode( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT );
1010 Bitmap thePreview;
1011 Point aCenterPos;
1012 Size theWndSize = GetSizePixel();
1013 Size thePrevSize;
1014 Color oldColor;
1015 Font aFont;
1017 aFont = aVD.GetFont();
1018 aFont.SetTransparent( TRUE );
1020 aVD.SetFont ( aFont );
1021 aVD.SetLineColor ();
1022 const Color& rWinColor = GetSettings().GetStyleSettings().GetWindowColor();
1023 aVD.SetBackground ( Wallpaper(rWinColor) );
1024 aVD.SetFillColor ( rWinColor );
1025 aVD.SetOutputSizePixel ( aPrvSize );
1027 //--------------------------------
1028 // Zellen auf virtual Device malen
1029 // und Ergebnis sichern
1030 //--------------------------------
1031 PaintCells();
1032 thePreview = aVD.GetBitmap( Point(0,0), aPrvSize );
1034 //--------------------------------------
1035 // Rahmen malen und Vorschau zentrieren:
1036 // (virtual Device fuer Fensterausgabe)
1037 //--------------------------------------
1038 aVD.SetOutputSizePixel( theWndSize );
1039 oldColor = aVD.GetLineColor();
1040 aVD.SetLineColor();
1041 aVD.DrawRect( Rectangle( Point(0,0), theWndSize ) );
1042 SetLineColor( oldColor );
1043 aCenterPos = Point( (theWndSize.Width() - aPrvSize.Width() ) / 2,
1044 (theWndSize.Height() - aPrvSize.Height()) / 2 );
1045 aVD.DrawBitmap( aCenterPos, thePreview );
1047 //----------------------------
1048 // Ausgabe im Vorschaufenster:
1049 //----------------------------
1050 DrawBitmap( Point(0,0), aVD.GetBitmap( Point(0,0), theWndSize ) );
1052 aVD.SetDrawMode( nOldDrawMode );
1055 //------------------------------------------------------------------------
1057 void __EXPORT AutoFmtPreview::Paint( const Rectangle& rRect )
1059 DoPaint( rRect );