1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <vcl/edit.hxx>
21 #include <vcl/layout.hxx>
22 #include <vcl/msgbox.hxx>
23 #include <vcl/svapp.hxx>
24 #include <svl/zforlist.hxx>
25 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
26 #include <com/sun/star/i18n/BreakIterator.hpp>
27 #include <comphelper/processfactory.hxx>
28 #include <svtools/scriptedtext.hxx>
29 #include <svtools/accessibilityoptions.hxx>
30 #include <svx/framelinkarray.hxx>
32 #include "swmodule.hxx"
33 #include "swtypes.hxx"
36 #include "tblafmt.hxx"
37 #include "tautofmt.hxx"
38 #include "shellres.hxx"
40 using namespace com::sun::star
;
42 #define FRAME_OFFSET 4
44 class AutoFmtPreview
: public Window
47 AutoFmtPreview(Window
* pParent
);
50 void NotifyChange( const SwTableAutoFmt
& rNewData
);
52 void DetectRTL(SwWrtShell
* pWrtShell
);
54 virtual void Resize();
56 virtual void Paint( const Rectangle
& rRect
);
59 SwTableAutoFmt aCurData
;
61 SvtScriptedTextHelper aScriptedText
;
62 svx::frame::Array maArray
; /// Implementation to draw the frame borders.
73 const String aStrNorth
;
75 const String aStrSouth
;
77 SvNumberFormatter
* pNumFmt
;
79 uno::Reference
< i18n::XBreakIterator
> m_xBreak
;
82 void DoPaint ( const Rectangle
& rRect
);
83 void CalcCellArray ( sal_Bool bFitWidth
);
87 sal_uInt8
GetFormatIndex( size_t nCol
, size_t nRow
) const;
88 const SvxBoxItem
& GetBoxItem( size_t nCol
, size_t nRow
) const;
90 void DrawString( size_t nCol
, size_t nRow
);
92 void DrawBackground();
94 void MakeFonts ( sal_uInt8 nIndex
, Font
& rFont
, Font
& rCJKFont
, Font
& rCTLFont
);
95 String
MakeNumberString( String cellString
, sal_Bool bAddDec
);
98 class SwStringInputDlg
: public ModalDialog
101 SwStringInputDlg( Window
* pParent
,
102 const String
& rTitle
,
103 const String
& rEditTitle
,
104 const String
& rDefault
);
107 void GetInputString( String
& rString
) const;
110 Edit
* m_pEdInput
; // Edit obtains the focus.
114 SwStringInputDlg::SwStringInputDlg(Window
* pParent
, const String
& rTitle
,
115 const String
& rEditTitle
, const String
& rDefault
)
116 : ModalDialog(pParent
, "StringInputDialog", "modules/swriter/ui/stringinput.ui")
118 get
<FixedText
>("name")->SetText(rEditTitle
);
119 get(m_pEdInput
, "edit");
122 m_pEdInput
->SetText(rDefault
);
125 void SwStringInputDlg::GetInputString( String
& rString
) const
127 rString
= m_pEdInput
->GetText();
131 SwStringInputDlg::~SwStringInputDlg()
135 // AutoFormat-Dialogue:
137 SwAutoFormatDlg::SwAutoFormatDlg( Window
* pParent
, SwWrtShell
* pWrtShell
,
138 sal_Bool bSetAutoFormat
, const SwTableAutoFmt
* pSelFmt
)
139 : SfxModalDialog(pParent
, "AutoFormatTableDialog", "modules/swriter/ui/autoformattable.ui")
140 , aStrTitle(SW_RES(STR_ADD_AUTOFORMAT_TITLE
))
141 , aStrLabel(SW_RES(STR_ADD_AUTOFORMAT_LABEL
))
142 , aStrClose(SW_RES(STR_BTN_AUTOFORMAT_CLOSE
))
143 , aStrDelTitle(SW_RES(STR_DEL_AUTOFORMAT_TITLE
))
144 , aStrDelMsg(SW_RES(STR_DEL_AUTOFORMAT_MSG
))
145 , aStrRenameTitle(SW_RES(STR_RENAME_AUTOFORMAT_TITLE
))
146 , aStrInvalidFmt(SW_RES(STR_INVALID_AUTOFORMAT_NAME
))
150 , bCoreDataChanged(sal_False
)
151 , bSetAutoFmt(bSetAutoFormat
)
153 get(m_pLbFormat
, "formatlb");
154 get(m_pFormatting
, "formatting");
155 get(m_pBtnNumFormat
, "numformatcb");
156 get(m_pBtnBorder
, "bordercb");
157 get(m_pBtnFont
, "fontcb");
158 get(m_pBtnPattern
, "patterncb");
159 get(m_pBtnAlignment
, "alignmentcb");
161 get(m_pBtnCancel
, "cancel");
162 get(m_pBtnAdd
, "add");
163 get(m_pBtnRemove
, "remove");
164 get(m_pBtnRename
, "rename");
165 get(m_pWndPreview
, "preview");
167 m_pWndPreview
->DetectRTL(pWrtShell
);
169 pTableTbl
= new SwTableAutoFmtTbl
;
175 SwAutoFormatDlg::~SwAutoFormatDlg()
177 if (bCoreDataChanged
)
182 void SwAutoFormatDlg::Init( const SwTableAutoFmt
* pSelFmt
)
184 Link
aLk( LINK( this, SwAutoFormatDlg
, CheckHdl
) );
185 m_pBtnBorder
->SetClickHdl( aLk
);
186 m_pBtnFont
->SetClickHdl( aLk
);
187 m_pBtnPattern
->SetClickHdl( aLk
);
188 m_pBtnAlignment
->SetClickHdl( aLk
);
189 m_pBtnNumFormat
->SetClickHdl( aLk
);
191 m_pBtnAdd
->SetClickHdl ( LINK( this, SwAutoFormatDlg
, AddHdl
) );
192 m_pBtnRemove
->SetClickHdl ( LINK( this, SwAutoFormatDlg
, RemoveHdl
) );
193 m_pBtnRename
->SetClickHdl ( LINK( this, SwAutoFormatDlg
, RenameHdl
) );
194 m_pBtnOk
->SetClickHdl ( LINK( this, SwAutoFormatDlg
, OkHdl
) );
195 m_pLbFormat
->SetSelectHdl( LINK( this, SwAutoFormatDlg
, SelFmtHdl
) );
197 m_pBtnAdd
->Enable( bSetAutoFmt
);
202 // Then the list to be expanded by the entry "- none -".
203 m_pLbFormat
->InsertEntry( ViewShell::GetShellRes()->aStrNone
);
208 for (sal_uInt8 i
= 0, nCount
= static_cast<sal_uInt8
>(pTableTbl
->size());
211 SwTableAutoFmt
const& rFmt
= (*pTableTbl
)[ i
];
212 m_pLbFormat
->InsertEntry(rFmt
.GetName());
213 if (pSelFmt
&& rFmt
.GetName() == pSelFmt
->GetName())
217 m_pLbFormat
->SelectEntryPos( 255 != nIndex
? (nDfltStylePos
+ nIndex
) : 0 );
221 void SwAutoFormatDlg::UpdateChecks( const SwTableAutoFmt
& rFmt
, sal_Bool bEnable
)
223 m_pBtnNumFormat
->Enable( bEnable
);
224 m_pBtnNumFormat
->Check( rFmt
.IsValueFormat() );
226 m_pBtnBorder
->Enable( bEnable
);
227 m_pBtnBorder
->Check( rFmt
.IsFrame() );
229 m_pBtnFont
->Enable( bEnable
);
230 m_pBtnFont
->Check( rFmt
.IsFont() );
232 m_pBtnPattern
->Enable( bEnable
);
233 m_pBtnPattern
->Check( rFmt
.IsBackground() );
235 m_pBtnAlignment
->Enable( bEnable
);
236 m_pBtnAlignment
->Check( rFmt
.IsJustify() );
239 void SwAutoFormatDlg::FillAutoFmtOfIndex( SwTableAutoFmt
*& rToFill
) const
244 *rToFill
= (*pTableTbl
)[ nIndex
];
246 rToFill
= new SwTableAutoFmt( (*pTableTbl
)[ nIndex
] );
249 delete rToFill
, rToFill
= 0;
255 IMPL_LINK( SwAutoFormatDlg
, CheckHdl
, Button
*, pBtn
)
257 SwTableAutoFmt
* pData
= &(*pTableTbl
)[nIndex
];
258 sal_Bool bCheck
= ((CheckBox
*)pBtn
)->IsChecked(), bDataChgd
= sal_True
;
260 if( pBtn
== m_pBtnNumFormat
)
261 pData
->SetValueFormat( bCheck
);
262 else if ( pBtn
== m_pBtnBorder
)
263 pData
->SetFrame( bCheck
);
264 else if ( pBtn
== m_pBtnFont
)
265 pData
->SetFont( bCheck
);
266 else if ( pBtn
== m_pBtnPattern
)
267 pData
->SetBackground( bCheck
);
268 else if ( pBtn
== m_pBtnAlignment
)
269 pData
->SetJustify( bCheck
);
271 bDataChgd
= sal_False
;
275 if( !bCoreDataChanged
)
277 m_pBtnCancel
->SetText( aStrClose
);
278 bCoreDataChanged
= sal_True
;
281 m_pWndPreview
->NotifyChange( *pData
);
286 IMPL_LINK_NOARG(SwAutoFormatDlg
, AddHdl
)
288 bool bOk
= false, bFmtInserted
= false;
291 SwStringInputDlg
* pDlg
= new SwStringInputDlg( this,
295 if( RET_OK
== pDlg
->Execute() )
298 pDlg
->GetInputString( aFormatName
);
300 if( aFormatName
.Len() > 0 )
303 for( n
= 0; n
< pTableTbl
->size(); ++n
)
304 if( (*pTableTbl
)[n
].GetName() == aFormatName
)
307 if( n
>= pTableTbl
->size() )
309 // Format with the name does not already exist, so take up.
310 SwTableAutoFmt
* pNewData
= new
311 SwTableAutoFmt( aFormatName
);
312 pShell
->GetTableAutoFmt( *pNewData
);
315 for( n
= 1; n
< pTableTbl
->size(); ++n
)
316 if( (*pTableTbl
)[ n
].GetName() > aFormatName
)
319 pTableTbl
->InsertAutoFmt(n
, pNewData
);
320 m_pLbFormat
->InsertEntry( aFormatName
, nDfltStylePos
+ n
);
321 m_pLbFormat
->SelectEntryPos( nDfltStylePos
+ n
);
323 m_pBtnAdd
->Enable( sal_False
);
324 if ( !bCoreDataChanged
)
326 m_pBtnCancel
->SetText( aStrClose
);
327 bCoreDataChanged
= sal_True
;
337 bOk
= RET_CANCEL
== ErrorBox( this,
338 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
350 IMPL_LINK_NOARG(SwAutoFormatDlg
, RemoveHdl
)
352 String aMessage
= aStrDelMsg
;
353 aMessage
.AppendAscii("\n\n");
354 aMessage
+= m_pLbFormat
->GetSelectEntry() ;
357 MessBox
* pBox
= new MessBox( this, WinBits( WB_OK_CANCEL
),
358 aStrDelTitle
, aMessage
);
360 if ( pBox
->Execute() == RET_OK
)
362 m_pLbFormat
->RemoveEntry( nDfltStylePos
+ nIndex
);
363 m_pLbFormat
->SelectEntryPos( nDfltStylePos
+ nIndex
-1 );
365 pTableTbl
->EraseAutoFmt(nIndex
);
370 m_pBtnRemove
->Enable(sal_False
);
371 m_pBtnRename
->Enable(sal_False
);
374 if( !bCoreDataChanged
)
376 m_pBtnCancel
->SetText( aStrClose
);
377 bCoreDataChanged
= sal_True
;
387 IMPL_LINK_NOARG(SwAutoFormatDlg
, RenameHdl
)
392 SwStringInputDlg
* pDlg
= new SwStringInputDlg( this,
393 aStrRenameTitle
, m_pLbFormat
->GetSelectEntry(),
395 if( pDlg
->Execute() == RET_OK
)
397 bool bFmtRenamed
= false;
399 pDlg
->GetInputString( aFormatName
);
401 if ( aFormatName
.Len() > 0 )
404 for( n
= 0; n
< pTableTbl
->size(); ++n
)
405 if ((*pTableTbl
)[n
].GetName() == aFormatName
)
408 if( n
>= pTableTbl
->size() )
410 // no format with this name exists, so rename it
411 m_pLbFormat
->RemoveEntry( nDfltStylePos
+ nIndex
);
412 SwTableAutoFmt
* p
= pTableTbl
->ReleaseAutoFmt( nIndex
);
414 p
->SetName( aFormatName
);
416 // keep all arrays sorted!
417 for( n
= 1; n
< pTableTbl
->size(); ++n
)
418 if ((*pTableTbl
)[n
].GetName() > aFormatName
)
423 pTableTbl
->InsertAutoFmt( n
, p
);
424 m_pLbFormat
->InsertEntry( aFormatName
, nDfltStylePos
+ n
);
425 m_pLbFormat
->SelectEntryPos( nDfltStylePos
+ n
);
427 if ( !bCoreDataChanged
)
429 m_pBtnCancel
->SetText( aStrClose
);
430 bCoreDataChanged
= sal_True
;
441 bOk
= RET_CANCEL
== ErrorBox( this,
442 WinBits( WB_OK_CANCEL
| WB_DEF_OK
),
454 IMPL_LINK_NOARG(SwAutoFormatDlg
, SelFmtHdl
)
456 sal_Bool bBtnEnable
= sal_False
;
457 sal_uInt8 nSelPos
= (sal_uInt8
) m_pLbFormat
->GetSelectEntryPos(), nOldIdx
= nIndex
;
458 if( nSelPos
>= nDfltStylePos
)
460 nIndex
= nSelPos
- nDfltStylePos
;
461 m_pWndPreview
->NotifyChange( (*pTableTbl
)[nIndex
] );
462 bBtnEnable
= 0 != nIndex
;
463 UpdateChecks( (*pTableTbl
)[nIndex
], sal_True
);
469 SwTableAutoFmt
aTmp( ViewShell::GetShellRes()->aStrNone
);
470 aTmp
.SetFont( sal_False
);
471 aTmp
.SetJustify( sal_False
);
472 aTmp
.SetFrame( sal_False
);
473 aTmp
.SetBackground( sal_False
);
474 aTmp
.SetValueFormat( sal_False
);
475 aTmp
.SetWidthHeight( sal_False
);
477 if( nOldIdx
!= nIndex
)
478 m_pWndPreview
->NotifyChange( aTmp
);
479 UpdateChecks( aTmp
, sal_False
);
482 m_pBtnRemove
->Enable( bBtnEnable
);
483 m_pBtnRename
->Enable( bBtnEnable
);
488 IMPL_LINK_NOARG_INLINE_START(SwAutoFormatDlg
, OkHdl
)
491 pShell
->SetTableAutoFmt( (*pTableTbl
)[ nIndex
] );
495 IMPL_LINK_NOARG_INLINE_END(SwAutoFormatDlg
, OkHdl
)
499 AutoFmtPreview::AutoFmtPreview(Window
* pParent
) :
501 aCurData ( aEmptyStr
),
503 aScriptedText ( aVD
),
504 bFitWidth ( sal_False
),
506 aStrJan ( SW_RES( STR_JAN
) ),
507 aStrFeb ( SW_RES( STR_FEB
) ),
508 aStrMar ( SW_RES( STR_MAR
) ),
509 aStrNorth ( SW_RES( STR_NORTH
) ),
510 aStrMid ( SW_RES( STR_MID
) ),
511 aStrSouth ( SW_RES( STR_SOUTH
) ),
512 aStrSum ( SW_RES( STR_SUM
) )
514 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
515 m_xBreak
= i18n::BreakIterator::create(xContext
);
516 pNumFmt
= new SvNumberFormatter( xContext
, LANGUAGE_SYSTEM
);
521 extern "C" SAL_DLLPUBLIC_EXPORT Window
* SAL_CALL
makeAutoFmtPreview(Window
*pParent
, VclBuilder::stringmap
&)
523 return new AutoFmtPreview(pParent
);
526 void AutoFmtPreview::Resize()
528 aPrvSize
= Size(GetSizePixel().Width() - 6, GetSizePixel().Height() - 30);
529 nLabelColWidth
= (aPrvSize
.Width() - 4) / 4 - 12;
530 nDataColWidth1
= (aPrvSize
.Width() - 4 - 2 * nLabelColWidth
) / 3;
531 nDataColWidth2
= (aPrvSize
.Width() - 4 - 2 * nLabelColWidth
) / 4;
532 nRowHeight
= (aPrvSize
.Height() - 4) / 5;
533 NotifyChange(aCurData
);
536 void AutoFmtPreview::DetectRTL(SwWrtShell
* pWrtShell
)
538 if (!pWrtShell
->IsCrsrInTbl()) // We haven't created the table yet
539 mbRTL
= Application::GetSettings().GetLayoutRTL();
541 mbRTL
= pWrtShell
->IsTableRightToLeft();
544 AutoFmtPreview::~AutoFmtPreview()
549 static void lcl_SetFontProperties(
551 const SvxFontItem
& rFontItem
,
552 const SvxWeightItem
& rWeightItem
,
553 const SvxPostureItem
& rPostureItem
)
555 rFont
.SetFamily ( rFontItem
.GetFamily() );
556 rFont
.SetName ( rFontItem
.GetFamilyName() );
557 rFont
.SetStyleName ( rFontItem
.GetStyleName() );
558 rFont
.SetCharSet ( rFontItem
.GetCharSet() );
559 rFont
.SetPitch ( rFontItem
.GetPitch() );
560 rFont
.SetWeight ( (FontWeight
)rWeightItem
.GetValue() );
561 rFont
.SetItalic ( (FontItalic
)rPostureItem
.GetValue() );
564 #define SETONALLFONTS( MethodName, Value ) \
565 rFont.MethodName( Value ); \
566 rCJKFont.MethodName( Value ); \
567 rCTLFont.MethodName( Value );
569 void AutoFmtPreview::MakeFonts( sal_uInt8 nIndex
, Font
& rFont
, Font
& rCJKFont
, Font
& rCTLFont
)
571 const SwBoxAutoFmt
& rBoxFmt
= aCurData
.GetBoxFmt( nIndex
);
573 rFont
= rCJKFont
= rCTLFont
= GetFont();
574 Size
aFontSize( rFont
.GetSize().Width(), 10 );
576 lcl_SetFontProperties( rFont
, rBoxFmt
.GetFont(), rBoxFmt
.GetWeight(), rBoxFmt
.GetPosture() );
577 lcl_SetFontProperties( rCJKFont
, rBoxFmt
.GetCJKFont(), rBoxFmt
.GetCJKWeight(), rBoxFmt
.GetCJKPosture() );
578 lcl_SetFontProperties( rCTLFont
, rBoxFmt
.GetCTLFont(), rBoxFmt
.GetCTLWeight(), rBoxFmt
.GetCTLPosture() );
580 SETONALLFONTS( SetUnderline
, (FontUnderline
)rBoxFmt
.GetUnderline().GetValue() );
581 SETONALLFONTS( SetOverline
, (FontUnderline
)rBoxFmt
.GetOverline().GetValue() );
582 SETONALLFONTS( SetStrikeout
, (FontStrikeout
)rBoxFmt
.GetCrossedOut().GetValue() );
583 SETONALLFONTS( SetOutline
, rBoxFmt
.GetContour().GetValue() );
584 SETONALLFONTS( SetShadow
, rBoxFmt
.GetShadowed().GetValue() );
585 SETONALLFONTS( SetColor
, rBoxFmt
.GetColor().GetValue() );
586 SETONALLFONTS( SetSize
, aFontSize
);
587 SETONALLFONTS( SetTransparent
, sal_True
);
590 sal_uInt8
AutoFmtPreview::GetFormatIndex( size_t nCol
, size_t nRow
) const
592 static const sal_uInt8 pnFmtMap
[] =
600 return pnFmtMap
[ maArray
.GetCellIndex( nCol
, nRow
, mbRTL
) ];
603 const SvxBoxItem
& AutoFmtPreview::GetBoxItem( size_t nCol
, size_t nRow
) const
605 return aCurData
.GetBoxFmt( GetFormatIndex( nCol
, nRow
) ).GetBox();
608 void AutoFmtPreview::DrawString( size_t nCol
, size_t nRow
)
610 // Output of the cell text:
614 sal_uInt8 nIndex
= static_cast< sal_uInt8
>( maArray
.GetCellIndex( nCol
, nRow
, mbRTL
) );
618 case 1: cellString
= aStrJan
; break;
619 case 2: cellString
= aStrFeb
; break;
620 case 3: cellString
= aStrMar
; break;
621 case 5: cellString
= aStrNorth
; break;
622 case 10: cellString
= aStrMid
; break;
623 case 15: cellString
= aStrSouth
; break;
625 case 20: cellString
= aStrSum
; break;
630 case 18: nVal
= nIndex
;
634 case 7: nVal
= nIndex
;
639 case 13: nVal
= nIndex
;
640 nNum
= 12 == nIndex
? 10 : 9;
643 case 9: nVal
= 21; nNum
= 7; goto MAKENUMSTR
;
644 case 14: nVal
= 36; nNum
= 11; goto MAKENUMSTR
;
645 case 19: nVal
= 51; nNum
= 7; goto MAKENUMSTR
;
646 case 21: nVal
= 33; nNum
= 13; goto MAKENUMSTR
;
647 case 22: nVal
= 36; nNum
= 14; goto MAKENUMSTR
;
648 case 23: nVal
= 39; nNum
= 13; goto MAKENUMSTR
;
649 case 24: nVal
= 108; nNum
= 15; goto MAKENUMSTR
;
651 if( aCurData
.IsValueFormat() )
653 String sFmt
; LanguageType eLng
, eSys
;
654 aCurData
.GetBoxFmt( (sal_uInt8
)nNum
).GetValueFormat( sFmt
, eLng
, eSys
);
658 xub_StrLen nCheckPos
;
659 sal_uInt32 nKey
= pNumFmt
->GetIndexPuttingAndConverting( sFmt
, eLng
,
660 eSys
, nType
, bNew
, nCheckPos
);
662 pNumFmt
->GetOutputString( nVal
, nKey
, cellString
, &pDummy
);
665 cellString
= OUString::number((sal_Int32
)nVal
);
670 if( cellString
.Len() )
673 sal_uInt8 nFmtIndex
= GetFormatIndex( nCol
, nRow
);
674 Rectangle cellRect
= maArray
.GetCellRect( nCol
, nRow
);
675 Point aPos
= cellRect
.TopLeft();
676 sal_uInt16 nRightX
= 0;
678 Size
theMaxStrSize( cellRect
.GetWidth() - FRAME_OFFSET
,
679 cellRect
.GetHeight() - FRAME_OFFSET
);
680 if( aCurData
.IsFont() )
682 Font aFont
, aCJKFont
, aCTLFont
;
683 MakeFonts( nFmtIndex
, aFont
, aCJKFont
, aCTLFont
);
684 aScriptedText
.SetFonts( &aFont
, &aCJKFont
, &aCTLFont
);
687 aScriptedText
.SetDefaultFont();
689 aScriptedText
.SetText( cellString
, m_xBreak
);
690 aStrSize
= aScriptedText
.GetTextSize();
692 if( aCurData
.IsFont() &&
693 theMaxStrSize
.Height() < aStrSize
.Height() )
695 // If the string in this font does not
696 // fit into the cell, the standard font
698 aScriptedText
.SetDefaultFont();
699 aStrSize
= aScriptedText
.GetTextSize();
702 while( theMaxStrSize
.Width() <= aStrSize
.Width() &&
703 cellString
.Len() > 1 )
705 cellString
.Erase( cellString
.Len() - 1 );
706 aScriptedText
.SetText( cellString
, m_xBreak
);
707 aStrSize
= aScriptedText
.GetTextSize();
710 nRightX
= (sal_uInt16
)( cellRect
.GetWidth()
714 // vertical (always centering):
715 aPos
.Y() += (nRowHeight
- (sal_uInt16
)aStrSize
.Height()) / 2;
720 else if (aCurData
.IsJustify())
722 sal_uInt16 nHorPos
= (sal_uInt16
)
723 ((cellRect
.GetWidth()-aStrSize
.Width())/2);
724 const SvxAdjustItem
& rAdj
= aCurData
.GetBoxFmt(nFmtIndex
).GetAdjust();
725 switch ( rAdj
.GetAdjust() )
727 case SVX_ADJUST_LEFT
:
728 aPos
.X() += FRAME_OFFSET
;
730 case SVX_ADJUST_RIGHT
:
741 if ( (nCol
== 0) || (nIndex
== 4) )
743 // Text-Label left or sum left aligned
744 aPos
.X() += FRAME_OFFSET
;
748 // numbers/dates right aligned
753 aScriptedText
.DrawText( aPos
);
759 void AutoFmtPreview::DrawStrings()
761 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
762 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
763 DrawString( nCol
, nRow
);
766 void AutoFmtPreview::DrawBackground()
768 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
770 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
772 SvxBrushItem
aBrushItem( aCurData
.GetBoxFmt( GetFormatIndex( nCol
, nRow
) ).GetBackground() );
774 aVD
.Push( PUSH_LINECOLOR
| PUSH_FILLCOLOR
);
776 aVD
.SetFillColor( aBrushItem
.GetColor() );
777 aVD
.DrawRect( maArray
.GetCellRect( nCol
, nRow
) );
783 void AutoFmtPreview::PaintCells()
786 if ( aCurData
.IsBackground() )
793 if ( aCurData
.IsFrame() )
794 maArray
.DrawArray( aVD
);
797 void AutoFmtPreview::Init()
799 SetBorderStyle( GetBorderStyle() | WINDOW_BORDER_MONO
);
800 maArray
.Initialize( 5, 5 );
801 maArray
.SetUseDiagDoubleClipping( false );
802 CalcCellArray( sal_False
);
806 void AutoFmtPreview::CalcCellArray( sal_Bool _bFitWidth
)
808 maArray
.SetXOffset( 2 );
809 maArray
.SetAllColWidths( _bFitWidth
? nDataColWidth2
: nDataColWidth1
);
810 maArray
.SetColWidth( 0, nLabelColWidth
);
811 maArray
.SetColWidth( 4, nLabelColWidth
);
813 maArray
.SetYOffset( 2 );
814 maArray
.SetAllRowHeights( nRowHeight
);
816 aPrvSize
.Width() = maArray
.GetWidth() + 4;
817 aPrvSize
.Height() = maArray
.GetHeight() + 4;
820 inline void lclSetStyleFromBorder( svx::frame::Style
& rStyle
, const ::editeng::SvxBorderLine
* pBorder
)
822 rStyle
.Set( pBorder
, 0.05, 5 );
825 void AutoFmtPreview::CalcLineMap()
827 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
829 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
831 svx::frame::Style aStyle
;
833 const SvxBoxItem
& rItem
= GetBoxItem( nCol
, nRow
);
834 lclSetStyleFromBorder( aStyle
, rItem
.GetLeft() );
835 maArray
.SetCellStyleLeft( nCol
, nRow
, aStyle
);
836 lclSetStyleFromBorder( aStyle
, rItem
.GetRight() );
837 maArray
.SetCellStyleRight( nCol
, nRow
, aStyle
);
838 lclSetStyleFromBorder( aStyle
, rItem
.GetTop() );
839 maArray
.SetCellStyleTop( nCol
, nRow
, aStyle
);
840 lclSetStyleFromBorder( aStyle
, rItem
.GetBottom() );
841 maArray
.SetCellStyleBottom( nCol
, nRow
, aStyle
);
843 // FIXME - uncomment to draw diagonal borders
844 // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() );
845 // maArray.SetCellStyleTLBR( nCol, nRow, aStyle );
846 // lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() );
847 // maArray.SetCellStyleBLTR( nCol, nRow, aStyle );
852 void AutoFmtPreview::NotifyChange( const SwTableAutoFmt
& rNewData
)
855 bFitWidth
= aCurData
.IsJustify();//sal_True; //???
856 CalcCellArray( bFitWidth
);
858 DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
861 void AutoFmtPreview::DoPaint( const Rectangle
& /*rRect*/ )
863 sal_uInt32 nOldDrawMode
= aVD
.GetDrawMode();
864 if( GetSettings().GetStyleSettings().GetHighContrastMode() )
865 aVD
.SetDrawMode( DRAWMODE_SETTINGSLINE
| DRAWMODE_SETTINGSFILL
| DRAWMODE_SETTINGSTEXT
| DRAWMODE_SETTINGSGRADIENT
);
869 Size theWndSize
= GetSizePixel();
873 aFont
= aVD
.GetFont();
874 aFont
.SetTransparent( sal_True
);
876 aVD
.SetFont ( aFont
);
878 const Color
& rWinColor
= GetSettings().GetStyleSettings().GetWindowColor();
879 aVD
.SetBackground ( Wallpaper(rWinColor
) );
880 aVD
.SetFillColor ( rWinColor
);
881 aVD
.SetOutputSizePixel ( aPrvSize
);
883 // Draw cells on virtual device
884 // and save the result
886 thePreview
= aVD
.GetBitmap( Point(0,0), aPrvSize
);
888 // Draw the Frame and center the preview:
889 // (virtual Device for window output)
890 aVD
.SetOutputSizePixel( theWndSize
);
891 oldColor
= aVD
.GetLineColor();
893 aVD
.DrawRect( Rectangle( Point(0,0), theWndSize
) );
894 SetLineColor( oldColor
);
895 aCenterPos
= Point( (theWndSize
.Width() - aPrvSize
.Width() ) / 2,
896 (theWndSize
.Height() - aPrvSize
.Height()) / 2 );
897 aVD
.DrawBitmap( aCenterPos
, thePreview
);
899 // Output in the preview window:
900 DrawBitmap( Point(0,0), aVD
.GetBitmap( Point(0,0), theWndSize
) );
902 aVD
.SetDrawMode( nOldDrawMode
);
905 void AutoFmtPreview::Paint( const Rectangle
& rRect
)
910 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */