LibreOffice Module sc (master) 1
tpsort.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#undef SC_DLLIMPLEMENTATION
21
22#include <vcl/svapp.hxx>
23#include <vcl/weld.hxx>
28#include <osl/diagnose.h>
29
30#include <scitems.hxx>
31#include <uiitems.hxx>
32#include <viewdata.hxx>
33#include <document.hxx>
34#include <global.hxx>
35#include <dbdata.hxx>
36#include <userlist.hxx>
37#include <rangeutl.hxx>
38#include <scresid.hxx>
39#include <sc.hrc>
40#include <strings.hrc>
41#include <globstr.hrc>
42
43#include <sortkeydlg.hxx>
44
45#include <sortdlg.hxx>
46
47#include <tpsort.hxx>
48
49using namespace com::sun::star;
50
51/*
52 * Since the settings on the second Tab Page (Options) effects
53 * the first Tab Page, there must be a way for it to communicate with the
54 * other Page.
55 *
56 * At the moment this problem is solved through using two data members of the
57 * Tab Pages. If a page is enabled / disabled, it compares this data member
58 * with its own state (-> Activate() / Deactivate()).
59 *
60 * In the meantime the class SfxTabPage offers the following method:
61 *
62 * virtual sal_Bool HasExchangeSupport() const; -> return sal_True;
63 * virtual void ActivatePage(const SfxItemSet &);
64 * virtual int DeactivatePage(SfxItemSet * = 0);
65 *
66 * This still needs to be changed!
67 */
68
69// Sort Criteria Tab page
70
72 : SfxTabPage(pPage, pController, "modules/scalc/ui/sortcriteriapage.ui", "SortCriteriaPage", &rArgSet)
73 ,
74
75 m_aIdle("ScTabPageSortFields Scroll To End Idle"),
76 aStrUndefined ( ScResId( SCSTR_UNDEFINED ) ),
77 aStrColumn ( ScResId( SCSTR_COLUMN ) ),
78 aStrRow ( ScResId( SCSTR_ROW ) ),
79 aStrRowLabel ( ScResId( SCSTR_ROW_LABEL ) ),
80 aStrColLabel ( ScResId( SCSTR_COL_LABEL ) ),
81
82 nWhichSort ( rArgSet.GetPool()->GetWhich( SID_SORT ) ),
83 pViewData ( nullptr ),
84 aSortData ( rArgSet.Get( nWhichSort ).GetSortData() ),
85 nFieldCount ( 0 ),
86 // show actual size of the sorting keys without limiting them to the default size
87 nSortKeyCount(std::max(aSortData.GetSortKeyCount(), static_cast<sal_uInt16>(DEFSORT)))
88
89 , m_xTop(m_xBuilder->weld_container("TopWindow"))
90 , m_xBtnHeader(m_xBuilder->weld_check_button("cbHeader"))
91 , m_xBtnTopDown(m_xBuilder->weld_radio_button("rbTopDown"))
92 , m_xBtnLeftRight(m_xBuilder->weld_radio_button("rbLeftRight"))
93 , m_xScrolledWindow(m_xBuilder->weld_scrolled_window("SortCriteriaPage"))
94 , m_xBox(m_xBuilder->weld_container("SortKeyWindow"))
95 , m_aSortWin(m_xBox.get())
96{
97 // tdf#147722 set some nominal small default height so the height adapts
98 // to all the other contents and the natural height of this widget isn't
99 // an input into the overall size
100 m_xScrolledWindow->set_size_request(-1, 42);
101
102 Init();
103
104 m_aIdle.SetInvokeHandler(LINK(this, ScTabPageSortFields, ScrollToEndHdl));
105
107}
108
110{
112 m_xBox.reset();
113 m_xScrolledWindow.reset();
114}
115
117{
118 // Check whether the field that is passed on is a database field:
119 ScDocument* pDoc = pViewData ? &pViewData->GetDocument() : nullptr;
120 if ( pDoc )
121 {
122 ScDBCollection* pDBColl = pDoc->GetDBCollection();
123 const SCTAB nCurTab = pViewData->GetTabNo();
124 if ( pDBColl )
125 {
126 ScDBData* pDBData
127 = pDBColl->GetDBAtArea( nCurTab,
130 if ( pDBData )
131 {
132 m_xBtnHeader->set_active(pDBData->HasHeader());
133 }
134 }
135 }
136 m_xBtnHeader->set_label(aStrColLabel);
137
138 Link<weld::Toggleable&,void> aLink = LINK(this, ScTabPageSortFields, SortDirHdl );
139 m_xBtnTopDown->connect_toggled( aLink );
140 m_xBtnLeftRight->connect_toggled( aLink );
141 m_xBtnHeader->connect_toggled( aLink );
142
143 const ScSortItem& rSortItem = GetItemSet().Get( nWhichSort );
144
145 pViewData = rSortItem.GetViewData();
146 OSL_ENSURE( pViewData, "ViewData not found!" );
147
148 nFieldArr.push_back( 0 );
149
150 // Create three sort key dialogs by default
151 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
152 {
153 AddSortKey(i+1);
154 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->connect_changed(LINK(this, ScTabPageSortFields, SelectHdl));
155 }
156}
157
158std::unique_ptr<SfxTabPage> ScTabPageSortFields::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* pArgSet)
159{
160 return std::make_unique<ScTabPageSortFields>(pPage, pController, *pArgSet);
161}
162
163void ScTabPageSortFields::Reset( const SfxItemSet* /* rArgSet */ )
164{
165 m_xBtnHeader->set_active( aSortData.bHasHeader );
166 m_xBtnTopDown->set_active( aSortData.bByRow );
167 m_xBtnLeftRight->set_active( !aSortData.bByRow );
168
169 if (m_aSortWin.m_aSortKeyItems[0]->m_xLbSort->get_count() == 0)
171
172 // ListBox selection:
173 if (!aSortData.maKeyState.empty() && aSortData.maKeyState[0].bDoSort)
174 {
175 // Make sure that the all sort keys are reset
176 for ( sal_uInt16 i=nSortKeyCount; i<aSortData.GetSortKeyCount(); i++ )
177 {
178 AddSortKey(i+1);
179 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->connect_changed( LINK( this,
180 ScTabPageSortFields, SelectHdl ) );
181 }
184
185 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
186 {
187 if (aSortData.maKeyState[i].bDoSort )
188 {
189 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->set_active( GetFieldSelPos(
190 aSortData.maKeyState[i].nField ) );
191 (aSortData.maKeyState[i].bAscending)
192 ? m_aSortWin.m_aSortKeyItems[i]->m_xBtnUp->set_active(true)
193 : m_aSortWin.m_aSortKeyItems[i]->m_xBtnDown->set_active(true);
194 }
195 else
196 {
197 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->set_active(0); // Select none
198 m_aSortWin.m_aSortKeyItems[i]->m_xBtnUp->set_active(true);
199 }
200 }
201
202 // Enable or disable field depending on preceding Listbox selection
203 m_aSortWin.m_aSortKeyItems[0]->EnableField();
204 for ( sal_uInt16 i=1; i<nSortKeyCount; i++ )
205 if ( m_aSortWin.m_aSortKeyItems[i - 1]->m_xLbSort->get_active() == 0 )
206 m_aSortWin.m_aSortKeyItems[i]->DisableField();
207 else
208 m_aSortWin.m_aSortKeyItems[i]->EnableField();
209 }
210 else
211 {
212 SCCOL nCol = pViewData->GetCurX();
213
214 if( nCol < aSortData.nCol1 )
215 nCol = aSortData.nCol1;
216 else if( nCol > aSortData.nCol2 )
217 nCol = aSortData.nCol2;
218
219 sal_uInt16 nSort1Pos = nCol - aSortData.nCol1+1;
220
221 m_aSortWin.m_aSortKeyItems[0]->m_xLbSort->set_active(nSort1Pos);
222 for ( sal_uInt16 i=1; i<nSortKeyCount; i++ )
223 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->set_active(0);
224
225 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
226 m_aSortWin.m_aSortKeyItems[i]->m_xBtnUp->set_active(true);
227
228 m_aSortWin.m_aSortKeyItems[0]->EnableField();
229 m_aSortWin.m_aSortKeyItems[1]->EnableField();
230 for ( sal_uInt16 i=2; i<nSortKeyCount; i++ )
231 m_aSortWin.m_aSortKeyItems[i]->DisableField();
232 }
233
234 // Make sure that there is always a last undefined sort key
235 if (m_aSortWin.m_aSortKeyItems[nSortKeyCount - 1]->m_xLbSort->get_active() > 0)
237}
238
240{
241 ScSortParam aNewSortData = aSortData;
242
243 const SfxItemSet* pExample = GetDialogExampleSet();
244 if (pExample)
245 {
246 if (const ScSortItem* pItem = pExample->GetItemIfSet(nWhichSort))
247 {
248 ScSortParam aTempData = pItem->GetSortData();
249 aTempData.maKeyState = aNewSortData.maKeyState;
250 aNewSortData = aTempData;
251 }
252 }
253 aNewSortData.bByRow = m_xBtnTopDown->get_active();
254 aNewSortData.bHasHeader = m_xBtnHeader->get_active();
255
256 std::vector<sal_Int32> nSortPos;
257
258 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
259 {
260 nSortPos.push_back(m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->get_active());
261 if (nSortPos[i] == -1) nSortPos[i] = 0;
262 }
263
264 if( nSortKeyCount >= aNewSortData.GetSortKeyCount() )
265 aNewSortData.maKeyState.resize(nSortKeyCount);
266
267 if ( nSortPos[0] > 0 )
268 {
269 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
270 {
271 aNewSortData.maKeyState[i].bDoSort = (nSortPos[i] > 0);
272 aNewSortData.maKeyState[i].nField = nFieldArr[nSortPos[i]];
273 aNewSortData.maKeyState[i].bAscending = m_aSortWin.m_aSortKeyItems[i]->m_xBtnUp->get_active();
274 }
275 }
276 else
277 {
278 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
279 aNewSortData.maKeyState[i].bDoSort = false;
280 }
281
282 rArgSet->Put( ScSortItem( SCITEM_SORTDATA, nullptr, &aNewSortData ) );
283
284 return true;
285}
286
287// for data exchange without dialogue detour:
289{
290 // Refresh local copy with shared data
291 aSortData = rSet.Get( SCITEM_SORTDATA ).GetSortData();
292
293 m_xBtnHeader->set_active( aSortData.bHasHeader );
294 m_xBtnTopDown->set_active( aSortData.bByRow );
295 m_xBtnLeftRight->set_active( !aSortData.bByRow );
296}
297
299{
300 if ( pSetP )
301 FillItemSet( pSetP );
302
303 return DeactivateRC::LeavePage;
304}
305
306void ScTabPageSortFields::FillFieldLists( sal_uInt16 nStartField )
307{
308 if ( !pViewData )
309 return;
310
312
313 for (sal_uInt16 j = nStartField; j < nSortKeyCount; ++j)
314 {
315 m_aSortWin.m_aSortKeyItems[j]->m_xLabel->set_label(aSortData.bByRow ? aStrColumn : aStrRow);
316 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->clear();
317 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->freeze();
318 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->append_text(aStrUndefined);
319 }
320
321 SCCOL nFirstSortCol = aSortData.nCol1;
322 SCROW nFirstSortRow = aSortData.nRow1;
323 SCTAB nTab = pViewData->GetTabNo();
324 sal_uInt16 i = 1;
325 nFieldArr.clear();
326 nFieldArr.push_back(0);
327
328 if ( aSortData.bByRow )
329 {
330 OUString aFieldName;
331 SCCOL nMaxCol = rDoc.ClampToAllocatedColumns(nTab, aSortData.nCol2);
332 SCCOL col;
333
334 for ( col=nFirstSortCol; col<=nMaxCol && i<SC_MAXFIELDS(rDoc.GetSheetLimits()); col++ )
335 {
336 aFieldName = rDoc.GetString(col, nFirstSortRow, nTab);
337 if ( !aSortData.bHasHeader || aFieldName.isEmpty() )
338 aFieldName = ScColToAlpha( col );
339 nFieldArr.push_back( col );
340
341 for ( sal_uInt16 j=nStartField; j<nSortKeyCount; j++ )
342 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->insert_text(i, aFieldName);
343
344 i++;
345 }
346 }
347 else
348 {
349 OUString aFieldName;
350 SCROW nMaxRow = aSortData.nRow2;
351 SCROW row;
352
353 for ( row=nFirstSortRow; row<=nMaxRow && i<SC_MAXFIELDS(rDoc.GetSheetLimits()); row++ )
354 {
355 aFieldName = rDoc.GetString(nFirstSortCol, row, nTab);
356 if ( !aSortData.bHasHeader || aFieldName.isEmpty() )
357 aFieldName = OUString::number( row+1);
358 nFieldArr.push_back( row );
359
360 for ( sal_uInt16 j=nStartField; j<nSortKeyCount; j++ )
361 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->insert_text(i, aFieldName);
362
363 i++;
364 }
365 }
366
367 for (sal_uInt16 j=nStartField; j < nSortKeyCount; ++j)
368 {
369 m_aSortWin.m_aSortKeyItems[j]->m_xLbSort->thaw();
370 }
371
372 nFieldCount = i;
373}
374
376{
377 sal_uInt16 nFieldPos = 0;
378 bool bFound = false;
379
380 for ( sal_uInt16 n=1; n<nFieldCount && !bFound; n++ )
381 {
382 if ( nFieldArr[n] == nField )
383 {
384 nFieldPos = n;
385 bFound = true;
386 }
387 }
388
389 return nFieldPos;
390}
391
393{
394 // Extend local SortParam copy
395 const ScSortKeyState atempKeyState = { 0, false, true };
396 aSortData.maKeyState.push_back( atempKeyState );
397
398 // Add Sort Key Item
401 m_aSortWin.m_aSortKeyItems[nItem]->m_xLbSort->connect_changed(
402 LINK( this, ScTabPageSortFields, SelectHdl ) );
403
404 FillFieldLists( nItem );
405
406 // Set Status
407 m_aSortWin.m_aSortKeyItems[nItem]->m_xBtnUp->set_active(true);
408 m_aSortWin.m_aSortKeyItems[nItem]->m_xLbSort->set_active(0);
409}
410
411// Handler:
412
414{
415 if ( (m_xBtnTopDown->get_active() != aSortData.bByRow) || (m_xBtnHeader->get_active() != aSortData.bHasHeader))
416 {
417 if (m_xBtnTopDown->get_active())
418 m_xBtnHeader->set_label(aStrColLabel);
419 else
420 m_xBtnHeader->set_label(aStrRowLabel);
421
422 aSortData.bByRow = m_xBtnTopDown->get_active();
423 aSortData.bHasHeader = m_xBtnHeader->get_active();
424
425 // remember selection
426 std::vector<sal_uInt16> nCurSel;
427 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
428 nCurSel.push_back( m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->get_active() );
429
430 FillFieldLists(0);
431
432 for ( sal_uInt16 i=0; i<nSortKeyCount; i++ )
433 m_aSortWin.m_aSortKeyItems[i]->m_xLbSort->set_active(nCurSel[i]);
434 }
435}
436
438{
439 OUString aSelEntry = rLb.get_active_text();
440 ScSortKeyItems::iterator pIter;
441
442 // If last listbox is enabled add one item
443 if (m_aSortWin.m_aSortKeyItems.back()->m_xLbSort.get() == &rLb)
444 {
445 if ( aSelEntry != aStrUndefined )
446 {
447 SetLastSortKey( nSortKeyCount );
448 return;
449 }
450 }
451
452 // Find selected listbox
453 pIter = std::find_if(m_aSortWin.m_aSortKeyItems.begin(), m_aSortWin.m_aSortKeyItems.end(),
454 [&rLb](const ScSortKeyItems::value_type& rItem) { return rItem->m_xLbSort.get() == &rLb; });
455
456 if (pIter == m_aSortWin.m_aSortKeyItems.end())
457 return;
458
459 // If not selecting the last Listbox, modify the succeeding ones
460 ++pIter;
461 if ( std::distance(m_aSortWin.m_aSortKeyItems.begin(), pIter) >= nSortKeyCount )
462 return;
463
464 if ( aSelEntry == aStrUndefined )
465 {
466 for ( ; pIter != m_aSortWin.m_aSortKeyItems.end(); ++pIter )
467 {
468 (*pIter)->m_xLbSort->set_active(0);
469
470 (*pIter)->DisableField();
471 }
472 }
473 else
474 {
475 (*pIter)->EnableField();
476 }
477}
478
480{
481 m_xScrolledWindow->vadjustment_set_value(m_xScrolledWindow->vadjustment_get_upper());
482}
483
484void ScTabPageSortFields::AddSortKey( sal_uInt16 nItem )
485{
486 m_aSortWin.AddSortKey(nItem);
487 m_aIdle.Start();
488}
489
490// Sort option Tab Page:
491
493 : SfxTabPage(pPage, pController, "modules/scalc/ui/sortoptionspage.ui", "SortOptionsPage", &rArgSet)
494 , aStrUndefined(ScResId(SCSTR_UNDEFINED))
495 , nWhichSort(rArgSet.GetPool()->GetWhich(SID_SORT))
496 , aSortData(rArgSet.Get(nWhichSort).GetSortData())
497 , pViewData(nullptr)
498 , pDoc(nullptr)
499 , m_xBtnCase(m_xBuilder->weld_check_button("case"))
500 , m_xBtnFormats(m_xBuilder->weld_check_button("formats"))
501 , m_xBtnNaturalSort(m_xBuilder->weld_check_button("naturalsort"))
502 , m_xBtnCopyResult(m_xBuilder->weld_check_button("copyresult"))
503 , m_xLbOutPos(m_xBuilder->weld_combo_box("outarealb"))
504 , m_xEdOutPos(m_xBuilder->weld_entry("outareaed"))
505 , m_xBtnSortUser(m_xBuilder->weld_check_button("sortuser"))
506 , m_xLbSortUser(m_xBuilder->weld_combo_box("sortuserlb"))
507 , m_xLbLanguage(new SvxLanguageBox(m_xBuilder->weld_combo_box("language")))
508 , m_xFtAlgorithm(m_xBuilder->weld_label("algorithmft"))
509 , m_xLbAlgorithm(m_xBuilder->weld_combo_box("algorithmlb"))
510 , m_xBtnIncComments(m_xBuilder->weld_check_button("includenotes"))
511 , m_xBtnIncImages(m_xBuilder->weld_check_button("includeimages"))
512{
513 m_xLbSortUser->set_size_request(m_xLbSortUser->get_approximate_digit_width() * 50, -1);
514 m_xLbSortUser->set_accessible_description(ScResId(STR_A11Y_DESC_SORTUSER));
515 Init();
517}
518
520{
521 // CollatorResource has user-visible names for sort algorithms
522 m_xColRes.reset(new CollatorResource);
523
526
527 const ScSortItem& rSortItem = GetItemSet().Get( nWhichSort );
528
529 m_xLbOutPos->connect_changed( LINK( this, ScTabPageSortOptions, SelOutPosHdl ) );
530 m_xBtnCopyResult->connect_toggled( LINK( this, ScTabPageSortOptions, EnableHdl ) );
531 m_xBtnSortUser->connect_toggled( LINK( this, ScTabPageSortOptions, EnableHdl ) );
532 m_xLbLanguage->connect_changed( LINK( this, ScTabPageSortOptions, FillAlgorHdl ) );
533
534 pViewData = rSortItem.GetViewData();
535 pDoc = pViewData ? &pViewData->GetDocument() : nullptr;
536
537 OSL_ENSURE( pViewData, "ViewData not found! :-/" );
538
539 if ( pViewData && pDoc )
540 {
542
543 m_xLbOutPos->clear();
544 m_xLbOutPos->append_text(aStrUndefined);
545 m_xLbOutPos->set_sensitive(false);
546
547 ScAreaNameIterator aIter( *pDoc );
548 OUString aName;
549 ScRange aRange;
550 while ( aIter.Next( aName, aRange ) )
551 {
552 OUString aRefStr(aRange.aStart.Format(ScRefFlags::ADDR_ABS_3D, pDoc, eConv));
553 m_xLbOutPos->append(aRefStr, aName);
554 }
555
556 m_xLbOutPos->set_active(0);
557 m_xEdOutPos->set_text(OUString());
558 }
559
561
562 // get available languages
563
564 m_xLbLanguage->SetLanguageList( SvxLanguageListFlags::ALL | SvxLanguageListFlags::ONLY_KNOWN, false );
565 m_xLbLanguage->InsertLanguage( LANGUAGE_SYSTEM );
566}
567
568std::unique_ptr<SfxTabPage> ScTabPageSortOptions::Create(weld::Container* pPage, weld::DialogController* pController, const SfxItemSet* rArgSet)
569{
570 return std::make_unique<ScTabPageSortOptions>(pPage, pController, *rArgSet);
571}
572
573void ScTabPageSortOptions::Reset( const SfxItemSet* /* rArgSet */ )
574{
575 if ( aSortData.bUserDef )
576 {
577 m_xBtnSortUser->set_active(true);
578 m_xLbSortUser->set_sensitive(true);
580 }
581 else
582 {
583 m_xBtnSortUser->set_active(false);
584 m_xLbSortUser->set_sensitive(false);
585 m_xLbSortUser->set_active(0);
586 }
587
588 m_xBtnCase->set_active( aSortData.bCaseSens );
593
595 if ( eLang == LANGUAGE_DONTKNOW )
596 eLang = LANGUAGE_SYSTEM;
597 m_xLbLanguage->set_active_id(eLang);
598 FillAlgor(); // get algorithms, select default
599 if ( !aSortData.aCollatorAlgorithm.isEmpty() )
600 m_xLbAlgorithm->set_active_text(m_xColRes->GetTranslation(aSortData.aCollatorAlgorithm));
601
602 if ( pDoc && !aSortData.bInplace )
603 {
607
611
612 OUString aStr(theOutPos.Format(nFormat, pDoc, pDoc->GetAddressConvention()));
613 m_xBtnCopyResult->set_active(true);
614 m_xLbOutPos->set_sensitive(true);
615 m_xEdOutPos->set_sensitive(true);
616 m_xEdOutPos->set_text( aStr );
618 m_xEdOutPos->grab_focus();
619 m_xEdOutPos->select_region(0, -1);
620 }
621 else
622 {
623 m_xBtnCopyResult->set_active( false );
624 m_xLbOutPos->set_sensitive(false);
625 m_xEdOutPos->set_sensitive(false);
626 m_xEdOutPos->set_text( OUString() );
627 }
628}
629
631{
632 // Create local copy of ScParam
633 ScSortParam aNewSortData = aSortData;
634
635 const SfxItemSet* pExample = GetDialogExampleSet();
636 if (pExample)
637 {
638 if (const ScSortItem* pSortItem = pExample->GetItemIfSet(nWhichSort))
639 aNewSortData = pSortItem->GetSortData();
640 }
641 aNewSortData.bCaseSens = m_xBtnCase->get_active();
642 aNewSortData.bNaturalSort = m_xBtnNaturalSort->get_active();
643 aNewSortData.aDataAreaExtras.mbCellNotes = m_xBtnIncComments->get_active();
644 aNewSortData.aDataAreaExtras.mbCellDrawObjects = m_xBtnIncImages->get_active();
645 aNewSortData.aDataAreaExtras.mbCellFormats = m_xBtnFormats->get_active();
646 aNewSortData.bInplace = !m_xBtnCopyResult->get_active();
647 aNewSortData.nDestCol = theOutPos.Col();
648 aNewSortData.nDestRow = theOutPos.Row();
649 aNewSortData.nDestTab = theOutPos.Tab();
650 aNewSortData.bUserDef = m_xBtnSortUser->get_active();
651 aNewSortData.nUserIndex = (m_xBtnSortUser->get_active())
652 ? m_xLbSortUser->get_active()
653 : 0;
654
655 // get locale
656 LanguageType eLang = m_xLbLanguage->get_active_id();
657 aNewSortData.aCollatorLocale = LanguageTag::convertToLocale( eLang, false);
658
659 // get algorithm
660 OUString sAlg;
661 if ( eLang != LANGUAGE_SYSTEM )
662 {
663 uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms(
664 aNewSortData.aCollatorLocale );
665 const int nSel = m_xLbAlgorithm->get_active();
666 if ( nSel < aAlgos.getLength() )
667 sAlg = aAlgos[nSel];
668 }
669 aNewSortData.aCollatorAlgorithm = sAlg;
670
671 rArgSet->Put( ScSortItem( SCITEM_SORTDATA, &aNewSortData ) );
672
673 return true;
674}
675
676// for data exchange without dialogue detour:
678{
679 // Refresh local copy with shared data
680 aSortData = rSet.Get( SCITEM_SORTDATA ).GetSortData();
681 ScSortDlg* pDlg = static_cast<ScSortDlg*>(GetDialogController());
682 if (!pDlg)
683 return;
684}
685
687{
688 bool bPosInputOk = true;
689
690 if ( m_xBtnCopyResult->get_active() )
691 {
692 OUString thePosStr = m_xEdOutPos->get_text();
693 ScAddress thePos;
694 sal_Int32 nColonPos = thePosStr.indexOf( ':' );
695
696 if ( -1 != nColonPos )
697 thePosStr = thePosStr.copy( 0, nColonPos );
698
699 if ( pViewData )
700 {
701 // visible table is default for input without table
702 // must be changed to GetRefTabNo when sorting has RefInput!
703 thePos.SetTab( pViewData->GetTabNo() );
704 }
705
706 ScRefFlags nResult = thePos.Parse( thePosStr, *pDoc, pDoc->GetAddressConvention() );
707
708 bPosInputOk = (nResult & ScRefFlags::VALID) == ScRefFlags::VALID;
709
710 if ( !bPosInputOk )
711 {
712 std::unique_ptr<weld::MessageDialog> xBox(Application::CreateMessageDialog(GetFrameWeld(),
713 VclMessageType::Warning, VclButtonsType::Ok,
714 ScResId(STR_INVALID_TABREF)));
715 xBox->run();
716 m_xEdOutPos->grab_focus();
717 m_xEdOutPos->select_region(0, -1);
718 theOutPos.Set(0,0,0);
719 }
720 else
721 {
722 m_xEdOutPos->set_text(thePosStr);
723 theOutPos = thePos;
724 }
725 }
726
727 if ( pSetP && bPosInputOk )
728 FillItemSet( pSetP );
729
730 return bPosInputOk ? DeactivateRC::LeavePage : DeactivateRC::KeepPage;
731}
732
734{
735 ScUserList* pUserLists = ScGlobal::GetUserList();
736
737 m_xLbSortUser->clear();
738 if ( pUserLists )
739 {
740 size_t nCount = pUserLists->size();
741 for (size_t i=0; i<nCount; ++i)
742 m_xLbSortUser->append_text((*pUserLists)[i].GetString());
743 }
744}
745
746// Handler:
747
748IMPL_LINK( ScTabPageSortOptions, EnableHdl, weld::Toggleable&, rButton, void )
749{
750 if (&rButton == m_xBtnCopyResult.get())
751 {
752 if (rButton.get_active())
753 {
754 m_xLbOutPos->set_sensitive(true);
755 m_xEdOutPos->set_sensitive(true);
756 m_xEdOutPos->grab_focus();
757 }
758 else
759 {
760 m_xLbOutPos->set_sensitive(false);
761 m_xEdOutPos->set_sensitive(false);
762 }
763 }
764 else if (&rButton == m_xBtnSortUser.get())
765 {
766 if (rButton.get_active())
767 {
768 m_xLbSortUser->set_sensitive(true);
769 m_xLbSortUser->grab_focus();
770 }
771 else
772 m_xLbSortUser->set_sensitive(false);
773 }
774}
775
777{
778 if (&rLb == m_xLbOutPos.get())
779 {
780 OUString aString;
781 const int nSelPos = m_xLbOutPos->get_active();
782
783 if (nSelPos > 0)
784 aString = m_xLbOutPos->get_id(nSelPos);
785
786 m_xEdOutPos->set_text(aString);
787 }
788}
789
791{
792 OUString theCurPosStr = m_xEdOutPos->get_text();
793 ScRefFlags nResult = ScAddress().Parse( theCurPosStr, *pDoc, pDoc->GetAddressConvention() );
794
795 if ( (nResult & ScRefFlags::VALID) != ScRefFlags::VALID )
796 return;
797
798 bool bFound = false;
799 sal_Int32 i = 0;
800 const int nCount = m_xLbOutPos->get_count();
801
802 for ( i=2; i<nCount && !bFound; i++ )
803 {
804 OUString aStr = m_xLbOutPos->get_id(i);
805 bFound = (theCurPosStr == aStr);
806 }
807
808 if ( bFound )
809 m_xLbOutPos->set_active(--i);
810 else
811 m_xLbOutPos->set_active(0);
812}
813
815{
816 m_xLbAlgorithm->freeze();
817 m_xLbAlgorithm->clear();
818
819 LanguageType eLang = m_xLbLanguage->get_active_id();
820 if ( eLang == LANGUAGE_SYSTEM )
821 {
822 // for LANGUAGE_SYSTEM no algorithm can be selected because
823 // it wouldn't necessarily exist for other languages
824 // -> leave list box empty if LANGUAGE_SYSTEM is selected
825 m_xFtAlgorithm->set_sensitive( false ); // nothing to select
826 m_xLbAlgorithm->set_sensitive( false ); // nothing to select
827 }
828 else
829 {
830 lang::Locale aLocale( LanguageTag::convertToLocale( eLang ));
831 const uno::Sequence<OUString> aAlgos = m_xColWrap->listCollatorAlgorithms( aLocale );
832
833 tools::Long nCount = aAlgos.getLength();
834 for (const OUString& sAlg : aAlgos)
835 {
836 OUString sUser = m_xColRes->GetTranslation( sAlg );
837 m_xLbAlgorithm->append_text(sUser);
838 }
839 m_xLbAlgorithm->set_active(0); // first entry is default
840 m_xFtAlgorithm->set_sensitive(nCount > 1); // enable only if there is a choice
841 m_xLbAlgorithm->set_sensitive(nCount > 1); // enable only if there is a choice
842 }
843
844 m_xLbAlgorithm->thaw();
845}
846
848{
849 FillAlgor();
850}
851
852/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void ScColToAlpha(OUStringBuffer &rBuf, SCCOL nCol)
append alpha representation of column to buffer
Definition: address.cxx:1884
ScRefFlags
Definition: address.hxx:158
#define GetWhich(nSlot)
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage, bool bMobile=false)
virtual void Start(bool bStartTimer=true) override
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
static LanguageType convertToLanguageType(const css::lang::Locale &rLocale, bool bResolveSystem=true)
SCTAB Tab() const
Definition: address.hxx:283
void Set(SCCOL nCol, SCROW nRow, SCTAB nTab)
Definition: address.hxx:403
SC_DLLPUBLIC void Format(OStringBuffer &r, ScRefFlags nFlags, const ScDocument *pDocument=nullptr, const Details &rDetails=detailsOOOa1) const
Definition: address.cxx:2074
SC_DLLPUBLIC ScRefFlags Parse(const OUString &, const ScDocument &, const Details &rDetails=detailsOOOa1, ExternalInfo *pExtInfo=nullptr, const css::uno::Sequence< css::sheet::ExternalLinkInfo > *pExternalLinks=nullptr, sal_Int32 *pSheetEndPos=nullptr, const OUString *pErrRef=nullptr)
Definition: address.cxx:1537
SCROW Row() const
Definition: address.hxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
bool Next(OUString &rName, ScRange &rRange)
Definition: rangeutl.cxx:1007
const ScDBData * GetDBAtArea(SCTAB nTab, SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2) const
Definition: dbdata.cxx:1431
bool HasHeader() const
Definition: dbdata.hxx:136
ScSheetLimits & GetSheetLimits() const
Definition: document.hxx:897
SC_DLLPUBLIC formula::FormulaGrammar::AddressConvention GetAddressConvention() const
Definition: documen3.cxx:500
SC_DLLPUBLIC ScDBCollection * GetDBCollection() const
Definition: document.hxx:826
SC_DLLPUBLIC SCCOL ClampToAllocatedColumns(SCTAB nTab, SCCOL nCol) const
Definition: documen3.cxx:2151
SC_DLLPUBLIC OUString GetString(SCCOL nCol, SCROW nRow, SCTAB nTab, const ScInterpreterContext *pContext=nullptr) const
Definition: document.cxx:3545
static SC_DLLPUBLIC ScUserList * GetUserList()
Definition: global.cxx:288
ScAddress aStart
Definition: address.hxx:497
ScViewData * GetViewData() const
Definition: uiitems.hxx:140
void AddSortKey(sal_uInt16 nItem)
Definition: sortkeydlg.cxx:58
ScSortKeyItems m_aSortKeyItems
Definition: sortkeydlg.hxx:40
virtual ~ScTabPageSortFields() override
Definition: tpsort.cxx:109
ScViewData * pViewData
Definition: tpsort.hxx:68
OUString aStrColLabel
Definition: tpsort.hxx:65
sal_uInt16 nSortKeyCount
Definition: tpsort.hxx:72
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpsort.cxx:288
ScSortParam aSortData
Definition: tpsort.hxx:69
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *rArgSet)
Definition: tpsort.cxx:158
void FillFieldLists(sal_uInt16 nStartField)
Definition: tpsort.cxx:306
void AddSortKey(sal_uInt16 nItem)
Definition: tpsort.cxx:484
sal_uInt16 GetFieldSelPos(SCCOLROW nField)
Definition: tpsort.cxx:375
virtual bool FillItemSet(SfxItemSet *rArgSet) override
Definition: tpsort.cxx:239
OUString aStrColumn
Definition: tpsort.hxx:62
OUString aStrRow
Definition: tpsort.hxx:63
ScTabPageSortFields(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
Definition: tpsort.cxx:71
TypedWhichId< ScSortItem > nWhichSort
Definition: tpsort.hxx:67
OUString aStrUndefined
Definition: tpsort.hxx:61
std::vector< SCCOLROW > nFieldArr
Definition: tpsort.hxx:70
void SetLastSortKey(sal_uInt16 nItem)
Definition: tpsort.cxx:392
std::unique_ptr< weld::Container > m_xBox
Definition: tpsort.hxx:79
sal_uInt16 nFieldCount
Definition: tpsort.hxx:71
virtual void Reset(const SfxItemSet *rArgSet) override
Definition: tpsort.cxx:163
ScSortKeyWindow m_aSortWin
Definition: tpsort.hxx:80
std::unique_ptr< weld::CheckButton > m_xBtnHeader
Definition: tpsort.hxx:75
std::unique_ptr< weld::RadioButton > m_xBtnLeftRight
Definition: tpsort.hxx:77
std::unique_ptr< weld::RadioButton > m_xBtnTopDown
Definition: tpsort.hxx:76
std::unique_ptr< weld::ScrolledWindow > m_xScrolledWindow
Definition: tpsort.hxx:78
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpsort.cxx:298
std::unique_ptr< CollatorResource > m_xColRes
Definition: tpsort.hxx:123
ScViewData * pViewData
Definition: tpsort.hxx:119
void FillUserSortListBox()
Definition: tpsort.cxx:733
std::unique_ptr< weld::CheckButton > m_xBtnSortUser
Definition: tpsort.hxx:132
std::unique_ptr< weld::ComboBox > m_xLbOutPos
Definition: tpsort.hxx:130
ScSortParam aSortData
Definition: tpsort.hxx:118
std::unique_ptr< weld::CheckButton > m_xBtnNaturalSort
Definition: tpsort.hxx:128
std::unique_ptr< weld::CheckButton > m_xBtnFormats
Definition: tpsort.hxx:127
std::unique_ptr< weld::CheckButton > m_xBtnIncComments
Definition: tpsort.hxx:137
std::unique_ptr< CollatorWrapper > m_xColWrap
Definition: tpsort.hxx:124
virtual bool FillItemSet(SfxItemSet *rArgSet) override
Definition: tpsort.cxx:630
std::unique_ptr< weld::ComboBox > m_xLbSortUser
Definition: tpsort.hxx:133
virtual DeactivateRC DeactivatePage(SfxItemSet *pSet) override
Definition: tpsort.cxx:686
virtual void ActivatePage(const SfxItemSet &rSet) override
Definition: tpsort.cxx:677
virtual void Reset(const SfxItemSet *rArgSet) override
Definition: tpsort.cxx:573
std::unique_ptr< SvxLanguageBox > m_xLbLanguage
Definition: tpsort.hxx:134
std::unique_ptr< weld::Label > m_xFtAlgorithm
Definition: tpsort.hxx:135
std::unique_ptr< weld::CheckButton > m_xBtnIncImages
Definition: tpsort.hxx:138
ScAddress theOutPos
Definition: tpsort.hxx:121
ScDocument * pDoc
Definition: tpsort.hxx:120
TypedWhichId< ScSortItem > nWhichSort
Definition: tpsort.hxx:117
ScTabPageSortOptions(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet &rArgSet)
Definition: tpsort.cxx:492
static std::unique_ptr< SfxTabPage > Create(weld::Container *pPage, weld::DialogController *pController, const SfxItemSet *pArgSet)
Definition: tpsort.cxx:568
std::unique_ptr< weld::CheckButton > m_xBtnCase
Definition: tpsort.hxx:126
std::unique_ptr< weld::Entry > m_xEdOutPos
Definition: tpsort.hxx:131
OUString aStrUndefined
Definition: tpsort.hxx:115
std::unique_ptr< weld::ComboBox > m_xLbAlgorithm
Definition: tpsort.hxx:136
std::unique_ptr< weld::CheckButton > m_xBtnCopyResult
Definition: tpsort.hxx:129
Collection of user-defined sort lists.
Definition: userlist.hxx:67
size_t size() const
Definition: userlist.cxx:346
SCTAB GetTabNo() const
Definition: viewdata.hxx:395
ScDocument & GetDocument() const
Definition: viewdata.hxx:380
SCCOL GetCurX() const
Definition: viewdata.hxx:401
const T * GetItemIfSet(TypedWhichId< T > nWhich, bool bSrchInParent=true) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
const SfxItemSet & GetItemSet() const
SfxOkDialogController * GetDialogController() const
void SetExchangeSupport()
const SfxItemSet * GetDialogExampleSet() const
weld::Window * GetFrameWeld() const
void SetInvokeHandler(const Link< Timer *, void > &rLink)
int nCount
#define max(a, b)
OUString aName
sal_Int64 n
#define LANGUAGE_SYSTEM
#define LANGUAGE_DONTKNOW
aStr
SVXCORE_DLLPUBLIC MSO_SPT Get(const OUString &)
Reference< XComponentContext > getProcessComponentContext()
int i
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
long Long
OUString ScResId(TranslateId aId)
Definition: scdll.cxx:90
#define SCITEM_SORTDATA
Definition: scitems.hxx:90
static SfxItemSet & rSet
#define DEFSORT
Definition: sortparam.hxx:22
bool mbCellDrawObjects
If TRUE, consider the presence of draw objects anchored to the cell.
Definition: sortparam.hxx:48
bool mbCellFormats
If TRUE, consider the presence of cell formats.
Definition: sortparam.hxx:50
bool mbCellNotes
If TRUE, consider the presence of cell notes besides data.
Definition: sortparam.hxx:46
SCTAB nDestTab
Definition: sortparam.hxx:117
SCROW nDestRow
Definition: sortparam.hxx:119
SCCOL nDestCol
Definition: sortparam.hxx:118
bool bNaturalSort
Definition: sortparam.hxx:114
::std::vector< ScSortKeyState > maKeyState
Definition: sortparam.hxx:121
OUString aCollatorAlgorithm
Definition: sortparam.hxx:123
bool bHasHeader
Definition: sortparam.hxx:111
ScDataAreaExtras aDataAreaExtras
Definition: sortparam.hxx:109
css::lang::Locale aCollatorLocale
Definition: sortparam.hxx:122
sal_uInt16 nUserIndex
Definition: sortparam.hxx:110
sal_uInt16 GetSortKeyCount() const
Definition: sortparam.hxx:139
bool bCaseSens
Definition: sortparam.hxx:113
DeactivateRC
IMPL_LINK_NOARG(ScTabPageSortFields, SortDirHdl, weld::Toggleable &, void)
Definition: tpsort.cxx:413
IMPL_LINK(ScTabPageSortFields, SelectHdl, weld::ComboBox &, rLb, void)
Definition: tpsort.cxx:437
SCCOL SC_MAXFIELDS(const ScSheetLimits &rLimits)
Definition: tpsort.hxx:37
sal_Int32 SCCOLROW
a type capable of holding either SCCOL or SCROW
Definition: types.hxx:23
sal_Int16 SCTAB
Definition: types.hxx:22
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17