-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathBrowseViewer.cs
More file actions
4332 lines (3952 loc) · 142 KB
/
BrowseViewer.cs
File metadata and controls
4332 lines (3952 loc) · 142 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
// Copyright (c) 2003-2017 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using SIL.FieldWorks.Common.FwUtils;
using static SIL.FieldWorks.Common.FwUtils.FwUtils;
using SIL.FieldWorks.Common.RootSites;
using SIL.FieldWorks.Common.ViewsInterfaces;
using SIL.FieldWorks.Filters;
using SIL.FieldWorks.Resources;
using SIL.LCModel;
using SIL.LCModel.Application;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;
using SIL.LCModel.Utils;
using SIL.PlatformUtilities;
using SIL.Reporting;
using SIL.Utils;
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Security;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using XCore;
namespace SIL.FieldWorks.Common.Controls
{
/// <summary>
/// This class is the arguments for a CheckBoxChangedEventHandler.
/// </summary>
public class CheckBoxChangedEventArgs : EventArgs
{
/// <summary>
///
/// </summary>
protected int[] m_hvoChanged;
/// <summary>
/// Initializes a new instance of the <see><cref>T:CheckBoxChangedEventArgs</cref></see> class.
/// </summary>
/// <param name="hvosChanged">The hvos changed.</param>
public CheckBoxChangedEventArgs(int[] hvosChanged)
{
m_hvoChanged = hvosChanged;
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets the hvos changed.
/// </summary>
/// <value>The hvos changed.</value>
/// ------------------------------------------------------------------------------------
public int[] HvosChanged
{
get { return m_hvoChanged; }
}
}
/// <summary>
/// This class is the arguments for a ClickCopyEventHandler.
/// </summary>
public class CheckBoxActiveChangedEventArgs : CheckBoxChangedEventArgs
{
private string m_redoMessage;
private string m_undoMessage;
/// <summary>
/// Initializes a new instance of the <see><cref>T:CheckBoxChangedEventArgs</cref></see> class.
/// </summary>
/// <param name="hvosChanged">The hvos changed.</param>
/// <param name="undoMessage">The message to use in any undo message</param>
/// <param name="redoMessage">The message to use in any redo message</param>
public CheckBoxActiveChangedEventArgs(int[] hvosChanged, string undoMessage, string redoMessage)
: base(hvosChanged)
{
m_undoMessage = undoMessage;
m_redoMessage = redoMessage;
}
/// <summary>
///
/// </summary>
public string UndoMessage
{
get { return m_undoMessage; }
}
/// <summary>
///
/// </summary>
public string RedoMessage
{
get { return m_redoMessage; }
}
}
/// <summary>
/// This is used for a slice to ask the data tree to display a context menu.
/// </summary>
public delegate void CheckBoxChangedEventHandler(object sender, CheckBoxChangedEventArgs e);
/// <summary>
///
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public delegate void CheckBoxActiveChangedEventHandler(object sender, CheckBoxActiveChangedEventArgs e);
#region ISortItemProvider declaration
/// <summary>
/// This interface is used for the BrowseViewer (specifically the Vc) to call back to the
/// RecordList (which it can't otherwise know about, because of avoiding circular dependencies)
/// and get the IManyOnePathSortItem for an item it is trying to display.
/// </summary>
public interface ISortItemProvider
{
/// ------------------------------------------------------------------------------------
/// <summary>
/// Sorts the item at.
/// </summary>
/// <param name="index">The index.</param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
IManyOnePathSortItem SortItemAt(int index);
/// ------------------------------------------------------------------------------------
/// <summary>
/// Appends the items for.
/// </summary>
/// <param name="hvo">The hvo.</param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
int AppendItemsFor(int hvo);
/// ------------------------------------------------------------------------------------
/// <summary>
/// Removes the items for.
/// </summary>
/// <param name="hvo">The hvo.</param>
/// ------------------------------------------------------------------------------------
void RemoveItemsFor(int hvo);
/// ------------------------------------------------------------------------------------
/// <summary>
/// Get the index of the given object, or -1 if it's not in the list.
/// </summary>
/// <param name="hvo"></param>
/// <returns></returns>
/// ------------------------------------------------------------------------------------
int IndexOf(int hvo);
/// <summary>
/// Class of objects being displayed in this list.
/// </summary>
int ListItemsClass { get; }
}
#endregion ISortItemProvider declaration
#region BrowseViewer class
/// <summary>
/// BrowseViewer is a container for various windows related to browsing. At a minimum it contains
/// a DhListView which provides the column headers and an XmlBrowseView that contains the
/// actual browse view. It may also have a FilterBar, and eventually other controls, e.g.,
/// for filling in columns of data.
/// </summary>
public class BrowseViewer : XCoreUserControl, ISnapSplitPosition, IxCoreContentControl, IPostLayoutInit, IRefreshableRoot
{
/// <summary>
/// Check state for items (check and uncheck only).
/// </summary>
internal protected enum CheckState
{
/// <summary>
///
/// </summary>
ToggleAll,
/// <summary>
///
/// </summary>
UncheckAll,
/// <summary>
///
/// </summary>
CheckAll
}
private readonly DisposableObjectsSet<RecordSorter> m_SortersToDispose = new DisposableObjectsSet<RecordSorter>();
private LcmCache m_cache;
private XmlNode m_nodeSpec;
/// <summary/>
protected DhListView m_lvHeader;
private RecordSorter m_sorter;
/// <summary>
/// Required designer variable.
/// </summary>
private IContainer components = null;
/// <summary></summary>
protected internal XmlBrowseViewBase m_xbv;
/// <summary></summary>
protected internal FilterBar m_filterBar;
/// <summary></summary>
protected internal RecordFilter m_currentFilter;
/// <summary>REFACTOR: this variable should be removed and handled through events. Having this here is bad design.</summary>
protected internal BulkEditBar m_bulkEditBar;
internal ISortItemProvider m_sortItemProvider;
private int m_lastLayoutWidth = 0;
/// <summary>
/// This cache is a 'Decorator' of the main FDO ISilDataAccess implementation.
/// This class adds support for fake flids used by the Browse view system,
/// which would normally not be available in the min FDO SDA implementation.
/// </summary>
private XMLViewsDataCache m_specialCache;
/// <summary></summary>
protected int m_icolCurrent = 0;
// bool m_doHScroll = false;
/// <summary/>
protected Button m_configureButton;
private Button m_checkMarkButton;
/// <summary/>
protected BrowseViewScroller m_scrollContainer = null;
/// <summary/>
protected ScrollBar m_scrollBar;
private ToolTip m_tooltip;
private bool m_listModificationInProgress;
private bool m_fFilterInitializationComplete = false;
private int[] m_colWidths; // Last values computed and set by AdjustColumnWidths.
// This flag is used to minimize redoing the filtering and sorting when
// changing the list of columns shown.
private bool m_fUpdatingColumnList = false;
/// <summary></summary>
protected internal Mediator m_mediator;
/// <summary></summary>
protected internal PropertyTable m_propertyTable;
/// <summary></summary>
public event FilterChangeHandler FilterChanged;
/// <summary>
/// Invoked when check box status alters. Typically there is only one item changed
/// (the one the user clicked on); in this case, client should generate PropChanged as needed
/// to update the display. When the user does something like CheckAll, a list is sent; in this case,
/// AFTER invoking the event, the browse view does a Reconstruct, so generating PropChanged is not
/// necessary (or helpul, unless some other view also needs updating).
/// </summary>
public event CheckBoxChangedEventHandler CheckBoxChanged;
/// <summary>
/// This event notifies you that the selected object changed, passing an argument from which you can
/// directly obtain the new object. If you care more about the position of the object in the list
/// (especially if the list may contain duplicates), you may wish to use the SelectedIndexChanged
/// event instead. This SelectionChangedEvent will not fire if the selection moves from one
/// occurrene of an object to another occurrence of the same object.
/// </summary>
public event FwSelectionChangedEventHandler SelectionChanged;
/// <summary>
/// This event notifies you that a selection was made with a double click, passing an argument
/// containing both the index and the hvo of the selected object. This happens currently only
/// for read-only views.
/// </summary>
public event FwSelectionChangedEventHandler SelectionMade;
/// <summary>
/// This event notifies you that the selected index changed. You can find the current index from
/// the SelectedIndex property, and look up the object if needed...but if you mainly care about
/// the object, it is probably better to use SelectionChangedEvent.
/// This is very nearly redundant...perhaps it would be better to just add an index to the
/// SelectionChanged event and fire it if either index or object changes...
/// </summary>
public event EventHandler SelectedIndexChanged;
/// <summary></summary>
public event EventHandler SorterChanged;
/// <summary> Target Column can be selected by the BulkEdit bar which may need to reorient the
/// RecordClerk to build a list based upon another RootObject class.</summary>
public event TargetColumnChangedHandler TargetColumnChanged;
/// <summary>
/// Fired whenever a column width or column order changes
/// </summary>
public event EventHandler ColumnsChanged;
/// <summary></summary>
public event EventHandler ListModificationInProgressChanged;
/// <summary></summary>
public event EventHandler SelectionDrawingFailure;
/// <summary>
/// EventHandler used when a refresh of the BrowseView has been performed.
/// </summary>
public event EventHandler RefreshCompleted;
/// <summary>
/// Handler to use when checking if two sorters are compatible, should be implemented in the Clerk
/// </summary>
public event SortCompatibleHandler SortersCompatible;
/// <summary>
/// True during a major change that affects the master list of objects.
/// The current example is deleting multiple objects from the list at once.
/// This is set true (and the corresponding event raised) at the start of the operation,
/// and back to false at the end. A client may want to suppress handling PropChanged
/// during the complex operation, and simply reload the list at the end.
/// </summary>
public bool ListModificationInProgress
{
get
{
CheckDisposed();
return m_listModificationInProgress;
}
}
/// <summary>
/// calls Focus on the important child control
/// </summary>
/// <param name="e"></param>
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
if (m_xbv != null && !m_xbv.Focused)
m_xbv.Focus();
}
/// <summary>
/// Update the selected cache for the given item.
/// </summary>
public void OnUpdateItemCheckedState(object obj)
{
if (obj is ICmObject)
{
int hvoItem = ((ICmObject)obj).Hvo;
int currentValue = GetCheckState(hvoItem);
SetItemCheckedState(hvoItem, currentValue, false);
}
}
/// <summary>
/// This supports external clients using the Bulk Edit Preview functionality.
/// To turn on, set to the index of the column that should have the preview
/// (zero based, not counting the check box column). To turn off, set to -1.
/// </summary>
public int PreviewColumn
{
get
{
int val = m_specialCache.get_IntProp(RootObjectHvo, XMLViewsDataCache.ktagActiveColumn);
if (val <= 0)
return -1;
else
return val - 1;
}
set
{
using (new ReconstructPreservingBVScrollPosition(this))
{
// No direct caching of fake stuff, but we can use the 'Decorator' SDA,
// as it won't affect the data store wit this flid.
//Cache.VwCacheDaAccessor.CacheIntProp(RootObjectHvo, XmlBrowseViewVc.ktagActiveColumn, value + 1);
m_specialCache.SetInt(RootObjectHvo, XMLViewsDataCache.ktagActiveColumn, value + 1);
if (!m_xbv.Vc.HasPreviewArrow && value >= 0)
m_xbv.Vc.PreviewArrow = BulkEditBar.PreviewArrowStatic;
} // Does RootBox.Reconstruct() here
}
}
/// <summary>
/// This also is part of making bulk edit-type previews available.
/// For each object that should have a preview alternate, cache a (non-multi) string value
/// that is the alternate, using this flid. Initialize all the values before setting the PreviewColumn.
/// (Enhance JohnT: possibly we could provide an event that is fired when we need previews of
/// a range of columns, triggered by LoadDataFor in the VC.)
/// </summary>
public int PreviewValuesTag
{
get { return XMLViewsDataCache.ktagAlternateValue; }
}
/// <summary>
/// Yet another part of enabling preview...must be set for each item that is 'enabled', that is,
/// it makes sense for it to be changed.
/// </summary>
public int PreviewEnabledTag
{
get { return XMLViewsDataCache.ktagItemEnabled; }
}
internal void SetListModificationInProgress(bool val)
{
CheckDisposed();
if (m_listModificationInProgress == val)
return;
m_listModificationInProgress = val;
if (ListModificationInProgressChanged != null)
ListModificationInProgressChanged(this, EventArgs.Empty);
}
/// <summary>
/// Receive a notification that a mouse-up has completed in the browse view.
/// </summary>
internal virtual void BrowseViewMouseUp(MouseEventArgs e)
{
CheckDisposed();
int dpiX = GetDpiX();
int selColWidth = m_xbv.Vc.SelectColumnWidth * dpiX / 72000;
if (m_xbv.Vc.HasSelectColumn && e.X < selColWidth)
{
int[] hvosChanged = new[] { m_xbv.SelectedObject };
// we've changed the state of a check box.
OnCheckBoxChanged(hvosChanged);
}
if (m_bulkEditBar != null && m_bulkEditBar.Visible)
m_bulkEditBar.UpdateEnableItems(m_xbv.SelectedObject);
}
/// <summary>
///
/// </summary>
/// <param name="hvosChanged"></param>
protected virtual void OnCheckBoxChanged(int[] hvosChanged)
{
try
{
if (CheckBoxChanged == null)
return;
CheckBoxChanged(this, new CheckBoxChangedEventArgs(hvosChanged));
}
finally
{
// if a check box has changed by user, clear any record of preserving for a mixed class,
// since we always want to try to stay consistent with the user's choice in checkbox state.
if (!m_fInUpdateCheckedItems)
{
m_lastChangedSelectionListItemsClass = 0;
OnListItemsAboutToChange(hvosChanged);
}
}
}
/// <summary>
/// Gets the inner XmlBrowseViewBase class.
/// </summary>
public XmlBrowseViewBase BrowseView
{
get
{
CheckDisposed();
return m_xbv;
}
}
/// <summary>
/// bulk edit bar, if one is installed. <c>null</c> if not.
/// </summary>
public BulkEditBar BulkEditBar
{
get
{
CheckDisposed();
return m_bulkEditBar;
}
}
internal LcmCache Cache
{
get
{
CheckDisposed();
return m_cache;
}
}
/// <summary>
/// Get the special 'Decorator' ISilDataAccess cache.
/// </summary>
public XMLViewsDataCache SpecialCache
{
get { return m_specialCache; }
}
internal FilterBar FilterBar
{
get
{
CheckDisposed();
return m_filterBar;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the sort item provider.
/// </summary>
/// <value>The sort item provider.</value>
/// ------------------------------------------------------------------------------------
public ISortItemProvider SortItemProvider
{
get
{
CheckDisposed();
return m_sortItemProvider;
}
}
internal int ListItemsClass
{
get { return m_xbv.Vc.ListItemsClass; }
}
/// <summary>
/// flags if the BrowseViewer has already sync'd its filters to the record clerk.
/// </summary>
private bool FilterInitializationComplete
{
get { return m_fFilterInitializationComplete; }
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// If the view has or might have a filter bar, call this after initialization to
/// ensure that it is synchronized with the current filter in the Clerk.
/// </summary>
/// <param name="currentFilter">The current filter.</param>
/// ------------------------------------------------------------------------------------
public void UpdateFilterBar(RecordFilter currentFilter)
{
CheckDisposed();
if (m_filterBar != null)
{
m_currentFilter = currentFilter;
if (!m_fFilterInitializationComplete)
{
// If we can append matching columns, then sync to the new list.
if (AppendMatchingHiddenColumns(currentFilter))
{
UpdateColumnList(); // adjusts columns and syncs all filters.
m_fFilterInitializationComplete = true;
return;
}
}
else
{
// May have some active already. Remove them.
RemoveFilters(this);
if (currentFilter == null)
{
return;
}
}
// syncs filters to currently shown columns.
m_filterBar.UpdateActiveItems(currentFilter);
}
SetBrowseViewSpellingStatus();
m_fFilterInitializationComplete = true;
}
// Called when filter is initialized or changed, sets desired spelling status.
private void SetBrowseViewSpellingStatus()
{
BrowseView.DoSpellCheck = WantBrowseSpellingStatus();
}
/// <summary>
/// We want to show spelling status if any spelling filters are active.
/// </summary>
/// <returns></returns>
private bool WantBrowseSpellingStatus()
{
if (m_currentFilter == null)
return false;
if (m_currentFilter is FilterBarCellFilter)
return (m_currentFilter as FilterBarCellFilter).Matcher is BadSpellingMatcher;
if (m_currentFilter is AndFilter)
{
foreach (object item in (m_currentFilter as AndFilter).Filters)
if (item is FilterBarCellFilter && (item as FilterBarCellFilter).Matcher is BadSpellingMatcher)
return true;
}
return false;
}
/// <summary>
/// Return the index of the 'selected' row in the main browse view.
/// Returns -1 if nothing is selected.
/// If the selection spans multiple rows, returns the anchor row.
/// If in select-only mode, there may be no selection, but it will then be the row
/// last clicked.
/// </summary>
public int SelectedIndex
{
get
{
CheckDisposed();
return m_xbv.SelectedIndex;
}
set
{
CheckDisposed();
m_xbv.SelectedIndex = value;
}
}
/// <summary>
/// Gets the column count. This count does not include the check box column.
/// </summary>
/// <value>The column count.</value>
public int ColumnCount
{
get
{
CheckDisposed();
return ColumnSpecs.Count;
}
}
/// <summary>
/// Gets the name of the specified column. The specified index is zero-based, it should
/// not include the check box column.
/// </summary>
/// <param name="icol">The index of the column.</param>
/// <returns>The column name</returns>
public string GetColumnName(int icol)
{
return XmlUtils.GetAttributeValue(ColumnSpecs[icol], "label");
}
/// <summary>
/// Gets the default sort column. The returned index is zero-based, it does not include
/// the check box column.
/// </summary>
/// <value>The default sort column.</value>
public virtual int DefaultSortColumn
{
get
{
CheckDisposed();
// the default column is always the first column
return 0;
}
}
/// <summary>
/// Gets the sorted columns. The returned indices are zero-based, they do not include
/// the check box column. Based off of InitSorter()
/// </summary>
/// <value>The sorted columns.</value>
public List<int> SortedColumns
{
get
{
CheckDisposed();
var cols = new List<int>();
if (m_filterBar != null && m_filterBar.ColumnInfo.Length > 0 && m_sorter != null)
{
if (m_sorter is AndSorter)
{
ArrayList sorters = (m_sorter as AndSorter).Sorters;
foreach (object sorterObj in sorters)
{
int icol = ColumnInfoIndexOfCompatibleSorter(sorterObj as RecordSorter);
if (icol >= 0)
cols.Add(icol);
}
}
else
{
int icol = ColumnInfoIndexOfCompatibleSorter(m_sorter);
if (icol >= 0)
cols.Add(icol);
}
}
return cols;
}
}
/// <summary>
/// Set/Get the sorter. Setting using this does not raise SorterChanged...it's meant
/// to be used to initialize it by the client.
/// </summary>
public RecordSorter Sorter
{
get
{
CheckDisposed();
return m_sorter;
}
set
{
CheckDisposed();
m_sorter = value;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Set the sorter and raise the SortChanged event.
/// </summary>
/// <param name="sorter">The sorter.</param>
/// <param name="fTriggerChanged">if set to <c>true</c> [f trigger changed].</param>
/// ------------------------------------------------------------------------------------
private void SetAndRaiseSorter(RecordSorter sorter, bool fTriggerChanged)
{
SyncSortArrows(sorter);
Sorter = sorter;
if (fTriggerChanged && SorterChanged != null)
SorterChanged(this, EventArgs.Empty);
}
internal void RaiseSelectionDrawingFailure()
{
CheckDisposed();
if (SelectionDrawingFailure != null)
SelectionDrawingFailure(this, EventArgs.Empty);
}
/// <summary>
/// Set up all of the sort arrows based on the sorter
/// </summary>
/// <param name="sorter">The sorter</param>
private void SyncSortArrows(RecordSorter sorter)
{
ResetSortArrowColumn();
if (sorter == null)
return;
ArrayList sorters;
if (sorter is AndSorter)
sorters = ((AndSorter)sorter).Sorters;
else
{
sorters = new ArrayList();
sorters.Add(sorter);
}
for (int i = 0; i < sorters.Count; i++)
{
// set our current column to the one we are sorting.
int ifsi = ColumnInfoIndexOfCompatibleSorter((RecordSorter)sorters[i]);
// set our header column arrow
SortOrder order = SortOrder.Ascending;
var grs = sorters[i] as GenRecordSorter;
if (grs != null)
{
var sfc = grs.Comparer as StringFinderCompare;
if (sfc != null)
order = sfc.Order;
}
int iHeaderColumn = ColumnHeaderIndex(ifsi);
if (i == 0)
SetSortArrowColumn(iHeaderColumn, order, DhListView.ArrowSize.Large);
else if (i == 1)
SetSortArrowColumn(iHeaderColumn, order, DhListView.ArrowSize.Medium);
else
SetSortArrowColumn(iHeaderColumn, order, DhListView.ArrowSize.Small);
Logger.WriteEvent(String.Format("Sort on {0} {1} ({2})",
m_lvHeader.ColumnsInDisplayOrder[iHeaderColumn].Text, order, i));
}
m_lvHeader.Refresh();
}
// Sets the sort arrow for the given header column. Also sets the current column if
// its a valid header column.
private void SetSortArrowColumn(int iSortArrowColumn, SortOrder order, DhListView.ArrowSize size)
{
if (iSortArrowColumn >= 0)
m_icolCurrent = iSortArrowColumn;
m_lvHeader.ShowHeaderIcon(iSortArrowColumn, order, size);
}
// Resets all column sort arrows
private void ResetSortArrowColumn()
{
for (int i = 0; i < m_lvHeader.Columns.Count; i++)
m_lvHeader.ShowHeaderIcon(i, SortOrder.None, DhListView.ArrowSize.Large);
}
/// <summary>
/// the object that has properties that are shown by this view.
/// </summary>
/// <remarks> this will be changed often in the case where this view is dependent on another one;
/// that is, or some other browse view has a list and each time to selected item changes, our
/// root object changes.
/// </remarks>
public int RootObjectHvo
{
get
{
CheckDisposed();
return m_xbv.RootObjectHvo;
}
set
{
CheckDisposed();
m_xbv.RootObjectHvo = value;
}
}
/// <summary>
/// Set the stylesheet used to display information.
/// </summary>
public IVwStylesheet StyleSheet
{
get
{
CheckDisposed();
return m_xbv.StyleSheet;
}
set
{
CheckDisposed();
m_xbv.StyleSheet = value;
if (m_filterBar != null)
m_filterBar.SetStyleSheet(value);
if (m_bulkEditBar != null)
m_bulkEditBar.SetStyleSheet(value);
}
}
/// <summary>
/// The top-level property of RootObjectHvo that we are displaying.
/// </summary>
public int MainTag
{
get
{
CheckDisposed();
return m_xbv.MainTag;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Default constructor is required for some reason I (JohnT) forget, probably to do with
/// design mode. Don't use it.
/// </summary>
/// ------------------------------------------------------------------------------------
public BrowseViewer()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call
base.AccNameDefault = "BrowseViewer"; // default accessibility name
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Initializes a new instance of the <see cref="T:BrowseViewer"/> class.
/// The sortItemProvider is typically the RecordList that impelements sorting and
/// filtering of the items we are displaying.
/// The data access passed typically is a decorator for the one in the cache, adding
/// the sorted, filtered list of objects accessed as property fakeFlid of hvoRoot.
/// </summary>
/// ------------------------------------------------------------------------------------
public BrowseViewer(XmlNode nodeSpec, int hvoRoot, int fakeFlid,
LcmCache cache, Mediator mediator, PropertyTable propertyTable, ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
{
ContructorSurrogate(nodeSpec, hvoRoot, fakeFlid, cache, mediator, propertyTable, sortItemProvider, sda);
}
/// <summary>
/// This caches selected states for objects in bulk edit views.
/// We want to allow a second copy of such a bulk edit to have different selections.
/// So we only store something here when we dispose of an old view. The next one opened
/// with the same parameters will have the same selections as the last one closed.
/// The key is the nodeSpec passed to the constructor surrogate and the hvoRoot.
/// The value is the
/// </summary>
static Dictionary<Tuple<XmlNode, int>, Tuple<Dictionary<int, int>, bool>> s_selectedCache
= new Dictionary<Tuple<XmlNode, int>, Tuple<Dictionary<int, int>, bool>>();
internal void ContructorSurrogate(XmlNode nodeSpec, int hvoRoot, int fakeFlid,
LcmCache cache, Mediator mediator, PropertyTable propertyTable, ISortItemProvider sortItemProvider, ISilDataAccessManaged sda)
{
CheckDisposed();
m_nodeSpec = nodeSpec;
m_cache = cache;
Tuple<Dictionary<int, int>, bool> selectedInfo;
var key = new Tuple<XmlNode, int>(nodeSpec, hvoRoot);
if (s_selectedCache.TryGetValue(key, out selectedInfo))
{
m_specialCache = new XMLViewsDataCache(sda, selectedInfo.Item2, selectedInfo.Item1);
s_selectedCache.Remove(key); // don't reuse again while this view is open
}
else
{
m_specialCache = new XMLViewsDataCache(sda, nodeSpec);
}
m_mediator = mediator;
m_propertyTable = propertyTable;
m_lvHeader = new DhListView(this);
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
SuspendLayout();
m_scrollContainer = new BrowseViewScroller(this);
m_scrollContainer.AutoScroll = true;
m_scrollContainer.TabStop = false;
Controls.Add(m_scrollContainer);
m_scrollBar = new VScrollBar();
//m_scrollBar.Scroll += new ScrollEventHandler(m_scrollBar_Scroll);
m_scrollBar.ValueChanged += m_scrollBar_ValueChanged;
m_scrollBar.TabStop = false;
Controls.Add(m_scrollBar);
// Set this before creating the browse view class so that custom parts can be
// generated properly.
m_sortItemProvider = sortItemProvider;
// Make the right subclass of XmlBrowseViewBase first, the column header creation uses information from it.
CreateBrowseViewClass(hvoRoot, fakeFlid, mediator, propertyTable);
// This would eventually get set in the startup process later, but we need it at least by the time
// we make the filter bar so the LayoutCache exists.
BrowseView.Vc.Cache = cache;
BrowseView.Vc.DataAccess = m_specialCache;
m_scrollContainer.SuspendLayout();
//
// listView1
//
//m_lvHeader.Dock = System.Windows.Forms.DockStyle.Top;
m_lvHeader.Name = "HeaderListView";
m_lvHeader.Size = new Size(4000, 22);
m_lvHeader.TabIndex = 0;
m_lvHeader.View = View.Details;
if (Platform.IsMono)
{
// FWNX-224
m_lvHeader.ColumnLeftClick += m_lvHeader_ColumnLeftClick;
}
else
m_lvHeader.ColumnClick += m_lvHeader_ColumnLeftClick;
m_lvHeader.ColumnRightClick += m_lvHeader_ColumnRightClick;
m_lvHeader.ColumnDragDropReordered += m_lvHeader_ColumnDragDropReordered;
m_lvHeader.AllowColumnReorder = true;
m_lvHeader.AccessibleName = "HeaderListView";
m_lvHeader.Scrollable = false; // don't EVER show scroll bar in it!!
m_lvHeader.TabStop = false;
//AddControl(m_lvHeader); Do this after making the filter bar if any.
Name = "BrowseView";
Size = new Size(400, 304);
if (ColumnIndexOffset() > 0)
{
ColumnHeader ch = new ColumnHeader {Text = ""};
m_lvHeader.Columns.Add(ch);
}
if (m_xbv.Vc.ShowColumnsRTL)
{
for (int i = ColumnSpecs.Count - 1; i >= 0; --i)
{
XmlNode node = ColumnSpecs[i];
ColumnHeader ch = MakeColumnHeader(node);
m_lvHeader.Columns.Add(ch);
}
}
else
{
for (int i = 0; i < ColumnSpecs.Count; ++i)
{
XmlNode node = ColumnSpecs[i];
ColumnHeader ch = MakeColumnHeader(node);
m_lvHeader.Columns.Add(ch);
}
}
// set default property, so it doesn't accidentally get set
// in OnPropertyChanged() when user right clicks for the first time (cf. LT-2789).
m_propertyTable.SetDefault("SortedFromEnd", false, PropertyTable.SettingsGroup.LocalSettings, false);
// set default property, so it doesn't accidentally get set
// in OnPropertyChanged() when user right clicks for the first time (cf. LT-2789).
m_propertyTable.SetDefault("SortedByLength", false, PropertyTable.SettingsGroup.LocalSettings, false);
//
// FilterBar
//
XmlAttribute xa = m_nodeSpec.Attributes["filterBar"];
if (xa != null && xa.Value == "true")
{
m_filterBar = new FilterBar(this, m_nodeSpec, m_propertyTable.GetValue<IApp>("App"));