1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>wxWidgets: wxTipProvider Overview</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="extra_stylesheet.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="page_container">
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0" style="width: 100%;">
<tbody>
<tr>
<td id="projectlogo">
<a href="http://www.wxwidgets.org/" target="_new">
<img alt="wxWidgets" src="logo.png"/>
</a>
</td>
<td style="padding-left: 0.5em; text-align: right;">
<span id="projectnumber">Version: 3.0.2</span>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Generated by Doxygen 1.8.2 -->
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related Pages</span></a></li>
<li><a href="modules.html"><span>Categories</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
</ul>
</div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">Documentation</a></li><li class="navelem"><a class="el" href="page_topics.html">Programming Guides</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title"><a class="el" href="classwx_tip_provider.html" title="This is the class used together with wxShowTip() function.">wxTipProvider</a> Overview </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>Many "modern" Windows programs have a feature (some would say annoyance) of presenting the user tips at program startup.</p>
<p>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:</p>
<div class="fragment"><div class="line"><span class="keywordflow">if</span> ( ...show tips at startup?... )</div>
<div class="line">{</div>
<div class="line"> <a class="code" href="classwx_tip_provider.html" title="This is the class used together with wxShowTip() function.">wxTipProvider</a> *tipProvider = <a class="code" href="group__group__funcmacro__dialog.html#ga9cc492bddff104d3afceca94ae945f38" title="This function creates a wxTipProvider which may be used with wxShowTip().">wxCreateFileTipProvider</a>(<span class="stringliteral">"tips.txt"</span>, 0);</div>
<div class="line"> <a class="code" href="group__group__funcmacro__dialog.html#ga71723a35f5e98349f5a79d7a025dac07" title="This function shows a "startup tip" to the user.">wxShowTip</a>(windowParent, tipProvider);</div>
<div class="line"> <span class="keyword">delete</span> tipProvider;</div>
<div class="line">}</div>
</div><!-- fragment --><p>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 <em>tip provider</em>. The tip provider is just an object of a class deriving from <a class="el" href="classwx_tip_provider.html" title="This is the class used together with wxShowTip() function.">wxTipProvider</a>. 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.</p>
<p>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 <a class="el" href="classwx_tip_provider.html" title="This is the class used together with wxShowTip() function.">wxTipProvider</a> and pass a pointer to the object of this class to wxShowTip - then you don't need wxCreateFileTipProvider at all.</p>
<p>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 <a class="el" href="classwx_tip_provider.html#acff065db246be564d5e888210d99e0fc" title="Returns the index of the current tip (i.e. the one which would be returned by GetTip()).">wxTipProvider::GetCurrentTip</a> and the flag telling whether to show the tips at startup at all.</p>
<p>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.</p>
<p>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:</p>
<div class="fragment"><div class="line"><a class="code" href="group__group__funcmacro__string.html#ga8a02b8875a521df57263a9e6f090f2d0" title="Macro to be used around all literal strings that should be translated.">_</a>(<span class="stringliteral">"This is my first tip"</span>)</div>
<div class="line"><a class="code" href="group__group__funcmacro__string.html#ga8a02b8875a521df57263a9e6f090f2d0" title="Macro to be used around all literal strings that should be translated.">_</a>("This is my second tip")</div>
</div><!-- fragment --><p>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.</p>
<dl class="section note"><dt>Note</dt><dd>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. Also, remember to escape any doublequote characters within the tip string with a backslash-doublequote.</dd></dl>
<p>See the dialogs program in your samples folder for a working example inside a program. </p>
</div></div><!-- contents -->
<address class="footer">
<small>
Generated on Thu Nov 27 2014 13:46:42 for wxWidgets by <a href="http://www.doxygen.org/index.html" target="_new">Doxygen</a> 1.8.2
</small>
</address>
<script src="wxwidgets.js" type="text/javascript"></script>
</div><!-- #page_container -->
</body>
</html>
|