Beispiel #1
0
        static X11DesktopColors()
        {
            FindDesktopEnvironment();

            switch (desktop)
            {
            case Desktop.Gtk: {
                //IntPtr		dispmgr;
                //IntPtr		gdkdisplay;
                IntPtr         widget;
                IntPtr         style_ptr;
                GtkStyleStruct style;

                try {
                    GtkInit();
                    //dispmgr =  gdk_display_manager_get ();
                    //gdkdisplay =  gdk_display_manager_get_default_display (dispmgr);

                    widget = gtk_invisible_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorControl           = ColorFromGdkColor(style.bg[0]);
                    ThemeEngine.Current.ColorControlText       = ColorFromGdkColor(style.fg[0]);
                    ThemeEngine.Current.ColorControlDark       = ColorFromGdkColor(style.dark[0]);
                    ThemeEngine.Current.ColorControlLight      = ColorFromGdkColor(style.light[0]);
                    ThemeEngine.Current.ColorControlLightLight = ControlPaint.Light(ThemeEngine.Current.ColorControlLight);
                    ThemeEngine.Current.ColorControlDarkDark   = ControlPaint.Dark(ThemeEngine.Current.ColorControlDark);

                    // We don't want ControlLight to disappear on a white background!
                    if (ThemeEngine.Current.ColorControlLight.ToArgb() == Color_.White.ToArgb())
                    {
                        ThemeEngine.Current.ColorControlLight = Color_.FromArgb(255, 227, 227, 227);
                    }
                    widget = gtk_menu_new();
                    gtk_widget_ensure_style(widget);
                    style_ptr = gtk_widget_get_style(widget);

                    style = (GtkStyleStruct)Marshal.PtrToStructure(style_ptr, typeof(GtkStyleStruct));

                    ThemeEngine.Current.ColorMenu     = ColorFromGdkColor(style.bg [0]);
                    ThemeEngine.Current.ColorMenuText = ColorFromGdkColor(style.text [0]);
                }

                catch (DllNotFoundException) {
                    Console.Error.WriteLine("Gtk not found (missing LD_LIBRARY_PATH to libgtk-x11-2.0.so.0?), using built-in colorscheme");
                }

                catch {
                    Console.Error.WriteLine("Gtk colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            case Desktop.KDE: {
                if (!ReadKDEColorsheme())
                {
                    Console.Error.WriteLine("KDE colorscheme read failure, using built-in colorscheme");
                }
                break;
            }

            default: {
                break;
            }
            }
        }
Beispiel #2
0
        private void DrawGroupBox(PaintEventArgs e)
        {
            Graphics  graphics      = e.Graphics;
            Rectangle textRectangle = ClientRectangle; // Max text bounding box passed to drawing methods to support RTL.

            int textOffset = 8;                        // Offset from the left bound.

            Color backColor = DisabledColor;

            Pen  light = new Pen(ControlPaint.Light(backColor, 1.0f));
            Pen  dark  = new Pen(ControlPaint.Dark(backColor, 0f));
            Size textSize;

            textRectangle.X     += textOffset;
            textRectangle.Width -= 2 * textOffset;

            try {
                if (UseCompatibleTextRendering)
                {
                    using (Brush textBrush = new SolidBrush(ForeColor)){
                        using (StringFormat format = new StringFormat()){
                            format.HotkeyPrefix = ShowKeyboardCues ? System.Drawing.Text.HotkeyPrefix.Show : System.Drawing.Text.HotkeyPrefix.Hide;

                            // Adjust string format for Rtl controls

                            if (RightToLeft == RightToLeft.Yes)
                            {
                                format.FormatFlags |= StringFormatFlags.DirectionRightToLeft;
                            }

                            textSize = Size.Ceiling(graphics.MeasureString(Text, Font, textRectangle.Width, format));

                            if (Enabled)
                            {
                                graphics.DrawString(Text, Font, textBrush, textRectangle, format);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(graphics, Text, Font, backColor, textRectangle, format);
                            }
                        }
                    }
                }
                else
                {
                    using (WindowsGraphics wg = WindowsGraphics.FromGraphics(graphics)){
                        IntTextFormatFlags flags = IntTextFormatFlags.WordBreak | IntTextFormatFlags.TextBoxControl;

                        if (!ShowKeyboardCues)
                        {
                            flags |= IntTextFormatFlags.HidePrefix;
                        }

                        if (RightToLeft == RightToLeft.Yes)
                        {
                            flags |= IntTextFormatFlags.RightToLeft;
                            flags |= IntTextFormatFlags.Right;
                        }


                        using (WindowsFont wfont = WindowsGraphicsCacheManager.GetWindowsFont(this.Font)) {
                            textSize = wg.MeasureText(Text, wfont, new Size(textRectangle.Width, int.MaxValue), flags);

                            if (Enabled)
                            {
                                wg.DrawText(Text, wfont, textRectangle, ForeColor, flags);
                            }
                            else
                            {
                                ControlPaint.DrawStringDisabled(wg, Text, Font, backColor, textRectangle, ((TextFormatFlags)flags));
                            }
                        }
                    }
                }

                int textLeft = textOffset;    // Left side of binding box (independent on RTL).

                if (RightToLeft == RightToLeft.Yes)
                {
                    textLeft += textRectangle.Width - textSize.Width;
                }

                // Math.Min to assure we paint at least a small line.
                int textRight = Math.Min(textLeft + textSize.Width, Width - 6);

                int boxTop = FontHeight / 2;

                if (SystemInformation.HighContrast && AccessibilityImprovements.Level1)
                {
                    Color boxColor;
                    if (Enabled)
                    {
                        boxColor = ForeColor;
                    }
                    else
                    {
                        boxColor = SystemColors.GrayText;
                    }
                    bool needToDispose = !boxColor.IsSystemColor;
                    Pen  boxPen        = null;
                    try {
                        if (needToDispose)
                        {
                            boxPen = new Pen(boxColor);
                        }
                        else
                        {
                            boxPen = SystemPens.FromSystemColor(boxColor);
                        }

                        // left
                        graphics.DrawLine(boxPen, 0, boxTop, 0, Height);
                        //bottom
                        graphics.DrawLine(boxPen, 0, Height - 1, Width, Height - 1);
                        //top-left
                        graphics.DrawLine(boxPen, 0, boxTop, textLeft, boxTop);
                        //top-right
                        graphics.DrawLine(boxPen, textRight, boxTop, Width - 1, boxTop);
                        //right
                        graphics.DrawLine(boxPen, Width - 1, boxTop, Width - 1, Height - 1);
                    }
                    finally {
                        if (needToDispose && boxPen != null)
                        {
                            boxPen.Dispose();
                        }
                    }
                }
                else
                {
                    // left
                    graphics.DrawLine(light, 1, boxTop, 1, Height - 1);
                    graphics.DrawLine(dark, 0, boxTop, 0, Height - 2);

                    // bottom
                    graphics.DrawLine(light, 0, Height - 1, Width, Height - 1);
                    graphics.DrawLine(dark, 0, Height - 2, Width - 1, Height - 2);

                    // top-left

                    graphics.DrawLine(dark, 0, boxTop - 1, textLeft, boxTop - 1);
                    graphics.DrawLine(light, 1, boxTop, textLeft, boxTop);

                    // top-right
                    graphics.DrawLine(dark, textRight, boxTop - 1, Width - 2, boxTop - 1);
                    graphics.DrawLine(light, textRight, boxTop, Width - 1, boxTop);

                    // right
                    graphics.DrawLine(light, Width - 1, boxTop - 1, Width - 1, Height - 1);
                    graphics.DrawLine(dark, Width - 2, boxTop, Width - 2, Height - 2);
                }
            }
            finally {
                light.Dispose();
                dark.Dispose();
            }
        }
        protected override void OnRenderButtonBackground(ToolStripItemRenderEventArgs e)
        {
            Graphics g = e.Graphics;

            g.CompositingQuality = CompositingQuality.HighQuality;
            g.SmoothingMode      = SmoothingMode.HighQuality;
            //todo:背景渐变色,边框色, 关闭按钮

            TabStrip       tabs = e.ToolStrip as TabStrip;
            TabStripButton tab  = e.Item as TabStripButton;

            if (tabs == null || tab == null)
            {
                if (_currentRenderer != null)
                {
                    _currentRenderer.DrawButtonBackground(e);
                }
                else
                {
                    base.OnRenderButtonBackground(e);
                }
                return;
            }

            bool      selected = tab.Checked;
            bool      hovered  = tab.Selected;
            int       top      = 0;
            int       left     = 0;
            int       width    = tab.Bounds.Width - 1;
            int       height   = tab.Bounds.Height - 1;
            Rectangle drawBorder;


            if (UseVS)
            {
                #region Visual Style

                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }
                    drawBorder = new Rectangle(0, 0, width, height);
                }
                else
                {
                    if (!selected)
                    {
                        left   = selOffset;
                        width -= (selOffset - 1);
                    }
                    else
                    {
                        left = 1;
                    }
                    drawBorder = new Rectangle(0, 0, height, width);
                }
                using (Bitmap b = new Bitmap(drawBorder.Width, drawBorder.Height))
                {
                    VisualStyleElement el = VisualStyleElement.Tab.TabItem.Normal;
                    if (selected)
                    {
                        el = VisualStyleElement.Tab.TabItem.Pressed;
                    }
                    if (hovered)
                    {
                        el = VisualStyleElement.Tab.TabItem.Hot;
                    }
                    if (!tab.Enabled)
                    {
                        el = VisualStyleElement.Tab.TabItem.Disabled;
                    }

                    if (!selected)
                    {
                    }
                    else if (hovered)
                    {
                        //drawBorder.Width++;
                    }
                    else
                    {
                        drawBorder.Height++;
                    }

                    using (Graphics gr = Graphics.FromImage(b))
                    {
                        VisualStyleRenderer rndr = new VisualStyleRenderer(el);
                        rndr.DrawBackground(gr, drawBorder);

                        if (tabs.Orientation == Orientation.Vertical)
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipXY);
                            }
                            else
                            {
                                b.RotateFlip(RotateFlipType.Rotate270FlipNone);
                            }
                        }
                        else
                        {
                            if (Mirrored)
                            {
                                b.RotateFlip(RotateFlipType.RotateNoneFlipY);
                            }
                        }
                        if (Mirrored)
                        {
                            left = tab.Bounds.Width - b.Width - left;
                            top  = tab.Bounds.Height - b.Height - top;
                        }
                        g.DrawImage(b, left, top);
                    }
                }

                #endregion
            } // UseVS == true END
            else
            {
                if (tabs.Orientation == Orientation.Horizontal)
                {
                    if (!selected)
                    {
                        top     = selOffset;
                        height -= (selOffset - 1);
                    }
                    else
                    {
                        top = 1;
                    }

                    if (Mirrored)
                    {
                        left = 1;
                        top  = 0;
                    }
                    else
                    {
                        top++;
                    }

                    width--;
                }
                else
                {
                    if (!selected)
                    {
                        left = selOffset;
                        width--;
                    }
                    else
                    {
                        left = 1;
                    }

                    if (Mirrored)
                    {
                        left = 0;
                        top  = 1;
                    }
                }
                height--;
                drawBorder = new Rectangle(left, top, width, height);

                using (GraphicsPath gp = new GraphicsPath())
                {
                    if (Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right - 2, drawBorder.Bottom);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Bottom - 2, drawBorder.Right, drawBorder.Top);
                    }
                    else if (!Mirrored && tabs.Orientation == Orientation.Horizontal)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Bottom, drawBorder.Left, drawBorder.Top + 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom);
                    }
                    else if (Mirrored && tabs.Orientation == Orientation.Vertical)
                    {
                        gp.AddLine(drawBorder.Left, drawBorder.Top, drawBorder.Right - 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Top + 1, 2, 2, 270, 90);
                        gp.AddLine(drawBorder.Right, drawBorder.Top + 2, drawBorder.Right, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Right - 2, drawBorder.Bottom - 3, 2, 2, 0, 90);
                        gp.AddLine(drawBorder.Right - 2, drawBorder.Bottom, drawBorder.Left, drawBorder.Bottom);
                    }
                    else
                    {
                        gp.AddLine(drawBorder.Right, drawBorder.Top, drawBorder.Left + 2, drawBorder.Top);
                        gp.AddArc(drawBorder.Left, drawBorder.Top + 1, 2, 2, 180, 90);
                        gp.AddLine(drawBorder.Left, drawBorder.Top + 2, drawBorder.Left, drawBorder.Bottom - 2);
                        gp.AddArc(drawBorder.Left, drawBorder.Bottom - 3, 2, 2, 90, 90);
                        gp.AddLine(drawBorder.Left + 2, drawBorder.Bottom, drawBorder.Right, drawBorder.Bottom);
                    }

                    if (selected || hovered)
                    {
                        Color fill = (hovered) ? Color.WhiteSmoke : Color.White;
                        if (_renderMode == ToolStripRenderMode.Professional)
                        {
                            fill = (hovered) ? ProfessionalColors.ButtonCheckedGradientBegin : ProfessionalColors.ButtonCheckedGradientEnd;
                            using (LinearGradientBrush br = new LinearGradientBrush(tab.ContentRectangle, fill, ProfessionalColors.ButtonCheckedGradientMiddle, LinearGradientMode.Vertical))
                            {
                                g.FillPath(br, gp);
                            }
                        }
                        else
                        {
                            using (SolidBrush br = new SolidBrush(fill))
                            {
                                g.FillPath(br, gp);
                            }
                        }
                    }
                    else
                    {
                        using (SolidBrush br = new SolidBrush(_inactivedTabBackColor))
                        {
                            g.FillPath(br, gp);
                        }
                    }

                    using (Pen p = new Pen((selected) ? ControlPaint.Dark(SystemColors.AppWorkspace) : SystemColors.AppWorkspace))
                    {
                        g.DrawPath(p, gp);
                    }
                }
            } // UseVS == false END
        }