Пример #1
0
        public TreeView()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            IImageListProviderService ips = ServiceHost.ImageListProvider;

            if (ips != null)
            {
                ImageList = ips.ImageList;
            }
            else
            {
                ImageList            = new ImageList();
                ImageList.ColorDepth = ColorDepth.Depth32Bit;
            }
        }
Пример #2
0
        protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }

            if (gp == null)
            {
                Rectangle r     = e.Bounds;
                int       angle = 180;

                r.Width--;
                r.Height--;

                //r.Inflate(-1, - radius/2);
                //r.Offset(0, (radius/2));

                gp = new GraphicsPath();
                // top left
                gp.AddArc(r.X, r.Y, radius, radius, angle, 90);
                angle += 90;
                // top right
                gp.AddArc(r.Right - radius, r.Y, radius, radius, angle, 90);
                angle += 90;
                // bottom right
                gp.AddArc(r.Right - radius, r.Bottom - radius, radius, radius, angle, 90);
                angle += 90;
                // bottom left
                gp.AddArc(r.X, r.Bottom - radius, radius, radius, angle, 90);

                gp.CloseAllFigures();
            }

            if (borderpen == null)
            {
                borderpen = new Pen(SystemColors.Highlight, 1);
                //borderpen.Alignment = PenAlignment.Center;
            }

            bool selected = (e.State & DrawItemState.Selected) != 0;

            //normal AA looks bad
            e.Graphics.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            //e.Graphics.PixelOffsetMode = PixelOffsetMode.None;
            string word1 = Text;

            Rectangle r2 = e.Bounds;

            r2.Width = r2.Height + 2;
            r2.X--;
            r2.Height += 2;
            r2.Y--;


            Rectangle r4 = e.Bounds;

            r4.Inflate(1, 1);
            //r4.Offset(-1,-1);
            e.Graphics.FillRectangle(SystemBrushes.Window, r4);

            //e.DrawBackground();

            if (!(Items[e.Index] is CodeModel.ICodeElement))
            {
                if (gradb == null)
                {
                    LinearGradientBrush gb = new LinearGradientBrush(r2,
                                                                     SystemColors.Control, SystemColors.ControlDark, 0f);
                    gb.SetSigmaBellShape(0.9f, 0.2f);
                    gradb = gb;
                }

                e.Graphics.FillRectangle(gradb, r2);
            }


            int   h = SystemInformation.MenuHeight;
            Brush b = SystemBrushes.ControlText;

            if (selected)
            {
                Rectangle r = e.Bounds;
                //Console.WriteLine(r);
                r.Width  -= 1;
                r.Height -= 1;

                Rectangle r3 = r;

                r3.Width -= SystemInformation.MenuHeight;
                r3.X     += SystemInformation.MenuHeight + 1;

                if (selbg == null)
                {
                    r2.X      -= r.Height / 2;
                    r2.Height *= 2;
                    LinearGradientBrush gb = new LinearGradientBrush(r2,
                                                                     Color.FromArgb(120, SystemColors.ControlLightLight),
                                                                     Color.FromArgb(120, SystemColors.Highlight), 90f);
                    gb.SetSigmaBellShape(0.6f, 0.9f);

                    selbg = gb;
                }
                e.Graphics.FillPath(selbg, gp);
                e.Graphics.DrawPath(borderpen, gp);
            }

            {
                Rectangle r = e.Bounds;
                r.Width = r.Height;
                r.X++; r.X++;
                r.Y++; r.Y++;

                if (!selected)
                {
                    //r.X++;
                    //r.Y++;
                }

                IImageListProviderService ips = ServiceHost.ImageListProvider;
                if (ips != null)
                {
                    int i = ips[Items[e.Index]];
                    if (i >= 0)
                    {
                        int f = (int)((e.Bounds.Height - 16) / 2f);
                        if ((e.State & DrawItemState.Focus) != 0)
                        {
                            ips.ImageList.Draw(e.Graphics, f + 3, e.Bounds.Top + f + 1, i);
                        }
                        else
                        {
                            ips.ImageList.Draw(e.Graphics, f + 3, e.Bounds.Top + f + 1, i);
                        }
                    }
                }

                if (!selected)
                {
                    //r.X--;
                    //r.Y--;
                }


                float fh = (float)font.FontFamily.GetCellAscent(0) / font.FontFamily.GetEmHeight(0);
                float bh = (float)font.FontFamily.GetCellDescent(0) / font.FontFamily.GetEmHeight(0);

                int hh = ((int)(float)(e.Bounds.Height - (fh - bh / 2) * font.Height) / 2);

                Type t = Items[e.Index] as Type;

                if (t == null)
                {
                    t = Items[e.Index].GetType();
                }

                Build.Project p = Items[e.Index] as Build.Project;
                if (p != null)
                {
                    e.Graphics.DrawString(p.ProjectName,
                                          SystemInformation.MenuFont,
                                          b,
                                          r.Right + 1, e.Bounds.Top + hh);
                }
                else
                {
                    Languages.Language l = Items[e.Index] as Languages.Language;
                    if (l != null)
                    {
                        e.Graphics.DrawString(l.Name,
                                              SystemInformation.MenuFont,
                                              b,
                                              r.Right + 1, e.Bounds.Top + hh);
                    }
                    else
                    {
                        CodeModel.ICodeElement cl = Items[e.Index] as CodeModel.ICodeElement;
                        if (cl != null)
                        {
                            e.Graphics.DrawString(cl is CodeModel.ICodeType ? cl.Fullname : ((cl is CodeModel.ICodeMethod || cl is CodeModel.ICodeField || cl is CodeModel.ICodeProperty) ? cl.ToString() : cl.Name),
                                                  SystemInformation.MenuFont,
                                                  b,
                                                  r.Right + 1, e.Bounds.Top + hh);
                        }
                        else
                        {
                            e.Graphics.DrawString(NameAttribute.GetName(t),
                                                  SystemInformation.MenuFont,
                                                  b,
                                                  r.Right + 1, e.Bounds.Top + hh);
                        }
                    }
                }

                gp.Dispose();
                gp = null;

                if (gradb != null)
                {
                    gradb.Dispose();
                    gradb = null;
                }

                if (selbg != null)
                {
                    selbg.Dispose();
                    selbg = null;
                }
            }
        }
