Open main menu

CDOT Wiki β

Changes

CIO 20133 Release 0.4 - OOP344

14,583 bytes added, 18:41, 12 November 2013
Created page with '==CButton== Button is a child of CField. It displays a small piece of text (usually one word or two) and accepts one key hit entry.<br /> When CButton is in edit mode, to indicat…'
==CButton==
Button is a child of CField.
It displays a small piece of text (usually one word or two) and accepts one key hit entry.<br />
When CButton is in edit mode, to indicate the editing mode, it will surround the text with squared brackets.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
namespace cio{
class CButton: public CField{
public:
CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS);
virtual ~CButton();
void draw(int fn=C_FULL_FRAME);
int edit();
bool editable()const;
void set(const void* str);
};
}

</syntaxhighlight></big>

===Attributes===
This class does not have any attributes of its own!
===Constructor / Destructor===
<big><syntaxhighlight lang="cpp">
CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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.<br />
Pass all the arguments directly to Field's constructor.<br />
For Field size (width and hight) do the following:<br />
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.
<big><syntaxhighlight lang="cpp">
virtual ~CButton();
</syntaxhighlight></big>
Deallocates the allocated memory pointed by Field's '''_data'''.

===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn=C_FULL_FRAME);
</syntaxhighlight></big>
Draws the Button with border around it if it is Bordered. Note that there should be a space before and after of the text that will be used to surround the text with "[" and "]"<br />
hint:<br />
:*First calls Frame's draw(fn) (passing the fn argument to the parents draw)

:Use console.display() to display the Button's text (pointed by Field's _data)
:*If not bordered
:*:display the text at absRow() and absCol()
:*If bordered
:*:display the text at absRow()+1 and absCol()+2

<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
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.<br />
When user hits a key, if the key is ENTER_KEY or SPACE, return C_BUTTON_HIT (defined in ciogh.h) otherwise return the entered key.<br />

<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
First deallocated what is pointed by Field's _data.
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.

<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Always returns true

===CButton Student Resources===
====CButton Help/Questions Blogs====
====CButton Blog Posts====
==CValEdit==
This class works exactly like CLineEdit and improves it by adding two features; Validation and Help. CValEdit is capable of validating the user input on exit and also provide help when CValEdit::edit() is active by invoking a '''"help"''' method before and after editing. If these two functions, (Validation and Help) are not provided, then CValEdit literally works like CLineEdit.
<big><syntaxhighlight lang="cpp">
#include "clineedit.h"

namespace cio{
class CValEdit: public CLineEdit{
void (*_help)(MessageStatus, CDialog&);
bool (*_validate)(const char*, CDialog&);
public:
CValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC,
void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
CValEdit(int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC,
void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
int edit();
};
}
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
void (*_help)(MessageStatus, CDialog&);
bool (*_validate)(const char*, CDialog&);
</syntaxhighlight></big>
*_help, holds the address of the help logic (function) or NULL if there is no help function is assigned
*_validate, holds the address of the validation logic (function) or NULL if there is no validation function is assgned

===Constructors===
<big><syntaxhighlight lang="cpp">
CValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC,
void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
CValEdit(int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC,
void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
These constructors pass all their arguments to corresponding arguments of CLineEdit constructor and then set '''_help''' and '''_validate''' attributes to the corresponding incoming arguments

===Method===
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
If the container() is NULL then this function works exactly like LineEdit::edit().<br />
If the container() is not NULL:
#If _help function exist, it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments.
#Calls CLineEdit's edit()
#If validation function exists, and the terminating key of CLineEdit's edit() is a navigation key(see below)
#:It will call the validation function on the Field's _data, if the data is valid, it goes to next step, otherwise it will repeat calling CLineEdit's edit().
#After validation is done, if _help function exists, it will recall the help function using MessageStatus::ClearMessage and contianer()'s reference as arguments.
#It will return the terminating key

''Navigation keys are Up key, Down key, Tab key or Enter key.''<br />
''MessageStatus is enumerated in '''ciogh.h'''''
===CValedit Student Resources===
====CValEdit Help/Questions Blogs====
====CValedit Blog Posts====

==CCheckMark==
Creates a single CheckMark on the screen and allows the user to:<br />
# Toggle it, if it is set to be a CheckMark for a Check List.
# Only check it when its unchecked, if it is set to be a CheckMark for a Radio Button List.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
#include "clabel.h"
namespace cio{
class CCheckMark : public CField{
bool _flag;
bool _radio;
char _format[4];
CLabel _Label;
public:
CCheckMark(bool Checked,const char* Format, const char* Text,
int Row, int Col, int Width, bool IsRadio = false);
CCheckMark(const CCheckMark& C);
void draw(int fn = C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* flag);
bool checked()const;
void checked(bool val);
bool radio();
void radio(bool isRadio);
operator bool();
operator char*();
bool operator=(bool flag);
};
}


</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
int _flag;
bool _radio;
char _format[4];
CLabel _Label;
</syntaxhighlight></big>
*'''_flag''' holds the status of the Checkbox (0: unchecked or 1: checked ) and is pointed by _data pointer .
*'''_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. "[X]", "(O)", "<*>", etc...).
*'''_Label''' holds the Label attached to the this Checkbox

===Constructor / Destructor===
<big><syntaxhighlight lang="cpp">
CCheckMark(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false);
</syntaxhighlight></big>
*Passes the ''Row, Col, Width and "1"'' to ''row, col, width and height'' arguments of CField and directly initializes _Label with ''Text, 0, 4, and (Width-4)'' for ''Str, Row, Col and Len'', arguments of CLabel's Constructor.<br />

