]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_list.cpp
98f1d2b9b10214bc2bf83a52f16505eae15e26d8
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_list.cpp
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"
16 #if wxUSE_HTML && wxUSE_STREAMS
23 #include "wx/html/forcelnk.h"
24 #include "wx/html/m_templ.h"
26 #include "wx/html/htmlcell.h"
31 //-----------------------------------------------------------------------------
33 //-----------------------------------------------------------------------------
35 class wxHtmlListmarkCell
: public wxHtmlCell
40 wxHtmlListmarkCell(wxDC
*dc
, const wxColour
& clr
);
41 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
,
42 wxHtmlRenderingInfo
& info
);
44 DECLARE_NO_COPY_CLASS(wxHtmlListmarkCell
)
47 wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC
* dc
, const wxColour
& clr
) : wxHtmlCell(), m_Brush(clr
, wxBRUSHSTYLE_SOLID
)
49 m_Width
= dc
->GetCharHeight();
50 m_Height
= dc
->GetCharHeight();
51 // bottom of list mark is lined with bottom of letters in next cell
52 m_Descent
= m_Height
/ 3;
57 void wxHtmlListmarkCell::Draw(wxDC
& dc
, int x
, int y
,
58 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
59 wxHtmlRenderingInfo
& WXUNUSED(info
))
62 dc
.DrawEllipse(x
+ m_PosX
+ m_Width
/ 3, y
+ m_PosY
+ m_Height
/ 3,
63 (m_Width
/ 3), (m_Width
/ 3));
66 //-----------------------------------------------------------------------------
68 //-----------------------------------------------------------------------------
70 struct wxHtmlListItemStruct
72 wxHtmlContainerCell
*mark
;
73 wxHtmlContainerCell
*cont
;
78 class wxHtmlListCell
: public wxHtmlContainerCell
84 wxHtmlListItemStruct
*m_RowInfo
;
85 void ReallocRows(int rows
);
86 void ComputeMinMaxWidths();
87 int ComputeMaxBase(wxHtmlCell
*cell
);
91 wxHtmlListCell(wxHtmlContainerCell
*parent
);
92 virtual ~wxHtmlListCell();
93 void AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
);
94 virtual void Layout(int w
);
96 DECLARE_NO_COPY_CLASS(wxHtmlListCell
)
99 wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell
*parent
) : wxHtmlContainerCell(parent
)
106 wxHtmlListCell::~wxHtmlListCell()
108 if (m_RowInfo
) free(m_RowInfo
);
111 int wxHtmlListCell::ComputeMaxBase(wxHtmlCell
*cell
)
116 wxHtmlCell
*child
= cell
->GetFirstChild();
120 int base
= ComputeMaxBase( child
);
121 if ( base
> 0 ) return base
+ child
->GetPosY();
122 child
= child
->GetNext();
125 return cell
->GetHeight() - cell
->GetDescent();
128 void wxHtmlListCell::Layout(int w
)
130 wxHtmlCell::Layout(w
);
132 ComputeMinMaxWidths();
133 m_Width
= wxMax(m_Width
, wxMin(w
, GetMaxTotalWidth()));
135 int s_width
= m_Width
- m_IndentLeft
;
138 for (int r
= 0; r
< m_NumRows
; r
++)
140 // do layout first time to layout contents and adjust pos
141 m_RowInfo
[r
].mark
->Layout(m_ListmarkWidth
);
142 m_RowInfo
[r
].cont
->Layout(s_width
- m_ListmarkWidth
);
144 const int base_mark
= ComputeMaxBase( m_RowInfo
[r
].mark
);
145 const int base_cont
= ComputeMaxBase( m_RowInfo
[r
].cont
);
146 const int adjust_mark
= vpos
+ wxMax(base_cont
-base_mark
,0);
147 const int adjust_cont
= vpos
+ wxMax(base_mark
-base_cont
,0);
149 m_RowInfo
[r
].mark
->SetPos(m_IndentLeft
, adjust_mark
);
150 m_RowInfo
[r
].cont
->SetPos(m_IndentLeft
+ m_ListmarkWidth
, adjust_cont
);
152 vpos
= wxMax(adjust_mark
+ m_RowInfo
[r
].mark
->GetHeight(),
153 adjust_cont
+ m_RowInfo
[r
].cont
->GetHeight());
158 void wxHtmlListCell::AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
)
160 ReallocRows(++m_NumRows
);
161 m_RowInfo
[m_NumRows
- 1].mark
= mark
;
162 m_RowInfo
[m_NumRows
- 1].cont
= cont
;
165 void wxHtmlListCell::ReallocRows(int rows
)
167 m_RowInfo
= (wxHtmlListItemStruct
*) realloc(m_RowInfo
, sizeof(wxHtmlListItemStruct
) * rows
);
168 m_RowInfo
[rows
- 1].mark
= NULL
;
169 m_RowInfo
[rows
- 1].cont
= NULL
;
170 m_RowInfo
[rows
- 1].minWidth
= 0;
171 m_RowInfo
[rows
- 1].maxWidth
= 0;
176 void wxHtmlListCell::ComputeMinMaxWidths()
178 if (m_NumRows
== 0) return;
183 for (int r
= 0; r
< m_NumRows
; r
++)
185 wxHtmlListItemStruct
& row
= m_RowInfo
[r
];
188 int maxWidth
= row
.cont
->GetMaxTotalWidth();
189 int width
= row
.cont
->GetWidth();
190 if (row
.mark
->GetWidth() > m_ListmarkWidth
)
191 m_ListmarkWidth
= row
.mark
->GetWidth();
192 if (maxWidth
> m_MaxTotalWidth
)
193 m_MaxTotalWidth
= maxWidth
;
197 m_Width
+= m_ListmarkWidth
+ m_IndentLeft
;
198 m_MaxTotalWidth
+= m_ListmarkWidth
+ m_IndentLeft
;
201 //-----------------------------------------------------------------------------
202 // wxHtmlListcontentCell
203 //-----------------------------------------------------------------------------
205 class wxHtmlListcontentCell
: public wxHtmlContainerCell
208 wxHtmlListcontentCell(wxHtmlContainerCell
*p
) : wxHtmlContainerCell(p
) {}
209 virtual void Layout(int w
) {
210 // Reset top indentation, fixes <li><p>
211 SetIndent(0, wxHTML_INDENT_TOP
);
212 wxHtmlContainerCell::Layout(w
);
216 //-----------------------------------------------------------------------------
218 //-----------------------------------------------------------------------------
221 TAG_HANDLER_BEGIN(OLULLI
, "OL,UL,LI")
224 wxHtmlListCell
*m_List
;
226 // this is number of actual item of list or 0 for dots
228 TAG_HANDLER_CONSTR(OLULLI
)
234 TAG_HANDLER_PROC(tag
)
236 wxHtmlContainerCell
*c
;
239 if (m_List
&& tag
.GetName() == wxT("LI"))
241 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_List
));
242 c
->SetAlignVer(wxHTML_ALIGN_TOP
);
244 wxHtmlContainerCell
*mark
= c
;
245 c
->SetWidthFloat(2 * m_WParser
->GetCharWidth(), wxHTML_UNITS_PIXELS
);
246 if (m_Numbering
== 0)
248 // Centering gives more space after the bullet
249 c
->SetAlignHor(wxHTML_ALIGN_CENTER
);
250 c
->InsertCell(new wxHtmlListmarkCell(m_WParser
->GetDC(), m_WParser
->GetActualColor()));
254 c
->SetAlignHor(wxHTML_ALIGN_RIGHT
);
256 markStr
.Printf(wxT("%i. "), m_Numbering
);
257 c
->InsertCell(new wxHtmlWordCell(markStr
, *(m_WParser
->GetDC())));
259 m_WParser
->CloseContainer();
261 c
= m_WParser
->OpenContainer();
263 m_List
->AddRow(mark
, c
);
264 c
= m_WParser
->OpenContainer();
265 m_WParser
->SetContainer(new wxHtmlListcontentCell(c
));
267 if (m_Numbering
!= 0) m_Numbering
++;
270 // Begin of List (not-numbered): "UL", "OL"
271 else if (tag
.GetName() == wxT("UL") || tag
.GetName() == wxT("OL"))
273 int oldnum
= m_Numbering
;
275 if (tag
.GetName() == wxT("UL")) m_Numbering
= 0;
276 else m_Numbering
= 1;
278 wxHtmlContainerCell
*oldcont
;
279 oldcont
= c
= m_WParser
->OpenContainer();
281 wxHtmlListCell
*oldList
= m_List
;
282 m_List
= new wxHtmlListCell(c
);
283 m_List
->SetIndent(2 * m_WParser
->GetCharWidth(), wxHTML_INDENT_LEFT
);
287 m_WParser
->SetContainer(oldcont
);
288 m_WParser
->CloseContainer();
290 m_Numbering
= oldnum
;
298 TAG_HANDLER_END(OLULLI
)
301 TAGS_MODULE_BEGIN(List
)
303 TAGS_MODULE_ADD(OLULLI
)
305 TAGS_MODULE_END(List
)