Esempio n. 1
0
        /// <summary>
        /// Draw the text.
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="color"></param>
        /// <param name="rect"></param>
        /// <param name="topOffset"></param>
        /// <param name="orientation"></param>
        /// <param name="fontDescription"></param>
        /// <param name="text"></param>
        /// <param name="contentAlignment"></param>
        /// <param name="flags"></param>
        public static void DrawText(IntPtr hdc, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text,
                                    ContentAlignment contentAlignment, int flags, bool rightToLeft)
        {
            NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
            NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color));

#if !PocketPC
            // QCR #439182 & 430913: the font is used for a control before even being initialized.
            // TODO: We need a better fix that avoids calling get_Font() for logical controls that are not initialized properly.
            if (fontDescription == null)
            {
                fontDescription = new FontDescription(Control.DefaultFont);
            }
#endif

            NativeWindowCommon.RECT rc = new NativeWindowCommon.RECT();
            rc.left   = rect.Left;
            rc.right  = rect.Right;
            rc.top    = rect.Top + topOffset;
            rc.bottom = rect.Bottom;

#if !PocketPC
            if (orientation != 0)
            {
                PrintRotatedText(hdc, fontDescription, orientation, text, rect, contentAlignment, rc, rightToLeft);
            }
            else
#endif
            {
                IntPtr hFont = fontDescription.FontHandle;
                NativeWindowCommon.SelectObject(hdc, hFont);
                NativeWindowCommon.DrawText(hdc, text, text.Length, ref rc, flags);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Draw the text supporting clipping according to ClipRegion.
        /// </summary>
        /// <param name="g"></param>
        /// <param name="color"></param>
        /// <param name="rect"></param>
        /// <param name="topOffset"></param>
        /// <param name="orientation"></param>
        /// <param name="fontDescription"></param>
        /// <param name="text"></param>
        /// <param name="contentAlignment"></param>
        /// <param name="flags"></param>
        public static void ClipSupportingDrawText(Graphics g, Color color, Rectangle rect, int topOffset, int orientation, FontDescription fontDescription, String text,
                                                  ContentAlignment contentAlignment, int flags, bool rightToLeft)
        {
            IntPtr region = IntPtr.Zero;
            IntPtr currentclippedRegion = g.Clip.GetHrgn(g);
            bool   IsRegionInfinite     = g.Clip.IsInfinite(g);
            IntPtr hdc = g.GetHdc();

            NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
            NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(color));

            // Text rectangle as clip Region
            IntPtr clipRegion = NativeWindowCommon.CreateRectRgn(rect.Left, rect.Top, rect.Right, rect.Bottom);

            // If Text starts above control, it needs to clip
            if (topOffset < 0)
            {
                // if current graphics is already clipped, then we need to merge with current text rectangle clip
                if (!IsRegionInfinite)
                {
                    NativeWindowCommon.CombineRgn(currentclippedRegion, currentclippedRegion, clipRegion, NativeWindowCommon.RGN_AND);
                }
            }

            if (IsRegionInfinite)
            {
                // If there is no clip region on graphics, set text rectangle as clip region
                region = clipRegion;
            }
            else if (currentclippedRegion != IntPtr.Zero)
            {
                // use intersected region as clip region
                region = currentclippedRegion;
            }

            // Select resultant clipped region on DC
            if (region != IntPtr.Zero)
            {
                NativeWindowCommon.SelectClipRgn(hdc, region);
            }


            if (clipRegion != IntPtr.Zero)
            {
                NativeWindowCommon.DeleteObject(clipRegion);
            }

            // Draw text
            DrawText(hdc, color, rect, topOffset, orientation, fontDescription, text, contentAlignment, flags, rightToLeft);

            // release objects
            g.ReleaseHdc(hdc);
            if (currentclippedRegion != IntPtr.Zero)
            {
                g.Clip.ReleaseHrgn(currentclippedRegion);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// draw header section title
        /// </summary>
        /// <param name="hdc"></param>
        /// <param name="rc"></param>
        internal void DrawTitle(IntPtr hdc, NativeWindowCommon.RECT rc, int index, bool supportsMultilineText, bool addEndEllipsesFlag, bool rightToLeftLayout)
        {
            Header.HeaderRenderer.GetTitleTextRect(index, ref rc);

            using (Graphics gr = Graphics.FromHdc(hdc))
            {
                //draw sort icon
                if (SortMark != HeaderSectionSortMarks.Non && !HasFilter)
                {
                    int iconWindth = SortIconWidth();
                    DrawSortMark(hdc, rc, gr);
                    rc.right -= iconWindth + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                }

                if (HasFilter)
                {
                    rc.right -= HeaderSection.FILTER_WIDTH + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                }

                //draw ... in the end of text if width is too short
                int width  = rc.right - rc.left;
                int format = NativeWindowCommon.DT_EDITCONTROL | NativeWindowCommon.DT_EXTERNALLEADING;

                if (supportsMultilineText)
                {
                    format |= NativeWindowCommon.DT_WORDBREAK;
                }

                StringBuilder stringBuilder = new StringBuilder(Text);

                if (addEndEllipsesFlag)
                {
                    //for windows CE && orientated fonts DT_END_ELLIPSIS style is not supported
                    //http://support.microsoft.com/kb/249678
                    format |= NativeWindowCommon.DT_END_ELLIPSIS;
                }

                if (Environment.OSVersion.Platform == PlatformID.WinCE)
                {
                    if (Text.IndexOf("\n") != -1)
                    {
                        SizeF size = gr.MeasureString(text, Font);
                        int   cur, len = cur = text.Length;
                        while (size.Width > width && cur > 1)
                        {
                            cur = --len;
                            stringBuilder.Length = len;
                            while (cur > 1 && len - cur < 3)
                            {
                                stringBuilder[--cur] = '.';
                            }
                            size = gr.MeasureString(stringBuilder.ToString(), Font);
                        }
                    }
                }



                NativeWindowCommon.SetBkMode(hdc, NativeWindowCommon.TRANSPARENT);
                NativeWindowCommon.SetTextColor(hdc, ColorTranslator.ToWin32(Color));
#if !PocketPC
                if (FontOrientation != 0)
                {
                    Rectangle rectangle = new Rectangle(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top);

                    ControlRenderer.PrintRotatedText(hdc, FontDescription, FontOrientation, stringBuilder.ToString(), rectangle, ContentAlignment, rc, rightToLeftLayout);
                }
                else
#endif
                {
                    //text flags are exactly the same as DrawText DT_*** flags
                    format |= (int)Utils.ContentAlignment2TextFlags(ContentAlignment);
                    if (isSingleLine())
                    {
                        format |= NativeWindowCommon.DT_SINGLELINE;
                    }

                    IntPtr hFont = FontDescription.FontHandle;
                    NativeWindowCommon.SelectObject(hdc, hFont);
                    NativeWindowCommon.DrawText(hdc, stringBuilder.ToString(), stringBuilder.Length, ref rc, format);
                }
#if !PocketPC
                //Set the rectangle back
                if (HasFilter)
                {
                    rc.right += HeaderSection.FILTER_WIDTH + Header.SORT_ICON_LEFT_RIGHT_MARGIN;
                    DrawFilter(hdc, rc);
                }
#endif
            }
        }