Changes from Version 1 of documentation/C++Manual/Controls/Form

Show
Ignore:
Author:
peterc (IP: 192.168.0.1)
Timestamp:
11/26/07 17:33:25 (10 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • documentation/C++Manual/Controls/Form

    v0 v1  
     1[[PageOutline(1-5, Contents)]] 
     2= Form controls = 
     3 
     4The Controls plugin includes a fully-featured set of form controls. The full RML specification for these controls can be found [wiki:documentation/RML/Forms here]. The available form controls are: 
     5 * text field 
     6 * password field 
     7 * multi-line text field 
     8 * radio button 
     9 * checkbox 
     10 * drop-down selection list 
     11 * data-driven drop-down selection list 
     12 * slider 
     13 
     14Below is the hierarchy for the custom form elements included in the Controls plugin. 
     15[[Image(controls_form_1.gif, nolink)]] 
     16 
     17== Form control interface == 
     18 
     19All form control elements are derived from the ''Rocket::Controls::ElementFormControl'' interface. Each form control has two values associated with it; ''name'' and ''value''. The name is used to identify the control. The value specifies the current setting of the control; the exact definition of the value depends on the control. When a group of form controls is submitted, the names and values of the controls become the parameters of the submission. 
     20 
     21The name of a form control can be retrieved and set using the ''GetName()'' and ''SetName()'' functions on ''Rocket::Controls::ElementFormControl''. 
     22 
     23{{{ 
     24// Returns the name of the form control. 
     25// @return The name of the form control. 
     26EMP::Core::String GetName() const; 
     27 
     28// Sets the name of the form control. 
     29// @param[in] name The new name of the form control. 
     30void SetName(const EMP::Core::String& name); 
     31}}} 
     32 
     33The value of a form control can be retrieved and set using the ''GetValue()'' and ''SetValue()'' functions. 
     34 
     35{{{ 
     36// Returns a string representation of the current value of the form control. 
     37// @return The value of the form control. 
     38EMP::Core::String GetValue() const; 
     39 
     40// Sets the current value of the form control. 
     41// @param[in] value The new value of the form control. 
     42void SetValue(const EMP::Core::String& value); 
     43}}} 
     44 
     45The exact syntax of the value varies from control to control, but ''GetValue()'' will always return a value in a human-readable form. 
     46 
     47Form controls can be enabled and disabled dynamically as well. All controls start enabled. 
     48 
     49{{{ 
     50// Returns the disabled status of the form control. 
     51// @return True if the element is disabled, false otherwise. 
     52bool IsDisabled() const; 
     53 
     54// Sets the disabled status of the form control. 
     55// @param[in] disabled True to disable the element, false to enable. 
     56void SetDisabled(bool disable); 
     57}}} 
     58 
     59=== Generic input interface === 
     60 
     61Most of the form controls are instanced through the <input> tag, with the "type" attribute determining how they operate. The possible values for "type" are: 
     62 * ''text'': A single-line text field. This is the default. 
     63 * ''password'': Similar to text, but renders asterisks for all characters. 
     64 * ''radio'': A radio button. 
     65 * ''checkbox'': A checkbox button. 
     66 * ''range'': A slider. 
     67 * ''submit'': An element with button-like behaviour for submitting its parent form. 
     68 
     69One interface is used to represent all such form controls regardless of their type. Their type can be changed even after they've been instanced. 
     70 
     71However, because they do not have a unique interface, they have no helper functions for accessing their attributes like the other form controls. Their attributes have to be accessed and mutated using ''GetAttribute()'' and ''SetAttribute()''. 
     72 
     73== Text field == 
     74 
     75The single-line text field control is specified in RML by the <input type="text" /> tag. A password-style text field can be specified by the <input type="password" /> tag. The interface to both of these elements is the ''Rocket::Controls::ElementFormControlInput'' class. 
     76 
     77The size of a text field refers of the average number of characters visible across the field. The value can be set with the "size" attribute. 
     78 
     79The maximum number of characters allowed in a text field is set with the "maxlength" attribute. 
     80 
     81== Text area == 
     82 
     83The text area, or multi-line text field, is specified in RML with the <textarea> tag. Any loose text between the text area's opening and closing tag will become the initial value of the control. The interface to the text area is the ''Rocket::Controls::ElementFormControlTextArea'' class. 
     84 
     85The intrinsic dimensions of the text area is controlled by the "cols" and "rows" attributes, which dictate the number of characters visible horizontally and vertically. These values can also be set in C++ through the relevant methods. 
     86 
     87{{{ 
     88// Sets the number of characters visible across the text area. 
     89// @param[in] size The number of visible characters. 
     90void SetNumColumns(int num_columns); 
     91 
     92// Returns the approximate number of characters visible at once. 
     93// @return The number of visible characters. 
     94int GetNumColumns() const; 
     95 
     96// Sets the number of visible lines of text in the text area. 
     97// @param[in] num_rows The new number of visible lines of text. 
     98void SetNumRows(int num_rows); 
     99 
     100// Returns the number of visible lines of text in the text area. 
     101// @return The number of visible lines of text. 
     102int GetNumRows() const; 
     103}}} 
     104 
     105Similarly to the single-line text field, the maximum number of characters in the text area can be limited with the "maxlength" attribute. It can be accessed in C++ using the ''GetMaxLength()'' function and changed with the ''SetMaxLength()'' function. 
     106 
     107{{{ 
     108// Sets the maximum length (in characters) of this text area. 
     109// @param[in] max_length The new maximum length of the text area. A number lower than zero will mean infinite characters. 
     110void SetMaxLength(int max_length); 
     111 
     112// Returns the maximum length (in characters) of this text area. 
     113// @return The maximum number of characters allowed in this text area. 
     114int GetMaxLength() const; 
     115}}} 
     116 
     117The word-wrapping state of the text area is set with the "wrap" attribute in RML. It can be changed in C++ with the ''GetWordWrap()'' and ''SetWordWrap()'' functions. 
     118 
     119{{{ 
     120// Enables or disables word-wrapping in the text area. 
     121// @param[in] word_wrap True to enable word-wrapping, false to disable. 
     122void SetWordWrap(bool word_wrap); 
     123 
     124// Returns the state of word-wrapping in the text area. 
     125// @return True if the text area is word-wrapping, false otherwise. 
     126bool GetWordWrap(); 
     127}}} 
     128 
     129== Radio button and checkbox == 
     130 
     131The radio button (<input type="radio" />) and checkbox (<input type="checkbox" />) are two similar types of form control. Both only submit their value if they are checked. The radio button will, when checked, uncheck all other radio buttons with the same name. The interface for both controls is ''Rocket::Controls::ElementFormControlInput''. 
     132 
     133The checked status of a checkbox or radio button defaults to false, but can be initialised to true with the "checked" attribute. To uncheck a checkbox, remove the "checked" attribute with ''RemoveAttribute()''. 
     134 
     135== Drop-down select box == 
     136 
     137The simple drop-down select control is specified in RML with the <select> tag. Individual options within the select box are specified with child <option> elements. The value of the select control is set to the value attribute of the currently selected option. The following RML fragment declares a select box: 
     138 
     139{{{ 
     140<select name="graphics"> 
     141        <option value="bad">Bad</option> 
     142        <option value="ok">OK</option> 
     143        <option value="good" selected>good</option> 
     144</select> 
     145}}} 
     146 
     147The select control's interface is the ''Rocket::Controls::ElementFormControlSelect'' class. The total number of options in the select box can be queried with the ''GetNumOptions()'' method. 
     148 
     149{{{ 
     150// Returns the number of options in the select control. 
     151// @return The number of options. 
     152int GetNumOptions() const; 
     153}}} 
     154 
     155Individual options can be accessed with the ''GetOption()'' method. 
     156 
     157{{{ 
     158// Returns one of the select control's option elements. 
     159// @param[in] The index of the desired option element. 
     160// @return The option element at the given index. This will be NULL if the index is out of bounds. 
     161Rocket::Controls::SelectOption* GetOption(int index); 
     162}}} 
     163 
     164GetOption() returns a ''Rocket::Controls::SelectOption'' structure, from which you can access the value of the option and the element hierarchy used to render it in the drop-down box. 
     165 
     166The selected option can be accessed with the ''GetSelection()'' function and set with the ''SetSelection()'' function. 
     167 
     168{{{ 
     169// Sets the index of the selection. If the new index lies outside of the bounds, it will be clamped. 
     170// @param[in] selection The new selection index. 
     171void SetSelection(int selection); 
     172 
     173// Returns the index of the currently selected item. 
     174// @return The index of the currently selected item. 
     175int GetSelection() const; 
     176}}} 
     177 
     178Options can be procedurally added and removed with the ''Add()'' and ''Remove()'' functions. 
     179 
     180{{{ 
     181// Adds a new option to the select control. 
     182// @param[in] rml The RML content used to represent the option. 
     183// @param[in] value The value of the option. 
     184// @param[in] before The index of the element to insert the new option before. If out of bounds the new option will be added at the end of the list. 
     185// @return The index of the new option. 
     186int Add(const EMP::Core::String& rml, 
     187        const EMP::Core::String& value, 
     188        int before = -1); 
     189 
     190// Removes an option from the select control. 
     191// @param[in] index The index of the option to remove. If this is outside of the bounds of the control's option list, no option will be removed. 
     192void Remove(int index); 
     193}}} 
     194 
     195== Data-driven drop-down select box == 
     196 
     197The data-driven drop-down select control is specified in RML with the <dataselect> tag. No options are specified within the tag; instead, they are populated from an ''EMP::Core::DataSource'' object, similarly to a [wiki:documentation/C++Manual/Controls/DataGrid data grid]. 
     198 
     199The select control's interface is the ''Rocket::Controls::ElementFormControlDataSelect'' class. It derives from ''Rocket::Controls::ElementFormControlSelect''. The data select's data source is set with the "source" attribute, and can be changed in C++ through the ''SetDataSource()'' method: 
     200 
     201{{{ 
     202// Sets the data source the control's options are driven from. 
     203// @param[in] data_source The name of the new data source. 
     204void SetDataSource(const EMP::Core::String& data_source); 
     205}}} 
     206 
     207== Range slider == 
     208 
     209The range control can be used to render a slider-based number field. It is specified in RML with the tag <input type='range' />. The range control's interface is the ''Rocket::Controls::ElementFormControlInput'' class. 
     210 
     211The minimum and maximum values for the range are specified with the "min" and "max" attributes. The ''step'' of the range, or increments in which the value can be increased or decreased, is specified with the "step" attribute. 
     212 
     213=== Applying properties === 
     214 
     215The range control generates [wiki:documentation/C++Manual/HiddenElements hidden elements] similarly to the [wiki:documentation/C++Manual/Scrollbars scrollbars]. The elements it generates are: 
     216 * ''sliderarrowdec'' 
     217 * ''sliderarrowinc'' 
     218 * ''slidertrack'' 
     219 * ''sliderbar'' 
     220 
     221See the documentation on [wiki:documentation/C++Manual/Scrollbars#ApplyingRCSSproperties configuring scrollbars] for more information on controlling the size and decoration of the elements of the range control. 
     222 
     223== Form container == 
     224 
     225The form element is designed as a container element for form controls. Forms can be submitted, which bundles the name and value pairs of all descendant form controls into a single event. The form element is specified in RML with the <form> tag. It will generate a "submit" event when it is submitted; therefore it is usual to provide an inline event handler for "onsubmit". 
     226 
     227The form element's interface is the ''Rocket::Controls::ElementForm'' class. The form can be submitted by calling the ''Submit()'' function. 
     228 
     229{{{ 
     230// Submits the form. 
     231// @param[in] submit_value The value to send through as the 'submit' parameter. 
     232void Submit(const EMP::Core::String& submit_value = ""); 
     233}}} 
     234 
     235The value of the ''submit_value'' parameter will become the value of the ''submit'' parameter on the submit event. This way, objects listening for event can distinguish between different kinds of submit actions. 
     236 
     237== Form submit button == 
     238 
     239The form submit button is specified in RML with the <input type="submit" /> tag. The submit button will trigger a submit on its ancestor form when it is clicked, with a submit value equal to its "value" attribute. Its interface is the class ''Rocket::Controls::ElementFormControlInput''.