preliminary implementation of Spreadsheet plugin

This commit is contained in:
Michael Becker 2020-08-28 16:39:39 -04:00
parent cd05d0ee03
commit 6046b4c1ea
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
10 changed files with 593 additions and 0 deletions

View File

@ -0,0 +1,85 @@
//
// SheetControl.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using System.Runtime.InteropServices;
using MBS.Framework.Drawing;
using MBS.Framework.UserInterface;
using MBS.Framework.UserInterface.Drawing;
using UniversalEditor.ObjectModels.Spreadsheet;
namespace UniversalEditor.Plugins.Office.UserInterface.Editors.Spreadsheet.Controls
{
public class SheetControl : CustomControl
{
public Sheet Sheet { get; set; } = null;
public const int MAX_ROWS = 20;
public const int MAX_COLS = 20;
protected override void OnPaint(PaintEventArgs e)
{
if (Sheet == null) return;
SolidBrush bfg = new SolidBrush(SystemColors.WindowForeground);
Rectangle rectColumnHeader = new Rectangle(0, 0, 0, 13);
// draw the column headers first
for (int c = 0; c < MAX_COLS; c++)
{
string title = Sheet.Columns.Contains(c) ? Sheet.Columns[c].Title : c.ToString();
int colWidth = Sheet.Columns.Contains(c) ? Sheet.Columns[c].Width.GetValueOrDefault((Parent as SpreadsheetEditor).DefaultColumnWidth) : (Parent as SpreadsheetEditor).DefaultColumnWidth;
rectColumnHeader.Width = colWidth;
Rectangle rectColumnHeaderText = new Rectangle(rectColumnHeader.X, rectColumnHeader.Y, rectColumnHeader.Width, rectColumnHeader.Height);
e.Graphics.DrawText(title, null, rectColumnHeaderText, bfg, HorizontalAlignment.Center, VerticalAlignment.Middle);
rectColumnHeader.X += rectColumnHeader.Width;
}
Rectangle cellRect = new Rectangle(0, 0, (Parent as SpreadsheetEditor).DefaultColumnWidth, (Parent as SpreadsheetEditor).DefaultRowHeight);
for (int r = 0; r < MAX_ROWS; r++)
{
int rowheight = (Parent as SpreadsheetEditor).DefaultRowHeight;
if (Sheet.Rows.Contains(r))
rowheight = Sheet.Rows[r].Height.GetValueOrDefault((Parent as SpreadsheetEditor).DefaultRowHeight);
for (int c = 0; c < MAX_COLS; c++)
{
int colwidth = (Parent as SpreadsheetEditor).DefaultColumnWidth;
if (Sheet.Columns.Contains(c))
colwidth = Sheet.Columns[c].Width.GetValueOrDefault((Parent as SpreadsheetEditor).DefaultColumnWidth);
e.Graphics.FillRectangle(new SolidBrush(Colors.White), cellRect);
cellRect.X += colwidth + 1;
if (r == 0)
{
e.Graphics.DrawLine(new Pen(Colors.DarkGray), cellRect.X - 1, 0, cellRect.X - 1, Size.Height);
}
}
cellRect.X = 0;
cellRect.Y += rowheight + 1;
e.Graphics.DrawLine(new Pen(Colors.DarkGray), 0, cellRect.Y - 1, Size.Width, cellRect.Y - 1);
}
}
}
}

View File

