示例#1
0
        public PopupListBox(object originalValue,
            int rowIndex, FastColumn column, Type columnType,
            Action<FastColumn, int, object> onValueUpdated, Control parent)
        {
            this.rowIndex = rowIndex;
            this.onValueUpdated = onValueUpdated;
            this.parent = parent;
            this.column = column;

            // получить допустимые значения
            if (columnType == typeof(bool)) values = new object[] { false, true };
            else if (columnType.IsSubclassOf(typeof(Enum)))
                values = Enum.GetValues(columnType).Cast<object>().ToArray();
            if (values == null) return;

            // сгенерировать массив строк для указанного типа
            var index = 0;
            foreach (var val in values)
            {
                if (val.Equals(originalValue))
                    selectedIndex = index;
                index++;
                var str = column.formatter == null ? val.ToString() : column.formatter(val);
                stringValues.Add(str);
            }
        }
 public void InvalidateCell(FastColumn col, int row)
 {
     if (!col.Visible)
     {
         return;
     }
     InvalidateCell(columns.IndexOf(col), row);
 }
        // changing selection
        protected virtual void ProcessMouseHitCell(FastColumn col,
                                                   int rowIndex, MouseEventArgs e)
        {
            // do not select string by hitting hyperlink
            if (col.IsHyperlinkStyleColumn)
            {
                return;
            }

            // select cell
            if (SelectEnabled && e.Button == MouseButtons.Left)
            {
                var singleSelectMode = true;
                if (MultiSelectEnabled)
                {
                    singleSelectMode =
                        ModifierKeys != Keys.Shift && ModifierKeys != Keys.Control;
                }
                // single line select
                if (singleSelectMode)
                {
                    // deselect all but current
                    for (var i = 0; i < rows.Count; i++)
                    {
                        rows[i].Selected = i == rowIndex;
                    }
                }
                // multi-line select
                else
                {
                    if (ModifierKeys == Keys.Control)
                    {// add or remove selected
                        rows[rowIndex].Selected = !rows[rowIndex].Selected;
                    }
                    if (ModifierKeys == Keys.Shift)
                    {
                        var beginSelectionIndex = Math.Min(rowIndex, lastHitRow);
                        if (beginSelectionIndex == -1)
                        {
                            beginSelectionIndex = rowIndex;
                        }
                        var endSelectionIndex = Math.Max(rowIndex, lastHitRow);
                        for (var i = beginSelectionIndex; i <= endSelectionIndex; i++)
                        {
                            rows[i].Selected = true;
                        }
                    }
                }

                if (selectionChanged != null)
                {
                    selectionChanged(e, rowIndex, col);
                }
            }
            // redraw
            Invalidate();
        }
示例#4
0
 private void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     var sets = (TradeSignalUpdate)grid.rows[rowIndex].ValueObject;
     if (col.PropertyName == sets.Property(p => p.CategoryName) && e.Button == MouseButtons.Left)
     {
         if (SignalUpdateSelected != null)
             SignalUpdateSelected(sets);
     }
 }
        public Point GetCellCoords(FastColumn column, int rowIndex)
        {
            var shiftX     = scrollBarH.Visible ? scrollBarH.Value : 0;
            var startIndex = scrollBarV.Value >= rows.Count ? 0 : scrollBarV.Value;

            var popTop  = CellHeight * (rowIndex - startIndex) + /*Top +*/ CaptionHeight + 1;
            var popLeft = 1 - shiftX + Columns.TakeWhile(col => col != column).Sum(col => col.ResultedWidth);

            return(new Point(popLeft, popTop));
        }
示例#6
0
 private void OnUserDrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes,
                                 Graphics g, Point leftTop, int cellWidth, int cellHeightI,
                                 Font font, Brush brushFont, Color?fontColor, int rowIndex, int cellPaddingI)
 {
     if (userDrawCellText != null)
     {
         userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeightI, font,
                          brushFont, fontColor, rowIndex, cellPaddingI);
     }
 }
        private void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
        {
            if (!col.IsHyperlinkStyleColumn || e.Button != MouseButtons.Left) return;

            SubscriptionSelected = col.Title == ColTitleSubscribe;
            SignalMakingSelected = col.Title == ColTitleMakeSingal;
            if (!SubscriptionSelected && !SignalMakingSelected) return;
            SelectedCategory = (PaidService)grid.rows[rowIndex].ValueObject;
            DialogResult = DialogResult.OK;
        }
        private void OnValueEntered(FastColumn col, int rowIndex, object newValue)
        {
            var valueObj = rows[rowIndex].ValueObject;

            if (fieldValueChanging != null)
            {
                bool cancel;
                fieldValueChanging(col, rowIndex, valueObj, ref newValue, out cancel);
                if (cancel)
                {
                    return;
                }
            }

            // изменить значение ячейки
            try
            {
                var colPropType = columnProperty[col];

                // если null...
                if (newValue == null || (newValue is string && (string)newValue == ""))
                {
                    if (!colPropType.PropertyType.IsValueType ||
                        colPropType.PropertyType == typeof(string))
                    {
                        colPropType.SetValue(valueObj, null, null);
                        if (fieldValueChanged != null)
                        {
                            fieldValueChanged(col, rowIndex, valueObj);
                        }
                    }
                }
                else if (colPropType.PropertyType == newValue.GetType())
                {
                    colPropType.SetValue(valueObj, newValue, null);
                    if (fieldValueChanged != null)
                    {
                        fieldValueChanged(col, rowIndex, valueObj);
                    }
                }
                else
                {
                    return;
                }
            }
            catch
            {
                return;
            }

            // обновить ячейку
            UpdateRow(rowIndex, valueObj);
            // перерисовать
            InvalidateCell(col, rowIndex);
        }
 private void GridOnUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (col.PropertyName == "Selected" && e.Button == MouseButtons.Left)
     {
         var obj = (GapsByTicker) (grid.rows[rowIndex].ValueObject);
         obj.Selected = !obj.Selected;
         grid.UpdateRow(rowIndex, obj);
         grid.InvalidateCell(col, rowIndex);
         return;
     }
 }
 private void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (rowIndex < 0 || rowIndex >= grid.rows.Count) return;
     if (e.Button == MouseButtons.Left && e.Clicks > 1)
     {
         DialogResult = DialogResult.OK;
         Close();
     }
     //if (grid.rows[rowIndex].Selected)
     //    grid.rows[rowIndex].Selected = false;
 }
        private void GridOnUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
        {
            if (col.PropertyName == "Title" && e.Button == MouseButtons.Left)
            {
                // вызвать скрипт сразу или дать перетащить его на график
                var scriptContainer = (ScriptContainer) grid.rows[rowIndex].ValueObject;
                var script = scriptContainer.script;

                // просто выполнить скрипт
                if (script.ScriptTarget == TerminalScript.TerminalScriptTarget.Терминал)
                {
                    script.ActivateScript(false);
                    //return;
                }
            }
        }
 void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     var objHotKey = grid.rows[rowIndex].ValueObject as ApplicationMessageBinding;
     if (e.Button != MouseButtons.Left || objHotKey == null)
         return;
     if (col.PropertyName == objHotKey.Property(p => p.Key))
     {
         var dlg = new HotKeySetForm(objHotKey);
         if (dlg.ShowDialog() != DialogResult.OK) return;
         grid.UpdateRow(rowIndex, objHotKey);
         grid.InvalidateRow(rowIndex);
     }
     else if (col.PropertyName == objHotKey.Property(p => p.Title))
     {
         txtbxDescription.Text = objHotKey.ActionDescription;
     }
 }
