Skip to content
This repository has been archived by the owner on Sep 4, 2024. It is now read-only.

[TreeView] [Gtk] [WPF] OnRowCollapsing and OnRowCollapsed implemented #348

Merged
merged 2 commits into from
Aug 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions TestApps/Samples/Samples/TreeViews.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,22 @@ public TreeViews ()
Console.WriteLine ("D:" + args.DeleteSource);
};
};
view.RowExpanding += delegate(object sender, TreeViewRowEventArgs e) {
var val = store.GetNavigatorAt (e.Position).GetValue (text);
Console.WriteLine("Expanding: " + val);
};
view.RowExpanded += delegate(object sender, TreeViewRowEventArgs e) {
var val = store.GetNavigatorAt (e.Position).GetValue (text);
Console.WriteLine("Expanded: " + val);
};
view.RowCollapsing += delegate(object sender, TreeViewRowEventArgs e) {
var val = store.GetNavigatorAt (e.Position).GetValue (text);
Console.WriteLine("Collapsing: " + val);
};
view.RowCollapsed += delegate(object sender, TreeViewRowEventArgs e) {
var val = store.GetNavigatorAt (e.Position).GetValue (text);
Console.WriteLine("Collapsed: " + val);
};

Button addButton = new Button ("Add");
addButton.Clicked += delegate(object sender, EventArgs e) {
Expand Down
38 changes: 36 additions & 2 deletions Xwt.Gtk/Xwt.GtkBackend/TreeViewBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,16 @@ public override void EnableEvent (object eventId)
Widget.RowActivated += HandleRowActivated;
break;
case TreeViewEvent.RowExpanding:
Widget.TestExpandRow += HandleTestExpandRow;;
Widget.TestExpandRow += HandleTestExpandRow;
break;
case TreeViewEvent.RowExpanded:
Widget.RowExpanded += HandleRowExpanded;;
Widget.RowExpanded += HandleRowExpanded;
break;
case TreeViewEvent.RowCollapsing:
Widget.TestCollapseRow += HandleTestCollapseRow;
break;
case TreeViewEvent.RowCollapsed:
Widget.RowCollapsed += HandleRowCollapsed;
break;
}
}
Expand All @@ -71,6 +77,12 @@ public override void DisableEvent (object eventId)
case TreeViewEvent.RowExpanded:
Widget.RowExpanded -= HandleRowExpanded;;
break;
case TreeViewEvent.RowCollapsing:
Widget.TestCollapseRow -= HandleTestCollapseRow;
break;
case TreeViewEvent.RowCollapsed:
Widget.RowCollapsed -= HandleRowCollapsed;
break;
}
}
}
Expand All @@ -97,6 +109,28 @@ void HandleTestExpandRow (object o, Gtk.TestExpandRowArgs args)
}
}

void HandleRowCollapsed (object o, Gtk.RowCollapsedArgs args)
{
Gtk.TreeIter it;
if (Widget.Model.GetIter (out it, args.Path)) {
CurrentEventRow = new IterPos (-1, it);
ApplicationContext.InvokeUserCode (delegate {
EventSink.OnRowCollapsed (new IterPos (-1, it));
});
}
}

void HandleTestCollapseRow (object o, Gtk.TestCollapseRowArgs args)
{
Gtk.TreeIter it;
if (Widget.Model.GetIter (out it, args.Path)) {
CurrentEventRow = new IterPos (-1, it);
ApplicationContext.InvokeUserCode (delegate {
EventSink.OnRowCollapsing (new IterPos (-1, it));
});
}
}

