Open main menu

CDOT Wiki β

Changes

Console Framework Classes 20103 - OOP344

3,832 bytes added, 12:36, 26 September 2011
m
no edit summary
Start by creating mock-up classes (class declaration and definition with empty methods that only compiles and don't do anything)
Each class MUST have its own header file to hold its declaration and ""cpp" " file to hold its implementation. To make sure you do not do circular includes follow these simple guidelines:
* Add recompilation safeguards to all your header files.
* Always use forward declaration if possible instead of including a class.
* Use includes only in files in which the actual header file code is used. avoid ""just in case" " includes.
= General Internal Header file =
The general header file holds the common setting and definition between all classes in the frame work.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
#ifndef ___CONFW_H__
#define ___CONFW_H__
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <&lt;string.h>&gt;
extern "&quot;C"&quot;{ #include "&quot;iol.h"&quot;
};
#define FW_BORDER_CHARS "&quot;/-\\|/-\\|"&quot;
#define FW_MAX_NO_FIELDS 100
# undef NO_HELPFUNC
#endif
#define NO_HELPFUNC ((void(*)(MessageStatus, FWDialog&amp;))(0))
#ifdef NO_VALDFUNC
# undef NO_VALDFUNC
#endif
#define NO_VALDFUNC ((bool(*)(const char*, FWDialog&amp;))(0))
#endif
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
=File Names=
Use the following rules to create filenames for your class.
These classes encapsulate all the functions written in IOL library in an Object Oriented method:
==Hierarchy==
<&lt;big><&gt;&lt;pre>&gt;
FWBorder
|
|-------- FWCheckList (Maybe?)
|-------- FWMenu (Maybe?)
<&lt;/pre><&gt;&lt;/big>&gt;
==FWBorder==
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWBorder {
int _row;
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
====Properties====
int _row, holds the relative coordinate of top row of this border with respect to its container.<&lt;br />&gt;int _col, same as _row, but for _col. <&lt;br />&gt;int _height, height of the entity. <&lt;br />&gt;int _width, width of the entity. <&lt;br />&gt;char _border[9], characters used to draw the border: <&lt;br />&gt;
: _border[0], left top
: _border[1], top side
: _border[6], bottom left
: _border[7], left side
bool _visible; Indicates if the border surrounding the entity is to be drawn or not. <&lt;br />&gt;
FWBorder* _container; holds the container (another FWBorder) which has opened this one (owner or container of the current FWBorder). '''_container''' will be NULL if this FWBorder does not have a container, in which case, it will be full screen and no matter what the values of row, col, width and height are, FWBorder will be '''Full Screen''' (no border will be drawn)
====Methods====
The following are the pseudo code to get absRow( ) and as well as absCol( ):
<&lt;pre>&gt;
r = _row
Cnt = container
end
return r
<&lt;/pre>&gt;
These two methods return the absolute coordinates of the FWBorder instance. (the row an column with respect to left top corner of the screen). These two functions are used to '''draw''' the border on the screen.
=====public=====
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWBorder(int Row=0, int Col=0, int Width=0,int Height=0,
bool Visible = false,
const char* Border=FW_BORDER_CHARS,
FWBorder* Container = (FWBorder*)0);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Sets the corresponding attributes to the incoming values in the argument list.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void visible(bool val);
bool visible()const;
int height()const;
int width()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
These Methods, set and get the corresponding attributes of the class
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool fullscreen()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns true if _container is null or else, it returns false;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual ~FWBorder();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
An empty virtual destructor.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual void draw(int refresh = FW_NO_REFRESH)const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
If _container is null then it just clears the screen and exits. <&lt;br />&gt;Otherwise:<&lt;br />&gt;
*If '''Refresh''' flag is set to FW_REFRESH, it will call the _container's draw, passing the same value as argument
*If the _visible flag is true, it will draw a box at _row and _col, with size of _width and _height using the _border characters and fills it with spaces. Otherwise it will just draw a box using spaces at the same location and same size.
Forward declaration of FWDialog is needed for this class;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWField: public FWBorder{
protected:
FWDialog* container();
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void* _data;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Will hold the address of any type of data a FWField can hold.
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWField(int Row = 0, int Col = 0,
int Width = 0, int Height =0,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Passes the corresponding attributes to it's parents constructor and then sets the _data attribute to the incoming Data argument.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
~FWField();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
An empty destructor
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual int edit() = 0;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Enforces the children to implement an edit() method
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual bool editable() const = 0;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Enforces the children to implement an editable() method that returns true if the class is to edit data and false if the class is to only display data.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual void set(const void* data) = 0;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Enforces the children to implement a set() method to set the _data attribute to the data the class is to work with.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual void* data();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns _data;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void container(FWDialog* theOwner);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Sets the _container attribute of FWBorder to '''theowner''' argument.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWDialog* container();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Casts the return value of FWBorder::container() to a FWDialog* and returns it.
FWLabel is child of FWField (therefore inheriting FWBorder too) responsible to display a short character string on the display.
This class is never editable
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWLabel: public FWField{
int _length;
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _length;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Holds the Length of the display area needed by iol_display.
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWLabel(const char *Str, int Row, int Col,
int Len = -1);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
*Passes corresponding arguments to its parent constructor
*Sets _length to the '''Len''' attribute.
*Then it will copy the content of what '''Str''' is pointing.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWLabel(int Row, int Col, int Len);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
*Passes corresponding arguments to its parent constructor
*Sets _length to the '''Len''' attribute.
This constructor is used when FWLabel is used for messaging and does not need initial value.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
~FWLabel();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Deallocates the memory pointed by _data;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int Refresh = FW_NO_REFRESH) const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Ignores the Refresh argument and make a direct call to '''iol_display''' to display the _data at '''absRow()''' and '''absCol()''' upto '''_length''' characters.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Since no editing is happening here, it just calls draw();
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns False.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void set(const void* str);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
copies the string pointed by '''str''' upto '''_length''' characters to '''_data'''.
==FWDialog==
FWDialog is a collection of several FWField; it organizes and groups FWFields for user entry and interaction <&lt;br />&gt;
The following definition is just a suggestion for how to implement this class. You can change it under with your professors confirmation to a better way if you like.
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWDialog: public FWBorder{
int add(FWField* field, bool dynamic = true);
int add(FWField& amp; field, bool dynamic = false); FWDialog& amp; operator<<&lt;&lt;(FWField* field); FWDialog& amp; operator<<&lt;&lt;(FWField& amp; field);
FWField& amp; operator[](unsigned int index); FWField& amp; curField();
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _fnum;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Holds the number of FWFields added to FWDialog.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _curidx;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Holds the index of the FWFields that is being edited now.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWField* _fld[FW_MAX_NO_FIELDS];
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
An array of FWFields pointers. Initially all the elements of _fld is set to null. When a FWField is added to the form, it will be pointed by one of the elements of this array.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool _dyn[FW_MAX_NO_FIELDS];
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;An array of boolean values exactly to the number of elements of _fld. When FWField number "&quot;n" &quot; is added to FWDialog and is pointed by _fld[n-1], the corresponding _dyn[n-1] indicate if the FWField held in _fld[n-1] is dynamically allocated or not. the _dyn flags will be used in the destructor as deallocation condition for each _fld element.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool _editable;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Is set to true, if at least one of the FWFields in _fld is editable.
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWDialog(FWBorder *Container = (FWBorder*)0,
int Row = -1, int Col = -1,
bool Borderd = false,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Passes all the arguments to its parent constructor and then sets the FWDialog to an empty dialog.<&lt;br />&gt;
(Sets all the Field pointers to null, flags to false and numbers to zero)
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
virtual ~FWDialog();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Loops through all the field pointers and checks to see if any of them are dynamically allocated and deletes them.
(it only deletes those fields that are flagged as dynamic)
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int fn = FW_NO_REFRESH)const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;If '''fn''' is '''FW_REFRESH''' or '''FW_FULL_FRAME''', it will call its parent draw with '''fn''' as its argument. Then It will draw all the '''Fields''' in the '''Dialog'''. <&lt;br />&gt;If '''fn''' is '''FW_NO_REFRESH''', then it will just draw all the '''Fields''' in the '''Dialog'''.<&lt;br />&gt;
If '''fn''' is a non-zero positive value, then it will only draw '''Field''' number '''fn''' in the dialog. (First added '''Field''' is field number one.)
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit(int fn = FW_NO_REFRESH);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
If '''FWDialog''' is not editable (all fields are non-editable), it will just display the Dialog and then waits for the user to enter a key and then terminates the function returning the key.<&lt;br />&gt;
If fn is '''0''' or less, then before editing, the draw method is called with '''fn''' as its argument and then editing begins from the first editable Field.
Start editing from field number '''fn''';
Call the edit of each field and depending on the value returned, do the following:<&lt;br />&gt;
# For '''ENTER_KEY''', '''TAB_KEY''' and '''DOWN_KEY''', go to next editable Field , if this is the last editable Field then restart from Field number one.
# For '''UP_KEY''' go to the previous editable Field, if there is no previous editable Field, go to the last editable Field in the Dialog.
# For any other key, terminate the edit function returning the character which caused the termination.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int add(FWField* field, bool dynamic = true);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Adds the '''FWField''' pointed by '''field''' to the Fields of the Dialog; by appending the value of the field pointer to the _fld array , setting the corresponding _dyn element to the value of dynamic argument and then increasing _fnum by one and returning it.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; int add(FWField& amp; field, bool dynamic = false);<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Makes a direct call to the previous add() method, passing the address of the '''field''' argument and the value of the '''dynamic''' argument and returning what it returns.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; FWDialog& amp; operator<<&lt;&lt;(FWField* field);<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Makes a direct call the first '''add()''' method returning a reference of the owner (the FWDialog);
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; FWDialog& amp; operator<<&lt;&lt;(FWField& amp; field);<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Makes a direct call the second '''add()''' method returning a reference of the owner (the FWDialog);
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
If at least one editable field exist in the Dialog, it returns true, otherwise, it returns false;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int fieldNum()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns number of fields added to the Dialog.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int curIndex()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns the index of the Field that was just being edited.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; FWField& amp; operator[](unsigned int index);<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns the reference of the Field with incoming index. (Note that here, the first field index is '''0''')
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; FWField& amp; curField();<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns the reference of the Field that was just being edited.
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWLineEdit: public FWField{
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;LineEdit, sets the Field's _data to the value of str. If LineEdit is instantiated with this constructor then it will edit an external string provided by the caller function of LineEdit. LineEdit in this case is not creating any dynamic memory, therefore _dyn is set to false (therefore the destructor will not attempt to deallocate the memory pointed by _data).<&lt;br />&gt;The location (row and col) and Bordered are directly passed to the parent (FWField) and str is passed as data to the parent constructor. Unlike Label, LineEdit could have border or not so depending on this (Bordered being true or false) the Height is set to 3 or 1 respectfully. <&lt;br />&gt;
(hint: use '''? :''' operator to pass the proper value to FWField's constructor)
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWLineEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Works exactly like the previous constructor with one difference; since no external data is passed to be edited here, this constructor must <span class="plainlinks">[http://www.thepiggybackrider.com/ <span style="color:black;font-weight:normal; text-decoration:none!important; background:none!important; text-decoration:none;/*CITATION*/">child carrier</span>]</span> allocate enough dynamic memory to accommodate editing of '''Maxdatalen''' characters. Then make it an empty string and set Fields's _data to point to it. Make sure _dyn is set to true in this case, so the destructor knows that it has to deallocate the memory at the end.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
~FWLineEdit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
If '''_dyn''' is true, it will deallocate the character array pointed by Fields's '''_data'''
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int Refresh = FW_NO_REFRESH)const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;If the Border is visible, it will first call Border's draw passing '''Refresh'''as an argument to it.<&lt;br />&gt;Then it will make a direct call to iol_display to show the data kept in Field's '''_data'''.<&lt;br />&gt;
The values used for the arguments of iol_display are:
*str: address of string pointed by _data + the value of _offset
*len: width() (''reduce by two is border is visible''')
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Makes and direct call to, and returns '''iol_edit()'''.
For the coordinates and width arguments follow the same rules as the draw function.
For the rest of the arguments of iol_edit, use the attributes of '''FWLineEdit'''.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Always return true;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void set(const void* Str);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Copies the characters pointed by '''Str''' into the memory pointed by Field's '''_data''' up to '''_maxdatalen''' characters.
When in edit mode, to indicate the editing mode, it will surround the text with squared brackets.
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWButton: public FWField{
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;When creating a Button, allocate enough memory to hold the contents of the '''Str''' and set Field's _data to point to it. Then copy the content of '''Str''' into the newly allocated memory.<&lt;br />&gt;Pass all the arguments directly to Field's constructor.<&lt;br />&gt;For Field size (width and hight) do the following:<&lt;br />&gt;
For width: Set width to the length of '''Str''' + 2 (adding 2 for surrounding brackets) or if the Button is bordered set width to the length of '''Str''' + 4 (adding 2 for surrounding brackets and 2 for the borders).
For height: Set the height to 1 or if the Button is bordered, set the height to 3.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
~FWButton();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Deallocates the allocated memory pointed by Field's '''_data'''.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int Refresh = FW_NO_REFRESH) const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
*First calls Border's draw()
use iol_display to display the Button's text (pointed by Field's _data)
*If bordered
*:display the text at absRow()+1 and absCol()+2
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;First draw() the Button, then surround it by squared brackets, place the cursor under the first character of Button's text and wait for user entry.<&lt;br />&gt;When user hits a key, if the key is ENTER_KEY or SPACE, return FW_BUTTON_HIT (defined in confw.h) otherwise return the entered key.<&lt;br />&gt;
Make sure the surrounding characters are replaced with spaces before exiting the edit() method.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Always returns true;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void set(const void* str);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Reallocate memory for new text set it to content of '''str''':
:''First deallocated what is pointed by Field's '''_data'''.''<&lt;br />&gt;
:''Then allocate new memory to the size of content of '''str''' and copy the content into it and make Field's '''_data''' point to it.''
FWCheck prints a checkbox and a Label in front of it and waits for user entry to possibly toggle the checkbox and exit.
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWCheck : public FWLabel {
int _flag;
void checked(bool val);
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _flag;
int _radio;
char _format[4];
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
*'''_flag''' holds the status of the Checkbox (0: unchecked or 1: checked).
*'''_radio''' dictates the behavior of the Checkbox as a radio-button, or a check-mark.
*'''_format''' holds the characters, the Checkbox is drawn with (i.e. "&quot;[X]"&quot;, "&quot;(O)"&quot;, "<&quot;&lt;*>"&gt;&quot;, etc...).
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, bool IsRadio = false);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
To create a FWCheck, pass Text, Row and Col + 4 to Parents Str, Row, Col. (added 4 to Col to make space for the checkmark at left).
Store Checked, IsRadio and Format in class attributes for future use.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int Refresh = FW_NO_REFRESH) const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;First call Label's draw passing Refresh as argument.<&lt;br />&gt;Then display a checkbox using iol_displayflag() using '''_format''' and '''_flag''' at absRow() and absCol(). <&lt;br />&gt;
''(make sure there is a space between the checkmark and the Label text)''
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Direct call and return of iol_flag, using same arguments used in draw();
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Always returns true;
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void set(const void* flag);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Set the '''_flag''' to the boolean pointed by '''flag''' attribute.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void *data();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Returns address of '''_flag'''
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool checked()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Return true if '''_flag''' is not zero.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void checked(bool val);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Sets '''_flag''' to 1 if val is true, or zero if val is false.
===Class Definition===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWValEdit: public FWLineEdit{
void (*_help)(MessageStatus, FWDialog&amp;); bool (*_validate)(const char*, FWDialog&amp;);
public:
FWValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool (*Validate)(const char* , FWDialog&amp;) = NO_VALDFUNC, void (*Help)(MessageStatus, FWDialog&amp;) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
FWValEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool (*Validate)(const char* , FWDialog&amp;) = NO_VALDFUNC, void (*Help)(MessageStatus, FWDialog&amp;) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
int edit();
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt; void (*_help)(MessageStatus, FWDialog&amp;); bool (*_validate)(const char*, FWDialog&amp;);<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Pointers to keep the address of possible help and validation function.<&lt;br />&gt;
''Note that if these two are NULL, then ValEdit works exactly like LineEdit''
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool (*Validate)(const char* , FWDialog&amp;) = NO_VALDFUNC, void (*Help)(MessageStatus, FWDialog&amp;) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
FWValEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool (*Validate)(const char* , FWDialog&amp;) = NO_VALDFUNC, void (*Help)(MessageStatus, FWDialog&amp;) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;They Pass the arguments to corresponding parents constructor.<&lt;br />&gt;
Then they Set '''_validate''' and '''_help''' attributes to their corresponding values in argument list.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;If the container() is NULL then this function works exactly like LineEdit::edit().<&lt;br />&gt;
If the container() is not NULL:
#If _help function exist it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments.
#It will return the terminating key
''Navigation keys are Up key, Down key, Tab key or Enter key.''<&lt;br />&gt;
''MessageStatus is enumerated in confw.h'''
at any time by calling the data() method the array of strings is converted back to a newline separated and null terminated array of characters (Converted back to text) and returned.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
class FWText:public FWField{
AnArrayOfStrings _lines; // see below
};
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
===Attributes===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
AnArrayOfStrings _lines;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Could be one the following:
*A two dimensional array of characters: char _lines[max_number_of_lines][max_number_of_characters_in_line+1];<&lt;br />&gt;
*: In this case you text size is limited to the max_number_of_lines and can not grow more than that.
*A dynamic array of strings: [[Dynamic Array Of Strings - OOP344 | StrArr]] _lines;<&lt;br />&gt;*: This case ([[Dynamic Array Of Strings - OOP344 | StrArr]]) is designed to simulate a two dimensional array of characters (or an array of strings) and has no limit in the number of lines and expands automatically if needed. You can use the code for ([[Dynamic Array Of Strings - OOP344 | StrArr]]) at your own risk to implement FWText, or you can design your own logic.<&lt;br />&gt;
*A Doubly Linked List (Queue) of strings [[Queue of Strings - OOP344 | StrQue]]
*: [[Queue of Strings - OOP344 | StrQue]] is a Queue of null terminated characters arrays (strings) and like StrArr has no limit in the number of lines and expands automatically if needed. Like StrArr, you can use the code for [[Queue of Strings - OOP344 | StrQue]] at your own risk to implement FWText, or you can design your own logic.<&lt;br />&gt;If you found any bugs or problems with [[Queue of Strings - OOP344 | StrQue]] or [[Dynamic Array Of Strings - OOP344 | StrArr]], do not modify it yourself but instead, please blog about it and send an email to [[mailto:fardad.soleimanloo@senecac.on.ca?subject=OOP344-StrQue me]] and I will take care of updating it.<&lt;br />&gt;
You can also find the code for [[Queue of Strings - OOP344 | StrQue]] and it's tester program in class notes repo: (svn://zenit.senecac.on.ca/oop344/trunk/C/13-Nov12).
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool _readOnly;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Keeps the status of the text being read only, or editable. (note that when read only, you can still scroll the text to left and right or up and down, but you can't modify the text).<&lt;br />&gt;
This flag is passed to iol_edit for the same reason.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _curpos;
int _fieldlen;
int* _insertmode;
int _offset;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Variables to be used with iol_edit to edit the lines of text.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _lcurpos;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Line Cursor Position; this variable keeps track of which line of text the cursor is on. _lcurpos is zero, if the cursor is on the fist line appearing in the Border.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int _loffset;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Offset Of the First Line; this variable keeps track of which line is the first appearing in the border. _loffset is zero, if the first string (line) of the string array is appearing on the fist line of the Border.<&lt;br /><&gt;&lt;br />&gt;
'''_lcurpos''' and '''_loffset''' have the same responsibility as _curpos, and _offset, but only for lines of the text. So as the left and right scrolling is done by manipulating _offset and _curpos, up and down scrolling of lines in the text are done by manipulating '''_loffset''' and '''_lcurpose'''
===Methods===
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWText(int Row, int Col, int Width, int Height, bool Readonly,
int* Insertmode, const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Sets all the attributes to their proper/corresponding values<&lt;br />&gt;
:''Note that FWText is always bordered''
If dynamic array of strings is used, initial text is allocated and set to an empty text.<&lt;br />&gt;<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
FWText(const char* Str, int Row, int Col, int Width, int Height, bool Readonly,
int* Insertmode, const char* Border=FW_BORDER_CHARS);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Works exactly like the previous constructor, but also it will call the '''set''' method of FWText to split the incoming text ('''Str''') at newline characters into an array of strings.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void draw(int Refresh = FW_NO_REFRESH)const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
#Calls its parents draw, to draw the border.
#Using iol_display, it prints lines of text from index _loffset, up to height()-2 times.
#:Note that each line is printed from _offset character using absRow() and absCol(), up o width()-2 characters
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void set(const void *Str);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Converts the newline delimited array of characters (the text) into an array of strings.<&lt;br />&gt;Set starts with the first string in the array of strings and copies the characters of the array to the current string until it reaches a newline character. <&lt;br />&gt;
Then it will null terminate the current string and go to the next string in the array of strings and repeats the same over and over until it reaches the end of the text.
:''Note that if '''FW_MAX_LINE_CHARS''' is reached before getting to the newline character, the current string is null terminated and copying continues into the next one''.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
void *data();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Converts the array of strings, back to a single string of text and returns it.<&lt;br />&gt;'''data()''' first calculates the size of the whole text including the newline characters at the end of each line. Then it will allocated enough memory to hold it all.<&lt;br /> &gt; Finally, it will concatenate all the strings back into the allocated memory adding a newline character to the end of each of them and returns it.<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
int edit();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;Draws the text area and then starts the editing from the first line.<&lt;br />&gt;The whole text should scroll to left, right, up or down instead, if the cursor tries to pass the edges of the text area.<&lt;br />&gt;When Enter key is hit, if in insertmode, a new line is inserted after the current line and any text after the cursor in the line should be moved into it.<&lt;br />&gt;When Backspace key is hit at the beginning of the line, the content of the current line should be moved to the previous line, the and current line should be deleted. The cursor in this case should stand in front of the copied data. <&lt;br />&gt;
:''Note that this will not happen if the sum of the length of the current and previous lines are more than FW_MAX_LINE_CHARS''
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool editable()const;
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
Always return true.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
bool readOnly()const;
void readOnly(bool val);
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
These two methods Get and Set the _readOnly attribute.
<&lt;big><&gt;&lt;syntaxhighlight lang="&quot;cpp">&quot;&gt;
~FWText();
<&lt;/syntaxhighlight><&gt;&lt;/big>&gt;
It deallocates the allocated memory. (If any memory allocation is used).
*Here is a sample of a make file on Linux, you can also find this '''makefile''' at svn://zenit.senecac.on.ca/oop344/trunk/C/Prj/makefile
<&lt;big><&gt;&lt;pre>&gt;
prj: iol.o fwborder.o fwfield.o fwlabel.o fwlineedit.o fwbutton.o fwcheck.o fwveditline.o fwdialog.o fwtext.o strarr.o testmains.o
c++ iol.o fwborder.o fwfield.o fwlabel.o fwlineedit.o fwbutton.o fwcheck.o fwveditline.o fwdialog.o fwtext.o strarr.o testmains.o \
c++ -c testmains.cpp
<&lt;/pre><&gt;&lt;/big>&gt;
==Testing==
1
edit