21
edits
Changes
Created page with 'Under Construction! ==CField== CField is an abstract base class that encapsulates the commonalities of all Input Outputs Console Fields which are placeable on a CDialog. All Fie…'
Under Construction!
==CField==
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 inherited from CFrame.
<big><syntaxhighlight lang="cpp">
#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()const; //<== check this, not sure
void container(CDialog* theContainer);
CDialog* container();
};
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
void* _data;
</syntaxhighlight></big>
Will hold the address of any type of data a CField can hold.
===Constructors and Methods===
<big><syntaxhighlight lang="cpp">
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);
</syntaxhighlight></big>
Passes the corresponding attributes to it's parents (CFrame) constructor and then sets the _data attribute to the incoming Data argument. Also using '''container(CDialog* theContainer)''' it set the container to NULL.
<big><syntaxhighlight lang="cpp">
~CField();
</syntaxhighlight></big>
Empty Destructor
<big><syntaxhighlight lang="cpp">
virtual int edit() = 0;
virtual bool editable() const = 0;
virtual void set(const void* data) = 0;
</syntaxhighlight></big>
Pure virtual methods to 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.
<big><syntaxhighlight lang="cpp">
virtual void* data() const; <--- Check this not sure....
</syntaxhighlight></big>
Returns _data.
<big><syntaxhighlight lang="cpp">
void container(CDialog* theContainer);
</syntaxhighlight></big>
Casts '''"theContainer"''' to a CFrame pointer and passes it to CFrame::frame(CFrame*) method; (to set the frame of CDialog)
<big><syntaxhighlight lang="cpp">
CDialog* container();
</syntaxhighlight></big>
Casts the return value of CFrame::frame() to a CDialog pointer and returns it.
===CField Student Resources===
====CField Help/Questions Blogs====
====CField Blog Posts====
==CLabel==
A readonly Field that encapsulates console.display() function. (i.e it is responsible to display a short character string on the display) CLabel although, by inheritance is Frame, but it is never '''bordered'''.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
class CLabel : public CField{
// for length of the field:
// Use void CFrame::width(int) to store length, and int CFrame::width() to retrieve the length
public:
CLabel(const CLabel& L);
CLabel(const char *Str, int Row, int Col,
int Len = 0);
CLabel(int Row, int Col, int Len);
~CLabel();
void draw(int fn=C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* str);
};
</syntaxhighlight></big>
===Attributes===
No attributes, (use Cframe attributes)
===Constructors / Destructor ===
<big><syntaxhighlight lang="cpp">
CLabel(const char *Str, int Row, int Col,
int Len = 0);
</syntaxhighlight></big>
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, copying only len characters of str.
In any way, the allocated memory is pointed by '''_data'''. Also it will set the width to the length of the memory allocated.
<big><syntaxhighlight lang="cpp">
CLabel(int Row, int Col, int Len);
</syntaxhighlight></big>
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.
<big><syntaxhighlight lang="cpp">
CLabel(const CLabel& L);
</syntaxhighlight></big>
Copies a CLabel safely to guaranty there is no memory leak.
<big><syntaxhighlight lang="cpp">
~CLabel();
</syntaxhighlight></big>
makes sure that memory pointed by _data is deallocated before the object is destroyed.
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn=C_NO_FRAME) ;
</syntaxhighlight></big>
makes a direct call to console.strdsp(), passing '''_data''' for the string to be printed and absRow() and absCol() for row and col and width() for len.
this function ignores the argument fn.
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
calls draw, returning 0.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
always return false.
<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
if width() is greater than zero, it will copy the string pointed by str into the string pointed by _data upto width characters.
if width() is zero,<br /> 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.
===CLabel Student Resources===
====CLabel Help/Questions Blogs====
====CLabel Blog Posts====
==CDialog==
Organizes CField objects on the screen, displays them and then lets the user edit them one by one.
<big><syntaxhighlight lang="cpp">
#include "cuigh.h"
#include "cframe.h"
namespace cui{
class CField;
class CDialog: public CFrame{
private:
int _fnum;
int _curidx;
CField** _fld;
bool* _dyn;
bool _editable;
unsigned int _fldSize;
public:
CDialog(CFrame *Container = (CFrame*)0,
int Row = -1, int Col = -1,
int Width = -1, int Height = -1,
bool Bordered = 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();
};
}
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
int _fnum;
</syntaxhighlight></big>
Holds the number of Fields added to the Dialog
<big><syntaxhighlight lang="cpp">
bool _editable;
</syntaxhighlight></big>
will be set to true if any of the Fields added are editable.
This is optional because it depends on how you are going to implement the collection of CFields:
<big><syntaxhighlight lang="cpp">
int _curidx;
</syntaxhighlight></big>
Holds the index of the Field that is currently being edited.
<big><syntaxhighlight lang="cpp">
CField** _fld;
</syntaxhighlight></big>
Dynamic array of CField pointers to hold the address of the CField objects added to the screen. The initial size of the array allocation is defined in '''''cuigh.h''''' under C_INITIAL_NO_FIELDS.
<big><syntaxhighlight lang="cpp">
bool* _dyn;
</syntaxhighlight></big>
A dynamic bool array that holds series of booleans 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. The initial size of the array allocation is defined in '''''cuigh.h''''' under C_INITIAL_NO_FIELDS. <br />
This array will later on be used by destructor to decide which object is dynamic and to be deleted.
<big><syntaxhighlight lang="cpp">
unsigned int _fldSize;
</syntaxhighlight></big>
Holds the current length of '''''_fld''''' and '''''_dyn'''''. <br />When adding a field to dialog if '''_fnum''' reaches '''_fldSize''', then the size of '''_fld''' and '''_dyn''' is expanded by '''''C_DIALOG_EXPANSION_SIZE''''', defined in '''cuigh.h'''
===Constructors/Destructors===
<big><syntaxhighlight lang="cpp">
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);
</syntaxhighlight></big>
The constructor passes all the incoming arguments to the corresponding arguments of the apparent constructor '''CFrame'''.<br />
Then it will set all called 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.
<big><syntaxhighlight lang="cpp">
virtual ~CDialog();
</syntaxhighlight></big>
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===
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
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 Zero, 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.)
<big><syntaxhighlight lang="cpp">
int edit(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
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 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:<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 '''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.
<big><syntaxhighlight lang="cpp">
int add(CField* field, bool dynamic = true);
</syntaxhighlight></big>
First, this function will check the value of _fnum. If '''_fnum''' has reached '''_fldSize''', ('''_fld''' and '''_dyn''' arrays are full) it will expand '''_fld''' and '''_dyn''' by '''C_DIALOG_EXPANSION_SIZE''' (defined in '''cuigh.h''') to make room for more '''CField'''.<br />
Then, 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 the index of added Field in the CDialog object.<br />
'''important note:'''<br />
Make sure that add() sets the container of the added CField to this CDialog object, using the container() method of CField<br />
Also make sure, if size of _fld and _dyn are expanded, then _fldSize is also increased.
<big><syntaxhighlight lang="cpp">
int add(CField& field, bool dynamic = false);
</syntaxhighlight></big>
Makes a direct call to the first add method.
<big><syntaxhighlight lang="cpp">
CDialog& operator<<(CField* field);
</syntaxhighlight></big>
Makes a direct call to the first add method, ignoring the second argument and then returns the owner (current CDialog).
<big><syntaxhighlight lang="cpp">
CDialog& operator<<(CField& field);
</syntaxhighlight></big>
Makes a direct call to the second add method, ignoring the second argument and then returns the owner (current CDialog).
<big><syntaxhighlight lang="cpp">
bool editable();
</syntaxhighlight></big>
Returns '''_editable''';
<big><syntaxhighlight lang="cpp">
int fieldNum()const;
</syntaxhighlight></big>
returns '''_fnum'''.
<big><syntaxhighlight lang="cpp">
int curIndex()const;
</syntaxhighlight></big>
returns '''_curidx''';
<big><syntaxhighlight lang="cpp">
CField& operator[](unsigned int index);
</syntaxhighlight></big>
Returns the reference of the Field with incoming index. (Note that here, the first field index is '''0''')
<big><syntaxhighlight lang="cpp">
CField& curField();
</syntaxhighlight></big>
Returns the reference of the Field that was just being edited.
===CDialog Student Resources===
====CDialog Help/Questions Blogs====
====CDialog Blog Posts====
==CLineEdit==
'''ClineEdit''' encapsulates the console.edit() function of Console class.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
namespace cui{
class CLineEdit: public CField{
bool _dyn;
int _maxdatalen;
bool* _insertmode;
int _curpos;
int _offset;
public:
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, bool* 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);
};
}
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
bool _dyn;
</syntaxhighlight></big>
_dyn is set to true if the object dynamically allocated memory and is responsible to free it at destruction time.
<big><syntaxhighlight lang="cpp">
int _maxdatalen;
</syntaxhighlight></big>
no comment!
<big><syntaxhighlight lang="cpp">
bool* _insertmode;
</syntaxhighlight></big>
points to the location of input method (insert or overstrike)
<big><syntaxhighlight lang="cpp">
int _curpos;
</syntaxhighlight></big>
current position of cursor
<big><syntaxhighlight lang="cpp">
int _offset;
</syntaxhighlight></big>
current offset
===Constructors / Destructor===
<big><syntaxhighlight lang="cpp">
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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 (CField) 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 CField's constructor)
<big><syntaxhighlight lang="cpp">
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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.
<big><syntaxhighlight lang="cpp">
~CLineEdit();
</syntaxhighlight></big>
If '''_dyn''' is true, it will deallocate the character array pointed by Fields's '''_data'''
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int Refresh = C_FULL_FRAME);
</syntaxhighlight></big>
It will first call Frame's draw passing '''Refresh''' as an argument to it.<br />
Then it will make a direct call to console.display() to show the data kept in Field's '''_data'''.<br />
The values used for the arguments of console.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 if border is visible''')
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
Makes a direct call to, and returns '''console.stredit()'''.
For the coordinates and width arguments follow the same rules as the draw function.
For the rest of the arguments of console.edit(), use the attributes of '''CLineEdit'''.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Always return true;
<big><syntaxhighlight lang="cpp">
void set(const void* Str);
</syntaxhighlight></big>
Copies the characters pointed by '''Str''' into the memory pointed by Field's '''_data''' up to '''_maxdatalen''' characters.
===CLineEdit Student Resources===
====CLineEdit Help/Questions Blogs====
* [http://ksidhucode.blogspot.ca/2013/07/should-they-be-friends.html Kevin S - Need help with draw()]
====CLineEdit Blog Posts====
==CField==
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 inherited from CFrame.
<big><syntaxhighlight lang="cpp">
#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()const; //<== check this, not sure
void container(CDialog* theContainer);
CDialog* container();
};
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
void* _data;
</syntaxhighlight></big>
Will hold the address of any type of data a CField can hold.
===Constructors and Methods===
<big><syntaxhighlight lang="cpp">
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);
</syntaxhighlight></big>
Passes the corresponding attributes to it's parents (CFrame) constructor and then sets the _data attribute to the incoming Data argument. Also using '''container(CDialog* theContainer)''' it set the container to NULL.
<big><syntaxhighlight lang="cpp">
~CField();
</syntaxhighlight></big>
Empty Destructor
<big><syntaxhighlight lang="cpp">
virtual int edit() = 0;
virtual bool editable() const = 0;
virtual void set(const void* data) = 0;
</syntaxhighlight></big>
Pure virtual methods to 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.
<big><syntaxhighlight lang="cpp">
virtual void* data() const; <--- Check this not sure....
</syntaxhighlight></big>
Returns _data.
<big><syntaxhighlight lang="cpp">
void container(CDialog* theContainer);
</syntaxhighlight></big>
Casts '''"theContainer"''' to a CFrame pointer and passes it to CFrame::frame(CFrame*) method; (to set the frame of CDialog)
<big><syntaxhighlight lang="cpp">
CDialog* container();
</syntaxhighlight></big>
Casts the return value of CFrame::frame() to a CDialog pointer and returns it.
===CField Student Resources===
====CField Help/Questions Blogs====
====CField Blog Posts====
==CLabel==
A readonly Field that encapsulates console.display() function. (i.e it is responsible to display a short character string on the display) CLabel although, by inheritance is Frame, but it is never '''bordered'''.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
class CLabel : public CField{
// for length of the field:
// Use void CFrame::width(int) to store length, and int CFrame::width() to retrieve the length
public:
CLabel(const CLabel& L);
CLabel(const char *Str, int Row, int Col,
int Len = 0);
CLabel(int Row, int Col, int Len);
~CLabel();
void draw(int fn=C_NO_FRAME) ;
int edit();
bool editable()const;
void set(const void* str);
};
</syntaxhighlight></big>
===Attributes===
No attributes, (use Cframe attributes)
===Constructors / Destructor ===
<big><syntaxhighlight lang="cpp">
CLabel(const char *Str, int Row, int Col,
int Len = 0);
</syntaxhighlight></big>
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, copying only len characters of str.
In any way, the allocated memory is pointed by '''_data'''. Also it will set the width to the length of the memory allocated.
<big><syntaxhighlight lang="cpp">
CLabel(int Row, int Col, int Len);
</syntaxhighlight></big>
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.
<big><syntaxhighlight lang="cpp">
CLabel(const CLabel& L);
</syntaxhighlight></big>
Copies a CLabel safely to guaranty there is no memory leak.
<big><syntaxhighlight lang="cpp">
~CLabel();
</syntaxhighlight></big>
makes sure that memory pointed by _data is deallocated before the object is destroyed.
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn=C_NO_FRAME) ;
</syntaxhighlight></big>
makes a direct call to console.strdsp(), passing '''_data''' for the string to be printed and absRow() and absCol() for row and col and width() for len.
this function ignores the argument fn.
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
calls draw, returning 0.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
always return false.
<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
if width() is greater than zero, it will copy the string pointed by str into the string pointed by _data upto width characters.
if width() is zero,<br /> 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.
===CLabel Student Resources===
====CLabel Help/Questions Blogs====
====CLabel Blog Posts====
==CDialog==
Organizes CField objects on the screen, displays them and then lets the user edit them one by one.
<big><syntaxhighlight lang="cpp">
#include "cuigh.h"
#include "cframe.h"
namespace cui{
class CField;
class CDialog: public CFrame{
private:
int _fnum;
int _curidx;
CField** _fld;
bool* _dyn;
bool _editable;
unsigned int _fldSize;
public:
CDialog(CFrame *Container = (CFrame*)0,
int Row = -1, int Col = -1,
int Width = -1, int Height = -1,
bool Bordered = 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();
};
}
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
int _fnum;
</syntaxhighlight></big>
Holds the number of Fields added to the Dialog
<big><syntaxhighlight lang="cpp">
bool _editable;
</syntaxhighlight></big>
will be set to true if any of the Fields added are editable.
This is optional because it depends on how you are going to implement the collection of CFields:
<big><syntaxhighlight lang="cpp">
int _curidx;
</syntaxhighlight></big>
Holds the index of the Field that is currently being edited.
<big><syntaxhighlight lang="cpp">
CField** _fld;
</syntaxhighlight></big>
Dynamic array of CField pointers to hold the address of the CField objects added to the screen. The initial size of the array allocation is defined in '''''cuigh.h''''' under C_INITIAL_NO_FIELDS.
<big><syntaxhighlight lang="cpp">
bool* _dyn;
</syntaxhighlight></big>
A dynamic bool array that holds series of booleans 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. The initial size of the array allocation is defined in '''''cuigh.h''''' under C_INITIAL_NO_FIELDS. <br />
This array will later on be used by destructor to decide which object is dynamic and to be deleted.
<big><syntaxhighlight lang="cpp">
unsigned int _fldSize;
</syntaxhighlight></big>
Holds the current length of '''''_fld''''' and '''''_dyn'''''. <br />When adding a field to dialog if '''_fnum''' reaches '''_fldSize''', then the size of '''_fld''' and '''_dyn''' is expanded by '''''C_DIALOG_EXPANSION_SIZE''''', defined in '''cuigh.h'''
===Constructors/Destructors===
<big><syntaxhighlight lang="cpp">
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);
</syntaxhighlight></big>
The constructor passes all the incoming arguments to the corresponding arguments of the apparent constructor '''CFrame'''.<br />
Then it will set all called 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.
<big><syntaxhighlight lang="cpp">
virtual ~CDialog();
</syntaxhighlight></big>
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===
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
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 Zero, 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.)
<big><syntaxhighlight lang="cpp">
int edit(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
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 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:<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 '''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.
<big><syntaxhighlight lang="cpp">
int add(CField* field, bool dynamic = true);
</syntaxhighlight></big>
First, this function will check the value of _fnum. If '''_fnum''' has reached '''_fldSize''', ('''_fld''' and '''_dyn''' arrays are full) it will expand '''_fld''' and '''_dyn''' by '''C_DIALOG_EXPANSION_SIZE''' (defined in '''cuigh.h''') to make room for more '''CField'''.<br />
Then, 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 the index of added Field in the CDialog object.<br />
'''important note:'''<br />
Make sure that add() sets the container of the added CField to this CDialog object, using the container() method of CField<br />
Also make sure, if size of _fld and _dyn are expanded, then _fldSize is also increased.
<big><syntaxhighlight lang="cpp">
int add(CField& field, bool dynamic = false);
</syntaxhighlight></big>
Makes a direct call to the first add method.
<big><syntaxhighlight lang="cpp">
CDialog& operator<<(CField* field);
</syntaxhighlight></big>
Makes a direct call to the first add method, ignoring the second argument and then returns the owner (current CDialog).
<big><syntaxhighlight lang="cpp">
CDialog& operator<<(CField& field);
</syntaxhighlight></big>
Makes a direct call to the second add method, ignoring the second argument and then returns the owner (current CDialog).
<big><syntaxhighlight lang="cpp">
bool editable();
</syntaxhighlight></big>
Returns '''_editable''';
<big><syntaxhighlight lang="cpp">
int fieldNum()const;
</syntaxhighlight></big>
returns '''_fnum'''.
<big><syntaxhighlight lang="cpp">
int curIndex()const;
</syntaxhighlight></big>
returns '''_curidx''';
<big><syntaxhighlight lang="cpp">
CField& operator[](unsigned int index);
</syntaxhighlight></big>
Returns the reference of the Field with incoming index. (Note that here, the first field index is '''0''')
<big><syntaxhighlight lang="cpp">
CField& curField();
</syntaxhighlight></big>
Returns the reference of the Field that was just being edited.
===CDialog Student Resources===
====CDialog Help/Questions Blogs====
====CDialog Blog Posts====
==CLineEdit==
'''ClineEdit''' encapsulates the console.edit() function of Console class.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
namespace cui{
class CLineEdit: public CField{
bool _dyn;
int _maxdatalen;
bool* _insertmode;
int _curpos;
int _offset;
public:
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, bool* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, bool* 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);
};
}
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
bool _dyn;
</syntaxhighlight></big>
_dyn is set to true if the object dynamically allocated memory and is responsible to free it at destruction time.
<big><syntaxhighlight lang="cpp">
int _maxdatalen;
</syntaxhighlight></big>
no comment!
<big><syntaxhighlight lang="cpp">
bool* _insertmode;
</syntaxhighlight></big>
points to the location of input method (insert or overstrike)
<big><syntaxhighlight lang="cpp">
int _curpos;
</syntaxhighlight></big>
current position of cursor
<big><syntaxhighlight lang="cpp">
int _offset;
</syntaxhighlight></big>
current offset
===Constructors / Destructor===
<big><syntaxhighlight lang="cpp">
CLineEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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 (CField) 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 CField's constructor)
<big><syntaxhighlight lang="cpp">
CLineEdit(int Row, int Col, int Width,
int Maxdatalen, int* Insertmode,
bool Bordered = false,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
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.
<big><syntaxhighlight lang="cpp">
~CLineEdit();
</syntaxhighlight></big>
If '''_dyn''' is true, it will deallocate the character array pointed by Fields's '''_data'''
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int Refresh = C_FULL_FRAME);
</syntaxhighlight></big>
It will first call Frame's draw passing '''Refresh''' as an argument to it.<br />
Then it will make a direct call to console.display() to show the data kept in Field's '''_data'''.<br />
The values used for the arguments of console.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 if border is visible''')
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
Makes a direct call to, and returns '''console.stredit()'''.
For the coordinates and width arguments follow the same rules as the draw function.
For the rest of the arguments of console.edit(), use the attributes of '''CLineEdit'''.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Always return true;
<big><syntaxhighlight lang="cpp">
void set(const void* Str);
</syntaxhighlight></big>
Copies the characters pointed by '''Str''' into the memory pointed by Field's '''_data''' up to '''_maxdatalen''' characters.
===CLineEdit Student Resources===
====CLineEdit Help/Questions Blogs====
* [http://ksidhucode.blogspot.ca/2013/07/should-they-be-friends.html Kevin S - Need help with draw()]
====CLineEdit Blog Posts====