@ -0,0 +1,103 @@
//
// SpreadsheetEditor.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
using UniversalEditor.UserInterface;
using MBS.Framework.UserInterface;
using UniversalEditor.ObjectModels.Spreadsheet;
using MBS.Framework.UserInterface.Drawing;
using MBS.Framework.Drawing;
using MBS.Framework.UserInterface.Layouts;
using UniversalEditor.Plugins.Office.UserInterface.Editors.Spreadsheet.Controls;
namespace UniversalEditor.Plugins.Office.UserInterface.Editors.Spreadsheet
{
public class SpreadsheetEditor : Editor
{
private SheetControl sheetctrl = null;
public SpreadsheetEditor()
{
Layout = new BoxLayout(Orientation.Vertical);
sheetctrl = new SheetControl();
Controls.Add(sheetctrl, new BoxLayout.Constraints(true, true));
}
public Sheet SelectedSheet
{
get
{
return sheetctrl.Sheet;
}
set
{
sheetctrl.Sheet = value;
}
}
public override void UpdateSelections()
{
}
protected override Selection CreateSelectionInternal(object content)
{
return null;
}
private static EditorReference _er = null;
public override EditorReference MakeReference()
{
if (_er == null)
{
_er = base.MakeReference();
_er.SupportedObjectModels.Add(typeof(SpreadsheetObjectModel));
}
return _er;
}
public int DefaultRowHeight { get; set; } = 16;
public int DefaultColumnWidth { get; set; } = 81;
protected override void OnCreated(EventArgs e)
{
base.OnCreated(e);
OnObjectModelChanged(e);
}
protected override void OnObjectModelChanged(EventArgs e)
{
base.OnObjectModelChanged(e);
SpreadsheetObjectModel spreadsheet = (ObjectModel as SpreadsheetObjectModel);
if (spreadsheet == null) return;
if (spreadsheet.Sheets.Count == 0)
{
for (int i = 0; i < 3; i++)
{
spreadsheet.Sheets.Add(new Sheet(String.Format("Sheet{0}", i.ToString())));
}
SelectedSheet = spreadsheet.Sheets[0];
}
}
}
}

View File

@ -34,11 +34,15 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Editors\Presentation\PresentationEditor.cs" />
<Compile Include="Editors\Presentation\Controls\PresentationSlideControl.cs" />
<Compile Include="Editors\Spreadsheet\SpreadsheetEditor.cs" />
<Compile Include="Editors\Spreadsheet\Controls\SheetControl.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Editors\" />
<Folder Include="Editors\Presentation\" />
<Folder Include="Editors\Presentation\Controls\" />
<Folder Include="Editors\Spreadsheet\" />
<Folder Include="Editors\Spreadsheet\Controls\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.UserInterface\UniversalEditor.UserInterface.csproj">

View File

@ -0,0 +1,62 @@
//
// Cell.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public class Cell
{
private Cell(int row, int column)
{
RowIndex = row;
ColumnIndex = column;
}
public int RowIndex { get; private set; } = 0;
public int ColumnIndex { get; private set; } = 0;
public Sheet Parent { get; private set; } = null;
public class CellCollection
{
private Sheet _parent = null;
public CellCollection(Sheet parent)
{
_parent = parent;
}
private System.Collections.Generic.Dictionary<CellIndex, Cell> _this = new System.Collections.Generic.Dictionary<CellIndex, Cell>();
public Cell this[int row, int column]
{
get
{
if (!_this.ContainsKey(new CellIndex(row, column)))
{
Cell c = new Cell(row, column);
c.Parent = _parent;
_this[new CellIndex(row, column)] = c;
}
return _this[new CellIndex(row, column)];
}
}
}
public object Value { get; set; } = null;
}
}

View File

@ -0,0 +1,35 @@
//
// CellIndex.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public struct CellIndex
{
public int Row;
public int Column;
public CellIndex(int row, int column)
{
Row = row;
Column = column;
}
}
}

View File

@ -0,0 +1,87 @@
//
// CellSizeInfo.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public class Column
{
public class ColumnCollection
{
private System.Collections.Generic.Dictionary<int, Column> _this = new System.Collections.Generic.Dictionary<int, Column>();
public Sheet Parent { get; private set; } = null;
public ColumnCollection(Sheet parent)
{
Parent = parent;
}
public Column this[int index]
{
get
{
if (!_this.ContainsKey(index))
{
_this[index] = new Column(index);
_this[index].Parent = Parent;
}
return _this[index];
}
}
public bool Contains(int index)
{
return _this.ContainsKey(index);
}
}
private Column(int index)
{
Index = index;
}
public int Index { get; private set; } = 0;
public Sheet Parent { get; private set; } = null;
public int? Width { get; set; } = null;
private string _Title = null;
public string Title
{
get
{
if (_Title == null)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
int chri = (int)'A' + Index;
sb.Append((char)((int)'A' + Index));
return sb.ToString();
}
return _Title;
}
set { _Title = value; }
}
}
}

View File

