mirror of
https://github.com/taigrr/arduinolibs
synced 2025-01-18 04:33:12 -08:00
202 lines
16 KiB
HTML
202 lines
16 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: ListField.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 Page</span></a></li>
|
|
<li><a href="pages.html"><span>Related 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 List</span></a></li>
|
|
</ul>
|
|
</div>
|
|
<div class="header">
|
|
<div class="headertitle">
|
|
<div class="title">ListField.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 "Software"),</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 "AS IS", 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 "ListField.h"</span>
|
|
<a name="l00024"></a>00024 <span class="preprocessor">#include <string.h></span>
|
|
<a name="l00025"></a>00025
|
|
<a name="l00064"></a><a class="code" href="classListField.html#a118501da7edb0b0bc6b493734975b4e9">00064</a> <a class="code" href="classListField.html#a118501da7edb0b0bc6b493734975b4e9" title="Constructs a new list field with a specific label.">ListField::ListField</a>(<span class="keyword">const</span> String &label)
|
|
<a name="l00065"></a>00065 : <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a>(label)
|
|
<a name="l00066"></a>00066 , _items(0)
|
|
<a name="l00067"></a>00067 , _itemCount(0)
|
|
<a name="l00068"></a>00068 , _value(-1)
|
|
<a name="l00069"></a>00069 , _printLen(0)
|
|
<a name="l00070"></a>00070 {
|
|
<a name="l00071"></a>00071 }
|
|
<a name="l00072"></a>00072
|
|
<a name="l00077"></a><a class="code" href="classListField.html#aa303898a1f74b52c1c4982653de488b7">00077</a> <a class="code" href="classListField.html#a118501da7edb0b0bc6b493734975b4e9" title="Constructs a new list field with a specific label.">ListField::ListField</a>(<a class="code" href="classForm.html" title="Manager for a form containing data input/output fields.">Form</a> &form, <span class="keyword">const</span> String &label, ListItems items, <span class="keywordtype">int</span> value)
|
|
<a name="l00078"></a>00078 : <a class="code" href="classField.html" title="Manages a single data input/output field within a Form.">Field</a>(form, label)
|
|
<a name="l00079"></a>00079 , _items(0)
|
|
<a name="l00080"></a>00080 , _itemCount(0)
|
|
<a name="l00081"></a>00081 , _value(value)
|
|
<a name="l00082"></a>00082 , _printLen(0)
|
|
<a name="l00083"></a>00083 {
|
|
<a name="l00084"></a>00084 <a class="code" href="classListField.html#ae6709bce9355451b651893691456704e" title="Sets the array of items for this list.">setItems</a>(items);
|
|
<a name="l00085"></a>00085 }
|
|
<a name="l00086"></a>00086
|
|
<a name="l00087"></a><a class="code" href="classListField.html#a5d752bd561cde735b175bcdfda55832a">00087</a> <span class="keywordtype">int</span> <a class="code" href="classListField.html#a5d752bd561cde735b175bcdfda55832a" title="Dispatches event via this field.">ListField::dispatch</a>(<span class="keywordtype">int</span> event)
|
|
<a name="l00088"></a>00088 {
|
|
<a name="l00089"></a>00089 <span class="keywordflow">if</span> (event == LCD_BUTTON_DOWN) {
|
|
<a name="l00090"></a>00090 <span class="keywordflow">if</span> (_value >= (_itemCount - 1))
|
|
<a name="l00091"></a>00091 <a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24" title="Sets the value of this list; i.e. the index within items() of the selected item.">setValue</a>(0);
|
|
<a name="l00092"></a>00092 <span class="keywordflow">else</span>
|
|
<a name="l00093"></a>00093 <a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24" title="Sets the value of this list; i.e. the index within items() of the selected item.">setValue</a>(_value + 1);
|
|
<a name="l00094"></a>00094 <span class="keywordflow">return</span> FORM_CHANGED;
|
|
<a name="l00095"></a>00095 } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (event == LCD_BUTTON_UP) {
|
|
<a name="l00096"></a>00096 <span class="keywordflow">if</span> (_value <= 0)
|
|
<a name="l00097"></a>00097 <a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24" title="Sets the value of this list; i.e. the index within items() of the selected item.">setValue</a>(_itemCount - 1);
|
|
<a name="l00098"></a>00098 <span class="keywordflow">else</span>
|
|
<a name="l00099"></a>00099 <a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24" title="Sets the value of this list; i.e. the index within items() of the selected item.">setValue</a>(_value - 1);
|
|
<a name="l00100"></a>00100 <span class="keywordflow">return</span> FORM_CHANGED;
|
|
<a name="l00101"></a>00101 }
|
|
<a name="l00102"></a>00102 <span class="keywordflow">return</span> -1;
|
|
<a name="l00103"></a>00103 }
|
|
<a name="l00104"></a>00104
|
|
<a name="l00105"></a><a class="code" href="classListField.html#a191b79b460e45cf48e04b04eface2888">00105</a> <span class="keywordtype">void</span> <a class="code" href="classListField.html#a191b79b460e45cf48e04b04eface2888" title="Enters the field due to form navigation.">ListField::enterField</a>(<span class="keywordtype">bool</span> reverse)
|
|
<a name="l00106"></a>00106 {
|
|
<a name="l00107"></a>00107 <a class="code" href="classListField.html#a191b79b460e45cf48e04b04eface2888" title="Enters the field due to form navigation.">Field::enterField</a>(reverse);
|
|
<a name="l00108"></a>00108 _printLen = 0;
|
|
<a name="l00109"></a>00109 printValue();
|
|
<a name="l00110"></a>00110 }
|
|
<a name="l00111"></a>00111
|
|
<a name="l00141"></a><a class="code" href="classListField.html#ae6709bce9355451b651893691456704e">00141</a> <span class="keywordtype">void</span> <a class="code" href="classListField.html#ae6709bce9355451b651893691456704e" title="Sets the array of items for this list.">ListField::setItems</a>(ListItems items)
|
|
<a name="l00142"></a>00142 {
|
|
<a name="l00143"></a>00143 _items = <a class="code" href="classListField.html#a4dbbdeebd386551eb8f245b42b45ccf0" title="Returns the array of items in this list.">items</a>;
|
|
<a name="l00144"></a>00144 _itemCount = 0;
|
|
<a name="l00145"></a>00145 <span class="keywordflow">if</span> (items) {
|
|
<a name="l00146"></a>00146 <span class="keywordflow">for</span> (;;) {
|
|
<a name="l00147"></a>00147 ListItem item = (ListItem)pgm_read_word(items);
|
|
<a name="l00148"></a>00148 <span class="keywordflow">if</span> (!item)
|
|
<a name="l00149"></a>00149 <span class="keywordflow">break</span>;
|
|
<a name="l00150"></a>00150 ++<a class="code" href="classListField.html#a4dbbdeebd386551eb8f245b42b45ccf0" title="Returns the array of items in this list.">items</a>;
|
|
<a name="l00151"></a>00151 ++_itemCount;
|
|
<a name="l00152"></a>00152 }
|
|
<a name="l00153"></a>00153 }
|
|
<a name="l00154"></a>00154 <span class="keywordflow">if</span> (_value >= _itemCount)
|
|
<a name="l00155"></a>00155 _value = _itemCount - 1;
|
|
<a name="l00156"></a>00156 <span class="keywordflow">if</span> (<a class="code" href="classField.html#a25d86a67b321e8c642edf75a10a35f72" title="Returns true if this field is the currently-displayed field in its owning form; false otherwise...">isCurrent</a>())
|
|
<a name="l00157"></a>00157 printValue();
|
|
<a name="l00158"></a>00158 }
|
|
<a name="l00159"></a>00159
|
|
<a name="l00178"></a><a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24">00178</a> <span class="keywordtype">void</span> <a class="code" href="classListField.html#a266193631e897fb0b46e1270b1d0eb24" title="Sets the value of this list; i.e. the index within items() of the selected item.">ListField::setValue</a>(<span class="keywordtype">int</span> value)
|
|
<a name="l00179"></a>00179 {
|
|
<a name="l00180"></a>00180 <span class="keywordflow">if</span> (_value != value) {
|
|
<a name="l00181"></a>00181 _value = <a class="code" href="classListField.html#aab8477757cd89bacd242c85bac2dccb1" title="Returns the value of this list; i.e. the index within items() of the selected item.">value</a>;
|
|
<a name="l00182"></a>00182 <span class="keywordflow">if</span> (_value < 0)
|
|
<a name="l00183"></a>00183 _value = 0;
|
|
<a name="l00184"></a>00184 <span class="keywordflow">if</span> (_value >= _itemCount)
|
|
<a name="l00185"></a>00185 _value = _itemCount - 1;
|
|
<a name="l00186"></a>00186 <span class="keywordflow">if</span> (<a class="code" href="classField.html#a25d86a67b321e8c642edf75a10a35f72" title="Returns true if this field is the currently-displayed field in its owning form; false otherwise...">isCurrent</a>())
|
|
<a name="l00187"></a>00187 printValue();
|
|
<a name="l00188"></a>00188 }
|
|
<a name="l00189"></a>00189 }
|
|
<a name="l00190"></a>00190
|
|
<a name="l00191"></a>00191 <span class="keywordtype">void</span> ListField::printValue()
|
|
<a name="l00192"></a>00192 {
|
|
<a name="l00193"></a>00193 <a class="code" href="classField.html#a5cf21bf958a71e51feac9e1bf9f599d1" title="Returns the LCD that this field is being drawn on.">lcd</a>()->setCursor(0, 1);
|
|
<a name="l00194"></a>00194 <span class="keywordtype">int</span> len = 0;
|
|
<a name="l00195"></a>00195 <span class="keywordflow">if</span> (_value >= 0) {
|
|
<a name="l00196"></a>00196 ListItem str = (ListItem)pgm_read_word(&(_items[_value]));
|
|
<a name="l00197"></a>00197 <span class="keywordtype">char</span> ch;
|
|
<a name="l00198"></a>00198 <span class="keywordflow">while</span> ((ch = pgm_read_byte(str)) != 0) {
|
|
<a name="l00199"></a>00199 <a class="code" href="classField.html#a5cf21bf958a71e51feac9e1bf9f599d1" title="Returns the LCD that this field is being drawn on.">lcd</a>()->write(ch);
|
|
<a name="l00200"></a>00200 ++len;
|
|
<a name="l00201"></a>00201 ++str;
|
|
<a name="l00202"></a>00202 }
|
|
<a name="l00203"></a>00203 }
|
|
<a name="l00204"></a>00204 <span class="keywordflow">while</span> (_printLen-- > len)
|
|
<a name="l00205"></a>00205 <a class="code" href="classField.html#a5cf21bf958a71e51feac9e1bf9f599d1" title="Returns the LCD that this field is being drawn on.">lcd</a>()->write(<span class="charliteral">' '</span>);
|
|
<a name="l00206"></a>00206 _printLen = len;
|
|
<a name="l00207"></a>00207 }
|
|
</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"> </span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark"> </span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark"> </span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark"> </span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark"> </span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark"> </span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark"> </span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark"> </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 
|
|
<a href="http://www.doxygen.org/index.html">
|
|
<img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.4 </small></address>
|
|
</body>
|
|
</html>
|