CPF/CPF.ReoGrid/Views/ViewportController.cs
2024-06-24 10:15:59 +08:00

237 lines
4.4 KiB
C#

using System;
using System.Collections.Generic;
using CPF.Drawing;
using CPF.Input;
using CPF.ReoGrid.Interaction;
using CPF.ReoGrid.Rendering;
namespace CPF.ReoGrid.Views
{
internal class ViewportController : IViewportController, IUserVisual, IVisualController
{
public Worksheet Worksheet
{
get
{
return this.worksheet;
}
}
public ViewportController(Worksheet sheet)
{
this.worksheet = sheet;
this.view = new View(this);
this.view.Children = new List<IView>();
}
public virtual Rect Bounds
{
get
{
return this.view.Bounds;
}
set
{
this.view.Bounds = value;
}
}
public virtual float ScaleFactor
{
get
{
return (this.View == null) ? 1f : this.View.ScaleFactor;
}
set
{
bool flag = this.View != null;
if (flag)
{
this.View.ScaleFactor = value;
}
}
}
public virtual IView View
{
get
{
return this.view;
}
set
{
this.view = value;
}
}
internal virtual void AddView(IView view)
{
this.view.Children.Add(view);
view.ViewportController = this;
}
internal virtual void InsertView(IView before, IView viewport)
{
IList<IView> children = this.view.Children;
int num = children.IndexOf(before);
bool flag = num > 0 && num < children.Count;
if (flag)
{
children.Insert(num, viewport);
}
else
{
children.Add(viewport);
}
}
internal virtual void InsertView(int index, IView viewport)
{
this.view.Children.Insert(index, viewport);
}
internal virtual bool RemoveView(IView view)
{
bool flag = this.view.Children.Remove(view);
bool result;
if (flag)
{
view.ViewportController = null;
result = true;
}
else
{
result = false;
}
return result;
}
internal bool IsViewVisible(ViewTypes head)
{
return (this.viewsVisible & head) == head;
}
public virtual void SetViewVisible(ViewTypes head, bool visible)
{
if (visible)
{
this.viewsVisible |= head;
}
else
{
this.viewsVisible &= ~head;
}
}
public virtual void UpdateController()
{
}
public virtual void Reset()
{
}
public virtual void Invalidate()
{
bool flag = this.worksheet != null;
if (flag)
{
this.worksheet.RequestInvalidate();
}
}
public virtual void Draw(CellDrawingContext dc)
{
bool flag = this.view.Visible && this.view.Width > 0f && this.view.Height > 0f;
if (flag)
{
this.view.Draw(dc);
}
this.worksheet.viewDirty = false;
}
public virtual IView FocusView { get; set; }
public virtual IUserVisual FocusVisual { get; set; }
public virtual bool OnMouseDown(Point location, MouseButtons buttons, InputModifiers modifiers)
{
bool flag = false;
bool flag2 = !flag;
if (flag2)
{
IView viewByPoint = this.view.GetViewByPoint(location);
bool flag3 = viewByPoint != null;
if (flag3)
{
flag = viewByPoint.OnMouseDown(viewByPoint.PointToView(location), buttons, modifiers);
}
}
return flag;
}
public virtual bool OnMouseMove(Point location, MouseButtons buttons)
{
bool flag = false;
bool flag2 = this.FocusView != null;
if (flag2)
{
this.FocusView.OnMouseMove(this.FocusView.PointToView(location), buttons);
}
bool flag3 = !flag;
if (flag3)
{
IView viewByPoint = this.view.GetViewByPoint(location);
bool flag4 = viewByPoint != null;
if (flag4)
{
flag = viewByPoint.OnMouseMove(viewByPoint.PointToView(location), buttons);
}
}
return flag;
}
public virtual bool OnMouseUp(Point location, MouseButtons buttons, InputModifiers modifiers)
{
bool result = false;
bool flag = this.FocusView != null;
if (flag)
{
result = this.FocusView.OnMouseUp(this.FocusView.PointToView(location), buttons, modifiers);
}
return result;
}
public virtual bool OnMouseDoubleClick(Point location, MouseButtons buttons)
{
bool result = false;
IView view = (this.FocusView != null) ? this.FocusView : this.view.GetViewByPoint(location);
bool flag = view != null;
if (flag)
{
result = view.OnMouseDoubleClick(view.PointToView(location), buttons);
}
return result;
}
public virtual bool OnKeyDown(KeyCode key)
{
return false;
}
public virtual void SetFocus()
{
}
public virtual void FreeFocus()
{
}
internal Worksheet worksheet;
protected IView view;
protected ViewTypes viewsVisible = ViewTypes.LeadHeader;
}
}