/// <summary> /// Derive the LgCharRenderProps from the DataGridViewCellStyle and FwTextBoxColumn. /// </summary> /// <remarks>Only used with Mono</remarks> private LgCharRenderProps GetRenderProps(DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { Debug.Assert(Platform.IsMono, "This method is only needed on Mono"); var renderProps = new LgCharRenderProps(); renderProps.szFaceName = new ushort[32]; // arrays should be created in constructor, but struct doesn't have one. renderProps.szFontVar = new ushort[64]; var foreColor = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; renderProps.clrFore = (uint)foreColor.ToArgb(); // The background behind the characters must be transparent for the correct // background color to show (at least for Selected). const uint transparent = 0xC0000000; // FwTextColor.kclrTransparent won't convert to uint renderProps.clrBack = transparent; renderProps.ws = col.TextBoxControl.WritingSystemCode; renderProps.fWsRtl = (byte)(col.TextBoxControl.RightToLeft == RightToLeft.Yes ? 1 : 0); var font = cellStyle.Font; renderProps.dympHeight = (int)(font.SizeInPoints * 1000.0); // size in millipoints int lim = Math.Min(renderProps.szFaceName.Length, font.Name.Length); for (var i = 0; i < lim; ++i) { renderProps.szFaceName[i] = (ushort)font.Name[i]; } // The rest of these values are set to default values. renderProps.clrUnder = 0xFFFFFF; renderProps.nDirDepth = 0; renderProps.ssv = 0; renderProps.unt = 0; renderProps.ttvBold = 0; renderProps.ttvItalic = 0; return(renderProps); }
/// <summary> /// Draw the text using the FieldWorks IVwGraphicsWin32 interface. /// </summary> /// <remarks>Only used with Mono</remarks> private void DrawFwText(Graphics graphics, Rectangle cellBounds, string text, DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { Debug.Assert(Platform.IsMono, "This method is only needed on Mono"); if (String.IsNullOrEmpty(text)) { return; } IntPtr hdc = graphics.GetHdc(); IVwGraphicsWin32 vg = VwGraphicsWin32Class.Create(); // actually VwGraphicsCairo try { vg.Initialize(hdc); var renderProps = GetRenderProps(cellStyle, col); vg.SetupGraphics(ref renderProps); int x; int y; GetLocationForText(cellBounds, (col.TextBoxControl.RightToLeft == RightToLeft.Yes), vg, text, out x, out y); vg.PushClipRect(cellBounds); vg.DrawText(x, y, text.Length, text, 0); vg.PopClipRect(); } finally { vg.ReleaseDC(); graphics.ReleaseHdc(hdc); } }
/// <summary> /// Paint this DataGridView cell. Overridden to allow RightToLeft display if needed. /// </summary> protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object val, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts) { FwTextBoxColumn col = OwningColumn as FwTextBoxColumn; if (formattedValue == null || col == null) { base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, val, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts); return; } // Prepaint DataGridViewPaintParts pre = DataGridViewPaintParts.Background | DataGridViewPaintParts.SelectionBackground; pre = pre & paintParts; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, val, formattedValue, errorText, cellStyle, advancedBorderStyle, pre); // Paint content if (!IsInEditMode && (paintParts & DataGridViewPaintParts.ContentForeground) == DataGridViewPaintParts.ContentForeground) { DrawFwText(graphics, cellBounds, formattedValue.ToString(), cellStyle, col); } // Postpaint DataGridViewPaintParts post = DataGridViewPaintParts.Border | DataGridViewPaintParts.Focus | DataGridViewPaintParts.ErrorIcon; post = post & paintParts; base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, val, formattedValue, errorText, cellStyle, advancedBorderStyle, post); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Adds a column with the given name. /// </summary> /// <param name="name">Name of the column.</param> /// <param name="widthPct">The width PCT.</param> /// ------------------------------------------------------------------------------------ private void AddColumn(string name, int widthPct) { FwTextBoxColumn col = new FwTextBoxColumn(m_cache, true); col.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; col.HeaderText = name; col.FillWeight = (float)widthPct; col.Resizable = DataGridViewTriState.True; col.StyleSheet = m_stylesheet; col.UseTextPropsFontForCell = true; Columns.Add(col); }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes the text box control. /// </summary> /// <param name="ctrl">The FwTextBox control to initialize.</param> /// <param name="rowIndex">The row index.</param> /// <remarks><paramref name="rowIndex"/> is usually the same as RowIndex, except in the /// case of a shared row (in which case RowIndex is always -1).</remarks> /// ------------------------------------------------------------------------------------ private void InitializeTextBoxControl(FwTextBoxControl ctrl, int rowIndex) { if (rowIndex < 0) { return; } // The owning column owns the FwTextBoxControl we need // to edit the cell. So let it do the intialization. FwTextBoxColumn col = OwningColumn as FwTextBoxColumn; if (col != null) { col.InitializeTextBoxControl(ctrl, GetValue(rowIndex) as ITsString, rowIndex); } }
/// -------------------------------------------------------------------------------------- /// <summary> /// Show checking errors with a status of irrelevant in gray text. Also make sure the /// font of font for the details column matches the font for the writing system of the /// cited text that goes in the current cell of that column. Finally, if the cited text /// is for a characters check and the character is a non-printable character, then /// show the character's name in red. /// </summary> /// -------------------------------------------------------------------------------------- protected override void OnCellFormatting(DataGridViewCellFormattingEventArgs e) { base.OnCellFormatting(e); // Under certain circumstances, this gets set at the bottom of this method. // This will make sure it's cleared before anything else. m_detailCellIsForNonPrintableChar = false; if (e.RowIndex < 0 || e.ColumnIndex < 0 || m_list.Count <= e.RowIndex) return; // Make sure we have a checking error. CheckingError error = m_list[e.RowIndex] as CheckingError; if (error == null) return; // If the check error status is no longer relevant, then make the text // color gray to indicate that fact. if (error.Status == CheckingStatus.StatusEnum.Irrelevant) e.CellStyle.ForeColor = SystemColors.GrayText; // If we're not dealing with the details column, // then no more format handling is necessary. if (e.ColumnIndex != EditorialChecksRenderingsControl.kDetailsCol) return; if (m_detailsCol == null) m_detailsCol = Columns[e.ColumnIndex] as FwTextBoxColumn; Font fnt = m_detailsCol.Font; // Get the writing system for the cited text that will be displayed in the cell. // If that writing system is the same as the column's (which should be default // vernacular), then no more formatting necessary. if (error.Details == null) return; // can't get Ws of null string int ws = TsStringUtils.GetWsAtOffset(error.Details, 0); if (ws <= 0) return; // Something bad happened (TE-8559) if (ws != m_detailsCol.WritingSystemCode) { // At this point, we know the detail columm's writing system (i.e. the default // vernacular) is different from the writing system for the current cell's cited // text. Therefore, get the font for the cited text's writing system and return // that in the cell's style object. if (!m_detailsColFonts.TryGetValue(ws, out fnt) || fnt.Size != m_detailsCol.Font.Size) { m_detailsColFonts[ws] = fnt = m_styleSheet.GetUiFontForWritingSystem(ws, m_detailsCol.Font.SizeInPoints); } e.CellStyle.Font = fnt; m_detailsCol.SetCellStyleAlignment(ws, e.CellStyle); } // Do nothing else if the check result is not for the characters check. if (error.CheckId != StandardCheckIds.kguidCharacters) return; string chr = error.MyNote.CitedText; if (string.IsNullOrEmpty(chr)) return; // If the character is a space or control character, then show the character name // rather than the character itself since, obviously, it couldn't be seen otherwise. if (Win32.AreCharGlyphsInFont(chr, fnt) && (Icu.IsControl(chr) || Icu.IsSpace(chr))) { e.Value = Icu.GetPrettyICUCharName(chr); e.CellStyle.ForeColor = Color.Red; e.CellStyle.Font = DefaultCellStyle.Font; m_detailCellIsForNonPrintableChar = true; } }
private LgCharRenderProps GetRenderProps(DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { var renderProps = new LgCharRenderProps(); renderProps.szFaceName = new ushort[32]; // arrays should be created in constructor, but struct doesn't have one. renderProps.szFontVar = new ushort[64]; var foreColor = Selected ? cellStyle.SelectionForeColor : cellStyle.ForeColor; renderProps.clrFore = (uint)foreColor.ToArgb(); // The background behind the characters must be transparent for the correct // background color to show (at least for Selected). const uint transparent = 0xC0000000; // FwTextColor.kclrTransparent won't convert to uint renderProps.clrBack = transparent; renderProps.ws = col.TextBoxControl.WritingSystemCode; renderProps.fWsRtl = (byte)(col.TextBoxControl.RightToLeft == RightToLeft.Yes ? 1 : 0); var font = cellStyle.Font; renderProps.dympHeight = (int)(font.SizeInPoints * 1000.0); // size in millipoints int lim = Math.Min(renderProps.szFaceName.Length, font.Name.Length); for (var i = 0; i < lim; ++i) renderProps.szFaceName[i] = (ushort)font.Name[i]; // The rest of these values are set to default values. renderProps.clrUnder = 0xFFFFFF; renderProps.nDirDepth = 0; renderProps.ssv = 0; renderProps.unt = 0; renderProps.ttvBold = 0; renderProps.ttvItalic = 0; return renderProps; }
/// <summary> /// Draw the text using the FieldWorks IVwGraphicsWin32 interface. /// </summary> private void DrawFwText(Graphics graphics, Rectangle cellBounds, string text, DataGridViewCellStyle cellStyle, FwTextBoxColumn col) { if (String.IsNullOrEmpty(text)) return; IntPtr hdc = graphics.GetHdc(); IVwGraphicsWin32 vg = VwGraphicsWin32Class.Create(); // actually VwGraphicsCairo try { vg.Initialize(hdc); var renderProps = GetRenderProps(cellStyle, col); vg.SetupGraphics(ref renderProps); int x; int y; GetLocationForText(cellBounds, (col.TextBoxControl.RightToLeft == RightToLeft.Yes), vg, text, out x, out y); vg.PushClipRect(cellBounds); vg.DrawText(x, y, text.Length, text, 0); vg.PopClipRect(); } finally { vg.ReleaseDC(); graphics.ReleaseHdc(hdc); } }