]>
Commit | Line | Data |
---|---|---|
ccaaf5b0 | 1 | \section{wxTipProvider overview}\label{tipsoverview} |
c50f1fb9 VZ |
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 wxWindows programmer, implementing this feature is extremely easy. To | |
f6bcfd97 | 9 | show a tip, it is enough to just call \helpref{wxShowTip}{wxshowtip} function |
c50f1fb9 VZ |
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 | |
f6bcfd97 | 22 | above, the text is supposed to be in the file tips.txt from where it is read by |
c50f1fb9 VZ |
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 | ||
70373b5a | 35 | You will probably want to save somewhere the index of the tip last |
c50f1fb9 VZ |
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. | |
22d6efa8 | 43 | |
70373b5a JS |
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 | \begin{verbatim} | |
52 | _("This is my first tip") | |
53 | _("This is my second tip") | |
54 | \end{verbatim} | |
55 | Now add your tips.txt file into the list of files that gettext searches | |
56 | for translatable strings. The tips will thus get included into your | |
57 | generated .po file catalog and be translated at runtime along with the rest of | |
58 | your aplication's translatable strings. | |
59 | Note1: Each line in the tips.txt file needs to strictly begin with exactly the | |
60 | 3 characters of underscore-parenthesis-doublequote, and end with | |
61 | doublequote-parenthesis, as shown above. | |
62 | Note2: Remember to escape any doublequote characters within the tip string with | |
63 | a backslash-doublequote. | |
64 | ||
65 | See the dialogs program in your samples folder for a working example inside a | |
66 | program. |