]>
git.saurik.com Git - wxWidgets.git/blob - user/wxLayout/wxlparser.cpp
316247bfc0004c27c084da7663347e8d98ebd246
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
)
33 // the end of line is either just '\n' or "\r\n" - we understand both (even
34 // though the second is used only under DOS/Windows) to be able to import
35 // DOS text files even under Unix
36 return (*p
== '\n') || ((*p
== '\r') && (*(p
+ 1) == '\n'));
39 void wxLayoutImportText(wxLayoutList
*list
, wxString
const &str
)
44 // we change the string temporarily inside this function
45 wxString
& s
= (wxString
&)str
; // const_cast
47 char * cptr
= s
.GetWriteBuf(s
.Len());
48 const char * begin
= cptr
;
54 while( *cptr
&& !IsEndOfLine(cptr
) )
61 // check if it's the end of this line
62 if ( IsEndOfLine(cptr
) )
64 // if it was "\r\n", skip the following '\n'
69 else if(backup
== '\0') // reached end of string
78 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
79 wxLayoutStyleInfo
*styleInfo
)
81 static char buffer
[20];
84 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
93 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->m_fg
.Red(),si
->m_fg
.Green(),si
->m_fg
.Blue());
100 sprintf(buffer
,"\"#%02X%02X%02X\"", si
->m_bg
.Red(),si
->m_bg
.Green(),si
->m_bg
.Blue());
108 html
+= " face=\"Arial,Helvetica\""; break;
110 html
+= " face=\"Times New Roman, Times\""; break;
112 html
+= " face=\"Courier New, Courier\""; break;
117 size
= BASE_SIZE
; sizecount
= 0;
118 while(size
< si
->size
&& sizecount
< 5)
123 while(size
> si
->size
&& sizecount
> -5)
129 sprintf(buffer
,"%+1d", sizecount
);
134 if(styleInfo
!= NULL
)
135 html
="</font>"+html
; // terminate any previous font command
137 if((si
->weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
140 if(si
->weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
143 if(si
->style
== wxSLANT
)
144 si
->style
= wxITALIC
; // the same for html
146 if((si
->style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
149 if(si
->style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
152 if(si
->underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
154 else if(si
->underline
== false && ( styleInfo
&& styleInfo
->underline
))
158 *styleInfo
= *si
; // update last style info
165 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
167 m_si
= list
->GetDefaultStyleInfo();
168 m_line
= list
->GetFirstLine();
169 m_iterator
= m_line
->GetFirstObject();
174 #define WXLO_IS_TEXT(type) \
175 ( type == WXLO_TYPE_TEXT \
176 || (type == WXLO_TYPE_CMD \
177 && mode == WXLO_EXPORT_AS_HTML))
180 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
184 wxLayoutExportObject
* export
;
186 if(status
->m_iterator
== NULLIT
) // end of line
188 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
189 // reached end of list
192 export
= new wxLayoutExportObject();
193 wxLayoutObjectType type
;
194 if(status
->m_iterator
!= NULLIT
)
196 type
= (** status
->m_iterator
).GetType();
197 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
199 export
->type
= WXLO_EXPORT_OBJECT
;
200 export
->content
.object
= *status
->m_iterator
;
201 status
->m_iterator
++;
206 { // iterator == NULLIT
207 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
209 export
->type
= WXLO_EXPORT_EMPTYLINE
;
210 export
->content
.object
= NULL
; //empty line
211 status
->m_line
= status
->m_line
->GetNextLine();
213 status
->m_iterator
= status
->m_line
->GetFirstObject();
217 type
= WXLO_TYPE_TEXT
;
220 wxString
*str
= new wxString();
221 // text must be concatenated
224 while(status
->m_iterator
== NULLIT
)
226 if(flags
& WXLO_EXPORT_AS_HTML
)
228 if(flags
& WXLO_EXPORT_WITH_CRLF
)
233 status
->m_line
= status
->m_line
->GetNextLine();
235 status
->m_iterator
= status
->m_line
->GetFirstObject();
237 break; // end of list
239 if(! status
->m_line
) // reached end of list, fall through
241 type
= (** status
->m_iterator
).GetType();
242 if(type
== WXLO_TYPE_ICON
)
247 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
250 if(mode
== WXLO_EXPORT_AS_HTML
)
251 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
252 *)*status
->m_iterator
, & status
->m_si
);
254 default: // ignore icons
257 status
->m_iterator
++;
260 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
261 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
262 export
->content
.text
= str
;