Changes

Jump to: navigation, search

Console UI Core Classes - OOP344 20113

14,192 bytes added, 06:31, 21 March 2012
CText Tester Crash
*[svn://zenit.senecac.on.ca/oop344/trunk/cioTesters/Test2DialogAndLabel.cpp Test2DialogAndLabel.cpp ]
*on matrix, with putty (Terminal/keyboard: Xterm R6)
*: on OSX, you can emulate XTerm keyboard settings using [http://iterm.sourceforge.net/ iTerm]/[http://www.iterm2.com/#/section/home ITerm 2]
*: ~fardad.soleimanloo/t2 runs the demo for the test
====Makefile for test 2 on matrix====
#:* void radio(bool isRadio);
#:* operator bool();
#:* operator char*();
#:* bool operator=(bool flag);
#:: (see [[#CCheckMark|CCheckMark]] description)
# Divide and assign tasks.
===Due Dates===
* Tuesday Dec, 6, 2011
 
===Testers===
*[svn://zenit.senecac.on.ca/oop344/trunk/cioTesters/Test8Text.cpp Test8Text.cpp]
*[svn://zenit.senecac.on.ca/oop344/trunk/cioTesters/Test9CCheckList.cpp Test9CCheckList.cpp]
*[svn://zenit.senecac.on.ca/oop344/trunk/cioTesters/Test10Menu.cpp Test10Menu.cpp]
 
==Project makefiles==
*create a file in the root of cio call it '''"makefile"''' and copy the makefile of your test from "[svn://zenit.senecac.on.ca/oop344/trunk/cio_makefile cio makefiles]" into it.
*: make sure the lines starting with c++ are tabbed once.
*: then at command line issue the command '''"make"''' to complie;
*: the name of the executable will bt tX, where X is the number of the test.
* Again: here are the project [svn://zenit.senecac.on.ca/oop344/trunk/cio_makefile makefiles] for Linux
== POST YOUR PROBLEM HERE==
void radio(bool isRadio); // addition for R0.6
operator bool(); // addtion for R0.6
operator char*(); // addition for R0.6
bool operator=(bool flag);
};
}
 
</syntaxhighlight></big>
</syntaxhighlight></big>
* Overload the '''bool''' cast to return the value of '''_flag'''
<big><syntaxhighlight lang="cpp">
operator char*(); // addtion for R0.6
</syntaxhighlight></big>
* Overload the '''char*''' cast to return the value of '''_Label.data()'''
<big><syntaxhighlight lang="cpp">
bool operator=(bool flag);; // addtion for R0.6
</syntaxhighlight></big>
* Overload the operator= and set the _flag to flag
==CMenuItem==
===The Text Helper Class===
[svn://zenit.senecac.on.ca/oop344/trunk/textClass Text class]
<!-- ===CText Tester Crash=== Incorrect, TD[0].data() allocates mem and copies the data into it using text::export string
<syntaxhighlight lang="cpp">
char* data = (char*)TD[0].data();
delete [] data;
</syntaxhighlight>
This fails because TD[0].data() refers to CField::data() and NOT CText::data() like it should.
Here are some possible fixes that I think Fardad meant to use:
<syntaxhighlight lang="cpp">
char* data = (char*)((CText&)(TD[0])).data();
OR
char* data = (char*)txt.data();
</syntaxhighlight>
Note, this does NOT crash on Matrix, only Windows and Visual Studio.
-->
==CCheckList==
unsigned int flags()const;
void flags(unsigned int theFlags);
unsigned int selectedIndex()const; void selectedIndex(unsigned int index);
unsigned int length();
};
<big><syntaxhighlight lang="cpp">
CCheckMark* _checkmarks[32];
</syntaxhighlight></big>
An array of 32 CCheckmark pointers that will piont to _cnt dynamically allocated CCheckMarks.
<big><syntaxhighlight lang="cpp">
bool _radio;
</syntaxhighlight></big>
Holds the behaviour of the CCheckList to be like a Radio Button List or Check Mark List
<big><syntaxhighlight lang="cpp">
char _format[4];
</syntaxhighlight></big>
Holds the format with which a check mark is displayed (i.e. "[X]" or "(o)" etc...)
<big><syntaxhighlight lang="cpp">
unsigned int _cnt;
</syntaxhighlight></big>
Holds the number of CCheckMarks currently in CCheckList
<big><syntaxhighlight lang="cpp">
unsigned int _flags;
</syntaxhighlight></big>
Always holds the bit pattern corresponding to the status of the CCheckMarks in the List. Note that bit 0 (right most) will correspond to the first CCheckMark.
<big><syntaxhighlight lang="cpp">
unsigned int _cur;
</syntaxhighlight></big>
Holds the index of the CCheckMark in the "_checkmarks" array which is currently being edited. (focused)
 
===Constructors/Destructor===
<big><syntaxhighlight lang="cpp">
CCheckList(const char* Format, int Row, int Col, int Width,bool radio, bool Bordered = true,const char* Border=C_BORDER_CHARS);
</syntaxhighlight></big>
Passes corresponding values to the Base class (CField) then
#sets the _data attribute to the address of _flags
#copies '''Format''' and '''radio''' into '''_format''' and '''_radio''' respectively
#sets '''_cnt, _cur''' and '''_flags''' to zero
<big><syntaxhighlight lang="cpp">
~CCheckList(void);
</syntaxhighlight></big>
Goes through '''_checkmarks''' up to '''_cnt''' and if deletes them one by one.
 
===Methods===
<big><syntaxhighlight lang="cpp">
CCheckList& add(const char* Text, bool selected = false);
</syntaxhighlight></big>
* Only adds a new CCheckMark if '''_cnt''' does not exceed the maximum amount of '''_checkmarks''' (32)
* Creates a new CCheckMark with the row being '''_cnt'''+1, the height being 1 and the length being the length of '''Text'''+4
* Sets the newly created CCheckMarks' frame to '''this'''
* Automatically expands the width of the CCheckList if the width of the newly created CCheckMark is bigger than the current width of the CCheckList
* Sets the height of the CCheckList to '''_cnt'''+3
* Updates the bit pattern of '''_flags'''
* Increments '''_cnt'''
<big><syntaxhighlight lang="cpp">
CCheckList& operator<<(const char* Text);
</syntaxhighlight></big>
returns add(Text).
<big><syntaxhighlight lang="cpp">
void draw(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
Draws the frame and then draws all the '''_checkmarks''', making sure the cursor is standing under the first checked checkmark.
<big><syntaxhighlight lang="cpp">
int edit();
</syntaxhighlight></big>
*Draws the '''CCheckList''' then starts the editing the '''_checkmarks''' form '''_cur''' and according to the return key of CCheckMark::edit():
**If Down or Right key is hit it goes to the next '''_checkmark''', if '''_cur''' is the last one, then it exits the edit, returning the last key entered.
**UP and Left key works in opposite direction of Down and Right, if '''_cur''' is already zero, then it exits the edit, returning the last key entered.
**If Space is hit, then if '''_radio''' is true, it will uncheck all the '''_checkmarks''' other than the '''_cur'''rent one.
<big><syntaxhighlight lang="cpp">
void* data();
</syntaxhighlight></big>
returns the bit pattern held in _flags. <br />
''make sure _flags are updated to the status of the '''_checkmarks'''''
<big><syntaxhighlight lang="cpp">
void set(const void* data);
</syntaxhighlight></big>
sets the '''_flags''' and updates the '''_checkmarks''' to the bitpattern of '''_flags'''
<big><syntaxhighlight lang="cpp">
CCheckMark& operator[](unsigned int index);
</syntaxhighlight></big>
returns the CCheckMark corresponding the '''index''' value.
<big><syntaxhighlight lang="cpp">
bool editable()const;
</syntaxhighlight></big>
always returns true;
<big><syntaxhighlight lang="cpp">
bool radio()const;
</syntaxhighlight></big>
returns '''_radio'''
<big><syntaxhighlight lang="cpp">
void radio(bool val);
</syntaxhighlight></big>
sets the _radio and updates all _checkMarks radio value.
<big><syntaxhighlight lang="cpp">
unsigned int flags()const;
</syntaxhighlight></big>
returns the '''_flags''' attribute
<big><syntaxhighlight lang="cpp">
void flags(unsigned int theFlags);
</syntaxhighlight></big>sets the '''_flags''' attribute<big><syntaxhighlight lang="cpp"> unsigned int selectedIndex()const;</syntaxhighlight></big>returns the index of the first CCheckMark that is selected, and -1 if nothing is selected.<big><syntaxhighlight lang="cpp"> void selectedIndex(unsigned int index);</syntaxhighlight></big>sets the selectedindex. (only un-selects the rest if object is in radio mode)<br />if index is less than zero, then it will un-selects all<big><syntaxhighlight lang="cpp">
unsigned int length();
</syntaxhighlight></big>
returns '''_cnt'''
 
==CMenu and MNode==
CMenu is a linked list of MNodes. Providing menu selection for the user in two formats; Drop Down List, or a simple menu.
 
<big><syntaxhighlight lang="cpp">
#ifndef __CIO__CMENU_H__
CButton _Title;
public:
static const bool SelectedSelect;
CMenu(const char* Title, const char* Format, int Row, int Col,
int Width, int Height,bool dropdown,
int edit();
void set(const void* data);
int selectedIndex()const;
int selectedIndex(int index);
const char* selectedText();
~CMenu(void);
};
extern const bool SelectedSelect;
}
</syntaxhighlight></big>
===MNode===
MNode holds to main about an Item in the menut:
# The CMenuItem object
# The index of this Item
MNode is a fully private class and is only accessible by CMenu.
====Attributes====
<big><syntaxhighlight lang="cpp">
CMenuItem* _item;
</syntaxhighlight></big>
Holds the address of a dynamically allocated CMenuItem
<big><syntaxhighlight lang="cpp">
unsigned int _index;
</syntaxhighlight></big>
Holds the index (sequence -1) number of the '''CMenuItem''' in the '''CMenu'''.
<big><syntaxhighlight lang="cpp">
MNode* _next;
MNode* _prev;
</syntaxhighlight></big>
Standard next and previous pointer for a linked list node.
 
====Constructor/Destructor====
<big><syntaxhighlight lang="cpp">
MNode(CMenuItem* item,unsigned int index, MNode* prev, MNode* next = ((MNode*)0));
</syntaxhighlight></big>
Sets the corresponding attributes to the values of the arguments.
<big><syntaxhighlight lang="cpp">
~MNode(void);
</syntaxhighlight></big>
deletes the '''_item'''
 
===CMenu===
CMenu is a linked list of MNodes and also contains a CButton for a Title (only used on if in '''_dropdown''' mode). <br />Assuming that a CMenu is created with a title as "FILE" and menu-items as "Save, Load, Print, Quit":*When in '''_dropdown''' mode:When drawing, Only the _Title(CButton) is drawn (and not the menu itself)<big><pre> FILE</pre></big>When edited (in '''_dropdown''' mode) the CButton gets activated and if it is hit, then the Menu will be dropped down (drawn) under the CButton and user can browse through the options and select one of them. selecting the option in this case will close the menu and CButton gets activated again:<br />when active, CMenu looks like this:<big><pre>[FILE]</pre></big>User hits enter: (since nothing is selected all menu items are unselected)<big><pre> FILE/-------\| Save || Load || Print || Quit |\-------/</pre></big>Now the cursor is standing under '''S'''ave.User hits down arrow twice to select '''P'''rint and then hits Space:<big><pre>[FILE]</pre></big>The Print is selected and The menu is closed and FILE is active again.If the user hits Enter again:<big><pre> FILE/-------\| Save || Load ||[Print]|| Quit |\-------/</pre></big>We will see the Print is selected and the cursor in under P.If user hits Enter instead of space, the selection wont change and whatever was selected before will remain the same:<big><pre>[FILE]</pre></big>User hits navigation keys and moves out of the CMenu Field.''Note that if '''left''' or '''right''' navigation keys are hit when the title is active, then they are translated to '''up''' or '''down''' respectively.*When NOT in '''_dropdown''' mode:*:The CButton will not be displayed at all, and when user starts to edit, he enters the menu browsing the items and if he gets to the end of the menu, the control goes to the next field in the dialog. If user goes up and passes the first them, then the control will go to the previous field in the dalog.<big><pre>/-------\| Save || Load ||[Print]|| Quit |\-------/</pre></big>''Note that if the number of menu items are more than the space provided by the CField's frame, then the menu items should scroll up and down to accommodate the selection'' ====Attributes====<big><syntaxhighlight lang ="cpp"> MNode* _first;</syntaxhighlight></big>points to the first CMenuItem visible on the menu.<big><syntaxhighlight lang ="cpp"> MNode* _head; MNode* _tail; MNode* _cur;</syntaxhighlight></big>standard Link list pointers<big><syntaxhighlight lang = "cpp"> char _format[3];</syntaxhighlight></big>The two characters used to surround the selected menu item<big><syntaxhighlight lang = "cpp"> unsigned int _cnt;</syntaxhighlight></big>The number of CMenuItems in CMenu<big><syntaxhighlight lang = "cpp"> int _selectedIndex;</syntaxhighlight></big>The index of the selected CMenuItem (saved in MNode::index), if there is no selected menu, then this value is -1.<big><syntaxhighlight lang ="cpp"> bool _dropdown;</syntaxhighlight></big>True if the Menu is a Drop Down Menu.<big><syntaxhighlight lang =Construcotr"cpp"> bool _dropped;</syntaxhighlight></big>Flag used to hold the status of a Drop Down Menu, (_dropped or not)<big><syntaxhighlight lang = "cpp"> bool goNext(); bool goPrev();</syntaxhighlight></big>standard gonext() and goprev() in linked lists<big><syntaxhighlight lang = "cpp"> CButton _Title;</syntaxhighlight></big>CButton holding the Title of this menu====Constructor/Destructor====<big><syntaxhighlight lang = "cpp"> CMenu(const char* Title, const char* Format, int Row, int Col, int Width, int Height,bool dropdown, const char* Border=C_BORDER_CHARS);</syntaxhighlight></big>#Initializes CField as follows:#* Row: Passes Row, if this menu is not a dropdown, otherwise it will pass Row+1.#* Col, Width, Height are passed directly#* Data: a void null pointer is passed for data#* Bordered: since CMenu is always bordered, true is passed here#* Border is directly passed.#Initializes _Title (the CButton) as follows:#* Str, Title is passed here#* Row, -1#* Col, 1#* Bordered, since the title of the dorpdown is alway NOT bordered, then false is passed here.#Constructor Settings:#* Link list attributes are set as standard linked list contructor#* Format is copied into _format#* _cnt is set to zero#* _selectedIndex is set to -1#* _data is set to address of _selectedIndex#* _dropdown is set to dropdown#* _dropped is set to false#* _Title's frame is set to the CMenu object (this)<big><syntaxhighlight lang = "cpp">~CMenu();</syntaxhighlight></big>Standard Linked list destructor 
====Methods====
<big><syntaxhighlight lang = "cpp">
CMenu& add(const char* Text, bool selected = false);
</syntaxhighlight></big>
Standard append for a linked list:
#creates an MNode with
#* a new CMenutItem with
#*:selected, _format, Text for first three arguments
#*:1, 1, and (width of the menu) -2, for Row col and width
#* the rest are what is needed for a standard append procedure for a linked list
#appends the new MNode to the end of the list
#if the new added CMenuItem is selected, it will update the selected index
'''''Note that if the added CMenuItem is the first CMenuItem in the list, then the _first pointer should be pointing to it'''''
<big><syntaxhighlight lang = "cpp">
CMenu& operator<<(const char* Text);
</syntaxhighlight></big>
returns add(Text)
<big><syntaxhighlight lang = "cpp">
CMenu& operator<<(bool select);
</syntaxhighlight></big>
if select is true, it will select the last CMenuItem added to the CMenu
<big><syntaxhighlight lang = "cpp">
void draw(int fn = C_FULL_FRAME);
</syntaxhighlight></big>
#if this is a '''_dropdown''', then it will draw the _Title
#: and then if '''_dropped''' is true, it will draw the CField and then draw the CMenuItems starting form what _first is pointing to, up to (CField's hieght -2) times.
#if this not a '''_dropdown''' then the _Title will never be drawn and the CMenuItems should be drawn as above.
<big><syntaxhighlight lang = "cpp">
int edit();
</syntaxhighlight></big>
Edits the menu the way it is explains in [[#CMenu|CMenu]] description.<br />
If it is too confusing, this [[CMenu pseudo code - OOP344 20113|pseudo code]] may help.
<big><syntaxhighlight lang = "cpp">
void set(const void* data);
</syntaxhighlight></big>
Sets the selected index to the integer pointed by data;
<big><syntaxhighlight lang = "cpp">
int selectedIndex() const;
</syntaxhighlight></big>
returns the selected index or -1 if nothing is selected
<big><syntaxhighlight lang = "cpp">
int selectedIndex(int index);
</syntaxhighlight></big>
sets the selected index.
<big><syntaxhighlight lang = "cpp">
const char* selectedText();
</syntaxhighlight></big>
returns the text of the selected menu, if nothing is selected, and empty string is returned.
<big><syntaxhighlight lang = "cpp">
bool editable()const;
</syntaxhighlight></big>
returns true if '''_cnt''' is greater than zero

Navigation menu