]>
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 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
13 #if wxUSE_HTML && wxUSE_STREAMS
24 #include "wx/html/forcelnk.h"
25 #include "wx/html/m_templ.h"
27 #include "wx/html/htmlcell.h"
32 //-----------------------------------------------------------------------------
34 //-----------------------------------------------------------------------------
36 class wxHtmlListmarkCell
: public wxHtmlCell
41 wxHtmlListmarkCell(wxDC
*dc
, const wxColour
& clr
);
42 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
43 wxHtmlRenderingInfo
& info
);
45 DECLARE_NO_COPY_CLASS(wxHtmlListmarkCell
)
48 wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC
* dc
, const wxColour
& clr
) : wxHtmlCell(), m_Brush(clr
, wxSOLID
)
50 m_Width
= dc
->GetCharHeight();
51 m_Height
= dc
->GetCharHeight();
52 // bottom of list mark is lined with bottom of letters in next cell
53 m_Descent
= m_Height
/ 3;
58 void wxHtmlListmarkCell::Draw(wxDC
& dc
, int x
, int y
,
59 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
60 wxHtmlRenderingInfo
& WXUNUSED(info
))
63 dc
.DrawEllipse(x
+ m_PosX
+ m_Width
/ 3, y
+ m_PosY
+ m_Height
/ 3,
64 (m_Width
/ 3), (m_Width
/ 3));
67 //-----------------------------------------------------------------------------
69 //-----------------------------------------------------------------------------
71 struct wxHtmlListItemStruct
73 wxHtmlContainerCell
*mark
;
74 wxHtmlContainerCell
*cont
;
79 class wxHtmlListCell
: public wxHtmlContainerCell
85 wxHtmlListItemStruct
*m_RowInfo
;
86 void ReallocRows(int rows
);
87 void ComputeMinMaxWidths();
88 int ComputeMaxBase(wxHtmlCell
*cell
);
92 wxHtmlListCell(wxHtmlContainerCell
*parent
);
93 virtual ~wxHtmlListCell();
94 void AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
);
95 virtual void Layout(int w
);
97 DECLARE_NO_COPY_CLASS(wxHtmlListCell
)
100 wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell
*parent
) : wxHtmlContainerCell(parent
)
107 wxHtmlListCell::~wxHtmlListCell()
109 if (m_RowInfo
) free(m_RowInfo
);
112 int wxHtmlListCell::ComputeMaxBase(wxHtmlCell
*cell
)
117 wxHtmlCell
*child
= cell
->GetFirstChild();
121 int base
= ComputeMaxBase( child
);
122 if ( base
> 0 ) return base
+ child
->GetPosY();
123 child
= child
->GetNext();
126 return cell
->GetHeight() - cell
->GetDescent();
129 void wxHtmlListCell::Layout(int w
)
131 wxHtmlCell::Layout(w
);
133 ComputeMinMaxWidths();
134 m_Width
= wxMax(m_Width
, wxMin(w
, GetMaxTotalWidth()));
136 int s_width
= m_Width
- m_IndentLeft
;
139 for (int r
= 0; r
< m_NumRows
; r
++)
141 // do layout first time to layout contents and adjust pos
142 m_RowInfo
[r
].mark
->Layout(m_ListmarkWidth
);
143 m_RowInfo
[r
].cont
->Layout(s_width
- m_ListmarkWidth
);
145 const int base_mark
= ComputeMaxBase( m_RowInfo
[r
].mark
);
146 const int base_cont
= ComputeMaxBase( m_RowInfo
[r
].cont
);
147 const int adjust_mark
= vpos
+ wxMax(base_cont
-base_mark
,0);
148 const int adjust_cont
= vpos
+ wxMax(base_mark
-base_cont
,0);
150 m_RowInfo
[r
].mark
->SetPos(m_IndentLeft
, adjust_mark
);
151 m_RowInfo
[r
].cont
->SetPos(m_IndentLeft
+ m_ListmarkWidth
, adjust_cont
);
153 vpos
= wxMax(adjust_mark
+ m_RowInfo
[r
].mark
->GetHeight(),
154 adjust_cont
+ m_RowInfo
[r
].cont
->GetHeight());
159 void wxHtmlListCell::AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
)
161 ReallocRows(++m_NumRows
);
162 m_RowInfo
[m_NumRows
- 1].mark
= mark
;
163 m_RowInfo
[m_NumRows
- 1].cont
= cont
;
166 void wxHtmlListCell::ReallocRows(int rows
)
168 m_RowInfo
= (wxHtmlListItemStruct
*) realloc(m_RowInfo
, sizeof(wxHtmlListItemStruct
) * rows
);
169 m_RowInfo
[rows
- 1].mark
= NULL
;
170 m_RowInfo
[rows
- 1].cont
= NULL
;
171 m_RowInfo
[rows
- 1].minWidth
= 0;
172 m_RowInfo
[rows
- 1].maxWidth
= 0;
177 void wxHtmlListCell::ComputeMinMaxWidths()
179 if (m_NumRows
== 0) return;
184 for (int r
= 0; r
< m_NumRows
; r
++)
186 wxHtmlListItemStruct
& row
= m_RowInfo
[r
];
189 int maxWidth
= row
.cont
->GetMaxTotalWidth();
190 int width
= row
.cont
->GetWidth();
191 if (row
.mark
->GetWidth() > m_ListmarkWidth
)
192 m_ListmarkWidth
= row
.mark
->GetWidth();
193 if (maxWidth
> m_MaxTotalWidth
)
194 m_MaxTotalWidth
= maxWidth
;
198 m_Width
+= m_ListmarkWidth
+ m_IndentLeft
;
199 m_MaxTotalWidth
+= m_ListmarkWidth
+ m_IndentLeft
;
202 //-----------------------------------------------------------------------------
203 // wxHtmlListcontentCell
204 //-----------------------------------------------------------------------------
206 class wxHtmlListcontentCell
: public wxHtmlContainerCell
209 wxHtmlListcontentCell(wxHtmlContainerCell
*p
) : wxHtmlContainerCell(p
) {}
210 virtual void Layout(int w
) {
211 // Reset top indentation, fixes <li><p>
212 SetIndent(0, wxHTML_INDENT_TOP
);
213 wxHtmlContainerCell::Layout(w
);
217 //-----------------------------------------------------------------------------
219 //-----------------------------------------------------------------------------
222 TAG_HANDLER_BEGIN(OLULLI
, "OL,UL,LI")
225 wxHtmlListCell
*m_List
;
227 // this is number of actual item of list or 0 for dots
229 TAG_HANDLER_CONSTR(OLULLI
)
235 TAG_HANDLER_PROC(tag
)
237 wxHtmlContainerCell
*c
;
240 if (m_List
&& tag
.GetName() == wxT("LI"))
242 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_List
));
243 c
->SetAlignVer(wxHTML_ALIGN_TOP
);
245 wxHtmlContainerCell
*mark
= c
;
246 c
->SetWidthFloat(2 * m_WParser
->GetCharWidth(), wxHTML_UNITS_PIXELS
);
247 if (m_Numbering
== 0)
249 // Centering gives more space after the bullet
250 c
->SetAlignHor(wxHTML_ALIGN_CENTER
);
251 c
->InsertCell(new wxHtmlListmarkCell(m_WParser
->GetDC(), m_WParser
->GetActualColor()));
255 c
->SetAlignHor(wxHTML_ALIGN_RIGHT
);
257 markStr
.Printf(wxT("%i. "), m_Numbering
);
258 c
->InsertCell(new wxHtmlWordCell(markStr
, *(m_WParser
->GetDC())));
260 m_WParser
->CloseContainer();
262 c
= m_WParser
->OpenContainer();
264 m_List
->AddRow(mark
, c
);
265 c
= m_WParser
->OpenContainer();
266 m_WParser
->SetContainer(new wxHtmlListcontentCell(c
));
268 if (m_Numbering
!= 0) m_Numbering
++;
271 // Begin of List (not-numbered): "UL", "OL"
272 else if (tag
.GetName() == wxT("UL") || tag
.GetName() == wxT("OL"))
274 int oldnum
= m_Numbering
;
276 if (tag
.GetName() == wxT("UL")) m_Numbering
= 0;
277 else m_Numbering
= 1;
279 wxHtmlContainerCell
*oldcont
;
280 oldcont
= c
= m_WParser
->OpenContainer();
282 wxHtmlListCell
*oldList
= m_List
;
283 m_List
= new wxHtmlListCell(c
);
284 m_List
->SetIndent(2 * m_WParser
->GetCharWidth(), wxHTML_INDENT_LEFT
);
288 m_WParser
->SetContainer(oldcont
);
289 m_WParser
->CloseContainer();
291 m_Numbering
= oldnum
;
299 TAG_HANDLER_END(OLULLI
)
302 TAGS_MODULE_BEGIN(List
)
304 TAGS_MODULE_ADD(OLULLI
)
306 TAGS_MODULE_END(List
)