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
,
155 list
->GetDefaults()->GetStyle(&m_si
);
156 m_line
= list
->GetFirstLine();
157 m_iterator
= m_line
->GetFirstObject();
161 if(m_fromPos
.x
!= -1)
163 while(m_line
&& m_line
->GetLineNumber() != m_fromPos
.y
)
164 m_line
= m_line
->GetNextLine();
167 m_iterator
= m_line
->FindObject(fromPos
.x
, &dummy
);
173 #define WXLO_IS_TEXT(type) \
174 ( type == WXLO_TYPE_TEXT \
175 || (type == WXLO_TYPE_CMD \
176 && mode == WXLO_EXPORT_AS_HTML))
180 extern const wxPoint wxLayoutExportNoPosition
= wxPoint(-1,-1);
182 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
186 wxLayoutExportObject
* export
;
188 if(status
->m_iterator
== NULLIT
) // end of line
190 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
191 // reached end of list
194 export
= new wxLayoutExportObject();
195 wxLayoutObjectType type
;
196 if(status
->m_iterator
!= NULLIT
)
198 type
= (** status
->m_iterator
).GetType();
199 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
201 export
->type
= WXLO_EXPORT_OBJECT
;
202 export
->content
.object
= *status
->m_iterator
;
203 status
->m_iterator
++;
208 { // iterator == NULLIT
209 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
211 export
->type
= WXLO_EXPORT_EMPTYLINE
;
212 export
->content
.object
= NULL
; //empty line
213 status
->m_line
= status
->m_line
->GetNextLine();
215 status
->m_iterator
= status
->m_line
->GetFirstObject();
219 type
= WXLO_TYPE_TEXT
;
222 wxString
*str
= new wxString();
223 // text must be concatenated
226 while(status
->m_iterator
== NULLIT
)
228 if(flags
& WXLO_EXPORT_AS_HTML
)
230 if(flags
& WXLO_EXPORT_WITH_CRLF
)
235 status
->m_line
= status
->m_line
->GetNextLine();
237 status
->m_iterator
= status
->m_line
->GetFirstObject();
239 break; // end of list
241 if(! status
->m_line
) // reached end of list, fall through
243 type
= (** status
->m_iterator
).GetType();
244 if(type
== WXLO_TYPE_ICON
)
249 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
252 wxASSERT_MSG( mode
== WXLO_EXPORT_AS_HTML
,
253 "reached cmd object in text mode" );
255 *str
+= wxLayoutExportCmdAsHTML(*(wxLayoutObjectCmd
const
256 *)*status
->m_iterator
, & status
->m_si
);
258 default: // ignore icons
261 status
->m_iterator
++;
264 export
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
265 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
266 export
->content
.text
= str
;