X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2dec67617f3cf1e2b724d16176c5dc20e8d97471..3882e74621cd5833fddb432fe014bea66c16ee28:/src/richtext/richtexthtml.cpp diff --git a/src/richtext/richtexthtml.cpp b/src/richtext/richtexthtml.cpp index 49552e64d3..c1722d2281 100644 --- a/src/richtext/richtexthtml.cpp +++ b/src/richtext/richtexthtml.cpp @@ -1,5 +1,5 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richtext/richtexthtml.cpp +// Name: src/richtext/richtexthtml.cpp // Purpose: HTML I/O for wxRichTextCtrl // Author: Julian Smart // Modified by: @@ -13,7 +13,7 @@ #include "wx/wxprec.h" #ifdef __BORLANDC__ - #pragma hdrstop + #pragma hdrstop #endif #if wxUSE_RICHTEXT @@ -21,15 +21,21 @@ #include "wx/richtext/richtexthtml.h" #ifndef WX_PRECOMP - #include "wx/wx.h" #endif #include "wx/filename.h" #include "wx/wfstream.h" #include "wx/txtstrm.h" +#if wxUSE_FILESYSTEM +#include "wx/filesys.h" +#include "wx/fs_mem.h" +#endif + IMPLEMENT_DYNAMIC_CLASS(wxRichTextHTMLHandler, wxRichTextFileHandler) +int wxRichTextHTMLHandler::sm_fileCounter = 1; + /// Can we handle this filename (if using files)? By default, checks the extension. bool wxRichTextHTMLHandler::CanHandle(const wxString& filename) const { @@ -52,56 +58,39 @@ bool wxRichTextHTMLHandler::DoLoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInp bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream) { + ClearTemporaryImageLocations(); + buffer->Defragment(); - + wxTextOutputStream str(stream); - + wxTextAttrEx currentParaStyle = buffer->GetAttributes(); wxTextAttrEx currentCharStyle = buffer->GetAttributes(); - + str << wxT("
\n"); - - /* - wxRichText may be support paper formats like a1/a2/a3/a4 - when this widget grown enough, i should turn back and support its new features - but not yet - - str << wxT(""); - - wxString left_indent = SymbolicIndent(currentParaStyle.GetLeftIndent()); - wxString right_indent = SymbolicIndent(currentParaStyle.GetRightIndent()); - - str << wxString::Format(wxT("%s | %s | |
");
- */
-
+
str << wxT("
|
after every paragraph - if(!m_list) + // If there is no opened list currently, insert a
after every paragraph + if (!m_list) { wxTextOutputStream str(stream); - wxString align = GetAlignment( thisStyle ); - str << wxString::Format(wxT("
"), align); + wxString align = GetAlignment(thisStyle); + str << wxString::Format(wxT("
"), align.c_str()); } } void wxRichTextHTMLHandler::NavigateToListPosition(const wxTextAttrEx& thisStyle, wxTextOutputStream& str) { - //indenting an item using an ul/ol tag is equal to inserting 5 x on its left side. - //so we should start from 100 point left - - //Is the second td's left wall of the current indentaion table at the 100+ point-left-side - //of the item, horizontally? - if( m_indent + 100 < thisStyle.GetLeftIndent() ) + // indenting an item using an ul/ol tag is equal to inserting 5 x on its left side. + // so we should start from 100 point left + + // Is the second td's left wall of the current indentaion table at the 100+ point-left-side + // of the item, horizontally? + if (m_indent + 100 < thisStyle.GetLeftIndent()) { - //yes it is + // yes it is LIndent(thisStyle, str); m_indent = thisStyle.GetLeftIndent() - 100; m_indents.Add( m_indent ); return; } - //No it isn't - + // No it isn't + int i = m_indents.size() - 1; - for(; i > -1; i--) + for (; i > -1; i--) { - //Is the second td's left wall of the current indentaion table at the 100+ point-left-side + //Is the second td's left wall of the current indentaion table at the 100+ point-left-side //of the item ? - if( m_indent + 100 < thisStyle.GetLeftIndent() ) + if (m_indent + 100 < thisStyle.GetLeftIndent()) { - //Yes it is + // Yes it is LIndent(thisStyle, str); m_indent = thisStyle.GetLeftIndent() - 100; m_indents.Add( m_indent ); break; } - else if( m_indent + 100 == thisStyle.GetLeftIndent() ) - break;//exact match + else if (m_indent + 100 == thisStyle.GetLeftIndent()) + break; //exact match else { - //No it is not, the second td's left wall of the current indentaion table is at the + // No it is not, the second td's left wall of the current indentaion table is at the //right side of the current item horizontally, so close it. str << wxT(""); - + m_indents.RemoveAt(i); - - if( i < 1 ){m_indent=0; break;} + + if (i < 1) + { + m_indent=0; break; + } m_indent = m_indents[i-1]; } } } void wxRichTextHTMLHandler::Indent( const wxTextAttrEx& thisStyle, wxTextOutputStream& str ) { - //As a five year experienced web developer i assure you there is no way to indent an item - //in html way, but we can use tables. - - - - //Item -> "Hello world" - //Its Left Indentation -> 100 - //Its Left Sub-Indentation ->40 - //A typical indentation-table for the item will be construct as the following - - //3 x nbsp = 60 - //2 x nbsp = 40 - //LSI = Left Sub Indent - //LI = Left Indent - LSI + //There is no way to indent an item in HTML, but we can use tables. + + // Item -> "Hello world" + // Its Left Indentation -> 100 + // Its Left Sub-Indentation ->40 + // A typical indentation-table for the item will be construct as the following + + // 3 x nbsp = 60 + // 2 x nbsp = 40 + // LSI = Left Sub Indent + // LI = Left Indent - LSI // - //------------------------------------------- - //| nbsp;|nbsp;nbsp;Hello World | - //| | | | | - //| V | V | - //| --LI-- | --LSI-- | - //------------------------------------------- - + // ------------------------------------------- + // | nbsp;|nbsp;nbsp;Hello World | + // | | | | | + // | V | V | + // | --LI-- | --LSI-- | + // ------------------------------------------- + str << wxT("
%s | "), symbolic_indent ); + str << wxString::Format( wxT("%s | "), symbolic_indent.c_str() ); str << wxT("");
-
- if( thisStyle.GetLeftSubIndent() < 0 )
+
+ if (thisStyle.GetLeftSubIndent() < 0)
{
- symbolic_indent = SymbolicIndent(~thisStyle.GetLeftSubIndent());
- str << wxString::Format(wxT("%s"), symbolic_indent);
+ str << SymbolicIndent(~thisStyle.GetLeftSubIndent());
}
}
void wxRichTextHTMLHandler::LIndent( const wxTextAttrEx& thisStyle, wxTextOutputStream& str )
{
- //Code:
- //r.BeginNumberedBullet(1, 200, 60);
- //r.Newline();
- //r.WriteText(wxT("first item"));
- //r.EndNumberedBullet();
- //r.BeginNumberedBullet(2, 200, 60);
- //r.Newline();
- //r.WriteText(wxT("second item."));
- //r.EndNumberedBullet();
+ // Code:
+ // r.BeginNumberedBullet(1, 200, 60);
+ // r.Newline();
+ // r.WriteText(wxT("first item"));
+ // r.EndNumberedBullet();
+ // r.BeginNumberedBullet(2, 200, 60);
+ // r.Newline();
+ // r.WriteText(wxT("second item."));
+ // r.EndNumberedBullet();
//
- //A typical indentation-table for the item will be construct as the following
-
- //1 x nbsp = 20 point
- //ULI -> 100pt (UL/OL tag indents its sub element by 100 point)
- //<--------- 100 pt ---------->|
- //------------------------------------------------------
- //| nbsp; nbsp;|
|