]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlparser.cpp
1 /*-*- c++ -*-********************************************************
2 * wxlparser.h : parsers, import/export for wxLayoutList *
4 * (C) 1998 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
)
26 // in addition to Unix EOL convention we also (but not instead) understand
27 // the DOS one under Windows
30 ((*p
== '\r') && (*(p
+ 1) == '\n')) ||
35 void wxLayoutImportText(wxLayoutList
&list
, String
const &str
)
37 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
38 const char * begin
= cptr
;
44 while( *cptr
&& !IsEndOfLine(cptr
) )
51 // check if it's the end of this line
52 if ( IsEndOfLine(cptr
) )
54 // if it was "\r\n", skip the following '\n'
59 else if(backup
== '\0') // reached end of string
66 String
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
67 wxLayoutStyleInfo
**lastStylePtr
)
69 static char buffer
[20];
72 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
73 wxLayoutStyleInfo
*last_si
= NULL
;
77 if(lastStylePtr
!= NULL
)
78 last_si
= *lastStylePtr
;
83 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->fg_red
,si
->fg_green
,si
->fg_blue
);
88 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->bg_red
,si
->bg_green
,si
->bg_blue
);
95 html
+= " face=\"Arial,Helvetica\""; break;
97 html
+= " face=\"Times New Roman, Times\""; break;
99 html
+= " face=\"Courier New, Courier\""; break;
104 size
= BASE_SIZE
; sizecount
= 0;
105 while(size
< si
->size
&& sizecount
< 5)
110 while(size
> si
->size
&& sizecount
> -5)
116 sprintf(buffer
,"%+1d", sizecount
);
122 html
="</font>"+html
; // terminate any previous font command
124 if((si
->weight
== wxBOLD
) && ( (!last_si
) || (last_si
->weight
!= wxBOLD
)))
127 if(si
->weight
!= wxBOLD
&& ( last_si
&& (last_si
->weight
== wxBOLD
)))
130 if(si
->style
== wxSLANT
)
131 si
->style
= wxITALIC
; // the same for html
133 if((si
->style
== wxITALIC
) && ( (!last_si
) || (last_si
->style
!= wxITALIC
)))
136 if(si
->style
!= wxITALIC
&& ( last_si
&& (last_si
->style
== wxITALIC
)))
139 if(si
->underline
&& ( (!last_si
) || ! last_si
->underline
))
141 else if(si
->underline
== false && ( last_si
&& last_si
->underline
))
152 #define WXLO_IS_TEXT(type) \
153 ( (type == WXLO_TYPE_TEXT || type == WXLO_TYPE_LINEBREAK) \
154 || (type == WXLO_TYPE_CMD \
155 && mode == WXLO_EXPORT_AS_HTML))
159 wxLayoutExportObject
*wxLayoutExport(wxLayoutList
&list
,
160 wxLayoutList::iterator
&from
,
161 wxLayoutExportMode mode
)
163 if(from
== list
.end())
166 wxLayoutObjectType type
= (*from
)->GetType();
167 wxLayoutExportObject
* export
= new wxLayoutExportObject();
169 static wxLayoutStyleInfo
*s_si
= NULL
;
171 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
173 export
->type
= WXLO_EXPORT_OBJECT
;
174 export
->content
.object
= *from
;
179 String
*str
= new String();
181 // text must be concatenated
182 while(from
!= list
.end() && WXLO_IS_TEXT(type
))
187 *str
+= ((wxLayoutObjectText
*)*from
)->GetText();
189 case WXLO_TYPE_LINEBREAK
:
190 if(mode
== WXLO_EXPORT_AS_HTML
)
195 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
196 "reached cmd object in text mode" );
198 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
201 default: // ignore icons
205 if(from
!= list
.end())
206 type
= (*from
)->GetType();
208 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
) ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
209 export
->content
.text
= str
;