Changes

Jump to: navigation, search

Console UI Core Classes - OOP344 20112

17,134 bytes added, 17:27, 16 August 2011
CLineEdit
:''Instead of replacing the whole logic, you could modify your functions with my additions, but since you have only two platforms covered in your logic, It may be easier to just replace your platform dependent logic with mine.''
==Adding CFrame and CField classes to your project (Release 0.2)==
* Duedate: Sunday Jul 31thWednesday Aug 3rd, 23:59;
# each team member:
#:# Branch the trunk into your branches (under whatever name you see fit)
<big><syntaxhighlight lang="cpp">
#pragma once
#include "cghiolgh.h"
class CFrame{
void capture();
</syntaxhighlight></big>
:if _covered pointer is not pointing to any allocated memory, it will call the bio_capture iol_capture function to capture the area that is going to be covered by this frame and keeps its address in _covered.
====Protected Methods====
virtual void hide();
</syntaxhighlight></big>
using bio_restoreiol_restore()it restores the characters behind the Frame back on screen. It will also free the memory pointed by _covered;
<big><syntaxhighlight lang="cpp">
These functions set and get the attributes of the CFrame.
 
==CField==
The code for this class is provided. You must understand and use it to develop your core classes.
==CLabel==
A readonly Field that encapsulates bio_displayiol_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'''.
<big><syntaxhighlight lang="cpp">
#include "cfield.h"
int _length;
</syntaxhighlight></big>
Holds the Length of the label, this will be stored to be passed to bio_display iol_display function.
===Constructors / Destructor ===
void draw(int fn=C_NO_FRAME) ;
</syntaxhighlight></big>
makes a direct call to bio_displayiol_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.
<big><syntaxhighlight lang="cpp">
</syntaxhighlight></big>
Returns the reference of the Field that was just being edited.
==CLineEdit==
'''ClineEdit''' encapsulates the iol_edit function of iol library.
<big><syntaxhighlight lang="cpp">
#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);
};
</syntaxhighlight></big>
 
 
 
<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 (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)
 
<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'''
 
<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 iol_display to show the data kept in Field's '''_data'''.<br />
The values used for the arguments of iol_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''')
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
Makes a direct call to, and returns '''iol_edit()'''.
For the coordinates and width arguments follow the same rules as the draw function.
For the rest of the arguments of iol_edit, use the attributes of '''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.
 
==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.
<big><syntaxhighlight lang="cpp">
#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);
};
 
</syntaxhighlight></big>
 
===Attributes===
This class does not have any attributes of its own!
===Constructor / Destructor===
<big><syntaxhighlight lang="cpp">
CButton(const char *Str, int Row, int Col,
bool Bordered = true,
const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
When creating a Button, allocate enough memory to hold the contents of the '''Str''' and set Field's _data to point to it. Then copy the content of '''Str''' into the newly allocated memory.<br />
Pass all the arguments directly to Field's constructor.<br />
For Field size (width and hight) do the following:<br />
For width: Set width to the length of '''Str''' + 2 (adding 2 for surrounding brackets) or if the Button is bordered set width to the length of '''Str''' + 4 (adding 2 for surrounding brackets and 2 for the borders).
For height: Set the height to 1 or if the Button is bordered, set the height to 3.
<big><syntaxhighlight lang="cpp">
virtual ~CButton();
</syntaxhighlight></big>
Deallocates the allocated memory pointed by Field's '''_data'''.
 
===Methods===
<big><syntaxhighlight lang="cpp">
void draw(int fn=C_FULL_FRAME);
</syntaxhighlight></big>
Draws the Button with border around it if it is Bordered. Note that there should be a space before and after of the text that will be used to surround the text with "[" and "]"<br />
hint:<br />
:*First calls Frame's draw(fn) (passing the fn argument to the parents draw)
 
:Use iol_display to display the Button's text (pointed by Field's _data)
:*If not bordered
:*:display the text at absRow() and absCol()
:*If bordered
:*:display the text at absRow()+1 and absCol()+2
 
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
First draw() the Button, then surround it by squared brackets, place the cursor under the first character of Button's text and wait for user entry.<br />
When user hits a key, if the key is ENTER_KEY or SPACE, return C_BUTTON_HIT (defined in iolgh.h) otherwise return the entered key.<br />
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
Always returns true;
<big><syntaxhighlight lang="cpp">
void set(const void* str);
</syntaxhighlight></big>
Reallocate memory for new text and then set it to content of '''str'''<br />
hint:<br />
:''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.''
 
==CCheck==
<big><syntaxhighlight lang="cpp">
#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);
};
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
int _flag;
int _radio;
char _format[4];
CLabel _Label;
</syntaxhighlight></big>
*'''_flag''' holds the status of the Checkbox (0: unchecked or 1: checked ) and is pointed by _data pointer .
*'''_radio''' dictates the behavior of the Checkbox as a radio-button, or a check-mark.
*'''_format''' holds the characters, the Checkbox is drawn with (i.e. "[X]", "(O)", "<*>", etc...).
*'''_Label''' holds the Label attached to the this Checkbox
===Constructor / Destructor===
<big><syntaxhighlight lang="cpp">
CCheck(bool Checked,const char* Format, const char* Text, int Row, int Col, int Width, bool IsRadio = false);
</syntaxhighlight></big>
*Passes the Row, Col, Width and "1" to row, col, width and height arguments of CField and directly initializes* _Label with Text, 0, 4, and (Width-4) for Str, Row, Col and Len, arguments of CLabel's Constructor.<br />
*: *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
<big><syntaxhighlight lang="cpp">
CCheck(const CCheck& C);
</syntaxhighlight></big>
*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===
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_NO_FRAME) ;
</syntaxhighlight></big>
*Uses iol_displayflag() to display _flag using _format at absRow() and absCol()
*Then draw()s the _Label
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
*returns iol_flag()'s returned value.
*:iol_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
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
*Always return true;
<big><syntaxhighlight lang="cpp">
void set(const void* flag);
</syntaxhighlight></big>
*Casts the incoming flag pointer to an (int*) and sets the content of '''_flag''' to where '''flag''' is pointing to.
<big><syntaxhighlight lang="cpp">
bool checked()const;
void checked(bool val);
</syntaxhighlight></big>
*These methods set and get _flag.
 
==CValEdit==
<big><syntaxhighlight lang="cpp">
#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();
};
</syntaxhighlight></big>
===Attributes===
<big><syntaxhighlight lang="cpp">
void (*_help)(MessageStatus, CDialog&);
bool (*_validate)(const char*, CDialog&);
</syntaxhighlight></big>
*_help, holds the address of the help logic (function) or NULL if there is no help function is assigned
*_validate, holds the address of the validation logic (function) or NULL if there is no validation function is assgned
 
===Constructors===
<big><syntaxhighlight lang="cpp">
CValEdit(char* Str, int Row, int Col, int Width,
int Maxdatalen, 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);
</syntaxhighlight></big>
These constructors pass all their arguments to corresponding arguments of CLineEdit constructor and then set '''_help''' and '''_validate''' attributes to the corresponding incoming arguments
 
===Method===
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
If the container() is NULL then this function works exactly like LineEdit::edit().<br />
If the container() is not NULL:
#If _help function exist it calls the function passing MessageStatus::SetMessage and container()'s reference as arguments.
#Calls 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.''<br />
''MessageStatus is enumerated in '''iolgh.h'''''
=Linux and Unix makefile=
Copy these makefiles under "makefile" name in root of your project in Linux or Mac.<br />
Replace the "<tab>" with tab character<br />
then issue the make command: <br />
$make <enter><br />
this will compile your code and create an executable called tXexe,(where X is you test number if there is no error<br />
==Test 1 (CFrame)==
<big><pre>
t1: iol.o cframe.o Test1Frame.o
c++ iol.o cframe.o Test1Frame.o -lncurses -ot1exe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
Test1Frame.o: Test1Frame.cpp cframe.h iolgh.h
</pre></big>
==Test 2 (Dialog and Label)==
<big><pre>
t2: iol.o cframe.o cfield.o cdialog.o clabel.o Test2DialogAndLabel.o
c++ iol.o cframe.o cfield.o cdialog.o clabel.o \
Test2DialogAndLabel.o -lncurses -ot2exe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
cfield.o: cfield.cpp cfield.h iolgh.h cframe.h
c++ -c cfield.cpp
 
cdialog.o: cdialog.cpp cdialog.h cfield.h iolgh.h cframe.h
c++ -c cdialog.cpp
 
clabel.o: clabel.cpp clabel.h cfield.h cframe.h iolgh.h
c++ -c clabel.cpp
 
Test2DialogAndLabel.o: Test2DialogAndLabel.cpp clabel.h cdialog.h cframe.h iolgh.h cfield.h
</pre></big>
==Test 3 (LineEdit)==
<big><pre>
t3: iol.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o
c++ iol.o cframe.o cfield.o cdialog.o clabel.o clineedit.o Test3DialogAndLineEdit.o \
-lncurses -ot3exe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
cfield.o: cfield.cpp cfield.h iolgh.h cframe.h
c++ -c cfield.cpp
 
cdialog.o: cdialog.cpp cdialog.h cfield.h iolgh.h cframe.h
c++ -c cdialog.cpp
 
clabel.o: clabel.cpp clabel.h cfield.h cframe.h iolgh.h
c++ -c clabel.cpp
 
clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h iolgh.h
c++ -c clineedit.cpp
Test3DialogAndLineEdit.o: Test3DialogAndLineEdit.cpp clineedit.h clabel.h cdialog.h cfield.h cframe.h iolgh.h
c++ -c Test3DialogAndLineEdit.cpp
</pre></big>
 
==Test 4 (Button)==
<big><pre>
t4: iol.o cframe.o cfield.o cdialog.o clabel.o cbutton.o Test4Button.o
c++ iol.o cframe.o cfield.o cdialog.o clabel.o cbutton.o Test4Button.o \
-lncurses -ot4exe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
cfield.o: cfield.cpp cfield.h iolgh.h cframe.h
c++ -c cfield.cpp
 
cdialog.o: cdialog.cpp cdialog.h cfield.h iolgh.h cframe.h
c++ -c cdialog.cpp
 
clabel.o: clabel.cpp clabel.h cfield.h cframe.h iolgh.h
c++ -c clabel.cpp
 
cbutton.o: cbutton.cpp cbutton.h cfield.h cframe.h iolgh.h
c++ -c cbutton.cpp
 
Test4Button.o: Test4Button.cpp cframe.h cfield.h cdialog.h clabel.h cbutton.h
c++ -c Test4Button.cpp
</pre></big>
 
==Test 5 (VLineEdit)==
<big><pre>
t5: iol.o cframe.o cfield.o cdialog.o clabel.o cbutton.o clineedit.o cveditline.o Test5ValEdit.o
c++ iol.o cframe.o cfield.o cdialog.o clabel.o clineedit.o cbutton.o cveditline.o Test5ValEdit.o \
-lncurses -oprjexe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
cfield.o: cfield.cpp cfield.h iolgh.h cframe.h
c++ -c cfield.cpp
 
cdialog.o: cdialog.cpp cdialog.h cfield.h iolgh.h cframe.h
c++ -c cdialog.cpp
 
clabel.o: clabel.cpp clabel.h cfield.h cframe.h iolgh.h
c++ -c clabel.cpp
 
clineedit.o: clineedit.cpp clineedit.h cfield.h cframe.h iolgh.h
c++ -c clineedit.cpp
 
cbutton.o: cbutton.cpp cbutton.h cfield.h cframe.h iolgh.h
c++ -c cbutton.cpp
 
cveditline.o: cveditline.cpp cveditline.h clineedit.h cfield.h cframe.h iolgh.h
c++ -c cveditline.cpp
 
Test5ValEdit.o: Test5ValEdit.cpp cframe.h cfield.h cdialog.h clabel.h clineedit.h cveditline.h
c++ -c Test5ValEdit.cpp
</pre></big>
 
==Test 6 (CCheck)==
<big><pre>
t6: iol.o cframe.o cfield.o cdialog.o clabel.o ccheck.o Test6Check.o
c++ iol.o cframe.o cfield.o cdialog.o clabel.o ccheck.o Test6Check.o \
-lncurses -ot6exe
 
iol.o: iol.c iol.h
cc -c iol.c
 
cframe.o: cframe.cpp cframe.h iolgh.h
c++ -c cframe.cpp
 
cfield.o: cfield.cpp cfield.h iolgh.h cframe.h
c++ -c cfield.cpp
 
cdialog.o: cdialog.cpp cdialog.h cfield.h iolgh.h cframe.h
c++ -c cdialog.cpp
 
clabel.o: clabel.cpp clabel.h cfield.h cframe.h iolgh.h
c++ -c clabel.cpp
 
ccheck.o: ccheck.cpp ccheck.h clabel.h cfield.h cframe.h iolgh.h
c++ -c ccheck.cpp
Test6Check.o: Test6Check.cpp cframe.h cfield.h cdialog.h clabel.h ccheck.h
c++ -c Test6Check.cpp
</pre></big>
1
edit

Navigation menu