ListView and TreeView are now scrollable without the need of a ScrollView

This commit is contained in:
Lluis Sanchez 2012-03-29 15:09:09 +02:00
Родитель 6e77c810a1
Коммит b32e4f1283
13 изменённых файлов: 246 добавлений и 48 удалений

Просмотреть файл

@ -146,47 +146,21 @@ namespace Xwt.GtkBackend
public ScrollPolicy VerticalScrollPolicy {
get {
return ConvertPolicy (Widget.VscrollbarPolicy);
return Util.ConvertScrollPolicy (Widget.VscrollbarPolicy);
}
set {
Widget.VscrollbarPolicy = ConvertPolicy (value);
Widget.VscrollbarPolicy = Util.ConvertScrollPolicy (value);
}
}
public ScrollPolicy HorizontalScrollPolicy {
get {
return ConvertPolicy (Widget.HscrollbarPolicy);
return Util.ConvertScrollPolicy (Widget.HscrollbarPolicy);
}
set {
Widget.HscrollbarPolicy = ConvertPolicy (value);
Widget.HscrollbarPolicy = Util.ConvertScrollPolicy (value);
}
}
ScrollPolicy ConvertPolicy (Gtk.PolicyType p)
{
switch (p) {
case Gtk.PolicyType.Always:
return ScrollPolicy.Always;
case Gtk.PolicyType.Automatic:
return ScrollPolicy.Automatic;
case Gtk.PolicyType.Never:
return ScrollPolicy.Never;
}
throw new InvalidOperationException ("Invalid policy value:" + p);
}
Gtk.PolicyType ConvertPolicy (ScrollPolicy p)
{
switch (p) {
case ScrollPolicy.Always:
return Gtk.PolicyType.Always;
case ScrollPolicy.Automatic:
return Gtk.PolicyType.Automatic;
case ScrollPolicy.Never:
return Gtk.PolicyType.Never;
}
throw new InvalidOperationException ("Invalid policy value:" + p);
}
}
class CustomViewPort: Gtk.Bin

Просмотреть файл

@ -34,19 +34,43 @@ namespace Xwt.GtkBackend
{
public TableViewBackend ()
{
Widget = new CustomTreeView (this);
Widget.Show ();
var sw = new Gtk.ScrolledWindow ();
sw.Child = new CustomTreeView (this);
sw.Child.Show ();
sw.Show ();
base.Widget = sw;
}
protected new Gtk.TreeView Widget {
get { return (Gtk.TreeView)base.Widget; }
set { base.Widget = value; }
get { return (Gtk.TreeView)ScrolledWindow.Child; }
}
protected Gtk.ScrolledWindow ScrolledWindow {
get { return (Gtk.ScrolledWindow)base.Widget; }
}
protected new ITableViewEventSink EventSink {
get { return (ITableViewEventSink)base.EventSink; }
}
public ScrollPolicy VerticalScrollPolicy {
get {
return Util.ConvertScrollPolicy (ScrolledWindow.VscrollbarPolicy);
}
set {
ScrolledWindow.VscrollbarPolicy = Util.ConvertScrollPolicy (value);
}
}
public ScrollPolicy HorizontalScrollPolicy {
get {
return Util.ConvertScrollPolicy (ScrolledWindow.HscrollbarPolicy);
}
set {
ScrolledWindow.HscrollbarPolicy = Util.ConvertScrollPolicy (value);
}
}
public override void EnableEvent (object eventId)
{
base.EnableEvent (eventId);

Просмотреть файл

@ -76,9 +76,7 @@ namespace Xwt.GtkBackend
public void SetHeigth (object backend, double value)
{
Pango.Layout tl = (Pango.Layout)backend;
this.Heigth = value;
}
public void SetTrimming (object backend, TextTrimming textTrimming)

Просмотреть файл

@ -194,6 +194,32 @@ namespace Xwt.GtkBackend
{
return new Color ((double)color.Red / (double)ushort.MaxValue, (double)color.Green / (double)ushort.MaxValue, (double)color.Blue / (double)ushort.MaxValue);
}
public static ScrollPolicy ConvertScrollPolicy (Gtk.PolicyType p)
{
switch (p) {
case Gtk.PolicyType.Always:
return ScrollPolicy.Always;
case Gtk.PolicyType.Automatic:
return ScrollPolicy.Automatic;
case Gtk.PolicyType.Never:
return ScrollPolicy.Never;
}
throw new InvalidOperationException ("Invalid policy value:" + p);
}
public static Gtk.PolicyType ConvertScrollPolicy (ScrollPolicy p)
{
switch (p) {
case ScrollPolicy.Always:
return Gtk.PolicyType.Always;
case ScrollPolicy.Automatic:
return Gtk.PolicyType.Automatic;
case ScrollPolicy.Never:
return Gtk.PolicyType.Never;
}
throw new InvalidOperationException ("Invalid policy value:" + p);
}
}
}

Просмотреть файл

