#pragma hdrstop
#endif
+#if wxUSE_RICHTEXT
+
+#include "wx/richtext/richtextbuffer.h"
+
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
-#include "wx/image.h"
-
-#if wxUSE_RICHTEXT
-
#include "wx/filename.h"
#include "wx/clipbrd.h"
+#include "wx/dataobj.h"
#include "wx/wfstream.h"
#include "wx/module.h"
#include "wx/mstream.h"
#include "wx/sstream.h"
-#include "wx/richtext/richtextbuffer.h"
#include "wx/richtext/richtextctrl.h"
#include "wx/richtext/richtextstyles.h"
wxRichTextObjectList::compatibility_iterator node = m_children.Find(child);
if (node)
{
+ wxRichTextObject* obj = node->GetData();
+ m_children.Erase(node);
if (deleteChild)
- delete node->GetData();
- delete node;
+ delete obj;
return true;
}
child->Dereference(); // Only delete if reference count is zero
node = node->GetNext();
- delete oldNode;
+ m_children.Erase(oldNode);
}
return true;
if (child->CanMerge(nextChild) && child->Merge(nextChild))
{
nextChild->Dereference();
- delete node->GetNext();
+ m_children.Erase(node->GetNext());
// Don't set node -- we'll see if we can merge again with the next
// child.
int maxWidth = 0;
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
-
+
bool layoutAll = true;
// Get invalid range, rounding to paragraph start/end.
if (firstParagraph)
{
wxRichTextObjectList::compatibility_iterator firstNode = m_children.Find(firstParagraph);
- wxRichTextObjectList::compatibility_iterator previousNode = firstNode ? firstNode->GetPrevious() : (wxRichTextObjectList::compatibility_iterator) NULL;
+ wxRichTextObjectList::compatibility_iterator previousNode = firstNode ? firstNode->GetPrevious() : wxRichTextObjectList::compatibility_iterator();
if (firstNode && previousNode)
{
wxRichTextParagraph* previousParagraph = wxDynamicCast(previousNode->GetData(), wxRichTextParagraph);
// A way to force speedy rest-of-buffer layout (the 'else' below)
bool forceQuickLayout = false;
-
+
while (node)
{
// Assume this box only contains paragraphs
{
wxSize sz;
- wxRichTextObjectList::compatibility_iterator startPara = NULL;
- wxRichTextObjectList::compatibility_iterator endPara = NULL;
+ wxRichTextObjectList::compatibility_iterator startPara = wxRichTextObjectList::compatibility_iterator();
+ wxRichTextObjectList::compatibility_iterator endPara = wxRichTextObjectList::compatibility_iterator();
// First find the first paragraph whose starting position is within the range.
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
}
wxRichTextObjectList::compatibility_iterator next1 = node1->GetNext();
- delete node1;
+ nextParagraph->GetChildren().Erase(node1);
node1 = next1;
}
{
// We'll be using a copy of the paragraph to make style changes,
// not updating the buffer directly.
- wxRichTextParagraph* newPara = NULL;
+ wxRichTextParagraph* newPara wxDUMMY_INITIALIZE(NULL);
if (haveControl && withUndo)
{
// we can start applying a different style.
// TODO: check that the style actually changes or is different
// from style outside of range
- wxRichTextObject* firstObject = NULL;
- wxRichTextObject* lastObject = NULL;
+ wxRichTextObject* firstObject wxDUMMY_INITIALIZE(NULL);
+ wxRichTextObject* lastObject wxDUMMY_INITIALIZE(NULL);
if (childRange.GetStart() == newPara->GetRange().GetStart())
firstObject = newPara->GetChildren().GetFirst()->GetData();
/// Get the text attributes for this position.
bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxTextAttrEx& style) const
{
- wxRichTextObject* obj = NULL;
+ wxRichTextObject* obj wxDUMMY_INITIALIZE(NULL);
if (style.IsParagraphStyle())
obj = GetParagraphAtPosition(position);
/// Get the text attributes for this position.
bool wxRichTextParagraphLayoutBox::GetStyle(long position, wxRichTextAttr& style) const
{
- wxRichTextObject* obj = NULL;
+ wxRichTextObject* obj wxDUMMY_INITIALIZE(NULL);
if (style.IsParagraphStyle())
obj = GetParagraphAtPosition(position);
void wxRichTextParagraphLayoutBox::Invalidate(const wxRichTextRange& invalidRange)
{
SetDirty(true);
-
+
if (invalidRange == wxRICHTEXT_ALL)
{
m_invalidRange = wxRICHTEXT_ALL;
// Already invalidating everything
if (m_invalidRange == wxRICHTEXT_ALL)
return;
-
+
if ((invalidRange.GetStart() < m_invalidRange.GetStart()) || m_invalidRange.GetStart() == -1)
m_invalidRange.SetStart(invalidRange.GetStart());
if (invalidRange.GetEnd() > m_invalidRange.GetEnd())
{
if (m_invalidRange == wxRICHTEXT_ALL || m_invalidRange == wxRICHTEXT_NONE)
return m_invalidRange;
-
+
wxRichTextRange range = m_invalidRange;
-
+
if (wholeParagraphs)
{
wxRichTextParagraph* para1 = GetParagraphAtPosition(range.GetStart());
wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL;
wxPoint linePos;
- int lineHeight = 0;
+ int lineHeight wxDUMMY_INITIALIZE(0);
if (line)
{
lineHeight = line->GetSize().y;
// Add a new line
wxRichTextLine* line = AllocateLine(lineCount);
-
+
// Set relative range so we won't have to change line ranges when paragraphs are moved
line->SetRange(wxRichTextRange(actualRange.GetStart() - GetRange().GetStart(), actualRange.GetEnd() - GetRange().GetStart()));
line->SetPosition(currentPosition);
bool wxRichTextParagraph::InsertText(long pos, const wxString& text)
{
wxRichTextObject* childToUse = NULL;
- wxRichTextObjectList::compatibility_iterator nodeToUse = NULL;
+ wxRichTextObjectList::compatibility_iterator nodeToUse = wxRichTextObjectList::compatibility_iterator();
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
while (node)
/// Add content back from list
void wxRichTextParagraph::MoveFromList(wxList& list)
{
- for (wxNode* node = list.GetFirst(); node; node = node->GetNext())
+ for (wxList::compatibility_iterator node = list.GetFirst(); node; node = node->GetNext())
{
AppendChild((wxRichTextObject*) node->GetData());
}
return false;
}
- wxNode* node = m_attributeStack.GetLast();
+ wxList::compatibility_iterator node = m_attributeStack.GetLast();
wxTextAttrEx* attr = (wxTextAttrEx*)node->GetData();
- delete node;
+ m_attributeStack.Erase(node);
SetDefaultStyle(*attr);
/// Clear the style stack
void wxRichTextBuffer::ClearStyleStack()
{
- for (wxNode* node = m_attributeStack.GetFirst(); node; node = node->GetNext())
+ for (wxList::compatibility_iterator node = m_attributeStack.GetFirst(); node; node = node->GetNext())
delete (wxTextAttrEx*) node->GetData();
m_attributeStack.Clear();
}
bool wxRichTextBuffer::CopyToClipboard(const wxRichTextRange& range)
{
bool success = false;
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
wxString text = GetTextForRange(range);
- if (wxTheClipboard->Open())
+ if (!wxTheClipboard->IsOpened() && wxTheClipboard->Open())
{
success = wxTheClipboard->SetData(new wxTextDataObject(text));
wxTheClipboard->Close();
}
+#else
+ wxUnusedVar(range);
+#endif
return success;
}
bool wxRichTextBuffer::PasteFromClipboard(long position)
{
bool success = false;
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
if (CanPasteFromClipboard())
{
if (wxTheClipboard->Open())
wxTheClipboard->Close();
}
}
+#else
+ wxUnusedVar(position);
+#endif
return success;
}
bool wxRichTextBuffer::CanPasteFromClipboard() const
{
bool canPaste = false;
- if (wxTheClipboard->Open())
+#if wxUSE_CLIPBOARD && wxUSE_DATAOBJ
+ if (!wxTheClipboard->IsOpened() && wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported(wxDF_TEXT) || wxTheClipboard->IsSupported(wxDF_BITMAP))
{
}
wxTheClipboard->Close();
}
+#endif
return canPaste;
}
bool wxRichTextCommand::Do()
{
- for (wxNode* node = m_actions.GetFirst(); node; node = node->GetNext())
+ for (wxList::compatibility_iterator node = m_actions.GetFirst(); node; node = node->GetNext())
{
wxRichTextAction* action = (wxRichTextAction*) node->GetData();
action->Do();
bool wxRichTextCommand::Undo()
{
- for (wxNode* node = m_actions.GetLast(); node; node = node->GetPrevious())
+ for (wxList::compatibility_iterator node = m_actions.GetLast(); node; node = node->GetPrevious())
{
wxRichTextAction* action = (wxRichTextAction*) node->GetData();
action->Undo();
m_ctrl->SetCaretPosition(caretPosition);
if (!m_ctrl->IsFrozen())
{
- m_ctrl->Layout();
+ m_ctrl->LayoutContent();
m_ctrl->PositionCaret();
- m_ctrl->Refresh();
+ m_ctrl->Refresh(false);
if (sendUpdateEvent)
m_ctrl->SendUpdateEvent();
wxFont wxRichTextAttr::CreateFont() const
{
wxFont font(m_fontSize, wxDEFAULT, m_fontStyle, m_fontWeight, m_fontUnderlined, m_fontFaceName);
+#ifdef __WXMAC__
+ font.SetNoAntiAliasing(true);
+#endif
return font;
}
{
if (ch == 10 && lastCh != 13)
str += wxT('\n');
-
+
if (ch > 0 && ch != 10)
str += wxChar(ch);
-
+
lastCh = ch;
}
}
void wxRichTextImageBlock::Clear()
{
- if (m_data)
- delete m_data;
+ delete[] m_data;
m_data = NULL;
m_dataSize = 0;
m_imageType = -1;
#endif
// wxUSE_RICHTEXT
-