示例#13
0
        private void GridQuoteUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
        {
            if (e.Button == MouseButtons.Right)
            {
                var selected = gridQuote.rows.Where(r => r.Selected).Select(r => (TickerInfo) r.ValueObject).ToList();
                menuQuote.Tag = selected.Count > 1
                                    ? selected
                                    : new List<TickerInfo> {(TickerInfo) gridQuote.rows[rowIndex].ValueObject};
                menuQuote.Show(gridQuote, e.X, e.Y);
                return;
            }

            selectedTicker = (TickerInfo)gridQuote.rows[rowIndex].ValueObject;
            tbActiveBase.Text = selectedTicker.ActiveBase;
            tbActiveCounter.Text = selectedTicker.ActiveCounter;
            tbFormat.Text = string.Format("{0:f" + selectedTicker.Precision + "}", 1.2345678);
        }
        public Point?GetCellUnderCursor(int x, int y)
        {
            if (rows.Count == 0)
            {
                return(null);
            }
            // check Y-coord
            if (IsInHeader(x, y))
            {
                return(null);
            }
            x += scrollBarH.Value;
            // check hit column
            FastColumn column   = null;
            var        left     = 0;
            var        colIndex = 0;

            foreach (var col in columns)
            {
                var right = left + col.ResultedWidth;
                if (x >= left && x < right)
                {
                    // do hit
                    column = col;
                    break;
                }
                left = right;
                colIndex++;
            }
            if (column == null)
            {
                return(null);
            }
            // check row hit
            var startRow  = scrollBarV.Value >= rows.Count ? 0 : scrollBarV.Value;
            var cellY     = y - CaptionHeight;
            var cellIndex = cellY / CellHeight;

            cellIndex += startRow;
            if (cellIndex >= rows.Count)
            {
                return(null);
            }
            return(new Point(colIndex, cellIndex));
        }
示例#15
0
 /// <summary>
 /// Обработчик клика по строке
 /// </summary>
 private void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (e.Button == MouseButtons.Left)
     {
         var ticker = (TickerTag)gridAllTickers.rows[rowIndex].ValueObject;
         switch (col.PropertyName)
         {
             case "IsSelected":
                 ticker.IsSelected = !ticker.IsSelected;
                 break;
             case "IsFavorite":
                 ticker.IsFavorite = !ticker.IsFavorite;
                 break;
         }
         gridAllTickers.UpdateRow(rowIndex, ticker);
         gridAllTickers.InvalidateCell(col, rowIndex);
     }
 }
示例#16
0
 private void GridUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     var tag = (SoundEventTag) grid.rows[rowIndex].ValueObject;
     // если выбрана иконка проигрывателя - играть файл
     if (col.PropertyName == tag.Property(p => p.ImageIndex))
     {
         PlaySound(tag.FileName);
         return;
     }
     if (col.PropertyName == tag.Property(p => p.FileName))
     {
         // предложить выбрать файл
         foreach (ToolStripMenuItem item in menuSound.Items)
         {
             item.Checked = item.Text == tag.FileName;
         }
         menuSound.Tag = rowIndex;
         menuSound.Show(grid, e.X, e.Y);
         return;
     }
 }
示例#17
0
        public PopupListBox(object originalValue,
                            int rowIndex, FastColumn column, Type columnType,
                            Action <FastColumn, int, object> onValueUpdated, Control parent)
        {
            this.rowIndex       = rowIndex;
            this.onValueUpdated = onValueUpdated;
            this.parent         = parent;
            this.column         = column;

            // получить допустимые значения
            if (columnType == typeof(bool))
            {
                values = new object[] { false, true }
            }
            ;
            else if (columnType.IsSubclassOf(typeof(Enum)))
            {
                values = Enum.GetValues(columnType).Cast <object>().ToArray();
            }
            if (values == null)
            {
                return;
            }

            // сгенерировать массив строк для указанного типа
            var index = 0;

            foreach (var val in values)
            {
                if (val.Equals(originalValue))
                {
                    selectedIndex = index;
                }
                index++;
                var str = column.formatter == null?val.ToString() : column.formatter(val);

                stringValues.Add(str);
            }
        }
 protected virtual void ProcessMouseUpInHeader(MouseEventArgs e, FastColumn col)
 {
     // change sort mode by left mouse button
     if (e.Button == MouseButtons.Left)
     {
         var oldOrder = col.SortOrder;
         col.SortOrder = col.SortOrder == FastColumnSort.None
                             ? FastColumnSort.Ascending
                             : col.SortOrder == FastColumnSort.Ascending
                                     ? FastColumnSort.Descending
                                     : FastColumnSort.None;
         if (sortOrderChanged != null)
         {
             sortOrderChanged(col, oldOrder, col.SortOrder);
         }
         if (columnSettingsChanged != null)
         {
             columnSettingsChanged();
         }
         OrderRows();
         Invalidate();
     }
 }
