update dev300-m58
[ooovba.git] / sc / source / ui / miscdlgs / scuiautofmt.cxx
blobfdfe37f1a3ffc77fbc7a79623cb35b08ddfb354f
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: scuiautofmt.cxx,v $
10 * $Revision: 1.8 $
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"
34 #undef SC_DLLIMPLEMENTATION
38 //------------------------------------------------------------------
40 #include "scitems.hxx"
41 #include <svx/algitem.hxx>
42 #include <svx/boxitem.hxx>
43 #include <svx/brshitem.hxx>
44 #include <svx/cntritem.hxx>
45 #include <svx/colritem.hxx>
46 #include <svx/crsditem.hxx>
47 #include <svx/fontitem.hxx>
48 #include <svx/postitem.hxx>
49 #include <svx/shdditem.hxx>
50 #include <svx/udlnitem.hxx>
51 #include <svx/wghtitem.hxx>
52 #include <svtools/zforlist.hxx>
53 #include <vcl/msgbox.hxx>
54 #include <comphelper/processfactory.hxx>
56 #include "sc.hrc"
57 #include "scmod.hxx"
58 #include "attrib.hxx"
59 #include "zforauto.hxx"
60 #include "scitems.hxx"
61 #include "global.hxx"
62 #include "globstr.hrc"
63 #include "autoform.hxx"
64 #include "strindlg.hxx"
65 #include "miscdlgs.hrc"
66 #include "scuiautofmt.hxx"
67 #include "scresid.hxx"
68 #include "document.hxx"
70 //========================================================================
71 // AutoFormat-Dialog:
73 ScAutoFormatDlg::ScAutoFormatDlg( Window* pParent,
74 ScAutoFormat* pAutoFormat,
75 const ScAutoFormatData* pSelFormatData,
76 ScDocument* pDoc ) :
78 ModalDialog ( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
80 aFlFormat ( this, ScResId( FL_FORMAT ) ),
81 aLbFormat ( this, ScResId( LB_FORMAT ) ),
82 pWndPreview ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
83 aBtnOk ( this, ScResId( BTN_OK ) ),
84 aBtnCancel ( this, ScResId( BTN_CANCEL ) ),
85 aBtnHelp ( this, ScResId( BTN_HELP ) ),
86 aBtnAdd ( this, ScResId( BTN_ADD ) ),
87 aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
88 aBtnMore ( this, ScResId( BTN_MORE ) ),
89 aFlFormatting ( this, ScResId( FL_FORMATTING ) ),
90 aBtnNumFormat ( this, ScResId( BTN_NUMFORMAT ) ),
91 aBtnBorder ( this, ScResId( BTN_BORDER ) ),
92 aBtnFont ( this, ScResId( BTN_FONT ) ),
93 aBtnPattern ( this, ScResId( BTN_PATTERN ) ),
94 aBtnAlignment ( this, ScResId( BTN_ALIGNMENT ) ),
95 aBtnAdjust ( this, ScResId( BTN_ADJUST ) ),
96 aBtnRename ( this, ScResId( BTN_RENAME ) ),
97 aStrTitle ( ScResId( STR_ADD_TITLE ) ),
98 aStrLabel ( ScResId( STR_ADD_LABEL ) ),
99 aStrClose ( ScResId( STR_BTN_CLOSE ) ),
100 aStrDelTitle ( ScResId( STR_DEL_TITLE ) ),
101 aStrDelMsg ( ScResId( STR_DEL_MSG ) ) ,
102 aStrRename ( ScResId( STR_RENAME_TITLE ) ),
104 pFormat ( pAutoFormat ),
105 pSelFmtData ( pSelFormatData ),
106 nIndex ( 0 ),
107 bCoreDataChanged( FALSE ),
108 bFmtInserted ( FALSE )
110 Init();
111 pWndPreview->NotifyChange( (*pFormat)[0] );
112 FreeResource();
115 //------------------------------------------------------------------------
117 __EXPORT ScAutoFormatDlg::~ScAutoFormatDlg()
119 delete pWndPreview;
122 //------------------------------------------------------------------------
124 void ScAutoFormatDlg::Init()
126 USHORT nCount;
127 String aEntry;
129 aLbFormat .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
130 aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
131 aBtnBorder .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
132 aBtnFont .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
133 aBtnPattern .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
134 aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
135 aBtnAdjust .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
136 aBtnAdd .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
137 aBtnRemove .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
138 aBtnOk .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
139 aBtnCancel .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
140 aBtnRename .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
141 aLbFormat .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
143 aBtnMore.AddWindow( &aBtnRename );
144 aBtnMore.AddWindow( &aBtnNumFormat );
145 aBtnMore.AddWindow( &aBtnBorder );
146 aBtnMore.AddWindow( &aBtnFont );
147 aBtnMore.AddWindow( &aBtnPattern );
148 aBtnMore.AddWindow( &aBtnAlignment );
149 aBtnMore.AddWindow( &aBtnAdjust );
150 aBtnMore.AddWindow( &aFlFormatting );
152 nCount = pFormat->GetCount();
154 for ( USHORT i = 0; i < nCount; i++ )
156 ((*pFormat)[i])->GetName( aEntry );
157 aLbFormat.InsertEntry( aEntry );
160 if ( nCount == 1 )
161 aBtnRemove.Disable();
163 aLbFormat.SelectEntryPos( 0 );
164 aBtnRename.Disable();
165 aBtnRemove.Disable();
167 nIndex = 0;
168 UpdateChecks();
170 if ( !pSelFmtData )
172 aBtnAdd.Disable();
173 aBtnRemove.Disable();
174 bFmtInserted = TRUE;
178 //------------------------------------------------------------------------
180 void ScAutoFormatDlg::UpdateChecks()
182 ScAutoFormatData* pData = (*pFormat)[nIndex];
184 aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
185 aBtnBorder .Check( pData->GetIncludeFrame() );
186 aBtnFont .Check( pData->GetIncludeFont() );
187 aBtnPattern .Check( pData->GetIncludeBackground() );
188 aBtnAlignment.Check( pData->GetIncludeJustify() );
189 aBtnAdjust .Check( pData->GetIncludeWidthHeight() );
192 //------------------------------------------------------------------------
193 // Handler:
194 //---------
196 IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
198 if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
200 if ( bCoreDataChanged )
201 ScGlobal::GetAutoFormat()->Save();
203 EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
205 return 0;
208 //------------------------------------------------------------------------
210 IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
212 if ( bCoreDataChanged )
213 ScGlobal::GetAutoFormat()->Save();
215 EndDialog( RET_OK );
216 return 0;
218 IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
220 //------------------------------------------------------------------------
222 IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
224 ScAutoFormatData* pData = (*pFormat)[nIndex];
225 BOOL bCheck = ((CheckBox*)pBtn)->IsChecked();
227 if ( pBtn == &aBtnNumFormat )
228 pData->SetIncludeValueFormat( bCheck );
229 else if ( pBtn == &aBtnBorder )
230 pData->SetIncludeFrame( bCheck );
231 else if ( pBtn == &aBtnFont )
232 pData->SetIncludeFont( bCheck );
233 else if ( pBtn == &aBtnPattern )
234 pData->SetIncludeBackground( bCheck );
235 else if ( pBtn == &aBtnAlignment )
236 pData->SetIncludeJustify( bCheck );
237 else if ( pBtn == &aBtnAdjust )
238 pData->SetIncludeWidthHeight( bCheck );
240 if ( !bCoreDataChanged )
242 aBtnCancel.SetText( aStrClose );
243 bCoreDataChanged = TRUE;
246 pWndPreview->NotifyChange( pData );
248 return 0;
251 //------------------------------------------------------------------------
253 IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
255 if ( !bFmtInserted && pSelFmtData )
257 String aStrStandard( ScResId(STR_STANDARD) );
258 String aFormatName;
259 ScStringInputDlg* pDlg;
260 BOOL bOk = FALSE;
262 while ( !bOk )
264 pDlg = new ScStringInputDlg( this,
265 aStrTitle,
266 aStrLabel,
267 aFormatName,
268 HID_SC_ADD_AUTOFMT );
270 if ( pDlg->Execute() == RET_OK )
272 pDlg->GetInputString( aFormatName );
274 if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) )
276 ScAutoFormatData* pNewData
277 = new ScAutoFormatData( *pSelFmtData );
279 pNewData->SetName( aFormatName );
280 bFmtInserted = pFormat->Insert( pNewData );
282 if ( bFmtInserted )
284 USHORT nAt = pFormat->IndexOf( pNewData );
286 aLbFormat.InsertEntry( aFormatName, nAt );
287 aLbFormat.SelectEntry( aFormatName );
288 aBtnAdd.Disable();
290 if ( !bCoreDataChanged )
292 aBtnCancel.SetText( aStrClose );
293 bCoreDataChanged = TRUE;
296 SelFmtHdl( 0 );
297 bOk = TRUE;
299 else
300 delete pNewData;
304 if ( !bFmtInserted )
306 USHORT nRet = ErrorBox( this,
307 WinBits( WB_OK_CANCEL | WB_DEF_OK),
308 ScGlobal::GetRscString(STR_INVALID_AFNAME)
309 ).Execute();
311 bOk = ( nRet == RET_CANCEL );
314 else
315 bOk = TRUE;
317 delete pDlg;
321 return 0;
324 //------------------------------------------------------------------------
326 IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
328 if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
330 String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
332 aMsg += aLbFormat.GetSelectEntry();
333 aMsg += aStrDelMsg.GetToken( 1, '#' );
335 if ( RET_YES ==
336 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
338 aLbFormat.RemoveEntry( nIndex );
339 aLbFormat.SelectEntryPos( nIndex-1 );
341 if ( nIndex-1 == 0 )
342 aBtnRemove.Disable();
344 if ( !bCoreDataChanged )
346 aBtnCancel.SetText( aStrClose );
347 bCoreDataChanged = TRUE;
350 pFormat->AtFree( nIndex ); // in der Core loeschen
351 nIndex--;
353 SelFmtHdl( 0 );
357 SelFmtHdl( 0 );
359 return 0;
362 IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, EMPTYARG )
364 BOOL bOk = FALSE;
365 while( !bOk )
368 String aFormatName=aLbFormat.GetSelectEntry();
369 String aEntry;
371 ScStringInputDlg* pDlg = new ScStringInputDlg( this,
372 aStrRename,
373 aStrLabel,
374 aFormatName,
375 HID_SC_RENAME_AUTOFMT );
376 if( pDlg->Execute() == RET_OK )
378 BOOL bFmtRenamed = FALSE;
379 pDlg->GetInputString( aFormatName );
380 USHORT n;
382 if ( aFormatName.Len() > 0 )
384 for( n = 0; n < pFormat->GetCount(); ++n )
386 (*pFormat)[n]->GetName(aEntry);
387 if ( aEntry== aFormatName)
388 break;
390 if( n >= pFormat->GetCount() )
392 // Format mit dem Namen noch nicht vorhanden, also
393 // umbenennen
395 aLbFormat.RemoveEntry(nIndex );
396 ScAutoFormatData* p=(*pFormat)[ nIndex ];
397 ScAutoFormatData* pNewData
398 = new ScAutoFormatData(*p);
400 pFormat->AtFree( nIndex );
402 pNewData->SetName( aFormatName );
404 pFormat->Insert( pNewData);
406 USHORT nCount = pFormat->GetCount();
408 aLbFormat.SetUpdateMode(FALSE);
409 aLbFormat.Clear();
410 for ( USHORT i = 0; i < nCount; i++ )
412 ((*pFormat)[i])->GetName( aEntry );
413 aLbFormat.InsertEntry( aEntry );
416 aLbFormat.SetUpdateMode( TRUE);
417 aLbFormat.SelectEntry( aFormatName);
419 if ( !bCoreDataChanged )
421 aBtnCancel.SetText( aStrClose );
422 bCoreDataChanged = TRUE;
426 SelFmtHdl( 0 );
427 bOk = TRUE;
428 bFmtRenamed = TRUE;
431 if( !bFmtRenamed )
433 bOk = RET_CANCEL == ErrorBox( this,
434 WinBits( WB_OK_CANCEL | WB_DEF_OK),
435 ScGlobal::GetRscString(STR_INVALID_AFNAME)
436 ).Execute();
439 else
440 bOk = TRUE;
441 delete pDlg;
444 return 0;
447 //------------------------------------------------------------------------
449 IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
451 nIndex = aLbFormat.GetSelectEntryPos();
452 UpdateChecks();
454 if ( nIndex == 0 )
456 aBtnRename.Disable();
457 aBtnRemove.Disable();
459 else
461 aBtnRename.Enable();
462 aBtnRemove.Enable();
465 pWndPreview->NotifyChange( (*pFormat)[nIndex] );
467 return 0;
470 //------------------------------------------------------------------------
472 String __EXPORT ScAutoFormatDlg::GetCurrFormatName()
474 String aResult;
476 ((*pFormat)[nIndex])->GetName( aResult );
478 return aResult;