]>
git.saurik.com Git - wxWidgets.git/blob - src/html/winpars.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
12 #pragma implementation
15 #include "wx/wxprec.h"
28 #include "wx/html/htmldefs.h"
29 #include "wx/html/winpars.h"
30 #include "wx/html/htmlwin.h"
33 //-----------------------------------------------------------------------------
35 //-----------------------------------------------------------------------------
38 wxList
wxHtmlWinParser::m_Modules
;
40 wxHtmlWinParser::wxHtmlWinParser(wxWindow
*wnd
) : wxHtmlParser()
45 m_CharHeight
= m_CharWidth
= 0;
50 for (i
= 0; i
< 2; i
++)
51 for (j
= 0; j
< 2; j
++)
52 for (k
= 0; k
< 2; k
++)
53 for (l
= 0; l
< 2; l
++)
54 for (m
= 0; m
< 7; m
++) {
55 m_FontsTable
[i
][j
][k
][l
][m
] = NULL
;
56 m_FontsFacesTable
[i
][j
][k
][l
][m
] = wxEmptyString
;
59 static int default_sizes
[7] = {7, 8, 10, 12, 16, 22, 30};
61 static int default_sizes
[7] = {10, 12, 14, 16, 19, 24, 32};
63 SetFonts("", "", default_sizes
);
66 // fill in wxHtmlParser's tables:
67 wxNode
*node
= m_Modules
.GetFirst();
69 wxHtmlTagsModule
*mod
= (wxHtmlTagsModule
*) node
-> GetData();
70 mod
-> FillHandlersTable(this);
71 node
= node
-> GetNext();
77 void wxHtmlWinParser::AddModule(wxHtmlTagsModule
*module)
79 m_Modules
.Append(module);
84 void wxHtmlWinParser::SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
)
88 for (i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
89 m_FontFaceFixed
= fixed_face
;
90 m_FontFaceNormal
= normal_face
;
92 for (i
= 0; i
< 2; i
++)
93 for (j
= 0; j
< 2; j
++)
94 for (k
= 0; k
< 2; k
++)
95 for (l
= 0; l
< 2; l
++)
96 for (m
= 0; m
< 7; m
++) {
97 if (m_FontsTable
[i
][j
][k
][l
][m
] != NULL
) {
98 delete m_FontsTable
[i
][j
][k
][l
][m
];
99 m_FontsTable
[i
][j
][k
][l
][m
] = NULL
;
106 void wxHtmlWinParser::InitParser(const wxString
& source
)
108 wxHtmlParser::InitParser(source
);
109 wxASSERT_MSG(m_DC
!= NULL
, _("no DC assigned to wxHtmlWinParser!!"));
111 m_FontBold
= m_FontItalic
= m_FontUnderlined
= m_FontFixed
= FALSE
;
112 m_FontSize
= 3; //default one
113 CreateCurrentFont(); // we're selecting default font into
114 m_DC
-> GetTextExtent("H", &m_CharWidth
, &m_CharHeight
);
115 /* NOTE : we're not using GetCharWidth/Height() because
116 of differences under X and win
120 m_Link
= wxHtmlLinkInfo("", "");
121 m_LinkColor
.Set(0, 0, 0xFF);
122 m_ActualColor
.Set(0, 0, 0);
123 m_Align
= wxHTML_ALIGN_LEFT
;
124 m_tmpLastWasSpace
= FALSE
;
129 m_Container
-> InsertCell(new wxHtmlColourCell(m_ActualColor
));
130 m_Container
-> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
135 void wxHtmlWinParser::DoneParser()
138 wxHtmlParser::DoneParser();
143 wxObject
* wxHtmlWinParser::GetProduct()
145 wxHtmlContainerCell
*top
;
149 GetContainer() -> SetIndent(m_CharHeight
, wxHTML_INDENT_TOP
);
151 while (top
-> GetParent()) top
= top
-> GetParent();
157 void wxHtmlWinParser::AddText(const char* txt
)
160 int i
= 0, x
, lng
= strlen(txt
);
161 char temp
[wxHTML_BUFLEN
];
165 if (m_tmpLastWasSpace
) {
166 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++;
171 d
= temp
[templen
++] = txt
[i
];
172 if ((d
== '\n') || (d
== '\r') || (d
== ' ') || (d
== '\t')) {
174 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++, x
++;
179 temp
[templen
-1] = ' ';
182 c
= new wxHtmlWordCell(temp
, *(GetDC()));
183 if (m_UseLink
) c
-> SetLink(m_Link
);
184 m_Container
-> InsertCell(c
);
185 m_tmpLastWasSpace
= TRUE
;
190 c
= new wxHtmlWordCell(temp
, *(GetDC()));
191 if (m_UseLink
) c
-> SetLink(m_Link
);
192 m_Container
-> InsertCell(c
);
193 m_tmpLastWasSpace
= FALSE
;
199 wxHtmlContainerCell
* wxHtmlWinParser::OpenContainer()
201 m_Container
= new wxHtmlContainerCell(m_Container
);
202 m_Container
-> SetAlignHor(m_Align
);
203 m_tmpLastWasSpace
= TRUE
;
204 /* to avoid space being first character in paragraph */
210 wxHtmlContainerCell
* wxHtmlWinParser::SetContainer(wxHtmlContainerCell
*c
)
212 m_tmpLastWasSpace
= TRUE
;
213 /* to avoid space being first character in paragraph */
214 return m_Container
= c
;
219 wxHtmlContainerCell
* wxHtmlWinParser::CloseContainer()
221 m_Container
= m_Container
-> GetParent();
226 void wxHtmlWinParser::SetFontSize(int s
)
229 else if (s
> 7) s
= 7;
235 wxFont
* wxHtmlWinParser::CreateCurrentFont()
237 int fb
= GetFontBold(),
238 fi
= GetFontItalic(),
239 fu
= GetFontUnderlined(),
241 fs
= GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
243 wxString face
= ff
? m_FontFaceFixed
: m_FontFaceNormal
;
244 wxString
*faceptr
= &(m_FontsFacesTable
[fb
][fi
][fu
][ff
][fs
]);
245 wxFont
**fontptr
= &(m_FontsTable
[fb
][fi
][fu
][ff
][fs
]);
247 if (*fontptr
!= NULL
&& *faceptr
!= face
) {
252 if (*fontptr
== NULL
) {
254 *fontptr
= new wxFont(
255 m_FontsSizes
[fs
] * m_PixelScale
,
256 ff
? wxMODERN
: wxSWISS
,
257 fi
? wxITALIC
: wxNORMAL
,
258 fb
? wxBOLD
: wxNORMAL
,
259 fu
? TRUE
: FALSE
, face
);
261 m_DC
-> SetFont(**fontptr
);
267 void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo
& link
)
270 m_UseLink
= (link
.GetHref() != wxEmptyString
);
276 //-----------------------------------------------------------------------------
277 // wxHtmlWinTagHandler
278 //-----------------------------------------------------------------------------
280 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler
, wxHtmlTagHandler
)
284 //-----------------------------------------------------------------------------
286 //-----------------------------------------------------------------------------
289 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule
, wxModule
)
292 bool wxHtmlTagsModule::OnInit()
294 wxHtmlWinParser::AddModule(this);
300 void wxHtmlTagsModule::OnExit()