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 #if !TEST_LAYOUT
25 // MARKER(update_precomp.py): autogen include statement, do not remove
26 #include "precompiled_sc.hxx"
27 #endif /* !TEST_LAYOUT */
28
29 #undef SC_DLLIMPLEMENTATION
30
31
32
33 #include <vcl/msgbox.hxx>
34 #include <i18npool/mslangid.hxx>
35 #include <svtools/collatorres.hxx>
36 #include <unotools/collatorwrapper.hxx>
37 #include <unotools/localedatawrapper.hxx>
38 #include <comphelper/processfactory.hxx>
39
40 #include "scitems.hxx"
41 #include "uiitems.hxx"
42 #include "viewdata.hxx"
43 #include "document.hxx"
44 #include "global.hxx"
45 #include "dbcolect.hxx"
46 #include "userlist.hxx"
47 #include "rangeutl.hxx"
48 #include "scresid.hxx"
49 #include "sc.hrc" // -> Slot IDs
50 #include "globstr.hrc"
51
52 #include "sortdlg.hxx"
53 #include "sortdlg.hrc"
54
55 #define _TPSORT_CXX
56 #include "tpsort.hxx"
57 #undef _TPSORT_CXX
58
59 using namespace com::sun::star;
60
61 // STATIC DATA -----------------------------------------------------------
62
63 static USHORT pSortRanges[] =
64 {
65 SID_SORT,
66 SID_SORT,
67 0
68 };
69
70 // -----------------------------------------------------------------------
71
72 /*
73 * Da sich Einstellungen auf der zweiten TabPage (Optionen) auf
74 * die erste TabPage auswirken, muss es die Moeglichkeit geben,
75 * dies der jeweils anderen Seite mitzuteilen.
76 *
77 * Im Moment wird dieses Problem ueber zwei Datenmember des TabDialoges
78 * geloest. Wird eine Seite Aktiviert/Deaktiviert, so gleicht sie diese
79 * Datenmember mit dem eigenen Zustand ab (->Activate()/Deactivate()).
80 *
81 * 31.01.95:
82 * Die Klasse SfxTabPage bietet mittlerweile ein Verfahren an:
83 *
84 * virtual BOOL HasExchangeSupport() const; -> return TRUE;
85 * virtual void ActivatePage(const SfxItemSet &);
86 * virtual int DeactivatePage(SfxItemSet * = 0);
87 *
88 * muss noch geaendert werden!
89 */
90
91 //========================================================================
92 //========================================================================
93 // Sortierkriterien-Tabpage:
94
ScTabPageSortFields(Window * pParent,const SfxItemSet & rArgSet)95 ScTabPageSortFields::ScTabPageSortFields( Window* pParent,
96 const SfxItemSet& rArgSet )
97
98 : SfxTabPage ( pParent,
99 ScResId( RID_SCPAGE_SORT_FIELDS ),
100 rArgSet ),
101 //
102 aFlSort1 ( this, ScResId( FL_SORT1 ) ),
103 aLbSort1 ( this, ScResId( LB_SORT1 ) ),
104 aBtnUp1 ( this, ScResId( BTN_UP1 ) ),
105 aBtnDown1 ( this, ScResId( BTN_DOWN1 ) ),
106 //
107 aFlSort2 ( this, ScResId( FL_SORT2 ) ),
108 aLbSort2 ( this, ScResId( LB_SORT2 ) ),
109 aBtnUp2 ( this, ScResId( BTN_UP2 ) ),
110 aBtnDown2 ( this, ScResId( BTN_DOWN2 ) ),
111 //
112 aFlSort3 ( this, ScResId( FL_SORT3 ) ),
113 aLbSort3 ( this, ScResId( LB_SORT3 ) ),
114 aBtnUp3 ( this, ScResId( BTN_UP3 ) ),
115 aBtnDown3 ( this, ScResId( BTN_DOWN3 ) ),
116
117 aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
118 aStrColumn ( ScResId( SCSTR_COLUMN ) ),
119 aStrRow ( ScResId( SCSTR_ROW ) ),
120 //
121 #if !TEST_LAYOUT
122 nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
123 #else /* TEST_LAYOUT */
124 nWhichSort ( 0 ),
125 #endif /* TEST_LAYOUT */
126 pDlg ( (ScSortDlg*)(GetParent()->GetParent()) ),
127 pViewData ( NULL ),
128 #if !TEST_LAYOUT
129 rSortData ( ((const ScSortItem&)
130 rArgSet.Get( nWhichSort )).
131 GetSortData() ),
132 #else /* TEST_LAYOUT */
133 rSortData ( *new ScSortParam() ),
134 #endif /* TEST_LAYOUT */
135 nFieldCount ( 0 ),
136 bHasHeader ( FALSE ),
137 bSortByRows ( FALSE )
138 {
139 Init();
140 FreeResource();
141 SetExchangeSupport();
142 }
143
144 // -----------------------------------------------------------------------
145
~ScTabPageSortFields()146 __EXPORT ScTabPageSortFields::~ScTabPageSortFields()
147 {
148 }
149
150 // -----------------------------------------------------------------------
151
Init()152 void ScTabPageSortFields::Init()
153 {
154 #if !TEST_LAYOUT
155 const ScSortItem& rSortItem = (const ScSortItem&)
156 GetItemSet().Get( nWhichSort );
157
158 pViewData = rSortItem.GetViewData();
159
160 DBG_ASSERT( pViewData, "ViewData not found!" );
161 #endif /* !TEST_LAYOUT */
162
163 nFieldArr[0] = 0;
164 nFirstCol = 0;
165 nFirstRow = 0;
166
167 aLbSort1.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
168 aLbSort2.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
169 aLbSort3.SetSelectHdl( LINK( this, ScTabPageSortFields, SelectHdl ) );
170 aLbSort1.Clear();
171 aLbSort2.Clear();
172 aLbSort3.Clear();
173
174 aSortLbArr[0] = &aLbSort1;
175 aSortLbArr[1] = &aLbSort2;
176 aSortLbArr[2] = &aLbSort3;
177 aDirBtnArr[0][0] = &aBtnUp1;
178 aDirBtnArr[0][1] = &aBtnDown1;
179 aDirBtnArr[1][0] = &aBtnUp2;
180 aDirBtnArr[1][1] = &aBtnDown2;
181 aDirBtnArr[2][0] = &aBtnUp3;
182 aDirBtnArr[2][1] = &aBtnDown3;
183 aFlArr[0] = &aFlSort1;
184 aFlArr[1] = &aFlSort2;
185 aFlArr[2] = &aFlSort3;
186 }
187
188 //------------------------------------------------------------------------
189
GetRanges()190 USHORT* __EXPORT ScTabPageSortFields::GetRanges()
191 {
192 return pSortRanges;
193 }
194
195 // -----------------------------------------------------------------------
196
Create(Window * pParent,const SfxItemSet & rArgSet)197 SfxTabPage* __EXPORT ScTabPageSortFields::Create( Window* pParent,
198 const SfxItemSet& rArgSet )
199 {
200 return ( new ScTabPageSortFields( pParent, rArgSet ) );
201 }
202
203 // -----------------------------------------------------------------------
204
Reset(const SfxItemSet &)205 void __EXPORT ScTabPageSortFields::Reset( const SfxItemSet& /* rArgSet */ )
206 {
207 bSortByRows = rSortData.bByRow;
208 bHasHeader = rSortData.bHasHeader;
209
210 if ( aLbSort1.GetEntryCount() == 0 )
211 FillFieldLists();
212
213 // Selektieren der ListBoxen:
214
215 if ( rSortData.bDoSort[0] )
216 {
217 for ( USHORT i=0; i<3; i++ )
218 {
219 if ( rSortData.bDoSort[i] )
220 {
221 aSortLbArr[i]->SelectEntryPos(
222 GetFieldSelPos( rSortData.nField[i] ) );
223
224 (rSortData.bAscending[i])
225 ? aDirBtnArr[i][0]->Check() // Up
226 : aDirBtnArr[i][1]->Check(); // Down
227 }
228 else
229 {
230 aSortLbArr[i]->SelectEntryPos( 0 ); // "keiner" selektieren
231 aDirBtnArr[i][0]->Check(); // Up
232 }
233 }
234
235 EnableField( 1 );
236 EnableField( 2 );
237 EnableField( 3 );
238 if ( aLbSort1.GetSelectEntryPos() == 0 )
239 DisableField( 2 );
240 if ( aLbSort2.GetSelectEntryPos() == 0 )
241 DisableField( 3 );
242 }
243 else
244 {
245 aLbSort1.SelectEntryPos( 1 );
246 aLbSort2.SelectEntryPos( 0 );
247 aLbSort3.SelectEntryPos( 0 );
248 aBtnUp1.Check();
249 aBtnUp2.Check();
250 aBtnUp3.Check();
251 EnableField ( 1 );
252 EnableField ( 2 );
253 DisableField( 3 );
254 }
255
256 if ( pDlg )
257 {
258 pDlg->SetByRows ( bSortByRows );
259 pDlg->SetHeaders( bHasHeader );
260 }
261 }
262
263 // -----------------------------------------------------------------------
264
FillItemSet(SfxItemSet & rArgSet)265 BOOL __EXPORT ScTabPageSortFields::FillItemSet( SfxItemSet& rArgSet )
266 {
267 ScSortParam theSortData = rSortData;
268 if (pDlg)
269 {
270 const SfxItemSet* pExample = pDlg->GetExampleSet();
271 const SfxPoolItem* pItem;
272 if ( pExample && pExample->GetItemState( nWhichSort, TRUE, &pItem ) == SFX_ITEM_SET )
273 theSortData = ((const ScSortItem*)pItem)->GetSortData();
274 }
275
276 USHORT nSort1Pos = aLbSort1.GetSelectEntryPos();
277 USHORT nSort2Pos = aLbSort2.GetSelectEntryPos();
278 USHORT nSort3Pos = aLbSort3.GetSelectEntryPos();
279
280 DBG_ASSERT( (nSort1Pos <= SC_MAXFIELDS)
281 && (nSort2Pos <= SC_MAXFIELDS)
282 && (nSort3Pos <= SC_MAXFIELDS),
283 "Array-Range Fehler!" );
284
285 if ( nSort1Pos == LISTBOX_ENTRY_NOTFOUND ) nSort1Pos = 0;
286 if ( nSort2Pos == LISTBOX_ENTRY_NOTFOUND ) nSort2Pos = 0;
287 if ( nSort3Pos == LISTBOX_ENTRY_NOTFOUND ) nSort3Pos = 0;
288
289 if ( nSort1Pos > 0 )
290 {
291 theSortData.bDoSort[0] = (nSort1Pos > 0);
292 theSortData.bDoSort[1] = (nSort2Pos > 0);
293 theSortData.bDoSort[2] = (nSort3Pos > 0);
294
295 // wenn auf Optionen-Seite "OK" gewaehlt wurde und
296 // dabei die Sortierrichtung umgestellt wurde, so
297 // wird das erste Feld der jeweiligen Richtung als
298 // Sortierkriterium gewaehlt (steht in nFieldArr[0]):
299 if ( bSortByRows != pDlg->GetByRows() )
300 {
301 theSortData.nField[0] =
302 theSortData.nField[1] =
303 theSortData.nField[2] = ( bSortByRows ?
304 static_cast<SCCOLROW>(nFirstRow) :
305 static_cast<SCCOLROW>(nFirstCol) );
306 }
307 else
308 {
309 theSortData.nField[0] = nFieldArr[nSort1Pos];
310 theSortData.nField[1] = nFieldArr[nSort2Pos];
311 theSortData.nField[2] = nFieldArr[nSort3Pos];
312 }
313
314 theSortData.bAscending[0] = aBtnUp1.IsChecked();
315 theSortData.bAscending[1] = aBtnUp2.IsChecked();
316 theSortData.bAscending[2] = aBtnUp3.IsChecked();
317 // bHasHeader ist in ScTabPageSortOptions::FillItemSet, wo es hingehoert
318 }
319 else
320 {
321 theSortData.bDoSort[0] =
322 theSortData.bDoSort[1] =
323 theSortData.bDoSort[2] = FALSE;
324 }
325
326 rArgSet.Put( ScSortItem( SCITEM_SORTDATA, NULL, &theSortData ) );
327
328 return TRUE;
329 }
330
331 // -----------------------------------------------------------------------
332
333 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
334 // void ScTabPageSortFields::ActivatePage( const SfxItemSet& rSet )
335
ActivatePage()336 void __EXPORT ScTabPageSortFields::ActivatePage()
337 {
338 if ( pDlg )
339 {
340 if ( bHasHeader != pDlg->GetHeaders()
341 || bSortByRows != pDlg->GetByRows() )
342 {
343 USHORT nCurSel1 = aLbSort1.GetSelectEntryPos();
344 USHORT nCurSel2 = aLbSort2.GetSelectEntryPos();
345 USHORT nCurSel3 = aLbSort3.GetSelectEntryPos();
346
347 bHasHeader = pDlg->GetHeaders();
348 bSortByRows = pDlg->GetByRows();
349 FillFieldLists();
350 aLbSort1.SelectEntryPos( nCurSel1 );
351 aLbSort2.SelectEntryPos( nCurSel2 );
352 aLbSort3.SelectEntryPos( nCurSel3 );
353 }
354 }
355 }
356
357 // -----------------------------------------------------------------------
358
DeactivatePage(SfxItemSet * pSetP)359 int __EXPORT ScTabPageSortFields::DeactivatePage( SfxItemSet* pSetP )
360 {
361 if ( pDlg )
362 {
363 if ( bHasHeader != pDlg->GetHeaders() )
364 pDlg->SetHeaders( bHasHeader );
365
366 if ( bSortByRows != pDlg->GetByRows() )
367 pDlg->SetByRows( bSortByRows );
368 }
369
370 if ( pSetP )
371 FillItemSet( *pSetP );
372
373 return SfxTabPage::LEAVE_PAGE;
374 }
375
376 // -----------------------------------------------------------------------
377
DisableField(USHORT nField)378 void ScTabPageSortFields::DisableField( USHORT nField )
379 {
380 nField--;
381
382 if ( nField<=2 )
383 {
384 aSortLbArr[nField] ->Disable();
385 aDirBtnArr[nField][0]->Disable();
386 aDirBtnArr[nField][1]->Disable();
387 aFlArr[nField] ->Disable();
388 }
389 }
390
391 // -----------------------------------------------------------------------
392
EnableField(USHORT nField)393 void ScTabPageSortFields::EnableField( USHORT nField )
394 {
395 nField--;
396
397 if ( nField<=2 )
398 {
399 aSortLbArr[nField] ->Enable();
400 aDirBtnArr[nField][0]->Enable();
401 aDirBtnArr[nField][1]->Enable();
402 aFlArr[nField] ->Enable();
403 }
404 }
405
406 // -----------------------------------------------------------------------
407
FillFieldLists()408 void ScTabPageSortFields::FillFieldLists()
409 {
410 if ( pViewData )
411 {
412 ScDocument* pDoc = pViewData->GetDocument();
413
414 if ( pDoc )
415 {
416 aLbSort1.Clear();
417 aLbSort2.Clear();
418 aLbSort3.Clear();
419 aLbSort1.InsertEntry( aStrUndefined, 0 );
420 aLbSort2.InsertEntry( aStrUndefined, 0 );
421 aLbSort3.InsertEntry( aStrUndefined, 0 );
422
423 SCCOL nFirstSortCol = rSortData.nCol1;
424 SCROW nFirstSortRow = rSortData.nRow1;
425 SCTAB nTab = pViewData->GetTabNo();
426 USHORT i = 1;
427
428 if ( bSortByRows )
429 {
430 String aFieldName;
431 SCCOL nMaxCol = rSortData.nCol2;
432 SCCOL col;
433
434 for ( col=nFirstSortCol; col<=nMaxCol && i<SC_MAXFIELDS; col++ )
435 {
436 pDoc->GetString( col, nFirstSortRow, nTab, aFieldName );
437 if ( !bHasHeader || (aFieldName.Len() == 0) )
438 {
439 aFieldName = aStrColumn;
440 aFieldName += ' ';
441 aFieldName += ColToAlpha( col );
442 }
443 nFieldArr[i] = col;
444 aLbSort1.InsertEntry( aFieldName, i );
445 aLbSort2.InsertEntry( aFieldName, i );
446 aLbSort3.InsertEntry( aFieldName, i );
447 i++;
448 }
449 }
450 else
451 {
452 String aFieldName;
453 SCROW nMaxRow = rSortData.nRow2;
454 SCROW row;
455
456 for ( row=nFirstSortRow; row<=nMaxRow && i<SC_MAXFIELDS; row++ )
457 {
458 pDoc->GetString( nFirstSortCol, row, nTab, aFieldName );
459 if ( !bHasHeader || (aFieldName.Len() == 0) )
460 {
461 aFieldName = aStrRow;
462 aFieldName += ' ';
463 aFieldName += String::CreateFromInt32( row+1 );
464 }
465 nFieldArr[i] = row;
466 aLbSort1.InsertEntry( aFieldName, i );
467 aLbSort2.InsertEntry( aFieldName, i );
468 aLbSort3.InsertEntry( aFieldName, i );
469 i++;
470 }
471 }
472 nFieldCount = i;
473 }
474 }
475 }
476
477 //------------------------------------------------------------------------
478
GetFieldSelPos(SCCOLROW nField)479 USHORT ScTabPageSortFields::GetFieldSelPos( SCCOLROW nField )
480 {
481 USHORT nFieldPos = 0;
482 BOOL bFound = FALSE;
483
484 for ( USHORT n=1; n<nFieldCount && !bFound; n++ )
485 {
486 if ( nFieldArr[n] == nField )
487 {
488 nFieldPos = n;
489 bFound = TRUE;
490 }
491 }
492
493 return nFieldPos;
494 }
495
496 // -----------------------------------------------------------------------
497 // Handler:
498 //---------
499
IMPL_LINK(ScTabPageSortFields,SelectHdl,ListBox *,pLb)500 IMPL_LINK( ScTabPageSortFields, SelectHdl, ListBox *, pLb )
501 {
502 String aSelEntry = pLb->GetSelectEntry();
503
504 if ( pLb == &aLbSort1 )
505 {
506 if ( aSelEntry == aStrUndefined )
507 {
508 aLbSort2.SelectEntryPos( 0 );
509 aLbSort3.SelectEntryPos( 0 );
510
511 if ( aFlSort2.IsEnabled() )
512 DisableField( 2 );
513
514 if ( aFlSort3.IsEnabled() )
515 DisableField( 3 );
516 }
517 else
518 {
519 if ( !aFlSort2.IsEnabled() )
520 EnableField( 2 );
521 }
522 }
523 else if ( pLb == &aLbSort2 )
524 {
525 if ( aSelEntry == aStrUndefined )
526 {
527 aLbSort3.SelectEntryPos( 0 );
528 if ( aFlSort3.IsEnabled() )
529 DisableField( 3 );
530 }
531 else
532 {
533 if ( !aFlSort3.IsEnabled() )
534 EnableField( 3 );
535 }
536 }
537 return 0;
538 }
539
540 //========================================================================
541 // Sortieroptionen-Tabpage:
542 //========================================================================
543
544 #include <layout/layout-pre.hxx>
545
546 #if ENABLE_LAYOUT
547 #undef ScResId
548 #define ScResId(x) #x
549 #undef SfxTabPage
550 #define SfxTabPage( parent, id, args ) SfxTabPage( parent, "sort-options.xml", id, &args )
551 #endif /* ENABLE_LAYOUT */
552
ScTabPageSortOptions(Window * pParent,const SfxItemSet & rArgSet)553 ScTabPageSortOptions::ScTabPageSortOptions( Window* pParent,
554 const SfxItemSet& rArgSet )
555
556 : SfxTabPage ( pParent,
557 ScResId( RID_SCPAGE_SORT_OPTIONS ),
558 rArgSet ),
559 //
560 aBtnCase ( this, ScResId( BTN_CASESENSITIVE ) ),
561 aBtnHeader ( this, ScResId( BTN_LABEL ) ),
562 aBtnFormats ( this, ScResId( BTN_FORMATS ) ),
563 aBtnCopyResult ( this, ScResId( BTN_COPYRESULT ) ),
564 aBtnNaturalSort ( this, ScResId( BTN_NATURALSORT ) ),
565 aLbOutPos ( this, ScResId( LB_OUTAREA ) ),
566 aEdOutPos ( this, ScResId( ED_OUTAREA ) ),
567 aBtnSortUser ( this, ScResId( BTN_SORT_USER ) ),
568 aLbSortUser ( this, ScResId( LB_SORT_USER ) ),
569 aFtLanguage ( this, ScResId( FT_LANGUAGE ) ),
570 aLbLanguage ( this, ScResId( LB_LANGUAGE ) ),
571 aFtAlgorithm ( this, ScResId( FT_ALGORITHM ) ),
572 aLbAlgorithm ( this, ScResId( LB_ALGORITHM ) ),
573 aLineDirection ( this, ScResId( FL_DIRECTION ) ),
574 aBtnTopDown ( this, ScResId( BTN_TOP_DOWN ) ),
575 aBtnLeftRight ( this, ScResId( BTN_LEFT_RIGHT ) ),
576 // aFtAreaLabel ( this, ScResId( FT_AREA_LABEL ) ),
577 // aFtArea ( this, ScResId( FT_AREA ) ),
578 //
579 #if ENABLE_LAYOUT
580 #undef this
581 #undef ScResId
582 #define ScResId(x) this, #x
583 #endif /* ENABLE_LAYOUT */
584 aStrRowLabel ( ScResId( STR_ROW_LABEL ) ),
585 aStrColLabel ( ScResId( STR_COL_LABEL ) ),
586 aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
587 aStrNoName ( ScGlobal::GetRscString(STR_DB_NONAME) ),
588 //
589 #if !TEST_LAYOUT
590 nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
591 rSortData ( ((const ScSortItem&)
592 rArgSet.Get( nWhichSort )).GetSortData() ),
593 #else /* TEST_LAYOUT */
594 nWhichSort ( 0 ),
595 rSortData ( *new ScSortParam() ),
596 #endif /* TEST_LAYOUT */
597 pViewData ( NULL ),
598 pDoc ( NULL ),
599 pDlg ( (ScSortDlg*)(GetParent() ? GetParent()->GetParent() : 0 ) ),
600 pColRes ( NULL ),
601 pColWrap ( NULL )
602 {
603 #if TEST_LAYOUT
604 (void) rArgSet;
605 #endif /* TEST_LAYOUT */
606 Init();
607 FreeResource();
608 SetExchangeSupport();
609 }
610
611 // -----------------------------------------------------------------------
612
~ScTabPageSortOptions()613 __EXPORT ScTabPageSortOptions::~ScTabPageSortOptions()
614 {
615 #if !TEST_LAYOUT
616 USHORT nEntries = aLbOutPos.GetEntryCount();
617
618 for ( USHORT i=1; i<nEntries; i++ )
619 delete (String*)aLbOutPos.GetEntryData( i );
620 #endif /* !TEST_LAYOUT */
621
622 delete pColRes;
623 delete pColWrap; //! not if from document
624 }
625
626 // -----------------------------------------------------------------------
627
Init()628 void ScTabPageSortOptions::Init()
629 {
630 // aStrAreaLabel = aFtAreaLabel.GetText();
631 // aStrAreaLabel.Append( (sal_Unicode) ' ' );
632
633 // CollatorRessource has user-visible names for sort algorithms
634 pColRes = new CollatorRessource();
635
636 //! use CollatorWrapper from document?
637 pColWrap = new CollatorWrapper( comphelper::getProcessServiceFactory() );
638
639 #if !TEST_LAYOUT
640 const ScSortItem& rSortItem = (const ScSortItem&)
641 GetItemSet().Get( nWhichSort );
642 #endif /* !TEST_LAYOUT */
643
644 aLbOutPos.SetSelectHdl ( LINK( this, ScTabPageSortOptions, SelOutPosHdl ) );
645 aBtnCopyResult.SetClickHdl( LINK( this, ScTabPageSortOptions, EnableHdl ) );
646 aBtnSortUser.SetClickHdl ( LINK( this, ScTabPageSortOptions, EnableHdl ) );
647 aBtnTopDown.SetClickHdl ( LINK( this, ScTabPageSortOptions, SortDirHdl ) );
648 aBtnLeftRight.SetClickHdl ( LINK( this, ScTabPageSortOptions, SortDirHdl ) );
649 aLbLanguage.SetSelectHdl ( LINK( this, ScTabPageSortOptions, FillAlgorHdl ) );
650
651 #if !TEST_LAYOUT
652 pViewData = rSortItem.GetViewData();
653 #endif /* TEST_LAYOUT */
654 pDoc = pViewData ? pViewData->GetDocument() : NULL;
655
656 DBG_ASSERT( pViewData, "ViewData not found! :-/" );
657
658 #if !TEST_LAYOUT
659 if ( pViewData && pDoc )
660 {
661 String theArea;
662 ScDBCollection* pDBColl = pDoc->GetDBCollection();
663 String theDbArea;
664 String theDbName = aStrNoName;
665 const SCTAB nCurTab = pViewData->GetTabNo();
666 const ScAddress::Convention eConv = pDoc->GetAddressConvention();
667 #endif /* !TEST_LAYOUT */
668
669 aLbOutPos.Clear();
670 aLbOutPos.InsertEntry( aStrUndefined, 0 );
671 aLbOutPos.Disable();
672
673 #if !TEST_LAYOUT
674 ScAreaNameIterator aIter( pDoc );
675 String aName;
676 ScRange aRange;
677 String aRefStr;
678 while ( aIter.Next( aName, aRange ) )
679 {
680 USHORT nInsert = aLbOutPos.InsertEntry( aName );
681
682 aRange.aStart.Format( aRefStr, SCA_ABS_3D, pDoc, eConv );
683 aLbOutPos.SetEntryData( nInsert, new String( aRefStr ) );
684 }
685 #endif /* !TEST_LAYOUT */
686
687 aLbOutPos.SelectEntryPos( 0 );
688 aEdOutPos.SetText( EMPTY_STRING );
689
690 #if !TEST_LAYOUT
691 /*
692 * Ueberpruefen, ob es sich bei dem uebergebenen
693 * Bereich um einen Datenbankbereich handelt:
694 */
695
696 ScAddress aScAddress( rSortData.nCol1, rSortData.nRow1, nCurTab );
697 ScRange( aScAddress,
698 ScAddress( rSortData.nCol2, rSortData.nRow2, nCurTab )
699 ).Format( theArea, SCR_ABS, pDoc, eConv );
700
701 if ( pDBColl )
702 {
703 ScDBData* pDBData
704 = pDBColl->GetDBAtArea( nCurTab,
705 rSortData.nCol1, rSortData.nRow1,
706 rSortData.nCol2, rSortData.nRow2 );
707 if ( pDBData )
708 {
709 pDBData->GetName( theDbName );
710 aBtnHeader.Check( pDBData->HasHeader() );
711 }
712 }
713
714 theArea.AppendAscii(RTL_CONSTASCII_STRINGPARAM(" ("));
715 theArea += theDbName;
716 theArea += ')';
717
718 //aFtArea.SetText( theArea );
719 //theArea.Insert( aStrAreaLabel, 0 );
720 //aFtAreaLabel.SetText( theArea );
721
722 aBtnHeader.SetText( aStrColLabel );
723 }
724 #endif /* TEST_LAYOUT */
725
726 FillUserSortListBox();
727
728 // get available languages
729
730 aLbLanguage.SetLanguageList( LANG_LIST_ALL | LANG_LIST_ONLY_KNOWN, FALSE );
731 aLbLanguage.InsertLanguage( LANGUAGE_SYSTEM );
732 }
733
734 //------------------------------------------------------------------------
735
GetRanges()736 USHORT* __EXPORT ScTabPageSortOptions::GetRanges()
737 {
738 return pSortRanges;
739 }
740
741 // -----------------------------------------------------------------------
742
743 #if ENABLE_LAYOUT
744 #undef SfxTabPage
745 #endif /* ENABLE_LAYOUT */
Create(Window * pParent,const SfxItemSet & rArgSet)746 SfxTabPage* __EXPORT ScTabPageSortOptions::Create(
747 Window* pParent,
748 const SfxItemSet& rArgSet )
749 {
750 return ( new ScTabPageSortOptions( pParent, rArgSet ) );
751 }
752
753 // -----------------------------------------------------------------------
754
Reset(const SfxItemSet &)755 void __EXPORT ScTabPageSortOptions::Reset( const SfxItemSet& /* rArgSet */ )
756 {
757 if ( rSortData.bUserDef )
758 {
759 aBtnSortUser.Check( TRUE );
760 aLbSortUser.Enable();
761 aLbSortUser.SelectEntryPos( rSortData.nUserIndex );
762 }
763 else
764 {
765 aBtnSortUser.Check( FALSE );
766 aLbSortUser.Disable();
767 aLbSortUser.SelectEntryPos( 0 );
768 }
769
770 aBtnCase.Check ( rSortData.bCaseSens );
771 aBtnFormats.Check ( rSortData.bIncludePattern );
772 aBtnHeader.Check ( rSortData.bHasHeader );
773 aBtnNaturalSort.Check ( rSortData.bNaturalSort );
774
775 if ( rSortData.bByRow )
776 {
777 aBtnTopDown.Check();
778 aBtnHeader.SetText( aStrColLabel );
779 }
780 else
781 {
782 aBtnLeftRight.Check();
783 aBtnHeader.SetText( aStrRowLabel );
784 }
785
786 LanguageType eLang = MsLangId::convertLocaleToLanguage( rSortData.aCollatorLocale );
787 if ( eLang == LANGUAGE_DONTKNOW )
788 eLang = LANGUAGE_SYSTEM;
789 aLbLanguage.SelectLanguage( eLang );
790 FillAlgorHdl( &aLbLanguage ); // get algorithms, select default
791 if ( rSortData.aCollatorAlgorithm.Len() )
792 aLbAlgorithm.SelectEntry( pColRes->GetTranslation( rSortData.aCollatorAlgorithm ) );
793
794 if ( pDoc && !rSortData.bInplace )
795 {
796 String aStr;
797 USHORT nFormat = (rSortData.nDestTab != pViewData->GetTabNo())
798 ? SCR_ABS_3D
799 : SCR_ABS;
800
801 theOutPos.Set( rSortData.nDestCol,
802 rSortData.nDestRow,
803 rSortData.nDestTab );
804
805 theOutPos.Format( aStr, nFormat, pDoc, pDoc->GetAddressConvention() );
806 aBtnCopyResult.Check();
807 aLbOutPos.Enable();
808 aEdOutPos.Enable();
809 aEdOutPos.SetText( aStr );
810 EdOutPosModHdl( &aEdOutPos );
811 aEdOutPos.GrabFocus();
812 aEdOutPos.SetSelection( Selection( 0, SELECTION_MAX ) );
813 }
814 else
815 {
816 aBtnCopyResult.Check( FALSE );
817 aLbOutPos.Disable();
818 aEdOutPos.Disable();
819 aEdOutPos.SetText( EMPTY_STRING );
820 }
821 }
822
823 // -----------------------------------------------------------------------
824
FillItemSet(SfxItemSet & rArgSet)825 BOOL __EXPORT ScTabPageSortOptions::FillItemSet( SfxItemSet& rArgSet )
826 {
827 ScSortParam theSortData = rSortData;
828 if (pDlg)
829 {
830 const SfxItemSet* pExample = pDlg->GetExampleSet();
831 const SfxPoolItem* pItem;
832 if ( pExample && pExample->GetItemState( nWhichSort, TRUE, &pItem ) == SFX_ITEM_SET )
833 theSortData = ((const ScSortItem*)pItem)->GetSortData();
834 }
835
836 theSortData.bByRow = aBtnTopDown.IsChecked();
837 theSortData.bHasHeader = aBtnHeader.IsChecked();
838 theSortData.bCaseSens = aBtnCase.IsChecked();
839 theSortData.bNaturalSort = aBtnNaturalSort.IsChecked();
840 theSortData.bIncludePattern = aBtnFormats.IsChecked();
841 theSortData.bInplace = !aBtnCopyResult.IsChecked();
842 theSortData.nDestCol = theOutPos.Col();
843 theSortData.nDestRow = theOutPos.Row();
844 theSortData.nDestTab = theOutPos.Tab();
845 theSortData.bUserDef = aBtnSortUser.IsChecked();
846 theSortData.nUserIndex = (aBtnSortUser.IsChecked())
847 ? aLbSortUser.GetSelectEntryPos()
848 : 0;
849
850 // get locale
851 LanguageType eLang = aLbLanguage.GetSelectLanguage();
852 theSortData.aCollatorLocale = MsLangId::convertLanguageToLocale( eLang, false );
853
854 // get algorithm
855 String sAlg;
856 if ( eLang != LANGUAGE_SYSTEM )
857 {
858 uno::Sequence<rtl::OUString> aAlgos = pColWrap->listCollatorAlgorithms(
859 theSortData.aCollatorLocale );
860 USHORT nSel = aLbAlgorithm.GetSelectEntryPos();
861 if ( nSel < aAlgos.getLength() )
862 sAlg = aAlgos[nSel];
863 }
864 theSortData.aCollatorAlgorithm = sAlg;
865
866 #if !TEST_LAYOUT
867 rArgSet.Put( ScSortItem( SCITEM_SORTDATA, &theSortData ) );
868 #endif /* TEST_LAYOUT */
869 return TRUE;
870 }
871
872 // -----------------------------------------------------------------------
873
874 // fuer Datenaustausch ohne Dialog-Umweg: (! noch zu tun !)
875 // void ScTabPageSortOptions::ActivatePage( const SfxItemSet& rSet )
ActivatePage()876 void __EXPORT ScTabPageSortOptions::ActivatePage()
877 {
878 if ( pDlg )
879 {
880 if ( aBtnHeader.IsChecked() != pDlg->GetHeaders() )
881 {
882 aBtnHeader.Check( pDlg->GetHeaders() );
883 }
884
885 if ( aBtnTopDown.IsChecked() != pDlg->GetByRows() )
886 {
887 aBtnTopDown.Check( pDlg->GetByRows() );
888 aBtnLeftRight.Check( !pDlg->GetByRows() );
889 }
890
891 aBtnHeader.SetText( (pDlg->GetByRows())
892 ? aStrColLabel
893 : aStrRowLabel );
894 }
895 }
896
897 // -----------------------------------------------------------------------
898
DeactivatePage(SfxItemSet * pSetP)899 int __EXPORT ScTabPageSortOptions::DeactivatePage( SfxItemSet* pSetP )
900 {
901 BOOL bPosInputOk = TRUE;
902
903 if ( aBtnCopyResult.IsChecked() )
904 {
905 String thePosStr = aEdOutPos.GetText();
906 ScAddress thePos;
907 xub_StrLen nColonPos = thePosStr.Search( ':' );
908
909 if ( STRING_NOTFOUND != nColonPos )
910 thePosStr.Erase( nColonPos );
911
912 if ( pViewData )
913 {
914 // visible table is default for input without table
915 // must be changed to GetRefTabNo when sorting has RefInput!
916 thePos.SetTab( pViewData->GetTabNo() );
917 }
918
919 USHORT nResult = thePos.Parse( thePosStr, pDoc, pDoc->GetAddressConvention() );
920
921 bPosInputOk = ( SCA_VALID == (nResult & SCA_VALID) );
922
923 if ( !bPosInputOk )
924 {
925 #if !ENABLE_LAYOUT
926 ErrorBox( this, WinBits( WB_OK | WB_DEF_OK ),
927 ScGlobal::GetRscString( STR_INVALID_TABREF )
928 ).Execute();
929 #endif /* ENABLE_LAYOUT */
930 aEdOutPos.GrabFocus();
931 aEdOutPos.SetSelection( Selection( 0, SELECTION_MAX ) );
932 theOutPos.Set(0,0,0);
933 }
934 else
935 {
936 aEdOutPos.SetText( thePosStr );
937 theOutPos = thePos;
938 }
939 }
940
941 if ( pDlg && bPosInputOk )
942 {
943 pDlg->SetHeaders( aBtnHeader.IsChecked() );
944 pDlg->SetByRows ( aBtnTopDown.IsChecked() );
945 }
946
947 if ( pSetP && bPosInputOk )
948 FillItemSet( *pSetP );
949
950 return bPosInputOk ? SfxTabPage::LEAVE_PAGE : SfxTabPage::KEEP_PAGE;
951 }
952
953 // -----------------------------------------------------------------------
954
FillUserSortListBox()955 void ScTabPageSortOptions::FillUserSortListBox()
956 {
957 ScUserList* pUserLists = ScGlobal::GetUserList();
958
959 aLbSortUser.Clear();
960 if ( pUserLists )
961 {
962 USHORT nCount = pUserLists->GetCount();
963 if ( nCount > 0 )
964 for ( USHORT i=0; i<nCount; i++ )
965 aLbSortUser.InsertEntry( (*pUserLists)[i]->GetString() );
966 }
967 }
968
969 // -----------------------------------------------------------------------
970 // Handler:
971
IMPL_LINK(ScTabPageSortOptions,EnableHdl,CheckBox *,pBox)972 IMPL_LINK( ScTabPageSortOptions, EnableHdl, CheckBox *, pBox )
973 {
974 if ( pBox == &aBtnCopyResult )
975 {
976 if ( pBox->IsChecked() )
977 {
978 aLbOutPos.Enable();
979 aEdOutPos.Enable();
980 aEdOutPos.GrabFocus();
981 }
982 else
983 {
984 aLbOutPos.Disable();
985 aEdOutPos.Disable();
986 }
987 }
988 else if ( pBox == &aBtnSortUser )
989 {
990 if ( pBox->IsChecked() )
991 {
992 aLbSortUser.Enable();
993 aLbSortUser.GrabFocus();
994 }
995 else
996 aLbSortUser.Disable();
997 }
998 return 0;
999 }
1000
1001 // -----------------------------------------------------------------------
1002
IMPL_LINK(ScTabPageSortOptions,SelOutPosHdl,ListBox *,pLb)1003 IMPL_LINK( ScTabPageSortOptions, SelOutPosHdl, ListBox *, pLb )
1004 {
1005 if ( pLb == &aLbOutPos )
1006 {
1007 String aString;
1008 USHORT nSelPos = aLbOutPos.GetSelectEntryPos();
1009
1010 if ( nSelPos > 0 )
1011 aString = *(String*)aLbOutPos.GetEntryData( nSelPos );
1012
1013 aEdOutPos.SetText( aString );
1014 }
1015 return 0;
1016 }
1017
1018 // -----------------------------------------------------------------------
1019
IMPL_LINK(ScTabPageSortOptions,SortDirHdl,RadioButton *,pBtn)1020 IMPL_LINK( ScTabPageSortOptions, SortDirHdl, RadioButton *, pBtn )
1021 {
1022 if ( pBtn == &aBtnTopDown )
1023 {
1024 aBtnHeader.SetText( aStrColLabel );
1025 }
1026 else if ( pBtn == &aBtnLeftRight )
1027 {
1028 aBtnHeader.SetText( aStrRowLabel );
1029 }
1030 return 0;
1031 }
1032
1033 // -----------------------------------------------------------------------
1034
EdOutPosModHdl(Edit * pEd)1035 void __EXPORT ScTabPageSortOptions::EdOutPosModHdl( Edit* pEd )
1036 {
1037 if ( pEd == &aEdOutPos )
1038 {
1039 String theCurPosStr = aEdOutPos.GetText();
1040 USHORT nResult = ScAddress().Parse( theCurPosStr, pDoc, pDoc->GetAddressConvention() );
1041
1042 if ( SCA_VALID == (nResult & SCA_VALID) )
1043 {
1044 String* pStr = NULL;
1045 BOOL bFound = FALSE;
1046 USHORT i = 0;
1047 USHORT nCount = aLbOutPos.GetEntryCount();
1048
1049 for ( i=2; i<nCount && !bFound; i++ )
1050 {
1051 pStr = (String*)aLbOutPos.GetEntryData( i );
1052 bFound = (theCurPosStr == *pStr);
1053 }
1054
1055 if ( bFound )
1056 aLbOutPos.SelectEntryPos( --i );
1057 else
1058 aLbOutPos.SelectEntryPos( 0 );
1059 }
1060 }
1061 }
1062
1063 // -----------------------------------------------------------------------
1064
IMPL_LINK(ScTabPageSortOptions,FillAlgorHdl,void *,EMPTYARG)1065 IMPL_LINK( ScTabPageSortOptions, FillAlgorHdl, void *, EMPTYARG )
1066 {
1067 aLbAlgorithm.SetUpdateMode( FALSE );
1068 aLbAlgorithm.Clear();
1069
1070 LanguageType eLang = aLbLanguage.GetSelectLanguage();
1071 if ( eLang == LANGUAGE_SYSTEM )
1072 {
1073 // for LANGUAGE_SYSTEM no algorithm can be selected because
1074 // it wouldn't necessarily exist for other languages
1075 // -> leave list box empty if LANGUAGE_SYSTEM is selected
1076 aFtAlgorithm.Enable( FALSE ); // nothing to select
1077 aLbAlgorithm.Enable( FALSE ); // nothing to select
1078 }
1079 else
1080 {
1081 lang::Locale aLocale( MsLangId::convertLanguageToLocale( eLang ));
1082 uno::Sequence<rtl::OUString> aAlgos = pColWrap->listCollatorAlgorithms( aLocale );
1083
1084 long nCount = aAlgos.getLength();
1085 const rtl::OUString* pArray = aAlgos.getConstArray();
1086 for (long i=0; i<nCount; i++)
1087 {
1088 String sAlg = pArray[i];
1089 String sUser = pColRes->GetTranslation( sAlg );
1090 aLbAlgorithm.InsertEntry( sUser, LISTBOX_APPEND );
1091 }
1092 aLbAlgorithm.SelectEntryPos( 0 ); // first entry is default
1093 aFtAlgorithm.Enable( nCount > 1 ); // enable only if there is a choice
1094 aLbAlgorithm.Enable( nCount > 1 ); // enable only if there is a choice
1095 }
1096
1097 aLbAlgorithm.SetUpdateMode( TRUE );
1098 return 0;
1099 }
1100
1101
1102