]>
git.saurik.com Git - wxWidgets.git/blob - src/html/winpars.cpp
3de90241e001ee2c052da51de66063461fba891e
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
;
57 static int default_sizes
[7] = {7, 8, 10, 12, 16, 22, 30};
59 static int default_sizes
[7] = {10, 12, 14, 16, 19, 24, 32};
61 SetFonts("", "", default_sizes
);
64 // fill in wxHtmlParser's tables:
65 wxNode
*node
= m_Modules
.GetFirst();
67 wxHtmlTagsModule
*mod
= (wxHtmlTagsModule
*) node
-> GetData();
68 mod
-> FillHandlersTable(this);
69 node
= node
-> GetNext();
75 void wxHtmlWinParser::AddModule(wxHtmlTagsModule
*module)
77 m_Modules
.Append(module);
82 void wxHtmlWinParser::SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
)
86 for (i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
87 m_FontFaceFixed
= fixed_face
;
88 m_FontFaceNormal
= normal_face
;
90 for (i
= 0; i
< 2; i
++)
91 for (j
= 0; j
< 2; j
++)
92 for (k
= 0; k
< 2; k
++)
93 for (l
= 0; l
< 2; l
++)
94 for (m
= 0; m
< 7; m
++) {
95 if (m_FontsTable
[i
][j
][k
][l
][m
] != NULL
) {
96 delete m_FontsTable
[i
][j
][k
][l
][m
];
97 m_FontsTable
[i
][j
][k
][l
][m
] = NULL
;
104 void wxHtmlWinParser::InitParser(const wxString
& source
)
106 wxHtmlParser::InitParser(source
);
107 wxASSERT_MSG(m_DC
!= NULL
, _("no DC assigned to wxHtmlWinParser!!"));
109 m_FontBold
= m_FontItalic
= m_FontUnderlined
= m_FontFixed
= FALSE
;
110 m_FontSize
= 3; //default one
111 CreateCurrentFont(); // we're selecting default font into
112 m_DC
-> GetTextExtent("H", &m_CharWidth
, &m_CharHeight
);
113 /* NOTE : we're not using GetCharWidth/Height() because
114 of differences under X and win
118 m_Link
= wxHtmlLinkInfo("", "");
119 m_LinkColor
.Set(0, 0, 0xFF);
120 m_ActualColor
.Set(0, 0, 0);
121 m_Align
= wxHTML_ALIGN_LEFT
;
122 m_tmpLastWasSpace
= FALSE
;
127 m_Container
-> InsertCell(new wxHtmlColourCell(m_ActualColor
));
128 m_Container
-> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
133 void wxHtmlWinParser::DoneParser()
136 wxHtmlParser::DoneParser();
141 wxObject
* wxHtmlWinParser::GetProduct()
143 wxHtmlContainerCell
*top
;
147 GetContainer() -> SetIndent(m_CharHeight
, wxHTML_INDENT_TOP
);
149 while (top
-> GetParent()) top
= top
-> GetParent();
155 wxList
* wxHtmlWinParser::GetTempData()
159 wxList
*lst
= wxHtmlParser::GetTempData();
161 if (lst
== NULL
) lst
= new wxList
;
162 lst
-> DeleteContents(TRUE
);
164 for (i
= 0; i
< 2; i
++)
165 for (j
= 0; j
< 2; j
++)
166 for (k
= 0; k
< 2; k
++)
167 for (l
= 0; l
< 2; l
++)
168 for (m
= 0; m
< 7; m
++) {
169 f
= m_FontsTable
[i
][j
][k
][l
][m
];
170 if (f
) lst
-> Append(f
);
177 void wxHtmlWinParser::AddText(const char* txt
)
180 int i
= 0, x
, lng
= strlen(txt
);
181 char temp
[wxHTML_BUFLEN
];
185 if (m_tmpLastWasSpace
) {
186 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++;
191 d
= temp
[templen
++] = txt
[i
];
192 if ((d
== '\n') || (d
== '\r') || (d
== ' ') || (d
== '\t')) {
194 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++, x
++;
199 temp
[templen
-1] = ' ';
202 c
= new wxHtmlWordCell(temp
, *(GetDC()));
203 if (m_UseLink
) c
-> SetLink(m_Link
);
204 m_Container
-> InsertCell(c
);
205 m_tmpLastWasSpace
= TRUE
;
210 c
= new wxHtmlWordCell(temp
, *(GetDC()));
211 if (m_UseLink
) c
-> SetLink(m_Link
);
212 m_Container
-> InsertCell(c
);
213 m_tmpLastWasSpace
= FALSE
;
219 wxHtmlContainerCell
* wxHtmlWinParser::OpenContainer()
221 m_Container
= new wxHtmlContainerCell(m_Container
);
222 m_Container
-> SetAlignHor(m_Align
);
223 m_tmpLastWasSpace
= TRUE
;
224 /* to avoid space being first character in paragraph */
230 wxHtmlContainerCell
* wxHtmlWinParser::SetContainer(wxHtmlContainerCell
*c
)
232 m_tmpLastWasSpace
= TRUE
;
233 /* to avoid space being first character in paragraph */
234 return m_Container
= c
;
239 wxHtmlContainerCell
* wxHtmlWinParser::CloseContainer()
241 m_Container
= m_Container
-> GetParent();
246 void wxHtmlWinParser::SetFontSize(int s
)
249 else if (s
> 7) s
= 7;
255 wxFont
* wxHtmlWinParser::CreateCurrentFont()
257 int fb
= GetFontBold(),
258 fi
= GetFontItalic(),
259 fu
= GetFontUnderlined(),
261 fs
= GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
263 if (m_FontsTable
[fb
][fi
][fu
][ff
][fs
] == NULL
) {
264 m_FontsTable
[fb
][fi
][fu
][ff
][fs
] =
266 m_FontsSizes
[fs
] * m_PixelScale
,
267 ff
? wxMODERN
: wxSWISS
,
268 fi
? wxITALIC
: wxNORMAL
,
269 fb
? wxBOLD
: wxNORMAL
,
270 fu
? TRUE
: FALSE
, ff
? m_FontFaceFixed
: m_FontFaceNormal
);
272 m_DC
-> SetFont(*(m_FontsTable
[fb
][fi
][fu
][ff
][fs
]));
273 return (m_FontsTable
[fb
][fi
][fu
][ff
][fs
]);
278 void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo
& link
)
281 m_UseLink
= (link
.GetHref() != wxEmptyString
);
287 //-----------------------------------------------------------------------------
288 // wxHtmlWinTagHandler
289 //-----------------------------------------------------------------------------
291 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler
, wxHtmlTagHandler
)
295 //-----------------------------------------------------------------------------
297 //-----------------------------------------------------------------------------
300 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule
, wxModule
)
303 bool wxHtmlTagsModule::OnInit()
305 wxHtmlWinParser::AddModule(this);
311 void wxHtmlTagsModule::OnExit()