/*-*- c++ -*-********************************************************
* wxlparser.h : parsers, import/export for wxLayoutList *
* *
- * (C) 1998 by Karsten Ballüder (Ballueder@usa.net) *
+ * (C) 1998,1999 by Karsten Ballüder (Ballueder@usa.net) *
* *
* $Id$
*******************************************************************/
# pragma implementation "wxlparser.h"
#endif
-#include "wxllist.h"
-#include "wxlparser.h"
+#include <wx/wxprec.h>
+
+#ifdef __BORLANDC__
+# pragma hdrstop
+#endif
+
+#include "Mpch.h"
+
+#ifdef M_PREFIX
+# include "gui/wxllist.h"
+# include "gui/wxlparser.h"
+#else
+# include "wxllist.h"
+# include "wxlparser.h"
+#endif
#define BASE_SIZE 12
-void wxLayoutImportText(wxLayoutList &list, String const &str)
+inline static bool IsEndOfLine(const char *p, int mode)
{
+ // in addition to Unix EOL convention we also (but not instead) understand
+ // the DOS one under Windows
+ return
+ (mode == WXLO_EXPORT_WITH_CRLF) ?
+ ((*p == '\r') && (*(p + 1) == '\n'))
+ :
+ (((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
+}
+
+void wxLayoutImportText(wxLayoutList *list, wxString const &str, int withflag)
+{
+ if(str.Length() == 0)
+ return;
char * cptr = (char *)str.c_str(); // string gets changed only temporarily
const char * begin = cptr;
char backup;
for(;;)
{
- begin = cptr++;
- while(*cptr && *cptr != '\n')
+ begin = cptr;
+ while( *cptr && !IsEndOfLine(cptr, withflag) )
cptr++;
backup = *cptr;
*cptr = '\0';
- list.Insert(begin);
+ list->Insert(begin);
*cptr = backup;
- if(backup == '\n')
- list.LineBreak();
+
+ // check if it's the end of this line
+ if ( IsEndOfLine(cptr, withflag) )
+ {
+ // if it was "\r\n", skip the following '\n'
+ if ( *cptr == '\r' )
+ cptr++;
+ list->LineBreak();
+ }
else if(backup == '\0') // reached end of string
break;
cptr++;
}
static
-String wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
- wxLayoutStyleInfo **lastStylePtr)
+wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
+ wxLayoutStyleInfo *styleInfo)
{
static char buffer[20];
- String html;
+ wxString html;
wxLayoutStyleInfo *si = cmd.GetStyle();
- wxLayoutStyleInfo *last_si = NULL;
int size, sizecount;
- if(lastStylePtr != NULL)
- last_si = *lastStylePtr;
-
html += "<font ";
- html +="color=";
- sprintf(buffer,"\"#%02X%02X%02X\"", si->fg_red,si->fg_green,si->fg_blue);
- html += buffer;
-
-
- html += " bgcolor=";
- sprintf(buffer,"\"#%02X%02X%02X\"", si->bg_red,si->bg_green,si->bg_blue);
- html += buffer;
+ if(si->m_fg_valid)
+ {
+ html +="color=";
+ sprintf(buffer,"\"#%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 += buffer;
+ }
+
switch(si->family)
{
case wxSWISS:
html +=">";
- if(last_si != NULL)
+ if(styleInfo != NULL)
html ="</font>"+html; // terminate any previous font command
- if((si->weight == wxBOLD) && ( (!last_si) || (last_si->weight != wxBOLD)))
+ if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
html += "<b>";
else
- if(si->weight != wxBOLD && ( last_si && (last_si->weight == wxBOLD)))
+ if(si->weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD)))
html += "</b>";
if(si->style == wxSLANT)
si->style = wxITALIC; // the same for html
- if((si->style == wxITALIC) && ( (!last_si) || (last_si->style != wxITALIC)))
+ if((si->style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC)))
html += "<i>";
else
- if(si->style != wxITALIC && ( last_si && (last_si->style == wxITALIC)))
+ if(si->style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC)))
html += "</i>";
- if(si->underline && ( (!last_si) || ! last_si->underline))
+ if(si->underline && ( (!styleInfo) || ! styleInfo->underline))
html += "<u>";
- else if(si->underline == false && ( last_si && last_si->underline))
+ else if(si->underline == false && ( styleInfo && styleInfo->underline))
html += "</u>";
+
+
+ *styleInfo = *si; // update last style info
- if(last_si)
- delete last_si;
- *lastStylePtr = si;
return html;
}
+wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list)
+{
+ m_si = *list->GetDefaults();
+ m_line = list->GetFirstLine();
+ m_iterator = m_line->GetFirstObject();
+}
+
+
+
#define WXLO_IS_TEXT(type) \
-( (type == WXLO_TYPE_TEXT || type == WXLO_TYPE_LINEBREAK) \
+( type == WXLO_TYPE_TEXT \
|| (type == WXLO_TYPE_CMD \
&& mode == WXLO_EXPORT_AS_HTML))
-
- wxLayoutExportObject *wxLayoutExport(wxLayoutList &list,
- wxLayoutList::iterator &from,
- wxLayoutExportMode mode)
+wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
+ int mode, int flags)
{
- if(from == list.end())
- return NULL;
-
- wxLayoutObjectType type = (*from)->GetType();
- wxLayoutExportObject * export = new wxLayoutExportObject();
-
- static wxLayoutStyleInfo *s_si = NULL;
+ wxASSERT(status);
+ wxLayoutExportObject * export;
- if( mode == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
+ if(status->m_iterator == NULLIT) // end of line
{
- export->type = WXLO_EXPORT_OBJECT;
- export->content.object = *from;
- from++;
- return export;
+ if(!status->m_line || status->m_line->GetNextLine() == NULL)
+ // reached end of list
+ return NULL;
+ }
+ export = 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;
+ status->m_iterator++;
+ return export;
+ }
+ }
+ else
+ { // iterator == NULLIT
+ if(mode == WXLO_EXPORT_AS_OBJECTS)
+ {
+ export->type = WXLO_EXPORT_EMPTYLINE;
+ export->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;
+ }
+ else
+ type = WXLO_TYPE_TEXT;
}
- String *str = new String();
-
+ wxString *str = new wxString();
// text must be concatenated
- while(from != list.end() && WXLO_IS_TEXT(type))
+ for(;;)
{
+ while(status->m_iterator == NULLIT)
+ {
+ if(flags & WXLO_EXPORT_AS_HTML)
+ *str += "<br>";
+ if(flags & WXLO_EXPORT_WITH_CRLF)
+ *str += "\r\n";
+ else
+ *str += '\n';
+
+ status->m_line = status->m_line->GetNextLine();
+ if(status->m_line)
+ status->m_iterator = status->m_line->GetFirstObject();
+ else
+ break; // end of list
+ }
+ if(! status->m_line) // reached end of list, fall through
+ break;
+ type = (** status->m_iterator).GetType();
+ if(type == WXLO_TYPE_ICON)
+ break;
switch(type)
{
case WXLO_TYPE_TEXT:
- *str += ((wxLayoutObjectText *)*from)->GetText();
- break;
- case WXLO_TYPE_LINEBREAK:
- if(mode == WXLO_EXPORT_AS_HTML)
- *str += "<br>";
- *str += '\n';
+ *str += ((wxLayoutObjectText *)*status->m_iterator)->GetText();
break;
case WXLO_TYPE_CMD:
- //wxASSERT(mode == WXLO_EXPORT_AS_HTML,"reached cmd object in text mode")
- assert(mode == WXLO_EXPORT_AS_HTML);
- *str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
- *)*from, &s_si);
+ if(mode == WXLO_EXPORT_AS_HTML)
+ *str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
+ *)*status->m_iterator, & status->m_si);
break;
default: // ignore icons
;
}
- from++;
- if(from != list.end())
- type = (*from)->GetType();
+ status->m_iterator++;
}
- export->type = (mode == WXLO_EXPORT_AS_HTML) ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
+
+ export->type = (mode == WXLO_EXPORT_AS_HTML)
+ ? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
export->content.text = str;
return export;
}
+