Exemplo n.º 1
0
        private void PaintGroup(ItemPaintArgs pa, RibbonTabItemGroup group, Rectangle rect, Rectangle groupBounds)
        {
            if (m_CaptionVisible && !m_QuickToolbarBounds.IsEmpty && rect.IntersectsWith(m_QuickToolbarBounds) || m_SystemCaptionItemBounds.IntersectsWith(groupBounds))
                return;
            eDotNetBarStyle effectiveStyle = this.EffectiveStyle;

            if (effectiveStyle == eDotNetBarStyle.Office2010 || effectiveStyle == eDotNetBarStyle.Metro)
                group.DisplayPositions.Add(new Rectangle(rect.X, rect.Y, rect.Width + 1, rect.Height));
            else
                group.DisplayPositions.Add(rect);


            if (BarFunctions.IsOffice2007Style(effectiveStyle))
            {
                RibbonTabGroupRendererEventArgs e = new RibbonTabGroupRendererEventArgs(pa.Graphics, group, rect, groupBounds, this.GetDefaultGroupFont(), pa, effectiveStyle);
                Rendering.BaseRenderer renderer = GetRenderer();
                renderer.DrawRibbonTabGroup(e);
            }
            else
            {
                ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(group.Style, pa.Graphics, rect);
                ElementStyleDisplay.Paint(info);
                ElementStyleDisplay.PaintText(info, group.GroupTitle, this.GetDefaultGroupFont());
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Paints ribbon tab group.
        /// </summary>
        /// <param name="e">Context information</param>
        public override void PaintTabGroup(RibbonTabGroupRendererEventArgs e)
        {
            Graphics g = e.Graphics;
            Office2007RibbonTabGroupColorTable colorTable = GetColors(e.RibbonTabItemGroup);
            if (colorTable == null)
                return;
            #if FRAMEWORK20
            if (e.ItemPaintArgs.GlassEnabled)
            {
                if (e.ItemPaintArgs.CachedPaint) return;
                PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, true);
                
                Rectangle rect = e.Bounds;
                rect.Height -= 2;
                IntPtr hdc = g.GetHdc();
                Font font = e.GroupFont;
                string text = e.RibbonTabItemGroup.GroupTitle;
                ThemeTextFormat tf = GetThemeFormat();
                try
                {
                    IntPtr memdc = WinApi.CreateCompatibleDC(hdc);
                    try
                    {
                        WinApi.BITMAPINFO bmpInfo = new WinApi.BITMAPINFO();
                        bmpInfo.biWidth = rect.Width;
                        bmpInfo.biHeight = -rect.Height;
                        bmpInfo.biPlanes = 1;
                        bmpInfo.biBitCount = 32;
                        bmpInfo.biSize = Marshal.SizeOf(bmpInfo);
                        IntPtr dib = WinApi.CreateDIBSection(hdc, bmpInfo, 0, 0, IntPtr.Zero, 0);
                        WinApi.SelectObject(memdc, dib);

                        IntPtr fontHandle = font.ToHfont();
                        WinApi.SelectObject(memdc, fontHandle);

                        Themes.RECT bounds = GetThemeTextBounds(rect);
                        System.Windows.Forms.VisualStyles.VisualStyleRenderer themeRenderer = new System.Windows.Forms.VisualStyles.VisualStyleRenderer(System.Windows.Forms.VisualStyles.VisualStyleElement.Window.Caption.Active);
                        Themes.DTTOPTS dttOpts = new Themes.DTTOPTS();
                        dttOpts.iGlowSize = 10;
                        dttOpts.crText = new Themes.COLORREF(colorTable.Text);
                        dttOpts.dwFlags = (int)Themes.DTT_VALIDBITS.DTT_COMPOSITED | (int)Themes.DTT_VALIDBITS.DTT_TEXTCOLOR;
                        if (colorTable.Background == null || colorTable.Background.IsEmpty || colorTable.Background.Start.A < 255)
                            dttOpts.dwFlags |= (int)Themes.DTT_VALIDBITS.DTT_GLOWSIZE;
                        dttOpts.dwSize = Marshal.SizeOf(dttOpts);
                        
                        // Draw Background
                        using (Graphics gb = Graphics.FromHdc(memdc))
                        {
                            PaintTabGroupBackground(gb, colorTable, new Rectangle(0, 0, rect.Width, rect.Height + 2), new Rectangle(0, 0, rect.Width, rect.Height + 2), true);
                        }
                        
                        Themes.DrawThemeTextEx(themeRenderer.Handle, memdc, 0, 0, text, -1, (int)tf, ref bounds, ref dttOpts);
                        

                        const int SRCCOPY = 0x00CC0020;
                        WinApi.BitBlt(hdc, rect.Left, rect.Top, rect.Width, rect.Height, memdc, 0, 0, SRCCOPY);

                        WinApi.DeleteObject(fontHandle);
                        WinApi.DeleteObject(dib);
                    }
                    finally
                    {
                        WinApi.DeleteDC(memdc);
                    }
                }
                finally
                {
                    g.ReleaseHdc(hdc);
                }
                return;
            }
            #endif

            PaintTabGroupBackground(g, colorTable, e.Bounds, e.GroupBounds, false);
            ElementStyle style = e.RibbonTabItemGroup.Style; //.Copy();
            Color styleTextColor = style.TextColor;
            Color styleTextShadowColor = style.TextShadowColor;
            Point styleTextShadowOffset = style.TextShadowOffset;
            style.FreezeEvents = true;
            style.TextColor = colorTable.Text;
            style.TextShadowColor = Color.Empty;
            style.TextShadowOffset = Point.Empty;

            ElementStyleDisplayInfo info = new ElementStyleDisplayInfo(style, e.Graphics, GetTextBounds(e));
            ElementStyleDisplay.PaintText(info, e.RibbonTabItemGroup.GroupTitle, e.GroupFont, false, e.RibbonTabItemGroup.Style.TextFormat | GetTextFormat());

            style.TextColor = styleTextColor;
            style.TextShadowColor = styleTextShadowColor;
            style.TextShadowOffset = styleTextShadowOffset;
            style.FreezeEvents = false;
        }
Exemplo n.º 3
0
 public abstract void PaintTabGroup(RibbonTabGroupRendererEventArgs e);
Exemplo n.º 4
0
 protected virtual Rectangle GetTextBounds(RibbonTabGroupRendererEventArgs e)
 {
     return e.Bounds;
 }