void HandleRowActivated (object o, Gtk.RowActivatedArgs args)
{
Gtk.TreeIter it;
Expand Down
7 changes: 7 additions & 0 deletions Xwt.WPF/Xwt.WPFBackend/ExTreeViewItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,19 @@ protected override void OnExpanded (RoutedEventArgs e)

protected override void OnCollapsed(RoutedEventArgs e)
{
var node = (TreeStoreNode)DataContext;
if (!IsExpanded)
UnselectChildren((object o, ExTreeViewItem i) =>
{
return i != this;
});
view.Backend.Context.InvokeUserCode (delegate {
((ITreeViewEventSink)view.Backend.EventSink).OnRowCollapsing (node);
});
base.OnCollapsed(e);
view.Backend.Context.InvokeUserCode (delegate {
((ITreeViewEventSink)view.Backend.EventSink).OnRowCollapsed (node);
});
}

public int Level {
Expand Down
6 changes: 5 additions & 1 deletion Xwt/Xwt.Backends/ITreeViewBackend.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,18 @@ public enum TreeViewEvent
{
RowActivated,
RowExpanding,
RowExpanded
RowExpanded,
RowCollapsing,
RowCollapsed
}

public interface ITreeViewEventSink: ITableViewEventSink
{
void OnRowActivated (TreePosition position);
void OnRowExpanding (TreePosition position);
void OnRowExpanded (TreePosition position);
void OnRowCollapsing (TreePosition position);
void OnRowCollapsed (TreePosition position);
}
}

66 changes: 65 additions & 1 deletion Xwt/Xwt/TreeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,17 @@ public void OnRowExpanding (TreePosition position)
{
((TreeView)Parent).OnRowExpanding (new TreeViewRowEventArgs (position));
}


public void OnRowCollapsed (TreePosition position)
{
((TreeView)Parent).OnRowCollapsed (new TreeViewRowEventArgs (position));
}

public void OnRowCollapsing (TreePosition position)
{
((TreeView)Parent).OnRowCollapsing (new TreeViewRowEventArgs (position));
}

public override Size GetDefaultNaturalSize ()
{
return Xwt.Backends.DefaultNaturalSizes.TreeView;
Expand All @@ -82,6 +92,8 @@ static TreeView ()
MapEvent (TreeViewEvent.RowActivated, typeof(TreeView), "OnRowActivated");
MapEvent (TreeViewEvent.RowExpanded, typeof(TreeView), "OnRowExpanded");
MapEvent (TreeViewEvent.RowExpanding, typeof(TreeView), "OnRowExpanding");
MapEvent (TreeViewEvent.RowCollapsed, typeof(TreeView), "OnRowCollapsed");
MapEvent (TreeViewEvent.RowCollapsing, typeof(TreeView), "OnRowCollapsing");
}

/// <summary>
Expand Down Expand Up @@ -515,6 +527,58 @@ public event EventHandler<TreeViewRowEventArgs> RowExpanded {
BackendHost.OnAfterEventRemove (TreeViewEvent.RowExpanded, rowExpanded);
}
}

/// <summary>
/// Raises the row collapsing event.
/// </summary>
/// <param name="a">The alpha component.</param>
protected virtual void OnRowCollapsing (TreeViewRowEventArgs a)
{
if (rowCollapsing != null)
rowCollapsing (this, a);
}

EventHandler<TreeViewRowEventArgs> rowCollapsing;

/// <summary>
/// Occurs just before a row is collapsed.
/// </summary>
public event EventHandler<TreeViewRowEventArgs> RowCollapsing {
add {
BackendHost.OnBeforeEventAdd (TreeViewEvent.RowCollapsing, rowCollapsing);
rowCollapsing += value;
}
remove {
rowCollapsing -= value;
BackendHost.OnAfterEventRemove (TreeViewEvent.RowCollapsing, rowCollapsing);
}
}

/// <summary>
/// Raises the row collapsing event.
/// </summary>
/// <param name="a">The alpha component.</param>
protected virtual void OnRowCollapsed (TreeViewRowEventArgs a)
{
if (rowCollapsed != null)
rowCollapsed (this, a);
}

EventHandler<TreeViewRowEventArgs> rowCollapsed;

/// <summary>
/// Occurs just before a row is collapsed
/// </summary>
public event EventHandler<TreeViewRowEventArgs> RowCollapsed {
add {
BackendHost.OnBeforeEventAdd (TreeViewEvent.RowCollapsed, rowCollapsed);
rowCollapsed += value;
}
remove {
rowCollapsed -= value;
BackendHost.OnAfterEventRemove (TreeViewEvent.RowCollapsed, rowCollapsed);
}
}
}

interface IColumnContainer
Expand Down