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: autofmt.cxx,v $
10 * $Revision: 1.19.122.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_sc.hxx"
36 //------------------------------------------------------------------
38 #include "scitems.hxx"
39 #include <svx/algitem.hxx>
40 #include <svx/boxitem.hxx>
41 #include <svx/brshitem.hxx>
42 #include <svx/cntritem.hxx>
43 #include <svx/colritem.hxx>
44 #include <svx/crsditem.hxx>
45 #include <svx/fontitem.hxx>
46 #include <svx/postitem.hxx>
47 #include <svx/shdditem.hxx>
48 #include <svx/udlnitem.hxx>
49 #include <svx/wghtitem.hxx>
50 #include <sfx2/topfrm.hxx>
51 #include <vcl/svapp.hxx>
52 #include <svtools/zforlist.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <comphelper/processfactory.hxx>
59 #include "zforauto.hxx"
60 #include "scitems.hxx"
62 #include "globstr.hrc"
63 #include "autoform.hxx"
64 //CHINA001 #include "strindlg.hxx"
65 #include "miscdlgs.hrc"
66 #include "autofmt.hxx"
67 #include "scresid.hxx"
68 #include "document.hxx"
70 #include "tabvwsh.hxx"
72 #define FRAME_OFFSET 4
77 //CHINA001 //========================================================================
78 //CHINA001 // AutoFormat-Dialog:
80 //CHINA001 ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
81 //CHINA001 ScAutoFormat* pAutoFormat,
82 //CHINA001 const ScAutoFormatData* pSelFormatData,
83 //CHINA001 ScDocument* pDoc ) :
85 //CHINA001 ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
87 //CHINA001 aLbFormat ( this, ScResId( LB_FORMAT ) ),
88 //CHINA001 aFlFormat ( this, ScResId( FL_FORMAT ) ),
89 //CHINA001 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
90 //CHINA001 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ),
91 //CHINA001 aBtnBorder ( this, ScResId( BTN_BORDER ) ),
92 //CHINA001 aBtnFont ( this, ScResId( BTN_FONT ) ),
93 //CHINA001 aBtnPattern ( this, ScResId( BTN_PATTERN ) ),
94 //CHINA001 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ),
95 //CHINA001 aBtnAdjust ( this, ScResId( BTN_ADJUST ) ),
96 //CHINA001 aFlFormatting ( this, ScResId( FL_FORMATTING ) ),
97 //CHINA001 aBtnOk ( this, ScResId( BTN_OK ) ),
98 //CHINA001 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
99 //CHINA001 aBtnHelp ( this, ScResId( BTN_HELP ) ),
100 //CHINA001 aBtnAdd ( this, ScResId( BTN_ADD ) ),
101 //CHINA001 aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
102 //CHINA001 aBtnMore ( this, ScResId( BTN_MORE ) ),
103 //CHINA001 aBtnRename ( this, ScResId( BTN_RENAME ) ),
104 //CHINA001 aStrTitle ( ScResId( STR_ADD_TITLE ) ),
105 //CHINA001 aStrLabel ( ScResId( STR_ADD_LABEL ) ),
106 //CHINA001 aStrRename ( ScResId( STR_RENAME_TITLE ) ),
107 //CHINA001 aStrClose ( ScResId( STR_BTN_CLOSE ) ),
108 //CHINA001 aStrDelTitle ( ScResId( STR_DEL_TITLE ) ),
109 //CHINA001 aStrDelMsg ( ScResId( STR_DEL_MSG ) ) ,
111 //CHINA001 nIndex ( 0 ),
112 //CHINA001 bFmtInserted ( FALSE ),
113 //CHINA001 bCoreDataChanged( FALSE ),
114 //CHINA001 pFormat ( pAutoFormat ),
115 //CHINA001 pSelFmtData ( pSelFormatData )
118 //CHINA001 pWndPreview->NotifyChange( (*pFormat)[0] );
119 //CHINA001 FreeResource();
122 //CHINA001 //------------------------------------------------------------------------
124 //CHINA001 ScAutoFormatDlg::~ScAutoFormatDlg()
126 //CHINA001 delete pWndPreview;
129 //CHINA001 //------------------------------------------------------------------------
131 //CHINA001 void ScAutoFormatDlg::Init()
133 //CHINA001 USHORT nCount;
134 //CHINA001 String aEntry;
136 //CHINA001 aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
137 //CHINA001 aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
138 //CHINA001 aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
139 //CHINA001 aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
140 //CHINA001 aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
141 //CHINA001 aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
142 //CHINA001 aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
143 //CHINA001 aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
144 //CHINA001 aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
145 //CHINA001 aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
146 //CHINA001 aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
147 //CHINA001 aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
148 //CHINA001 aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
150 //CHINA001 aBtnMore.AddWindow( &aBtnRename );
151 //CHINA001 aBtnMore.AddWindow( &aBtnNumFormat );
152 //CHINA001 aBtnMore.AddWindow( &aBtnBorder );
153 //CHINA001 aBtnMore.AddWindow( &aBtnFont );
154 //CHINA001 aBtnMore.AddWindow( &aBtnPattern );
155 //CHINA001 aBtnMore.AddWindow( &aBtnAlignment );
156 //CHINA001 aBtnMore.AddWindow( &aBtnAdjust );
157 //CHINA001 aBtnMore.AddWindow( &aFlFormatting );
159 //CHINA001 nCount = pFormat->GetCount();
161 //CHINA001 for ( USHORT i = 0; i < nCount; i++ )
163 //CHINA001 ((*pFormat)[i])->GetName( aEntry );
164 //CHINA001 aLbFormat.InsertEntry( aEntry );
167 //CHINA001 if ( nCount == 1 )
168 //CHINA001 aBtnRemove.Disable();
170 //CHINA001 aLbFormat.SelectEntryPos( 0 );
171 //CHINA001 aBtnRename.Disable();
172 //CHINA001 aBtnRemove.Disable();
174 //CHINA001 nIndex = 0;
175 //CHINA001 UpdateChecks();
177 //CHINA001 if ( !pSelFmtData )
179 //CHINA001 aBtnAdd.Disable();
180 //CHINA001 aBtnRemove.Disable();
181 //CHINA001 bFmtInserted = TRUE;
185 //CHINA001 //------------------------------------------------------------------------
187 //CHINA001 void ScAutoFormatDlg::UpdateChecks()
189 //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex];
191 //CHINA001 aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
192 //CHINA001 aBtnBorder .Check( pData->GetIncludeFrame() );
193 //CHINA001 aBtnFont .Check( pData->GetIncludeFont() );
194 //CHINA001 aBtnPattern .Check( pData->GetIncludeBackground() );
195 //CHINA001 aBtnAlignment.Check( pData->GetIncludeJustify() );
196 //CHINA001 aBtnAdjust .Check( pData->GetIncludeWidthHeight() );
199 //CHINA001 //------------------------------------------------------------------------
200 //CHINA001 // Handler:
201 //CHINA001 //---------
203 //CHINA001 IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
205 //CHINA001 if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
207 //CHINA001 if ( bCoreDataChanged )
208 //CHINA001 ScGlobal::GetAutoFormat()->Save();
210 //CHINA001 EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
215 //CHINA001 //------------------------------------------------------------------------
217 //CHINA001 IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
219 //CHINA001 if ( bCoreDataChanged )
220 //CHINA001 ScGlobal::GetAutoFormat()->Save();
222 //CHINA001 EndDialog( RET_OK );
225 //CHINA001 IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
227 //CHINA001 //------------------------------------------------------------------------
229 //CHINA001 IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
231 //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex];
232 //CHINA001 BOOL bCheck = ((CheckBox*)pBtn)->IsChecked();
234 //CHINA001 if ( pBtn == &aBtnNumFormat )
235 //CHINA001 pData->SetIncludeValueFormat( bCheck );
236 //CHINA001 else if ( pBtn == &aBtnBorder )
237 //CHINA001 pData->SetIncludeFrame( bCheck );
238 //CHINA001 else if ( pBtn == &aBtnFont )
239 //CHINA001 pData->SetIncludeFont( bCheck );
240 //CHINA001 else if ( pBtn == &aBtnPattern )
241 //CHINA001 pData->SetIncludeBackground( bCheck );
242 //CHINA001 else if ( pBtn == &aBtnAlignment )
243 //CHINA001 pData->SetIncludeJustify( bCheck );
244 //CHINA001 else if ( pBtn == &aBtnAdjust )
245 //CHINA001 pData->SetIncludeWidthHeight( bCheck );
247 //CHINA001 if ( !bCoreDataChanged )
249 //CHINA001 aBtnCancel.SetText( aStrClose );
250 //CHINA001 bCoreDataChanged = TRUE;
253 //CHINA001 pWndPreview->NotifyChange( pData );
258 //CHINA001 //------------------------------------------------------------------------
260 //CHINA001 IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
262 //CHINA001 if ( !bFmtInserted && pSelFmtData )
264 //CHINA001 String aStrStandard( ScResId(STR_STANDARD) );
265 //CHINA001 String aFormatName;
266 //CHINA001 ScStringInputDlg* pDlg;
267 //CHINA001 BOOL bOk = FALSE;
269 //CHINA001 while ( !bOk )
271 //CHINA001 pDlg = new ScStringInputDlg( this,
272 //CHINA001 aStrTitle,
273 //CHINA001 aStrLabel,
274 //CHINA001 aFormatName,
275 //CHINA001 HID_SC_ADD_AUTOFMT );
277 //CHINA001 if ( pDlg->Execute() == RET_OK )
279 //CHINA001 pDlg->GetInputString( aFormatName );
281 //CHINA001 if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) )
283 //CHINA001 ScAutoFormatData* pNewData
284 //CHINA001 = new ScAutoFormatData( *pSelFmtData );
286 //CHINA001 pNewData->SetName( aFormatName );
287 //CHINA001 bFmtInserted = pFormat->Insert( pNewData );
289 //CHINA001 if ( bFmtInserted )
291 //CHINA001 USHORT nAt = pFormat->IndexOf( pNewData );
293 //CHINA001 aLbFormat.InsertEntry( aFormatName, nAt );
294 //CHINA001 aLbFormat.SelectEntry( aFormatName );
295 //CHINA001 aBtnAdd.Disable();
297 //CHINA001 if ( !bCoreDataChanged )
299 //CHINA001 aBtnCancel.SetText( aStrClose );
300 //CHINA001 bCoreDataChanged = TRUE;
303 //CHINA001 SelFmtHdl( 0 );
304 //CHINA001 bOk = TRUE;
307 //CHINA001 delete pNewData;
311 //CHINA001 if ( !bFmtInserted )
313 //CHINA001 USHORT nRet = ErrorBox( this,
314 //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK),
315 //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME)
316 //CHINA001 ).Execute();
318 //CHINA001 bOk = ( nRet == RET_CANCEL );
322 //CHINA001 bOk = TRUE;
324 //CHINA001 delete pDlg;
331 //CHINA001 //------------------------------------------------------------------------
333 //CHINA001 IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
335 //CHINA001 if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
337 //CHINA001 String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
339 //CHINA001 aMsg += aLbFormat.GetSelectEntry();
340 //CHINA001 aMsg += aStrDelMsg.GetToken( 1, '#' );
342 //CHINA001 if ( RET_YES ==
343 //CHINA001 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
345 //CHINA001 aLbFormat.RemoveEntry( nIndex );
346 //CHINA001 aLbFormat.SelectEntryPos( nIndex-1 );
348 //CHINA001 if ( nIndex-1 == 0 )
349 //CHINA001 aBtnRemove.Disable();
351 //CHINA001 if ( !bCoreDataChanged )
353 //CHINA001 aBtnCancel.SetText( aStrClose );
354 //CHINA001 bCoreDataChanged = TRUE;
357 //CHINA001 pFormat->AtFree( nIndex ); // in der Core loeschen
360 //CHINA001 SelFmtHdl( 0 );
364 //CHINA001 SelFmtHdl( 0 );
369 //CHINA001 IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, pBtn)
371 //CHINA001 BOOL bOk = FALSE;
372 //CHINA001 while( !bOk )
375 //CHINA001 String aFormatName=aLbFormat.GetSelectEntry();
376 //CHINA001 String aEntry;
378 //CHINA001 ScStringInputDlg* pDlg = new ScStringInputDlg( this,
379 //CHINA001 aStrRename,
380 //CHINA001 aStrLabel,
381 //CHINA001 aFormatName,
382 //CHINA001 HID_SC_RENAME_AUTOFMT );
383 //CHINA001 if( pDlg->Execute() == RET_OK )
385 //CHINA001 BOOL bFmtRenamed = FALSE;
386 //CHINA001 pDlg->GetInputString( aFormatName );
389 //CHINA001 if ( aFormatName.Len() > 0 )
391 //CHINA001 for( n = 0; n < pFormat->GetCount(); ++n )
393 //CHINA001 (*pFormat)[n]->GetName(aEntry);
394 //CHINA001 if ( aEntry== aFormatName)
397 //CHINA001 if( n >= pFormat->GetCount() )
399 //CHINA001 // Format mit dem Namen noch nicht vorhanden, also
400 //CHINA001 // umbenennen
402 //CHINA001 aLbFormat.RemoveEntry(nIndex );
403 //CHINA001 ScAutoFormatData* p=(*pFormat)[ nIndex ];
404 //CHINA001 ScAutoFormatData* pNewData
405 //CHINA001 = new ScAutoFormatData(*p);
407 //CHINA001 pFormat->AtFree( nIndex );
409 //CHINA001 pNewData->SetName( aFormatName );
411 //CHINA001 pFormat->Insert( pNewData);
413 //CHINA001 USHORT nCount = pFormat->GetCount();
415 //CHINA001 aLbFormat.SetUpdateMode(FALSE);
416 //CHINA001 aLbFormat.Clear();
417 //CHINA001 for ( USHORT i = 0; i < nCount; i++ )
419 //CHINA001 ((*pFormat)[i])->GetName( aEntry );
420 //CHINA001 aLbFormat.InsertEntry( aEntry );
423 //CHINA001 aLbFormat.SetUpdateMode( TRUE);
424 //CHINA001 aLbFormat.SelectEntry( aFormatName);
426 //CHINA001 if ( !bCoreDataChanged )
428 //CHINA001 aBtnCancel.SetText( aStrClose );
429 //CHINA001 bCoreDataChanged = TRUE;
433 //CHINA001 SelFmtHdl( 0 );
434 //CHINA001 bOk = TRUE;
435 //CHINA001 bFmtRenamed = TRUE;
438 //CHINA001 if( !bFmtRenamed )
440 //CHINA001 bOk = RET_CANCEL == ErrorBox( this,
441 //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK),
442 //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME)
443 //CHINA001 ).Execute();
447 //CHINA001 bOk = TRUE;
448 //CHINA001 delete pDlg;
454 //CHINA001 //------------------------------------------------------------------------
456 //CHINA001 IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
458 //CHINA001 nIndex = aLbFormat.GetSelectEntryPos();
459 //CHINA001 UpdateChecks();
461 //CHINA001 if ( nIndex == 0 )
463 //CHINA001 aBtnRename.Disable();
464 //CHINA001 aBtnRemove.Disable();
468 //CHINA001 aBtnRename.Enable();
469 //CHINA001 aBtnRemove.Enable();
472 //CHINA001 pWndPreview->NotifyChange( (*pFormat)[nIndex] );
477 //CHINA001 //------------------------------------------------------------------------
479 //CHINA001 String ScAutoFormatDlg::GetCurrFormatName()
481 //CHINA001 String aResult;
483 //CHINA001 ((*pFormat)[nIndex])->GetName( aResult );
485 //CHINA001 return aResult;
488 //========================================================================
491 ScAutoFmtPreview::ScAutoFmtPreview( Window
* pParent
, const ResId
& rRes
, ScDocument
* pDoc
) :
492 Window ( pParent
, rRes
),
495 aScriptedText ( aVD
),
496 xBreakIter ( pDoc
->GetBreakIterator() ),
499 aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ),
500 mnLabelColWidth ( (aPrvSize
.Width() - 4) / 4 - 12 ),
501 mnDataColWidth1 ( (aPrvSize
.Width() - 4 - 2 * mnLabelColWidth
) / 3 ),
502 mnDataColWidth2 ( (aPrvSize
.Width() - 4 - 2 * mnLabelColWidth
) / 4 ),
503 mnRowHeight ( (aPrvSize
.Height() - 4) / 5 ),
504 aStrJan ( ScResId( STR_JAN
) ),
505 aStrFeb ( ScResId( STR_FEB
) ),
506 aStrMar ( ScResId( STR_MAR
) ),
507 aStrNorth ( ScResId( STR_NORTH
) ),
508 aStrMid ( ScResId( STR_MID
) ),
509 aStrSouth ( ScResId( STR_SOUTH
) ),
510 aStrSum ( ScResId( STR_SUM
) ),
511 pNumFmt ( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge
) )
515 ((String
&)aStrMar
).AssignAscii(RTL_CONSTASCII_STRINGPARAM( "Olk" ));
518 //------------------------------------------------------------------------
520 ScAutoFmtPreview::~ScAutoFmtPreview()
525 //------------------------------------------------------------------------
527 void lcl_SetFontProperties(
529 const SvxFontItem
& rFontItem
,
530 const SvxWeightItem
& rWeightItem
,
531 const SvxPostureItem
& rPostureItem
)
533 rFont
.SetFamily ( rFontItem
.GetFamily() );
534 rFont
.SetName ( rFontItem
.GetFamilyName() );
535 rFont
.SetStyleName ( rFontItem
.GetStyleName() );
536 rFont
.SetCharSet ( rFontItem
.GetCharSet() );
537 rFont
.SetPitch ( rFontItem
.GetPitch() );
538 rFont
.SetWeight ( (FontWeight
)rWeightItem
.GetValue() );
539 rFont
.SetItalic ( (FontItalic
)rPostureItem
.GetValue() );
542 void ScAutoFmtPreview::MakeFonts( USHORT nIndex
, Font
& rFont
, Font
& rCJKFont
, Font
& rCTLFont
)
546 rFont
= rCJKFont
= rCTLFont
= GetFont();
547 Size
aFontSize( rFont
.GetSize().Width(), 10 );
549 const SvxFontItem
* pFontItem
= (const SvxFontItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT
);
550 const SvxWeightItem
* pWeightItem
= (const SvxWeightItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_WEIGHT
);
551 const SvxPostureItem
* pPostureItem
= (const SvxPostureItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_POSTURE
);
552 const SvxFontItem
* pCJKFontItem
= (const SvxFontItem
*) pCurData
->GetItem( nIndex
, ATTR_CJK_FONT
);
553 const SvxWeightItem
* pCJKWeightItem
= (const SvxWeightItem
*) pCurData
->GetItem( nIndex
, ATTR_CJK_FONT_WEIGHT
);
554 const SvxPostureItem
* pCJKPostureItem
= (const SvxPostureItem
*) pCurData
->GetItem( nIndex
, ATTR_CJK_FONT_POSTURE
);
555 const SvxFontItem
* pCTLFontItem
= (const SvxFontItem
*) pCurData
->GetItem( nIndex
, ATTR_CTL_FONT
);
556 const SvxWeightItem
* pCTLWeightItem
= (const SvxWeightItem
*) pCurData
->GetItem( nIndex
, ATTR_CTL_FONT_WEIGHT
);
557 const SvxPostureItem
* pCTLPostureItem
= (const SvxPostureItem
*) pCurData
->GetItem( nIndex
, ATTR_CTL_FONT_POSTURE
);
558 const SvxUnderlineItem
* pUnderlineItem
= (const SvxUnderlineItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_UNDERLINE
);
559 const SvxOverlineItem
* pOverlineItem
= (const SvxOverlineItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_OVERLINE
);
560 const SvxCrossedOutItem
* pCrossedOutItem
= (const SvxCrossedOutItem
*)pCurData
->GetItem( nIndex
, ATTR_FONT_CROSSEDOUT
);
561 const SvxContourItem
* pContourItem
= (const SvxContourItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_CONTOUR
);
562 const SvxShadowedItem
* pShadowedItem
= (const SvxShadowedItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_SHADOWED
);
563 const SvxColorItem
* pColorItem
= (const SvxColorItem
*) pCurData
->GetItem( nIndex
, ATTR_FONT_COLOR
);
565 lcl_SetFontProperties( rFont
, *pFontItem
, *pWeightItem
, *pPostureItem
);
566 lcl_SetFontProperties( rCJKFont
, *pCJKFontItem
, *pCJKWeightItem
, *pCJKPostureItem
);
567 lcl_SetFontProperties( rCTLFont
, *pCTLFontItem
, *pCTLWeightItem
, *pCTLPostureItem
);
569 Color
aColor( pColorItem
->GetValue() );
570 if( aColor
.GetColor() == COL_TRANSPARENT
)
571 aColor
= GetSettings().GetStyleSettings().GetWindowTextColor();
573 #define SETONALLFONTS( MethodName, Value ) \
574 rFont.MethodName( Value ); rCJKFont.MethodName( Value ); rCTLFont.MethodName( Value );
576 SETONALLFONTS( SetUnderline
, (FontUnderline
)pUnderlineItem
->GetValue() )
577 SETONALLFONTS( SetOverline
, (FontUnderline
)pOverlineItem
->GetValue() )
578 SETONALLFONTS( SetStrikeout
, (FontStrikeout
)pCrossedOutItem
->GetValue() )
579 SETONALLFONTS( SetOutline
, pContourItem
->GetValue() )
580 SETONALLFONTS( SetShadow
, pShadowedItem
->GetValue() )
581 SETONALLFONTS( SetColor
, aColor
)
582 SETONALLFONTS( SetSize
, aFontSize
)
583 SETONALLFONTS( SetTransparent
, TRUE
)
589 //------------------------------------------------------------------------
591 USHORT
ScAutoFmtPreview::GetFormatIndex( size_t nCol
, size_t nRow
) const
593 static const USHORT pnFmtMap
[] =
601 return pnFmtMap
[ maArray
.GetCellIndex( nCol
, nRow
, mbRTL
) ];
604 const SvxBoxItem
& ScAutoFmtPreview::GetBoxItem( size_t nCol
, size_t nRow
) const
606 DBG_ASSERT( pCurData
, "ScAutoFmtPreview::GetBoxItem - no format data found" );
607 return *static_cast< const SvxBoxItem
* >( pCurData
->GetItem( GetFormatIndex( nCol
, nRow
), ATTR_BORDER
) );
610 const SvxLineItem
& ScAutoFmtPreview::GetDiagItem( size_t nCol
, size_t nRow
, bool bTLBR
) const
612 DBG_ASSERT( pCurData
, "ScAutoFmtPreview::GetDiagItem - no format data found" );
613 return *static_cast< const SvxLineItem
* >( pCurData
->GetItem( GetFormatIndex( nCol
, nRow
), bTLBR
? ATTR_BORDER_TLBR
: ATTR_BORDER_BLTR
) );
616 //------------------------------------------------------------------------
618 void ScAutoFmtPreview::DrawString( size_t nCol
, size_t nRow
)
622 //------------------------
623 // Ausgabe des Zelltextes:
624 //------------------------
627 BOOL bNumFormat
= pCurData
->GetIncludeValueFormat();
630 Color
* pDummy
= NULL
;
631 USHORT nIndex
= static_cast< USHORT
>( maArray
.GetCellIndex( nCol
, nRow
, mbRTL
) );
635 case 1: cellString
= aStrJan
; break;
636 case 2: cellString
= aStrFeb
; break;
637 case 3: cellString
= aStrMar
; break;
638 case 5: cellString
= aStrNorth
; break;
639 case 10: cellString
= aStrMid
; break;
640 case 15: cellString
= aStrSouth
; break;
642 case 20: cellString
= aStrSum
; break;
647 case 18: nVal
= nIndex
;
651 case 7: nVal
= nIndex
;
656 case 13: nVal
= nIndex
;
657 nNum
= 12 == nIndex
? 10 : 9;
660 case 9: nVal
= 21; nNum
= 7; goto mknum
;
661 case 14: nVal
= 36; nNum
= 11; goto mknum
;
662 case 19: nVal
= 51; nNum
= 7; goto mknum
;
663 case 21: nVal
= 33; nNum
= 13; goto mknum
;
664 case 22: nVal
= 36; nNum
= 14; goto mknum
;
665 case 23: nVal
= 39; nNum
= 13; goto mknum
;
666 case 24: nVal
= 108; nNum
= 15;
670 ScNumFormatAbbrev
& rNumFormat
= (ScNumFormatAbbrev
&)pCurData
->GetNumFormat( (USHORT
) nNum
);
671 nNum
= rNumFormat
.GetFormatIndex( *pNumFmt
);
675 pNumFmt
->GetOutputString( nVal
, nNum
, cellString
, &pDummy
);
679 if ( cellString
.Len() > 0 )
682 USHORT nFmtIndex
= GetFormatIndex( nCol
, nRow
);
683 Rectangle cellRect
= maArray
.GetCellRect( nCol
, nRow
);
684 Point aPos
= cellRect
.TopLeft();
686 BOOL bJustify
= pCurData
->GetIncludeJustify();
687 SvxHorJustifyItem
aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD
, ATTR_HOR_JUSTIFY
);
688 SvxCellHorJustify eJustification
;
693 eJustification
= mbRTL
? SVX_HOR_JUSTIFY_RIGHT
: bJustify
?
694 (SvxCellHorJustify
)(((const SvxHorJustifyItem
*)pCurData
->GetItem( nFmtIndex
, ATTR_HOR_JUSTIFY
))->GetValue()) :
695 SVX_HOR_JUSTIFY_STANDARD
;
697 if ( pCurData
->GetIncludeFont() )
699 Font aFont
, aCJKFont
, aCTLFont
;
702 MakeFonts( nFmtIndex
, aFont
, aCJKFont
, aCTLFont
);
704 theMaxStrSize
= cellRect
.GetSize();
705 theMaxStrSize
.Width() -= FRAME_OFFSET
;
706 theMaxStrSize
.Height() -= FRAME_OFFSET
;
708 aScriptedText
.SetFonts( &aFont
, &aCJKFont
, &aCTLFont
);
709 aScriptedText
.SetText( cellString
, xBreakIter
);
710 aStrSize
= aScriptedText
.GetTextSize();
712 if ( theMaxStrSize
.Height() < aStrSize
.Height() )
714 // wenn der String in diesem Font nicht
715 // in die Zelle passt, wird wieder der
716 // Standard-Font genommen:
717 aScriptedText
.SetDefaultFont();
718 aStrSize
= aScriptedText
.GetTextSize();
720 while ( ( theMaxStrSize
.Width() <= aStrSize
.Width() )
721 && ( cellString
.Len() > 1 ) )
723 if( eJustification
== SVX_HOR_JUSTIFY_RIGHT
)
724 cellString
.Erase( 0, 1 );
726 cellString
.Erase( cellString
.Len() - 1 );
728 aScriptedText
.SetText( cellString
, xBreakIter
);
729 aStrSize
= aScriptedText
.GetTextSize();
734 aScriptedText
.SetDefaultFont();
735 aScriptedText
.SetText( cellString
, xBreakIter
);
736 aStrSize
= aScriptedText
.GetTextSize();
739 nRightX
= (USHORT
)( cellRect
.GetWidth()
743 //-----------------------------
744 // vertikal (immer zentrieren):
745 //-----------------------------
746 aPos
.Y() += (mnRowHeight
- (USHORT
)aStrSize
.Height()) / 2;
751 if ( eJustification
!= SVX_HOR_JUSTIFY_STANDARD
)
753 USHORT nHorPos
= (USHORT
)
754 ((cellRect
.GetWidth()-aStrSize
.Width())/2);
756 switch ( eJustification
)
758 case SVX_HOR_JUSTIFY_LEFT
:
759 aPos
.X() += FRAME_OFFSET
;
761 case SVX_HOR_JUSTIFY_RIGHT
:
764 case SVX_HOR_JUSTIFY_BLOCK
:
765 case SVX_HOR_JUSTIFY_REPEAT
:
766 case SVX_HOR_JUSTIFY_CENTER
:
769 case SVX_HOR_JUSTIFY_STANDARD
:
771 // Standard wird hier nicht behandelt
777 //---------------------
778 // Standardausrichtung:
779 //---------------------
780 if ( (nCol
== 0) || (nRow
== 0) )
782 // Text-Label links oder Summe linksbuendig
783 aPos
.X() += FRAME_OFFSET
;
787 // Zahlen/Datum rechtsbuendig
792 //-------------------------------
793 aScriptedText
.DrawText( aPos
);
794 //-------------------------------
801 //------------------------------------------------------------------------
803 void ScAutoFmtPreview::DrawStrings()
805 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
806 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
807 DrawString( nCol
, nRow
);
810 //------------------------------------------------------------------------
812 void ScAutoFmtPreview::DrawBackground()
816 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
818 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
820 const SvxBrushItem
* pItem
= static_cast< const SvxBrushItem
* >(
821 pCurData
->GetItem( GetFormatIndex( nCol
, nRow
), ATTR_BACKGROUND
) );
823 aVD
.Push( PUSH_LINECOLOR
| PUSH_FILLCOLOR
);
825 aVD
.SetFillColor( pItem
->GetColor() );
826 aVD
.DrawRect( maArray
.GetCellRect( nCol
, nRow
) );
833 //------------------------------------------------------------------------
835 void ScAutoFmtPreview::PaintCells()
840 if ( pCurData
->GetIncludeBackground() )
847 if ( pCurData
->GetIncludeFrame() )
848 maArray
.DrawArray( aVD
);
852 //------------------------------------------------------------------------
854 void ScAutoFmtPreview::Init()
856 SetBorderStyle( WINDOW_BORDER_MONO
);
857 maArray
.Initialize( 5, 5 );
858 maArray
.SetUseDiagDoubleClipping( false );
859 CalcCellArray( FALSE
);
862 TypeId
aType(TYPE(ScDocShell
));
863 ScDocShell
* pDocShell
= (ScDocShell
*)SfxObjectShell::GetFirst(&aType
);
864 SfxViewFrame
* pFrame
= SfxViewFrame::GetFirst( pDocShell
);
865 SfxViewShell
* p
= pFrame
->GetViewShell();
866 ScTabViewShell
* pViewSh
= dynamic_cast< ScTabViewShell
* >( p
);
867 ScViewData
* pViewData
= pViewSh
->GetViewData();
868 SCTAB nCurrentTab
= pViewData
->GetTabNo();
869 ScDocument
* pDoc
= pViewData
->GetDocument();
870 mbRTL
= pDoc
->IsLayoutRTL( nCurrentTab
);
873 //------------------------------------------------------------------------
875 void ScAutoFmtPreview::CalcCellArray( BOOL bFitWidthP
)
877 maArray
.SetXOffset( 2 );
878 maArray
.SetAllColWidths( bFitWidthP
? mnDataColWidth2
: mnDataColWidth1
);
879 maArray
.SetColWidth( 0, mnLabelColWidth
);
880 maArray
.SetColWidth( 4, mnLabelColWidth
);
882 maArray
.SetYOffset( 2 );
883 maArray
.SetAllRowHeights( mnRowHeight
);
885 aPrvSize
.Width() = maArray
.GetWidth() + 4;
886 aPrvSize
.Height() = maArray
.GetHeight() + 4;
889 //------------------------------------------------------------------------
891 inline void lclSetStyleFromBorder( svx::frame::Style
& rStyle
, const SvxBorderLine
* pBorder
)
893 rStyle
.Set( pBorder
, 1.0 / TWIPS_PER_POINT
, 5 );
896 void ScAutoFmtPreview::CalcLineMap()
900 for( size_t nRow
= 0; nRow
< 5; ++nRow
)
902 for( size_t nCol
= 0; nCol
< 5; ++nCol
)
904 svx::frame::Style aStyle
;
906 const SvxBoxItem
& rItem
= GetBoxItem( nCol
, nRow
);
907 lclSetStyleFromBorder( aStyle
, rItem
.GetLeft() );
908 maArray
.SetCellStyleLeft( nCol
, nRow
, aStyle
);
909 lclSetStyleFromBorder( aStyle
, rItem
.GetRight() );
910 maArray
.SetCellStyleRight( nCol
, nRow
, aStyle
);
911 lclSetStyleFromBorder( aStyle
, rItem
.GetTop() );
912 maArray
.SetCellStyleTop( nCol
, nRow
, aStyle
);
913 lclSetStyleFromBorder( aStyle
, rItem
.GetBottom() );
914 maArray
.SetCellStyleBottom( nCol
, nRow
, aStyle
);
916 lclSetStyleFromBorder( aStyle
, GetDiagItem( nCol
, nRow
, true ).GetLine() );
917 maArray
.SetCellStyleTLBR( nCol
, nRow
, aStyle
);
918 lclSetStyleFromBorder( aStyle
, GetDiagItem( nCol
, nRow
, false ).GetLine() );
919 maArray
.SetCellStyleBLTR( nCol
, nRow
, aStyle
);
925 //------------------------------------------------------------------------
927 void ScAutoFmtPreview::NotifyChange( ScAutoFormatData
* pNewData
)
929 if ( pNewData
!= pCurData
)
932 bFitWidth
= pNewData
->GetIncludeWidthHeight();
933 CalcCellArray( bFitWidth
);
936 else if ( bFitWidth
!= pNewData
->GetIncludeWidthHeight() )
938 bFitWidth
= !bFitWidth
;
939 CalcCellArray( bFitWidth
);
942 DoPaint( Rectangle( Point(0,0), GetSizePixel() ) );
945 //------------------------------------------------------------------------
947 void ScAutoFmtPreview::DoPaint( const Rectangle
& /* rRect */ )
949 sal_uInt32 nOldDrawMode
= aVD
.GetDrawMode();
950 // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed TRUE)
951 if( GetSettings().GetStyleSettings().GetHighContrastMode() )
952 aVD
.SetDrawMode( DRAWMODE_SETTINGSLINE
| DRAWMODE_SETTINGSFILL
| DRAWMODE_SETTINGSTEXT
| DRAWMODE_SETTINGSGRADIENT
);
954 Size
aWndSize( GetSizePixel() );
955 Font
aFont( aVD
.GetFont() );
956 Color
aBackCol( GetSettings().GetStyleSettings().GetWindowColor() );
958 Rectangle
aRect( aTmpPoint
, aWndSize
);
960 aFont
.SetTransparent( TRUE
);
961 aVD
.SetFont( aFont
);
963 aVD
.SetFillColor( aBackCol
);
964 aVD
.SetOutputSize( aWndSize
);
965 aVD
.DrawRect( aRect
);
969 SetFillColor( aBackCol
);
972 Point
aPos( (aWndSize
.Width() - aPrvSize
.Width()) / 2, (aWndSize
.Height() - aPrvSize
.Height()) / 2 );
973 if (Application::GetSettings().GetLayoutRTL())
974 aPos
.X() = -aPos
.X();
975 DrawOutDev( aPos
, aWndSize
, Point(), aWndSize
, aVD
);
977 aVD
.SetDrawMode( nOldDrawMode
);
980 //------------------------------------------------------------------------
982 void ScAutoFmtPreview::Paint( const Rectangle
& rRect
)