Esempio n. 1
0
        public EcasEnum(EcasEnumItem[] vItems)
        {
            if(vItems == null) throw new ArgumentNullException("vItems");

            m_vItems = vItems;
        }
Esempio n. 2
0
        public static void ParametersToDataGridView(DataGridView dg,
                                                    IEcasParameterized p, IEcasObject objDefaults)
        {
            if (dg == null)
            {
                throw new ArgumentNullException("dg");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }
            if (p.Parameters == null)
            {
                throw new ArgumentException();
            }
            if (objDefaults == null)
            {
                throw new ArgumentNullException("objDefaults");
            }
            if (objDefaults.Parameters == null)
            {
                throw new ArgumentException();
            }

            dg.Rows.Clear();
            dg.Columns.Clear();

            Color clrBack      = dg.DefaultCellStyle.BackColor;
            Color clrValueBack = dg.DefaultCellStyle.BackColor;

            if (clrValueBack.GetBrightness() >= 0.5)
            {
                clrValueBack = UIUtil.DarkenColor(clrValueBack, 0.075);
            }
            else
            {
                clrValueBack = UIUtil.LightenColor(clrValueBack, 0.075);
            }

            dg.ColumnHeadersVisible = false;
            dg.RowHeadersVisible    = false;
            dg.GridColor            = clrBack;
            dg.BackgroundColor      = clrBack;
            dg.DefaultCellStyle.SelectionBackColor = clrBack;
            dg.DefaultCellStyle.SelectionForeColor = dg.DefaultCellStyle.ForeColor;
            dg.AllowDrop                = false;
            dg.AllowUserToAddRows       = false;
            dg.AllowUserToDeleteRows    = false;
            dg.AllowUserToOrderColumns  = false;
            dg.AllowUserToResizeColumns = false;
            dg.AllowUserToResizeRows    = false;
            // dg.EditMode: see below
            dg.Tag = p;

            int nWidth = (dg.ClientSize.Width - UIUtil.GetVScrollBarWidth());

            dg.Columns.Add("Name", KPRes.FieldName);
            dg.Columns.Add("Value", KPRes.FieldValue);
            dg.Columns[0].Width = (nWidth / 2);
            dg.Columns[1].Width = (nWidth / 2);

            bool bUseDefaults = true;

            if (objDefaults.Type == null)
            {
                Debug.Assert(false);
            }                                                                 // Optimistic
            else if (p.Type == null)
            {
                Debug.Assert(false);
            }                                                            // Optimistic
            else if (!objDefaults.Type.Equals(p.Type))
            {
                bUseDefaults = false;
            }

            for (int i = 0; i < p.Parameters.Length; ++i)
            {
                EcasParameter ep = p.Parameters[i];

                dg.Rows.Add();
                DataGridViewRow            row = dg.Rows[dg.Rows.Count - 1];
                DataGridViewCellCollection cc  = row.Cells;

                Debug.Assert(cc.Count == 2);
                cc[0].Value    = ep.Name;
                cc[0].ReadOnly = true;

                string strParam = (bUseDefaults ? EcasUtil.GetParamString(
                                       objDefaults.Parameters, i) : string.Empty);

                DataGridViewCell c = null;
                switch (ep.Type)
                {
                case EcasValueType.String:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = strParam;
                    break;

                case EcasValueType.Bool:
                    c = new DataGridViewCheckBoxCell(false);
                    (c as DataGridViewCheckBoxCell).Value =
                        StrUtil.StringToBool(strParam);
                    break;

                case EcasValueType.EnumStrings:
                    DataGridViewComboBoxCell cmb = new DataGridViewComboBoxCell();
                    cmb.Sorted       = false;
                    cmb.DisplayStyle = DataGridViewComboBoxDisplayStyle.DropDownButton;
                    int iFound = -1;
                    for (int e = 0; e < ep.EnumValues.ItemCount; ++e)
                    {
                        EcasEnumItem eei = ep.EnumValues.Items[e];
                        cmb.Items.Add(eei.Name);
                        if (eei.ID.ToString() == strParam)
                        {
                            iFound = e;
                        }
                    }
                    if (iFound >= 0)
                    {
                        cmb.Value = ep.EnumValues.Items[iFound].Name;
                    }
                    else if (ep.EnumValues.ItemCount > 0)
                    {
                        cmb.Value = ep.EnumValues.Items[0].Name;
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                    c = cmb;
                    break;

                case EcasValueType.Int64:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = FilterTypeI64(strParam);
                    break;

                case EcasValueType.UInt64:
                    c       = new DataGridViewTextBoxCell();
                    c.Value = FilterTypeU64(strParam);
                    break;

                default:
                    Debug.Assert(false);
                    break;
                }

                if (c != null)
                {
                    cc[1] = c;
                }
                cc[1].ReadOnly                 = false;
                cc[1].Style.BackColor          = clrValueBack;
                cc[1].Style.SelectionBackColor = clrValueBack;
            }

            // Perform postponed setting of EditMode (cannot set it earlier
            // due to a Mono bug on FreeBSD);
            // https://sourceforge.net/p/keepass/discussion/329220/thread/cb8270e2/
            dg.EditMode = DataGridViewEditMode.EditOnEnter;
        }