X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/f1d800d91ec8f75eaf021ae975145abb36c4506b..5c87527c5a81eda63e7ccbda2f226ca02716e7da:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index b25bd7ae0a..33031e957a 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -57,6 +57,7 @@ const wxChar wxRichTextLineBreakChar = (wxChar) 29; inline void wxCheckSetFont(wxDC& dc, const wxFont& font) { +#if 0 const wxFont& font1 = dc.GetFont(); if (font1.IsOk() && font.IsOk()) { @@ -68,6 +69,7 @@ inline void wxCheckSetFont(wxDC& dc, const wxFont& font) font1.GetFaceName() == font.GetFaceName()) return; } +#endif dc.SetFont(font); } @@ -431,7 +433,7 @@ bool wxRichTextCompositeObject::Defragment(const wxRichTextRange& range) while (node) { wxRichTextObject* child = node->GetData(); - if (!child->GetRange().IsOutside(range)) + if (range == wxRICHTEXT_ALL || !child->GetRange().IsOutside(range)) { wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject); if (composite) @@ -3548,7 +3550,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) ClearUnusedLines(lineCount); // Apply styles to wrapped lines - ApplyParagraphStyle(attr, rect); + ApplyParagraphStyle(attr, rect, dc); SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceBeforePara + spaceAfterPara)); @@ -3600,7 +3602,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) } /// Apply paragraph styles, such as centering, to wrapped lines -void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect) +void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect, wxDC& dc) { if (!attr.HasAlignment()) return; @@ -3616,12 +3618,14 @@ void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRe // centering, right-justification if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE) { - pos.x = (rect.GetWidth() - size.x)/2 + pos.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = (rect.GetWidth() - (pos.x - rect.x) - rightIndent - size.x)/2 + pos.x; line->SetPosition(pos); } else if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) { - pos.x = pos.x + rect.GetWidth() - size.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = rect.x + rect.GetWidth() - size.x - rightIndent; line->SetPosition(pos); } @@ -4171,7 +4175,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text += textObj->GetTextForRange(range); } else - return true; + { + text += wxT(" "); + } } node = node->GetNext(); @@ -4191,7 +4197,9 @@ bool wxRichTextParagraph::GetContiguousPlainText(wxString& text, const wxRichTex text = textObj->GetTextForRange(range) + text; } else - return true; + { + text = wxT(" ") + text; + } } node = node->GetPrevious(); @@ -4222,7 +4230,7 @@ bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& d widthBefore = 0; size_t i; - for (i = (size_t) range.GetStart(); i < (size_t) range.GetEnd(); i++) + for (i = (size_t) range.GetStart(); i <= (size_t) range.GetEnd(); i++) { int widthFromStartOfThisRange = (*partialExtents)[i - GetRange().GetStart()] - widthBefore; @@ -5334,8 +5342,14 @@ bool wxRichTextBuffer::InsertNewlineWithUndo(long pos, wxRichTextCtrl* ctrl, int { if (para && para->GetRange().GetEnd() == pos) pos1 ++; + + // Now see if we need to number the paragraph. if (newPara->GetAttributes().HasBulletNumber()) - newPara->GetAttributes().SetBulletNumber(newPara->GetAttributes().GetBulletNumber()+1); + { + wxRichTextAttr numberingAttr; + if (FindNextParagraphNumber(para, numberingAttr)) + wxRichTextApplyStyle(newPara->GetAttributes(), (const wxRichTextAttr&) numberingAttr); + } } action->SetPosition(pos); @@ -5444,6 +5458,25 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio } } } + + // Also apply list style if present + if (lookUpNewParaStyle && !para->GetAttributes().GetListStyleName().IsEmpty() && GetStyleSheet()) + { + wxRichTextListStyleDefinition* listDef = GetStyleSheet()->FindListStyle(para->GetAttributes().GetListStyleName()); + if (listDef) + { + int thisIndent = para->GetAttributes().GetLeftIndent(); + int thisLevel = para->GetAttributes().HasOutlineLevel() ? para->GetAttributes().GetOutlineLevel() : listDef->FindLevelForIndent(thisIndent); + + // Apply the overall list style, and item style for this level + wxRichTextAttr listStyle(listDef->GetCombinedStyleForLevel(thisLevel, GetStyleSheet())); + wxRichTextApplyStyle(attr, listStyle); + attr.SetOutlineLevel(thisLevel); + if (para->GetAttributes().HasBulletNumber()) + attr.SetBulletNumber(para->GetAttributes().GetBulletNumber()); + } + } + if (!foundAttributes) { attr = para->GetAttributes(); @@ -5456,14 +5489,6 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio attr.SetFlags(flags); } - // Now see if we need to number the paragraph. - if (attr.HasBulletStyle()) - { - wxTextAttr numberingAttr; - if (FindNextParagraphNumber(para, numberingAttr)) - wxRichTextApplyStyle(attr, (const wxTextAttr&) numberingAttr); - } - return attr; } else @@ -6160,10 +6185,10 @@ bool wxRichTextBuffer::PasteFromClipboard(long position) if (action->GetNewParagraphs().GetChildCount() == 1) action->GetNewParagraphs().SetPartialParagraph(true); - action->SetPosition(position); + action->SetPosition(position+1); // Set the range we'll need to delete in Undo - action->SetRange(wxRichTextRange(position, position)); + action->SetRange(wxRichTextRange(position+1, position+1)); SubmitAction(action); @@ -7044,10 +7069,11 @@ bool wxRichTextImage::LoadFromBlock() /// Make block from the wxImage bool wxRichTextImage::MakeBlock() { - if (m_imageBlock.GetImageType() == wxBITMAP_TYPE_ANY || m_imageBlock.GetImageType() == -1) - m_imageBlock.SetImageType(wxBITMAP_TYPE_PNG); + wxBitmapType type = m_imageBlock.GetImageType(); + if ( type == wxBITMAP_TYPE_ANY || type == wxBITMAP_TYPE_INVALID ) + m_imageBlock.SetImageType(type = wxBITMAP_TYPE_PNG); - m_imageBlock.MakeImageBlock(m_image, m_imageBlock.GetImageType()); + m_imageBlock.MakeImageBlock(m_image, type); return m_imageBlock.Ok(); } @@ -7393,7 +7419,7 @@ bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, wxBitmapType wxString filenameToRead(filename); bool removeFile = false; - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type if ((imageType != wxBITMAP_TYPE_JPEG) && convertToJPEG) @@ -7435,7 +7461,7 @@ bool wxRichTextImageBlock::MakeImageBlock(wxImage& image, wxBitmapType imageType m_imageType = imageType; image.SetOption(wxT("quality"), quality); - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type wxString tempFile; @@ -7565,7 +7591,10 @@ bool wxRichTextImageBlock::ReadHex(wxInputStream& stream, int length, wxBitmapTy if (m_data) delete[] m_data; - wxChar str[2]; + // create a null terminated temporary string: + char str[3]; + str[2] = '\0'; + m_data = new unsigned char[dataSize]; int i; for (i = 0; i < dataSize; i ++)