]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_list.cpp
Incomplete setup build fix.
[wxWidgets.git] / src / html / m_list.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
c88293a4 2// Name: m_list.cpp
5526e819
VS
3// Purpose: wxHtml module for lists
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819 6// Copyright: (c) 1999 Vaclav Slavik
65571936 7// Licence: wxWindows licence
5526e819 8/////////////////////////////////////////////////////////////////////////////
14f355c2 9#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
ec4f5ef5
RS
10#pragma implementation
11#endif
12
314260fb 13#include "wx/wxprec.h"
ec4f5ef5 14
5526e819
VS
15
16#include "wx/defs.h"
f6bcfd97 17#if wxUSE_HTML && wxUSE_STREAMS
5526e819 18
2b5f62a0 19#ifdef __BORLANDC__
ec4f5ef5
RS
20#pragma hdrstop
21#endif
22
23#ifndef WXPRECOMP
04dbb646
VZ
24 #include "wx/brush.h"
25 #include "wx/dc.h"
ec4f5ef5
RS
26#endif
27
69941f05
VS
28#include "wx/html/forcelnk.h"
29#include "wx/html/m_templ.h"
5526e819 30
69941f05 31#include "wx/html/htmlcell.h"
5526e819 32
c88293a4 33FORCE_LINK_ME(m_list)
5526e819
VS
34
35
36//-----------------------------------------------------------------------------
37// wxHtmlListmarkCell
38//-----------------------------------------------------------------------------
39
40class wxHtmlListmarkCell : public wxHtmlCell
41{
42 private:
43 wxBrush m_Brush;
44 public:
45 wxHtmlListmarkCell(wxDC *dc, const wxColour& clr);
36c4ff4d 46 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2,
285f58ab 47 wxHtmlRenderingInfo& info);
fc7a2a60
VZ
48
49 DECLARE_NO_COPY_CLASS(wxHtmlListmarkCell)
5526e819
VS
50};
51
52wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID)
53{
ee66bc1f 54 m_Width = dc->GetCharHeight();
1da7aa8c 55 m_Height = dc->GetCharHeight();
5526e819
VS
56 m_Descent = 0;
57}
58
59
60
36c4ff4d 61void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y,
2a2e4f4a 62 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 63 wxHtmlRenderingInfo& WXUNUSED(info))
5526e819
VS
64{
65 dc.SetBrush(m_Brush);
d1da8872 66 dc.DrawEllipse(x + m_PosX + m_Width / 3, y + m_PosY + m_Height / 3,
ee66bc1f 67 (m_Width / 3), (m_Width / 3));
5526e819
VS
68}
69
5b2b456f
VS
70//-----------------------------------------------------------------------------
71// wxHtmlListCell
72//-----------------------------------------------------------------------------
73
74struct wxHtmlListItemStruct
75{
76 wxHtmlContainerCell *mark;
77 wxHtmlContainerCell *cont;
78 int minWidth;
79 int maxWidth;
80};
81
82class wxHtmlListCell : public wxHtmlContainerCell
83{
84 private:
85 wxBrush m_Brush;
86
87 int m_NumRows;
88 wxHtmlListItemStruct *m_RowInfo;
89 void ReallocRows(int rows);
90 void ComputeMinMaxWidths();
91 int m_ListmarkWidth;
92
93 public:
94 wxHtmlListCell(wxHtmlContainerCell *parent);
95 virtual ~wxHtmlListCell();
96 void AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *cont);
97 virtual void Layout(int w);
d1da8872 98
5b2b456f
VS
99 DECLARE_NO_COPY_CLASS(wxHtmlListCell)
100};
101
102wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell *parent) : wxHtmlContainerCell(parent)
103{
104 m_NumRows = 0;
105 m_RowInfo = 0;
106 m_ListmarkWidth = 0;
107}
108
109wxHtmlListCell::~wxHtmlListCell()
110{
111 if (m_RowInfo) free(m_RowInfo);
112}
113
114void wxHtmlListCell::Layout(int w)
115{
116 wxHtmlCell::Layout(w);
117
118 ComputeMinMaxWidths();
119 m_Width = wxMax(m_Width, wxMin(w, GetMaxTotalWidth()));
120
121 int s_width = m_Width - m_IndentLeft;
122
123 int vpos = 0;
124 for (int r = 0; r < m_NumRows; r++)
125 {
126 m_RowInfo[r].mark->Layout(m_ListmarkWidth);
127 m_RowInfo[r].mark->SetPos(m_IndentLeft, vpos);
128 m_RowInfo[r].cont->Layout(s_width - m_ListmarkWidth);
129 m_RowInfo[r].cont->SetPos(m_IndentLeft + m_ListmarkWidth, vpos);
130 vpos += wxMax(m_RowInfo[r].cont->GetHeight(), m_RowInfo[r].mark->GetHeight());
131 }
132 m_Height = vpos;
133}
134
135void wxHtmlListCell::AddRow(wxHtmlContainerCell *mark, wxHtmlContainerCell *cont)
136{
137 ReallocRows(++m_NumRows);
138 m_RowInfo[m_NumRows - 1].mark = mark;
139 m_RowInfo[m_NumRows - 1].cont = cont;
140}
141
142void wxHtmlListCell::ReallocRows(int rows)
143{
144 m_RowInfo = (wxHtmlListItemStruct*) realloc(m_RowInfo, sizeof(wxHtmlListItemStruct) * rows);
145 m_RowInfo[rows - 1].mark = 0;
146 m_RowInfo[rows - 1].cont = 0;
147 m_RowInfo[rows - 1].minWidth = 0;
148 m_RowInfo[rows - 1].maxWidth = 0;
5526e819 149
5b2b456f
VS
150 m_NumRows = rows;
151}
5526e819 152
5b2b456f
VS
153void wxHtmlListCell::ComputeMinMaxWidths()
154{
155 if (m_NumRows == 0) return;
d1da8872 156
5b2b456f
VS
157 m_MaxTotalWidth = 0;
158 m_Width = 0;
159
160 for (int r = 0; r < m_NumRows; r++)
161 {
162 wxHtmlListItemStruct& row = m_RowInfo[r];
163 row.mark->Layout(1);
164 row.cont->Layout(1);
165 int maxWidth = row.cont->GetMaxTotalWidth();
166 int width = row.cont->GetWidth();
167 if (row.mark->GetWidth() > m_ListmarkWidth)
168 m_ListmarkWidth = row.mark->GetWidth();
169 if (maxWidth > m_MaxTotalWidth)
170 m_MaxTotalWidth = maxWidth;
171 if (width > m_Width)
172 m_Width = width;
173 }
174 m_Width += m_ListmarkWidth + m_IndentLeft;
175 m_MaxTotalWidth += m_ListmarkWidth + m_IndentLeft;
176}
177
178//-----------------------------------------------------------------------------
179// wxHtmlListcontentCell
180//-----------------------------------------------------------------------------
181
182class wxHtmlListcontentCell : public wxHtmlContainerCell
183{
184public:
185 wxHtmlListcontentCell(wxHtmlContainerCell *p) : wxHtmlContainerCell(p) {}
d1da8872 186 virtual void Layout(int w) {
5b2b456f
VS
187 // Reset top indentation, fixes <li><p>
188 SetIndent(0, wxHTML_INDENT_TOP);
189 wxHtmlContainerCell::Layout(w);
190 }
191};
5526e819
VS
192
193//-----------------------------------------------------------------------------
194// The list handler:
195//-----------------------------------------------------------------------------
196
197
198TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
199
200 TAG_HANDLER_VARS
5b2b456f 201 wxHtmlListCell *m_List;
5526e819
VS
202 int m_Numbering;
203 // this is number of actual item of list or 0 for dots
204
205 TAG_HANDLER_CONSTR(OLULLI)
206 {
1660c80f 207 m_List = NULL;
5526e819
VS
208 m_Numbering = 0;
209 }
210
211 TAG_HANDLER_PROC(tag)
212 {
213 wxHtmlContainerCell *c;
214
215 // List Item:
5b2b456f 216 if (m_List && tag.GetName() == wxT("LI"))
04dbb646 217 {
5b2b456f
VS
218 c = m_WParser->SetContainer(new wxHtmlContainerCell(m_List));
219 c->SetAlignVer(wxHTML_ALIGN_TOP);
211dfedd 220
5b2b456f 221 wxHtmlContainerCell *mark = c;
211dfedd 222 c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
211dfedd 223 if (m_Numbering == 0)
ad410280
JS
224 {
225 // Centering gives more space after the bullet
226 c->SetAlignHor(wxHTML_ALIGN_CENTER);
211dfedd 227 c->InsertCell(new wxHtmlListmarkCell(m_WParser->GetDC(), m_WParser->GetActualColor()));
ad410280 228 }
211dfedd 229 else
04dbb646 230 {
ad410280 231 c->SetAlignHor(wxHTML_ALIGN_RIGHT);
211dfedd
VS
232 wxString mark;
233 mark.Printf(wxT("%i."), m_Numbering);
234 c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC())));
5526e819 235 }
211dfedd
VS
236 m_WParser->CloseContainer();
237
238 c = m_WParser->OpenContainer();
211dfedd 239
5b2b456f
VS
240 m_List->AddRow(mark, c);
241 c = m_WParser->OpenContainer();
242 m_WParser->SetContainer(new wxHtmlListcontentCell(c));
d1da8872 243
211dfedd 244 if (m_Numbering != 0) m_Numbering++;
5526e819
VS
245 }
246
247 // Begin of List (not-numbered): "UL", "OL"
5b2b456f 248 else if (tag.GetName() == wxT("UL") || tag.GetName() == wxT("OL"))
04dbb646 249 {
5526e819
VS
250 int oldnum = m_Numbering;
251
0413cec5 252 if (tag.GetName() == wxT("UL")) m_Numbering = 0;
5526e819
VS
253 else m_Numbering = 1;
254
5b2b456f
VS
255 wxHtmlContainerCell *oldcont;
256 oldcont = c = m_WParser->OpenContainer();
5526e819 257
5b2b456f
VS
258 wxHtmlListCell *oldList = m_List;
259 m_List = new wxHtmlListCell(c);
260 m_List->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
d1da8872 261
5526e819 262 ParseInner(tag);
5526e819 263
5b2b456f 264 m_WParser->SetContainer(oldcont);
1da7aa8c
VS
265 m_WParser->CloseContainer();
266
5526e819 267 m_Numbering = oldnum;
5b2b456f 268 m_List = oldList;
d1da8872 269 return true;
5526e819 270 }
5b2b456f
VS
271 return false;
272
5526e819
VS
273 }
274
275TAG_HANDLER_END(OLULLI)
276
277
278TAGS_MODULE_BEGIN(List)
279
280 TAGS_MODULE_ADD(OLULLI)
281
282TAGS_MODULE_END(List)
283
284#endif