]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlparser.cpp
3370fd5fc74bb9ef364fd58ec1664e55d510ca49
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"
13 #include <wx/wxprec.h>
22 # include "gui/wxllist.h"
23 # include "gui/wxlparser.h"
26 # include "wxlparser.h"
31 inline static bool IsEndOfLine(const char *p
, int mode
)
33 // in addition to Unix EOL convention we also (but not instead) understand
34 // the DOS one under Windows
36 (mode
== WXLO_EXPORT_WITH_CRLF
) ?
37 ((*p
== '\r') && (*(p
+ 1) == '\n'))
39 (((*p
== '\r') && (*(p
+ 1) == '\n'))||(*p
== '\n'));
42 void wxLayoutImportText(wxLayoutList
*list
, wxString
const &str
, int withflag
)
46 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
47 const char * begin
= cptr
;
53 while( *cptr
&& !IsEndOfLine(cptr
, withflag
) )
60 // check if it's the end of this line
61 if ( IsEndOfLine(cptr
, withflag
) )
63 // if it was "\r\n", skip the following '\n'
68 else if(backup
== '\0') // reached end of string
75 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
76 wxLayoutStyleInfo
*styleInfo
)
78 static char buffer
[20];
81 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
90 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->m_fg
.Red(),si
->m_fg
.Green(),si
->m_fg
.Blue());
97 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->m_bg
.Red(),si
->m_bg
.Green(),si
->m_bg
.Blue());
105 html
+= " face=\"Arial,Helvetica\""; break;
107 html
+= " face=\"Times New Roman, Times\""; break;
109 html
+= " face=\"Courier New, Courier\""; break;
114 size
= BASE_SIZE
; sizecount
= 0;
115 while(size
< si
->size
&& sizecount
< 5)
120 while(size
> si
->size
&& sizecount
> -5)
126 sprintf(buffer
,"%+1d", sizecount
);
131 if(styleInfo
!= NULL
)
132 html
="</font>"+html
; // terminate any previous font command
134 if((si
->weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
137 if(si
->weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
140 if(si
->style
== wxSLANT
)
141 si
->style
= wxITALIC
; // the same for html
143 if((si
->style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
146 if(si
->style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
149 if(si
->underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
151 else if(si
->underline
== false && ( styleInfo
&& styleInfo
->underline
))
155 *styleInfo
= *si
; // update last style info
162 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
164 m_si
= *list
->GetDefaults();
165 m_line
= list
->GetFirstLine();
166 m_iterator
= m_line
->GetFirstObject();
171 #define WXLO_IS_TEXT(type) \
172 ( type == WXLO_TYPE_TEXT \
173 || (type == WXLO_TYPE_CMD \
174 && mode == WXLO_EXPORT_AS_HTML))
177 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
181 wxLayoutExportObject
* export
;
183 if(status
->m_iterator
== NULLIT
) // end of line
185 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
186 // reached end of list
189 export
= new wxLayoutExportObject();
190 wxLayoutObjectType type
;
191 if(status
->m_iterator
!= NULLIT
)
193 type
= (** status
->m_iterator
).GetType();
194 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
196 export
->type
= WXLO_EXPORT_OBJECT
;
197 export
->content
.object
= *status
->m_iterator
;
198 status
->m_iterator
++;
203 { // iterator == NULLIT
204 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
206 export
->type
= WXLO_EXPORT_EMPTYLINE
;
207 export
->content
.object
= NULL
; //empty line
208 status
->m_line
= status
->m_line
->GetNextLine();
210 status
->m_iterator
= status
->m_line
->GetFirstObject();
214 type
= WXLO_TYPE_TEXT
;
217 wxString
*str
= new wxString();
218 // text must be concatenated
221 while(status
->m_iterator
== NULLIT
)
223 if(flags
& WXLO_EXPORT_AS_HTML
)
225 if(flags
& WXLO_EXPORT_WITH_CRLF
)
230 status
->m_line
= status
->m_line
->GetNextLine();
232 status
->m_iterator
= status
->m_line
->GetFirstObject();
234 break; // end of list
236 if(! status
->m_line
) // reached end of list, fall through
238 type
= (** status
->m_iterator
).GetType();
239 if(type
== WXLO_TYPE_ICON
)
244 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
247 if(mode
== WXLO_EXPORT_AS_HTML
)
248 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
249 *)*status
->m_iterator
, & status
->m_si
);
251 default: // ignore icons
254 status
->m_iterator
++;
257 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
258 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
259 export
->content
.text
= str
;