1*b3f79822SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*b3f79822SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*b3f79822SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*b3f79822SAndrew Rist * distributed with this work for additional information 6*b3f79822SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*b3f79822SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*b3f79822SAndrew Rist * "License"); you may not use this file except in compliance 9*b3f79822SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*b3f79822SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*b3f79822SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*b3f79822SAndrew Rist * software distributed under the License is distributed on an 15*b3f79822SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*b3f79822SAndrew Rist * KIND, either express or implied. See the License for the 17*b3f79822SAndrew Rist * specific language governing permissions and limitations 18*b3f79822SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*b3f79822SAndrew Rist *************************************************************/ 21*b3f79822SAndrew Rist 22*b3f79822SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_sc.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir 28cdf0e10cSrcweir 29cdf0e10cSrcweir //------------------------------------------------------------------ 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include "scitems.hxx" 32cdf0e10cSrcweir #include <svx/algitem.hxx> 33cdf0e10cSrcweir #include <editeng/boxitem.hxx> 34cdf0e10cSrcweir #include <editeng/brshitem.hxx> 35cdf0e10cSrcweir #include <editeng/cntritem.hxx> 36cdf0e10cSrcweir #include <editeng/colritem.hxx> 37cdf0e10cSrcweir #include <editeng/crsditem.hxx> 38cdf0e10cSrcweir #include <editeng/fontitem.hxx> 39cdf0e10cSrcweir #include <editeng/postitem.hxx> 40cdf0e10cSrcweir #include <editeng/shdditem.hxx> 41cdf0e10cSrcweir #include <editeng/udlnitem.hxx> 42cdf0e10cSrcweir #include <editeng/wghtitem.hxx> 43cdf0e10cSrcweir #include <vcl/svapp.hxx> 44cdf0e10cSrcweir #include <svl/zforlist.hxx> 45cdf0e10cSrcweir #include <vcl/msgbox.hxx> 46cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 47cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 48cdf0e10cSrcweir 49cdf0e10cSrcweir #include "sc.hrc" 50cdf0e10cSrcweir #include "scmod.hxx" 51cdf0e10cSrcweir #include "attrib.hxx" 52cdf0e10cSrcweir #include "zforauto.hxx" 53cdf0e10cSrcweir #include "scitems.hxx" 54cdf0e10cSrcweir #include "global.hxx" 55cdf0e10cSrcweir #include "globstr.hrc" 56cdf0e10cSrcweir #include "autoform.hxx" 57cdf0e10cSrcweir //CHINA001 #include "strindlg.hxx" 58cdf0e10cSrcweir #include "miscdlgs.hrc" 59cdf0e10cSrcweir #include "autofmt.hxx" 60cdf0e10cSrcweir #include "scresid.hxx" 61cdf0e10cSrcweir #include "document.hxx" 62cdf0e10cSrcweir #include "docsh.hxx" 63cdf0e10cSrcweir #include "tabvwsh.hxx" 64cdf0e10cSrcweir 65cdf0e10cSrcweir #define FRAME_OFFSET 4 66cdf0e10cSrcweir 67cdf0e10cSrcweir 68cdf0e10cSrcweir //CHINA001 //======================================================================== 69cdf0e10cSrcweir //CHINA001 // AutoFormat-Dialog: 70cdf0e10cSrcweir //CHINA001 71cdf0e10cSrcweir //CHINA001 ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent, 72cdf0e10cSrcweir //CHINA001 ScAutoFormat* pAutoFormat, 73cdf0e10cSrcweir //CHINA001 const ScAutoFormatData* pSelFormatData, 74cdf0e10cSrcweir //CHINA001 ScDocument* pDoc ) : 75cdf0e10cSrcweir //CHINA001 76cdf0e10cSrcweir //CHINA001 ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ), 77cdf0e10cSrcweir //CHINA001 // 78cdf0e10cSrcweir //CHINA001 aLbFormat ( this, ScResId( LB_FORMAT ) ), 79cdf0e10cSrcweir //CHINA001 aFlFormat ( this, ScResId( FL_FORMAT ) ), 80cdf0e10cSrcweir //CHINA001 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ), 81cdf0e10cSrcweir //CHINA001 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ), 82cdf0e10cSrcweir //CHINA001 aBtnBorder ( this, ScResId( BTN_BORDER ) ), 83cdf0e10cSrcweir //CHINA001 aBtnFont ( this, ScResId( BTN_FONT ) ), 84cdf0e10cSrcweir //CHINA001 aBtnPattern ( this, ScResId( BTN_PATTERN ) ), 85cdf0e10cSrcweir //CHINA001 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ), 86cdf0e10cSrcweir //CHINA001 aBtnAdjust ( this, ScResId( BTN_ADJUST ) ), 87cdf0e10cSrcweir //CHINA001 aFlFormatting ( this, ScResId( FL_FORMATTING ) ), 88cdf0e10cSrcweir //CHINA001 aBtnOk ( this, ScResId( BTN_OK ) ), 89cdf0e10cSrcweir //CHINA001 aBtnCancel ( this, ScResId( BTN_CANCEL ) ), 90cdf0e10cSrcweir //CHINA001 aBtnHelp ( this, ScResId( BTN_HELP ) ), 91cdf0e10cSrcweir //CHINA001 aBtnAdd ( this, ScResId( BTN_ADD ) ), 92cdf0e10cSrcweir //CHINA001 aBtnRemove ( this, ScResId( BTN_REMOVE ) ), 93cdf0e10cSrcweir //CHINA001 aBtnMore ( this, ScResId( BTN_MORE ) ), 94cdf0e10cSrcweir //CHINA001 aBtnRename ( this, ScResId( BTN_RENAME ) ), 95cdf0e10cSrcweir //CHINA001 aStrTitle ( ScResId( STR_ADD_TITLE ) ), 96cdf0e10cSrcweir //CHINA001 aStrLabel ( ScResId( STR_ADD_LABEL ) ), 97cdf0e10cSrcweir //CHINA001 aStrRename ( ScResId( STR_RENAME_TITLE ) ), 98cdf0e10cSrcweir //CHINA001 aStrClose ( ScResId( STR_BTN_CLOSE ) ), 99cdf0e10cSrcweir //CHINA001 aStrDelTitle ( ScResId( STR_DEL_TITLE ) ), 100cdf0e10cSrcweir //CHINA001 aStrDelMsg ( ScResId( STR_DEL_MSG ) ) , 101cdf0e10cSrcweir //CHINA001 // 102cdf0e10cSrcweir //CHINA001 nIndex ( 0 ), 103cdf0e10cSrcweir //CHINA001 bFmtInserted ( sal_False ), 104cdf0e10cSrcweir //CHINA001 bCoreDataChanged( sal_False ), 105cdf0e10cSrcweir //CHINA001 pFormat ( pAutoFormat ), 106cdf0e10cSrcweir //CHINA001 pSelFmtData ( pSelFormatData ) 107cdf0e10cSrcweir //CHINA001 { 108cdf0e10cSrcweir //CHINA001 Init(); 109cdf0e10cSrcweir //CHINA001 pWndPreview->NotifyChange( (*pFormat)[0] ); 110cdf0e10cSrcweir //CHINA001 FreeResource(); 111cdf0e10cSrcweir //CHINA001 } 112cdf0e10cSrcweir //CHINA001 113cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 114cdf0e10cSrcweir //CHINA001 115cdf0e10cSrcweir //CHINA001 ScAutoFormatDlg::~ScAutoFormatDlg() 116cdf0e10cSrcweir //CHINA001 { 117cdf0e10cSrcweir //CHINA001 delete pWndPreview; 118cdf0e10cSrcweir //CHINA001 } 119cdf0e10cSrcweir //CHINA001 120cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 121cdf0e10cSrcweir //CHINA001 122cdf0e10cSrcweir //CHINA001 void ScAutoFormatDlg::Init() 123cdf0e10cSrcweir //CHINA001 { 124cdf0e10cSrcweir //CHINA001 sal_uInt16 nCount; 125cdf0e10cSrcweir //CHINA001 String aEntry; 126cdf0e10cSrcweir //CHINA001 127cdf0e10cSrcweir //CHINA001 aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) ); 128cdf0e10cSrcweir //CHINA001 aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 129cdf0e10cSrcweir //CHINA001 aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 130cdf0e10cSrcweir //CHINA001 aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 131cdf0e10cSrcweir //CHINA001 aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 132cdf0e10cSrcweir //CHINA001 aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 133cdf0e10cSrcweir //CHINA001 aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) ); 134cdf0e10cSrcweir //CHINA001 aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) ); 135cdf0e10cSrcweir //CHINA001 aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) ); 136cdf0e10cSrcweir //CHINA001 aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) ); 137cdf0e10cSrcweir //CHINA001 aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) ); 138cdf0e10cSrcweir //CHINA001 aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) ); 139cdf0e10cSrcweir //CHINA001 aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) ); 140cdf0e10cSrcweir //CHINA001 141cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnRename ); 142cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnNumFormat ); 143cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnBorder ); 144cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnFont ); 145cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnPattern ); 146cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnAlignment ); 147cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aBtnAdjust ); 148cdf0e10cSrcweir //CHINA001 aBtnMore.AddWindow( &aFlFormatting ); 149cdf0e10cSrcweir //CHINA001 150cdf0e10cSrcweir //CHINA001 nCount = pFormat->GetCount(); 151cdf0e10cSrcweir //CHINA001 152cdf0e10cSrcweir //CHINA001 for ( sal_uInt16 i = 0; i < nCount; i++ ) 153cdf0e10cSrcweir //CHINA001 { 154cdf0e10cSrcweir //CHINA001 ((*pFormat)[i])->GetName( aEntry ); 155cdf0e10cSrcweir //CHINA001 aLbFormat.InsertEntry( aEntry ); 156cdf0e10cSrcweir //CHINA001 } 157cdf0e10cSrcweir //CHINA001 158cdf0e10cSrcweir //CHINA001 if ( nCount == 1 ) 159cdf0e10cSrcweir //CHINA001 aBtnRemove.Disable(); 160cdf0e10cSrcweir //CHINA001 161cdf0e10cSrcweir //CHINA001 aLbFormat.SelectEntryPos( 0 ); 162cdf0e10cSrcweir //CHINA001 aBtnRename.Disable(); 163cdf0e10cSrcweir //CHINA001 aBtnRemove.Disable(); 164cdf0e10cSrcweir //CHINA001 165cdf0e10cSrcweir //CHINA001 nIndex = 0; 166cdf0e10cSrcweir //CHINA001 UpdateChecks(); 167cdf0e10cSrcweir //CHINA001 168cdf0e10cSrcweir //CHINA001 if ( !pSelFmtData ) 169cdf0e10cSrcweir //CHINA001 { 170cdf0e10cSrcweir //CHINA001 aBtnAdd.Disable(); 171cdf0e10cSrcweir //CHINA001 aBtnRemove.Disable(); 172cdf0e10cSrcweir //CHINA001 bFmtInserted = sal_True; 173cdf0e10cSrcweir //CHINA001 } 174cdf0e10cSrcweir //CHINA001 } 175cdf0e10cSrcweir //CHINA001 176cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 177cdf0e10cSrcweir //CHINA001 178cdf0e10cSrcweir //CHINA001 void ScAutoFormatDlg::UpdateChecks() 179cdf0e10cSrcweir //CHINA001 { 180cdf0e10cSrcweir //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex]; 181cdf0e10cSrcweir //CHINA001 182cdf0e10cSrcweir //CHINA001 aBtnNumFormat.Check( pData->GetIncludeValueFormat() ); 183cdf0e10cSrcweir //CHINA001 aBtnBorder .Check( pData->GetIncludeFrame() ); 184cdf0e10cSrcweir //CHINA001 aBtnFont .Check( pData->GetIncludeFont() ); 185cdf0e10cSrcweir //CHINA001 aBtnPattern .Check( pData->GetIncludeBackground() ); 186cdf0e10cSrcweir //CHINA001 aBtnAlignment.Check( pData->GetIncludeJustify() ); 187cdf0e10cSrcweir //CHINA001 aBtnAdjust .Check( pData->GetIncludeWidthHeight() ); 188cdf0e10cSrcweir //CHINA001 } 189cdf0e10cSrcweir //CHINA001 190cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 191cdf0e10cSrcweir //CHINA001 // Handler: 192cdf0e10cSrcweir //CHINA001 //--------- 193cdf0e10cSrcweir //CHINA001 194cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn ) 195cdf0e10cSrcweir //CHINA001 { 196cdf0e10cSrcweir //CHINA001 if ( pBtn == &aBtnOk || pBtn == &aBtnCancel ) 197cdf0e10cSrcweir //CHINA001 { 198cdf0e10cSrcweir //CHINA001 if ( bCoreDataChanged ) 199cdf0e10cSrcweir //CHINA001 ScGlobal::GetAutoFormat()->Save(); 200cdf0e10cSrcweir //CHINA001 201cdf0e10cSrcweir //CHINA001 EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL ); 202cdf0e10cSrcweir //CHINA001 } 203cdf0e10cSrcweir //CHINA001 return 0; 204cdf0e10cSrcweir //CHINA001 } 205cdf0e10cSrcweir //CHINA001 206cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 207cdf0e10cSrcweir //CHINA001 208cdf0e10cSrcweir //CHINA001 IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG ) 209cdf0e10cSrcweir //CHINA001 { 210cdf0e10cSrcweir //CHINA001 if ( bCoreDataChanged ) 211cdf0e10cSrcweir //CHINA001 ScGlobal::GetAutoFormat()->Save(); 212cdf0e10cSrcweir //CHINA001 213cdf0e10cSrcweir //CHINA001 EndDialog( RET_OK ); 214cdf0e10cSrcweir //CHINA001 return 0; 215cdf0e10cSrcweir //CHINA001 } 216cdf0e10cSrcweir //CHINA001 IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG ) 217cdf0e10cSrcweir //CHINA001 218cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 219cdf0e10cSrcweir //CHINA001 220cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn ) 221cdf0e10cSrcweir //CHINA001 { 222cdf0e10cSrcweir //CHINA001 ScAutoFormatData* pData = (*pFormat)[nIndex]; 223cdf0e10cSrcweir //CHINA001 sal_Bool bCheck = ((CheckBox*)pBtn)->IsChecked(); 224cdf0e10cSrcweir //CHINA001 225cdf0e10cSrcweir //CHINA001 if ( pBtn == &aBtnNumFormat ) 226cdf0e10cSrcweir //CHINA001 pData->SetIncludeValueFormat( bCheck ); 227cdf0e10cSrcweir //CHINA001 else if ( pBtn == &aBtnBorder ) 228cdf0e10cSrcweir //CHINA001 pData->SetIncludeFrame( bCheck ); 229cdf0e10cSrcweir //CHINA001 else if ( pBtn == &aBtnFont ) 230cdf0e10cSrcweir //CHINA001 pData->SetIncludeFont( bCheck ); 231cdf0e10cSrcweir //CHINA001 else if ( pBtn == &aBtnPattern ) 232cdf0e10cSrcweir //CHINA001 pData->SetIncludeBackground( bCheck ); 233cdf0e10cSrcweir //CHINA001 else if ( pBtn == &aBtnAlignment ) 234cdf0e10cSrcweir //CHINA001 pData->SetIncludeJustify( bCheck ); 235cdf0e10cSrcweir //CHINA001 else if ( pBtn == &aBtnAdjust ) 236cdf0e10cSrcweir //CHINA001 pData->SetIncludeWidthHeight( bCheck ); 237cdf0e10cSrcweir //CHINA001 238cdf0e10cSrcweir //CHINA001 if ( !bCoreDataChanged ) 239cdf0e10cSrcweir //CHINA001 { 240cdf0e10cSrcweir //CHINA001 aBtnCancel.SetText( aStrClose ); 241cdf0e10cSrcweir //CHINA001 bCoreDataChanged = sal_True; 242cdf0e10cSrcweir //CHINA001 } 243cdf0e10cSrcweir //CHINA001 244cdf0e10cSrcweir //CHINA001 pWndPreview->NotifyChange( pData ); 245cdf0e10cSrcweir //CHINA001 246cdf0e10cSrcweir //CHINA001 return 0; 247cdf0e10cSrcweir //CHINA001 } 248cdf0e10cSrcweir //CHINA001 249cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 250cdf0e10cSrcweir //CHINA001 251cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG ) 252cdf0e10cSrcweir //CHINA001 { 253cdf0e10cSrcweir //CHINA001 if ( !bFmtInserted && pSelFmtData ) 254cdf0e10cSrcweir //CHINA001 { 255cdf0e10cSrcweir //CHINA001 String aStrStandard( ScResId(STR_STANDARD) ); 256cdf0e10cSrcweir //CHINA001 String aFormatName; 257cdf0e10cSrcweir //CHINA001 ScStringInputDlg* pDlg; 258cdf0e10cSrcweir //CHINA001 sal_Bool bOk = sal_False; 259cdf0e10cSrcweir //CHINA001 260cdf0e10cSrcweir //CHINA001 while ( !bOk ) 261cdf0e10cSrcweir //CHINA001 { 262cdf0e10cSrcweir //CHINA001 pDlg = new ScStringInputDlg( this, 263cdf0e10cSrcweir //CHINA001 aStrTitle, 264cdf0e10cSrcweir //CHINA001 aStrLabel, 265cdf0e10cSrcweir //CHINA001 aFormatName, 266cdf0e10cSrcweir //CHINA001 HID_SC_ADD_AUTOFMT ); 267cdf0e10cSrcweir //CHINA001 268cdf0e10cSrcweir //CHINA001 if ( pDlg->Execute() == RET_OK ) 269cdf0e10cSrcweir //CHINA001 { 270cdf0e10cSrcweir //CHINA001 pDlg->GetInputString( aFormatName ); 271cdf0e10cSrcweir //CHINA001 272cdf0e10cSrcweir //CHINA001 if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) ) 273cdf0e10cSrcweir //CHINA001 { 274cdf0e10cSrcweir //CHINA001 ScAutoFormatData* pNewData 275cdf0e10cSrcweir //CHINA001 = new ScAutoFormatData( *pSelFmtData ); 276cdf0e10cSrcweir //CHINA001 277cdf0e10cSrcweir //CHINA001 pNewData->SetName( aFormatName ); 278cdf0e10cSrcweir //CHINA001 bFmtInserted = pFormat->Insert( pNewData ); 279cdf0e10cSrcweir //CHINA001 280cdf0e10cSrcweir //CHINA001 if ( bFmtInserted ) 281cdf0e10cSrcweir //CHINA001 { 282cdf0e10cSrcweir //CHINA001 sal_uInt16 nAt = pFormat->IndexOf( pNewData ); 283cdf0e10cSrcweir //CHINA001 284cdf0e10cSrcweir //CHINA001 aLbFormat.InsertEntry( aFormatName, nAt ); 285cdf0e10cSrcweir //CHINA001 aLbFormat.SelectEntry( aFormatName ); 286cdf0e10cSrcweir //CHINA001 aBtnAdd.Disable(); 287cdf0e10cSrcweir //CHINA001 288cdf0e10cSrcweir //CHINA001 if ( !bCoreDataChanged ) 289cdf0e10cSrcweir //CHINA001 { 290cdf0e10cSrcweir //CHINA001 aBtnCancel.SetText( aStrClose ); 291cdf0e10cSrcweir //CHINA001 bCoreDataChanged = sal_True; 292cdf0e10cSrcweir //CHINA001 } 293cdf0e10cSrcweir //CHINA001 294cdf0e10cSrcweir //CHINA001 SelFmtHdl( 0 ); 295cdf0e10cSrcweir //CHINA001 bOk = sal_True; 296cdf0e10cSrcweir //CHINA001 } 297cdf0e10cSrcweir //CHINA001 else 298cdf0e10cSrcweir //CHINA001 delete pNewData; 299cdf0e10cSrcweir //CHINA001 300cdf0e10cSrcweir //CHINA001 } 301cdf0e10cSrcweir //CHINA001 302cdf0e10cSrcweir //CHINA001 if ( !bFmtInserted ) 303cdf0e10cSrcweir //CHINA001 { 304cdf0e10cSrcweir //CHINA001 sal_uInt16 nRet = ErrorBox( this, 305cdf0e10cSrcweir //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK), 306cdf0e10cSrcweir //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME) 307cdf0e10cSrcweir //CHINA001 ).Execute(); 308cdf0e10cSrcweir //CHINA001 309cdf0e10cSrcweir //CHINA001 bOk = ( nRet == RET_CANCEL ); 310cdf0e10cSrcweir //CHINA001 } 311cdf0e10cSrcweir //CHINA001 } 312cdf0e10cSrcweir //CHINA001 else 313cdf0e10cSrcweir //CHINA001 bOk = sal_True; 314cdf0e10cSrcweir //CHINA001 315cdf0e10cSrcweir //CHINA001 delete pDlg; 316cdf0e10cSrcweir //CHINA001 } 317cdf0e10cSrcweir //CHINA001 } 318cdf0e10cSrcweir //CHINA001 319cdf0e10cSrcweir //CHINA001 return 0; 320cdf0e10cSrcweir //CHINA001 } 321cdf0e10cSrcweir //CHINA001 322cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 323cdf0e10cSrcweir //CHINA001 324cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG ) 325cdf0e10cSrcweir //CHINA001 { 326cdf0e10cSrcweir //CHINA001 if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) ) 327cdf0e10cSrcweir //CHINA001 { 328cdf0e10cSrcweir //CHINA001 String aMsg( aStrDelMsg.GetToken( 0, '#' ) ); 329cdf0e10cSrcweir //CHINA001 330cdf0e10cSrcweir //CHINA001 aMsg += aLbFormat.GetSelectEntry(); 331cdf0e10cSrcweir //CHINA001 aMsg += aStrDelMsg.GetToken( 1, '#' ); 332cdf0e10cSrcweir //CHINA001 333cdf0e10cSrcweir //CHINA001 if ( RET_YES == 334cdf0e10cSrcweir //CHINA001 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() ) 335cdf0e10cSrcweir //CHINA001 { 336cdf0e10cSrcweir //CHINA001 aLbFormat.RemoveEntry( nIndex ); 337cdf0e10cSrcweir //CHINA001 aLbFormat.SelectEntryPos( nIndex-1 ); 338cdf0e10cSrcweir //CHINA001 339cdf0e10cSrcweir //CHINA001 if ( nIndex-1 == 0 ) 340cdf0e10cSrcweir //CHINA001 aBtnRemove.Disable(); 341cdf0e10cSrcweir //CHINA001 342cdf0e10cSrcweir //CHINA001 if ( !bCoreDataChanged ) 343cdf0e10cSrcweir //CHINA001 { 344cdf0e10cSrcweir //CHINA001 aBtnCancel.SetText( aStrClose ); 345cdf0e10cSrcweir //CHINA001 bCoreDataChanged = sal_True; 346cdf0e10cSrcweir //CHINA001 } 347cdf0e10cSrcweir //CHINA001 348cdf0e10cSrcweir //CHINA001 pFormat->AtFree( nIndex ); // in der Core loeschen 349cdf0e10cSrcweir //CHINA001 nIndex--; 350cdf0e10cSrcweir //CHINA001 351cdf0e10cSrcweir //CHINA001 SelFmtHdl( 0 ); 352cdf0e10cSrcweir //CHINA001 } 353cdf0e10cSrcweir //CHINA001 } 354cdf0e10cSrcweir //CHINA001 355cdf0e10cSrcweir //CHINA001 SelFmtHdl( 0 ); 356cdf0e10cSrcweir //CHINA001 357cdf0e10cSrcweir //CHINA001 return 0; 358cdf0e10cSrcweir //CHINA001 } 359cdf0e10cSrcweir //CHINA001 360cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, pBtn) 361cdf0e10cSrcweir //CHINA001 { 362cdf0e10cSrcweir //CHINA001 sal_Bool bOk = sal_False; 363cdf0e10cSrcweir //CHINA001 while( !bOk ) 364cdf0e10cSrcweir //CHINA001 { 365cdf0e10cSrcweir //CHINA001 366cdf0e10cSrcweir //CHINA001 String aFormatName=aLbFormat.GetSelectEntry(); 367cdf0e10cSrcweir //CHINA001 String aEntry; 368cdf0e10cSrcweir //CHINA001 369cdf0e10cSrcweir //CHINA001 ScStringInputDlg* pDlg = new ScStringInputDlg( this, 370cdf0e10cSrcweir //CHINA001 aStrRename, 371cdf0e10cSrcweir //CHINA001 aStrLabel, 372cdf0e10cSrcweir //CHINA001 aFormatName, 373cdf0e10cSrcweir //CHINA001 HID_SC_RENAME_AUTOFMT ); 374cdf0e10cSrcweir //CHINA001 if( pDlg->Execute() == RET_OK ) 375cdf0e10cSrcweir //CHINA001 { 376cdf0e10cSrcweir //CHINA001 sal_Bool bFmtRenamed = sal_False; 377cdf0e10cSrcweir //CHINA001 pDlg->GetInputString( aFormatName ); 378cdf0e10cSrcweir //CHINA001 sal_uInt16 n; 379cdf0e10cSrcweir //CHINA001 380cdf0e10cSrcweir //CHINA001 if ( aFormatName.Len() > 0 ) 381cdf0e10cSrcweir //CHINA001 { 382cdf0e10cSrcweir //CHINA001 for( n = 0; n < pFormat->GetCount(); ++n ) 383cdf0e10cSrcweir //CHINA001 { 384cdf0e10cSrcweir //CHINA001 (*pFormat)[n]->GetName(aEntry); 385cdf0e10cSrcweir //CHINA001 if ( aEntry== aFormatName) 386cdf0e10cSrcweir //CHINA001 break; 387cdf0e10cSrcweir //CHINA001 } 388cdf0e10cSrcweir //CHINA001 if( n >= pFormat->GetCount() ) 389cdf0e10cSrcweir //CHINA001 { 390cdf0e10cSrcweir //CHINA001 // Format mit dem Namen noch nicht vorhanden, also 391cdf0e10cSrcweir //CHINA001 // umbenennen 392cdf0e10cSrcweir //CHINA001 393cdf0e10cSrcweir //CHINA001 aLbFormat.RemoveEntry(nIndex ); 394cdf0e10cSrcweir //CHINA001 ScAutoFormatData* p=(*pFormat)[ nIndex ]; 395cdf0e10cSrcweir //CHINA001 ScAutoFormatData* pNewData 396cdf0e10cSrcweir //CHINA001 = new ScAutoFormatData(*p); 397cdf0e10cSrcweir //CHINA001 398cdf0e10cSrcweir //CHINA001 pFormat->AtFree( nIndex ); 399cdf0e10cSrcweir //CHINA001 400cdf0e10cSrcweir //CHINA001 pNewData->SetName( aFormatName ); 401cdf0e10cSrcweir //CHINA001 402cdf0e10cSrcweir //CHINA001 pFormat->Insert( pNewData); 403cdf0e10cSrcweir //CHINA001 404cdf0e10cSrcweir //CHINA001 sal_uInt16 nCount = pFormat->GetCount(); 405cdf0e10cSrcweir //CHINA001 406cdf0e10cSrcweir //CHINA001 aLbFormat.SetUpdateMode(sal_False); 407cdf0e10cSrcweir //CHINA001 aLbFormat.Clear(); 408cdf0e10cSrcweir //CHINA001 for ( sal_uInt16 i = 0; i < nCount; i++ ) 409cdf0e10cSrcweir //CHINA001 { 410cdf0e10cSrcweir //CHINA001 ((*pFormat)[i])->GetName( aEntry ); 411cdf0e10cSrcweir //CHINA001 aLbFormat.InsertEntry( aEntry ); 412cdf0e10cSrcweir //CHINA001 } 413cdf0e10cSrcweir //CHINA001 414cdf0e10cSrcweir //CHINA001 aLbFormat.SetUpdateMode( sal_True); 415cdf0e10cSrcweir //CHINA001 aLbFormat.SelectEntry( aFormatName); 416cdf0e10cSrcweir //CHINA001 417cdf0e10cSrcweir //CHINA001 if ( !bCoreDataChanged ) 418cdf0e10cSrcweir //CHINA001 { 419cdf0e10cSrcweir //CHINA001 aBtnCancel.SetText( aStrClose ); 420cdf0e10cSrcweir //CHINA001 bCoreDataChanged = sal_True; 421cdf0e10cSrcweir //CHINA001 } 422cdf0e10cSrcweir //CHINA001 423cdf0e10cSrcweir //CHINA001 424cdf0e10cSrcweir //CHINA001 SelFmtHdl( 0 ); 425cdf0e10cSrcweir //CHINA001 bOk = sal_True; 426cdf0e10cSrcweir //CHINA001 bFmtRenamed = sal_True; 427cdf0e10cSrcweir //CHINA001 } 428cdf0e10cSrcweir //CHINA001 } 429cdf0e10cSrcweir //CHINA001 if( !bFmtRenamed ) 430cdf0e10cSrcweir //CHINA001 { 431cdf0e10cSrcweir //CHINA001 bOk = RET_CANCEL == ErrorBox( this, 432cdf0e10cSrcweir //CHINA001 WinBits( WB_OK_CANCEL | WB_DEF_OK), 433cdf0e10cSrcweir //CHINA001 ScGlobal::GetRscString(STR_INVALID_AFNAME) 434cdf0e10cSrcweir //CHINA001 ).Execute(); 435cdf0e10cSrcweir //CHINA001 } 436cdf0e10cSrcweir //CHINA001 } 437cdf0e10cSrcweir //CHINA001 else 438cdf0e10cSrcweir //CHINA001 bOk = sal_True; 439cdf0e10cSrcweir //CHINA001 delete pDlg; 440cdf0e10cSrcweir //CHINA001 } 441cdf0e10cSrcweir //CHINA001 442cdf0e10cSrcweir //CHINA001 return 0; 443cdf0e10cSrcweir //CHINA001 } 444cdf0e10cSrcweir //CHINA001 445cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 446cdf0e10cSrcweir //CHINA001 447cdf0e10cSrcweir //CHINA001 IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG ) 448cdf0e10cSrcweir //CHINA001 { 449cdf0e10cSrcweir //CHINA001 nIndex = aLbFormat.GetSelectEntryPos(); 450cdf0e10cSrcweir //CHINA001 UpdateChecks(); 451cdf0e10cSrcweir //CHINA001 452cdf0e10cSrcweir //CHINA001 if ( nIndex == 0 ) 453cdf0e10cSrcweir //CHINA001 { 454cdf0e10cSrcweir //CHINA001 aBtnRename.Disable(); 455cdf0e10cSrcweir //CHINA001 aBtnRemove.Disable(); 456cdf0e10cSrcweir //CHINA001 } 457cdf0e10cSrcweir //CHINA001 else 458cdf0e10cSrcweir //CHINA001 { 459cdf0e10cSrcweir //CHINA001 aBtnRename.Enable(); 460cdf0e10cSrcweir //CHINA001 aBtnRemove.Enable(); 461cdf0e10cSrcweir //CHINA001 } 462cdf0e10cSrcweir //CHINA001 463cdf0e10cSrcweir //CHINA001 pWndPreview->NotifyChange( (*pFormat)[nIndex] ); 464cdf0e10cSrcweir //CHINA001 465cdf0e10cSrcweir //CHINA001 return 0; 466cdf0e10cSrcweir //CHINA001 } 467cdf0e10cSrcweir //CHINA001 468cdf0e10cSrcweir //CHINA001 //------------------------------------------------------------------------ 469cdf0e10cSrcweir //CHINA001 470cdf0e10cSrcweir //CHINA001 String ScAutoFormatDlg::GetCurrFormatName() 471cdf0e10cSrcweir //CHINA001 { 472cdf0e10cSrcweir //CHINA001 String aResult; 473cdf0e10cSrcweir //CHINA001 474cdf0e10cSrcweir //CHINA001 ((*pFormat)[nIndex])->GetName( aResult ); 475cdf0e10cSrcweir //CHINA001 476cdf0e10cSrcweir //CHINA001 return aResult; 477cdf0e10cSrcweir //CHINA001 } 478cdf0e10cSrcweir //CHINA001 479cdf0e10cSrcweir //======================================================================== 480cdf0e10cSrcweir // ScAutoFmtPreview 481cdf0e10cSrcweir 482cdf0e10cSrcweir ScAutoFmtPreview::ScAutoFmtPreview( Window* pParent, const ResId& rRes, ScDocument* pDoc ) : 483cdf0e10cSrcweir Window ( pParent, rRes ), 484cdf0e10cSrcweir pCurData ( NULL ), 485cdf0e10cSrcweir aVD ( *this ), 486cdf0e10cSrcweir aScriptedText ( aVD ), 487cdf0e10cSrcweir xBreakIter ( pDoc->GetBreakIterator() ), 488cdf0e10cSrcweir bFitWidth ( sal_False ), 489cdf0e10cSrcweir mbRTL ( false ), 490cdf0e10cSrcweir aPrvSize ( GetSizePixel().Width() - 6, GetSizePixel().Height() - 30 ), 491cdf0e10cSrcweir mnLabelColWidth ( (aPrvSize.Width() - 4) / 4 - 12 ), 492cdf0e10cSrcweir mnDataColWidth1 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 3 ), 493cdf0e10cSrcweir mnDataColWidth2 ( (aPrvSize.Width() - 4 - 2 * mnLabelColWidth) / 4 ), 494cdf0e10cSrcweir mnRowHeight ( (aPrvSize.Height() - 4) / 5 ), 495cdf0e10cSrcweir aStrJan ( ScResId( STR_JAN ) ), 496cdf0e10cSrcweir aStrFeb ( ScResId( STR_FEB ) ), 497cdf0e10cSrcweir aStrMar ( ScResId( STR_MAR ) ), 498cdf0e10cSrcweir aStrNorth ( ScResId( STR_NORTH ) ), 499cdf0e10cSrcweir aStrMid ( ScResId( STR_MID ) ), 500cdf0e10cSrcweir aStrSouth ( ScResId( STR_SOUTH ) ), 501cdf0e10cSrcweir aStrSum ( ScResId( STR_SUM ) ), 502cdf0e10cSrcweir pNumFmt ( new SvNumberFormatter( ::comphelper::getProcessServiceFactory(), ScGlobal::eLnge ) ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir Init(); 505cdf0e10cSrcweir } 506cdf0e10cSrcweir 507cdf0e10cSrcweir //------------------------------------------------------------------------ 508cdf0e10cSrcweir 509cdf0e10cSrcweir ScAutoFmtPreview::~ScAutoFmtPreview() 510cdf0e10cSrcweir { 511cdf0e10cSrcweir delete pNumFmt; 512cdf0e10cSrcweir } 513cdf0e10cSrcweir 514cdf0e10cSrcweir //------------------------------------------------------------------------ 515cdf0e10cSrcweir 516cdf0e10cSrcweir void lcl_SetFontProperties( 517cdf0e10cSrcweir Font& rFont, 518cdf0e10cSrcweir const SvxFontItem& rFontItem, 519cdf0e10cSrcweir const SvxWeightItem& rWeightItem, 520cdf0e10cSrcweir const SvxPostureItem& rPostureItem ) 521cdf0e10cSrcweir { 522cdf0e10cSrcweir rFont.SetFamily ( rFontItem.GetFamily() ); 523cdf0e10cSrcweir rFont.SetName ( rFontItem.GetFamilyName() ); 524cdf0e10cSrcweir rFont.SetStyleName ( rFontItem.GetStyleName() ); 525cdf0e10cSrcweir rFont.SetCharSet ( rFontItem.GetCharSet() ); 526cdf0e10cSrcweir rFont.SetPitch ( rFontItem.GetPitch() ); 527cdf0e10cSrcweir rFont.SetWeight ( (FontWeight)rWeightItem.GetValue() ); 528cdf0e10cSrcweir rFont.SetItalic ( (FontItalic)rPostureItem.GetValue() ); 529cdf0e10cSrcweir } 530cdf0e10cSrcweir 531cdf0e10cSrcweir void ScAutoFmtPreview::MakeFonts( sal_uInt16 nIndex, Font& rFont, Font& rCJKFont, Font& rCTLFont ) 532cdf0e10cSrcweir { 533cdf0e10cSrcweir if ( pCurData ) 534cdf0e10cSrcweir { 535cdf0e10cSrcweir rFont = rCJKFont = rCTLFont = GetFont(); 536cdf0e10cSrcweir Size aFontSize( rFont.GetSize().Width(), 10 ); 537cdf0e10cSrcweir 538cdf0e10cSrcweir const SvxFontItem* pFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_FONT ); 539cdf0e10cSrcweir const SvxWeightItem* pWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_FONT_WEIGHT ); 540cdf0e10cSrcweir const SvxPostureItem* pPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_FONT_POSTURE ); 541cdf0e10cSrcweir const SvxFontItem* pCJKFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT ); 542cdf0e10cSrcweir const SvxWeightItem* pCJKWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_WEIGHT ); 543cdf0e10cSrcweir const SvxPostureItem* pCJKPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CJK_FONT_POSTURE ); 544cdf0e10cSrcweir const SvxFontItem* pCTLFontItem = (const SvxFontItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT ); 545cdf0e10cSrcweir const SvxWeightItem* pCTLWeightItem = (const SvxWeightItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_WEIGHT ); 546cdf0e10cSrcweir const SvxPostureItem* pCTLPostureItem = (const SvxPostureItem*) pCurData->GetItem( nIndex, ATTR_CTL_FONT_POSTURE ); 547cdf0e10cSrcweir const SvxUnderlineItem* pUnderlineItem = (const SvxUnderlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_UNDERLINE ); 548cdf0e10cSrcweir const SvxOverlineItem* pOverlineItem = (const SvxOverlineItem*) pCurData->GetItem( nIndex, ATTR_FONT_OVERLINE ); 549cdf0e10cSrcweir const SvxCrossedOutItem* pCrossedOutItem = (const SvxCrossedOutItem*)pCurData->GetItem( nIndex, ATTR_FONT_CROSSEDOUT ); 550cdf0e10cSrcweir const SvxContourItem* pContourItem = (const SvxContourItem*) pCurData->GetItem( nIndex, ATTR_FONT_CONTOUR ); 551cdf0e10cSrcweir const SvxShadowedItem* pShadowedItem = (const SvxShadowedItem*) pCurData->GetItem( nIndex, ATTR_FONT_SHADOWED ); 552cdf0e10cSrcweir const SvxColorItem* pColorItem = (const SvxColorItem*) pCurData->GetItem( nIndex, ATTR_FONT_COLOR ); 553cdf0e10cSrcweir 554cdf0e10cSrcweir lcl_SetFontProperties( rFont, *pFontItem, *pWeightItem, *pPostureItem ); 555cdf0e10cSrcweir lcl_SetFontProperties( rCJKFont, *pCJKFontItem, *pCJKWeightItem, *pCJKPostureItem ); 556cdf0e10cSrcweir lcl_SetFontProperties( rCTLFont, *pCTLFontItem, *pCTLWeightItem, *pCTLPostureItem ); 557cdf0e10cSrcweir 558cdf0e10cSrcweir Color aColor( pColorItem->GetValue() ); 559cdf0e10cSrcweir if( aColor.GetColor() == COL_TRANSPARENT ) 560cdf0e10cSrcweir aColor = GetSettings().GetStyleSettings().GetWindowTextColor(); 561cdf0e10cSrcweir 562cdf0e10cSrcweir #define SETONALLFONTS( MethodName, Value ) \ 563cdf0e10cSrcweir rFont.MethodName( Value ); rCJKFont.MethodName( Value ); rCTLFont.MethodName( Value ); 564cdf0e10cSrcweir 565cdf0e10cSrcweir SETONALLFONTS( SetUnderline, (FontUnderline)pUnderlineItem->GetValue() ) 566cdf0e10cSrcweir SETONALLFONTS( SetOverline, (FontUnderline)pOverlineItem->GetValue() ) 567cdf0e10cSrcweir SETONALLFONTS( SetStrikeout, (FontStrikeout)pCrossedOutItem->GetValue() ) 568cdf0e10cSrcweir SETONALLFONTS( SetOutline, pContourItem->GetValue() ) 569cdf0e10cSrcweir SETONALLFONTS( SetShadow, pShadowedItem->GetValue() ) 570cdf0e10cSrcweir SETONALLFONTS( SetColor, aColor ) 571cdf0e10cSrcweir SETONALLFONTS( SetSize, aFontSize ) 572cdf0e10cSrcweir SETONALLFONTS( SetTransparent, sal_True ) 573cdf0e10cSrcweir 574cdf0e10cSrcweir #undef SETONALLFONTS 575cdf0e10cSrcweir } 576cdf0e10cSrcweir } 577cdf0e10cSrcweir 578cdf0e10cSrcweir //------------------------------------------------------------------------ 579cdf0e10cSrcweir 580cdf0e10cSrcweir sal_uInt16 ScAutoFmtPreview::GetFormatIndex( size_t nCol, size_t nRow ) const 581cdf0e10cSrcweir { 582cdf0e10cSrcweir static const sal_uInt16 pnFmtMap[] = 583cdf0e10cSrcweir { 584cdf0e10cSrcweir 0, 1, 2, 1, 3, 585cdf0e10cSrcweir 4, 5, 6, 5, 7, 586cdf0e10cSrcweir 8, 9, 10, 9, 11, 587cdf0e10cSrcweir 4, 5, 6, 5, 7, 588cdf0e10cSrcweir 12, 13, 14, 13, 15 589cdf0e10cSrcweir }; 590cdf0e10cSrcweir return pnFmtMap[ maArray.GetCellIndex( nCol, nRow, mbRTL ) ]; 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir const SvxBoxItem& ScAutoFmtPreview::GetBoxItem( size_t nCol, size_t nRow ) const 594cdf0e10cSrcweir { 595cdf0e10cSrcweir DBG_ASSERT( pCurData, "ScAutoFmtPreview::GetBoxItem - no format data found" ); 596cdf0e10cSrcweir return *static_cast< const SvxBoxItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BORDER ) ); 597cdf0e10cSrcweir } 598cdf0e10cSrcweir 599cdf0e10cSrcweir const SvxLineItem& ScAutoFmtPreview::GetDiagItem( size_t nCol, size_t nRow, bool bTLBR ) const 600cdf0e10cSrcweir { 601cdf0e10cSrcweir DBG_ASSERT( pCurData, "ScAutoFmtPreview::GetDiagItem - no format data found" ); 602cdf0e10cSrcweir return *static_cast< const SvxLineItem* >( pCurData->GetItem( GetFormatIndex( nCol, nRow ), bTLBR ? ATTR_BORDER_TLBR : ATTR_BORDER_BLTR ) ); 603cdf0e10cSrcweir } 604cdf0e10cSrcweir 605cdf0e10cSrcweir //------------------------------------------------------------------------ 606cdf0e10cSrcweir 607cdf0e10cSrcweir void ScAutoFmtPreview::DrawString( size_t nCol, size_t nRow ) 608cdf0e10cSrcweir { 609cdf0e10cSrcweir if ( pCurData ) 610cdf0e10cSrcweir { 611cdf0e10cSrcweir //------------------------ 612cdf0e10cSrcweir // Ausgabe des Zelltextes: 613cdf0e10cSrcweir //------------------------ 614cdf0e10cSrcweir 615cdf0e10cSrcweir String cellString; 616cdf0e10cSrcweir sal_Bool bNumFormat = pCurData->GetIncludeValueFormat(); 617cdf0e10cSrcweir sal_uLong nNum; 618cdf0e10cSrcweir double nVal; 619cdf0e10cSrcweir Color* pDummy = NULL; 620cdf0e10cSrcweir sal_uInt16 nIndex = static_cast< sal_uInt16 >( maArray.GetCellIndex( nCol, nRow, mbRTL ) ); 621cdf0e10cSrcweir 622cdf0e10cSrcweir switch( nIndex ) 623cdf0e10cSrcweir { 624cdf0e10cSrcweir case 1: cellString = aStrJan; break; 625cdf0e10cSrcweir case 2: cellString = aStrFeb; break; 626cdf0e10cSrcweir case 3: cellString = aStrMar; break; 627cdf0e10cSrcweir case 5: cellString = aStrNorth; break; 628cdf0e10cSrcweir case 10: cellString = aStrMid; break; 629cdf0e10cSrcweir case 15: cellString = aStrSouth; break; 630cdf0e10cSrcweir case 4: 631cdf0e10cSrcweir case 20: cellString = aStrSum; break; 632cdf0e10cSrcweir 633cdf0e10cSrcweir case 6: 634cdf0e10cSrcweir case 8: 635cdf0e10cSrcweir case 16: 636cdf0e10cSrcweir case 18: nVal = nIndex; 637cdf0e10cSrcweir nNum = 5; 638cdf0e10cSrcweir goto mknum; 639cdf0e10cSrcweir case 17: 640cdf0e10cSrcweir case 7: nVal = nIndex; 641cdf0e10cSrcweir nNum = 6; 642cdf0e10cSrcweir goto mknum; 643cdf0e10cSrcweir case 11: 644cdf0e10cSrcweir case 12: 645cdf0e10cSrcweir case 13: nVal = nIndex; 646cdf0e10cSrcweir nNum = 12 == nIndex ? 10 : 9; 647cdf0e10cSrcweir goto mknum; 648cdf0e10cSrcweir 649cdf0e10cSrcweir case 9: nVal = 21; nNum = 7; goto mknum; 650cdf0e10cSrcweir case 14: nVal = 36; nNum = 11; goto mknum; 651cdf0e10cSrcweir case 19: nVal = 51; nNum = 7; goto mknum; 652cdf0e10cSrcweir case 21: nVal = 33; nNum = 13; goto mknum; 653cdf0e10cSrcweir case 22: nVal = 36; nNum = 14; goto mknum; 654cdf0e10cSrcweir case 23: nVal = 39; nNum = 13; goto mknum; 655cdf0e10cSrcweir case 24: nVal = 108; nNum = 15; 656cdf0e10cSrcweir mknum: 657cdf0e10cSrcweir if( bNumFormat ) 658cdf0e10cSrcweir { 659cdf0e10cSrcweir ScNumFormatAbbrev& rNumFormat = (ScNumFormatAbbrev&)pCurData->GetNumFormat( (sal_uInt16) nNum ); 660cdf0e10cSrcweir nNum = rNumFormat.GetFormatIndex( *pNumFmt ); 661cdf0e10cSrcweir } 662cdf0e10cSrcweir else 663cdf0e10cSrcweir nNum = 0; 664cdf0e10cSrcweir pNumFmt->GetOutputString( nVal, nNum, cellString, &pDummy ); 665cdf0e10cSrcweir break; 666cdf0e10cSrcweir } 667cdf0e10cSrcweir 668cdf0e10cSrcweir if ( cellString.Len() > 0 ) 669cdf0e10cSrcweir { 670cdf0e10cSrcweir Size aStrSize; 671cdf0e10cSrcweir sal_uInt16 nFmtIndex = GetFormatIndex( nCol, nRow ); 672cdf0e10cSrcweir Rectangle cellRect = maArray.GetCellRect( nCol, nRow ); 673cdf0e10cSrcweir Point aPos = cellRect.TopLeft(); 674cdf0e10cSrcweir sal_uInt16 nRightX = 0; 675cdf0e10cSrcweir sal_Bool bJustify = pCurData->GetIncludeJustify(); 676cdf0e10cSrcweir SvxHorJustifyItem aHorJustifyItem( SVX_HOR_JUSTIFY_STANDARD, ATTR_HOR_JUSTIFY ); 677cdf0e10cSrcweir SvxCellHorJustify eJustification; 678cdf0e10cSrcweir 679cdf0e10cSrcweir //------------- 680cdf0e10cSrcweir // Ausrichtung: 681cdf0e10cSrcweir //------------- 682cdf0e10cSrcweir eJustification = mbRTL ? SVX_HOR_JUSTIFY_RIGHT : bJustify ? 683cdf0e10cSrcweir (SvxCellHorJustify)(((const SvxHorJustifyItem*)pCurData->GetItem( nFmtIndex, ATTR_HOR_JUSTIFY ))->GetValue()) : 684cdf0e10cSrcweir SVX_HOR_JUSTIFY_STANDARD; 685cdf0e10cSrcweir 686cdf0e10cSrcweir if ( pCurData->GetIncludeFont() ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir Font aFont, aCJKFont, aCTLFont; 689cdf0e10cSrcweir Size theMaxStrSize; 690cdf0e10cSrcweir 691cdf0e10cSrcweir MakeFonts( nFmtIndex, aFont, aCJKFont, aCTLFont ); 692cdf0e10cSrcweir 693cdf0e10cSrcweir theMaxStrSize = cellRect.GetSize(); 694cdf0e10cSrcweir theMaxStrSize.Width() -= FRAME_OFFSET; 695cdf0e10cSrcweir theMaxStrSize.Height() -= FRAME_OFFSET; 696cdf0e10cSrcweir 697cdf0e10cSrcweir aScriptedText.SetFonts( &aFont, &aCJKFont, &aCTLFont ); 698cdf0e10cSrcweir aScriptedText.SetText( cellString, xBreakIter ); 699cdf0e10cSrcweir aStrSize = aScriptedText.GetTextSize(); 700cdf0e10cSrcweir 701cdf0e10cSrcweir if ( theMaxStrSize.Height() < aStrSize.Height() ) 702cdf0e10cSrcweir { 703cdf0e10cSrcweir // wenn der String in diesem Font nicht 704cdf0e10cSrcweir // in die Zelle passt, wird wieder der 705cdf0e10cSrcweir // Standard-Font genommen: 706cdf0e10cSrcweir aScriptedText.SetDefaultFont(); 707cdf0e10cSrcweir aStrSize = aScriptedText.GetTextSize(); 708cdf0e10cSrcweir } 709cdf0e10cSrcweir while ( ( theMaxStrSize.Width() <= aStrSize.Width() ) 710cdf0e10cSrcweir && ( cellString.Len() > 1 ) ) 711cdf0e10cSrcweir { 712cdf0e10cSrcweir if( eJustification == SVX_HOR_JUSTIFY_RIGHT ) 713cdf0e10cSrcweir cellString.Erase( 0, 1 ); 714cdf0e10cSrcweir else 715cdf0e10cSrcweir cellString.Erase( cellString.Len() - 1 ); 716cdf0e10cSrcweir 717cdf0e10cSrcweir aScriptedText.SetText( cellString, xBreakIter ); 718cdf0e10cSrcweir aStrSize = aScriptedText.GetTextSize(); 719cdf0e10cSrcweir } 720cdf0e10cSrcweir } 721cdf0e10cSrcweir else 722cdf0e10cSrcweir { 723cdf0e10cSrcweir aScriptedText.SetDefaultFont(); 724cdf0e10cSrcweir aScriptedText.SetText( cellString, xBreakIter ); 725cdf0e10cSrcweir aStrSize = aScriptedText.GetTextSize(); 726cdf0e10cSrcweir } 727cdf0e10cSrcweir 728cdf0e10cSrcweir nRightX = (sal_uInt16)( cellRect.GetWidth() 729cdf0e10cSrcweir - aStrSize.Width() 730cdf0e10cSrcweir - FRAME_OFFSET ); 731cdf0e10cSrcweir 732cdf0e10cSrcweir //----------------------------- 733cdf0e10cSrcweir // vertikal (immer zentrieren): 734cdf0e10cSrcweir //----------------------------- 735cdf0e10cSrcweir aPos.Y() += (mnRowHeight - (sal_uInt16)aStrSize.Height()) / 2; 736cdf0e10cSrcweir 737cdf0e10cSrcweir //----------- 738cdf0e10cSrcweir // horizontal 739cdf0e10cSrcweir //----------- 740cdf0e10cSrcweir if ( eJustification != SVX_HOR_JUSTIFY_STANDARD ) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir sal_uInt16 nHorPos = (sal_uInt16) 743cdf0e10cSrcweir ((cellRect.GetWidth()-aStrSize.Width())/2); 744cdf0e10cSrcweir 745cdf0e10cSrcweir switch ( eJustification ) 746cdf0e10cSrcweir { 747cdf0e10cSrcweir case SVX_HOR_JUSTIFY_LEFT: 748cdf0e10cSrcweir aPos.X() += FRAME_OFFSET; 749cdf0e10cSrcweir break; 750cdf0e10cSrcweir case SVX_HOR_JUSTIFY_RIGHT: 751cdf0e10cSrcweir aPos.X() += nRightX; 752cdf0e10cSrcweir break; 753cdf0e10cSrcweir case SVX_HOR_JUSTIFY_BLOCK: 754cdf0e10cSrcweir case SVX_HOR_JUSTIFY_REPEAT: 755cdf0e10cSrcweir case SVX_HOR_JUSTIFY_CENTER: 756cdf0e10cSrcweir aPos.X() += nHorPos; 757cdf0e10cSrcweir break; 758cdf0e10cSrcweir case SVX_HOR_JUSTIFY_STANDARD: 759cdf0e10cSrcweir default: 760cdf0e10cSrcweir // Standard wird hier nicht behandelt 761cdf0e10cSrcweir break; 762cdf0e10cSrcweir } 763cdf0e10cSrcweir } 764cdf0e10cSrcweir else 765cdf0e10cSrcweir { 766cdf0e10cSrcweir //--------------------- 767cdf0e10cSrcweir // Standardausrichtung: 768cdf0e10cSrcweir //--------------------- 769cdf0e10cSrcweir if ( (nCol == 0) || (nRow == 0) ) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir // Text-Label links oder Summe linksbuendig 772cdf0e10cSrcweir aPos.X() += FRAME_OFFSET; 773cdf0e10cSrcweir } 774cdf0e10cSrcweir else 775cdf0e10cSrcweir { 776cdf0e10cSrcweir // Zahlen/Datum rechtsbuendig 777cdf0e10cSrcweir aPos.X() += nRightX; 778cdf0e10cSrcweir } 779cdf0e10cSrcweir } 780cdf0e10cSrcweir 781cdf0e10cSrcweir //------------------------------- 782cdf0e10cSrcweir aScriptedText.DrawText( aPos ); 783cdf0e10cSrcweir //------------------------------- 784cdf0e10cSrcweir } 785cdf0e10cSrcweir } 786cdf0e10cSrcweir } 787cdf0e10cSrcweir 788cdf0e10cSrcweir #undef FRAME_OFFSET 789cdf0e10cSrcweir 790cdf0e10cSrcweir //------------------------------------------------------------------------ 791cdf0e10cSrcweir 792cdf0e10cSrcweir void ScAutoFmtPreview::DrawStrings() 793cdf0e10cSrcweir { 794cdf0e10cSrcweir for( size_t nRow = 0; nRow < 5; ++nRow ) 795cdf0e10cSrcweir for( size_t nCol = 0; nCol < 5; ++nCol ) 796cdf0e10cSrcweir DrawString( nCol, nRow ); 797cdf0e10cSrcweir } 798cdf0e10cSrcweir 799cdf0e10cSrcweir //------------------------------------------------------------------------ 800cdf0e10cSrcweir 801cdf0e10cSrcweir void ScAutoFmtPreview::DrawBackground() 802cdf0e10cSrcweir { 803cdf0e10cSrcweir if( pCurData ) 804cdf0e10cSrcweir { 805cdf0e10cSrcweir for( size_t nRow = 0; nRow < 5; ++nRow ) 806cdf0e10cSrcweir { 807cdf0e10cSrcweir for( size_t nCol = 0; nCol < 5; ++nCol ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir const SvxBrushItem* pItem = static_cast< const SvxBrushItem* >( 810cdf0e10cSrcweir pCurData->GetItem( GetFormatIndex( nCol, nRow ), ATTR_BACKGROUND ) ); 811cdf0e10cSrcweir 812cdf0e10cSrcweir aVD.Push( PUSH_LINECOLOR | PUSH_FILLCOLOR ); 813cdf0e10cSrcweir aVD.SetLineColor(); 814cdf0e10cSrcweir aVD.SetFillColor( pItem->GetColor() ); 815cdf0e10cSrcweir aVD.DrawRect( maArray.GetCellRect( nCol, nRow ) ); 816cdf0e10cSrcweir aVD.Pop(); 817cdf0e10cSrcweir } 818cdf0e10cSrcweir } 819cdf0e10cSrcweir } 820cdf0e10cSrcweir } 821cdf0e10cSrcweir 822cdf0e10cSrcweir //------------------------------------------------------------------------ 823cdf0e10cSrcweir 824cdf0e10cSrcweir void ScAutoFmtPreview::PaintCells() 825cdf0e10cSrcweir { 826cdf0e10cSrcweir if ( pCurData ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir // 1) background 829cdf0e10cSrcweir if ( pCurData->GetIncludeBackground() ) 830cdf0e10cSrcweir DrawBackground(); 831cdf0e10cSrcweir 832cdf0e10cSrcweir // 2) values 833cdf0e10cSrcweir DrawStrings(); 834cdf0e10cSrcweir 835cdf0e10cSrcweir // 3) border 836cdf0e10cSrcweir if ( pCurData->GetIncludeFrame() ) 837cdf0e10cSrcweir maArray.DrawArray( aVD ); 838cdf0e10cSrcweir } 839cdf0e10cSrcweir } 840cdf0e10cSrcweir 841cdf0e10cSrcweir //------------------------------------------------------------------------ 842cdf0e10cSrcweir 843cdf0e10cSrcweir void ScAutoFmtPreview::Init() 844cdf0e10cSrcweir { 845cdf0e10cSrcweir SetBorderStyle( WINDOW_BORDER_MONO ); 846cdf0e10cSrcweir maArray.Initialize( 5, 5 ); 847cdf0e10cSrcweir maArray.SetUseDiagDoubleClipping( false ); 848cdf0e10cSrcweir CalcCellArray( sal_False ); 849cdf0e10cSrcweir CalcLineMap(); 850cdf0e10cSrcweir 851cdf0e10cSrcweir TypeId aType(TYPE(ScDocShell)); 852cdf0e10cSrcweir ScDocShell* pDocShell = (ScDocShell*)SfxObjectShell::GetFirst(&aType); 853cdf0e10cSrcweir SfxViewFrame* pFrame = SfxViewFrame::GetFirst( pDocShell ); 854cdf0e10cSrcweir SfxViewShell* p = pFrame->GetViewShell(); 855cdf0e10cSrcweir ScTabViewShell* pViewSh = dynamic_cast< ScTabViewShell* >( p ); 856cdf0e10cSrcweir ScViewData* pViewData = pViewSh->GetViewData(); 857cdf0e10cSrcweir SCTAB nCurrentTab = pViewData->GetTabNo(); 858cdf0e10cSrcweir ScDocument* pDoc = pViewData->GetDocument(); 859cdf0e10cSrcweir mbRTL = pDoc->IsLayoutRTL( nCurrentTab ); 860cdf0e10cSrcweir } 861cdf0e10cSrcweir 862cdf0e10cSrcweir //------------------------------------------------------------------------ 863cdf0e10cSrcweir 864cdf0e10cSrcweir void ScAutoFmtPreview::CalcCellArray( sal_Bool bFitWidthP ) 865cdf0e10cSrcweir { 866cdf0e10cSrcweir maArray.SetXOffset( 2 ); 867cdf0e10cSrcweir maArray.SetAllColWidths( bFitWidthP ? mnDataColWidth2 : mnDataColWidth1 ); 868cdf0e10cSrcweir maArray.SetColWidth( 0, mnLabelColWidth ); 869cdf0e10cSrcweir maArray.SetColWidth( 4, mnLabelColWidth ); 870cdf0e10cSrcweir 871cdf0e10cSrcweir maArray.SetYOffset( 2 ); 872cdf0e10cSrcweir maArray.SetAllRowHeights( mnRowHeight ); 873cdf0e10cSrcweir 874cdf0e10cSrcweir aPrvSize.Width() = maArray.GetWidth() + 4; 875cdf0e10cSrcweir aPrvSize.Height() = maArray.GetHeight() + 4; 876cdf0e10cSrcweir } 877cdf0e10cSrcweir 878cdf0e10cSrcweir //------------------------------------------------------------------------ 879cdf0e10cSrcweir 880cdf0e10cSrcweir inline void lclSetStyleFromBorder( svx::frame::Style& rStyle, const SvxBorderLine* pBorder ) 881cdf0e10cSrcweir { 882cdf0e10cSrcweir rStyle.Set( pBorder, 1.0 / TWIPS_PER_POINT, 5 ); 883cdf0e10cSrcweir } 884cdf0e10cSrcweir 885cdf0e10cSrcweir void ScAutoFmtPreview::CalcLineMap() 886cdf0e10cSrcweir { 887cdf0e10cSrcweir if ( pCurData ) 888cdf0e10cSrcweir { 889cdf0e10cSrcweir for( size_t nRow = 0; nRow < 5; ++nRow ) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir for( size_t nCol = 0; nCol < 5; ++nCol ) 892cdf0e10cSrcweir { 893cdf0e10cSrcweir svx::frame::Style aStyle; 894cdf0e10cSrcweir 895cdf0e10cSrcweir const SvxBoxItem& rItem = GetBoxItem( nCol, nRow ); 896cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, rItem.GetLeft() ); 897cdf0e10cSrcweir maArray.SetCellStyleLeft( nCol, nRow, aStyle ); 898cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, rItem.GetRight() ); 899cdf0e10cSrcweir maArray.SetCellStyleRight( nCol, nRow, aStyle ); 900cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, rItem.GetTop() ); 901cdf0e10cSrcweir maArray.SetCellStyleTop( nCol, nRow, aStyle ); 902cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, rItem.GetBottom() ); 903cdf0e10cSrcweir maArray.SetCellStyleBottom( nCol, nRow, aStyle ); 904cdf0e10cSrcweir 905cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, true ).GetLine() ); 906cdf0e10cSrcweir maArray.SetCellStyleTLBR( nCol, nRow, aStyle ); 907cdf0e10cSrcweir lclSetStyleFromBorder( aStyle, GetDiagItem( nCol, nRow, false ).GetLine() ); 908cdf0e10cSrcweir maArray.SetCellStyleBLTR( nCol, nRow, aStyle ); 909cdf0e10cSrcweir } 910cdf0e10cSrcweir } 911cdf0e10cSrcweir } 912cdf0e10cSrcweir } 913cdf0e10cSrcweir 914cdf0e10cSrcweir //------------------------------------------------------------------------ 915cdf0e10cSrcweir 916cdf0e10cSrcweir void ScAutoFmtPreview::NotifyChange( ScAutoFormatData* pNewData ) 917cdf0e10cSrcweir { 918cdf0e10cSrcweir if ( pNewData != pCurData ) 919cdf0e10cSrcweir { 920cdf0e10cSrcweir pCurData = pNewData; 921cdf0e10cSrcweir bFitWidth = pNewData->GetIncludeWidthHeight(); 922cdf0e10cSrcweir CalcCellArray( bFitWidth ); 923cdf0e10cSrcweir CalcLineMap(); 924cdf0e10cSrcweir } 925cdf0e10cSrcweir else if ( bFitWidth != pNewData->GetIncludeWidthHeight() ) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir bFitWidth = !bFitWidth; 928cdf0e10cSrcweir CalcCellArray( bFitWidth ); 929cdf0e10cSrcweir } 930cdf0e10cSrcweir 931cdf0e10cSrcweir DoPaint( Rectangle( Point(0,0), GetSizePixel() ) ); 932cdf0e10cSrcweir } 933cdf0e10cSrcweir 934cdf0e10cSrcweir //------------------------------------------------------------------------ 935cdf0e10cSrcweir 936cdf0e10cSrcweir void ScAutoFmtPreview::DoPaint( const Rectangle& /* rRect */ ) 937cdf0e10cSrcweir { 938cdf0e10cSrcweir sal_uInt32 nOldDrawMode = aVD.GetDrawMode(); 939cdf0e10cSrcweir // #105733# SvtAccessibilityOptions::GetIsForBorders is no longer used (always assumed sal_True) 940cdf0e10cSrcweir if( GetSettings().GetStyleSettings().GetHighContrastMode() ) 941cdf0e10cSrcweir aVD.SetDrawMode( DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT ); 942cdf0e10cSrcweir 943cdf0e10cSrcweir Size aWndSize( GetSizePixel() ); 944cdf0e10cSrcweir Font aFont( aVD.GetFont() ); 945cdf0e10cSrcweir Color aBackCol( GetSettings().GetStyleSettings().GetWindowColor() ); 946cdf0e10cSrcweir Point aTmpPoint; 947cdf0e10cSrcweir Rectangle aRect( aTmpPoint, aWndSize ); 948cdf0e10cSrcweir 949cdf0e10cSrcweir aFont.SetTransparent( sal_True ); 950cdf0e10cSrcweir aVD.SetFont( aFont ); 951cdf0e10cSrcweir aVD.SetLineColor(); 952cdf0e10cSrcweir aVD.SetFillColor( aBackCol ); 953cdf0e10cSrcweir aVD.SetOutputSize( aWndSize ); 954cdf0e10cSrcweir aVD.DrawRect( aRect ); 955cdf0e10cSrcweir 956cdf0e10cSrcweir PaintCells(); 957cdf0e10cSrcweir SetLineColor(); 958cdf0e10cSrcweir SetFillColor( aBackCol ); 959cdf0e10cSrcweir DrawRect( aRect ); 960cdf0e10cSrcweir 961cdf0e10cSrcweir Point aPos( (aWndSize.Width() - aPrvSize.Width()) / 2, (aWndSize.Height() - aPrvSize.Height()) / 2 ); 962cdf0e10cSrcweir if (Application::GetSettings().GetLayoutRTL()) 963cdf0e10cSrcweir aPos.X() = -aPos.X(); 964cdf0e10cSrcweir DrawOutDev( aPos, aWndSize, Point(), aWndSize, aVD ); 965cdf0e10cSrcweir 966cdf0e10cSrcweir aVD.SetDrawMode( nOldDrawMode ); 967cdf0e10cSrcweir } 968cdf0e10cSrcweir 969cdf0e10cSrcweir //------------------------------------------------------------------------ 970cdf0e10cSrcweir 971cdf0e10cSrcweir void ScAutoFmtPreview::Paint( const Rectangle& rRect ) 972cdf0e10cSrcweir { 973cdf0e10cSrcweir DoPaint( rRect ); 974cdf0e10cSrcweir } 975cdf0e10cSrcweir 976