示例#19
0
        /// <summary>
        /// make columns auto and fill rows
        /// </summary>
        /// <param name="objects">rows' data</param>
        /// <param name="specimenType">type of value object</param>
        /// <param name="skipPropertiesWoDisplayName">do not add column where no DsiplayName attribute provided</param>
        /// <param name="boolSubstitutions">null or substitution for boolean: true, false, null</param>
        /// <param name="defaultColumnMinWidth">default column min width, pixels</param>
        /// <param name="dateTimeFormatString">format string for DateTime columns (may be null)</param>
        public void DataBind(IList objects, Type specimenType,
                             bool skipPropertiesWoDisplayName, string[] boolSubstitutions, int defaultColumnMinWidth,
                             string dateTimeFormatString)
        {
            // make columns by public instance props
            foreach (var prop in specimenType.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var attrs     = prop.GetCustomAttributes(true);
                var browsAttr = attrs.FirstOrDefault(a => a is BrowsableAttribute);
                if (browsAttr != null)
                {
                    if (!((BrowsableAttribute)browsAttr).Browsable)
                    {
                        continue;
                    }
                }

                // get column title from DisplayName attr
                var columnTitle = prop.Name;
                var propName    = columnTitle;

                var propNameAtr = attrs.FirstOrDefault(a => a is DisplayNameAttribute);
                if (propNameAtr != null)
                {
                    columnTitle = ((DisplayNameAttribute)propNameAtr).DisplayName;
                }
                else
                {
                    if (skipPropertiesWoDisplayName)
                    {
                        continue;
                    }
                }

                // get column width by property type
                int columnWidth;
                if (!defaultColumnWidth.TryGetValue(prop.PropertyType, out columnWidth))
                {
                    columnWidth = defaultColumnMinWidth;
                }

                // make column record
                var col = new FastColumn(propName, columnTitle)
                {
                    Title          = columnTitle,
                    ColumnMinWidth = columnWidth
                };

                // add column - to - property association
                columnProperty.Add(col, prop);

                // format boolean ...
                if (prop.PropertyType == typeof(bool) || prop.PropertyType == typeof(bool?))
                {
                    if (boolSubstitutions != null && boolSubstitutions.Length > 1)
                    {
                        col.ColumnMinWidth = 0;
                        var strTrue  = boolSubstitutions[0];
                        var strFalse = boolSubstitutions[1];
                        var strNull  = boolSubstitutions.Length == 2 ? strFalse : boolSubstitutions[2];

                        // measure column width (fixed!)
                        using (var g = CreateGraphics())
                        {
                            var fnt   = FontHeader ?? Font;
                            var maxWd = g.MeasureString(col.Title, fnt).Width + 6;
                            foreach (var str in boolSubstitutions)
                            {
                                var wd = g.MeasureString(str, fnt).Width;
                                if (wd > maxWd)
                                {
                                    maxWd = wd;
                                }
                            }
                            col.ColumnWidth = (int)maxWd + 4;
                        }

                        // formatter
                        if (prop.PropertyType == typeof(bool))
                        {
                            col.formatter = c => ((bool)c) ? strTrue : strFalse;
                        }
                        else
                        {
                            col.formatter = c => ((bool?)c).HasValue ?
                                            (((bool?)c).Value ? strTrue : strFalse) : strNull;
                        }
                    }
                }

                // format DateTime ...
                if (prop.PropertyType == typeof(DateTime) || prop.PropertyType == typeof(DateTime?))
                {
                    if (!string.IsNullOrEmpty(dateTimeFormatString))
                    {
                        col.FormatString = dateTimeFormatString;
                    }
                }

                columns.Add(col);
            }

            // calc min table width
            CalcSetTableMinWidth(defaultColumnMinWidth);

            // add rows
            AddRows(objects);

            CheckSize();
        }
 protected virtual void ProcessMouseUpInHeader(MouseEventArgs e, FastColumn col)
 {
     // change sort mode by left mouse button
     if (e.Button == MouseButtons.Left)
     {
         var oldOrder = col.SortOrder;
         col.SortOrder = col.SortOrder == FastColumnSort.None
                             ? FastColumnSort.Ascending
                             : col.SortOrder == FastColumnSort.Ascending
                                     ? FastColumnSort.Descending
                                     : FastColumnSort.None;
         if (sortOrderChanged != null)
             sortOrderChanged(col, oldOrder, col.SortOrder);
         if (columnSettingsChanged != null)
             columnSettingsChanged();
         OrderRows();
         Invalidate();
     }
 }
        private void OnValueEntered(FastColumn col, int rowIndex, object newValue)
        {
            var valueObj = rows[rowIndex].ValueObject;

            if (fieldValueChanging != null)
            {
                bool cancel;
                fieldValueChanging(col, rowIndex, valueObj, ref newValue, out cancel);
                if (cancel) return;
            }

            // изменить значение ячейки
            try
            {
                var colPropType = columnProperty[col];

                // если null...
                if (newValue == null || (newValue is string && (string) newValue == ""))
                {
                    if (!colPropType.PropertyType.IsValueType ||
                        colPropType.PropertyType == typeof (string))
                    {
                        colPropType.SetValue(valueObj, null, null);
                        if (fieldValueChanged != null)
                            fieldValueChanged(col, rowIndex, valueObj);
                    }
                }
                else if (colPropType.PropertyType == newValue.GetType())
                {
                    colPropType.SetValue(valueObj, newValue, null);
                    if (fieldValueChanged != null)
                        fieldValueChanged(col, rowIndex, valueObj);
                }
                else
                    return;
            }
            catch
            {
                return;
            }

            // обновить ячейку
            UpdateRow(rowIndex, valueObj);
            // перерисовать
            InvalidateCell(col, rowIndex);
        }