@ -55,6 +55,58 @@ namespace Xwt.Mac
Widget.AutoresizesSubviews = true;
}
public ScrollPolicy VerticalScrollPolicy {
get {
if (scroll.AutohidesScrollers && scroll.HasVerticalScroller)
return ScrollPolicy.Automatic;
else if (scroll.HasVerticalScroller)
return ScrollPolicy.Always;
else
return ScrollPolicy.Never;
}
set {
switch (value) {
case ScrollPolicy.Automatic:
scroll.AutohidesScrollers = true;
scroll.HasVerticalScroller = true;
break;
case ScrollPolicy.Always:
scroll.AutohidesScrollers = false;
scroll.HasVerticalScroller = true;
break;
case ScrollPolicy.Never:
scroll.HasVerticalScroller = false;
break;
}
}
}
public ScrollPolicy HorizontalScrollPolicy {
get {
if (scroll.AutohidesScrollers && scroll.HasHorizontalScroller)
return ScrollPolicy.Automatic;
else if (scroll.HasHorizontalScroller)
return ScrollPolicy.Always;
else
return ScrollPolicy.Never;
}
set {
switch (value) {
case ScrollPolicy.Automatic:
scroll.AutohidesScrollers = true;
scroll.HasHorizontalScroller = true;
break;
case ScrollPolicy.Always:
scroll.AutohidesScrollers = false;
scroll.HasHorizontalScroller = true;
break;
case ScrollPolicy.Never:
scroll.HasHorizontalScroller = false;
break;
}
}
}
protected override Size GetNaturalSize ()
{
return EventSink.GetDefaultNaturalSize ();

Просмотреть файл

@ -43,6 +43,20 @@ namespace Xwt.WPFBackend
ListView = new ExListView();
ListView.View = this.view;
}
// TODO
public Xwt.ScrollPolicy VerticalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
}
// TODO
public Xwt.ScrollPolicy HorizontalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
}
public bool HeadersVisible {
get { return this.headersVisible; }

Просмотреть файл

@ -82,6 +82,20 @@ namespace Xwt.WPFBackend
}
}
}
// TODO
public Xwt.ScrollPolicy VerticalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
}
// TODO
public Xwt.ScrollPolicy HorizontalScrollPolicy
{
get { return Xwt.ScrollPolicy.Automatic; }
set { }
}
internal MultiColumnTreeViewItem GenerateTreeViewItem (TreeNode node)
{

Просмотреть файл

@ -0,0 +1,36 @@
//
// IScrollableWidgetBackend.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace Xwt.Backends
{
public interface IScrollableWidgetBackend
{
ScrollPolicy VerticalScrollPolicy { get; set; }
ScrollPolicy HorizontalScrollPolicy { get; set; }
}
}

Просмотреть файл

@ -28,7 +28,7 @@ using System;
namespace Xwt.Backends
{
public interface ITableViewBackend: IWidgetBackend, IColumnContainerBackend
public interface ITableViewBackend: IWidgetBackend, IColumnContainerBackend, IScrollableWidgetBackend
{
void SetSelectionMode (SelectionMode mode);
void SelectAll ();

Просмотреть файл

@ -281,6 +281,8 @@
<Compile Include="Xwt\CursorType.cs" />
<Compile Include="Xwt\SelectColorDialog.cs" />
<Compile Include="Xwt.Backends\ISelectColorDialogBackend.cs" />
<Compile Include="Xwt\IScrollableWidget.cs" />
<Compile Include="Xwt.Backends\IScrollableWidgetBackend.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup />

Просмотреть файл

@ -0,0 +1,36 @@
//
// IScrollableWidget.cs
//
// Author:
// Lluis Sanchez <lluis@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace Xwt
{
public interface IScrollableWidget
{
ScrollPolicy VerticalScrollPolicy { get; set; }
ScrollPolicy HorizontalScrollPolicy { get; set; }
}
}

Просмотреть файл

@ -30,7 +30,7 @@ using System.ComponentModel;
namespace Xwt
{
public class ListView: Widget, IColumnContainer
public class ListView: Widget, IColumnContainer, IScrollableWidget
{
ListViewColumnCollection columns;
IListDataSource dataSource;
@ -62,6 +62,7 @@ namespace Xwt
public ListView ()
{
columns = new ListViewColumnCollection (this);
VerticalScrollPolicy = HorizontalScrollPolicy = ScrollPolicy.Automatic;
}
protected override Widget.EventSink CreateEventSink ()
@ -79,6 +80,16 @@ namespace Xwt
columns.Attach (Backend);
}
public ScrollPolicy VerticalScrollPolicy {
get { return Backend.VerticalScrollPolicy; }
set { Backend.VerticalScrollPolicy = value; }
}
public ScrollPolicy HorizontalScrollPolicy {
get { return Backend.HorizontalScrollPolicy; }
set { Backend.HorizontalScrollPolicy = value; }
}
public ListViewColumnCollection Columns {
get {
return columns;

Просмотреть файл

@ -33,7 +33,7 @@ using Xwt.Backends;
namespace Xwt
{
public class TreeView: Widget, IColumnContainer
public class TreeView: Widget, IColumnContainer, IScrollableWidget
{
ListViewColumnCollection columns;
ITreeDataSource dataSource;
@ -63,6 +63,18 @@ namespace Xwt
public TreeView ()
{
columns = new ListViewColumnCollection (this);
VerticalScrollPolicy = HorizontalScrollPolicy = ScrollPolicy.Automatic;
}
/// <summary>
/// Initializes a new instance of the <see cref="Xwt.TreeView"/> class.
/// </summary>
/// <param name='source'>
/// Data source
/// </param>
public TreeView (ITreeDataSource source): this ()
{
DataSource = source;
}
protected override Widget.EventSink CreateEventSink ()
@ -81,15 +93,14 @@ namespace Xwt
columns.Attach (Backend);
}
/// <summary>
/// Initializes a new instance of the <see cref="Xwt.TreeView"/> class.
/// </summary>
/// <param name='source'>
/// Data source
/// </param>
public TreeView (ITreeDataSource source): this ()
{
DataSource = source;
public ScrollPolicy VerticalScrollPolicy {
get { return Backend.VerticalScrollPolicy; }
set { Backend.VerticalScrollPolicy = value; }
}
public ScrollPolicy HorizontalScrollPolicy {
get { return Backend.HorizontalScrollPolicy; }
set { Backend.HorizontalScrollPolicy = value; }
}
/// <summary>