1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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
41 #ifndef _EDIT_HXX //autogen
42 #include <vcl/edit.hxx>
44 #ifndef _MSGBOX_HXX //autogen
45 #include <vcl/msgbox.hxx>
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"
61 #include "tblafmt.hxx"
63 #include "tautofmt.hxx"
65 #include "shellres.hxx"
67 #include "tautofmt.hrc"
70 using namespace com::sun::star
;
72 #define FRAME_OFFSET 4
74 //========================================================================
76 class AutoFmtPreview
: public Window
79 AutoFmtPreview( Window
* pParent
, const ResId
& rRes
, SwWrtShell
* pWrtShell
);
82 void NotifyChange( const SwTableAutoFmt
& rNewData
);
85 virtual void Paint( const Rectangle
& rRect
);
88 SwTableAutoFmt aCurData
;
90 SvtScriptedTextHelper aScriptedText
;
91 svx::frame::Array maArray
; /// Implementation to draw the frame borders.
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 //-------------------------------------------
113 void DoPaint ( const Rectangle
& rRect
);
114 void CalcCellArray ( BOOL bFitWidth
);
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
);
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
134 SwStringInputDlg( Window
* pParent
,
135 const String
& rTitle
,
136 const String
& rEditTitle
,
137 const String
& rDefault
);
140 void GetInputString( String
& rString
) const;
143 Edit aEdInput
; // Edit erhaelt so den Focus
144 FixedText aFtEditTitle
;
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
) )
162 aFtEditTitle
.SetText( rEditTitle
);
163 aEdInput
.SetText( rDefault
);
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
),
216 bCoreDataChanged( FALSE
),
217 bSetAutoFmt ( bSetAutoFormat
)
219 pTableTbl
= new SwTableAutoFmtTbl
;
227 //------------------------------------------------------------------------
230 __EXPORT
SwAutoFormatDlg::~SwAutoFormatDlg()
234 if( bCoreDataChanged
)
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
);
270 // dann muss die Liste um den Eintrag <Keins> erweitert werden.
271 aLbFormat
.InsertEntry( ViewShell::GetShellRes()->aStrNone
);
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() )
284 aLbFormat
.SelectEntryPos( 255 != nIndex
? (nDfltStylePos
+ nIndex
) : 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
314 *rToFill
= *(*pTableTbl
)[ nIndex
];
316 rToFill
= new SwTableAutoFmt( *(*pTableTbl
)[ nIndex
] );
319 delete rToFill
, rToFill
= 0;
323 /*------------------------------------------------------------------------
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 );
350 if( !bCoreDataChanged
)
352 aBtnCancel
.SetText( aStrClose
);
353 bCoreDataChanged
= TRUE
;
356 pWndPreview
->NotifyChange( *pData
);
361 /*------------------------------------------------------------------------*/
364 IMPL_LINK( SwAutoFormatDlg
, AddHdl
, void *, EMPTYARG
)
366 BOOL bOk
= FALSE
, bFmtInserted
= FALSE
;
369 SwStringInputDlg
* pDlg
= new SwStringInputDlg( this,
373 if( RET_OK
== pDlg
->Execute() )
376 pDlg
->GetInputString( aFormatName
);
378 if( aFormatName
.Len() > 0 )
381 for( n
= 0; n
< pTableTbl
->Count(); ++n
)
382 if( (*pTableTbl
)[n
]->GetName() == aFormatName
)
385 if( n
>= pTableTbl
->Count() )
387 // Format mit dem Namen noch nicht vorhanden, also
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
)
398 pTableTbl
->Insert( pNewData
, n
);
399 aLbFormat
.InsertEntry( aFormatName
, nDfltStylePos
+ n
);
400 aLbFormat
.SelectEntryPos( nDfltStylePos
+ n
);
402 aBtnAdd
.Enable( FALSE
);
403 if ( !bCoreDataChanged
)
405 aBtnCancel
.SetText( aStrClose
);
406 bCoreDataChanged
= TRUE
;
416 bOk
= RET_CANCEL
== ErrorBox( this,
417 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
429 //------------------------------------------------------------------------
431 IMPL_LINK( SwAutoFormatDlg
, RemoveHdl
, void *, EMPTYARG
)
433 String aMessage
= aStrDelMsg
;
434 aMessage
.AppendAscii("\n\n");
435 aMessage
+= aLbFormat
.GetSelectEntry() ;
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
);
451 aBtnRemove
.Enable(FALSE
);
452 aBtnRename
.Enable(FALSE
);
455 if( !bCoreDataChanged
)
457 aBtnCancel
.SetText( aStrClose
);
458 bCoreDataChanged
= TRUE
;
468 IMPL_LINK( SwAutoFormatDlg
, RenameHdl
, void *, EMPTYARG
)
473 SwStringInputDlg
* pDlg
= new SwStringInputDlg( this,
474 aStrRenameTitle
, aLbFormat
.GetSelectEntry(),
476 if( pDlg
->Execute() == RET_OK
)
478 BOOL bFmtRenamed
= FALSE
;
480 pDlg
->GetInputString( aFormatName
);
482 if ( aFormatName
.Len() > 0 )
485 for( n
= 0; n
< pTableTbl
->Count(); ++n
)
486 if ((*pTableTbl
)[n
]->GetName() == aFormatName
)
489 if( n
>= pTableTbl
->Count() )
491 // Format mit dem Namen noch nicht vorhanden, also
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
)
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
;
523 bOk
= RET_CANCEL
== ErrorBox( this,
524 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
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
);
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
);
571 //------------------------------------------------------------------------
573 IMPL_LINK_INLINE_START( SwAutoFormatDlg
, OkHdl
, Button
*, EMPTYARG
)
576 pShell
->SetTableAutoFmt( *(*pTableTbl
)[ nIndex
] );
580 IMPL_LINK_INLINE_END( SwAutoFormatDlg
, OkHdl
, Button
*, EMPTYARG
)
582 //========================================================================
585 //------------------------------------------------------------------------
587 AutoFmtPreview::AutoFmtPreview( Window
* pParent
, const ResId
& rRes
, SwWrtShell
* pWrtShell
) :
588 Window ( pParent
, rRes
),
590 aCurData ( aEmptyStr
),
592 aScriptedText ( aVD
),
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();
612 mbRTL
= pWrtShell
->IsTableRightToLeft();
614 DBG_ASSERT( m_xMSF
.is(), "AutoFmtPreview: no MultiServiceFactory");
617 m_xBreak
= uno::Reference
< i18n::XBreakIterator
>(
618 m_xMSF
->createInstance (
619 rtl::OUString::createFromAscii( "com.sun.star.i18n.BreakIterator" ) ),
622 pNumFmt
= new SvNumberFormatter( m_xMSF
, LANGUAGE_SYSTEM
);
627 //------------------------------------------------------------------------
629 __EXPORT
AutoFmtPreview::~AutoFmtPreview()
634 //------------------------------------------------------------------------
636 static void lcl_SetFontProperties(
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
[] =
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 //------------------------
707 BYTE nIndex
= static_cast< BYTE
>( maArray
.GetCellIndex( nCol
, nRow
, mbRTL
) );
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;
718 case 20: cellString
= aStrSum
; break;
723 case 18: nVal
= nIndex
;
727 case 7: nVal
= nIndex
;
732 case 13: nVal
= nIndex
;
733 nNum
= 12 == nIndex
? 10 : 9;
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
;
744 if( aCurData
.IsValueFormat() )
746 String sFmt
; LanguageType eLng
, eSys
;
747 aCurData
.GetBoxFmt( (BYTE
)nNum
).GetValueFormat( sFmt
, eLng
, eSys
);
751 xub_StrLen nCheckPos
;
752 sal_uInt32 nKey
= pNumFmt
->GetIndexPuttingAndConverting( sFmt
, eLng
,
753 eSys
, nType
, bNew
, nCheckPos
);
755 pNumFmt
->GetOutputString( nVal
, nKey
, cellString
, &pDummy
);
758 cellString
= String::CreateFromInt32((sal_Int32
)nVal
);
763 if( cellString
.Len() )
766 BYTE nFmtIndex
= GetFormatIndex( nCol
, nRow
);
767 Rectangle cellRect
= maArray
.GetCellRect( nCol
, nRow
);
768 Point aPos
= cellRect
.TopLeft();
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
);
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 );
804 cellString
.Erase( cellString
.Len() - 1 );
805 aScriptedText
.SetText( cellString
, m_xBreak
);
806 aStrSize
= aScriptedText
.GetTextSize();
809 nRightX
= (USHORT
)( cellRect
.GetWidth()
817 aCurData.GetHorJustify( nFmtIndex, aHorJustifyItem );
818 eJustification = (CellHorJustify)aHorJustifyItem.GetValue();
822 eJustification = SC_HOR_JUSTIFY_STANDARD;
825 //-----------------------------
826 // vertikal (immer zentrieren):
827 //-----------------------------
828 aPos
.Y() += (nRowHeight
- (USHORT
)aStrSize
.Height()) / 2;
833 /* if ( eJustification != SC_HOR_JUSTIFY_STANDARD )*/
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
;
846 case SVX_ADJUST_RIGHT
:
856 //---------------------
857 // Standardausrichtung:
858 //---------------------
859 if ( (nCol
== 0) || (nIndex
== 4) )
861 // Text-Label links oder Summe linksbuendig
862 aPos
.X() += FRAME_OFFSET
;
866 // Zahlen/Datum rechtsbuendig
871 //-------------------------------
872 aScriptedText
.DrawText( aPos
);
873 //-------------------------------
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
);
901 aVD
.SetFillColor( aBrushItem
.GetColor() );
902 aVD
.DrawRect( maArray
.GetCellRect( nCol
, nRow
) );
908 //------------------------------------------------------------------------
911 void AutoFmtPreview::PaintCells()
914 if ( aCurData
.IsBackground() )
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
);
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
)
994 bFitWidth
= aCurData
.IsJustify();//TRUE; //???
995 CalcCellArray( bFitWidth
);
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
);
1012 Size theWndSize
= GetSizePixel();
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 //--------------------------------
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();
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
)