]>
Commit | Line | Data |
---|---|---|
5526e819 VS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: mod_list.cpp | |
3 | // Purpose: wxHtml module for lists | |
4 | // Author: Vaclav Slavik | |
5 | // Copyright: (c) 1999 Vaclav Slavik | |
6 | // Licence: wxWindows Licence | |
7 | ///////////////////////////////////////////////////////////////////////////// | |
8 | ||
9 | #include "wx/defs.h" | |
10 | #if wxUSE_HTML | |
11 | ||
12 | #include <wx/html/forcelink.h> | |
13 | #include <wx/html/mod_templ.h> | |
14 | ||
15 | #include <wx/html/htmlcell.h> | |
16 | ||
17 | FORCE_LINK_ME(mod_list) | |
18 | ||
19 | ||
20 | //----------------------------------------------------------------------------- | |
21 | // wxHtmlListmarkCell | |
22 | //----------------------------------------------------------------------------- | |
23 | ||
24 | class wxHtmlListmarkCell : public wxHtmlCell | |
25 | { | |
26 | private: | |
27 | wxBrush m_Brush; | |
28 | public: | |
29 | wxHtmlListmarkCell(wxDC *dc, const wxColour& clr); | |
30 | void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2); | |
31 | }; | |
32 | ||
33 | wxHtmlListmarkCell::wxHtmlListmarkCell(wxDC* dc, const wxColour& clr) : wxHtmlCell(), m_Brush(clr, wxSOLID) | |
34 | { | |
35 | m_Width = dc -> GetCharWidth(); | |
36 | m_Height = dc -> GetCharHeight(); | |
37 | m_Descent = 0; | |
38 | } | |
39 | ||
40 | ||
41 | ||
42 | void wxHtmlListmarkCell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2) | |
43 | { | |
44 | dc.SetBrush(m_Brush); | |
45 | dc.DrawEllipse(x + m_PosX + m_Width / 4, y + m_PosY + m_Height / 4, m_Width / 2, m_Width / 2); | |
46 | wxHtmlCell::Draw(dc, x, y, view_y1, view_y2); | |
47 | } | |
48 | ||
49 | ||
50 | ||
51 | ||
52 | //----------------------------------------------------------------------------- | |
53 | // The list handler: | |
54 | //----------------------------------------------------------------------------- | |
55 | ||
56 | ||
57 | TAG_HANDLER_BEGIN(OLULLI, "OL,UL,LI") | |
58 | ||
59 | TAG_HANDLER_VARS | |
60 | int m_Numbering; | |
61 | // this is number of actual item of list or 0 for dots | |
62 | ||
63 | TAG_HANDLER_CONSTR(OLULLI) | |
64 | { | |
65 | m_Numbering = 0; | |
66 | } | |
67 | ||
68 | TAG_HANDLER_PROC(tag) | |
69 | { | |
70 | wxHtmlContainerCell *c; | |
71 | ||
72 | // List Item: | |
73 | if (tag.GetName() == "LI") { | |
74 | if (!tag.IsEnding()) { | |
75 | m_WParser -> CloseContainer(); | |
76 | m_WParser -> CloseContainer(); | |
77 | ||
78 | c = m_WParser -> OpenContainer(); | |
79 | c -> SetWidthFloat(2 * m_WParser -> GetCharWidth(), HTML_UNITS_PIXELS); | |
80 | c -> SetAlignHor(HTML_ALIGN_RIGHT); | |
81 | if (m_Numbering == 0) | |
82 | c -> InsertCell(new wxHtmlListmarkCell(m_WParser -> GetDC(), m_WParser -> GetActualColor())); | |
83 | else { | |
84 | wxString mark; | |
85 | mark.Printf("%i.", m_Numbering); | |
86 | c -> InsertCell(new wxHtmlWordCell(mark, *(m_WParser -> GetDC()))); | |
87 | } | |
88 | m_WParser -> CloseContainer(); | |
89 | ||
90 | c = m_WParser -> OpenContainer(); | |
91 | c -> SetIndent(m_WParser -> GetCharWidth() / 4, HTML_INDENT_LEFT); | |
92 | c -> SetWidthFloat(-2 * m_WParser -> GetCharWidth(), HTML_UNITS_PIXELS); | |
93 | ||
94 | m_WParser -> OpenContainer(); | |
95 | ||
96 | if (m_Numbering != 0) m_Numbering++; | |
97 | } | |
98 | return FALSE; | |
99 | } | |
100 | ||
101 | // Begin of List (not-numbered): "UL", "OL" | |
102 | else { | |
103 | int oldnum = m_Numbering; | |
104 | ||
105 | if (tag.GetName() == "UL") m_Numbering = 0; | |
106 | else m_Numbering = 1; | |
107 | ||
108 | c = m_WParser -> GetContainer(); | |
109 | if (c -> GetFirstCell() != NULL) { | |
110 | m_WParser -> CloseContainer(); | |
111 | m_WParser -> OpenContainer(); | |
112 | c = m_WParser -> GetContainer(); | |
113 | } | |
114 | c -> SetAlignHor(HTML_ALIGN_LEFT); | |
115 | c -> SetIndent(2 * m_WParser -> GetCharWidth(), HTML_INDENT_LEFT); | |
116 | m_WParser -> OpenContainer() -> SetAlignVer(HTML_ALIGN_TOP); | |
117 | ||
118 | m_WParser -> OpenContainer(); | |
119 | m_WParser -> OpenContainer(); | |
120 | ParseInner(tag); | |
121 | m_WParser -> CloseContainer(); | |
122 | ||
123 | m_WParser -> CloseContainer(); | |
124 | m_WParser -> CloseContainer(); | |
125 | m_WParser -> CloseContainer(); | |
126 | m_WParser -> OpenContainer(); | |
127 | ||
128 | m_Numbering = oldnum; | |
129 | return TRUE; | |
130 | } | |
131 | } | |
132 | ||
133 | TAG_HANDLER_END(OLULLI) | |
134 | ||
135 | ||
136 | TAGS_MODULE_BEGIN(List) | |
137 | ||
138 | TAGS_MODULE_ADD(OLULLI) | |
139 | ||
140 | TAGS_MODULE_END(List) | |
141 | ||
142 | #endif |