示例#1
0
        /// <summary>
        /// retrieves, to which column should be scrolled in order to make
        /// the column nForLastCol the last visible column
        /// </summary>
        /// <param name="nForLastCol">the column number which should be the last visible column</param>
        /// <param name="layout">Worksheet layout referring to.</param>
        /// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
        /// <param name="TableAreaWidth">Width of the table area shown.</param>
        /// <returns>the number of the first visible column</returns>
        public static int GetFirstVisibleColumnForLastVisibleColumn(int nForLastCol, WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
        {
            var data      = layout.DataTable.DataColumns;
            var colStyles = layout.DataColumnStyles;

            int    i        = nForLastCol;
            int    retv     = nForLastCol;
            double horzSize = TableAreaWidth - layout.RowHeaderStyle.Width;

            while (i >= 0)
            {
                horzSize -= colStyles[data[i]].WidthD;
                if (horzSize > 0 && i > 0)
                {
                    i--;
                }
                else
                {
                    break;
                }
            }

            if (horzSize < 0)
            {
                i++; // increase one colum if size was bigger than available size
            }
            return(i <= nForLastCol ? i : nForLastCol);
        }
示例#2
0
        /// <summary>
        /// Retrieves the column number clicked onto
        /// </summary>
        /// <param name="positionX">Clicked position.</param>
        /// <param name="layout">Worksheet layout referring to.</param>
        /// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
        /// <param name="left">Returns the left position of the clicked cell.</param>
        /// <param name="width">Returns the width of the clicked cell.</param>
        /// <returns>Either -1 when clicked on the row header area, column number when clicked in the column range, or int.MinValue when clicked outside of all.</returns>
        public static int GetColumnNumber(double positionX, WorksheetLayout layout, int HorzScrollPos, out double left, out double width)
        {
            int firstVisibleColumn = HorzScrollPos;
            int actualColumnRight  = layout.RowHeaderStyle.Width;
            int columnCount        = layout.DataTable.DataColumns.ColumnCount;

            left = 0;

            if (positionX < actualColumnRight)
            {
                width = actualColumnRight;
                return(-1);
            }

            for (int i = firstVisibleColumn; i < columnCount; i++)
            {
                left = actualColumnRight;
                Altaxo.Worksheet.ColumnStyle cs = layout.GetDataColumnStyle(i);
                actualColumnRight += cs.Width;
                if (actualColumnRight > positionX)
                {
                    width = cs.Width;
                    return(i);
                }
            } // end for

            width = 0;
            return(int.MinValue);
        }
示例#3
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                WorksheetLayout s = null != o ? (WorksheetLayout)o : new WorksheetLayout();

                Deserialize(s, info, parent);
                return(s);
            }
示例#4
0
        /// <summary>
        /// Returns the row number of the clicked cell.
        /// </summary>
        /// <param name="positionY">The vertical position value.</param>
        /// <param name="layout">The worksheet area.</param>
        /// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
        /// <param name="top">Returns the top value of the clicked cell.</param>
        /// <param name="height">Returns the height value of the clicked cell.</param>
        /// <param name="bPropertyCol">True if clicked on either the property column header or a property column, else false.</param>
        /// <returns>The row number of the clicked cell, or -1 if clicked on the column header.</returns>
        /// <remarks>If clicked onto a property cell, the function returns the property column number.</remarks>
        public static int GetRowNumber(double positionY, WorksheetLayout layout, int VertScrollPos, out double top, out double height, out bool bPropertyCol)
        {
            top = 0;
            if (positionY < layout.ColumnHeaderStyle.Height)
            {
                height       = layout.ColumnHeaderStyle.Height;
                bPropertyCol = false;
                return(-1);
            }

            var verticalPositionOfFirstVisibleDataRow = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);
            var visiblePropertyColumns = GetVisiblePropertyColumns(0, positionY * 1.125, layout, VertScrollPos); // trick here: because coordinates lower than positionY are not relevant, we use a clipping region slightly larger than positionY

            if (positionY < verticalPositionOfFirstVisibleDataRow && visiblePropertyColumns > 0)
            {
                // calculate the raw row number
                int rawrow = (int)Math.Floor((positionY - layout.ColumnHeaderStyle.Height) / layout.PropertyColumnHeaderStyle.Height);

                top    = layout.ColumnHeaderStyle.Height + rawrow * layout.PropertyColumnHeaderStyle.Height;
                height = layout.PropertyColumnHeaderStyle.Height;

                bPropertyCol = true;
                return(rawrow + GetFirstVisiblePropertyColumn(layout, VertScrollPos));
            }
            else
            {
                int rawrow = (int)Math.Floor((positionY - verticalPositionOfFirstVisibleDataRow) / layout.RowHeaderStyle.Height);

                top          = verticalPositionOfFirstVisibleDataRow + rawrow * layout.RowHeaderStyle.Height;
                height       = layout.RowHeaderStyle.Height;
                bPropertyCol = false;
                return(rawrow + GetFirstVisibleTableRow(layout, VertScrollPos));
            }
        }
示例#5
0
            public virtual void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                WorksheetLayout s = (WorksheetLayout)obj;

                info.AddValue("Guid", System.Xml.XmlConvert.ToString(s.m_Guid));
                info.AddValue("Table", Main.DocumentPath.GetAbsolutePath(s.m_DataTable));
                info.AddValue("RowHeaderStyle", s.m_RowHeaderStyle);
                info.AddValue("ColumnHeaderStyle", s.m_ColumnHeaderStyle);
                info.AddValue("PropertyColumnHeaderStyle", s.m_PropertyColumnHeaderStyle);

                info.CreateArray("DefaultColumnStyles", s.m_DefaultColumnStyles.Values.Count);
                foreach (object style in s.m_DefaultColumnStyles.Values)
                {
                    info.AddValue("DefaultColumnStyle", style);
                }
                info.CommitArray();

                info.CreateArray("ColumnStyles", s.m_ColumnStyles.Count);
                foreach (System.Collections.DictionaryEntry dictentry in s.m_ColumnStyles)
                {
                    info.CreateElement("e");

                    Main.IDocumentNode col = (Main.IDocumentNode)dictentry.Key;
                    info.AddValue("Column", Main.DocumentPath.GetAbsolutePath(col));
                    info.AddValue("Style", dictentry.Value);

                    info.CommitElement(); // "e"
                }
                info.CommitArray();
            }
