]>
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 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
153 list
->GetDefaults()->GetStyle(&m_si
);
154 m_line
= list
->GetFirstLine();
155 m_iterator
= m_line
->GetFirstObject();
160 #define WXLO_IS_TEXT(type) \
161 ( type == WXLO_TYPE_TEXT \
162 || (type == WXLO_TYPE_CMD \
163 && mode == WXLO_EXPORT_AS_HTML))
166 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
170 wxLayoutExportObject
* export
;
172 if(status
->m_iterator
== NULLIT
) // end of line
174 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
175 // reached end of list
178 export
= new wxLayoutExportObject();
179 wxLayoutObjectType type
;
180 if(status
->m_iterator
!= NULLIT
)
182 type
= (** status
->m_iterator
).GetType();
183 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
185 export
->type
= WXLO_EXPORT_OBJECT
;
186 export
->content
.object
= *status
->m_iterator
;
187 status
->m_iterator
++;
192 { // iterator == NULLIT
193 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
195 export
->type
= WXLO_EXPORT_EMPTYLINE
;
196 export
->content
.object
= NULL
; //empty line
197 status
->m_line
= status
->m_line
->GetNextLine();
199 status
->m_iterator
= status
->m_line
->GetFirstObject();
203 type
= WXLO_TYPE_TEXT
;
206 wxString
*str
= new wxString();
207 // text must be concatenated
210 while(status
->m_iterator
== NULLIT
)
212 if(flags
& WXLO_EXPORT_AS_HTML
)
214 if(flags
& WXLO_EXPORT_WITH_CRLF
)
219 status
->m_line
= status
->m_line
->GetNextLine();
221 status
->m_iterator
= status
->m_line
->GetFirstObject();
223 break; // end of list
225 if(! status
->m_line
) // reached end of list, fall through
227 type
= (** status
->m_iterator
).GetType();
228 if(type
== WXLO_TYPE_ICON
)
233 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
236 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
237 "reached cmd object in text mode" );
239 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
240 *)*status
->m_iterator
, & status
->m_si
);
242 default: // ignore icons
245 status
->m_iterator
++;
248 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
249 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
250 export
->content
.text
= str
;