forked from audacity/audacity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyView.cpp
More file actions
2342 lines (1983 loc) · 55.4 KB
/
Copy pathKeyView.cpp
File metadata and controls
2342 lines (1983 loc) · 55.4 KB
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
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**********************************************************************
Audacity: A Digital Audio Editor
KeyView.cpp
*******************************************************************//*!
\class KeyView
\brief Provides multiple views of keyboard shortcuts
*//*********************************************************************/
#include "../Audacity.h"
#include "KeyView.h"
#include <wx/setup.h> // for wxUSE_* macros
#include <wx/defs.h>
#include <wx/settings.h>
#include <wx/vlbox.h>
#include "../AColor.h"
#include "../ShuttleGui.h"
#include "../commands/CommandManager.h"
#include <wx/dc.h>
#include <wx/menu.h>
#if wxUSE_ACCESSIBILITY
#include "WindowAccessible.h"
// ----------------------------------------------------------------------------
// KeyViewAx
//
// wxAccessible object providing information for KeyView.
// ----------------------------------------------------------------------------
class KeyViewAx final : public WindowAccessible
{
public:
KeyViewAx(KeyView *view);
void SetCurrentLine(int row);
void ListUpdated();
bool LineToId(int line, int & childId);
bool IdToLine(int childId, int & line);
// Can return either a child object, or an integer
// representing the child element, starting from 1.
wxAccStatus HitTest(const wxPoint & pt, int *childId, wxAccessible **childObject) override;
// Retrieves the address of an IDispatch interface for the specified child.
// All objects must support this property.
wxAccStatus GetChild(int childId, wxAccessible **child) override;
// Gets the number of children.
wxAccStatus GetChildCount(int *childCount) override;
// Gets the default action for this object (0) or > 0 (the action for a child).
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
// string if there is no action.
// The retrieved string describes the action that is performed on an object,
// not what the object does as a result. For example, a toolbar button that prints
// a document has a default action of "Press" rather than "Prints the current document."
wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
// Returns the description for this object or a child.
wxAccStatus GetDescription(int childId, wxString *description) override;
// Gets the window with the keyboard focus.
// If childId is 0 and child is NULL, no object in
// this subhierarchy has the focus.
// If this object has the focus, child should be 'this'.
wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
// Returns help text for this object or a child, similar to tooltip text.
wxAccStatus GetHelpText(int childId, wxString *helpText) override;
// Returns the keyboard shortcut for this object or child.
// Return e.g. ALT+K
wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
// rect is in screen coordinates.
wxAccStatus GetLocation(wxRect & rect, int elementId) override;
// Navigates from fromId to toId/toObject.
wxAccStatus Navigate(wxNavDir navDir, int fromId,
int *toId, wxAccessible **toObject) override;
// Gets the name of the specified object.
wxAccStatus GetName(int childId, wxString *name) override;
// Gets the parent, or NULL.
wxAccStatus GetParent(wxAccessible **parent) override;
// Returns a role constant.
wxAccStatus GetRole(int childId, wxAccRole *role) override;
// Gets a variant representing the selected children
// of this object.
// Acceptable values:
// - a null variant (IsNull() returns TRUE)
// - a list variant (GetType() == wxT("list"))
// - an integer representing the selected child element,
// or 0 if this object is selected (GetType() == wxT("long"))
// - a "void*" pointer to a wxAccessible child object
wxAccStatus GetSelections(wxVariant *selections) override;
// Returns a state constant.
wxAccStatus GetState(int childId, long *state) override;
// Returns a localized string representing the value for the object
// or child.
wxAccStatus GetValue(int childId, wxString *strValue) override;
#if defined(__WXMAC__)
// Selects the object or child.
wxAccStatus Select(int childId, wxAccSelectionFlags selectFlags) override;
#endif
private:
KeyView *mView;
int mLastId;
};
#endif
// Various drawing constants
#define KV_BITMAP_SIZE 16
#define KV_LEFT_MARGIN 2
#define KV_COLUMN_SPACER 5
#define KV_VSCROLL_WIDTH 16 /* figure this out automatically? */
// Define the KeyNode arrays
// Define the event table
BEGIN_EVENT_TABLE(KeyView, wxVListBox)
EVT_LEFT_DOWN(KeyView::OnLeftDown)
EVT_KEY_DOWN(KeyView::OnKeyDown)
EVT_LISTBOX(wxID_ANY, KeyView::OnSelected)
EVT_SET_FOCUS(KeyView::OnSetFocus)
EVT_KILL_FOCUS(KeyView::OnKillFocus)
EVT_SIZE(KeyView::OnSize)
EVT_SCROLLWIN(KeyView::OnScroll)
END_EVENT_TABLE();
static wxString CommandTranslated = "Command";
// ============================================================================
// KeyView class
// ============================================================================
KeyView::KeyView(wxWindow *parent,
wxWindowID id,
const wxPoint & pos,
const wxSize & size)
: wxVListBox(parent, id, pos, size, wxBORDER_THEME | wxHSCROLL | wxVSCROLL),
mScrollX(0),
mWidth(0)
{
#if wxUSE_ACCESSIBILITY
// Create and set accessibility object
SetAccessible(mAx = safenew KeyViewAx(this));
#endif
SetMinSize({-1, 150});
// The default view
mViewType = ViewByTree;
// Calculate measurements used for columns and scrolling
RecalcExtents();
}
KeyView::~KeyView()
{
}
//
// Returns the index of the selected node
//
int
KeyView::GetSelected() const
{
return LineToIndex(GetSelection());
}
//
// Returns the name of the control
//
wxString
KeyView::GetName() const
{
// Just forward request
return wxVListBox::GetName();
}
//
// Returns the label for the given index
//
wxString
KeyView::GetLabel(int index) const
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return wxEmptyString;
}
return mNodes[index].label;
}
//
// Returns the prefix (if available) prepended to the label for the given index
//
wxString
KeyView::GetFullLabel(int index) const
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return wxEmptyString;
}
// Cache the node and label
const KeyNode & node = mNodes[index];
wxString label = node.label;
// Prepend the prefix if available
if (!node.prefix.empty())
{
label = node.prefix + wxT(" - ") + label;
}
return label;
}
//
// Returns the index for the given name
//
int
KeyView::GetIndexByName(const CommandID & name) const
{
int cnt = (int) mNodes.size();
// Search the nodes for the key
for (int i = 0; i < cnt; i++)
{
if (name == mNodes[i].name)
{
return mNodes[i].index;
}
}
return wxNOT_FOUND;
}
//
// Returns the command manager name for the given index
//
CommandID
KeyView::GetName(int index) const
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return {};
}
return mNodes[index].name;
}
//
// Returns the command manager index for the given key combination
//
CommandID
KeyView::GetNameByKey(const NormalizedKeyString & key) const
{
int cnt = (int) mNodes.size();
// Search the nodes for the key
for (int i = 0; i < cnt; i++)
{
if ( key == mNodes[i].key )
{
return mNodes[i].name;
}
}
return {};
}
//
// Returns the index for the given key
//
int
KeyView::GetIndexByKey(const NormalizedKeyString & key) const
{
int cnt = (int) mNodes.size();
// Search the nodes for the key
for (int i = 0; i < cnt; i++)
{
if ( key == mNodes[i].key )
{
return mNodes[i].index;
}
}
return wxNOT_FOUND;
}
//
// Returns the key for the given index
//
NormalizedKeyString
KeyView::GetKey(int index) const
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return {};
}
return mNodes[index].key;
}
//
// Use to determine if a key can be assigned to the given index
//
bool
KeyView::CanSetKey(int index) const
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return false;
}
// Parents can't be assigned keys
return !mNodes[index].isparent;
}
//
// Sets the key for the given index
//
bool
KeyView::SetKey(int index, const NormalizedKeyString & key)
{
// Make sure index is valid
if (index < 0 || index >= (int) mNodes.size())
{
wxASSERT(false);
return false;
}
// Cache the node
KeyNode & node = mNodes[index];
// Do not allow setting keys on branches
if (node.isparent)
{
return false;
}
// Set the NEW key
node.key = key;
// Check to see if the key column needs to be expanded
int x, y;
GetTextExtent(node.key.Display(), &x, &y);
if (x > mKeyWidth || y > mLineHeight)
{
// New key is wider than column so recalc extents (will refresh view)
RecalcExtents();
return true;
}
// Refresh the view lines
RefreshAll();
return true;
}
//
// Sets the key for the given name
//
bool
KeyView::SetKeyByName(const CommandID & name, const NormalizedKeyString & key)
{
int index = GetIndexByName(name);
// Bail is the name wasn't found
if (index == wxNOT_FOUND)
{
return false;
}
// Go set the key
return SetKey(index, key);
}
//
// Sets the view type
//
void
KeyView::SetView(ViewByType type)
{
int index = LineToIndex(GetSelection());
// Handle an existing selection
if (index != wxNOT_FOUND)
{
// Cache the currently selected node
KeyNode & node = mNodes[index];
// Expand branches if switching to Tree view and a line
// is currently selected
if (type == ViewByTree)
{
// Cache the node's depth
int depth = node.depth;
// Search for its parents, setting each one as open
for (int i = node.index - 1; i >= 0 && depth > 1; i--)
{
if (mNodes[i].depth < depth)
{
mNodes[i].isopen = true;
depth = mNodes[i].depth;
}
}
}
}
// Unselect any currently selected line...do even if none selected
SelectNode(-1);
// Save NEW type
mViewType = type;
// Refresh the view lines
RefreshLines();
// Reselect old node (if possible)
if (index != wxNOT_FOUND)
{
SelectNode(index);
}
// ensure that a node is selected so that when the keyview is the focus,
// this is indicated visually, and the Narrator screen reader reads it.
if ((GetSelection() == wxNOT_FOUND))
{
SelectNode(LineToIndex(0));
}
return;
}
//
// Sets the filter
//
void
KeyView::SetFilter(const wxString & filter)
{
int index = LineToIndex(GetSelection());
// Unselect any currently selected line...do even if none selected
SelectNode(-1);
// Save the filter
mFilter = filter.Lower();
// Refresh the view lines
RefreshLines();
// Reselect old node (if possible)
if (index != wxNOT_FOUND)
{
SelectNode(index);
}
// ensure that a node is selected so that when the keyview is the focus,
// this is indicated visually, and the Narrator screen reader reads it.
if ((GetSelection() == wxNOT_FOUND))
{
SelectNode(LineToIndex(0));
}
}
//
// Expand all branches
//
void
KeyView::ExpandAll()
{
int cnt = (int) mNodes.size();
// Set all parent nodes to open
for (int i = 0; i < cnt; i++)
{
KeyNode & node = mNodes[i];
if (node.isparent)
{
node.isopen = true;
}
}
RefreshLines();
}
//
// Collapse all branches
//
void
KeyView::CollapseAll()
{
int cnt = (int) mNodes.size();
// Set all parent nodes to closed
for (int i = 0; i < cnt; i++)
{
KeyNode & node = mNodes[i];
if (node.isparent)
{
node.isopen = false;
}
}
RefreshLines();
}
//
// Recalculate the measurements used for columns and scrolling
//
void
KeyView::RecalcExtents()
{
// Reset
mLineHeight = 0;
mCommandWidth = 0;
mKeyWidth = 0;
// Examine all nodes
int cnt = (int) mNodes.size();
for (int i = 0; i < cnt; i++)
{
KeyNode & node = mNodes[i];
int x, y;
if (node.iscat)
{
// Measure the category
GetTextExtent(node.category, &x, &y);
}
else if (node.ispfx)
{
// Measure the prefix
GetTextExtent(node.prefix, &x, &y);
}
else
{
// Measure the key
GetTextExtent(node.key.Display(), &x, &y);
mLineHeight = wxMax(mLineHeight, y);
mKeyWidth = wxMax(mKeyWidth, x);
// Prepend prefix for view types other than tree
wxString label = node.label;
if (mViewType != ViewByTree && !node.prefix.empty())
{
label = node.prefix + wxT(" - ") + label;
}
// Measure the label
GetTextExtent(label, &x, &y);
}
// Finish calc for command column
mLineHeight = wxMax(mLineHeight, y);
mCommandWidth = wxMax(mCommandWidth, x);
}
// Update horizontal scrollbar
UpdateHScroll();
}
//
// Update the horizontal scrollbar or remove it if not needed
//
void
KeyView::UpdateHScroll()
{
// Get the internal dimensions of the view
wxRect r = GetClientRect();
// Calculate the full line width
mWidth = KV_LEFT_MARGIN +
mKeyWidth +
KV_COLUMN_SPACER +
mCommandWidth +
KV_VSCROLL_WIDTH;
// Retrieve the current horizontal scroll amount
mScrollX = GetScrollPos(wxHORIZONTAL);
if (mWidth <= r.GetWidth())
{
// Remove the scrollbar if it will fit within client width
SetScrollbar(wxHORIZONTAL, 0, 0, 0);
}
else
{
// Set scrollbar metrics
SetScrollbar(wxHORIZONTAL, mScrollX, r.GetWidth(), mWidth);
}
// Refresh the entire view
RefreshAll();
}
//
// Process a NEW set of bindings
//
void
KeyView::RefreshBindings(const CommandIDs & names,
const TranslatableStrings & categories,
const TranslatableStrings & prefixes,
const TranslatableStrings & labels,
const std::vector<NormalizedKeyString> & keys,
bool bSort
)
{
// Start clean
mNodes.clear();
// Same as in RecalcExtents() but do it inline
mLineHeight = 0;
mKeyWidth = 0;
mCommandWidth = 0;
wxString lastcat;
wxString lastpfx;
int nodecnt = 0;
int depth = 1;
bool incat = false;
bool inpfx = false;
// lookup translation once only
CommandTranslated = _("Command");
// Examine all names...all arrays passed have the same indexes
int cnt = (int) names.size();
for (int i = 0; i < cnt; i++)
{
auto name = names[i];
int x, y;
// Remove any menu code from the category and prefix
wxString cat = categories[i].Translation();
wxString pfx = prefixes[i].Translation();
// Append "Menu" this node is for a menu title
if (cat != CommandTranslated)
{
cat.Append(wxT(" "));
cat += _("Menu");
}
// Process a NEW category
if (cat != lastcat)
{
// A NEW category always finishes any current subtree
if (inpfx)
{
// Back to category level
depth--;
inpfx = false;
}
// Only time this is not true is during the first iteration
if (incat)
{
// Back to root level
depth--;
incat = false;
}
// Remember for next iteration
lastcat = cat;
// Add a NEW category node
if (!cat.empty())
{
KeyNode node;
// Fill in the node info
node.name = CommandID{}; // don't associate branches with a command
node.category = cat;
node.prefix = pfx;
node.label = cat;
node.index = nodecnt++;
node.iscat = true;
node.isparent = true;
node.depth = depth++;
node.isopen = true;
// Add it to the tree
mNodes.push_back(node);
incat = true;
// Measure category
GetTextExtent(cat, &x, &y);
mLineHeight = wxMax(mLineHeight, y);
mCommandWidth = wxMax(mCommandWidth, x);
}
}
// Process a NEW prefix
if (pfx != lastpfx)
{
// Done with prefix branch
if (inpfx)
{
depth--;
inpfx = false;
}
// Remember for next iteration
lastpfx = pfx;
// Add a NEW prefix node
if (!pfx.empty())
{
KeyNode node;
// Fill in the node info
node.name = CommandID{}; // don't associate branches with a command
node.category = cat;
node.prefix = pfx;
node.label = pfx;
node.index = nodecnt++;
node.ispfx = true;
node.isparent = true;
node.depth = depth++;
node.isopen = true;
// Add it to the tree
mNodes.push_back(node);
inpfx = true;
}
}
// Add the key entry
KeyNode node;
node.category = cat;
node.prefix = pfx;
// Labels for undo and redo change according to the last command
// which can be undone/redone, so give them a special check in order
// not to confuse users
if (name == wxT("Undo"))
{
node.label = _("Undo");
}
else if (name == wxT("Redo"))
{
node.label = _("Redo");
}
else
{
auto label = labels[i];
node.label = label.Strip().Translation();
}
// Fill in remaining info
node.name = name;
node.key = keys[i];
node.index = nodecnt++;
node.depth = depth;
// Add it to the tree
mNodes.push_back(node);
// Measure key
GetTextExtent(node.key.Display(), &x, &y);
mLineHeight = wxMax(mLineHeight, y);
mKeyWidth = wxMax(mKeyWidth, x);
// Prepend prefix for all view types to determine maximum
// column widths
wxString label = node.label;
if (!node.prefix.empty())
{
label = node.prefix + wxT(" - ") + label;
}
// Measure label
GetTextExtent(label, &x, &y);
mLineHeight = wxMax(mLineHeight, y);
mCommandWidth = wxMax(mCommandWidth, x);
}
#if 0
// For debugging
for (int j = 0; j < mNodes.size(); j++)
{
KeyNode & node = mNodes[j];
wxLogDebug(wxT("NODE line %4d index %4d depth %1d open %1d parent %1d cat %1d pfx %1d name %s STR %s | %s | %s"),
node.line,
node.index,
node.depth,
node.isopen,
node.isparent,
node.iscat,
node.ispfx,
node.name,
node.category,
node.prefix,
node.label);
}
#endif
// Update horizontal scrollbar
UpdateHScroll();
// Refresh the view lines
RefreshLines(bSort);
// Set the selected node if we've just reprepared the list and nothing was selected.
if ((GetSelection()==wxNOT_FOUND) && bSort )
{
SelectNode(LineToIndex(0));
}
}
//
// Refresh the list of lines within the current view
//
void
KeyView::RefreshLines(bool bSort)
{
int cnt = (int) mNodes.size();
int linecnt = 0;
mLines.clear();
// Process a filter if one is set
if (!mFilter.empty())
{
// Examine all nodes
for (int i = 0; i < cnt; i++)
{
KeyNode & node = mNodes[i];
// Reset line number
node.line = wxNOT_FOUND;
// Search columns based on view type
wxString searchit;
switch (mViewType)
{
// The x"01" separator is used to prevent finding a
// match comprising the end of the label and beginning
// of the key. It was chosen since it's not very likely
// to appear in the filter itself.
case ViewByTree:
searchit = node.label.Lower() +
wxT("\01x") +
node.key.Display().Lower();
break;
case ViewByName:
searchit = node.label.Lower();
break;
case ViewByKey:
searchit = node.key.Display().Lower();
break;
}
if (searchit.Find(mFilter) == wxNOT_FOUND)
{
// Not found so continue to next node
continue;
}
// For the Key View, if the filter is a single character,
// then it has to be the last character in the searchit string,
// and be preceded by nothing or +.
if ((mViewType == ViewByKey) &&
(mFilter.length() == 1) &&
(mFilter != searchit.Last() ||
((searchit.length() > 1) &&
((wxString)(searchit.GetChar(searchit.length() - 2)) != wxT("+")))))
{
// Not suitable so continue to next node
continue;
}
// For tree view, we must make sure all parent nodes are included
// whether they match the filter or not.
if (mViewType == ViewByTree)
{
std::vector<KeyNode*> queue;
int depth = node.depth;
// This node is a category or prefix node, so always mark them
// as open.
//
// What this is really doing is resolving a situation where the
// the filter matches a parent node and nothing underneath. In
// this case, the node would never be marked as open.
if (node.isparent)
{
node.isopen = true;
}
// Examine siblings until a parent is found.
for (int j = node.index - 1; j >= 0 && depth > 0; j--)
{
// Found a parent
if (mNodes[j].depth < depth)
{
// Examine all previously added nodes to see if this nodes
// ancestors need to be added prior to adding this node.
bool found = false;
for (int k = (int) mLines.size() - 1; k >= 0; k--)
{
// The node indexes match, so we've found the parent of the
// child node.
if (mLines[k]->index == mNodes[j].index)
{
found = true;
break;
}
}
// The parent wasn't found so remember it for later
// addition. Can't add directory to mLines here since
// they will wind up in reverse order.
if (!found)
{
queue.push_back(&mNodes[j]);
}
// Traverse up the tree
depth = mNodes[j].depth;
}
}
// Add any queues nodes to list. This will all be
// parent nodes, so mark them as open.
for (int j = (int) queue.size() - 1; j >= 0; j--)
{
queue[j]->isopen = true;
queue[j]->line = linecnt++;
mLines.push_back(queue[j]);
}
}
// Finally add the child node
node.line = linecnt++;
mLines.push_back(&node);
}
}
else
{
// Examine all nodes - non-filtered
for (int i = 0; i < cnt; i++)
{
KeyNode & node = mNodes[i];
// Reset line number
node.line = wxNOT_FOUND;
// Node is either a category or prefix
if (node.isparent)
{
// Only need to do this for tree views
if (mViewType != ViewByTree)
{
continue;
}
// Add the node
node.line = linecnt++;
mLines.push_back(&node);
// If this node is not open, then skip all of its descendants
if (!node.isopen)
{