]>
git.saurik.com Git - wxWidgets.git/blob - samples/richedit/wxlparser.cpp
1 /*-*- c++ -*-********************************************************
2 * wxlparser.h : parsers, import/export for wxLayoutList *
4 * (C) 1998,1999 by Karsten Ballüder (Ballueder@usa.net) *
7 *******************************************************************/
18 # include "gui/wxllist.h"
19 # include "gui/wxlparser.h"
22 # include "wxlparser.h"
27 inline static bool IsEndOfLine(const wxChar
*p
)
29 // the end of line is either just '\n' or "\r\n" - we understand both (even
30 // though the second is used only under DOS/Windows) to be able to import
31 // DOS text files even under Unix
32 return (*p
== '\n') || ((*p
== '\r') && (*(p
+ 1) == '\n'));
35 void wxLayoutImportText(wxLayoutList
*list
, wxString
const &str
)
40 // we change the string only temporarily inside this function
41 // VZ: I still don't like it... the string data may be shared...
42 wxChar
* cptr
= (wxChar
*)str
.c_str(); // const_cast
43 const wxChar
* begin
= cptr
;
50 while( *cptr
&& !IsEndOfLine(cptr
) )
57 // check if it's the end of this line
58 if ( IsEndOfLine(cptr
) )
60 // if it was "\r\n", skip the following '\n'
65 else if(backup
== '\0') // reached end of string
72 wxString
wxLayoutExportCmdAsHTML(wxLayoutObjectCmd
const & cmd
,
73 wxLayoutStyleInfo
*styleInfo
,
76 static wxChar buffer
[20];
79 wxLayoutStyleInfo
*si
= cmd
.GetStyle();
88 wxSprintf(buffer
,_T("\"#%02X%02X%02X\""), si
->m_fg
.Red(),si
->m_fg
.Green(),si
->m_fg
.Blue());
94 html
+= _T(" bgcolor=");
95 wxSprintf(buffer
,_T("\"#%02X%02X%02X\""), si
->m_bg
.Red(),si
->m_bg
.Green(),si
->m_bg
.Blue());
103 html
+= _T(" face=\"Arial,Helvetica\""); break;
105 html
+= _T(" face=\"Times New Roman, Times\""); break;
107 html
+= _T(" face=\"Courier New, Courier\""); break;
112 size
= BASE_SIZE
; sizecount
= 0;
113 while(size
< si
->size
&& sizecount
< 5)
118 while(size
> si
->size
&& sizecount
> -5)
124 wxSprintf(buffer
,_T("%+1d"), sizecount
);
129 if(styleInfo
!= NULL
&& ! firstTime
)
130 html
= _T("</font>")+html
; // terminate any previous font command
132 if((si
->weight
== wxBOLD
) && ( (!styleInfo
) || (styleInfo
->weight
!= wxBOLD
)))
135 if(si
->weight
!= wxBOLD
&& ( styleInfo
&& (styleInfo
->weight
== wxBOLD
)))
138 if(si
->style
== wxSLANT
)
139 si
->style
= wxITALIC
; // the same for html
141 if((si
->style
== wxITALIC
) && ( (!styleInfo
) || (styleInfo
->style
!= wxITALIC
)))
144 if(si
->style
!= wxITALIC
&& ( styleInfo
&& (styleInfo
->style
== wxITALIC
)))
147 if(si
->underline
&& ( (!styleInfo
) || ! styleInfo
->underline
))
149 else if(si
->underline
== false && ( styleInfo
&& styleInfo
->underline
))
153 *styleInfo
= *si
; // update last style info
160 wxLayoutExportStatus::wxLayoutExportStatus(wxLayoutList
*list
)
162 m_si
= list
->GetDefaultStyleInfo();
163 m_line
= list
->GetFirstLine();
164 m_iterator
= m_line
->GetFirstObject();
170 #define WXLO_IS_TEXT(type) \
171 ( type == WXLO_TYPE_TEXT \
172 || (type == WXLO_TYPE_CMD \
173 && mode == WXLO_EXPORT_AS_HTML))
176 wxLayoutExportObject
*wxLayoutExport(wxLayoutExportStatus
*status
,
179 wxLayoutObjectList::iterator
nulled(NULL
);
181 wxLayoutExportObject
* exp
;
183 if(status
->m_iterator
== nulled
) // end of line
185 if(!status
->m_line
|| status
->m_line
->GetNextLine() == NULL
)
186 // reached end of list
189 exp
= new wxLayoutExportObject();
190 wxLayoutObjectType type
;
191 if(status
->m_iterator
!= nulled
)
193 type
= (** status
->m_iterator
).GetType();
194 if( mode
== WXLO_EXPORT_AS_OBJECTS
|| ! WXLO_IS_TEXT(type
)) // simple case
196 exp
->type
= WXLO_EXPORT_OBJECT
;
197 exp
->content
.object
= *status
->m_iterator
;
198 status
->m_iterator
++;
203 { // iterator == nulled
204 if(mode
== WXLO_EXPORT_AS_OBJECTS
)
206 exp
->type
= WXLO_EXPORT_EMPTYLINE
;
207 exp
->content
.object
= NULL
; //empty line
208 status
->m_line
= status
->m_line
->GetNextLine();
210 status
->m_iterator
= status
->m_line
->GetFirstObject();
214 type
= WXLO_TYPE_TEXT
;
218 wxString
*str
= new wxString();
219 // text must be concatenated
222 while(status
->m_iterator
== nulled
)
224 if(mode
& WXLO_EXPORT_AS_HTML
)
226 if(flags
& WXLO_EXPORT_WITH_CRLF
)
231 status
->m_line
= status
->m_line
->GetNextLine();
233 status
->m_iterator
= status
->m_line
->GetFirstObject();
235 break; // end of list
237 if(! status
->m_line
) // reached end of list, fall through
239 type
= (** status
->m_iterator
).GetType();
240 if(type
== WXLO_TYPE_ICON
)
245 *str
+= ((wxLayoutObjectText
*)*status
->m_iterator
)->GetText();
248 if(mode
== WXLO_EXPORT_AS_HTML
)
249 *str
+= wxLayoutExportCmdAsHTML(
250 *(wxLayoutObjectCmd
const *)*status
->m_iterator
,
251 & status
->m_si
, status
->m_FirstTime
);
252 status
->m_FirstTime
= false;
254 default: // ignore icons
257 status
->m_iterator
++;
259 exp
->type
= (mode
== WXLO_EXPORT_AS_HTML
)
260 ? WXLO_EXPORT_HTML
: WXLO_EXPORT_TEXT
;
261 exp
->content
.text
= str
;