/////////////////////////////////////////////////////////////////////////////
-// 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
/////////////////////////////////////////////////////////////////////////////
#pragma hdrstop
#endif
+#if wxUSE_RICHTEXT && wxUSE_XML
+
+#include "wx/richtext/richtextxml.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/wfstream.h"
#include "wx/txtstrm.h"
#include "wx/xml/xml.h"
-#include "wx/richtext/richtextxml.h"
-
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));
return str1;
}
+// For use with earlier versions of wxWidgets
+#ifndef WXUNUSED_IN_UNICODE
+#if wxUSE_UNICODE
+#define WXUNUSED_IN_UNICODE(x) WXUNUSED(x)
+#else
+#define WXUNUSED_IN_UNICODE(x) x
+#endif
+#endif
+
// 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));
+ if (convFile)
+ {
+ const wxWX2MBbuf buf(str.mb_str(*convFile));
+ stream.Write((const char*)buf, strlen((const char*)buf));
+ }
+ else
+ {
+ const wxWX2MBbuf buf(str.mb_str(wxConvUTF8));
+ stream.Write((const char*)buf, strlen((const char*)buf));
+ }
#else
if ( convFile == NULL )
stream.Write(str.mb_str(), str.Len());
wxString buf;
size_t i, last, len;
wxChar c;
-
+
len = str.Len();
last = 0;
for (i = 0; i < len; i++)
return stream;
}
+#if 0
static wxOutputStream& operator <<(wxOutputStream& stream, long l)
{
wxString str;
str.Printf(wxT("%c"), c);
return stream << str;
}
+#endif
// Convert a colour to a 6-digit hex string
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;
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
#endif
- // wxUSE_RICHTEXT
-
+ // wxUSE_RICHTEXT && wxUSE_XML