]>
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_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
)
39 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
40 const char * begin
= cptr
;
46 while( *cptr
&& !IsEndOfLine(cptr
, withflag
) )
53 // check if it's the end of this line
54 if ( IsEndOfLine(cptr
, withflag
) )
56 // if it was "\r\n", skip the following '\n'
61 else if(backup
== '\0') // reached end of string
68 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
69 wxLayoutStyleInfo
*styleInfo
)
71 static char buffer
[20];
74 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
83 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->fg_red
,si
->fg_green
,si
->fg_blue
);
90 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->bg_red
,si
->bg_green
,si
->bg_blue
);
98 html
+= " face=\"Arial,Helvetica\""; break;
100 html
+= " face=\"Times New Roman, Times\""; break;
102 html
+= " face=\"Courier New, Courier\""; break;
107 size
= BASE_SIZE
; sizecount
= 0;
108 while(size
< si
->size
&& sizecount
< 5)
113 while(size
> si
->size
&& sizecount
> -5)
119 sprintf(buffer
,"%+1d", sizecount
);
124 if(styleInfo
!= NULL
)
125 html
="</font>"+html
; // terminate any previous font command
127 if((si
->weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
130 if(si
->weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
133 if(si
->style
== wxSLANT
)
134 si
->style
= wxITALIC
; // the same for html
136 if((si
->style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
139 if(si
->style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
142 if(si
->underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
144 else if(si
->underline
== false && ( styleInfo
&& styleInfo
->underline
))
148 *styleInfo
= *si
; // update last style info
155 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
157 m_si
= *list
->GetDefaults();
158 m_line
= list
->GetFirstLine();
159 m_iterator
= m_line
->GetFirstObject();
164 #define WXLO_IS_TEXT(type) \
165 ( type == WXLO_TYPE_TEXT \
166 || (type == WXLO_TYPE_CMD \
167 && mode == WXLO_EXPORT_AS_HTML))
170 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
174 wxLayoutExportObject
* export
;
176 if(status
->m_iterator
== NULLIT
) // end of line
178 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
179 // reached end of list
182 export
= new wxLayoutExportObject();
183 wxLayoutObjectType type
;
184 if(status
->m_iterator
!= NULLIT
)
186 type
= (** status
->m_iterator
).GetType();
187 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
189 export
->type
= WXLO_EXPORT_OBJECT
;
190 export
->content
.object
= *status
->m_iterator
;
191 status
->m_iterator
++;
196 { // iterator == NULLIT
197 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
199 export
->type
= WXLO_EXPORT_EMPTYLINE
;
200 export
->content
.object
= NULL
; //empty line
201 status
->m_line
= status
->m_line
->GetNextLine();
203 status
->m_iterator
= status
->m_line
->GetFirstObject();
207 type
= WXLO_TYPE_TEXT
;
210 wxString
*str
= new wxString();
211 // text must be concatenated
214 while(status
->m_iterator
== NULLIT
)
216 if(flags
& WXLO_EXPORT_AS_HTML
)
218 if(flags
& WXLO_EXPORT_WITH_CRLF
)
223 status
->m_line
= status
->m_line
->GetNextLine();
225 status
->m_iterator
= status
->m_line
->GetFirstObject();
227 break; // end of list
229 if(! status
->m_line
) // reached end of list, fall through
231 type
= (** status
->m_iterator
).GetType();
232 if(type
== WXLO_TYPE_ICON
)
237 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
240 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
241 "reached cmd object in text mode" );
243 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
244 *)*status
->m_iterator
, & status
->m_si
);
246 default: // ignore icons
249 status
->m_iterator
++;
252 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
253 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
254 export
->content
.text
= str
;