Rewritten technote for Doxygen documentation
[wxWidgets.git] / docs / tech / tn0003.txt
1                      Adding wxWidgets class documentation
2                      ====================================
3
4 This note is aimed at people wishing to add documentation for a
5 class to either the main wxWidgets manual, or to their own
6 manual.
7
8 wxWidgets uses Doxygen to process header input files with embedded
9 documentation in the form of C++ comments and output in HTML, and XML
10 (Doxygen itself can also output Latex, manpages, RTF, PDF etc).
11 See http://www.doxygen.org for more info about Doxygen.
12
13 If you want to add documentation of a new class/function to the 
14 existing manual in docs/doxygen, you need to create a new .h file,
15 e.g. myclass.h, under the interface folder, which contains the public
16 interface of the new class/function in C++ syntax.
17 The documentation can then be added in form of Doxygen comments to
18 the header file.
19
20 You may also want to write a separate topic file,
21 e.g. docs/doxygen/overviews/myclass.h, and add the entry to
22 docs/doxygen/mainpages/topics.h.
23
24 If applicable, also add an entry to docs/doxygen/mainpages/categories.h.
25
26 You can generate a first raw version of myclass.h simply taking its
27 "real" header and removing all the private and protected sections and
28 in general removing everything the user "shouldn't know": i.e. all things
29 which are implementation details.
30
31
32 Running Doxygen
33 ===============
34
35 First, make sure you have a recent version of Doxygen installed in your system.
36
37 For HTML:
38
39   1) cd wxWidgets/docs/doxygen
40   2) run ./regen.sh [Unix]    or   regen.bat [Windows]
41
42 [TODO: istructions for generation of other formats]
43
44
45 Important Dos and Don'ts
46 ========================
47
48 DO:
49
50 - Doxygen supports both commands in the form \command and @command;
51   all wxWidgets documentation uses the @command form.
52
53 - strive to use dedicated Doxygen commands for e.g. notes, lists,
54   sections, etc. The "Special commands" page:
55     http://www.stack.nl/~dimitri/doxygen/commands.html
56   is your friend!
57   It's also very important to make a consistent use of the ALIASES
58   defined by wxWidgets' Doxyfile. Open that file for more info.
59
60 - when you write true, false and NULL with their C++ semantic meaning,
61   then use the @true, @false and @NULL commands.
62
63 - separe different paragraphs with an empty comment line.
64   This is important otherwise Doxygen puts everything in the same
65   paragraph making the result less readable.
66
67 - leave a blank comment line between a @section, @subsection, @page
68   and the next paragraph.
69
70 - test your changes, both reading the generated HTML docs and by looking
71   at the "doxygen.log" file produced (which will warn you about any
72   eventual mistake found in the comments).
73
74 - quote all the following characters prefixing them with a "@" char:
75
76          @  $  \  &  <  >  #  %
77
78 - when using a Doxygen alias like @itemdef{}, you need to escape the
79   comma characters which appear on the first argument, otherwise Doxygen
80   will interpret them as the marker of the end of the first argument and
81   the beginning of the second argument's text.
82
83   E.g. if you want to define the item "wxEVT_MACRO(id, func)" you need to
84        write:
85             @itemdef{wxEVT_MACRO(id\, func), This is the description of the macro}
86
87   Also note that you need to escape only the commas of the first argument's text;
88   second argument can have up to 10 commas unescaped (see the Doxyfile for the
89   trick used to implement this).
90
91 DON'T:
92
93 - use jargon, such as 'gonna', or omit the definite article.
94   The manual is intended to be a fluent, English document and
95   not a collection of rough notes.
96
97 - use non-alphanumeric characters in link anchors.
98
99
100 Documentation comment for a class
101 =================================
102
103 Start off with:
104
105 /**
106  * @class wxMyClass
107  * @headerfile wx/myclass.h
108  *
109  * ...here goes the description... 
110  *
111  * @beginEventTable
112  * @event{EVT_SOME_EVENT(id, func)}:
113  *        Description for EVT_SOME_EVENT.
114  * @endEventTable
115  *
116  * @beginStyleTable
117  * @style{wxSOME_STYLE}:
118  *        Description for wxSOME_STYLE.
119  * ...
120  * @endStyleTable
121  *
122  * @beginExtraStyleTable
123  * @style{wxSOME_EXTRA_STYLE}:
124  *        Description for wxSOME_EXTRA_STYLE.
125  * ...
126  * @endExtraStyleTable
127  *
128  * @library{wxbase}
129  * @stdobjects
130  * ...here goes the list of predefined instances...
131  *
132  * @seealso
133  * ...here goes the see-also list...
134  * you can make references to topic overviews or other
135  * manual pages using the @ref command
136  */
137
138 Note that the events, styles and extra-styles tables as
139 well as @stdobjects and @seealso lists are optional.
140
141 Also note that you shouldn't use the Doxygen builtin @sa command
142 for the see-also list but rather the wxWidgets' alias @seealso
143 in this case.
144
145
146 Documentation comment for a function
147 ====================================
148
149 Start off with:
150
151 /**
152  * ...here goes the description of the function....
153  *
154  * @param param1
155  * ...here goes the description for the first parameter of this function
156  * @param param2
157  * ...here goes the description for the second parameter of this function
158  * ...
159  *
160  * @return
161  * ...here goes the description of what the function returns...
162  *
163  * @note ...here go any eventual notes about this function...
164  *
165  * @remarks ...here go any eventual remarks about this function...
166  *
167  * @sa ...here goes the see-also list...
168  */
169
170 Note that the @return, @note, @remarks, @sa commands are optional.
171
172 Also note that unlike for class' description, you should use the doxygen
173 builtin @sa command here for see-also lists.
174
175 The @param command has an optional attribute specifying the direction of 
176 the attribute. Possible values are "in" and "out". E.g.
177
178 /**
179  * Copies bytes from a source memory area to a destination memory area,
180  * where both areas may not overlap.
181  * @param[out]     dest   The memory area to copy to.
182  * @param[in]      src    The memory area to copy from.
183  * @param[in]      n      The number of bytes to copy.
184  * @param[in,out]  pmisc  Used both as input and as output.
185  */
186 void func(void *dest, const void *src, size_t n, void *pmisc);
187
188
189 Documentation comment for a topic overview
190 ==========================================
191
192 Topic overviews are stored inside the docs/doxygen/overviews folder
193 and are completely placed inside a single comment block in the form of:
194
195 /*!
196
197  @page overview_tname wxSomeStuff overview
198
199  This page provides an overview of the wxSomeStuff and related classes.
200  ....
201
202  @li @ref overview_tname_intro
203  @li @ref overview_tname_details
204  ...
205
206  <hr>
207
208
209  @section overview_tname_intro Introduction
210
211  ...here goes the introduction to this topic...
212
213
214  @section overview_tname_details Details
215
216  ...here go the details to this topic...
217
218 */
219
220 Note that there is a convention in the anchor link names.
221 Doxygen in fact requires that for each @page, @section, @subsection, etc tag, 
222 there is a corresponding link anchor.
223
224 The following conventions are used in wxWidgets doxygen comments:
225
226 1) all "main" pages of the manual (those which are placed in docs/doxygen/mainpages) 
227    have link anchors which begin with "page_"
228
229 2) all topic overviews (those which are placed in docs/doxygen/overviews) have link 
230    anchors which begin with "overview_"
231
232 3) all @section, @subsection, @subsubsection tags should have as link anchor name
233    the name of the parent section plus a specific word separed with an underscore; e.g.:
234
235 /*!
236
237  @page overview_tname wxSomeStuff overview
238
239  @section overview_tname_intro Introduction
240   @subsection overview_tname_intro_firstpart First part
241   @subsection overview_tname_intro_secondpart Second part
242    @subsubsection overview_tname_intro_secondpart_sub Second part subsection
243   @subsection overview_tname_intro_thirdpart Third part
244
245  @section overview_tname_details Details
246  ...
247
248 */
249
250
251 === EOF ===
252
253 Author: FM (under the lines of the previous technote about tex2rtf)
254 Version: $Id$