示例#6
0
        public static RectangleD2D GetCoordinatesOfPropertyCell(int nCol, int nRow, WorksheetLayout layout, int HorzScrollPos, int VertScrollPos)
        {
            double y, h;

            GetXCoordinatesOfColumn(nRow, layout, HorzScrollPos, out var x, out var w);

            y = GetTopCoordinateOfPropertyColumn(nCol, layout, VertScrollPos);
            h = layout.PropertyColumnHeaderStyle.Height;
            return(new RectangleD2D(x, y, w, h));
        }
示例#7
0
        /// <summary>
        /// Gets the first table row that is visible under the coordinate top.
        /// </summary>
        /// <param name="top">The upper coordinate of the clipping rectangle.</param>
        /// <param name="layout">Worksheet layout referring to.</param>
        /// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
        /// <returns>The first table row that is visible below the top coordinate.</returns>
        public static int GetFirstVisibleTableRow(double top, WorksheetLayout layout, int VertScrollPos)
        {
            int posOfDataRow0 = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);

            //int firstTotRow = (int)Math.Max(RemainingEnabledPropertyColumns,Math.Floor((top-m_TableLayout.ColumnHeaderStyle.Height)/(double)m_TableLayout.RowHeaderStyle.Height));
            //return FirstVisibleTableRow + Math.Max(0,firstTotRow-RemainingEnabledPropertyColumns);
            int firstVis = (int)Math.Floor((top - posOfDataRow0) / layout.RowHeaderStyle.Height);

            return((firstVis < 0 ? 0 : firstVis) + Math.Max(0, VertScrollPos));
        }
示例#8
0
        public static int GetFirstVisiblePropertyColumn(double top, WorksheetLayout layout, int VertScrollPos)
        {
            if (VertScrollPos >= 0 || !layout.ShowPropertyColumns)
            {
                return(-1);
            }

            int firstTotRow = (int)Math.Max(0, Math.Floor((top - layout.ColumnHeaderStyle.Height) / layout.PropertyColumnHeaderStyle.Height));

            return(firstTotRow + GetFirstVisiblePropertyColumn(layout, VertScrollPos));
        }
示例#9
0
            public override void Serialize(object obj, Altaxo.Serialization.Xml.IXmlSerializationInfo info)
            {
                base.Serialize(obj, info);

                WorksheetLayout s = (WorksheetLayout)obj;

                info.CreateArray("DefaultPropertyColumnStyles", s.m_DefaultPropertyColumnStyles.Values.Count);
                foreach (object style in s.m_DefaultPropertyColumnStyles.Values)
                {
                    info.AddValue("DefaultPropertyColumnStyle", style);
                }
                info.CommitArray();
            }
示例#10
0
            protected override void Deserialize(WorksheetLayout s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                base.Deserialize(s, info, parent);

                int count = info.OpenArray(); // DefaultPropertyColumnStyles

                for (int i = 0; i < count; i++)
                {
                    var defstyle = (ColumnStyle)info.GetValue("DefaultPropertyColumnStyle", s._propertyColumnStyles);
                    s._propertyColumnStyles.SetDefaultColumnStyle(defstyle.GetType(), defstyle);
                }
                info.CloseArray(count);
            }
示例#11
0
        public string GetNameOfChildObject(object o)
        {
            WorksheetLayout layout = o as WorksheetLayout;

            if (layout == null)
            {
                return(null);
            }
            if (null == this[layout.Guid])
            {
                return(null); // is not contained in this collection
            }
            return(layout.Guid.ToString());
        }
示例#12
0
        public void Add(WorksheetLayout layout)
        {
            layout.ParentObject = this;

            // Test if this Guid is already present
            object o = this[layout.Guid];

            if (o != null && !object.ReferenceEquals(o, layout))
            {
                layout.NewGuid();
            }

            m_TableLayouts[layout.Guid.ToString()] = layout;
        }
示例#13
0
 public static int GetFullyVisiblePropertyColumns(double top, double bottom, WorksheetLayout layout, int VertScrollPos)
 {
     if (layout.ShowPropertyColumns)
     {
         int firstTotRow = (int)Math.Max(0, Math.Floor((top - layout.ColumnHeaderStyle.Height) / layout.PropertyColumnHeaderStyle.Height));
         int lastTotRow  = (int)Math.Floor((bottom - layout.ColumnHeaderStyle.Height) / layout.PropertyColumnHeaderStyle.Height) - 1;
         int maxPossRows = Math.Max(0, GetRemainingEnabledPropertyColumns(layout, VertScrollPos) - firstTotRow);
         return(Math.Min(maxPossRows, Math.Max(0, 1 + lastTotRow - firstTotRow)));
     }
     else
     {
         return(0);
     }
 }
示例#14
0
        public static int GetFullyVisibleTableRows(double top, double bottom, WorksheetLayout layout, int VertScrollPos)
        {
            int posOfDataRow0 = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);

            if (top < posOfDataRow0)
            {
                top = posOfDataRow0;
            }

            int firstRow = (int)Math.Floor((top - posOfDataRow0) / layout.RowHeaderStyle.Height);
            int lastRow  = (int)Math.Floor((bottom - posOfDataRow0) / layout.RowHeaderStyle.Height) - 1;

            return(Math.Max(0, 1 + lastRow - firstRow));
        }
