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