]>
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();
56 // bottom of list mark is lined with bottom of letters in next cell
57 m_Descent
= m_Height
/ 3;
62 void wxHtmlListmarkCell::Draw(wxDC
& dc
, int x
, int y
,
63 int WXUNUSED(view_y1
), int WXUNUSED(view_y2
),
64 wxHtmlRenderingInfo
& WXUNUSED(info
))
67 dc
.DrawEllipse(x
+ m_PosX
+ m_Width
/ 3, y
+ m_PosY
+ m_Height
/ 3,
68 (m_Width
/ 3), (m_Width
/ 3));
71 //-----------------------------------------------------------------------------
73 //-----------------------------------------------------------------------------
75 struct wxHtmlListItemStruct
77 wxHtmlContainerCell
*mark
;
78 wxHtmlContainerCell
*cont
;
83 class wxHtmlListCell
: public wxHtmlContainerCell
89 wxHtmlListItemStruct
*m_RowInfo
;
90 void ReallocRows(int rows
);
91 void ComputeMinMaxWidths();
92 int ComputeMaxBase(wxHtmlCell
*cell
);
96 wxHtmlListCell(wxHtmlContainerCell
*parent
);
97 virtual ~wxHtmlListCell();
98 void AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
);
99 virtual void Layout(int w
);
101 DECLARE_NO_COPY_CLASS(wxHtmlListCell
)
104 wxHtmlListCell::wxHtmlListCell(wxHtmlContainerCell
*parent
) : wxHtmlContainerCell(parent
)
111 wxHtmlListCell::~wxHtmlListCell()
113 if (m_RowInfo
) free(m_RowInfo
);
116 int wxHtmlListCell::ComputeMaxBase(wxHtmlCell
*cell
)
121 wxHtmlCell
*child
= cell
->GetFirstChild();
125 int base
= ComputeMaxBase( child
);
126 if ( base
> 0 ) return base
+ child
->GetPosY();
127 child
= child
->GetNext();
130 return cell
->GetHeight() - cell
->GetDescent();
133 void wxHtmlListCell::Layout(int w
)
135 wxHtmlCell::Layout(w
);
137 ComputeMinMaxWidths();
138 m_Width
= wxMax(m_Width
, wxMin(w
, GetMaxTotalWidth()));
140 int s_width
= m_Width
- m_IndentLeft
;
143 for (int r
= 0; r
< m_NumRows
; r
++)
145 // do layout first time to layout contents and adjust pos
146 m_RowInfo
[r
].mark
->Layout(m_ListmarkWidth
);
147 m_RowInfo
[r
].cont
->Layout(s_width
- m_ListmarkWidth
);
149 const int base_mark
= ComputeMaxBase( m_RowInfo
[r
].mark
);
150 const int base_cont
= ComputeMaxBase( m_RowInfo
[r
].cont
);
151 const int adjust_mark
= vpos
+ wxMax(base_cont
-base_mark
,0);
152 const int adjust_cont
= vpos
+ wxMax(base_mark
-base_cont
,0);
154 m_RowInfo
[r
].mark
->SetPos(m_IndentLeft
, adjust_mark
);
155 m_RowInfo
[r
].cont
->SetPos(m_IndentLeft
+ m_ListmarkWidth
, adjust_cont
);
157 vpos
= wxMax(adjust_mark
+ m_RowInfo
[r
].mark
->GetHeight(),
158 adjust_cont
+ m_RowInfo
[r
].cont
->GetHeight());
163 void wxHtmlListCell::AddRow(wxHtmlContainerCell
*mark
, wxHtmlContainerCell
*cont
)
165 ReallocRows(++m_NumRows
);
166 m_RowInfo
[m_NumRows
- 1].mark
= mark
;
167 m_RowInfo
[m_NumRows
- 1].cont
= cont
;
170 void wxHtmlListCell::ReallocRows(int rows
)
172 m_RowInfo
= (wxHtmlListItemStruct
*) realloc(m_RowInfo
, sizeof(wxHtmlListItemStruct
) * rows
);
173 m_RowInfo
[rows
- 1].mark
= NULL
;
174 m_RowInfo
[rows
- 1].cont
= NULL
;
175 m_RowInfo
[rows
- 1].minWidth
= 0;
176 m_RowInfo
[rows
- 1].maxWidth
= 0;
181 void wxHtmlListCell::ComputeMinMaxWidths()
183 if (m_NumRows
== 0) return;
188 for (int r
= 0; r
< m_NumRows
; r
++)
190 wxHtmlListItemStruct
& row
= m_RowInfo
[r
];
193 int maxWidth
= row
.cont
->GetMaxTotalWidth();
194 int width
= row
.cont
->GetWidth();
195 if (row
.mark
->GetWidth() > m_ListmarkWidth
)
196 m_ListmarkWidth
= row
.mark
->GetWidth();
197 if (maxWidth
> m_MaxTotalWidth
)
198 m_MaxTotalWidth
= maxWidth
;
202 m_Width
+= m_ListmarkWidth
+ m_IndentLeft
;
203 m_MaxTotalWidth
+= m_ListmarkWidth
+ m_IndentLeft
;
206 //-----------------------------------------------------------------------------
207 // wxHtmlListcontentCell
208 //-----------------------------------------------------------------------------
210 class wxHtmlListcontentCell
: public wxHtmlContainerCell
213 wxHtmlListcontentCell(wxHtmlContainerCell
*p
) : wxHtmlContainerCell(p
) {}
214 virtual void Layout(int w
) {
215 // Reset top indentation, fixes <li><p>
216 SetIndent(0, wxHTML_INDENT_TOP
);
217 wxHtmlContainerCell::Layout(w
);
221 //-----------------------------------------------------------------------------
223 //-----------------------------------------------------------------------------
226 TAG_HANDLER_BEGIN(OLULLI
, "OL,UL,LI")
229 wxHtmlListCell
*m_List
;
231 // this is number of actual item of list or 0 for dots
233 TAG_HANDLER_CONSTR(OLULLI
)
239 TAG_HANDLER_PROC(tag
)
241 wxHtmlContainerCell
*c
;
244 if (m_List
&& tag
.GetName() == wxT("LI"))
246 c
= m_WParser
->SetContainer(new wxHtmlContainerCell(m_List
));
247 c
->SetAlignVer(wxHTML_ALIGN_TOP
);
249 wxHtmlContainerCell
*mark
= c
;
250 c
->SetWidthFloat(2 * m_WParser
->GetCharWidth(), wxHTML_UNITS_PIXELS
);
251 if (m_Numbering
== 0)
253 // Centering gives more space after the bullet
254 c
->SetAlignHor(wxHTML_ALIGN_CENTER
);
255 c
->InsertCell(new wxHtmlListmarkCell(m_WParser
->GetDC(), m_WParser
->GetActualColor()));
259 c
->SetAlignHor(wxHTML_ALIGN_RIGHT
);
261 markStr
.Printf(wxT("%i."), m_Numbering
);
262 c
->InsertCell(new wxHtmlWordCell(markStr
, *(m_WParser
->GetDC())));
264 m_WParser
->CloseContainer();
266 c
= m_WParser
->OpenContainer();
268 m_List
->AddRow(mark
, c
);
269 c
= m_WParser
->OpenContainer();
270 m_WParser
->SetContainer(new wxHtmlListcontentCell(c
));
272 if (m_Numbering
!= 0) m_Numbering
++;
275 // Begin of List (not-numbered): "UL", "OL"
276 else if (tag
.GetName() == wxT("UL") || tag
.GetName() == wxT("OL"))
278 int oldnum
= m_Numbering
;
280 if (tag
.GetName() == wxT("UL")) m_Numbering
= 0;
281 else m_Numbering
= 1;
283 wxHtmlContainerCell
*oldcont
;
284 oldcont
= c
= m_WParser
->OpenContainer();
286 wxHtmlListCell
*oldList
= m_List
;
287 m_List
= new wxHtmlListCell(c
);
288 m_List
->SetIndent(2 * m_WParser
->GetCharWidth(), wxHTML_INDENT_LEFT
);
292 m_WParser
->SetContainer(oldcont
);
293 m_WParser
->CloseContainer();
295 m_Numbering
= oldnum
;
303 TAG_HANDLER_END(OLULLI
)
306 TAGS_MODULE_BEGIN(List
)
308 TAGS_MODULE_ADD(OLULLI
)
310 TAGS_MODULE_END(List
)