示例#15
0
 public static int GetFirstVisiblePropertyColumn(WorksheetLayout layout, int VertScrollPos)
 {
     if (layout.ShowPropertyColumns && VertScrollPos < 0)
     {
         // make sure that VertScrollPos does not exceed TotalEnabledPropertyColumns
         if (VertScrollPos < -GetTotalEnabledPropertyColumns(layout))
         {
             VertScrollPos = -GetTotalEnabledPropertyColumns(layout);
         }
         return(GetTotalEnabledPropertyColumns(layout) + VertScrollPos);
     }
     else
     {
         return(-1);
     }
 }
示例#16
0
        /// <summary>
        /// Gets the horizontal position and the width of a data column.
        /// </summary>
        /// <param name="nCol">Number of data column.</param>
        /// <param name="layout">Worksheet layout.</param>
        /// <param name="HorzScrollPos">Horizontal scroll position (number of the first column to display).</param>
        /// <param name="left">Returns the x coordinate of the left boundary of the specified column.</param>
        /// <param name="width">Returns the width of the specified column.</param>
        public static void GetXCoordinatesOfColumn(int nCol, WorksheetLayout layout, int HorzScrollPos, out double left, out double width)
        {
            int colOffs = nCol - HorzScrollPos;

            var    data      = layout.DataTable.DataColumns;
            var    colStyles = layout.DataColumnStyles;
            double x         = layout.RowHeaderStyle.Width;

            for (int i = HorzScrollPos; i < nCol; i++)
            {
                x += colStyles[data[i]].Width;
            }

            left  = x;
            width = colStyles[data[nCol]].Width;
        }
示例#17
0
		protected virtual void InternalInitializeWorksheetLayout(WorksheetLayout value)
		{
			if (null != _worksheetLayout)
				throw new ApplicationException("This controller is already controlling a layout");
			if (null != _table)
				throw new ApplicationException("This controller is already controlling a table");
			if (null == value)
				throw new ArgumentNullException("value");
			if (null == value.DataTable)
				throw new ApplicationException("The DataTable of the WorksheetLayout is null");

			_worksheetLayout = value;
			_table = _worksheetLayout.DataTable;
			var table = _table; // use local variable for anonymous method below
			_table.Changed += (_weakTableNameChangedHandler = new WeakEventHandler(this.EhTableNameChanged, x => table.Changed -= x));
			OnTitleNameChanged();
		}
示例#18
0
            public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                WorksheetLayoutCollection s = null != o ? (WorksheetLayoutCollection)o : new WorksheetLayoutCollection();

                int count;

                count = info.OpenArray(); // TableLayouts

                for (int i = 0; i < count; i++)
                {
                    WorksheetLayout style = (WorksheetLayout)info.GetValue("WorksheetLayout", s);
                    s.m_TableLayouts.Add(style.Guid, style);
                }
                info.CloseArray(count);

                return(s);
            }
示例#19
0
        /// <summary>
        /// Shows the SaveAs dialog and then saves the worksheet (data table and the corresponding layout, including scripts) into a xml file.
        /// </summary>
        /// <param name="worksheet">The worksheet to save.</param>
        /// <param name="saveAsTemplate">If true, the data are not saved, but only the layout of the worksheet (columns, property columns, scripts). If false, everything including the data is saved.</param>
        public static void ShowSaveAsDialog(this WorksheetLayout worksheet, bool saveAsTemplate)
        {
            var options = new Altaxo.Gui.SaveFileOptions();

            options.AddFilter("*.axowks", "Altaxo worksheet files (*.axowks)");
            options.AddFilter("*.*", "All files (*.*)");
            options.FilterIndex      = 0;
            options.RestoreDirectory = true;

            if (Current.Gui.ShowSaveFileDialog(options))
            {
                using (Stream myStream = new System.IO.FileStream(options.FileName, FileMode.Create, FileAccess.Write, FileShare.Read))
                {
                    Save(worksheet, myStream, saveAsTemplate);
                    myStream.Close();
                }
            }
        }