示例#22
0
        private void UpdateObject(FastColumn col, int rowIndex, object newValue)
        {
            if (tabControl.SelectedTab == null)
                return;
            var fastGrid = tabControl.SelectedTab.Controls[0] as FastGrid.FastGrid;
            if (fastGrid == null)
                return;

            // updating real object
            var rowObject = (FastPropertyGridRow) fastGrid.rows[rowIndex].ValueObject;
            var objProp = rowObject.Property;
            if (objProp == null)
                return;
            try
            {
                if(selectedObjects != null)
                    foreach (var chartObject in selectedObjects)
                        objProp.SetValue(chartObject, newValue, null);
                else if(selectedObject != null)
                    objProp.SetValue(selectedObject, newValue, null);
            }
            catch
            {
            }

            // updating grid object
            RebuildSample();
            var valueProp = rowObject.GetType().GetProperty(rowObject.Property(p => p.Value));
            var stringProp = rowObject.GetType().GetProperty(rowObject.Property(p => p.StringValue));
            valueProp.SetValue(rowObject, newValue, null);
            stringProp.SetValue(rowObject, GetStringValue(newValue, rowObject.Property), null);
            fastGrid.UpdateRow(rowIndex, rowObject);
            fastGrid.InvalidateRow(rowIndex);
        }
        public Point GetCellCoords(FastColumn column, int rowIndex)
        {
            var shiftX = scrollBarH.Visible ? scrollBarH.Value : 0;
            var startIndex = scrollBarV.Value >= rows.Count ? 0 : scrollBarV.Value;

            var popTop = CellHeight * (rowIndex - startIndex) + /*Top +*/ CaptionHeight + 1;
            var popLeft = 1 - shiftX + Columns.TakeWhile(col => col != column).Sum(col => col.ResultedWidth);

            return new Point(popLeft, popTop);
        }
示例#24
0
        public PopupTextBox(object obj, int width, int height,
            int rowIndex, FastColumn column, PropertyInfo property,
            Action<FastColumn, int, object> onValueUpdated)
            : this()
        {
            Margin = Padding.Empty;
            Padding = Padding.Empty;
            AutoSize = false;
            Width = width;
            Height = height;

            RowIndex = rowIndex;
            Column = column;
            PropertyType = property.PropertyType;
            OnValueUpdated = onValueUpdated;

            var valueAttr =
                property.GetCustomAttributes(true).FirstOrDefault(a => a is ValueListAttribute) as
                ValueListAttribute;
            ComboBox comboBox = null;
            if (valueAttr != null)
            {
                comboBox = new ComboBox();
                foreach (var value in valueAttr.Values)
                {
                    comboBox.Items.Add(value);
                    if (value.Equals(obj))
                        comboBox.SelectedItem = value;
                }
                comboBox.KeyUp += OnControlKeyUp;
            }
            if (PropertyType == typeof(int) || PropertyType == typeof(decimal) ||
                PropertyType == typeof (float) || PropertyType == typeof (double) ||
                PropertyType == typeof (long) || PropertyType == typeof (short) ||
                PropertyType == typeof (int?) || PropertyType == typeof (decimal?))
            {
                var numericControl = new NumericUpDown();
                if (PropertyType == typeof (decimal) || PropertyType == typeof (float) ||
                    PropertyType == typeof (double) || PropertyType == typeof (decimal?))
                {
                    decimal value = 0;
                    if (PropertyType == typeof (decimal))
                        value = (decimal) obj;
                    else if (PropertyType == typeof (float))
                        value = (decimal) (float) obj;
                    else if (PropertyType == typeof (double))
                        value = (decimal) (double) obj;
                    else if (PropertyType == typeof (decimal?))
                        value = ((decimal?) obj).HasValue ? ((decimal?) obj).Value : 0;
                    var decimalString = value.ToString().Replace(',', '.');
                    if (decimalString.Contains("."))
                        numericControl.DecimalPlaces = decimalString.Substring(decimalString.IndexOf(".") + 1).Length;
                    numericControl.Minimum = decimal.MinValue;
                    numericControl.Maximum = decimal.MaxValue;
                    numericControl.Value = value;
                }
                else if (PropertyType == typeof (int))
                {
                    numericControl.Minimum = int.MinValue;
                    numericControl.Maximum = int.MaxValue;
                    numericControl.Value = (int) obj;
                }
                else if (PropertyType == typeof (long))
                {
                    numericControl.Minimum = long.MinValue;
                    numericControl.Maximum = long.MaxValue;
                    numericControl.Value = (long) obj;
                }
                else if (PropertyType == typeof (short))
                {
                    numericControl.Minimum = short.MinValue;
                    numericControl.Maximum = short.MaxValue;
                    numericControl.Value = (short) obj;
                }
                else if (PropertyType == typeof (int?))
                {
                    numericControl.Minimum = int.MinValue;
                    numericControl.Maximum = int.MaxValue;
                    numericControl.Value = ((int?) obj).HasValue ? ((int?) obj).Value : 0;
                }
                numericControl.ValueChanged += OnValueChanged;
                numericControl.KeyUp += OnControlKeyUp;

                if (valueAttr != null)
                {
                    comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                    if (valueAttr.IsEditable)
                    {
                        comboBox.Controls.Add(numericControl);
                        comboBox.SelectedIndexChanged += (sender, args) =>
                            {
                                var thisComboBox = sender as ComboBox;
                                if (thisComboBox == null)
                                    return;
                                if (thisComboBox.SelectedIndex == -1)
                                    return;
                                decimal result;
                                if (!decimal.TryParse(thisComboBox.SelectedItem.ToString(), out result))
                                    return;
                                numericControl.Value = result;
                            };
                        comboBox.Resize += (sender, args) =>
                            {
                                var thisComboBox = sender as ComboBox;
                                if (thisComboBox == null)
                                    return;
                                numericControl.Width = thisComboBox.Width - SystemInformation.VerticalScrollBarWidth - 2;
                            };
                    }
                    else
                    {
                        comboBox.SelectedIndexChanged += OnValueChanged;
                    }

                    Content = comboBox;
                }
                else
                    Content = numericControl;
            }
            else if (PropertyType == typeof (DateTime))
            {
                var control = new DateTimePicker
                    {
                        Format = DateTimePickerFormat.Custom,
                        CustomFormat = "dd.MM.yyyy HH:mm:ss",
                        ShowUpDown = true
                    };
                try
                {
                    control.Value = (DateTime) obj;
                }
                catch
                {
                }
                control.ValueChanged += OnValueChanged;

                Content = control;
            }
            else
            {
                if (valueAttr != null)
                {
                    comboBox.DropDownStyle = valueAttr.IsEditable ? ComboBoxStyle.DropDown : ComboBoxStyle.DropDownList;
                    if (valueAttr.IsEditable)
                    {
                        if (string.IsNullOrEmpty(comboBox.Text))
                            comboBox.Text = obj.ToString();
                        comboBox.TextChanged += OnValueChanged;
                    }
                    comboBox.SelectedIndexChanged += OnValueChanged;

                    Content = comboBox;
                }
                else
                {
                    var textControl = new TextBox {Text = obj as string};
                    textControl.KeyUp += OnControlKeyUp;

                    Content = textControl;
                }
            }

            Content.Dock = DockStyle.Fill;

            var host = new ToolStripControlHost(Content)
                           {
                               Margin = Padding.Empty,
                               Padding = Padding.Empty,
                               AutoSize = false,
                               Width = width,
                               Height = height
                           };
            Items.Add(host);
            Opened += (sender, e) => Content.Focus();
        }
