Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using InstructionElementsClass;
- using System;
- using System.Collections;
- using System.Diagnostics;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using System.Xml;
- namespace LadderView
- {
- public class CLadderView : Control
- {
- private static int viewID = 0;
- private static bool compareSynro;
- private bool printing;
- private Rectangle page1PrintRect;
- private Rectangle page2PrintRect;
- private int currentPage = -1;
- private Graphics printerGraphics;
- private CLadderView.PrintPageInfo[] printPages;
- private bool isCompareView;
- private bool printDiffRungsOnly;
- private LadderRoutine m_pRoutine;
- private ProgramClass m_pProgram;
- private ProgramHolder m_pProgholder;
- private Controller m_Controller;
- private SetHorizScrollbarPos _SetHorizScrollbarPos;
- private SetVertScrollbarPos _SetVertScrollbarPos;
- private SetHorizScrollbarRange _SetHorizScrollbarRange;
- private SetVertScrollbarRange _SetVertScrollbarRange;
- private ViewPropertiesSetup _ViewPropertiesSetup;
- private ArrayList m_AddrTagsForUpdating;
- private ArrayList m_Rungs;
- private CVRungdef m_pFirstViewRung;
- private CVRungdef m_pCurrentTopViewRung;
- private CVRungdef m_pCursorRung;
- private IRungViewElement m_pCursorElement;
- private bool m_bHaveFocus;
- private CVRungdef m_pSelectedRung;
- private IRungViewElement m_pAnchorElem;
- private CVRungdef m_pAnchorRung;
- private ArrayList m_SelectedList;
- private CViewOptionsdef m_Options;
- private int m_nScrollWidth;
- private int m_nLadderWindowLeft;
- private int m_nLadderWindowTop;
- private int m_nTopRungOffset;
- private int m_nWidth;
- private int m_nLeftMouseButUpActionToDo;
- private CLadderView m_MatchingView;
- private int id;
- private Point m_DragStartPoint = Point.Empty;
- private MenuItem menuItem1;
- private MenuItem menuItem2;
- private MenuItem menuItem3;
- private MenuItem menuItem4;
- private ContextMenu contextMainMenu;
- private LadderViewEditClass mTheEditor;
- public event RoutineChangedCb RoutineChangedHook;
- public CLadderView MatchingView
- {
- get => this.m_MatchingView;
- set
- {
- this.m_MatchingView = value;
- if (this.m_MatchingView == null)
- return;
- for (int index = 0; index < this.m_pRoutine.GetRungCount(); ++index)
- {
- CRung rungAt = this.m_pRoutine.GetRungAt(index);
- if (rungAt != null)
- rungAt.MatchingRoutine = this.m_MatchingView.LadderRoutine;
- }
- for (int index = 0; index < this.m_Rungs.Count; ++index)
- {
- CVRungdef rung = (CVRungdef) this.m_Rungs[index];
- if (rung != null && rung.GetRungElement() is CRung rungElement && rungElement.MatchingRung != null)
- rung.MatchingViewRung = this.m_MatchingView.GetViewRung(rungElement.MatchingRung.RungNumber);
- }
- }
- }
- public LadderRoutine LadderRoutine => this.m_pRoutine;
- public bool IsPrinting => this.printing;
- public Graphics PrinterGraphics
- {
- get => this.printerGraphics;
- set => this.printerGraphics = value;
- }
- public int CurrentPage => this.IsPrinting ? this.currentPage : -1;
- public int PageCount => this.printPages != null ? this.printPages.Length : -1;
- public bool IsCompareView
- {
- get => this.isCompareView;
- set => this.isCompareView = value;
- }
- public CLadderView()
- {
- this.InitializeComponent();
- this.id = CLadderView.viewID++;
- this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
- this.ResizeRedraw = true;
- this.m_SelectedList = new ArrayList();
- this.m_Options = new CViewOptionsdef();
- this.m_Options.LadderInstructionFont = this.Font;
- this.mTheEditor = new LadderViewEditClass(this);
- }
- ~CLadderView() => this.FreeRungInfo();
- public void HookHorizScrollBarPos(SetHorizScrollbarPos theSetHorizScrollbarPos) => this._SetHorizScrollbarPos = theSetHorizScrollbarPos;
- public void HookVertScrollBarPos(SetVertScrollbarPos theSetVertScrollBarPos) => this._SetVertScrollbarPos = theSetVertScrollBarPos;
- public void HookHorizScrollBarRange(SetHorizScrollbarRange theSetHorizScrollbarRange) => this._SetHorizScrollbarRange = theSetHorizScrollbarRange;
- public void HookVertScrollBarRange(SetVertScrollbarRange theSetVertScrollbarRange) => this._SetVertScrollbarRange = theSetVertScrollbarRange;
- public void HookViewPropertiesSetup(ViewPropertiesSetup theViewPropertiesSetup) => this._ViewPropertiesSetup = theViewPropertiesSetup;
- public bool ScrollToNextDifference()
- {
- if (this.m_pCurrentTopViewRung != null && this.m_pCurrentTopViewRung.NextDifferenceRung != null)
- {
- CVRungdef nextDifferenceRung = this.m_pCurrentTopViewRung.NextDifferenceRung as CVRungdef;
- this.GotoRung(nextDifferenceRung);
- if (nextDifferenceRung.NextDifferenceRung != null)
- return true;
- }
- return false;
- }
- public bool ScrollToPreviousDifference()
- {
- if (this.m_pCurrentTopViewRung != null && this.m_pCurrentTopViewRung.PreviousDifferenceRung != null)
- {
- CVRungdef previousDifferenceRung = this.m_pCurrentTopViewRung.PreviousDifferenceRung as CVRungdef;
- this.GotoRung(previousDifferenceRung);
- if (previousDifferenceRung.PreviousDifferenceRung != null)
- return true;
- }
- return false;
- }
- protected override void OnPaint(PaintEventArgs pe)
- {
- this.OnDrawRungs(pe.Graphics, pe.ClipRectangle);
- base.OnPaint(pe);
- }
- private void InitializeComponent()
- {
- this.menuItem1 = new MenuItem();
- this.menuItem2 = new MenuItem();
- this.menuItem3 = new MenuItem();
- this.menuItem4 = new MenuItem();
- this.contextMainMenu = new ContextMenu();
- this.menuItem1.Index = -1;
- this.menuItem1.Text = "Properties";
- this.menuItem1.Click += new EventHandler(this.Properties_Click);
- this.menuItem2.Index = -1;
- this.menuItem2.Text = "-";
- this.menuItem3.Index = -1;
- this.menuItem3.Text = "Assemble Edits";
- this.menuItem4.Index = -1;
- this.menuItem4.Text = "Cancel Edits";
- this.contextMainMenu.MenuItems.AddRange(new MenuItem[4]
- {
- this.menuItem1,
- this.menuItem2,
- this.menuItem3,
- this.menuItem4
- });
- this.AllowDrop = false;
- this.BackColor = SystemColors.Window;
- this.CausesValidation = false;
- this.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
- this.ForeColor = SystemColors.WindowText;
- this.KeyPress += new KeyPressEventHandler(this.CLadderView_OnKeyPress);
- this.Click += new EventHandler(this.CLadderView_Enter);
- this.SizeChanged += new EventHandler(this.CLadderView_SizeChanged);
- this.Enter += new EventHandler(this.CLadderView_Enter);
- this.MouseUp += new MouseEventHandler(this.CLadderView_MouseUp);
- this.KeyUp += new KeyEventHandler(this.CLadderView_KeyUp);
- this.KeyDown += new KeyEventHandler(this.CLadderView_KeyDown);
- this.DoubleClick += new EventHandler(this.CLadderView_DoubleClick);
- this.MouseMove += new MouseEventHandler(this.CLadderView_MouseMove);
- this.MouseDown += new MouseEventHandler(this.CLadderView_MouseDown);
- this.Leave += new EventHandler(this.CLadderView_Leave);
- }
- private void CLadderView_MouseDown(object sender, MouseEventArgs e)
- {
- if (!this.Focused)
- this.Focus();
- Point empty = Point.Empty with
- {
- X = e.X,
- Y = e.Y
- };
- switch (e.Button)
- {
- case MouseButtons.Left:
- this.OnLeftButtonDown(empty);
- break;
- case MouseButtons.Right:
- this.OnRightButtonDown(empty);
- break;
- case MouseButtons.Middle:
- this.OnMiddleButtonDown(empty);
- break;
- }
- }
- private void CLadderView_MouseMove(object sender, MouseEventArgs e)
- {
- }
- private void CLadderView_MouseUp(object sender, MouseEventArgs e)
- {
- Point empty = Point.Empty with
- {
- X = e.X,
- Y = e.Y
- };
- if (e.Button != MouseButtons.Left)
- return;
- this.OnLeftButtonUp(empty);
- }
- protected override bool IsInputKey(Keys theKeyChecked) => theKeyChecked == Keys.Down || theKeyChecked == Keys.Up || theKeyChecked == Keys.Left || theKeyChecked == Keys.Right || theKeyChecked == Keys.Home || theKeyChecked == Keys.End || theKeyChecked == Keys.Prior || theKeyChecked == Keys.Next || theKeyChecked == Keys.Return || theKeyChecked == Keys.Tab || base.IsInputKey(theKeyChecked);
- private void CLadderView_KeyDown(object sender, KeyEventArgs e)
- {
- Keys modifiers = e.Modifiers;
- bool flag1 = false;
- if (modifiers == Keys.Shift)
- flag1 = true;
- bool flag2 = false;
- if (modifiers == Keys.Control)
- flag2 = true;
- switch (e.KeyCode)
- {
- case Keys.Tab:
- if (flag1)
- break;
- this.MoveCursorNextOperand();
- break;
- case Keys.Return:
- if (!this.IsEditable())
- break;
- this.OnEditIns();
- break;
- case Keys.Prior:
- if (flag2)
- {
- this.GotoPrevProgFile();
- break;
- }
- this.GotoPrevRung();
- if (this.MatchingView == null)
- break;
- this.MatchingView.GotoPrevRung();
- break;
- case Keys.Next:
- if (flag2)
- {
- this.GotoNextProgFile();
- break;
- }
- this.GotoNextRung();
- if (this.MatchingView == null)
- break;
- this.MatchingView.GotoNextRung();
- break;
- case Keys.End:
- if (flag2)
- {
- this.MoveCursorLastRung();
- break;
- }
- this.MoveCursorEnd();
- break;
- case Keys.Home:
- if (flag2)
- {
- this.MoveCursorFirstRung();
- break;
- }
- this.MoveCursorHome();
- break;
- case Keys.Left:
- this.MoveCursorLeft();
- break;
- case Keys.Up:
- this.MoveCursorUp();
- if (this.MatchingView == null)
- break;
- this.MatchingView.MoveCursorUp();
- break;
- case Keys.Right:
- this.MoveCursorRight();
- break;
- case Keys.Down:
- this.MoveCursorDown();
- break;
- }
- }
- public void CLadderView_OnKeyPress(object sender, KeyPressEventArgs e)
- {
- if (!this.IsEditable())
- return;
- char keyChar = e.KeyChar;
- if (keyChar == '/')
- {
- this.MoveCursorHome();
- this.OnEditIns();
- }
- else
- {
- if (char.IsControl(keyChar))
- return;
- this.EditIns(e.KeyChar);
- }
- }
- private void CLadderView_KeyUp(object sender, KeyEventArgs e)
- {
- Keys modifiers = e.Modifiers;
- bool flag = false;
- if (modifiers == Keys.Shift)
- flag = true;
- if (e.KeyCode != Keys.Tab || !flag)
- return;
- this.MoveCursorPrevOperand();
- }
- public CViewOptionsdef GetViewOptions() => this.m_Options;
- public void SetViewOptions(CViewOptionsdef options)
- {
- this.m_Options = options;
- this.ResetView();
- }
- public IRungViewElement GetCurrentCursorElement() => !this.m_bHaveFocus ? (IRungViewElement) null : this.m_pCursorElement;
- public bool IsItemSelected(IRungViewElement theItem)
- {
- if (!this.m_bHaveFocus)
- return false;
- foreach (IRungViewElement selected in this.m_SelectedList)
- {
- if (selected == theItem)
- return true;
- }
- return false;
- }
- public void SetUserXmlProject(
- XmlNode ladderXml,
- XmlNode programTagsXml,
- XmlNode globalTagsXml,
- bool bBase,
- string sDocumentationLanguage)
- {
- this.SetUserXmlProject(ladderXml, programTagsXml, globalTagsXml, false, bBase, sDocumentationLanguage);
- }
- public void SetUserXmlProject(
- XmlNode ladderXml,
- XmlNode programTagsXml,
- XmlNode globalTagsXml,
- bool delayRefresh,
- bool bBase,
- string sDocumentationLanguage)
- {
- LadderRoutine progfile = new LadderRoutine();
- progfile.m_bBase = bBase;
- progfile.SetController(this.m_Controller);
- progfile.FromXML(ladderXml);
- TagSymbolClass data1 = new TagSymbolClass();
- data1.LoadXML(globalTagsXml, sDocumentationLanguage);
- TagSymbolClass data2 = new TagSymbolClass();
- data2.LoadXML(programTagsXml, sDocumentationLanguage);
- progfile.SetGlobalTags(data1);
- progfile.SetProgramTags(data2);
- this.SetUserRoutine(progfile);
- }
- public void SetUserXmlProject(
- XmlNode ladderXml,
- XmlNode programTagsXml,
- XmlNode globalTagsXml,
- bool delayRefresh,
- bool bBase,
- string sDocumentationLanguage,
- bool isOnly)
- {
- LadderRoutine progfile = new LadderRoutine();
- progfile.m_bBase = bBase;
- progfile.SetController(this.m_Controller);
- progfile.FromXML_ForBaseCompareOnly(ladderXml);
- TagSymbolClass data1 = new TagSymbolClass();
- data1.LoadXML(globalTagsXml, sDocumentationLanguage);
- TagSymbolClass data2 = new TagSymbolClass();
- data2.LoadXML(programTagsXml, sDocumentationLanguage);
- progfile.SetGlobalTags(data1);
- progfile.SetProgramTags(data2);
- this.SetUserRoutine(progfile);
- }
- public void SetUserXMLFile(string filename)
- {
- LadderRoutine progfile = new LadderRoutine();
- progfile.SetController(this.m_Controller);
- progfile.FromXMLFile(filename);
- this.SetFile(progfile);
- this.RoutineHasChanged();
- }
- public void SetUserXMLProgram(string xml)
- {
- LadderRoutine progfile = new LadderRoutine();
- progfile.SetController(this.m_Controller);
- progfile.FromXML(xml);
- this.SetFile(progfile);
- this.RoutineHasChanged();
- }
- public void SetControllerFamily(string ControllerFamily)
- {
- if (this.m_Controller == null)
- this.m_Controller = new Controller();
- this.m_Controller.SetFamily(ControllerFamily);
- }
- public void LegNeutralTextToXmlWriter(string neutralText, XmlWriter writer)
- {
- LadderRoutine ladderRoutine = new LadderRoutine();
- ladderRoutine.SetController(this.m_Controller);
- ladderRoutine.LegNeutralTextToXmlWriter(neutralText, writer);
- }
- public void ExpandLegNeutralTextToXml(string neutralText, XmlWriter writer)
- {
- LadderRoutine ladderRoutine = new LadderRoutine();
- ladderRoutine.SetController(this.m_Controller);
- ladderRoutine.ExpandLegNeutralTextToXml(neutralText, writer);
- }
- public void ExpandLegNeutralTextToXml(XmlNode textNode, out XmlNode legNode)
- {
- LadderRoutine ladderRoutine = new LadderRoutine();
- ladderRoutine.SetController(this.m_Controller);
- ladderRoutine.ExpandLegNeutralTextToXml(textNode, out legNode);
- }
- public void SetUserRoutine(LadderRoutine progfile)
- {
- this.SetFile(progfile);
- this.RoutineHasChanged();
- }
- public void SetUserMainProgram(ProgramHolder progholder)
- {
- this.m_pProgholder = progholder;
- this.GotoFirstProgFile();
- this.RoutineHasChanged();
- }
- private void RoutineHasChanged()
- {
- if (this.RoutineChangedHook == null)
- return;
- foreach (RoutineChangedCb invocation in this.RoutineChangedHook.GetInvocationList())
- invocation();
- }
- public string GetProgramRoutineTitle()
- {
- if (this.m_pProgholder == null || this.m_pRoutine == null)
- return "";
- string str1 = "Routine-> " + this.m_pRoutine.GetName() + " - " + this.m_pRoutine.GetDescription() + " Total rungs = " + this.m_pRoutine.GetRungCount().ToString();
- string str2 = "";
- if (this.m_pProgram != null)
- str2 = "Program-> " + this.m_pProgram.GetName() + " - " + this.m_pProgram.GetDescription() + " Total Routines = " + this.m_pProgram.GetRoutineCount().ToString();
- return str2 + " : " + str1;
- }
- private void GotoFirstProgFile()
- {
- if (this.m_pProgholder == null)
- return;
- int num1 = 0;
- int num2 = 0;
- ProgramHolder pProgholder = this.m_pProgholder;
- int index = num1;
- int num3 = index + 1;
- ProgramClass program = pProgholder.GetProgram(index);
- bool flag = false;
- for (; program != null; program = this.m_pProgholder.GetProgram(num3++))
- {
- for (IRoutine routine = program.GetRoutine(num2++); routine != null; routine = program.GetRoutine(num2++))
- {
- if (routine != null && routine.GetRoutineType() == "Ladder")
- {
- this.SetFile((LadderRoutine) routine);
- flag = true;
- break;
- }
- }
- if (flag)
- {
- this.m_pProgram = program;
- break;
- }
- }
- }
- public void GotoPrevProgFile()
- {
- if (this.m_pProgholder == null)
- return;
- int num1 = 0;
- if (this.m_pProgram != null)
- num1 = this.m_pProgholder.GetProgramFileIndex(this.m_pProgram) - 1;
- int num2 = 0;
- ProgramClass programClass = this.m_pProgram;
- if (this.m_pRoutine != null)
- {
- int routineFileIndex = programClass.GetRoutineFileIndex((IRoutine) this.m_pRoutine);
- if (routineFileIndex == 0)
- {
- programClass = this.m_pProgholder.GetProgram(num1--);
- if (programClass == null)
- return;
- num2 = programClass.GetRoutineCount() - 1;
- }
- else
- num2 = routineFileIndex - 1;
- }
- if (num2 == -1)
- num2 = programClass.GetRoutineCount() - 1;
- bool flag = false;
- while (programClass != null)
- {
- for (IRoutine routine = programClass.GetRoutine(num2--); routine != null; routine = programClass.GetRoutine(num2--))
- {
- if (routine != null && routine.GetRoutineType() == "Ladder")
- {
- this.SetFile((LadderRoutine) routine);
- flag = true;
- break;
- }
- }
- if (flag)
- {
- this.m_pProgram = programClass;
- break;
- }
- programClass = this.m_pProgholder.GetProgram(num1--);
- if (programClass != null)
- num2 = programClass.GetRoutineCount() - 1;
- }
- if (!flag)
- return;
- this.RoutineHasChanged();
- }
- public void GotoNextProgFile()
- {
- if (this.m_pProgholder == null)
- return;
- int num1 = 0;
- if (this.m_pProgram != null)
- num1 = this.m_pProgholder.GetProgramFileIndex(this.m_pProgram) + 1;
- int num2 = 0;
- ProgramClass programClass1 = this.m_pProgram;
- if (this.m_pRoutine != null)
- {
- int routineFileIndex = programClass1.GetRoutineFileIndex((IRoutine) this.m_pRoutine);
- if (routineFileIndex >= programClass1.GetRoutineCount())
- {
- programClass1 = this.m_pProgholder.GetProgram(num1++);
- if (programClass1 == null)
- return;
- num2 = 0;
- }
- else
- num2 = routineFileIndex + 1;
- }
- if (num2 == -1)
- num2 = 0;
- bool flag = false;
- while (programClass1 != null)
- {
- ProgramClass programClass2 = programClass1;
- int index = num2;
- int num3 = index + 1;
- for (IRoutine routine = programClass2.GetRoutine(index); routine != null; routine = programClass1.GetRoutine(num3++))
- {
- if (routine != null && routine.GetRoutineType() == "Ladder")
- {
- this.SetFile((LadderRoutine) routine);
- flag = true;
- break;
- }
- }
- if (flag)
- {
- this.m_pProgram = programClass1;
- break;
- }
- programClass1 = this.m_pProgholder.GetProgram(num1++);
- num2 = 0;
- }
- if (!flag)
- return;
- this.RoutineHasChanged();
- }
- private void FreeRungInfo()
- {
- if (this.m_Rungs != null)
- {
- for (int index = 0; index < this.m_Rungs.Count; ++index)
- {
- CVRungdef rung = (CVRungdef) this.m_Rungs[index];
- if (rung != null)
- {
- rung.SetNext((IRungViewElement) null);
- rung.SetPrevious((IRungViewElement) null);
- rung.PreviousDifferenceRung = (IRungViewElement) null;
- rung.NextDifferenceRung = (IRungViewElement) null;
- }
- }
- this.m_Rungs.RemoveRange(0, this.m_Rungs.Count);
- }
- this.m_pFirstViewRung = (CVRungdef) null;
- }
- private void UpdateRungNumberIndicator()
- {
- }
- public void SetFile(LadderRoutine progfile)
- {
- this.FreeRungInfo();
- if (progfile == null)
- return;
- this.m_pRoutine = progfile;
- if (!this.Initialize())
- return;
- CVRungdef pFirstViewRung = this.m_pFirstViewRung;
- this.OnRefreshRung(pFirstViewRung);
- this.SetTopRung(pFirstViewRung);
- this.m_pCursorRung = pFirstViewRung;
- this.m_pCursorElement = (IRungViewElement) pFirstViewRung;
- this.ResetView();
- this.m_pSelectedRung = (CVRungdef) null;
- if (this.m_SelectedList.Count > 0)
- this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
- if (pFirstViewRung == null)
- return;
- this.SetCursor(this.m_pCursorRung, this.m_pCursorElement);
- }
- private bool IsEditable() => false;
- private void Properties_Click(object sender, EventArgs e)
- {
- if (this._ViewPropertiesSetup == null)
- return;
- this._ViewPropertiesSetup(this.m_Options);
- }
- private bool Initialize()
- {
- if (this.m_pRoutine == null)
- return false;
- int rungCount = this.m_pRoutine.GetRungCount();
- this.m_Rungs = new ArrayList(rungCount);
- CVRungdef theprev = (CVRungdef) null;
- for (int index = 0; index < rungCount; ++index)
- {
- CVRungdef thenext = new CVRungdef(this.m_pRoutine.GetRungAt(index), this);
- thenext.ScrollNumber = index;
- if (theprev != null)
- {
- theprev.SetNext((IRungViewElement) thenext);
- thenext.SetPrevious((IRungViewElement) theprev);
- }
- if (this.m_pFirstViewRung == null)
- this.m_pFirstViewRung = thenext;
- this.m_Rungs.Add((object) thenext);
- theprev = thenext;
- }
- this.SetupDifferencePointers();
- if (this._SetVertScrollbarRange != null)
- this._SetVertScrollbarRange(0, rungCount);
- return true;
- }
- private void SetupDifferencePointers()
- {
- CVRungdef cvRungdef1 = (CVRungdef) null;
- for (CVRungdef cvRungdef2 = this.m_pFirstViewRung; cvRungdef2 != null; cvRungdef2 = (CVRungdef) cvRungdef2.Next())
- {
- cvRungdef2.PreviousDifferenceRung = (IRungViewElement) cvRungdef1;
- if (cvRungdef2.DifferenceRung)
- {
- cvRungdef1 = cvRungdef2;
- CVRungdef cvRungdef3 = cvRungdef2;
- do
- {
- cvRungdef3 = (CVRungdef) cvRungdef3.Previous();
- if (cvRungdef3 != null)
- cvRungdef3.NextDifferenceRung = (IRungViewElement) cvRungdef2;
- }
- while (cvRungdef3 != null && !cvRungdef3.DifferenceRung);
- }
- }
- }
- public void OnSizeChanged()
- {
- Rectangle VwRc = Rectangle.Empty;
- this.GetViewRect(out VwRc);
- this.OnSizeChanged(VwRc);
- }
- public void OnSizeChanged(Rectangle rc)
- {
- if (this.MatchingView != null && !CLadderView.compareSynro)
- {
- CLadderView.compareSynro = true;
- this.MatchingView.OnSizeChanged(rc);
- CLadderView.compareSynro = false;
- }
- this.m_nWidth = rc.Width - this.m_Options.GetGridUnit().Width;
- this.OnSetStaleRungs();
- this.OnSetRungPositions();
- this.Refresh();
- }
- public void ResetView() => this.ResetView(true);
- public void ResetView(bool bRedraw)
- {
- bool flag = false;
- Graphics graphics;
- if (this.IsPrinting)
- {
- graphics = this.printerGraphics;
- }
- else
- {
- graphics = this.CreateGraphics();
- flag = true;
- }
- this.m_Options.SetGridUnit((SizeF) graphics.MeasureString("M", this.m_Options.LadderInstructionFont).ToSize());
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- this.m_nWidth = VwRc.Width - this.m_Options.GetGridUnit().Width;
- if (this.m_Options.DisplayPageHeader)
- {
- this.m_nLadderWindowTop = VwRc.Top + 2 * this.m_Options.GetGridUnit().Height;
- this.m_nTopRungOffset = this.m_nLadderWindowTop;
- }
- else
- {
- this.m_nLadderWindowTop = VwRc.Top;
- this.m_nTopRungOffset = this.m_nLadderWindowTop;
- }
- this.m_nLadderWindowLeft = VwRc.Left;
- if (flag)
- graphics.Dispose();
- this.OnSetStaleRungs();
- if (bRedraw)
- this.OnSetRungPositions();
- if (this._SetHorizScrollbarRange != null)
- this._SetHorizScrollbarRange(0, this.m_nScrollWidth);
- if (this._SetHorizScrollbarPos != null)
- this._SetHorizScrollbarPos(0);
- if (!bRedraw)
- return;
- this.Refresh();
- }
- private int GetWidth() => this.m_nWidth;
- public bool OnScroll(Rectangle test_rc)
- {
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- VwRc.Y += this.m_nLadderWindowTop;
- int width = 0;
- int num = 0;
- if (test_rc.Bottom > VwRc.Bottom)
- {
- num = test_rc.Bottom - VwRc.Bottom;
- if (test_rc.Top - num < VwRc.Top)
- num = test_rc.Top - VwRc.Top;
- }
- if (test_rc.Top <= VwRc.Top)
- num = test_rc.Top - VwRc.Top;
- if (test_rc.Right > VwRc.Right)
- {
- width = VwRc.Right - test_rc.Right;
- if (test_rc.Left + width < VwRc.Left)
- width = VwRc.Left - test_rc.Left;
- }
- if (test_rc.Left <= VwRc.Left)
- width = VwRc.Left - test_rc.Left;
- if (width == 0 && num == 0)
- return false;
- Size sizeScroll = new Size(width, -num);
- if (this.MatchingView != null && !CLadderView.compareSynro)
- {
- CLadderView.compareSynro = true;
- this.MatchingView.OnScrollBy(sizeScroll);
- CLadderView.compareSynro = false;
- }
- return this.OnScrollBy(sizeScroll);
- }
- public void InvalidateRect(Rectangle rc) => this.Invalidate(rc);
- public void InvalidateRect(Rectangle rc, bool bErasebackground) => this.Invalidate(rc, true);
- public void GetViewRect(out Rectangle VwRc)
- {
- VwRc = Rectangle.Empty;
- if (!this.printing)
- {
- VwRc = this.DisplayRectangle;
- VwRc.Height -= 20;
- }
- else if (this.CurrentPage == 1)
- VwRc = this.page1PrintRect;
- else
- VwRc = this.page2PrintRect;
- }
- public bool IsViewActive() => true;
- public bool EditAscii(int rungnumber, int rungelemindex, string str, char ch) => false;
- private void OnSetRungPositions()
- {
- if (this.printing)
- {
- this.OnSetAllRungPositions();
- }
- else
- {
- CVRungdef pRung = this.m_pCurrentTopViewRung;
- if (pRung == null)
- return;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- int num = 0;
- Point ScreenPosition = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset);
- bool flag = true;
- for (; VwRc.Bottom > ScreenPosition.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
- {
- flag = false;
- this.OnRefreshRung(pRung);
- Size size = pRung.GetSize();
- if (size.Width > num)
- num = size.Width;
- pRung.SetPosition(this.m_Options, ScreenPosition);
- ScreenPosition.Y += size.Height;
- }
- if (pRung != null)
- {
- for (Point position = pRung.GetPosition(); position.Y <= VwRc.Bottom; position = pRung.GetPosition())
- {
- this.OnRefreshRung(pRung);
- Size size = pRung.GetSize();
- pRung.SetPosition(this.m_Options, ScreenPosition);
- ScreenPosition.Y += size.Height;
- pRung = (CVRungdef) pRung.Next();
- if (pRung == null)
- break;
- }
- }
- if (flag)
- {
- this.OnRefreshRung(this.m_pCurrentTopViewRung);
- Size size = this.m_pCurrentTopViewRung.GetSize();
- if (size.Width > num)
- num = size.Width;
- this.m_pCurrentTopViewRung.SetPosition(this.m_Options, ScreenPosition);
- }
- if (num > this.m_nScrollWidth)
- {
- this.m_nScrollWidth = num;
- if (this._SetHorizScrollbarRange != null)
- this._SetHorizScrollbarRange(0, this.m_nScrollWidth);
- }
- this.ResetAsyncData();
- }
- }
- private void OnSetAllRungPositions()
- {
- CVRungdef pRung = this.m_pCurrentTopViewRung;
- if (pRung == null)
- return;
- Point ScreenPosition = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset);
- for (; pRung != null; pRung = (CVRungdef) pRung.Next())
- {
- this.OnRefreshRung(pRung);
- Size size = pRung.GetSize();
- pRung.SetPosition(this.m_Options, ScreenPosition);
- if (this.printDiffRungsOnly)
- {
- if (pRung.DifferenceRung)
- ScreenPosition.Y += size.Height;
- }
- else
- ScreenPosition.Y += size.Height;
- }
- }
- private void SetTopRung(CVRungdef pVRung) => this.m_pCurrentTopViewRung = pVRung;
- private void ResetAsyncData()
- {
- if (this.m_AddrTagsForUpdating == null)
- this.m_AddrTagsForUpdating = new ArrayList();
- else
- this.m_AddrTagsForUpdating.RemoveRange(0, this.m_AddrTagsForUpdating.Count);
- CVRungdef pRung = this.m_pCurrentTopViewRung;
- if (pRung == null)
- return;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
- {
- this.OnRefreshRung(pRung);
- Size size = pRung.GetSize();
- ((CRung) pRung.GetRungElem())?.AddToUpdateList(this.m_AddrTagsForUpdating);
- point.Y += size.Height;
- }
- }
- public void OnDataChanged(ArrayList changedData)
- {
- if (this.m_Options.IsPrinting())
- return;
- CVRungdef pRung = this.m_pCurrentTopViewRung;
- if (pRung == null)
- return;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
- {
- this.OnRefreshRung(pRung);
- Size size = pRung.GetSize();
- pRung.UpdateLiveData(changedData, this);
- point.Y += size.Height;
- }
- }
- public void OnRefreshRung(CVRungdef pRung)
- {
- Size headerSize = Size.Empty;
- if (pRung == null)
- return;
- bool flag = false;
- Graphics g;
- if (this.IsPrinting)
- {
- g = this.printerGraphics;
- }
- else
- {
- g = this.CreateGraphics();
- flag = true;
- }
- if (pRung.IsStale() || pRung.MatchingViewRung != null)
- {
- if (this.m_Options.DisplayLadderAsLadder)
- {
- if (this.m_Options.DisplayLadderUsingRungWrap)
- pRung.CalcSize_LadderLimitWidth(g, this, this.GetWidth(), this.GetWidth(), out headerSize);
- else
- pRung.CalcSize_Ladder(g, this, this.GetWidth());
- }
- else if (this.m_Options.DisplayLadderAsAscii)
- pRung.CalcSize_Ascii(g, this, this.GetWidth());
- }
- if (!flag)
- return;
- g.Dispose();
- }
- private void OnSetStaleRungs()
- {
- if (this.m_Rungs == null)
- return;
- foreach (CVRungdef rung in this.m_Rungs)
- rung.SetStale();
- }
- public void InitializePrinting(
- Graphics g,
- Rectangle Page1ClipRect,
- Rectangle Page2ClipRect,
- float scale,
- bool diffOnly)
- {
- Trace.WriteLine("-------------Start: InitializePrinting ()");
- this.m_Options.LadderInstructionFont = new Font(this.m_Options.LadderInstructionFont.Name, this.m_Options.LadderInstructionFont.Size * scale);
- this.printerGraphics = g;
- this.page1PrintRect = Page1ClipRect;
- this.page2PrintRect = Page2ClipRect;
- this.printing = true;
- this.printDiffRungsOnly = diffOnly;
- this.currentPage = 1;
- this.OnSizeChanged();
- this.ResetView(true);
- this.printPages = this.CalculatePrintedPages();
- this.printing = false;
- Trace.WriteLine("-------------End: InitializePrinting ()");
- }
- private CLadderView.PrintPageInfo[] CalculatePrintedPages()
- {
- bool printing = this.printing;
- int currentPage = this.currentPage;
- this.printing = true;
- this.currentPage = 1;
- int num = 0;
- ArrayList arrayList = new ArrayList();
- Rectangle rectangle = this.page1PrintRect;
- CVRungdef cvRungdef = this.m_pFirstViewRung;
- CLadderView.PrintPageInfo printPageInfo1 = new CLadderView.PrintPageInfo();
- printPageInfo1.StartRung = cvRungdef;
- printPageInfo1.EndRung = cvRungdef;
- printPageInfo1.ClipRect = rectangle;
- printPageInfo1.TopRungOffset = 0;
- bool flag = false;
- while (cvRungdef != null)
- {
- Size size = cvRungdef.GetSize();
- if (!this.printDiffRungsOnly || cvRungdef.DifferenceRung)
- num += size.Height;
- if (num > rectangle.Height)
- {
- if (flag)
- printPageInfo1.EndRung = cvRungdef;
- arrayList.Add((object) printPageInfo1);
- int rungCount = printPageInfo1.RungCount;
- CLadderView.PrintPageInfo printPageInfo2 = new CLadderView.PrintPageInfo();
- printPageInfo2.StartRung = cvRungdef;
- printPageInfo2.EndRung = cvRungdef;
- printPageInfo2.TopRungOffset = !flag ? printPageInfo1.TopRungOffset + -1 * rectangle.Height : -1 * rectangle.Height + (num - size.Height);
- num = size.Height + printPageInfo2.TopRungOffset;
- ++this.currentPage;
- rectangle = this.page2PrintRect;
- printPageInfo2.ClipRect = rectangle;
- printPageInfo1 = printPageInfo2;
- }
- else
- printPageInfo1.EndRung = cvRungdef;
- if (num <= rectangle.Height)
- {
- cvRungdef = (CVRungdef) cvRungdef.Next();
- flag = true;
- }
- else
- flag = false;
- }
- arrayList.Add((object) printPageInfo1);
- this.printing = printing;
- this.currentPage = currentPage;
- return (CLadderView.PrintPageInfo[]) arrayList.ToArray(typeof (CLadderView.PrintPageInfo));
- }
- public void OnPrintRungs(Graphics g, int page)
- {
- if (page < 1 || page > this.printPages.Length)
- return;
- this.printerGraphics = g;
- this.printing = true;
- this.currentPage = page;
- CLadderView.PrintPageInfo printPage = this.printPages[page - 1];
- CVRungdef cvRungdef = printPage.StartRung;
- this.m_pCurrentTopViewRung = printPage.StartRung;
- this.printerGraphics.SetClip(printPage.ClipRect);
- this.ResetView(true);
- if (cvRungdef == null)
- return;
- if (printPage.TopRungOffset != 0)
- this.printerGraphics.TranslateTransform(0.0f, (float) printPage.TopRungOffset, MatrixOrder.Append);
- for (; cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
- {
- if (!this.printDiffRungsOnly || cvRungdef.DifferenceRung)
- cvRungdef.Draw(this.printerGraphics, this);
- if (cvRungdef == printPage.EndRung)
- break;
- }
- if (printPage.TopRungOffset != 0)
- this.printerGraphics.ResetTransform();
- this.printing = false;
- }
- private void OnDrawRungs(Graphics g, Rectangle ClipRect)
- {
- CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
- if (cvRungdef == null)
- return;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- int num = this.m_nTopRungOffset;
- Size empty = Size.Empty;
- for (; VwRc.Bottom > num && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
- {
- Size size = cvRungdef.GetSize();
- num = cvRungdef.GetPosition().Y + size.Height;
- if (num > VwRc.Top)
- cvRungdef.Draw(g, this);
- }
- }
- private bool SetCursor(CVRungdef pAtRung, IRungViewElement pAtElementInRung)
- {
- if (pAtRung == null || pAtElementInRung == null)
- return false;
- if (this.m_pCursorElement != null && this.m_pCursorRung != null)
- this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
- this.m_pCursorElement = pAtElementInRung;
- this.m_pCursorRung = pAtRung;
- this.OnRefreshRung(this.m_pCursorRung);
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- this.m_pCursorElement.SetCursor(this);
- this.ClearAllSelections();
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
- this.UpdateRungNumberIndicator();
- this.Refresh();
- return true;
- }
- private void SetAnchorItem(CVRungdef pAnchorRung, IRungViewElement pAnchorElem)
- {
- if (pAnchorRung == null || pAnchorElem == null)
- return;
- this.m_pAnchorElem = pAnchorElem;
- this.m_pAnchorRung = pAnchorRung;
- }
- private void ClearAnchor()
- {
- this.m_pAnchorElem = (IRungViewElement) null;
- this.m_pAnchorRung = (CVRungdef) null;
- }
- private bool SetCursor(CVRungdef pAtRung, IRungViewElement pAtElementInRung, Point pt)
- {
- if (pAtRung == null || pAtElementInRung == null)
- return false;
- if (this.m_pCursorElement != null && this.m_pCursorRung != null)
- this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
- this.m_pCursorElement = pAtElementInRung;
- this.m_pCursorRung = pAtRung;
- this.OnRefreshRung(this.m_pCursorRung);
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- {
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorRung.MatchingViewRung != null)
- this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
- }
- this.m_pCursorElement.SetCursor(this, pt);
- this.ClearAllSelections();
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
- this.UpdateRungNumberIndicator();
- this.Refresh();
- return true;
- }
- private bool SetCursorAndSelect(CVRungdef pAtRung, IRungViewElement pAtElementInRung)
- {
- if (pAtRung == null || pAtElementInRung == null)
- return false;
- if (this.m_pCursorElement != null && this.m_pCursorRung != null)
- this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
- this.m_pCursorElement = pAtElementInRung;
- this.m_pCursorRung = pAtRung;
- this.OnRefreshRung(this.m_pCursorRung);
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- {
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorRung.MatchingViewRung != null)
- this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
- }
- this.m_pCursorElement.SetCursor(this);
- Keys modifierKeys = Control.ModifierKeys;
- bool flag = false;
- if (modifierKeys == Keys.Shift)
- flag = true;
- if (flag)
- {
- this.SelectSpan(this.m_pCursorRung, this.m_pCursorElement);
- }
- else
- {
- this.ClearAllSelections();
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
- }
- this.UpdateRungNumberIndicator();
- this.Refresh();
- return true;
- }
- private bool SetCursorAndSelect(CVRungdef pAtRung, IRungViewElement pAtElementInRung, Point pt)
- {
- if (pAtRung == null || pAtElementInRung == null)
- return false;
- if (this.m_pCursorElement != null && this.m_pCursorRung != null)
- this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
- this.m_pCursorElement = pAtElementInRung;
- this.m_pCursorRung = pAtRung;
- this.OnRefreshRung(this.m_pCursorRung);
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- this.m_pCursorElement.SetCursor(this, pt);
- Keys modifierKeys = Control.ModifierKeys;
- bool flag1 = false;
- if (modifierKeys == Keys.Shift)
- flag1 = true;
- bool flag2 = false;
- if (modifierKeys == Keys.Control)
- flag2 = true;
- this.m_nLeftMouseButUpActionToDo = 0;
- if (flag2 && !flag1)
- {
- if (!this.m_pCursorElement.IsSelected(this))
- {
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
- }
- else
- this.m_nLeftMouseButUpActionToDo = 2;
- }
- else if (flag1)
- this.SelectSpan(this.m_pCursorRung, this.m_pCursorElement);
- else if (!this.m_pCursorElement.IsSelected(this))
- {
- this.ClearAllSelections();
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
- }
- else
- this.m_nLeftMouseButUpActionToDo = 1;
- this.UpdateRungNumberIndicator();
- this.Refresh();
- return true;
- }
- private void SelectSpan(CVRungdef pSelectRung, IRungViewElement pSpanElem)
- {
- if (pSelectRung == null || pSpanElem == null || this.m_pAnchorRung == null || this.m_pAnchorElem == null)
- return;
- this.ClearAllSelections();
- IRungElement rungElement1 = this.m_pAnchorElem.GetRungElement();
- IRungElement rungElement2 = pSpanElem.GetRungElement();
- if (rungElement1 == null || rungElement2 == null)
- return;
- if (this.m_pAnchorElem.IsRung() && !pSpanElem.IsRung() || !this.m_pAnchorElem.IsRung() && pSpanElem.IsRung() || rungElement1.GetOwner() != rungElement2.GetOwner())
- {
- this.SetAnchorItem(pSelectRung, pSpanElem);
- this.m_pSelectedRung = pSelectRung;
- this.m_SelectedList.Add((object) pSpanElem);
- pSpanElem.SetSelected(this, this.IsRungOnScreen(pSelectRung));
- }
- else
- {
- this.m_pSelectedRung = this.m_pAnchorRung;
- bool flag = true;
- IRungViewElement rungViewElement1 = this.m_pAnchorElem;
- IRungViewElement pTestRung1 = this.m_pAnchorElem;
- for (; rungViewElement1 != pSpanElem; rungViewElement1 = rungViewElement1.Next())
- {
- if (rungViewElement1 == null)
- {
- flag = false;
- for (IRungViewElement rungViewElement2 = pSpanElem; rungViewElement2 != pTestRung1; rungViewElement2 = rungViewElement2.Next())
- {
- if (rungViewElement2 == null)
- return;
- }
- break;
- }
- }
- if (flag)
- {
- while (pTestRung1 != pSpanElem)
- {
- this.m_SelectedList.Add((object) pTestRung1);
- if (pTestRung1.IsRung())
- pTestRung1.SetSelected(this, this.IsRungOnScreen((CVRungdef) pTestRung1));
- else
- pTestRung1.SetSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
- pTestRung1 = pTestRung1.Next();
- if (pTestRung1 == null)
- break;
- }
- }
- else
- {
- IRungViewElement pTestRung2 = pTestRung1;
- while (pTestRung2 != pSpanElem)
- {
- this.m_SelectedList.Add((object) pTestRung2);
- if (pTestRung2.IsRung())
- pTestRung2.SetSelected(this, this.IsRungOnScreen((CVRungdef) pTestRung2));
- else
- pTestRung2.SetSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
- pTestRung2 = pTestRung2.Previous();
- if (pTestRung2 == null)
- break;
- }
- }
- this.m_SelectedList.Add((object) pSpanElem);
- if (pSpanElem.IsRung())
- pSpanElem.SetSelected(this, this.IsRungOnScreen((CVRungdef) pSpanElem));
- else
- pSpanElem.SetSelected(this, this.IsRungOnScreen(pSelectRung));
- ArrayList arrayList = new ArrayList(this.m_SelectedList.Count);
- if (flag)
- return;
- for (int index = this.m_SelectedList.Count - 1; index >= 0; --index)
- {
- object selected = this.m_SelectedList[index];
- arrayList.Add(selected);
- }
- this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
- for (int index = 0; index < arrayList.Count; ++index)
- this.m_SelectedList.Add(arrayList[index]);
- }
- }
- private void SelectItem(CVRungdef pSelRung, IRungViewElement pSelElem)
- {
- if (pSelRung == null || pSelElem == null)
- return;
- IRungViewElement rungViewElement = (IRungViewElement) null;
- if (this.m_pSelectedRung != null)
- {
- if (this.m_SelectedList.Count > 0)
- rungViewElement = (IRungViewElement) this.m_SelectedList[0];
- if (rungViewElement != null && rungViewElement.IsRung())
- {
- if (pSelRung != pSelElem)
- this.ClearAllSelections();
- }
- else if (this.m_pSelectedRung != pSelRung)
- this.ClearAllSelections();
- }
- IRungElement rungElement1 = pSelElem.GetRungElement();
- for (int index = 0; index < this.m_SelectedList.Count; ++index)
- {
- IRungViewElement selected = (IRungViewElement) this.m_SelectedList[index];
- if (selected == pSelElem)
- {
- this.m_SelectedList.RemoveAt(index);
- if (selected.IsRung())
- selected.ClearSelected(this, this.IsRungOnScreen((CVRungdef) selected));
- else
- selected.ClearSelected(this, this.IsRungOnScreen(pSelRung));
- if (this.m_SelectedList.Count > 0)
- return;
- this.m_pSelectedRung = (CVRungdef) null;
- return;
- }
- IRungElement rungElement2 = selected.GetRungElement();
- if (rungElement2 != null && rungElement1 != null && rungElement2.GetOwner() != rungElement1.GetOwner())
- {
- this.ClearAllSelections();
- break;
- }
- }
- this.m_pSelectedRung = pSelRung;
- this.m_SelectedList.Add((object) pSelElem);
- pSelElem.SetSelected(this, this.IsRungOnScreen(pSelRung));
- }
- private void ClearAllSelections()
- {
- for (int index = 0; index < this.m_SelectedList.Count; ++index)
- {
- IRungViewElement selected = (IRungViewElement) this.m_SelectedList[index];
- if (selected.IsRung())
- selected.ClearSelected(this, this.IsRungOnScreen((CVRungdef) selected));
- else
- selected.ClearSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
- }
- this.m_pSelectedRung = (CVRungdef) null;
- this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
- }
- private bool SetCursor(Point pt)
- {
- CVRungdef rungWithPt = this.GetRungWithPt(pt);
- if (rungWithPt == null)
- return false;
- IRungViewElement rungElementWithPt = this.GetRungElementWithPt(pt);
- return rungElementWithPt != null && this.SetCursorAndSelect(rungWithPt, rungElementWithPt, pt);
- }
- private IGraphic GetElementWithPt(Point pt) => this.GetRungWithPt(pt)?.GetElementWithPt(this, pt);
- private IRungViewElement GetRungElementWithPt(Point pt)
- {
- IGraphic elementWithPt = this.GetElementWithPt(pt);
- if (elementWithPt == null)
- return (IRungViewElement) null;
- return elementWithPt.IsRungElement() ? (IRungViewElement) elementWithPt : (IRungViewElement) null;
- }
- private CVRungdef GetViewRung(IRungElement docrung)
- {
- if (this.m_pFirstViewRung != null)
- {
- for (IRungViewElement viewRung = (IRungViewElement) this.m_pFirstViewRung; viewRung != null; viewRung = viewRung.Next())
- {
- if (viewRung.GetRungElement() == docrung)
- return (CVRungdef) viewRung;
- }
- }
- return (CVRungdef) null;
- }
- private CVRungdef GetRungWithPt(Point pt)
- {
- CVRungdef rungWithPt = this.m_pCurrentTopViewRung;
- if (rungWithPt == null)
- return (CVRungdef) null;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && rungWithPt != null; rungWithPt = (CVRungdef) rungWithPt.Next())
- {
- if (rungWithPt.HavePt(pt))
- return rungWithPt;
- point.Y += rungWithPt.GetSize().Height;
- }
- return (CVRungdef) null;
- }
- private bool IsRungOnScreen(CVRungdef pTestRung)
- {
- CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
- if (cvRungdef == null || pTestRung == null)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- for (int nTopRungOffset = this.m_nTopRungOffset; VwRc.Bottom > nTopRungOffset && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
- {
- if (pTestRung == cvRungdef)
- return true;
- nTopRungOffset += cvRungdef.GetSize().Height;
- }
- return false;
- }
- private bool IsRungOnScreen(int nRung)
- {
- CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
- if (cvRungdef == null)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- for (int nTopRungOffset = this.m_nTopRungOffset; VwRc.Bottom > nTopRungOffset && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
- {
- if (cvRungdef.GetRungNumber() == nRung)
- return true;
- nTopRungOffset += cvRungdef.GetSize().Height;
- }
- return false;
- }
- public void mVertScrollBar_Scroll(object sender, ScrollEventArgs e)
- {
- int height = this.m_Options.GetGridUnit().Height;
- ScrollEventType type = e.Type;
- int index = e.NewValue / 100;
- switch (type)
- {
- case ScrollEventType.SmallDecrement:
- if (this.m_pCurrentTopViewRung == null)
- break;
- int rungoffset1 = this.m_nTopRungOffset + height;
- if (rungoffset1 > this.m_nLadderWindowTop)
- {
- if (this.m_pCurrentTopViewRung.Previous() == null)
- break;
- this.OnRefreshRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
- int rungoffset2 = this.m_nLadderWindowTop - this.m_pCurrentTopViewRung.Previous().GetSize().Height + height;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous(), rungoffset2);
- break;
- }
- this.GotoRung(this.m_pCurrentTopViewRung, rungoffset1);
- break;
- case ScrollEventType.SmallIncrement:
- if (this.m_pCurrentTopViewRung == null)
- break;
- int rungoffset3 = this.m_nTopRungOffset - height;
- if (this.m_pCurrentTopViewRung.GetSize().Height + rungoffset3 <= this.m_nLadderWindowTop)
- {
- if (this.m_pCurrentTopViewRung.Next() == null)
- break;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
- break;
- }
- this.GotoRung(this.m_pCurrentTopViewRung, rungoffset3);
- break;
- case ScrollEventType.LargeDecrement:
- if (this.m_pCurrentTopViewRung == null)
- break;
- if (this.m_nTopRungOffset != this.m_nLadderWindowTop)
- {
- this.GotoRung(this.m_pCurrentTopViewRung);
- break;
- }
- if (this.m_pCurrentTopViewRung.Previous() == null)
- break;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
- break;
- case ScrollEventType.LargeIncrement:
- if (this.m_pCurrentTopViewRung == null || this.m_pCurrentTopViewRung.Next() == null)
- break;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
- break;
- case ScrollEventType.ThumbPosition:
- this.GotoRungAt(index);
- break;
- case ScrollEventType.ThumbTrack:
- this.GotoRungAt(index);
- break;
- case ScrollEventType.First:
- this.GotoRung(this.GetFirstViewRung());
- break;
- case ScrollEventType.Last:
- this.GotoRung(this.GetLastViewRung());
- break;
- }
- }
- public void mHorizScrollBar_Scroll(object sender, ScrollEventArgs e)
- {
- int ladderWindowLeft = this.m_nLadderWindowLeft;
- int nScrollWidth = this.m_nScrollWidth;
- int num1 = nScrollWidth <= 10 ? 1 : nScrollWidth / 10;
- int num2 = nScrollWidth <= 100 ? 1 : nScrollWidth / 100;
- ScrollEventType type = e.Type;
- int newValue = e.NewValue;
- switch (type)
- {
- case ScrollEventType.SmallDecrement:
- this.m_nLadderWindowLeft += num2;
- if (this.m_nLadderWindowLeft > 0)
- {
- this.m_nLadderWindowLeft = 0;
- break;
- }
- break;
- case ScrollEventType.SmallIncrement:
- this.m_nLadderWindowLeft -= num2;
- if (this.m_nLadderWindowLeft < -nScrollWidth)
- {
- this.m_nLadderWindowLeft = -nScrollWidth;
- break;
- }
- break;
- case ScrollEventType.LargeDecrement:
- this.m_nLadderWindowLeft += num1;
- if (this.m_nLadderWindowLeft > 0)
- {
- this.m_nLadderWindowLeft = 0;
- break;
- }
- break;
- case ScrollEventType.LargeIncrement:
- this.m_nLadderWindowLeft -= num1;
- if (this.m_nLadderWindowLeft < -nScrollWidth)
- {
- this.m_nLadderWindowLeft = -nScrollWidth;
- break;
- }
- break;
- case ScrollEventType.ThumbPosition:
- this.m_nLadderWindowLeft = -newValue;
- break;
- case ScrollEventType.ThumbTrack:
- this.m_nLadderWindowLeft = -newValue;
- break;
- case ScrollEventType.First:
- this.m_nLadderWindowLeft = 0;
- break;
- case ScrollEventType.Last:
- this.m_nLadderWindowLeft = nScrollWidth;
- break;
- }
- if (ladderWindowLeft == this.m_nLadderWindowLeft)
- return;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- VwRc.Y += this.m_nLadderWindowTop;
- if (this._SetHorizScrollbarPos != null)
- this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
- this.OnSetRungPositions();
- this.Invalidate(VwRc);
- this.Refresh();
- }
- private bool OnScrollBy(Size sizeScroll)
- {
- bool flag1 = true;
- int nScrollWidth = this.m_nScrollWidth;
- bool flag2 = false;
- if (sizeScroll.Width != 0)
- {
- int num = nScrollWidth <= 100 ? 1 : nScrollWidth / 100;
- int nlines = sizeScroll.Width / num;
- if (nlines * num != sizeScroll.Width)
- {
- if (sizeScroll.Width < 0)
- --nlines;
- else
- ++nlines;
- }
- if (flag1)
- flag2 = nlines >= 0 ? this.OnHScrollLinesLeft(nlines) : this.OnHScrollLinesRight(-nlines);
- else if (nlines < 0)
- {
- if (this.m_nLadderWindowLeft > -nScrollWidth)
- flag2 = true;
- }
- else if (this.m_nLadderWindowLeft < 0)
- flag2 = true;
- }
- if (sizeScroll.Height != 0)
- {
- int nlines = sizeScroll.Height / this.m_Options.GetGridUnit().Height;
- if (nlines * this.m_Options.GetGridUnit().Height != sizeScroll.Height)
- {
- if (sizeScroll.Height < 0)
- --nlines;
- else
- ++nlines;
- }
- if (flag1)
- flag2 = nlines >= 0 ? this.OnVScrollLinesUp(nlines) : this.OnVScrollLinesDown(-nlines);
- else if (nlines < 0)
- {
- if (this.m_pCurrentTopViewRung.Next() != null)
- flag2 = true;
- }
- else if (this.m_pCurrentTopViewRung.Previous() != null || this.m_nTopRungOffset < this.m_nLadderWindowTop)
- flag2 = true;
- }
- return flag2;
- }
- public bool OnVScrollLinesDown(int nlines)
- {
- if (nlines <= 0)
- return false;
- int height = this.m_Options.GetGridUnit().Height;
- int num1 = 0;
- while (nlines-- > 0)
- {
- this.m_nTopRungOffset -= height;
- int num2 = -height;
- if (this.m_pCurrentTopViewRung.GetSize().Height + this.m_nTopRungOffset <= this.m_nLadderWindowTop)
- {
- if (this.m_pCurrentTopViewRung.Next() != null)
- {
- this.SetTopRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
- this.m_nTopRungOffset = this.m_nLadderWindowTop;
- }
- else
- {
- this.m_nTopRungOffset += height;
- num2 = 0;
- }
- }
- this.OnSetRungPositions();
- num1 += num2;
- }
- if (num1 == 0)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- this.Invalidate(VwRc);
- this.Refresh();
- if (this.m_pCurrentTopViewRung != null && this._SetVertScrollbarPos != null)
- this._SetVertScrollbarPos(this.m_pCurrentTopViewRung.GetRungNumber());
- return true;
- }
- public bool OnVScrollLinesUp(int nlines)
- {
- if (nlines <= 0)
- return false;
- int height = this.m_Options.GetGridUnit().Height;
- int num1 = 0;
- while (nlines-- > 0)
- {
- this.m_nTopRungOffset += height;
- int num2 = height;
- if (this.m_nTopRungOffset > this.m_nLadderWindowTop)
- {
- if (this.m_pCurrentTopViewRung.Previous() != null)
- {
- this.SetTopRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
- this.OnRefreshRung(this.m_pCurrentTopViewRung);
- this.m_nTopRungOffset = this.m_nLadderWindowTop - this.m_pCurrentTopViewRung.GetSize().Height;
- this.m_nTopRungOffset += height;
- }
- else
- {
- this.m_nTopRungOffset -= height;
- num2 = 0;
- }
- }
- this.OnSetRungPositions();
- num1 += num2;
- }
- if (num1 == 0)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- this.Invalidate(VwRc);
- this.Refresh();
- if (this.m_pCurrentTopViewRung != null && this._SetVertScrollbarPos != null)
- this._SetVertScrollbarPos(this.m_pCurrentTopViewRung.GetRungNumber());
- return true;
- }
- private bool OnHScrollLinesLeft(int nlines)
- {
- if (nlines <= 0)
- return false;
- int ladderWindowLeft = this.m_nLadderWindowLeft;
- int nScrollWidth = this.m_nScrollWidth;
- this.m_nLadderWindowLeft += (nScrollWidth <= 100 ? 1 : nScrollWidth / 100) * nlines;
- if (this.m_nLadderWindowLeft > 0)
- this.m_nLadderWindowLeft = 0;
- if (ladderWindowLeft == this.m_nLadderWindowLeft)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- VwRc.Y += this.m_nLadderWindowTop;
- if (this._SetHorizScrollbarPos != null)
- this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
- this.OnSetRungPositions();
- this.Invalidate(VwRc);
- this.Refresh();
- return true;
- }
- private bool OnHScrollLinesRight(int nlines)
- {
- if (nlines <= 0)
- return false;
- int ladderWindowLeft = this.m_nLadderWindowLeft;
- int nScrollWidth = this.m_nScrollWidth;
- this.m_nLadderWindowLeft -= (nScrollWidth <= 100 ? 1 : nScrollWidth / 100) * nlines;
- if (this.m_nLadderWindowLeft < -nScrollWidth)
- this.m_nLadderWindowLeft = -nScrollWidth;
- if (ladderWindowLeft == this.m_nLadderWindowLeft)
- return false;
- Rectangle VwRc;
- this.GetViewRect(out VwRc);
- VwRc.Y += this.m_nLadderWindowTop;
- if (this._SetHorizScrollbarPos != null)
- this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
- this.OnSetRungPositions();
- this.Invalidate(VwRc);
- this.Refresh();
- return true;
- }
- private void CloseEditWindows() => this.GetEditor().RemoveAllEditControls();
- private void OnRightButtonDown(Point pt)
- {
- this.CloseEditWindows();
- if (!this.IsEditable() || this.IsCompareView)
- return;
- this.contextMainMenu.Show((Control) this, pt);
- }
- private void OnMiddleButtonDown(Point pt) => this.CloseEditWindows();
- private void OnLeftButtonDown(Point pt)
- {
- if (!this.IsEditable())
- return;
- bool flag1 = this.SetCursor(pt);
- IRungViewElement pAtElementInRung = this.m_pCursorElement;
- CVRungdef pCursorRung = this.m_pCursorRung;
- IRungElement docrung = (IRungElement) null;
- if (pCursorRung != null)
- docrung = pCursorRung.GetRungElement();
- IRungElement rungelem = (IRungElement) null;
- if (pAtElementInRung != null)
- rungelem = pAtElementInRung.GetRungElement();
- this.CloseEditWindows();
- CRung crung = (CRung) null;
- if (this.m_pCursorRung != null)
- crung = (CRung) this.m_pCursorRung.GetRungElem();
- IRungElement rungElement = (IRungElement) null;
- if (this.m_pCursorElement != null)
- rungElement = this.m_pCursorElement.GetRungElement();
- if (crung != docrung || rungElement != rungelem)
- {
- CVRungdef viewRung = this.GetViewRung(docrung);
- if (viewRung != null)
- pAtElementInRung = viewRung.GetViewElement(rungelem);
- if (viewRung != null && pAtElementInRung != null)
- this.SetCursor(viewRung, pAtElementInRung);
- else if (viewRung != null)
- this.SetCursor(viewRung, (IRungViewElement) viewRung);
- }
- if (!flag1)
- return;
- Keys modifierKeys = Control.ModifierKeys;
- bool flag2 = false;
- if (modifierKeys == Keys.Shift)
- flag2 = true;
- bool flag3 = false;
- if (modifierKeys == Keys.Control)
- flag3 = true;
- if (!flag2 && !flag3)
- this.m_pCursorElement.GetRungElement()?.IsBranch();
- this.m_DragStartPoint = pt;
- }
- private void OnLeftButtonUp(Point pt)
- {
- if (!this.IsEditable())
- return;
- if (this.m_nLeftMouseButUpActionToDo == 1)
- {
- this.ClearAllSelections();
- this.m_nLeftMouseButUpActionToDo = 0;
- }
- else
- {
- if (this.m_nLeftMouseButUpActionToDo != 2)
- return;
- this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
- this.ClearAnchor();
- this.m_nLeftMouseButUpActionToDo = 0;
- }
- }
- private void MoveCursorHome() => this.SetCursor(this.m_pCursorRung, (IRungViewElement) this.m_pCursorRung);
- private void MoveCursorEnd()
- {
- if (this.m_pCursorRung == null)
- return;
- this.SetCursor(this.m_pCursorRung, this.m_pCursorRung.GetCursorLast(this));
- }
- private void MoveCursorToRung(int nRungNum) => this.MoveCursorToRung(this.GetViewRung(nRungNum));
- private void MoveCursorToRung(CVRungdef pRung)
- {
- if (pRung == null)
- return;
- this.GotoRung(pRung);
- Keys modifierKeys = Control.ModifierKeys;
- bool flag = false;
- if (modifierKeys == Keys.Shift)
- flag = true;
- if (flag)
- this.SetCursorAndSelect(pRung, (IRungViewElement) pRung);
- else
- this.SetCursor(pRung, (IRungViewElement) pRung);
- }
- private void GotoRungNumber(int rungNumber) => this.GotoRung(this.GetViewRung(rungNumber));
- private void GotoRungAt(int index) => this.GotoRung(this.GetViewRungAt(index));
- public void GotoNextRung()
- {
- if (this.m_pCurrentTopViewRung == null || this.m_pCurrentTopViewRung.Next() == null)
- return;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
- }
- public void GotoPrevRung()
- {
- if (this.m_pCurrentTopViewRung == null)
- return;
- if (this.m_nTopRungOffset != this.m_nLadderWindowTop)
- {
- this.GotoRung(this.m_pCurrentTopViewRung);
- }
- else
- {
- if (this.m_pCurrentTopViewRung.Previous() == null)
- return;
- this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
- }
- }
- private void GotoRung(CVRungdef ToRung, int rungoffset)
- {
- if (ToRung == null)
- return;
- int rungNumber = ToRung.GetRungNumber();
- CVRungdef pVRung = ToRung.IsBlankRung || rungNumber == -1 ? ToRung : this.GetViewRung(rungNumber);
- if (pVRung == null)
- return;
- this.SetTopRung(pVRung);
- this.m_nTopRungOffset = rungoffset;
- this.OnSetRungPositions();
- this.Refresh();
- if (this._SetVertScrollbarPos == null)
- return;
- this._SetVertScrollbarPos(rungNumber);
- }
- private void GotoRung(CVRungdef ToRung) => this.GotoRung(ToRung, this.m_nLadderWindowTop);
- private CVRungdef GetLastViewRung() => this.m_Rungs != null && this.m_Rungs.Count > 0 ? (CVRungdef) this.m_Rungs[this.m_Rungs.Count - 1] : (CVRungdef) null;
- private CVRungdef GetFirstViewRung() => this.m_Rungs != null && this.m_Rungs.Count > 0 ? (CVRungdef) this.m_Rungs[0] : (CVRungdef) null;
- private CVRungdef GetViewRung(int rungnumber)
- {
- if (this.m_Rungs != null)
- {
- foreach (CVRungdef rung in this.m_Rungs)
- {
- if (rung.GetRungNumber() == rungnumber)
- return rung;
- }
- }
- return (CVRungdef) null;
- }
- private CVRungdef GetViewRungAt(int index)
- {
- if (this.m_Rungs == null)
- return (CVRungdef) null;
- return this.m_Rungs.Count > index ? (CVRungdef) this.m_Rungs[index] : (CVRungdef) this.m_Rungs[this.m_Rungs.Count - 1];
- }
- private void MoveCursorLastRung() => this.MoveCursorToRung(this.GetLastViewRung());
- private void MoveCursorFirstRung() => this.MoveCursorToRung(this.GetFirstViewRung());
- private void MoveCursorLeft()
- {
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- {
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorRung.MatchingViewRung != null)
- this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
- }
- if (this.m_pCursorElement == null)
- return;
- IRungViewElement cursorLeft = this.m_pCursorElement.GetCursorLeft(this);
- if (cursorLeft != null)
- {
- this.SetCursorAndSelect(this.m_pCursorRung, cursorLeft);
- }
- else
- {
- if (this.m_pCursorRung == null || this.m_pCursorRung.Previous() == null)
- return;
- this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Previous(), this.m_pCursorRung.Previous().GetCursorLast(this));
- }
- }
- private void MoveCursorRight()
- {
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- {
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorRung.MatchingViewRung != null)
- this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
- }
- if (this.m_pCursorElement == null)
- return;
- IRungViewElement cursorRight = this.m_pCursorElement.GetCursorRight(this);
- if (cursorRight != null)
- {
- this.SetCursorAndSelect(this.m_pCursorRung, cursorRight);
- }
- else
- {
- if (this.m_pCursorRung == null || this.m_pCursorRung.Next() == null)
- return;
- this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Next(), this.m_pCursorRung.Next());
- }
- }
- private void MoveCursorUp()
- {
- if (this.m_pCursorElement == null)
- return;
- IRungViewElement cursorUp = this.m_pCursorElement.GetCursorUp(this);
- if (cursorUp != null)
- {
- if (cursorUp == this.m_pCursorElement)
- this.m_pCursorElement.MoveCursorUp(this);
- else
- this.SetCursorAndSelect(this.m_pCursorRung, cursorUp);
- }
- else
- {
- if (this.m_pCursorRung == null || this.m_pCursorRung.Previous() == null)
- return;
- this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Previous(), this.m_pCursorRung.Previous());
- }
- }
- private void MoveCursorDown()
- {
- if (this.m_pCursorElement == null)
- return;
- IRungViewElement cursorDown = this.m_pCursorElement.GetCursorDown(this);
- if (cursorDown != null)
- {
- if (cursorDown == this.m_pCursorElement)
- this.m_pCursorElement.MoveCursorDown(this);
- else
- this.SetCursorAndSelect(this.m_pCursorRung, cursorDown);
- }
- else
- {
- if (this.m_pCursorRung == null || this.m_pCursorRung.Next() == null)
- return;
- this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Next(), this.m_pCursorRung.Next());
- }
- }
- private bool MoveCursorPrevOperand()
- {
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorElement != null && this.m_pCursorElement.IsInstruction() && this.m_pCursorElement.MovePrevOpndField(this))
- return true;
- IRungViewElement pAtElementInRung = (IRungViewElement) null;
- if (this.m_pCursorElement != null)
- pAtElementInRung = this.m_pCursorElement.GetCursorPrevious(this);
- CVRungdef cvRungdef = this.m_pCursorRung;
- while (cvRungdef != null)
- {
- while (pAtElementInRung != null && !pAtElementInRung.IsInstruction())
- pAtElementInRung = pAtElementInRung.GetCursorPrevious(this);
- if (pAtElementInRung != null)
- {
- this.SetCursor(cvRungdef, pAtElementInRung);
- if (this.m_pCursorElement != null)
- this.m_pCursorElement.SetLastOpndField(this);
- return true;
- }
- if (cvRungdef.Previous() != null)
- {
- cvRungdef = (CVRungdef) cvRungdef.Previous();
- this.OnRefreshRung(cvRungdef);
- pAtElementInRung = cvRungdef.GetCursorLast(this);
- }
- else
- break;
- }
- return false;
- }
- private bool MoveCursorNextOperand()
- {
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- if (this.m_pCursorElement != null && this.m_pCursorElement.IsInstruction() && this.m_pCursorElement.MoveNextOpndField(this))
- return true;
- IRungViewElement pAtElementInRung = (IRungViewElement) null;
- if (this.m_pCursorElement != null)
- pAtElementInRung = this.m_pCursorElement.GetCursorNext(this);
- CVRungdef cvRungdef = this.m_pCursorRung;
- while (cvRungdef != null)
- {
- while (pAtElementInRung != null && !pAtElementInRung.IsInstruction())
- pAtElementInRung = pAtElementInRung.GetCursorNext(this);
- if (pAtElementInRung != null)
- {
- this.SetCursor(cvRungdef, pAtElementInRung);
- return true;
- }
- if (cvRungdef.Next() != null)
- {
- cvRungdef = (CVRungdef) cvRungdef.Next();
- this.OnRefreshRung(cvRungdef);
- pAtElementInRung = (IRungViewElement) cvRungdef;
- }
- else
- break;
- }
- return false;
- }
- public LadderViewEditClass GetEditor() => this.mTheEditor;
- private void OnEditIns()
- {
- if (this.m_pCursorElement == null && this.m_pCursorRung == null)
- return;
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- this.m_pCursorElement.Edit(this, "");
- }
- private void EditIns(char nCharPressed)
- {
- if (this.m_pCursorElement == null && this.m_pCursorRung == null)
- return;
- if (!this.IsRungOnScreen(this.m_pCursorRung))
- this.GotoRung(this.m_pCursorRung);
- this.m_pCursorElement.Edit(this, nCharPressed.ToString());
- }
- private void CLadderView_DoubleClick(object sender, EventArgs e) => this.OnEditIns();
- private void CLadderView_Enter(object sender, EventArgs e)
- {
- this.Focus();
- this.m_bHaveFocus = true;
- this.Refresh();
- }
- private void CLadderView_Leave(object sender, EventArgs e)
- {
- this.m_bHaveFocus = false;
- this.Refresh();
- }
- private void CLadderView_SizeChanged(object sender, EventArgs e) => this.OnSizeChanged();
- public bool CanViewZoomIn() => (double) (this.m_Options.LadderInstructionFont.Size + 0.5f) <= 20.0;
- public bool CanViewZoomOut() => (double) (this.m_Options.LadderInstructionFont.Size - 0.5f) > 0.0;
- public void OnZoomIn()
- {
- Font ladderInstructionFont = this.m_Options.LadderInstructionFont;
- float emSize = ladderInstructionFont.Size + 0.5f;
- if ((double) emSize > 20.0)
- return;
- this.m_Options.LadderInstructionFont = new Font(ladderInstructionFont.FontFamily, emSize, ladderInstructionFont.Style);
- this.ResetView();
- }
- public void OnZoomOut()
- {
- Font ladderInstructionFont = this.m_Options.LadderInstructionFont;
- float emSize = ladderInstructionFont.Size - 0.5f;
- if ((double) emSize <= 0.0)
- return;
- this.m_Options.LadderInstructionFont = new Font(ladderInstructionFont.FontFamily, emSize, ladderInstructionFont.Style);
- this.ResetView();
- }
- public void SetControllerVersion(string sVersion)
- {
- if (this.m_Controller == null)
- return;
- this.m_Controller.SetMajorRevision(sVersion);
- }
- private struct PrintPageInfo
- {
- public CVRungdef StartRung;
- public CVRungdef EndRung;
- public Rectangle ClipRect;
- public int TopRungOffset;
- public int RungCount
- {
- get
- {
- int rungCount = 1;
- IRungViewElement rungViewElement = (IRungViewElement) this.StartRung;
- while (rungViewElement != this.EndRung)
- {
- rungViewElement = rungViewElement.Next();
- ++rungCount;
- }
- return rungCount;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement