Advertisement
Guest User

CLadderView

a guest
Dec 16th, 2023
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 74.69 KB | Source Code | 0 0
  1. using InstructionElementsClass;
  2. using System;
  3. using System.Collections;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.Windows.Forms;
  8. using System.Xml;
  9.  
  10. namespace LadderView
  11. {
  12.   public class CLadderView : Control
  13.   {
  14.     private static int viewID = 0;
  15.     private static bool compareSynro;
  16.     private bool printing;
  17.     private Rectangle page1PrintRect;
  18.     private Rectangle page2PrintRect;
  19.     private int currentPage = -1;
  20.     private Graphics printerGraphics;
  21.     private CLadderView.PrintPageInfo[] printPages;
  22.     private bool isCompareView;
  23.     private bool printDiffRungsOnly;
  24.     private LadderRoutine m_pRoutine;
  25.     private ProgramClass m_pProgram;
  26.     private ProgramHolder m_pProgholder;
  27.     private Controller m_Controller;
  28.     private SetHorizScrollbarPos _SetHorizScrollbarPos;
  29.     private SetVertScrollbarPos _SetVertScrollbarPos;
  30.     private SetHorizScrollbarRange _SetHorizScrollbarRange;
  31.     private SetVertScrollbarRange _SetVertScrollbarRange;
  32.     private ViewPropertiesSetup _ViewPropertiesSetup;
  33.     private ArrayList m_AddrTagsForUpdating;
  34.     private ArrayList m_Rungs;
  35.     private CVRungdef m_pFirstViewRung;
  36.     private CVRungdef m_pCurrentTopViewRung;
  37.     private CVRungdef m_pCursorRung;
  38.     private IRungViewElement m_pCursorElement;
  39.     private bool m_bHaveFocus;
  40.     private CVRungdef m_pSelectedRung;
  41.     private IRungViewElement m_pAnchorElem;
  42.     private CVRungdef m_pAnchorRung;
  43.     private ArrayList m_SelectedList;
  44.     private CViewOptionsdef m_Options;
  45.     private int m_nScrollWidth;
  46.     private int m_nLadderWindowLeft;
  47.     private int m_nLadderWindowTop;
  48.     private int m_nTopRungOffset;
  49.     private int m_nWidth;
  50.     private int m_nLeftMouseButUpActionToDo;
  51.     private CLadderView m_MatchingView;
  52.     private int id;
  53.     private Point m_DragStartPoint = Point.Empty;
  54.     private MenuItem menuItem1;
  55.     private MenuItem menuItem2;
  56.     private MenuItem menuItem3;
  57.     private MenuItem menuItem4;
  58.     private ContextMenu contextMainMenu;
  59.     private LadderViewEditClass mTheEditor;
  60.  
  61.     public event RoutineChangedCb RoutineChangedHook;
  62.  
  63.     public CLadderView MatchingView
  64.     {
  65.       get => this.m_MatchingView;
  66.       set
  67.       {
  68.         this.m_MatchingView = value;
  69.         if (this.m_MatchingView == null)
  70.           return;
  71.         for (int index = 0; index < this.m_pRoutine.GetRungCount(); ++index)
  72.         {
  73.           CRung rungAt = this.m_pRoutine.GetRungAt(index);
  74.           if (rungAt != null)
  75.             rungAt.MatchingRoutine = this.m_MatchingView.LadderRoutine;
  76.         }
  77.         for (int index = 0; index < this.m_Rungs.Count; ++index)
  78.         {
  79.           CVRungdef rung = (CVRungdef) this.m_Rungs[index];
  80.           if (rung != null && rung.GetRungElement() is CRung rungElement && rungElement.MatchingRung != null)
  81.             rung.MatchingViewRung = this.m_MatchingView.GetViewRung(rungElement.MatchingRung.RungNumber);
  82.         }
  83.       }
  84.     }
  85.  
  86.     public LadderRoutine LadderRoutine => this.m_pRoutine;
  87.  
  88.     public bool IsPrinting => this.printing;
  89.  
  90.     public Graphics PrinterGraphics
  91.     {
  92.       get => this.printerGraphics;
  93.       set => this.printerGraphics = value;
  94.     }
  95.  
  96.     public int CurrentPage => this.IsPrinting ? this.currentPage : -1;
  97.  
  98.     public int PageCount => this.printPages != null ? this.printPages.Length : -1;
  99.  
  100.     public bool IsCompareView
  101.     {
  102.       get => this.isCompareView;
  103.       set => this.isCompareView = value;
  104.     }
  105.  
  106.     public CLadderView()
  107.     {
  108.       this.InitializeComponent();
  109.       this.id = CLadderView.viewID++;
  110.       this.SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true);
  111.       this.ResizeRedraw = true;
  112.       this.m_SelectedList = new ArrayList();
  113.       this.m_Options = new CViewOptionsdef();
  114.       this.m_Options.LadderInstructionFont = this.Font;
  115.       this.mTheEditor = new LadderViewEditClass(this);
  116.     }
  117.  
  118.     ~CLadderView() => this.FreeRungInfo();
  119.  
  120.     public void HookHorizScrollBarPos(SetHorizScrollbarPos theSetHorizScrollbarPos) => this._SetHorizScrollbarPos = theSetHorizScrollbarPos;
  121.  
  122.     public void HookVertScrollBarPos(SetVertScrollbarPos theSetVertScrollBarPos) => this._SetVertScrollbarPos = theSetVertScrollBarPos;
  123.  
  124.     public void HookHorizScrollBarRange(SetHorizScrollbarRange theSetHorizScrollbarRange) => this._SetHorizScrollbarRange = theSetHorizScrollbarRange;
  125.  
  126.     public void HookVertScrollBarRange(SetVertScrollbarRange theSetVertScrollbarRange) => this._SetVertScrollbarRange = theSetVertScrollbarRange;
  127.  
  128.     public void HookViewPropertiesSetup(ViewPropertiesSetup theViewPropertiesSetup) => this._ViewPropertiesSetup = theViewPropertiesSetup;
  129.  
  130.     public bool ScrollToNextDifference()
  131.     {
  132.       if (this.m_pCurrentTopViewRung != null && this.m_pCurrentTopViewRung.NextDifferenceRung != null)
  133.       {
  134.         CVRungdef nextDifferenceRung = this.m_pCurrentTopViewRung.NextDifferenceRung as CVRungdef;
  135.         this.GotoRung(nextDifferenceRung);
  136.         if (nextDifferenceRung.NextDifferenceRung != null)
  137.           return true;
  138.       }
  139.       return false;
  140.     }
  141.  
  142.     public bool ScrollToPreviousDifference()
  143.     {
  144.       if (this.m_pCurrentTopViewRung != null && this.m_pCurrentTopViewRung.PreviousDifferenceRung != null)
  145.       {
  146.         CVRungdef previousDifferenceRung = this.m_pCurrentTopViewRung.PreviousDifferenceRung as CVRungdef;
  147.         this.GotoRung(previousDifferenceRung);
  148.         if (previousDifferenceRung.PreviousDifferenceRung != null)
  149.           return true;
  150.       }
  151.       return false;
  152.     }
  153.  
  154.     protected override void OnPaint(PaintEventArgs pe)
  155.     {
  156.       this.OnDrawRungs(pe.Graphics, pe.ClipRectangle);
  157.       base.OnPaint(pe);
  158.     }
  159.  
  160.     private void InitializeComponent()
  161.     {
  162.       this.menuItem1 = new MenuItem();
  163.       this.menuItem2 = new MenuItem();
  164.       this.menuItem3 = new MenuItem();
  165.       this.menuItem4 = new MenuItem();
  166.       this.contextMainMenu = new ContextMenu();
  167.       this.menuItem1.Index = -1;
  168.       this.menuItem1.Text = "Properties";
  169.       this.menuItem1.Click += new EventHandler(this.Properties_Click);
  170.       this.menuItem2.Index = -1;
  171.       this.menuItem2.Text = "-";
  172.       this.menuItem3.Index = -1;
  173.       this.menuItem3.Text = "Assemble Edits";
  174.       this.menuItem4.Index = -1;
  175.       this.menuItem4.Text = "Cancel Edits";
  176.       this.contextMainMenu.MenuItems.AddRange(new MenuItem[4]
  177.       {
  178.         this.menuItem1,
  179.         this.menuItem2,
  180.         this.menuItem3,
  181.         this.menuItem4
  182.       });
  183.       this.AllowDrop = false;
  184.       this.BackColor = SystemColors.Window;
  185.       this.CausesValidation = false;
  186.       this.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, (byte) 0);
  187.       this.ForeColor = SystemColors.WindowText;
  188.       this.KeyPress += new KeyPressEventHandler(this.CLadderView_OnKeyPress);
  189.       this.Click += new EventHandler(this.CLadderView_Enter);
  190.       this.SizeChanged += new EventHandler(this.CLadderView_SizeChanged);
  191.       this.Enter += new EventHandler(this.CLadderView_Enter);
  192.       this.MouseUp += new MouseEventHandler(this.CLadderView_MouseUp);
  193.       this.KeyUp += new KeyEventHandler(this.CLadderView_KeyUp);
  194.       this.KeyDown += new KeyEventHandler(this.CLadderView_KeyDown);
  195.       this.DoubleClick += new EventHandler(this.CLadderView_DoubleClick);
  196.       this.MouseMove += new MouseEventHandler(this.CLadderView_MouseMove);
  197.       this.MouseDown += new MouseEventHandler(this.CLadderView_MouseDown);
  198.       this.Leave += new EventHandler(this.CLadderView_Leave);
  199.     }
  200.  
  201.     private void CLadderView_MouseDown(object sender, MouseEventArgs e)
  202.     {
  203.       if (!this.Focused)
  204.         this.Focus();
  205.       Point empty = Point.Empty with
  206.       {
  207.         X = e.X,
  208.         Y = e.Y
  209.       };
  210.       switch (e.Button)
  211.       {
  212.         case MouseButtons.Left:
  213.           this.OnLeftButtonDown(empty);
  214.           break;
  215.         case MouseButtons.Right:
  216.           this.OnRightButtonDown(empty);
  217.           break;
  218.         case MouseButtons.Middle:
  219.           this.OnMiddleButtonDown(empty);
  220.           break;
  221.       }
  222.     }
  223.  
  224.     private void CLadderView_MouseMove(object sender, MouseEventArgs e)
  225.     {
  226.     }
  227.  
  228.     private void CLadderView_MouseUp(object sender, MouseEventArgs e)
  229.     {
  230.       Point empty = Point.Empty with
  231.       {
  232.         X = e.X,
  233.         Y = e.Y
  234.       };
  235.       if (e.Button != MouseButtons.Left)
  236.         return;
  237.       this.OnLeftButtonUp(empty);
  238.     }
  239.  
  240.     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);
  241.  
  242.     private void CLadderView_KeyDown(object sender, KeyEventArgs e)
  243.     {
  244.       Keys modifiers = e.Modifiers;
  245.       bool flag1 = false;
  246.       if (modifiers == Keys.Shift)
  247.         flag1 = true;
  248.       bool flag2 = false;
  249.       if (modifiers == Keys.Control)
  250.         flag2 = true;
  251.       switch (e.KeyCode)
  252.       {
  253.         case Keys.Tab:
  254.           if (flag1)
  255.             break;
  256.           this.MoveCursorNextOperand();
  257.           break;
  258.         case Keys.Return:
  259.           if (!this.IsEditable())
  260.             break;
  261.           this.OnEditIns();
  262.           break;
  263.         case Keys.Prior:
  264.           if (flag2)
  265.           {
  266.             this.GotoPrevProgFile();
  267.             break;
  268.           }
  269.           this.GotoPrevRung();
  270.           if (this.MatchingView == null)
  271.             break;
  272.           this.MatchingView.GotoPrevRung();
  273.           break;
  274.         case Keys.Next:
  275.           if (flag2)
  276.           {
  277.             this.GotoNextProgFile();
  278.             break;
  279.           }
  280.           this.GotoNextRung();
  281.           if (this.MatchingView == null)
  282.             break;
  283.           this.MatchingView.GotoNextRung();
  284.           break;
  285.         case Keys.End:
  286.           if (flag2)
  287.           {
  288.             this.MoveCursorLastRung();
  289.             break;
  290.           }
  291.           this.MoveCursorEnd();
  292.           break;
  293.         case Keys.Home:
  294.           if (flag2)
  295.           {
  296.             this.MoveCursorFirstRung();
  297.             break;
  298.           }
  299.           this.MoveCursorHome();
  300.           break;
  301.         case Keys.Left:
  302.           this.MoveCursorLeft();
  303.           break;
  304.         case Keys.Up:
  305.           this.MoveCursorUp();
  306.           if (this.MatchingView == null)
  307.             break;
  308.           this.MatchingView.MoveCursorUp();
  309.           break;
  310.         case Keys.Right:
  311.           this.MoveCursorRight();
  312.           break;
  313.         case Keys.Down:
  314.           this.MoveCursorDown();
  315.           break;
  316.       }
  317.     }
  318.  
  319.     public void CLadderView_OnKeyPress(object sender, KeyPressEventArgs e)
  320.     {
  321.       if (!this.IsEditable())
  322.         return;
  323.       char keyChar = e.KeyChar;
  324.       if (keyChar == '/')
  325.       {
  326.         this.MoveCursorHome();
  327.         this.OnEditIns();
  328.       }
  329.       else
  330.       {
  331.         if (char.IsControl(keyChar))
  332.           return;
  333.         this.EditIns(e.KeyChar);
  334.       }
  335.     }
  336.  
  337.     private void CLadderView_KeyUp(object sender, KeyEventArgs e)
  338.     {
  339.       Keys modifiers = e.Modifiers;
  340.       bool flag = false;
  341.       if (modifiers == Keys.Shift)
  342.         flag = true;
  343.       if (e.KeyCode != Keys.Tab || !flag)
  344.         return;
  345.       this.MoveCursorPrevOperand();
  346.     }
  347.  
  348.     public CViewOptionsdef GetViewOptions() => this.m_Options;
  349.  
  350.     public void SetViewOptions(CViewOptionsdef options)
  351.     {
  352.       this.m_Options = options;
  353.       this.ResetView();
  354.     }
  355.  
  356.     public IRungViewElement GetCurrentCursorElement() => !this.m_bHaveFocus ? (IRungViewElement) null : this.m_pCursorElement;
  357.  
  358.     public bool IsItemSelected(IRungViewElement theItem)
  359.     {
  360.       if (!this.m_bHaveFocus)
  361.         return false;
  362.       foreach (IRungViewElement selected in this.m_SelectedList)
  363.       {
  364.         if (selected == theItem)
  365.           return true;
  366.       }
  367.       return false;
  368.     }
  369.  
  370.     public void SetUserXmlProject(
  371.       XmlNode ladderXml,
  372.       XmlNode programTagsXml,
  373.       XmlNode globalTagsXml,
  374.       bool bBase,
  375.       string sDocumentationLanguage)
  376.     {
  377.       this.SetUserXmlProject(ladderXml, programTagsXml, globalTagsXml, false, bBase, sDocumentationLanguage);
  378.     }
  379.  
  380.     public void SetUserXmlProject(
  381.       XmlNode ladderXml,
  382.       XmlNode programTagsXml,
  383.       XmlNode globalTagsXml,
  384.       bool delayRefresh,
  385.       bool bBase,
  386.       string sDocumentationLanguage)
  387.     {
  388.       LadderRoutine progfile = new LadderRoutine();
  389.       progfile.m_bBase = bBase;
  390.       progfile.SetController(this.m_Controller);
  391.       progfile.FromXML(ladderXml);
  392.       TagSymbolClass data1 = new TagSymbolClass();
  393.       data1.LoadXML(globalTagsXml, sDocumentationLanguage);
  394.       TagSymbolClass data2 = new TagSymbolClass();
  395.       data2.LoadXML(programTagsXml, sDocumentationLanguage);
  396.       progfile.SetGlobalTags(data1);
  397.       progfile.SetProgramTags(data2);
  398.       this.SetUserRoutine(progfile);
  399.     }
  400.  
  401.     public void SetUserXmlProject(
  402.       XmlNode ladderXml,
  403.       XmlNode programTagsXml,
  404.       XmlNode globalTagsXml,
  405.       bool delayRefresh,
  406.       bool bBase,
  407.       string sDocumentationLanguage,
  408.       bool isOnly)
  409.     {
  410.       LadderRoutine progfile = new LadderRoutine();
  411.       progfile.m_bBase = bBase;
  412.       progfile.SetController(this.m_Controller);
  413.       progfile.FromXML_ForBaseCompareOnly(ladderXml);
  414.       TagSymbolClass data1 = new TagSymbolClass();
  415.       data1.LoadXML(globalTagsXml, sDocumentationLanguage);
  416.       TagSymbolClass data2 = new TagSymbolClass();
  417.       data2.LoadXML(programTagsXml, sDocumentationLanguage);
  418.       progfile.SetGlobalTags(data1);
  419.       progfile.SetProgramTags(data2);
  420.       this.SetUserRoutine(progfile);
  421.     }
  422.  
  423.     public void SetUserXMLFile(string filename)
  424.     {
  425.       LadderRoutine progfile = new LadderRoutine();
  426.       progfile.SetController(this.m_Controller);
  427.       progfile.FromXMLFile(filename);
  428.       this.SetFile(progfile);
  429.       this.RoutineHasChanged();
  430.     }
  431.  
  432.     public void SetUserXMLProgram(string xml)
  433.     {
  434.       LadderRoutine progfile = new LadderRoutine();
  435.       progfile.SetController(this.m_Controller);
  436.       progfile.FromXML(xml);
  437.       this.SetFile(progfile);
  438.       this.RoutineHasChanged();
  439.     }
  440.  
  441.     public void SetControllerFamily(string ControllerFamily)
  442.     {
  443.       if (this.m_Controller == null)
  444.         this.m_Controller = new Controller();
  445.       this.m_Controller.SetFamily(ControllerFamily);
  446.     }
  447.  
  448.     public void LegNeutralTextToXmlWriter(string neutralText, XmlWriter writer)
  449.     {
  450.       LadderRoutine ladderRoutine = new LadderRoutine();
  451.       ladderRoutine.SetController(this.m_Controller);
  452.       ladderRoutine.LegNeutralTextToXmlWriter(neutralText, writer);
  453.     }
  454.  
  455.     public void ExpandLegNeutralTextToXml(string neutralText, XmlWriter writer)
  456.     {
  457.       LadderRoutine ladderRoutine = new LadderRoutine();
  458.       ladderRoutine.SetController(this.m_Controller);
  459.       ladderRoutine.ExpandLegNeutralTextToXml(neutralText, writer);
  460.     }
  461.  
  462.     public void ExpandLegNeutralTextToXml(XmlNode textNode, out XmlNode legNode)
  463.     {
  464.       LadderRoutine ladderRoutine = new LadderRoutine();
  465.       ladderRoutine.SetController(this.m_Controller);
  466.       ladderRoutine.ExpandLegNeutralTextToXml(textNode, out legNode);
  467.     }
  468.  
  469.     public void SetUserRoutine(LadderRoutine progfile)
  470.     {
  471.       this.SetFile(progfile);
  472.       this.RoutineHasChanged();
  473.     }
  474.  
  475.     public void SetUserMainProgram(ProgramHolder progholder)
  476.     {
  477.       this.m_pProgholder = progholder;
  478.       this.GotoFirstProgFile();
  479.       this.RoutineHasChanged();
  480.     }
  481.  
  482.     private void RoutineHasChanged()
  483.     {
  484.       if (this.RoutineChangedHook == null)
  485.         return;
  486.       foreach (RoutineChangedCb invocation in this.RoutineChangedHook.GetInvocationList())
  487.         invocation();
  488.     }
  489.  
  490.     public string GetProgramRoutineTitle()
  491.     {
  492.       if (this.m_pProgholder == null || this.m_pRoutine == null)
  493.         return "";
  494.       string str1 = "Routine-> " + this.m_pRoutine.GetName() + " - " + this.m_pRoutine.GetDescription() + "  Total rungs = " + this.m_pRoutine.GetRungCount().ToString();
  495.       string str2 = "";
  496.       if (this.m_pProgram != null)
  497.         str2 = "Program-> " + this.m_pProgram.GetName() + " - " + this.m_pProgram.GetDescription() + "  Total Routines = " + this.m_pProgram.GetRoutineCount().ToString();
  498.       return str2 + " : " + str1;
  499.     }
  500.  
  501.     private void GotoFirstProgFile()
  502.     {
  503.       if (this.m_pProgholder == null)
  504.         return;
  505.       int num1 = 0;
  506.       int num2 = 0;
  507.       ProgramHolder pProgholder = this.m_pProgholder;
  508.       int index = num1;
  509.       int num3 = index + 1;
  510.       ProgramClass program = pProgholder.GetProgram(index);
  511.       bool flag = false;
  512.       for (; program != null; program = this.m_pProgholder.GetProgram(num3++))
  513.       {
  514.         for (IRoutine routine = program.GetRoutine(num2++); routine != null; routine = program.GetRoutine(num2++))
  515.         {
  516.           if (routine != null && routine.GetRoutineType() == "Ladder")
  517.           {
  518.             this.SetFile((LadderRoutine) routine);
  519.             flag = true;
  520.             break;
  521.           }
  522.         }
  523.         if (flag)
  524.         {
  525.           this.m_pProgram = program;
  526.           break;
  527.         }
  528.       }
  529.     }
  530.  
  531.     public void GotoPrevProgFile()
  532.     {
  533.       if (this.m_pProgholder == null)
  534.         return;
  535.       int num1 = 0;
  536.       if (this.m_pProgram != null)
  537.         num1 = this.m_pProgholder.GetProgramFileIndex(this.m_pProgram) - 1;
  538.       int num2 = 0;
  539.       ProgramClass programClass = this.m_pProgram;
  540.       if (this.m_pRoutine != null)
  541.       {
  542.         int routineFileIndex = programClass.GetRoutineFileIndex((IRoutine) this.m_pRoutine);
  543.         if (routineFileIndex == 0)
  544.         {
  545.           programClass = this.m_pProgholder.GetProgram(num1--);
  546.           if (programClass == null)
  547.             return;
  548.           num2 = programClass.GetRoutineCount() - 1;
  549.         }
  550.         else
  551.           num2 = routineFileIndex - 1;
  552.       }
  553.       if (num2 == -1)
  554.         num2 = programClass.GetRoutineCount() - 1;
  555.       bool flag = false;
  556.       while (programClass != null)
  557.       {
  558.         for (IRoutine routine = programClass.GetRoutine(num2--); routine != null; routine = programClass.GetRoutine(num2--))
  559.         {
  560.           if (routine != null && routine.GetRoutineType() == "Ladder")
  561.           {
  562.             this.SetFile((LadderRoutine) routine);
  563.             flag = true;
  564.             break;
  565.           }
  566.         }
  567.         if (flag)
  568.         {
  569.           this.m_pProgram = programClass;
  570.           break;
  571.         }
  572.         programClass = this.m_pProgholder.GetProgram(num1--);
  573.         if (programClass != null)
  574.           num2 = programClass.GetRoutineCount() - 1;
  575.       }
  576.       if (!flag)
  577.         return;
  578.       this.RoutineHasChanged();
  579.     }
  580.  
  581.     public void GotoNextProgFile()
  582.     {
  583.       if (this.m_pProgholder == null)
  584.         return;
  585.       int num1 = 0;
  586.       if (this.m_pProgram != null)
  587.         num1 = this.m_pProgholder.GetProgramFileIndex(this.m_pProgram) + 1;
  588.       int num2 = 0;
  589.       ProgramClass programClass1 = this.m_pProgram;
  590.       if (this.m_pRoutine != null)
  591.       {
  592.         int routineFileIndex = programClass1.GetRoutineFileIndex((IRoutine) this.m_pRoutine);
  593.         if (routineFileIndex >= programClass1.GetRoutineCount())
  594.         {
  595.           programClass1 = this.m_pProgholder.GetProgram(num1++);
  596.           if (programClass1 == null)
  597.             return;
  598.           num2 = 0;
  599.         }
  600.         else
  601.           num2 = routineFileIndex + 1;
  602.       }
  603.       if (num2 == -1)
  604.         num2 = 0;
  605.       bool flag = false;
  606.       while (programClass1 != null)
  607.       {
  608.         ProgramClass programClass2 = programClass1;
  609.         int index = num2;
  610.         int num3 = index + 1;
  611.         for (IRoutine routine = programClass2.GetRoutine(index); routine != null; routine = programClass1.GetRoutine(num3++))
  612.         {
  613.           if (routine != null && routine.GetRoutineType() == "Ladder")
  614.           {
  615.             this.SetFile((LadderRoutine) routine);
  616.             flag = true;
  617.             break;
  618.           }
  619.         }
  620.         if (flag)
  621.         {
  622.           this.m_pProgram = programClass1;
  623.           break;
  624.         }
  625.         programClass1 = this.m_pProgholder.GetProgram(num1++);
  626.         num2 = 0;
  627.       }
  628.       if (!flag)
  629.         return;
  630.       this.RoutineHasChanged();
  631.     }
  632.  
  633.     private void FreeRungInfo()
  634.     {
  635.       if (this.m_Rungs != null)
  636.       {
  637.         for (int index = 0; index < this.m_Rungs.Count; ++index)
  638.         {
  639.           CVRungdef rung = (CVRungdef) this.m_Rungs[index];
  640.           if (rung != null)
  641.           {
  642.             rung.SetNext((IRungViewElement) null);
  643.             rung.SetPrevious((IRungViewElement) null);
  644.             rung.PreviousDifferenceRung = (IRungViewElement) null;
  645.             rung.NextDifferenceRung = (IRungViewElement) null;
  646.           }
  647.         }
  648.         this.m_Rungs.RemoveRange(0, this.m_Rungs.Count);
  649.       }
  650.       this.m_pFirstViewRung = (CVRungdef) null;
  651.     }
  652.  
  653.     private void UpdateRungNumberIndicator()
  654.     {
  655.     }
  656.  
  657.     public void SetFile(LadderRoutine progfile)
  658.     {
  659.       this.FreeRungInfo();
  660.       if (progfile == null)
  661.         return;
  662.       this.m_pRoutine = progfile;
  663.       if (!this.Initialize())
  664.         return;
  665.       CVRungdef pFirstViewRung = this.m_pFirstViewRung;
  666.       this.OnRefreshRung(pFirstViewRung);
  667.       this.SetTopRung(pFirstViewRung);
  668.       this.m_pCursorRung = pFirstViewRung;
  669.       this.m_pCursorElement = (IRungViewElement) pFirstViewRung;
  670.       this.ResetView();
  671.       this.m_pSelectedRung = (CVRungdef) null;
  672.       if (this.m_SelectedList.Count > 0)
  673.         this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
  674.       if (pFirstViewRung == null)
  675.         return;
  676.       this.SetCursor(this.m_pCursorRung, this.m_pCursorElement);
  677.     }
  678.  
  679.     private bool IsEditable() => false;
  680.  
  681.     private void Properties_Click(object sender, EventArgs e)
  682.     {
  683.       if (this._ViewPropertiesSetup == null)
  684.         return;
  685.       this._ViewPropertiesSetup(this.m_Options);
  686.     }
  687.  
  688.     private bool Initialize()
  689.     {
  690.       if (this.m_pRoutine == null)
  691.         return false;
  692.       int rungCount = this.m_pRoutine.GetRungCount();
  693.       this.m_Rungs = new ArrayList(rungCount);
  694.       CVRungdef theprev = (CVRungdef) null;
  695.       for (int index = 0; index < rungCount; ++index)
  696.       {
  697.         CVRungdef thenext = new CVRungdef(this.m_pRoutine.GetRungAt(index), this);
  698.         thenext.ScrollNumber = index;
  699.         if (theprev != null)
  700.         {
  701.           theprev.SetNext((IRungViewElement) thenext);
  702.           thenext.SetPrevious((IRungViewElement) theprev);
  703.         }
  704.         if (this.m_pFirstViewRung == null)
  705.           this.m_pFirstViewRung = thenext;
  706.         this.m_Rungs.Add((object) thenext);
  707.         theprev = thenext;
  708.       }
  709.       this.SetupDifferencePointers();
  710.       if (this._SetVertScrollbarRange != null)
  711.         this._SetVertScrollbarRange(0, rungCount);
  712.       return true;
  713.     }
  714.  
  715.     private void SetupDifferencePointers()
  716.     {
  717.       CVRungdef cvRungdef1 = (CVRungdef) null;
  718.       for (CVRungdef cvRungdef2 = this.m_pFirstViewRung; cvRungdef2 != null; cvRungdef2 = (CVRungdef) cvRungdef2.Next())
  719.       {
  720.         cvRungdef2.PreviousDifferenceRung = (IRungViewElement) cvRungdef1;
  721.         if (cvRungdef2.DifferenceRung)
  722.         {
  723.           cvRungdef1 = cvRungdef2;
  724.           CVRungdef cvRungdef3 = cvRungdef2;
  725.           do
  726.           {
  727.             cvRungdef3 = (CVRungdef) cvRungdef3.Previous();
  728.             if (cvRungdef3 != null)
  729.               cvRungdef3.NextDifferenceRung = (IRungViewElement) cvRungdef2;
  730.           }
  731.           while (cvRungdef3 != null && !cvRungdef3.DifferenceRung);
  732.         }
  733.       }
  734.     }
  735.  
  736.     public void OnSizeChanged()
  737.     {
  738.       Rectangle VwRc = Rectangle.Empty;
  739.       this.GetViewRect(out VwRc);
  740.       this.OnSizeChanged(VwRc);
  741.     }
  742.  
  743.     public void OnSizeChanged(Rectangle rc)
  744.     {
  745.       if (this.MatchingView != null && !CLadderView.compareSynro)
  746.       {
  747.         CLadderView.compareSynro = true;
  748.         this.MatchingView.OnSizeChanged(rc);
  749.         CLadderView.compareSynro = false;
  750.       }
  751.       this.m_nWidth = rc.Width - this.m_Options.GetGridUnit().Width;
  752.       this.OnSetStaleRungs();
  753.       this.OnSetRungPositions();
  754.       this.Refresh();
  755.     }
  756.  
  757.     public void ResetView() => this.ResetView(true);
  758.  
  759.     public void ResetView(bool bRedraw)
  760.     {
  761.       bool flag = false;
  762.       Graphics graphics;
  763.       if (this.IsPrinting)
  764.       {
  765.         graphics = this.printerGraphics;
  766.       }
  767.       else
  768.       {
  769.         graphics = this.CreateGraphics();
  770.         flag = true;
  771.       }
  772.       this.m_Options.SetGridUnit((SizeF) graphics.MeasureString("M", this.m_Options.LadderInstructionFont).ToSize());
  773.       Rectangle VwRc;
  774.       this.GetViewRect(out VwRc);
  775.       this.m_nWidth = VwRc.Width - this.m_Options.GetGridUnit().Width;
  776.       if (this.m_Options.DisplayPageHeader)
  777.       {
  778.         this.m_nLadderWindowTop = VwRc.Top + 2 * this.m_Options.GetGridUnit().Height;
  779.         this.m_nTopRungOffset = this.m_nLadderWindowTop;
  780.       }
  781.       else
  782.       {
  783.         this.m_nLadderWindowTop = VwRc.Top;
  784.         this.m_nTopRungOffset = this.m_nLadderWindowTop;
  785.       }
  786.       this.m_nLadderWindowLeft = VwRc.Left;
  787.       if (flag)
  788.         graphics.Dispose();
  789.       this.OnSetStaleRungs();
  790.       if (bRedraw)
  791.         this.OnSetRungPositions();
  792.       if (this._SetHorizScrollbarRange != null)
  793.         this._SetHorizScrollbarRange(0, this.m_nScrollWidth);
  794.       if (this._SetHorizScrollbarPos != null)
  795.         this._SetHorizScrollbarPos(0);
  796.       if (!bRedraw)
  797.         return;
  798.       this.Refresh();
  799.     }
  800.  
  801.     private int GetWidth() => this.m_nWidth;
  802.  
  803.     public bool OnScroll(Rectangle test_rc)
  804.     {
  805.       Rectangle VwRc;
  806.       this.GetViewRect(out VwRc);
  807.       VwRc.Y += this.m_nLadderWindowTop;
  808.       int width = 0;
  809.       int num = 0;
  810.       if (test_rc.Bottom > VwRc.Bottom)
  811.       {
  812.         num = test_rc.Bottom - VwRc.Bottom;
  813.         if (test_rc.Top - num < VwRc.Top)
  814.           num = test_rc.Top - VwRc.Top;
  815.       }
  816.       if (test_rc.Top <= VwRc.Top)
  817.         num = test_rc.Top - VwRc.Top;
  818.       if (test_rc.Right > VwRc.Right)
  819.       {
  820.         width = VwRc.Right - test_rc.Right;
  821.         if (test_rc.Left + width < VwRc.Left)
  822.           width = VwRc.Left - test_rc.Left;
  823.       }
  824.       if (test_rc.Left <= VwRc.Left)
  825.         width = VwRc.Left - test_rc.Left;
  826.       if (width == 0 && num == 0)
  827.         return false;
  828.       Size sizeScroll = new Size(width, -num);
  829.       if (this.MatchingView != null && !CLadderView.compareSynro)
  830.       {
  831.         CLadderView.compareSynro = true;
  832.         this.MatchingView.OnScrollBy(sizeScroll);
  833.         CLadderView.compareSynro = false;
  834.       }
  835.       return this.OnScrollBy(sizeScroll);
  836.     }
  837.  
  838.     public void InvalidateRect(Rectangle rc) => this.Invalidate(rc);
  839.  
  840.     public void InvalidateRect(Rectangle rc, bool bErasebackground) => this.Invalidate(rc, true);
  841.  
  842.     public void GetViewRect(out Rectangle VwRc)
  843.     {
  844.       VwRc = Rectangle.Empty;
  845.       if (!this.printing)
  846.       {
  847.         VwRc = this.DisplayRectangle;
  848.         VwRc.Height -= 20;
  849.       }
  850.       else if (this.CurrentPage == 1)
  851.         VwRc = this.page1PrintRect;
  852.       else
  853.         VwRc = this.page2PrintRect;
  854.     }
  855.  
  856.     public bool IsViewActive() => true;
  857.  
  858.     public bool EditAscii(int rungnumber, int rungelemindex, string str, char ch) => false;
  859.  
  860.     private void OnSetRungPositions()
  861.     {
  862.       if (this.printing)
  863.       {
  864.         this.OnSetAllRungPositions();
  865.       }
  866.       else
  867.       {
  868.         CVRungdef pRung = this.m_pCurrentTopViewRung;
  869.         if (pRung == null)
  870.           return;
  871.         Rectangle VwRc;
  872.         this.GetViewRect(out VwRc);
  873.         int num = 0;
  874.         Point ScreenPosition = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset);
  875.         bool flag = true;
  876.         for (; VwRc.Bottom > ScreenPosition.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
  877.         {
  878.           flag = false;
  879.           this.OnRefreshRung(pRung);
  880.           Size size = pRung.GetSize();
  881.           if (size.Width > num)
  882.             num = size.Width;
  883.           pRung.SetPosition(this.m_Options, ScreenPosition);
  884.           ScreenPosition.Y += size.Height;
  885.         }
  886.         if (pRung != null)
  887.         {
  888.           for (Point position = pRung.GetPosition(); position.Y <= VwRc.Bottom; position = pRung.GetPosition())
  889.           {
  890.             this.OnRefreshRung(pRung);
  891.             Size size = pRung.GetSize();
  892.             pRung.SetPosition(this.m_Options, ScreenPosition);
  893.             ScreenPosition.Y += size.Height;
  894.             pRung = (CVRungdef) pRung.Next();
  895.             if (pRung == null)
  896.               break;
  897.           }
  898.         }
  899.         if (flag)
  900.         {
  901.           this.OnRefreshRung(this.m_pCurrentTopViewRung);
  902.           Size size = this.m_pCurrentTopViewRung.GetSize();
  903.           if (size.Width > num)
  904.             num = size.Width;
  905.           this.m_pCurrentTopViewRung.SetPosition(this.m_Options, ScreenPosition);
  906.         }
  907.         if (num > this.m_nScrollWidth)
  908.         {
  909.           this.m_nScrollWidth = num;
  910.           if (this._SetHorizScrollbarRange != null)
  911.             this._SetHorizScrollbarRange(0, this.m_nScrollWidth);
  912.         }
  913.         this.ResetAsyncData();
  914.       }
  915.     }
  916.  
  917.     private void OnSetAllRungPositions()
  918.     {
  919.       CVRungdef pRung = this.m_pCurrentTopViewRung;
  920.       if (pRung == null)
  921.         return;
  922.       Point ScreenPosition = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset);
  923.       for (; pRung != null; pRung = (CVRungdef) pRung.Next())
  924.       {
  925.         this.OnRefreshRung(pRung);
  926.         Size size = pRung.GetSize();
  927.         pRung.SetPosition(this.m_Options, ScreenPosition);
  928.         if (this.printDiffRungsOnly)
  929.         {
  930.           if (pRung.DifferenceRung)
  931.             ScreenPosition.Y += size.Height;
  932.         }
  933.         else
  934.           ScreenPosition.Y += size.Height;
  935.       }
  936.     }
  937.  
  938.     private void SetTopRung(CVRungdef pVRung) => this.m_pCurrentTopViewRung = pVRung;
  939.  
  940.     private void ResetAsyncData()
  941.     {
  942.       if (this.m_AddrTagsForUpdating == null)
  943.         this.m_AddrTagsForUpdating = new ArrayList();
  944.       else
  945.         this.m_AddrTagsForUpdating.RemoveRange(0, this.m_AddrTagsForUpdating.Count);
  946.       CVRungdef pRung = this.m_pCurrentTopViewRung;
  947.       if (pRung == null)
  948.         return;
  949.       Rectangle VwRc;
  950.       this.GetViewRect(out VwRc);
  951.       for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
  952.       {
  953.         this.OnRefreshRung(pRung);
  954.         Size size = pRung.GetSize();
  955.         ((CRung) pRung.GetRungElem())?.AddToUpdateList(this.m_AddrTagsForUpdating);
  956.         point.Y += size.Height;
  957.       }
  958.     }
  959.  
  960.     public void OnDataChanged(ArrayList changedData)
  961.     {
  962.       if (this.m_Options.IsPrinting())
  963.         return;
  964.       CVRungdef pRung = this.m_pCurrentTopViewRung;
  965.       if (pRung == null)
  966.         return;
  967.       Rectangle VwRc;
  968.       this.GetViewRect(out VwRc);
  969.       for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && pRung != null; pRung = (CVRungdef) pRung.Next())
  970.       {
  971.         this.OnRefreshRung(pRung);
  972.         Size size = pRung.GetSize();
  973.         pRung.UpdateLiveData(changedData, this);
  974.         point.Y += size.Height;
  975.       }
  976.     }
  977.  
  978.     public void OnRefreshRung(CVRungdef pRung)
  979.     {
  980.       Size headerSize = Size.Empty;
  981.       if (pRung == null)
  982.         return;
  983.       bool flag = false;
  984.       Graphics g;
  985.       if (this.IsPrinting)
  986.       {
  987.         g = this.printerGraphics;
  988.       }
  989.       else
  990.       {
  991.         g = this.CreateGraphics();
  992.         flag = true;
  993.       }
  994.       if (pRung.IsStale() || pRung.MatchingViewRung != null)
  995.       {
  996.         if (this.m_Options.DisplayLadderAsLadder)
  997.         {
  998.           if (this.m_Options.DisplayLadderUsingRungWrap)
  999.             pRung.CalcSize_LadderLimitWidth(g, this, this.GetWidth(), this.GetWidth(), out headerSize);
  1000.           else
  1001.             pRung.CalcSize_Ladder(g, this, this.GetWidth());
  1002.         }
  1003.         else if (this.m_Options.DisplayLadderAsAscii)
  1004.           pRung.CalcSize_Ascii(g, this, this.GetWidth());
  1005.       }
  1006.       if (!flag)
  1007.         return;
  1008.       g.Dispose();
  1009.     }
  1010.  
  1011.     private void OnSetStaleRungs()
  1012.     {
  1013.       if (this.m_Rungs == null)
  1014.         return;
  1015.       foreach (CVRungdef rung in this.m_Rungs)
  1016.         rung.SetStale();
  1017.     }
  1018.  
  1019.     public void InitializePrinting(
  1020.       Graphics g,
  1021.       Rectangle Page1ClipRect,
  1022.       Rectangle Page2ClipRect,
  1023.       float scale,
  1024.       bool diffOnly)
  1025.     {
  1026.       Trace.WriteLine("-------------Start:  InitializePrinting ()");
  1027.       this.m_Options.LadderInstructionFont = new Font(this.m_Options.LadderInstructionFont.Name, this.m_Options.LadderInstructionFont.Size * scale);
  1028.       this.printerGraphics = g;
  1029.       this.page1PrintRect = Page1ClipRect;
  1030.       this.page2PrintRect = Page2ClipRect;
  1031.       this.printing = true;
  1032.       this.printDiffRungsOnly = diffOnly;
  1033.       this.currentPage = 1;
  1034.       this.OnSizeChanged();
  1035.       this.ResetView(true);
  1036.       this.printPages = this.CalculatePrintedPages();
  1037.       this.printing = false;
  1038.       Trace.WriteLine("-------------End:  InitializePrinting ()");
  1039.     }
  1040.  
  1041.     private CLadderView.PrintPageInfo[] CalculatePrintedPages()
  1042.     {
  1043.       bool printing = this.printing;
  1044.       int currentPage = this.currentPage;
  1045.       this.printing = true;
  1046.       this.currentPage = 1;
  1047.       int num = 0;
  1048.       ArrayList arrayList = new ArrayList();
  1049.       Rectangle rectangle = this.page1PrintRect;
  1050.       CVRungdef cvRungdef = this.m_pFirstViewRung;
  1051.       CLadderView.PrintPageInfo printPageInfo1 = new CLadderView.PrintPageInfo();
  1052.       printPageInfo1.StartRung = cvRungdef;
  1053.       printPageInfo1.EndRung = cvRungdef;
  1054.       printPageInfo1.ClipRect = rectangle;
  1055.       printPageInfo1.TopRungOffset = 0;
  1056.       bool flag = false;
  1057.       while (cvRungdef != null)
  1058.       {
  1059.         Size size = cvRungdef.GetSize();
  1060.         if (!this.printDiffRungsOnly || cvRungdef.DifferenceRung)
  1061.           num += size.Height;
  1062.         if (num > rectangle.Height)
  1063.         {
  1064.           if (flag)
  1065.             printPageInfo1.EndRung = cvRungdef;
  1066.           arrayList.Add((object) printPageInfo1);
  1067.           int rungCount = printPageInfo1.RungCount;
  1068.           CLadderView.PrintPageInfo printPageInfo2 = new CLadderView.PrintPageInfo();
  1069.           printPageInfo2.StartRung = cvRungdef;
  1070.           printPageInfo2.EndRung = cvRungdef;
  1071.           printPageInfo2.TopRungOffset = !flag ? printPageInfo1.TopRungOffset + -1 * rectangle.Height : -1 * rectangle.Height + (num - size.Height);
  1072.           num = size.Height + printPageInfo2.TopRungOffset;
  1073.           ++this.currentPage;
  1074.           rectangle = this.page2PrintRect;
  1075.           printPageInfo2.ClipRect = rectangle;
  1076.           printPageInfo1 = printPageInfo2;
  1077.         }
  1078.         else
  1079.           printPageInfo1.EndRung = cvRungdef;
  1080.         if (num <= rectangle.Height)
  1081.         {
  1082.           cvRungdef = (CVRungdef) cvRungdef.Next();
  1083.           flag = true;
  1084.         }
  1085.         else
  1086.           flag = false;
  1087.       }
  1088.       arrayList.Add((object) printPageInfo1);
  1089.       this.printing = printing;
  1090.       this.currentPage = currentPage;
  1091.       return (CLadderView.PrintPageInfo[]) arrayList.ToArray(typeof (CLadderView.PrintPageInfo));
  1092.     }
  1093.  
  1094.     public void OnPrintRungs(Graphics g, int page)
  1095.     {
  1096.       if (page < 1 || page > this.printPages.Length)
  1097.         return;
  1098.       this.printerGraphics = g;
  1099.       this.printing = true;
  1100.       this.currentPage = page;
  1101.       CLadderView.PrintPageInfo printPage = this.printPages[page - 1];
  1102.       CVRungdef cvRungdef = printPage.StartRung;
  1103.       this.m_pCurrentTopViewRung = printPage.StartRung;
  1104.       this.printerGraphics.SetClip(printPage.ClipRect);
  1105.       this.ResetView(true);
  1106.       if (cvRungdef == null)
  1107.         return;
  1108.       if (printPage.TopRungOffset != 0)
  1109.         this.printerGraphics.TranslateTransform(0.0f, (float) printPage.TopRungOffset, MatrixOrder.Append);
  1110.       for (; cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
  1111.       {
  1112.         if (!this.printDiffRungsOnly || cvRungdef.DifferenceRung)
  1113.           cvRungdef.Draw(this.printerGraphics, this);
  1114.         if (cvRungdef == printPage.EndRung)
  1115.           break;
  1116.       }
  1117.       if (printPage.TopRungOffset != 0)
  1118.         this.printerGraphics.ResetTransform();
  1119.       this.printing = false;
  1120.     }
  1121.  
  1122.     private void OnDrawRungs(Graphics g, Rectangle ClipRect)
  1123.     {
  1124.       CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
  1125.       if (cvRungdef == null)
  1126.         return;
  1127.       Rectangle VwRc;
  1128.       this.GetViewRect(out VwRc);
  1129.       int num = this.m_nTopRungOffset;
  1130.       Size empty = Size.Empty;
  1131.       for (; VwRc.Bottom > num && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
  1132.       {
  1133.         Size size = cvRungdef.GetSize();
  1134.         num = cvRungdef.GetPosition().Y + size.Height;
  1135.         if (num > VwRc.Top)
  1136.           cvRungdef.Draw(g, this);
  1137.       }
  1138.     }
  1139.  
  1140.     private bool SetCursor(CVRungdef pAtRung, IRungViewElement pAtElementInRung)
  1141.     {
  1142.       if (pAtRung == null || pAtElementInRung == null)
  1143.         return false;
  1144.       if (this.m_pCursorElement != null && this.m_pCursorRung != null)
  1145.         this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
  1146.       this.m_pCursorElement = pAtElementInRung;
  1147.       this.m_pCursorRung = pAtRung;
  1148.       this.OnRefreshRung(this.m_pCursorRung);
  1149.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  1150.         this.GotoRung(this.m_pCursorRung);
  1151.       this.m_pCursorElement.SetCursor(this);
  1152.       this.ClearAllSelections();
  1153.       this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1154.       this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
  1155.       this.UpdateRungNumberIndicator();
  1156.       this.Refresh();
  1157.       return true;
  1158.     }
  1159.  
  1160.     private void SetAnchorItem(CVRungdef pAnchorRung, IRungViewElement pAnchorElem)
  1161.     {
  1162.       if (pAnchorRung == null || pAnchorElem == null)
  1163.         return;
  1164.       this.m_pAnchorElem = pAnchorElem;
  1165.       this.m_pAnchorRung = pAnchorRung;
  1166.     }
  1167.  
  1168.     private void ClearAnchor()
  1169.     {
  1170.       this.m_pAnchorElem = (IRungViewElement) null;
  1171.       this.m_pAnchorRung = (CVRungdef) null;
  1172.     }
  1173.  
  1174.     private bool SetCursor(CVRungdef pAtRung, IRungViewElement pAtElementInRung, Point pt)
  1175.     {
  1176.       if (pAtRung == null || pAtElementInRung == null)
  1177.         return false;
  1178.       if (this.m_pCursorElement != null && this.m_pCursorRung != null)
  1179.         this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
  1180.       this.m_pCursorElement = pAtElementInRung;
  1181.       this.m_pCursorRung = pAtRung;
  1182.       this.OnRefreshRung(this.m_pCursorRung);
  1183.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  1184.       {
  1185.         this.GotoRung(this.m_pCursorRung);
  1186.         if (this.m_pCursorRung.MatchingViewRung != null)
  1187.           this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
  1188.       }
  1189.       this.m_pCursorElement.SetCursor(this, pt);
  1190.       this.ClearAllSelections();
  1191.       this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1192.       this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
  1193.       this.UpdateRungNumberIndicator();
  1194.       this.Refresh();
  1195.       return true;
  1196.     }
  1197.  
  1198.     private bool SetCursorAndSelect(CVRungdef pAtRung, IRungViewElement pAtElementInRung)
  1199.     {
  1200.       if (pAtRung == null || pAtElementInRung == null)
  1201.         return false;
  1202.       if (this.m_pCursorElement != null && this.m_pCursorRung != null)
  1203.         this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
  1204.       this.m_pCursorElement = pAtElementInRung;
  1205.       this.m_pCursorRung = pAtRung;
  1206.       this.OnRefreshRung(this.m_pCursorRung);
  1207.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  1208.       {
  1209.         this.GotoRung(this.m_pCursorRung);
  1210.         if (this.m_pCursorRung.MatchingViewRung != null)
  1211.           this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
  1212.       }
  1213.       this.m_pCursorElement.SetCursor(this);
  1214.       Keys modifierKeys = Control.ModifierKeys;
  1215.       bool flag = false;
  1216.       if (modifierKeys == Keys.Shift)
  1217.         flag = true;
  1218.       if (flag)
  1219.       {
  1220.         this.SelectSpan(this.m_pCursorRung, this.m_pCursorElement);
  1221.       }
  1222.       else
  1223.       {
  1224.         this.ClearAllSelections();
  1225.         this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1226.         this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
  1227.       }
  1228.       this.UpdateRungNumberIndicator();
  1229.       this.Refresh();
  1230.       return true;
  1231.     }
  1232.  
  1233.     private bool SetCursorAndSelect(CVRungdef pAtRung, IRungViewElement pAtElementInRung, Point pt)
  1234.     {
  1235.       if (pAtRung == null || pAtElementInRung == null)
  1236.         return false;
  1237.       if (this.m_pCursorElement != null && this.m_pCursorRung != null)
  1238.         this.m_pCursorElement.ClearCursor(this, this.IsRungOnScreen(this.m_pCursorRung));
  1239.       this.m_pCursorElement = pAtElementInRung;
  1240.       this.m_pCursorRung = pAtRung;
  1241.       this.OnRefreshRung(this.m_pCursorRung);
  1242.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  1243.         this.GotoRung(this.m_pCursorRung);
  1244.       this.m_pCursorElement.SetCursor(this, pt);
  1245.       Keys modifierKeys = Control.ModifierKeys;
  1246.       bool flag1 = false;
  1247.       if (modifierKeys == Keys.Shift)
  1248.         flag1 = true;
  1249.       bool flag2 = false;
  1250.       if (modifierKeys == Keys.Control)
  1251.         flag2 = true;
  1252.       this.m_nLeftMouseButUpActionToDo = 0;
  1253.       if (flag2 && !flag1)
  1254.       {
  1255.         if (!this.m_pCursorElement.IsSelected(this))
  1256.         {
  1257.           this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1258.           this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
  1259.         }
  1260.         else
  1261.           this.m_nLeftMouseButUpActionToDo = 2;
  1262.       }
  1263.       else if (flag1)
  1264.         this.SelectSpan(this.m_pCursorRung, this.m_pCursorElement);
  1265.       else if (!this.m_pCursorElement.IsSelected(this))
  1266.       {
  1267.         this.ClearAllSelections();
  1268.         this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1269.         this.SetAnchorItem(this.m_pCursorRung, this.m_pCursorElement);
  1270.       }
  1271.       else
  1272.         this.m_nLeftMouseButUpActionToDo = 1;
  1273.       this.UpdateRungNumberIndicator();
  1274.       this.Refresh();
  1275.       return true;
  1276.     }
  1277.  
  1278.     private void SelectSpan(CVRungdef pSelectRung, IRungViewElement pSpanElem)
  1279.     {
  1280.       if (pSelectRung == null || pSpanElem == null || this.m_pAnchorRung == null || this.m_pAnchorElem == null)
  1281.         return;
  1282.       this.ClearAllSelections();
  1283.       IRungElement rungElement1 = this.m_pAnchorElem.GetRungElement();
  1284.       IRungElement rungElement2 = pSpanElem.GetRungElement();
  1285.       if (rungElement1 == null || rungElement2 == null)
  1286.         return;
  1287.       if (this.m_pAnchorElem.IsRung() && !pSpanElem.IsRung() || !this.m_pAnchorElem.IsRung() && pSpanElem.IsRung() || rungElement1.GetOwner() != rungElement2.GetOwner())
  1288.       {
  1289.         this.SetAnchorItem(pSelectRung, pSpanElem);
  1290.         this.m_pSelectedRung = pSelectRung;
  1291.         this.m_SelectedList.Add((object) pSpanElem);
  1292.         pSpanElem.SetSelected(this, this.IsRungOnScreen(pSelectRung));
  1293.       }
  1294.       else
  1295.       {
  1296.         this.m_pSelectedRung = this.m_pAnchorRung;
  1297.         bool flag = true;
  1298.         IRungViewElement rungViewElement1 = this.m_pAnchorElem;
  1299.         IRungViewElement pTestRung1 = this.m_pAnchorElem;
  1300.         for (; rungViewElement1 != pSpanElem; rungViewElement1 = rungViewElement1.Next())
  1301.         {
  1302.           if (rungViewElement1 == null)
  1303.           {
  1304.             flag = false;
  1305.             for (IRungViewElement rungViewElement2 = pSpanElem; rungViewElement2 != pTestRung1; rungViewElement2 = rungViewElement2.Next())
  1306.             {
  1307.               if (rungViewElement2 == null)
  1308.                 return;
  1309.             }
  1310.             break;
  1311.           }
  1312.         }
  1313.         if (flag)
  1314.         {
  1315.           while (pTestRung1 != pSpanElem)
  1316.           {
  1317.             this.m_SelectedList.Add((object) pTestRung1);
  1318.             if (pTestRung1.IsRung())
  1319.               pTestRung1.SetSelected(this, this.IsRungOnScreen((CVRungdef) pTestRung1));
  1320.             else
  1321.               pTestRung1.SetSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
  1322.             pTestRung1 = pTestRung1.Next();
  1323.             if (pTestRung1 == null)
  1324.               break;
  1325.           }
  1326.         }
  1327.         else
  1328.         {
  1329.           IRungViewElement pTestRung2 = pTestRung1;
  1330.           while (pTestRung2 != pSpanElem)
  1331.           {
  1332.             this.m_SelectedList.Add((object) pTestRung2);
  1333.             if (pTestRung2.IsRung())
  1334.               pTestRung2.SetSelected(this, this.IsRungOnScreen((CVRungdef) pTestRung2));
  1335.             else
  1336.               pTestRung2.SetSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
  1337.             pTestRung2 = pTestRung2.Previous();
  1338.             if (pTestRung2 == null)
  1339.               break;
  1340.           }
  1341.         }
  1342.         this.m_SelectedList.Add((object) pSpanElem);
  1343.         if (pSpanElem.IsRung())
  1344.           pSpanElem.SetSelected(this, this.IsRungOnScreen((CVRungdef) pSpanElem));
  1345.         else
  1346.           pSpanElem.SetSelected(this, this.IsRungOnScreen(pSelectRung));
  1347.         ArrayList arrayList = new ArrayList(this.m_SelectedList.Count);
  1348.         if (flag)
  1349.           return;
  1350.         for (int index = this.m_SelectedList.Count - 1; index >= 0; --index)
  1351.         {
  1352.           object selected = this.m_SelectedList[index];
  1353.           arrayList.Add(selected);
  1354.         }
  1355.         this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
  1356.         for (int index = 0; index < arrayList.Count; ++index)
  1357.           this.m_SelectedList.Add(arrayList[index]);
  1358.       }
  1359.     }
  1360.  
  1361.     private void SelectItem(CVRungdef pSelRung, IRungViewElement pSelElem)
  1362.     {
  1363.       if (pSelRung == null || pSelElem == null)
  1364.         return;
  1365.       IRungViewElement rungViewElement = (IRungViewElement) null;
  1366.       if (this.m_pSelectedRung != null)
  1367.       {
  1368.         if (this.m_SelectedList.Count > 0)
  1369.           rungViewElement = (IRungViewElement) this.m_SelectedList[0];
  1370.         if (rungViewElement != null && rungViewElement.IsRung())
  1371.         {
  1372.           if (pSelRung != pSelElem)
  1373.             this.ClearAllSelections();
  1374.         }
  1375.         else if (this.m_pSelectedRung != pSelRung)
  1376.           this.ClearAllSelections();
  1377.       }
  1378.       IRungElement rungElement1 = pSelElem.GetRungElement();
  1379.       for (int index = 0; index < this.m_SelectedList.Count; ++index)
  1380.       {
  1381.         IRungViewElement selected = (IRungViewElement) this.m_SelectedList[index];
  1382.         if (selected == pSelElem)
  1383.         {
  1384.           this.m_SelectedList.RemoveAt(index);
  1385.           if (selected.IsRung())
  1386.             selected.ClearSelected(this, this.IsRungOnScreen((CVRungdef) selected));
  1387.           else
  1388.             selected.ClearSelected(this, this.IsRungOnScreen(pSelRung));
  1389.           if (this.m_SelectedList.Count > 0)
  1390.             return;
  1391.           this.m_pSelectedRung = (CVRungdef) null;
  1392.           return;
  1393.         }
  1394.         IRungElement rungElement2 = selected.GetRungElement();
  1395.         if (rungElement2 != null && rungElement1 != null && rungElement2.GetOwner() != rungElement1.GetOwner())
  1396.         {
  1397.           this.ClearAllSelections();
  1398.           break;
  1399.         }
  1400.       }
  1401.       this.m_pSelectedRung = pSelRung;
  1402.       this.m_SelectedList.Add((object) pSelElem);
  1403.       pSelElem.SetSelected(this, this.IsRungOnScreen(pSelRung));
  1404.     }
  1405.  
  1406.     private void ClearAllSelections()
  1407.     {
  1408.       for (int index = 0; index < this.m_SelectedList.Count; ++index)
  1409.       {
  1410.         IRungViewElement selected = (IRungViewElement) this.m_SelectedList[index];
  1411.         if (selected.IsRung())
  1412.           selected.ClearSelected(this, this.IsRungOnScreen((CVRungdef) selected));
  1413.         else
  1414.           selected.ClearSelected(this, this.IsRungOnScreen(this.m_pSelectedRung));
  1415.       }
  1416.       this.m_pSelectedRung = (CVRungdef) null;
  1417.       this.m_SelectedList.RemoveRange(0, this.m_SelectedList.Count);
  1418.     }
  1419.  
  1420.     private bool SetCursor(Point pt)
  1421.     {
  1422.       CVRungdef rungWithPt = this.GetRungWithPt(pt);
  1423.       if (rungWithPt == null)
  1424.         return false;
  1425.       IRungViewElement rungElementWithPt = this.GetRungElementWithPt(pt);
  1426.       return rungElementWithPt != null && this.SetCursorAndSelect(rungWithPt, rungElementWithPt, pt);
  1427.     }
  1428.  
  1429.     private IGraphic GetElementWithPt(Point pt) => this.GetRungWithPt(pt)?.GetElementWithPt(this, pt);
  1430.  
  1431.     private IRungViewElement GetRungElementWithPt(Point pt)
  1432.     {
  1433.       IGraphic elementWithPt = this.GetElementWithPt(pt);
  1434.       if (elementWithPt == null)
  1435.         return (IRungViewElement) null;
  1436.       return elementWithPt.IsRungElement() ? (IRungViewElement) elementWithPt : (IRungViewElement) null;
  1437.     }
  1438.  
  1439.     private CVRungdef GetViewRung(IRungElement docrung)
  1440.     {
  1441.       if (this.m_pFirstViewRung != null)
  1442.       {
  1443.         for (IRungViewElement viewRung = (IRungViewElement) this.m_pFirstViewRung; viewRung != null; viewRung = viewRung.Next())
  1444.         {
  1445.           if (viewRung.GetRungElement() == docrung)
  1446.             return (CVRungdef) viewRung;
  1447.         }
  1448.       }
  1449.       return (CVRungdef) null;
  1450.     }
  1451.  
  1452.     private CVRungdef GetRungWithPt(Point pt)
  1453.     {
  1454.       CVRungdef rungWithPt = this.m_pCurrentTopViewRung;
  1455.       if (rungWithPt == null)
  1456.         return (CVRungdef) null;
  1457.       Rectangle VwRc;
  1458.       this.GetViewRect(out VwRc);
  1459.       for (Point point = new Point(this.m_nLadderWindowLeft, this.m_nTopRungOffset); VwRc.Bottom > point.Y && rungWithPt != null; rungWithPt = (CVRungdef) rungWithPt.Next())
  1460.       {
  1461.         if (rungWithPt.HavePt(pt))
  1462.           return rungWithPt;
  1463.         point.Y += rungWithPt.GetSize().Height;
  1464.       }
  1465.       return (CVRungdef) null;
  1466.     }
  1467.  
  1468.     private bool IsRungOnScreen(CVRungdef pTestRung)
  1469.     {
  1470.       CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
  1471.       if (cvRungdef == null || pTestRung == null)
  1472.         return false;
  1473.       Rectangle VwRc;
  1474.       this.GetViewRect(out VwRc);
  1475.       for (int nTopRungOffset = this.m_nTopRungOffset; VwRc.Bottom > nTopRungOffset && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
  1476.       {
  1477.         if (pTestRung == cvRungdef)
  1478.           return true;
  1479.         nTopRungOffset += cvRungdef.GetSize().Height;
  1480.       }
  1481.       return false;
  1482.     }
  1483.  
  1484.     private bool IsRungOnScreen(int nRung)
  1485.     {
  1486.       CVRungdef cvRungdef = this.m_pCurrentTopViewRung;
  1487.       if (cvRungdef == null)
  1488.         return false;
  1489.       Rectangle VwRc;
  1490.       this.GetViewRect(out VwRc);
  1491.       for (int nTopRungOffset = this.m_nTopRungOffset; VwRc.Bottom > nTopRungOffset && cvRungdef != null; cvRungdef = (CVRungdef) cvRungdef.Next())
  1492.       {
  1493.         if (cvRungdef.GetRungNumber() == nRung)
  1494.           return true;
  1495.         nTopRungOffset += cvRungdef.GetSize().Height;
  1496.       }
  1497.       return false;
  1498.     }
  1499.  
  1500.     public void mVertScrollBar_Scroll(object sender, ScrollEventArgs e)
  1501.     {
  1502.       int height = this.m_Options.GetGridUnit().Height;
  1503.       ScrollEventType type = e.Type;
  1504.       int index = e.NewValue / 100;
  1505.       switch (type)
  1506.       {
  1507.         case ScrollEventType.SmallDecrement:
  1508.           if (this.m_pCurrentTopViewRung == null)
  1509.             break;
  1510.           int rungoffset1 = this.m_nTopRungOffset + height;
  1511.           if (rungoffset1 > this.m_nLadderWindowTop)
  1512.           {
  1513.             if (this.m_pCurrentTopViewRung.Previous() == null)
  1514.               break;
  1515.             this.OnRefreshRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
  1516.             int rungoffset2 = this.m_nLadderWindowTop - this.m_pCurrentTopViewRung.Previous().GetSize().Height + height;
  1517.             this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous(), rungoffset2);
  1518.             break;
  1519.           }
  1520.           this.GotoRung(this.m_pCurrentTopViewRung, rungoffset1);
  1521.           break;
  1522.         case ScrollEventType.SmallIncrement:
  1523.           if (this.m_pCurrentTopViewRung == null)
  1524.             break;
  1525.           int rungoffset3 = this.m_nTopRungOffset - height;
  1526.           if (this.m_pCurrentTopViewRung.GetSize().Height + rungoffset3 <= this.m_nLadderWindowTop)
  1527.           {
  1528.             if (this.m_pCurrentTopViewRung.Next() == null)
  1529.               break;
  1530.             this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
  1531.             break;
  1532.           }
  1533.           this.GotoRung(this.m_pCurrentTopViewRung, rungoffset3);
  1534.           break;
  1535.         case ScrollEventType.LargeDecrement:
  1536.           if (this.m_pCurrentTopViewRung == null)
  1537.             break;
  1538.           if (this.m_nTopRungOffset != this.m_nLadderWindowTop)
  1539.           {
  1540.             this.GotoRung(this.m_pCurrentTopViewRung);
  1541.             break;
  1542.           }
  1543.           if (this.m_pCurrentTopViewRung.Previous() == null)
  1544.             break;
  1545.           this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
  1546.           break;
  1547.         case ScrollEventType.LargeIncrement:
  1548.           if (this.m_pCurrentTopViewRung == null || this.m_pCurrentTopViewRung.Next() == null)
  1549.             break;
  1550.           this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
  1551.           break;
  1552.         case ScrollEventType.ThumbPosition:
  1553.           this.GotoRungAt(index);
  1554.           break;
  1555.         case ScrollEventType.ThumbTrack:
  1556.           this.GotoRungAt(index);
  1557.           break;
  1558.         case ScrollEventType.First:
  1559.           this.GotoRung(this.GetFirstViewRung());
  1560.           break;
  1561.         case ScrollEventType.Last:
  1562.           this.GotoRung(this.GetLastViewRung());
  1563.           break;
  1564.       }
  1565.     }
  1566.  
  1567.     public void mHorizScrollBar_Scroll(object sender, ScrollEventArgs e)
  1568.     {
  1569.       int ladderWindowLeft = this.m_nLadderWindowLeft;
  1570.       int nScrollWidth = this.m_nScrollWidth;
  1571.       int num1 = nScrollWidth <= 10 ? 1 : nScrollWidth / 10;
  1572.       int num2 = nScrollWidth <= 100 ? 1 : nScrollWidth / 100;
  1573.       ScrollEventType type = e.Type;
  1574.       int newValue = e.NewValue;
  1575.       switch (type)
  1576.       {
  1577.         case ScrollEventType.SmallDecrement:
  1578.           this.m_nLadderWindowLeft += num2;
  1579.           if (this.m_nLadderWindowLeft > 0)
  1580.           {
  1581.             this.m_nLadderWindowLeft = 0;
  1582.             break;
  1583.           }
  1584.           break;
  1585.         case ScrollEventType.SmallIncrement:
  1586.           this.m_nLadderWindowLeft -= num2;
  1587.           if (this.m_nLadderWindowLeft < -nScrollWidth)
  1588.           {
  1589.             this.m_nLadderWindowLeft = -nScrollWidth;
  1590.             break;
  1591.           }
  1592.           break;
  1593.         case ScrollEventType.LargeDecrement:
  1594.           this.m_nLadderWindowLeft += num1;
  1595.           if (this.m_nLadderWindowLeft > 0)
  1596.           {
  1597.             this.m_nLadderWindowLeft = 0;
  1598.             break;
  1599.           }
  1600.           break;
  1601.         case ScrollEventType.LargeIncrement:
  1602.           this.m_nLadderWindowLeft -= num1;
  1603.           if (this.m_nLadderWindowLeft < -nScrollWidth)
  1604.           {
  1605.             this.m_nLadderWindowLeft = -nScrollWidth;
  1606.             break;
  1607.           }
  1608.           break;
  1609.         case ScrollEventType.ThumbPosition:
  1610.           this.m_nLadderWindowLeft = -newValue;
  1611.           break;
  1612.         case ScrollEventType.ThumbTrack:
  1613.           this.m_nLadderWindowLeft = -newValue;
  1614.           break;
  1615.         case ScrollEventType.First:
  1616.           this.m_nLadderWindowLeft = 0;
  1617.           break;
  1618.         case ScrollEventType.Last:
  1619.           this.m_nLadderWindowLeft = nScrollWidth;
  1620.           break;
  1621.       }
  1622.       if (ladderWindowLeft == this.m_nLadderWindowLeft)
  1623.         return;
  1624.       Rectangle VwRc;
  1625.       this.GetViewRect(out VwRc);
  1626.       VwRc.Y += this.m_nLadderWindowTop;
  1627.       if (this._SetHorizScrollbarPos != null)
  1628.         this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
  1629.       this.OnSetRungPositions();
  1630.       this.Invalidate(VwRc);
  1631.       this.Refresh();
  1632.     }
  1633.  
  1634.     private bool OnScrollBy(Size sizeScroll)
  1635.     {
  1636.       bool flag1 = true;
  1637.       int nScrollWidth = this.m_nScrollWidth;
  1638.       bool flag2 = false;
  1639.       if (sizeScroll.Width != 0)
  1640.       {
  1641.         int num = nScrollWidth <= 100 ? 1 : nScrollWidth / 100;
  1642.         int nlines = sizeScroll.Width / num;
  1643.         if (nlines * num != sizeScroll.Width)
  1644.         {
  1645.           if (sizeScroll.Width < 0)
  1646.             --nlines;
  1647.           else
  1648.             ++nlines;
  1649.         }
  1650.         if (flag1)
  1651.           flag2 = nlines >= 0 ? this.OnHScrollLinesLeft(nlines) : this.OnHScrollLinesRight(-nlines);
  1652.         else if (nlines < 0)
  1653.         {
  1654.           if (this.m_nLadderWindowLeft > -nScrollWidth)
  1655.             flag2 = true;
  1656.         }
  1657.         else if (this.m_nLadderWindowLeft < 0)
  1658.           flag2 = true;
  1659.       }
  1660.       if (sizeScroll.Height != 0)
  1661.       {
  1662.         int nlines = sizeScroll.Height / this.m_Options.GetGridUnit().Height;
  1663.         if (nlines * this.m_Options.GetGridUnit().Height != sizeScroll.Height)
  1664.         {
  1665.           if (sizeScroll.Height < 0)
  1666.             --nlines;
  1667.           else
  1668.             ++nlines;
  1669.         }
  1670.         if (flag1)
  1671.           flag2 = nlines >= 0 ? this.OnVScrollLinesUp(nlines) : this.OnVScrollLinesDown(-nlines);
  1672.         else if (nlines < 0)
  1673.         {
  1674.           if (this.m_pCurrentTopViewRung.Next() != null)
  1675.             flag2 = true;
  1676.         }
  1677.         else if (this.m_pCurrentTopViewRung.Previous() != null || this.m_nTopRungOffset < this.m_nLadderWindowTop)
  1678.           flag2 = true;
  1679.       }
  1680.       return flag2;
  1681.     }
  1682.  
  1683.     public bool OnVScrollLinesDown(int nlines)
  1684.     {
  1685.       if (nlines <= 0)
  1686.         return false;
  1687.       int height = this.m_Options.GetGridUnit().Height;
  1688.       int num1 = 0;
  1689.       while (nlines-- > 0)
  1690.       {
  1691.         this.m_nTopRungOffset -= height;
  1692.         int num2 = -height;
  1693.         if (this.m_pCurrentTopViewRung.GetSize().Height + this.m_nTopRungOffset <= this.m_nLadderWindowTop)
  1694.         {
  1695.           if (this.m_pCurrentTopViewRung.Next() != null)
  1696.           {
  1697.             this.SetTopRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
  1698.             this.m_nTopRungOffset = this.m_nLadderWindowTop;
  1699.           }
  1700.           else
  1701.           {
  1702.             this.m_nTopRungOffset += height;
  1703.             num2 = 0;
  1704.           }
  1705.         }
  1706.         this.OnSetRungPositions();
  1707.         num1 += num2;
  1708.       }
  1709.       if (num1 == 0)
  1710.         return false;
  1711.       Rectangle VwRc;
  1712.       this.GetViewRect(out VwRc);
  1713.       this.Invalidate(VwRc);
  1714.       this.Refresh();
  1715.       if (this.m_pCurrentTopViewRung != null && this._SetVertScrollbarPos != null)
  1716.         this._SetVertScrollbarPos(this.m_pCurrentTopViewRung.GetRungNumber());
  1717.       return true;
  1718.     }
  1719.  
  1720.     public bool OnVScrollLinesUp(int nlines)
  1721.     {
  1722.       if (nlines <= 0)
  1723.         return false;
  1724.       int height = this.m_Options.GetGridUnit().Height;
  1725.       int num1 = 0;
  1726.       while (nlines-- > 0)
  1727.       {
  1728.         this.m_nTopRungOffset += height;
  1729.         int num2 = height;
  1730.         if (this.m_nTopRungOffset > this.m_nLadderWindowTop)
  1731.         {
  1732.           if (this.m_pCurrentTopViewRung.Previous() != null)
  1733.           {
  1734.             this.SetTopRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
  1735.             this.OnRefreshRung(this.m_pCurrentTopViewRung);
  1736.             this.m_nTopRungOffset = this.m_nLadderWindowTop - this.m_pCurrentTopViewRung.GetSize().Height;
  1737.             this.m_nTopRungOffset += height;
  1738.           }
  1739.           else
  1740.           {
  1741.             this.m_nTopRungOffset -= height;
  1742.             num2 = 0;
  1743.           }
  1744.         }
  1745.         this.OnSetRungPositions();
  1746.         num1 += num2;
  1747.       }
  1748.       if (num1 == 0)
  1749.         return false;
  1750.       Rectangle VwRc;
  1751.       this.GetViewRect(out VwRc);
  1752.       this.Invalidate(VwRc);
  1753.       this.Refresh();
  1754.       if (this.m_pCurrentTopViewRung != null && this._SetVertScrollbarPos != null)
  1755.         this._SetVertScrollbarPos(this.m_pCurrentTopViewRung.GetRungNumber());
  1756.       return true;
  1757.     }
  1758.  
  1759.     private bool OnHScrollLinesLeft(int nlines)
  1760.     {
  1761.       if (nlines <= 0)
  1762.         return false;
  1763.       int ladderWindowLeft = this.m_nLadderWindowLeft;
  1764.       int nScrollWidth = this.m_nScrollWidth;
  1765.       this.m_nLadderWindowLeft += (nScrollWidth <= 100 ? 1 : nScrollWidth / 100) * nlines;
  1766.       if (this.m_nLadderWindowLeft > 0)
  1767.         this.m_nLadderWindowLeft = 0;
  1768.       if (ladderWindowLeft == this.m_nLadderWindowLeft)
  1769.         return false;
  1770.       Rectangle VwRc;
  1771.       this.GetViewRect(out VwRc);
  1772.       VwRc.Y += this.m_nLadderWindowTop;
  1773.       if (this._SetHorizScrollbarPos != null)
  1774.         this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
  1775.       this.OnSetRungPositions();
  1776.       this.Invalidate(VwRc);
  1777.       this.Refresh();
  1778.       return true;
  1779.     }
  1780.  
  1781.     private bool OnHScrollLinesRight(int nlines)
  1782.     {
  1783.       if (nlines <= 0)
  1784.         return false;
  1785.       int ladderWindowLeft = this.m_nLadderWindowLeft;
  1786.       int nScrollWidth = this.m_nScrollWidth;
  1787.       this.m_nLadderWindowLeft -= (nScrollWidth <= 100 ? 1 : nScrollWidth / 100) * nlines;
  1788.       if (this.m_nLadderWindowLeft < -nScrollWidth)
  1789.         this.m_nLadderWindowLeft = -nScrollWidth;
  1790.       if (ladderWindowLeft == this.m_nLadderWindowLeft)
  1791.         return false;
  1792.       Rectangle VwRc;
  1793.       this.GetViewRect(out VwRc);
  1794.       VwRc.Y += this.m_nLadderWindowTop;
  1795.       if (this._SetHorizScrollbarPos != null)
  1796.         this._SetHorizScrollbarPos(-this.m_nLadderWindowLeft);
  1797.       this.OnSetRungPositions();
  1798.       this.Invalidate(VwRc);
  1799.       this.Refresh();
  1800.       return true;
  1801.     }
  1802.  
  1803.     private void CloseEditWindows() => this.GetEditor().RemoveAllEditControls();
  1804.  
  1805.     private void OnRightButtonDown(Point pt)
  1806.     {
  1807.       this.CloseEditWindows();
  1808.       if (!this.IsEditable() || this.IsCompareView)
  1809.         return;
  1810.       this.contextMainMenu.Show((Control) this, pt);
  1811.     }
  1812.  
  1813.     private void OnMiddleButtonDown(Point pt) => this.CloseEditWindows();
  1814.  
  1815.     private void OnLeftButtonDown(Point pt)
  1816.     {
  1817.       if (!this.IsEditable())
  1818.         return;
  1819.       bool flag1 = this.SetCursor(pt);
  1820.       IRungViewElement pAtElementInRung = this.m_pCursorElement;
  1821.       CVRungdef pCursorRung = this.m_pCursorRung;
  1822.       IRungElement docrung = (IRungElement) null;
  1823.       if (pCursorRung != null)
  1824.         docrung = pCursorRung.GetRungElement();
  1825.       IRungElement rungelem = (IRungElement) null;
  1826.       if (pAtElementInRung != null)
  1827.         rungelem = pAtElementInRung.GetRungElement();
  1828.       this.CloseEditWindows();
  1829.       CRung crung = (CRung) null;
  1830.       if (this.m_pCursorRung != null)
  1831.         crung = (CRung) this.m_pCursorRung.GetRungElem();
  1832.       IRungElement rungElement = (IRungElement) null;
  1833.       if (this.m_pCursorElement != null)
  1834.         rungElement = this.m_pCursorElement.GetRungElement();
  1835.       if (crung != docrung || rungElement != rungelem)
  1836.       {
  1837.         CVRungdef viewRung = this.GetViewRung(docrung);
  1838.         if (viewRung != null)
  1839.           pAtElementInRung = viewRung.GetViewElement(rungelem);
  1840.         if (viewRung != null && pAtElementInRung != null)
  1841.           this.SetCursor(viewRung, pAtElementInRung);
  1842.         else if (viewRung != null)
  1843.           this.SetCursor(viewRung, (IRungViewElement) viewRung);
  1844.       }
  1845.       if (!flag1)
  1846.         return;
  1847.       Keys modifierKeys = Control.ModifierKeys;
  1848.       bool flag2 = false;
  1849.       if (modifierKeys == Keys.Shift)
  1850.         flag2 = true;
  1851.       bool flag3 = false;
  1852.       if (modifierKeys == Keys.Control)
  1853.         flag3 = true;
  1854.       if (!flag2 && !flag3)
  1855.         this.m_pCursorElement.GetRungElement()?.IsBranch();
  1856.       this.m_DragStartPoint = pt;
  1857.     }
  1858.  
  1859.     private void OnLeftButtonUp(Point pt)
  1860.     {
  1861.       if (!this.IsEditable())
  1862.         return;
  1863.       if (this.m_nLeftMouseButUpActionToDo == 1)
  1864.       {
  1865.         this.ClearAllSelections();
  1866.         this.m_nLeftMouseButUpActionToDo = 0;
  1867.       }
  1868.       else
  1869.       {
  1870.         if (this.m_nLeftMouseButUpActionToDo != 2)
  1871.           return;
  1872.         this.SelectItem(this.m_pCursorRung, this.m_pCursorElement);
  1873.         this.ClearAnchor();
  1874.         this.m_nLeftMouseButUpActionToDo = 0;
  1875.       }
  1876.     }
  1877.  
  1878.     private void MoveCursorHome() => this.SetCursor(this.m_pCursorRung, (IRungViewElement) this.m_pCursorRung);
  1879.  
  1880.     private void MoveCursorEnd()
  1881.     {
  1882.       if (this.m_pCursorRung == null)
  1883.         return;
  1884.       this.SetCursor(this.m_pCursorRung, this.m_pCursorRung.GetCursorLast(this));
  1885.     }
  1886.  
  1887.     private void MoveCursorToRung(int nRungNum) => this.MoveCursorToRung(this.GetViewRung(nRungNum));
  1888.  
  1889.     private void MoveCursorToRung(CVRungdef pRung)
  1890.     {
  1891.       if (pRung == null)
  1892.         return;
  1893.       this.GotoRung(pRung);
  1894.       Keys modifierKeys = Control.ModifierKeys;
  1895.       bool flag = false;
  1896.       if (modifierKeys == Keys.Shift)
  1897.         flag = true;
  1898.       if (flag)
  1899.         this.SetCursorAndSelect(pRung, (IRungViewElement) pRung);
  1900.       else
  1901.         this.SetCursor(pRung, (IRungViewElement) pRung);
  1902.     }
  1903.  
  1904.     private void GotoRungNumber(int rungNumber) => this.GotoRung(this.GetViewRung(rungNumber));
  1905.  
  1906.     private void GotoRungAt(int index) => this.GotoRung(this.GetViewRungAt(index));
  1907.  
  1908.     public void GotoNextRung()
  1909.     {
  1910.       if (this.m_pCurrentTopViewRung == null || this.m_pCurrentTopViewRung.Next() == null)
  1911.         return;
  1912.       this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Next());
  1913.     }
  1914.  
  1915.     public void GotoPrevRung()
  1916.     {
  1917.       if (this.m_pCurrentTopViewRung == null)
  1918.         return;
  1919.       if (this.m_nTopRungOffset != this.m_nLadderWindowTop)
  1920.       {
  1921.         this.GotoRung(this.m_pCurrentTopViewRung);
  1922.       }
  1923.       else
  1924.       {
  1925.         if (this.m_pCurrentTopViewRung.Previous() == null)
  1926.           return;
  1927.         this.GotoRung((CVRungdef) this.m_pCurrentTopViewRung.Previous());
  1928.       }
  1929.     }
  1930.  
  1931.     private void GotoRung(CVRungdef ToRung, int rungoffset)
  1932.     {
  1933.       if (ToRung == null)
  1934.         return;
  1935.       int rungNumber = ToRung.GetRungNumber();
  1936.       CVRungdef pVRung = ToRung.IsBlankRung || rungNumber == -1 ? ToRung : this.GetViewRung(rungNumber);
  1937.       if (pVRung == null)
  1938.         return;
  1939.       this.SetTopRung(pVRung);
  1940.       this.m_nTopRungOffset = rungoffset;
  1941.       this.OnSetRungPositions();
  1942.       this.Refresh();
  1943.       if (this._SetVertScrollbarPos == null)
  1944.         return;
  1945.       this._SetVertScrollbarPos(rungNumber);
  1946.     }
  1947.  
  1948.     private void GotoRung(CVRungdef ToRung) => this.GotoRung(ToRung, this.m_nLadderWindowTop);
  1949.  
  1950.     private CVRungdef GetLastViewRung() => this.m_Rungs != null && this.m_Rungs.Count > 0 ? (CVRungdef) this.m_Rungs[this.m_Rungs.Count - 1] : (CVRungdef) null;
  1951.  
  1952.     private CVRungdef GetFirstViewRung() => this.m_Rungs != null && this.m_Rungs.Count > 0 ? (CVRungdef) this.m_Rungs[0] : (CVRungdef) null;
  1953.  
  1954.     private CVRungdef GetViewRung(int rungnumber)
  1955.     {
  1956.       if (this.m_Rungs != null)
  1957.       {
  1958.         foreach (CVRungdef rung in this.m_Rungs)
  1959.         {
  1960.           if (rung.GetRungNumber() == rungnumber)
  1961.             return rung;
  1962.         }
  1963.       }
  1964.       return (CVRungdef) null;
  1965.     }
  1966.  
  1967.     private CVRungdef GetViewRungAt(int index)
  1968.     {
  1969.       if (this.m_Rungs == null)
  1970.         return (CVRungdef) null;
  1971.       return this.m_Rungs.Count > index ? (CVRungdef) this.m_Rungs[index] : (CVRungdef) this.m_Rungs[this.m_Rungs.Count - 1];
  1972.     }
  1973.  
  1974.     private void MoveCursorLastRung() => this.MoveCursorToRung(this.GetLastViewRung());
  1975.  
  1976.     private void MoveCursorFirstRung() => this.MoveCursorToRung(this.GetFirstViewRung());
  1977.  
  1978.     private void MoveCursorLeft()
  1979.     {
  1980.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  1981.       {
  1982.         this.GotoRung(this.m_pCursorRung);
  1983.         if (this.m_pCursorRung.MatchingViewRung != null)
  1984.           this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
  1985.       }
  1986.       if (this.m_pCursorElement == null)
  1987.         return;
  1988.       IRungViewElement cursorLeft = this.m_pCursorElement.GetCursorLeft(this);
  1989.       if (cursorLeft != null)
  1990.       {
  1991.         this.SetCursorAndSelect(this.m_pCursorRung, cursorLeft);
  1992.       }
  1993.       else
  1994.       {
  1995.         if (this.m_pCursorRung == null || this.m_pCursorRung.Previous() == null)
  1996.           return;
  1997.         this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Previous(), this.m_pCursorRung.Previous().GetCursorLast(this));
  1998.       }
  1999.     }
  2000.  
  2001.     private void MoveCursorRight()
  2002.     {
  2003.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  2004.       {
  2005.         this.GotoRung(this.m_pCursorRung);
  2006.         if (this.m_pCursorRung.MatchingViewRung != null)
  2007.           this.MatchingView.GotoRung(this.m_pCursorRung.MatchingViewRung);
  2008.       }
  2009.       if (this.m_pCursorElement == null)
  2010.         return;
  2011.       IRungViewElement cursorRight = this.m_pCursorElement.GetCursorRight(this);
  2012.       if (cursorRight != null)
  2013.       {
  2014.         this.SetCursorAndSelect(this.m_pCursorRung, cursorRight);
  2015.       }
  2016.       else
  2017.       {
  2018.         if (this.m_pCursorRung == null || this.m_pCursorRung.Next() == null)
  2019.           return;
  2020.         this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Next(), this.m_pCursorRung.Next());
  2021.       }
  2022.     }
  2023.  
  2024.     private void MoveCursorUp()
  2025.     {
  2026.       if (this.m_pCursorElement == null)
  2027.         return;
  2028.       IRungViewElement cursorUp = this.m_pCursorElement.GetCursorUp(this);
  2029.       if (cursorUp != null)
  2030.       {
  2031.         if (cursorUp == this.m_pCursorElement)
  2032.           this.m_pCursorElement.MoveCursorUp(this);
  2033.         else
  2034.           this.SetCursorAndSelect(this.m_pCursorRung, cursorUp);
  2035.       }
  2036.       else
  2037.       {
  2038.         if (this.m_pCursorRung == null || this.m_pCursorRung.Previous() == null)
  2039.           return;
  2040.         this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Previous(), this.m_pCursorRung.Previous());
  2041.       }
  2042.     }
  2043.  
  2044.     private void MoveCursorDown()
  2045.     {
  2046.       if (this.m_pCursorElement == null)
  2047.         return;
  2048.       IRungViewElement cursorDown = this.m_pCursorElement.GetCursorDown(this);
  2049.       if (cursorDown != null)
  2050.       {
  2051.         if (cursorDown == this.m_pCursorElement)
  2052.           this.m_pCursorElement.MoveCursorDown(this);
  2053.         else
  2054.           this.SetCursorAndSelect(this.m_pCursorRung, cursorDown);
  2055.       }
  2056.       else
  2057.       {
  2058.         if (this.m_pCursorRung == null || this.m_pCursorRung.Next() == null)
  2059.           return;
  2060.         this.SetCursorAndSelect((CVRungdef) this.m_pCursorRung.Next(), this.m_pCursorRung.Next());
  2061.       }
  2062.     }
  2063.  
  2064.     private bool MoveCursorPrevOperand()
  2065.     {
  2066.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  2067.         this.GotoRung(this.m_pCursorRung);
  2068.       if (this.m_pCursorElement != null && this.m_pCursorElement.IsInstruction() && this.m_pCursorElement.MovePrevOpndField(this))
  2069.         return true;
  2070.       IRungViewElement pAtElementInRung = (IRungViewElement) null;
  2071.       if (this.m_pCursorElement != null)
  2072.         pAtElementInRung = this.m_pCursorElement.GetCursorPrevious(this);
  2073.       CVRungdef cvRungdef = this.m_pCursorRung;
  2074.       while (cvRungdef != null)
  2075.       {
  2076.         while (pAtElementInRung != null && !pAtElementInRung.IsInstruction())
  2077.           pAtElementInRung = pAtElementInRung.GetCursorPrevious(this);
  2078.         if (pAtElementInRung != null)
  2079.         {
  2080.           this.SetCursor(cvRungdef, pAtElementInRung);
  2081.           if (this.m_pCursorElement != null)
  2082.             this.m_pCursorElement.SetLastOpndField(this);
  2083.           return true;
  2084.         }
  2085.         if (cvRungdef.Previous() != null)
  2086.         {
  2087.           cvRungdef = (CVRungdef) cvRungdef.Previous();
  2088.           this.OnRefreshRung(cvRungdef);
  2089.           pAtElementInRung = cvRungdef.GetCursorLast(this);
  2090.         }
  2091.         else
  2092.           break;
  2093.       }
  2094.       return false;
  2095.     }
  2096.  
  2097.     private bool MoveCursorNextOperand()
  2098.     {
  2099.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  2100.         this.GotoRung(this.m_pCursorRung);
  2101.       if (this.m_pCursorElement != null && this.m_pCursorElement.IsInstruction() && this.m_pCursorElement.MoveNextOpndField(this))
  2102.         return true;
  2103.       IRungViewElement pAtElementInRung = (IRungViewElement) null;
  2104.       if (this.m_pCursorElement != null)
  2105.         pAtElementInRung = this.m_pCursorElement.GetCursorNext(this);
  2106.       CVRungdef cvRungdef = this.m_pCursorRung;
  2107.       while (cvRungdef != null)
  2108.       {
  2109.         while (pAtElementInRung != null && !pAtElementInRung.IsInstruction())
  2110.           pAtElementInRung = pAtElementInRung.GetCursorNext(this);
  2111.         if (pAtElementInRung != null)
  2112.         {
  2113.           this.SetCursor(cvRungdef, pAtElementInRung);
  2114.           return true;
  2115.         }
  2116.         if (cvRungdef.Next() != null)
  2117.         {
  2118.           cvRungdef = (CVRungdef) cvRungdef.Next();
  2119.           this.OnRefreshRung(cvRungdef);
  2120.           pAtElementInRung = (IRungViewElement) cvRungdef;
  2121.         }
  2122.         else
  2123.           break;
  2124.       }
  2125.       return false;
  2126.     }
  2127.  
  2128.     public LadderViewEditClass GetEditor() => this.mTheEditor;
  2129.  
  2130.     private void OnEditIns()
  2131.     {
  2132.       if (this.m_pCursorElement == null && this.m_pCursorRung == null)
  2133.         return;
  2134.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  2135.         this.GotoRung(this.m_pCursorRung);
  2136.       this.m_pCursorElement.Edit(this, "");
  2137.     }
  2138.  
  2139.     private void EditIns(char nCharPressed)
  2140.     {
  2141.       if (this.m_pCursorElement == null && this.m_pCursorRung == null)
  2142.         return;
  2143.       if (!this.IsRungOnScreen(this.m_pCursorRung))
  2144.         this.GotoRung(this.m_pCursorRung);
  2145.       this.m_pCursorElement.Edit(this, nCharPressed.ToString());
  2146.     }
  2147.  
  2148.     private void CLadderView_DoubleClick(object sender, EventArgs e) => this.OnEditIns();
  2149.  
  2150.     private void CLadderView_Enter(object sender, EventArgs e)
  2151.     {
  2152.       this.Focus();
  2153.       this.m_bHaveFocus = true;
  2154.       this.Refresh();
  2155.     }
  2156.  
  2157.     private void CLadderView_Leave(object sender, EventArgs e)
  2158.     {
  2159.       this.m_bHaveFocus = false;
  2160.       this.Refresh();
  2161.     }
  2162.  
  2163.     private void CLadderView_SizeChanged(object sender, EventArgs e) => this.OnSizeChanged();
  2164.  
  2165.     public bool CanViewZoomIn() => (double) (this.m_Options.LadderInstructionFont.Size + 0.5f) <= 20.0;
  2166.  
  2167.     public bool CanViewZoomOut() => (double) (this.m_Options.LadderInstructionFont.Size - 0.5f) > 0.0;
  2168.  
  2169.     public void OnZoomIn()
  2170.     {
  2171.       Font ladderInstructionFont = this.m_Options.LadderInstructionFont;
  2172.       float emSize = ladderInstructionFont.Size + 0.5f;
  2173.       if ((double) emSize > 20.0)
  2174.         return;
  2175.       this.m_Options.LadderInstructionFont = new Font(ladderInstructionFont.FontFamily, emSize, ladderInstructionFont.Style);
  2176.       this.ResetView();
  2177.     }
  2178.  
  2179.     public void OnZoomOut()
  2180.     {
  2181.       Font ladderInstructionFont = this.m_Options.LadderInstructionFont;
  2182.       float emSize = ladderInstructionFont.Size - 0.5f;
  2183.       if ((double) emSize <= 0.0)
  2184.         return;
  2185.       this.m_Options.LadderInstructionFont = new Font(ladderInstructionFont.FontFamily, emSize, ladderInstructionFont.Style);
  2186.       this.ResetView();
  2187.     }
  2188.  
  2189.     public void SetControllerVersion(string sVersion)
  2190.     {
  2191.       if (this.m_Controller == null)
  2192.         return;
  2193.       this.m_Controller.SetMajorRevision(sVersion);
  2194.     }
  2195.  
  2196.     private struct PrintPageInfo
  2197.     {
  2198.       public CVRungdef StartRung;
  2199.       public CVRungdef EndRung;
  2200.       public Rectangle ClipRect;
  2201.       public int TopRungOffset;
  2202.  
  2203.       public int RungCount
  2204.       {
  2205.         get
  2206.         {
  2207.           int rungCount = 1;
  2208.           IRungViewElement rungViewElement = (IRungViewElement) this.StartRung;
  2209.           while (rungViewElement != this.EndRung)
  2210.           {
  2211.             rungViewElement = rungViewElement.Next();
  2212.             ++rungCount;
  2213.           }
  2214.           return rungCount;
  2215.         }
  2216.       }
  2217.     }
  2218.   }
  2219. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement