1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <vcl/toolkit/roadmap.hxx>
#include <tools/debug.hxx>
#include <tools/json_writer.hxx>
#include <osl/diagnose.h>
#include <strings.hrc>
#include <svdata.hxx>
#include <wizdlg.hxx>
#include <vector>
#include "wizimpldata.hxx"
#include <uiobject-internal.hxx>
namespace vcl
{
sal_Int32 RoadmapWizardImpl::getStateIndexInPath( WizardTypes::WizardState _nState, const WizardPath& _rPath )
{
sal_Int32 nStateIndexInPath = 0;
bool bFound = false;
for (auto const& path : _rPath)
{
if (path == _nState)
{
bFound = true;
break;
}
++nStateIndexInPath;
}
if (!bFound)
nStateIndexInPath = -1;
return nStateIndexInPath;
}
sal_Int32 RoadmapWizardImpl::getStateIndexInPath( WizardTypes::WizardState _nState, PathId _nPathId )
{
sal_Int32 nStateIndexInPath = -1;
Paths::const_iterator aPathPos = aPaths.find( _nPathId );
if ( aPathPos != aPaths.end( ) )
nStateIndexInPath = getStateIndexInPath( _nState, aPathPos->second );
return nStateIndexInPath;
}
sal_Int32 RoadmapWizardImpl::getFirstDifferentIndex( const WizardPath& _rLHS, const WizardPath& _rRHS )
{
sal_Int32 nMinLength = ::std::min( _rLHS.size(), _rRHS.size() );
for ( sal_Int32 nCheck = 0; nCheck < nMinLength; ++nCheck )
{
if ( _rLHS[ nCheck ] != _rRHS[ nCheck ] )
return nCheck;
}
return nMinLength;
}
//= RoadmapWizard
RoadmapWizard::RoadmapWizard(vcl::Window* pParent, WinBits nStyle, InitFlag eFlag)
: Dialog(pParent, nStyle, eFlag)
, maWizardLayoutIdle("vcl RoadmapWizard maWizardLayoutIdle")
, m_pFinish(nullptr)
, m_pCancel(nullptr)
, m_pNextPage(nullptr)
, m_pPrevPage(nullptr)
, m_pHelp(nullptr)
, m_xWizardImpl(new WizardMachineImplData)
, m_xRoadmapImpl(new RoadmapWizardImpl)
{
mpFirstPage = nullptr;
mpFirstBtn = nullptr;
mpCurTabPage = nullptr;
mpPrevBtn = nullptr;
mpNextBtn = nullptr;
mpViewWindow = nullptr;
mnCurLevel = 0;
mbEmptyViewMargin = false;
mnLeftAlignCount = 0;
maWizardLayoutIdle.SetPriority(TaskPriority::RESIZE);
maWizardLayoutIdle.SetInvokeHandler( LINK( this, RoadmapWizard, ImplHandleWizardLayoutTimerHdl ) );
implConstruct(WizardButtonFlags::NEXT | WizardButtonFlags::PREVIOUS | WizardButtonFlags::FINISH | WizardButtonFlags::CANCEL | WizardButtonFlags::HELP);
SetLeftAlignedButtonCount( 1 );
mbEmptyViewMargin = true;
m_xRoadmapImpl->pRoadmap.disposeAndReset( VclPtr<ORoadmap>::Create( this, WB_TABSTOP ) );
m_xRoadmapImpl->pRoadmap->SetText( VclResId( STR_WIZDLG_ROADMAP_TITLE ) );
m_xRoadmapImpl->pRoadmap->SetPosPixel( Point( 0, 0 ) );
m_xRoadmapImpl->pRoadmap->SetItemSelectHdl( LINK( this, RoadmapWizard, OnRoadmapItemSelected ) );
Size aRoadmapSize = LogicToPixel(Size(85, 0), MapMode(MapUnit::MapAppFont));
aRoadmapSize.setHeight( GetSizePixel().Height() );
m_xRoadmapImpl->pRoadmap->SetSizePixel( aRoadmapSize );
mpViewWindow = m_xRoadmapImpl->pRoadmap;
m_xRoadmapImpl->pRoadmap->Show();
}
RoadmapWizardMachine::RoadmapWizardMachine(weld::Window* pParent)
: WizardMachine(pParent, WizardButtonFlags::NEXT | WizardButtonFlags::PREVIOUS | WizardButtonFlags::FINISH | WizardButtonFlags::CANCEL | WizardButtonFlags::HELP)
, m_pImpl( new RoadmapWizardImpl )
{
m_xAssistant->connect_jump_page(LINK(this, RoadmapWizardMachine, OnRoadmapItemSelected));
}
void RoadmapWizard::ShowRoadmap(bool bShow)
{
m_xRoadmapImpl->pRoadmap->Show(bShow);
CalcAndSetSize();
}
RoadmapWizard::~RoadmapWizard()
{
disposeOnce();
}
RoadmapWizardMachine::~RoadmapWizardMachine()
{
}
void RoadmapWizard::dispose()
{
m_xRoadmapImpl.reset();
m_pFinish.disposeAndClear();
m_pCancel.disposeAndClear();
m_pNextPage.disposeAndClear();
m_pPrevPage.disposeAndClear();
m_pHelp.disposeAndClear();
if (m_xWizardImpl)
{
for (WizardTypes::WizardState i = 0; i < m_xWizardImpl->nFirstUnknownPage; ++i)
{
TabPage *pPage = GetPage(i);
if (pPage)
pPage->disposeOnce();
}
m_xWizardImpl.reset();
}
maWizardLayoutIdle.Stop();
// Remove all buttons
while ( mpFirstBtn )
RemoveButton( mpFirstBtn->mpButton );
// Remove all pages
while ( mpFirstPage )
RemovePage( mpFirstPage->mpPage );
mpCurTabPage.clear();
mpPrevBtn.clear();
mpNextBtn.clear();
mpViewWindow.clear();
Dialog::dispose();
}
void RoadmapWizard::SetRoadmapHelpId( const OUString& _rId )
{
m_xRoadmapImpl->pRoadmap->SetHelpId( _rId );
}
void RoadmapWizard::SetRoadmapBitmap(const BitmapEx& rBmp)
{
m_xRoadmapImpl->pRoadmap->SetRoadmapBitmap(rBmp);
}
void RoadmapWizardMachine::SetRoadmapHelpId(const OUString& rId)
{
m_xAssistant->set_page_side_help_id(rId);
}
void RoadmapWizardMachine::declarePath( PathId _nPathId, const WizardPath& _lWizardStates)
{
m_pImpl->aPaths.emplace( _nPathId, _lWizardStates );
if ( m_pImpl->aPaths.size() == 1 )
// the very first path -> activate it
activatePath( _nPathId );
else
implUpdateRoadmap( );
}
void RoadmapWizardMachine::activatePath( PathId _nPathId, bool _bDecideForIt )
{
if ( ( _nPathId == m_pImpl->nActivePath ) && ( _bDecideForIt == m_pImpl->bActivePathIsDefinite ) )
// nothing to do
return;
// does the given path exist?
Paths::const_iterator aNewPathPos = m_pImpl->aPaths.find( _nPathId );
DBG_ASSERT( aNewPathPos != m_pImpl->aPaths.end(), "RoadmapWizard::activate: there is no such path!" );
if ( aNewPathPos == m_pImpl->aPaths.end() )
return;
// determine the index of the current state in the current path
sal_Int32 nCurrentStatePathIndex = -1;
if ( m_pImpl->nActivePath != -1 )
nCurrentStatePathIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath );
DBG_ASSERT( static_cast<sal_Int32>(aNewPathPos->second.size()) > nCurrentStatePathIndex,
"RoadmapWizard::activate: you cannot activate a path which has less states than we've already advanced!" );
// If this asserts, this for instance means that we are already in state number, say, 5
// of our current path, and the caller tries to activate a path which has less than 5
// states
if ( static_cast<sal_Int32>(aNewPathPos->second.size()) <= nCurrentStatePathIndex )
return;
// assert that the current and the new path are equal, up to nCurrentStatePathIndex
Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath );
if ( aActivePathPos != m_pImpl->aPaths.end() )
{
if ( RoadmapWizardImpl::getFirstDifferentIndex( aActivePathPos->second, aNewPathPos->second ) <= nCurrentStatePathIndex )
{
OSL_FAIL( "RoadmapWizard::activate: you cannot activate a path which conflicts with the current one *before* the current state!" );
return;
}
}
m_pImpl->nActivePath = _nPathId;
m_pImpl->bActivePathIsDefinite = _bDecideForIt;
implUpdateRoadmap( );
}
void RoadmapWizard::implUpdateRoadmap( )
{
DBG_ASSERT( m_xRoadmapImpl->aPaths.find( m_xRoadmapImpl->nActivePath ) != m_xRoadmapImpl->aPaths.end(),
"RoadmapWizard::implUpdateRoadmap: there is no such path!" );
const WizardPath& rActivePath( m_xRoadmapImpl->aPaths[ m_xRoadmapImpl->nActivePath ] );
sal_Int32 nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( getCurrentState(), rActivePath );
if (nCurrentStatePathIndex < 0)
return;
// determine up to which index (in the new path) we have to display the items
RoadmapTypes::ItemIndex nUpperStepBoundary = static_cast<RoadmapTypes::ItemIndex>(rActivePath.size());
bool bIncompletePath = false;
if ( !m_xRoadmapImpl->bActivePathIsDefinite )
{
for (auto const& path : m_xRoadmapImpl->aPaths)
{
if ( path.first == m_xRoadmapImpl->nActivePath )
// it's the path we are just activating -> no need to check anything
continue;
// the index from which on both paths differ
sal_Int32 nDivergenceIndex = RoadmapWizardImpl::getFirstDifferentIndex( rActivePath, path.second );
if ( nDivergenceIndex <= nCurrentStatePathIndex )
// they differ in an index which we have already left behind us
// -> this is no conflict anymore
continue;
// the path conflicts with our new path -> don't activate the
// *complete* new path, but only up to the step which is unambiguous
nUpperStepBoundary = nDivergenceIndex;
bIncompletePath = true;
}
}
// now, we have to remove all items after nCurrentStatePathIndex, and insert the items from the active
// path, up to (excluding) nUpperStepBoundary
RoadmapTypes::ItemIndex nLoopUntil = ::std::max( nUpperStepBoundary, m_xRoadmapImpl->pRoadmap->GetItemCount() );
for ( RoadmapTypes::ItemIndex nItemIndex = nCurrentStatePathIndex; nItemIndex < nLoopUntil; ++nItemIndex )
{
bool bExistentItem = ( nItemIndex < m_xRoadmapImpl->pRoadmap->GetItemCount() );
bool bNeedItem = ( nItemIndex < nUpperStepBoundary );
bool bInsertItem = false;
if ( bExistentItem )
{
if ( !bNeedItem )
{
while ( nItemIndex < m_xRoadmapImpl->pRoadmap->GetItemCount() )
m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem( nItemIndex );
break;
}
else
{
// there is an item with this index in the roadmap - does it match what is requested by
// the respective state in the active path?
RoadmapTypes::ItemId nPresentItemId = m_xRoadmapImpl->pRoadmap->GetItemID( nItemIndex );
WizardTypes::WizardState nRequiredState = rActivePath[ nItemIndex ];
if ( nPresentItemId != nRequiredState )
{
m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem( nItemIndex );
bInsertItem = true;
}
}
}
else
{
DBG_ASSERT( bNeedItem, "RoadmapWizard::implUpdateRoadmap: ehm - none needed, none present - why did the loop not terminate?" );
bInsertItem = bNeedItem;
}
WizardTypes::WizardState nState( rActivePath[ nItemIndex ] );
if ( bInsertItem )
{
m_xRoadmapImpl->pRoadmap->InsertRoadmapItem(
nItemIndex,
getStateDisplayName( nState ),
nState,
true
);
}
const bool bEnable = m_xRoadmapImpl->aDisabledStates.find( nState ) == m_xRoadmapImpl->aDisabledStates.end();
m_xRoadmapImpl->pRoadmap->EnableRoadmapItem( m_xRoadmapImpl->pRoadmap->GetItemID( nItemIndex ), bEnable );
}
m_xRoadmapImpl->pRoadmap->SetRoadmapComplete( !bIncompletePath );
}
void RoadmapWizardMachine::implUpdateRoadmap( )
{
DBG_ASSERT( m_pImpl->aPaths.find( m_pImpl->nActivePath ) != m_pImpl->aPaths.end(),
"RoadmapWizard::implUpdateRoadmap: there is no such path!" );
const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] );
sal_Int32 nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( getCurrentState(), rActivePath );
if (nCurrentStatePathIndex < 0)
return;
// determine up to which index (in the new path) we have to display the items
RoadmapTypes::ItemIndex nUpperStepBoundary = static_cast<RoadmapTypes::ItemIndex>(rActivePath.size());
if ( !m_pImpl->bActivePathIsDefinite )
{
for (auto const& path : m_pImpl->aPaths)
{
if ( path.first == m_pImpl->nActivePath )
// it's the path we are just activating -> no need to check anything
continue;
// the index from which on both paths differ
sal_Int32 nDivergenceIndex = RoadmapWizardImpl::getFirstDifferentIndex( rActivePath, path.second );
if ( nDivergenceIndex <= nCurrentStatePathIndex )
// they differ in an index which we have already left behind us
// -> this is no conflict anymore
continue;
// the path conflicts with our new path -> don't activate the
// *complete* new path, but only up to the step which is unambiguous
nUpperStepBoundary = nDivergenceIndex;
}
}
// can we advance from the current page?
bool bCurrentPageCanAdvance = true;
BuilderPage* pCurrentPage = GetPage( getCurrentState() );
if ( pCurrentPage )
{
const IWizardPageController* pController = getPageController( GetPage( getCurrentState() ) );
OSL_ENSURE( pController != nullptr, "RoadmapWizard::implUpdateRoadmap: no controller for the current page!" );
bCurrentPageCanAdvance = !pController || pController->canAdvance();
}
// now, we have to remove all items after nCurrentStatePathIndex, and insert the items from the active
// path, up to (excluding) nUpperStepBoundary
RoadmapTypes::ItemIndex nRoadmapItems = m_xAssistant->get_n_pages();
RoadmapTypes::ItemIndex nLoopUntil = ::std::max( nUpperStepBoundary, nRoadmapItems );
for ( RoadmapTypes::ItemIndex nItemIndex = nCurrentStatePathIndex; nItemIndex < nLoopUntil; ++nItemIndex )
{
bool bExistentItem = ( nItemIndex < nRoadmapItems );
bool bNeedItem = ( nItemIndex < nUpperStepBoundary );
bool bInsertItem = false;
if ( bExistentItem )
{
if ( !bNeedItem )
{
int nPages = nRoadmapItems;
for (int i = nPages - 1; i >= nItemIndex; --i)
{
m_xAssistant->set_page_title(m_xAssistant->get_page_ident(i), "");
--nRoadmapItems;
}
break;
}
else
{
// there is an item with this index in the roadmap - does it match what is requested by
// the respective state in the active path?
RoadmapTypes::ItemId nPresentItemId = m_xAssistant->get_page_ident(nItemIndex).toInt32();
WizardTypes::WizardState nRequiredState = rActivePath[ nItemIndex ];
if ( nPresentItemId != nRequiredState )
{
m_xAssistant->set_page_title(OUString::number(nPresentItemId), "");
bInsertItem = true;
}
}
}
else
{
DBG_ASSERT( bNeedItem, "RoadmapWizard::implUpdateRoadmap: ehm - none needed, none present - why did the loop not terminate?" );
bInsertItem = bNeedItem;
}
WizardTypes::WizardState nState( rActivePath[ nItemIndex ] );
if ( bInsertItem )
{
GetOrCreatePage(nState);
}
OUString sIdent(getPageIdentForState(nState));
m_xAssistant->set_page_index(sIdent, nItemIndex);
m_xAssistant->set_page_title(sIdent, getStateDisplayName(nState));
// if the item is *after* the current state, but the current page does not
// allow advancing, the disable the state. This relieves derived classes
// from disabling all future states just because the current state does not
// (yet) allow advancing.
const bool bUnconditionedDisable = !bCurrentPageCanAdvance && ( nItemIndex > nCurrentStatePathIndex );
const bool bEnable = !bUnconditionedDisable && ( m_pImpl->aDisabledStates.find( nState ) == m_pImpl->aDisabledStates.end() );
m_xAssistant->set_page_sensitive(sIdent, bEnable);
}
}
WizardTypes::WizardState RoadmapWizard::determineNextState( WizardTypes::WizardState _nCurrentState ) const
{
sal_Int32 nCurrentStatePathIndex = -1;
Paths::const_iterator aActivePathPos = m_xRoadmapImpl->aPaths.find( m_xRoadmapImpl->nActivePath );
if ( aActivePathPos != m_xRoadmapImpl->aPaths.end() )
nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( _nCurrentState, aActivePathPos->second );
DBG_ASSERT( nCurrentStatePathIndex != -1, "RoadmapWizard::determineNextState: ehm - how can we travel if there is no (valid) active path?" );
if ( nCurrentStatePathIndex == -1 )
return WZS_INVALID_STATE;
sal_Int32 nNextStateIndex = nCurrentStatePathIndex + 1;
while ( ( nNextStateIndex < static_cast<sal_Int32>(aActivePathPos->second.size()) )
&& ( m_xRoadmapImpl->aDisabledStates.find( aActivePathPos->second[ nNextStateIndex ] ) != m_xRoadmapImpl->aDisabledStates.end() )
)
{
++nNextStateIndex;
}
if ( nNextStateIndex >= static_cast<sal_Int32>(aActivePathPos->second.size()) )
// there is no next state in the current path (at least none which is enabled)
return WZS_INVALID_STATE;
return aActivePathPos->second[ nNextStateIndex ];
}
WizardTypes::WizardState RoadmapWizardMachine::determineNextState( WizardTypes::WizardState _nCurrentState ) const
{
sal_Int32 nCurrentStatePathIndex = -1;
Paths::const_iterator aActivePathPos = m_pImpl->aPaths.find( m_pImpl->nActivePath );
if ( aActivePathPos != m_pImpl->aPaths.end() )
nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( _nCurrentState, aActivePathPos->second );
DBG_ASSERT( nCurrentStatePathIndex != -1, "RoadmapWizard::determineNextState: ehm - how can we travel if there is no (valid) active path?" );
if ( nCurrentStatePathIndex == -1 )
return WZS_INVALID_STATE;
sal_Int32 nNextStateIndex = nCurrentStatePathIndex + 1;
while ( ( nNextStateIndex < static_cast<sal_Int32>(aActivePathPos->second.size()) )
&& ( m_pImpl->aDisabledStates.find( aActivePathPos->second[ nNextStateIndex ] ) != m_pImpl->aDisabledStates.end() )
)
{
++nNextStateIndex;
}
if ( nNextStateIndex >= static_cast<sal_Int32>(aActivePathPos->second.size()) )
// there is no next state in the current path (at least none which is enabled)
return WZS_INVALID_STATE;
return aActivePathPos->second[ nNextStateIndex ];
}
bool RoadmapWizardMachine::canAdvance() const
{
if ( !m_pImpl->bActivePathIsDefinite )
{
// check how many paths are still allowed
const WizardPath& rActivePath( m_pImpl->aPaths[ m_pImpl->nActivePath ] );
// if current path has only the base item, it is not possible to proceed without activating another path
if(rActivePath.size()<=1)
return false;
sal_Int32 nCurrentStatePathIndex = RoadmapWizardImpl::getStateIndexInPath( getCurrentState(), rActivePath );
size_t nPossiblePaths(0);
for (auto const& path : m_pImpl->aPaths)
{
// the index from which on both paths differ
sal_Int32 nDivergenceIndex = RoadmapWizardImpl::getFirstDifferentIndex( rActivePath, path.second );
if ( nDivergenceIndex > nCurrentStatePathIndex )
// this path is still a possible path
nPossiblePaths += 1;
}
// if we have more than one path which is still possible, then we assume
// to always have a next state. Though there might be scenarios where this
// is not true, but this is too sophisticated (means not really needed) right now.
if ( nPossiblePaths > 1 )
return true;
}
const WizardPath& rPath = m_pImpl->aPaths[ m_pImpl->nActivePath ];
return *rPath.rbegin() != getCurrentState();
}
void RoadmapWizardMachine::updateTravelUI()
{
WizardMachine::updateTravelUI();
// disable the "Previous" button if all states in our history are disabled
std::vector< WizardTypes::WizardState > aHistory;
getStateHistory( aHistory );
bool bHaveEnabledState = false;
for (auto const& state : aHistory)
{
if ( isStateEnabled(state) )
{
bHaveEnabledState = true;
break;
}
}
enableButtons( WizardButtonFlags::PREVIOUS, bHaveEnabledState );
implUpdateRoadmap();
}
IMPL_LINK_NOARG(RoadmapWizard, OnRoadmapItemSelected, LinkParamNone*, void)
{
RoadmapTypes::ItemId nCurItemId = m_xRoadmapImpl->pRoadmap->GetCurrentRoadmapItemID();
if ( nCurItemId == getCurrentState() )
// nothing to do
return;
if ( isTravelingSuspended() )
return;
RoadmapWizardTravelSuspension aTravelGuard( *this );
sal_Int32 nCurrentIndex = m_xRoadmapImpl->getStateIndexInPath( getCurrentState(), m_xRoadmapImpl->nActivePath );
sal_Int32 nNewIndex = m_xRoadmapImpl->getStateIndexInPath( nCurItemId, m_xRoadmapImpl->nActivePath );
DBG_ASSERT( ( nCurrentIndex != -1 ) && ( nNewIndex != -1 ),
"RoadmapWizard::OnRoadmapItemSelected: something's wrong here!" );
if ( ( nCurrentIndex == -1 ) || ( nNewIndex == -1 ) )
{
return;
}
bool bResult = true;
if ( nNewIndex > nCurrentIndex )
{
bResult = skipUntil( static_cast<WizardTypes::WizardState>(nCurItemId) );
WizardTypes::WizardState nTemp = static_cast<WizardTypes::WizardState>(nCurItemId);
while( nTemp )
{
if( m_xRoadmapImpl->aDisabledStates.find( --nTemp ) != m_xRoadmapImpl->aDisabledStates.end() )
removePageFromHistory( nTemp );
}
}
else
bResult = skipBackwardUntil( static_cast<WizardTypes::WizardState>(nCurItemId) );
if ( !bResult )
m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() );
}
IMPL_LINK(RoadmapWizardMachine, OnRoadmapItemSelected, const OUString&, rCurItemId, bool)
{
WizardTypes::WizardState nSelectedState = getStateFromPageIdent(rCurItemId);
if (nSelectedState == getCurrentState())
// nothing to do
return false;
if ( isTravelingSuspended() )
return false;
WizardTravelSuspension aTravelGuard( *this );
sal_Int32 nCurrentIndex = m_pImpl->getStateIndexInPath( getCurrentState(), m_pImpl->nActivePath );
sal_Int32 nNewIndex = m_pImpl->getStateIndexInPath( nSelectedState, m_pImpl->nActivePath );
DBG_ASSERT( ( nCurrentIndex != -1 ) && ( nNewIndex != -1 ),
"RoadmapWizard::OnRoadmapItemSelected: something's wrong here!" );
if ( ( nCurrentIndex == -1 ) || ( nNewIndex == -1 ) )
{
return false;
}
bool bResult = true;
if ( nNewIndex > nCurrentIndex )
{
bResult = skipUntil(nSelectedState);
WizardTypes::WizardState nTemp = nSelectedState;
while( nTemp )
{
if( m_pImpl->aDisabledStates.find( --nTemp ) != m_pImpl->aDisabledStates.end() )
removePageFromHistory( nTemp );
}
}
else
bResult = skipBackwardUntil(nSelectedState);
return bResult;
}
void RoadmapWizard::enterState(WizardTypes::WizardState /*nState*/)
{
// synchronize the roadmap
implUpdateRoadmap( );
m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID( getCurrentState() );
}
void RoadmapWizardMachine::enterState( WizardTypes::WizardState _nState )
{
WizardMachine::enterState( _nState );
// synchronize the roadmap
implUpdateRoadmap();
}
OUString RoadmapWizard::getStateDisplayName( WizardTypes::WizardState _nState ) const
{
OUString sDisplayName;
StateDescriptions::const_iterator pos = m_xRoadmapImpl->aStateDescriptors.find( _nState );
OSL_ENSURE( pos != m_xRoadmapImpl->aStateDescriptors.end(),
"RoadmapWizard::getStateDisplayName: no default implementation available for this state!" );
if ( pos != m_xRoadmapImpl->aStateDescriptors.end() )
sDisplayName = pos->second.first;
return sDisplayName;
}
OUString RoadmapWizardMachine::getStateDisplayName( WizardTypes::WizardState _nState ) const
{
OUString sDisplayName;
StateDescriptions::const_iterator pos = m_pImpl->aStateDescriptors.find( _nState );
OSL_ENSURE( pos != m_pImpl->aStateDescriptors.end(),
"RoadmapWizard::getStateDisplayName: no default implementation available for this state!" );
if ( pos != m_pImpl->aStateDescriptors.end() )
sDisplayName = pos->second.first;
return sDisplayName;
}
VclPtr<TabPage> RoadmapWizard::createPage( WizardTypes::WizardState _nState )
{
VclPtr<TabPage> pPage;
StateDescriptions::const_iterator pos = m_xRoadmapImpl->aStateDescriptors.find( _nState );
OSL_ENSURE( pos != m_xRoadmapImpl->aStateDescriptors.end(),
"RoadmapWizard::createPage: no default implementation available for this state!" );
if ( pos != m_xRoadmapImpl->aStateDescriptors.end() )
{
RoadmapPageFactory pFactory = pos->second.second;
pPage = (*pFactory)( *this );
}
return pPage;
}
void RoadmapWizardMachine::enableState( WizardTypes::WizardState _nState, bool _bEnable )
{
// remember this (in case the state appears in the roadmap later on)
if ( _bEnable )
m_pImpl->aDisabledStates.erase( _nState );
else
{
m_pImpl->aDisabledStates.insert( _nState );
removePageFromHistory( _nState );
}
// if the state is currently in the roadmap, reflect it's new status
m_xAssistant->set_page_sensitive(getPageIdentForState(_nState), _bEnable);
}
bool RoadmapWizardMachine::knowsState( WizardTypes::WizardState i_nState ) const
{
for (auto const& path : m_pImpl->aPaths)
{
for (auto const& state : path.second)
{
if ( state == i_nState )
return true;
}
}
return false;
}
bool RoadmapWizardMachine::isStateEnabled( WizardTypes::WizardState _nState ) const
{
return m_pImpl->aDisabledStates.find( _nState ) == m_pImpl->aDisabledStates.end();
}
void RoadmapWizard::InsertRoadmapItem(int nItemIndex, const OUString& rText, int nItemId, bool bEnable)
{
m_xRoadmapImpl->pRoadmap->InsertRoadmapItem(nItemIndex, rText, nItemId, bEnable);
}
void RoadmapWizard::SelectRoadmapItemByID(int nItemId, bool bGrabFocus)
{
m_xRoadmapImpl->pRoadmap->SelectRoadmapItemByID(nItemId, bGrabFocus);
}
void RoadmapWizard::DeleteRoadmapItems()
{
while (m_xRoadmapImpl->pRoadmap->GetItemCount())
m_xRoadmapImpl->pRoadmap->DeleteRoadmapItem(0);
}
void RoadmapWizard::SetItemSelectHdl( const Link<LinkParamNone*,void>& _rHdl )
{
m_xRoadmapImpl->pRoadmap->SetItemSelectHdl(_rHdl);
}
int RoadmapWizard::GetCurrentRoadmapItemID() const
{
return m_xRoadmapImpl->pRoadmap->GetCurrentRoadmapItemID();
}
FactoryFunction RoadmapWizard::GetUITestFactory() const
{
return RoadmapWizardUIObject::create;
}
namespace
{
bool isButton(WindowType eType)
{
return eType == WindowType::PUSHBUTTON || eType == WindowType::OKBUTTON
|| eType == WindowType::CANCELBUTTON || eType == WindowType::HELPBUTTON;
}
}
void RoadmapWizard::DumpAsPropertyTree(tools::JsonWriter& rJsonWriter)
{
rJsonWriter.put("id", get_id());
rJsonWriter.put("type", "dialog");
rJsonWriter.put("title", GetText());
OUString sDialogId = GetHelpId();
sal_Int32 nStartPos = sDialogId.lastIndexOf('/');
nStartPos = nStartPos >= 0 ? nStartPos + 1 : 0;
rJsonWriter.put("dialogid", sDialogId.copy(nStartPos));
{
auto aResponses = rJsonWriter.startArray("responses");
for (const auto& rResponse : m_xRoadmapImpl->maResponses)
{
auto aResponse = rJsonWriter.startStruct();
rJsonWriter.put("id", rResponse.first->get_id());
rJsonWriter.put("response", rResponse.second);
}
}
vcl::Window* pFocusControl = GetFirstControlForFocus();
if (pFocusControl)
rJsonWriter.put("init_focus_id", pFocusControl->get_id());
{
auto childrenNode = rJsonWriter.startArray("children");
auto containerNode = rJsonWriter.startStruct();
rJsonWriter.put("id", "container");
rJsonWriter.put("type", "container");
rJsonWriter.put("vertical", true);
{
auto containerChildrenNode = rJsonWriter.startArray("children");
// tabpages
for (int i = 0; i < GetChildCount(); i++)
{
vcl::Window* pChild = GetChild(i);
if (!isButton(pChild->GetType()) && pChild != mpViewWindow)
{
auto childNode = rJsonWriter.startStruct();
pChild->DumpAsPropertyTree(rJsonWriter);
}
}
// buttons
{
auto buttonsNode = rJsonWriter.startStruct();
rJsonWriter.put("id", "buttons");
rJsonWriter.put("type", "buttonbox");
rJsonWriter.put("layoutstyle", "end");
{
auto buttonsChildrenNode = rJsonWriter.startArray("children");
for (int i = 0; i < GetChildCount(); i++)
{
vcl::Window* pChild = GetChild(i);
if (isButton(pChild->GetType()))
{
auto childNode = rJsonWriter.startStruct();
pChild->DumpAsPropertyTree(rJsonWriter);
}
}
}
}
}
}
}
} // namespace vcl
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|