better <HR> tag handling in wxHTML
[wxWidgets.git] / src / html / m_hline.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: m_hline.cpp
3 // Purpose: wxHtml module for horizontal line (HR tag)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifdef __GNUG__
11 #pragma implementation
12 #endif
13
14 #include "wx/wxprec.h"
15
16
17 #include "wx/defs.h"
18 #if wxUSE_HTML && wxUSE_STREAMS
19 #ifdef __BORDLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WXPRECOMP
24 #include "wx/brush.h"
25 #include "wx/pen.h"
26 #include "wx/dc.h"
27 #endif
28
29 #include "wx/html/forcelnk.h"
30 #include "wx/html/m_templ.h"
31
32 #include "wx/html/htmlcell.h"
33
34 FORCE_LINK_ME(m_hline)
35
36
37 //-----------------------------------------------------------------------------
38 // wxHtmlLineCell
39 //-----------------------------------------------------------------------------
40
41 class wxHtmlLineCell : public wxHtmlCell
42 {
43 public:
44 wxHtmlLineCell(int size, bool shading) : wxHtmlCell() {m_Height = size; m_HasShading = shading;}
45 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
46 void Layout(int w)
47 { m_Width = w; wxHtmlCell::Layout(w); }
48
49 private:
50 // Should we draw 3-D shading or not
51 bool m_HasShading;
52 };
53
54
55 void wxHtmlLineCell::Draw(wxDC& dc, int x, int y, int WXUNUSED(view_y1), int WXUNUSED(view_y2))
56 {
57 wxBrush mybrush(wxT("GREY"), (m_HasShading) ? wxTRANSPARENT : wxSOLID);
58 wxPen mypen(wxT("GREY"), 1, wxSOLID);
59 dc.SetBrush(mybrush);
60 dc.SetPen(mypen);
61 dc.DrawRectangle(x + m_PosX, y + m_PosY, m_Width, m_Height);
62 }
63
64
65
66
67 //-----------------------------------------------------------------------------
68 // The list handler:
69 //-----------------------------------------------------------------------------
70
71
72 TAG_HANDLER_BEGIN(HR, "HR")
73
74 TAG_HANDLER_PROC(tag)
75 {
76 wxHtmlContainerCell *c;
77 int sz;
78 bool HasShading;
79
80 m_WParser->CloseContainer();
81 c = m_WParser->OpenContainer();
82
83 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_VERTICAL);
84 c->SetAlignHor(wxHTML_ALIGN_CENTER);
85 c->SetAlign(tag);
86 c->SetWidthFloat(tag);
87 sz = 1;
88 tag.GetParamAsInt(wxT("SIZE"), &sz);
89 HasShading = !(tag.HasParam(wxT("NOSHADE")));
90 c->InsertCell(new wxHtmlLineCell((int)((double)sz * m_WParser->GetPixelScale()), HasShading));
91
92 m_WParser->CloseContainer();
93 m_WParser->OpenContainer();
94
95 return FALSE;
96 }
97
98 TAG_HANDLER_END(HR)
99
100
101
102
103
104 TAGS_MODULE_BEGIN(HLine)
105
106 TAGS_MODULE_ADD(HR)
107
108 TAGS_MODULE_END(HLine)
109
110 #endif