-
-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathSlice.cs
More file actions
3340 lines (2947 loc) · 99.6 KB
/
Slice.cs
File metadata and controls
3340 lines (2947 loc) · 99.6 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) 2014-2018 SIL International
// This software is licensed under the LGPL, version 2.1 or later
// (http://www.gnu.org/licenses/lgpl-2.1.html)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using SIL.FieldWorks.Common.Controls;
using SIL.FieldWorks.Common.Framework.DetailControls.Resources;
using SIL.FieldWorks.Common.FwUtils;
using SIL.FieldWorks.Common.RootSites;
using SIL.FieldWorks.FdoUi;
using SIL.FieldWorks.LexText.Controls;
using SIL.LCModel;
using SIL.LCModel.Core.Cellar;
using SIL.LCModel.Core.KernelInterfaces;
using SIL.LCModel.Infrastructure;
using SIL.LCModel.Utils;
using SIL.PlatformUtilities;
using SIL.Utils;
using XCore;
namespace SIL.FieldWorks.Common.Framework.DetailControls
{
enum Direction
{
Up, Down
}
/// <summary>
/// A Slice is essentially one row of a tree.
/// It contains both a SliceTreeNode on the left of the splitter line, and a
/// (optional) subclass of control on the right.
/// </summary>
/// <remarks>Slices know about drawing labels, measuring height, dealing with drag operations
/// within the tree for this item, knowing whether the item can be expanded,
/// and optionally drawing the part of the tree that is opposite the item, and
/// many other things.}
///</remarks>
public class Slice : UserControl, IxCoreColleague
{
#region Constants
/// <summary>
/// If label width is made wider than this, switch to full labels.
/// </summary>
const int MaxAbbrevWidth = 60;
#endregion Constants
#region Data members
/// <summary>
/// Subscribe to this event if you want to provide a Context menu for this slice
/// </summary>
public event TreeNodeEventHandler ShowContextMenu;
protected PropertyTable m_propertyTable;
// These two variables allow us to save the parameters passed in IxCoreColleage.Init
// so we can pass them on when our control is set.
protected Mediator m_mediator;
XmlNode m_configurationParameters;
//test
// protected MenuController m_menuController= null;
protected ImageCollection m_smallImages = null;
//end test
protected int m_indent = 0;
protected DataTree.TreeItemState m_expansion = DataTree.TreeItemState.ktisFixed; // Default is not expandable.
protected string m_strLabel;
protected string m_strAbbr;
protected bool m_isHighlighted = false;
protected Font m_fontLabel = new Font(MiscUtils.StandardSansSerif, 10);
protected XmlNode m_configurationNode; // If this slice was generated from an XmlNode, store it here.
protected XmlNode m_callerNode; // This stores the layout time caller for menu processing
protected Point m_location;
protected ICmObject m_obj; // The object that will be the context if our children are expanded, or for figuring
// what things can be inserted here.
protected object[] m_key; // Key indicates path of nodes and objects used to construct this.
protected LcmCache m_cache;
// Indicates the 'weight' of object that starts at the top of this slice.
// By default a slice is just considered to be a field (of the same object as the one before).
protected ObjectWeight m_weight = ObjectWeight.field;
protected bool m_widthHasBeenSetByDataTree = false;
protected IPersistenceProvider m_persistenceProvider;
protected Slice m_parentSlice;
private readonly SplitContainer m_splitter;
#endregion Data members
#region Properties
/// <summary>
/// The weight of object that starts at the beginning of this slice.
/// </summary>
public ObjectWeight Weight
{
get
{
CheckDisposed();
return m_weight;
}
set
{
CheckDisposed();
m_weight = value;
}
}
/// <summary></summary>
public ContextMenu RetrieveContextMenuForHotlinks()
{
CheckDisposed();
if (ParentForm?.Name == "PopupToolWindow")
{
return null;
}
return ContainingDataTree.GetSliceContextMenu(this, true);
}
/// <summary></summary>
public object[] Key
{
get
{
CheckDisposed();
return m_key;
}
set
{
CheckDisposed();
m_key = value;
}
}
/// ------------------------------------------------------------------------------------
/// <summary>
/// Gets or sets the mediator.
/// </summary>
/// ------------------------------------------------------------------------------------
public virtual Mediator Mediator
{
get
{
CheckDisposed();
return m_mediator;
}
set
{
CheckDisposed();
m_mediator = value;
var rs = Control as SimpleRootSite;
if (rs != null)
{
rs.Init(Mediator, m_propertyTable, m_configurationNode); // Init it as xCoreColleague.
}
else if (Control != null)
{
// If not a SimpleRootSite, maybe it owns one. Init that as xCoreColleague.
for (int i = 0; i < Control.Controls.Count; ++i)
{
rs = Control.Controls[i] as SimpleRootSite;
if (rs != null)
rs.Init(Mediator, m_propertyTable, m_configurationNode);
}
}
}
}
public PropertyTable PropTable
{
get { return m_propertyTable; }
set { m_propertyTable = value; }
}
/// <summary></summary>
public IPersistenceProvider PersistenceProvider
{
get
{
CheckDisposed();
return m_persistenceProvider;
}
set
{
CheckDisposed();
m_persistenceProvider = value;
}
}
/// <summary></summary>
public DataTree ContainingDataTree
{
get
{
CheckDisposed();
return Parent as DataTree;
}
}
protected internal SplitContainer SplitCont
{
get
{
CheckDisposed();
return Controls[0] as SplitContainer;
}
}
/// <summary></summary>
public SliceTreeNode TreeNode
{
get
{
CheckDisposed();
return SplitCont.Panel1.Controls[0] as SliceTreeNode;
}
}
/// <summary></summary>
public LcmCache Cache
{
get
{
CheckDisposed();
return m_cache;
}
set
{
CheckDisposed();
m_cache = value;
}
}
/// <summary></summary>
public ICmObject Object
{
get
{
CheckDisposed();
return m_obj;
}
set
{
CheckDisposed();
m_obj = value;
}
}
/// <summary>
/// the XmlNode that was used to construct this slice
/// </summary>
public XmlNode ConfigurationNode
{
get
{
CheckDisposed();
return m_configurationNode;
}
set
{
CheckDisposed();
m_configurationNode = value;
}
}
/// <summary>
/// This node stores the caller for future processing
/// </summary>
public XmlNode CallerNode
{
get
{
CheckDisposed();
return m_callerNode;
}
set
{
CheckDisposed();
m_callerNode = value;
}
}
/// <summary>
/// Check if the value of this slices CallerNode is equal to the value of the CallerNode passed in.
/// </summary>
/// <returns>true if the values are equal, false if the values are not equal</returns>
public bool CallerNodeEqual(XmlNode otherNode)
{
return CallerNode.OuterXml == otherNode.OuterXml;
}
// Review JohnT: or just make it public? Or make more delegation methods?
/// <summary></summary>
public virtual Control Control
{
get
{
CheckDisposed();
Debug.Assert(SplitCont.Panel2.Controls.Count == 0 || SplitCont.Panel2.Controls.Count == 1);
return SplitCont.Panel2.Controls.Count == 1 ? SplitCont.Panel2.Controls[0] : null;
}
set
{
CheckDisposed();
Debug.Assert(SplitCont.Panel2.Controls.Count == 0);
if (value != null)
{
SplitCont.Panel2.Controls.Add(value);
// mediator was set first; pass it to colleague.
if (m_mediator != null && value is IxCoreColleague)
(value as IxCoreColleague).Init(m_mediator, m_propertyTable, m_configurationParameters);
}
}
}
/// <summary>
/// this tells whether the slice should be treated as a handle on the owned atomic object which it
/// refers to, for the purposes of deletion, copy, etc. For example, the Pronunciation field of
/// LexVariant owns a LexPronunciation, so the Pronunciation field should have this attribute set.
/// </summary>
/// <example>MoEndoCompound has a "linker" slice which actually just wraps the attributes of a
/// MoForm that is owned in the linker attribute. so when the user opens the context menu on this slice
/// he really wants to be operating on the linker, not be owning MoEndoCompound.
/// Another example. LexVariant owns an atomic LexPronunciation in a Pronunciation field. If we set
/// wrapsAtomic for the Pronunciation field, then this returns true, allowing an Insert Pronunciation
/// menu to activate.</example>
public bool WrapsAtomic
{
get
{
CheckDisposed();
return XmlUtils.GetOptionalBooleanAttributeValue(m_configurationNode, "wrapsAtomic", false);
}
}
/// <summary>
/// is this node representing a property which is an (ordered) sequence?
/// </summary>
public bool IsSequenceNode
{
get
{
CheckDisposed();
if (ConfigurationNode == null)
return false;
XmlNode node = ConfigurationNode.SelectSingleNode("seq");
if (node == null)
return false;
string field = XmlUtils.GetOptionalAttributeValue(node, "field");
if (string.IsNullOrEmpty(field))
return false;
Debug.Assert(m_obj != null, "JH Made a false assumption!");
int flid = GetFlid(field);
Debug.Assert(flid != 0); // current field should have ID!
//at this point we are not even thinking about showing reference sequences in the DataTree
//so I have not dealt with that
return (GetFieldType(flid) == (int)CellarPropertyType.OwningSequence);
}
}
/// <summary>
/// is this node representing a property which is an (unordered) collection?
/// </summary>
public bool IsCollectionNode
{
get
{
CheckDisposed();
if (ConfigurationNode == null)
return false;
return ConfigurationNode.SelectSingleNode("seq") != null && !IsSequenceNode;
}
}
/// <summary>
/// is this node a header?
/// </summary>
public bool IsHeaderNode
{
get
{
CheckDisposed();
return XmlUtils.GetOptionalAttributeValue(ConfigurationNode, "header") == "true";
}
}
/// <summary>
/// whether the label should be highlighted or not
/// </summary>
public bool Highlighted
{
set
{
CheckDisposed();
bool current = m_isHighlighted;
m_isHighlighted = value;
// See LT-5415 for how to get here with TreeNode == null, possibly while this
// slice is being disposed in the call to the base class Dispose method.
// If TreeNode is null, then this object has been disposed.
// Since we now throw an exception, in the CheckDisposed method if it is disposed,
// there is now no reason to ask if it is null.
if (current != m_isHighlighted)
Refresh();
//TreeNode.Refresh();
}
}
/// <summary></summary>
public ImageCollection SmallImages
{
get
{
CheckDisposed();
return null; //no tree icons
}
set
{
CheckDisposed();
m_smallImages = value;
}
}
#endregion Properties
#region Construction and initialization
/// <summary></summary>
public Slice()
{
// Create a SplitContainer to hold the two (or one control.
m_splitter = new SplitContainer {TabStop = false, AccessibleName = "Slice.SplitContainer"};
// Do this once right away, mainly so child controls like check box that don't control
// their own height will get it right; then after the controls get added to it, don't do it again
// until our own size is definitely established by SetWidthForDataTreeLayout.
m_splitter.Size = Size;
Controls.Add(m_splitter);
// This is really important. Since some slices are invisible, all must be,
// or Show() will reorder them.
Visible = false;
}
/// <summary></summary>
public Slice(Control ctrlT)
: this()
{
if(ctrlT != Control)
Control = ctrlT;
#if _DEBUG
Control.CheckForIllegalCrossThreadCalls = true;
#endif
}
/// <summary>
/// This method should be called once the various properties of the slice have been set,
/// particularly the Cache, Object, Key, and Spec. The slice may create its Control in
/// this method, so don't assume it exists before this is called. It should be called
/// before installing the slice.
/// </summary>
public virtual void FinishInit()
{
CheckDisposed();
}
protected override void OnEnter(EventArgs e)
{
CheckDisposed();
base.OnEnter(e);
if (ContainingDataTree == null || ContainingDataTree.ConstructingSlices) // FWNX-423, FWR-2508
return;
ContainingDataTree.CurrentSlice = this;
TakeFocus(false);
}
#endregion Construction and initialization
#region Miscellaneous UI methods
protected virtual string HelpId
{
get
{
CheckDisposed();
//if the idea has not been added, try using the "field" attribute as the key
return XmlUtils.GetAttributeValue(ConfigurationNode, "id")
?? XmlUtils.GetAttributeValue(ConfigurationNode, "field");
}
}
/// <summary>
/// This is passed the color that the XDE specified, if any, otherwise null.
/// The default is to use the normal window color for editable text.
/// Subclasses which know they should have a different default should
/// override this method, but normally should use the specified color if not
/// null.
/// </summary>
/// <param name="backColorName">Name of the back color.</param>
public virtual void OverrideBackColor(String backColorName)
{
CheckDisposed();
if (Control == null)
return;
if (backColorName != null)
{
Control.BackColor = backColorName == "Control" ? Color.FromKnownColor(KnownColor.ControlLight) : Color.FromName(backColorName);
}
else
Control.BackColor = SystemColors.Window;
}
/// <summary>
/// We tend to get a visual stuttering effect if sub-controls are made visible before the
/// main slice is correctly positioned. This method is called after the slice is positioned
/// to give it a chance to make embedded controls visible.
/// This default implementation does nothing.
/// </summary>
public virtual void ShowSubControls()
{
CheckDisposed();
}
#endregion Miscellaneous UI methods
#region events, clicking, etc.
/// <summary></summary>
public void OnTreeNodeClick(object sender, EventArgs args)
{
CheckDisposed();
TakeFocus();
}
/// <summary></summary>
public void TakeFocus()
{
CheckDisposed();
TakeFocus(true);
}
/// <summary>
/// The slice should become the focus slice (and return true).
/// If the fOkToFocusTreeNode argument is false, this should happen iff it has a control which
/// is appropriate to focus.
/// Note: JohnT: recently I noticed that trying to focus the tree node doesn't seem to do
/// anything; I'm not sure passing true is useful.
/// </summary>
public bool TakeFocus(bool fOkToFocusTreeNode)
{
CheckDisposed();
Control ctrl = Control;
if (!Visible)
{
if ((ctrl != null && ctrl.TabStop) || fOkToFocusTreeNode)
{
// We very possibly want to focus this node, but .NET won't let us focus it till it is visible.
// Make it so.
DataTree.MakeSliceVisible(this);
}
}
if (ctrl != null && ctrl.CanFocus && ctrl.TabStop)
{
ctrl.Focus();
}
else if (fOkToFocusTreeNode)
{
TreeNode.Focus();
}
else
return false;
//this is a bit of a hack, because focus and OnEnter are related but not equivalent...
//some slices never get an on enter, but claim to be focus-able.
if (ContainingDataTree.CurrentSlice != this)
ContainingDataTree.CurrentSlice = this;
return true;
}
/// <summary>
/// Focus the main child control, if possible.
/// </summary>
protected override void OnGotFocus(EventArgs e)
{
CheckDisposed();
if (Disposing)
return;
DataTree.MakeSliceVisible(this); // otherwise no change our control can take focus.
base.OnGotFocus(e);
if (Control != null && Control.CanFocus)
Control.Focus();
}
#endregion events, clicking, etc.
#region Tree management
/// <summary>
/// In some contexts we insert into the slice array a 'dummy' slice
/// which can handle some queries directly (e.g., it may know
/// its indentation level) but needs to 'BecomeReal' if it becomes
/// fully visible. The purpose is laziness...often we insert the
/// same dummy slice into many locations, and they are progressively
/// replaced with real ones.
/// </summary>
public virtual bool IsRealSlice
{
get
{
CheckDisposed();
return true;
}
}
/// <summary>
/// In some contexts, we use a "ghost" slice to represent data that
/// has not yet been created. These are "real" slices, but they don't
/// represent "real" data. Thus, for example, the underlying object
/// can't be deleted because it doesn't exist. (But the ghost slice
/// may claim to have an object, because it needs such information to
/// create the data once the user decides to type something...
/// </summary>
public virtual bool IsGhostSlice
{
get
{
CheckDisposed();
return false;
}
}
/// <summary>
/// Some 'unreal' slices can become 'real' (ready to actually display) without
/// actually replacing themselves with a different object. Such slices override
/// this method to do whatever is needed and then answer true. If a slice
/// answers false to IsRealSlice, this is tried, and if it returns false,
/// then BecomeReal is called.
/// </summary>
public virtual bool BecomeRealInPlace()
{
CheckDisposed();
return false;
}
/// <summary>
/// In some contexts we insert into the slice array
/// </summary>
public virtual Slice BecomeReal(int index)
{
CheckDisposed();
return this;
}
private void SetViewStylesheet(Control control, DataTree tc)
{
var rootSite = control as SimpleRootSite;
if (rootSite != null && rootSite.StyleSheet == null)
rootSite.StyleSheet = tc.StyleSheet;
foreach (Control c in control.Controls)
SetViewStylesheet(c, tc);
}
/// <summary></summary>
public virtual bool ShowContextMenuIconInTreeNode()
{
CheckDisposed();
return this == ContainingDataTree.CurrentSlice;
}
/// <summary></summary>
public virtual void SetCurrentState(bool isCurrent)
{
CheckDisposed();
if (Control != null && Control is INotifyControlInCurrentSlice && !BeingDiscarded)
(Control as INotifyControlInCurrentSlice).SliceIsCurrent = isCurrent;
if (TreeNode != null)
TreeNode.Invalidate();
Slice slice = this;
while (slice != null && !slice.IsDisposed)
{
slice.Active = isCurrent;
if (slice.IsHeaderNode)
break;
slice = slice.ParentSlice;
}
}
/// <summary></summary>
public virtual void Install(DataTree parent)
{
CheckDisposed();
if (parent == null) // Parent == null ||
throw new InvalidOperationException("The slice '" + GetType().Name + "' must be placed in the Parent.Controls property before installing it.");
SplitContainer sc = SplitCont;
// prevents the controls of the new 'SplitContainer' being NAMELESS
if (sc.Panel1.AccessibleName == null)
sc.Panel1.AccessibleName = "Panel1";
if (sc.Panel2.AccessibleName == null)
sc.Panel2.AccessibleName = "Panel2";
SliceTreeNode treeNode;
bool isBeingReused = sc.Panel1.Controls.Count > 0;
if (isBeingReused)
{
treeNode = (SliceTreeNode)sc.Panel1.Controls[0];
}
else
{
// Make a standard SliceTreeNode now.
treeNode = new SliceTreeNode(this);
treeNode.SuspendLayout();
treeNode.Dock = DockStyle.Fill;
sc.Panel1.Controls.Add(treeNode);
sc.AccessibleName = "SplitContainer";
}
if (!string.IsNullOrEmpty(Label))
{
// Susanna wanted to try five, rather than the default of four
// to see if wider and still invisble made it easier to work with.
// It may end up being made visible in a light grey color, but then it would
// go back to the default of four.
// Being visible at four may be too overpowering, so we may have to
// manually draw a thin line to give the user a que as to where the splitter bar is.
// Then, if it gets to be visible, we will probably need to add a bit of padding between
// the line and the main slice content, or its text will be connected to the line.
sc.SplitterWidth = 5;
// It was hard-coded to 40, but it isn't right for indented slices,
// as they then can be shrunk so narrow as to completely cover up their label.
sc.Panel1MinSize = (20 * (Indent + 1)) + 20;
sc.Panel2MinSize = 0; // min size of right pane
// This makes the splitter essentially invisible.
sc.BackColor = Color.FromKnownColor(KnownColor.Window); //to make it invisible
treeNode.MouseEnter += treeNode_MouseEnter;
treeNode.MouseLeave += treeNode_MouseLeave;
treeNode.MouseHover += treeNode_MouseEnter;
}
else
{
// SummarySlice is one of these kinds of Slices.
//Debug.WriteLine("Slice gets no usable splitter: " + GetType().Name);
sc.SplitterWidth = 1;
sc.Panel1MinSize = LabelIndent();
sc.SplitterDistance = LabelIndent();
sc.IsSplitterFixed = true;
// Just in case it was previously installed with a different label.
treeNode.MouseEnter -= treeNode_MouseEnter;
treeNode.MouseLeave -= treeNode_MouseLeave;
treeNode.MouseHover -= treeNode_MouseEnter;
}
int newHeight;
Control mainControl = Control;
if (mainControl != null)
{
// Has SliceTreeNode and Control.
// Set stylesheet on every view-based child control that doesn't already have one.
SetViewStylesheet(mainControl, parent);
mainControl.AccessibleName = string.IsNullOrEmpty(Label) ? "Slice_unknown" : Label;
// By default the height of the slice comes from the height of the embedded
// control.
// Just store the new height for now, as actually settig it, will cause events,
// and the slice has no parent yet, which will be bad for those event handlers.
//this.Height = Math.Max(Control.Height, LabelHeight);
newHeight = Math.Max(mainControl.Height, LabelHeight);
mainControl.Dock = DockStyle.Fill;
sc.FixedPanel = FixedPanel.Panel1;
}
else
{
// Has SliceTreeNode but no Control.
// LexReferenceMultiSlice has no control, as of 12/30/2006.
newHeight = LabelHeight;
sc.Panel2Collapsed = true;
sc.FixedPanel = FixedPanel.Panel2;
}
// REVIEW (Hasso) 2018.07: would it be better to check !parent.Controls.Contains(this)?
if (!isBeingReused)
{
parent.Controls.Add(this); // Parent will have to move it into the right place.
parent.Slices.Add(this);
}
if (Platform.IsMono)
{
// FWNX-266
if (mainControl != null && mainControl.Visible == false)
{
// ensure Launcher Control is shown.
mainControl.Visible = true;
}
}
SetSplitPosition();
// Don'f fire off all those size changed event handlers, unless it is really needed.
if (Height != newHeight)
Height = newHeight;
treeNode.ResumeLayout(false);
}
void treeNode_MouseLeave(object sender, EventArgs e)
{
Highlighted = false;
}
void treeNode_MouseEnter(object sender, EventArgs e)
{
Highlighted = true;
}
/// <summary>
/// Attempt to set the split position, but do NOT modify the global setting for
/// the data tree if unsuccessful. This occurs during window initialization, since
/// (I think) slices are created before the proper width is set for the containing
/// data pane, and the constraints on the width of the splitter may not allow it to
/// take on the persisted position.
/// </summary>
internal void SetSplitPosition()
{
SplitContainer sc = SplitCont;
Debug.Assert(sc != null, "LT-13912 -- Need to determine why the SplitContainer is null here.");
if (sc == null || sc.IsSplitterFixed) // LT-13912 apparently sc comes out null sometimes.
return;
int valueSansLabelindent = ContainingDataTree.SliceSplitPositionBase;
int correctSplitPosition = valueSansLabelindent + LabelIndent();
if (sc.SplitterDistance != correctSplitPosition)
{
sc.SplitterDistance = correctSplitPosition;
//if ((sc.SplitterDistance > MaxAbbrevWidth && valueSansLabelindent <= MaxAbbrevWidth)
// || (sc.SplitterDistance <= MaxAbbrevWidth && valueSansLabelindent > MaxAbbrevWidth))
//{
TreeNode.Invalidate();
//}
}
}
protected override void OnSizeChanged(EventArgs e)
{
CheckDisposed();
// Skip handling this, if the DataTree hasn't
// set the official width using SetWidthForDataTreeLayout
if (!m_widthHasBeenSetByDataTree)
return;
// LT-18750 Calling OnSizeChanged in the base class sometimes resets the AutoScrollPosition to the top of the Slice (Windows).
// When m_splitter.Size is changed, it also has the same effect. It is possible that ScrollControlIntoView() is called
// in a method subscribed to an event in the base class, but my investigation was unsuccessful.
Point oldPoint = ContainingDataTree.AutoScrollPosition;
bool scrollChanged = false;
base.OnSizeChanged(e);
if (ContainingDataTree.AutoScrollPosition != oldPoint)
{
scrollChanged = true;
}
int verticalAdjustment = Size.Height - m_splitter.Size.Height;
// This should be done by setting DockStyle to Fill but that somehow doesn't always fix the
// height of the splitter's panels.
m_splitter.Size = Size;
if (scrollChanged)
{
bool verticalScrollChangedCorrectly = ContainingDataTree.AutoScrollPosition.Y - oldPoint.Y == -verticalAdjustment;
if (!verticalScrollChangedCorrectly)
// Set the AutoScrollPosition to scroll the distance reflecting the change to the SplitContainer
ContainingDataTree.AutoScrollPosition = new Point(-oldPoint.X, -oldPoint.Y + verticalAdjustment);
}
// This definitely seems as if it shouldn't be necessary at all. And if it were necessary,
// it should be fine to just call PerformLayout at once. But it doesn't work. Dragging the splitter
// of a multi-line view in a way that changes its height somehow leaves the panels of the splitter
// a different height from the splitter itself, which means that when making it narrower,
// and therefore higher, the bottom of the longer view is cut off. This is the only workaround
// that I (JohnT) have been able to find. It's possible that something has layout suspended
// (since this can get called from OnSizeChanged of a child window, I think) and it only
// works to layout the splitter afterwards? Anyway this seems to work...test carefully if you
// think of taking it out.
if (m_splitter.Panel2.Height != this.Height)
{
Application.Idle += LayoutSplitter;
}
}
void LayoutSplitter(object sender, EventArgs e)
{
Application.Idle -= LayoutSplitter;
if (m_splitter != null && !IsDisposed)
m_splitter.PerformLayout();
}
/// <summary>
/// If we don't have a splitter (because no label), set the width of the
/// tree node directly; the other node's size is set by being docked 'fill'.
/// </summary>
/// <param name="levent"></param>
protected override void OnLayout(LayoutEventArgs levent)
{
CheckDisposed();
if (SplitCont.Panel2Collapsed)
TreeNode.Width = LabelIndent();
base.OnLayout(levent);
}
/// <summary>
/// Indicates whether this is an active slice, which means it displays extra
/// controls. Currently only SummarySlices can be active.
/// (We could use this for the context menu icon, but that only shows on
/// the actual current slice, whereas several slices may show commands.)
/// </summary>
public virtual bool Active
{
get
{
CheckDisposed();
return false;
}
set
{
CheckDisposed();
}
}
#region IDisposable override
/// <summary></summary>
public void CheckDisposed()
{
if (IsDisposed)
throw new ObjectDisposedException(ToString() + GetHashCode(), "Trying to use object that has been disposed.");
}
/// <summary>
/// Executes in two distinct scenarios.
///