]>
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];
82 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.fg_red
,si
.fg_green
,si
.fg_blue
);
87 sprintf(buffer
,"\"#%02X%02X%02X\"", si
.bg_red
,si
.bg_green
,si
.bg_blue
);
94 html
+= " face=\"Arial,Helvetica\""; break;
96 html
+= " face=\"Times New Roman, Times\""; break;
98 html
+= " face=\"Courier New, Courier\""; break;
103 size
= BASE_SIZE
; sizecount
= 0;
104 while(size
< si
.size
&& sizecount
< 5)
109 while(size
> si
.size
&& sizecount
> -5)
115 sprintf(buffer
,"%+1d", sizecount
);
120 if(styleInfo
!= NULL
)
121 html
="</font>"+html
; // terminate any previous font command
123 if((si
.weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
126 if(si
.weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
129 if(si
.style
== wxSLANT
)
130 si
.style
= wxITALIC
; // the same for html
132 if((si
.style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
135 if(si
.style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
138 if(si
.underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
140 else if(si
.underline
== false && ( styleInfo
&& styleInfo
->underline
))
144 *styleInfo
= si
; // update last style info
151 #define WXLO_IS_TEXT(type) \
152 ( type == WXLO_TYPE_TEXT \
153 || (type == WXLO_TYPE_CMD \
154 && mode == WXLO_EXPORT_AS_HTML))
158 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
162 wxLayoutExportObject
* export
;
164 if(status
->m_iterator
== NULLIT
) // end of line
166 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
167 // reached end of list
170 export
= new wxLayoutExportObject();
171 wxLayoutObjectType type
;
172 if(status
->m_iterator
!= NULLIT
)
174 type
= (** status
->m_iterator
).GetType();
175 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
177 export
->type
= WXLO_EXPORT_OBJECT
;
178 export
->content
.object
= *status
->m_iterator
;
179 status
->m_iterator
++;
184 { // iterator == NULLIT
185 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
187 export
->type
= WXLO_EXPORT_EMPTYLINE
;
188 export
->content
.object
= NULL
; //empty line
189 status
->m_line
= status
->m_line
->GetNextLine();
191 status
->m_iterator
= status
->m_line
->GetFirstObject();
195 type
= WXLO_TYPE_TEXT
;
198 wxString
*str
= new wxString();
199 // text must be concatenated
200 int testf
= WXLO_EXPORT_WITH_CRLF
;
203 while(status
->m_iterator
== NULLIT
)
205 if(flags
& WXLO_EXPORT_AS_HTML
)
207 if(flags
& WXLO_EXPORT_WITH_CRLF
)
212 status
->m_line
= status
->m_line
->GetNextLine();
214 status
->m_iterator
= status
->m_line
->GetFirstObject();
216 break; // end of list
218 if(! status
->m_line
) // reached end of list, fall through
220 type
= (** status
->m_iterator
).GetType();
221 if(type
== WXLO_TYPE_ICON
)
226 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
229 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
230 "reached cmd object in text mode" );
232 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
233 *)*status
->m_iterator
, & status
->m_si
);
235 default: // ignore icons
238 status
->m_iterator
++;
241 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
242 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
243 export
->content
.text
= str
;