]>
git.saurik.com Git - wxWidgets.git/blob - src/html/winpars.cpp
73d81a70dbe034866ddfa1de807b9b6e0c3cbd3e
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
;
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_LinkColor
.Set(0, 0, 0xFF);
119 m_ActualColor
.Set(0, 0, 0);
120 m_Align
= wxHTML_ALIGN_LEFT
;
121 m_tmpLastWasSpace
= FALSE
;
126 m_Container
-> InsertCell(new wxHtmlColourCell(m_ActualColor
));
127 m_Container
-> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
132 void wxHtmlWinParser::DoneParser()
135 wxHtmlParser::DoneParser();
140 wxObject
* wxHtmlWinParser::GetProduct()
142 wxHtmlContainerCell
*top
;
146 GetContainer() -> SetIndent(m_CharHeight
, wxHTML_INDENT_TOP
);
148 while (top
-> GetParent()) top
= top
-> GetParent();
154 wxList
* wxHtmlWinParser::GetTempData()
158 wxList
*lst
= wxHtmlParser::GetTempData();
160 if (lst
== NULL
) lst
= new wxList
;
161 lst
-> DeleteContents(TRUE
);
163 for (i
= 0; i
< 2; i
++)
164 for (j
= 0; j
< 2; j
++)
165 for (k
= 0; k
< 2; k
++)
166 for (l
= 0; l
< 2; l
++)
167 for (m
= 0; m
< 7; m
++) {
168 f
= m_FontsTable
[i
][j
][k
][l
][m
];
169 if (f
) lst
-> Append(f
);
176 void wxHtmlWinParser::AddText(const char* txt
)
179 int i
= 0, x
, lng
= strlen(txt
);
180 char temp
[wxHTML_BUFLEN
];
184 if (m_tmpLastWasSpace
) {
185 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++;
190 d
= temp
[templen
++] = txt
[i
];
191 if ((d
== '\n') || (d
== '\r') || (d
== ' ') || (d
== '\t')) {
193 while ((i
< lng
) && ((txt
[i
] == '\n') || (txt
[i
] == '\r') || (txt
[i
] == ' ') || (txt
[i
] == '\t'))) i
++, x
++;
198 temp
[templen
-1] = ' ';
201 c
= new wxHtmlWordCell(temp
, *(GetDC()));
202 if (m_UseLink
) c
-> SetLink(m_Link
);
203 m_Container
-> InsertCell(c
);
204 m_tmpLastWasSpace
= TRUE
;
209 c
= new wxHtmlWordCell(temp
, *(GetDC()));
210 if (m_UseLink
) c
-> SetLink(m_Link
);
211 m_Container
-> InsertCell(c
);
212 m_tmpLastWasSpace
= FALSE
;
218 wxHtmlContainerCell
* wxHtmlWinParser::OpenContainer()
220 m_Container
= new wxHtmlContainerCell(m_Container
);
221 m_Container
-> SetAlignHor(m_Align
);
222 m_tmpLastWasSpace
= TRUE
;
223 /* to avoid space being first character in paragraph */
229 wxHtmlContainerCell
* wxHtmlWinParser::SetContainer(wxHtmlContainerCell
*c
)
231 m_tmpLastWasSpace
= TRUE
;
232 /* to avoid space being first character in paragraph */
233 return m_Container
= c
;
238 wxHtmlContainerCell
* wxHtmlWinParser::CloseContainer()
240 m_Container
= m_Container
-> GetParent();
245 wxFont
* wxHtmlWinParser::CreateCurrentFont()
247 int fb
= GetFontBold(),
248 fi
= GetFontItalic(),
249 fu
= GetFontUnderlined(),
251 fs
= GetFontSize() + 2 /*remap from <-2;4> to <0;7>*/ ;
253 if (m_FontsTable
[fb
][fi
][fu
][ff
][fs
] == NULL
) {
254 m_FontsTable
[fb
][fi
][fu
][ff
][fs
] =
256 m_FontsSizes
[fs
] * m_PixelScale
,
257 ff
? wxMODERN
: wxSWISS
,
258 fi
? wxITALIC
: wxNORMAL
,
259 fb
? wxBOLD
: wxNORMAL
,
260 fu
? TRUE
: FALSE
, ff
? m_FontFaceFixed
: m_FontFaceNormal
);
262 m_DC
-> SetFont(*(m_FontsTable
[fb
][fi
][fu
][ff
][fs
]));
263 return (m_FontsTable
[fb
][fi
][fu
][ff
][fs
]);
269 //-----------------------------------------------------------------------------
270 // wxHtmlWinTagHandler
271 //-----------------------------------------------------------------------------
273 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler
, wxHtmlTagHandler
)
277 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
282 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule
, wxModule
)
285 bool wxHtmlTagsModule::OnInit()
287 wxHtmlWinParser::AddModule(this);
293 void wxHtmlTagsModule::OnExit()