]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_list.cpp
FreeBSD compilation fix
[wxWidgets.git] / src / html / m_list.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: m_list.cpp
3 // Purpose: wxHtml module for lists
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9 #ifdef __GNUG__
10 #pragma implementation
11 #endif
12
13 #include "wx/wxprec.h"
14
15
16 #include "wx/defs.h"
17 #if wxUSE_HTML && wxUSE_STREAMS
18
19 #ifdef __BORDLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WXPRECOMP
24 #include "wx/brush.h"
25 #include "wx/dc.h"
26 #endif
27
28 #include "wx/html/forcelnk.h"
29 #include "wx/html/m_templ.h"
30
31 #include "wx/html/htmlcell.h"
32
33 FORCE_LINK_ME(m_list)
34
35
36 //-----------------------------------------------------------------------------
37 // wxHtmlListmarkCell
38 //-----------------------------------------------------------------------------
39
40 class wxHtmlListmarkCell : public wxHtmlCell
41 {
42 private:
43 wxBrush m_Brush;
44 public:
45 wxHtmlListmarkCell(wxDC *dc, const wxColour& clr);
46 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
47 };
48
49 wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID)
50 {
51 m_Width = dc->GetCharWidth();
52 m_Height = dc->GetCharHeight();
53 m_Descent = 0;
54 }
55
56
57
58 void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
59 {
60 dc.SetBrush(m_Brush);
61 dc.DrawEllipse(x + m_PosX + m_Width / 4, y + m_PosY + m_Height / 4, m_Width / 2, m_Width / 2);
62 }
63
64
65
66
67 //-----------------------------------------------------------------------------
68 // The list handler:
69 //-----------------------------------------------------------------------------
70
71
72 TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
73
74 TAG_HANDLER_VARS
75 int m_Numbering;
76 // this is number of actual item of list or 0 for dots
77
78 TAG_HANDLER_CONSTR(OLULLI)
79 {
80 m_Numbering = 0;
81 }
82
83 TAG_HANDLER_PROC(tag)
84 {
85 wxHtmlContainerCell *c;
86
87 // List Item:
88 if (tag.GetName() == wxT("LI"))
89 {
90 if (!tag.IsEnding())
91 {
92 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
93 // this is to prevent indetation in <li><p> case
94 m_WParser->CloseContainer();
95 m_WParser->CloseContainer();
96
97 c = m_WParser->OpenContainer();
98 c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
99 c->SetAlignHor(wxHTML_ALIGN_RIGHT);
100 if (m_Numbering == 0)
101 c->InsertCell(new wxHtmlListmarkCell(m_WParser->GetDC(), m_WParser->GetActualColor()));
102 else
103 {
104 wxString mark;
105 mark.Printf(wxT("%i."), m_Numbering);
106 c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC())));
107 }
108 m_WParser->CloseContainer();
109
110 c = m_WParser->OpenContainer();
111 c->SetIndent(m_WParser->GetCharWidth() / 4, wxHTML_INDENT_LEFT);
112 c->SetWidthFloat(-2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
113
114 m_WParser->OpenContainer();
115
116 if (m_Numbering != 0) m_Numbering++;
117 }
118 return FALSE;
119 }
120
121 // Begin of List (not-numbered): "UL", "OL"
122 else
123 {
124 int oldnum = m_Numbering;
125
126 if (tag.GetName() == wxT("UL")) m_Numbering = 0;
127 else m_Numbering = 1;
128
129 c = m_WParser->GetContainer();
130 if (c->GetFirstCell() != NULL)
131 {
132 m_WParser->CloseContainer();
133 m_WParser->OpenContainer();
134 c = m_WParser->GetContainer();
135 }
136 c->SetAlignHor(wxHTML_ALIGN_LEFT);
137 c->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
138 m_WParser->OpenContainer()->SetAlignVer(wxHTML_ALIGN_TOP);
139
140 m_WParser->OpenContainer();
141 m_WParser->OpenContainer();
142 ParseInner(tag);
143
144 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
145 // this is to prevent indetation in <li><p> case
146 m_WParser->CloseContainer();
147
148 m_WParser->CloseContainer();
149 m_WParser->CloseContainer();
150 m_WParser->CloseContainer();
151 m_WParser->OpenContainer();
152
153 m_Numbering = oldnum;
154 return TRUE;
155 }
156 }
157
158 TAG_HANDLER_END(OLULLI)
159
160
161 TAGS_MODULE_BEGIN(List)
162
163 TAGS_MODULE_ADD(OLULLI)
164
165 TAGS_MODULE_END(List)
166
167 #endif