Difference between revisions of "Console UI Core Classes - OOP344 20111"
m (undoing spam) |
(corrected spam and special character replacement) |
||
Line 13: | Line 13: | ||
Start by creating mock-up classes (class declaration and definition with empty methods that only compiles and don't do anything). | 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 | + | 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. | * Add recompilation safeguards to all your header files. | ||
* Always use forward declaration if possible instead of including a class header-file. | * Always use forward declaration if possible instead of including a class header-file. | ||
* Use includes only in files in which the actual header file code is used. | * Use includes only in files in which the actual header file code is used. | ||
− | * '''Avoid | + | * '''Avoid "just in case" includes.''' |
=Due Dates= | =Due Dates= | ||
===Sat March 19 R3.0=== | ===Sat March 19 R3.0=== | ||
Line 47: | Line 47: | ||
= General Internal Header file (cgh.h R0.1)= | = General Internal Header file (cgh.h R0.1)= | ||
The general header file holds the common setting and definition between all the Core Classes. | The general header file holds the common setting and definition between all the Core Classes. | ||
− | + | <syntaxhighlight lang="cpp"> | |
#ifndef ___CGH_H__ | #ifndef ___CGH_H__ | ||
Line 66: | Line 66: | ||
#define C_NO_FRAME 0 | #define C_NO_FRAME 0 | ||
− | #define C_BORDER_CHARS | + | #define C_BORDER_CHARS "/-\\|/-\\|" |
enum CDirection {bio_centre, bio_left, bio_right, bio_up, bio_down}; | enum CDirection {bio_centre, bio_left, bio_right, bio_up, bio_down}; | ||
− | extern | + | extern "C"{ |
− | #include | + | #include "bio.h" |
}; | }; | ||
Line 79: | Line 79: | ||
# undef NO_HELPFUNC | # undef NO_HELPFUNC | ||
#endif | #endif | ||
− | #define NO_HELPFUNC ((void(*)(MessageStatus, CDialog& | + | #define NO_HELPFUNC ((void(*)(MessageStatus, CDialog&))(0)) |
#ifdef NO_VALDFUNC | #ifdef NO_VALDFUNC | ||
# undef NO_VALDFUNC | # undef NO_VALDFUNC | ||
#endif | #endif | ||
− | #define NO_VALDFUNC ((bool(*)(const char*, CDialog& | + | #define NO_VALDFUNC ((bool(*)(const char*, CDialog&))(0)) |
Line 90: | Line 90: | ||
#endif | #endif | ||
− | + | </syntaxhighlight> | |
=File Names= | =File Names= | ||
Line 98: | Line 98: | ||
*:For example '''CFrame''' class should have '''cframe.h''' and '''cframe.cpp''' files for its implementation. | *:For example '''CFrame''' class should have '''cframe.h''' and '''cframe.cpp''' files for its implementation. | ||
=Hierarchy= | =Hierarchy= | ||
− | + | <pre> | |
CFrame | CFrame | ||
| | | | ||
Line 129: | Line 129: | ||
| | | | ||
|-------- CMenu | |-------- CMenu | ||
− | + | </pre> | |
=Basic (BIO) Encapsulating Classes= | =Basic (BIO) Encapsulating Classes= | ||
Line 142: | Line 142: | ||
<syntaxhighlight lang="cpp">; | <syntaxhighlight lang="cpp">; | ||
#pragma once | #pragma once | ||
− | #include | + | #include "cgh.h" |
class CFrame{ | class CFrame{ | ||
Line 196: | Line 196: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
===Properties=== | ===Properties=== | ||
− | int _row, holds the relative coordinate of top row of this border with respect to its container. | + | int _row, holds the relative coordinate of top row of this border with respect to its container.<br /> |
− | int _col, same as _row, but for _col. | + | int _col, same as _row, but for _col. <br /> |
− | int _height, height of the entity. | + | int _height, height of the entity. <br /> |
− | int _width, width of the entity. | + | int _width, width of the entity. <br /> |
− | char _border[9], characters used to draw the border: | + | char _border[9], characters used to draw the border: <br /> |
: _border[0], left top | : _border[0], left top | ||
: _border[1], top side | : _border[1], top side | ||
Line 209: | Line 209: | ||
: _border[6], bottom left | : _border[6], bottom left | ||
: _border[7], left side | : _border[7], left side | ||
− | bool _visible; Indicates if the border surrounding the entity is to be drawn or not. | + | bool _visible; Indicates if the border surrounding the entity is to be drawn or not. <br /> |
− | CFrame* _frame; holds the container (another CFrame) which has opened this one (owner or container of the current CFrame). '''_frame''' will be NULL if this CFrame 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, CFrame will be '''Full Screen''' (no border will be drawn) | + | CFrame* _frame; holds the container (another CFrame) which has opened this one (owner or container of the current CFrame). '''_frame''' will be NULL if this CFrame 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, CFrame will be '''Full Screen''' (no border will be drawn)<br /> |
char* _covered; is a pointer to a character array that hold what was under this frame before being drawn. When the CFrame wants to hides itself, it simple copies the content of this array back on the screen on its own coordinates. | char* _covered; is a pointer to a character array that hold what was under this frame before being drawn. When the CFrame wants to hides itself, it simple copies the content of this array back on the screen on its own coordinates. | ||
===Methods and Constructors=== | ===Methods and Constructors=== | ||
====Private Methods==== | ====Private Methods==== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void capture(); | void capture(); | ||
− | + | </syntaxhighlight> | |
:if _covered pointer is not pointing to any allocated memory, it will call the bio_capture function to capture the area that is going to be covered by this frame and keeps its address in _covered. | :if _covered pointer is not pointing to any allocated memory, it will call the bio_capture function to capture the area that is going to be covered by this frame and keeps its address in _covered. | ||
Line 227: | Line 227: | ||
====Public Methods==== | ====Public Methods==== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1, | CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1, | ||
bool Visible = false, | bool Visible = false, | ||
const char* Border=C_BORDER_CHARS, | const char* Border=C_BORDER_CHARS, | ||
CFrame* Frame = (CFrame*)0); | CFrame* Frame = (CFrame*)0); | ||
− | + | </syntaxhighlight> | |
:Sets the corresponding attributes to the incoming values in the argument list and set _covered to null | :Sets the corresponding attributes to the incoming values in the argument list and set _covered to null | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual void draw(int fn=C_FULL_FRAME); | virtual void draw(int fn=C_FULL_FRAME); | ||
− | + | </syntaxhighlight> | |
* First it will '''capture()''' the coordinates it is supposed to cover | * First it will '''capture()''' the coordinates it is supposed to cover | ||
− | * If frame is '''fullscreen()''' then it just clears the screen and exits. | + | * If frame is '''fullscreen()''' then it just clears the screen and exits. <br /> |
− | Otherwise: | + | Otherwise:<br /> |
*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. | *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. | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual void move(CDirection dir); | virtual void move(CDirection dir); | ||
− | + | </syntaxhighlight> | |
− | First it will hide the Frame, then adjust the row and col to more to the | + | First it will hide the Frame, then adjust the row and col to more to the "dir" direction and then draws the Frame back on screen. |
− | + | <syntaxhighlight lang="cpp"> | |
virtual void hide(); | virtual void hide(); | ||
− | + | </syntaxhighlight> | |
using bio_restore()it restores the characters behind the Frame back on screen. It will also free the memory pointed by _covered; | using bio_restore()it restores the characters behind the Frame back on screen. It will also free the memory pointed by _covered; | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual ~CFrame(); | virtual ~CFrame(); | ||
− | + | </syntaxhighlight> | |
It will make sure allocated memories are freed. | It will make sure allocated memories are freed. | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool fullscreen()const; | bool fullscreen()const; | ||
void visible(bool val); | void visible(bool val); | ||
Line 273: | Line 273: | ||
void width(int val); | void width(int val); | ||
int width()const; | int width()const; | ||
− | + | </syntaxhighlight> | |
These functions set and get the attributes of the CFrame. | These functions set and get the attributes of the CFrame. | ||
− | ===CFrame.cpp & | + | ===CFrame.cpp & Test1Frame.cpp Bug Fix for R0.3.5=== |
Please visit my blog for the description and solution of the bug during the CFrame | Please visit my blog for the description and solution of the bug during the CFrame | ||
− | * [http://www.ashkansotoudeh.com/blog/?p=159 CFrame.cpp & | + | * [http://www.ashkansotoudeh.com/blog/?p=159 CFrame.cpp & Test1Frame.cpp Bug Fix for R0.3.5] by [[User:asotoude|Ashkan]] |
==CField== | ==CField== | ||
Line 284: | Line 284: | ||
CField is an abstract base class that encapsulates the commonalities of all Input Outputs Console Fields which are placeable on a CDialog. All Fields could be Framed, therefore a CField is int | CField is an abstract base class that encapsulates the commonalities of all Input Outputs Console Fields which are placeable on a CDialog. All Fields could be Framed, therefore a CField is int | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cframe.h" |
class CDialog; | class CDialog; | ||
class CField : public CFrame{ | class CField : public CFrame{ | ||
Line 307: | Line 307: | ||
CDialog* container(); | CDialog* container(); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void* _data; | void* _data; | ||
− | + | </syntaxhighlight> | |
Will hold the address of any type of data a CField can hold. | Will hold the address of any type of data a CField can hold. | ||
===Constructors and Methods=== | ===Constructors and Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CField(int Row = 0, int Col = 0, | CField(int Row = 0, int Col = 0, | ||
int Width = 0, int Height =0, | int Width = 0, int Height =0, | ||
Line 320: | Line 320: | ||
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
Passes the corresponding attributes to it's parents constructor and then sets the _data attribute to the incoming Data argument. | Passes the corresponding attributes to it's parents constructor and then sets the _data attribute to the incoming Data argument. | ||
− | + | <syntaxhighlight lang="cpp"> | |
~CField(); | ~CField(); | ||
− | + | </syntaxhighlight> | |
Empty Destructor | Empty Destructor | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual int edit() = 0; | virtual int edit() = 0; | ||
virtual bool editable() const = 0; | virtual bool editable() const = 0; | ||
virtual void set(const void* data) = 0; | virtual void set(const void* data) = 0; | ||
− | + | </syntaxhighlight> | |
Enforce the children to implement; | Enforce the children to implement; | ||
* an edit() method | * an edit() method | ||
* an editable() method that returns true if the class is to edit data and false if the class is to only display data. | * an editable() method that returns true if the class is to edit data and false if the class is to only display data. | ||
* a set() method to set the _data attribute to the data the class is to work with. | * a set() method to set the _data attribute to the data the class is to work with. | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual void* data(); | virtual void* data(); | ||
− | + | </syntaxhighlight> | |
Returns _data. | Returns _data. | ||
− | + | <syntaxhighlight lang="cpp"> | |
void container(CDialog* theContainer); | void container(CDialog* theContainer); | ||
CDialog* container(); | CDialog* container(); | ||
− | + | </syntaxhighlight> | |
Sets and Gets the _frame attribute of CFrame by calling CFrame::frame() method. Make sure to cast The CDialog to CFrame when setting and cast CFrame to CDialog when getting | Sets and Gets the _frame attribute of CFrame by calling CFrame::frame() method. Make sure to cast The CDialog to CFrame when setting and cast CFrame to CDialog when getting | ||
==CLabel== | ==CLabel== | ||
A readonly Field that encapsulates bio_display() function. (i.e it is responsible to display a short character string on the display) CLable although, by inheritance is Frame, but it is never '''bordered'''. | A readonly Field that encapsulates bio_display() function. (i.e it is responsible to display a short character string on the display) CLable although, by inheritance is Frame, but it is never '''bordered'''. | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
class CLabel : public CField{ | class CLabel : public CField{ | ||
int _length; | int _length; | ||
Line 355: | Line 355: | ||
int Len = 0); | int Len = 0); | ||
CLabel(int Row, int Col, int Len); | CLabel(int Row, int Col, int Len); | ||
− | CLabel(const CLabel& | + | CLabel(const CLabel& L); |
~CLabel(); | ~CLabel(); | ||
void draw(int fn=C_NO_FRAME) ; | void draw(int fn=C_NO_FRAME) ; | ||
Line 362: | Line 362: | ||
void set(const void* str); | void set(const void* str); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
int _length; | int _length; | ||
− | + | </syntaxhighlight> | |
Holds the Length of the label, this will be stored to be passed to bio_display function. | Holds the Length of the label, this will be stored to be passed to bio_display function. | ||
===Constructors / Destructor === | ===Constructors / Destructor === | ||
− | + | <syntaxhighlight lang="cpp"> | |
CLabel(const char *Str, int Row, int Col, | CLabel(const char *Str, int Row, int Col, | ||
int Len = 0); | int Len = 0); | ||
− | + | </syntaxhighlight> | |
passes the Row and Col to the CField constructor and then; | passes the Row and Col to the CField constructor and then; | ||
if len is zero, it will allocate enough memory to store the string pointed by Str and then copies the Str into it. | if len is zero, it will allocate enough memory to store the string pointed by Str and then copies the Str into it. | ||
− | if len | + | if len > 0, then it will allocate enough memory to store '''len''' chars in a string. |
In any way, the allocated memory is pointed by '''_data''' | In any way, the allocated memory is pointed by '''_data''' | ||
− | + | <syntaxhighlight lang="cpp"> | |
CLabel(int Row, int Col, int Len); | CLabel(int Row, int Col, int Len); | ||
− | + | </syntaxhighlight> | |
Works exactly like the previous constructor, but len in this case can not be zero. (no validation required) and the string pointed by _data will be set to an empty string. | Works exactly like the previous constructor, but len in this case can not be zero. (no validation required) and the string pointed by _data will be set to an empty string. | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CLabel(const CLabel& | + | CLabel(const CLabel& L); |
− | + | </syntaxhighlight> | |
Copy Constructor | Copy Constructor | ||
− | + | <syntaxhighlight lang="cpp"> | |
~CLabel(); | ~CLabel(); | ||
− | + | </syntaxhighlight> | |
makes sure that memory pointed by _data is deallocated before the object is destroyed. | makes sure that memory pointed by _data is deallocated before the object is destroyed. | ||
===Methods=== | ===Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int fn=C_NO_FRAME) ; | void draw(int fn=C_NO_FRAME) ; | ||
− | + | </syntaxhighlight> | |
makes a direct call to bio_display, passing '''_data''' for the string to be printed and absRow() and absCol() for row and col and _length for len. | makes a direct call to bio_display, passing '''_data''' for the string to be printed and absRow() and absCol() for row and col and _length for len. | ||
this function ignores the argument fn. | this function ignores the argument fn. | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
calls draw, returning 0. | calls draw, returning 0. | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool editable()const; | bool editable()const; | ||
− | + | </syntaxhighlight> | |
always return false. | always return false. | ||
− | + | <syntaxhighlight lang="cpp"> | |
void set(const void* str); | void set(const void* str); | ||
− | + | </syntaxhighlight> | |
if _length is greater than zero, it will copy the string pointed by str into the string pointed by _data upto _length characters. | if _length is greater than zero, it will copy the string pointed by str into the string pointed by _data upto _length characters. | ||
if _length is zero, it will delete the memory pointed by _data and reallocates enough memory for str and copies the string pointed by str into the newly allocated memory pointed by _data. | if _length is zero, it will delete the memory pointed by _data and reallocates enough memory for str and copies the string pointed by str into the newly allocated memory pointed by _data. | ||
Line 414: | Line 414: | ||
Organizes CField objects on the screen, displays them and then lets the user edit them one by one. | Organizes CField objects on the screen, displays them and then lets the user edit them one by one. | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cgh.h" |
− | #include | + | #include "cframe.h" |
class CField; | class CField; | ||
Line 440: | Line 440: | ||
int add(CField* field, bool dynamic = true); | int add(CField* field, bool dynamic = true); | ||
− | int add(CField& | + | int add(CField& field, bool dynamic = false); |
− | CDialog& | + | CDialog& operator<<(CField* field); |
− | CDialog& | + | CDialog& operator<<(CField& field); |
bool editable(); | bool editable(); | ||
Line 448: | Line 448: | ||
int curIndex()const; | int curIndex()const; | ||
− | CField& | + | CField& operator[](unsigned int index); |
− | CField& | + | CField& curField(); |
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
====Mandatory==== | ====Mandatory==== | ||
− | + | <syntaxhighlight lang="cpp"> | |
int _fnum; | int _fnum; | ||
− | + | </syntaxhighlight> | |
Holds the number of Fields added to the Dialog | Holds the number of Fields added to the Dialog | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool _editable; | bool _editable; | ||
− | + | </syntaxhighlight> | |
will be set to true if any of the Fields added are editable. | will be set to true if any of the Fields added are editable. | ||
====Optional==== | ====Optional==== | ||
This is optional because it depends on how you are going to implement the collection of CFields: | This is optional because it depends on how you are going to implement the collection of CFields: | ||
− | + | <syntaxhighlight lang="cpp"> | |
int _curidx; | int _curidx; | ||
− | + | </syntaxhighlight> | |
Holds the index of the Field that is currently being edited. | Holds the index of the Field that is currently being edited. | ||
− | + | <syntaxhighlight lang="cpp"> | |
CField* _fld[C_MAX_NO_FIELDS]; | CField* _fld[C_MAX_NO_FIELDS]; | ||
− | + | </syntaxhighlight> | |
Array of CField pointers to hold the address of the CField objects added to the screen. | Array of CField pointers to hold the address of the CField objects added to the screen. | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool _dyn[C_MAX_NO_FIELDS]; | bool _dyn[C_MAX_NO_FIELDS]; | ||
− | + | </syntaxhighlight> | |
Holds series of boolean to the exact number of fields, and each boolean here will hold false if the corresponding field pointed by _fld is allocated dynamically or not. | Holds series of boolean to the exact number of fields, and each boolean here will hold false if the corresponding field pointed by _fld is allocated dynamically or not. | ||
This array will later on be used by destructor to decide which object is dynamic and to be deleted. | This array will later on be used by destructor to decide which object is dynamic and to be deleted. | ||
===Constructors/Destructors=== | ===Constructors/Destructors=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CDialog(CFrame *Container = (CFrame*)0, | CDialog(CFrame *Container = (CFrame*)0, | ||
int Row = -1, int Col = -1, | int Row = -1, int Col = -1, | ||
Line 485: | Line 485: | ||
bool Borderd = false, | bool Borderd = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
− | The constructor, passes all the incoming arguments to the corresponding arguments of the apparent constructor '''CFrame'''. | + | The constructor, passes all the incoming arguments to the corresponding arguments of the apparent constructor '''CFrame'''.<br /> |
Then it will set called a attributes to their default values and then sets all the field pointers (_fld) to NULL. | Then it will set called a attributes to their default values and then sets all the field pointers (_fld) to NULL. | ||
It also sets all the dynamic (_dyn) flags to false. | It also sets all the dynamic (_dyn) flags to false. | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual ~CDialog(); | virtual ~CDialog(); | ||
− | + | </syntaxhighlight> | |
The destructor, will loop through all the field pointers and if the corresponding dynamic flag is true then it will delete the field pointed to by the field pointer. | The destructor, will loop through all the field pointers and if the corresponding dynamic flag is true then it will delete the field pointed to by the field pointer. | ||
===Methods=== | ===Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int fn = C_FULL_FRAME); | void draw(int fn = C_FULL_FRAME); | ||
− | + | </syntaxhighlight> | |
− | If '''fn''' is '''C_FULL_FRAME''', it will call its parent draw. Then It will draw all the '''Fields''' in the '''Dialog'''. | + | If '''fn''' is '''C_FULL_FRAME''', it will call its parent draw. Then It will draw all the '''Fields''' in the '''Dialog'''. <br /> |
− | If '''fn''' is not '''C_FULL_FRAME''', then it will just draw all the '''Fields''' in the '''Dialog'''. | + | If '''fn''' is not '''C_FULL_FRAME''', then it will just draw all the '''Fields''' in the '''Dialog'''.<br /> |
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.) | 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.) | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(int fn = C_FULL_FRAME); | int edit(int fn = C_FULL_FRAME); | ||
− | + | </syntaxhighlight> | |
− | If '''CDialog''' 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. | + | If '''CDialog''' 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.<br /> |
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. | 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. | ||
Line 514: | Line 514: | ||
Start editing from field number '''fn'''; | Start editing from field number '''fn'''; | ||
− | Call the edit of each field and depending on the value returned, do the following: | + | Call the edit of each field and depending on the value returned, do the following:<br /> |
# 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 '''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 '''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. | # For any other key, terminate the edit function returning the character which caused the termination. | ||
− | + | <syntaxhighlight lang="cpp"> | |
int add(CField* field, bool dynamic = true); | int add(CField* field, bool dynamic = true); | ||
− | + | </syntaxhighlight> | |
− | Adds the '''CField''' pointed by '''field''' to the Fields of the Dialog; by appending the value of the field pointer after the last added '''field'' in the _fld array , setting the corresponding _dyn element to the value of dynamic argument and then increasing _fnum by one and returning it. | + | Adds the '''CField''' pointed by '''field''' to the Fields of the Dialog; by appending the value of the field pointer after the last added '''field'' in the _fld array , setting the corresponding _dyn element to the value of dynamic argument and then increasing _fnum by one and returning it.<br /> |
− | '''important note: | + | '''important note:<br /> |
Make sure that add() sets the container of the added CField to this CDialog object, using the container() method of CField''' | Make sure that add() sets the container of the added CField to this CDialog object, using the container() method of CField''' | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | int add(CField& | + | int add(CField& field, bool dynamic = false); |
− | + | </syntaxhighlight> | |
Makes a direct call to the first add method. | Makes a direct call to the first add method. | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CDialog& | + | CDialog& operator<<(CField* field); |
− | + | </syntaxhighlight> | |
Makes a direct call to the first add method, ignoring the second argument and then returns the owner (current CDialog). | Makes a direct call to the first add method, ignoring the second argument and then returns the owner (current CDialog). | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CDialog& | + | CDialog& operator<<(CField& field); |
− | + | </syntaxhighlight> | |
Makes a direct call to the second add method, ignoring the second argument and then returns the owner (current CDialog). | Makes a direct call to the second add method, ignoring the second argument and then returns the owner (current CDialog). | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool editable(); | bool editable(); | ||
− | + | </syntaxhighlight> | |
Returns '''_editable'''; | Returns '''_editable'''; | ||
− | + | <syntaxhighlight lang="cpp"> | |
int fieldNum()const; | int fieldNum()const; | ||
− | + | </syntaxhighlight> | |
returns '''_fnum'''. | returns '''_fnum'''. | ||
− | + | <syntaxhighlight lang="cpp"> | |
int curIndex()const; | int curIndex()const; | ||
− | + | </syntaxhighlight> | |
returns '''_curidx'''; | returns '''_curidx'''; | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CField& | + | CField& operator[](unsigned int index); |
− | + | </syntaxhighlight> | |
Returns the reference of the Field with incoming index. (Note that here, the first field index is '''0''') | Returns the reference of the Field with incoming index. (Note that here, the first field index is '''0''') | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CField& | + | CField& curField(); |
− | + | </syntaxhighlight> | |
Returns the reference of the Field that was just being edited. | Returns the reference of the Field that was just being edited. | ||
==CLineEdit== | ==CLineEdit== | ||
'''ClineEdit''' encapsulates the bio_edit function of bio library. | '''ClineEdit''' encapsulates the bio_edit function of bio library. | ||
− | + | <syntaxhighlight lang="cpp"> | |
#pragma once | #pragma once | ||
− | #include | + | #include "cfield.h" |
class CLineEdit: public CField{ | class CLineEdit: public CField{ | ||
Line 587: | Line 587: | ||
void set(const void* Str); | void set(const void* Str); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
− | + | <syntaxhighlight lang="cpp"> | |
CLineEdit(char* Str, int Row, int Col, int Width, | CLineEdit(char* Str, int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
− | 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). | + | 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).<br /> |
− | 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. | + | 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. <br /> |
(hint: use '''? :''' operator to pass the proper Height value to FWField's constructor) | (hint: use '''? :''' operator to pass the proper Height value to FWField's constructor) | ||
− | + | <syntaxhighlight lang="cpp"> | |
CLineEdit(int Row, int Col, int Width, | CLineEdit(int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
Works exactly like the previous constructor with one difference; since no external data is passed to be edited here, this constructor must 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. | Works exactly like the previous constructor with one difference; since no external data is passed to be edited here, this constructor must 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. | ||
− | + | <syntaxhighlight lang="cpp"> | |
~CLineEdit(); | ~CLineEdit(); | ||
− | + | </syntaxhighlight> | |
If '''_dyn''' is true, it will deallocate the character array pointed by Fields's '''_data''' | If '''_dyn''' is true, it will deallocate the character array pointed by Fields's '''_data''' | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int Refresh = C_FULL_FRAME); | void draw(int Refresh = C_FULL_FRAME); | ||
− | + | </syntaxhighlight> | |
− | It will first call Frame's draw passing '''Refresh'''as an argument to it. | + | It will first call Frame's draw passing '''Refresh'''as an argument to it.<br /> |
− | Then it will make a direct call to bio_display to show the data kept in Field's '''_data'''. | + | Then it will make a direct call to bio_display to show the data kept in Field's '''_data'''.<br /> |
The values used for the arguments of bio_display are: | The values used for the arguments of bio_display are: | ||
*str: address of string pointed by _data + the value of _offset | *str: address of string pointed by _data + the value of _offset | ||
Line 624: | Line 624: | ||
*col: absCol() (''add one if border is visible'') | *col: absCol() (''add one if border is visible'') | ||
*len: width() (''reduce by two is border is visible''') | *len: width() (''reduce by two is border is visible''') | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
Makes a direct call to, and returns '''bio_edit()'''. | Makes a direct call to, and returns '''bio_edit()'''. | ||
For the coordinates and width arguments follow the same rules as the draw function. | For the coordinates and width arguments follow the same rules as the draw function. | ||
For the rest of the arguments of bio_edit, use the attributes of '''CLineEdit'''. | For the rest of the arguments of bio_edit, use the attributes of '''CLineEdit'''. | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool editable()const; | bool editable()const; | ||
− | + | </syntaxhighlight> | |
Always return true; | Always return true; | ||
− | + | <syntaxhighlight lang="cpp"> | |
void set(const void* Str); | void set(const void* Str); | ||
− | + | </syntaxhighlight> | |
Copies the characters pointed by '''Str''' into the memory pointed by Field's '''_data''' up to '''_maxdatalen''' characters. | Copies the characters pointed by '''Str''' into the memory pointed by Field's '''_data''' up to '''_maxdatalen''' characters. | ||
Line 644: | Line 644: | ||
It displays a small piece of text (usually one word or two) and accepts one key hit entry. | It displays a small piece of text (usually one word or two) and accepts one key hit entry. | ||
When in edit mode, to indicate the editing mode, it will surround the text with squared brackets. | When in edit mode, to indicate the editing mode, it will surround the text with squared brackets. | ||
− | + | <syntaxhighlight lang="cpp"> | |
#pragma once | #pragma once | ||
− | #include | + | #include "cfield.h" |
class CButton: public CField{ | class CButton: public CField{ | ||
public: | public: | ||
Line 659: | Line 659: | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
This class does not have any attributes of its own! | This class does not have any attributes of its own! | ||
===Constructor / Destructor=== | ===Constructor / Destructor=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CButton(const char *Str, int Row, int Col, | CButton(const char *Str, int Row, int Col, | ||
bool Bordered = true, | bool Bordered = true, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
− | 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. | + | 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. | + | Pass all the arguments directly to Field's constructor.<br /> |
− | For Field size (width and hight) do the following: | + | 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 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. | For height: Set the height to 1 or if the Button is bordered, set the height to 3. | ||
− | + | <syntaxhighlight lang="cpp"> | |
virtual ~CButton(); | virtual ~CButton(); | ||
− | + | </syntaxhighlight> | |
Deallocates the allocated memory pointed by Field's '''_data'''. | Deallocates the allocated memory pointed by Field's '''_data'''. | ||
===Methods=== | ===Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int fn=C_FULL_FRAME); | void draw(int fn=C_FULL_FRAME); | ||
− | + | </syntaxhighlight> | |
− | 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 | + | 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: | + | hint:<br /> |
:*First calls Frame's draw(fn) (passing the fn argument to the parents draw) | :*First calls Frame's draw(fn) (passing the fn argument to the parents draw) | ||
Line 693: | Line 693: | ||
:*:display the text at absRow()+1 and absCol()+2 | :*:display the text at absRow()+1 and absCol()+2 | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
− | 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. | + | 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 cgh.h) otherwise return the entered key. | + | When user hits a key, if the key is ENTER_KEY or SPACE, return C_BUTTON_HIT (defined in cgh.h) otherwise return the entered key.<br /> |
− | + | <syntaxhighlight lang="cpp"> | |
bool editable()const; | bool editable()const; | ||
− | + | </syntaxhighlight> | |
Always returns true; | Always returns true; | ||
− | + | <syntaxhighlight lang="cpp"> | |
void set(const void* str); | void set(const void* str); | ||
− | + | </syntaxhighlight> | |
− | Reallocate memory for new text and then set it to content of '''str''' | + | Reallocate memory for new text and then set it to content of '''str'''<br /> |
− | hint: | + | hint:<br /> |
− | :''First deallocated what is pointed by Field's '''_data'''.'' | + | :''First deallocated what is pointed by Field's '''_data'''.''<br /> |
:''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.'' | :''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.'' | ||
==CCheck== | ==CCheck== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
− | #include | + | #include "clabel.h" |
class CCheck : public CField{ | class CCheck : public CField{ | ||
int _flag; | int _flag; | ||
Line 721: | Line 721: | ||
public: | public: | ||
CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false); | CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false); | ||
− | CCheck(const CCheck& | + | CCheck(const CCheck& C); |
void draw(int fn = C_NO_FRAME) ; | void draw(int fn = C_NO_FRAME) ; | ||
int edit(); | int edit(); | ||
Line 730: | Line 730: | ||
void checked(bool val); | void checked(bool val); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
int _flag; | int _flag; | ||
int _radio; | int _radio; | ||
char _format[4]; | char _format[4]; | ||
CLabel _Label; | CLabel _Label; | ||
− | + | </syntaxhighlight> | |
*'''_flag''' holds the status of the Checkbox (0: unchecked or 1: checked ) and is pointed by _data pointer . | *'''_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. | *'''_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. | + | *'''_format''' holds the characters, the Checkbox is drawn with (i.e. "[X]", "(O)", "<*>", etc...). |
*'''_Label''' holds the Label attached to the this Checkbox | *'''_Label''' holds the Label attached to the this Checkbox | ||
===Constructor / Destructor=== | ===Constructor / Destructor=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false); | CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false); | ||
− | + | </syntaxhighlight> | |
− | *Passes the Row, Col, Width and | + | *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 /> |
*: *see page 64 of Practical Programming Techniques Using C++ | *: *see page 64 of Practical Programming Techniques Using C++ | ||
*Sets the frame of _Label to itself | *Sets the frame of _Label to itself | ||
Line 754: | Line 754: | ||
*Sets _data to the address of _flag | *Sets _data to the address of _flag | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CCheck(const CCheck& | + | CCheck(const CCheck& C); |
− | + | </syntaxhighlight> | |
− | *Passes incoming CCheck reference ( | + | *Passes incoming CCheck 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 CCheck reference ( | + | *Sets all the attributes of this object to the attributes of incoming CCheck reference ("C") |
*Sets _data to the address of _flag | *Sets _data to the address of _flag | ||
===Methods=== | ===Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int fn = C_NO_FRAME) ; | void draw(int fn = C_NO_FRAME) ; | ||
− | + | </syntaxhighlight> | |
*Uses bio_displayflag() to display _flag using _format at absRow() and absCol() | *Uses bio_displayflag() to display _flag using _format at absRow() and absCol() | ||
*Then draw()s the _Label | *Then draw()s the _Label | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
*returns bio_flag()'s returned value. | *returns bio_flag()'s returned value. | ||
*:bio_flag is to edit the value of _flag using the same arguments used in draw() as radiobutton or checkbox depending to the value of _radio | *:bio_flag is to edit the value of _flag using the same arguments used in draw() as radiobutton or checkbox depending to the value of _radio | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool editable()const; | bool editable()const; | ||
− | + | </syntaxhighlight> | |
*Always return true; | *Always return true; | ||
− | + | <syntaxhighlight lang="cpp"> | |
void set(const void* flag); | void set(const void* flag); | ||
− | + | </syntaxhighlight> | |
*Casts the incoming flag pointer to an (int*) and sets the content of '''_flag''' to where '''flag''' is pointing to. | *Casts the incoming flag pointer to an (int*) and sets the content of '''_flag''' to where '''flag''' is pointing to. | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool checked()const; | bool checked()const; | ||
void checked(bool val); | void checked(bool val); | ||
− | + | </syntaxhighlight> | |
*These methods set and get _flag. | *These methods set and get _flag. | ||
==CMenuItem== | ==CMenuItem== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
class CMenuItem:public CField{ | class CMenuItem:public CField{ | ||
int _selected; | int _selected; | ||
Line 795: | Line 795: | ||
public: | public: | ||
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width); | CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width); | ||
− | CMenuItem(const CMenuItem & | + | CMenuItem(const CMenuItem &CM); |
virtual ~CMenuItem(void); | virtual ~CMenuItem(void); | ||
void draw(int fn = C_NO_FRAME) ; | void draw(int fn = C_NO_FRAME) ; | ||
Line 805: | Line 805: | ||
const char* Text(); | const char* Text(); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
int _selected; | int _selected; | ||
char _format[3]; | char _format[3]; | ||
char* _text; | char* _text; | ||
− | + | </syntaxhighlight> | |
*_selected holds the status of the menuitem (0: not selected, 1: selected) and is pointed by _data. | *_selected holds the status of the menuitem (0: not selected, 1: selected) and is pointed by _data. | ||
− | *_format hods the surrounding | + | *_format hods the surrounding "selection indicator" characters used by bio_displaymenuitem. |
*_text points to the allocated memory holding the text of the menuitem | *_text points to the allocated memory holding the text of the menuitem | ||
===Constructors / Destructor=== | ===Constructors / Destructor=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width); | CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width); | ||
− | + | </syntaxhighlight> | |
*Sets _selected to Selected (0 for false and 1 for true) | *Sets _selected to Selected (0 for false and 1 for true) | ||
*Copies Format into _format | *Copies Format into _format | ||
Line 826: | Line 826: | ||
*Sets _data to the address of _selected | *Sets _data to the address of _selected | ||
*It passes the Row, the Col and the Width to the CField constructor | *It passes the Row, the Col and the Width to the CField constructor | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | CMenuItem(const CMenuItem & | + | CMenuItem(const CMenuItem &CM); |
− | + | </syntaxhighlight> | |
− | *Passes the incoming CMenuItem ( | + | *Passes the incoming CMenuItem ("CM") to CFiled's constructor |
*Allocated enough memory to hold CM._text and sets _text to address of newly allocated memory | *Allocated enough memory to hold CM._text and sets _text to address of newly allocated memory | ||
*Copies the string pointed by CM._text into _text | *Copies the string pointed by CM._text into _text | ||
*Sets _selected to CM._selected | *Sets _selected to CM._selected | ||
*Sets _data to the address of _selected | *Sets _data to the address of _selected | ||
− | + | <syntaxhighlight lang="cpp"> | |
~CMenuItem(void); | ~CMenuItem(void); | ||
− | + | </syntaxhighlight> | |
*Deallocated the memory pointed by _text | *Deallocated the memory pointed by _text | ||
===Methods=== | ===Methods=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
void draw(int fn = C_NO_FRAME) ; | void draw(int fn = C_NO_FRAME) ; | ||
− | + | </syntaxhighlight> | |
*Draws the object using bio_displayMenuItem function. | *Draws the object using bio_displayMenuItem function. | ||
*:Make sure absRow() and absCol() are used for Row and Col args of bio_displayMenuItem | *:Make sure absRow() and absCol() are used for Row and Col args of bio_displayMenuItem | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
*Returns the returned value of bio_menuItem() using the same arguemtns used in draw() | *Returns the returned value of bio_menuItem() using the same arguemtns used in draw() | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool editable()const; | bool editable()const; | ||
− | + | </syntaxhighlight> | |
*Always returns true | *Always returns true | ||
− | + | <syntaxhighlight lang="cpp"> | |
void set(const void* Selected); | void set(const void* Selected); | ||
− | + | </syntaxhighlight> | |
*Sets _selected to content pointed by Selected | *Sets _selected to content pointed by Selected | ||
− | + | <syntaxhighlight lang="cpp"> | |
bool selected()const; | bool selected()const; | ||
void selected(bool val); | void selected(bool val); | ||
− | + | </syntaxhighlight> | |
*These methods set and get _selected. | *These methods set and get _selected. | ||
− | + | <syntaxhighlight lang="cpp"> | |
const char* Text()const; | const char* Text()const; | ||
− | + | </syntaxhighlight> | |
*Returns _text | *Returns _text | ||
=Complex Core User Interface classes= | =Complex Core User Interface classes= | ||
==CValEdit== | ==CValEdit== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "clineedit.h" |
class CValEdit: public CLineEdit{ | class CValEdit: public CLineEdit{ | ||
− | void (*_help)(MessageStatus, CDialog& | + | void (*_help)(MessageStatus, CDialog&); |
− | bool (*_validate)(const char*, CDialog& | + | bool (*_validate)(const char*, CDialog&); |
public: | public: | ||
CValEdit(char* Str, int Row, int Col, int Width, | CValEdit(char* Str, int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
− | bool (*Validate)(const char* , CDialog& | + | bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, |
− | void (*Help)(MessageStatus, CDialog& | + | void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC, |
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
CValEdit(int Row, int Col, int Width, | CValEdit(int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
− | bool (*Validate)(const char* , CDialog& | + | bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, |
− | void (*Help)(MessageStatus, CDialog& | + | void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC, |
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
int edit(); | int edit(); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
===Attributes=== | ===Attributes=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | void (*_help)(MessageStatus, CDialog& | + | void (*_help)(MessageStatus, CDialog&); |
− | bool (*_validate)(const char*, CDialog& | + | bool (*_validate)(const char*, CDialog&); |
− | + | </syntaxhighlight> | |
*_help, holds the address of the help logic (function) or NULL if there is no help function is assigned | *_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 | *_validate, holds the address of the validation logic (function) or NULL if there is no validation function is assgned | ||
===Constructors=== | ===Constructors=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
CValEdit(char* Str, int Row, int Col, int Width, | CValEdit(char* Str, int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
− | bool (*Validate)(const char* , CDialog& | + | bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, |
− | void (*Help)(MessageStatus, CDialog& | + | void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC, |
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
CValEdit(int Row, int Col, int Width, | CValEdit(int Row, int Col, int Width, | ||
int Maxdatalen, int* Insertmode, | int Maxdatalen, int* Insertmode, | ||
− | bool (*Validate)(const char* , CDialog& | + | bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC, |
− | void (*Help)(MessageStatus, CDialog& | + | void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC, |
bool Bordered = false, | bool Bordered = false, | ||
const char* Border=C_BORDER_CHARS); | const char* Border=C_BORDER_CHARS); | ||
− | + | </syntaxhighlight> | |
These constructors pass all their arguments to corresponding arguments of CLineEdit constructor and then set '''_help''' and '''_validate''' attributes to the corresponding incoming arguments | 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=== | ===Method=== | ||
− | + | <syntaxhighlight lang="cpp"> | |
int edit(); | int edit(); | ||
− | + | </syntaxhighlight> | |
− | If the container() is NULL then this function works exactly like LineEdit::edit(). | + | If the container() is NULL then this function works exactly like LineEdit::edit().<br /> |
If the container() is not NULL: | If the container() is not NULL: | ||
#If _help function exist it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments. | #If _help function exist it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments. | ||
Line 928: | Line 928: | ||
#It will return the terminating key | #It will return the terminating key | ||
− | ''Navigation keys are Up key, Down key, Tab key or Enter key.'' | + | ''Navigation keys are Up key, Down key, Tab key or Enter key.''<br /> |
''MessageStatus is enumerated in '''cgh.h''''' | ''MessageStatus is enumerated in '''cgh.h''''' | ||
==CText== | ==CText== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
Line 963: | Line 963: | ||
~CText(); | ~CText(); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
==CCheckList== | ==CCheckList== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
− | #include | + | #include "ccheck.h" |
class CCheckList; | class CCheckList; | ||
Line 979: | Line 979: | ||
public: | public: | ||
CCheckList(const char* Format, int Row, int Col, int Width,bool radio, bool Bordered = true,const char* Border=C_BORDER_CHARS); | CCheckList(const char* Format, int Row, int Col, int Width,bool radio, bool Bordered = true,const char* Border=C_BORDER_CHARS); | ||
− | CCheckList& | + | CCheckList& add(const char* Text, bool selected = false); |
void draw(int fn = C_FULL_FRAME); | void draw(int fn = C_FULL_FRAME); | ||
int edit(); | int edit(); | ||
void* data(); | void* data(); | ||
void set(const void* data); | void set(const void* data); | ||
− | bool& | + | bool& operator[](unsigned int index); |
bool editable()const; | bool editable()const; | ||
bool radio(); | bool radio(); | ||
Line 991: | Line 991: | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
==CMenu== | ==CMenu== | ||
− | + | <syntaxhighlight lang="cpp"> | |
− | #include | + | #include "cfield.h" |
− | #include | + | #include "cmenuitem.h" |
class Cmenu; | class Cmenu; | ||
Line 1,002: | Line 1,002: | ||
public: | public: | ||
CMenu(const char* Format, int Row, int Col, int Width, bool Bordered = true,const char* Border=C_BORDER_CHARS); | CMenu(const char* Format, int Row, int Col, int Width, bool Bordered = true,const char* Border=C_BORDER_CHARS); | ||
− | CMenu& | + | CMenu& add(const char* Text, bool selected = false); |
void draw(int fn = C_FULL_FRAME); | void draw(int fn = C_FULL_FRAME); | ||
int edit(); | int edit(); | ||
Line 1,014: | Line 1,014: | ||
~CMenu(void); | ~CMenu(void); | ||
}; | }; | ||
− | + | </syntaxhighlight> | |
=Make Files and Testers= | =Make Files and Testers= | ||
− | Copy these makefiles under | + | Copy these makefiles under "makefile" name in root of your project in Linux or Mac.<br /> |
− | Replace the | + | Replace the "<tab>" with tab character<br /> |
− | then issue the make command: | + | then issue the make command: <br /> |
− | $make | + | $make <enter><br /> |
− | this will compile your code and create an executable called prjexe, if there is no error | + | this will compile your code and create an executable called prjexe, if there is no error<br /> |
− | Also, copies of all these make files and tester programs are commited to: '''svn://zenit.senecac.on.ca/oop344/trunk/Testers | + | Also, copies of all these make files and tester programs are commited to: '''svn://zenit.senecac.on.ca/oop344/trunk/Testers<br /> |
− | The executable of testers are compiled and copied in my account on matrix: | + | The executable of testers are compiled and copied in my account on matrix:<br /> |
− | login to matix and run: | + | login to matix and run:<br /> |
− | $~fardad.soleimanloo/t[X] | + | $~fardad.soleimanloo/t[X]<br /> |
where [X] is number of the test. (i.e. run $fardad.soleimanloo/t3 for test3 | where [X] is number of the test. (i.e. run $fardad.soleimanloo/t3 for test3 | ||
== Test2 Make file == | == Test2 Make file == | ||
− | + | <pre> | |
t2: bio.o cframe.o cfield.o cdialog.o clabel.o Test2DialogAndLabel.o | t2: bio.o cframe.o cfield.o cdialog.o clabel.o Test2DialogAndLabel.o | ||
<tab>c++ bio.o cframe.o cfield.o cdialog.o clabel.o \ | <tab>c++ bio.o cframe.o cfield.o cdialog.o clabel.o \ | ||
Line 1,050: | Line 1,050: | ||
<tab>c++ -c Test2DialogAndLabel.cpp | <tab>c++ -c Test2DialogAndLabel.cpp | ||
− | </pre | + | </pre> |
==Test 3 make file== | ==Test 3 make file== | ||
− | + | <pre> | |
prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o | prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o | ||
− | + | <tab>c++ bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o \ | |
-lncurses -oprjexe | -lncurses -oprjexe | ||
bio.o: bio.c bio.h | bio.o: bio.c bio.h | ||
− | + | <tab>cc -c bio.c | |
cframe.o: cframe.cpp cframe.h cgh.h | cframe.o: cframe.cpp cframe.h cgh.h | ||
− | + | <tab>c++ -c cframe.cpp | |
cfield.o: cfield.cpp cfield.h cgh.h cframe.h | cfield.o: cfield.cpp cfield.h cgh.h cframe.h | ||
− | + | <tab>c++ -c cfield.cpp | |
cdialog.o: cdialog.cpp cdialog.h cfield.h cgh.h cframe.h | cdialog.o: cdialog.cpp cdialog.h cfield.h cgh.h cframe.h | ||
− | + | <tab>c++ -c cdialog.cpp | |
clabel.o: clabel.cpp clabel.h cfield.h cframe.h cgh.h | clabel.o: clabel.cpp clabel.h cfield.h cframe.h cgh.h | ||
− | + | <tab>c++ -c clabel.cpp | |
clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h cgh.h | clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h cgh.h | ||
− | + | <tab>c++ -c clineedit.cpp | |
Test3DialogAndLineEdit.o: Test3DialogAndLineEdit.cpp clineedit.h clabel.h cdialog.h cfield.h cframe.h cgh.h | Test3DialogAndLineEdit.o: Test3DialogAndLineEdit.cpp clineedit.h clabel.h cdialog.h cfield.h cframe.h cgh.h | ||
− | + | <tab>c++ -c Test3DialogAndLineEdit.cpp | |
− | + | </pre> | |
==Full Project Makefile== | ==Full Project Makefile== | ||
Not Tested! | Not Tested! | ||
− | + | <pre> | |
prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o | prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o | ||
c++ bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o \ | c++ bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o \ | ||
Line 1,133: | Line 1,133: | ||
c++ -c prj.cpp | c++ -c prj.cpp | ||
− | </pre | + | </pre> |
Latest revision as of 13:07, 17 April 2013
OOP344 | Weekly Schedule | Student List | Teams | Project | Student Resources
Under Construction!
Release 0.5
Before anything, go to your repository/branches/fardad/bio_additions and open bio.c and bio.h, then copy and apply the additional functions and changes to your own bio.c and bio.h in trunk. Make sure it compiles and runs properly. These changes add buffering support to be able to prevent flickering. The functionalities added will not change the console behavior or the bio functions. After applying the changes, everything should work they way they worked before.
Your objective at this stage is to create series of core classes designed to interact with the user. These Core Classes then can be used in development of any interactive application.
Please note that the class definitions here are minimum requirement for the Core Classes and you are free to add any enhancements or features you find useful. However make sure that you discuss these enhancements with your professor to make sure they are feasible before implementation.
It is highly recommended to develop the classes in the order they are stated here. You must create your won tester programs fore each class (if possible); However, close to due date of each release, a tester program is provided to help you verify the functionality of your classes. Executables of the test programs are available on matrix to show you how it is supposed to run.
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 header-file.
- Use includes only in files in which the actual header file code is used.
- Avoid "just in case" includes.
Contents
Due Dates
Sat March 19 R3.0
- Merge the bio additions to your bio.c and bio.h
- Add all the files for mock-up classes
- create .h and .cpp files for all classes
- the name of the file is all lower case and is the same as class name (i.e CFrame class: cframe.h and cframe.cpp)
- copy the class definitions into .h files
- create mock-up methods for the class defs
- create .h and .cpp files for all classes
- Tag it in Release 0.3
Tue March 22 R3.5
- merge the code for CFrame and CField from branches\fardad\FrameFieldStrarr into your project and compile, run and test it with Test1Frame.cpp
- Tag it in Release 0.35
Tue march 29 R4.0
- Code the following
- CDialog
- CLabel Tester: Test2DialogAndLabel.cpp
- CLineEdit Tester: Test3DialogAndLineEdit.cpp
- After successful testing, tag them in R4.0
Fri Apr 8 R5.0
- Code the following
- CCheck
- CButton
- CMenuItem
- CValEdit
- After successful testing, tag them in R5.0
General Internal Header file (cgh.h R0.1)
The general header file holds the common setting and definition between all the Core Classes.
#ifndef ___CGH_H__
#define ___CGH_H__
#ifndef _CRT_SECURE_NO_DEPRECATE
#define _CRT_SECURE_NO_DEPRECATE
#endif
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#define C_MAX_NO_FIELDS 100
#define C_BUTTON_HIT 1
#define C_MAX_LINE_CHARS (1024u)
#define C_FULL_FRAME -1
#define C_NO_FRAME 0
#define C_BORDER_CHARS "/-\\|/-\\|"
enum CDirection {bio_centre, bio_left, bio_right, bio_up, bio_down};
extern "C"{
#include "bio.h"
};
enum MessageStatus{ClearMessage,SetMessage};
#ifdef NO_HELPFUNC
# undef NO_HELPFUNC
#endif
#define NO_HELPFUNC ((void(*)(MessageStatus, CDialog&))(0))
#ifdef NO_VALDFUNC
# undef NO_VALDFUNC
#endif
#define NO_VALDFUNC ((bool(*)(const char*, CDialog&))(0))
#define C_MAX_LINE_CHARS (1024u)
#define C_INITIAL_NUM_OF_LINES (100u)
#endif
File Names
Use the following rules to create filenames for your class.
- Each class MUST have its own header file and cpp file for implementation
- Use the class name for the name of the file but make sure it is all lowercase.
- For example CFrame class should have cframe.h and cframe.cpp files for its implementation.
Hierarchy
CFrame | |---CDialog | | |---CField | |-------- CLabel | | |-------- CButton | | |-------- CLineEdit | | | |-------CValEdit | |-------- CText | | |-------- CCheck | | |-------- CCheckList | | |-------- CMenuItem | | |-------- CMenu
Basic (BIO) Encapsulating Classes
CFrame
The code for this class is provided. You must understand and use it to develop your core classes.
CFrame class is responsible to create a frame or structure in which all user interface classes contain themselves in. It can draw a border around it self or be border-less. CFrame also, before displaying itself on the screen, will save the area it is about to cover, so it can redisplay them to hide itself.
CFrame is base of all objects in our user interface system.
;
#pragma once
#include "cgh.h"
class CFrame{
int _row; // relative row of left top corner to the container frame or the screen if _frame is null
int _col; // relative col of left top corner to the container frame or the screen if _frame is null
int _height;
int _width;
char _border[9]; // border characters
bool _visible; // is bordered or not
CFrame* _frame; // pointer to the container of the frame (the frame, surrounding this frame)
char* _covered; // pointer to the characters of the screen which are covered by this frame, when displayed
void capture(); // captures and saves the characters in the area covered by this frame when displayed and sets
// _covered to point to it
protected:
int absRow()const;
int absCol()const;
public:
CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1,
bool Visible = false,
const char* Border=C_BORDER_CHARS,
CFrame* Frame = (CFrame*)0);
virtual void draw(int fn=C_FULL_FRAME);
virtual void move(CDirection dir);
virtual void hide();
virtual ~CFrame();
/* setters and getters: */
bool fullscreen()const;
void visible(bool val);
bool visible()const;
void frame(CFrame* theContainer);
CFrame* frame();
void row(int val);
int row()const;
void col(int val);
int col()const;
void height(int val);
int height()const;
void width(int val);
int width()const;
void refresh();
};
Properties
int _row, holds the relative coordinate of top row of this border with respect to its container.
int _col, same as _row, but for _col.
int _height, height of the entity.
int _width, width of the entity.
char _border[9], characters used to draw the border:
- _border[0], left top
- _border[1], top side
- _border[2], right top
- _border[3], right side
- _border[4], right bottom
- _border[5], bottom side
- _border[6], bottom left
- _border[7], left side
bool _visible; Indicates if the border surrounding the entity is to be drawn or not.
CFrame* _frame; holds the container (another CFrame) which has opened this one (owner or container of the current CFrame). _frame will be NULL if this CFrame 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, CFrame will be Full Screen (no border will be drawn)
char* _covered; is a pointer to a character array that hold what was under this frame before being drawn. When the CFrame wants to hides itself, it simple copies the content of this array back on the screen on its own coordinates.
Methods and Constructors
Private Methods
void capture();
- if _covered pointer is not pointing to any allocated memory, it will call the bio_capture function to capture the area that is going to be covered by this frame and keeps its address in _covered.
Protected Methods
- int absRow()const; calculates the absolute row (relative to the left top corner of the screen) and returns it.
- it returns the sum of row() of this border plus all the row()s of the _frames
- int absCol()const; calculates the absolute column(relative to the left top corner of the screen) and returns it.
- it returns the sum of col() of this border plus all the col()s of the _frames
Public Methods
CFrame(int Row=-1, int Col=-1, int Width=-1,int Height=-1,
bool Visible = false,
const char* Border=C_BORDER_CHARS,
CFrame* Frame = (CFrame*)0);
- Sets the corresponding attributes to the incoming values in the argument list and set _covered to null
virtual void draw(int fn=C_FULL_FRAME);
- First it will capture() the coordinates it is supposed to cover
- If frame is fullscreen() then it just clears the screen and exits.
Otherwise:
- 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.
virtual void move(CDirection dir);
First it will hide the Frame, then adjust the row and col to more to the "dir" direction and then draws the Frame back on screen.
virtual void hide();
using bio_restore()it restores the characters behind the Frame back on screen. It will also free the memory pointed by _covered;
virtual ~CFrame();
It will make sure allocated memories are freed.
bool fullscreen()const;
void visible(bool val);
bool visible()const;
void frame(CFrame* theContainer);
CFrame* frame();
void row(int val);
int row()const;
void col(int val);
int col()const;
void height(int val);
int height()const;
void width(int val);
int width()const;
These functions set and get the attributes of the CFrame.
CFrame.cpp & Test1Frame.cpp Bug Fix for R0.3.5
Please visit my blog for the description and solution of the bug during the CFrame
CField
The code for this class is provided. You must understand and use it to develop your core classes.
CField is an abstract base class that encapsulates the commonalities of all Input Outputs Console Fields which are placeable on a CDialog. All Fields could be Framed, therefore a CField is int
#include "cframe.h"
class CDialog;
class CField : public CFrame{
protected:
void* _data;
public:
CField(int Row = 0, int Col = 0,
int Width = 0, int Height =0,
void* Data = (void*) 0,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
~CField();
virtual int edit() = 0;
virtual bool editable() const = 0;
virtual void set(const void* data) = 0;
virtual void* data();
void container(CDialog* theContainer);
CDialog* container();
};
Attributes
void* _data;
Will hold the address of any type of data a CField can hold.
Constructors and Methods
CField(int Row = 0, int Col = 0,
int Width = 0, int Height =0,
void* Data = (void*) 0,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
Passes the corresponding attributes to it's parents constructor and then sets the _data attribute to the incoming Data argument.
~CField();
Empty Destructor
virtual int edit() = 0;
virtual bool editable() const = 0;
virtual void set(const void* data) = 0;
Enforce the children to implement;
- an edit() method
- an editable() method that returns true if the class is to edit data and false if the class is to only display data.
- a set() method to set the _data attribute to the data the class is to work with.
virtual void* data();
Returns _data.
void container(CDialog* theContainer);
CDialog* container();
Sets and Gets the _frame attribute of CFrame by calling CFrame::frame() method. Make sure to cast The CDialog to CFrame when setting and cast CFrame to CDialog when getting
CLabel
A readonly Field that encapsulates bio_display() function. (i.e it is responsible to display a short character string on the display) CLable although, by inheritance is Frame, but it is never bordered.
#include "cfield.h"
class CLabel : public CField{
int _length;
public:
CLabel(const char *Str, int Row, int Col,
int Len = 0);
CLabel(int Row, int Col, int Len);
CLabel(const CLabel& L);
~CLabel();
void draw(int fn=C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* str);
};
Attributes
int _length;
Holds the Length of the label, this will be stored to be passed to bio_display function.
Constructors / Destructor
CLabel(const char *Str, int Row, int Col,
int Len = 0);
passes the Row and Col to the CField constructor and then; if len is zero, it will allocate enough memory to store the string pointed by Str and then copies the Str into it. if len > 0, then it will allocate enough memory to store len chars in a string. In any way, the allocated memory is pointed by _data
CLabel(int Row, int Col, int Len);
Works exactly like the previous constructor, but len in this case can not be zero. (no validation required) and the string pointed by _data will be set to an empty string.
CLabel(const CLabel& L);
Copy Constructor
~CLabel();
makes sure that memory pointed by _data is deallocated before the object is destroyed.
Methods
void draw(int fn=C_NO_FRAME) ;
makes a direct call to bio_display, passing _data for the string to be printed and absRow() and absCol() for row and col and _length for len. this function ignores the argument fn.
int edit();
calls draw, returning 0.
bool editable()const;
always return false.
void set(const void* str);
if _length is greater than zero, it will copy the string pointed by str into the string pointed by _data upto _length characters. if _length is zero, it will delete the memory pointed by _data and reallocates enough memory for str and copies the string pointed by str into the newly allocated memory pointed by _data.
CDialog
Organizes CField objects on the screen, displays them and then lets the user edit them one by one.
#include "cgh.h"
#include "cframe.h"
class CField;
class CDialog: public CFrame{
private:
int _fnum;
/* Suggestion: */
int _curidx;
CField* _fld[C_MAX_NO_FIELDS];
bool _dyn[C_MAX_NO_FIELDS];
/* you can do this part any way you like only if it covers the minimum requirements of the assignment*/
/* talk to your professor if you want to do it differently */
bool _editable;
public:
CDialog(CFrame *Container = (CFrame*)0,
int Row = -1, int Col = -1,
int Width = -1, int Height = -1,
bool Borderd = false,
const char* Border=C_BORDER_CHARS);
virtual ~CDialog();
void draw(int fn = C_FULL_FRAME);
int edit(int fn = C_FULL_FRAME);
int add(CField* field, bool dynamic = true);
int add(CField& field, bool dynamic = false);
CDialog& operator<<(CField* field);
CDialog& operator<<(CField& field);
bool editable();
int fieldNum()const;
int curIndex()const;
CField& operator[](unsigned int index);
CField& curField();
};
Attributes
Mandatory
int _fnum;
Holds the number of Fields added to the Dialog
bool _editable;
will be set to true if any of the Fields added are editable.
Optional
This is optional because it depends on how you are going to implement the collection of CFields:
int _curidx;
Holds the index of the Field that is currently being edited.
CField* _fld[C_MAX_NO_FIELDS];
Array of CField pointers to hold the address of the CField objects added to the screen.
bool _dyn[C_MAX_NO_FIELDS];
Holds series of boolean to the exact number of fields, and each boolean here will hold false if the corresponding field pointed by _fld is allocated dynamically or not. This array will later on be used by destructor to decide which object is dynamic and to be deleted.
Constructors/Destructors
CDialog(CFrame *Container = (CFrame*)0,
int Row = -1, int Col = -1,
int Width = -1, int Height = -1,
bool Borderd = false,
const char* Border=C_BORDER_CHARS);
The constructor, passes all the incoming arguments to the corresponding arguments of the apparent constructor CFrame.
Then it will set called a attributes to their default values and then sets all the field pointers (_fld) to NULL.
It also sets all the dynamic (_dyn) flags to false.
virtual ~CDialog();
The destructor, will loop through all the field pointers and if the corresponding dynamic flag is true then it will delete the field pointed to by the field pointer.
Methods
void draw(int fn = C_FULL_FRAME);
If fn is C_FULL_FRAME, it will call its parent draw. Then It will draw all the Fields in the Dialog.
If fn is not C_FULL_FRAME, then it will just draw all the Fields in the Dialog.
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.)
int edit(int fn = C_FULL_FRAME);
If CDialog 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.
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.
If fn is greater than 0 then editing begins from the first editable key on or after Field number fn.
Note that fn is the sequence number of field and not the index. (First field number is one)
Start editing from field number fn;
Call the edit of each field and depending on the value returned, do the following:
- 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.
int add(CField* field, bool dynamic = true);
Adds the CField' pointed by field to the Fields of the Dialog; by appending the value of the field pointer after the last added field in the _fld array , setting the corresponding _dyn element to the value of dynamic argument and then increasing _fnum by one and returning it.
important note:
Make sure that add() sets the container of the added CField to this CDialog object, using the container() method of CField
int add(CField& field, bool dynamic = false);
Makes a direct call to the first add method.
CDialog& operator<<(CField* field);
Makes a direct call to the first add method, ignoring the second argument and then returns the owner (current CDialog).
CDialog& operator<<(CField& field);
Makes a direct call to the second add method, ignoring the second argument and then returns the owner (current CDialog).
bool editable();
Returns _editable;
int fieldNum()const;
returns _fnum.
int curIndex()const;
returns _curidx;
CField& operator[](unsigned int index);
Returns the reference of the Field with incoming index. (Note that here, the first field index is 0)
CField& curField();
Returns the reference of the Field that was just being edited.
CLineEdit
ClineEdit encapsulates the bio_edit function of bio library.
#pragma once
#include "cfield.h"
class CLineEdit: public CField{
bool _dyn;
int _maxdatalen;
int* _insertmode;
int _curpos;
int _offset;
public:
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
~CLineEdit();
void draw(int Refresh = C_FULL_FRAME);
int edit();
bool editable()const;
void set(const void* Str);
};
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
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).
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.
(hint: use ? : operator to pass the proper Height value to FWField's constructor)
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
Works exactly like the previous constructor with one difference; since no external data is passed to be edited here, this constructor must 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.
~CLineEdit();
If _dyn is true, it will deallocate the character array pointed by Fields's _data
void draw(int Refresh = C_FULL_FRAME);
It will first call Frame's draw passing Refreshas an argument to it.
Then it will make a direct call to bio_display to show the data kept in Field's _data.
The values used for the arguments of bio_display are:
- str: address of string pointed by _data + the value of _offset
- row: absRow() (add one if border is visible)
- col: absCol() (add one if border is visible)
- len: width() (reduce by two is border is visible')
int edit();
Makes a direct call to, and returns bio_edit(). For the coordinates and width arguments follow the same rules as the draw function. For the rest of the arguments of bio_edit, use the attributes of CLineEdit.
bool editable()const;
Always return true;
void set(const void* Str);
Copies the characters pointed by Str into the memory pointed by Field's _data up to _maxdatalen characters.
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. When in edit mode, to indicate the editing mode, it will surround the text with squared brackets.
#pragma once
#include "cfield.h"
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);
};
Attributes
This class does not have any attributes of its own!
Constructor / Destructor
CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS);
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.
Pass all the arguments directly to Field's constructor.
For Field size (width and hight) do the following:
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.
virtual ~CButton();
Deallocates the allocated memory pointed by Field's _data.
Methods
void draw(int fn=C_FULL_FRAME);
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 "]"
hint:
- First calls Frame's draw(fn) (passing the fn argument to the parents draw)
- Use bio_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
- If not bordered
int edit();
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.
When user hits a key, if the key is ENTER_KEY or SPACE, return C_BUTTON_HIT (defined in cgh.h) otherwise return the entered key.
bool editable()const;
Always returns true;
void set(const void* str);
Reallocate memory for new text and then set it to content of str
hint:
- 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.
CCheck
#include "cfield.h"
#include "clabel.h"
class CCheck : public CField{
int _flag;
int _radio;
char _format[4];
CLabel _Label;
public:
CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false);
CCheck(const CCheck& C);
void draw(int fn = C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* flag);
// note that void *data() is removed!!!
bool checked()const;
void checked(bool val);
};
Attributes
int _flag;
int _radio;
char _format[4];
CLabel _Label;
- _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
CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false);
- 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.
- *see page 64 of Practical Programming Techniques Using C++
- Sets the frame of _Label to itself
- Sets _flag to Checked
- Sets _radio to IsRadio
- Copies Format to _format
- Sets _data to the address of _flag
CCheck(const CCheck& C);
- Passes incoming CCheck 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 CCheck reference ("C")
- Sets _data to the address of _flag
Methods
void draw(int fn = C_NO_FRAME) ;
- Uses bio_displayflag() to display _flag using _format at absRow() and absCol()
- Then draw()s the _Label
int edit();
- returns bio_flag()'s returned value.
- bio_flag is to edit the value of _flag using the same arguments used in draw() as radiobutton or checkbox depending to the value of _radio
bool editable()const;
- Always return true;
void set(const void* flag);
- Casts the incoming flag pointer to an (int*) and sets the content of _flag to where flag is pointing to.
bool checked()const;
void checked(bool val);
- These methods set and get _flag.
CMenuItem
#include "cfield.h"
class CMenuItem:public CField{
int _selected;
char _format[3];
char* _text;
public:
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
CMenuItem(const CMenuItem &CM);
virtual ~CMenuItem(void);
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();
};
Attributes
int _selected;
char _format[3];
char* _text;
- _selected holds the status of the menuitem (0: not selected, 1: selected) and is pointed by _data.
- _format hods the surrounding "selection indicator" characters used by bio_displaymenuitem.
- _text points to the allocated memory holding the text of the menuitem
Constructors / Destructor
CMenuItem(bool Selected,const char* Format, const char* Text, int Row, int Col, int Width);
- Sets _selected to Selected (0 for false and 1 for true)
- Copies Format into _format
- Allocated enough memory to hold Text and sets _text to address of newly allocated memory
- Copies the string pointed by Text into _text
- Sets _data to the address of _selected
- It passes the Row, the Col and the Width to the CField constructor
CMenuItem(const CMenuItem &CM);
- Passes the incoming CMenuItem ("CM") to CFiled's constructor
- Allocated enough memory to hold CM._text and sets _text to address of newly allocated memory
- Copies the string pointed by CM._text into _text
- Sets _selected to CM._selected
- Sets _data to the address of _selected
~CMenuItem(void);
- Deallocated the memory pointed by _text
Methods
void draw(int fn = C_NO_FRAME) ;
- Draws the object using bio_displayMenuItem function.
- Make sure absRow() and absCol() are used for Row and Col args of bio_displayMenuItem
int edit();
- Returns the returned value of bio_menuItem() using the same arguemtns used in draw()
bool editable()const;
- Always returns true
void set(const void* Selected);
- Sets _selected to content pointed by Selected
bool selected()const;
void selected(bool val);
- These methods set and get _selected.
const char* Text()const;
- Returns _text
Complex Core User Interface classes
CValEdit
#include "clineedit.h"
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, int* 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, int* 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();
};
Attributes
void (*_help)(MessageStatus, CDialog&);
bool (*_validate)(const char*, CDialog&);
- _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
CValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* 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, int* Insertmode,
bool (*Validate)(const char* , CDialog&) = NO_VALDFUNC,
void (*Help)(MessageStatus, CDialog&) = NO_HELPFUNC,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
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
int edit();
If the container() is NULL then this function works exactly like LineEdit::edit().
If the container() is not NULL:
- If _help function exist it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments.
- Calls LineEdit's edit()
- If validation function exists and the terminating key of LineEdit'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 LineEdit'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.
MessageStatus is enumerated in cgh.h
CText
#include "cfield.h"
class CText:public CField{
// WHATEVER _lines; // a collection of lines (will be set later)
bool _readOnly;
int _curpos;
int _fieldlen;
int _maxdatalen;
int* _insertmode;
int _offset;
int _lcurpos;
int _loffset;
// bool _dynamic;
public:
CText(int Row, int Col, int Width, int Height, bool Readonly,
int* Insertmode, const char* Border=C_BORDER_CHARS);
CText(const char* Str, int Row, int Col, int Width, int Height, bool Readonly,
int* Insertmode, const char* Border=C_BORDER_CHARS);
void draw(int fn = C_FULL_FRAME);
void set(const void *Str);
void *data();
int edit();
bool editable()const;
bool readOnly();
void readOnly(bool val);
~CText();
};
CCheckList
#include "cfield.h"
#include "ccheck.h"
class CCheckList;
class CCheckList : public CField{
??????
bool _radio;
char _format[4];
int _cnt;
unsigned int _flags;
public:
CCheckList(const char* Format, int Row, int Col, int Width,bool radio, bool Bordered = true,const char* Border=C_BORDER_CHARS);
CCheckList& add(const char* Text, bool selected = false);
void draw(int fn = C_FULL_FRAME);
int edit();
void* data();
void set(const void* data);
bool& operator[](unsigned int index);
bool editable()const;
bool radio();
void radio(bool val);
~CCheckList(void);
};
CMenu
#include "cfield.h"
#include "cmenuitem.h"
class Cmenu;
class CMenu : public CField{
?????
public:
CMenu(const char* Format, int Row, int Col, int Width, bool Bordered = true,const char* Border=C_BORDER_CHARS);
CMenu& add(const char* Text, bool selected = false);
void draw(int fn = C_FULL_FRAME);
int edit();
void* data();
void set(const void* data);
int selectedIndex();
int selectedIndex(unsigned int index);
const char* selectedText();
void selectedText(char *text);
bool editable()const;
~CMenu(void);
};
Make Files and Testers
Copy these makefiles under "makefile" name in root of your project in Linux or Mac.
Replace the "<tab>" with tab character
then issue the make command:
$make <enter>
this will compile your code and create an executable called prjexe, if there is no error
Also, copies of all these make files and tester programs are commited to: svn://zenit.senecac.on.ca/oop344/trunk/Testers
The executable of testers are compiled and copied in my account on matrix:
login to matix and run:
$~fardad.soleimanloo/t[X]
where [X] is number of the test. (i.e. run $fardad.soleimanloo/t3 for test3
Test2 Make file
t2: bio.o cframe.o cfield.o cdialog.o clabel.o Test2DialogAndLabel.o <tab>c++ bio.o cframe.o cfield.o cdialog.o clabel.o \ Test2DialogAndLabel.o -lncurses -oprjexe bio.o: bio.c bio.h <tab>cc -c bio.c cframe.o: cframe.cpp cframe.h cgh.h <tab>c++ -c cframe.cpp cfield.o: cfield.cpp cfield.h cgh.h cframe.h <tab>c++ -c cfield.cpp cdialog.o: cdialog.cpp cdialog.h cfield.h cgh.h cframe.h <tab>c++ -c cdialog.cpp clabel.o: clabel.cpp clabel.h cfield.h cframe.h cgh.h <tab>c++ -c clabel.cpp Test2DialogAndLabel.o: Test2DialogAndLabel.cpp clabel.h cdialog.h cframe.h cgh.h cfield.h <tab>c++ -c Test2DialogAndLabel.cpp
Test 3 make file
prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o <tab>c++ bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o \ -lncurses -oprjexe bio.o: bio.c bio.h <tab>cc -c bio.c cframe.o: cframe.cpp cframe.h cgh.h <tab>c++ -c cframe.cpp cfield.o: cfield.cpp cfield.h cgh.h cframe.h <tab>c++ -c cfield.cpp cdialog.o: cdialog.cpp cdialog.h cfield.h cgh.h cframe.h <tab>c++ -c cdialog.cpp clabel.o: clabel.cpp clabel.h cfield.h cframe.h cgh.h <tab>c++ -c clabel.cpp clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h cgh.h <tab>c++ -c clineedit.cpp Test3DialogAndLineEdit.o: Test3DialogAndLineEdit.cpp clineedit.h clabel.h cdialog.h cfield.h cframe.h cgh.h <tab>c++ -c Test3DialogAndLineEdit.cpp
Full Project Makefile
Not Tested!
prj: bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o c++ bio.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cmenuitem.o cbutton.o ccheck.o cchecklist.o cmenu.o cveditline.o ctext.o strarr.o prj.o \ -lncurses -oprjexe bio.o: bio.c bio.h cc -c bio.c cframe.o: cframe.cpp cframe.h cgh.h c++ -c cframe.cpp cfield.o: cfield.cpp cfield.h cgh.h cframe.h c++ -c cfield.cpp cdialog.o: cdialog.cpp cdialog.h cfield.h cgh.h cframe.h c++ -c cdialog.cpp clabel.o: clabel.cpp clabel.h cfield.h cframe.h cgh.h c++ -c clabel.cpp clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h cgh.h c++ -c clineedit.cpp cmenuitem.o: cmenuitem.cpp cmenuitem.h cfield.h cframe.h cgh.h C++ -c cmenuitem.cpp cbutton.o: cbutton.cpp cbutton.h cfield.h cframe.h cgh.h c++ -c cbutton.cpp ccheck.o: ccheck.cpp ccheck.h clabel.h cfield.h cframe.h cgh.h c++ -c ccheck.cpp cchecklist.o: cchecklist.cpp cchecklist.h ccheck.h clabel.h cfield.h cframe.h cgh.h c++ -c cchecklist.cpp cveditline.o: cveditline.cpp cveditline.h clineedit.h cfield.h cframe.h cgh.h c++ -c cveditline.cpp strarr.o: strarr.cpp strarr.h c++ -c strarr.cpp ctext.o: ctext.cpp ctext.h clineedit.h cfield.h cframe.h cgh.h strarr.h c++ -c ctext.cpp cmenu.o: cmenu.cpp cmenu.h cmenuitem.h cfield.h cframe.h cgh.h c++ -c cmenu.cpp prj.o: prj.cpp cframe.h cfield.h cdialog.h clabel.h clineedit.h cmenuitem.h cbutton.h ccheck.h cchecklist.h cmenu.h cveditline.h ctext.h c++ -c prj.cpp