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