/// <summary> /// Called when the drop occurs onto a page, performing sequence /// initialization. /// </summary> protected void OnPageDrop() { XmlNodeList sequenceElemts = (XmlNodeList)_attributes.SelectNodes("sequence[ @ref ]", FormsNamespace.NamespaceManager); if (sequenceElemts == null) { return; } StringBuilder sb = new StringBuilder("<properties>"); foreach (XmlNode sequenceElem in sequenceElemts) { string property = sequenceElem.Attributes["ref"].Value; string format = sequenceElem.Attributes["format"].Value; string pattern = string.Format(CultureInfo.InvariantCulture, "<{0}>{1}</{0}>", property, sequenceElem.Attributes["pattern"].Value); Regex regex = new Regex(pattern, RegexOptions.ExplicitCapture); int max = 0; foreach (Shape iterShape in _shape.ContainingPage.Shapes) { string shapeName = VisioUtils.GetProperty(iterShape, "User", "QuartzShape"); if (shapeName == null) { continue; } string shapeXml = VisioUtils.GetProperty(iterShape, "Prop", "ShapeXML"); Match m = regex.Match(shapeXml); if (m.Success == false) { continue; } int index = int.Parse(m.Groups["index"].Value, CultureInfo.InvariantCulture); if (index > max) { max = index; } } sb.AppendFormat("<{0}>", property); sb.AppendFormat(format, ++max); sb.AppendFormat("</{0}>", property); } sb.AppendFormat("</properties>"); VisioUtils.SetProperty(_shape, "Prop", "ShapeXML", sb.ToString()); }
/// <summary> /// Requests that the shape process the shape command. /// </summary> /// <param name="command">Command requested by the shape.</param> /// <param name="context">Execution context: these are the arguments specified in the event. Please /// note that the command is one of the arguments.</param> /// <param name="settings">Display settings.</param> /// <returns>New display settings.</returns> public DisplaySettings Execute(string command, NameValueCollection context, DisplaySettings settings, bool forceChange) { bool dropEvent = (string.IsNullOrEmpty(VisioUtils.GetProperty(_shape, "Prop", "ShapeXML"))); if (command == "drop" && !dropEvent) { return(settings); } /* * If the command was a "drop" (shape dragged from stencil into page) * then execute it right now. This must be done before the following * statement. */ if (command == "drop") { OnPageDrop(); } /* * */ string shapeXml = null; if (forceChange && VisioUtils.ShapeCustomProps != null) { shapeXml = VisioUtils.ShapeCustomProps; VisioUtils.SetProperty(VisioShape, "Prop", "ShapeXML", shapeXml); } else { shapeXml = VisioUtils.GetProperty(VisioShape, "Prop", "ShapeXML"); } Form.SetShapeXml(shapeXml); /* * Command router. */ switch (command) { case "drop": case "edit": return(OnShapeEdit(command, context, settings, forceChange)); default: return(OnExecuteCustom(command, context, settings)); } }
/// <summary> /// Edits the properties of the designated shape. /// </summary> /// <param name="command">Command requested by the shape.</param> /// <param name="context">Execution context: these are the arguments specified in the event. Please /// note that the command is one of the arguments.</param> /// <param name="settings">Display settings.</param> /// <returns>New display settings.</returns> protected DisplaySettings OnShapeEdit(string command, NameValueCollection context, DisplaySettings settings, bool forceChange) { if (settings == null) { throw new ArgumentNullException("settings"); } if (Form.PropertyCount == 0) { return(settings); } DisplaySettings ns = (DisplaySettings)settings.Clone(); Form.Left = settings.Left; Form.Top = settings.Top; Form.SelectedTabName = settings.TabName; if (!forceChange) { Form.ShowDialog(); } if (Form.DialogResult == DialogResult.OK || forceChange) { XmlDocument xml = Form.GetShapeXml(); string shapeText = GetShapeText(xml); #region Channel Text StringBuilder channelText = new StringBuilder(); foreach (XmlElement xe in xml.SelectNodes("properties/channels/channel")) { if (channelText.Length == 0) { channelText.Append("["); } else { channelText.Append(", "); } channelText.Append(xe.InnerText); } if (channelText.Length > 0) { channelText.Append(']'); } #endregion SetShapeText(shapeText, channelText.ToString()); VisioUtils.SetProperty(_shape, "Prop", "ShapeXML", xml.OuterXml); ns.TabName = Form.SelectedTabName; } else { if (command == "drop") { try { VisioShape.Delete(); } catch (Exception) { } } } ns.Left = Form.Left; ns.Top = Form.Top; return(ns); }
/// <summary> /// Sets the shape text on a Tab shape. /// </summary> /// <param name="text">Text to show.</param> protected override void SetShapeText(string text) { try { XmlNode labelSpanNode = null; string labelSpanValue = labelSpanDefault; int labelSpan; if (base.GetProperties() != null) { labelSpanNode = base.GetProperties().SelectSingleNode("//labelSpan"); if (labelSpanNode != null) { labelSpanValue = labelSpanNode.InnerText; } try { labelSpan = int.Parse(labelSpanValue); if (labelSpan < 1) { labelSpanValue = labelSpanDefault; } } catch (Exception) { labelSpanValue = labelSpanDefault; } } bool writeText = false; // BEGIN_HAMMER Control c = (Control)Form["columns"]; if (c == null) { c = (Control)Form["items"]; if (c != null) { writeText = true; } } if (c == null) { c = (Control)Form["tabs"]; } // END_HAMMER ListBox lb = (ListBox)c.Controls[5]; int count = lb.Items.Count; int index, min, max; // Mostra por defeito 3 elementos (para o caso de ser populado por uma lov) int cnt = lb.Items.Count; if (cnt == 0) { cnt = 3; } VisioUtils.SetProperty(VisioShape, "Prop", "ValidItems", lb.Items.Count.ToString()); min = count + 1; max = columnsXMax + 1; for (index = min; index < max; index++) { VisShape center = VisioShape.Shapes[index]; center.get_Cells("LockTextEdit").ResultIU = 0; center.Text = string.Empty; center.get_Cells("LockTextEdit").ResultIU = 1; } for (index = 1; index < min; index++) { VisShape center = VisioShape.Shapes[index]; center.get_Cells("LockTextEdit").ResultIU = 0; Object obj = lb.Items[index - 1]; center.Text = obj.ToString(); center.get_Cells("LockTextEdit").ResultIU = 1; } if (writeText) { for (int i = 1; i <= VisioShape.Shapes.Count; i++) { VisShape center = VisioShape.Shapes[i]; int isInput = VisioUtils.GetPropertyInt(center, "Prop", "Label"); if (isInput > 0) { if (labelSpanValue != null) { VisioUtils.SetProperty(center, "User", "LabelLen", labelSpanValue); } center.get_Cells("LockTextEdit").ResultIU = 0; center.Text = text; center.get_Cells("LockTextEdit").ResultIU = 1; i = VisioShape.Shapes.Count + 1; } } } } catch (FormatException) { ESIMessageBox.ShowError(Resources.GetString(ResourceTokens.ShapeTableColumns)); } }