]> git.saurik.com Git - wxWidgets.git/blame - docs/latex/wx/ttips.tex
Spacing tweak
[wxWidgets.git] / docs / latex / wx / ttips.tex
CommitLineData
ccaaf5b0 1\section{wxTipProvider overview}\label{tipsoverview}
c50f1fb9
VZ
2
3Many "modern" Windows programs have a feature (some would say annoyance) of
4presenting the user tips at program startup. While this is probably useless to
5the advanced users of the program, the experience shows that the tips may be
6quite helpful for the novices and so more and more programs now do this.
7
fc2171bd 8For a wxWidgets programmer, implementing this feature is extremely easy. To
f6bcfd97 9show a tip, it is enough to just call \helpref{wxShowTip}{wxshowtip} function
c50f1fb9
VZ
10like this:
11
12\begin{verbatim}
13 if ( ...show tips at startup?... )
14 {
15 wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", 0);
16 wxShowTip(windowParent, tipProvider);
17 delete tipProvider;
18 }
19\end{verbatim}
20
21Of course, you need to get the text of the tips from somewhere - in the example
f6bcfd97 22above, the text is supposed to be in the file tips.txt from where it is read by
c50f1fb9
VZ
23the {\it tip provider}. The tip provider is just an object of a class deriving
24from \helpref{wxTipProvider}{wxtipprovider}. It has to implement one pure
25virtual function of the base class: \helpref{GetTip}{wxtipprovidergettip}.
26In the case of the tip provider created by
27\helpref{wxCreateFileTipProvider}{wxcreatefiletipprovider}, the tips are just
28the lines of the text file.
29
30If you want to implement your own tip provider (for example, if you wish to
31hardcode the tips inside your program), you just have to derive another class
32from wxTipProvider and pass a pointer to the object of this class to wxShowTip
33- then you don't need wxCreateFileTipProvider at all.
34
70373b5a 35You will probably want to save somewhere the index of the tip last
c50f1fb9
VZ
36shown - so that the program doesn't always show the same tip on startup. As you
37also need to remember whether to show tips or not (you shouldn't do it if the
38user unchecked "Show tips on startup" checkbox in the dialog), you will
39probably want to store both the index of the
40last shown tip (as returned by
41\helpref{wxTipProvider::GetCurrentTip}{wxtipprovidergetcurrenttip} and the flag
42telling whether to show the tips at startup at all.
22d6efa8 43
70373b5a
JS
44In a tips.txt file, lines that begin with a \# character are considered comments
45and are automatically skipped. Blank lines and lines only having spaces are also
46skipped.
47
48You can easily add runtime-translation capacity by placing each line of the
49tips.txt file inside the usual translation macro. For example, your tips.txt
50file would look like this:
f010ad48 51
70373b5a
JS
52\begin{verbatim}
53_("This is my first tip")
54_("This is my second tip")
55\end{verbatim}
f010ad48 56
70373b5a
JS
57Now add your tips.txt file into the list of files that gettext searches
58for translatable strings. The tips will thus get included into your
59generated .po file catalog and be translated at runtime along with the rest of
dbd94b75 60your application's translatable strings.
70373b5a
JS
61Note1: Each line in the tips.txt file needs to strictly begin with exactly the
623 characters of underscore-parenthesis-doublequote, and end with
63doublequote-parenthesis, as shown above.
64Note2: Remember to escape any doublequote characters within the tip string with
65a backslash-doublequote.
66
67See the dialogs program in your samples folder for a working example inside a
68program.
f010ad48 69