示例#1
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object component, Attribute[] attrs)
        {
            TypeConverter tc = component is IndicatorBase?TypeDescriptor.GetConverter(typeof(IndicatorBase)) : TypeDescriptor.GetConverter(typeof(DrawingTools.DrawingTool));

            PropertyDescriptorCollection propertyDescriptorCollection = tc.GetProperties(context, component, attrs);

            if (propertyDescriptorCollection == null)
            {
                return(null);
            }

            PropertyDescriptorCollection properties = new PropertyDescriptorCollection(null);

            foreach (PropertyDescriptor pd in propertyDescriptorCollection)
            {
                if (!pd.IsBrowsable || pd.IsReadOnly)
                {
                    continue;
                }

                if (pd.Name == "IsAutoScale" || pd.Name == "DisplayInDataBox" || pd.Name == "MaximumBarsLookBack" || pd.Name == "Calculate" ||
                    pd.Name == "PaintPriceMarkers" || pd.Name == "Displacement" || pd.Name == "ScaleJustification")
                {
                    continue;
                }

                if (pd.Name == "SelectedTypes")
                {
                    int i = 1;
                    foreach (Type type in Core.Globals.AssemblyRegistry.GetDerivedTypes(typeof(DrawingTools.DrawingTool)))
                    {
                        DrawingTools.DrawingTool tool = type.Assembly.CreateInstance(type.FullName) as DrawingTools.DrawingTool;
                        if (tool == null || !tool.DisplayOnChartsMenus)
                        {
                            continue;
                        }
                        DrawingToolPropertyDescriptor descriptor = new DrawingToolPropertyDescriptor(type, tool.Name, i);
                        properties.Add(descriptor);
                        i++;
                    }
                    continue;
                }

                properties.Add(pd);
            }
            return(properties);
        }
示例#2
0
        internal DrawingTools.DrawingTool CreateDrawingTool(IDesignerHost designerHost)
        {
            DrawingTools.DrawingTool ret = null;

            // construct tool via DesignerHost at DesignTime.
            if (designerHost != null)
            {
                ret = designerHost.CreateComponent(ToolType) as DrawingTools.DrawingTool;
            }
            else
            {
                // construct tool via reflection at Runtime.
                ConstructorInfo ci = ToolType.GetConstructor(new Type[] { });

                ret = ci.Invoke(null) as DrawingTools.DrawingTool;
            }

            ret.Persistence = this;
            return(ret);
        }
