Changed the UL bullet to be a square -- I couldn't get
[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 WXUNUSED(view_y1), int WXUNUSED(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 // This looks better IMHO (JACS) -- I tried to get ellipses/circles working but they can
63 // just look terrible, at least on Windows. TODO: maybe have configurable bullets,
64 // possibly with the app supplying bitmaps.
65 int size = (int) ((m_Width / 2.0) + 0.5);
66 dc.DrawRectangle(x + m_PosX + (m_Width - size)/2, y + m_PosY + (m_Height - size)/ 2, size, size);
67 }
68
69
70
71
72 //-----------------------------------------------------------------------------
73 // The list handler:
74 //-----------------------------------------------------------------------------
75
76
77 TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
78
79 TAG_HANDLER_VARS
80 int m_Numbering;
81 // this is number of actual item of list or 0 for dots
82
83 TAG_HANDLER_CONSTR(OLULLI)
84 {
85 m_Numbering = 0;
86 }
87
88 TAG_HANDLER_PROC(tag)
89 {
90 wxHtmlContainerCell *c;
91
92 // List Item:
93 if (tag.GetName() == wxT("LI"))
94 {
95 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
96 // this is to prevent indetation in <li><p> case
97 m_WParser->CloseContainer();
98 m_WParser->CloseContainer();
99
100 c = m_WParser->OpenContainer();
101 c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
102 if (m_Numbering == 0)
103 {
104 // Centering gives more space after the bullet
105 c->SetAlignHor(wxHTML_ALIGN_CENTER);
106 c->InsertCell(new wxHtmlListmarkCell(m_WParser->GetDC(), m_WParser->GetActualColor()));
107 }
108 else
109 {
110 c->SetAlignHor(wxHTML_ALIGN_RIGHT);
111 wxString mark;
112 mark.Printf(wxT("%i."), m_Numbering);
113 c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC())));
114 }
115 m_WParser->CloseContainer();
116
117 c = m_WParser->OpenContainer();
118 c->SetIndent(m_WParser->GetCharWidth() / 4, wxHTML_INDENT_LEFT);
119 c->SetWidthFloat(-2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
120
121 m_WParser->OpenContainer();
122
123 if (m_Numbering != 0) m_Numbering++;
124
125 return FALSE;
126 }
127
128 // Begin of List (not-numbered): "UL", "OL"
129 else
130 {
131 int oldnum = m_Numbering;
132
133 if (tag.GetName() == wxT("UL")) m_Numbering = 0;
134 else m_Numbering = 1;
135
136 c = m_WParser->GetContainer();
137 if (c->GetFirstCell() != NULL)
138 {
139 m_WParser->CloseContainer();
140 m_WParser->OpenContainer();
141 c = m_WParser->GetContainer();
142 }
143 c->SetAlignHor(wxHTML_ALIGN_LEFT);
144 c->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
145 m_WParser->OpenContainer()->SetAlignVer(wxHTML_ALIGN_TOP);
146
147 m_WParser->OpenContainer();
148 m_WParser->OpenContainer();
149 ParseInner(tag);
150
151 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
152 // this is to prevent indetation in <li><p> case
153 m_WParser->CloseContainer();
154
155 m_WParser->CloseContainer();
156 m_WParser->CloseContainer();
157 m_WParser->CloseContainer();
158 m_WParser->OpenContainer();
159
160 m_Numbering = oldnum;
161 return TRUE;
162 }
163 }
164
165 TAG_HANDLER_END(OLULLI)
166
167
168 TAGS_MODULE_BEGIN(List)
169
170 TAGS_MODULE_ADD(OLULLI)
171
172 TAGS_MODULE_END(List)
173
174 #endif