*Sets the frame of _Label to its owner (Checkmark i.e. 'this');
*Sets _flag to Checked
*Sets _radio to IsRadio
*Copies Format to _format
*Sets _data to the address of _flag

<big><syntaxhighlight lang="cpp">
CCheckMark(const CCheckMark& C);
</syntaxhighlight></big>
*Passes incoming CCheckMark reference ("C") to CField's copy constructor, and directly initializes the _Label with the _Label of C
*Sets all the attributes of this object to the attributes of incoming CCheckMark reference ("C")
*Sets _data to the address of _flag

===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_NO_FRAME) ;
</syntaxhighlight></big>
Using Console methods:<br />
#displays the _format string at absRow() and absCol()
#if _flag is false, it will overwrite the second character printed above, with a space (removes the check mark on console)
#draw()s the _Label
#sets the position of the cursor at the checkmark (second character of printed _format)
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
#draw()s the checkmark
#gets a key
#: the key must be either SPACE or any non-printable character (all printable character are ignored)
#if the entered key is space
##if _radio is true, it will set the _flag to true
##if _radio is false, it will flip the value of _flag.
##draw()s the checkmark again
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
*Always return true;
<big><syntaxhighlight lang="cpp">
void set(const void* flag);
</syntaxhighlight></big>
*Casts the incoming flag pointer to an (bool*) and sets the content of '''_flag''' to where '''flag''' is pointing to.
<big><syntaxhighlight lang="cpp">
bool checked()const;
void checked(bool val);
</syntaxhighlight></big>
*These methods set and get _flag.
<big><syntaxhighlight lang="cpp">
bool radio(); // addition for R0.6
void radio(bool isRadio); // addition for R0.6
</syntaxhighlight></big>
* These to methods, get and set the '''_radio''' attribute.
<big><syntaxhighlight lang="cpp">
operator bool(); // addtion for R0.6
</syntaxhighlight></big>
* Overload the '''bool''' cast to return the value of '''_flag'''
<big><syntaxhighlight lang="cpp">
operator char*(); // addtion for R0.6
</syntaxhighlight></big>
* Overload the '''char*''' cast to return the value of '''_Label.data()'''
<big><syntaxhighlight lang="cpp">
bool operator=(bool flag);; // addtion for R0.6
</syntaxhighlight></big>
* Overload the operator= and set the _flag to flag

===CCheckMark Student Resources===
====CCheckMark Help/Questions Blogs====

====CCheckMark Blog Posts====

==CMenuItem==
CMenuItem provides a Label that can be marked as selected by pressing the space bar.
<big><syntaxhighlight lang="cpp">
#include "clabel.h"
#include "cfield.h"
namespace cio{
class CMenuItem:public CField{
bool _selected;
char _format[3];
CLabel Label;
public:
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
CMenuItem(const CMenuItem &CM);
void draw(int fn = C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* Selected);
bool selected()const;
void selected(bool val);
const char* Text()const;
};
}

</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
bool _selected;
</syntaxhighlight></big>
Holds the status of the MenuItem, being selected or not;
<big><syntaxhighlight lang="cpp">
char _format[3];
</syntaxhighlight></big>
Holds the surrounding characters with which a selected MenuItem is shown:<br />
If _format holds "[]", then a selected MenuItem will be like [MenuText]
<big><syntaxhighlight lang="cpp">
CLabel Label;
</syntaxhighlight></big>
Hold the Text of the MenuItem.

===Constructors / Destructor===
<big><syntaxhighlight lang="cpp">
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
</syntaxhighlight></big>
#Initializes the CField with Row, Col, Width and 1 for Height
#Initializes the Label with (Text, 0, 1 and Width-2) for (Str, Row, Col, and Len)
#Sets the attributes to corresponding arguments
#Sets CFields::_data to the address of _format
#Sets the Label's frame to this object.
<big><syntaxhighlight lang="cpp">
CMenuItem(const CMenuItem &CM);
</syntaxhighlight></big>
#Passes CM to CField and Initializes the Label with CM
#Sets the _selected to _selected of CM
#Sets CFields::_data to the address of _format
#Sets the Label's frame to this object.

===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_NO_FRAME) ;
</syntaxhighlight></big>
#Draws the Label with fn
#If _selected is true, it surrounds the Label Text the _format[0] and _format[1]
#If _selected if false, it surrounds the Label with SPACEs (overwrites _format[0] and _format[1])
#Positions the cursor at the first character of the Label
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
#draw()s the MenuItem
#gets a key
#: the key must be either SPACE or any non-printable character (all printable character are ignored)
#if the entered key is space
##it will set the _selected to true
##draw()s the MenuItem again
#returns the key
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Returns true.
<big><syntaxhighlight lang="cpp">
void set(const void* Selected);
</syntaxhighlight></big>
Sets _selected to where Selected is pointing to
<big><syntaxhighlight lang="cpp">
bool selected()const;
</syntaxhighlight></big>
Returns Selected
<big><syntaxhighlight lang="cpp">
void selected(bool val);
</syntaxhighlight></big>
Sets _selected to val
<big><syntaxhighlight lang="cpp">
const char* Text();
</syntaxhighlight></big>
Returns the text of Label

===CMenuItem Student Resources===
====CMenuItem Help/Questions Blogs====

====CMenuItem Blog Posts====
==Tester Programs and Sub Releases==
===R0.4.1 CButton===
===R0.4.2 CValEdit===
===R0.4.3 CCheckMark===
===R0.4.4 CMenuItem===
==Due Date==