示例#3
0
        private FrameworkElement CreateControl()
        {
            if (grid != null)
            {
                return(grid);
            }

            grid = new Grid {
                VerticalAlignment = VerticalAlignment.Top, HorizontalAlignment = HorizontalAlignment.Left, Margin = new Thickness(Left, Top, 0, 0)
            };

            grid.ColumnDefinitions.Add(new ColumnDefinition       {
                Width = new GridLength()
            });
            grid.ColumnDefinitions.Add(new ColumnDefinition       {
                Width = new GridLength()
            });
            grid.RowDefinitions.Add(new RowDefinition          {
                Height = new GridLength()
            });

            Brush background  = Application.Current.FindResource("BackgroundMainWindow")      as Brush ?? Brushes.White;
            Brush borderBrush = Application.Current.FindResource("BorderThinBrush")           as Brush ?? Brushes.Black;

            Grid g = new Grid();

            g.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });
            g.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(1, GridUnitType.Star)
            });
            g.RowDefinitions.Add(new RowDefinition {
                Height = new GridLength(2, GridUnitType.Star)
            });

            for (int r = 0; r < g.RowDefinitions.Count; r++)
            {
                System.Windows.Shapes.Ellipse e = new System.Windows.Shapes.Ellipse
                {
                    Width  = 3,
                    Height = 3,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Center,
                    Fill = borderBrush
                };
                Grid.SetRow(e, r);
                g.Children.Add(e);
            }

            b = new Border
            {
                VerticalAlignment = VerticalAlignment.Top,
                BorderThickness   = new Thickness(0, 1, 1, 1),
                BorderBrush       = borderBrush,
                Background        = background,
                Width             = 12,
                Height            = 24,
                Cursor            = System.Windows.Input.Cursors.Hand,
                Child             = g
            };

            b.MouseDown += (o, e) =>
            {
                startPoint = e.GetPosition(ChartPanel);
                margin     = grid.Margin;
                if (e.ClickCount > 1)
                {
                    b.ReleaseMouseCapture();
                    ChartControl.OnIndicatorsHotKey(this, null);
                }
                else
                {
                    b.CaptureMouse();
                }
            };

            b.MouseUp += (o, e) => { b.ReleaseMouseCapture(); };

            b.MouseMove += (o, e) =>
            {
                if (!b.IsMouseCaptured || grid == null || ChartPanel == null)
                {
                    return;
                }

                Point newPoint = e.GetPosition(ChartPanel);
                grid.Margin = new Thickness {
                    Left = Math.Max(0, Math.Min(margin.Left + (newPoint.X - startPoint.X), ChartPanel.ActualWidth - grid.ActualWidth)),
                    Top  = Math.Max(0, Math.Min(margin.Top + (newPoint.Y - startPoint.Y), ChartPanel.ActualHeight - grid.ActualHeight))
                };

                Left = grid.Margin.Left;
                Top  = grid.Margin.Top;
            };

            Grid.SetColumn(b, 1);

            grid.Children.Add(b);

            Grid            contentGrid = new Grid();
            List <XElement> elements    = SortElements(XElement.Parse(SelectedTypes.ToString()));
            int             column      = 0;
            int             count       = 0;
            FontFamily      fontFamily  = Application.Current.Resources["IconsFamily"] as FontFamily;
            Style           style       = Application.Current.Resources["LinkButtonStyle"] as Style;

            //ToolBar tb = new ToolBar();

            while (count < elements.Count)
            {
                if (contentGrid.ColumnDefinitions.Count <= column)
                {
                    contentGrid.ColumnDefinitions.Add(new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    });
                }
                for (int j = 0; j < NumberOfRows && count < elements.Count; j++)
                {
                    if (contentGrid.RowDefinitions.Count <= j)
                    {
                        contentGrid.RowDefinitions.Add(new RowDefinition {
                            Height = new GridLength(1, GridUnitType.Auto)
                        });
                    }
                    XElement element = elements[count];
                    try
                    {
                        DrawingTools.DrawingTool dt = Core.Globals.AssemblyRegistry[element.Attribute("Assembly").Value].CreateInstance(element.Name.ToString()) as DrawingTools.DrawingTool;
                        if (dt != null && dt.DisplayOnChartsMenus)
                        {
                            Button bb = new Button
                            {
                                Content    = dt.Icon ?? Gui.Tools.Icons.DrawPencil,
                                ToolTip    = dt.DisplayName,
                                Style      = style,
                                FontFamily = fontFamily,
                                FontSize   = 16,
                                FontStyle  = FontStyles.Normal,
                                Margin     = new Thickness(3),
                                Padding    = new Thickness(3)
                            };

                            Grid.SetRow(bb, j);
                            Grid.SetColumn(bb, column);

                            bb.Click += (sender, args) =>
                            {
                                if (ChartControl != null)
                                {
                                    ChartControl.TryStartDrawing(dt.GetType().FullName);
                                }
                            };

                            contentGrid.Children.Add(bb);
                            //tb.Items.Add(bb);
                            count++;
                        }
                        else
                        {
                            elements.RemoveAt(j);
                            j--;
                        }
                    }
                    catch (Exception e)
                    {
                        elements.RemoveAt(j);
                        j--;
                        Cbi.Log.Process(typeof(Custom.Resource), "NinjaScriptTileError", new object[] { element.Name.ToString(), e }, LogLevel.Error, LogCategories.NinjaScript);
                    }
                }
                column++;
            }

            Border tileHolder = new Border
            {
                Cursor          = System.Windows.Input.Cursors.Arrow,
                Background      = Application.Current.FindResource("BackgroundMainWindow") as Brush,
                BorderThickness = new Thickness((double)(Application.Current.FindResource("BorderThinThickness") ?? 1)),
                BorderBrush     = Application.Current.FindResource("BorderThinBrush") as Brush,
                Child           = contentGrid
            };

            grid.Children.Add(tileHolder);

            if (IsVisibleOnlyFocused)
            {
                Binding binding = new Binding("IsActive")
                {
                    Source = ChartControl.OwnerChart, Converter = Application.Current.FindResource("BoolToVisConverter") as IValueConverter
                };
                grid.SetBinding(UIElement.VisibilityProperty, binding);
            }

            return(grid);
        }