private CustomViewRegistry() { _createCallback = new CreateControlDelegate(CreateControl); _getPropertyCallback = new GetPropertyDelegate(GetProperty); _setPropertyCallback = new SetPropertyDelegate(SetProperty); _constructorMap = new Dictionary <string, Func <CustomView> >(); _propertyRangeManager = new PropertyRangeManager(); }
public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber) { overRight = false; overDown = false; lineNumber = -1; colNumber = -1; return(null); }
public RawLayout(StructField[] fields, CreateControlDelegate createControlDelegate) { this.AutoScroll = true; this.FlowDirection = System.Windows.Forms.FlowDirection.TopDown; this.Dock = System.Windows.Forms.DockStyle.Fill; System.Xml.XmlDocument doc = new System.Xml.XmlDocument(); foreach (StructField item in fields) { System.Windows.Forms.Label lbl = new UI.LynnLabel(); lbl.Text = string.Format("{0} {1}", item.ID, item.Name); lbl.Width = 200; this.Controls.Add(lbl); System.Xml.XmlElement node = doc.CreateElement("Control"); node.SetAttribute("ID", item.ID); node.SetAttribute("Editor", EditorFactory.CreateFromDefaultValue(item.DefaultValue)); System.Windows.Forms.Control con = createControlDelegate(node); con.Width = 200; this.Controls.Add(con); } }
void OnHyperlinkClick(object sender, HyperlinkClickEventArgs e) { if (e.ModifierKeys != this.richEdit.Options.Hyperlinks.ModifierKeys) { return; } CreateControlDelegate createControl = null; if (!hyperlinkMappings.TryGetValue(e.Hyperlink.NavigateUri, out createControl)) { return; } if (this.activeWindow != null) { this.activeWindow.IsOpen = false; this.activeWindow = null; } PopupControlBase control = createControl(); control.Range = e.Hyperlink.Range; FloatingContainer container = FloatingContainerFactory.Create(FloatingMode.Window); control.OwnerWindow = container; container.Content = control; container.Owner = this.richEdit; container.Hidden += (obj, args) => { ((ILogicalOwner)this.richEdit).RemoveChild((FloatingContainer)obj); }; ((ILogicalOwner)this.richEdit).AddChild(container); container.SizeToContent = SizeToContent.WidthAndHeight; container.ContainerStartupLocation = WindowStartupLocation.Manual; container.FloatLocation = GetWindowLocation(); container.IsOpen = true; this.activeWindow = container; control.Focus(); e.Handled = true; }
public TableLayout(System.Xml.XmlNode param, CreateControlDelegate createControlDelegate) { this.Margin = new System.Windows.Forms.Padding(0); this.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None; this.Dock = System.Windows.Forms.DockStyle.Fill; this.RowCount = Int32.Parse(param.Attributes["RowCount"].Value); this.ColumnCount = Int32.Parse(param.Attributes["ColumnCount"].Value); this.AutoScroll = true; for (int i = 0; i < this.RowCount; i++) this.RowStyles.Add(new System.Windows.Forms.RowStyle()); for (int i = 0; i < this.ColumnCount; i++) this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); foreach (System.Xml.XmlNode item in param.ChildNodes) { if (item.Name != "TableCell") continue; int x, y; x = Int32.Parse(item.Attributes["X"].Value); y = Int32.Parse(item.Attributes["Y"].Value); if (item.Attributes["Width"] != null) { string str = item.Attributes["Width"].Value; if (str.Contains("/")) { float up = float.Parse(str.Substring(0, str.IndexOf('/'))); float down = float.Parse(str.Substring(str.IndexOf('/') + 1)); this.ColumnStyles[x - 1].SizeType = System.Windows.Forms.SizeType.Percent; this.ColumnStyles[x - 1].Width = up / down; } else { this.ColumnStyles[x - 1].SizeType = System.Windows.Forms.SizeType.Absolute; this.ColumnStyles[x - 1].Width = Int32.Parse(str); } } if (item.Attributes["Height"] != null) { string str = item.Attributes["Height"].Value; if (str.StartsWith("1/")) { this.RowStyles[y - 1].SizeType = System.Windows.Forms.SizeType.Percent; this.RowStyles[y - 1].Height = 1.0f / Int32.Parse(str.Substring(2)); } else { this.RowStyles[y - 1].SizeType = System.Windows.Forms.SizeType.Absolute; this.RowStyles[y - 1].Height = Int32.Parse(str); } } System.Windows.Forms.Control con = null; if (item.FirstChild is System.Xml.XmlText) { con = new UI.LynnLabel(); con.Text = item.FirstChild.Value; } else if (item.FirstChild.Name == "Control" || item.FirstChild.Name == "Layout") { con = createControlDelegate(item.FirstChild); } if (con != null) { //con.Margin = new System.Windows.Forms.Padding(5); con.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(con, x - 1, y - 1); if (item.Attributes["ColumnSpan"] != null) { this.SetColumnSpan(con, Int32.Parse(item.Attributes["ColumnSpan"].Value)); } if (item.Attributes["RowSpan"] != null) { this.SetRowSpan(con, Int32.Parse(item.Attributes["RowSpan"].Value)); } } } }
public abstract IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber);
public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber) { lineNumber = -1; colNumber = -1; overRight = false; overDown = false; RssScore genScore = score as RssScore; if (genScore == null) { return(null); } int maxX = startX + pnlWidth; int maxY = startY + pnlHeight; int posX = startX; int posY = startY; int maxColumnSize = pnlWidth / m_charWidth; // for all the rows IList <T> controls = new List <T>(); int totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER); foreach (string[] row_ in labels) { // ignore empty lines if (row_ == null || row_.Length == 0) { continue; } lineNumber++; // ignore lines on previous page if (lineNumber < startLine) { continue; } // ignore if outside and break to next row if (LimitToPage && posY > maxY) { overDown = true; break; } bool isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER); string[] row = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_; Style lineStyle = (lineNumber % 2 == 0) ? m_defaultStyle : m_altStyle; int nbLines = 1; for (int index = startColumn; index < row.Length; index++) { string cell = row[0]; // evaluate size of the control in pixel int maxChar = maxColumnSize; // count new lines int nb = Tools.CountLines(cell); nbLines = Math.Max(nbLines, nb); int length = m_charWidth * maxChar; int height = m_charHeight * nbLines; // create the control string[] aa = cell.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); T control = createControl(posX, posY, length, m_charHeight, ColumnDisplay.Alignment.Left, aa[0], m_fontName, m_fontSize, lineStyle, maxChar, 0); if (control != null) { controls.Add(control); } } // set Y pos to the bottom of the control posY += m_charHeight * nbLines; } Tools.LogMessage("{0} controls created", controls.Count); return(controls); }
public override IList <T> Build(BaseScore score, string[][] labels, int startLine, int startColumn, int startX, int startY, int pnlWidth, int pnlHeight, CreateControlDelegate <T> createControl, out bool overRight, out bool overDown, out int lineNumber, out int colNumber) { lineNumber = -1; colNumber = -1; overRight = false; overDown = false; //Tools.LogMessage("X = {0}, Y = {1}, W = {2}, H = {3}", startX, startY, pnlWidth, pnlHeight); GenericScore genScore = score as GenericScore; if (genScore == null) { return(null); } int maxX = startX + pnlWidth; int maxY = startY + pnlHeight; int posX = startX; int posY = startY; int maxColumnSize = pnlWidth / m_charWidth; // Get Columns Sizes ColumnDisplay[] cols = GetSizes(genScore, labels); RuleEvaluator engine = new RuleEvaluator(genScore.Rules); ParsingOptions opt = genScore.GetParseOption(); bool reverseOrder = Tools.CheckParsingOption(opt, ParsingOptions.Reverse); bool wordWrap = Tools.CheckParsingOption(opt, ParsingOptions.WordWrap); // for all the rows IList <T> controls = new List <T>(); int totalLines = labels.Count(p => p != null && p[0] != ScoreCenterPlugin.C_HEADER); foreach (string[] row_ in labels) { // ignore empty lines if (row_ == null || row_.Length == 0) { continue; } lineNumber++; // ignore lines on previous page if (lineNumber < startLine) { continue; } // calculate X position posX = startX;// -startColumn; // ignore if outside and break to next row if (LimitToPage && posY > maxY) { overDown = true; break; } bool isHeader = (row_[0] == ScoreCenterPlugin.C_HEADER); string[] row = isHeader ? row_.Where(c => c != ScoreCenterPlugin.C_HEADER).ToArray() : row_; #region Evaluate rule for full line //bool isHeader = !String.IsNullOrEmpty(this.Score.Headers) && lineNumber == 0; Style lineStyle = (lineNumber % 2 == 0) ? m_defaultStyle : m_altStyle; bool merge = false; if (!isHeader) { Rule rule = engine.CheckLine(row, lineNumber, totalLines); if (rule != null) { // skip lines and continue if (rule.Action == RuleAction.SkipLine) { continue; } merge = rule.Action == RuleAction.MergeCells; lineStyle = FindStyle(rule.Format) ?? lineStyle; } } #endregion #region For all columns int nbLines = 1; int nbControls = 0; for (int index = startColumn; index < row.Length; index++) { int colIndex = reverseOrder ? row.Length - index - 1 : index; // get cell string cell = row[colIndex]; ColumnDisplay colSize = GetColumnSize(colIndex, cols, cell, merge); if (colSize.Size == 0) { continue; } // ignore controls outside area if (LimitToPage && posX > maxX) { overRight = true; continue; } // evaluate size of the control in pixel int maxChar = Math.Min(colSize.Size + 1, maxColumnSize); // wrap needed? if (wordWrap || AutoWrap) { int i = maxChar + 1; while (i < cell.Length) { cell = cell.Insert(i, Environment.NewLine); i += maxChar + 1; } } // count new lines int nb = Tools.CountLines(cell); nbLines = Math.Max(nbLines, nb); int length = m_charWidth * maxChar; int height = m_charHeight * nbLines; if (posX < startX) { // cell was on previous page // increase posX so that we can get to current page posX += length; continue; } #region Evaluate rule for the cell Style cellStyle = lineStyle; if (!isHeader) { IList <Rule> cellRules = engine.CheckCell(cell, colIndex); foreach (var cellRule in cellRules) { cell = RuleProcessor.Process(cell, cellRule); if (cellRule != null && cellRule.Action == RuleAction.FormatCell) { cellStyle = FindStyle(cellRule.Format) ?? lineStyle; } } } #endregion // create the control string[] aa = cell.Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < aa.Length; i++) { T control = createControl(posX, posY + (i * m_charHeight), length, m_charHeight, colSize.Alignement, aa[i], m_fontName, m_fontSize, cellStyle, maxChar, colIndex); if (control != null) { controls.Add(control); nbControls++; } } // set X pos to the end of the control posX += Math.Min(length, pnlWidth - 1); } #endregion // set Y pos to the bottom of the control if (nbControls > 0 || isHeader) { posY += m_charHeight * nbLines; } } Tools.LogMessage("{0}: {1} controls created", score.Id, controls.Count); return(controls); }
public TableLayout(System.Xml.XmlNode param, CreateControlDelegate createControlDelegate) { this.Margin = new System.Windows.Forms.Padding(0); this.CellBorderStyle = System.Windows.Forms.TableLayoutPanelCellBorderStyle.None; this.Dock = System.Windows.Forms.DockStyle.Fill; this.RowCount = Int32.Parse(param.Attributes["RowCount"].Value); this.ColumnCount = Int32.Parse(param.Attributes["ColumnCount"].Value); this.AutoScroll = true; for (int i = 0; i < this.RowCount; i++) { this.RowStyles.Add(new System.Windows.Forms.RowStyle()); } for (int i = 0; i < this.ColumnCount; i++) { this.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); } foreach (System.Xml.XmlNode item in param.ChildNodes) { if (item.Name != "TableCell") { continue; } int x, y; x = Int32.Parse(item.Attributes["X"].Value); y = Int32.Parse(item.Attributes["Y"].Value); if (item.Attributes["Width"] != null) { string str = item.Attributes["Width"].Value; if (str.Contains("/")) { float up = float.Parse(str.Substring(0, str.IndexOf('/'))); float down = float.Parse(str.Substring(str.IndexOf('/') + 1)); this.ColumnStyles[x - 1].SizeType = System.Windows.Forms.SizeType.Percent; this.ColumnStyles[x - 1].Width = up / down; } else { this.ColumnStyles[x - 1].SizeType = System.Windows.Forms.SizeType.Absolute; this.ColumnStyles[x - 1].Width = Int32.Parse(str); } } if (item.Attributes["Height"] != null) { string str = item.Attributes["Height"].Value; if (str.StartsWith("1/")) { this.RowStyles[y - 1].SizeType = System.Windows.Forms.SizeType.Percent; this.RowStyles[y - 1].Height = 1.0f / Int32.Parse(str.Substring(2)); } else { this.RowStyles[y - 1].SizeType = System.Windows.Forms.SizeType.Absolute; this.RowStyles[y - 1].Height = Int32.Parse(str); } } System.Windows.Forms.Control con = null; if (item.FirstChild is System.Xml.XmlText) { con = new UI.LynnLabel(); con.Text = item.FirstChild.Value; } else if (item.FirstChild.Name == "Control" || item.FirstChild.Name == "Layout") { con = createControlDelegate(item.FirstChild); } if (con != null) { //con.Margin = new System.Windows.Forms.Padding(5); con.Dock = System.Windows.Forms.DockStyle.Fill; this.Controls.Add(con, x - 1, y - 1); if (item.Attributes["ColumnSpan"] != null) { this.SetColumnSpan(con, Int32.Parse(item.Attributes["ColumnSpan"].Value)); } if (item.Attributes["RowSpan"] != null) { this.SetRowSpan(con, Int32.Parse(item.Attributes["RowSpan"].Value)); } } } }