protected override void OnDraw(DevAge.Drawing.GraphicsCache graphics, RectangleF area) { System.Drawing.Drawing2D.GraphicsState state = graphics.Graphics.Save(); try { float width2 = area.Width / 2; float height2 = area.Height / 2; //For a better drawing use the clear type rendering graphics.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; //Move the origin to the center of the cell (for a more easy rotation) graphics.Graphics.TranslateTransform(area.X + width2, area.Y + height2); graphics.Graphics.RotateTransform(Angle); StringFormat.Alignment = StringAlignment.Center; StringFormat.LineAlignment = StringAlignment.Center; graphics.Graphics.DrawString(Value, Font, graphics.BrushsCache.GetBrush(ForeColor), 0, 0, StringFormat); } finally { graphics.Graphics.Restore(state); } }
/// <summary> /// Value constrcutor /// </summary> public RichTextBox(DevAge.Windows.Forms.RichText value) : base(value) { View = new Views.RichTextBox(); Model.AddModel(new Models.RichTextBox()); AddController(Controllers.RichTextBox.Default); Editor = new Editors.RichTextBox(); }
/// <summary> /// Sets the effect of the selected text. /// </summary> public void SetSelectionEffect(CellContext cellContext, DevAge.Windows.Forms.EffectType effect) { ValueChangeEventArgs valArgs = new ValueChangeEventArgs(null, effect); if (cellContext.Grid != null) cellContext.Grid.Controller.OnValueChanging(cellContext, valArgs); if (cellContext.Grid != null) cellContext.Grid.Controller.OnValueChanged(cellContext, EventArgs.Empty); }
public static System.Windows.Forms.HorizontalAlignment ContentToHorizontalAlignment(DevAge.Drawing.ContentAlignment a) { if (Drawing.Utilities.IsLeft(a)) return System.Windows.Forms.HorizontalAlignment.Left; else if (Drawing.Utilities.IsRight(a)) return System.Windows.Forms.HorizontalAlignment.Right; else return System.Windows.Forms.HorizontalAlignment.Center; }
//Here I should also implement MeasureContent (think also for a solution to allow rotated text with any kind of allignment) protected override SizeF OnMeasureContent(DevAge.Drawing.MeasureHelper measure, SizeF maxSize) { SizeF size; SizeF boundSize = new SizeF(); //For a better drawing use the clear type rendering measure.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit; StringFormat.Alignment = StringAlignment.Center; StringFormat.LineAlignment = StringAlignment.Center; size = measure.Graphics.MeasureString(Value, Font); float boundAngle = Math.Abs(Angle); boundSize.Width = (float)Math.Cos((boundAngle / 180) * Math.PI) * size.Width; boundSize.Height = (float)Math.Sin((boundAngle / 180) * Math.PI) * size.Width; return boundSize; }
/// <summary> /// Draw the highlighted cells. /// </summary> /// <param name="graphics"></param> /// <param name="drawingRange">The range of cells that must be redrawed. Consider that can contains also not selected cells.</param> protected virtual void DrawHighlight(DevAge.Drawing.GraphicsCache graphics, Range drawingRange) { if (Region.IsEmpty() || Region.IntersectsWith(drawingRange) == false) return; System.Drawing.Brush brush = graphics.BrushsCache.GetBrush(BackColor); foreach (Range rng in Region.GetRanges()) { System.Drawing.Rectangle rectToDraw = Grid.RangeToRectangle(rng); if (rectToDraw == System.Drawing.Rectangle.Empty) continue; System.Drawing.RectangleF contentRect = Border.GetContentRectangle(rectToDraw); graphics.Graphics.FillRectangle(brush, contentRect); Border.Draw(graphics, rectToDraw); } }
public static System.Windows.Forms.TextFormatFlags ContentAligmentToTextFormatFlags(DevAge.Drawing.ContentAlignment a) { System.Windows.Forms.TextFormatFlags f = (System.Windows.Forms.TextFormatFlags)0; if (Drawing.Utilities.IsBottom(a)) f |= System.Windows.Forms.TextFormatFlags.Bottom; else if (Drawing.Utilities.IsTop(a)) f |= System.Windows.Forms.TextFormatFlags.Top; else //if (Drawing.Utilities.IsMiddle(a)) f |= System.Windows.Forms.TextFormatFlags.VerticalCenter; if (Drawing.Utilities.IsLeft(a)) f |= System.Windows.Forms.TextFormatFlags.Left; else if (Drawing.Utilities.IsRight(a)) f |= System.Windows.Forms.TextFormatFlags.Right; else //if (Drawing.Utilities.IsCenter(a)) f |= System.Windows.Forms.TextFormatFlags.HorizontalCenter; return f; }
/// <summary> /// Constructor /// </summary> /// <param name="value"></param> public RichTextGDI(DevAge.Windows.Forms.RichText value) : base(value) { }
/// <summary> /// Free cached data from rich edit control after printing /// </summary> public void FormatRangeDone(DevAge.Windows.Forms.DevAgeRichTextBox RTB) { IntPtr lParam = new IntPtr(0); SendMessage(RTB.Handle, EM_FORMATRANGE, 0, lParam); }
/// <summary> /// Calculate or render the contents of our RichTextBox for printing /// </summary> /// <param name="measureOnly">If true, only the calculation is performed, /// otherwise the text is rendered as well</param> /// <param name="b"></param> /// <param name="rtb"></param> /// <param name="charFrom">Index of first character to be printed</param> /// <param name="charTo">Index of last character to be printed</param> /// <returns>(Index of last character that fitted on the /// page) + 1</returns> //public int FormatRange(bool measureOnly, PrintPageEventArgs e, int charFrom, int charTo) public int FormatRange(bool measureOnly, DevAge.Windows.Forms.DevAgeRichTextBox rtb, ref Bitmap b, int charFrom, int charTo) { // Specify which characters to print STRUCT_CHARRANGE cr; cr.cpMin = charFrom; cr.cpMax = charTo; // Specify the area inside page margins STRUCT_RECT rc; rc.Top = HundredthInchToTwips(0); rc.Bottom = HundredthInchToTwips(b.Height); rc.Left = HundredthInchToTwips(0); rc.Right = HundredthInchToTwips(b.Width); // Specify the page area STRUCT_RECT rcPage; rcPage.Top = HundredthInchToTwips(0); rcPage.Bottom = HundredthInchToTwips(b.Height); rcPage.Left = HundredthInchToTwips(0); rcPage.Right = HundredthInchToTwips(b.Width); // Get device context of output device Graphics g = Graphics.FromImage(b); IntPtr hdc = g.GetHdc(); // Fill in the FORMATRANGE struct STRUCT_FORMATRANGE fr; fr.chrg = cr; fr.hdc = hdc; fr.hdcTarget = hdc; fr.rc = rc; fr.rcPage = rcPage; // Non-Zero wParam means render, Zero means measure Int32 wParam = (measureOnly ? 0 : 1); // Allocate memory for the FORMATRANGE struct and // copy the contents of our struct to this memory IntPtr lParam = Marshal.AllocCoTaskMem(Marshal.SizeOf(fr)); Marshal.StructureToPtr(fr, lParam, false); // Send the actual Win32 message int res = SendMessage(rtb.Handle, EM_FORMATRANGE, wParam, lParam); // Free allocated memory Marshal.FreeCoTaskMem(lParam); // and release the device context g.ReleaseHdc(hdc); g.Dispose(); return res; }
/// <summary> /// Constructor /// </summary> /// <param name="value"></param> public RichText(DevAge.Windows.Forms.RichText value) { Value = value; }
public override void OnValueChanging(CellContext sender, DevAge.ComponentModel.ValueEventArgs e) { base.OnValueChanging (sender, e); //BeginEdit on the row, set the Cancel = true if failed to start editing. bool success = ((DataGrid)sender.Grid).BeginEditRow(sender.Position.Row); if (success == false) throw new SourceGridException("Failed to editing row " + sender.Position.Row.ToString()); }
public static string BorderToHTMLStyle(DevAge.Drawing.IBorder border) { if (border is DevAge.Drawing.RectangleBorder) { DevAge.Drawing.RectangleBorder brd = (DevAge.Drawing.RectangleBorder)border; return "border-top:" + BorderToHTMLStyle(brd.Top) + ";border-right:" + BorderToHTMLStyle(brd.Right) + ";border-bottom:" + BorderToHTMLStyle(brd.Bottom) + ";border-left:" + BorderToHTMLStyle(brd.Left) + ";"; } else return string.Empty; }
/// <summary> /// Draw the specified Cell /// </summary> protected virtual void PaintCell(DevAge.Drawing.GraphicsCache graphics, CellContext cellContext, RectangleF drawRectangle) { if (drawRectangle.Width > 0 && drawRectangle.Height > 0 && cellContext.CanBeDrawn() ) { cellContext.Cell.View.DrawCell(cellContext, graphics, drawRectangle); } }
public override void OnValueChanging(CellContext sender, DevAge.ComponentModel.ValueEventArgs e) { base.OnValueChanging(sender, e); if (sender.Cell != null && sender.Cell.Controller != null) sender.Cell.Controller.OnValueChanging(sender, e); }
/// <summary> /// Fired before the value of the cell is changed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public virtual void OnValueChanging(CellContext sender, DevAge.ComponentModel.ValueEventArgs e) { }
private void CreateColumns(DevAge.ComponentModel.IBoundList boundList) { //Create the editors SourceGrid.Cells.Editors.TextBoxNumeric numericEditor = new SourceGrid.Cells.Editors.TextBoxNumeric(typeof(decimal)); numericEditor.TypeConverter = new DevAge.ComponentModel.Converter.NumberTypeConverter(typeof(decimal), "N"); numericEditor.AllowNull = true; //the database value can be null (System.DbNull) SourceGrid.Cells.Editors.ComboBox externalIdEditor = new SourceGrid.Cells.Editors.ComboBox(typeof(int)); externalIdEditor.StandardValues = new int[]{1, 2, 3, 4}; externalIdEditor.StandardValuesExclusive = true; externalIdEditor.Control.FormattingEnabled = true; DevAge.ComponentModel.Validator.ValueMapping mapping = new DevAge.ComponentModel.Validator.ValueMapping(); mapping.ValueList = new int[]{1, 2, 3, 4}; mapping.DisplayStringList = new string[] { "Reference 1", "Reference 2", "Reference 3", "Reference 4" }; mapping.BindValidator(externalIdEditor); //Create the views SourceGrid.Cells.Views.Cell viewSelected = new SourceGrid.Cells.Views.Cell(); viewSelected.Font = new Font(dataGrid.Font, FontStyle.Bold); viewSelected.ForeColor = Color.DarkGreen; //Create selected conditions SourceGrid.Conditions.ConditionView selectedConditionBold = new SourceGrid.Conditions.ConditionView(viewSelected); selectedConditionBold.EvaluateFunction = delegate(SourceGrid.DataGridColumn column, int gridRow, object itemRow) { DataRowView row = (DataRowView)itemRow; return row["Selected"] is bool && (bool)row["Selected"] == true; }; SourceGrid.Conditions.ConditionCell selectedConditionStar = new SourceGrid.Conditions.ConditionCell(new SourceGrid.Cells.Virtual.CellVirtual()); selectedConditionStar.Cell.Model.AddModel(new SourceGrid.Cells.Models.Image(Properties.Resources.Star.ToBitmap())); selectedConditionStar.EvaluateFunction = delegate(SourceGrid.DataGridColumn column, int gridRow, object itemRow) { DataRowView row = (DataRowView)itemRow; return row["Selected"] is bool && (bool)row["Selected"] == true; }; //Create columns SourceGrid.DataGridColumn gridColumn; gridColumn = dataGrid.Columns.Add("Selected", "Selected", typeof(bool)); gridColumn = dataGrid.Columns.Add("Country", "Country", typeof(string)); gridColumn.DataCell.Model.AddModel(new BoundImage("Uniform")); gridColumn.Conditions.Add(selectedConditionBold); gridColumn = dataGrid.Columns.Add("Uniform", "Uniform", new SourceGrid.Cells.DataGrid.Image()); gridColumn.Conditions.Add(selectedConditionBold); gridColumn = dataGrid.Columns.Add("Population", "Population", numericEditor); gridColumn.Conditions.Add(selectedConditionBold); gridColumn = dataGrid.Columns.Add("Surface", "Surface", numericEditor); gridColumn.Conditions.Add(selectedConditionBold); gridColumn = dataGrid.Columns.Add("ExternalID", "ExternalID", externalIdEditor); gridColumn.Conditions.Add(selectedConditionBold); gridColumn = dataGrid.Columns.Add("Star", "Star", new SourceGrid.Cells.Virtual.CellVirtual()); gridColumn.DataCell.Model.AddModel(new SourceGrid.Cells.Models.Image(Properties.Resources.StarOff)); gridColumn.Conditions.Add(selectedConditionStar); foreach (SourceGrid.DataGridColumn col in dataGrid.Columns) { col.DataCell.AddController(SourceGrid.Cells.Controllers.ToolTipText.Default); col.DataCell.Model.AddModel(MyToolTipModel.Default); } }
protected virtual void ExportCell(CellContext context, DevAge.Drawing.GraphicsCache graphics, System.Drawing.Rectangle rectangle) { if (context.Cell != null) { context.Cell.View.DrawCell(context, graphics, rectangle); } }
public void SetSortMode(CellContext cellContext, DevAge.Drawing.HeaderSortStyle pStyle) { m_SortStatus.Style = pStyle; }
public RangePaintEventArgs(GridVirtual grid, DevAge.Drawing.GraphicsCache graphicsCache, Range drawingRange) { mGrid = grid; mGraphicsCache = graphicsCache; mDrawingRange = drawingRange; }
/// <summary> /// Constructor /// </summary> /// <param name="p_Style">Status of current sort.</param> public SortStatus(DevAge.Drawing.HeaderSortStyle p_Style) { Style = p_Style; Comparer = null; }
public static bool IsCenter(DevAge.Drawing.ContentAlignment a) { return (a == DevAge.Drawing.ContentAlignment.BottomCenter || a == DevAge.Drawing.ContentAlignment.MiddleCenter || a == DevAge.Drawing.ContentAlignment.TopCenter); }
/// <summary> /// Constructor /// </summary> /// <param name="p_Style">Status of current sort.</param> /// <param name="p_Comparer">Comparer used to sort the column. The comparer will take 2 Cell. If null the default ValueCellComparer is used.</param> public SortStatus(DevAge.Drawing.HeaderSortStyle p_Style, System.Collections.IComparer p_Comparer) : this(p_Style) { Comparer = p_Comparer; }
public static bool IsRight(DevAge.Drawing.ContentAlignment a) { return (a == DevAge.Drawing.ContentAlignment.BottomRight || a == DevAge.Drawing.ContentAlignment.MiddleRight || a == DevAge.Drawing.ContentAlignment.TopRight); }
public static string BorderToHTMLStyle(DevAge.Drawing.BorderLine p_Border) { if (p_Border.Width>0) { return p_Border.Width.ToString() + "px solid " + ColorToHTML(p_Border.Color); } else return "none"; }
public static bool IsLeft(DevAge.Drawing.ContentAlignment a) { return (a == DevAge.Drawing.ContentAlignment.BottomLeft || a == DevAge.Drawing.ContentAlignment.MiddleLeft || a == DevAge.Drawing.ContentAlignment.TopLeft); }
protected override void PaintCell(DevAge.Drawing.GraphicsCache graphics, CellContext cellContext, RectangleF drawRectangle) { Range cellRange = PositionToCellRange(cellContext.Position); if (cellRange.ColumnsCount == 1 && cellRange.RowsCount == 1) { base.PaintCell(graphics, cellContext, drawRectangle); } else //Row/Col Span > 1 { // I draw the merged cell only if not already drawn otherwise // drawing the same cell can cause some problem when using // special drawing code (for example semi transparent background) if (mDrawnRange.Contains(cellRange) == false) { Rectangle spanRect = RangeToRectangle(cellRange); base.PaintCell(graphics, cellContext, spanRect); mDrawnRange.Add(cellRange); } } }
void mBoundList_ItemDeleted ( object sender, DevAge.ComponentModel.ItemDeletedEventArgs e ) { Rows.RowDeleted(e.Item); }
/// <summary> /// Fired before the value of the cell is changed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> public void OnValueChanging(CellContext sender, DevAge.ComponentModel.ValueEventArgs e) { if (ValueChanging!=null) ValueChanging(sender, e); }
/// <summary> /// Draw the specified Cell /// </summary> protected virtual void PaintCell(DevAge.Drawing.GraphicsCache graphics, CellContext cellContext, RectangleF drawRectangle) { if (drawRectangle.Width > 0 && drawRectangle.Height > 0 && (cellContext.Cell.Editor == null || cellContext.Cell.Editor.EnableCellDrawOnEdit || cellContext.IsEditing() == false) ) { cellContext.Cell.View.DrawCell(cellContext, graphics, drawRectangle); } }