Exemple #1
0
        /// <summary>
        /// Draws the formatted string on a given graphics, clipping the text by the
        /// ClipBounds set on the Graphics.
        /// </summary>
        /// <param graphics device context to draw the string in.</param>
        /// <param name="rect">The rectangle where the string is drawn.</param>
        /// <exception cref="ArgumentNullException"><i>g</i> is null</exception>
        public void DrawClipped(Graphics graphics, Rectangle rect)
        {
            RectangleF rcClip = graphics.ClipBounds;
            IntPtr     hdc    = graphics.GetHdc();

            try
            {
                IntPtr clipRgn = Win32Declarations.CreateRectRgn(0, 0, 0, 0);
                if (Win32Declarations.GetClipRgn(hdc, clipRgn) != 1)
                {
                    Win32Declarations.DeleteObject(clipRgn);
                    clipRgn = IntPtr.Zero;
                }
                Win32Declarations.IntersectClipRect(hdc, (int)rcClip.Left, (int)rcClip.Top,
                                                    (int)rcClip.Right, (int)rcClip.Bottom);

                Draw(hdc, rect);

                Win32Declarations.SelectClipRgn(hdc, clipRgn);
                Win32Declarations.DeleteObject(clipRgn);
            }
            finally
            {
                graphics.ReleaseHdc(hdc);
            }
        }
Exemple #2
0
        private static void DrawSingleIcon(RowState state, Graphics g, int index,
                                           Rectangle rcCol, int midPointX, int midPointY)
        {
            if (index >= Core.ResourceIconManager.ImageList.Images.Count)
            {
                // possible on shutdown (OM-8972)
                return;
            }

            RectangleF rcClip = g.ClipBounds;

            rcClip.Intersect(new RectangleF(rcCol.Left, rcCol.Top, rcCol.Width, rcCol.Height));
            IntPtr hdc = g.GetHdc();

            try
            {
                IntPtr clipRgn = Win32Declarations.CreateRectRgn(0, 0, 0, 0);
                if (Win32Declarations.GetClipRgn(hdc, clipRgn) != 1)
                {
                    Win32Declarations.DeleteObject(clipRgn);
                    clipRgn = IntPtr.Zero;
                }
                Win32Declarations.IntersectClipRect(hdc, (int)rcClip.Left, (int)rcClip.Top,
                                                    (int)rcClip.Right, (int)rcClip.Bottom);

                int ildState = ((state & RowState.ActiveSelected) != 0)
                    ? Win32Declarations.ILD_SELECTED
                    : Win32Declarations.ILD_NORMAL;

                Win32Declarations.ImageList_Draw(Core.ResourceIconManager.ImageList.Handle,
                                                 index, hdc, midPointX - 8, midPointY - 8, ildState);

                Win32Declarations.SelectClipRgn(hdc, clipRgn);
                Win32Declarations.DeleteObject(clipRgn);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
        }
Exemple #3
0
        protected override void DrawItem(Graphics g, Rectangle rc, object item, RowState state, string highlightText)
        {
            IResource res = item as IResource;

            if (res != null && res.GetLinksTo(null, TasksPlugin._linkTarget).Count > 0)
            {
                int midPointX = rc.Left + Width / 2;
                int midPointY = (rc.Top + rc.Bottom) / 2;

                RectangleF rcClip = g.ClipBounds;
                rcClip.Intersect(new RectangleF(rc.Left, rc.Top, rc.Width, rc.Height));
                IntPtr hdc = g.GetHdc();
                try
                {
                    IntPtr clipRgn = Win32Declarations.CreateRectRgn(0, 0, 0, 0);
                    if (Win32Declarations.GetClipRgn(hdc, clipRgn) != 1)
                    {
                        Win32Declarations.DeleteObject(clipRgn);
                        clipRgn = IntPtr.Zero;
                    }
                    Win32Declarations.IntersectClipRect(hdc, (int)rcClip.Left, (int)rcClip.Top,
                                                        (int)rcClip.Right, (int)rcClip.Bottom);

                    int ildState = ((state & RowState.ActiveSelected) != 0)
                        ? Win32Declarations.ILD_SELECTED : Win32Declarations.ILD_NORMAL;

                    Win32Declarations.ImageList_Draw(TasksPlugin._ImageList.Handle, 0, hdc,
                                                     midPointX - 8, midPointY - 8, ildState);

                    Win32Declarations.SelectClipRgn(hdc, clipRgn);
                    Win32Declarations.DeleteObject(clipRgn);
                }
                finally
                {
                    g.ReleaseHdc(hdc);
                }
            }
        }
Exemple #4
0
        public int DrawText(Graphics g, string text, Font font, Color color, Rectangle rc, StringFormat format)
        {
            int        height;
            RectangleF rcClip = g.ClipBounds;
            RECT       rect   = new RECT(rc.Left, rc.Top, rc.Right, rc.Bottom);
            IntPtr     hdc    = g.GetHdc();

            try
            {
                IntPtr clipRgn = Win32Declarations.CreateRectRgn(0, 0, 0, 0);
                if (Win32Declarations.GetClipRgn(hdc, clipRgn) != 1)
                {
                    Win32Declarations.DeleteObject(clipRgn);
                    clipRgn = IntPtr.Zero;
                }
                Win32Declarations.IntersectClipRect(hdc, (int)rcClip.Left, (int)rcClip.Top, (int)rcClip.Right, (int)rcClip.Bottom);

                IntPtr         hFont     = _fontCache.GetHFont(font);
                IntPtr         oldFont   = Win32Declarations.SelectObject(hdc, hFont);
                int            textColor = Win32Declarations.ColorToRGB(color);
                int            oldColor  = Win32Declarations.SetTextColor(hdc, textColor);
                BackgroundMode oldMode   = Win32Declarations.SetBkMode(hdc, BackgroundMode.TRANSPARENT);

                DrawTextFormatFlags flags = 0;
                if ((format.FormatFlags & StringFormatFlags.NoWrap) != 0)
                {
                    flags |= DrawTextFormatFlags.DT_SINGLELINE;
                }
                else
                {
                    flags |= DrawTextFormatFlags.DT_WORDBREAK;
                }
                if (format.Alignment == StringAlignment.Center)
                {
                    flags |= DrawTextFormatFlags.DT_CENTER;
                }
                else if (format.Alignment == StringAlignment.Far)
                {
                    flags |= DrawTextFormatFlags.DT_RIGHT;
                }

                if (format.LineAlignment == StringAlignment.Center)
                {
                    flags |= DrawTextFormatFlags.DT_VCENTER;
                }
                if (format.Trimming == StringTrimming.EllipsisCharacter)
                {
                    flags |= DrawTextFormatFlags.DT_END_ELLIPSIS;
                }
                if (format.HotkeyPrefix == HotkeyPrefix.None)
                {
                    flags |= DrawTextFormatFlags.DT_NOPREFIX;
                }

                height = Win32Declarations.DrawText(hdc, text, text.Length, ref rect, flags);

                Win32Declarations.SelectClipRgn(hdc, clipRgn);
                Win32Declarations.DeleteObject(clipRgn);

                Win32Declarations.SetBkMode(hdc, oldMode);
                Win32Declarations.SetTextColor(hdc, oldColor);
                Win32Declarations.SelectObject(hdc, oldFont);
            }
            finally
            {
                g.ReleaseHdc(hdc);
            }
            return(height);
        }