Пример #3
0
        public bool Show(Point location, string hint, CodeModel.ICodeElement[] hints, int fontheight, Type[] filters)
        {
            SuspendLayout();

            if (this.filters == null)
            {
                this.filters = filters;
            }

            DialogResult = DialogResult.Cancel;
            choices.Items.Clear();

            lasthint = hint;

            //System.Diagnostics.Trace.WriteLine(Join(this.filters),     "Filters       ");

            IImageListProviderService ims = ServiceHost.ImageListProvider;

            ArrayList all = new ArrayList();

            foreach (CodeModel.ICodeElement s in hints)
            {
                if (Languages.Language.FilterType(this.filters, s))
                {
                    all.Add(s);
                }
            }

            all.Sort(CODEELEMCOMPARER);
            choices.Items.AddRange(all.ToArray());

            if (choices.Items.Count == 0)
            {
                ResumeLayout();
                if (Visible)
                {
                    Hide();

                    return(true);
                }
                else
                {
                    DialogResult = DialogResult.No;
                    return(false);
                }
            }

            choices.SelectedIndex = 0;

            if (choices.Items.Count == 1)
            {
                if (this.filters == filters || lastguess == ((CodeModel.ICodeElement)(choices.SelectedItem)).Fullname)
                {
                    ResumeLayout();
                    DialogResult = DialogResult.OK;
                    if (Visible)
                    {
                        Hide();
                        return(true);
                    }
                    else
                    {
                        return(false);
                    }
                }

                lastguess = ((CodeModel.ICodeElement)(choices.SelectedItem)).Fullname;
            }

            int diff = Height - ClientSize.Height;

            if (choices.Items.Count < 12)
            {
                Height = choices.ItemHeight * choices.Items.Count + diff + 2;
            }
            else
            {
                Height = choices.ItemHeight * 12 + diff + 2;
            }

            Screen ss = Screen.FromPoint(location);

            //x

            if (location.X + Width > ss.WorkingArea.Width)
            {
                location.X = ss.WorkingArea.Width - Width;
            }

            //y

            if (location.Y + Height > ss.WorkingArea.Bottom)
            {
                location.Y = location.Y - fontheight - Height;
            }

            Location = location;

            ResumeLayout();

            if (!Visible)
            {
                Show();
            }
            return(true);
        }
Пример #4
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                if (SelectedNode == null)
                {
                    return;
                }

                ContextMenuStrip cm = new ContextMenuStrip();

                object tag = SelectedNode.Tag;

                if (tag is Project)
                {
                    Project p = tag as Project;

                    IMenuService ms = ServiceHost.Menu;

                    ToolStripMenuItem pm = ms["Project"];

                    foreach (ToolStripItem mi in pm.DropDownItems)
                    {
                        if (mi is ToolStripSeparator)
                        {
                            cm.Items.Add(new ToolStripSeparator());
                        }
                        else
                        {
                            cm.Items.Add(((ToolStripMenuItem)mi).Clone());
                        }
                    }
                }
                else if (tag is BuildItem)
                {
                    ToolStripMenuItem pmi = new ToolStripMenuItem("Remove", null,
                                                                  new EventHandler(RemoveFile));


                    IImageListProviderService ims = ServiceHost.ImageListProvider;

                    cm.ImageList = ims.ImageList;

                    _RemoveFile rf = new _RemoveFile();
                    rf.value       = tag;
                    pmi.ImageIndex = ims[rf];
                    cm.Items.Add(pmi);

                    cm.Items.Add(new ToolStripSeparator());

                    pmi = new ToolStripMenuItem("Action");
                    cm.Items.Add(pmi);

                    Project proj = ServiceHost.Project.Current;

                    foreach (string action in proj.Actions)
                    {
                        ToolStripMenuItem am = new ToolStripMenuItem(action, null, new EventHandler(ChangeAction));
                        pmi.DropDownItems.Add(am);

                        string dd = (tag as BuildItem).Name;
                        if (dd == action)
                        {
                            am.Checked = true;
                        }
                    }
                }

                cm.Show(this, new Point(e.X, e.Y));
            }
            base.OnMouseUp(e);
        }