1
edit
Changes
→PLATFORM KEY DEFINITIONS
<big><big><big>TextEdit , OOP344 Open Source Project 20102</big></big></big>(under construction)
<big><big><big>Release 0.1</big></big></big>
Include your already existing C code into your C++ code as follows:
<big><syntaxhighlight lang="cpp">
extern "C"{
#include "iof.h"
};
</syntaxhighlight></big>
This tells to C++ compiler, the included header file contains C functions and should be complied and called as such. Remember, you do not need and should not rename your iof.c to iof.cpp, since the compiler is already aware of the C functions in iof.c.
<pre>
#ifndef __BIO_BTEXT_H____IO_TEXT_H__ #define __BIO_BTEXT_H____IO_TEXT_H__
extern "C"{
#include "biofiof.h"
};
Also as mentioned above, A Form object is responsible to hold the input/output objects and display and edit them in an orderly fashion. A Form, so to speak, could be an array or list of input/output objects.
These objects by design, could be framed, which means they can have a border drawn around them. Because of this, a class needs to be designed to represent a Frame (we call it '''IOFrame''') to represent a Frame and this class should be inherited by all Framed objects.
Also, the input/output objects all have the same purpose (that is displaying or editing something). This "same purpose" will be encapsulated in an abstract class called '''[[#IOField | IOField]]''' that presents the idea of an input/output object in a form.
== IOFrame ==
<br />
[[OOP344 20102 IOFrame test main|A main() function to test IOFrame::draw Offsets]]<br />
== IOField ==
To accommodate the above we create the following class:
<big><presyntaxhighlight lang=cpp>
# include "ioframe.h"
};
</presyntaxhighlight></big>
* '''_owner''' Holds the address of the Form the IOField Belongs to. If null, it means the IOField does not belong to any Form and it is stand alone
* '''R0.4: IOForm* owner();''' returns the value of the '''_owner''' attribute.
== BLabel IOLabel ==
The only attribute BLabel need IOLabel needs in addition to its parents is an integer to Hold the length of the string to be shown.
<big><presyntaxhighlight lang="cpp">
#include "IOField.h"
class BLabel IOLabel: public IOField{
int _length;
public:
void display() const;
int edit();
bool editable()const;
IOField& set(const void* str);
};
</presyntaxhighlight></big>
*'''BLabelIOLabel(const char *str, int row, int col, int len = 0);''' After passing row and col to its parent, it allocates memory to hold the contents of '''str'''.
Allocation should be done after setting the '''_length''' to the proper value; if len is less than or equal to zero, then '''_length''' will be set to the length of the '''str''', otherwise, '''_length''' will be set to the value of incoming '''len'''.
Then the contents of str should be copied up to _legnth chars into '''IOField::_data'''. Make sure that the string is null terminated.
*'''BLabelIOLabel(int row, int col, int len);'''
This constructor is used to create an empty BLabel IOLabel. It works exactly like the above constructor, with one difference; there is no string to initialize the newly allocated memory.
'''_length''' is set to incoming '''len''' and then '''IOField::_data''' is set to the address of the newly allocated '''_length +1 ''' chars.
Set the first char of the _data to null to set the string to blank.
*'''virtual ~BLabelIOLabel();''' Deletes the data held in IOField::_data
*'''void display() const;''' Using bio_displayiof_display, displays IOField::_data at IOField::row() and IOField::col(), up to _length characters
*'''int edit();''' Calls the display() method and returns 0.
*'''bool editable()const;''' Always return false
*'''IOField& set(const void* str);''' Copies the '''str''' into IOField::_data up to _length chars and then returns a reference of the BLabel IOLabel.
== BEdit IOEdit ==BEdit IOEdit is A an IOField that is responsible to encapsulate the bio_editiof_edit.
To do so in addition to the attributes of its parents; row, col and width (that is fieldlen) it needs to have the following:
*An integer to keep the offset position.
*An integer pointer to hold the address of the insert status.
<big><presyntaxhighlight lang="cpp">class BEditIOEdit: public IOField{
bool _dyn;
int _maxdatalen;
int _offset;
public:
int maxdatalen, int* insertmode,
bool framed = false);
int maxdatalen, int* insertmode,
bool framed = false);
~BEditIOEdit();
void display()const;
IOField& set(const void* str);
};
</presyntaxhighlight></big>*'''BEditIOEdit(char* str, int row, int col, int fieldlen,int maxdatalen, int* insertmode,bool framed = false);'''
Edit, sets IOField::_data to value of str. If BEdit IOEdit is instantiated with this constructor then it will edit an external string provided by the caller function of BEditIOEdit. BEdit IOEdit in this case is not creating any dynamic memory, therefore '''_dyn''' is set to false;
The location (row and col) and '''framed''' are directly passed to the parent and str is passed as data to the parent constructor.
Unlike BLabel IOLabel, BEdit IOEdit could be framed or not so depending on this (framed being true or false) the size (width and height) of BEdit IOEdit are set as follows:
If framed is false, then there is no border around the editing line so the height of the frame should be set to 0 and the width of the frame should be equal to the value of fieldlen. How ever is if the editing line is bordered, then it needs 3 chars for height and fieldlen + 2 as width:
<big><pre>
*'''BEditIOEdit(int row, int col, int fieldlen,int maxdatalen, int* insertmode,bool framed = false);''' This Constructor works exactly like the above with respect to location and size, but for data, because no data is provided to edit, it will create a dynamic, blank char string to accommodate the editing.
the size of the allocation will be maxdatelen +1 and obviously _dyn is set to true, so the destructor knows the memory has to be deallocated at the time of destruction. The allocated memory should be pointed by IOField::_data.
*'''~BEditIOEdit();''' If _dyn is true it will delete the string pointed by IOField::_data.
*'''void display()const;''' First it will call the display() method of its parent and then makes a direct call to bio_display iof_display using the row(), col() and fieldlen() accessors.*'''int edit();''' makes a direct call to bio_edit iof_edit passing the corresponding values from the attributes and accessor methods. the IsTextEditor is set t to '''0''' and the readonly is set to '''0''' too (for now).
*'''bool editable()const;''' returns true
*'''int row()const;''' returns the IOField::row() but it will add one to it, if BEdit IOEdit is framed*'''int col()const;''' returns the IOField::col() but it will add one to it, if BEdit IOEdit is framed*'''int fieldlen()const;''' returns the IOFrame::width() but reduces it by 2 if BEdit IOEdit is framed
*'''IOField& set(const void* str);''' copies the content of str into IOField::_data up to maxdatalen characters.
IOForm is a collection of IOFields. IOForm organizes and groups the IOFields for user entry.
<big><presyntaxhighlight lang="cpp">
# include "iotext.h"
class IOForm: public IOFrame{
private: int _fnum; int _curidx; IOField* _fld[MAX_NO_FIELDS]; bool _dyn[MAX_NO_FIELDS]; bool _editable; IOForm* _owner; public: IOForm(int row = -1, int col = -1, int width = -1, int height = -1, bool framed = false); virtual ~IOForm(); void display(int fn = OT_CLR_AND_DSPLY_ALL_CLR_AND_DSPLY_ALL)const; int edit(int fn = 0, IOForm* owner = (IOForm*)0); IOForm& add(IOField* field, bool dynamic = true); IOForm& add(IOField& field, bool dynamic = false); bool editable(); int fieldNum()const; int curField()const; IOForm& set(IOForm* owner);
IOField& operator[](unsigned int index);
};
</presyntaxhighlight></big>
* '''_fnum''' is the number of IOFields added to the IOForm
* '''void display(int fn = 0)const;'''<br />
If '''fn''' is OT_CLR_AND_DSPLY_ALL_CLR_AND_DSPLY_ALL, then it will check to see if _owner is not null. If _owner is not null, it will call the _owner's display() with OT_CLR_AND_DSPLY_ALL_CLR_AND_DSPLY_ALL, otherwise it will just clear the screen.<br />
Then it first call IOFrame::draw() and then it will display all the _fld elements, one by one.
If '''fn''' is OT_DSPLY_ALL _DSPLY_ALL then it will just call IOFrame::draw() and then it will display all the _fld elements, one by one.<br />
If '''fn''' is greater than 0 then it will only display '''_fld''' number '''fn''' (_fld[fn-1])
Executable sample for optext Release 0.3: ~fardad.soleimanloo/optext0.3
= IOVEdit =
Inherit IOEdit class to a Validated line editor class called IOVEdit.
IOVEdit, works exactly like a IOEdit, with two differences; 1- It supports Help messages. 2- Supports data validation
<big><pre>
void (*_help)(MessageStatus, IOForm&);
<big><pre>
int maxdatalen, int* insertmode,
bool (*validate)(const char* , IOForm&) = NO_VFUNC,
void (*help)(MessageStatus, IOForm&) = NO_HFUNC,
bool framed = false);
int maxdatalen, int* insertmode,
bool (*validate)(const char* , IOForm&) = NO_VFUNC,
</pre></big>
These two constructors pass all the information directly to BEditIOEdit's constructor and then set the "function pointers" attributes to their corresponding arguments.
== Public Function ==
</pre></big>
* if '''owner()''' of BVedit IOVEdit is null, then it simply calls the BEditIOEdit's '''edit()''' and terminates (returning the same value as BEditIOEdit::edit())
* if '''owner()''' is not null
** if the help function pointer attribute is not NULL, it will call it passing '''SetMesssage'' , and '''*owner()''' as arguments (This will show the help message for this field, before editing begins.)
** if the validation function pointer is not null then it will call the BEditIOEdit::edit() and validate the data with it by keep repeating the BEditIOEdit::edit() until either validation function return true or the BEditIOEdit::edit() was terminated by a non navigation key.
*** Navigation keys are: '''UP_KEY DOWN_KEY TAB_KEY and ENTER_KEY'''
** Right before the BVeditIOVEdit::edit() Terminates, if the help function pointer attribute is not NULL, it will call it again passing '''ClearMesssage'' , and '''owner()''' as arguments (this will clear the help message after editing is done.)** BVeditIOVEdit::edit() will return the return value of BEditIOEdit::edit().= BTextEdit IOTextEdit =
== Constructors ==
<big><pre>
bool readonly, int* insertmode);
int row, int col, int height,int width,
bool readonly, int* insertmode);
</pre></big>
The maximum width of the text could be considered constant that is defined in '''OT_MAX_LINE_CHARS'''.
</pre></big>
Sets the data of BTextEdit IOTextEdit to the incomming data in the character array pointed by '''str'''.
<big><pre>
bool readOnly();
</pre></big>
Returns, if BTextEdit IOTextEdit is read-only or not.
<big><pre>
virtual ~BTextEditIOTextEdit();
</pre></big>
Deallocates the dynamic memory used by the class before BTextEdit IOTextEdit is destroyed.
|---IOField
|
|--------BLabelIOLabel
|
|--------BEditIOEdit
| |
| |-------BVeditIOVEdit
|
|--------BTextEditIOTextEdit
</pre></big>
= Due Dates =
= Executable Samples on Matrix=
== compiling under Linux ==
To compile in matrix, use:
g++ yada.cpp yadoo.cpp -x c biofiof.c -lncurses
If you have many cpp's, you may also do
g++ *.cpp -x c biofiof.c -lncurses
== Sample makefile for optext release 0.3 TextEdit ==
<big><pre>
ioframe.o: ioframe.cpp ioframe.h iotext.h
c++ -c ioframe.cpp
c++ -c optext.cpp
</pre></big>
= PLATFORM KEY DEFINITIONS =
<u>'''VCC and PLT_BCC'''</u>
* UP_KEY 1072
* DOWN_KEY 1080
* LEFT_KEY 1075
* RIGHT_KEY 1077
* PGUP_KEY 1073
* PGDN_KEY 1081
* ENTER_KEY 13
* TAB_KEY 9
* BACSPACE_KEY 8
* DEL_KEY 1083
* HOME_KEY 1071
* END_KEY 1079
* ESCAPE_KEY 27
* INSERT_KEY 1082
* F1_KEY 1059
* F2_KEY 1060
* F3_KEY 1061
* F4_KEY 1062
* F5_KEY 1063
* F6_KEY 1064
* F7_KEY 1065
* F8_KEY 1066
* F9_KEY 1067
* F10_KEY 1068
* F11_KEY 1133
* F12_KEY 1134
<u>'''LNX'''</u> /* use PUTTY terminal only and set the keyboard to Xtrem R6 */
* UP_KEY 259
* DOWN_KEY 258
* LEFT_KEY 260
* RIGHT_KEY 261
* PGUP_KEY 339
* PGDN_KEY 338
* ENTER_KEY 10
* TAB_KEY 9
* BACKSPACE_KEY 263
* DEL_KEY 330
* HOME_KEY 262
* END_KEY 360
* ESCAPE_KEY 27
* INSRT_KEY 331
* F1_KEY 265
* F2_KEY 266
* F3_KEY 267
* F4_KEY 268
* F5_KEY 269
* F6_KEY 270
* F7_KEY 271
* F8_KEY 272
* F9_KEY 273
* F10_KEY 274
* F11_KEY 275
* F12_KEY 276
<u>'''MAC'''</u>
* UP_KEY 259
* DOWN_KEY 258
* LEFT_KEY 260
* RIGHT_KEY 261
* PGUP_KEY 339
* PGDN_KEY 338
* ENTER_KEY 10
* TAB_KEY 9
* BACKSPACE_KEY 263
* DEL_KEY 127
* HOME_KEY 262
* END_KEY 360
* ESCAPE_KEY 27
* INSERT_KEY 331
* F1_KEY 995
* F2_KEY 996
* F3_KEY 997
* F4_KEY 998
* F5_KEY 269
* F6_KEY 270
* F7_KEY 111
* F8_KEY 272
* F9_KEY 273
* F10_KEY 274
* F11_KEY 275
* F12_KEY 126