diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/Controls/SheetControl.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/Controls/SheetControl.cs new file mode 100644 index 00000000..abb18fe9 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/Controls/SheetControl.cs @@ -0,0 +1,85 @@ +// +// SheetControl.cs +// +// Author: +// Michael Becker +// +// 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 . +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); + } + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/SpreadsheetEditor.cs b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/SpreadsheetEditor.cs new file mode 100644 index 00000000..35dd1b09 --- /dev/null +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/Editors/Spreadsheet/SpreadsheetEditor.cs @@ -0,0 +1,103 @@ +// +// SpreadsheetEditor.cs +// +// Author: +// Michael Becker +// +// 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 . +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]; + } + } + } +} diff --git a/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/UniversalEditor.Plugins.Office.UserInterface.csproj b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/UniversalEditor.Plugins.Office.UserInterface.csproj index e8b458e9..a6da7d5d 100644 --- a/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/UniversalEditor.Plugins.Office.UserInterface.csproj +++ b/Plugins.UserInterface/UniversalEditor.Plugins.Office.UserInterface/UniversalEditor.Plugins.Office.UserInterface.csproj @@ -34,11 +34,15 @@ + + + + diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Cell.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Cell.cs new file mode 100644 index 00000000..8ee3c052 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Cell.cs @@ -0,0 +1,62 @@ +// +// Cell.cs +// +// Author: +// Michael Becker +// +// 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 . +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 _this = new System.Collections.Generic.Dictionary(); + 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; + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/CellIndex.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/CellIndex.cs new file mode 100644 index 00000000..d6339904 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/CellIndex.cs @@ -0,0 +1,35 @@ +// +// CellIndex.cs +// +// Author: +// Michael Becker +// +// 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 . +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; + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Column.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Column.cs new file mode 100644 index 00000000..de4ac60b --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Column.cs @@ -0,0 +1,87 @@ +// +// CellSizeInfo.cs +// +// Author: +// Michael Becker +// +// 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 . + +using System; + +namespace UniversalEditor.ObjectModels.Spreadsheet +{ + public class Column + { + public class ColumnCollection + { + private System.Collections.Generic.Dictionary _this = new System.Collections.Generic.Dictionary(); + + 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; } + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Row.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Row.cs new file mode 100644 index 00000000..bfc9ac55 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Row.cs @@ -0,0 +1,81 @@ +// +// Row.cs +// +// Author: +// Michael Becker +// +// 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 . +using System; +namespace UniversalEditor.ObjectModels.Spreadsheet +{ + public class Row + { + public class RowCollection + { + private System.Collections.Generic.Dictionary _this = new System.Collections.Generic.Dictionary(); + + 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; + } + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Sheet.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Sheet.cs new file mode 100644 index 00000000..8211a04d --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/Sheet.cs @@ -0,0 +1,75 @@ +// +// Sheet.cs +// +// Author: +// Michael Becker +// +// 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 . +using System; +namespace UniversalEditor.ObjectModels.Spreadsheet +{ + public class Sheet + { + + public class SheetCollection + : System.Collections.ObjectModel.Collection + { + 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; + } + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/SpreadsheetObjectModel.cs b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/SpreadsheetObjectModel.cs new file mode 100644 index 00000000..2ad66624 --- /dev/null +++ b/Plugins/UniversalEditor.Plugins.Office/ObjectModels/Spreadsheet/SpreadsheetObjectModel.cs @@ -0,0 +1,54 @@ +// +// SpreadsheetObjectModel.cs +// +// Author: +// Michael Becker +// +// 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 . +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; + } + + } +} diff --git a/Plugins/UniversalEditor.Plugins.Office/UniversalEditor.Plugins.Office.csproj b/Plugins/UniversalEditor.Plugins.Office/UniversalEditor.Plugins.Office.csproj index 0bb6958d..b8203e5b 100644 --- a/Plugins/UniversalEditor.Plugins.Office/UniversalEditor.Plugins.Office.csproj +++ b/Plugins/UniversalEditor.Plugins.Office/UniversalEditor.Plugins.Office.csproj @@ -40,6 +40,12 @@ + + + + + + @@ -49,6 +55,7 @@ +