1998-06-29 08:44:36 -04:00
|
|
|
|
/*-*- c++ -*-********************************************************
|
|
|
|
|
* wxlparser.h : parsers, import/export for wxLayoutList *
|
|
|
|
|
* *
|
1999-02-08 10:20:38 -05:00
|
|
|
|
* (C) 1998,1999 by Karsten Ball<EFBFBD>der (Ballueder@usa.net) *
|
1998-06-29 08:44:36 -04:00
|
|
|
|
* *
|
|
|
|
|
* $Id$
|
|
|
|
|
*******************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
# pragma implementation "wxlparser.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
1998-10-24 14:08:20 -04:00
|
|
|
|
//#include "Mpch.h"
|
1999-02-08 10:20:38 -05:00
|
|
|
|
#ifdef M_PREFIX
|
1998-10-24 14:08:20 -04:00
|
|
|
|
# include "gui/wxllist.h"
|
|
|
|
|
# include "gui/wxlparser.h"
|
|
|
|
|
#else
|
|
|
|
|
# include "wxllist.h"
|
|
|
|
|
# include "wxlparser.h"
|
|
|
|
|
#endif
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
#define BASE_SIZE 12
|
|
|
|
|
|
1999-02-08 10:20:38 -05:00
|
|
|
|
inline static bool IsEndOfLine(const char *p, int mode)
|
1998-10-24 14:08:20 -04:00
|
|
|
|
{
|
|
|
|
|
// in addition to Unix EOL convention we also (but not instead) understand
|
|
|
|
|
// the DOS one under Windows
|
|
|
|
|
return
|
1999-02-08 10:20:38 -05:00
|
|
|
|
((mode & WXLO_EXPORT_WITH_MASK) == WXLO_EXPORT_WITH_CRLF) ?
|
|
|
|
|
((*p == '\r') && (*(p + 1) == '\n'))
|
|
|
|
|
:
|
|
|
|
|
(((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
|
1998-10-24 14:08:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
void wxLayoutImportText(wxLayoutList &list, wxString const &str, int withflag)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
char * cptr = (char *)str.c_str(); // string gets changed only temporarily
|
|
|
|
|
const char * begin = cptr;
|
|
|
|
|
char backup;
|
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
1998-10-24 14:08:20 -04:00
|
|
|
|
begin = cptr;
|
1999-02-08 10:20:38 -05:00
|
|
|
|
while( *cptr && !IsEndOfLine(cptr, withflag) )
|
1998-06-29 08:44:36 -04:00
|
|
|
|
cptr++;
|
|
|
|
|
backup = *cptr;
|
|
|
|
|
*cptr = '\0';
|
|
|
|
|
list.Insert(begin);
|
|
|
|
|
*cptr = backup;
|
1998-10-24 14:08:20 -04:00
|
|
|
|
|
|
|
|
|
// check if it's the end of this line
|
1999-02-08 10:20:38 -05:00
|
|
|
|
if ( IsEndOfLine(cptr, withflag) )
|
1998-10-24 14:08:20 -04:00
|
|
|
|
{
|
|
|
|
|
// if it was "\r\n", skip the following '\n'
|
|
|
|
|
if ( *cptr == '\r' )
|
|
|
|
|
cptr++;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
list.LineBreak();
|
1998-10-24 14:08:20 -04:00
|
|
|
|
}
|
1998-06-29 08:44:36 -04:00
|
|
|
|
else if(backup == '\0') // reached end of string
|
|
|
|
|
break;
|
|
|
|
|
cptr++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
|
|
|
|
wxLayoutStyleInfo *styleInfo)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
static char buffer[20];
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxString html;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxLayoutStyleInfo si;
|
|
|
|
|
cmd.GetStyle(&si);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
int size, sizecount;
|
|
|
|
|
|
|
|
|
|
html += "<font ";
|
|
|
|
|
|
|
|
|
|
html +="color=";
|
1999-03-07 16:38:50 -05:00
|
|
|
|
sprintf(buffer,"\"#%02X%02X%02X\"", si.fg_red,si.fg_green,si.fg_blue);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += buffer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
html += " bgcolor=";
|
1999-03-07 16:38:50 -05:00
|
|
|
|
sprintf(buffer,"\"#%02X%02X%02X\"", si.bg_red,si.bg_green,si.bg_blue);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += buffer;
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
switch(si.family)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
case wxSWISS:
|
|
|
|
|
case wxMODERN:
|
|
|
|
|
html += " face=\"Arial,Helvetica\""; break;
|
|
|
|
|
case wxROMAN:
|
|
|
|
|
html += " face=\"Times New Roman, Times\""; break;
|
|
|
|
|
case wxTELETYPE:
|
|
|
|
|
html += " face=\"Courier New, Courier\""; break;
|
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = BASE_SIZE; sizecount = 0;
|
1999-03-07 16:38:50 -05:00
|
|
|
|
while(size < si.size && sizecount < 5)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
sizecount ++;
|
|
|
|
|
size = (size*12)/10;
|
|
|
|
|
}
|
1999-03-07 16:38:50 -05:00
|
|
|
|
while(size > si.size && sizecount > -5)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
sizecount --;
|
|
|
|
|
size = (size*10)/12;
|
|
|
|
|
}
|
|
|
|
|
html += "size=";
|
|
|
|
|
sprintf(buffer,"%+1d", sizecount);
|
|
|
|
|
html += buffer;
|
|
|
|
|
|
|
|
|
|
html +=">";
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(styleInfo != NULL)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html ="</font>"+html; // terminate any previous font command
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if((si.weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "<b>";
|
|
|
|
|
else
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(si.weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD)))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "</b>";
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(si.style == wxSLANT)
|
|
|
|
|
si.style = wxITALIC; // the same for html
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if((si.style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC)))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "<i>";
|
|
|
|
|
else
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(si.style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC)))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "</i>";
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(si.underline && ( (!styleInfo) || ! styleInfo->underline))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "<u>";
|
1999-03-07 16:38:50 -05:00
|
|
|
|
else if(si.underline == false && ( styleInfo && styleInfo->underline))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
html += "</u>";
|
1999-03-07 16:38:50 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*styleInfo = si; // update last style info
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define WXLO_IS_TEXT(type) \
|
1999-03-07 16:38:50 -05:00
|
|
|
|
( type == WXLO_TYPE_TEXT \
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|| (type == WXLO_TYPE_CMD \
|
1999-02-08 10:20:38 -05:00
|
|
|
|
&& (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
1999-02-08 10:20:38 -05:00
|
|
|
|
int mode)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxASSERT(status);
|
|
|
|
|
wxLayoutExportObject * export;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(status->m_iterator == NULLIT) // end of line
|
|
|
|
|
{
|
|
|
|
|
if(!status->m_line || status->m_line->GetNextLine() == NULL) // reached end of list
|
|
|
|
|
return NULL;
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
status->m_line = status->m_line->GetNextLine();
|
|
|
|
|
status->m_iterator = status->m_line->GetFirstObject();
|
|
|
|
|
export = new wxLayoutExportObject();;
|
|
|
|
|
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
|
|
|
|
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
|
|
|
|
if((mode & WXLO_EXPORT_WITH_CRLF) == WXLO_EXPORT_WITH_CRLF)
|
|
|
|
|
export->content.text = new wxString("\r\n");
|
|
|
|
|
else
|
|
|
|
|
export->content.text = new wxString("\n");
|
|
|
|
|
return export;
|
|
|
|
|
}
|
|
|
|
|
}
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
export = new wxLayoutExportObject();
|
|
|
|
|
wxLayoutObjectType type = (** status->m_iterator).GetType();
|
1999-02-08 10:20:38 -05:00
|
|
|
|
if( (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_OBJECTS || ! WXLO_IS_TEXT(type)) // simple case
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
export->type = WXLO_EXPORT_OBJECT;
|
1999-03-07 16:38:50 -05:00
|
|
|
|
export->content.object = *status->m_iterator;
|
|
|
|
|
status->m_iterator++;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
return export;
|
|
|
|
|
}
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
// else: must be text
|
|
|
|
|
wxString *str = new wxString();
|
1998-06-29 08:44:36 -04:00
|
|
|
|
// text must be concatenated
|
1999-03-07 16:38:50 -05:00
|
|
|
|
do
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
|
|
|
|
switch(type)
|
|
|
|
|
{
|
|
|
|
|
case WXLO_TYPE_TEXT:
|
1999-03-07 16:38:50 -05:00
|
|
|
|
*str += ((wxLayoutObjectText *)*status->m_iterator)->GetText();
|
1998-06-29 08:44:36 -04:00
|
|
|
|
break;
|
|
|
|
|
case WXLO_TYPE_CMD:
|
1999-02-08 10:20:38 -05:00
|
|
|
|
wxASSERT_MSG( (mode&WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML,
|
1998-10-24 14:08:20 -04:00
|
|
|
|
"reached cmd object in text mode" );
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
*str += wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd const
|
1999-03-07 16:38:50 -05:00
|
|
|
|
*)*status->m_iterator, & status->m_si);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
break;
|
|
|
|
|
default: // ignore icons
|
|
|
|
|
;
|
|
|
|
|
}
|
1999-03-07 16:38:50 -05:00
|
|
|
|
status->m_iterator++;
|
|
|
|
|
if(status->m_iterator == NULLIT) // end of line!
|
|
|
|
|
{
|
|
|
|
|
if((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
|
|
|
|
*str += "<br>";
|
|
|
|
|
if((mode & WXLO_EXPORT_WITH_CRLF) == 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
|
|
|
|
|
status->m_iterator = NULLIT;
|
|
|
|
|
}
|
|
|
|
|
if(status->m_iterator != NULLIT)
|
|
|
|
|
type = (** status->m_iterator).GetType();
|
|
|
|
|
else
|
|
|
|
|
break;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
1999-03-07 16:38:50 -05:00
|
|
|
|
while(WXLO_IS_TEXT(type));
|
|
|
|
|
|
|
|
|
|
export->type = ((mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML)
|
|
|
|
|
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
export->content.text = str;
|
|
|
|
|
return export;
|
|
|
|
|
}
|
1999-03-07 16:38:50 -05:00
|
|
|
|
|