/////////////////////////////////////////////////////////////////////////////
-// Name: richtextbuffer.h
+// Name: wx/richtext/richtextbuffer.h
// Purpose: Buffer for wxRichTextCtrl
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
it can report a partial size, so that wrapping can be implemented,
hit test calculations performed, etc. So GetRangeSize must be implemented
for each object.
-
+
*/
#ifndef _WX_RICHTEXTBUFFER_H_
/// Lay the item out at the specified position with the given size constraint.
/// Layout must set the cached size.
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style) = 0;
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style) = 0;
/// Hit-testing: returns a flag indicating hit test details, plus
/// information about position
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual wxRichTextObject* GetLeafObjectAtPosition(long position) const;
/// Get the paragraph by number
- virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
+ virtual wxRichTextParagraph* GetParagraphAtLine(long paragraphNumber) const;
/// Get the paragraph for a given line
- virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
+ virtual wxRichTextParagraph* GetParagraphForLine(wxRichTextLine* line) const;
/// Get the length of the paragraph
virtual int GetParagraphLength(long paragraphNumber) const;
/// Copy
void Copy(const wxRichTextParagraphLayoutBox& obj);
- /// Clone
- virtual wxRichTextObject* Clone() { return new wxRichTextParagraphLayoutBox(*this); }
-
/// Calculate ranges
virtual void UpdateRanges() { long end; CalculateRange(0, end); }
void Copy(const wxRichTextFragment& obj);
/// Clone
- virtual wxRichTextObject* Clone() { return new wxRichTextFragment(*this); }
+ virtual wxRichTextObject* Clone() const { return new wxRichTextFragment(*this); }
protected:
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
/// Get/set the object size for the given range. Returns false if the range
/// is invalid for this object.
virtual bool DeleteRange(const wxRichTextRange& range);
/// Returns true if the object is empty
- virtual bool IsEmpty() const { return m_text.IsEmpty(); }
+ virtual bool IsEmpty() const { return m_text.empty(); }
/// Returns true if this object can merge itself with the given one.
virtual bool CanMerge(wxRichTextObject* object) const;
// to conserve space.
// If it's not a JPEG we can make use of 'image', already scaled, so we don't have to
// load the image a 2nd time.
- virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = TRUE);
+ virtual bool MakeImageBlock(const wxString& filename, int imageType, wxImage& image, bool convertToJPEG = true);
// Make an image block from the wxImage in the given
// format.
virtual bool Draw(wxDC& dc, const wxRichTextRange& range, const wxRichTextRange& selectionRange, const wxRect& rect, int descent, int style);
/// Lay the item out
- virtual bool Layout(wxDC& dc, const wxRect& rect, int style);
+ virtual bool Layout(wxDC& dc, const wxRect& rect, const wxRichTextRange& affected, int style);
/// Get the object size for the given range. Returns false if the range
/// is invalid for this object.
public:
// Ctor for one action
wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
- wxRichTextCtrl* ctrl, bool ignoreFirstTime = FALSE);
+ wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
// Ctor for multiple actions
wxRichTextCommand(const wxString& name);
{
public:
wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
- wxRichTextCtrl* ctrl, bool ignoreFirstTime = FALSE);
+ wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
~wxRichTextAction();
{ }
#if wxUSE_STREAMS
- virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0;
- virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0;
+ bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
+ { return DoLoadFile(buffer, stream); }
+ bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
+ { return DoSaveFile(buffer, stream); }
#endif
- virtual bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
- virtual bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
+ bool LoadFile(wxRichTextBuffer *buffer, const wxString& filename);
+ bool SaveFile(wxRichTextBuffer *buffer, const wxString& filename);
/// Can we handle this filename (if using files)? By default, checks the extension.
virtual bool CanHandle(const wxString& filename) const;
protected:
+#if wxUSE_STREAMS
+ virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream) = 0;
+ virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) = 0;
+#endif
+
wxString m_name;
wxString m_extension;
int m_type;
: wxRichTextFileHandler(name, ext, type)
{ }
-#if wxUSE_STREAMS
- virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
- virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
-#endif
-
/// Can we save using this handler?
virtual bool CanSave() const { return true; }
protected:
+#if wxUSE_STREAMS
+ virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
+ virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
+#endif
+
};
/*!
#endif
// _WX_RICHTEXTBUFFER_H_
-
/////////////////////////////////////////////////////////////////////////////
-// Name: richtextctrl.h
+// Name: wx/richtext/richtextctrl.h
// Purpose: A rich edit control
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
#else
public wxScrolledWindow
#endif
-{
+{
DECLARE_CLASS( wxRichTextCtrl )
DECLARE_EVENT_TABLE()
// Show a context menu for Rich Edit controls (the standard
// EDIT control has one already)
void OnContextMenu(wxContextMenuEvent& event);
-
+
// Event handlers
/// Painting
/// Paint the background
virtual void PaintBackground(wxDC& dc);
-
+
/// Recreate buffer bitmap if necessary
virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
// Data members
private:
- /// Allows nested Freeze/Thaw
+ /// Allows nested Freeze/Thaw
int m_freezeCount;
/// Buffer bitmap
/////////////////////////////////////////////////////////////////////////////
-// Name: richeditxml.h
+// Name: wx/richtext/richeditxml.h
// Purpose: XML and HTML I/O for wxRichTextCtrl
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
{ }
#if wxUSE_STREAMS
- virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
- virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
+ virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
+ virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
/// Recursively export an object
bool ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int level);
{ }
#if wxUSE_STREAMS
- virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
- virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
+ virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
+ virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
#endif
/// Can we save using this handler?
/////////////////////////////////////////////////////////////////////////////
-// Name: richtextbuffer.cpp
+// Name: richtext/richtextbuffer.cpp
// Purpose: Buffer for wxRichTextCtrl
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
bool wxRichTextCompositeObject::DeleteRange(const wxRichTextRange& range)
{
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
-
+
while (node)
{
wxRichTextObject* obj = (wxRichTextObject*) node->GetData();
wxRichTextObjectList::compatibility_iterator next = node->GetNext();
-
+
// Delete the range in each paragraph
// When a chunk has been deleted, internally the content does not
// If you may delete content from the same object twice, recalculate
// the ranges inbetween DeleteRange calls by calling CalculateRanges, and
// adjust the range you're deleting accordingly.
-
+
if (!obj->GetRange().IsOutside(range))
{
obj->DeleteRange(range);
{
// An empty paragraph has length 1, so won't be deleted unless the
// whole range is deleted.
- RemoveChild(obj, true);
+ RemoveChild(obj, true);
}
}
-
+
node = next;
}
-
+
return true;
}
if (!child->GetRange().IsOutside(range))
{
childRange.LimitTo(child->GetRange());
-
+
wxString childText = child->GetTextForRange(childRange);
-
+
text += childText;
}
node = node->GetNext();
{
wxRichTextObject* child = node->GetData();
wxRichTextCompositeObject* composite = wxDynamicCast(child, wxRichTextCompositeObject);
- if (composite)
+ if (composite)
composite->Defragment();
if (node->GetNext())
{
wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
wxASSERT (child != NULL);
-
+
if (child && !child->GetRange().IsOutside(range))
{
wxRect childRect(child->GetPosition(), child->GetCachedSize());
-
+
if (childRect.GetTop() > rect.GetBottom() || childRect.GetBottom() < rect.GetTop())
{
// Skip
rect.height - m_topMargin - m_bottomMargin);
int maxWidth = 0;
-
+
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
-
+
// If we know what range is affected, start laying out from that point on.
if (affected.GetStart() > GetRange().GetStart())
{
{
wxRichTextParagraph* previousParagraph = wxDynamicCast(previousNode->GetData(), wxRichTextParagraph);
availableSpace.y = previousParagraph->GetPosition().y + previousParagraph->GetCachedSize().y;
-
+
// Now we're going to start iterating from the first affected paragraph.
node = firstNode;
}
wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
wxASSERT (child != NULL);
-
+
if (child && !child->GetRange().IsOutside(affected))
{
child->Layout(dc, availableSpace, affected, style);
// move everything up or down. This assumes that all the children have previously
// been laid out and have wrapped line lists associated with them.
// TODO: check all paragraphs before the affected range.
-
+
int inc = availableSpace.y - child->GetPosition().y;
-
+
while (node)
{
wxRichTextParagraph* child = wxDynamicCast(node->GetData(), wxRichTextParagraph);
child->Layout(dc, availableSpace, affected, style);
else
child->SetPosition(wxPoint(child->GetPosition().x, child->GetPosition().y + inc));
-
+
availableSpace.y += child->GetCachedSize().y;
maxWidth = wxMax(maxWidth, child->GetCachedSize().x);
}
-
- node = node->GetNext();
+
+ node = node->GetNext();
}
break;
}
return line;
node2 = node2->GetNext();
- }
+ }
node = node->GetNext();
}
return line;
node2 = node2->GetNext();
- }
+ }
node = node->GetNext();
}
i ++;
}
- if (!line.IsEmpty())
+ if (!line.empty())
{
lastPara = new wxRichTextParagraph(line, this, & style);
//wxLogDebug("Para Face = %s", lastPara->GetAttributes().GetFont().GetFaceName());
while (objectNode)
{
wxRichTextObject* newObj = objectNode->GetData()->Clone();
-
+
if (!nextObject)
{
// Append
// Insert before nextObject
para->InsertChild(newObj, nextObject);
}
-
+
objectNode = objectNode->GetNext();
}
while (objectNode)
{
wxRichTextObject* newObj = objectNode->GetData()->Clone();
-
+
// Append
para->AppendChild(newObj);
-
+
objectNode = objectNode->GetNext();
}
if (nextParagraph)
InsertChild(finalPara, nextParagraph);
else
- AppendChild(finalPara);
+ AppendChild(finalPara);
}
else while (i)
{
InsertChild(finalPara, nextParagraph);
else
AppendChild(finalPara);
-
+
i = i->GetNext();
}
// Ensure there's at least one object
if (finalPara->GetChildCount() == 0)
{
- wxRichTextPlainText* text = new wxRichTextPlainText(wxT(""));
+ wxRichTextPlainText* text = new wxRichTextPlainText(wxEmptyString);
text->SetAttributes(finalPara->GetAttributes());
finalPara->AppendChild(text);
{
wxRichTextParagraph* para = wxDynamicCast(i->GetData(), wxRichTextParagraph);
wxASSERT( para != NULL );
-
+
AppendChild(para->Clone());
-
+
i = i->GetNext();
}
if (!para->GetRange().IsOutside(range))
{
fragment.AppendChild(para->Clone());
- }
+ }
i = i->GetNext();
}
while (node2)
{
wxRichTextLine* line = node2->GetData();
-
+
if (line->GetRange().Contains(pos))
{
// If the caret is displayed at the end of the previous wrapped line,
}
lineCount ++;
-
+
node2 = node2->GetNext();
}
// If we didn't find it in the lines, it must be
while (node2)
{
wxRichTextLine* line = node2->GetData();
-
+
if (lineCount == lineNumber)
return line;
lineCount ++;
-
+
node2 = node2->GetNext();
- }
+ }
}
else
lineCount += child->GetLines().GetCount();
bool wxRichTextParagraphLayoutBox::DeleteRange(const wxRichTextRange& range)
{
wxRichTextObjectList::compatibility_iterator node = m_children.GetFirst();
-
+
while (node)
{
wxRichTextParagraph* obj = wxDynamicCast(node->GetData(), wxRichTextParagraph);
wxASSERT (obj != NULL);
wxRichTextObjectList::compatibility_iterator next = node->GetNext();
-
+
// Delete the range in each paragraph
if (!obj->GetRange().IsOutside(range))
RemoveChild(nextParagraph, true);
}
- }
+ }
}
}
-
+
node = next;
}
-
+
return true;
}
text += wxT("\n");
wxRichTextRange childRange = range;
childRange.LimitTo(child->GetRange());
-
+
wxString childText = child->GetTextForRange(childRange);
-
+
text += childText;
lineCount ++;
if (para)
{
wxRichTextObjectList::compatibility_iterator node = para->GetChildren().GetFirst();
-
+
while (node)
{
wxRichTextObject* child = node->GetData();
if (child->GetRange().Contains(position))
return child;
-
+
node = node->GetNext();
}
if (position == para->GetRange().GetEnd() && para->GetChildCount() > 0)
bool haveControl = (GetRichTextCtrl() != NULL);
wxRichTextAction* action = NULL;
-
+
if (haveControl && withUndo)
{
action = new wxRichTextAction(NULL, _("Change Style"), wxRICHTEXT_CHANGE_STYLE, & GetRichTextCtrl()->GetBuffer(), GetRichTextCtrl());
// We'll be using a copy of the paragraph to make style changes,
// not updating the buffer directly.
wxRichTextParagraph* newPara = NULL;
-
+
if (haveControl && withUndo)
{
newPara = new wxRichTextParagraph(*para);
{
wxRichTextRange childRange(range);
childRange.LimitTo(newPara->GetRange());
-
+
// Find the starting position and if necessary split it so
// 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;
-
+
if (childRange.GetStart() == newPara->GetRange().GetStart())
firstObject = newPara->GetChildren().GetFirst()->GetData();
else
firstObject = newPara->SplitAt(range.GetStart());
-
+
// Increment by 1 because we're apply the style one _after_ the split point
long splitPoint = childRange.GetEnd();
if (splitPoint != newPara->GetRange().GetEnd())
splitPoint ++;
-
+
// Find last object
if (splitPoint == newPara->GetRange().GetEnd() || splitPoint == (newPara->GetRange().GetEnd() - 1))
lastObject = newPara->GetChildren().GetLast()->GetData();
// lastObject is set as a side-effect of splitting. It's
// returned as the object before the new object.
(void) newPara->SplitAt(splitPoint, & lastObject);
-
+
wxASSERT(firstObject != NULL);
wxASSERT(lastObject != NULL);
-
+
if (!firstObject || !lastObject)
continue;
-
+
wxRichTextObjectList::compatibility_iterator firstNode = newPara->GetChildren().Find(firstObject);
wxRichTextObjectList::compatibility_iterator lastNode = newPara->GetChildren().Find(lastObject);
-
+
wxASSERT(firstNode != NULL);
wxASSERT(lastNode != NULL);
-
+
wxRichTextObjectList::compatibility_iterator node2 = firstNode;
-
+
while (node2)
{
wxRichTextObject* child = node2->GetData();
-
+
wxRichTextApplyStyle(child->GetAttributes(), style);
if (node2 == lastNode)
break;
-
+
node2 = node2->GetNext();
}
}
{
Clear();
- AddParagraph(wxT(""));
+ AddParagraph(wxEmptyString);
}
/*!
else
{
wxString bulletText = GetBulletText();
- if (!bulletText.IsEmpty())
+ if (!bulletText.empty())
{
if (GetAttributes().GetFont().Ok())
dc.SetFont(GetAttributes().GetFont());
-
+
if (GetAttributes().GetTextColour().Ok())
dc.SetTextForeground(GetAttributes().GetTextColour());
-
+
dc.SetBackgroundMode(wxTRANSPARENT);
-
+
// Get line height from first line, if any
wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL;
-
+
wxPoint linePos;
int lineHeight = 0;
if (line)
linePos = GetPosition();
linePos.y += spaceBeforePara;
}
-
+
int charHeight = dc.GetCharHeight();
-
+
int x = GetPosition().x + leftIndent;
int y = linePos.y + (lineHeight - charHeight);
-
+
dc.DrawText(bulletText, x, y);
}
}
}
}
-
+
// Draw the range for each line, one object at a time.
wxRichTextLineList::compatibility_iterator node = m_cachedLines.GetFirst();
}
node = node->GetNext();
- }
+ }
return true;
}
wrapPosition = wxMax(lastCompletedEndPos+1,child->GetRange().GetEnd());
// wxLogDebug(wxT("Split at %ld"), wrapPosition);
-
+
// Let's find the actual size of the current line now
wxSize actualSize;
wxRichTextRange actualRange(lastCompletedEndPos+1, wrapPosition);
currentWidth = actualSize.x;
lineHeight = wxMax(lineHeight, actualSize.y);
maxDescent = wxMax(childDescent, maxDescent);
-
+
// Add a new line
- wxRichTextLine* line = new wxRichTextLine(this);
+ wxRichTextLine* line = new wxRichTextLine(this);
line->SetRange(actualRange);
line->SetPosition(currentPosition);
line->SetSize(wxSize(currentWidth, lineHeight));
line->SetDescent(maxDescent);
m_cachedLines.Append(line);
-
+
// Now move down a line. TODO: add margins, spacing
currentPosition.y += lineHeight;
currentPosition.y += lineSpacing;
currentWidth = 0;
maxDescent = 0;
- maxWidth = wxMax(maxWidth, currentWidth);
-
+ maxWidth = wxMax(maxWidth, currentWidth);
+
lineCount ++;
// TODO: account for zero-length objects, such as fields
wxASSERT(wrapPosition > lastCompletedEndPos);
-
+
lastEndPos = wrapPosition;
lastCompletedEndPos = lastEndPos;
currentPosition.x = (lineCount == 0 ? startPositionFirstLine : startPositionSubsequentLines);
wxRichTextLine* line = new wxRichTextLine(this);
-
+
line->SetRange(lastCompletedEndPos+1, GetRange().GetEnd()-1);
line->SetPosition(currentPosition);
currentPosition.y += lineHeight;
currentPosition.y += lineSpacing;
lineCount ++;
-
+
m_cachedLines.Append(line);
}
wxRichTextObject* child = node->GetData();
child->SetRange(wxRichTextRange(textObject->GetRange().GetStart() + textLength,
textObject->GetRange().GetEnd() + textLength));
-
+
node = node->GetNext();
}
if (!child->GetRange().IsOutside(range))
{
wxSize childSize;
-
+
wxRichTextRange rangeToUse = range;
rangeToUse.LimitTo(child->GetRange());
int childDescent = 0;
-
+
if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags))
{
sz.y = wxMax(sz.y, childSize.y);
if (!line->GetRange().IsOutside(range))
{
wxSize lineSize;
-
+
wxRichTextObjectList::compatibility_iterator node2 = m_children.GetFirst();
while (node2)
{
wxRichTextObject* child = node2->GetData();
-
+
if (!child->GetRange().IsOutside(line->GetRange()))
{
wxRichTextRange rangeToUse = line->GetRange();
rangeToUse.LimitTo(child->GetRange());
-
+
wxSize childSize;
int childDescent = 0;
if (child->GetRangeSize(rangeToUse, childSize, childDescent, dc, flags))
}
descent = wxMax(descent, childDescent);
}
-
+
node2 = node2->GetNext();
}
{
wxSize childSize;
int descent = 0;
-
+
wxRichTextRange rangeToUse(line->GetRange().GetStart(), i);
-
+
GetRangeSize(rangeToUse, childSize, descent, dc, wxRICHTEXT_UNFORMATTED);
int nextX = childSize.x + linePos.x;
}
}
}
-
+
node = node->GetNext();
}
wxRichTextObject* obj = node->GetData();
if (obj->GetRange().Contains(position))
return obj;
-
+
node = node->GetNext();
}
return NULL;
// Let's draw unselected chunk, selected chunk, then unselected chunk.
dc.SetBackgroundMode(wxTRANSPARENT);
-
+
// 1. Initial unselected chunk, if any, up until start of selection.
if (selectionRange.GetStart() > range.GetStart() && selectionRange.GetStart() <= range.GetEnd())
{
dc.SetTextForeground(GetAttributes().GetTextColour());
dc.DrawText(stringFragment, x, y);
- }
+ }
}
return true;
bool wxRichTextPlainText::CanMerge(wxRichTextObject* object) const
{
return object->GetClassInfo() == CLASSINFO(wxRichTextPlainText) &&
- (m_text.IsEmpty() || wxTextAttrEq(GetAttributes(), object->GetAttributes()));
+ (m_text.empty() || wxTextAttrEq(GetAttributes(), object->GetAttributes()));
}
/// Returns true if this object merged itself with the given one.
void wxRichTextBuffer::Reset()
{
DeleteChildren();
- AddParagraph(wxT(""));
+ AddParagraph(wxEmptyString);
GetCommandProcessor()->ClearCommands();
Modify(false);
}
// Set the range we'll need to delete in Undo
action->SetRange(wxRichTextRange(pos, pos + text.Length() - 1));
-
+
SubmitAction(action);
-
+
return true;
}
wxTextAttrEx attr(GetBasicStyle());
wxRichTextApplyStyle(attr, GetDefaultStyle());
-
- wxRichTextParagraph* newPara = new wxRichTextParagraph(wxT(""), this, & attr);
+
+ wxRichTextParagraph* newPara = new wxRichTextParagraph(wxEmptyString, this, & attr);
action->GetNewParagraphs().AppendChild(newPara);
action->GetNewParagraphs().UpdateRanges();
action->GetNewParagraphs().SetPartialParagraph(false);
// Set the range we'll need to delete in Undo
action->SetRange(wxRichTextRange(pos, pos));
-
+
SubmitAction(action);
-
+
return true;
}
wxTextAttrEx attr(GetBasicStyle());
wxRichTextApplyStyle(attr, GetDefaultStyle());
-
+
wxRichTextParagraph* newPara = new wxRichTextParagraph(this, & attr);
wxRichTextImage* imageObject = new wxRichTextImage(imageBlock, newPara);
newPara->AppendChild(imageObject);
// Set the range we'll need to delete in Undo
action->SetRange(wxRichTextRange(pos, pos));
-
+
SubmitAction(action);
-
+
return true;
}
bool wxRichTextBuffer::DeleteRangeWithUndo(const wxRichTextRange& range, long initialCaretPosition, long WXUNUSED(newCaretPositon), wxRichTextCtrl* ctrl)
{
wxRichTextAction* action = new wxRichTextAction(NULL, _("Delete"), wxRICHTEXT_DELETE, this, ctrl);
-
+
action->SetPosition(initialCaretPosition);
// Set the range to delete
action->SetRange(range);
-
+
// Copy the fragment that we'll need to restore in Undo
CopyFragment(range, action->GetOldParagraphs());
}
SubmitAction(action);
-
+
return true;
}
m_batchedCommand = new wxRichTextCommand(cmdName);
}
- m_batchedCommandDepth ++;
+ m_batchedCommandDepth ++;
return true;
}
/// Begin suppressing undo/redo commands.
bool wxRichTextBuffer::BeginSuppressUndo()
{
- m_suppressUndo ++;
+ m_suppressUndo ++;
return true;
}
/// End suppressing undo/redo commands.
bool wxRichTextBuffer::EndSuppressUndo()
{
- m_suppressUndo --;
+ m_suppressUndo --;
return true;
}
wxTextAttrEx attr;
attr.SetFont(font,wxTEXT_ATTR_FONT_WEIGHT);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFont(font, wxTEXT_ATTR_FONT_ITALIC);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFont(font, wxTEXT_ATTR_FONT_UNDERLINE);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFont(font, wxTEXT_ATTR_FONT_SIZE);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_FONT);
attr.SetFont(font);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_TEXT_COLOUR);
attr.SetTextColour(colour);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_ALIGNMENT);
attr.SetAlignment(alignment);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_LEFT_INDENT);
attr.SetLeftIndent(leftIndent, leftSubIndent);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_RIGHT_INDENT);
attr.SetRightIndent(rightIndent);
-
+
return BeginStyle(attr);
}
attr.SetFlags(flags);
attr.SetParagraphSpacingBefore(before);
attr.SetParagraphSpacingAfter(after);
-
+
return BeginStyle(attr);
}
wxTextAttrEx attr;
attr.SetFlags(wxTEXT_ATTR_LINE_SPACING);
attr.SetLineSpacing(lineSpacing);
-
+
return BeginStyle(attr);
}
attr.SetBulletStyle(bulletStyle);
attr.SetBulletNumber(bulletNumber);
attr.SetLeftIndent(leftIndent, leftSubIndent);
-
+
return BeginStyle(attr);
}
attr.SetBulletStyle(bulletStyle);
attr.SetLeftIndent(leftIndent, leftSubIndent);
attr.SetBulletSymbol(symbol);
-
+
return BeginStyle(attr);
}
bool success = false;
wxString text = GetTextForRange(range);
if (wxTheClipboard->Open())
- {
+ {
success = wxTheClipboard->SetData(new wxTextDataObject(text));
wxTheClipboard->Close();
}
wxString text(data.GetText());
InsertTextWithUndo(position+1, text, GetRichTextCtrl());
-
+
success = true;
}
else if (wxTheClipboard->IsSupported(wxDF_BITMAP))
wxImage image(bitmap.ConvertToImage());
wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Image"), wxRICHTEXT_INSERT, this, GetRichTextCtrl(), false);
-
+
action->GetNewParagraphs().AddImage(image);
if (action->GetNewParagraphs().GetChildCount() == 1)
action->GetNewParagraphs().SetPartialParagraph(true);
-
+
action->SetPosition(position);
-
+
// Set the range we'll need to delete in Undo
action->SetRange(wxRichTextRange(position, position));
-
+
SubmitAction(action);
success = true;
/// Can we paste from the clipboard?
bool wxRichTextBuffer::CanPasteFromClipboard() const
{
- bool canPaste = FALSE;
+ bool canPaste = false;
if (wxTheClipboard->Open())
{
if (wxTheClipboard->IsSupported(wxDF_TEXT) || wxTheClipboard->IsSupported(wxDF_BITMAP))
{
- canPaste = TRUE;
+ canPaste = true;
}
wxTheClipboard->Close();
}
*/
wxRichTextCommand::wxRichTextCommand(const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
- wxRichTextCtrl* ctrl, bool ignoreFirstTime): wxCommand(TRUE, name)
+ wxRichTextCtrl* ctrl, bool ignoreFirstTime): wxCommand(true, name)
{
/* wxRichTextAction* action = */ new wxRichTextAction(this, name, id, buffer, ctrl, ignoreFirstTime);
}
-wxRichTextCommand::wxRichTextCommand(const wxString& name): wxCommand(TRUE, name)
+wxRichTextCommand::wxRichTextCommand(const wxString& name): wxCommand(true, name)
{
}
if (sendUpdateEvent)
m_ctrl->SendUpdateEvent();
}
- }
+ }
}
/// Replace the buffer paragraphs with the new ones.
bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style)
{
-
+
// Whole font. Avoiding setting individual attributes if possible, since
// it recreates the font each time.
if ((style.GetFlags() & (wxTEXT_ATTR_FONT)) == (wxTEXT_ATTR_FONT))
if (style.GetFlags() & wxTEXT_ATTR_FONT_FACE)
font.SetFaceName(style.GetFontFaceName());
-
+
if (style.GetFlags() & wxTEXT_ATTR_FONT_SIZE)
font.SetPointSize(style.GetFontSize());
-
+
if (style.GetFlags() & wxTEXT_ATTR_FONT_ITALIC)
font.SetStyle(style.GetFontStyle());
-
+
if (style.GetFlags() & wxTEXT_ATTR_FONT_WEIGHT)
font.SetWeight(style.GetFontWeight());
-
+
if (style.GetFlags() & wxTEXT_ATTR_FONT_UNDERLINE)
font.SetUnderlined(style.GetFontUnderlined());
IMPLEMENT_CLASS(wxRichTextFileHandler, wxObject)
+#if wxUSE_STREAMS
bool wxRichTextFileHandler::LoadFile(wxRichTextBuffer *buffer, const wxString& filename)
{
wxFFileInputStream stream(filename);
else
return false;
}
+#endif // wxUSE_STREAMS
/// Can we handle this filename (if using files)? By default, checks the extension.
bool wxRichTextFileHandler::CanHandle(const wxString& filename) const
IMPLEMENT_CLASS(wxRichTextPlainTextHandler, wxRichTextFileHandler)
#if wxUSE_STREAMS
-bool wxRichTextPlainTextHandler::LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
+bool wxRichTextPlainTextHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
{
if (!stream.IsOk())
return false;
ch = stream.GetC();
if (ch > 0)
- str += ch;
+ str += wxChar(ch);
}
buffer->Clear();
}
-bool wxRichTextPlainTextHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
+bool wxRichTextPlainTextHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
{
if (!stream.IsOk())
return false;
stream.Write((const char*) buf, text.Length());
return true;
}
-
-#endif
+#endif // wxUSE_STREAMS
/*
* Stores information about an image, in binary in-memory form
m_imageType = imageType;
wxString filenameToRead(filename);
- bool removeFile = FALSE;
+ bool removeFile = false;
if (imageType == -1)
- return FALSE; // Could not determine image type
+ return false; // Could not determine image type
if ((imageType != wxBITMAP_TYPE_JPEG) && convertToJPEG)
{
image.SaveFile(tempFile, wxBITMAP_TYPE_JPEG);
filenameToRead = tempFile;
- removeFile = TRUE;
+ removeFile = true;
m_imageType = wxBITMAP_TYPE_JPEG;
}
wxFile file;
if (!file.Open(filenameToRead))
- return FALSE;
+ return false;
m_dataSize = (size_t) file.Length();
file.Close();
image.SetOption(wxT("quality"), quality);
if (imageType == -1)
- return FALSE; // Could not determine image type
+ return false; // Could not determine image type
wxString tempFile;
bool success = wxGetTempFileName(_("image"), tempFile) ;
-
+
wxASSERT(success);
wxUnusedVar(success);
-
+
if (!image.SaveFile(tempFile, m_imageType))
{
if (wxFileExists(tempFile))
wxRemoveFile(tempFile);
- return FALSE;
+ return false;
}
wxFile file;
if (!file.Open(tempFile))
- return FALSE;
+ return false;
m_dataSize = (size_t) file.Length();
file.Close();
bool wxRichTextImageBlock::Load(wxImage& image)
{
if (!m_data)
- return FALSE;
+ return false;
// Read in the image.
#if 1
if (!WriteBlock(tempFile, m_data, m_dataSize))
{
- return FALSE;
+ return false;
}
success = image.LoadFile(tempFile, GetImageType());
wxRemoveFile(tempFile);
{
hex = wxDecToHex(m_data[i]);
wxCharBuffer buf = hex.ToAscii();
-
+
stream.Write((const char*) buf, hex.Length());
}
str[0] = stream.GetC();
str[1] = stream.GetC();
- m_data[i] = wxHexToDec(str);
+ m_data[i] = (unsigned char)wxHexToDec(str);
}
m_dataSize = dataSize;
{
wxFileOutputStream outStream(filename);
if (!outStream.Ok())
- return FALSE;
+ return false;
return WriteBlock(outStream, block, size);
}
/////////////////////////////////////////////////////////////////////////////
-// Name: richeditctrl.cpp
+// Name: richtext/richeditctrl.cpp
// Purpose: A rich edit control
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
{
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
-
+
GetBuffer().SetRichTextCtrl(this);
wxTextAttrEx attributes;
SetDefaultStyle(attributes);
SetBasicStyle(attributes);
- SetBackgroundColour(*wxWHITE);
+ SetBackgroundColour(*wxWHITE);
SetBackgroundStyle(wxBG_STYLE_CUSTOM);
- // Tell the sizers to use the given or best size
+ // Tell the sizers to use the given or best size
SetBestFittingSize(size);
-
+
// Create a buffer
RecreateBuffer(size);
PositionCaret();
SetCursor(wxCursor(wxCURSOR_IBEAM));
-
+
return true;
}
return;
dc.SetFont(GetFont());
-
+
// Paint the background
PaintBackground(dc);
wxRegion dirtyRegion = GetUpdateRegion();
wxRect drawingArea(GetLogicalPoint(wxPoint(0, 0)), GetClientSize());
- wxRect availableSpace(wxPoint(0, 0), GetClientSize());
+ wxRect availableSpace(GetClientSize());
if (GetBuffer().GetDirty())
{
GetBuffer().Layout(dc, availableSpace, GetBuffer().GetRange(), wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT);
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
-
+
long position = 0;
int hit = GetBuffer().HitTest(dc, event.GetLogicalPosition(dc), position);
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
-
+
long position = 0;
wxPoint logicalPt = event.GetLogicalPosition(dc);
int hit = GetBuffer().HitTest(dc, logicalPt, position);
if (m_caretPosition != position)
{
bool extendSel = ExtendSelection(m_caretPosition, position, wxRICHTEXT_SHIFT_DOWN);
-
+
MoveCaret(position, caretAtLineStart);
SetDefaultStyleToCursorStyle();
-
+
if (extendSel)
Refresh();
}
{
wxLogDebug(wxT("Strange selection range"));
}
-
+
return true;
}
else
// the same position but indicate that we're to show
// at the start of the next line.
m_caretPosition = oldPosition;
- m_caretAtLineStart = true;
+ m_caretAtLineStart = true;
}
SetDefaultStyleToCursorStyle();
return;
return true;
}
else
- return false;
+ return false;
}
/// Move left
return true;
}
else
- return false;
+ return false;
}
/// Move up
wxRichTextLine* lineObj = GetBuffer().GetLineForVisibleLineNumber(newLine);
if (lineObj)
- {
- pt.y = lineObj->GetAbsolutePosition().y + 2;
+ {
+ pt.y = lineObj->GetAbsolutePosition().y + 2;
}
else
return false;
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
-
+
int hitTest = GetBuffer().HitTest(dc, pt, newPos);
-
+
if (hitTest != wxRICHTEXT_HITTEST_NONE)
{
// If end of previous line, and hitTest is wxRICHTEXT_HITTEST_BEFORE,
return true;
}
else
- return false;
+ return false;
}
/// Move to the end of the buffer
return true;
}
else
- return false;
+ return false;
}
/// Move noPages pages up
// Finds the caret position for the next word
long wxRichTextCtrl::FindNextWordPosition(int direction) const
-{
+{
long endPos = GetBuffer().GetRange().GetEnd();
if (direction > 0)
{
long i = m_caretPosition+1+direction; // +1 for conversion to character pos
-
+
// First skip current text to space
while (i < endPos && i > -1)
{
// i is in character, not caret positions
wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i));
- if (text != wxT(" ") && !text.IsEmpty())
+ if (text != wxT(" ") && !text.empty())
i += direction;
else
{
{
// i is in character, not caret positions
wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i));
- if (text.IsEmpty()) // End of paragraph, or maybe an image
+ if (text.empty()) // End of paragraph, or maybe an image
return wxMax(-1, i - 1);
- else if (text == wxT(" ") || text.IsEmpty())
+ else if (text == wxT(" ") || text.empty())
i += direction;
else
{
{
// i is in character, not caret positions
wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i));
- if (text.IsEmpty()) // End of paragraph, or maybe an image
+ if (text.empty()) // End of paragraph, or maybe an image
break;
- else if (text == wxT(" ") || text.IsEmpty())
+ else if (text == wxT(" ") || text.empty())
i += direction;
else
break;
{
// i is in character, not caret positions
wxString text = GetBuffer().GetTextForRange(wxRichTextRange(i, i));
- if (text != wxT(" ") /* && !text.IsEmpty() */)
+ if (text != wxT(" ") /* && !text.empty() */)
i += direction;
else
{
return i;
- break;
}
}
if (i < -1)
if (pos != m_caretPosition)
{
wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos, true);
-
+
if (!ExtendSelection(m_caretPosition, pos, flags))
SelectNone();
-
+
SetCaretPosition(pos, para->GetRange().GetStart() != pos);
PositionCaret();
SetDefaultStyleToCursorStyle();
Refresh();
return true;
}
-
+
return false;
}
if (pos != m_caretPosition)
{
wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos, true);
-
+
if (!ExtendSelection(m_caretPosition, pos, flags))
SelectNone();
-
+
SetCaretPosition(pos, para->GetRange().GetStart() != pos);
PositionCaret();
SetDefaultStyleToCursorStyle();
Refresh();
return true;
}
-
+
return false;
}
void wxRichTextCtrl::OnSize(wxSizeEvent& event)
{
GetBuffer().SetDirty(true);
-
+
RecreateBuffer();
event.Skip();
int startX, startY;
GetViewStart(& startX, & startY);
-
+
int maxPositionX = 0; // wxMax(sz.x - clientSize.x, 0);
int maxPositionY = (wxMax(maxHeight - clientSize.y, 0))/pixelsPerUnit;
-
+
// Move to previous scroll position if
// possible
SetScrollbars(0, pixelsPerUnit,
// Clear the background
dc.SetBrush(wxBrush(backgroundColour));
dc.SetPen(*wxTRANSPARENT_PEN);
- wxRect windowRect(wxPoint(0, 0), GetClientSize());
+ wxRect windowRect(GetClientSize());
windowRect.x -= 2; windowRect.y -= 2;
windowRect.width += 4; windowRect.height += 4;
-
+
// We need to shift the rectangle to take into account
// scrolling. Converting device to logical coordinates.
CalcUnscrolledPosition(windowRect.x, windowRect.y, & windowRect.x, & windowRect.y);
wxSize sz = size;
if (sz == wxDefaultSize)
sz = GetClientSize();
-
+
if (sz.x < 1 || sz.y < 1)
return false;
-
+
if (!m_bufferBitmap.Ok() || m_bufferBitmap.GetWidth() < sz.x || m_bufferBitmap.GetHeight() < sz.y)
m_bufferBitmap = wxBitmap(sz.x, sz.y);
return m_bufferBitmap.Ok();
else
{
wxLogError(_("File couldn't be loaded."));
-
+
return false;
}
}
if (bitmap.Ok())
{
wxRichTextImageBlock imageBlock;
-
+
wxImage image = bitmap.ConvertToImage();
if (image.Ok() && imageBlock.MakeImageBlock(image, bitmapType))
return WriteImage(imageBlock);
if (CanPaste())
{
BeginBatchUndo(_("Paste"));
-
+
long newPos = m_caretPosition;
DeleteSelectedContent(& newPos);
-
+
GetBuffer().PasteFromClipboard(newPos);
EndBatchUndo();
{
wxClientDC dc(this);
dc.SetFont(GetFont());
-
+
PrepareDC(dc);
wxPoint pt;
/// setting the caret position.
bool wxRichTextCtrl::Layout()
{
- wxRect availableSpace(wxPoint(0, 0), GetClientSize());
+ wxRect availableSpace(GetClientSize());
if (availableSpace.width == 0)
availableSpace.width = 10;
if (availableSpace.height == 0)
wxClientDC dc(this);
dc.SetFont(GetFont());
-
+
PrepareDC(dc);
GetBuffer().Defragment();
GetBuffer().UpdateRanges(); // If items were deleted, ranges need recalculation
GetBuffer().Layout(dc, availableSpace, GetBuffer().GetRange(), wxRICHTEXT_FIXED_WIDTH|wxRICHTEXT_VARIABLE_HEIGHT);
GetBuffer().SetDirty(false);
-
+
if (!IsFrozen())
SetupScrollbars();
wxRichTextRange range = GetSelectionRange();
attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT);
attr.SetFontWeight(wxBOLD);
-
+
return HasCharacterAttributes(range, attr);
}
else
wxRichTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
attr.SetFontStyle(wxITALIC);
-
+
return HasCharacterAttributes(range, attr);
}
else
wxRichTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
attr.SetFontUnderlined(true);
-
+
return HasCharacterAttributes(range, attr);
}
else
wxRichTextRange range = GetSelectionRange();
wxRichTextAttr attr;
attr.SetAlignment(alignment);
-
+
return HasParagraphAttributes(range, attr);
}
else
/////////////////////////////////////////////////////////////////////////////
-// Name: richtextxml.cpp
+// Name: richtext/richtextxml.cpp
// Purpose: XML and HTML I/O for wxRichTextCtrl
// Author: Julian Smart
-// Modified by:
+// Modified by:
// Created: 2005-09-30
-// RCS-ID:
+// RCS-ID: $Id$
// Copyright: (c) Julian Smart
// Licence: wxWindows licence
/////////////////////////////////////////////////////////////////////////////
IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler)
#if wxUSE_STREAMS
-bool wxRichTextXMLHandler::LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
+bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream)
{
if (!stream.IsOk())
return false;
else
ImportXML(buffer, child);
}
-
+
child = child->GetNext();
}
}
success = false;
}
}
-
+
delete xmlDoc;
buffer->UpdateRanges();
{
int imageType = wxBITMAP_TYPE_PNG;
wxString value = node->GetPropVal(wxT("imagetype"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
imageType = wxAtoi(value);
wxString data;
// wxLogDebug(data);
dataChild = dataChild->GetNext();
}
-
+
}
imageChild = imageChild->GetNext();
}
- if (!data.IsEmpty())
+ if (!data.empty())
{
wxRichTextImage* imageObj = new wxRichTextImage(para);
para->AppendChild(imageObj);
ImportXML(buffer, child);
child = child->GetNext();
}
- }
+ }
return true;
}
wxString wxRichTextXMLHandler::GetParamValue(wxXmlNode *node, const wxString& param)
{
- if (param.IsEmpty())
+ if (param.empty())
return GetNodeContent(node);
else
return GetNodeContent(GetParamNode(node, param));
// write string to output:
inline static void OutputString(wxOutputStream& stream, const wxString& str,
- wxMBConv *convMem = NULL, wxMBConv *convFile = NULL)
+ wxMBConv *WXUNUSED_IN_UNICODE(convMem) = NULL, wxMBConv *convFile = NULL)
{
- if (str.IsEmpty()) return;
+ if (str.empty()) return;
#if wxUSE_UNICODE
const wxWX2MBbuf buf(str.mb_str(convFile ? *convFile : wxConvUTF8));
stream.Write((const char*)buf, strlen((const char*)buf));
wxString buf;
size_t i, last, len;
wxChar c;
-
+
len = str.Len();
last = 0;
for (i = 0; i < len; i++)
// Convert 6-digit hex string to a colour
wxColour HexStringToColour(const wxString& hex)
{
- unsigned int r = 0;
- unsigned int g = 0;
- unsigned int b = 0;
- r = wxHexToDec(hex.Mid(0, 2));
- g = wxHexToDec(hex.Mid(2, 2));
- b = wxHexToDec(hex.Mid(4, 2));
+ unsigned char r = (unsigned char)wxHexToDec(hex.Mid(0, 2));
+ unsigned char g = (unsigned char)wxHexToDec(hex.Mid(2, 2));
+ unsigned char b = (unsigned char)wxHexToDec(hex.Mid(4, 2));
return wxColour(r, g, b);
}
-bool wxRichTextXMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
+bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
{
if (!stream.IsOk())
return false;
wxString memencoding(wxT("ISO-8859-1")) ;
#endif
wxString s ;
-
+
wxMBConv *convMem = NULL, *convFile = NULL;
#if wxUSE_UNICODE
convFile = new wxCSConv(fileencoding);
convMem = new wxCSConv(memencoding);
}
#endif
-
+
s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
(const wxChar*) version, (const wxChar*) fileencoding );
OutputString(stream, s, NULL, NULL);
OutputString(stream, wxT("\n</richtext>") , NULL, NULL);
OutputString(stream, wxT("\n"), NULL, NULL);
-
+
delete convFile;
delete convMem;
OutputIndentation(stream, indent);
stream << wxT("<") << objectName;
-
+
wxString style = CreateStyle(obj.GetAttributes(), false);
-
+
stream << style << wxT(">");
-
+
wxString str = text.GetText();
if (str.Length() > 0 && (str[0] == wxT(' ') || str[str.Length()-1] == wxT(' ')))
{
{
OutputIndentation(stream, indent);
stream << wxT("<") << objectName;
-
+
bool isPara = false;
if (objectName == wxT("paragraph") || objectName == wxT("paragraphlayout"))
isPara = true;
wxString style = CreateStyle(obj.GetAttributes(), isPara);
-
+
stream << style << wxT(">");
-
+
wxRichTextCompositeObject& composite = (wxRichTextCompositeObject&) obj;
size_t i;
for (i = 0; i < composite.GetChildCount(); i++)
str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
}
- if (!attr.GetCharacterStyleName().IsEmpty())
+ if (!attr.GetCharacterStyleName().empty())
str << wxT(" charactertyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
if (isPara)
str << wxT(" bulletnumber=\"") << (int) attr.GetBulletNumber() << wxT("\"");
str << wxT(" bulletsymbol=\"") << wxString(attr.GetBulletSymbol()) << wxT("\"");
- if (!attr.GetParagraphStyleName().IsEmpty())
+ if (!attr.GetParagraphStyleName().empty())
str << wxT(" parstyle=\"") << wxString(attr.GetParagraphStyleName()) << wxT("\"");
}
fontFacename = node->GetPropVal(wxT("fontface"), wxEmptyString);
wxString value = node->GetPropVal(wxT("fontfamily"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
fontFamily = wxAtoi(value);
value = node->GetPropVal(wxT("fontstyle"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
fontStyle = wxAtoi(value);
value = node->GetPropVal(wxT("fontsize"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
fontSize = wxAtoi(value);
value = node->GetPropVal(wxT("fontweight"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
fontWeight = wxAtoi(value);
value = node->GetPropVal(wxT("fontunderlined"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
fontUnderlined = wxAtoi(value) != 0;
attr.SetFont(* wxTheFontList->FindOrCreateFont(fontSize, fontFamily, fontStyle, fontWeight, fontUnderlined, fontFacename));
value = node->GetPropVal(wxT("textcolor"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
{
if (value[0] == wxT('#'))
attr.SetTextColour(HexStringToColour(value.Mid(1)));
}
value = node->GetPropVal(wxT("backgroundcolor"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
{
if (value[0] == wxT('#'))
attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
}
value = node->GetPropVal(wxT("characterstyle"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetCharacterStyleName(value);
// Set paragraph attributes
if (isPara)
{
value = node->GetPropVal(wxT("alignment"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
int leftSubIndent = 0;
int leftIndent = 0;
value = node->GetPropVal(wxT("leftindent"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
leftIndent = wxAtoi(value);
value = node->GetPropVal(wxT("leftsubindent"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
leftSubIndent = wxAtoi(value);
attr.SetLeftIndent(leftIndent, leftSubIndent);
value = node->GetPropVal(wxT("rightindent"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetRightIndent(wxAtoi(value));
value = node->GetPropVal(wxT("parspacingbefore"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetParagraphSpacingBefore(wxAtoi(value));
value = node->GetPropVal(wxT("parspacingafter"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetParagraphSpacingAfter(wxAtoi(value));
value = node->GetPropVal(wxT("linespacing"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetLineSpacing(wxAtoi(value));
value = node->GetPropVal(wxT("bulletstyle"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetBulletStyle(wxAtoi(value));
value = node->GetPropVal(wxT("bulletnumber"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetBulletNumber(wxAtoi(value));
value = node->GetPropVal(wxT("bulletsymbol"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetBulletSymbol(value[0]);
value = node->GetPropVal(wxT("parstyle"), wxEmptyString);
- if (!value.IsEmpty())
+ if (!value.empty())
attr.SetParagraphStyleName(value);
}
#if wxUSE_STREAMS
-bool wxRichTextHTMLHandler::LoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
+bool wxRichTextHTMLHandler::DoLoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
{
return false;
}
* We need to output only _changes_ in character formatting.
*/
-bool wxRichTextHTMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
+bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
{
buffer->Defragment();
}
node2 = node2->GetNext();
- }
+ }
OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, false);
#endif
// wxUSE_RICHTEXT
-