]>
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 //-----------------------------------------------------------------------------
37 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinParser
,wxHtmlParser
)
39 wxList
wxHtmlWinParser::m_Modules
;
41 wxHtmlWinParser::wxHtmlWinParser(wxWindow
*wnd
) : wxHtmlParser()
46 m_CharHeight
= m_CharWidth
= 0;
51 for (i
= 0; i
< 2; i
++)
52 for (j
= 0; j
< 2; j
++)
53 for (k
= 0; k
< 2; k
++)
54 for (l
= 0; l
< 2; l
++)
55 for (m
= 0; m
< 7; m
++)
56 m_FontsTable
[i
][j
][k
][l
][m
] = NULL
;
58 int default_sizes
[7] = {7, 8, 10, 12, 16, 22, 30};
60 int default_sizes
[7] = {10, 12, 14, 16, 19, 24, 32};
62 SetFonts("", wxSLANT
, "", wxSLANT
, default_sizes
);
65 // fill in wxHtmlParser's tables:
66 wxNode
*node
= m_Modules
.GetFirst();
68 wxHtmlTagsModule
*mod
= (wxHtmlTagsModule
*) node
-> GetData();
69 mod
-> FillHandlersTable(this);
70 node
= node
-> GetNext();
76 void wxHtmlWinParser::AddModule(wxHtmlTagsModule
*module)
78 m_Modules
.Append(module);
83 void wxHtmlWinParser::SetFonts(wxString normal_face
, int normal_italic_mode
, wxString fixed_face
, int fixed_italic_mode
, int *sizes
)
85 for (int i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
86 m_FontFaceFixed
= fixed_face
;
87 m_FontFaceNormal
= normal_face
;
88 m_ItalicModeFixed
= fixed_italic_mode
;
89 m_ItalicModeNormal
= normal_italic_mode
;
94 void wxHtmlWinParser::InitParser(const wxString
& source
)
96 wxHtmlParser::InitParser(source
);
97 wxASSERT_MSG(m_DC
!= NULL
, _("no DC assigned to wxHtmlWinParser!!"));
99 m_FontBold
= m_FontItalic
= m_FontUnderlined
= m_FontFixed
= FALSE
;
101 CreateCurrentFont(); // we're selecting default font into
102 m_DC
-> GetTextExtent("H", &m_CharWidth
, &m_CharHeight
);
103 /* NOTE : we're not using GetCharWidth/Height() because
104 of differences under X and win
108 m_LinkColor
.Set(0, 0, 0xFF);
109 m_ActualColor
.Set(0, 0, 0);
110 m_Align
= HTML_ALIGN_LEFT
;
111 m_tmpLastWasSpace
= FALSE
;
116 m_Container
-> InsertCell(new wxHtmlColourCell(m_ActualColor
));
117 m_Container
-> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
122 void wxHtmlWinParser::DoneParser()
125 wxHtmlParser::DoneParser();
130 wxObject
* wxHtmlWinParser::GetProduct()
132 wxHtmlContainerCell
*top
;
136 GetContainer() -> SetIndent(m_CharHeight
, HTML_INDENT_TOP
);
138 while (top
-> GetParent()) top
= top
-> GetParent();
144 wxList
* wxHtmlWinParser::GetTempData()
148 wxList
*lst
= wxHtmlParser::GetTempData();
150 if (lst
== NULL
) lst
= new wxList
;
151 lst
-> DeleteContents(TRUE
);
153 for (i
= 0; i
< 2; i
++)
154 for (j
= 0; j
< 2; j
++)
155 for (k
= 0; k
< 2; k
++)
156 for (l
= 0; l
< 2; l
++)
157 for (m
= 0; m
< 7; m
++) {
158 f
= m_FontsTable
[i
][j
][k
][l
][m
];
159 if (f
) lst
-> Append(f
);
166 void wxHtmlWinParser::AddText(const char* txt
)
169 int i
= 0, x
, lng
= strlen(txt
);
170 char temp
[HTML_BUFLEN
];
174 if (m_tmpLastWasSpace
) {
175 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++;
180 d
= temp
[templen
++] = txt
[i
];
181 if ((d
== '\n') || (d
== '\r') || (d
== ' ') || (d
== '\t')) {
183 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++, x
++;
188 temp
[templen
-1] = ' ';
191 c
= new wxHtmlWordCell(temp
, *(GetDC()));
192 if (m_UseLink
) c
-> SetLink(m_Link
);
193 m_Container
-> InsertCell(c
);
194 m_tmpLastWasSpace
= TRUE
;
199 c
= new wxHtmlWordCell(temp
, *(GetDC()));
200 if (m_UseLink
) c
-> SetLink(m_Link
);
201 m_Container
-> InsertCell(c
);
202 m_tmpLastWasSpace
= FALSE
;
208 wxHtmlContainerCell
* wxHtmlWinParser::OpenContainer()
210 m_Container
= new wxHtmlContainerCell(m_Container
);
211 m_Container
-> SetAlignHor(m_Align
);
212 m_tmpLastWasSpace
= TRUE
;
213 /* to avoid space being first character in paragraph */
219 wxHtmlContainerCell
* wxHtmlWinParser::SetContainer(wxHtmlContainerCell
*c
)
221 m_tmpLastWasSpace
= TRUE
;
222 /* to avoid space being first character in paragraph */
223 return m_Container
= c
;
228 wxHtmlContainerCell
* wxHtmlWinParser::CloseContainer()
230 m_Container
= m_Container
-> GetParent();
236 wxFont
* wxHtmlWinParser::CreateCurrentFont()
238 int fb
= GetFontBold(),
239 fi
= GetFontItalic(),
240 fu
= GetFontUnderlined(),
242 fs
= GetFontSize() + 2 /*remap from <-2;4> to <0;7>*/ ;
244 if (m_FontsTable
[fb
][fi
][fu
][ff
][fs
] == NULL
) {
245 m_FontsTable
[fb
][fi
][fu
][ff
][fs
] =
246 //wxTheFontList -> FindOrCreateFont(
249 ff
? wxMODERN
: wxSWISS
,
250 fi
? (ff
? m_ItalicModeFixed
: m_ItalicModeNormal
) : wxNORMAL
,
251 fb
? wxBOLD
: wxNORMAL
,
252 fu
? TRUE
: FALSE
, ff
? m_FontFaceFixed
: m_FontFaceNormal
);
254 m_DC
-> SetFont(*(m_FontsTable
[fb
][fi
][fu
][ff
][fs
]));
255 return (m_FontsTable
[fb
][fi
][fu
][ff
][fs
]);
261 //-----------------------------------------------------------------------------
262 // wxHtmlWinTagHandler
263 //-----------------------------------------------------------------------------
265 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler
, wxHtmlTagHandler
)
269 //-----------------------------------------------------------------------------
271 //-----------------------------------------------------------------------------
274 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule
, wxModule
)
277 bool wxHtmlTagsModule::OnInit()
279 wxHtmlWinParser::AddModule(this);
285 void wxHtmlTagsModule::OnExit()