/// <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 } }