// Assume this box only contains paragraphs
wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
- wxCHECK_MSG( child, false, wxT("Unknown object in layout") );
+ // Unsure if this is needed
+ // wxCHECK_MSG( child, false, wxT("Unknown object in layout") );
if (child && child->IsShown())
{
// Now top and tail the first and last paragraphs in our new fragment (which might be the same).
if (!fragment.IsEmpty())
{
- wxRichTextRange topTailRange(range);
-
wxRichTextParagraph* firstPara = wxDynamicCast(fragment.GetChildren().GetFirst()->GetData(), wxRichTextParagraph);
wxASSERT( firstPara != NULL );
+ wxRichTextParagraph* lastPara = wxDynamicCast(fragment.GetChildren().GetLast()->GetData(), wxRichTextParagraph);
+ wxASSERT( lastPara != NULL );
+
+ if (!firstPara || !lastPara)
+ return false;
+
+ bool isFragment = (range.GetEnd() < lastPara->GetRange().GetEnd());
+
+ long firstPos = firstPara->GetRange().GetStart();
+
+ // Adjust for renumbering from zero
+ wxRichTextRange topTailRange(range.GetStart() - firstPos, range.GetEnd() - firstPos);
+
+ long end;
+ fragment.CalculateRange(0, end);
+
// Chop off the start of the paragraph
- if (topTailRange.GetStart() > firstPara->GetRange().GetStart())
+ if (topTailRange.GetStart() > 0)
{
- wxRichTextRange r(firstPara->GetRange().GetStart(), topTailRange.GetStart()-1);
+ wxRichTextRange r(0, topTailRange.GetStart()-1);
firstPara->DeleteRange(r);
// Make sure the numbering is correct
- long end;
- fragment.CalculateRange(firstPara->GetRange().GetStart(), end);
+ fragment.CalculateRange(0, end);
// Now, we've deleted some positions, so adjust the range
// accordingly.
- topTailRange.SetEnd(topTailRange.GetEnd() - r.GetLength());
+ topTailRange.SetStart(range.GetLength());
+ topTailRange.SetEnd(fragment.GetOwnRange().GetEnd());
+ }
+ else
+ {
+ topTailRange.SetStart(range.GetLength());
+ topTailRange.SetEnd(fragment.GetOwnRange().GetEnd());
}
- wxRichTextParagraph* lastPara = wxDynamicCast(fragment.GetChildren().GetLast()->GetData(), wxRichTextParagraph);
- wxASSERT( lastPara != NULL );
-
- if (topTailRange.GetEnd() < (lastPara->GetRange().GetEnd()-1))
+ if (topTailRange.GetStart() < (lastPara->GetRange().GetEnd()-1))
{
- wxRichTextRange r(topTailRange.GetEnd()+1, lastPara->GetRange().GetEnd()-1); /* -1 since actual text ends 1 position before end of para marker */
- lastPara->DeleteRange(r);
+ lastPara->DeleteRange(topTailRange);
// Make sure the numbering is correct
long end;
- fragment.CalculateRange(firstPara->GetRange().GetStart(), end);
+ fragment.CalculateRange(0, end);
// We only have part of a paragraph at the end
fragment.SetPartialParagraph(true);
}
else
{
- if (topTailRange.GetEnd() == (lastPara->GetRange().GetEnd() - 1))
- // We have a partial paragraph (don't save last new paragraph marker)
- fragment.SetPartialParagraph(true);
- else
- // We have a complete paragraph
- fragment.SetPartialParagraph(false);
+ // We have a partial paragraph (don't save last new paragraph marker)
+ // or complete paragraph
+ fragment.SetPartialParagraph(isFragment);
}
}
int lineSpacing = 0;
// Let's assume line spacing of 10 is normal, 15 is 1.5, 20 is 2, etc.
- if (attr.HasLineSpacing() && attr.GetLineSpacing() > 0 && attr.GetFont().Ok())
+ if (attr.HasLineSpacing() && attr.GetLineSpacing() > 0 && attr.GetFont().IsOk())
{
wxCheckSetFont(dc, attr.GetFont());
lineSpacing = (int) (double(dc.GetCharHeight()) * (double(attr.GetLineSpacing())/10.0 - 1.0));
int paraDescent = 0;
// This calculates the partial text extents
- GetRangeSize(GetRange(), paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_CACHE_SIZE, wxPoint(0,0), & partialExtents);
+ GetRangeSize(GetRange(), paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_CACHE_SIZE, rect.GetPosition(), & partialExtents);
#else
node = m_children.GetFirst();
while (node)
int paraDescent;
// This calculates the partial text extents
- GetRangeSize(lineRange, paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED, wxPoint(0,0), & partialExtents);
+ GetRangeSize(lineRange, paraSize, paraDescent, dc, wxRICHTEXT_UNFORMATTED, linePos, & partialExtents);
int lastX = linePos.x;
size_t i;
int charHeight = dc.GetCharHeight();
int x, y;
- if ( textFont.Ok() )
+ if ( textFont.IsOk() )
{
if ( textAttr.HasTextEffects() && (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT) )
{
bool bScript(false);
wxFont font(GetBuffer()->GetFontTable().FindFont(textAttr));
- if (font.Ok())
+ if (font.IsOk())
{
if ( textAttr.HasTextEffects() && ( (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUPERSCRIPT)
|| (textAttr.GetTextEffects() & wxTEXT_ATTR_EFFECT_SUBSCRIPT) ) )
}
/// Submit command to insert paragraphs
-bool wxRichTextParagraphLayoutBox::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int flags)
+bool wxRichTextParagraphLayoutBox::InsertParagraphsWithUndo(long pos, const wxRichTextParagraphLayoutBox& paragraphs, wxRichTextCtrl* ctrl, wxRichTextBuffer* buffer, int WXUNUSED(flags))
{
wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, buffer, this, ctrl, false);
- wxRichTextAttr attr(buffer->GetDefaultStyle());
-
- wxRichTextAttr* p = NULL;
- wxRichTextAttr paraAttr;
- if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
- {
- paraAttr = GetStyleForNewParagraph(buffer, pos);
- if (!paraAttr.IsDefault())
- p = & paraAttr;
- }
- else
- p = & attr;
-
action->GetNewParagraphs() = paragraphs;
- if (p && !p->IsDefault())
- {
- for (wxRichTextObjectList::compatibility_iterator node = action->GetNewParagraphs().GetChildren().GetFirst(); node; node = node->GetNext())
- {
- wxRichTextObject* child = node->GetData();
- child->SetAttributes(*p);
- }
- }
-
action->SetPosition(pos);
wxRichTextRange range = wxRichTextRange(pos, pos + paragraphs.GetOwnRange().GetEnd() - 1);
{
wxRichTextStyleSheet* oldSheet = GetStyleSheet();
- wxWindowID id = wxID_ANY;
+ wxWindowID winid = wxID_ANY;
if (GetRichTextCtrl())
- id = GetRichTextCtrl()->GetId();
+ winid = GetRichTextCtrl()->GetId();
- wxRichTextEvent event(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, id);
+ wxRichTextEvent event(wxEVT_COMMAND_RICHTEXT_STYLESHEET_REPLACING, winid);
event.SetEventObject(GetRichTextCtrl());
event.SetContainer(GetRichTextCtrl()->GetFocusObject());
event.SetOldStyleSheet(oldSheet);
bool wxRichTextStdRenderer::DrawStandardBullet(wxRichTextParagraph* paragraph, wxDC& dc, const wxRichTextAttr& bulletAttr, const wxRect& rect)
{
- if (bulletAttr.GetTextColour().Ok())
+ if (bulletAttr.GetTextColour().IsOk())
{
wxCheckSetPen(dc, wxPen(bulletAttr.GetTextColour()));
wxCheckSetBrush(dc, wxBrush(bulletAttr.GetTextColour()));
wxCheckSetFont(dc, font);
- if (attr.GetTextColour().Ok())
+ if (attr.GetTextColour().IsOk())
dc.SetTextForeground(attr.GetTextColour());
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
wxRichTextCell* cell = GetCell(j, i);
if (cell->IsShown())
{
- wxASSERT(colWidths[i] > 0);
-
// Get max specified cell height
// Don't handle percentages for height
if (cell->GetAttributes().GetTextBoxAttr().GetHeight().IsValid() && cell->GetAttributes().GetTextBoxAttr().GetHeight().GetUnits() != wxTEXT_ATTR_UNITS_PERCENTAGE)
bool wxRichTextFileHandler::LoadFile(wxRichTextBuffer *buffer, const wxString& filename)
{
wxFFileInputStream stream(filename);
- if (stream.Ok())
+ if (stream.IsOk())
return LoadFile(buffer, stream);
return false;
bool wxRichTextFileHandler::SaveFile(wxRichTextBuffer *buffer, const wxString& filename)
{
wxFFileOutputStream stream(filename);
- if (stream.Ok())
+ if (stream.IsOk())
return SaveFile(buffer, stream);
return false;
// Write data in hex to a stream
bool wxRichTextImageBlock::WriteHex(wxOutputStream& stream)
{
- const int bufSize = 512;
- char buf[bufSize+1];
+ if (m_dataSize == 0)
+ return true;
+
+ int bufSize = 100000;
+ if (int(2*m_dataSize) < bufSize)
+ bufSize = 2*m_dataSize;
+ char* buf = new char[bufSize+1];
int left = m_dataSize;
int n, i, j;
buf[n] = 0;
stream.Write((const char*) buf, n);
}
+ delete[] buf;
return true;
}
unsigned char* wxRichTextImageBlock::ReadBlock(const wxString& filename, size_t size)
{
wxFileInputStream stream(filename);
- if (!stream.Ok())
+ if (!stream.IsOk())
return NULL;
return ReadBlock(stream, size);
bool wxRichTextImageBlock::WriteBlock(const wxString& filename, unsigned char* block, size_t size)
{
wxFileOutputStream outStream(filename);
- if (!outStream.Ok())
+ if (!outStream.IsOk())
return false;
return WriteBlock(outStream, block, size);