]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_list.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml module for lists
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
10 #pragma implementation
13 #include "wx/wxprec.h"
17 #if wxUSE_HTML && wxUSE_STREAMS
28 #include "wx/html/forcelnk.h"
29 #include "wx/html/m_templ.h"
31 #include "wx/html/htmlcell.h"
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class wxHtmlListmarkCell
: public wxHtmlCell
45 wxHtmlListmarkCell(wxDC
*dc
, const wxColour
& clr
);
46 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
47 wxHtmlRenderingInfo
& info
);
49 DECLARE_NO_COPY_CLASS(wxHtmlListmarkCell
)
52 wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC
* dc
, const wxColour
& clr
) : wxHtmlCell(), m_Brush(clr
, wxSOLID
)
54 m_Width
= dc
->GetCharHeight();
55 m_Height
= dc
->GetCharHeight();
61 void wxHtmlListmarkCell::Draw(wxDC
& dc
, int x
, int y
,
62 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
63 wxHtmlRenderingInfo
& WXUNUSED(info
))
66 dc
.DrawEllipse(x
+ m_PosX
+ m_Width
/ 3, y
+ m_PosY
+ m_Height
/ 3,
67 (m_Width
/ 3), (m_Width
/ 3));
70 //-----------------------------------------------------------------------------
72 //-----------------------------------------------------------------------------
74 struct wxHtmlListItemStruct
76 wxHtmlContainerCell
*mark
;
77 wxHtmlContainerCell
*cont
;
82 class wxHtmlListCell
: public wxHtmlContainerCell
88 wxHtmlListItemStruct
*m_RowInfo
;
89 void ReallocRows(int rows
);
90 void ComputeMinMaxWidths();
94 wxHtmlListCell(wxHtmlContainerCell
*parent
);
95 virtual ~wxHtmlListCell();
96 void AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
);
97 virtual void Layout(int w
);
99 DECLARE_NO_COPY_CLASS(wxHtmlListCell
)
102 wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell
*parent
) : wxHtmlContainerCell(parent
)
109 wxHtmlListCell::~wxHtmlListCell()
111 if (m_RowInfo
) free(m_RowInfo
);
114 void wxHtmlListCell::Layout(int w
)
116 wxHtmlCell::Layout(w
);
118 ComputeMinMaxWidths();
119 m_Width
= wxMax(m_Width
, wxMin(w
, GetMaxTotalWidth()));
121 int s_width
= m_Width
- m_IndentLeft
;
124 for (int r
= 0; r
< m_NumRows
; r
++)
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());
135 void wxHtmlListCell::AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
)
137 ReallocRows(++m_NumRows
);
138 m_RowInfo
[m_NumRows
- 1].mark
= mark
;
139 m_RowInfo
[m_NumRows
- 1].cont
= cont
;
142 void wxHtmlListCell::ReallocRows(int rows
)
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;
153 void wxHtmlListCell::ComputeMinMaxWidths()
155 if (m_NumRows
== 0) return;
160 for (int r
= 0; r
< m_NumRows
; r
++)
162 wxHtmlListItemStruct
& row
= m_RowInfo
[r
];
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
;
174 m_Width
+= m_ListmarkWidth
+ m_IndentLeft
;
175 m_MaxTotalWidth
+= m_ListmarkWidth
+ m_IndentLeft
;
178 //-----------------------------------------------------------------------------
179 // wxHtmlListcontentCell
180 //-----------------------------------------------------------------------------
182 class wxHtmlListcontentCell
: public wxHtmlContainerCell
185 wxHtmlListcontentCell(wxHtmlContainerCell
*p
) : wxHtmlContainerCell(p
) {}
186 virtual void Layout(int w
) {
187 // Reset top indentation, fixes <li><p>
188 SetIndent(0, wxHTML_INDENT_TOP
);
189 wxHtmlContainerCell::Layout(w
);
193 //-----------------------------------------------------------------------------
195 //-----------------------------------------------------------------------------
198 TAG_HANDLER_BEGIN(OLULLI
, "OL,UL,LI")
201 wxHtmlListCell
*m_List
;
203 // this is number of actual item of list or 0 for dots
205 TAG_HANDLER_CONSTR(OLULLI
)
210 TAG_HANDLER_PROC(tag
)
212 wxHtmlContainerCell
*c
;
215 if (m_List
&& tag
.GetName() == wxT("LI"))
217 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_List
));
218 c
->SetAlignVer(wxHTML_ALIGN_TOP
);
220 wxHtmlContainerCell
*mark
= c
;
221 c
->SetWidthFloat(2 * m_WParser
->GetCharWidth(), wxHTML_UNITS_PIXELS
);
222 if (m_Numbering
== 0)
224 // Centering gives more space after the bullet
225 c
->SetAlignHor(wxHTML_ALIGN_CENTER
);
226 c
->InsertCell(new wxHtmlListmarkCell(m_WParser
->GetDC(), m_WParser
->GetActualColor()));
230 c
->SetAlignHor(wxHTML_ALIGN_RIGHT
);
232 mark
.Printf(wxT("%i."), m_Numbering
);
233 c
->InsertCell(new wxHtmlWordCell(mark
, *(m_WParser
->GetDC())));
235 m_WParser
->CloseContainer();
237 c
= m_WParser
->OpenContainer();
239 m_List
->AddRow(mark
, c
);
240 c
= m_WParser
->OpenContainer();
241 m_WParser
->SetContainer(new wxHtmlListcontentCell(c
));
243 if (m_Numbering
!= 0) m_Numbering
++;
246 // Begin of List (not-numbered): "UL", "OL"
247 else if (tag
.GetName() == wxT("UL") || tag
.GetName() == wxT("OL"))
249 int oldnum
= m_Numbering
;
251 if (tag
.GetName() == wxT("UL")) m_Numbering
= 0;
252 else m_Numbering
= 1;
254 wxHtmlContainerCell
*oldcont
;
255 oldcont
= c
= m_WParser
->OpenContainer();
257 wxHtmlListCell
*oldList
= m_List
;
258 m_List
= new wxHtmlListCell(c
);
259 m_List
->SetIndent(2 * m_WParser
->GetCharWidth(), wxHTML_INDENT_LEFT
);
263 m_WParser
->SetContainer(oldcont
);
264 m_WParser
->CloseContainer();
266 m_Numbering
= oldnum
;
274 TAG_HANDLER_END(OLULLI
)
277 TAGS_MODULE_BEGIN(List
)
279 TAGS_MODULE_ADD(OLULLI
)
281 TAGS_MODULE_END(List
)