]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlparser.cpp
c5705745a4c3278fc8d4207f29cc3b741875a6ad
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 wxChar
*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 only temporarily inside this function
45 // VZ: I still don't like it... the string data may be shared...
46 wxChar
* cptr
= (wxChar
*)str
.c_str(); // const_cast
47 const wxChar
* 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
76 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
77 wxLayoutStyleInfo
*styleInfo
,
80 static wxChar buffer
[20];
83 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
92 wxSprintf(buffer
,_T("\"#%02X%02X%02X\""), si
->m_fg
.Red(),si
->m_fg
.Green(),si
->m_fg
.Blue());
98 html
+= _T(" bgcolor=");
99 wxSprintf(buffer
,_T("\"#%02X%02X%02X\""), si
->m_bg
.Red(),si
->m_bg
.Green(),si
->m_bg
.Blue());
107 html
+= _T(" face=\"Arial,Helvetica\""); break;
109 html
+= _T(" face=\"Times New Roman, Times\""); break;
111 html
+= _T(" face=\"Courier New, Courier\""); break;
116 size
= BASE_SIZE
; sizecount
= 0;
117 while(size
< si
->size
&& sizecount
< 5)
122 while(size
> si
->size
&& sizecount
> -5)
128 wxSprintf(buffer
,_T("%+1d"), sizecount
);
133 if(styleInfo
!= NULL
&& ! firstTime
)
134 html
= _T("</font>")+html
; // terminate any previous font command
136 if((si
->weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
139 if(si
->weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
142 if(si
->style
== wxSLANT
)
143 si
->style
= wxITALIC
; // the same for html
145 if((si
->style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
148 if(si
->style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
151 if(si
->underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
153 else if(si
->underline
== false && ( styleInfo
&& styleInfo
->underline
))
157 *styleInfo
= *si
; // update last style info
164 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
166 m_si
= list
->GetDefaultStyleInfo();
167 m_line
= list
->GetFirstLine();
168 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
,
183 wxLayoutObjectList::iterator
nulled(NULL
);
185 wxLayoutExportObject
* exp
;
187 if(status
->m_iterator
== nulled
) // end of line
189 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
190 // reached end of list
193 exp
= new wxLayoutExportObject();
194 wxLayoutObjectType type
;
195 if(status
->m_iterator
!= nulled
)
197 type
= (** status
->m_iterator
).GetType();
198 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
200 exp
->type
= WXLO_EXPORT_OBJECT
;
201 exp
->content
.object
= *status
->m_iterator
;
202 status
->m_iterator
++;
207 { // iterator == nulled
208 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
210 exp
->type
= WXLO_EXPORT_EMPTYLINE
;
211 exp
->content
.object
= NULL
; //empty line
212 status
->m_line
= status
->m_line
->GetNextLine();
214 status
->m_iterator
= status
->m_line
->GetFirstObject();
218 type
= WXLO_TYPE_TEXT
;
222 wxString
*str
= new wxString();
223 // text must be concatenated
226 while(status
->m_iterator
== nulled
)
228 if(mode
& 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 if(mode
== WXLO_EXPORT_AS_HTML
)
253 *str
+= wxLayoutExportCmdAsHTML(
254 *(wxLayoutObjectCmd
const *)*status
->m_iterator
,
255 & status
->m_si
, status
->m_FirstTime
);
256 status
->m_FirstTime
= false;
258 default: // ignore icons
261 status
->m_iterator
++;
263 exp
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
264 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
265 exp
->content
.text
= str
;