tips.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: tips.h
  3. // Purpose: topic overview
  4. // Author: wxWidgets team
  5. // Licence: wxWindows licence
  6. /////////////////////////////////////////////////////////////////////////////
  7. /**
  8. @page overview_tips wxTipProvider Overview
  9. @tableofcontents
  10. Many "modern" Windows programs have a feature (some would say annoyance) of
  11. presenting the user tips at program startup. While this is probably useless to
  12. the advanced users of the program, the experience shows that the tips may be
  13. quite helpful for the novices and so more and more programs now do this. For a
  14. wxWidgets programmer, implementing this feature is extremely easy. To show a
  15. tip, it is enough to just call wxShowTip function like this:
  16. @code
  17. if ( ...show tips at startup?... )
  18. {
  19. wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", 0);
  20. wxShowTip(windowParent, tipProvider);
  21. delete tipProvider;
  22. }
  23. @endcode
  24. Of course, you need to get the text of the tips from somewhere - in the example
  25. above, the text is supposed to be in the file tips.txt from where it is read by
  26. the <em>tip provider</em>. The tip provider is just an object of a class
  27. deriving from wxTipProvider. It has to implement one pure virtual function of
  28. the base class: GetTip. In the case of the tip provider created by
  29. wxCreateFileTipProvider, the tips are just the lines of the text file.
  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
  33. wxShowTip - then you don't need wxCreateFileTipProvider at all.
  34. You will probably want to save somewhere the index of the tip last shown - so
  35. that the program doesn't always show the same tip on startup. As you also need
  36. to remember whether to show tips or not (you shouldn't do it if the user
  37. unchecked "Show tips on startup" checkbox in the dialog), you will probably
  38. want to store both the index of the last shown tip (as returned by
  39. wxTipProvider::GetCurrentTip and the flag telling whether to show the tips at
  40. startup at all.
  41. In a tips.txt file, lines that begin with a # character are considered comments
  42. and are automatically skipped. Blank lines and lines only having spaces are
  43. also skipped.
  44. You can easily add runtime-translation capacity by placing each line of the
  45. tips.txt file inside the usual translation macro. For example, your tips.txt
  46. file would look like this:
  47. @code
  48. _("This is my first tip")
  49. _("This is my second tip")
  50. @endcode
  51. Now add your tips.txt file into the list of files that gettext searches for
  52. translatable strings. The tips will thus get included into your generated .po
  53. file catalog and be translated at runtime along with the rest of your
  54. application's translatable strings.
  55. @note Each line in the tips.txt file needs to strictly begin with exactly the 3
  56. characters of underscore-parenthesis-doublequote, and end with
  57. doublequote-parenthesis, as shown above. Also, remember to escape any
  58. doublequote characters within the tip string with a backslash-doublequote.
  59. See the dialogs program in your samples folder for a working example inside a
  60. program.
  61. */