示例#25
0
        public PopupTextBox(object obj, int width, int height,
                            int rowIndex, FastColumn column, PropertyInfo property,
                            Action <FastColumn, int, object> onValueUpdated)
            : this()
        {
            Margin   = Padding.Empty;
            Padding  = Padding.Empty;
            AutoSize = false;
            Width    = width;
            Height   = height;

            RowIndex       = rowIndex;
            Column         = column;
            PropertyType   = property.PropertyType;
            OnValueUpdated = onValueUpdated;

            var valueAttr =
                property.GetCustomAttributes(true).FirstOrDefault(a => a is ValueListAttribute) as
                ValueListAttribute;
            ComboBox comboBox = null;

            if (valueAttr != null)
            {
                comboBox = new ComboBox();
                foreach (var value in valueAttr.Values)
                {
                    comboBox.Items.Add(value);
                    if (value.Equals(obj))
                    {
                        comboBox.SelectedItem = value;
                    }
                }
                comboBox.KeyUp += OnControlKeyUp;
            }
            if (PropertyType == typeof(int) || PropertyType == typeof(decimal) ||
                PropertyType == typeof(float) || PropertyType == typeof(double) ||
                PropertyType == typeof(long) || PropertyType == typeof(short) ||
                PropertyType == typeof(int?) || PropertyType == typeof(decimal?))
            {
                var numericControl = new NumericUpDown();
                if (PropertyType == typeof(decimal) || PropertyType == typeof(float) ||
                    PropertyType == typeof(double) || PropertyType == typeof(decimal?))
                {
                    decimal value = 0;
                    if (PropertyType == typeof(decimal))
                    {
                        value = (decimal)obj;
                    }
                    else if (PropertyType == typeof(float))
                    {
                        value = (decimal)(float)obj;
                    }
                    else if (PropertyType == typeof(double))
                    {
                        value = (decimal)(double)obj;
                    }
                    else if (PropertyType == typeof(decimal?))
                    {
                        value = ((decimal?)obj).HasValue ? ((decimal?)obj).Value : 0;
                    }
                    var decimalString = value.ToString().Replace(',', '.');
                    if (decimalString.Contains("."))
                    {
                        numericControl.DecimalPlaces = decimalString.Substring(decimalString.IndexOf(".") + 1).Length;
                    }
                    numericControl.Minimum = decimal.MinValue;
                    numericControl.Maximum = decimal.MaxValue;
                    numericControl.Value   = value;
                }
                else if (PropertyType == typeof(int))
                {
                    numericControl.Minimum = int.MinValue;
                    numericControl.Maximum = int.MaxValue;
                    numericControl.Value   = (int)obj;
                }
                else if (PropertyType == typeof(long))
                {
                    numericControl.Minimum = long.MinValue;
                    numericControl.Maximum = long.MaxValue;
                    numericControl.Value   = (long)obj;
                }
                else if (PropertyType == typeof(short))
                {
                    numericControl.Minimum = short.MinValue;
                    numericControl.Maximum = short.MaxValue;
                    numericControl.Value   = (short)obj;
                }
                else if (PropertyType == typeof(int?))
                {
                    numericControl.Minimum = int.MinValue;
                    numericControl.Maximum = int.MaxValue;
                    numericControl.Value   = ((int?)obj).HasValue ? ((int?)obj).Value : 0;
                }
                numericControl.ValueChanged += OnValueChanged;
                numericControl.KeyUp        += OnControlKeyUp;

                if (valueAttr != null)
                {
                    comboBox.DropDownStyle = ComboBoxStyle.DropDownList;
                    if (valueAttr.IsEditable)
                    {
                        comboBox.Controls.Add(numericControl);
                        comboBox.SelectedIndexChanged += (sender, args) =>
                        {
                            var thisComboBox = sender as ComboBox;
                            if (thisComboBox == null)
                            {
                                return;
                            }
                            if (thisComboBox.SelectedIndex == -1)
                            {
                                return;
                            }
                            decimal result;
                            if (!decimal.TryParse(thisComboBox.SelectedItem.ToString(), out result))
                            {
                                return;
                            }
                            numericControl.Value = result;
                        };
                        comboBox.Resize += (sender, args) =>
                        {
                            var thisComboBox = sender as ComboBox;
                            if (thisComboBox == null)
                            {
                                return;
                            }
                            numericControl.Width = thisComboBox.Width - SystemInformation.VerticalScrollBarWidth - 2;
                        };
                    }
                    else
                    {
                        comboBox.SelectedIndexChanged += OnValueChanged;
                    }

                    Content = comboBox;
                }
                else
                {
                    Content = numericControl;
                }
            }
            else if (PropertyType == typeof(DateTime))
            {
                var control = new DateTimePicker
                {
                    Format       = DateTimePickerFormat.Custom,
                    CustomFormat = "dd.MM.yyyy HH:mm:ss",
                    ShowUpDown   = true
                };
                try
                {
                    control.Value = (DateTime)obj;
                }
                catch
                {
                }
                control.ValueChanged += OnValueChanged;

                Content = control;
            }
            else
            {
                if (valueAttr != null)
                {
                    comboBox.DropDownStyle = valueAttr.IsEditable ? ComboBoxStyle.DropDown : ComboBoxStyle.DropDownList;
                    if (valueAttr.IsEditable)
                    {
                        if (string.IsNullOrEmpty(comboBox.Text))
                        {
                            comboBox.Text = obj.ToString();
                        }
                        comboBox.TextChanged += OnValueChanged;
                    }
                    comboBox.SelectedIndexChanged += OnValueChanged;

                    Content = comboBox;
                }
                else
                {
                    var textControl = new TextBox {
                        Text = obj as string
                    };
                    textControl.KeyUp += OnControlKeyUp;

                    Content = textControl;
                }
            }

            Content.Dock = DockStyle.Fill;

            var host = new ToolStripControlHost(Content)
            {
                Margin   = Padding.Empty,
                Padding  = Padding.Empty,
                AutoSize = false,
                Width    = width,
                Height   = height
            };

            Items.Add(host);
            Opened += (sender, e) => Content.Focus();
        }
 private void GridViewUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (e.Button != MouseButtons.Left || e.Clicks <= 1) return;
     SelectedIndiName = ((IndicatorDescription)gridView.rows[rowIndex].ValueObject).Name;
     DialogResult = DialogResult.OK;
 }
