]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_list.cpp
crashes fixed, trying to remove erradic redraws when layouting windows
[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
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
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
VS
61void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y,
62 int WXUNUSED(view_y1), int WXUNUSED(view_y2),
285f58ab 63 wxHtmlRenderingInfo& WXUNUSED(info))
5526e819
VS
64{
65 dc.SetBrush(m_Brush);
ee66bc1f
VS
66 dc.DrawEllipse(x + m_PosX + m_Width / 3, y + m_PosY + m_Height / 3,
67 (m_Width / 3), (m_Width / 3));
5526e819
VS
68}
69
70
71
72
73//-----------------------------------------------------------------------------
74// The list handler:
75//-----------------------------------------------------------------------------
76
77
78TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI")
79
80 TAG_HANDLER_VARS
81 int m_Numbering;
82 // this is number of actual item of list or 0 for dots
83
84 TAG_HANDLER_CONSTR(OLULLI)
85 {
86 m_Numbering = 0;
87 }
88
89 TAG_HANDLER_PROC(tag)
90 {
91 wxHtmlContainerCell *c;
92
93 // List Item:
04dbb646
VZ
94 if (tag.GetName() == wxT("LI"))
95 {
211dfedd
VS
96 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
97 // this is to prevent indetation in <li><p> case
98 m_WParser->CloseContainer();
99 m_WParser->CloseContainer();
100
101 c = m_WParser->OpenContainer();
102 c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
211dfedd 103 if (m_Numbering == 0)
ad410280
JS
104 {
105 // Centering gives more space after the bullet
106 c->SetAlignHor(wxHTML_ALIGN_CENTER);
211dfedd 107 c->InsertCell(new wxHtmlListmarkCell(m_WParser->GetDC(), m_WParser->GetActualColor()));
ad410280 108 }
211dfedd 109 else
04dbb646 110 {
ad410280 111 c->SetAlignHor(wxHTML_ALIGN_RIGHT);
211dfedd
VS
112 wxString mark;
113 mark.Printf(wxT("%i."), m_Numbering);
114 c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC())));
5526e819 115 }
211dfedd
VS
116 m_WParser->CloseContainer();
117
118 c = m_WParser->OpenContainer();
119 c->SetIndent(m_WParser->GetCharWidth() / 4, wxHTML_INDENT_LEFT);
120 c->SetWidthFloat(-2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS);
121
122 m_WParser->OpenContainer();
123
124 if (m_Numbering != 0) m_Numbering++;
125
5526e819
VS
126 return FALSE;
127 }
128
129 // Begin of List (not-numbered): "UL", "OL"
04dbb646
VZ
130 else
131 {
5526e819
VS
132 int oldnum = m_Numbering;
133
0413cec5 134 if (tag.GetName() == wxT("UL")) m_Numbering = 0;
5526e819
VS
135 else m_Numbering = 1;
136
1da7aa8c 137 c = m_WParser->GetContainer();
e3774124 138 if (c->GetFirstChild() != NULL)
04dbb646 139 {
1da7aa8c
VS
140 m_WParser->CloseContainer();
141 m_WParser->OpenContainer();
142 c = m_WParser->GetContainer();
5526e819 143 }
1da7aa8c
VS
144 c->SetAlignHor(wxHTML_ALIGN_LEFT);
145 c->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT);
146 m_WParser->OpenContainer()->SetAlignVer(wxHTML_ALIGN_TOP);
5526e819 147
1da7aa8c
VS
148 m_WParser->OpenContainer();
149 m_WParser->OpenContainer();
5526e819 150 ParseInner(tag);
5526e819 151
1da7aa8c
VS
152 m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP);
153 // this is to prevent indetation in <li><p> case
154 m_WParser->CloseContainer();
155
156 m_WParser->CloseContainer();
157 m_WParser->CloseContainer();
158 m_WParser->CloseContainer();
159 m_WParser->OpenContainer();
5526e819
VS
160
161 m_Numbering = oldnum;
162 return TRUE;
163 }
164 }
165
166TAG_HANDLER_END(OLULLI)
167
168
169TAGS_MODULE_BEGIN(List)
170
171 TAGS_MODULE_ADD(OLULLI)
172
173TAGS_MODULE_END(List)
174
175#endif