]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlparser.cpp
1 /*-*- c++ -*-********************************************************
2 * wxlparser.h : parsers, import/export for wxLayoutList *
4 * (C) 1998,1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
10 # pragma implementation "wxlparser.h"
15 # include "gui/wxllist.h"
16 # include "gui/wxlparser.h"
19 # include "wxlparser.h"
24 inline static bool IsEndOfLine(const char *p
, int mode
)
26 // in addition to Unix EOL convention we also (but not instead) understand
27 // the DOS one under Windows
29 ((mode
& WXLO_EXPORT_WITH_MASK
) == WXLO_EXPORT_WITH_CRLF
) ?
30 ((*p
== '\r') && (*(p
+ 1) == '\n'))
32 (((*p
== '\r') && (*(p
+ 1) == '\n'))||(*p
== '\n'));
35 void wxLayoutImportText(wxLayoutList
*list
, wxString
const &str
, int withflag
)
37 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
38 const char * begin
= cptr
;
44 while( *cptr
&& !IsEndOfLine(cptr
, withflag
) )
51 // check if it's the end of this line
52 if ( IsEndOfLine(cptr
, withflag
) )
54 // if it was "\r\n", skip the following '\n'
59 else if(backup
== '\0') // reached end of string
66 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
67 wxLayoutStyleInfo
*styleInfo
)
69 static char buffer
[20];
80 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.fg_red
,si
.fg_green
,si
.fg_blue
);
85 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.bg_red
,si
.bg_green
,si
.bg_blue
);
92 html
+= " face=\"Arial,Helvetica\""; break;
94 html
+= " face=\"Times New Roman, Times\""; break;
96 html
+= " face=\"Courier New, Courier\""; break;
101 size
= BASE_SIZE
; sizecount
= 0;
102 while(size
< si
.size
&& sizecount
< 5)
107 while(size
> si
.size
&& sizecount
> -5)
113 sprintf(buffer
,"%+1d", sizecount
);
118 if(styleInfo
!= NULL
)
119 html
="</font>"+html
; // terminate any previous font command
121 if((si
.weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
124 if(si
.weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
127 if(si
.style
== wxSLANT
)
128 si
.style
= wxITALIC
; // the same for html
130 if((si
.style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
133 if(si
.style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
136 if(si
.underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
138 else if(si
.underline
== false && ( styleInfo
&& styleInfo
->underline
))
142 *styleInfo
= si
; // update last style info
149 #define WXLO_IS_TEXT(type) \
150 ( type == WXLO_TYPE_TEXT \
151 || (type == WXLO_TYPE_CMD \
152 && (mode & WXLO_EXPORT_AS_MASK) == WXLO_EXPORT_AS_HTML))
156 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
160 wxLayoutExportObject
* export
;
162 if(status
->m_iterator
== NULLIT
) // end of line
164 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
) // reached end of list
168 status
->m_line
= status
->m_line
->GetNextLine();
169 status
->m_iterator
= status
->m_line
->GetFirstObject();
170 export
= new wxLayoutExportObject();;
171 if( (mode
& WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_OBJECTS
) // simple case
173 export
->type
= WXLO_EXPORT_OBJECT
;
174 export
->content
.object
= *status
->m_iterator
;
175 status
->m_iterator
++;
179 export
->type
= ((mode
& WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_HTML
)
180 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
181 if((mode
& WXLO_EXPORT_WITH_CRLF
) == WXLO_EXPORT_WITH_CRLF
)
182 export
->content
.text
= new wxString("\r\n");
184 export
->content
.text
= new wxString("\n");
189 export
= new wxLayoutExportObject();
190 wxLayoutObjectType type
= (** status
->m_iterator
).GetType();
191 if( (mode
& WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
193 export
->type
= WXLO_EXPORT_OBJECT
;
194 export
->content
.object
= *status
->m_iterator
;
195 status
->m_iterator
++;
199 // else: must be text
200 wxString
*str
= new wxString();
201 // text must be concatenated
207 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
210 wxASSERT_MSG( (mode
&WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_HTML
,
211 "reached cmd object in text mode" );
213 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
214 *)*status
->m_iterator
, & status
->m_si
);
216 default: // ignore icons
219 status
->m_iterator
++;
220 if(status
->m_iterator
== NULLIT
) // end of line!
222 if((mode
& WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_HTML
)
224 if((mode
& WXLO_EXPORT_WITH_CRLF
) == WXLO_EXPORT_WITH_CRLF
)
228 status
->m_line
= status
->m_line
->GetNextLine();
230 status
->m_iterator
= status
->m_line
->GetFirstObject();
232 status
->m_iterator
= NULLIT
;
234 if(status
->m_iterator
!= NULLIT
)
235 type
= (** status
->m_iterator
).GetType();
239 while(WXLO_IS_TEXT(type
));
241 export
->type
= ((mode
& WXLO_EXPORT_AS_MASK
) == WXLO_EXPORT_AS_HTML
)
242 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
243 export
->content
.text
= str
;