Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/xwt.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs')
-rw-r--r--Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs198
1 files changed, 70 insertions, 128 deletions
diff --git a/Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs b/Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs
index ad3b7ab3..c83d0d77 100644
--- a/Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs
+++ b/Xwt.XamMac/Xwt.Mac/NSTableViewBackend.cs
@@ -32,29 +32,14 @@ using AppKit;
using CoreGraphics;
using Foundation;
using Xwt.Backends;
+using ObjCRuntime;
namespace Xwt.Mac
{
- public class NSTableViewBackend : NSTableView
+ public class NSTableViewBackend : NSTableView, IViewObject
{
- IWidgetEventSink eventSink;
- protected ApplicationContext context;
NSTrackingArea trackingArea; // Captures Mouse Entered, Exited, and Moved events
- class ListDelegate: NSTableViewDelegate
- {
- public override nfloat GetRowHeight (NSTableView tableView, nint row)
- {
- var height = tableView.RowHeight;
- for (int i = 0; i < tableView.ColumnCount; i++) {
- var cell = tableView.GetCell (i, row);
- if (cell != null)
- height = (nfloat) Math.Max (height, cell.CellSize.Height);
- }
- return height;
- }
- }
-
public override NSObject WeakDataSource {
get { return base.WeakDataSource; }
set {
@@ -71,39 +56,29 @@ namespace Xwt.Mac
internal void AutosizeColumns ()
{
+ if (DataSource == null || RowCount == 0)
+ return;
var columns = TableColumns ();
- foreach (var col in columns)
- AutosizeColumn (col);
- if (columns.Any (c => c.ResizingMask.HasFlag (NSTableColumnResizing.Autoresizing)))
+ if (columns.Length == 1 && columns[0].ResizingMask.HasFlag (NSTableColumnResizing.Autoresizing))
+ return;
+ var needsSizeToFit = false;
+ for (nint i = 0; i < columns.Length; i++) {
+ AutosizeColumn (columns[i], i);
+ needsSizeToFit |= columns[i].ResizingMask.HasFlag (NSTableColumnResizing.Autoresizing);
+ }
+ if (needsSizeToFit)
SizeToFit ();
}
- void AutosizeColumn (NSTableColumn tableColumn)
+ void AutosizeColumn (NSTableColumn tableColumn, nint colIndex)
{
- var column = IndexOfColumn (tableColumn);
-
- var s = tableColumn.HeaderCell.CellSize;
+ var contentWidth = tableColumn.HeaderCell.CellSize.Width;
if (!tableColumn.ResizingMask.HasFlag (NSTableColumnResizing.UserResizingMask)) {
- for (int i = 0; i < base.RowCount; i++)
- {
- var cell = base.GetCell (column, i);
- s.Width = (nfloat)Math.Max (s.Width, cell.CellSize.Width);
- }
+ contentWidth = Delegate.GetSizeToFitColumnWidth (this, colIndex);
if (!tableColumn.ResizingMask.HasFlag (NSTableColumnResizing.Autoresizing))
- tableColumn.Width = s.Width;
+ tableColumn.Width = contentWidth;
}
- tableColumn.MinWidth = s.Width;
- }
-
- nint IndexOfColumn (NSTableColumn tableColumn)
- {
- nint icol = -1;
- foreach (var col in TableColumns ()) {
- icol++;
- if (col == tableColumn)
- return icol;
- }
- return icol;
+ tableColumn.MinWidth = contentWidth;
}
public override void ReloadData ()
@@ -123,148 +98,115 @@ namespace Xwt.Mac
{
if (!columnResizeQueued) {
columnResizeQueued = true;
- Application.MainLoop.QueueExitAction (delegate {
+ (Backend.ApplicationContext.Toolkit.GetSafeBackend (Backend.ApplicationContext.Toolkit) as ToolkitEngineBackend).InvokeBeforeMainLoop (delegate {
columnResizeQueued = false;
AutosizeColumns ();
});
}
}
- public NSTableViewBackend(IWidgetEventSink eventSink, ApplicationContext context) {
- this.context = context;
- this.eventSink = eventSink;
- this.Delegate = new ListDelegate ();
+ public NSTableViewBackend (ListViewBackend viewBackend) {
+ Backend = viewBackend;
AllowsColumnReordering = false;
}
-
public ViewBackend Backend { get; set; }
- public NSTableView View {
+ public NSView View {
get { return this; }
}
+ public override void ResetCursorRects ()
+ {
+ base.ResetCursorRects ();
+ if (Backend.Cursor != null)
+ AddCursorRect (Bounds, Backend.Cursor);
+ }
+
public override void UpdateTrackingAreas ()
{
- if (trackingArea != null) {
- RemoveTrackingArea (trackingArea);
- trackingArea.Dispose ();
- }
- CGRect viewBounds = this.Bounds;
- var options = NSTrackingAreaOptions.MouseMoved | NSTrackingAreaOptions.ActiveInKeyWindow | NSTrackingAreaOptions.MouseEnteredAndExited;
- trackingArea = new NSTrackingArea (viewBounds, options, this, null);
- AddTrackingArea (trackingArea);
+ this.UpdateEventTrackingArea (ref trackingArea);
}
public override void RightMouseDown (NSEvent theEvent)
{
- base.RightMouseDown (theEvent);
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- ButtonEventArgs args = new ButtonEventArgs ();
- args.X = p.X;
- args.Y = p.Y;
- args.Button = PointerButton.Right;
- args.IsContextMenuTrigger = theEvent.TriggersContextMenu ();
- context.InvokeUserCode (delegate {
- eventSink.OnButtonPressed (args);
- });
+ if (!this.HandleMouseDown (theEvent))
+ base.RightMouseDown (theEvent);
}
public override void RightMouseUp (NSEvent theEvent)
{
- base.RightMouseUp (theEvent);
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- ButtonEventArgs args = new ButtonEventArgs ();
- args.X = p.X;
- args.Y = p.Y;
- args.Button = PointerButton.Right;
- context.InvokeUserCode (delegate {
- eventSink.OnButtonReleased (args);
- });
+ if (!this.HandleMouseUp (theEvent))
+ base.RightMouseUp (theEvent);
}
public override void MouseDown (NSEvent theEvent)
{
- base.MouseDown (theEvent);
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- ButtonEventArgs args = new ButtonEventArgs ();
- args.X = p.X;
- args.Y = p.Y;
- args.Button = PointerButton.Left;
- args.IsContextMenuTrigger = theEvent.TriggersContextMenu ();
- context.InvokeUserCode (delegate {
- eventSink.OnButtonPressed (args);
- });
+ if (!this.HandleMouseDown (theEvent))
+ base.MouseDown (theEvent);
}
public override void MouseUp (NSEvent theEvent)
{
- base.MouseUp (theEvent);
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- ButtonEventArgs args = new ButtonEventArgs ();
- args.X = p.X;
- args.Y = p.Y;
- args.Button = (PointerButton) (int)theEvent.ButtonNumber + 1;
- context.InvokeUserCode (delegate {
- eventSink.OnButtonReleased (args);
- });
+ if (!this.HandleMouseUp (theEvent))
+ base.MouseUp (theEvent);
+ }
+
+ public override void OtherMouseDown (NSEvent theEvent)
+ {
+ if (!this.HandleMouseDown (theEvent))
+ base.OtherMouseDown (theEvent);
+ }
+
+ public override void OtherMouseUp (NSEvent theEvent)
+ {
+ if (!this.HandleMouseUp (theEvent))
+ base.OtherMouseUp (theEvent);
}
public override void MouseEntered (NSEvent theEvent)
{
- context.InvokeUserCode (eventSink.OnMouseEntered);
+ this.HandleMouseEntered (theEvent);
}
public override void MouseExited (NSEvent theEvent)
{
- context.InvokeUserCode (eventSink.OnMouseExited);
+ this.HandleMouseExited (theEvent);
}
public override void MouseMoved (NSEvent theEvent)
{
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- MouseMovedEventArgs args = new MouseMovedEventArgs ((long) TimeSpan.FromSeconds (theEvent.Timestamp).TotalMilliseconds, p.X, p.Y);
- context.InvokeUserCode (delegate {
- eventSink.OnMouseMoved (args);
- });
+ if (!this.HandleMouseMoved (theEvent))
+ base.MouseMoved (theEvent);
}
- public override void MouseDragged (NSEvent theEvent)
+ public override void RightMouseDragged (NSEvent theEvent)
{
- var p = ConvertPointFromView (theEvent.LocationInWindow, null);
- MouseMovedEventArgs args = new MouseMovedEventArgs ((long) TimeSpan.FromSeconds (theEvent.Timestamp).TotalMilliseconds, p.X, p.Y);
- context.InvokeUserCode (delegate {
- eventSink.OnMouseMoved (args);
- });
+ if (!this.HandleMouseMoved (theEvent))
+ base.RightMouseDragged (theEvent);
}
- public override void KeyDown (NSEvent theEvent)
+ public override void MouseDragged (NSEvent theEvent)
{
- var keyArgs = theEvent.ToXwtKeyEventArgs ();
- context.InvokeUserCode (delegate {
- eventSink.OnKeyPressed (keyArgs);
- });
- if (keyArgs.Handled)
- return;
+ if (!this.HandleMouseMoved (theEvent))
+ base.MouseDragged (theEvent);
+ }
- var textArgs = new TextInputEventArgs (theEvent.Characters);
- if (!String.IsNullOrEmpty(theEvent.Characters))
- context.InvokeUserCode (delegate {
- eventSink.OnTextInput (textArgs);
- });
- if (textArgs.Handled)
- return;
+ public override void OtherMouseDragged (NSEvent theEvent)
+ {
+ if (!this.HandleMouseMoved (theEvent))
+ base.OtherMouseDragged (theEvent);
+ }
- base.KeyDown (theEvent);
+ public override void KeyDown (NSEvent theEvent)
+ {
+ if (!this.HandleKeyDown (theEvent))
+ base.KeyDown (theEvent);
}
public override void KeyUp (NSEvent theEvent)
{
- var keyArgs = theEvent.ToXwtKeyEventArgs ();
- context.InvokeUserCode (delegate {
- eventSink.OnKeyReleased (keyArgs);
- });
- if (!keyArgs.Handled)
+ if (!this.HandleKeyUp (theEvent))
base.KeyUp (theEvent);
}
}