]>
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
)
37 char * cptr
= (char *)str
.c_str(); // string gets changed only temporarily
38 const char * begin
= cptr
;
44 while( *cptr
&& !IsEndOfLine(cptr
, withflag
) )
51 // check if it's the end of this line
52 if ( IsEndOfLine(cptr
, withflag
) )
54 // if it was "\r\n", skip the following '\n'
59 else if(backup
== '\0') // reached end of string
66 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
67 wxLayoutStyleInfo
*styleInfo
)
69 static char buffer
[20];
80 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.fg_red
,si
.fg_green
,si
.fg_blue
);
85 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.bg_red
,si
.bg_green
,si
.bg_blue
);
92 html
+= " face=\"Arial,Helvetica\""; break;
94 html
+= " face=\"Times New Roman, Times\""; break;
96 html
+= " face=\"Courier New, Courier\""; break;
101 size
= BASE_SIZE
; sizecount
= 0;
102 while(size
< si
.size
&& sizecount
< 5)
107 while(size
> si
.size
&& sizecount
> -5)
113 sprintf(buffer
,"%+1d", sizecount
);
118 if(styleInfo
!= NULL
)
119 html
="</font>"+html
; // terminate any previous font command
121 if((si
.weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
124 if(si
.weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
127 if(si
.style
== wxSLANT
)
128 si
.style
= wxITALIC
; // the same for html
130 if((si
.style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
133 if(si
.style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
136 if(si
.underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
138 else if(si
.underline
== false && ( styleInfo
&& styleInfo
->underline
))
142 *styleInfo
= si
; // update last style info
149 #define WXLO_IS_TEXT(type) \
150 ( type == WXLO_TYPE_TEXT \
151 || (type == WXLO_TYPE_CMD \
152 && mode == WXLO_EXPORT_AS_HTML))
156 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
160 wxLayoutExportObject
* export
;
162 if(status
->m_iterator
== NULLIT
) // end of line
164 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
165 // reached end of list
168 export
= new wxLayoutExportObject();
169 wxLayoutObjectType type
;
170 if(status
->m_iterator
!= NULLIT
)
172 type
= (** status
->m_iterator
).GetType();
173 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
175 export
->type
= WXLO_EXPORT_OBJECT
;
176 export
->content
.object
= *status
->m_iterator
;
177 status
->m_iterator
++;
182 { // iterator == NULLIT
183 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
185 export
->type
= WXLO_EXPORT_EMPTYLINE
;
186 export
->content
.object
= NULL
; //empty line
187 status
->m_line
= status
->m_line
->GetNextLine();
189 status
->m_iterator
= status
->m_line
->GetFirstObject();
193 type
= WXLO_TYPE_TEXT
;
196 wxString
*str
= new wxString();
197 // text must be concatenated
198 int testf
= WXLO_EXPORT_WITH_CRLF
;
201 while(status
->m_iterator
== NULLIT
)
203 if(flags
& WXLO_EXPORT_AS_HTML
)
205 if(flags
& WXLO_EXPORT_WITH_CRLF
)
210 status
->m_line
= status
->m_line
->GetNextLine();
212 status
->m_iterator
= status
->m_line
->GetFirstObject();
214 break; // end of list
216 if(! status
->m_line
) // reached end of list, fall through
218 type
= (** status
->m_iterator
).GetType();
219 if(type
== WXLO_TYPE_ICON
)
224 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
227 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
228 "reached cmd object in text mode" );
230 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
231 *)*status
->m_iterator
, & status
->m_si
);
233 default: // ignore icons
236 status
->m_iterator
++;
239 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
240 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
241 export
->content
.text
= str
;