/// <summary>
        /// Loads the style.
        /// </summary>
        /// <remarks>Documented by Dev05, 2007-10-31</remarks>
        private void LoadStyle()
        {
            if (style == null)
            {
                return;
            }

            actualizing = true;

            comboBoxColorPickerBack.Color = style.BackgroundColor != Color.Empty ? style.BackgroundColor : Color.White;
            comboBoxColorPickerFore.Color = style.ForeColor != Color.Empty ? style.ForeColor : Color.White;

            if (style.FontFamily != null)
            {
                comboBoxFontFamily.SelectedItem = families[style.FontFamily];
            }
            else
            {
                comboBoxFontFamily.SelectedIndex = 0;
            }

            checkBoxFontStyleNone.Checked      = style.FontStyle == CSSFontStyle.None;
            checkBoxFontStyleRegular.Checked   = (style.FontStyle & CSSFontStyle.Regular) == CSSFontStyle.Regular;
            checkBoxFontStyleBold.Checked      = (style.FontStyle & CSSFontStyle.Bold) == CSSFontStyle.Bold;
            checkBoxFontStyleItalic.Checked    = (style.FontStyle & CSSFontStyle.Italic) == CSSFontStyle.Italic;
            checkBoxFontStyleStrikeout.Checked = (style.FontStyle & CSSFontStyle.Strikeout) == CSSFontStyle.Strikeout;
            checkBoxFontStyleUnderline.Checked = (style.FontStyle & CSSFontStyle.Underline) == CSSFontStyle.Underline;

            EnumLocalizer.SelectItem(comboBoxFontSizeUnit, style.FontSizeUnit);
            numericUpDownFontSize.Value = (style.FontSize == 0) ? 12 : style.FontSize;
            EnumLocalizer.SelectItem(comboBoxHAlign, style.HorizontalAlign);
            EnumLocalizer.SelectItem(comboBoxVAlign, style.VerticalAlign);

            checkBoxBackColor.Checked  = style.BackgroundColor.Name != "Empty" && style.BackgroundColor.Name != "0";
            checkBoxFontFamily.Checked = style.FontFamily != null;
            checkBoxFontSize.Checked   = style.FontSize > 0;
            checkBoxForeColor.Checked  = style.ForeColor.Name != "Empty" && style.ForeColor.Name != "0";
            checkBoxHAlign.Checked     = style.HorizontalAlign != MLifter.DAL.Interfaces.HorizontalAlignment.None;
            checkBoxVAlign.Checked     = style.VerticalAlign != VerticalAlignment.None;

            foreach (KeyValuePair <string, string> pair in style.OtherElements)
            {
                XPTable.Models.Row row = new XPTable.Models.Row();
                tableOtherElements.TableModel.Rows.Add(row);
                row.Cells.Add(new XPTable.Models.Cell("x"));
                row.Cells.Add(new XPTable.Models.Cell(pair.Key));
                row.Cells.Add(new XPTable.Models.Cell(pair.Value));
            }

            AddEmtyRow();

            EnableControls();
            actualizing = false;
        }
示例#2
0
        /// <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();
            }
        }
示例#3
0
        /// <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();
        }
示例#4
0
        /// <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();
        }