const consistent for Clone(). Load/Save split to DoLoad/DoSave. Build fixes, warning fixes and other source cleaning.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@35953 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Włodzimierz Skiba
2005-10-19 17:00:58 +00:00
parent 7f9d2f2aaf
commit 7fe8059f58
6 changed files with 318 additions and 319 deletions

View File

@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -81,7 +81,7 @@
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_
@@ -511,7 +511,7 @@ public:
/// 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
@@ -743,7 +743,7 @@ public:
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.
@@ -782,7 +782,7 @@ public:
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.
@@ -850,10 +850,10 @@ public:
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;
@@ -909,9 +909,6 @@ public:
/// Copy
void Copy(const wxRichTextParagraphLayoutBox& obj);
/// Clone
virtual wxRichTextObject* Clone() { return new wxRichTextParagraphLayoutBox(*this); }
/// Calculate ranges
virtual void UpdateRanges() { long end; CalculateRange(0, end); }
@@ -969,7 +966,7 @@ public:
void Copy(const wxRichTextFragment& obj);
/// Clone
virtual wxRichTextObject* Clone() { return new wxRichTextFragment(*this); }
virtual wxRichTextObject* Clone() const { return new wxRichTextFragment(*this); }
protected:
@@ -1077,7 +1074,7 @@ public:
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.
@@ -1166,7 +1163,7 @@ public:
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.
@@ -1186,7 +1183,7 @@ public:
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;
@@ -1240,7 +1237,7 @@ public:
// 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.
@@ -1319,7 +1316,7 @@ public:
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.
@@ -1671,7 +1668,7 @@ class WXDLLIMPEXP_ADV wxRichTextCommand: public wxCommand
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);
@@ -1700,7 +1697,7 @@ class WXDLLIMPEXP_ADV wxRichTextAction: public wxObject
{
public:
wxRichTextAction(wxRichTextCommand* cmd, const wxString& name, wxRichTextCommandId id, wxRichTextBuffer* buffer,
wxRichTextCtrl* ctrl, bool ignoreFirstTime = FALSE);
wxRichTextCtrl* ctrl, bool ignoreFirstTime = false);
~wxRichTextAction();
@@ -1771,12 +1768,14 @@ public:
{ }
#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;
@@ -1802,6 +1801,11 @@ public:
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;
@@ -1821,11 +1825,6 @@ public:
: 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; }
@@ -1834,6 +1833,11 @@ public:
protected:
#if wxUSE_STREAMS
virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream);
virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream);
#endif
};
/*!
@@ -1865,4 +1869,3 @@ bool wxRichTextApplyStyle(wxTextAttrEx& destStyle, const wxRichTextAttr& style);
#endif
// _WX_RICHTEXTBUFFER_H_

View File

@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -84,7 +84,7 @@ class WXDLLIMPEXP_ADV wxRichTextCtrl:
#else
public wxScrolledWindow
#endif
{
{
DECLARE_CLASS( wxRichTextCtrl )
DECLARE_EVENT_TABLE()
@@ -520,7 +520,7 @@ public:
// Show a context menu for Rich Edit controls (the standard
// EDIT control has one already)
void OnContextMenu(wxContextMenuEvent& event);
// Event handlers
/// Painting
@@ -568,7 +568,7 @@ public:
/// Paint the background
virtual void PaintBackground(wxDC& dc);
/// Recreate buffer bitmap if necessary
virtual bool RecreateBuffer(const wxSize& size = wxDefaultSize);
@@ -652,7 +652,7 @@ public:
// Data members
private:
/// Allows nested Freeze/Thaw
/// Allows nested Freeze/Thaw
int m_freezeCount;
/// Buffer bitmap

View File

@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -37,8 +37,8 @@ public:
{ }
#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);
@@ -84,8 +84,8 @@ public:
{ }
#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?

File diff suppressed because it is too large Load Diff

View File

@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -128,7 +128,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos
{
SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}
GetBuffer().SetRichTextCtrl(this);
wxTextAttrEx attributes;
@@ -141,12 +141,12 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos
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);
@@ -156,7 +156,7 @@ bool wxRichTextCtrl::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos
PositionCaret();
SetCursor(wxCursor(wxCURSOR_IBEAM));
return true;
}
@@ -225,14 +225,14 @@ void wxRichTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(event))
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);
@@ -269,7 +269,7 @@ void wxRichTextCtrl::OnLeftClick(wxMouseEvent& event)
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
long position = 0;
int hit = GetBuffer().HitTest(dc, event.GetLogicalPosition(dc), position);
@@ -339,7 +339,7 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
wxClientDC dc(this);
PrepareDC(dc);
dc.SetFont(GetFont());
long position = 0;
wxPoint logicalPt = event.GetLogicalPosition(dc);
int hit = GetBuffer().HitTest(dc, logicalPt, position);
@@ -366,10 +366,10 @@ void wxRichTextCtrl::OnMoveMouse(wxMouseEvent& event)
if (m_caretPosition != position)
{
bool extendSel = ExtendSelection(m_caretPosition, position, wxRICHTEXT_SHIFT_DOWN);
MoveCaret(position, caretAtLineStart);
SetDefaultStyleToCursorStyle();
if (extendSel)
Refresh();
}
@@ -663,7 +663,7 @@ bool wxRichTextCtrl::ExtendSelection(long oldPos, long newPos, int flags)
{
wxLogDebug(wxT("Strange selection range"));
}
return true;
}
else
@@ -809,7 +809,7 @@ void wxRichTextCtrl::MoveCaretForward(long oldPosition)
// 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;
@@ -900,7 +900,7 @@ bool wxRichTextCtrl::MoveRight(int noPositions, int flags)
return true;
}
else
return false;
return false;
}
/// Move left
@@ -929,7 +929,7 @@ bool wxRichTextCtrl::MoveLeft(int noPositions, int flags)
return true;
}
else
return false;
return false;
}
/// Move up
@@ -963,8 +963,8 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
wxRichTextLine* lineObj = GetBuffer().GetLineForVisibleLineNumber(newLine);
if (lineObj)
{
pt.y = lineObj->GetAbsolutePosition().y + 2;
{
pt.y = lineObj->GetAbsolutePosition().y + 2;
}
else
return false;
@@ -973,9 +973,9 @@ bool wxRichTextCtrl::MoveDown(int noLines, int flags)
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,
@@ -1127,7 +1127,7 @@ bool wxRichTextCtrl::MoveHome(int flags)
return true;
}
else
return false;
return false;
}
/// Move to the end of the buffer
@@ -1149,7 +1149,7 @@ bool wxRichTextCtrl::MoveEnd(int flags)
return true;
}
else
return false;
return false;
}
/// Move noPages pages up
@@ -1195,19 +1195,19 @@ bool wxRichTextCtrl::PageDown(int noPages, int flags)
// 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
{
@@ -1218,9 +1218,9 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const
{
// 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
{
@@ -1241,9 +1241,9 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const
{
// 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;
@@ -1253,12 +1253,11 @@ long wxRichTextCtrl::FindNextWordPosition(int direction) const
{
// 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)
@@ -1274,10 +1273,10 @@ bool wxRichTextCtrl::WordLeft(int WXUNUSED(n), int flags)
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();
@@ -1286,7 +1285,7 @@ bool wxRichTextCtrl::WordLeft(int WXUNUSED(n), int flags)
Refresh();
return true;
}
return false;
}
@@ -1297,10 +1296,10 @@ bool wxRichTextCtrl::WordRight(int WXUNUSED(n), int flags)
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();
@@ -1309,7 +1308,7 @@ bool wxRichTextCtrl::WordRight(int WXUNUSED(n), int flags)
Refresh();
return true;
}
return false;
}
@@ -1317,7 +1316,7 @@ bool wxRichTextCtrl::WordRight(int WXUNUSED(n), int flags)
void wxRichTextCtrl::OnSize(wxSizeEvent& event)
{
GetBuffer().SetDirty(true);
RecreateBuffer();
event.Skip();
@@ -1346,10 +1345,10 @@ void wxRichTextCtrl::SetupScrollbars()
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,
@@ -1367,10 +1366,10 @@ void wxRichTextCtrl::PaintBackground(wxDC& dc)
// 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);
@@ -1383,10 +1382,10 @@ bool wxRichTextCtrl::RecreateBuffer(const wxSize& size)
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();
@@ -1414,7 +1413,7 @@ bool wxRichTextCtrl::LoadFile(const wxString& filename, int type)
else
{
wxLogError(_("File couldn't be loaded."));
return false;
}
}
@@ -1630,7 +1629,7 @@ bool wxRichTextCtrl::WriteImage(const wxBitmap& bitmap, int bitmapType)
if (bitmap.Ok())
{
wxRichTextImageBlock imageBlock;
wxImage image = bitmap.ConvertToImage();
if (image.Ok() && imageBlock.MakeImageBlock(image, bitmapType))
return WriteImage(imageBlock);
@@ -1678,10 +1677,10 @@ void wxRichTextCtrl::Paste()
if (CanPaste())
{
BeginBatchUndo(_("Paste"));
long newPos = m_caretPosition;
DeleteSelectedContent(& newPos);
GetBuffer().PasteFromClipboard(newPos);
EndBatchUndo();
@@ -2147,7 +2146,7 @@ bool wxRichTextCtrl::GetCaretPositionForIndex(long position, wxRect& rect)
{
wxClientDC dc(this);
dc.SetFont(GetFont());
PrepareDC(dc);
wxPoint pt;
@@ -2205,7 +2204,7 @@ bool wxRichTextCtrl::MoveCaret(long pos, bool showAtLineStart)
/// 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)
@@ -2213,14 +2212,14 @@ bool wxRichTextCtrl::Layout()
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();
@@ -2236,7 +2235,7 @@ bool wxRichTextCtrl::IsSelectionBold() const
wxRichTextRange range = GetSelectionRange();
attr.SetFlags(wxTEXT_ATTR_FONT_WEIGHT);
attr.SetFontWeight(wxBOLD);
return HasCharacterAttributes(range, attr);
}
else
@@ -2263,7 +2262,7 @@ bool wxRichTextCtrl::IsSelectionItalics() const
wxRichTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_ITALIC);
attr.SetFontStyle(wxITALIC);
return HasCharacterAttributes(range, attr);
}
else
@@ -2290,7 +2289,7 @@ bool wxRichTextCtrl::IsSelectionUnderlined() const
wxRichTextAttr attr;
attr.SetFlags(wxTEXT_ATTR_FONT_UNDERLINE);
attr.SetFontUnderlined(true);
return HasCharacterAttributes(range, attr);
}
else
@@ -2358,7 +2357,7 @@ bool wxRichTextCtrl::IsSelectionAligned(wxTextAttrAlignment alignment) const
wxRichTextRange range = GetSelectionRange();
wxRichTextAttr attr;
attr.SetAlignment(alignment);
return HasParagraphAttributes(range, attr);
}
else

View File

@@ -1,10 +1,10 @@
/////////////////////////////////////////////////////////////////////////////
// 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
/////////////////////////////////////////////////////////////////////////////
@@ -37,7 +37,7 @@
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;
@@ -67,7 +67,7 @@ bool wxRichTextXMLHandler::LoadFile(wxRichTextBuffer *buffer, wxInputStream& str
else
ImportXML(buffer, child);
}
child = child->GetNext();
}
}
@@ -76,7 +76,7 @@ bool wxRichTextXMLHandler::LoadFile(wxRichTextBuffer *buffer, wxInputStream& str
success = false;
}
}
delete xmlDoc;
buffer->UpdateRanges();
@@ -145,7 +145,7 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
{
int imageType = wxBITMAP_TYPE_PNG;
wxString value = node->GetPropVal(wxT("imagetype"), wxEmptyString);
if (!value.IsEmpty())
if (!value.empty())
imageType = wxAtoi(value);
wxString data;
@@ -163,12 +163,12 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
// wxLogDebug(data);
dataChild = dataChild->GetNext();
}
}
imageChild = imageChild->GetNext();
}
if (!data.IsEmpty())
if (!data.empty())
{
wxRichTextImage* imageObj = new wxRichTextImage(para);
para->AppendChild(imageObj);
@@ -192,7 +192,7 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node)
ImportXML(buffer, child);
child = child->GetNext();
}
}
}
return true;
}
@@ -242,7 +242,7 @@ wxString wxRichTextXMLHandler::GetNodeContent(wxXmlNode *node)
wxString wxRichTextXMLHandler::GetParamValue(wxXmlNode *node, const wxString& param)
{
if (param.IsEmpty())
if (param.empty())
return GetNodeContent(node);
else
return GetNodeContent(GetParamNode(node, param));
@@ -259,9 +259,9 @@ wxString wxRichTextXMLHandler::GetText(wxXmlNode *node, const wxString& param, b
// 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));
@@ -284,7 +284,7 @@ static void OutputStringEnt(wxOutputStream& stream, const wxString& str,
wxString buf;
size_t i, last, len;
wxChar c;
len = str.Len();
last = 0;
for (i = 0; i < len; i++)
@@ -359,17 +359,14 @@ static wxString ColourToHexString(const wxColour& col)
// 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;
@@ -383,7 +380,7 @@ bool wxRichTextXMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& st
wxString memencoding(wxT("ISO-8859-1")) ;
#endif
wxString s ;
wxMBConv *convMem = NULL, *convFile = NULL;
#if wxUSE_UNICODE
convFile = new wxCSConv(fileencoding);
@@ -394,7 +391,7 @@ bool wxRichTextXMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& st
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);
@@ -405,7 +402,7 @@ bool wxRichTextXMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& st
OutputString(stream, wxT("\n</richtext>") , NULL, NULL);
OutputString(stream, wxT("\n"), NULL, NULL);
delete convFile;
delete convMem;
@@ -433,11 +430,11 @@ bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxMBConv* 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(' ')))
{
@@ -478,15 +475,15 @@ bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxMBConv* convMem,
{
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++)
@@ -527,7 +524,7 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool isPara
str << wxT(" fontface=\"") << attr.GetFont().GetFaceName() << wxT("\"");
}
if (!attr.GetCharacterStyleName().IsEmpty())
if (!attr.GetCharacterStyleName().empty())
str << wxT(" charactertyle=\"") << wxString(attr.GetCharacterStyleName()) << wxT("\"");
if (isPara)
@@ -543,7 +540,7 @@ wxString wxRichTextXMLHandler::CreateStyle(const wxTextAttrEx& attr, bool 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("\"");
}
@@ -563,29 +560,29 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool is
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)));
@@ -594,7 +591,7 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool is
}
value = node->GetPropVal(wxT("backgroundcolor"), wxEmptyString);
if (!value.IsEmpty())
if (!value.empty())
{
if (value[0] == wxT('#'))
attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
@@ -603,56 +600,56 @@ bool wxRichTextXMLHandler::GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool is
}
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);
}
@@ -674,7 +671,7 @@ bool wxRichTextHTMLHandler::CanHandle(const wxString& filename) const
#if wxUSE_STREAMS
bool wxRichTextHTMLHandler::LoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
bool wxRichTextHTMLHandler::DoLoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
{
return false;
}
@@ -683,7 +680,7 @@ bool wxRichTextHTMLHandler::LoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInput
* 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();
@@ -719,7 +716,7 @@ bool wxRichTextHTMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& s
}
node2 = node2->GetNext();
}
}
OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, false);
@@ -805,4 +802,3 @@ void wxRichTextHTMLHandler::OutputParagraphFormatting(const wxTextAttrEx& WXUNUS
#endif
// wxUSE_RICHTEXT