1b3f79822SAndrew Rist /**************************************************************
2b3f79822SAndrew Rist  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scui.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //------------------------------------------------------------------
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include "scitems.hxx"
33cdf0e10cSrcweir #include <svx/algitem.hxx>
34cdf0e10cSrcweir #include <editeng/boxitem.hxx>
35cdf0e10cSrcweir #include <editeng/brshitem.hxx>
36cdf0e10cSrcweir #include <editeng/cntritem.hxx>
37cdf0e10cSrcweir #include <editeng/colritem.hxx>
38cdf0e10cSrcweir #include <editeng/crsditem.hxx>
39cdf0e10cSrcweir #include <editeng/fontitem.hxx>
40cdf0e10cSrcweir #include <editeng/postitem.hxx>
41cdf0e10cSrcweir #include <editeng/shdditem.hxx>
42cdf0e10cSrcweir #include <editeng/udlnitem.hxx>
43cdf0e10cSrcweir #include <editeng/wghtitem.hxx>
44cdf0e10cSrcweir #include <svl/zforlist.hxx>
45cdf0e10cSrcweir #include <vcl/msgbox.hxx>
46cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
47cdf0e10cSrcweir #include <sfx2/sfxresid.hxx>
48cdf0e10cSrcweir #include "sc.hrc"
49cdf0e10cSrcweir #include "scmod.hxx"
50cdf0e10cSrcweir #include "attrib.hxx"
51cdf0e10cSrcweir #include "zforauto.hxx"
52cdf0e10cSrcweir #include "scitems.hxx"
53cdf0e10cSrcweir #include "global.hxx"
54cdf0e10cSrcweir #include "globstr.hrc"
55cdf0e10cSrcweir #include "autoform.hxx"
56cdf0e10cSrcweir #include "strindlg.hxx"
57cdf0e10cSrcweir #include "miscdlgs.hrc"
58cdf0e10cSrcweir #include "scuiautofmt.hxx"
59cdf0e10cSrcweir #include "scresid.hxx"
60cdf0e10cSrcweir #include "document.hxx"
61cdf0e10cSrcweir 
62cdf0e10cSrcweir //========================================================================
63cdf0e10cSrcweir // AutoFormat-Dialog:
64cdf0e10cSrcweir 
ScAutoFormatDlg(Window * pParent,ScAutoFormat * pAutoFormat,const ScAutoFormatData * pSelFormatData,ScDocument * pDoc)65cdf0e10cSrcweir ScAutoFormatDlg::ScAutoFormatDlg( Window*					pParent,
66cdf0e10cSrcweir 								  ScAutoFormat* 			pAutoFormat,
67cdf0e10cSrcweir                                   const ScAutoFormatData*   pSelFormatData,
68cdf0e10cSrcweir                                   ScDocument*               pDoc ) :
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	ModalDialog 	( pParent, ScResId( RID_SCDLG_AUTOFORMAT ) ),
71cdf0e10cSrcweir 	//
72cdf0e10cSrcweir     aFlFormat       ( this, ScResId( FL_FORMAT ) ),
73cdf0e10cSrcweir 	aLbFormat		( this, ScResId( LB_FORMAT ) ),
74cdf0e10cSrcweir     pWndPreview     ( new ScAutoFmtPreview( this, ScResId( WND_PREVIEW ), pDoc ) ),
75cdf0e10cSrcweir 	aBtnOk			( this, ScResId( BTN_OK ) ),
76cdf0e10cSrcweir 	aBtnCancel		( this, ScResId( BTN_CANCEL ) ),
77cdf0e10cSrcweir 	aBtnHelp		( this, ScResId( BTN_HELP ) ),
78cdf0e10cSrcweir 	aBtnAdd 		( this, ScResId( BTN_ADD ) ),
79cdf0e10cSrcweir 	aBtnRemove		( this, ScResId( BTN_REMOVE ) ),
80cdf0e10cSrcweir 	aBtnMore		( this, ScResId( BTN_MORE ) ),
81cdf0e10cSrcweir     aFlFormatting   ( this, ScResId( FL_FORMATTING ) ),
82cdf0e10cSrcweir 	aBtnNumFormat	( this, ScResId( BTN_NUMFORMAT ) ),
83cdf0e10cSrcweir 	aBtnBorder		( this, ScResId( BTN_BORDER ) ),
84cdf0e10cSrcweir 	aBtnFont		( this, ScResId( BTN_FONT ) ),
85cdf0e10cSrcweir 	aBtnPattern 	( this, ScResId( BTN_PATTERN ) ),
86cdf0e10cSrcweir 	aBtnAlignment	( this, ScResId( BTN_ALIGNMENT ) ),
87cdf0e10cSrcweir 	aBtnAdjust		( this, ScResId( BTN_ADJUST ) ),
88cdf0e10cSrcweir 	aBtnRename		( this, ScResId( BTN_RENAME ) ),
89cdf0e10cSrcweir     aStrTitle       ( ScResId( STR_ADD_TITLE ) ),
90cdf0e10cSrcweir     aStrLabel       ( ScResId( STR_ADD_LABEL ) ),
91cdf0e10cSrcweir     aStrClose       ( ScResId( STR_BTN_CLOSE ) ),
92cdf0e10cSrcweir     aStrDelTitle    ( ScResId( STR_DEL_TITLE ) ),
93cdf0e10cSrcweir     aStrDelMsg      ( ScResId( STR_DEL_MSG ) ) ,
94cdf0e10cSrcweir     aStrRename      ( ScResId( STR_RENAME_TITLE ) ),
95cdf0e10cSrcweir 	//
96cdf0e10cSrcweir 	pFormat 		( pAutoFormat ),
97cdf0e10cSrcweir 	pSelFmtData 	( pSelFormatData ),
98cdf0e10cSrcweir 	nIndex			( 0 ),
99cdf0e10cSrcweir 	bCoreDataChanged( sal_False ),
100cdf0e10cSrcweir 	bFmtInserted	( sal_False )
101cdf0e10cSrcweir {
102cdf0e10cSrcweir 	Init();
103cdf0e10cSrcweir 	pWndPreview->NotifyChange( (*pFormat)[0] );
104cdf0e10cSrcweir 	FreeResource();
105cdf0e10cSrcweir }
106cdf0e10cSrcweir 
107cdf0e10cSrcweir //------------------------------------------------------------------------
108cdf0e10cSrcweir 
~ScAutoFormatDlg()109cdf0e10cSrcweir __EXPORT ScAutoFormatDlg::~ScAutoFormatDlg()
110cdf0e10cSrcweir {
111cdf0e10cSrcweir 	delete pWndPreview;
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir //------------------------------------------------------------------------
115cdf0e10cSrcweir 
Init()116cdf0e10cSrcweir void ScAutoFormatDlg::Init()
117cdf0e10cSrcweir {
118cdf0e10cSrcweir 	sal_uInt16 nCount;
119cdf0e10cSrcweir 	String aEntry;
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	aLbFormat	 .SetSelectHdl( LINK( this, ScAutoFormatDlg, SelFmtHdl ) );
122cdf0e10cSrcweir 	aBtnNumFormat.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
123cdf0e10cSrcweir 	aBtnBorder	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
124cdf0e10cSrcweir 	aBtnFont	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
125cdf0e10cSrcweir 	aBtnPattern  .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
126cdf0e10cSrcweir 	aBtnAlignment.SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
127cdf0e10cSrcweir 	aBtnAdjust	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, CheckHdl ) );
128cdf0e10cSrcweir 	aBtnAdd 	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, AddHdl ) );
129cdf0e10cSrcweir 	aBtnRemove	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, RemoveHdl ) );
130cdf0e10cSrcweir 	aBtnOk		 .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
131cdf0e10cSrcweir 	aBtnCancel	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, CloseHdl ) );
132cdf0e10cSrcweir 	aBtnRename	 .SetClickHdl ( LINK( this, ScAutoFormatDlg, RenameHdl ) );
133cdf0e10cSrcweir 	aLbFormat	 .SetDoubleClickHdl( LINK( this, ScAutoFormatDlg, DblClkHdl ) );
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnRename );
136cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnNumFormat );
137cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnBorder );
138cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnFont );
139cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnPattern );
140cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnAlignment );
141cdf0e10cSrcweir 	aBtnMore.AddWindow( &aBtnAdjust );
142cdf0e10cSrcweir     aBtnMore.AddWindow( &aFlFormatting );
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 	nCount = pFormat->GetCount();
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	for ( sal_uInt16 i = 0; i < nCount; i++ )
147cdf0e10cSrcweir 	{
148cdf0e10cSrcweir 		((*pFormat)[i])->GetName( aEntry );
149cdf0e10cSrcweir 		aLbFormat.InsertEntry( aEntry );
150cdf0e10cSrcweir 	}
151cdf0e10cSrcweir 
152cdf0e10cSrcweir 	if ( nCount == 1 )
153cdf0e10cSrcweir 		aBtnRemove.Disable();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 	aLbFormat.SelectEntryPos( 0 );
156cdf0e10cSrcweir 	aBtnRename.Disable();
157cdf0e10cSrcweir 	aBtnRemove.Disable();
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 	nIndex = 0;
160cdf0e10cSrcweir 	UpdateChecks();
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 	if ( !pSelFmtData )
163cdf0e10cSrcweir 	{
164cdf0e10cSrcweir 		aBtnAdd.Disable();
165cdf0e10cSrcweir 		aBtnRemove.Disable();
166cdf0e10cSrcweir 		bFmtInserted = sal_True;
167cdf0e10cSrcweir 	}
168cdf0e10cSrcweir }
169cdf0e10cSrcweir 
170cdf0e10cSrcweir //------------------------------------------------------------------------
171cdf0e10cSrcweir 
UpdateChecks()172cdf0e10cSrcweir void ScAutoFormatDlg::UpdateChecks()
173cdf0e10cSrcweir {
174cdf0e10cSrcweir 	ScAutoFormatData* pData = (*pFormat)[nIndex];
175cdf0e10cSrcweir 
176cdf0e10cSrcweir 	aBtnNumFormat.Check( pData->GetIncludeValueFormat() );
177cdf0e10cSrcweir 	aBtnBorder	 .Check( pData->GetIncludeFrame() );
178cdf0e10cSrcweir 	aBtnFont	 .Check( pData->GetIncludeFont() );
179cdf0e10cSrcweir 	aBtnPattern  .Check( pData->GetIncludeBackground() );
180cdf0e10cSrcweir 	aBtnAlignment.Check( pData->GetIncludeJustify() );
181cdf0e10cSrcweir 	aBtnAdjust	 .Check( pData->GetIncludeWidthHeight() );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir 
184cdf0e10cSrcweir //------------------------------------------------------------------------
185cdf0e10cSrcweir // Handler:
186cdf0e10cSrcweir //---------
187cdf0e10cSrcweir 
IMPL_LINK(ScAutoFormatDlg,CloseHdl,PushButton *,pBtn)188cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, CloseHdl, PushButton *, pBtn )
189cdf0e10cSrcweir {
190cdf0e10cSrcweir 	if ( pBtn == &aBtnOk || pBtn == &aBtnCancel )
191cdf0e10cSrcweir 	{
192cdf0e10cSrcweir 		if ( bCoreDataChanged )
193cdf0e10cSrcweir 			ScGlobal::GetAutoFormat()->Save();
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 		EndDialog( (pBtn == &aBtnOk) ? RET_OK : RET_CANCEL );
196cdf0e10cSrcweir 	}
197cdf0e10cSrcweir 	return 0;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //------------------------------------------------------------------------
201cdf0e10cSrcweir 
IMPL_LINK_INLINE_START(ScAutoFormatDlg,DblClkHdl,void *,EMPTYARG)202cdf0e10cSrcweir IMPL_LINK_INLINE_START( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	if ( bCoreDataChanged )
205cdf0e10cSrcweir 		ScGlobal::GetAutoFormat()->Save();
206cdf0e10cSrcweir 
207cdf0e10cSrcweir 	EndDialog( RET_OK );
208cdf0e10cSrcweir 	return 0;
209cdf0e10cSrcweir }
IMPL_LINK_INLINE_END(ScAutoFormatDlg,DblClkHdl,void *,EMPTYARG)210cdf0e10cSrcweir IMPL_LINK_INLINE_END( ScAutoFormatDlg, DblClkHdl, void *, EMPTYARG )
211cdf0e10cSrcweir 
212cdf0e10cSrcweir //------------------------------------------------------------------------
213cdf0e10cSrcweir 
214cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, CheckHdl, Button *, pBtn )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir 	ScAutoFormatData* pData  = (*pFormat)[nIndex];
217cdf0e10cSrcweir 	sal_Bool			  bCheck = ((CheckBox*)pBtn)->IsChecked();
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 	if ( pBtn == &aBtnNumFormat )
220cdf0e10cSrcweir 		pData->SetIncludeValueFormat( bCheck );
221cdf0e10cSrcweir 	else if ( pBtn == &aBtnBorder )
222cdf0e10cSrcweir 		pData->SetIncludeFrame( bCheck );
223cdf0e10cSrcweir 	else if ( pBtn == &aBtnFont )
224cdf0e10cSrcweir 		pData->SetIncludeFont( bCheck );
225cdf0e10cSrcweir 	else if ( pBtn == &aBtnPattern )
226cdf0e10cSrcweir 		pData->SetIncludeBackground( bCheck );
227cdf0e10cSrcweir 	else if ( pBtn == &aBtnAlignment )
228cdf0e10cSrcweir 		pData->SetIncludeJustify( bCheck );
229cdf0e10cSrcweir 	else if ( pBtn == &aBtnAdjust )
230cdf0e10cSrcweir 		pData->SetIncludeWidthHeight( bCheck );
231cdf0e10cSrcweir 
232cdf0e10cSrcweir 	if ( !bCoreDataChanged )
233cdf0e10cSrcweir 	{
234cdf0e10cSrcweir 		aBtnCancel.SetText( aStrClose );
235cdf0e10cSrcweir 		bCoreDataChanged = sal_True;
236cdf0e10cSrcweir 	}
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	pWndPreview->NotifyChange( pData );
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 	return 0;
241cdf0e10cSrcweir }
242cdf0e10cSrcweir 
243cdf0e10cSrcweir //------------------------------------------------------------------------
244cdf0e10cSrcweir 
IMPL_LINK(ScAutoFormatDlg,AddHdl,void *,EMPTYARG)245cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, AddHdl, void *, EMPTYARG )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir 	if ( !bFmtInserted && pSelFmtData )
248cdf0e10cSrcweir 	{
249cdf0e10cSrcweir 		String				aStrStandard( SfxResId(STR_STANDARD) );
250cdf0e10cSrcweir 		String				aFormatName;
251cdf0e10cSrcweir 		ScStringInputDlg*	pDlg;
252cdf0e10cSrcweir 		sal_Bool				bOk = sal_False;
253cdf0e10cSrcweir 
254cdf0e10cSrcweir 		while ( !bOk )
255cdf0e10cSrcweir 		{
256cdf0e10cSrcweir 			pDlg = new ScStringInputDlg( this,
257cdf0e10cSrcweir 										 aStrTitle,
258cdf0e10cSrcweir 										 aStrLabel,
259cdf0e10cSrcweir 										 aFormatName,
260cdf0e10cSrcweir 										 HID_SC_ADD_AUTOFMT, HID_SC_AUTOFMT_NAME );
261cdf0e10cSrcweir 
262cdf0e10cSrcweir 			if ( pDlg->Execute() == RET_OK )
263cdf0e10cSrcweir 			{
264cdf0e10cSrcweir 				pDlg->GetInputString( aFormatName );
265cdf0e10cSrcweir 
266cdf0e10cSrcweir 				if ( (aFormatName.Len() > 0) && (aFormatName != aStrStandard) )
267cdf0e10cSrcweir 				{
268cdf0e10cSrcweir 					ScAutoFormatData* pNewData
269cdf0e10cSrcweir 						= new ScAutoFormatData( *pSelFmtData );
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 					pNewData->SetName( aFormatName );
272cdf0e10cSrcweir 					bFmtInserted = pFormat->Insert( pNewData );
273cdf0e10cSrcweir 
274cdf0e10cSrcweir 					if ( bFmtInserted )
275cdf0e10cSrcweir 					{
276cdf0e10cSrcweir 						sal_uInt16 nAt = pFormat->IndexOf( pNewData );
277cdf0e10cSrcweir 
278cdf0e10cSrcweir 						aLbFormat.InsertEntry( aFormatName, nAt );
279cdf0e10cSrcweir 						aLbFormat.SelectEntry( aFormatName );
280cdf0e10cSrcweir 						aBtnAdd.Disable();
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 						if ( !bCoreDataChanged )
283cdf0e10cSrcweir 						{
284cdf0e10cSrcweir 							aBtnCancel.SetText( aStrClose );
285cdf0e10cSrcweir 							bCoreDataChanged = sal_True;
286cdf0e10cSrcweir 						}
287cdf0e10cSrcweir 
288cdf0e10cSrcweir 						SelFmtHdl( 0 );
289cdf0e10cSrcweir 						bOk = sal_True;
290cdf0e10cSrcweir 					}
291cdf0e10cSrcweir 					else
292cdf0e10cSrcweir 						delete pNewData;
293cdf0e10cSrcweir 
294cdf0e10cSrcweir 				}
295cdf0e10cSrcweir 
296cdf0e10cSrcweir 				if ( !bFmtInserted )
297cdf0e10cSrcweir 				{
298cdf0e10cSrcweir 					sal_uInt16 nRet = ErrorBox( this,
299cdf0e10cSrcweir 											WinBits( WB_OK_CANCEL | WB_DEF_OK),
300cdf0e10cSrcweir 											ScGlobal::GetRscString(STR_INVALID_AFNAME)
301cdf0e10cSrcweir 										  ).Execute();
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 					bOk = ( nRet == RET_CANCEL );
304cdf0e10cSrcweir 				}
305cdf0e10cSrcweir 			}
306cdf0e10cSrcweir 			else
307cdf0e10cSrcweir 				bOk = sal_True;
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 			delete pDlg;
310cdf0e10cSrcweir 		}
311cdf0e10cSrcweir 	}
312cdf0e10cSrcweir 
313cdf0e10cSrcweir 	return 0;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir 
316cdf0e10cSrcweir //------------------------------------------------------------------------
317cdf0e10cSrcweir 
IMPL_LINK(ScAutoFormatDlg,RemoveHdl,void *,EMPTYARG)318cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, RemoveHdl, void *, EMPTYARG )
319cdf0e10cSrcweir {
320cdf0e10cSrcweir 	if ( (nIndex > 0) && (aLbFormat.GetEntryCount() > 0) )
321cdf0e10cSrcweir 	{
322cdf0e10cSrcweir 		String aMsg( aStrDelMsg.GetToken( 0, '#' ) );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir 		aMsg += aLbFormat.GetSelectEntry();
325cdf0e10cSrcweir 		aMsg += aStrDelMsg.GetToken( 1, '#' );
326cdf0e10cSrcweir 
327cdf0e10cSrcweir 		if ( RET_YES ==
328cdf0e10cSrcweir 			 QueryBox( this, WinBits( WB_YES_NO | WB_DEF_YES ), aMsg ).Execute() )
329cdf0e10cSrcweir 		{
330cdf0e10cSrcweir 			aLbFormat.RemoveEntry( nIndex );
331cdf0e10cSrcweir 			aLbFormat.SelectEntryPos( nIndex-1 );
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 			if ( nIndex-1 == 0 )
334cdf0e10cSrcweir 				aBtnRemove.Disable();
335cdf0e10cSrcweir 
336cdf0e10cSrcweir 			if ( !bCoreDataChanged )
337cdf0e10cSrcweir 			{
338cdf0e10cSrcweir 				aBtnCancel.SetText( aStrClose );
339cdf0e10cSrcweir 				bCoreDataChanged = sal_True;
340cdf0e10cSrcweir 			}
341cdf0e10cSrcweir 
342cdf0e10cSrcweir 			pFormat->AtFree( nIndex ); // in der Core loeschen
343cdf0e10cSrcweir 			nIndex--;
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 			SelFmtHdl( 0 );
346cdf0e10cSrcweir 		}
347cdf0e10cSrcweir 	}
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 	SelFmtHdl( 0 );
350cdf0e10cSrcweir 
351cdf0e10cSrcweir 	return 0;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir 
IMPL_LINK(ScAutoFormatDlg,RenameHdl,void *,EMPTYARG)354cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, RenameHdl, void *, EMPTYARG )
355cdf0e10cSrcweir {
356cdf0e10cSrcweir 	sal_Bool bOk = sal_False;
357cdf0e10cSrcweir 	while( !bOk )
358cdf0e10cSrcweir 	{
359cdf0e10cSrcweir 
360cdf0e10cSrcweir 		String aFormatName=aLbFormat.GetSelectEntry();
361cdf0e10cSrcweir 		String aEntry;
362cdf0e10cSrcweir 
363cdf0e10cSrcweir 		ScStringInputDlg* pDlg = new ScStringInputDlg( this,
364cdf0e10cSrcweir 										 aStrRename,
365cdf0e10cSrcweir 										 aStrLabel,
366cdf0e10cSrcweir 										 aFormatName,
367cdf0e10cSrcweir                                          HID_SC_REN_AFMT_DLG, HID_SC_REN_AFMT_NAME );
368cdf0e10cSrcweir 		if( pDlg->Execute() == RET_OK )
369cdf0e10cSrcweir 		{
370cdf0e10cSrcweir 			sal_Bool bFmtRenamed = sal_False;
371cdf0e10cSrcweir 			pDlg->GetInputString( aFormatName );
372cdf0e10cSrcweir 			sal_uInt16 n;
373cdf0e10cSrcweir 
374cdf0e10cSrcweir 			if ( aFormatName.Len() > 0 )
375cdf0e10cSrcweir 			{
376cdf0e10cSrcweir 				for( n = 0; n < pFormat->GetCount(); ++n )
377cdf0e10cSrcweir 				{
378cdf0e10cSrcweir 					(*pFormat)[n]->GetName(aEntry);
379cdf0e10cSrcweir 					if ( aEntry== aFormatName)
380cdf0e10cSrcweir 						break;
381cdf0e10cSrcweir 				}
382cdf0e10cSrcweir 				if( n >= pFormat->GetCount() )
383cdf0e10cSrcweir 				{
384cdf0e10cSrcweir 					// Format mit dem Namen noch nicht vorhanden, also
385cdf0e10cSrcweir 					// umbenennen
386cdf0e10cSrcweir 
387cdf0e10cSrcweir 					aLbFormat.RemoveEntry(nIndex );
388cdf0e10cSrcweir 					ScAutoFormatData* p=(*pFormat)[ nIndex ];
389cdf0e10cSrcweir 					ScAutoFormatData* pNewData
390cdf0e10cSrcweir 						= new ScAutoFormatData(*p);
391cdf0e10cSrcweir 
392cdf0e10cSrcweir 					pFormat->AtFree( nIndex );
393cdf0e10cSrcweir 
394cdf0e10cSrcweir 					pNewData->SetName( aFormatName );
395cdf0e10cSrcweir 
396cdf0e10cSrcweir 					pFormat->Insert( pNewData);
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 					sal_uInt16 nCount = pFormat->GetCount();
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 					aLbFormat.SetUpdateMode(sal_False);
401cdf0e10cSrcweir 					aLbFormat.Clear();
402cdf0e10cSrcweir 					for ( sal_uInt16 i = 0; i < nCount; i++ )
403cdf0e10cSrcweir 					{
404cdf0e10cSrcweir 						((*pFormat)[i])->GetName( aEntry );
405cdf0e10cSrcweir 						aLbFormat.InsertEntry( aEntry );
406cdf0e10cSrcweir 					}
407cdf0e10cSrcweir 
408cdf0e10cSrcweir 					aLbFormat.SetUpdateMode( sal_True);
409cdf0e10cSrcweir 					aLbFormat.SelectEntry( aFormatName);
410cdf0e10cSrcweir 
411cdf0e10cSrcweir 					if ( !bCoreDataChanged )
412cdf0e10cSrcweir 					{
413cdf0e10cSrcweir 						aBtnCancel.SetText( aStrClose );
414cdf0e10cSrcweir 						bCoreDataChanged = sal_True;
415cdf0e10cSrcweir 					}
416cdf0e10cSrcweir 
417cdf0e10cSrcweir 
418cdf0e10cSrcweir 					SelFmtHdl( 0 );
419cdf0e10cSrcweir 					bOk = sal_True;
420cdf0e10cSrcweir 					bFmtRenamed = sal_True;
421cdf0e10cSrcweir 				}
422cdf0e10cSrcweir 			}
423cdf0e10cSrcweir 			if( !bFmtRenamed )
424cdf0e10cSrcweir 			{
425cdf0e10cSrcweir 				bOk = RET_CANCEL == ErrorBox( this,
426cdf0e10cSrcweir 									WinBits( WB_OK_CANCEL | WB_DEF_OK),
427cdf0e10cSrcweir 									ScGlobal::GetRscString(STR_INVALID_AFNAME)
428cdf0e10cSrcweir 									).Execute();
429cdf0e10cSrcweir 			}
430cdf0e10cSrcweir 		}
431cdf0e10cSrcweir 		else
432cdf0e10cSrcweir 			bOk = sal_True;
433cdf0e10cSrcweir 		delete pDlg;
434cdf0e10cSrcweir 	}
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 	return 0;
437cdf0e10cSrcweir }
438cdf0e10cSrcweir 
439cdf0e10cSrcweir //------------------------------------------------------------------------
440cdf0e10cSrcweir 
IMPL_LINK(ScAutoFormatDlg,SelFmtHdl,void *,EMPTYARG)441cdf0e10cSrcweir IMPL_LINK( ScAutoFormatDlg, SelFmtHdl, void *, EMPTYARG )
442cdf0e10cSrcweir {
443cdf0e10cSrcweir 	nIndex = aLbFormat.GetSelectEntryPos();
444cdf0e10cSrcweir 	UpdateChecks();
445cdf0e10cSrcweir 
446cdf0e10cSrcweir 	if ( nIndex == 0 )
447cdf0e10cSrcweir 	{
448cdf0e10cSrcweir 		aBtnRename.Disable();
449cdf0e10cSrcweir 		aBtnRemove.Disable();
450cdf0e10cSrcweir 	}
451cdf0e10cSrcweir 	else
452cdf0e10cSrcweir 	{
453cdf0e10cSrcweir 		aBtnRename.Enable();
454cdf0e10cSrcweir 		aBtnRemove.Enable();
455cdf0e10cSrcweir 	}
456cdf0e10cSrcweir 
457cdf0e10cSrcweir 	pWndPreview->NotifyChange( (*pFormat)[nIndex] );
458cdf0e10cSrcweir 
459cdf0e10cSrcweir 	return 0;
460cdf0e10cSrcweir }
461cdf0e10cSrcweir 
462cdf0e10cSrcweir //------------------------------------------------------------------------
463cdf0e10cSrcweir 
GetCurrFormatName()464cdf0e10cSrcweir String __EXPORT ScAutoFormatDlg::GetCurrFormatName()
465cdf0e10cSrcweir {
466cdf0e10cSrcweir 	String	aResult;
467cdf0e10cSrcweir 
468cdf0e10cSrcweir 	((*pFormat)[nIndex])->GetName( aResult );
469cdf0e10cSrcweir 
470cdf0e10cSrcweir 	return aResult;
471cdf0e10cSrcweir }
472