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
|
|
|
|
|
|
1999-05-10 06:44:09 -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-03-29 04:56:44 -05:00
|
|
|
|
(mode == WXLO_EXPORT_WITH_CRLF) ?
|
1999-02-08 10:20:38 -05:00
|
|
|
|
((*p == '\r') && (*(p + 1) == '\n'))
|
|
|
|
|
:
|
|
|
|
|
(((*p == '\r') && (*(p + 1) == '\n'))||(*p == '\n'));
|
1998-10-24 14:08:20 -04:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-14 16:22:10 -05:00
|
|
|
|
void wxLayoutImportText(wxLayoutList *list, wxString const &str, int withflag)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1999-04-03 11:57:46 -05:00
|
|
|
|
if(str.Length() == 0)
|
|
|
|
|
return;
|
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';
|
1999-03-14 16:22:10 -05:00
|
|
|
|
list->Insert(begin);
|
1998-06-29 08:44:36 -04:00
|
|
|
|
*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++;
|
1999-03-14 16:22:10 -05: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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1999-05-09 11:24:57 -04:00
|
|
|
|
wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list,
|
|
|
|
|
wxPoint fromPos,
|
|
|
|
|
wxPoint toPos)
|
|
|
|
|
{
|
|
|
|
|
list->GetDefaults()->GetStyle(&m_si);
|
|
|
|
|
m_line = list->GetFirstLine();
|
|
|
|
|
m_iterator = m_line->GetFirstObject();
|
|
|
|
|
m_fromPos = fromPos;
|
|
|
|
|
m_toPos = toPos;
|
|
|
|
|
|
1999-05-09 13:28:58 -04:00
|
|
|
|
if(m_fromPos.x != -1)
|
1999-05-09 11:24:57 -04:00
|
|
|
|
{
|
1999-05-09 13:28:58 -04:00
|
|
|
|
while(m_line && m_line->GetLineNumber() != m_fromPos.y)
|
|
|
|
|
m_line = m_line->GetNextLine();
|
1999-05-09 11:24:57 -04:00
|
|
|
|
wxASSERT(m_line);
|
1999-05-09 13:28:58 -04:00
|
|
|
|
CoordType dummy;
|
|
|
|
|
m_iterator = m_line->FindObject(fromPos.x, &dummy);
|
1999-05-09 11:24:57 -04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1998-06-29 08:44:36 -04:00
|
|
|
|
#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-03-29 04:56:44 -05:00
|
|
|
|
&& mode == WXLO_EXPORT_AS_HTML))
|
1998-06-29 08:44:36 -04:00
|
|
|
|
|
|
|
|
|
|
1999-05-09 11:24:57 -04:00
|
|
|
|
|
|
|
|
|
extern const wxPoint wxLayoutExportNoPosition = wxPoint(-1,-1);
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
1999-03-29 04:56:44 -05:00
|
|
|
|
int mode, int flags)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxASSERT(status);
|
|
|
|
|
wxLayoutExportObject * export;
|
1999-03-14 16:22:10 -05:00
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
if(status->m_iterator == NULLIT) // end of line
|
|
|
|
|
{
|
1999-03-29 04:56:44 -05:00
|
|
|
|
if(!status->m_line || status->m_line->GetNextLine() == NULL)
|
|
|
|
|
// reached end of list
|
1999-03-07 16:38:50 -05:00
|
|
|
|
return NULL;
|
1999-03-29 04:56:44 -05: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 16:38:50 -05:00
|
|
|
|
{
|
1999-03-29 04:56:44 -05:00
|
|
|
|
export->type = WXLO_EXPORT_OBJECT;
|
|
|
|
|
export->content.object = *status->m_iterator;
|
|
|
|
|
status->m_iterator++;
|
1999-03-07 16:38:50 -05:00
|
|
|
|
return export;
|
|
|
|
|
}
|
|
|
|
|
}
|
1999-03-29 04:56:44 -05: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 08:44:36 -04:00
|
|
|
|
}
|
|
|
|
|
|
1999-03-07 16:38:50 -05:00
|
|
|
|
wxString *str = new wxString();
|
1998-06-29 08:44:36 -04:00
|
|
|
|
// text must be concatenated
|
1999-03-29 04:56:44 -05:00
|
|
|
|
for(;;)
|
1998-06-29 08:44:36 -04:00
|
|
|
|
{
|
1999-03-29 04:56:44 -05: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 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-03-29 04:56:44 -05:00
|
|
|
|
wxASSERT_MSG( mode == 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++;
|
1998-06-29 08:44:36 -04:00
|
|
|
|
}
|
1999-03-07 16:38:50 -05:00
|
|
|
|
|
1999-03-29 04:56:44 -05:00
|
|
|
|
export->type = (mode == WXLO_EXPORT_AS_HTML)
|
1999-03-07 16:38:50 -05:00
|
|
|
|
? 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
|
|
|
|
|