示例#20
0
            protected virtual void Deserialize(WorksheetLayout s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
            {
                XmlSerializationSurrogate0 surr = new XmlSerializationSurrogate0();

                surr.m_ColStyles              = new System.Collections.Hashtable();
                surr.m_TableLayout            = s;
                info.DeserializationFinished += new Altaxo.Serialization.Xml.XmlDeserializationCallbackEventHandler(surr.EhDeserializationFinished);


                s.m_Guid                      = System.Xml.XmlConvert.ToGuid(info.GetString("Guid"));
                surr.m_PathToTable            = (Main.DocumentPath)info.GetValue("Table", s);
                s.m_RowHeaderStyle            = (RowHeaderStyle)info.GetValue("RowHeaderStyle", s);
                s.m_ColumnHeaderStyle         = (ColumnHeaderStyle)info.GetValue("ColumnHeaderStyle", s);
                s.m_PropertyColumnHeaderStyle = (ColumnHeaderStyle)info.GetValue("PropertyColumnHeaderStyle", s);


                int count;

                count = info.OpenArray(); // DefaultColumnStyles

                for (int i = 0; i < count; i++)
                {
                    object defstyle = info.GetValue("DefaultColumnStyle", s);
                    s.DefaultColumnStyles.Add(defstyle.GetType(), defstyle);
                }
                info.CloseArray(count);


                // deserialize the columnstyles
                // this must be deserialized in a new instance of this surrogate, since we can not resolve it immediately
                count = info.OpenArray();
                if (count > 0)
                {
                    for (int i = 0; i < count; i++)
                    {
                        info.OpenElement(); // "e"
                        Main.DocumentPath key = (Main.DocumentPath)info.GetValue("Column", s);
                        object            val = info.GetValue("Style", s);
                        surr.m_ColStyles.Add(key, val);
                        info.CloseElement();
                    }
                }
                info.CloseArray(count);
            }
示例#21
0
        /// <summary>
        /// Saves the worksheet (data table and the corresponding layout, including scripts) into a xml file.
        /// </summary>
        /// <param name="worksheet">The worksheet to save.</param>
        /// <param name="myStream">The stream where the xml data are to save into.</param>
        /// <param name="saveAsTemplate">If true, the data are not saved, but only the layout of the worksheet (columns, property columns, scripts). If false, everything including the data is saved.</param>
        public static void Save(this WorksheetLayout worksheet, System.IO.Stream myStream, bool saveAsTemplate)
        {
            var info = new Altaxo.Serialization.Xml.XmlStreamSerializationInfo();

            if (saveAsTemplate)
            {
                info.SetProperty("Altaxo.Data.DataColumn.SaveAsTemplate", "true");
            }
            info.BeginWriting(myStream);

            // TODO there is an issue with TableLayout that prevents a nice deserialization
            // this is because TableLayout stores the name of its table during serialization
            // onto deserialization this works well if the entire document is restored, but
            // doesn't work if only a table and its layout is to be restored. In this case, the layout
            // references the already present table with the same name in the document instead of the table
            // deserialized. Also, the GUID isn't unique if the template is deserialized more than one time.

            var tableAndLayout =
                new Altaxo.Worksheet.TablePlusLayout(worksheet.DataTable, worksheet);

            info.AddValue("TablePlusLayout", tableAndLayout);
            info.EndWriting();
        }
示例#22
0
        public static int GetFullyVisibleColumns(WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
        {
            var data      = layout.DataTable.DataColumns;
            var nCols     = data.ColumnCount;
            var colStyles = layout.DataColumnStyles;

            int    numCols = 0;
            double x       = layout.RowHeaderStyle.Width;

            for (int nCol = HorzScrollPos; nCol < nCols; nCol++)
            {
                x += colStyles[data[nCol]].Width;
                if (x <= TableAreaWidth)
                {
                    numCols++;
                }
                else
                {
                    break;
                }
            }
            return(numCols);
        }
示例#23
0
		/// <summary>
		/// retrieves, to which column should be scrolled in order to make
		/// the column nForLastCol the last visible column
		/// </summary>
		/// <param name="nForLastCol">the column number which should be the last visible column</param>
		/// <param name="layout">Worksheet layout referring to.</param>
		/// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
		/// <param name="TableAreaWidth">Width of the table area shown.</param>
		/// <returns>the number of the first visible column</returns>
		public static int GetFirstVisibleColumnForLastVisibleColumn(int nForLastCol, WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
		{
			var data = layout.DataTable.DataColumns;
			var colStyles = layout.DataColumnStyles;

			int i = nForLastCol;
			int retv = nForLastCol;
			double horzSize = TableAreaWidth - layout.RowHeaderStyle.Width;
			while (i >= 0)
			{
				horzSize -= colStyles[data[i]].WidthD;
				if (horzSize > 0 && i > 0)
					i--;
				else
					break;
			}

			if (horzSize < 0)
				i++; // increase one colum if size was bigger than available size

			return i <= nForLastCol ? i : nForLastCol;
		}
示例#24
0
		public static int GetTopCoordinateOfPropertyColumn(int nCol, WorksheetLayout layout, int VertScrollPos)
		{
			return layout.ColumnHeaderStyle.Height + (nCol - GetFirstVisiblePropertyColumn(layout, VertScrollPos)) * layout.PropertyColumnHeaderStyle.Height;
		}
示例#25
0
 /// <summary>
 /// Gets the first table row that is visible.
 /// </summary>
 /// <returns>The first table row that is visible.</returns>
 public static int GetFirstVisibleTableRow(WorksheetLayout layout, int VertScrollPos)
 {
     return(Math.Max(0, VertScrollPos));
 }
示例#26
0
        /// <summary>
        /// Creates the ClickedCellInfo from the data grid and the mouse coordinates of the click.
        /// </summary>
        /// <param name="positionX">The horizontal position value.</param>
        /// <param name="positionY">The vertical position value.</param>
        /// <param name="layout">The worksheet area.</param>
        /// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
        /// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
        public static AreaInfo GetAreaType(double positionX, double positionY, WorksheetLayout layout, int HorzScrollPos, int VertScrollPos)
        {
            //var _clickedCellRectangle = new Rect(0,0,0,0);
            var      hittedColumn = GetColumnNumber(positionX, layout, HorzScrollPos, out var left, out var width);
            var      hittedRow    = GetRowNumber(positionY, layout, VertScrollPos, out var top, out var height, out var bIsPropertyColumn);
            AreaType hittedAreaType;

            if (bIsPropertyColumn)
            {
                if (hittedColumn == -1)
                {
                    hittedAreaType = AreaType.PropertyColumnHeader;
                }
                else if (hittedColumn >= 0)
                {
                    hittedAreaType = AreaType.PropertyCell;
                }
                else
                {
                    hittedAreaType = AreaType.OutsideAll;
                }

                // Swap columns and rows since it is a property column
                int h = hittedColumn;
                hittedColumn = hittedRow;
                hittedRow    = h;
            }
            else // it is not a property related cell
            {
                if (hittedRow == -1 && hittedColumn == -1)
                {
                    hittedAreaType = AreaType.TableHeader;
                }
                else if (hittedRow == -1 && hittedColumn >= 0)
                {
                    hittedAreaType = AreaType.DataColumnHeader;
                }
                else if (hittedRow >= 0 && hittedColumn == -1)
                {
                    hittedAreaType = AreaType.DataRowHeader;
                }
                else if (hittedRow >= 0 && hittedColumn >= 0)
                {
                    hittedAreaType = AreaType.DataCell;
                }
                else
                {
                    hittedAreaType = AreaType.OutsideAll;
                }
            }

            var result = new AreaInfo()
            {
                ColumnNumber  = hittedColumn,
                RowNumber     = hittedRow,
                AreaRectangle = new RectangleD2D(left, top, width, height),
                AreaType      = hittedAreaType
            };

            return(result);
        }
示例#27
0
		public static int GetLastFullyVisibleTableRow(WorksheetLayout layout, int VertScrollPos, double TableAreaHeight)
		{
			return GetFirstVisibleTableRow(layout, VertScrollPos) + GetFullyVisibleTableRows(0, TableAreaHeight, layout, VertScrollPos) - 1;
		}
示例#28
0
        /// <summary>
        /// Get a list of horizontal positions, where the cursor should switch to a horizontal resizing cursor.
        /// </summary>
        /// <param name="destinationList">List to fill with the positions (old items will be deleted).</param>
        /// <param name="layout">Worksheet layout.</param>
        /// <param name="HorzScrollPos">Horizontal scroll position.</param>
        /// <param name="TableAreaWidth">Width of the table area.</param>
        /// <returns>HorzScrollPos that was given in the argument list.</returns>
        public static int GetColumnWidthResizingPositions(List <double> destinationList, WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
        {
            destinationList.Clear();
            var    data      = layout.DataTable.DataColumns;
            var    colStyles = layout.DataColumnStyles;
            double x         = layout.RowHeaderStyle.WidthD;

            for (int i = HorzScrollPos; i < data.ColumnCount && x < TableAreaWidth; i++)
            {
                x += colStyles[data[i]].Width;
                destinationList.Add(x);
            }
            return(HorzScrollPos);
        }
示例#29
0
		public static int GetFullyVisiblePropertyColumns(double top, double bottom, WorksheetLayout layout, int VertScrollPos)
		{
			if (layout.ShowPropertyColumns)
			{
				int firstTotRow = (int)Math.Max(0, Math.Floor((top - layout.ColumnHeaderStyle.Height) / (double)layout.PropertyColumnHeaderStyle.Height));
				int lastTotRow = (int)Math.Floor((bottom - layout.ColumnHeaderStyle.Height) / (double)layout.PropertyColumnHeaderStyle.Height) - 1;
				int maxPossRows = Math.Max(0, GetRemainingEnabledPropertyColumns(layout, VertScrollPos) - firstTotRow);
				return Math.Min(maxPossRows, Math.Max(0, 1 + lastTotRow - firstTotRow));
			}
			else
				return 0;
		}
 /// <summary>
 /// Creates a WorksheetController which shows the table data into the
 /// View <paramref name="view"/>.
 /// </summary>
 /// <param name="layout">The worksheet layout.</param>
 /// <param name="bDeserializationConstructor">If true, no layout has to be provided, since this is used as deserialization constructor.</param>
 protected SDWorksheetViewContent(Altaxo.Worksheet.WorksheetLayout layout, bool bDeserializationConstructor)
     :
     this(new WorksheetController(layout))
 {
 }
示例#31
0
        protected virtual void Deserialize(WorksheetLayout s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
        {
        

        XmlSerializationSurrogate0 surr = new XmlSerializationSurrogate0();
        surr.m_ColStyles = new System.Collections.Hashtable();
        surr.m_TableLayout = s;
        info.DeserializationFinished += new Altaxo.Serialization.Xml.XmlDeserializationCallbackEventHandler(surr.EhDeserializationFinished);


        s.m_Guid = System.Xml.XmlConvert.ToGuid(info.GetString("Guid"));
        surr.m_PathToTable = (Main.DocumentPath)info.GetValue("Table",s);
        s.m_RowHeaderStyle = (RowHeaderStyle)info.GetValue("RowHeaderStyle" , s);  
        s.m_ColumnHeaderStyle = (ColumnHeaderStyle)info.GetValue("ColumnHeaderStyle",s);  
        s.m_PropertyColumnHeaderStyle = (ColumnHeaderStyle)info.GetValue("PropertyColumnHeaderStyle",s);  


        int count;
        count = info.OpenArray(); // DefaultColumnStyles
        
        for(int i=0;i<count;i++)
        {
          object defstyle = info.GetValue("DefaultColumnStyle",s);
          s.DefaultColumnStyles.Add(defstyle.GetType(), defstyle);
        }
        info.CloseArray(count);
      

        // deserialize the columnstyles
        // this must be deserialized in a new instance of this surrogate, since we can not resolve it immediately
        count = info.OpenArray();
        if(count>0)
        {
          for(int i=0;i<count;i++)
          {
            info.OpenElement(); // "e"
            Main.DocumentPath key = (Main.DocumentPath)info.GetValue("Column",s);
            object val = info.GetValue("Style",s);
            surr.m_ColStyles.Add(key,val);
            info.CloseElement();
          }
        }
        info.CloseArray(count);
      }
示例#32
0
		public static int GetLastFullyVisibleColumn(WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
		{
			return HorzScrollPos + GetFullyVisibleColumns(layout, HorzScrollPos, TableAreaWidth) - 1;
		}
示例#33
0
		/// <summary>
		/// Retrieves the column number clicked onto
		/// </summary>
		/// <param name="positionX">Clicked position.</param>
		/// <param name="layout">Worksheet layout referring to.</param>
		/// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
		/// <param name="left">Returns the left position of the clicked cell.</param>
		/// <param name="width">Returns the width of the clicked cell.</param>
		/// <returns>Either -1 when clicked on the row header area, column number when clicked in the column range, or int.MinValue when clicked outside of all.</returns>
		public static int GetColumnNumber(double positionX, WorksheetLayout layout, int HorzScrollPos, out double left, out double width)
		{
			int firstVisibleColumn = HorzScrollPos;
			int actualColumnRight = layout.RowHeaderStyle.Width;
			int columnCount = layout.DataTable.DataColumns.ColumnCount;

			left = 0;

			if (positionX < actualColumnRight)
			{
				width = actualColumnRight;
				return -1;
			}

			for (int i = firstVisibleColumn; i < columnCount; i++)
			{
				left = actualColumnRight;
				Altaxo.Worksheet.ColumnStyle cs = layout.GetDataColumnStyle(i);
				actualColumnRight += cs.Width;
				if (actualColumnRight > positionX)
				{
					width = cs.Width;
					return i;
				}
			} // end for

			width = 0;
			return int.MinValue;
		}
示例#34
0
		public static RectangleD2D GetCoordinatesOfPropertyCell(int nCol, int nRow, WorksheetLayout layout, int HorzScrollPos, int VertScrollPos)
		{
			double x, y, w, h;
			GetXCoordinatesOfColumn(nRow, layout, HorzScrollPos, out x, out w);

			y = GetTopCoordinateOfPropertyColumn(nCol, layout, VertScrollPos);
			h = layout.PropertyColumnHeaderStyle.Height;
			return new RectangleD2D(x, y, w, h);
		}
示例#35
0
		/// <summary>
		/// Get a list of horizontal positions, where the cursor should switch to a horizontal resizing cursor.
		/// </summary>
		/// <param name="destinationList">List to fill with the positions (old items will be deleted).</param>
		/// <param name="layout">Worksheet layout.</param>
		/// <param name="HorzScrollPos">Horizontal scroll position.</param>
		/// <param name="TableAreaWidth">Width of the table area.</param>
		/// <returns>HorzScrollPos that was given in the argument list.</returns>
		public static int GetColumnWidthResizingPositions(List<double> destinationList, WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
		{
			destinationList.Clear();
			var data = layout.DataTable.DataColumns;
			var colStyles = layout.DataColumnStyles;
			double x = layout.RowHeaderStyle.WidthD;
			for (int i = HorzScrollPos; i < data.ColumnCount && x < TableAreaWidth; i++)
			{
				x += colStyles[data[i]].Width;
				destinationList.Add(x);
			}
			return HorzScrollPos;
		}
 /// <summary>
 /// Creates a WorksheetController which shows the table data into the
 /// View <paramref name="view"/>.
 /// </summary>
 /// <param name="layout">The worksheet layout.</param>
 /// <param name="bDeserializationConstructor">If true, no layout has to be provided, since this is used as deserialization constructor.</param>
 protected SDWorksheetController(Altaxo.Worksheet.WorksheetLayout layout, bool bDeserializationConstructor)
     :
     base(layout, bDeserializationConstructor)
 {
 }
示例#37
0
 public static int GetLastFullyVisibleColumn(WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
 {
     return(HorzScrollPos + GetFullyVisibleColumns(layout, HorzScrollPos, TableAreaWidth) - 1);
 }
示例#38
0
		public virtual void Dispose()
		{
			var view = ViewObject;
			this.ViewObject = null;
			if (view is IDisposable)
				((IDisposable)view).Dispose();

			if (null != _table)
			{
				_weakTableNameChangedHandler.Remove();
			}

			_table = null;
			_worksheetLayout = null; // removes also the event handler(s)
		}
示例#39
0
		public static int GetTopCoordinateOfTableRow(int nRow, WorksheetLayout layout, int VertScrollPos)
		{
			return GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos) + (nRow - (VertScrollPos < 0 ? 0 : VertScrollPos)) * layout.RowHeaderStyle.Height;
		}
示例#40
0
		public static int GetFullyVisibleColumns(WorksheetLayout layout, int HorzScrollPos, double TableAreaWidth)
		{
			var data = layout.DataTable.DataColumns;
			var nCols = data.ColumnCount;
			var colStyles = layout.DataColumnStyles;

			int numCols = 0;
			double x = layout.RowHeaderStyle.Width;
			for (int nCol = HorzScrollPos; nCol < nCols; nCol++)
			{
				x += colStyles[data[nCol]].Width;
				if (x <= TableAreaWidth)
					numCols++;
				else
					break;
			}
			return numCols;
		}
示例#41
0
		public static int GetFullyVisibleTableRows(double top, double bottom, WorksheetLayout layout, int VertScrollPos)
		{
			int posOfDataRow0 = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);

			if (top < posOfDataRow0)
				top = posOfDataRow0;

			int firstRow = (int)Math.Floor((top - posOfDataRow0) / (double)layout.RowHeaderStyle.Height);
			int lastRow = (int)Math.Floor((bottom - posOfDataRow0) / (double)layout.RowHeaderStyle.Height) - 1;
			return Math.Max(0, 1 + lastRow - firstRow);
		}
示例#42
0
		public static int GetLastFullyVisiblePropertyColumn(WorksheetLayout layout, int VertScrollPos, double TableAreaHeight)
		{
			return GetFirstVisiblePropertyColumn(layout, VertScrollPos) + GetFullyVisiblePropertyColumns(layout, VertScrollPos, TableAreaHeight) - 1;
		}
    public void Add(WorksheetLayout layout)
    {
      layout.ParentObject = this;

      // Test if this Guid is already present
      object o = this[layout.Guid];
      if(o!=null && !object.ReferenceEquals(o,layout))
        layout.NewGuid();

      m_TableLayouts[layout.Guid.ToString()] = layout;
    }
示例#44
0
		public static int GetFirstAndNumberOfVisibleColumn(double left, double right, WorksheetLayout layout, int HorzScrollPos, out int numVisibleColumns)
		{
			var data = layout.DataTable.DataColumns;
			var nCols = data.ColumnCount;
			var colStyles = layout.DataColumnStyles;

			int nFirstCol = -1;
			int nLastCol = nCols; // Attention: this is one more than the index of the last column.
			double x = layout.RowHeaderStyle.Width;
			for (int nCol = HorzScrollPos; nCol < nCols; nCol++)
			{
				x += colStyles[data[nCol]].Width;

				if ((nFirstCol < 0) && (x > left))
				{
					nFirstCol = nCol;
				}

				if (x >= right)
				{
					nLastCol = nCol + 1;
					break;
				}
			}

			numVisibleColumns = nFirstCol < 0 ? 0 : Math.Max(0, nLastCol - nFirstCol);
			return nFirstCol;
		}
示例#45
0
 /// <summary>
 /// This returns the vertical position of the first visible data row.;
 /// </summary>
 public static int GetVerticalPositionOfFirstVisibleDataRow(WorksheetLayout layout, int VertScrollPos)
 {
     return(layout.ColumnHeaderStyle.Height + (VertScrollPos >= 0 ? 0 : -VertScrollPos * layout.PropertyColumnHeaderStyle.Height));
 }
示例#46
0
		public static int GetTotalEnabledPropertyColumns(WorksheetLayout layout)
		{
			return layout.ShowPropertyColumns ? layout.DataTable.PropertyColumnCount : 0;
		}
示例#47
0
		/// <summary>
		/// Gets the number of fully visible property columns in the full table area, i.e. between the y coordinates 0 to TableAreaHeight.
		/// </summary>
		/// <param name="layout"></param>
		/// <param name="VertScrollPos"></param>
		/// <param name="TableAreaHeight"></param>
		/// <returns></returns>
		public static int GetFullyVisiblePropertyColumns(WorksheetLayout layout, int VertScrollPos, double TableAreaHeight)
		{
			return GetFullyVisiblePropertyColumns(0, TableAreaHeight, layout, VertScrollPos);
		}
示例#48
0
		/// <summary>Returns the remaining number of property columns that could be shown below the current scroll position.</summary>
		public static int GetRemainingEnabledPropertyColumns(WorksheetLayout layout, int VertScrollPos)
		{
			return layout.ShowPropertyColumns ? Math.Max(0, -VertScrollPos) : 0;
		}
示例#49
0
		public static int GetFirstVisiblePropertyColumn(WorksheetLayout layout, int VertScrollPos)
		{
			if (layout.ShowPropertyColumns && VertScrollPos < 0)
			{
				// make sure that VertScrollPos does not exceed TotalEnabledPropertyColumns
				if (VertScrollPos < -GetTotalEnabledPropertyColumns(layout))
					VertScrollPos = -GetTotalEnabledPropertyColumns(layout);
				return GetTotalEnabledPropertyColumns(layout) + VertScrollPos;
			}
			else
				return -1;
		}
示例#50
0
		/// <summary>
		/// Gets the horizontal position and the width of a data column.
		/// </summary>
		/// <param name="nCol">Number of data column.</param>
		/// <param name="layout">Worksheet layout.</param>
		/// <param name="HorzScrollPos">Horizontal scroll position (number of the first column to display).</param>
		/// <param name="left">Returns the x coordinate of the left boundary of the specified column.</param>
		/// <param name="width">Returns the width of the specified column.</param>
		public static void GetXCoordinatesOfColumn(int nCol, WorksheetLayout layout, int HorzScrollPos, out double left, out double width)
		{
			int colOffs = nCol - HorzScrollPos;

			var data = layout.DataTable.DataColumns;
			var colStyles = layout.DataColumnStyles;
			double x = layout.RowHeaderStyle.Width;
			for (int i = HorzScrollPos; i < nCol; i++)
				x += colStyles[data[i]].Width;

			left = x;
			width = colStyles[data[nCol]].Width;
		}
示例#51
0
		/// <summary>
		/// Returns the row number of the clicked cell.
		/// </summary>
		/// <param name="positionY">The vertical position value.</param>
		/// <param name="layout">The worksheet area.</param>
		/// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
		/// <param name="top">Returns the top value of the clicked cell.</param>
		/// <param name="height">Returns the height value of the clicked cell.</param>
		/// <param name="bPropertyCol">True if clicked on either the property column header or a property column, else false.</param>
		/// <returns>The row number of the clicked cell, or -1 if clicked on the column header.</returns>
		/// <remarks>If clicked onto a property cell, the function returns the property column number.</remarks>
		public static int GetRowNumber(double positionY, WorksheetLayout layout, int VertScrollPos, out double top, out double height, out bool bPropertyCol)
		{
			top = 0;
			if (positionY < layout.ColumnHeaderStyle.Height)
			{
				height = layout.ColumnHeaderStyle.Height;
				bPropertyCol = false;
				return -1;
			}

			var verticalPositionOfFirstVisibleDataRow = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);
			var visiblePropertyColumns = GetVisiblePropertyColumns(0, positionY * 1.125, layout, VertScrollPos); // trick here: because coordinates lower than positionY are not relevant, we use a clipping region slightly larger than positionY

			if (positionY < verticalPositionOfFirstVisibleDataRow && visiblePropertyColumns > 0)
			{
				// calculate the raw row number
				int rawrow = (int)Math.Floor((positionY - layout.ColumnHeaderStyle.Height) / (double)layout.PropertyColumnHeaderStyle.Height);

				top = layout.ColumnHeaderStyle.Height + rawrow * layout.PropertyColumnHeaderStyle.Height;
				height = layout.PropertyColumnHeaderStyle.Height;

				bPropertyCol = true;
				return rawrow + GetFirstVisiblePropertyColumn(layout, VertScrollPos);
			}
			else
			{
				int rawrow = (int)Math.Floor((positionY - verticalPositionOfFirstVisibleDataRow) / (double)layout.RowHeaderStyle.Height);

				top = verticalPositionOfFirstVisibleDataRow + rawrow * layout.RowHeaderStyle.Height;
				height = layout.RowHeaderStyle.Height;
				bPropertyCol = false;
				return rawrow + GetFirstVisibleTableRow(layout, VertScrollPos);
			}
		}
示例#52
0
		public static int GetFirstVisiblePropertyColumn(double top, WorksheetLayout layout, int VertScrollPos)
		{
			if (VertScrollPos >= 0 || !layout.ShowPropertyColumns)
				return -1;

			int firstTotRow = (int)Math.Max(0, Math.Floor((top - layout.ColumnHeaderStyle.Height) / (double)layout.PropertyColumnHeaderStyle.Height));
			return firstTotRow + GetFirstVisiblePropertyColumn(layout, VertScrollPos);
		}
示例#53
0
		/// <summary>
		/// Creates the ClickedCellInfo from the data grid and the mouse coordinates of the click.
		/// </summary>
		/// <param name="positionX">The horizontal position value.</param>
		/// <param name="positionY">The vertical position value.</param>
		/// <param name="layout">The worksheet area.</param>
		/// <param name="HorzScrollPos">Value of the horizontal scroll bar.</param>
		/// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
		public static AreaInfo GetAreaType(double positionX, double positionY, WorksheetLayout layout, int HorzScrollPos, int VertScrollPos)
		{
			bool bIsPropertyColumn = false;
			double left, top, width, height; // coordinates of clicked cell
																			 //var _clickedCellRectangle = new Rect(0,0,0,0);
			var hittedColumn = GetColumnNumber(positionX, layout, HorzScrollPos, out left, out width);
			var hittedRow = GetRowNumber(positionY, layout, VertScrollPos, out top, out height, out bIsPropertyColumn);
			AreaType hittedAreaType;

			if (bIsPropertyColumn)
			{
				if (hittedColumn == -1)
					hittedAreaType = AreaType.PropertyColumnHeader;
				else if (hittedColumn >= 0)
					hittedAreaType = AreaType.PropertyCell;
				else
					hittedAreaType = AreaType.OutsideAll;

				// Swap columns and rows since it is a property column
				int h = hittedColumn;
				hittedColumn = hittedRow;
				hittedRow = h;
			}
			else // it is not a property related cell
			{
				if (hittedRow == -1 && hittedColumn == -1)
					hittedAreaType = AreaType.TableHeader;
				else if (hittedRow == -1 && hittedColumn >= 0)
					hittedAreaType = AreaType.DataColumnHeader;
				else if (hittedRow >= 0 && hittedColumn == -1)
					hittedAreaType = AreaType.DataRowHeader;
				else if (hittedRow >= 0 && hittedColumn >= 0)
					hittedAreaType = AreaType.DataCell;
				else
					hittedAreaType = AreaType.OutsideAll;
			}

			AreaInfo result = new AreaInfo()
			{
				ColumnNumber = hittedColumn,
				RowNumber = hittedRow,
				AreaRectangle = new RectangleD2D(left, top, width, height),
				AreaType = hittedAreaType
			};
			return result;
		}
示例#54
0
		/// <summary>
		/// This returns the vertical position of the first visible data row.;
		/// </summary>
		public static int GetVerticalPositionOfFirstVisibleDataRow(WorksheetLayout layout, int VertScrollPos)
		{
			return layout.ColumnHeaderStyle.Height + (VertScrollPos >= 0 ? 0 : -VertScrollPos * layout.PropertyColumnHeaderStyle.Height);
		}
示例#55
0
      protected override void Deserialize(WorksheetLayout s, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent)
      {
        base.Deserialize(s, info, parent);

        int count = info.OpenArray(); // DefaultPropertyColumnStyles
        for (int i = 0; i < count; i++)
        {
          object defstyle = info.GetValue("DefaultPropertyColumnStyle", s);
          s.DefaultPropertyColumnStyles.Add(defstyle.GetType(), defstyle);
        }
        info.CloseArray(count);
      }
示例#56
0
		/// <summary>
		/// Gets the first table row that is visible.
		/// </summary>
		/// <returns>The first table row that is visible.</returns>
		public static int GetFirstVisibleTableRow(WorksheetLayout layout, int VertScrollPos)
		{
			return Math.Max(0, VertScrollPos);
		}
 public SDWorksheetController(Altaxo.Worksheet.WorksheetLayout layout)
     : this(layout, false)
 {
 }
示例#58
0
		/// <summary>
		/// Gets the first table row that is visible under the coordinate top.
		/// </summary>
		/// <param name="top">The upper coordinate of the clipping rectangle.</param>
		/// <param name="layout">Worksheet layout referring to.</param>
		/// <param name="VertScrollPos">Value of the vertical scroll bar.</param>
		/// <returns>The first table row that is visible below the top coordinate.</returns>
		public static int GetFirstVisibleTableRow(double top, WorksheetLayout layout, int VertScrollPos)
		{
			int posOfDataRow0 = GetVerticalPositionOfFirstVisibleDataRow(layout, VertScrollPos);

			//int firstTotRow = (int)Math.Max(RemainingEnabledPropertyColumns,Math.Floor((top-m_TableLayout.ColumnHeaderStyle.Height)/(double)m_TableLayout.RowHeaderStyle.Height));
			//return FirstVisibleTableRow + Math.Max(0,firstTotRow-RemainingEnabledPropertyColumns);
			int firstVis = (int)Math.Floor((top - posOfDataRow0) / (double)layout.RowHeaderStyle.Height);
			return (firstVis < 0 ? 0 : firstVis) + Math.Max(0, VertScrollPos);
		}
 /// <summary>
 /// Creates a GraphController which shows the <see cref="Altaxo.Graph.Gdi.GraphDocument"/> in the <c>layout</c>.
 /// </summary>
 /// <param name="layout">The graph layout which holds the graph document.</param>
 public SDWorksheetViewContent(Altaxo.Worksheet.WorksheetLayout layout)
     : this(layout, false)
 {
 }
示例#60
0
		public WorksheetViewLayout(WorksheetLayout worksheetLayout)
		{
			_worksheetLayout = worksheetLayout;
		}