Exemplo n.º 1
0
        public static IEnumerable <TControl> RenderControlList <TModel, TKey, TControl>(this IEnumerable <TModel> models, Control.ControlCollection controls, Func <TModel, int, TKey> key, Func <TModel, int, TControl> builder) where TControl : Control
        {
            var existingKeys = controls.OfType <Control>().Where(x => x.Tag is ControlKey).ToDictionary(x => ((ControlKey)x.Tag).Key);
            var index        = 0;
            var result       = new List <TControl>();

            foreach (var m in models)
            {
                var k = key(m, index);
                if (existingKeys.TryGetValue(k, out Control c))
                {
                    // not build again
                    existingKeys.Remove(k);
                }
                else
                {
                    c     = builder(m, index);
                    c.Tag = new ControlKey(k);
                    controls.Add(c);
                }

                controls.SetChildIndex(c, index);
                index++;
                result.Add((TControl)c);
            }

            // remove unused controls
            foreach (var value in existingKeys.Values)
            {
                controls.Remove(value);
            }

            return(result);
        }
Exemplo n.º 2
0
        // for ControlCollection
        public static bool Swap(this Control.ControlCollection source, int fromIndex, int toIndex)
        {
            Action <int, object> insertAtCallback = (index, item) => {
                source.Add((Control)item);
                source.SetChildIndex((Control)item, index);
            };

            return(source.Swap(fromIndex, toIndex, insertAtCallback));
        }
Exemplo n.º 3
0
 private void loadSettings()
 {
     foreach (var setting in SettingsManager.Instance.RegisteredSettings)
     {
         ISettingEditorControl editorControl = SettingEditorTypeRegister.Instance.GetEditorForSetting(setting);
         Control editorControlCasted         = editorControl as Control;
         if (editorControlCasted != null)
         {
             editorControlCasted.Dock = DockStyle.Top;
             TabPage pageForCategory = getPageForCategory(setting.Category);
             Control.ControlCollection pagesControlCollection = pageForCategory.Controls;
             pagesControlCollection.Add(editorControlCasted);
             pagesControlCollection.SetChildIndex(editorControlCasted, 0);
         }
     }
 }
Exemplo n.º 4
0
        public static void Insert(this Control.ControlCollection controlCollection, int index, Control item)
        {
            bool isCListBox = _controlsListBoxType.IsAssignableFrom(controlCollection.Owner.GetType());

            if (isCListBox)
            {
                ((ControlsListBox)controlCollection.Owner).LockUpdateFor(item);
            }

            if (controlCollection.Count < index)
            {
                throw new IndexOutOfRangeException();
            }
            controlCollection.Add(item);
            controlCollection.SetChildIndex(item, index);

            if (isCListBox)
            {
                ((ControlsListBox)controlCollection.Owner).UnlockUpdateFor(item);
            }
        }
Exemplo n.º 5
0
        public static void InsertAfter(this Control.ControlCollection controls, Control after, Control newCtrl)
        {
            var newIndex = controls.Count;

            controls.Add(newCtrl);

            if (after != null)
            {
                var index = 0;
                foreach (var ctrl in controls)
                {
                    if (ctrl == after)
                    {
                        break;
                    }
                    index++;
                }
                if (index < newIndex)
                {
                    controls.SetChildIndex(newCtrl, index + 1);
                }
            }
        }
