xref: /trunk/main/sc/source/ui/optdlg/tpusrlst.cxx (revision a479921a)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_scui.hxx"
26 
27 
28 
29 
30 //------------------------------------------------------------------
31 
32 #include <vcl/msgbox.hxx>
33 
34 #include "global.hxx"
35 #include "document.hxx"
36 #include "tabvwsh.hxx"
37 #include "viewdata.hxx"
38 #include "uiitems.hxx"
39 #include "userlist.hxx"
40 #include "rangeutl.hxx"
41 #include "crdlg.hxx"
42 #include "scresid.hxx"
43 #include "sc.hrc"       // -> Slot-IDs
44 #include "optdlg.hrc"
45 #include "globstr.hrc"
46 
47 #define _TPUSRLST_CXX
48 #include "tpusrlst.hxx"
49 #undef _TPUSRLST_CXX
50 
51 //CHINA001 #include "scui_def.hxx" //CHINA001
52 //CHINA001 #include "scresid.hxx" //add by CHINA001
53 //CHINA001 #include "miscdlgs.hrc"  //add by CHINA001
54 //CHINA001
55 //CHINA001 #include "scabstdlg.hxx" //CHINA001
56 // STATIC DATA -----------------------------------------------------------
57 
58 #define CR	(sal_Unicode)13
59 #define LF	(sal_Unicode)10
60 
61 static sal_uInt16 pUserListsRanges[] =
62 {
63 	SID_SCUSERLISTS,
64 	SID_SCUSERLISTS,
65 	0
66 };
67 
68 static const sal_Unicode cDelimiter = ',';
69 
70 
71 //========================================================================
72 // Benutzerdefinierte Listen:
73 
74 
ScTpUserLists(Window * pParent,const SfxItemSet & rCoreAttrs)75 ScTpUserLists::ScTpUserLists( Window*				pParent,
76 							  const SfxItemSet& 	rCoreAttrs )
77 
78 	:	SfxTabPage		( pParent,
79 						  ScResId( RID_SCPAGE_USERLISTS ),
80 						  rCoreAttrs ),
81 		aFtLists		( this, ScResId( FT_LISTS ) ),
82 		aLbLists		( this, ScResId( LB_LISTS ) ),
83 		aFtEntries		( this, ScResId( FT_ENTRIES ) ),
84 		aEdEntries		( this, ScResId( ED_ENTRIES ) ),
85 		aFtCopyFrom 	( this, ScResId( FT_COPYFROM ) ),
86 		aEdCopyFrom 	( this, ScResId( ED_COPYFROM ) ),
87 		aBtnNew 		( this, ScResId( BTN_NEW ) ),
88 		aBtnAdd 		( this, ScResId( BTN_ADD ) ),
89 		aBtnRemove		( this, ScResId( BTN_REMOVE ) ),
90 		aBtnCopy		( this, ScResId( BTN_COPY ) ),
91 		aStrQueryRemove ( ScResId( STR_QUERYREMOVE ) ),
92 		aStrNew 		( aBtnNew.GetText() ),
93 		aStrCancel		( ScResId( STR_DISMISS ) ),
94 		aStrAdd 		( ScResId( SCSTR_ADD ) ),
95 		aStrModify		( ScResId( SCSTR_MODIFY ) ),
96 		aStrCopyList	( ScResId( STR_COPYLIST ) ),
97 		aStrCopyFrom	( ScResId( STR_COPYFROM ) ),
98 		aStrCopyErr		( ScResId( STR_COPYERR ) ),
99 		//
100 		nWhichUserLists ( GetWhich( SID_SCUSERLISTS ) ),
101 		pUserLists		( NULL ),
102 		pDoc			( NULL ),
103 		pViewData		( NULL ),
104 		pRangeUtil		( new ScRangeUtil ),
105 		bModifyMode 	( sal_False ),
106 		bCancelMode 	( sal_False ),
107 		bCopyDone		( sal_False ),
108 		nCancelPos		( 0 )
109 {
110 	SetExchangeSupport();
111 	Init();
112 	FreeResource();
113 }
114 
115 // -----------------------------------------------------------------------
116 
~ScTpUserLists()117 __EXPORT ScTpUserLists::~ScTpUserLists()
118 {
119 	delete pUserLists;
120 	delete pRangeUtil;
121 }
122 
123 // -----------------------------------------------------------------------
124 
Init()125 void ScTpUserLists::Init()
126 {
127 	SfxViewShell*	pSh = SfxViewShell::Current();
128 	ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, pSh);
129 
130 	aLbLists.SetSelectHdl	( LINK( this, ScTpUserLists, LbSelectHdl ) );
131 	aBtnNew.SetClickHdl		( LINK( this, ScTpUserLists, BtnClickHdl ) );
132 	aBtnNew.SetClickHdl		( LINK( this, ScTpUserLists, BtnClickHdl ) );
133 	aBtnAdd.SetClickHdl		( LINK( this, ScTpUserLists, BtnClickHdl ) );
134 	aBtnRemove.SetClickHdl	( LINK( this, ScTpUserLists, BtnClickHdl ) );
135 	aEdEntries.SetModifyHdl	( LINK( this, ScTpUserLists, EdEntriesModHdl ) );
136 
137 
138 	if ( pViewSh )
139 	{
140 		SCTAB	nStartTab	= 0;
141 		SCTAB	nEndTab 	= 0;
142 		SCCOL	nStartCol	= 0;
143 		SCROW	nStartRow	= 0;
144 		SCCOL	nEndCol 	= 0;
145 		SCROW	nEndRow 	= 0;
146 
147 		pViewData = pViewSh->GetViewData();
148 		pDoc = pViewData->GetDocument();
149 
150 		pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
151 								  nEndCol,	 nEndRow,  nEndTab );
152 
153 		PutInOrder( nStartCol, nEndCol );
154 		PutInOrder( nStartRow, nEndRow );
155 		PutInOrder( nStartTab, nEndTab );
156 
157         ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab
158                 ).Format( aStrSelectedArea, SCR_ABS_3D, pDoc );
159 
160 		aBtnCopy.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
161 		aBtnCopy.Enable();
162 	}
163 	else
164 	{
165 		aBtnCopy.Disable();
166 		aFtCopyFrom.Disable();
167 		aEdCopyFrom.Disable();
168 	}
169 
170 //	aLbLists.GrabFocus();
171 }
172 
173 // -----------------------------------------------------------------------
174 
GetRanges()175 sal_uInt16* __EXPORT ScTpUserLists::GetRanges()
176 {
177 	return pUserListsRanges;
178 }
179 
180 // -----------------------------------------------------------------------
181 
Create(Window * pParent,const SfxItemSet & rAttrSet)182 SfxTabPage* __EXPORT ScTpUserLists::Create( Window* pParent, const SfxItemSet& rAttrSet )
183 {
184 	return ( new ScTpUserLists( pParent, rAttrSet ) );
185 }
186 
187 // -----------------------------------------------------------------------
188 
Reset(const SfxItemSet & rCoreAttrs)189 void __EXPORT ScTpUserLists::Reset( const SfxItemSet& rCoreAttrs )
190 {
191 	const ScUserListItem& rUserListItem = (const ScUserListItem&)
192 										   rCoreAttrs.Get( nWhichUserLists );
193 	const ScUserList*	  pCoreList 	= rUserListItem.GetUserList();
194 
195 	DBG_ASSERT( pCoreList, "UserList not found :-/" );
196 
197 	if ( pCoreList )
198 	{
199 		if ( !pUserLists )
200 			pUserLists = new ScUserList( *pCoreList );
201 		else
202 			*pUserLists = *pCoreList;
203 
204 		if ( UpdateUserListBox() > 0 )
205 		{
206 			aLbLists.SelectEntryPos( 0 );
207 			UpdateEntries( 0 );
208 		}
209 	}
210 	else if ( !pUserLists )
211 		pUserLists = new ScUserList;
212 
213 	aEdCopyFrom.SetText( aStrSelectedArea );
214 
215 	if ( aLbLists.GetEntryCount() == 0 )
216 	{
217 		aFtLists	.Disable();
218 		aLbLists	.Disable();
219 		aFtEntries	.Disable();
220 		aEdEntries	.Disable();
221 		aBtnRemove	.Disable();
222 	}
223 
224 	aBtnNew.SetText( aStrNew );
225 	aBtnAdd.SetText( aStrAdd );
226 	aBtnAdd.Disable();
227 
228 	if ( !bCopyDone && pViewData )
229 	{
230 		aFtCopyFrom .Enable();
231 		aEdCopyFrom .Enable();
232 		aBtnCopy	.Enable();
233 	}
234 
235 //	aLbLists.GrabFocus();
236 }
237 
238 // -----------------------------------------------------------------------
239 
FillItemSet(SfxItemSet & rCoreAttrs)240 sal_Bool __EXPORT ScTpUserLists::FillItemSet( SfxItemSet& rCoreAttrs )
241 {
242 	// Modifikationen noch nicht uebernommen?
243 	// -> Click auf Add-Button simulieren
244 
245 	if ( bModifyMode || bCancelMode )
246 		BtnClickHdl( &aBtnAdd );
247 
248 	const ScUserListItem& rUserListItem = (const ScUserListItem&)
249 										   GetItemSet().Get( nWhichUserLists );
250 
251 	ScUserList* pCoreList		= rUserListItem.GetUserList();
252 	sal_Bool		bDataModified	= sal_False;
253 
254 	if ( (pUserLists == NULL) && (pCoreList == NULL) )
255 	{
256 		bDataModified = sal_False;
257 	}
258 	else if ( pUserLists != NULL )
259 	{
260 		if ( pCoreList != NULL )
261 			bDataModified = (*pUserLists != *pCoreList);
262 		else
263 			bDataModified = sal_True;
264 	}
265 
266 	if ( bDataModified )
267 	{
268 		ScUserListItem aULItem( nWhichUserLists );
269 
270 		if ( pUserLists )
271 			aULItem.SetUserList( *pUserLists );
272 
273 		rCoreAttrs.Put( aULItem );
274 	}
275 
276 	return bDataModified;
277 }
278 
279 // -----------------------------------------------------------------------
280 
DeactivatePage(SfxItemSet * pSetP)281 int __EXPORT ScTpUserLists::DeactivatePage( SfxItemSet* pSetP )
282 {
283     if ( pSetP )
284         FillItemSet( *pSetP );
285 
286 	return LEAVE_PAGE;
287 }
288 
289 // -----------------------------------------------------------------------
290 
UpdateUserListBox()291 sal_uInt16 ScTpUserLists::UpdateUserListBox()
292 {
293 	aLbLists.Clear();
294 
295 	if ( !pUserLists ) return 0;
296 
297 	//----------------------------------------------------------
298 
299 	sal_uInt16	nCount = pUserLists->GetCount();
300 	String	aEntry;
301 
302 	if ( nCount > 0 )
303 	{
304 		for ( sal_uInt16 i=0; i<nCount; i++ )
305 		{
306 			aEntry = (*pUserLists)[i]->GetString();
307 			DBG_ASSERT( aEntry.Len() > 0, "Empty UserList-entry :-/" );
308 			aLbLists.InsertEntry( aEntry );
309 		}
310 	}
311 
312 	return nCount;
313 }
314 
315 // -----------------------------------------------------------------------
316 
UpdateEntries(sal_uInt16 nList)317 void ScTpUserLists::UpdateEntries( sal_uInt16 nList )
318 {
319 	if ( !pUserLists ) return;
320 
321 	//----------------------------------------------------------
322 
323 	if ( nList < pUserLists->GetCount() )
324 	{
325 		ScUserListData* pList	  = (*pUserLists)[nList];
326 		sal_uInt16			nSubCount = pList->GetSubCount();
327 		String			aEntryListStr;
328 
329 		for ( sal_uInt16 i=0; i<nSubCount; i++ )
330 		{
331 			if ( i!=0 )
332 				aEntryListStr += CR;
333 			aEntryListStr += pList->GetSubStr( i );
334 		}
335 
336 		aEntryListStr.ConvertLineEnd();
337 		aEdEntries.SetText( aEntryListStr );
338 	}
339 	else
340 	{
341 		DBG_ERROR( "Invalid ListIndex :-/" );
342 	}
343 }
344 
345 // -----------------------------------------------------------------------
346 
MakeListStr(String & rListStr)347 void ScTpUserLists::MakeListStr( String& rListStr )
348 {
349 	String	aInputStr(rListStr);
350 	String	aStr;
351 
352 	xub_StrLen	nLen	= aStr.Len();
353 	xub_StrLen	c		= 0;
354 
355 	aInputStr.ConvertLineEnd( LINEEND_LF );
356 	//aStr.EraseAllChars( ' ' );
357 
358 	xub_StrLen nToken=rListStr.GetTokenCount(LF);
359 
360 	for(xub_StrLen i=0;i<nToken;i++)
361 	{
362 		String aString=rListStr.GetToken(i,LF);
363 		aString.EraseLeadingChars(' ');
364 		aString.EraseTrailingChars(' ');
365 		aStr+=aString;
366 		aStr+=cDelimiter;
367 	}
368 
369 	/*
370 	// '\n' durch cDelimiter ersetzen:
371 	for ( c=0;
372 		  (c < nLen) && (nFound != STRING_NOTFOUND);
373 		  c++ )
374 	{
375 		nFound = aStr.Search( LF, nFound );
376 		if ( nFound != STRING_NOTFOUND )
377 			aStr[nFound] = cDelimiter;
378 	}
379 	*/
380 
381 	aStr.EraseLeadingChars( cDelimiter );
382 	aStr.EraseTrailingChars( cDelimiter );
383 	nLen = aStr.Len();
384 
385 	rListStr.Erase();
386 
387 	// Alle Doppelten cDelimiter entfernen:
388 	c=0;
389 	while ( c < nLen )
390 	{
391 		rListStr += aStr.GetChar(c);
392 		c++;
393 
394 		if ( aStr.GetChar(c) == cDelimiter )
395 		{
396 			rListStr += aStr.GetChar(c);
397 
398 			while ( (aStr.GetChar(c) == cDelimiter) && (c < nLen) )
399 				c++;
400 		}
401 	}
402 
403 }
404 
405 // -----------------------------------------------------------------------
406 
AddNewList(const String & rEntriesStr)407 void ScTpUserLists::AddNewList( const String& rEntriesStr )
408 {
409 	String theEntriesStr( rEntriesStr );
410 
411 	if ( !pUserLists )
412 		pUserLists = new ScUserList;
413 
414 	MakeListStr( theEntriesStr );
415 
416 	if ( !pUserLists->Insert( new ScUserListData( theEntriesStr ) ) )
417     {
418 		DBG_ERROR( "Entry could not be inserted :-/" );
419     }
420 }
421 
422 // -----------------------------------------------------------------------
423 
CopyListFromArea(const ScRefAddress & rStartPos,const ScRefAddress & rEndPos)424 void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos,
425 									  const ScRefAddress& rEndPos )
426 {
427 	if ( bCopyDone ) return;
428 
429 	//----------------------------------------------------------
430 
431 	SCTAB	nTab			= rStartPos.Tab();
432 	SCCOL	nStartCol		= rStartPos.Col();
433 	SCROW	nStartRow		= rStartPos.Row();
434 	SCCOL	nEndCol			= rEndPos.Col();
435 	SCROW	nEndRow			= rEndPos.Row();
436 	sal_uInt16	nCellDir		= SCRET_COLS;
437 	sal_Bool	bValueIgnored	= sal_False;
438 
439 	if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) )
440 	{
441 		nCellDir = ScColOrRowDlg( this, aStrCopyList, aStrCopyFrom ).Execute();
442 //CHINA001		ScAbstractDialogFactory* pFact = ScAbstractDialogFactory::Create();
443 //CHINA001		DBG_ASSERT(pFact, "ScAbstractFactory create fail!");//CHINA001
444 //CHINA001
445 //CHINA001		VclAbstractDialog* pDlg = pFact->CreateScColOrRowDlg( this, aStrCopyList, aStrCopyFrom,ResId(RID_SCDLG_COLORROW) );
446 //CHINA001		DBG_ASSERT(pDlg, "Dialog create fail!");//CHINA001
447 //CHINA001		nCellDir = pDlg->Execute();
448 //CHINA001		delete pDlg; //CHINA001
449 	}
450 	else if ( nStartCol != nEndCol )
451 		nCellDir = SCRET_ROWS;
452 	else
453 		nCellDir = SCRET_COLS;
454 
455 	if ( nCellDir != RET_CANCEL )
456 	{
457 		String	aStrList;
458 		String	aStrField;
459 
460 		if ( nCellDir == SCRET_COLS )
461 		{
462 			for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
463 			{
464 				for ( SCROW row=nStartRow; row<=nEndRow; row++ )
465 				{
466 					if ( pDoc->HasStringData( col, row, nTab ) )
467 					{
468 						pDoc->GetString( col, row, nTab, aStrField );
469 
470 						if ( aStrField.Len() > 0 )
471 						{
472 							aStrList += aStrField;
473 							aStrList += '\n';
474 						}
475 					}
476 					else
477 						bValueIgnored = sal_True;
478 				}
479 				if ( aStrList.Len() > 0 )
480 					AddNewList( aStrList );
481 				aStrList.Erase();
482 			}
483 		}
484 		else
485 		{
486 			for ( SCROW row=nStartRow; row<=nEndRow; row++ )
487 			{
488 				for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
489 				{
490 					if ( pDoc->HasStringData( col, row, nTab ) )
491 					{
492 						pDoc->GetString( col, row, nTab, aStrField );
493 
494 						if ( aStrField.Len() > 0 )
495 						{
496 							aStrList += aStrField;
497 							aStrList += '\n';
498 						}
499 					}
500 					else
501 						bValueIgnored = sal_True;
502 				}
503 				if ( aStrList.Len() > 0 )
504 					AddNewList( aStrList );
505 				aStrList.Erase();
506 			}
507 		}
508 
509 		if ( bValueIgnored )
510 		{
511 			InfoBox( this, aStrCopyErr ).Execute();
512 		}
513 	}
514 
515 	//----------------------------------------------------------
516 
517 	bCopyDone = sal_True;
518 
519 }
520 
521 // -----------------------------------------------------------------------
522 
ModifyList(sal_uInt16 nSelList,const String & rEntriesStr)523 void ScTpUserLists::ModifyList( sal_uInt16			nSelList,
524 								const String&	rEntriesStr )
525 {
526 	if ( !pUserLists ) return;
527 
528 	//----------------------------------------------------------
529 
530 	String theEntriesStr( rEntriesStr );
531 
532 	MakeListStr( theEntriesStr );
533 
534 	(*pUserLists)[nSelList]->SetString( theEntriesStr );
535 }
536 
537 // -----------------------------------------------------------------------
538 
RemoveList(sal_uInt16 nList)539 void ScTpUserLists::RemoveList( sal_uInt16 nList )
540 {
541 	if ( pUserLists ) pUserLists->AtFree( nList );
542 }
543 
544 //-----------------------------------------------------------------------
545 // Handler:
546 //---------
547 
IMPL_LINK(ScTpUserLists,LbSelectHdl,ListBox *,pLb)548 IMPL_LINK( ScTpUserLists, LbSelectHdl, ListBox*, pLb )
549 {
550 	if ( pLb == &aLbLists )
551 	{
552 		sal_uInt16 nSelPos = aLbLists.GetSelectEntryPos();
553 		if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
554 		{
555 			if ( !aFtEntries.IsEnabled() )	aFtEntries.Enable();
556 			if ( !aEdEntries.IsEnabled() )	aEdEntries.Enable();
557 			if ( !aBtnRemove.IsEnabled() )	aBtnRemove.Enable();
558 			if (  aBtnAdd.IsEnabled() ) 	aBtnAdd.Disable();
559 
560 			UpdateEntries( nSelPos );
561 		}
562 	}
563 
564 	return 0;
565 }
566 
567 // -----------------------------------------------------------------------
568 
IMPL_LINK(ScTpUserLists,BtnClickHdl,PushButton *,pBtn)569 IMPL_LINK( ScTpUserLists, BtnClickHdl, PushButton*, pBtn )
570 {
571 	if ( pBtn == &aBtnNew )
572 	{
573 		if ( !bCancelMode )
574 		{
575 			nCancelPos = ( aLbLists.GetEntryCount() > 0 )
576 							? aLbLists.GetSelectEntryPos()
577 							: 0;
578 			aLbLists.SetNoSelection();
579 			aFtLists.Disable();
580 			aLbLists.Disable();
581 			aFtEntries.Enable();
582 			aEdEntries.Enable();
583 			aEdEntries.SetText( EMPTY_STRING );
584 			aEdEntries.GrabFocus();
585 			aBtnAdd.Disable();
586 			aBtnRemove.Disable();
587 			//-----------------------------
588 			if ( aBtnCopy.IsEnabled() )
589 			{
590 				aBtnCopy.Disable();
591 				aFtCopyFrom.Disable();
592 				aEdCopyFrom.Disable();
593 			}
594 			aBtnNew.SetText( aStrCancel );
595 			bCancelMode = sal_True;
596 		}
597 		else // if ( bCancelMode )
598 		{
599 			if ( aLbLists.GetEntryCount() > 0 )
600 			{
601 				aLbLists.SelectEntryPos( nCancelPos );
602 				LbSelectHdl( &aLbLists );
603 				aFtLists.Enable();
604 				aLbLists.Enable();
605 			}
606 			else
607 			{
608 				aFtEntries.Disable();
609 				aEdEntries.Disable();
610 				aEdEntries.SetText( EMPTY_STRING );
611 				aBtnRemove.Disable();
612 			}
613 			aBtnAdd.Disable();
614 			//-----------------------------
615 			if ( pViewData && !bCopyDone )
616 			{
617 				aBtnCopy.Enable();
618 				aFtCopyFrom.Enable();
619 				aEdCopyFrom.Enable();
620 			}
621 			aBtnNew.SetText( aStrNew );
622 			bCancelMode = sal_False;
623 			bModifyMode = sal_False;
624 		}
625 	}
626 	else if ( pBtn == &aBtnAdd )
627 	{
628 		String theEntriesStr( aEdEntries.GetText() );
629 
630 		if ( !bModifyMode )
631 		{
632 			if ( theEntriesStr.Len() > 0 )
633 			{
634 				AddNewList( theEntriesStr );
635 				UpdateUserListBox();
636 				aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 );
637 				LbSelectHdl( &aLbLists );
638 				aFtLists.Enable();
639 				aLbLists.Enable();
640 			}
641 			else
642 			{
643 				if ( aLbLists.GetEntryCount() > 0 )
644 				{
645 					aLbLists.SelectEntryPos( nCancelPos );
646 					LbSelectHdl( &aLbLists );
647 					aLbLists.Enable();
648 					aLbLists.Enable();
649 				}
650 			}
651 
652 			aBtnAdd.Disable();
653 			aBtnRemove.Enable();
654 			aBtnNew.SetText( aStrNew );
655 			bCancelMode = sal_False;
656 		}
657 		else // if ( bModifyMode )
658 		{
659 			sal_uInt16 nSelList = aLbLists.GetSelectEntryPos();
660 
661 			DBG_ASSERT( nSelList != LISTBOX_ENTRY_NOTFOUND,	"Modify without List :-/" );
662 
663 			if ( theEntriesStr.Len() > 0 )
664 			{
665 				ModifyList( nSelList, theEntriesStr );
666 				UpdateUserListBox();
667 				aLbLists.SelectEntryPos( nSelList );
668 			}
669 			else
670 			{
671 				aLbLists.SelectEntryPos( 0 );
672 				LbSelectHdl( &aLbLists );
673 			}
674 
675 			aBtnNew.SetText( aStrNew ); bCancelMode = sal_False;
676 			aBtnAdd.SetText( aStrAdd ); bModifyMode = sal_False;
677 			aBtnAdd.Disable();
678 			aBtnRemove.Enable();
679 			aFtLists.Enable();
680 			aLbLists.Enable();
681 		}
682 
683 		if ( pViewData && !bCopyDone )
684 		{
685 			aBtnCopy.Enable();
686 			aFtCopyFrom.Enable();
687 			aEdCopyFrom.Enable();
688 		}
689 	}
690 	else if ( pBtn == &aBtnRemove )
691 	{
692 		if ( aLbLists.GetEntryCount() > 0 )
693 		{
694 			sal_uInt16 nRemovePos	= aLbLists.GetSelectEntryPos();
695 			String aMsg 		( aStrQueryRemove.GetToken( 0, '#' ) );
696 
697 			aMsg += aLbLists.GetEntry( nRemovePos );
698 			aMsg += aStrQueryRemove.GetToken( 1, '#' );
699 
700 
701 			if ( RET_YES == QueryBox( this,
702 									  WinBits( WB_YES_NO | WB_DEF_YES ),
703 									  aMsg
704 									 ).Execute() )
705 			{
706 				RemoveList( nRemovePos );
707 				UpdateUserListBox();
708 
709 				if ( aLbLists.GetEntryCount() > 0 )
710 				{
711 					aLbLists.SelectEntryPos(
712 						( nRemovePos >= aLbLists.GetEntryCount() )
713 							? aLbLists.GetEntryCount()-1
714 							: nRemovePos );
715 					LbSelectHdl( &aLbLists );
716 				}
717 				else
718 				{
719 					aFtLists.Disable();
720 					aLbLists.Disable();
721 					aFtEntries.Disable();
722 					aEdEntries.Disable();
723 					aEdEntries.SetText( EMPTY_STRING );
724 					aBtnRemove.Disable();
725 				}
726 			}
727 
728 			if ( pViewData && !bCopyDone && !aBtnCopy.IsEnabled() )
729 			{
730 				aBtnCopy.Enable();
731 				aFtCopyFrom.Enable();
732 				aEdCopyFrom.Enable();
733 			}
734 		}
735 	}
736 	else if ( pViewData && (pBtn == &aBtnCopy) )
737 	{
738 		if ( bCopyDone )
739 			return 0;
740 
741 		//-----------------------------------------------------------
742 
743 		ScRefAddress theStartPos;
744 		ScRefAddress theEndPos;
745 		String		theAreaStr( aEdCopyFrom.GetText() );
746 		sal_Bool		bAreaOk = sal_False;
747 
748 		if ( theAreaStr.Len() > 0 )
749 		{
750 			bAreaOk = pRangeUtil->IsAbsArea( theAreaStr,
751 											 pDoc,
752 											 pViewData->GetTabNo(),
753 											 &theAreaStr,
754 											 &theStartPos,
755 											 &theEndPos,
756                                              pDoc->GetAddressConvention() );
757 			if ( !bAreaOk )
758 			{
759 				bAreaOk = pRangeUtil->IsAbsPos(  theAreaStr,
760 												 pDoc,
761 												 pViewData->GetTabNo(),
762 												 &theAreaStr,
763 												 &theStartPos,
764                                                  pDoc->GetAddressConvention() );
765 				theEndPos = theStartPos;
766 			}
767 		}
768 
769 		if ( bAreaOk )
770 		{
771 			CopyListFromArea( theStartPos, theEndPos );
772 			UpdateUserListBox();
773 			aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 );
774 			LbSelectHdl( &aLbLists );
775 			aEdCopyFrom	.SetText( theAreaStr );
776 			aEdCopyFrom	.Disable();
777 			aBtnCopy	.Disable();
778 			aFtCopyFrom	.Disable();
779 		}
780 		else
781 		{
782 			ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
783 					  ScGlobal::GetRscString( STR_INVALID_TABREF )
784 					).Execute();
785 			aEdCopyFrom.GrabFocus();
786 			aEdCopyFrom.SetSelection( Selection( 0, SELECTION_MAX ) );
787 		}
788 	}
789 
790 	return 0;
791 }
792 
793 // -----------------------------------------------------------------------
794 
IMPL_LINK(ScTpUserLists,EdEntriesModHdl,MultiLineEdit *,pEd)795 IMPL_LINK( ScTpUserLists, EdEntriesModHdl, MultiLineEdit*, pEd )
796 {
797 	if ( pEd != &aEdEntries )
798 		return 0;
799 
800 	//-----------------------------------------------------------
801 
802 	if ( aBtnCopy.IsEnabled() )
803 	{
804 		aBtnCopy	.Disable();
805 		aFtCopyFrom	.Disable();
806 		aEdCopyFrom	.Disable();
807 	}
808 
809 	if ( aEdEntries.GetText().Len() > 0 )
810 	{
811 		if ( !bCancelMode && !bModifyMode )
812 		{
813 			aBtnNew.SetText( aStrCancel );	bCancelMode = sal_True;
814 			aBtnAdd.SetText( aStrModify );	bModifyMode = sal_True;
815 			aBtnAdd.Enable();
816 			aBtnRemove.Disable();
817 			aFtLists.Disable();
818 			aLbLists.Disable();
819 		}
820 		else // if ( bCancelMode || bModifyMode )
821 		{
822 			if ( !aBtnAdd.IsEnabled() ) aBtnAdd.Enable();
823 		}
824 	}
825 	else
826 	{
827 		if ( aBtnAdd.IsEnabled() ) aBtnAdd.Disable();
828 	}
829 
830 	return 0;
831 }
832 
833 
834 
835