X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/6c11b5265004937450f8e08d55b8a1476e1452dd..3340066af696862df9394469b341b700fe4e3a68:/samples/richedit/wxlparser.cpp diff --git a/samples/richedit/wxlparser.cpp b/samples/richedit/wxlparser.cpp index 316247bfc0..dc457fb85d 100644 --- a/samples/richedit/wxlparser.cpp +++ b/samples/richedit/wxlparser.cpp @@ -10,7 +10,7 @@ # pragma implementation "wxlparser.h" #endif -#include +#include "wx/wxprec.h" #ifdef __BORLANDC__ # pragma hdrstop @@ -41,10 +41,9 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str) if ( !str ) return; - // we change the string temporarily inside this function - wxString& s = (wxString &)str; // const_cast - - char * cptr = s.GetWriteBuf(s.Len()); + // we change the string only temporarily inside this function + // VZ: I still don't like it... the string data may be shared... + char * cptr = (char *)str.c_str(); // const_cast const char * begin = cptr; char backup; @@ -70,13 +69,12 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str) break; cptr++; } - - s.UngetWriteBuf(); } static wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, - wxLayoutStyleInfo *styleInfo) + wxLayoutStyleInfo *styleInfo, + bool firstTime) { static char buffer[20]; wxString html; @@ -131,7 +129,7 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, html +=">"; - if(styleInfo != NULL) + if(styleInfo != NULL && ! firstTime) html =""+html; // terminate any previous font command if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD))) @@ -167,6 +165,7 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list) m_si = list->GetDefaultStyleInfo(); m_line = list->GetFirstLine(); m_iterator = m_line->GetFirstObject(); + m_FirstTime = TRUE; } @@ -181,7 +180,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status, int mode, int flags) { wxASSERT(status); - wxLayoutExportObject * export; + wxLayoutExportObject * exp; if(status->m_iterator == NULLIT) // end of line { @@ -189,29 +188,29 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status, // reached end of list return NULL; } - export = new wxLayoutExportObject(); + exp = new wxLayoutExportObject(); wxLayoutObjectType type; if(status->m_iterator != NULLIT) { type = (** status->m_iterator).GetType(); if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case { - export->type = WXLO_EXPORT_OBJECT; - export->content.object = *status->m_iterator; + exp->type = WXLO_EXPORT_OBJECT; + exp->content.object = *status->m_iterator; status->m_iterator++; - return export; + return exp; } } else { // iterator == NULLIT if(mode == WXLO_EXPORT_AS_OBJECTS) { - export->type = WXLO_EXPORT_EMPTYLINE; - export->content.object = NULL; //empty line + exp->type = WXLO_EXPORT_EMPTYLINE; + exp->content.object = NULL; //empty line status->m_line = status->m_line->GetNextLine(); if(status->m_line) status->m_iterator = status->m_line->GetFirstObject(); - return export; + return exp; } else type = WXLO_TYPE_TEXT; @@ -223,7 +222,7 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status, { while(status->m_iterator == NULLIT) { - if(flags & WXLO_EXPORT_AS_HTML) + if(mode & WXLO_EXPORT_AS_HTML) *str += "
"; if(flags & WXLO_EXPORT_WITH_CRLF) *str += "\r\n"; @@ -248,18 +247,19 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status, break; case WXLO_TYPE_CMD: if(mode == WXLO_EXPORT_AS_HTML) - *str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const - *)*status->m_iterator, & status->m_si); + *str += wxLayoutExportCmdAsHTML( + *(wxLayoutObjectCmd const *)*status->m_iterator, + & status->m_si, status->m_FirstTime); + status->m_FirstTime = FALSE; break; default: // ignore icons ; } status->m_iterator++; } - - export->type = (mode == WXLO_EXPORT_AS_HTML) + exp->type = (mode == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT; - export->content.text = str; - return export; + exp->content.text = str; + return exp; }