]>
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"
14 #include "wxlparser.h"
18 void wxLayoutImportText(wxLayoutList
&list
, String
const &str
)
20 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
21 const char * begin
= cptr
;
27 while(*cptr
&& *cptr
!= '\n')
35 else if(backup
== '\0') // reached end of string
42 String
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
43 wxLayoutStyleInfo
**lastStylePtr
)
45 static char buffer
[20];
48 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
49 wxLayoutStyleInfo
*last_si
= NULL
;
53 if(lastStylePtr
!= NULL
)
54 last_si
= *lastStylePtr
;
59 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->fg_red
,si
->fg_green
,si
->fg_blue
);
64 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->bg_red
,si
->bg_green
,si
->bg_blue
);
71 html
+= " face=\"Arial,Helvetica\""; break;
73 html
+= " face=\"Times New Roman, Times\""; break;
75 html
+= " face=\"Courier New, Courier\""; break;
80 size
= BASE_SIZE
; sizecount
= 0;
81 while(size
< si
->size
&& sizecount
< 5)
86 while(size
> si
->size
&& sizecount
> -5)
92 sprintf(buffer
,"%+1d", sizecount
);
98 html
="</font>"+html
; // terminate any previous font command
100 if((si
->weight
== wxBOLD
) && ( (!last_si
) || (last_si
->weight
!= wxBOLD
)))
103 if(si
->weight
!= wxBOLD
&& ( last_si
&& (last_si
->weight
== wxBOLD
)))
106 if(si
->style
== wxSLANT
)
107 si
->style
= wxITALIC
; // the same for html
109 if((si
->style
== wxITALIC
) && ( (!last_si
) || (last_si
->style
!= wxITALIC
)))
112 if(si
->style
!= wxITALIC
&& ( last_si
&& (last_si
->style
== wxITALIC
)))
115 if(si
->underline
&& ( (!last_si
) || ! last_si
->underline
))
117 else if(si
->underline
== false && ( last_si
&& last_si
->underline
))
128 #define WXLO_IS_TEXT(type) \
129 ( (type == WXLO_TYPE_TEXT || type == WXLO_TYPE_LINEBREAK) \
130 || (type == WXLO_TYPE_CMD \
131 && mode == WXLO_EXPORT_AS_HTML))
135 wxLayoutExportObject
*wxLayoutExport(wxLayoutList
&list
,
136 wxLayoutList::iterator
&from
,
137 wxLayoutExportMode mode
)
139 if(from
== list
.end())
142 wxLayoutObjectType type
= (*from
)->GetType();
143 wxLayoutExportObject
* export
= new wxLayoutExportObject();
145 static wxLayoutStyleInfo
*s_si
= NULL
;
147 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
149 export
->type
= WXLO_EXPORT_OBJECT
;
150 export
->content
.object
= *from
;
155 String
*str
= new String();
157 // text must be concatenated
158 while(from
!= list
.end() && WXLO_IS_TEXT(type
))
163 *str
+= ((wxLayoutObjectText
*)*from
)->GetText();
165 case WXLO_TYPE_LINEBREAK
:
166 if(mode
== WXLO_EXPORT_AS_HTML
)
171 //wxASSERT(mode == WXLO_EXPORT_AS_HTML,"reached cmd object in text mode")
172 assert(mode
== WXLO_EXPORT_AS_HTML
);
173 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
176 default: // ignore icons
180 if(from
!= list
.end())
181 type
= (*from
)->GetType();
183 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
) ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
184 export
->content
.text
= str
;