1 // Copyright 2001-2019 Crytek GmbH / Crytek Group. All rights reserved.
4 using System
.Collections
.Generic
;
6 using System
.Windows
.Forms
;
7 using Aga
.Controls
.Tree
.NodeControls
;
10 namespace Aga
.Controls
.Tree
12 partial class TreeViewAdv
14 private TreeNodeAdv _editingNode
;
16 public EditableControl CurrentEditorOwner { get; private set; }
17 public Control CurrentEditor { get; private set; }
19 public void HideEditor()
21 if (CurrentEditorOwner
!= null)
22 CurrentEditorOwner
.EndEdit(false);
25 internal void DisplayEditor(Control editor
, EditableControl owner
)
27 if (editor
== null || owner
== null || CurrentNode
== null)
28 throw new ArgumentNullException();
32 CurrentEditor
= editor
;
33 CurrentEditorOwner
= owner
;
34 _editingNode
= CurrentNode
;
36 editor
.Validating
+= EditorValidating
;
41 owner
.UpdateEditor(editor
);
44 internal bool HideEditor(bool applyChanges
)
46 if (CurrentEditor
!= null)
54 //Check once more if editor was closed in ApplyChanges
55 if (CurrentEditor
!= null)
57 CurrentEditor
.Validating
-= EditorValidating
;
58 CurrentEditorOwner
.DoDisposeEditor(CurrentEditor
);
60 CurrentEditor
.Parent
= null;
61 CurrentEditor
.Dispose();
64 CurrentEditorOwner
= null;
71 private bool ApplyChanges()
75 CurrentEditorOwner
.ApplyChanges(_editingNode
, CurrentEditor
);
76 _errorProvider
.Clear();
79 catch (ArgumentException ex
)
81 _errorProvider
.SetError(CurrentEditor
, ex
.Message
);
82 /*CurrentEditor.Validating -= EditorValidating;
83 MessageBox.Show(this, ex.Message, "Value is not valid", MessageBoxButtons.OK, MessageBoxIcon.Warning);
84 CurrentEditor.Focus();
85 CurrentEditor.Validating += EditorValidating;*/
90 void EditorValidating(object sender
, System
.ComponentModel
.CancelEventArgs e
)
92 e
.Cancel
= !ApplyChanges();
95 public void UpdateEditorBounds()
97 if (CurrentEditor
!= null)
99 EditorContext context
= new EditorContext();
100 context
.Owner
= CurrentEditorOwner
;
101 context
.CurrentNode
= CurrentNode
;
102 context
.Editor
= CurrentEditor
;
103 context
.DrawContext
= _measureContext
;
104 SetEditorBounds(context
);
108 private void SetEditorBounds(EditorContext context
)
110 foreach (NodeControlInfo info
in GetNodeControls(context
.CurrentNode
))
112 if (context
.Owner
== info
.Control
&& info
.Control
is EditableControl
)
114 Point p
= info
.Bounds
.Location
;
115 p
.X
+= info
.Control
.LeftMargin
;
117 p
.Y
-= (_rowLayout
.GetRowBounds(FirstVisibleRow
).Y
- ColumnHeaderHeight
);
118 int width
= DisplayRectangle
.Width
- p
.X
;
119 if (UseColumns
&& info
.Control
.ParentColumn
!= null && Columns
.Contains(info
.Control
.ParentColumn
))
121 Rectangle rect
= GetColumnBounds(info
.Control
.ParentColumn
.Index
);
122 width
= rect
.Right
- OffsetX
- p
.X
;
124 context
.Bounds
= new Rectangle(p
.X
, p
.Y
, width
, info
.Bounds
.Height
);
125 ((EditableControl
)info
.Control
).SetEditorBounds(context
);
131 private Rectangle
GetColumnBounds(int column
)
134 for (int i
= 0; i
< Columns
.Count
; i
++)
136 if (Columns
[i
].IsVisible
)
139 x
+= Columns
[i
].Width
;
141 return new Rectangle(x
, 0, Columns
[i
].Width
, 0);
144 return Rectangle
.Empty
;