]>
Commit | Line | Data |
---|---|---|
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 | ///////////////////////////////////////////////////////////////////////////// | |
ec4f5ef5 RS |
9 | #ifdef __GNUG__ |
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 | 33 | FORCE_LINK_ME(m_list) |
5526e819 VS |
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); | |
36c4ff4d VS |
46 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2, |
47 | wxHtmlRenderingState& state); | |
5526e819 VS |
48 | }; |
49 | ||
50 | wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID) | |
51 | { | |
ee66bc1f | 52 | m_Width = dc->GetCharHeight(); |
1da7aa8c | 53 | m_Height = dc->GetCharHeight(); |
5526e819 VS |
54 | m_Descent = 0; |
55 | } | |
56 | ||
57 | ||
58 | ||
36c4ff4d VS |
59 | void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y, |
60 | int WXUNUSED(view_y1), int WXUNUSED(view_y2), | |
61 | wxHtmlRenderingState& WXUNUSED(state)) | |
5526e819 VS |
62 | { |
63 | dc.SetBrush(m_Brush); | |
ee66bc1f VS |
64 | dc.DrawEllipse(x + m_PosX + m_Width / 3, y + m_PosY + m_Height / 3, |
65 | (m_Width / 3), (m_Width / 3)); | |
5526e819 VS |
66 | } |
67 | ||
68 | ||
69 | ||
70 | ||
71 | //----------------------------------------------------------------------------- | |
72 | // The list handler: | |
73 | //----------------------------------------------------------------------------- | |
74 | ||
75 | ||
76 | TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") | |
77 | ||
78 | TAG_HANDLER_VARS | |
79 | int m_Numbering; | |
80 | // this is number of actual item of list or 0 for dots | |
81 | ||
82 | TAG_HANDLER_CONSTR(OLULLI) | |
83 | { | |
84 | m_Numbering = 0; | |
85 | } | |
86 | ||
87 | TAG_HANDLER_PROC(tag) | |
88 | { | |
89 | wxHtmlContainerCell *c; | |
90 | ||
91 | // List Item: | |
04dbb646 VZ |
92 | if (tag.GetName() == wxT("LI")) |
93 | { | |
211dfedd VS |
94 | m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP); |
95 | // this is to prevent indetation in <li><p> case | |
96 | m_WParser->CloseContainer(); | |
97 | m_WParser->CloseContainer(); | |
98 | ||
99 | c = m_WParser->OpenContainer(); | |
100 | c->SetWidthFloat(2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS); | |
211dfedd | 101 | if (m_Numbering == 0) |
ad410280 JS |
102 | { |
103 | // Centering gives more space after the bullet | |
104 | c->SetAlignHor(wxHTML_ALIGN_CENTER); | |
211dfedd | 105 | c->InsertCell(new wxHtmlListmarkCell(m_WParser->GetDC(), m_WParser->GetActualColor())); |
ad410280 | 106 | } |
211dfedd | 107 | else |
04dbb646 | 108 | { |
ad410280 | 109 | c->SetAlignHor(wxHTML_ALIGN_RIGHT); |
211dfedd VS |
110 | wxString mark; |
111 | mark.Printf(wxT("%i."), m_Numbering); | |
112 | c->InsertCell(new wxHtmlWordCell(mark, *(m_WParser->GetDC()))); | |
5526e819 | 113 | } |
211dfedd VS |
114 | m_WParser->CloseContainer(); |
115 | ||
116 | c = m_WParser->OpenContainer(); | |
117 | c->SetIndent(m_WParser->GetCharWidth() / 4, wxHTML_INDENT_LEFT); | |
118 | c->SetWidthFloat(-2 * m_WParser->GetCharWidth(), wxHTML_UNITS_PIXELS); | |
119 | ||
120 | m_WParser->OpenContainer(); | |
121 | ||
122 | if (m_Numbering != 0) m_Numbering++; | |
123 | ||
5526e819 VS |
124 | return FALSE; |
125 | } | |
126 | ||
127 | // Begin of List (not-numbered): "UL", "OL" | |
04dbb646 VZ |
128 | else |
129 | { | |
5526e819 VS |
130 | int oldnum = m_Numbering; |
131 | ||
0413cec5 | 132 | if (tag.GetName() == wxT("UL")) m_Numbering = 0; |
5526e819 VS |
133 | else m_Numbering = 1; |
134 | ||
1da7aa8c | 135 | c = m_WParser->GetContainer(); |
04dbb646 VZ |
136 | if (c->GetFirstCell() != NULL) |
137 | { | |
1da7aa8c VS |
138 | m_WParser->CloseContainer(); |
139 | m_WParser->OpenContainer(); | |
140 | c = m_WParser->GetContainer(); | |
5526e819 | 141 | } |
1da7aa8c VS |
142 | c->SetAlignHor(wxHTML_ALIGN_LEFT); |
143 | c->SetIndent(2 * m_WParser->GetCharWidth(), wxHTML_INDENT_LEFT); | |
144 | m_WParser->OpenContainer()->SetAlignVer(wxHTML_ALIGN_TOP); | |
5526e819 | 145 | |
1da7aa8c VS |
146 | m_WParser->OpenContainer(); |
147 | m_WParser->OpenContainer(); | |
5526e819 | 148 | ParseInner(tag); |
5526e819 | 149 | |
1da7aa8c VS |
150 | m_WParser->GetContainer()->SetIndent(0, wxHTML_INDENT_TOP); |
151 | // this is to prevent indetation in <li><p> case | |
152 | m_WParser->CloseContainer(); | |
153 | ||
154 | m_WParser->CloseContainer(); | |
155 | m_WParser->CloseContainer(); | |
156 | m_WParser->CloseContainer(); | |
157 | m_WParser->OpenContainer(); | |
5526e819 VS |
158 | |
159 | m_Numbering = oldnum; | |
160 | return TRUE; | |
161 | } | |
162 | } | |
163 | ||
164 | TAG_HANDLER_END(OLULLI) | |
165 | ||
166 | ||
167 | TAGS_MODULE_BEGIN(List) | |
168 | ||
169 | TAGS_MODULE_ADD(OLULLI) | |
170 | ||
171 | TAGS_MODULE_END(List) | |
172 | ||
173 | #endif |