@ -0,0 +1,81 @@
//
// Row.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public class Row
{
public class RowCollection
{
private System.Collections.Generic.Dictionary<int, Row> _this = new System.Collections.Generic.Dictionary<int, Row>();
public Sheet Parent { get; private set; } = null;
public RowCollection(Sheet parent)
{
Parent = parent;
}
public Row this[int index]
{
get
{
if (!_this.ContainsKey(index))
{
_this[index] = new Row(index);
_this[index].Parent = Parent;
}
return _this[index];
}
}
public bool Contains(int index)
{
return _this.ContainsKey(index);
}
}
private Row(int index)
{
Index = index;
}
public int Index { get; private set; } = 0;
public Sheet Parent { get; private set; } = null;
public int? Height { get; set; } = null;
private string _Title = null;
public string Title
{
get
{
if (_Title == null)
return (Index + 1).ToString();
return _Title;
}
set
{
_Title = value;
}
}
}
}

View File

@ -0,0 +1,75 @@
//
// Sheet.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public class Sheet
{
public class SheetCollection
: System.Collections.ObjectModel.Collection<Sheet>
{
private SpreadsheetObjectModel _parent = null;
public SheetCollection(SpreadsheetObjectModel parent)
{
_parent = parent;
}
protected override void ClearItems()
{
for (int i = 0; i < Count; i++)
{
this[i].Parent = null;
}
base.ClearItems();
}
protected override void InsertItem(int index, Sheet item)
{
base.InsertItem(index, item);
item.Parent = _parent;
}
protected override void RemoveItem(int index)
{
this[index].Parent = null;
base.RemoveItem(index);
}
}
public Row.RowCollection Rows { get; private set; } = null;
public Column.ColumnCollection Columns { get; private set; } = null;
public Cell.CellCollection Cells { get; private set; } = null;
public SpreadsheetObjectModel Parent { get; private set; } = null;
public string Title { get; set; } = null;
public Sheet()
{
Rows = new Row.RowCollection(this);
Columns = new Column.ColumnCollection(this);
Cells = new Cell.CellCollection(this);
}
public Sheet(string title) : this()
{
Title = title;
}
}
}

View File

@ -0,0 +1,54 @@
//
// SpreadsheetObjectModel.cs
//
// Author:
// Michael Becker <alcexhim@gmail.com>
//
// Copyright (c) 2020 Mike Becker's Software
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System;
namespace UniversalEditor.ObjectModels.Spreadsheet
{
public class SpreadsheetObjectModel : ObjectModel
{
private static ObjectModelReference _omr = null;
public override void Clear()
{
}
public override void CopyTo(ObjectModel where)
{
}
public SpreadsheetObjectModel()
{
Sheets = new Sheet.SheetCollection(this);
}
public Sheet.SheetCollection Sheets { get; private set; } = null;
protected override ObjectModelReference MakeReferenceInternal()
{
if (_omr == null)
{
_omr = base.MakeReferenceInternal();
_omr.Title = "Spreadsheet";
}
return _omr;
}
}
}

View File

@ -40,6 +40,12 @@
<Compile Include="DataFormats\Presentation\HyperCard\HyperCardDataFormat.cs" />
<Compile Include="DataFormats\Presentation\HyperCard\HyperCardScript.cs" />
<Compile Include="DataFormats\Presentation\HyperCard\HyperCardUserLevel.cs" />
<Compile Include="ObjectModels\Spreadsheet\SpreadsheetObjectModel.cs" />
<Compile Include="ObjectModels\Spreadsheet\Cell.cs" />
<Compile Include="ObjectModels\Spreadsheet\CellIndex.cs" />
<Compile Include="ObjectModels\Spreadsheet\Column.cs" />
<Compile Include="ObjectModels\Spreadsheet\Row.cs" />
<Compile Include="ObjectModels\Spreadsheet\Sheet.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="ObjectModels\" />
@ -49,6 +55,7 @@
<Folder Include="DataFormats\Presentation\HyperCard\" />
<Folder Include="DataFormats\Presentation\HyperCard\Internal\" />
<Folder Include="DataFormats\Presentation\HyperCard\Internal\STAK\" />
<Folder Include="ObjectModels\Spreadsheet\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">