示例#27
0
        private void GridTradeSettingsOnUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
        {
            if (e.Button != MouseButtons.Left)
                return;

            var record = (GridImageRecord) gridTradeSettings.rows[rowIndex].ValueObject;

            // показать раздел справки
            if (col.Title == "?")
            {
                HelpManager.Instance.ShowHelp(HelpManager.KeyTradeSettings);
                return;
            }

            // изменить соотв. настройку
            if (col.PropertyName == record.Property(p => p.ImageIndex))
            {
                if (record.BooleanValue.HasValue)
                {
                    record.BooleanValue = !record.BooleanValue.Value;
                    record.setValue(record.BooleanValue.Value);
                }
                gridTradeSettings.UpdateRow(rowIndex, record);
                gridTradeSettings.InvalidateRow(rowIndex);
            }
        }
示例#28
0
 private void GridCandlesUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (e.Clicks == 2)
         ButtonCandleChangeClick(this, null);
 }
示例#29
0
 private void GridCandlesSelectionChanged(MouseEventArgs e, int rowIndex, FastColumn col)
 {
     buttonCandleChange.Enabled = false;
     buttonCandleRemove.Enabled = false;
     var selectedRows = gridCandles.rows.Where(r => r.Selected).ToList();
     if (selectedRows.Count != 0)
     {
         buttonCandleChange.Enabled = true;
         buttonCandleRemove.Enabled = ((BarSettings)(selectedRows[0].ValueObject)).IsUserDefined;
     }
 }
示例#30
0
 private void GridUserHitCell(object sender, MouseEventArgs mouseEventArgs, int rowIndex, FastColumn col)
 {
     if (rowIndex >= 0 && rowIndex < grid.rows.Count)
         gridObjectSelected(grid.rows[rowIndex].ValueObject);
 }
示例#31
0
        private void DrawCellText(int columnIndex, FastColumn column, FastCell cell, BrushesStorage brushes,
                                  Graphics g, Point leftTop, int cellWidth, int cellHeight,
                                  Font font, Brush brushFont, Color?fontColor, int rowIndex, int cellPadding)
        {
            if (userDrawCellText != null)
            {
                userDrawCellText(columnIndex, column, cell, brushes, g, leftTop, cellWidth, cellHeight, font, brushFont,
                                 fontColor, rowIndex, cellPadding);
                return;
            }

            var cellFont = column.ColumnFont ?? font;
            var brush    = brushFont;

            if (fontColor.HasValue)
            {
                brush = brushes.GetBrush(fontColor.Value);
            }

            // apply hyperlink colors?
            if (column.IsHyperlinkStyleColumn)
            {
                var linkColor = column.ColorHyperlinkTextInactive;
                if (column.HyperlinkFontInactive != null)
                {
                    cellFont = column.HyperlinkFontInactive;
                }

                if (owner.LastHoveredCell.HasValue)
                {
                    var hoveredCell = owner.LastHoveredCell.Value;
                    // is there cursor above?
                    if (columnIndex == hoveredCell.X && rowIndex == hoveredCell.Y)
                    {
                        linkColor = column.ColorHyperlinkTextActive;
                        if (column.HyperlinkFontActive != null)
                        {
                            cellFont = column.HyperlinkFontActive;
                        }
                    }
                }
                if (linkColor.HasValue)
                {
                    brush = brushes.GetBrush(linkColor.Value);
                }
            }

            var cellString = cell.CellString;

            // Color render
            if (cell.CellValue is Color)
            {
                var c = (Color)cell.CellValue;
                g.FillRectangle(new SolidBrush(c), leftTop.X + cellPadding, leftTop.Y + 2, 25, cellHeight - 3);
                cellString = string.Format("{0}; {1}; {2}", c.B, c.G, c.R);
                leftTop.X += 25;
            }

            if (column.CellHAlignment == StringAlignment.Center)
            {
                g.DrawString(cellString, cellFont, brush,
                             leftTop.X + cellWidth / 2, leftTop.Y + cellHeight / 2, cellTextFormatHCenter);
            }
            if (column.CellHAlignment == StringAlignment.Near)
            {
                g.DrawString(cellString, cellFont, brush,
                             leftTop.X + cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHNear);
            }
            if (column.CellHAlignment == StringAlignment.Far)
            {
                g.DrawString(cellString, cellFont, brush,
                             leftTop.X + cellWidth - cellPadding, leftTop.Y + cellHeight / 2, cellTextFormatHFar);
            }
        }
        private void GridRobotUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col, RobotGridItem gridItem)
        {
            var robot = gridItem.Robot;

            // показать меню выбора Magic-a,
            // подсветить в первую очередь, незанятые номера
            if (col.PropertyName == RobotGridItem.speciman.Property(p => p.Magic) && e.Button == MouseButtons.Left)
            {
                ShowMagicMenu(e, gridItem, rowIndex);
                return;
            }

            // показать окно настройки тикеров для робота
            if (col.PropertyName == RobotGridItem.speciman.Property(p => p.HumanRTickers) && e.Button == MouseButtons.Left)
            {
                var dlg = new RobotTimeframesForm(robot.Graphics);
                if (dlg.ShowDialog() != DialogResult.OK) return;
                robot.Graphics = dlg.UpdatedGraphics;
                gridRobot.UpdateRow(rowIndex, gridItem);
                gridRobot.InvalidateCell(col, rowIndex);
                return;
            }

            // настроить робота
            if ((/*col.PropertyName == "TypeName" || */e.Clicks > 1) && e.Button == MouseButtons.Left)
            {
                ShowRobotParamsDialog(robot);
            }
        }
