X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9a83f860948059b0273b5cc6d9e43fadad3ebfca..1e005ad1fdc1ce9bdc8b4339f1d58a32e9d9e761:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 6601fa34ad..1b3ff5896f 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -1387,7 +1387,7 @@ long wxRichTextParagraphLayoutBox::GetVisibleLineNumber(long pos, bool caretPosi wxRichTextLine* line = node2->GetData(); wxRichTextRange lineRange = line->GetAbsoluteRange(); - if (lineRange.Contains(pos)) + if (lineRange.Contains(pos) || pos == lineRange.GetStart()) { // If the caret is displayed at the end of the previous wrapped line, // we want to return the line it's _displayed_ at (not the actual line @@ -2469,7 +2469,7 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& { // Stop searching if we're beyond the range of interest if (para->GetRange().GetStart() > range.GetEnd()) - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; if (!para->GetRange().IsOutside(range)) { @@ -2478,7 +2478,12 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& while (node2) { wxRichTextObject* child = node2->GetData(); - if (!child->GetRange().IsOutside(range) && child->IsKindOf(CLASSINFO(wxRichTextPlainText))) + // Allow for empty string if no buffer + wxRichTextRange childRange = child->GetRange(); + if (childRange.GetLength() == 0 && GetRange().GetLength() == 1) + childRange.SetEnd(childRange.GetEnd()+1); + + if (!childRange.IsOutside(range) && child->IsKindOf(CLASSINFO(wxRichTextPlainText))) { foundCount ++; wxTextAttr textAttr = para->GetCombinedAttributes(child->GetAttributes()); @@ -2495,7 +2500,7 @@ bool wxRichTextParagraphLayoutBox::HasCharacterAttributes(const wxRichTextRange& node = node->GetNext(); } - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; } /// Test if this whole range has paragraph attributes of the specified kind. If any @@ -2517,7 +2522,7 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& { // Stop searching if we're beyond the range of interest if (para->GetRange().GetStart() > range.GetEnd()) - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; if (!para->GetRange().IsOutside(range)) { @@ -2533,7 +2538,7 @@ bool wxRichTextParagraphLayoutBox::HasParagraphAttributes(const wxRichTextRange& node = node->GetNext(); } - return foundCount == matchingCount; + return foundCount == matchingCount && foundCount != 0; } void wxRichTextParagraphLayoutBox::Clear() @@ -2649,6 +2654,13 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh // So when changing a list style interactively, could retrieve level based on current style, then // set appropriate indent and apply new style. + int outline = -1; + int num = -1; + if (para->GetAttributes().HasOutlineLevel()) + outline = para->GetAttributes().GetOutlineLevel(); + if (para->GetAttributes().HasBulletNumber()) + num = para->GetAttributes().GetBulletNumber(); + if (!para->GetAttributes().GetParagraphStyleName().IsEmpty() && !para->GetAttributes().GetListStyleName().IsEmpty()) { int currentIndent = para->GetAttributes().GetLeftIndent(); @@ -2699,6 +2711,11 @@ bool wxRichTextParagraphLayoutBox::ApplyStyleSheet(wxRichTextStyleSheet* styleSh foundCount ++; } } + + if (outline != -1) + para->GetAttributes().SetOutlineLevel(outline); + if (num != -1) + para->GetAttributes().SetBulletNumber(num); } node = node->GetNext(); @@ -3321,11 +3338,10 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) int lineSpacing = 0; // Let's assume line spacing of 10 is normal, 15 is 1.5, 20 is 2, etc. - if (attr.GetLineSpacing() != 10 && GetBuffer()) + if (attr.HasLineSpacing() && attr.GetLineSpacing() > 0 && attr.GetFont().Ok()) { - wxFont font(GetBuffer()->GetFontTable().FindFont(attr)); - wxCheckSetFont(dc, font); - lineSpacing = (ConvertTenthsMMToPixels(dc, dc.GetCharHeight()) * attr.GetLineSpacing())/10; + wxCheckSetFont(dc, attr.GetFont()); + lineSpacing = (int) (double(dc.GetCharHeight()) * (double(attr.GetLineSpacing())/10.0 - 1.0)); } // Available space for text on each line differs. @@ -3355,8 +3371,8 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) wxPoint currentPosition(0, spaceBeforePara); // We will calculate lines relative to paragraph int lineHeight = 0; int maxWidth = 0; + int maxAscent = 0; int maxDescent = 0; - int lineCount = 0; wxRichTextObjectList::compatibility_iterator node; @@ -3484,8 +3500,9 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) #endif currentWidth = actualSize.x; - lineHeight = wxMax(lineHeight, actualSize.y); maxDescent = wxMax(childDescent, maxDescent); + maxAscent = wxMax(actualSize.y-childDescent, maxAscent); + lineHeight = maxDescent + maxAscent; // Add a new line wxRichTextLine* line = AllocateLine(lineCount); @@ -3501,6 +3518,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) currentPosition.y += lineSpacing; currentWidth = 0; maxDescent = 0; + maxAscent = 0; maxWidth = wxMax(maxWidth, currentWidth); lineCount ++; @@ -3524,8 +3542,9 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) { // We still fit, so don't add a line, and keep going currentWidth += childSize.x; - lineHeight = wxMax(lineHeight, childSize.y); maxDescent = wxMax(childDescent, maxDescent); + maxAscent = wxMax(childSize.y-childDescent, maxAscent); + lineHeight = maxDescent + maxAscent; maxWidth = wxMax(maxWidth, currentWidth); lastEndPos = child->GetRange().GetEnd(); @@ -3574,7 +3593,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) // Apply styles to wrapped lines ApplyParagraphStyle(attr, rect, dc); - SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceBeforePara + spaceAfterPara)); + SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceAfterPara)); m_dirty = false; @@ -3641,17 +3660,13 @@ void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRe if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE) { int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); - pos.x = (rect.GetWidth() - (pos.x - rect.x) - rightIndent - size.x)/2 + pos.x; - // Lines are relative to the paragraph position - pos.x -= GetPosition().x; + pos.x = (rect.GetWidth() - pos.x - rightIndent - size.x)/2 + pos.x; line->SetPosition(pos); } else if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) { int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); - pos.x = rect.x + rect.GetWidth() - size.x - rightIndent; - // Lines are relative to the paragraph position - pos.x -= GetPosition().x; + pos.x = rect.GetWidth() - size.x - rightIndent; line->SetPosition(pos); } @@ -4800,7 +4815,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); } - wxCoord x_orig = x; + wxCoord x_orig = x; while (hasTabs) { // the string has a tab @@ -6960,8 +6975,12 @@ void wxRichTextAction::UpdateAppearance(long caretPosition, bool sendUpdateEvent // Detect last line in the buffer else if (!node2->GetNext() && para->GetRange().Contains(m_buffer->GetRange().GetEnd())) { - foundEnd = true; - lastY = pt.y + line->GetSize().y; + // If deleting text, make sure we refresh below as well as above + if (positionOffset >= 0) + { + foundEnd = true; + lastY = pt.y + line->GetSize().y; + } node2 = wxRichTextLineList::compatibility_iterator(); node = wxRichTextObjectList::compatibility_iterator(); @@ -7415,11 +7434,7 @@ wxRichTextImageBlock::wxRichTextImageBlock(const wxRichTextImageBlock& block):wx wxRichTextImageBlock::~wxRichTextImageBlock() { - if (m_data) - { - delete[] m_data; - m_data = NULL; - } + wxDELETEA(m_data); } void wxRichTextImageBlock::Init() @@ -7431,8 +7446,7 @@ void wxRichTextImageBlock::Init() void wxRichTextImageBlock::Clear() { - delete[] m_data; - m_data = NULL; + wxDELETEA(m_data); m_dataSize = 0; m_imageType = wxBITMAP_TYPE_INVALID; } @@ -7531,11 +7545,7 @@ bool wxRichTextImageBlock::Write(const wxString& filename) void wxRichTextImageBlock::Copy(const wxRichTextImageBlock& block) { m_imageType = block.m_imageType; - if (m_data) - { - delete[] m_data; - m_data = NULL; - } + wxDELETEA(m_data); m_dataSize = block.m_dataSize; if (m_dataSize == 0) return; @@ -7782,8 +7792,7 @@ bool wxRichTextBufferDataObject::GetDataHere(void *pBuf) const bool wxRichTextBufferDataObject::SetData(size_t WXUNUSED(len), const void *buf) { - delete m_richTextBuffer; - m_richTextBuffer = NULL; + wxDELETE(m_richTextBuffer); wxString bufXML((const char*) buf, wxConvUTF8); @@ -7794,8 +7803,7 @@ bool wxRichTextBufferDataObject::SetData(size_t WXUNUSED(len), const void *buf) { wxLogError(wxT("Could not read the buffer from an XML stream.\nYou may have forgotten to add the XML file handler.")); - delete m_richTextBuffer; - m_richTextBuffer = NULL; + wxDELETE(m_richTextBuffer); return false; }