Open main menu

CDOT Wiki β

Changes

OOP344 Assignment Two

5,338 bytes added, 11:13, 16 November 2009
adding description IO_TextEdit
==IO_TextEdit==
Inherit IO_Field and IO_Frame into a new class called IO_TextEdit. (Read: Practical Programming Techniques Using C++, pages 94 to 96, Multiple Inheritance topic)
 
IO_TextEdit, uses the io_edit() function of ciol library the the isTextEditor flag set to true. IO_TextEdit calls the io_edit function repeatedly to edit series of strings that is created dynamically by the IO_TextEdit. If an intial newline ('\n') sepearted string is provided, IO_TextEdit will split the string into several strings and copy them into dynamically allocated series of strings.
 
IO_TextEdit will do the edit in a framed multiline text field. Editing begins with the cursor at the top left of the field or from the position the editing was terminated before.
 
Each line can be edited using the io_edit. If during the process of editing the string is shifted, make sure all lines are shifted together. If in overstrike mode hitting the enter key goes to next line. Otherwise (in insert mode) it should insert a new line after the current line and if there is any data after the current position, the data should be cut, and pasted to the newly created line. The cursor should stand at the beginning of the new line.
 
Up and Down arrows should focus the editing on previous and next lines respectfully and if needed, to accomodate this the lines should shift to up and down. How ever, However if UP and Down keys are hit on the first or last line of data, then the function will terminate returning those values.
 
Page up and down should scrole the lines in the text field up and down "height-2" times, or better to say, scroll the text a page up or down if possible. if paging is not possible, then the keys are ignored.
 
Each line in the text can be the maximum of "_IO_TEXT_ALLOCATION_LINE_SIZE" characters, definded in io_def.h
 
==Constructors==
 
IO_TextEdit can be created as follows:
 
===Dynamic Data===
 
<big><pre>IO_TextEdit(int row, int col, int width, int height,int maxLines = -1,
int* insertmode, const char* frameChars = (const char*)0);</pre></big>
 
This constructor set the class to dynamically create "sereies of strings" to be edited by io_edit function in the edit method when needed.The arguments, row and column are top and left coordinates of the text feild and width and hieght are the width and height of the text field.
 
insertMode is where the insert flag status is kept.
 
frameChars hold the optional characters to build the frame.
 
The "single dimension string" representation of the "series of the strings" holding the text, in this case, will be allocated and kept dynamically.
 
maxLines argument will limit the number of the lines in text, unless it is set to -1.
 
===Non-dynamic Data===
 
<big><pre>IO_TextEdit(char* str, int row, int col, int width, int height,int maxLines = -1,
int* insertmode, const char* frameChars = (const char*)0);</pre></big>
 
This constructor initially splits the newline seperated data from the "str" argument into series of lines that are created dynamically to be edited by the io_edit function in the edit method. The arguments, row and column are top and left coordinates of the text feild and width and hieght are the width and height of the text field.
 
insertMode is where the insert flag status is kept.
 
frameChars hold the optional characters to build the frame.
 
The "single dimension string" representation of the "series of the strings" holding the text will the be where str argument is pointing to. No dynamic memory is allocated for this.It is the caller program's responsibilty to accomodate enough space for the data;
 
maxLines argument will limit the number of the lines in text, unless it is set to -1.
 
Make sure you store the address of where str is pointing in the _data of IO_Field for future use.
 
==Public Methods==
 
===void display()const;===
 
Displays the frame, and in the fram it will display the text from the top left being the first character of the first line or othewise any position it was been right before the editing was terminated the last time.
 
===void *data();===
 
first converts back the series of string to a single dimenssion newline seperated string of characters pointed by the IO_Field's data, and then returns it.
 
If object is dynamic (created by the first construcotr) then you may have to reallocate memory to make room for convertion.
 
If object is not dynamic, (made by the second constructor) then the conversion's target will be the _data of IO_Field that was set by the construcotr. No dynamic memory allocation should be done for the conversion. It is the user program of the object's responsiblity to provide enough memory for this.
 
Make sure you modify void IO_Field::data(); method to virtual for this to work;
 
===int edit();===
 
Edits the text one line at a the framed text field created by the constructor as mentioned in the description of the class.
 
===bool editable()const;===
 
Always returns true;
 
===void set(const void *str);===
 
splits the newline seperated data from the "str" argument into "series of stings" that are created dynamically to be edited by the io_edit function in the edit method.
 
===virtual ~IO_TextEdit();===
 
deallocates the "series of strings" created for editing purposes. Also if object holds the data dynamically (created by fist constructor) it will deallocate memory pointed by the IO_Fields _data;
=The Application=