示例#33
0
 private void GridOnUserHitCell(object sender, MouseEventArgs mouseEventArgs, int rowIndex, FastColumn col)
 {
     selectedScript = (ScriptItem)grid.rows[rowIndex].ValueObject;
     DialogResult = DialogResult.OK;
 }
示例#34
0
 public void AddColumn(FastColumn col)
 {
     columns.Add(col);
 }
示例#35
0
 // открытие стандартного редактора в зависимости от типа свойства
 private void OpenBaseEditor(PropertyInfo property, FastGrid.FastGrid fastGrid, int rowIndex, FastColumn col)
 {
     var coords = fastGrid.GetCellCoords(col, rowIndex);
     var blankRow = new FastPropertyGridRow();
     var cellValue =
         fastGrid.rows[rowIndex].cells[fastGrid.Columns.FindIndex(c => c.PropertyName == blankRow.Property(p => p.Value))].CellValue;
     var propType = property.PropertyType;
     if ((propType == typeof (bool) || propType.IsEnum))
     {
         var pop = new PopupListBox(cellValue, rowIndex, col, propType, UpdateObject, fastGrid);
         pop.ShowOptions(coords.X, coords.Y);
         return;
     }
     if ((propType == typeof (string) || Converter.IsConvertable(propType)))
     {
         // редактор подставляется в FastGrid.PopupTextBox
         try
         {
             var pop = new PopupTextBox(cellValue, col.ResultedWidth, fastGrid.CellHeight, rowIndex, col, property, null);
             pop.OnValueUpdated += UpdateObject;
             pop.Show(fastGrid, coords);
         }
         catch(Exception ex)
         {
             Logger.Error("FastPropertyGrid.OpenBaseEditor", ex);
         }
         return;
     }
 }
示例#36
0
 public void AddColumn(FastColumn col)
 {
     columns.Add(col);
 }
示例#37
0
 private void UserHitCell(object sender, MouseEventArgs mouseEventArgs, int rowIndex, FastColumn col)
 {
     if (tabControl.SelectedTab == null)
         return;
     var fastGrid = tabControl.SelectedTab.Controls[0] as FastGrid.FastGrid;
     if (fastGrid == null)
         return;
     // отображение описания
     var rowObject = (FastPropertyGridRow) fastGrid.rows[rowIndex].ValueObject;
     if (rowObject.Property == null)
         return;
     detailTextBox.SelectionFont = Font;
     detailTextBox.Text = rowObject.Title;
     var attrs = rowObject.Property.GetCustomAttributes(true);
     var descriptionAttribute = attrs.FirstOrDefault(a => a is LocalizedDescriptionAttribute) as DescriptionAttribute;
     if (descriptionAttribute == null)
         descriptionAttribute = attrs.FirstOrDefault(a => a is DescriptionAttribute) as DescriptionAttribute;
     if (descriptionAttribute != null)
         detailTextBox.Text += Environment.NewLine + descriptionAttribute.Description;
     detailTextBox.Select(0, rowObject.Title.Length);
     detailTextBox.SelectionFont = new Font(Font, FontStyle.Bold);
     // открытие редактора
     if (fastGrid.Columns.IndexOf(col) != 1)
         return;
     editingRowIndex = rowIndex;
     editingColumn = col;
     var editorAttribute = attrs.FirstOrDefault(a => a is EditorAttribute) as EditorAttribute;
     var editorType = editorAttribute != null
                          ? Type.GetType(editorAttribute.EditorTypeName)
                          : GetStandardEditorType(rowObject.Property.PropertyType);
     if (editorType == null)
     {
         OpenBaseEditor(rowObject.Property, fastGrid, rowIndex, col);
         return;
     }
     OpenSpecialEditor();
 }
