Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #undef SC_DLLIMPLEMENTATION
31 : :
32 : : #include <comphelper/string.hxx>
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 : : // STATIC DATA -----------------------------------------------------------
53 : :
54 : : #define CR (sal_Unicode)13
55 : : #define LF (sal_Unicode)10
56 : :
57 : : static const sal_Unicode cDelimiter = ',';
58 : :
59 : : //========================================================================
60 : : // Benutzerdefinierte Listen:
61 : :
62 : :
63 : 0 : ScTpUserLists::ScTpUserLists( Window* pParent,
64 : : const SfxItemSet& rCoreAttrs )
65 : :
66 : : : SfxTabPage ( pParent,
67 : : ScResId( RID_SCPAGE_USERLISTS ),
68 : : rCoreAttrs ),
69 : : aFtLists ( this, ScResId( FT_LISTS ) ),
70 : : aLbLists ( this, ScResId( LB_LISTS ) ),
71 : : aFtEntries ( this, ScResId( FT_ENTRIES ) ),
72 : : aEdEntries ( this, ScResId( ED_ENTRIES ) ),
73 : : aFtCopyFrom ( this, ScResId( FT_COPYFROM ) ),
74 : : aEdCopyFrom ( this, ScResId( ED_COPYFROM ) ),
75 : : aBtnNew ( this, ScResId( BTN_NEW ) ),
76 : : aBtnAdd ( this, ScResId( BTN_ADD ) ),
77 : : aBtnRemove ( this, ScResId( BTN_REMOVE ) ),
78 : : aBtnCopy ( this, ScResId( BTN_COPY ) ),
79 : : aStrQueryRemove ( ScResId( STR_QUERYREMOVE ) ),
80 : : aStrNew ( aBtnNew.GetText() ),
81 : : aStrCancel ( ScResId( STR_DISMISS ) ),
82 : : aStrAdd ( ScResId( SCSTR_ADD ) ),
83 : : aStrModify ( ScResId( SCSTR_MODIFY ) ),
84 : : aStrCopyList ( ScResId( STR_COPYLIST ) ),
85 : : aStrCopyFrom ( ScResId( STR_COPYFROM ) ),
86 : : aStrCopyErr ( ScResId( STR_COPYERR ) ),
87 : 0 : nWhichUserLists ( GetWhich( SID_SCUSERLISTS ) ),
88 : : pUserLists ( NULL ),
89 : : pDoc ( NULL ),
90 : : pViewData ( NULL ),
91 : 0 : pRangeUtil ( new ScRangeUtil ),
92 : : bModifyMode ( false ),
93 : : bCancelMode ( false ),
94 : : bCopyDone ( false ),
95 : 0 : nCancelPos ( 0 )
96 : : {
97 : 0 : SetExchangeSupport();
98 : 0 : Init();
99 : 0 : FreeResource();
100 : 0 : }
101 : :
102 : : // -----------------------------------------------------------------------
103 : :
104 : 0 : ScTpUserLists::~ScTpUserLists()
105 : : {
106 : 0 : delete pUserLists;
107 : 0 : delete pRangeUtil;
108 : 0 : }
109 : :
110 : : // -----------------------------------------------------------------------
111 : :
112 : 0 : void ScTpUserLists::Init()
113 : : {
114 : 0 : SfxViewShell* pSh = SfxViewShell::Current();
115 : 0 : ScTabViewShell* pViewSh = PTR_CAST(ScTabViewShell, pSh);
116 : :
117 : 0 : aLbLists.SetSelectHdl ( LINK( this, ScTpUserLists, LbSelectHdl ) );
118 : 0 : aBtnNew.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
119 : 0 : aBtnNew.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
120 : 0 : aBtnAdd.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
121 : 0 : aBtnRemove.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
122 : 0 : aEdEntries.SetModifyHdl ( LINK( this, ScTpUserLists, EdEntriesModHdl ) );
123 : :
124 : :
125 : 0 : if ( pViewSh )
126 : : {
127 : 0 : SCTAB nStartTab = 0;
128 : 0 : SCTAB nEndTab = 0;
129 : 0 : SCCOL nStartCol = 0;
130 : 0 : SCROW nStartRow = 0;
131 : 0 : SCCOL nEndCol = 0;
132 : 0 : SCROW nEndRow = 0;
133 : :
134 : 0 : pViewData = pViewSh->GetViewData();
135 : 0 : pDoc = pViewData->GetDocument();
136 : :
137 : : pViewData->GetSimpleArea( nStartCol, nStartRow, nStartTab,
138 : 0 : nEndCol, nEndRow, nEndTab );
139 : :
140 : 0 : PutInOrder( nStartCol, nEndCol );
141 : 0 : PutInOrder( nStartRow, nEndRow );
142 : 0 : PutInOrder( nStartTab, nEndTab );
143 : :
144 : : ScRange( nStartCol, nStartRow, nStartTab, nEndCol, nEndRow, nEndTab
145 : 0 : ).Format( aStrSelectedArea, SCR_ABS_3D, pDoc );
146 : :
147 : 0 : aBtnCopy.SetClickHdl ( LINK( this, ScTpUserLists, BtnClickHdl ) );
148 : 0 : aBtnCopy.Enable();
149 : : }
150 : : else
151 : : {
152 : 0 : aBtnCopy.Disable();
153 : 0 : aFtCopyFrom.Disable();
154 : 0 : aEdCopyFrom.Disable();
155 : : }
156 : 0 : }
157 : :
158 : : // -----------------------------------------------------------------------
159 : :
160 : 0 : SfxTabPage* ScTpUserLists::Create( Window* pParent, const SfxItemSet& rAttrSet )
161 : : {
162 : 0 : return ( new ScTpUserLists( pParent, rAttrSet ) );
163 : : }
164 : :
165 : : // -----------------------------------------------------------------------
166 : :
167 : 0 : void ScTpUserLists::Reset( const SfxItemSet& rCoreAttrs )
168 : : {
169 : : const ScUserListItem& rUserListItem = (const ScUserListItem&)
170 : 0 : rCoreAttrs.Get( nWhichUserLists );
171 : 0 : const ScUserList* pCoreList = rUserListItem.GetUserList();
172 : :
173 : : OSL_ENSURE( pCoreList, "UserList not found :-/" );
174 : :
175 : 0 : if ( pCoreList )
176 : : {
177 : 0 : if ( !pUserLists )
178 : 0 : pUserLists = new ScUserList( *pCoreList );
179 : : else
180 : 0 : *pUserLists = *pCoreList;
181 : :
182 : 0 : if ( UpdateUserListBox() > 0 )
183 : : {
184 : 0 : aLbLists.SelectEntryPos( 0 );
185 : 0 : UpdateEntries( 0 );
186 : : }
187 : : }
188 : 0 : else if ( !pUserLists )
189 : 0 : pUserLists = new ScUserList;
190 : :
191 : 0 : aEdCopyFrom.SetText( aStrSelectedArea );
192 : :
193 : 0 : if ( aLbLists.GetEntryCount() == 0 )
194 : : {
195 : 0 : aFtLists .Disable();
196 : 0 : aLbLists .Disable();
197 : 0 : aFtEntries .Disable();
198 : 0 : aEdEntries .Disable();
199 : 0 : aBtnRemove .Disable();
200 : : }
201 : :
202 : 0 : aBtnNew.SetText( aStrNew );
203 : 0 : aBtnAdd.SetText( aStrAdd );
204 : 0 : aBtnAdd.Disable();
205 : :
206 : 0 : if ( !bCopyDone && pViewData )
207 : : {
208 : 0 : aFtCopyFrom .Enable();
209 : 0 : aEdCopyFrom .Enable();
210 : 0 : aBtnCopy .Enable();
211 : : }
212 : 0 : }
213 : :
214 : : // -----------------------------------------------------------------------
215 : :
216 : 0 : sal_Bool ScTpUserLists::FillItemSet( SfxItemSet& rCoreAttrs )
217 : : {
218 : : // Modifikationen noch nicht uebernommen?
219 : : // -> Click auf Add-Button simulieren
220 : :
221 : 0 : if ( bModifyMode || bCancelMode )
222 : 0 : BtnClickHdl( &aBtnAdd );
223 : :
224 : : const ScUserListItem& rUserListItem = (const ScUserListItem&)
225 : 0 : GetItemSet().Get( nWhichUserLists );
226 : :
227 : 0 : ScUserList* pCoreList = rUserListItem.GetUserList();
228 : 0 : sal_Bool bDataModified = false;
229 : :
230 : 0 : if ( (pUserLists == NULL) && (pCoreList == NULL) )
231 : : {
232 : 0 : bDataModified = false;
233 : : }
234 : 0 : else if ( pUserLists != NULL )
235 : : {
236 : 0 : if ( pCoreList != NULL )
237 : 0 : bDataModified = (*pUserLists != *pCoreList);
238 : : else
239 : 0 : bDataModified = sal_True;
240 : : }
241 : :
242 : 0 : if ( bDataModified )
243 : : {
244 : 0 : ScUserListItem aULItem( nWhichUserLists );
245 : :
246 : 0 : if ( pUserLists )
247 : 0 : aULItem.SetUserList( *pUserLists );
248 : :
249 : 0 : rCoreAttrs.Put( aULItem );
250 : : }
251 : :
252 : 0 : return bDataModified;
253 : : }
254 : :
255 : : // -----------------------------------------------------------------------
256 : :
257 : 0 : int ScTpUserLists::DeactivatePage( SfxItemSet* pSetP )
258 : : {
259 : 0 : if ( pSetP )
260 : 0 : FillItemSet( *pSetP );
261 : :
262 : 0 : return LEAVE_PAGE;
263 : : }
264 : :
265 : : // -----------------------------------------------------------------------
266 : :
267 : 0 : sal_uInt16 ScTpUserLists::UpdateUserListBox()
268 : : {
269 : 0 : aLbLists.Clear();
270 : :
271 : 0 : if ( !pUserLists ) return 0;
272 : :
273 : : //----------------------------------------------------------
274 : :
275 : 0 : size_t nCount = pUserLists->size();
276 : 0 : String aEntry;
277 : :
278 : 0 : for ( size_t i=0; i<nCount; ++i )
279 : : {
280 : 0 : aEntry = (*pUserLists)[i]->GetString();
281 : : OSL_ENSURE( aEntry.Len() > 0, "Empty UserList-entry :-/" );
282 : 0 : aLbLists.InsertEntry( aEntry );
283 : : }
284 : :
285 : 0 : return nCount;
286 : : }
287 : :
288 : : // -----------------------------------------------------------------------
289 : :
290 : 0 : void ScTpUserLists::UpdateEntries( size_t nList )
291 : : {
292 : 0 : if ( !pUserLists ) return;
293 : :
294 : : //----------------------------------------------------------
295 : :
296 : 0 : if ( nList < pUserLists->size() )
297 : : {
298 : 0 : const ScUserListData* pList = (*pUserLists)[nList];
299 : 0 : sal_uInt16 nSubCount = pList->GetSubCount();
300 : 0 : String aEntryListStr;
301 : :
302 : 0 : for ( sal_uInt16 i=0; i<nSubCount; i++ )
303 : : {
304 : 0 : if ( i!=0 )
305 : 0 : aEntryListStr += CR;
306 : 0 : aEntryListStr += String(pList->GetSubStr(i));
307 : : }
308 : :
309 : 0 : aEdEntries.SetText(convertLineEnd(aEntryListStr, GetSystemLineEnd()));
310 : : }
311 : : else
312 : : {
313 : : OSL_FAIL( "Invalid ListIndex :-/" );
314 : : }
315 : : }
316 : :
317 : : // -----------------------------------------------------------------------
318 : :
319 : 0 : void ScTpUserLists::MakeListStr( String& rListStr )
320 : : {
321 : 0 : String aStr;
322 : :
323 : 0 : xub_StrLen nToken = comphelper::string::getTokenCount(rListStr, LF);
324 : :
325 : 0 : for(xub_StrLen i=0;i<nToken;i++)
326 : : {
327 : 0 : rtl::OUString aString = comphelper::string::strip(rListStr.GetToken(i, LF), ' ');
328 : 0 : aStr+=aString;
329 : 0 : aStr+=cDelimiter;
330 : 0 : }
331 : :
332 : 0 : aStr = comphelper::string::strip(aStr, cDelimiter);
333 : 0 : xub_StrLen nLen = aStr.Len();
334 : :
335 : 0 : rListStr.Erase();
336 : :
337 : : // Alle Doppelten cDelimiter entfernen:
338 : 0 : xub_StrLen c = 0;
339 : 0 : while ( c < nLen )
340 : : {
341 : 0 : rListStr += aStr.GetChar(c);
342 : 0 : c++;
343 : :
344 : 0 : if ( aStr.GetChar(c) == cDelimiter )
345 : : {
346 : 0 : rListStr += aStr.GetChar(c);
347 : :
348 : 0 : while ( (aStr.GetChar(c) == cDelimiter) && (c < nLen) )
349 : 0 : c++;
350 : : }
351 : 0 : }
352 : :
353 : 0 : }
354 : :
355 : : // -----------------------------------------------------------------------
356 : :
357 : 0 : void ScTpUserLists::AddNewList( const String& rEntriesStr )
358 : : {
359 : 0 : String theEntriesStr( rEntriesStr );
360 : :
361 : 0 : if ( !pUserLists )
362 : 0 : pUserLists = new ScUserList;
363 : :
364 : 0 : MakeListStr( theEntriesStr );
365 : :
366 : 0 : pUserLists->push_back(new ScUserListData(theEntriesStr));
367 : 0 : }
368 : :
369 : : // -----------------------------------------------------------------------
370 : :
371 : 0 : void ScTpUserLists::CopyListFromArea( const ScRefAddress& rStartPos,
372 : : const ScRefAddress& rEndPos )
373 : : {
374 : 0 : if ( bCopyDone ) return;
375 : :
376 : : //----------------------------------------------------------
377 : :
378 : 0 : SCTAB nTab = rStartPos.Tab();
379 : 0 : SCCOL nStartCol = rStartPos.Col();
380 : 0 : SCROW nStartRow = rStartPos.Row();
381 : 0 : SCCOL nEndCol = rEndPos.Col();
382 : 0 : SCROW nEndRow = rEndPos.Row();
383 : 0 : sal_uInt16 nCellDir = SCRET_COLS;
384 : 0 : sal_Bool bValueIgnored = false;
385 : :
386 : 0 : if ( (nStartCol != nEndCol) && (nStartRow != nEndRow) )
387 : : {
388 : 0 : nCellDir = ScColOrRowDlg( this, aStrCopyList, aStrCopyFrom ).Execute();
389 : : }
390 : 0 : else if ( nStartCol != nEndCol )
391 : 0 : nCellDir = SCRET_ROWS;
392 : : else
393 : 0 : nCellDir = SCRET_COLS;
394 : :
395 : 0 : if ( nCellDir != RET_CANCEL )
396 : : {
397 : 0 : String aStrList;
398 : 0 : String aStrField;
399 : :
400 : 0 : if ( nCellDir == SCRET_COLS )
401 : : {
402 : 0 : for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
403 : : {
404 : 0 : for ( SCROW row=nStartRow; row<=nEndRow; row++ )
405 : : {
406 : 0 : if ( pDoc->HasStringData( col, row, nTab ) )
407 : : {
408 : 0 : pDoc->GetString( col, row, nTab, aStrField );
409 : :
410 : 0 : if ( aStrField.Len() > 0 )
411 : : {
412 : 0 : aStrList += aStrField;
413 : 0 : aStrList += '\n';
414 : : }
415 : : }
416 : : else
417 : 0 : bValueIgnored = sal_True;
418 : : }
419 : 0 : if ( aStrList.Len() > 0 )
420 : 0 : AddNewList( aStrList );
421 : 0 : aStrList.Erase();
422 : : }
423 : : }
424 : : else
425 : : {
426 : 0 : for ( SCROW row=nStartRow; row<=nEndRow; row++ )
427 : : {
428 : 0 : for ( SCCOL col=nStartCol; col<=nEndCol; col++ )
429 : : {
430 : 0 : if ( pDoc->HasStringData( col, row, nTab ) )
431 : : {
432 : 0 : pDoc->GetString( col, row, nTab, aStrField );
433 : :
434 : 0 : if ( aStrField.Len() > 0 )
435 : : {
436 : 0 : aStrList += aStrField;
437 : 0 : aStrList += '\n';
438 : : }
439 : : }
440 : : else
441 : 0 : bValueIgnored = sal_True;
442 : : }
443 : 0 : if ( aStrList.Len() > 0 )
444 : 0 : AddNewList( aStrList );
445 : 0 : aStrList.Erase();
446 : : }
447 : : }
448 : :
449 : 0 : if ( bValueIgnored )
450 : : {
451 : 0 : InfoBox( this, aStrCopyErr ).Execute();
452 : 0 : }
453 : : }
454 : :
455 : : //----------------------------------------------------------
456 : :
457 : 0 : bCopyDone = sal_True;
458 : :
459 : : }
460 : :
461 : : // -----------------------------------------------------------------------
462 : :
463 : 0 : void ScTpUserLists::ModifyList( sal_uInt16 nSelList,
464 : : const String& rEntriesStr )
465 : : {
466 : 0 : if ( !pUserLists ) return;
467 : :
468 : : //----------------------------------------------------------
469 : :
470 : 0 : String theEntriesStr( rEntriesStr );
471 : :
472 : 0 : MakeListStr( theEntriesStr );
473 : :
474 : 0 : (*pUserLists)[nSelList]->SetString( theEntriesStr );
475 : : }
476 : :
477 : : // -----------------------------------------------------------------------
478 : :
479 : 0 : void ScTpUserLists::RemoveList( size_t nList )
480 : : {
481 : 0 : if (pUserLists && nList < pUserLists->size())
482 : : {
483 : 0 : ScUserList::iterator itr = pUserLists->begin();
484 : 0 : ::std::advance(itr, nList);
485 : 0 : pUserLists->erase(itr);
486 : : }
487 : 0 : }
488 : :
489 : : //-----------------------------------------------------------------------
490 : : // Handler:
491 : : //---------
492 : :
493 : 0 : IMPL_LINK( ScTpUserLists, LbSelectHdl, ListBox*, pLb )
494 : : {
495 : 0 : if ( pLb == &aLbLists )
496 : : {
497 : 0 : sal_uInt16 nSelPos = aLbLists.GetSelectEntryPos();
498 : 0 : if ( nSelPos != LISTBOX_ENTRY_NOTFOUND )
499 : : {
500 : 0 : if ( !aFtEntries.IsEnabled() ) aFtEntries.Enable();
501 : 0 : if ( !aEdEntries.IsEnabled() ) aEdEntries.Enable();
502 : 0 : if ( !aBtnRemove.IsEnabled() ) aBtnRemove.Enable();
503 : 0 : if ( aBtnAdd.IsEnabled() ) aBtnAdd.Disable();
504 : :
505 : 0 : UpdateEntries( nSelPos );
506 : : }
507 : : }
508 : :
509 : 0 : return 0;
510 : : }
511 : :
512 : : // -----------------------------------------------------------------------
513 : :
514 : 0 : IMPL_LINK( ScTpUserLists, BtnClickHdl, PushButton*, pBtn )
515 : : {
516 : 0 : if ( pBtn == &aBtnNew )
517 : : {
518 : 0 : if ( !bCancelMode )
519 : : {
520 : 0 : nCancelPos = ( aLbLists.GetEntryCount() > 0 )
521 : 0 : ? aLbLists.GetSelectEntryPos()
522 : 0 : : 0;
523 : 0 : aLbLists.SetNoSelection();
524 : 0 : aFtLists.Disable();
525 : 0 : aLbLists.Disable();
526 : 0 : aFtEntries.Enable();
527 : 0 : aEdEntries.Enable();
528 : 0 : aEdEntries.SetText( EMPTY_STRING );
529 : 0 : aEdEntries.GrabFocus();
530 : 0 : aBtnAdd.Disable();
531 : 0 : aBtnRemove.Disable();
532 : : //-----------------------------
533 : 0 : if ( aBtnCopy.IsEnabled() )
534 : : {
535 : 0 : aBtnCopy.Disable();
536 : 0 : aFtCopyFrom.Disable();
537 : 0 : aEdCopyFrom.Disable();
538 : : }
539 : 0 : aBtnNew.SetText( aStrCancel );
540 : 0 : bCancelMode = sal_True;
541 : : }
542 : : else // if ( bCancelMode )
543 : : {
544 : 0 : if ( aLbLists.GetEntryCount() > 0 )
545 : : {
546 : 0 : aLbLists.SelectEntryPos( nCancelPos );
547 : 0 : LbSelectHdl( &aLbLists );
548 : 0 : aFtLists.Enable();
549 : 0 : aLbLists.Enable();
550 : : }
551 : : else
552 : : {
553 : 0 : aFtEntries.Disable();
554 : 0 : aEdEntries.Disable();
555 : 0 : aEdEntries.SetText( EMPTY_STRING );
556 : 0 : aBtnRemove.Disable();
557 : : }
558 : 0 : aBtnAdd.Disable();
559 : : //-----------------------------
560 : 0 : if ( pViewData && !bCopyDone )
561 : : {
562 : 0 : aBtnCopy.Enable();
563 : 0 : aFtCopyFrom.Enable();
564 : 0 : aEdCopyFrom.Enable();
565 : : }
566 : 0 : aBtnNew.SetText( aStrNew );
567 : 0 : bCancelMode = false;
568 : 0 : bModifyMode = false;
569 : : }
570 : : }
571 : 0 : else if ( pBtn == &aBtnAdd )
572 : : {
573 : 0 : String theEntriesStr( aEdEntries.GetText() );
574 : :
575 : 0 : if ( !bModifyMode )
576 : : {
577 : 0 : if ( theEntriesStr.Len() > 0 )
578 : : {
579 : 0 : AddNewList( theEntriesStr );
580 : 0 : UpdateUserListBox();
581 : 0 : aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 );
582 : 0 : LbSelectHdl( &aLbLists );
583 : 0 : aFtLists.Enable();
584 : 0 : aLbLists.Enable();
585 : : }
586 : : else
587 : : {
588 : 0 : if ( aLbLists.GetEntryCount() > 0 )
589 : : {
590 : 0 : aLbLists.SelectEntryPos( nCancelPos );
591 : 0 : LbSelectHdl( &aLbLists );
592 : 0 : aLbLists.Enable();
593 : 0 : aLbLists.Enable();
594 : : }
595 : : }
596 : :
597 : 0 : aBtnAdd.Disable();
598 : 0 : aBtnRemove.Enable();
599 : 0 : aBtnNew.SetText( aStrNew );
600 : 0 : bCancelMode = false;
601 : : }
602 : : else // if ( bModifyMode )
603 : : {
604 : 0 : sal_uInt16 nSelList = aLbLists.GetSelectEntryPos();
605 : :
606 : : OSL_ENSURE( nSelList != LISTBOX_ENTRY_NOTFOUND, "Modify without List :-/" );
607 : :
608 : 0 : if ( theEntriesStr.Len() > 0 )
609 : : {
610 : 0 : ModifyList( nSelList, theEntriesStr );
611 : 0 : UpdateUserListBox();
612 : 0 : aLbLists.SelectEntryPos( nSelList );
613 : : }
614 : : else
615 : : {
616 : 0 : aLbLists.SelectEntryPos( 0 );
617 : 0 : LbSelectHdl( &aLbLists );
618 : : }
619 : :
620 : 0 : aBtnNew.SetText( aStrNew ); bCancelMode = false;
621 : 0 : aBtnAdd.SetText( aStrAdd ); bModifyMode = false;
622 : 0 : aBtnAdd.Disable();
623 : 0 : aBtnRemove.Enable();
624 : 0 : aFtLists.Enable();
625 : 0 : aLbLists.Enable();
626 : : }
627 : :
628 : 0 : if ( pViewData && !bCopyDone )
629 : : {
630 : 0 : aBtnCopy.Enable();
631 : 0 : aFtCopyFrom.Enable();
632 : 0 : aEdCopyFrom.Enable();
633 : 0 : }
634 : : }
635 : 0 : else if ( pBtn == &aBtnRemove )
636 : : {
637 : 0 : if ( aLbLists.GetEntryCount() > 0 )
638 : : {
639 : 0 : sal_uInt16 nRemovePos = aLbLists.GetSelectEntryPos();
640 : 0 : String aMsg ( aStrQueryRemove.GetToken( 0, '#' ) );
641 : :
642 : 0 : aMsg += aLbLists.GetEntry( nRemovePos );
643 : 0 : aMsg += aStrQueryRemove.GetToken( 1, '#' );
644 : :
645 : :
646 : 0 : if ( RET_YES == QueryBox( this,
647 : : WinBits( WB_YES_NO | WB_DEF_YES ),
648 : : aMsg
649 : 0 : ).Execute() )
650 : : {
651 : 0 : RemoveList( nRemovePos );
652 : 0 : UpdateUserListBox();
653 : :
654 : 0 : if ( aLbLists.GetEntryCount() > 0 )
655 : : {
656 : : aLbLists.SelectEntryPos(
657 : 0 : ( nRemovePos >= aLbLists.GetEntryCount() )
658 : 0 : ? aLbLists.GetEntryCount()-1
659 : 0 : : nRemovePos );
660 : 0 : LbSelectHdl( &aLbLists );
661 : : }
662 : : else
663 : : {
664 : 0 : aFtLists.Disable();
665 : 0 : aLbLists.Disable();
666 : 0 : aFtEntries.Disable();
667 : 0 : aEdEntries.Disable();
668 : 0 : aEdEntries.SetText( EMPTY_STRING );
669 : 0 : aBtnRemove.Disable();
670 : : }
671 : : }
672 : :
673 : 0 : if ( pViewData && !bCopyDone && !aBtnCopy.IsEnabled() )
674 : : {
675 : 0 : aBtnCopy.Enable();
676 : 0 : aFtCopyFrom.Enable();
677 : 0 : aEdCopyFrom.Enable();
678 : 0 : }
679 : : }
680 : : }
681 : 0 : else if ( pViewData && (pBtn == &aBtnCopy) )
682 : : {
683 : 0 : if ( bCopyDone )
684 : 0 : return 0;
685 : :
686 : : //-----------------------------------------------------------
687 : :
688 : 0 : ScRefAddress theStartPos;
689 : 0 : ScRefAddress theEndPos;
690 : 0 : String theAreaStr( aEdCopyFrom.GetText() );
691 : 0 : sal_Bool bAreaOk = false;
692 : :
693 : 0 : if ( theAreaStr.Len() > 0 )
694 : : {
695 : : bAreaOk = pRangeUtil->IsAbsArea( theAreaStr,
696 : : pDoc,
697 : 0 : pViewData->GetTabNo(),
698 : : &theAreaStr,
699 : : &theStartPos,
700 : : &theEndPos,
701 : 0 : pDoc->GetAddressConvention() );
702 : 0 : if ( !bAreaOk )
703 : : {
704 : : bAreaOk = pRangeUtil->IsAbsPos( theAreaStr,
705 : : pDoc,
706 : 0 : pViewData->GetTabNo(),
707 : : &theAreaStr,
708 : : &theStartPos,
709 : 0 : pDoc->GetAddressConvention() );
710 : 0 : theEndPos = theStartPos;
711 : : }
712 : : }
713 : :
714 : 0 : if ( bAreaOk )
715 : : {
716 : 0 : CopyListFromArea( theStartPos, theEndPos );
717 : 0 : UpdateUserListBox();
718 : 0 : aLbLists.SelectEntryPos( aLbLists.GetEntryCount()-1 );
719 : 0 : LbSelectHdl( &aLbLists );
720 : 0 : aEdCopyFrom .SetText( theAreaStr );
721 : 0 : aEdCopyFrom .Disable();
722 : 0 : aBtnCopy .Disable();
723 : 0 : aFtCopyFrom .Disable();
724 : : }
725 : : else
726 : : {
727 : : ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
728 : 0 : ScGlobal::GetRscString( STR_INVALID_TABREF )
729 : 0 : ).Execute();
730 : 0 : aEdCopyFrom.GrabFocus();
731 : 0 : aEdCopyFrom.SetSelection( Selection( 0, SELECTION_MAX ) );
732 : 0 : }
733 : : }
734 : :
735 : 0 : return 0;
736 : : }
737 : :
738 : : // -----------------------------------------------------------------------
739 : :
740 : 0 : IMPL_LINK( ScTpUserLists, EdEntriesModHdl, MultiLineEdit*, pEd )
741 : : {
742 : 0 : if ( pEd != &aEdEntries )
743 : 0 : return 0;
744 : :
745 : : //-----------------------------------------------------------
746 : :
747 : 0 : if ( aBtnCopy.IsEnabled() )
748 : : {
749 : 0 : aBtnCopy .Disable();
750 : 0 : aFtCopyFrom .Disable();
751 : 0 : aEdCopyFrom .Disable();
752 : : }
753 : :
754 : 0 : if ( aEdEntries.GetText().Len() > 0 )
755 : : {
756 : 0 : if ( !bCancelMode && !bModifyMode )
757 : : {
758 : 0 : aBtnNew.SetText( aStrCancel ); bCancelMode = sal_True;
759 : 0 : aBtnAdd.SetText( aStrModify ); bModifyMode = sal_True;
760 : 0 : aBtnAdd.Enable();
761 : 0 : aBtnRemove.Disable();
762 : 0 : aFtLists.Disable();
763 : 0 : aLbLists.Disable();
764 : : }
765 : : else // if ( bCancelMode || bModifyMode )
766 : : {
767 : 0 : if ( !aBtnAdd.IsEnabled() ) aBtnAdd.Enable();
768 : : }
769 : : }
770 : : else
771 : : {
772 : 0 : if ( aBtnAdd.IsEnabled() ) aBtnAdd.Disable();
773 : : }
774 : :
775 : 0 : return 0;
776 : : }
777 : :
778 : :
779 : :
780 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|