1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/Form_8cpp_source.html
2012-05-29 15:24:22 +10:00

256 lines
20 KiB
HTML

<!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"/>
<title>ArduinoLibs: Form.cpp Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css"/>
</head>
<body onload='searchBox.OnSelectItem(0);'>
<!-- Generated by Doxygen 1.7.4 -->
<script type="text/javascript"><!--
var searchBox = new SearchBox("searchBox", "search",false,'Search');
--></script>
<div id="top">
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">ArduinoLibs</div>
</td>
</tr>
</tbody>
</table>
</div>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li class="current"><a href="files.html"><span>Files</span></a></li>
<li id="searchli">
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<div id="navrow2" class="tabs2">
<ul class="tablist">
<li><a href="files.html"><span>File&#160;List</span></a></li>
</ul>
</div>
<div class="header">
<div class="headertitle">
<div class="title">Form.cpp</div> </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*</span>
<a name="l00002"></a>00002 <span class="comment"> * Copyright (C) 2012 Southern Storm Software, Pty Ltd.</span>
<a name="l00003"></a>00003 <span class="comment"> *</span>
<a name="l00004"></a>00004 <span class="comment"> * Permission is hereby granted, free of charge, to any person obtaining a</span>
<a name="l00005"></a>00005 <span class="comment"> * copy of this software and associated documentation files (the &quot;Software&quot;),</span>
<a name="l00006"></a>00006 <span class="comment"> * to deal in the Software without restriction, including without limitation</span>
<a name="l00007"></a>00007 <span class="comment"> * the rights to use, copy, modify, merge, publish, distribute, sublicense,</span>
<a name="l00008"></a>00008 <span class="comment"> * and/or sell copies of the Software, and to permit persons to whom the</span>
<a name="l00009"></a>00009 <span class="comment"> * Software is furnished to do so, subject to the following conditions:</span>
<a name="l00010"></a>00010 <span class="comment"> *</span>
<a name="l00011"></a>00011 <span class="comment"> * The above copyright notice and this permission notice shall be included</span>
<a name="l00012"></a>00012 <span class="comment"> * in all copies or substantial portions of the Software.</span>
<a name="l00013"></a>00013 <span class="comment"> *</span>
<a name="l00014"></a>00014 <span class="comment"> * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS</span>
<a name="l00015"></a>00015 <span class="comment"> * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,</span>
<a name="l00016"></a>00016 <span class="comment"> * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE</span>
<a name="l00017"></a>00017 <span class="comment"> * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER</span>
<a name="l00018"></a>00018 <span class="comment"> * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING</span>
<a name="l00019"></a>00019 <span class="comment"> * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER</span>
<a name="l00020"></a>00020 <span class="comment"> * DEALINGS IN THE SOFTWARE.</span>
<a name="l00021"></a>00021 <span class="comment"> */</span>
<a name="l00022"></a>00022
<a name="l00023"></a>00023 <span class="preprocessor">#include &quot;Form.h&quot;</span>
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;Field.h&quot;</span>
<a name="l00025"></a>00025
<a name="l00047"></a><a class="code" href="classForm.html#ad30836b22edde707a52d94090b716996">00047</a> <a class="code" href="classForm.html#ad30836b22edde707a52d94090b716996" title="Constructs a new form and associates it with lcd.">Form::Form</a>(LiquidCrystal &amp;lcd)
<a name="l00048"></a>00048 : _lcd(&amp;lcd)
<a name="l00049"></a>00049 , first(0)
<a name="l00050"></a>00050 , last(0)
<a name="l00051"></a>00051 , current(0)
<a name="l00052"></a>00052 {
<a name="l00053"></a>00053 }
<a name="l00054"></a>00054
<a name="l00058"></a><a class="code" href="classForm.html#a9cda7cce41e81bfaca51e922d4f9b98f">00058</a> <a class="code" href="classForm.html#a9cda7cce41e81bfaca51e922d4f9b98f" title="Detaches all remaining fields and destroys this form.">Form::~Form</a>()
<a name="l00059"></a>00059 {
<a name="l00060"></a>00060 <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field = first;
<a name="l00061"></a>00061 <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *next;
<a name="l00062"></a>00062 <span class="keywordflow">while</span> (field != 0) {
<a name="l00063"></a>00063 next = field-&gt;next;
<a name="l00064"></a>00064 field-&gt;_form = 0;
<a name="l00065"></a>00065 field-&gt;next = 0;
<a name="l00066"></a>00066 field-&gt;prev = 0;
<a name="l00067"></a>00067 field = next;
<a name="l00068"></a>00068 }
<a name="l00069"></a>00069 }
<a name="l00070"></a>00070
<a name="l00099"></a><a class="code" href="classForm.html#a89bd3850e87caa2ca7b2e946f923d0ee">00099</a> <span class="keywordtype">int</span> <a class="code" href="classForm.html#a89bd3850e87caa2ca7b2e946f923d0ee" title="Dispatches event to the currently active field using Field::dispatch().">Form::dispatch</a>(<span class="keywordtype">int</span> event)
<a name="l00100"></a>00100 {
<a name="l00101"></a>00101 <span class="keywordflow">if</span> (current) {
<a name="l00102"></a>00102 <span class="keywordtype">int</span> exitval = current-&gt;<a class="code" href="classField.html#a061bd1ed4d8b079df86465df8facd3b3" title="Dispatches event via this field.">dispatch</a>(event);
<a name="l00103"></a>00103 <span class="keywordflow">if</span> (exitval &gt;= 0)
<a name="l00104"></a>00104 <span class="keywordflow">return</span> exitval;
<a name="l00105"></a>00105 }
<a name="l00106"></a>00106 <span class="keywordflow">if</span> (event == LCD_BUTTON_LEFT)
<a name="l00107"></a>00107 <a class="code" href="classForm.html#acb080fe4f4631e9060e6efab8eaa0a90" title="Changes to the previous field in the &quot;tab order&quot;.">prevField</a>();
<a name="l00108"></a>00108 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == LCD_BUTTON_RIGHT)
<a name="l00109"></a>00109 <a class="code" href="classForm.html#a788a186ea4a7ebd75283a948ca45f4d1" title="Changes to the next field in the &quot;tab order&quot;.">nextField</a>();
<a name="l00110"></a>00110 <span class="keywordflow">return</span> 0;
<a name="l00111"></a>00111 }
<a name="l00112"></a>00112
<a name="l00118"></a><a class="code" href="classForm.html#a788a186ea4a7ebd75283a948ca45f4d1">00118</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#a788a186ea4a7ebd75283a948ca45f4d1" title="Changes to the next field in the &quot;tab order&quot;.">Form::nextField</a>()
<a name="l00119"></a>00119 {
<a name="l00120"></a>00120 <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field = current;
<a name="l00121"></a>00121 <span class="keywordflow">if</span> (!field)
<a name="l00122"></a>00122 field = first;
<a name="l00123"></a>00123 <span class="keywordflow">if</span> (field &amp;&amp; field-&gt;next)
<a name="l00124"></a>00124 field = field-&gt;next;
<a name="l00125"></a>00125 <span class="keywordflow">else</span>
<a name="l00126"></a>00126 field = first;
<a name="l00127"></a>00127 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(field);
<a name="l00128"></a>00128 }
<a name="l00129"></a>00129
<a name="l00135"></a><a class="code" href="classForm.html#acb080fe4f4631e9060e6efab8eaa0a90">00135</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#acb080fe4f4631e9060e6efab8eaa0a90" title="Changes to the previous field in the &quot;tab order&quot;.">Form::prevField</a>()
<a name="l00136"></a>00136 {
<a name="l00137"></a>00137 <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field = current;
<a name="l00138"></a>00138 <span class="keywordflow">if</span> (!field)
<a name="l00139"></a>00139 field = last;
<a name="l00140"></a>00140 <span class="keywordflow">if</span> (field &amp;&amp; field-&gt;prev)
<a name="l00141"></a>00141 field = field-&gt;prev;
<a name="l00142"></a>00142 <span class="keywordflow">else</span>
<a name="l00143"></a>00143 field = last;
<a name="l00144"></a>00144 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(field);
<a name="l00145"></a>00145 }
<a name="l00146"></a>00146
<a name="l00152"></a><a class="code" href="classForm.html#aba75b59f68b31dd77dbbac9ab5c3124b">00152</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#aba75b59f68b31dd77dbbac9ab5c3124b" title="Changes to default field (i.e., the first field).">Form::defaultField</a>()
<a name="l00153"></a>00153 {
<a name="l00154"></a>00154 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(first);
<a name="l00155"></a>00155 }
<a name="l00156"></a>00156
<a name="l00165"></a><a class="code" href="classForm.html#a5cb056ace428e75e321610555bfecac7">00165</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#a5cb056ace428e75e321610555bfecac7" title="Adds field to this form.">Form::addField</a>(<a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field)
<a name="l00166"></a>00166 {
<a name="l00167"></a>00167 <span class="keywordflow">if</span> (field-&gt;_form)
<a name="l00168"></a>00168 <span class="keywordflow">return</span>; <span class="comment">// Already added to a form.</span>
<a name="l00169"></a>00169 field-&gt;_form = <span class="keyword">this</span>;
<a name="l00170"></a>00170 field-&gt;next = 0;
<a name="l00171"></a>00171 field-&gt;prev = last;
<a name="l00172"></a>00172 <span class="keywordflow">if</span> (last)
<a name="l00173"></a>00173 last-&gt;next = field;
<a name="l00174"></a>00174 <span class="keywordflow">else</span>
<a name="l00175"></a>00175 first = field;
<a name="l00176"></a>00176 last = field;
<a name="l00177"></a>00177 }
<a name="l00178"></a>00178
<a name="l00187"></a><a class="code" href="classForm.html#a7abd717029f9b19ee7318470072cd697">00187</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#a7abd717029f9b19ee7318470072cd697" title="Removes field from this form.">Form::removeField</a>(<a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field)
<a name="l00188"></a>00188 {
<a name="l00189"></a>00189 <span class="keywordflow">if</span> (field-&gt;_form != <span class="keyword">this</span>)
<a name="l00190"></a>00190 <span class="keywordflow">return</span>; <span class="comment">// Not a member of this form.</span>
<a name="l00191"></a>00191 <span class="keywordflow">if</span> (current == field) {
<a name="l00192"></a>00192 <span class="keywordflow">if</span> (field-&gt;next)
<a name="l00193"></a>00193 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(field-&gt;next);
<a name="l00194"></a>00194 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (field-&gt;prev)
<a name="l00195"></a>00195 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(field-&gt;prev);
<a name="l00196"></a>00196 <span class="keywordflow">else</span>
<a name="l00197"></a>00197 <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">setCurrentField</a>(0);
<a name="l00198"></a>00198 }
<a name="l00199"></a>00199 <span class="keywordflow">if</span> (field-&gt;next)
<a name="l00200"></a>00200 field-&gt;next-&gt;prev = field-&gt;prev;
<a name="l00201"></a>00201 <span class="keywordflow">else</span>
<a name="l00202"></a>00202 last = field-&gt;prev;
<a name="l00203"></a>00203 <span class="keywordflow">if</span> (field-&gt;prev)
<a name="l00204"></a>00204 field-&gt;prev-&gt;next = field-&gt;next;
<a name="l00205"></a>00205 <span class="keywordflow">else</span>
<a name="l00206"></a>00206 first = field-&gt;next;
<a name="l00207"></a>00207 field-&gt;_form = 0;
<a name="l00208"></a>00208 field-&gt;next = 0;
<a name="l00209"></a>00209 field-&gt;prev = 0;
<a name="l00210"></a>00210 }
<a name="l00211"></a>00211
<a name="l00230"></a><a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5">00230</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#ae6004fedfa07191ffd47d7b12370b4e5" title="Sets the current field that is displayed on-screen.">Form::setCurrentField</a>(<a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a> *field)
<a name="l00231"></a>00231 {
<a name="l00232"></a>00232 <span class="keywordflow">if</span> (field &amp;&amp; field-&gt;_form != <span class="keyword">this</span>)
<a name="l00233"></a>00233 <span class="keywordflow">return</span>; <span class="comment">// Wrong form.</span>
<a name="l00234"></a>00234 <span class="keywordflow">if</span> (visible) {
<a name="l00235"></a>00235 <span class="keywordtype">bool</span> reverse = <span class="keyword">false</span>;
<a name="l00236"></a>00236 <span class="keywordflow">if</span> (current) {
<a name="l00237"></a>00237 current-&gt;<a class="code" href="classField.html#ad6805c75ee1e62f8cd8bd550c4530c07" title="Exits the field due to form navigation.">exitField</a>();
<a name="l00238"></a>00238 <span class="keywordflow">if</span> (field-&gt;next == current)
<a name="l00239"></a>00239 reverse = <span class="keyword">true</span>;
<a name="l00240"></a>00240 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!field-&gt;next &amp;&amp; current == first)
<a name="l00241"></a>00241 reverse = <span class="keyword">true</span>;
<a name="l00242"></a>00242 }
<a name="l00243"></a>00243 current = field;
<a name="l00244"></a>00244 _lcd-&gt;clear();
<a name="l00245"></a>00245 <span class="keywordflow">if</span> (current)
<a name="l00246"></a>00246 current-&gt;<a class="code" href="classField.html#aa032bbeacb405c56546cb56fbbee94f5" title="Enters the field due to form navigation.">enterField</a>(reverse);
<a name="l00247"></a>00247 } <span class="keywordflow">else</span> {
<a name="l00248"></a>00248 current = field;
<a name="l00249"></a>00249 }
<a name="l00250"></a>00250 }
<a name="l00251"></a>00251
<a name="l00274"></a><a class="code" href="classForm.html#a9e8d718ab55a8034c22c606ccfa90d65">00274</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#a9e8d718ab55a8034c22c606ccfa90d65" title="Shows the form, or does nothing if the form is already on-screen.">Form::show</a>()
<a name="l00275"></a>00275 {
<a name="l00276"></a>00276 <span class="keywordflow">if</span> (!visible) {
<a name="l00277"></a>00277 <span class="keywordflow">if</span> (!current)
<a name="l00278"></a>00278 current = first;
<a name="l00279"></a>00279 visible = <span class="keyword">true</span>;
<a name="l00280"></a>00280 _lcd-&gt;clear();
<a name="l00281"></a>00281 <span class="keywordflow">if</span> (current)
<a name="l00282"></a>00282 current-&gt;<a class="code" href="classField.html#aa032bbeacb405c56546cb56fbbee94f5" title="Enters the field due to form navigation.">enterField</a>(<span class="keyword">false</span>);
<a name="l00283"></a>00283 }
<a name="l00284"></a>00284 }
<a name="l00285"></a>00285
<a name="l00293"></a><a class="code" href="classForm.html#a88b9146a3f68e837c5e831203096f9e9">00293</a> <span class="keywordtype">void</span> <a class="code" href="classForm.html#a88b9146a3f68e837c5e831203096f9e9" title="Hides the form, or does nothing if the form is not on-screen.">Form::hide</a>()
<a name="l00294"></a>00294 {
<a name="l00295"></a>00295 <span class="keywordflow">if</span> (visible) {
<a name="l00296"></a>00296 <span class="keywordflow">if</span> (current)
<a name="l00297"></a>00297 current-&gt;<a class="code" href="classField.html#ad6805c75ee1e62f8cd8bd550c4530c07" title="Exits the field due to form navigation.">exitField</a>();
<a name="l00298"></a>00298 visible = <span class="keyword">false</span>;
<a name="l00299"></a>00299 _lcd-&gt;clear();
<a name="l00300"></a>00300 }
<a name="l00301"></a>00301 }
<a name="l00302"></a>00302
</pre></div></div>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<hr class="footer"/><address class="footer"><small>Generated on Tue May 29 2012 15:23:58 for ArduinoLibs by&#160;
<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
</body>
</html>