示例#38
0
 private void GridUserHitCell(object sender, MouseEventArgs mouseEventArgs, int rowIndex, FastColumn col)
 {
     if (rowIndex >= 0 && rowIndex < grid.rows.Count)
     {
         gridObjectSelected(grid.rows[rowIndex].ValueObject);
     }
 }
        // changing selection
        protected virtual void ProcessMouseHitCell(FastColumn col,
            int rowIndex, MouseEventArgs e)
        {
            // do not select string by hitting hyperlink
            if (col.IsHyperlinkStyleColumn) return;

            // select cell
            if (SelectEnabled && e.Button == MouseButtons.Left)
            {
                var singleSelectMode = true;
                if (MultiSelectEnabled)
                    singleSelectMode =
                        ModifierKeys != Keys.Shift && ModifierKeys != Keys.Control;
                // single line select
                if (singleSelectMode)
                {
                    // deselect all but current
                    for (var i = 0; i < rows.Count; i++)
                        rows[i].Selected = i == rowIndex;
                }
                // multi-line select
                else
                {
                    if (ModifierKeys == Keys.Control)
                    {// add or remove selected
                        rows[rowIndex].Selected = !rows[rowIndex].Selected;
                    }
                    if (ModifierKeys == Keys.Shift)
                    {
                        var beginSelectionIndex = Math.Min(rowIndex, lastHitRow);
                        if (beginSelectionIndex == -1)
                            beginSelectionIndex = rowIndex;
                        var endSelectionIndex = Math.Max(rowIndex, lastHitRow);
                        for (var i = beginSelectionIndex; i <= endSelectionIndex; i++)
                            rows[i].Selected = true;
                    }
                }

                if (selectionChanged != null)
                    selectionChanged(e, rowIndex, col);
            }
            // redraw
            Invalidate();
        }
 private void GridOnUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (e.Clicks > 1 && e.Button == MouseButtons.Left)
     {
         // вызвать диалог торговли
         var tickerInfo = ((QuoteDataRecord) grid.rows[rowIndex].ValueObject).Title;
         new OrderDlg(tickerInfo).ShowDialog();
     }
 }
        private bool CheckMouseHitCell(MouseEventArgs e)
        {
            var cell = GetCellUnderCursor(e.X, e.Y);
            if (!cell.HasValue)
                return false;

            if (rows[cell.Value.Y].IsGroupingRow)
            {
                var row = rows[cell.Value.Y];
                if (row.Collapsed)
                {
                    var movedRows = collapsedRows.Where(r => r.OwnerGroupingRow == row).ToList();
                    collapsedRows.RemoveAll(movedRows.Contains);
                    rows.InsertRange(rows.IndexOf(row) + 1, movedRows);
                    row.Collapsed = false;
                }
                else
                {
                    var movedRows = rows.Where(r => r.OwnerGroupingRow == row).ToList();
                    rows.RemoveAll(movedRows.Contains);
                    collapsedRows.AddRange(movedRows);
                    row.Collapsed = true;
                }
                Invalidate();
                return true;
            }

            // process selection
            // lastHitRow & lastHitColumn store previous selection 4 correct selection
            ProcessMouseHitCell(columns[cell.Value.X], cell.Value.Y, e);

            // store cell hit
            lastHitRow = cell.Value.Y;
            lastHitColumn = columns[cell.Value.X];

            // edit value
            if (lastHitColumn.IsEditable)
            {
                if ((CellEditMode == CellEditModeTrigger.LeftClick && e.Button == MouseButtons.Left) ||
                    (CellEditMode == CellEditModeTrigger.LeftDoubleClick && e.Clicks > 1 &&
                     e.Button == MouseButtons.Left) ||
                    (CellEditMode == CellEditModeTrigger.RightClick && e.Button == MouseButtons.Right))
                {
                    var allow = true;
                    if (fieldValueBeforeEdit != null)
                        allow = fieldValueBeforeEdit(lastHitColumn, lastHitRow,
                                                     rows[lastHitRow].cells[columns.IndexOf(lastHitColumn)]);
                    if (allow)
                    {
                        ShowEditField(cell.Value);
                        return true;
                    }
                }
            }

            // fire the event
            if (userHitCell != null)
                userHitCell(this, e, lastHitRow, lastHitColumn);
            return true;
        }
示例#42
0
 public void InvalidateCell(FastColumn col, int row)
 {
     if (!col.Visible) return;
     InvalidateCell(columns.IndexOf(col), row);
 }
示例#43
0
 private void GridEventsUserHitCell(object sender, MouseEventArgs e, int rowIndex, FastColumn col)
 {
     if (!col.IsHyperlinkStyleColumn) return;
     contextMenuAction.Tag = rowIndex;
     var sets = (AccountEventSettings) gridEvents.rows[rowIndex].ValueObject;
     foreach (ToolStripMenuItem item in contextMenuAction.Items)
         item.Checked = sets.EventAction == (AccountEventAction) item.Tag;
     contextMenuAction.Show(gridEvents, e.X, e.Y);
 }
        private bool CheckMouseHitCell(MouseEventArgs e)
        {
            var cell = GetCellUnderCursor(e.X, e.Y);

            if (!cell.HasValue)
            {
                return(false);
            }

            if (rows[cell.Value.Y].IsGroupingRow)
            {
                var row = rows[cell.Value.Y];
                if (row.Collapsed)
                {
                    var movedRows = collapsedRows.Where(r => r.OwnerGroupingRow == row).ToList();
                    collapsedRows.RemoveAll(movedRows.Contains);
                    rows.InsertRange(rows.IndexOf(row) + 1, movedRows);
                    row.Collapsed = false;
                }
                else
                {
                    var movedRows = rows.Where(r => r.OwnerGroupingRow == row).ToList();
                    rows.RemoveAll(movedRows.Contains);
                    collapsedRows.AddRange(movedRows);
                    row.Collapsed = true;
                }
                Invalidate();
                return(true);
            }

            // process selection
            // lastHitRow & lastHitColumn store previous selection 4 correct selection
            ProcessMouseHitCell(columns[cell.Value.X], cell.Value.Y, e);

            // store cell hit
            lastHitRow    = cell.Value.Y;
            lastHitColumn = columns[cell.Value.X];

            // edit value
            if (lastHitColumn.IsEditable)
            {
                if ((CellEditMode == CellEditModeTrigger.LeftClick && e.Button == MouseButtons.Left) ||
                    (CellEditMode == CellEditModeTrigger.LeftDoubleClick && e.Clicks > 1 &&
                     e.Button == MouseButtons.Left) ||
                    (CellEditMode == CellEditModeTrigger.RightClick && e.Button == MouseButtons.Right))
                {
                    var allow = true;
                    if (fieldValueBeforeEdit != null)
                    {
                        allow = fieldValueBeforeEdit(lastHitColumn, lastHitRow,
                                                     rows[lastHitRow].cells[columns.IndexOf(lastHitColumn)]);
                    }
                    if (allow)
                    {
                        ShowEditField(cell.Value);
                        return(true);
                    }
                }
            }

            // fire the event
            if (userHitCell != null)
            {
                userHitCell(this, e, lastHitRow, lastHitColumn);
            }
            return(true);
        }