Exemplo n.º 6
0
        public bool OnLoad(LogFile logfile, Control chartSpectrum, Label labelWaterfall, Control.ControlCollection collection, MainForm mainForm)
        {
            Control waterfall     = null;
            bool    foundWriteLog = false;

            // registry goop to look unconditionally in 32bit registry for WriteLog, whether we are x86 or x64
            Microsoft.Win32.RegistryKey rk32 = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Registry32);
            {
                if (null != rk32)
                {
                    Microsoft.Win32.RegistryKey wlrk32 = rk32.OpenSubKey(@"Software\\W5XD\\WriteLog\\Install");
                    if (null != wlrk32)
                    {
                        object wlDir = wlrk32.GetValue("Directory");

                        /* SetCurrentDirectory
                         * Why?
                         * The WriteLog waterfall depends on the d3dcsx.dll (Microsoft's DirectX2D). That dll must be installed
                         * on a per-application basis. Win32's dll lookup for the case of loading for a .net assembly in the GAC
                         * needs to find d3dcxs. WL installs a copy, so we "cd" this exe there so it will be found.
                         */
                        if (null != wlDir)
                        {
                            try
                            {
                                System.IO.Directory.SetCurrentDirectory(wlDir.ToString() +
#if BUILD_X86
                                                                        "Programs"
#elif BUILD_X64
                                                                        "DigiRite X64 Waterfall"
#endif
                                                                        );
                                foundWriteLog = true;
                            }
                            catch (System.Exception) { } // ignore failure
                        }
                        wlrk32.Close();
                    }
                    rk32.Close();
                }
            }

            if (!foundWriteLog)
            {   // second chance look for waterfall install
                Microsoft.Win32.RegistryKey rkMachineDefault = Microsoft.Win32.RegistryKey.OpenBaseKey(Microsoft.Win32.RegistryHive.LocalMachine, Microsoft.Win32.RegistryView.Default);
                if (null != rkMachineDefault)
                {
                    Microsoft.Win32.RegistryKey wf = rkMachineDefault.OpenSubKey(@"Software\\DigiRite\\Waterfall");
                    if (null != wf)
                    {
                        object wfDir = wf.GetValue("Directory");
                        if (null != wfDir)
                        {
                            try {
                                System.IO.Directory.SetCurrentDirectory(wfDir.ToString());
                            }  catch (System.Exception) { } // ignore failure
                        }
                        wf.Close();
                    }
                    rkMachineDefault.Close();
                }
            }

            try
            {
                // if WriteLog's DigiRiteWaterfall assembly loads, use it.
                System.Reflection.Assembly waterfallAssembly = System.Reflection.Assembly.Load(
                    "WriteLogWaterfallDigiRite, Version=12.0.52.5, Culture=neutral, PublicKeyToken=e34bde9f0678e8b6");
                System.Type t = waterfallAssembly.GetType("WriteLog.WaterfallFactory");
                if (t == null)
                {
                    throw new System.Exception("WaterfallFactory type not found");
                }

                wfFactory       = (WriteLog.IWaterfallFactory)System.Activator.CreateInstance(t);
                waterfall       = (Control)wfFactory.GetWaterfall();
                waterfallEditor = wfFactory.GetEditor() as Form;
                iwaterfall      = (WriteLog.IWaterfallV3)waterfall;
            }
            catch (System.Exception ex)
            {                                                                   // if WriteLog is not installed, this is "normal successful completion"
                logfile.SendToLog("Load waterfall exception " + ex.ToString()); // not normal
            }

            if (null != waterfall)
            {   // waterfall loaded. it goes where chartSpectrum was.
                ((System.ComponentModel.ISupportInitialize)waterfall).BeginInit();
                waterfall.Location      = chartSpectrum.Location;
                waterfall.Dock          = chartSpectrum.Dock;
                waterfall.Size          = chartSpectrum.Size;
                waterfall.TabIndex      = chartSpectrum.TabIndex;
                waterfall.Name          = "waterfall";
                waterfall.Font          = labelWaterfall.Font; // labelWaterfall is placeholder for properties
                waterfall.BackColor     = labelWaterfall.BackColor;
                waterfall.ForeColor     = labelWaterfall.ForeColor;
                waterfall.Visible       = true;
                iwaterfall.TxFreqHz     = mainForm.TxFrequency;
                iwaterfall.RxFreqHz     = mainForm.RxFrequency;
                iwaterfall.onTxFreqMove = new WriteLog.OnFreqMove((int hz) => { mainForm.TxFrequency = hz; });
                iwaterfall.onRxFreqMove = new WriteLog.OnFreqMove((int hz) => { mainForm.RxFrequency = hz; });
                ((System.ComponentModel.ISupportInitialize)waterfall).EndInit();

                collection.Remove(chartSpectrum);
                collection.Add(waterfall);
                collection.SetChildIndex(waterfall, 0);

                peak        = iwaterfall as WriteLog.IPeakRx;
                annotations = iwaterfall as WriteLog.IAnnotations;
            }

            return(iwaterfall != null);
        }
 public static void Insert(this Control.ControlCollection collection, Control control, int pos)
 {
     collection.Add(control);
     collection.SetChildIndex(control, pos);
 }
