wxWidgets/docs/latex/wx/ttips.tex

44 lines
2.1 KiB
TeX
Raw Normal View History

\section{wxTipProvider overview}\label{tipsoverview}
Many "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 wxWindows programmer, implementing this feature is extremely easy. To
show a tip, it is enough to just call \helpref{wxShowTip}{wxshowtip} function
like this:
\begin{verbatim}
if ( ...show tips at startup?... )
{
wxTipProvider *tipProvider = wxCreateFileTipProvider("tips.txt", 0);
wxShowTip(windowParent, tipProvider);
delete tipProvider;
}
\end{verbatim}
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 {\it tip provider}. The tip provider is just an object of a class deriving
from \helpref{wxTipProvider}{wxtipprovider}. It has to implement one pure
virtual function of the base class: \helpref{GetTip}{wxtipprovidergettip}.
In the case of the tip provider created by
\helpref{wxCreateFileTipProvider}{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.
Finally, 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
\helpref{wxTipProvider::GetCurrentTip}{wxtipprovidergetcurrenttip} and the flag
telling whether to show the tips at startup at all.