X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/89be8239db1ae24f501ac68c5bcff3e5ca2efa84..1a8372ba0f655f8f9fec7d942f9665fcb458903c:/samples/richedit/wxlparser.cpp?ds=sidebyside diff --git a/samples/richedit/wxlparser.cpp b/samples/richedit/wxlparser.cpp index 1089a45885..75d9f981b9 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 @@ -28,7 +28,7 @@ #define BASE_SIZE 12 -inline static bool IsEndOfLine(const char *p) +inline static bool IsEndOfLine(const wxChar *p) { // the end of line is either just '\n' or "\r\n" - we understand both (even // though the second is used only under DOS/Windows) to be able to import @@ -43,9 +43,9 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str) // 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; + wxChar * cptr = (wxChar *)str.c_str(); // const_cast + const wxChar * begin = cptr; + wxChar backup; for(;;) { @@ -73,28 +73,29 @@ void wxLayoutImportText(wxLayoutList *list, wxString const &str) static wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, - wxLayoutStyleInfo *styleInfo) + wxLayoutStyleInfo *styleInfo, + bool firstTime) { - static char buffer[20]; + static wxChar buffer[20]; wxString html; wxLayoutStyleInfo *si = cmd.GetStyle(); int size, sizecount; - html += "m_fg_valid) { - html +="color="; - sprintf(buffer,"\"#%02X%02X%02X\"", si->m_fg.Red(),si->m_fg.Green(),si->m_fg.Blue()); + html += _T("color="); + wxSprintf(buffer,_T("\"#%02X%02X%02X\""), si->m_fg.Red(),si->m_fg.Green(),si->m_fg.Blue()); html += buffer; } if(si->m_bg_valid) { - html += " bgcolor="; - sprintf(buffer,"\"#%02X%02X%02X\"", si->m_bg.Red(),si->m_bg.Green(),si->m_bg.Blue()); + html += _T(" bgcolor="); + wxSprintf(buffer,_T("\"#%02X%02X%02X\""), si->m_bg.Red(),si->m_bg.Green(),si->m_bg.Blue()); html += buffer; } @@ -102,11 +103,11 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, { case wxSWISS: case wxMODERN: - html += " face=\"Arial,Helvetica\""; break; + html += _T(" face=\"Arial,Helvetica\""); break; case wxROMAN: - html += " face=\"Times New Roman, Times\""; break; + html += _T(" face=\"Times New Roman, Times\""); break; case wxTELETYPE: - html += " face=\"Courier New, Courier\""; break; + html += _T(" face=\"Courier New, Courier\""); break; default: ; } @@ -122,34 +123,34 @@ wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd, sizecount --; size = (size*10)/12; } - html += "size="; - sprintf(buffer,"%+1d", sizecount); + html += _T("size="); + wxSprintf(buffer,_T("%+1d"), sizecount); html += buffer; - html +=">"; + html += _T(">"); - if(styleInfo != NULL) - html =""+html; // terminate any previous font command + if(styleInfo != NULL && ! firstTime) + html = _T("")+html; // terminate any previous font command if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD))) - html += ""; + html += _T(""); else if(si->weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD))) - html += ""; + html += _T(""); if(si->style == wxSLANT) si->style = wxITALIC; // the same for html if((si->style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC))) - html += ""; + html += _T(""); else if(si->style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC))) - html += ""; + html += _T(""); if(si->underline && ( (!styleInfo) || ! styleInfo->underline)) - html += ""; + html += _T(""); else if(si->underline == false && ( styleInfo && styleInfo->underline)) - html += ""; + html += _T(""); *styleInfo = *si; // update last style info @@ -164,6 +165,7 @@ wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list) m_si = list->GetDefaultStyleInfo(); m_line = list->GetFirstLine(); m_iterator = m_line->GetFirstObject(); + m_FirstTime = TRUE; } @@ -220,10 +222,10 @@ wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status, { while(status->m_iterator == NULLIT) { - if(flags & WXLO_EXPORT_AS_HTML) - *str += "
"; + if(mode & WXLO_EXPORT_AS_HTML) + *str += _T("
"); if(flags & WXLO_EXPORT_WITH_CRLF) - *str += "\r\n"; + *str += _T("\r\n"); else *str += '\n'; @@ -245,15 +247,16 @@ 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++; } - exp->type = (mode == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT; exp->content.text = str;