From 8cf3e90650a73dc26ece7ba5b396f12788727e71 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 18 Feb 2015 12:18:27 +0000 Subject: [PATCH] Now allows space for a bullet even if no left subindent was specified; added a MeasureBullet function to support this. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78518 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/richtext/richtextbuffer.h | 8 ++++ interface/wx/richtext/richtextbuffer.h | 8 ++++ src/richtext/richtextbuffer.cpp | 62 +++++++++++++++++++++++++- 3 files changed, 76 insertions(+), 2 deletions(-) diff --git a/include/wx/richtext/richtextbuffer.h b/include/wx/richtext/richtextbuffer.h index 26ef86426a..2e9b759434 100644 --- a/include/wx/richtext/richtextbuffer.h +++ b/include/wx/richtext/richtextbuffer.h @@ -6965,6 +6965,11 @@ public: Enumerate the standard bullet names currently supported. This function should be overridden. */ virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; + + /** + Measure the bullet. + */ + virtual bool MeasureBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, wxSize& sz) = 0; }; /** @@ -6997,6 +7002,9 @@ public: // Enumerate the standard bullet names currently supported virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); + + // Measure the bullet. + virtual bool MeasureBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, wxSize& sz); }; /*! diff --git a/interface/wx/richtext/richtextbuffer.h b/interface/wx/richtext/richtextbuffer.h index 085d031e19..833b8400f8 100644 --- a/interface/wx/richtext/richtextbuffer.h +++ b/interface/wx/richtext/richtextbuffer.h @@ -6749,6 +6749,11 @@ public: Enumerate the standard bullet names currently supported. This function should be overridden. */ virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames) = 0; + + /** + Measure the bullet. + */ + virtual bool MeasureBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, wxSize& sz) = 0; }; /** @@ -6781,6 +6786,9 @@ public: // Enumerate the standard bullet names currently supported virtual bool EnumerateStandardBulletNames(wxArrayString& bulletNames); + + // Measure the bullet. + virtual bool MeasureBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, wxSize& sz); }; /*! diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 77ddd1dbf4..009475b9f4 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -4821,9 +4821,8 @@ bool wxRichTextParagraph::Draw(wxDC& dc, wxRichTextDrawingContext& context, cons DrawBoxAttributes(dc, GetBuffer(), attr, paraRect, 0); // Draw the bullet, if any - if ((attr.GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE) == 0 && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_CONTINUATION) == 0) + if ((attr.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE) && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_CONTINUATION) == 0) { - if (attr.GetLeftSubIndent() != 0) { int spaceBeforePara = ConvertTenthsMMToPixels(dc, attr.GetParagraphSpacingBefore()); int leftIndent = ConvertTenthsMMToPixels(dc, attr.GetLeftIndent()); @@ -5019,6 +5018,22 @@ bool wxRichTextParagraph::Layout(wxDC& dc, wxRichTextDrawingContext& context, co } } + // Make space for a bullet with no subindent. + if ((leftIndent == 0) && (attr.GetBulletStyle() != wxTEXT_ATTR_BULLET_STYLE_NONE)) + { + wxSize bulletSize; + if (wxRichTextBuffer::GetRenderer() && wxRichTextBuffer::GetRenderer()->MeasureBullet(this, dc, attr, bulletSize)) + { + wxFont font(buffer->GetFontTable().FindFont(attr)); + if (font.IsOk()) + { + wxCheckSetFont(dc, font); + wxCoord spaceW = 0, spaceH = 0, maxDescent = 0; + dc.GetTextExtent(wxT(" "), & spaceW, & spaceH, & maxDescent); + leftSubIndent = bulletSize.x + spaceW; + } + } + } // Start position for each line relative to the paragraph int startPositionFirstLine = leftIndent; int startPositionSubsequentLines = leftIndent + leftSubIndent; @@ -9233,6 +9248,49 @@ bool wxRichTextStdRenderer::DrawBitmapBullet(wxRichTextParagraph* WXUNUSED(parag return false; } +// Measure the bullet. +bool wxRichTextStdRenderer::MeasureBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& attr, wxSize& sz) +{ + wxFont font; + if (attr.HasFont()) + { + font = paragraph->GetBuffer()->GetFontTable().FindFont(attr); + } + else + font = (*wxNORMAL_FONT); + + wxCheckSetFont(dc, font); + + if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_STANDARD) + { + sz.x = (int) (((float) dc.GetCharHeight()) * wxRichTextBuffer::GetBulletProportion()); + sz.y = sz.y; + } + else if (attr.HasBulletText()) + { + wxCoord w, h, maxDescent; + dc.GetTextExtent(attr.GetBulletText(), & w, &h, & maxDescent); + sz.x = w; + sz.y = h; + } + else if (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_BITMAP) + { + // A guess, at present. + sz.x = 10; + sz.y = 10; + } + else + { + // Need to guess a size for a number bullet. + wxCoord w, h, maxDescent; + dc.GetTextExtent(wxT("8888."), & w, &h, & maxDescent); + sz.x = w; + sz.y = h; + } + + return true; +} + /// Enumerate the standard bullet names currently supported bool wxRichTextStdRenderer::EnumerateStandardBulletNames(wxArrayString& bulletNames) {