|
5 | 5 | * Date: 27/09/2008 9:15 AM |
6 | 6 | * |
7 | 7 | * Change log: |
| 8 | + * 2018-10-06 JPP - Fix rendering so that OLVColumn.WordWrap works when using customised Renderers |
8 | 9 | * 2018-05-01 JPP - Use ITextMatchFilter interface rather than TextMatchFilter concrete class. |
9 | 10 | * v2.9.2 |
10 | 11 | * 2016-06-02 JPP - CalculateImageWidth() no longer adds 2 to the image width |
@@ -279,20 +280,32 @@ public class BaseRenderer : AbstractRenderer { |
279 | 280 | /// <summary> |
280 | 281 | /// Can the renderer wrap lines that do not fit completely within the cell? |
281 | 282 | /// </summary> |
282 | | - /// <remarks>Wrapping text doesn't work with the GDI renderer.</remarks> |
| 283 | + /// <remarks> |
| 284 | + /// <para>If this is not set specifically, the value will be taken from Column.WordWrap</para> |
| 285 | + /// <para> |
| 286 | + /// Wrapping text doesn't work with the GDI renderer, so if this set to true, GDI+ rendering will used. |
| 287 | + /// The difference between GDI and GDI+ rendering can give word wrapped columns a slight different appearance. |
| 288 | + /// </para> |
| 289 | + /// </remarks> |
283 | 290 | [Category("Appearance"), |
284 | 291 | Description("Can the renderer wrap text that does not fit completely within the cell"), |
285 | | - DefaultValue(false)] |
286 | | - public bool CanWrap { |
| 292 | + DefaultValue(null)] |
| 293 | + public bool? CanWrap { |
287 | 294 | get { return canWrap; } |
288 | | - set { |
289 | | - canWrap = value; |
290 | | - if (canWrap) |
291 | | - this.UseGdiTextRendering = false; |
292 | | - } |
| 295 | + set { canWrap = value; } |
293 | 296 | } |
294 | | - private bool canWrap; |
295 | 297 |
|
| 298 | + private bool? canWrap; |
| 299 | + |
| 300 | + /// <summary> |
| 301 | + /// Get the actual value that should be used right now for CanWrap |
| 302 | + /// </summary> |
| 303 | + [Browsable(false)] |
| 304 | + protected bool CanWrapOrDefault { |
| 305 | + get { |
| 306 | + return this.CanWrap ?? this.Column != null && this.Column.WordWrap; |
| 307 | + } |
| 308 | + } |
296 | 309 | /// <summary> |
297 | 310 | /// Gets or sets how many pixels will be left blank around this cell |
298 | 311 | /// </summary> |
@@ -419,13 +432,15 @@ public int Spacing { |
419 | 432 | /// Should text be rendered using GDI routines? This makes the text look more |
420 | 433 | /// like a native List view control. |
421 | 434 | /// </summary> |
| 435 | + /// <remarks>Even if this is set to true, it will return false if the renderer |
| 436 | + /// is set to word wrap, since GDI doesn't handle wrapping.</remarks> |
422 | 437 | [Category("Appearance"), |
423 | 438 | Description("Should text be rendered using GDI routines?"), |
424 | 439 | DefaultValue(true)] |
425 | 440 | public virtual bool UseGdiTextRendering { |
426 | 441 | get { |
427 | | - // Can't use GDI routines on a GDI+ printer context |
428 | | - return !this.IsPrinting && useGdiTextRendering; |
| 442 | + // Can't use GDI routines on a GDI+ printer context or when word wrapping is required |
| 443 | + return !this.IsPrinting && !this.CanWrapOrDefault && useGdiTextRendering; |
429 | 444 | } |
430 | 445 | set { useGdiTextRendering = value; } |
431 | 446 | } |
@@ -502,6 +517,16 @@ public DrawListViewSubItemEventArgs Event { |
502 | 517 | /// <summary> |
503 | 518 | /// Gets or sets the font to be used for text in this cell |
504 | 519 | /// </summary> |
| 520 | + /// <remarks> |
| 521 | + /// <para> |
| 522 | + /// In general, this property should be treated as internal. |
| 523 | + /// If you do set this, the given font will be used without any other consideration. |
| 524 | + /// All other factors -- selection state, hot item, hyperlinks -- will be ignored. |
| 525 | + /// </para> |
| 526 | + /// <para> |
| 527 | + /// A better way to set the font is to change either ListItem.Font or SubItem.Font |
| 528 | + /// </para> |
| 529 | + /// </remarks> |
505 | 530 | [Browsable(false), |
506 | 531 | DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
507 | 532 | public Font Font { |
@@ -622,6 +647,14 @@ public OLVListSubItem SubItem { |
622 | 647 | /// <summary> |
623 | 648 | /// The brush that will be used to paint the text |
624 | 649 | /// </summary> |
| 650 | + /// <remarks> |
| 651 | + /// <para> |
| 652 | + /// In general, this property should be treated as internal. It will be reset after each render. |
| 653 | + /// </para> |
| 654 | + /// <para> |
| 655 | + /// </para> |
| 656 | + /// In particular, don't set it to configure the color of the text on the control. That should be done via SubItem.ForeColor |
| 657 | + /// </remarks> |
625 | 658 | [Browsable(false), |
626 | 659 | DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] |
627 | 660 | public Brush TextBrush { |
@@ -661,7 +694,6 @@ private void ClearState() { |
661 | 694 | this.Event = null; |
662 | 695 | this.DrawItemEvent = null; |
663 | 696 | this.Aspect = null; |
664 | | - this.Font = null; |
665 | 697 | this.TextBrush = null; |
666 | 698 | } |
667 | 699 |
|
@@ -1733,7 +1765,7 @@ protected virtual void DrawTextGdi(Graphics g, Rectangle r, String txt) { |
1733 | 1765 |
|
1734 | 1766 | // I think there is a bug in the TextRenderer. Setting or not setting SingleLine doesn't make |
1735 | 1767 | // any difference -- it is always single line. |
1736 | | - if (!this.CanWrap) |
| 1768 | + if (!this.CanWrapOrDefault) |
1737 | 1769 | flags |= TextFormatFlags.SingleLine; |
1738 | 1770 | TextRenderer.DrawText(g, txt, this.Font, r, this.GetForegroundColor(), backColor, flags); |
1739 | 1771 | } |
@@ -1770,7 +1802,7 @@ protected virtual StringFormat StringFormatForGdiPlus { |
1770 | 1802 | fmt.LineAlignment = this.EffectiveCellVerticalAlignment; |
1771 | 1803 | fmt.Trimming = StringTrimming.EllipsisCharacter; |
1772 | 1804 | fmt.Alignment = this.Column == null ? StringAlignment.Near : this.Column.TextStringAlign; |
1773 | | - if (!this.CanWrap) |
| 1805 | + if (!this.CanWrapOrDefault) |
1774 | 1806 | fmt.FormatFlags = StringFormatFlags.NoWrap; |
1775 | 1807 | return fmt; |
1776 | 1808 | } |
@@ -1816,6 +1848,13 @@ protected virtual void DrawTextGdiPlus(Graphics g, Rectangle r, String txt) { |
1816 | 1848 | /// <summary> |
1817 | 1849 | /// This renderer highlights substrings that match a given text filter. |
1818 | 1850 | /// </summary> |
| 1851 | + /// <remarks> |
| 1852 | + /// Implementation note: |
| 1853 | + /// This renderer uses the functionality of BaseRenderer to draw the text, and |
| 1854 | + /// then draws a translucent frame over the top of the already rendered text glyphs. |
| 1855 | + /// There's no way to draw the matching text in a different font or color in this |
| 1856 | + /// implementation. |
| 1857 | + /// </remarks> |
1819 | 1858 | public class HighlightTextRenderer : BaseRenderer, IFilterAwareRenderer { |
1820 | 1859 | #region Life and death |
1821 | 1860 |
|
|
0 commit comments