1999-06-07 09:57:14 +00:00
|
|
|
|
/*-*- c++ -*-********************************************************
|
|
|
|
|
* wxlparser.h : parsers, import/export for wxLayoutList *
|
|
|
|
|
* *
|
|
|
|
|
* (C) 1998,1999 by Karsten Ball<EFBFBD>der (Ballueder@usa.net) *
|
|
|
|
|
* *
|
|
|
|
|
* $Id$
|
|
|
|
|
*******************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
|
# pragma implementation "wxlparser.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2001-10-30 13:33:34 +00:00
|
|
|
|
#include "wx/wxprec.h"
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
#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
|
|
|
|
|
|
2003-09-11 09:33:17 +00:00
|
|
|
|
inline static bool IsEndOfLine(const wxChar *p)
|
1999-06-07 09:57:14 +00:00
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
|
// DOS text files even under Unix
|
|
|
|
|
return (*p == '\n') || ((*p == '\r') && (*(p + 1) == '\n'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void wxLayoutImportText(wxLayoutList *list, wxString const &str)
|
|
|
|
|
{
|
|
|
|
|
if ( !str )
|
|
|
|
|
return;
|
|
|
|
|
|
1999-06-12 21:07:44 +00:00
|
|
|
|
// we change the string only temporarily inside this function
|
|
|
|
|
// VZ: I still don't like it... the string data may be shared...
|
2003-09-11 09:33:17 +00:00
|
|
|
|
wxChar * cptr = (wxChar *)str.c_str(); // const_cast
|
|
|
|
|
const wxChar * begin = cptr;
|
2003-11-20 17:43:57 +00:00
|
|
|
|
wxUnusedVar(begin);
|
2003-09-11 09:33:17 +00:00
|
|
|
|
wxChar backup;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
begin = cptr;
|
|
|
|
|
while( *cptr && !IsEndOfLine(cptr) )
|
|
|
|
|
cptr++;
|
|
|
|
|
backup = *cptr;
|
|
|
|
|
*cptr = '\0';
|
|
|
|
|
list->Insert(begin);
|
|
|
|
|
*cptr = backup;
|
|
|
|
|
|
|
|
|
|
// check if it's the end of this line
|
|
|
|
|
if ( IsEndOfLine(cptr) )
|
|
|
|
|
{
|
|
|
|
|
// 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
|
|
|
|
|
wxString wxLayoutExportCmdAsHTML(wxLayoutObjectCmd const & cmd,
|
1999-12-01 18:05:54 +00:00
|
|
|
|
wxLayoutStyleInfo *styleInfo,
|
|
|
|
|
bool firstTime)
|
1999-06-07 09:57:14 +00:00
|
|
|
|
{
|
2003-09-11 09:33:17 +00:00
|
|
|
|
static wxChar buffer[20];
|
1999-06-07 09:57:14 +00:00
|
|
|
|
wxString html;
|
|
|
|
|
|
|
|
|
|
wxLayoutStyleInfo *si = cmd.GetStyle();
|
|
|
|
|
|
|
|
|
|
int size, sizecount;
|
|
|
|
|
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("<font ");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
if(si->m_fg_valid)
|
|
|
|
|
{
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("color=");
|
|
|
|
|
wxSprintf(buffer,_T("\"#%02X%02X%02X\""), si->m_fg.Red(),si->m_fg.Green(),si->m_fg.Blue());
|
1999-06-07 09:57:14 +00:00
|
|
|
|
html += buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(si->m_bg_valid)
|
|
|
|
|
{
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T(" bgcolor=");
|
|
|
|
|
wxSprintf(buffer,_T("\"#%02X%02X%02X\""), si->m_bg.Red(),si->m_bg.Green(),si->m_bg.Blue());
|
1999-06-07 09:57:14 +00:00
|
|
|
|
html += buffer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
switch(si->family)
|
|
|
|
|
{
|
|
|
|
|
case wxSWISS:
|
|
|
|
|
case wxMODERN:
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T(" face=\"Arial,Helvetica\""); break;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
case wxROMAN:
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T(" face=\"Times New Roman, Times\""); break;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
case wxTELETYPE:
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T(" face=\"Courier New, Courier\""); break;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size = BASE_SIZE; sizecount = 0;
|
|
|
|
|
while(size < si->size && sizecount < 5)
|
|
|
|
|
{
|
|
|
|
|
sizecount ++;
|
|
|
|
|
size = (size*12)/10;
|
|
|
|
|
}
|
|
|
|
|
while(size > si->size && sizecount > -5)
|
|
|
|
|
{
|
|
|
|
|
sizecount --;
|
|
|
|
|
size = (size*10)/12;
|
|
|
|
|
}
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("size=");
|
|
|
|
|
wxSprintf(buffer,_T("%+1d"), sizecount);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
html += buffer;
|
|
|
|
|
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T(">");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
1999-12-01 18:05:54 +00:00
|
|
|
|
if(styleInfo != NULL && ! firstTime)
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html = _T("</font>")+html; // terminate any previous font command
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
if((si->weight == wxBOLD) && ( (!styleInfo) || (styleInfo->weight != wxBOLD)))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("<b>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
else
|
|
|
|
|
if(si->weight != wxBOLD && ( styleInfo && (styleInfo->weight == wxBOLD)))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("</b>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
if(si->style == wxSLANT)
|
|
|
|
|
si->style = wxITALIC; // the same for html
|
|
|
|
|
|
|
|
|
|
if((si->style == wxITALIC) && ( (!styleInfo) || (styleInfo->style != wxITALIC)))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("<i>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
else
|
|
|
|
|
if(si->style != wxITALIC && ( styleInfo && (styleInfo->style == wxITALIC)))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("</i>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
if(si->underline && ( (!styleInfo) || ! styleInfo->underline))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("<u>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
else if(si->underline == false && ( styleInfo && styleInfo->underline))
|
2003-09-11 09:33:17 +00:00
|
|
|
|
html += _T("</u>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*styleInfo = *si; // update last style info
|
|
|
|
|
|
|
|
|
|
return html;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList *list)
|
|
|
|
|
{
|
|
|
|
|
m_si = list->GetDefaultStyleInfo();
|
|
|
|
|
m_line = list->GetFirstLine();
|
|
|
|
|
m_iterator = m_line->GetFirstObject();
|
2003-11-20 17:43:57 +00:00
|
|
|
|
m_FirstTime = true;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#define WXLO_IS_TEXT(type) \
|
|
|
|
|
( type == WXLO_TYPE_TEXT \
|
|
|
|
|
|| (type == WXLO_TYPE_CMD \
|
|
|
|
|
&& mode == WXLO_EXPORT_AS_HTML))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
wxLayoutExportObject *wxLayoutExport(wxLayoutExportStatus *status,
|
|
|
|
|
int mode, int flags)
|
|
|
|
|
{
|
|
|
|
|
wxASSERT(status);
|
1999-10-10 16:52:34 +00:00
|
|
|
|
wxLayoutExportObject * exp;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
if(status->m_iterator == NULLIT) // end of line
|
|
|
|
|
{
|
|
|
|
|
if(!status->m_line || status->m_line->GetNextLine() == NULL)
|
|
|
|
|
// reached end of list
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
1999-10-10 16:52:34 +00:00
|
|
|
|
exp = new wxLayoutExportObject();
|
1999-06-07 09:57:14 +00:00
|
|
|
|
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-10-10 16:52:34 +00:00
|
|
|
|
exp->type = WXLO_EXPORT_OBJECT;
|
|
|
|
|
exp->content.object = *status->m_iterator;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
status->m_iterator++;
|
1999-10-10 16:52:34 +00:00
|
|
|
|
return exp;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{ // iterator == NULLIT
|
|
|
|
|
if(mode == WXLO_EXPORT_AS_OBJECTS)
|
|
|
|
|
{
|
1999-10-10 16:52:34 +00:00
|
|
|
|
exp->type = WXLO_EXPORT_EMPTYLINE;
|
|
|
|
|
exp->content.object = NULL; //empty line
|
1999-06-07 09:57:14 +00:00
|
|
|
|
status->m_line = status->m_line->GetNextLine();
|
|
|
|
|
if(status->m_line)
|
|
|
|
|
status->m_iterator = status->m_line->GetFirstObject();
|
1999-10-10 16:52:34 +00:00
|
|
|
|
return exp;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
type = WXLO_TYPE_TEXT;
|
|
|
|
|
}
|
2003-11-20 17:43:57 +00:00
|
|
|
|
wxUnusedVar(type);
|
1999-06-07 09:57:14 +00:00
|
|
|
|
|
|
|
|
|
wxString *str = new wxString();
|
|
|
|
|
// text must be concatenated
|
|
|
|
|
for(;;)
|
|
|
|
|
{
|
|
|
|
|
while(status->m_iterator == NULLIT)
|
|
|
|
|
{
|
1999-12-01 18:05:54 +00:00
|
|
|
|
if(mode & WXLO_EXPORT_AS_HTML)
|
2003-09-11 09:33:17 +00:00
|
|
|
|
*str += _T("<br>");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
if(flags & WXLO_EXPORT_WITH_CRLF)
|
2003-09-11 09:33:17 +00:00
|
|
|
|
*str += _T("\r\n");
|
1999-06-07 09:57:14 +00:00
|
|
|
|
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 *)*status->m_iterator)->GetText();
|
|
|
|
|
break;
|
|
|
|
|
case WXLO_TYPE_CMD:
|
|
|
|
|
if(mode == WXLO_EXPORT_AS_HTML)
|
1999-12-01 18:05:54 +00:00
|
|
|
|
*str += wxLayoutExportCmdAsHTML(
|
|
|
|
|
*(wxLayoutObjectCmd const *)*status->m_iterator,
|
|
|
|
|
& status->m_si, status->m_FirstTime);
|
2003-11-20 17:43:57 +00:00
|
|
|
|
status->m_FirstTime = false;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
break;
|
|
|
|
|
default: // ignore icons
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
status->m_iterator++;
|
|
|
|
|
}
|
1999-10-10 16:52:34 +00:00
|
|
|
|
exp->type = (mode == WXLO_EXPORT_AS_HTML)
|
1999-06-07 09:57:14 +00:00
|
|
|
|
? WXLO_EXPORT_HTML : WXLO_EXPORT_TEXT;
|
1999-10-10 16:52:34 +00:00
|
|
|
|
exp->content.text = str;
|
|
|
|
|
return exp;
|
1999-06-07 09:57:14 +00:00
|
|
|
|
}
|
|
|
|
|
|