public SMRichText(SMControl parent) { Font = parent.Font; Paragraph = parent.Paragraph; Columns = -1; ColumnSeparatorWidth = 20; }
public void SetObject(SMControl obj) { Object = obj; textBox1.Text = obj.Text; textBox2.Text = obj.Tag; checkBox1.Checked = obj.Selectable; }
private void SenseTracking(bool endOfTracking) { SMControl prevTracked = null; foreach (SMControl sc in CurrentPage.Objects) { if (sc.UIStateHover) { prevTracked = sc; if (endOfTracking) { sc.UIStateHover = false; } break; } } if (MouseContext.endControl != prevTracked) { foreach (SMControl sc in CurrentPage.Objects) { sc.UIStateHover = false; } if (!endOfTracking && MouseContext.endControl != null) { MouseContext.endControl.OnDragHotTrackStarted(MouseContext.draggedItem, MouseContext); } if (prevTracked != null) { prevTracked.OnDragHotTrackEnded(MouseContext.draggedItem, MouseContext); } } }
public void InitiateReplacementMove(SMControl target, SMWordBase replaced) { if (target == null) { return; } if (target is SMTextViewBase) { SMTextViewBase tvb = (SMTextViewBase)target; StringBuilder sb = new StringBuilder(); foreach (SMWordBase wb in this.drawWords) { if (wb is SMWordText) { if (wb == replaced) { sb.AppendFormat("<edit text=\"{0}\" tag=\"\">", (wb as SMWordText).text); } else { sb.Append((wb as SMWordText).text); } } } tvb.Text = sb.ToString(); tvb.TextDidChange(); } }
private void InitWithPage(MNPage p) { tabControl1.SelectedTab = tabPage; if (p_Book.Pages.ContainsKey(p.Id)) { p_Page = p_Book.Pages[p.Id]; } else { p_Page = new ReviewPage(); p_Book.Pages[p.Id] = p_Page; p_Page.PageTitle = p.TextBRaw; p_Page.PageHelp = p.MessageTextRaw; } richTextBox1.Text = p_Page.PageTitle; richTextBox2.Text = p_Page.PageHelp; richTextBox3.Text = p_Page.PageNotes; textItemText.Text = ""; textItemNotes.Text = ""; p_PageOrig = p; p_ItemOrig = null; UpdatePageHelpColor(); UpdatePageTitleColor(); }
public override void OnClick(PVDragContext dc) { foreach (SMKeyboardKey key in Keys) { if (key.PaintedRect.Contains(dc.lastPoint)) { if (key.Pressed) { // send message about KeyChar pressed SMControl targetControl = Page.FindObjectWithAPIName(TargetControl); if (targetControl != null) { if (key.Key.Equals("#back")) { targetControl.ExecuteMessage("acceptBack"); } else if (key.Key.Equals("#enter")) { targetControl.ExecuteMessage("acceptEnter"); } else { targetControl.ExecuteMessage("acceptString", new GSString(key.Key)); } } } } key.Pressed = false; } base.OnClick(dc); }
public void OnTapEnd(SMControl control, PVDragContext context) { if (Document != null) { scheduledScripts.Clear(); ExtractControlConnections(control, scheduledScripts, "OnTapEnd"); ExecuteScheduledObjects(control); } }
public void OnDragMove(SMControl control, SMTokenItem token, PVDragContext context) { if (Document != null) { scheduledScripts.Clear(); ExtractControlConnections(control, scheduledScripts, "OnDragMove"); ExecuteScheduledObjects(control); } }
public bool ContainsControl(SMControl control) { SMRectangleArea cga = Area; SMRectangleArea ca = control.Area; bool pr = cga.RelativeArea.Contains(ca.RelativeArea); return(pr ? ControlIsCompatible(control) : false); }
public bool OnDropWillFinish(SMControl control, PVDragContext context) { if (Document != null) { scheduledScripts.Clear(); ExtractControlConnections(control, scheduledScripts, "OnDropWillFinish"); ExecuteScheduledObjects(control); } return(true); }
private void UpdateHelpText(string text) { if (p_focusX >= 0 && p_focusX < p_xmax && p_focusY >= 0 && p_focusY < p_ymax) { SMControl c = Page.FindObjectWithAPIName(this.HelpTextControlName); if (c != null) { c.ExecuteMessage("setText", new GSString(text ?? p_array[p_focusX, p_focusY, 2])); } } }
private void ExtractControlConnections(SMControl control, List <string> scheduled, string name) { if (control != null) { MNReferencedText rt = control.FindScript(name); if (rt != null) { scheduled.Add(rt.Text); } } }
public void OnClick(SMControl control, PVDragContext context) { if (Document != null) { scheduledScripts.Clear(); if (control.ScriptOnClick.Length > 0) { scheduledScripts.Add(control.ScriptOnClick); } ExecuteScheduledObjects(control); } }
private static void AppendWord(List <SMWordBase> list, string text, SMControl control, RunningFormat fmt) { // TODO SMWordText wt = new SMWordText(control.Font); wt.text = text; wt.tag = text.Trim(); wt.Draggable = fmt.dragResponse; wt.Evaluation = MNEvaluationType.None; wt.Font = fmt.GetFont(); wt.replacementTarget = fmt.selectForReplacementTarget; list.Add(wt); }
// control events public void OnDragFinished(SMControl control, SMTokenItem token, PVDragContext context) { // find all connections of type "partOfGroup" where target is control // and notify parent group that this event has occured // find all activities in graph that are target conected to this control as source and have // name of connection as this event // and execute them and then execute their successors if (Document != null) { scheduledScripts.Clear(); ExtractControlConnections(control, scheduledScripts, "OnDragFinished"); ExecuteScheduledObjects(control); } }
private void StartDocumentReview(MNDocument doc, string filePath) { Document = doc; ClearUI(); labelBookTitle.Text = Document.Book.BookTitle; tabControl1.SelectedTab = tabBook; LoadData(filePath.Replace(".smb", ".smr")); p_PageOrig = null; p_ItemOrig = null; p_Page = new ReviewPage(); p_Item = new ReviewItem(); }
public bool ControlIsCompatible(SMControl control) { switch (GroupType) { case SMGroupListLabelsType.Images: return(control is SMImage); case SMGroupListLabelsType.Labels: return(control is SMLabel); case SMGroupListLabelsType.CheckBoxes: return(control is SMCheckBox); default: return(false); } }
private void StartDocumentReview(MNDocument doc, string filePath) { Document = doc; doc.Reviews = p_Book; ClearUI(); labelBookTitle.Text = Document.Book.BookTitle; tabControl1.SelectedTab = tabBook; string folder = Properties.Settings.Default.ReviewsDirectory; if (Directory.Exists(folder)) { string path = Path.Combine(folder, Path.GetFileNameWithoutExtension(Document.Book.FilePath) + ".smr"); LoadData(path); } p_PageOrig = null; p_ItemOrig = null; p_Page = new ReviewPage(); p_Item = new ReviewItem(); }
private void SetItem(SMControl sControl) { if (p_Page.Items.ContainsKey(sControl.Id)) { p_Item = p_Page.Items[sControl.Id]; } else { p_Item = new ReviewItem(); p_Page.Items[sControl.Id] = p_Item; p_Item.ItemText = sControl.TextRaw; p_Item.ItemNotes = ""; } tabControl1.SelectedTab = tabItem; labelControlId.Text = sControl.Id.ToString(); textItemText.Text = p_Item.ItemText; textItemNotes.Text = p_Item.ItemNotes; p_ItemOrig = sControl; UpdateItemTextColor(); }
public SMControl FindControl(int controlId) { SMControl ctrl = null; foreach (MNPage page in Data.Pages) { ctrl = page.FindObject(controlId); if (ctrl != null) { return(ctrl); } } foreach (MNPage page in Data.Templates) { ctrl = page.FindObject(controlId); if (ctrl != null) { return(ctrl); } } return(null); }
public void WriteControl(StringBuilder S, SMControl C, int L) { WriteLS(S, L); S.AppendFormat("OBJECT: {0}\n", C.Id); }
private void InitWithPage(MNPage p) { tabControl1.SelectedTab = tabPage; StringBuilder sb = new StringBuilder(); sb.Append("<html><head></head><body style='font-family:Helvetica'>"); if (p_Book.Pages.ContainsKey(p.Id)) { p_Page = p_Book.Pages[p.Id]; } else { webBrowser1.DocumentText = ""; return; } if (!p.TextB.Equals(p_Page.PageTitle)) { sb.AppendFormat("<p><b>Page Title</b><br>{0}</p>", p_Page.PageTitle); } if (!p.MessageText.Equals(p_Page.PageHelp)) { sb.AppendFormat("<p><b>Page Help</b><br>{0}</p>", p_Page.PageHelp); } if (!string.IsNullOrWhiteSpace(p_Page.PageNotes)) { sb.AppendFormat("<p><b>Page Help</b><br>{0}</p>", p_Page.PageNotes); } bool header = false; foreach (KeyValuePair <long, ReviewItem> revi in p_Page.Items) { if (!header) { sb.AppendFormat("<h3 style='background:#efa0ef'>Items</h3>"); header = true; } sb.AppendLine("<table style='border:1px solid black;'>"); sb.AppendFormat("<tr><td>ID</td><td>{0}</td></tr>", revi.Key); SMControl itor = p_PageOrig.FindObject(revi.Key); if (itor != null && !itor.Text.Equals(p_Item.ItemText)) { sb.AppendFormat("<tr><td>New Text</td><td>{0}</td></tr>", revi.Value.ItemText); sb.AppendFormat("<tr><td>Orig Text</td><td>{0}</td></tr>", itor.Text); } else if (itor != null) { sb.AppendFormat("<tr><td>Text</td><td>{0}</td></tr>", revi.Value.ItemText); } if (!string.IsNullOrWhiteSpace(revi.Value.ItemNotes)) { sb.AppendFormat("<tr><td>Notes</td><td>{0}</td></tr>", revi.Value.ItemNotes); } sb.AppendLine("</table>"); } sb.Append("</body></html>"); p_PageOrig = p; p_ItemOrig = null; webBrowser1.DocumentText = sb.ToString(); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="textBounds"></param> /// <param name="drawWords"></param> /// <param name="control"></param> /// <param name="RunningLine"></param> /// <param name="Columns">Value -1 means, that no paging is done, normaly columns are 1,2,3...</param> /// <param name="ColumnSeparatorWidth"></param> /// <param name="PageCount"></param> /// <returns></returns> public static SMRichLayout RecalculateWordsLayout(MNPageContext context, Rectangle textBounds, List <SMWordBase> drawWords, SMControl control, SMRunningLine RunningLine, int Columns) { textBounds.X = 0; textBounds.Y = 0; float lineY = textBounds.Y; float lineX = textBounds.X; float lineEnd = textBounds.Right; float lineHeight = 0f; float lineWidth = textBounds.Width; float columnWidth = textBounds.Width; int lineNo = 0; int columnNo = 0; int pageNo = 0; int rightX = textBounds.X; bool writeLineNo = false; bool isNewLine = false; bool isNewColumn = false; SMWordLine currLine = new SMWordLine(); SMRichLayout richLayout = new SMRichLayout(); richLayout.Lines = new List <SMWordLine>(); richLayout.Lines.Add(currLine); richLayout.DropablesCount = 0; //context.g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias; if (Columns > 1) { columnWidth = textBounds.Width / Columns; lineWidth = textBounds.Width / Columns - control.ContentPadding.Left - control.ContentPadding.Right; lineX = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left; lineEnd = lineX + lineWidth; } else { columnWidth = textBounds.Width; lineWidth = textBounds.Width - control.ContentPadding.Left - control.ContentPadding.Right; lineX = textBounds.X + control.ContentPadding.Left; lineEnd = lineX + lineWidth; } float bottom = textBounds.Bottom; bool isSpaceText = false; int startsWithParentheses = 0; bool isNewPage = false; // first placement of word tokens foreach (SMWordBase wt in drawWords) { isSpaceText = false; writeLineNo = true; isNewLine = false; isNewColumn = false; isNewPage = false; startsWithParentheses = 0; if (wt is SMWordSpecial) { SMWordSpecial spwt = (SMWordSpecial)wt; if (spwt.Type == SMWordSpecialType.Newline) { isNewLine = true; writeLineNo = false; } else if (spwt.Type == SMWordSpecialType.NewColumn) { isNewLine = false; writeLineNo = false; isNewColumn = true; } else if (spwt.Type == SMWordSpecialType.HorizontalLine) { wt.rect.Width = lineEnd - lineX - 1; wt.rect.Height = 20; } else if (spwt.Type == SMWordSpecialType.NewPage) { isNewPage = true; writeLineNo = false; } } else if (wt is SMWordToken) { SMWordToken wtk = (SMWordToken)wt; if (wtk.Cardinality == SMConnectionCardinality.One || wtk.Editable) { richLayout.DropablesCount++; } string s = wtk.GetCurrentText(); wt.rect.Size = context.g.MeasureString(s, wtk.Font.Font, textBounds.Width, StringFormat.GenericTypographic); } else if (wt is SMWordText) { SMWordText wtt = wt as SMWordText; if (wtt.Draggable != SMDragResponse.None && control.Draggable != wtt.Draggable) { control.Draggable = wtt.Draggable; } if (wtt.text.StartsWith("\"") || wtt.text.StartsWith("\u201c")) { SizeF sf = context.g.MeasureString("\u201c", wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic); startsWithParentheses = (int)sf.Width; } if (wtt.text.Equals(" ")) { wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font); isSpaceText = true; } else { wtt.rect.Size = context.g.MeasureString(wtt.text, wtt.Font.Font, textBounds.Width, StringFormat.GenericTypographic); } } else if (wt is SMWordImage) { SMWordImage wti = wt as SMWordImage; wti.rect.Size = wti.imageSize; } if (writeLineNo && !control.Autosize) { if ((lineX + wt.rect.Width > lineEnd) || RunningLine == SMRunningLine.SingleWord) { if (currLine.Count > 0) { isNewLine = true; } } } if (isNewLine) { if (currLine.Count == 0) { lineY += lineHeight * control.Paragraph.LineSpacing / 2; } else { lineY += lineHeight * control.Paragraph.LineSpacing; } currLine = new SMWordLine(); richLayout.Lines.Add(currLine); lineHeight = context.g.MeasureString("M", control.GetUsedFont()).Height / 2; lineNo++; if (Columns != -1 && !control.Autosize) { if (lineY + lineHeight > textBounds.Bottom) { isNewColumn = true; } } } if (isNewPage) { lineNo = 0; columnNo = 0; pageNo++; lineY = textBounds.Top; } if (isNewColumn) { columnNo++; lineNo = 0; if (columnNo >= Columns) { pageNo++; columnNo = 0; } lineY = textBounds.Top; } if (isNewLine || isNewColumn || isNewPage) { lineX = textBounds.X + columnNo * columnWidth + control.ContentPadding.Left; lineEnd = lineX + lineWidth; } if (writeLineNo) { if (currLine.Count == 0 && startsWithParentheses > 0) { wt.rect.X -= startsWithParentheses; lineX -= startsWithParentheses; } if (currLine.Count > 0 || !isSpaceText) { currLine.Add(wt); wt.LineNo = lineNo; wt.ColumnNo = columnNo; wt.PageNo = pageNo; wt.rect.Location = new PointF(lineX, lineY); lineX += wt.rect.Width; rightX = Math.Max(rightX, (int)lineX); } lineHeight = Math.Max(lineHeight, wt.rect.Height); writeLineNo = false; } } lineY += lineHeight * control.Paragraph.LineSpacing; // vertical alignment AdjustVerticaly(textBounds, richLayout.Lines, control.GetVerticalAlign()); // horizontal aligment AdjustLinesHorizontaly((int)lineWidth, control.GetHorizontalAlign(), richLayout.Lines); richLayout.Pages = pageNo + 1; richLayout.bottomY = (int)lineY + 1; richLayout.rightX = rightX + 1; return(richLayout); }
/// <summary> /// Pointer started /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PageView_MouseDown(object sender, MouseEventArgs e) { if (CurrentPage == null || MouseContext.State == PVDragContext.Status.RefusingDrop) { return; } if (e.Button == System.Windows.Forms.MouseButtons.Left) { ReviewFrame.Shared.SetPageTab(); if (!TemporaryMessageBoxVisible) { Context.hitHeaderButton = TestHitHeaderButton(Context.PhysicalToLogical(new Point(e.X, e.Y))); } if (TemporaryMessageBoxVisible) { } else if (p_displayedMenu != null) { MouseContext.lastPoint = Context.PhysicalToLogical(new Point(e.X, e.Y)); MouseContext.startPoint = MouseContext.lastPoint; MouseContext.startControl = null; MouseContext.endControl = null; MouseContext.State = PVDragContext.Status.ClickDown; MouseContext.DragType = SMDragResponse.None; MouseContext.context = Context; MouseContext.StartClicked = true; Context.selectedMenuItem = p_displayedMenu.TestHit(MouseContext); } else if (Context.hitHeaderButton > 0) { } else if (p_displayedMenu == null) { MouseContext.lastPoint = Context.PhysicalToLogical(new Point(e.X, e.Y)); MouseContext.startPoint = MouseContext.lastPoint; MouseContext.startControl = CurrentPage.FindObjectContainingPoint(Context, MouseContext.lastPoint); MouseContext.endControl = null; MouseContext.State = PVDragContext.Status.ClickDown; MouseContext.DragType = SMDragResponse.None; MouseContext.context = Context; if (MouseContext.startControl != null) { MouseContext.startControl.OnTapBegin(MouseContext); } MouseContext.StartClicked = true; timerLongClick.Start(); } Invalidate(); } else if (e.Button == System.Windows.Forms.MouseButtons.Right) { Point p = Context.PhysicalToLogical(new Point(e.X, e.Y)); SMControl sControl = CurrentPage.FindObjectContainingPoint(Context, p); if (sControl != null) { MNNotificationCenter.BroadcastMessage(this, "ObjectForReview", sControl); } } }
public void SetObject(SMControl obj) { Object = (SMOrderedList)obj; }
public void SetObject(SMControl obj) { Object = obj; textBox1.Name = Object.StyleName; }
public override void Paint(MNPageContext context) { Graphics g = context.g; SMImageButton pi = this; Rectangle rect = Area.GetBounds(context); SMStatusLayout layout = PrepareBrushesAndPens(); DrawStyledBackground(context, layout, rect); DrawStyledBorder(context, layout, rect); Rectangle bounds = ContentPadding.ApplyPadding(rect); Rectangle imageBounds = Rectangle.Empty; Rectangle textBounds = Rectangle.Empty; SMContentArangement argm = this.ContentArangement; SMContentScaling ContentScaling = SMContentScaling.Fit; Image image = GetContentImage(); if (image == null) { argm = SMContentArangement.TextOnly; } if (argm == SMContentArangement.ImageOnly) { SMContentScaling scaling = ContentScaling; Rectangle rc = DrawImage(context, null, bounds, image, scaling, 0, 0); showRect = rc; } else { Rectangle imgRect = bounds; Size textSize = Size.Empty; Font usedFont = GetUsedFont(); string plainText = Text; if (plainText.Length != 0) { textSize = rt.MeasureString(context, plainText, bounds.Width); } Rectangle textRect = bounds; if (argm == SMContentArangement.ImageAbove) { textRect.Height = textSize.Height; textRect.Y = bounds.Bottom - textRect.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Top; } else if (argm == SMContentArangement.ImageBelow) { textRect.Height = textSize.Height; textRect.X = (textRect.Left + textRect.Right) / 2 - textSize.Width / 2; textRect.Width = textSize.Width; imgRect.Y = textRect.Bottom + ContentPadding.Bottom; imgRect.Height = bounds.Height - textRect.Height - ContentPadding.Bottom; } else if (argm == SMContentArangement.ImageOnLeft) { imgRect.Size = SMControl.GetImageDrawSize(bounds, image); if (bounds.Width - imgRect.Width < textSize.Width + ContentPadding.LeftRight) { imgRect.Width = bounds.Width - textSize.Width - ContentPadding.LeftRight; imgRect.Size = SMControl.GetImageDrawSize(imgRect, image); } textRect.Width = bounds.Width - imgRect.Width - ContentPadding.LeftRight; textRect.X = bounds.Right - textRect.Width; imgRect.Y = (bounds.Top + bounds.Bottom) / 2 - imgRect.Height / 2; } else if (argm == SMContentArangement.ImageOnRight) { imgRect.Size = SMControl.GetImageDrawSize(bounds, image); if (bounds.Width - imgRect.Width < textSize.Width + ContentPadding.LeftRight) { imgRect.Width = bounds.Width - textSize.Width - ContentPadding.LeftRight; imgRect.Size = SMControl.GetImageDrawSize(imgRect, image); } textRect.Width = bounds.Width - imgRect.Width - ContentPadding.LeftRight; imgRect.X = textRect.Right + ContentPadding.Right; } else if (argm == SMContentArangement.ImageOnly) { textRect = Rectangle.Empty; } else if (argm == SMContentArangement.TextOnly) { imgRect = Rectangle.Empty; } if (!imgRect.IsEmpty) { Rectangle rc = DrawImage(context, null, imgRect, image, ContentScaling, 0, 0); showRect = rc; } if (!textRect.IsEmpty) { textRect.Inflate(1, 1); rt.DrawString(context, layout, plainText, textRect); } } base.Paint(context); }
/// <summary> /// Text is normal text and contains words, spaces and tags /// tags are like HTML tags /// examples are given bellow /// </summary> /// <param name="text"></param> /// <returns></returns> // examples of tags: // <tag> // <tag attr1=val1> // <tag attr2="val1" attr3='val3' attr4=val5> public static List <SMWordBase> WordListFromString(string text, SMControl control) { List <SMWordBase> list = new List <SMWordBase>(); TextParseMode mode = TextParseMode.General; StringBuilder word = new StringBuilder(); StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); TextTag tt = new TextTag(); RunningFormat fmt = new RunningFormat(); string argumentName = ""; fmt.SetFontStyle(control.Font.Style); fmt.fontSize = control.Font.Size; fmt.fontName = control.Font.Name; fmt.defaultFontSize = fmt.fontSize; foreach (char readedChar in text) { if (mode == TextParseMode.General) { if (readedChar == '&') { mode = TextParseMode.SpecChar; sb.Clear(); continue; } else if (readedChar == '<') { mode = TextParseMode.WaitForTagNameStart; sb.Clear(); continue; } else if (Char.IsWhiteSpace(readedChar)) { ClearWordBuffer(list, word, control, fmt); if (readedChar == '\n') { list.Add(new SMWordSpecial(control.Font) { Type = SMWordSpecialType.Newline }); } else { AppendWord(list, " ", control, fmt); } } else { word.Append(readedChar); } } else if (mode == TextParseMode.SpecChar) { if (readedChar == ';') { word.Append(GetCharFromCode(sb.ToString())); mode = TextParseMode.General; } else { sb.Append(readedChar); } } else if (mode == TextParseMode.WaitForTagNameStart) { if (readedChar == '>') { mode = TextParseMode.General; } else if (!Char.IsWhiteSpace(readedChar)) { sb.Append(readedChar); mode = TextParseMode.ReadTagName; } } else if (mode == TextParseMode.ReadTagName) { if (Char.IsWhiteSpace(readedChar)) { tt.tag = sb.ToString(); sb.Clear(); mode = TextParseMode.WaitForArgOrEnd; } else if (readedChar == '>') { tt.tag = sb.ToString(); mode = TextParseMode.General; AppendTag(list, word, tt, control, fmt); tt.Clear(); } else { sb.Append(readedChar); } } else if (mode == TextParseMode.WaitForArgOrEnd) { if (readedChar == '>') { mode = TextParseMode.General; AppendTag(list, word, tt, control, fmt); tt.Clear(); } else if (Char.IsWhiteSpace(readedChar)) { } else { sb.Clear(); sb.Append(readedChar); mode = TextParseMode.ReadArgName; } } else if (mode == TextParseMode.ReadArgName) { if (readedChar == '>') { mode = TextParseMode.General; if (sb.Length > 0) { tt.attrs.Add(sb.ToString(), string.Empty); AppendTag(list, word, tt, control, fmt); tt.Clear(); } } else if (readedChar == '=') { argumentName = sb.ToString(); sb.Clear(); mode = TextParseMode.WaitForArgValue; } else if (Char.IsWhiteSpace(readedChar)) { argumentName = sb.ToString(); sb.Clear(); mode = TextParseMode.WaitForAssignOrEnd; } else { sb.Append(readedChar); } } else if (mode == TextParseMode.WaitForAssignOrEnd) { if (readedChar == '=') { mode = TextParseMode.WaitForArgValue; } else if (readedChar == '>') { mode = TextParseMode.General; if (argumentName.Length > 0) { tt.attrs.Add(argumentName, string.Empty); AppendTag(list, word, tt, control, fmt); tt.Clear(); } } else if (!Char.IsWhiteSpace(readedChar)) { mode = TextParseMode.ReadArgName; if (argumentName.Length > 0 && !tt.attrs.ContainsKey(argumentName)) { tt.attrs.Add(argumentName, string.Empty); } sb.Clear(); sb.Append(readedChar); } } else if (mode == TextParseMode.WaitForArgValue) { if (readedChar == '>') { mode = TextParseMode.General; if (argumentName.Length > 0) { tt.attrs.Add(argumentName, string.Empty); AppendTag(list, word, tt, control, fmt); tt.Clear(); } } else if (readedChar == '\"') { sb.Clear(); mode = TextParseMode.ReadArgValueString; } else if (readedChar == '\'') { sb.Clear(); mode = TextParseMode.ReadArgValueQuote; } else if (!Char.IsWhiteSpace(readedChar)) { sb.Clear(); sb.Append(readedChar); mode = TextParseMode.ReadArgValue; } } else if (mode == TextParseMode.ReadArgValue) { if (readedChar == '>') { mode = TextParseMode.General; if (argumentName.Length > 0) { tt.attrs.Add(argumentName, sb.ToString()); AppendTag(list, word, tt, control, fmt); tt.Clear(); } } else if (readedChar == '&') { sb2.Clear(); mode = TextParseMode.ReadArgValueSpecChar; } else if (Char.IsWhiteSpace(readedChar)) { mode = TextParseMode.WaitForArgOrEnd; if (argumentName.Length > 0) { tt.attrs[argumentName] = sb.ToString(); sb.Clear(); argumentName = ""; } } else { sb.Append(readedChar); } } else if (mode == TextParseMode.ReadArgValueSpecChar) { if (readedChar == ';') { sb.Append(GetCharFromCode(sb2.ToString())); mode = TextParseMode.ReadArgValue; } else { sb2.Append(readedChar); } } else if (mode == TextParseMode.ReadArgValueString) { if (readedChar == '&') { sb2.Clear(); mode = TextParseMode.ReadArgValueStringSpecChar; } else if (readedChar == '\"') { mode = TextParseMode.WaitForArgOrEnd; if (argumentName.Length > 0) { tt.attrs.Add(argumentName, sb.ToString()); sb.Clear(); argumentName = ""; } } else { sb.Append(readedChar); } } else if (mode == TextParseMode.ReadArgValueStringSpecChar) { if (readedChar == ';') { sb.Append(GetCharFromCode(sb2.ToString())); mode = TextParseMode.ReadArgValueString; } else { sb2.Append(readedChar); } } else if (mode == TextParseMode.ReadArgValueQuote) { if (readedChar == '&') { sb2.Clear(); mode = TextParseMode.ReadArgValueQuoteSpecChar; } else if (readedChar == '\"') { mode = TextParseMode.WaitForArgOrEnd; if (argumentName.Length > 0) { tt.attrs.Add(argumentName, sb.ToString()); sb.Clear(); argumentName = ""; } } else { sb.Append(readedChar); } } else if (mode == TextParseMode.ReadArgValueQuoteSpecChar) { if (readedChar == ';') { sb.Append(GetCharFromCode(sb2.ToString())); mode = TextParseMode.ReadArgValueQuote; } else { sb2.Append(readedChar); } } } // finalization if (word.Length > 0) { AppendWord(list, word.ToString(), control, fmt); word.Clear(); } // set first editable as focused foreach (SMWordBase wb in list) { if (wb is SMWordToken) { SMWordToken wt = (SMWordToken)wb; if (wt.Editable) { wt.Focused = true; break; } } } return(list); }
private static void AppendTag(List <SMWordBase> list, StringBuilder word, TextTag tt, SMControl control, RunningFormat fmt) { // TODO ClearWordBuffer(list, word, control, fmt); switch (tt.tag) { case "draggable": fmt.dragResponse = SMDragResponse.Drag; break; case "/draggable": fmt.dragResponse = SMDragResponse.None; break; case "drop": { SMWordToken wt = new SMWordToken(control.Font); wt.text = tt.attrs.ContainsKey("text") ? tt.attrs["text"] : "_____"; wt.tag = tt.attrs.ContainsKey("tag") ? tt.attrs["tag"] : ""; wt.Draggable = SMDragResponse.None; wt.Cardinality = SMConnectionCardinality.One; wt.Evaluation = control.HasLazyEvaluation ? MNEvaluationType.Lazy : MNEvaluationType.Immediate; list.Add(wt); } break; case "edit": { SMWordToken wt = new SMWordToken(control.Font); wt.text = tt.attrs.ContainsKey("text") ? tt.attrs["text"] : "_____"; wt.tag = tt.attrs.ContainsKey("tag") ? tt.attrs["tag"] : ""; wt.Draggable = SMDragResponse.None; wt.Editable = true; wt.Cardinality = SMConnectionCardinality.One; wt.Evaluation = control.HasLazyEvaluation ? MNEvaluationType.Lazy : MNEvaluationType.Immediate; list.Add(wt); } break; case "seltorepl": fmt.selectForReplacementTarget = tt.attrs.ContainsKey("target") ? tt.attrs["target"] : null; break; case "/seltorepl": fmt.selectForReplacementTarget = null; break; case "page": list.Add(new SMWordSpecial(control.Font) { Type = SMWordSpecialType.NewPage }); break; case "hr": list.Add(new SMWordSpecial(control.Font) { Type = SMWordSpecialType.HorizontalLine }); break; case "br": list.Add(new SMWordSpecial(control.Font) { Type = SMWordSpecialType.Newline }); AppendWord(list, "\n", control, fmt); break; case "col": list.Add(new SMWordSpecial(control.Font) { Type = SMWordSpecialType.NewColumn }); //AppendWord(list, "\n", control, fmt); break; case "r": fmt.Bold = false; fmt.Italic = false; fmt.Strikeout = false; fmt.Underline = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "/r": ClearWordBuffer(list, word, control, fmt); fmt.Bold = control.Font.Bold; fmt.Italic = control.Font.Italic; fmt.Underline = control.Font.Underline; fmt.Strikeout = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "b": ClearWordBuffer(list, word, control, fmt); fmt.Bold = true; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "/b": ClearWordBuffer(list, word, control, fmt); fmt.Bold = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "i": ClearWordBuffer(list, word, control, fmt); fmt.Italic = true; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "/i": ClearWordBuffer(list, word, control, fmt); fmt.Italic = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "u": ClearWordBuffer(list, word, control, fmt); fmt.Underline = true; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "/u": ClearWordBuffer(list, word, control, fmt); fmt.Underline = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "so": ClearWordBuffer(list, word, control, fmt); fmt.Strikeout = true; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; case "/so": ClearWordBuffer(list, word, control, fmt); fmt.Strikeout = false; //fmt.fontStyleValid = (fmt.fontStyle != control.Style.Font.Style); break; default: ClearWordBuffer(list, word, control, fmt); if (tt.tag.StartsWith("fs")) { int arg = 0; if (int.TryParse(tt.tag.Substring(2), out arg)) { fmt.fontSize = (float)arg / 100 * fmt.defaultFontSize; } } break; } }
private static void ClearWordBuffer(List <SMWordBase> list, StringBuilder word, SMControl control, RunningFormat fmt) { if (word.Length > 0) { AppendWord(list, word.ToString(), control, fmt); word.Clear(); } }