/// <summary> /// Handles the CellButtonClicked event of the tableXSL control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="XPTable.Events.CellButtonEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-10-30</remarks> private void tableXSL_CellButtonClicked(object sender, XPTable.Events.CellButtonEventArgs e) { XSLStyleElement element = e.Cell.Tag as XSLStyleElement; FontDialog fontdialog = new FontDialog(); fontdialog.ShowColor = false; fontdialog.ShowApply = false; fontdialog.ShowEffects = false; fontdialog.ShowHelp = false; fontdialog.ScriptsOnly = true; fontdialog.MinSize = 6; fontdialog.MaxSize = 72; fontdialog.FontMustExist = true; FontStyle style = FontStyle.Regular; if (element.Items.ContainsKey("font-weight") && element.Items["font-weight"].ToLower() == "bold") { style |= FontStyle.Bold; } if (element.Items.ContainsKey("font-style") && element.Items["font-style"].ToLower() == "italic") { style |= FontStyle.Italic; } string fontFace = element.Items.ContainsKey("font-family") ? element.Items["font-family"] : "Arial"; int defaultFontSize = 12; int fontSize = defaultFontSize; if (element.Items.ContainsKey("font-size") && !element.Items["font-size"].Contains("%")) { if (element.Items["font-size"].EndsWith("pt")) { if (!Int32.TryParse(element.Items["font-size"].Replace("pt", String.Empty), out fontSize)) { fontSize = defaultFontSize; } } else { if (!Int32.TryParse(element.Items["font-size"], out fontSize)) { fontSize = defaultFontSize; } } } try // to handle a rare exception that can be thrown when the user selects an invalid font { fontdialog.Font = new Font(fontFace, fontSize, style); } catch { fontdialog.Font = new Font("Microsoft Sans Serif", fontSize, style); } if (fontdialog.ShowDialog() == DialogResult.OK) { if (element.Items.ContainsKey("font-size")) { element.Items["font-size"] = Math.Round(fontdialog.Font.Size, 0).ToString() + "pt"; } else { element.Items.Add("font-size", Math.Round(fontdialog.Font.Size, 0).ToString() + "pt"); } if (element.Items.ContainsKey("font-style")) { element.Items["font-style"] = fontdialog.Font.Italic ? "italic" : "normal"; } else { element.Items.Add("font-style", fontdialog.Font.Italic ? "italic" : "normal"); } if (element.Items.ContainsKey("font-weight")) { element.Items["font-weight"] = fontdialog.Font.Bold ? "bold" : "normal"; } else { element.Items.Add("font-weight", fontdialog.Font.Bold ? "bold" : "normal"); } if (element.Items.ContainsKey("font-family")) { element.Items["font-family"] = fontdialog.Font.FontFamily.Name; } else { element.Items.Add("font-family", fontdialog.Font.FontFamily.Name); } SaveFile(); ShowPreview(); } }
/// <summary> /// Parses the CSS. /// </summary> /// <param name="css">The CSS.</param> /// <remarks>Documented by Dev03, 2008-03-05</remarks> private void ParseCSS(string css) { // ignore comments when parsing css Regex stripComments = new Regex(@"/\*(.|\n)*?\*/", RegexOptions.Multiline); css = stripComments.Replace(css, String.Empty); string[] elements = css.Split(new char[] { '{', '}' }); xslElements = new List <XSLStyleElement>(); for (int i = 0; i < elements.Length - 1; i++) { XSLStyleElement element = new XSLStyleElement(); element.Name = elements[i].Trim(); i++; string subElements = elements[i].Trim(); Regex whitespace = new Regex("[\n\r\t]"); subElements = whitespace.Replace(subElements, String.Empty); string[] pairs = subElements.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string pair in pairs) { string[] parts = pair.Split(new char[] { ':' }, 2); element.Items[parts[0].ToLower().Trim()] = parts[1].Trim(); } // end parsing xslElements.Add(element); } tableXSL.TableModel.Rows.Clear(); foreach (XSLStyleElement element in xslElements) { tableXSL.TableModel.Rows.Add(new XPTable.Models.Row(new string[] { element.Name.StartsWith(".") ? element.Name.Substring(1) : element.Name })); Cell colorCell; if (element.Items.ContainsKey("color")) { int colorValue; if (Int32.TryParse(element.Items["color"].Substring(1, 6), System.Globalization.NumberStyles.AllowHexSpecifier, null, out colorValue)) { colorCell = new XPTable.Models.Cell(Color.FromArgb(255, Color.FromArgb(colorValue))); } else { colorCell = new XPTable.Models.Cell(Color.Empty); } } else { colorCell = new XPTable.Models.Cell(Color.Empty); } colorCell.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); colorCell.Tag = element; colorCell.ToolTipText = "color"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(colorCell); Cell backgroundColorCell; if (element.Items.ContainsKey("background-color")) { int colorValue; if (Int32.TryParse(element.Items["background-color"].Substring(1, 6), System.Globalization.NumberStyles.AllowHexSpecifier, null, out colorValue)) { backgroundColorCell = new XPTable.Models.Cell(Color.FromArgb(255, Color.FromArgb(colorValue))); } else { backgroundColorCell = new XPTable.Models.Cell(Color.Empty); } } else { backgroundColorCell = new XPTable.Models.Cell(Color.Empty); } backgroundColorCell.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); backgroundColorCell.Tag = element; backgroundColorCell.ToolTipText = "background-color"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(backgroundColorCell); Cell cellToAdd = new XPTable.Models.Cell(Properties.Resources.STYLEEDIT_SELECTFONTBUTTON); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "font"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); cellToAdd = new XPTable.Models.Cell(); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "HAlign"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); EnumLocalizer hNone = new EnumLocalizer(Properties.Resources.ResourceManager, MLifter.DAL.Interfaces.HorizontalAlignment.None); if (element.Items.ContainsKey("text-align")) { EnumLocalizer textAlign = horizontalElements.Find(delegate(EnumLocalizer loc) { return(loc.value.ToString().Equals(element.Items["text-align"], StringComparison.InvariantCultureIgnoreCase)); }); cellToAdd.Text = (textAlign != null) ? textAlign.ToString() : hNone.ToString(); } else if (element.Items.ContainsKey("float")) { cellToAdd.Text = element.Items["float"]; cellToAdd.ToolTipText = "float"; } else { cellToAdd.Text = hNone.ToString(); } cellToAdd = new XPTable.Models.Cell(); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "VAlign"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); EnumLocalizer vNone = new EnumLocalizer(Properties.Resources.ResourceManager, MLifter.DAL.Interfaces.VerticalAlignment.None); if (element.Items.ContainsKey("vertical-align")) { EnumLocalizer verticalAlign = verticalElements.Find(delegate(EnumLocalizer loc) { return(loc.value.ToString().Equals(element.Items["vertical-align"], StringComparison.InvariantCultureIgnoreCase)); }); cellToAdd.Text = (verticalAlign != null) ? verticalAlign.ToString() : vNone.ToString(); } else { cellToAdd.Text = vNone.ToString(); } } SaveFile(); }
/// <summary> /// Handles the PropertyChanged event of the XSLStyleEdit control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="XPTable.Events.CellEventArgs"/> instance containing the event data.</param> /// <remarks>Documented by Dev05, 2007-10-30</remarks> void XSLStyleEdit_PropertyChanged(object sender, XPTable.Events.CellEventArgs e) { if (!loading) { XSLStyleElement element = (e.Cell.Tag as XSLStyleElement); if (e.Cell.ToolTipText == "color" || e.Cell.ToolTipText == "background-color") { Color color = (Color)e.Cell.Data; if (element.Items.ContainsKey(e.Cell.ToolTipText)) { element.Items[e.Cell.ToolTipText] = string.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B); } else { element.Items.Add(e.Cell.ToolTipText, string.Format("#{0:x2}{1:x2}{2:x2}", color.R, color.G, color.B)); } } else if (e.Cell.ToolTipText == "HAlign") { if (e.Cell.Text == horizontalElements[0].ToString()) { element.Items.Remove("text-align"); } else { EnumLocalizer textAlign = horizontalElements.Find(delegate(EnumLocalizer loc) { return(loc.ToString().Equals(e.Cell.Text, StringComparison.CurrentCultureIgnoreCase)); }); if (textAlign == null) { element.Items.Remove("text-align"); } else { if (element.Items.ContainsKey("text-align")) { element.Items["text-align"] = textAlign.value.ToString().ToLower(); } else { element.Items.Add("text-align", textAlign.value.ToString().ToLower()); } } } } else if (e.Cell.ToolTipText == "float") { if (element.Items.ContainsKey("float")) { element.Items["float"] = e.Cell.Text; } else { element.Items.Add("float", e.Cell.Text); } if (e.Cell.Text == horizontalElements[0].ToString()) { element.Items.Remove("float"); } } else if (e.Cell.ToolTipText == "VAlign") { if (e.Cell.Text == verticalElements[0].ToString()) { element.Items.Remove("vertical-align"); } else { EnumLocalizer verticalAlign = verticalElements.Find(delegate(EnumLocalizer loc) { return(loc.ToString().Equals(e.Cell.Text, StringComparison.CurrentCultureIgnoreCase)); }); if (verticalAlign == null) { element.Items.Remove("vertical-align"); } else { if (element.Items.ContainsKey("vertical-align")) { element.Items["vertical-align"] = verticalAlign.value.ToString().ToLower(); } else { element.Items.Add("vertical-align", verticalAlign.value.ToString().ToLower()); } } } } SaveFile(); ShowPreview(); } }
/// <summary> /// Parses the CSS. /// </summary> /// <param name="css">The CSS.</param> /// <remarks>Documented by Dev03, 2008-03-05</remarks> private void ParseCSS(string css) { // ignore comments when parsing css Regex stripComments = new Regex(@"/\*(.|\n)*?\*/", RegexOptions.Multiline); css = stripComments.Replace(css, String.Empty); string[] elements = css.Split(new char[] { '{', '}' }); xslElements = new List<XSLStyleElement>(); for (int i = 0; i < elements.Length - 1; i++) { XSLStyleElement element = new XSLStyleElement(); element.Name = elements[i].Trim(); i++; string subElements = elements[i].Trim(); Regex whitespace = new Regex("[\n\r\t]"); subElements = whitespace.Replace(subElements, String.Empty); string[] pairs = subElements.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries); foreach (string pair in pairs) { string[] parts = pair.Split(new char[] { ':' }, 2); element.Items[parts[0].ToLower().Trim()] = parts[1].Trim(); } // end parsing xslElements.Add(element); } tableXSL.TableModel.Rows.Clear(); foreach (XSLStyleElement element in xslElements) { tableXSL.TableModel.Rows.Add(new XPTable.Models.Row(new string[] { element.Name.StartsWith(".") ? element.Name.Substring(1) : element.Name })); Cell colorCell; if (element.Items.ContainsKey("color")) { int colorValue; if (Int32.TryParse(element.Items["color"].Substring(1, 6), System.Globalization.NumberStyles.AllowHexSpecifier, null, out colorValue)) { colorCell = new XPTable.Models.Cell(Color.FromArgb(255, Color.FromArgb(colorValue))); } else { colorCell = new XPTable.Models.Cell(Color.Empty); } } else { colorCell = new XPTable.Models.Cell(Color.Empty); } colorCell.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); colorCell.Tag = element; colorCell.ToolTipText = "color"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(colorCell); Cell backgroundColorCell; if (element.Items.ContainsKey("background-color")) { int colorValue; if (Int32.TryParse(element.Items["background-color"].Substring(1, 6), System.Globalization.NumberStyles.AllowHexSpecifier, null, out colorValue)) { backgroundColorCell = new XPTable.Models.Cell(Color.FromArgb(255, Color.FromArgb(colorValue))); } else { backgroundColorCell = new XPTable.Models.Cell(Color.Empty); } } else { backgroundColorCell = new XPTable.Models.Cell(Color.Empty); } backgroundColorCell.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); backgroundColorCell.Tag = element; backgroundColorCell.ToolTipText = "background-color"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(backgroundColorCell); Cell cellToAdd = new XPTable.Models.Cell(Properties.Resources.STYLEEDIT_SELECTFONTBUTTON); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "font"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); cellToAdd = new XPTable.Models.Cell(); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "HAlign"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); EnumLocalizer hNone = new EnumLocalizer(Properties.Resources.ResourceManager, MLifter.DAL.Interfaces.HorizontalAlignment.None); if (element.Items.ContainsKey("text-align")) { EnumLocalizer textAlign = horizontalElements.Find(delegate(EnumLocalizer loc) { return loc.value.ToString().Equals(element.Items["text-align"], StringComparison.InvariantCultureIgnoreCase); }); cellToAdd.Text = (textAlign != null) ? textAlign.ToString() : hNone.ToString(); } else if (element.Items.ContainsKey("float")) { cellToAdd.Text = element.Items["float"]; cellToAdd.ToolTipText = "float"; } else cellToAdd.Text = hNone.ToString(); cellToAdd = new XPTable.Models.Cell(); cellToAdd.PropertyChanged += new XPTable.Events.CellEventHandler(XSLStyleEdit_PropertyChanged); cellToAdd.Tag = element; cellToAdd.ToolTipText = "VAlign"; tableXSL.TableModel.Rows[tableXSL.TableModel.Rows.Count - 1].Cells.Add(cellToAdd); EnumLocalizer vNone = new EnumLocalizer(Properties.Resources.ResourceManager, MLifter.DAL.Interfaces.VerticalAlignment.None); if (element.Items.ContainsKey("vertical-align")) { EnumLocalizer verticalAlign = verticalElements.Find(delegate(EnumLocalizer loc) { return loc.value.ToString().Equals(element.Items["vertical-align"], StringComparison.InvariantCultureIgnoreCase); }); cellToAdd.Text = (verticalAlign != null) ? verticalAlign.ToString() : vNone.ToString(); } else cellToAdd.Text = vNone.ToString(); } SaveFile(); }