Exemplo n.º 8
0
        public void Import(ref int gooseItems, Control.ControlCollection cc, PacketDevice netDev)
        {
            using (OpenFileDialog importOpenFileDialog = new OpenFileDialog())
            {
                importOpenFileDialog.Title  = "Select XML File";
                importOpenFileDialog.Filter = "Xml File(*.xml)|*.xml";

                if (DialogResult.OK == importOpenFileDialog.ShowDialog())
                {
                    XDocument xmlDoc = XDocument.Load(importOpenFileDialog.FileName);
                    XElement  gooses = xmlDoc.Element("Gooses");

                    if (gooses != null && xmlDoc.Elements("Gooses").Count() == 1)
                    {
                        if (gooses.Elements().Count() > 0)
                        {
                            foreach (XElement goose in gooses.Elements())
                            {
                                GooseControl gc = new GooseControl("Goose " + gooseItems++.ToString() + ":", "00:00:00:00:00:00", netDev);

                                XElement parameters = goose.Element("Parameters");
                                if (parameters != null && goose.Elements("Parameters").Count() == 1)
                                {
                                    if (parameters.Elements().Count() == 17)
                                    {
                                        foreach (XElement parameter in parameters.Elements())
                                        {
                                            if (parameter.Attribute("Value") != null)
                                            {
                                                gc.gooseParameters[parameter.Name.ToString()] = parameter.Attribute("Value").Value.ToString();
                                            }
                                            else
                                            {
                                                MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                return;
                                            }
                                        }

                                        gc.updateComponents();
                                    }
                                    else
                                    {
                                        MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        return;
                                    }

                                    XElement dataset = goose.Element("DataSet");

                                    if (dataset != null && goose.Elements("DataSet").Count() == 1)
                                    {
                                        if (dataset.Elements("Data").Count() > 0)
                                        {
                                            foreach (XElement data in dataset.Elements("Data"))
                                            {
                                                recursiveCreateDataList(gc.dataList, data);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                        return;
                                    }

                                    XElement seqdata = goose.Element("SeqData");

                                    if (seqdata != null && goose.Elements("SeqData").Count() == 1)
                                    {
                                        if (seqdata.Elements("Data").Count() > 0)
                                        {
                                            NodeGVL gvl = new NodeGVL("Data");

                                            GooseDataEdit gde = new GooseDataEdit();

                                            int i = 0;

                                            foreach (GOOSE_ASN1_Model.Data dataListCn in gc.dataList)
                                            {
                                                i = gde.recursiveReadData(null, dataListCn, gvl, i, DateTime.Now);
                                            }

                                            gc.seqData.Clear();

                                            foreach (XElement seqd in seqdata.Elements("Data"))
                                            {
                                                if (seqd.Attribute("Name") != null)
                                                {
                                                    if (gvl.GetChildNodes().Length > 0)
                                                    {
                                                        foreach (NodeGData ngdcn in gvl.GetChildNodes())
                                                        {
                                                            NodeGData fngd;
                                                            if ((fngd = recursiveFindNodeGData(ngdcn, seqd.Attribute("Name").Value)) != null)
                                                            {
                                                                if (seqd.Attribute("Duration") != null && seqd.Attribute("Value") != null)
                                                                {
                                                                    gc.seqData.Add(new SeqData(fngd, seqd.Attribute("Value").Value, Convert.ToInt32(seqd.Attribute("Duration").Value)));
                                                                }
                                                                else
                                                                {
                                                                    MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                                    return;
                                                                }

                                                                break;
                                                            }
                                                        }
                                                    }
                                                }
                                                else
                                                {
                                                    MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                                    return;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                            return;
                                        }
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                                    return;
                                }

                                gc.Dock = DockStyle.Top;
                                cc.Add(gc);
                                cc.SetChildIndex(gc, 0);
                            }
                        }
                        else
                        {
                            MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid XML file !", "Import from Xml", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
        }
Exemplo n.º 9
0
        private static void ReorderChildControlsByLoc(Control c)
        {
            if (c == null)
            {
                Debug.Assert(false); return;
            }

            Control.ControlCollection cc = c.Controls;
            if ((cc == null) || (cc.Count == 0))
            {
                return;
            }

            c.SuspendLayout();
            try
            {
                List <KeyValuePair <Rectangle, Control> > l =
                    new List <KeyValuePair <Rectangle, Control> >();
                int cDockT = 0, cDockB = 0, cDockL = 0, cDockR = 0, cDockF = 0;

                foreach (Control cSub in cc)
                {
                    if ((cSub == null) || (cSub == c))
                    {
                        Debug.Assert(false); continue;
                    }

                    Rectangle rect = cSub.Bounds;
                    if ((rect.Width < 0) || (rect.Height < 0))
                    {
                        Debug.Assert(false); continue;
                    }

                    switch (cSub.Dock)
                    {
                    case DockStyle.Top:
                        ++cDockT; break;

                    case DockStyle.Bottom:
                        ++cDockB; break;

                    case DockStyle.Left:
                        ++cDockL; break;

                    case DockStyle.Right:
                        ++cDockR; break;

                    case DockStyle.Fill:
                        ++cDockF; break;

                    default: break;
                    }

                    l.Add(new KeyValuePair <Rectangle, Control>(rect, cSub));
                }

                // Reordering docked controls can move them visually
                bool bDockMovePossible = (
                    ((cDockT + cDockL + cDockF) >= 2) ||                    // Top left
                    ((cDockT + cDockR + cDockF) >= 2) ||                    // Top right
                    ((cDockB + cDockL + cDockF) >= 2) ||                    // Bottom left
                    ((cDockB + cDockR + cDockF) >= 2));                     // Bottom right

                bool bIgnoreType = ((c is DataGridView) || (c is NumericUpDown) ||
                                    (c is SplitContainer) || (c is TabControl) || (c is ToolStrip));

                Debug.Assert(bIgnoreType || !cc.IsReadOnly);
                if ((l.Count >= 2) && !bDockMovePossible && !bIgnoreType &&
                    !cc.IsReadOnly)
                {
                    l.Sort(GlobalWindowManager.CompareByLoc);

                    for (int i = 0; i < l.Count; ++i)
                    {
                        cc.SetChildIndex(l[i].Value, i);
                    }

#if DEBUG
                    for (int i = 0; i < l.Count; ++i)
                    {
                        Debug.Assert(cc[i] == l[i].Value);
                    }
#endif
                }

                foreach (KeyValuePair <Rectangle, Control> kvp in l)
                {
                    ReorderChildControlsByLoc(kvp.Value);
                }
            }
            catch (Exception) { Debug.Assert(false); }
            finally { c.ResumeLayout(); }
        }