1
2 #include "docblock.h"
3
4 #ifndef CB_PRECOMP
5 #include "cbcolourmanager.h"
6 #endif
7 #include <iostream>
8
DocBlock()9 DocBlock::DocBlock():
10 m_Description(_T("**description**")),
11 m_Brief(_T("**brief**"))
12 {
13 //ctor
14 }
15
~DocBlock()16 DocBlock::~DocBlock()
17 {
18 //dtor
19 }
20
GetDescription()21 wxString DocBlock::GetDescription()
22 {
23 if (m_DocMap.count(m_Description) == 1)
24 return m_DocMap[m_Description];
25
26 return wxEmptyString;
27 }
28
HasDescription()29 bool DocBlock::HasDescription()
30 {
31 return (m_DocMap.count(m_Description) == 1);
32 }
33
AddDescription(const wxString & descr)34 void DocBlock::AddDescription(const wxString &descr)
35 {
36 m_DocMap[m_Description] = descr;
37 }
38
GetBrief()39 wxString DocBlock::GetBrief()
40 {
41 if (m_DocMap.count(m_Brief) == 1)
42 return m_DocMap[m_Brief];
43
44 return wxEmptyString;
45 }
46
HasBrief()47 bool DocBlock::HasBrief()
48 {
49 return (m_DocMap.count(m_Brief) == 1);
50 }
51
GetParamCount()52 int DocBlock::GetParamCount()
53 {
54 int pc = 0;
55 for (std::map<wxString,wxString>::iterator it = m_DocMap.begin(); it != m_DocMap.end(); ++it)
56 {
57 if (!it->first.IsSameAs(m_Description) && !it->first.IsSameAs(m_Brief))
58 pc++;
59 }
60 return pc;
61 }
62
GetValue(wxString & key)63 wxString DocBlock::GetValue(wxString& key)
64 {
65 if (m_DocMap.count(key) == 1)
66 return m_DocMap[key];
67
68 return wxEmptyString;
69 }
70
AddBrief(const wxString & bline)71 void DocBlock::AddBrief(const wxString &bline)
72 {
73 m_DocMap[_T("**brief**")] = bline;
74 }
75
AddParam(const wxString & name,const wxString & descr)76 void DocBlock::AddParam(const wxString &name, const wxString &descr)
77 {
78 m_DocMap[name.Lower()] = descr;
79 }
80
Clear()81 void DocBlock::Clear()
82 {
83 m_DocMap.clear();
84 }
85
86 //*****************************************
87 namespace HTMLTags
88 {
89 static const wxString br = _T("<br>");
90 static const wxString sep = _T(" ");
91 static const wxString b1 = _T("<b>");
92 static const wxString b0 = _T("</b>");
93
94 static const wxString a1 = _T("<a>");
95 static const wxString a0 = _T("</a>");
96
97 static const wxString i1 = _T("<i>");
98 static const wxString i0 = _T("</i>");
99
100 static const wxString pre1 = _T("<pre>");
101 static const wxString pre0 = _T("</pre>");
102
103 static const wxString nbsp(_T(" "));
104 static const wxString tab = nbsp + nbsp + nbsp;
105
106 static const wxString commandTag = _T("cmd=");
107 }
108
GenerateHtmlDoc(TokenFlat * token,int token_idx,bool & hasDoc)109 wxString HtmlDoc::GenerateHtmlDoc(TokenFlat* token, int token_idx, bool& hasDoc)
110 {
111 //http://docs.wxwidgets.org/2.8/wx_wxhtml.html#htmltagssupported
112 using namespace HTMLTags;
113
114 ColourManager *colours = Manager::Get()->GetColourManager();
115
116 wxString html = _T("<html><body bgcolor=\"");
117 html += colours->GetColour(wxT("cc_docs_back")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\" text=\"");
118 html += colours->GetColour(wxT("cc_docs_fore")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\" link=\"");
119 html += colours->GetColour(wxT("cc_docs_link")).GetAsString(wxC2S_HTML_SYNTAX) + _T("\">");
120
121 html += _T("<a name=\"top\"></a>");
122
123 hasDoc = false;
124 if (!token || token->m_DisplayName.IsEmpty())
125 return wxEmptyString;
126
127 // add parent:
128 if (!token->m_ParentDisplayName.IsEmpty())
129 {
130 wxString parent;
131 if (token->m_ParentTokenKind == tkModule)
132 html += _T("module: ") + b1 + token->m_ParentDisplayName + b0 + br;
133 }
134
135 html += br;
136 wxString moreInfo;
137
138 //add scope and name:
139 switch (token->m_TokenKind)
140 {
141 case tkFunction:
142 html += token->m_PartFirst + _T(" function ") + b1 + token->m_DisplayName + b0;
143 html += _T(" ") + token->m_Args.Trim(false);
144 html += sep + token->m_PartLast;
145 html += br;
146 break;
147
148 case tkSubroutine:
149 html += _T("subroutine ") + b1 + token->m_DisplayName + b0;
150 html += sep + token->m_Args;
151 html += br;
152 if (token->m_ParentTokenKind == tkFile)
153 moreInfo = _T("global");
154 else if (token->m_TokenAccess == taPrivate)
155 moreInfo = _T("private");
156 break;
157
158 case tkVariable:
159 html += token->m_TypeDefinition + _T(" :: ") + b1 + token->m_DisplayName + b0 + token->m_Args + br;
160 moreInfo = token->GetTokenKindString();
161 break;
162
163 case tkInterface:
164 html += token->m_TypeDefinition + nbsp + b1 + token->m_DisplayName + b0 + br;
165 if (token->m_TypeDefinition.IsEmpty())
166 moreInfo = _T("interface");
167 else
168 moreInfo = _T("generic interface");
169 break;
170
171 default:
172 html += b1 + token->m_DisplayName + b0 + br;
173 moreInfo = token->GetTokenKindString();
174 }
175
176 //add kind:
177 if (!moreInfo.IsEmpty())
178 html += i1 + _T("<font color=\"green\" size=3>") + _T("(") +
179 moreInfo +_T(")") + _T("</font>") + i0 + br;
180
181 if (!token->m_DocString.IsEmpty())
182 {
183 const wxString brsep = _T("@brief_end@");
184 size_t brf = token->m_DocString.find(brsep);
185 size_t bre_idx = 11;
186 if (brf != wxString::npos)
187 bre_idx += brf;
188 else
189 bre_idx = 0;
190
191 if (bre_idx > 11)
192 {
193 html += br + i1 + b1 + _T("Brief:") + b0 + i0 + br;
194 html += tab + token->m_DocString.substr(0,brf) + br;
195 hasDoc = true;
196 }
197
198 if (bre_idx < token->m_DocString.size())
199 {
200 html += br + i1 + b1 + _T("Description:") + b0 + i0 + br;
201 html += tab + token->m_DocString.substr(bre_idx) + br;
202 hasDoc = true;
203 }
204 }
205
206 //add go to declaration
207 html += br + br + _T("<a href=\"") + commandTag + _T("goto") + wxString::Format(_T("%i"), token_idx)
208 + _T("\">") + _T("Open declaration") + _T("</a>") + br + br;
209
210 // Append 'close' link:
211 html += _T("<a href=\"") + commandTag + _T("close")
212 + _T("\">") + _T("close") + _T("</a>"),
213
214 html += _T("</body></html>");
215
216 return html;
217 }
218
219
OnDocumentationLink(wxHtmlLinkEvent & event,bool & dismissPopup,bool & isGoto,long int & tokenIdx)220 wxString HtmlDoc::OnDocumentationLink(wxHtmlLinkEvent &event, bool &dismissPopup, bool &isGoto, long int &tokenIdx)
221 {
222 using namespace HTMLTags;
223
224 const wxString& href = event.GetLinkInfo().GetHref();
225 wxString args;
226 wxString tidx_str;
227
228 dismissPopup = false;
229 isGoto = false;
230
231 if (!href.StartsWith(commandTag, &args))
232 return wxEmptyString;
233
234 if (args.StartsWith(_T("goto"), &tidx_str))
235 {
236 if(tidx_str.ToLong(&tokenIdx))
237 {
238 dismissPopup = true;
239 isGoto = true;
240 }
241 }
242 else if (args.StartsWith(_T("close")))
243 dismissPopup = true;
244
245 return wxEmptyString;
246 }
247
GetDocForTooltip(TokenFlat * token)248 wxString HtmlDoc::GetDocForTooltip(TokenFlat* token)
249 {
250 return HtmlDoc::GetDocShort(token->m_DocString);
251 }
252
GetDocShort(const wxString & tokDoc)253 wxString HtmlDoc::GetDocShort(const wxString& tokDoc)
254 {
255 wxString doc;
256 if (!tokDoc.IsEmpty())
257 {
258 const wxString brsep = _T("@brief_end@");
259 size_t brf = tokDoc.find(brsep);
260 size_t bre_idx = 11;
261 if (brf != wxString::npos)
262 bre_idx += brf;
263 else
264 bre_idx = 0;
265
266 if (bre_idx > 11)
267 {
268 doc = tokDoc.substr(0,brf);
269 }
270 else if (bre_idx < tokDoc.size())
271 {
272 doc = tokDoc.substr(bre_idx);
273 if (doc.size() > 120) // limit length of doc
274 doc = doc.substr(0,120) + _T("...");
275 }
276 }
277 return doc;
278 }
279
280
281