wxtipprovider overviewmany "modern" windows programs have a feature (some would say annoyance) of presenting the user tips at program startup. while this is probably useless to the advanced users of the program, the experience shows that the tips may be quite helpful for the novices and so more and more programs now do this. for a wxwidgets programmer, implementing this feature is extremely easy. to show a tip, it is enough to just call wxshowtip function like this:
if ( ...show tips at startup?... ) { wxtipprovider *tipprovider = wxcreatefiletipprovider("tips.txt", 0); wxshowtip(windowparent, tipprovider); delete tipprovider; }of course, you need to get the text of the tips from somewhere - in the example above, the text is supposed to be in the file tips.txt from where it is read by the tip provider. the tip provider is just an object of a class deriving from wxtipprovider. it has to implement one pure virtual function of the base class: gettip. in the case of the tip provider created by wxcreatefiletipprovider, the tips are just the lines of the text file. if you want to implement your own tip provider (for example, if you wish to hardcode the tips inside your program), you just have to derive another class from wxtipprovider and pass a pointer to the object of this class to wxshowtip - then you don't need wxcreatefiletipprovider at all. you will probably want to save somewhere the index of the tip last shown - so that the program doesn't always show the same tip on startup. as you also need to remember whether to show tips or not (you shouldn't do it if the user unchecked "show tips on startup" checkbox in the dialog), you will probably want to store both the index of the last shown tip (as returned by wxtipprovider::getcurrenttip and the flag telling whether to show the tips at startup at all. in a tips.txt file, lines that begin with a # character are considered comments and are automatically skipped. blank lines and lines only having spaces are also skipped. you can easily add runtime-translation capacity by placing each line of the tips.txt file inside the usual translation macro. for example, your tips.txt file would look like this:
_("this is my first tip") _("this is my second tip")now add your tips.txt file into the list of files that gettext searches for translatable strings. the tips will thus get included into your generated .po file catalog and be translated at runtime along with the rest of your application's translatable strings. note1: each line in the tips.txt file needs to strictly begin with exactly the 3 characters of underscore-parenthesis-doublequote, and end with doublequote-parenthesis, as shown above. note2: remember to escape any doublequote characters within the tip string with a backslash-doublequote. see the dialogs program in your samples folder for a working example inside a program.
|