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